2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 package jalview.appletgui;
25 import java.awt.event.*;
27 import jalview.datamodel.*;
29 public class AnnotationLabels
30 extends Panel implements ActionListener, MouseListener, MouseMotionListener
33 boolean active = false;
36 boolean resizing = false;
39 static String ADDNEW = "Add New Row";
40 static String EDITNAME = "Edit Label/Description";
41 static String HIDE = "Hide This Row";
42 static String SHOWALL = "Show All Hidden Rows";
43 static String OUTPUT_TEXT = "Show Values In Textbox";
44 static String COPYCONS_SEQ = "Copy Consensus Sequence";
51 public AnnotationLabels(AlignmentPanel ap)
56 addMouseListener(this);
57 addMouseMotionListener(this);
60 public AnnotationLabels(AlignViewport av)
65 public void setScrollOffset(int y)
71 int getSelectedRow(int y)
74 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
82 for (int i = 0; i < aa.length; i++)
89 height += aa[i].height;
100 public void actionPerformed(ActionEvent evt)
102 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
104 if (evt.getActionCommand().equals(ADDNEW))
106 AlignmentAnnotation newAnnotation = new AlignmentAnnotation("",
108 new Annotation[ap.av.alignment.getWidth()]);
110 if (!editLabelDescription(newAnnotation))
115 ap.av.alignment.addAnnotation(newAnnotation);
116 ap.av.alignment.setAnnotationIndex(newAnnotation, 0);
118 else if (evt.getActionCommand().equals(EDITNAME))
120 editLabelDescription(aa[selectedRow]);
122 else if (evt.getActionCommand().equals(HIDE))
124 aa[selectedRow].visible = false;
126 else if (evt.getActionCommand().equals(SHOWALL))
128 for (int i = 0; i < aa.length; i++)
130 aa[i].visible = (aa[i].annotations==null) ? false : true;
133 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
135 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
136 Frame frame = new Frame();
138 jalview.bin.JalviewLite.addFrame(frame,
139 ap.alignFrame.getTitle() + " - " +
140 aa[selectedRow].label, 500, 100);
141 cap.setText(aa[selectedRow].toString());
143 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
145 SequenceI cons = av.getConsensusSeq();
148 copy_annotseqtoclipboard(cons);
152 ap.annotationPanel.adjustPanelHeight();
153 setSize(getSize().width, ap.annotationPanel.getSize().height);
155 ap.paintAlignment(true);
158 boolean editLabelDescription(AlignmentAnnotation annotation)
160 EditNameDialog dialog = new EditNameDialog(
162 annotation.description,
164 "Annotation Description",
166 "Edit Annotation Name / Description",
171 annotation.label = dialog.getName();
172 annotation.description = dialog.getDescription();
181 public void mouseMoved(MouseEvent evt)
183 int row = getSelectedRow(evt.getY() - scrollOffset);
189 tooltip = new Tooltip(ap.av.alignment.
190 getAlignmentAnnotation()[row].
196 tooltip.setTip(ap.av.alignment.
197 getAlignmentAnnotation()[row].description);
200 else if (tooltip != null)
207 public void mouseDragged(MouseEvent evt)
210 public void mouseClicked(MouseEvent evt)
213 public void mouseReleased(MouseEvent evt)
216 public void mouseEntered(MouseEvent evt)
219 public void mouseExited(MouseEvent evt)
222 public void mousePressed(MouseEvent evt)
224 selectedRow = getSelectedRow(evt.getY() - scrollOffset);
226 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
228 PopupMenu popup = new PopupMenu("Annotations");
230 MenuItem item = new MenuItem(ADDNEW);
231 item.addActionListener(this);
233 item = new MenuItem(EDITNAME);
234 item.addActionListener(this);
236 item = new MenuItem(HIDE);
237 item.addActionListener(this);
239 item = new MenuItem(SHOWALL);
240 item.addActionListener(this);
243 item = new MenuItem(OUTPUT_TEXT);
244 item.addActionListener(this);
247 if (aa[selectedRow] == ap.av.consensus)
249 popup.addSeparator();
250 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
251 "Ignore Gaps In Consensus",
252 ap.av.getIgnoreGapsConsensus());
254 cbmi.addItemListener(new ItemListener()
256 public void itemStateChanged(ItemEvent e)
258 ap.av.setIgnoreGapsConsensus(cbmi.getState());
259 ap.paintAlignment(true);
263 item = new MenuItem(COPYCONS_SEQ);
264 item.addActionListener(this);
268 popup.show(this, evt.getX(), evt.getY());
275 * @param e DOCUMENT ME!
277 protected void copy_annotseqtoclipboard(SequenceI sq)
279 if (sq == null || sq.getLength() < 1)
283 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
284 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
285 sq.getStart() + "\t" +
287 sq.getSequenceAsString() + "\n");
288 if (av.hasHiddenColumns)
290 jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
291 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
293 int[] region = (int[])
294 av.getColumnSelection().getHiddenColumns().elementAt(i);
296 jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]
303 public void update(Graphics g)
308 public void paint(Graphics g)
310 int w = getSize().width;
311 if (image == null || w != image.getWidth(this))
313 image = createImage(w, ap.annotationPanel.getSize().height);
316 drawComponent(image.getGraphics(), w);
317 g.drawImage(image, 0, 0, this);
320 public void drawComponent(Graphics g, int width)
322 g.setFont(av.getFont());
323 FontMetrics fm = g.getFontMetrics(av.getFont());
324 g.setColor(Color.white);
325 g.fillRect(0, 0, getSize().width, getSize().height);
327 g.translate(0, scrollOffset);
328 g.setColor(Color.black);
330 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
331 int y = g.getFont().getSize();
336 for (int i = 0; i < aa.length; i++)
343 x = width - fm.stringWidth(aa[i].label) - 3;
347 y += (aa[i].height / 3);
350 g.drawString(aa[i].label, x, y);
354 y += (2 * aa[i].height / 3);