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 Checkbox padGaps = new Checkbox("Fill Empty Gaps With \""
161 +ap.av.getGapCharacter()+"\"",
164 EditNameDialog dialog = new EditNameDialog(
166 annotation.description,
168 "Annotation Description",
170 "Edit Annotation Name / Description",
173 Panel empty = new Panel(new FlowLayout());
178 dialog.setVisible(true);
182 annotation.label = dialog.getName();
183 annotation.description = dialog.getDescription();
184 annotation.setPadGaps(padGaps.getState(), av.getGapCharacter());
193 public void mouseMoved(MouseEvent evt)
195 int row = getSelectedRow(evt.getY() - scrollOffset);
201 tooltip = new Tooltip(ap.av.alignment.
202 getAlignmentAnnotation()[row].
208 tooltip.setTip(ap.av.alignment.
209 getAlignmentAnnotation()[row].description);
212 else if (tooltip != null)
219 public void mouseDragged(MouseEvent evt)
222 public void mouseClicked(MouseEvent evt)
225 public void mouseReleased(MouseEvent evt)
228 public void mouseEntered(MouseEvent evt)
231 public void mouseExited(MouseEvent evt)
234 public void mousePressed(MouseEvent evt)
236 selectedRow = getSelectedRow(evt.getY() - scrollOffset);
238 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
240 PopupMenu popup = new PopupMenu("Annotations");
242 MenuItem item = new MenuItem(ADDNEW);
243 item.addActionListener(this);
245 item = new MenuItem(EDITNAME);
246 item.addActionListener(this);
248 item = new MenuItem(HIDE);
249 item.addActionListener(this);
251 item = new MenuItem(SHOWALL);
252 item.addActionListener(this);
255 item = new MenuItem(OUTPUT_TEXT);
256 item.addActionListener(this);
259 if (aa[selectedRow] == ap.av.consensus)
261 popup.addSeparator();
262 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
263 "Ignore Gaps In Consensus",
264 ap.av.getIgnoreGapsConsensus());
266 cbmi.addItemListener(new ItemListener()
268 public void itemStateChanged(ItemEvent e)
270 ap.av.setIgnoreGapsConsensus(cbmi.getState());
271 ap.paintAlignment(true);
275 item = new MenuItem(COPYCONS_SEQ);
276 item.addActionListener(this);
280 popup.show(this, evt.getX(), evt.getY());
287 * @param e DOCUMENT ME!
289 protected void copy_annotseqtoclipboard(SequenceI sq)
291 if (sq == null || sq.getLength() < 1)
295 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
296 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
297 sq.getStart() + "\t" +
299 sq.getSequenceAsString() + "\n");
300 if (av.hasHiddenColumns)
302 jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
303 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
305 int[] region = (int[])
306 av.getColumnSelection().getHiddenColumns().elementAt(i);
308 jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]
315 public void update(Graphics g)
320 public void paint(Graphics g)
322 int w = getSize().width;
323 if (image == null || w != image.getWidth(this))
325 image = createImage(w, ap.annotationPanel.getSize().height);
328 drawComponent(image.getGraphics(), w);
329 g.drawImage(image, 0, 0, this);
332 public void drawComponent(Graphics g, int width)
334 g.setFont(av.getFont());
335 FontMetrics fm = g.getFontMetrics(av.getFont());
336 g.setColor(Color.white);
337 g.fillRect(0, 0, getSize().width, getSize().height);
339 g.translate(0, scrollOffset);
340 g.setColor(Color.black);
342 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
343 int y = g.getFont().getSize();
348 for (int i = 0; i < aa.length; i++)
355 x = width - fm.stringWidth(aa[i].label) - 3;
359 y += (aa[i].height / 3);
362 g.drawString(aa[i].label, x, y);
366 y += (2 * aa[i].height / 3);