2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
28 public class AnnotationLabels
29 extends Panel implements ActionListener, MouseListener, MouseMotionListener
32 boolean active = false;
35 boolean resizing = false;
38 static String ADDNEW = "Add New Row";
39 static String EDITNAME = "Edit Label/Description";
40 static String HIDE = "Hide This Row";
41 static String SHOWALL = "Show All Hidden Rows";
42 static String OUTPUT_TEXT = "Show Values In Textbox";
43 static String COPYCONS_SEQ = "Copy Consensus Sequence";
50 public AnnotationLabels(AlignmentPanel ap)
55 addMouseListener(this);
56 addMouseMotionListener(this);
59 public AnnotationLabels(AlignViewport av)
64 public void setScrollOffset(int y)
70 int getSelectedRow(int y)
73 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
81 for (int i = 0; i < aa.length; i++)
88 height += aa[i].height;
99 public void actionPerformed(ActionEvent evt)
101 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
103 if (evt.getActionCommand().equals(ADDNEW))
105 AlignmentAnnotation newAnnotation = new AlignmentAnnotation("",
107 new Annotation[ap.av.alignment.getWidth()]);
109 if (!editLabelDescription(newAnnotation))
114 ap.av.alignment.addAnnotation(newAnnotation);
115 ap.av.alignment.setAnnotationIndex(newAnnotation, 0);
117 else if (evt.getActionCommand().equals(EDITNAME))
119 editLabelDescription(aa[selectedRow]);
121 else if (evt.getActionCommand().equals(HIDE))
123 aa[selectedRow].visible = false;
125 else if (evt.getActionCommand().equals(SHOWALL))
127 for (int i = 0; i < aa.length; i++)
129 aa[i].visible = (aa[i].annotations==null) ? false : true;
132 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
134 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
135 Frame frame = new Frame();
137 jalview.bin.JalviewLite.addFrame(frame,
138 ap.alignFrame.getTitle() + " - " +
139 aa[selectedRow].label, 500, 100);
140 cap.setText(aa[selectedRow].toString());
142 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
144 SequenceI cons = av.getConsensusSeq();
147 copy_annotseqtoclipboard(cons);
151 ap.annotationPanel.adjustPanelHeight();
152 setSize(getSize().width, ap.annotationPanel.getSize().height);
154 ap.paintAlignment(true);
157 boolean editLabelDescription(AlignmentAnnotation annotation)
159 Checkbox padGaps = new Checkbox("Fill Empty Gaps With \""
160 +ap.av.getGapCharacter()+"\"",
163 EditNameDialog dialog = new EditNameDialog(
165 annotation.description,
167 "Annotation Description",
169 "Edit Annotation Name / Description",
172 Panel empty = new Panel(new FlowLayout());
177 dialog.setVisible(true);
181 annotation.label = dialog.getName();
182 annotation.description = dialog.getDescription();
183 annotation.setPadGaps(padGaps.getState(), av.getGapCharacter());
192 public void mouseMoved(MouseEvent evt)
194 int row = getSelectedRow(evt.getY() - scrollOffset);
200 tooltip = new Tooltip(ap.av.alignment.
201 getAlignmentAnnotation()[row].getDescription(true),
206 tooltip.setTip(ap.av.alignment.
207 getAlignmentAnnotation()[row].getDescription(true));
210 else if (tooltip != null)
217 public void mouseDragged(MouseEvent evt)
220 public void mouseClicked(MouseEvent evt)
223 public void mouseReleased(MouseEvent evt)
226 public void mouseEntered(MouseEvent evt)
229 public void mouseExited(MouseEvent evt)
232 public void mousePressed(MouseEvent evt)
234 selectedRow = getSelectedRow(evt.getY() - scrollOffset);
236 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
238 PopupMenu popup = new PopupMenu("Annotations");
240 MenuItem item = new MenuItem(ADDNEW);
241 item.addActionListener(this);
243 item = new MenuItem(EDITNAME);
244 item.addActionListener(this);
246 item = new MenuItem(HIDE);
247 item.addActionListener(this);
249 item = new MenuItem(SHOWALL);
250 item.addActionListener(this);
253 item = new MenuItem(OUTPUT_TEXT);
254 item.addActionListener(this);
257 if (aa[selectedRow] == ap.av.consensus)
259 popup.addSeparator();
260 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
261 "Ignore Gaps In Consensus",
262 ap.av.getIgnoreGapsConsensus());
264 cbmi.addItemListener(new ItemListener()
266 public void itemStateChanged(ItemEvent e)
268 ap.av.setIgnoreGapsConsensus(cbmi.getState());
269 ap.paintAlignment(true);
273 item = new MenuItem(COPYCONS_SEQ);
274 item.addActionListener(this);
278 popup.show(this, evt.getX(), evt.getY());
285 * @param e DOCUMENT ME!
287 protected void copy_annotseqtoclipboard(SequenceI sq)
289 if (sq == null || sq.getLength() < 1)
293 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
294 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
295 sq.getStart() + "\t" +
297 sq.getSequenceAsString() + "\n");
298 if (av.hasHiddenColumns)
300 jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
301 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
303 int[] region = (int[])
304 av.getColumnSelection().getHiddenColumns().elementAt(i);
306 jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]
313 public void update(Graphics g)
318 public void paint(Graphics g)
320 int w = getSize().width;
321 if (image == null || w != image.getWidth(this))
323 image = createImage(w, ap.annotationPanel.getSize().height);
326 drawComponent(image.getGraphics(), w);
327 g.drawImage(image, 0, 0, this);
330 public void drawComponent(Graphics g, int width)
332 g.setFont(av.getFont());
333 FontMetrics fm = g.getFontMetrics(av.getFont());
334 g.setColor(Color.white);
335 g.fillRect(0, 0, getSize().width, getSize().height);
337 g.translate(0, scrollOffset);
338 g.setColor(Color.black);
340 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
341 int y = g.getFont().getSize();
346 for (int i = 0; i < aa.length; i++)
353 x = width - fm.stringWidth(aa[i].label) - 3;
357 y += (aa[i].height / 3);
360 g.drawString(aa[i].label, x, y);
364 y += (2 * aa[i].height / 3);