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].getDescription(true),
207 tooltip.setTip(ap.av.alignment.
208 getAlignmentAnnotation()[row].getDescription(true));
211 else if (tooltip != null)
218 public void mouseDragged(MouseEvent evt)
221 public void mouseClicked(MouseEvent evt)
224 public void mouseReleased(MouseEvent evt)
227 public void mouseEntered(MouseEvent evt)
230 public void mouseExited(MouseEvent evt)
233 public void mousePressed(MouseEvent evt)
235 selectedRow = getSelectedRow(evt.getY() - scrollOffset);
237 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
239 PopupMenu popup = new PopupMenu("Annotations");
241 MenuItem item = new MenuItem(ADDNEW);
242 item.addActionListener(this);
244 item = new MenuItem(EDITNAME);
245 item.addActionListener(this);
247 item = new MenuItem(HIDE);
248 item.addActionListener(this);
250 item = new MenuItem(SHOWALL);
251 item.addActionListener(this);
254 item = new MenuItem(OUTPUT_TEXT);
255 item.addActionListener(this);
258 if (aa[selectedRow] == ap.av.consensus)
260 popup.addSeparator();
261 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
262 "Ignore Gaps In Consensus",
263 ap.av.getIgnoreGapsConsensus());
265 cbmi.addItemListener(new ItemListener()
267 public void itemStateChanged(ItemEvent e)
269 ap.av.setIgnoreGapsConsensus(cbmi.getState());
270 ap.paintAlignment(true);
274 item = new MenuItem(COPYCONS_SEQ);
275 item.addActionListener(this);
279 popup.show(this, evt.getX(), evt.getY());
286 * @param e DOCUMENT ME!
288 protected void copy_annotseqtoclipboard(SequenceI sq)
290 if (sq == null || sq.getLength() < 1)
294 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
295 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
296 sq.getStart() + "\t" +
298 sq.getSequenceAsString() + "\n");
299 if (av.hasHiddenColumns)
301 jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
302 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
304 int[] region = (int[])
305 av.getColumnSelection().getHiddenColumns().elementAt(i);
307 jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]
314 public void update(Graphics g)
319 public void paint(Graphics g)
321 int w = getSize().width;
322 if (image == null || w != image.getWidth(this))
324 image = createImage(w, ap.annotationPanel.getSize().height);
327 drawComponent(image.getGraphics(), w);
328 g.drawImage(image, 0, 0, this);
331 public void drawComponent(Graphics g, int width)
333 g.setFont(av.getFont());
334 FontMetrics fm = g.getFontMetrics(av.getFont());
335 g.setColor(Color.white);
336 g.fillRect(0, 0, getSize().width, getSize().height);
338 g.translate(0, scrollOffset);
339 g.setColor(Color.black);
341 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
342 int y = g.getFont().getSize();
347 for (int i = 0; i < aa.length; i++)
354 x = width - fm.stringWidth(aa[i].label) - 3;
358 y += (aa[i].height / 3);
361 g.drawString(aa[i].label, x, y);
365 y += (2 * aa[i].height / 3);