2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.datamodel.*;
\r
29 public class AnnotationLabels
\r
30 extends Panel implements ActionListener, MouseListener, MouseMotionListener
\r
33 boolean active = false;
\r
36 boolean resizing = false;
\r
38 static String EDITNAME = "Edit label/description";
\r
39 static String HIDE = "Hide this row";
\r
40 static String DELETE = "Delete this row";
\r
41 static String SHOWALL = "Show all hidden rows";
\r
42 static String OUTPUT_TEXT = "Show Values In Textbox";
\r
43 static String COPYCONS_SEQ = "Copy Consensus Sequence";
\r
45 int selectedRow = 0;
\r
46 int scrollOffset = 0;
\r
50 public AnnotationLabels(AlignmentPanel ap)
\r
55 addMouseListener(this);
\r
56 addMouseMotionListener(this);
\r
59 public AnnotationLabels(AlignViewport av)
\r
64 public void setScrollOffset(int y)
\r
70 void getSelectedRow(int y)
\r
73 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
81 for (int i = 0; i < aa.length; i++)
\r
88 height += aa[i].height;
\r
97 public void actionPerformed(ActionEvent evt)
\r
99 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
101 if (evt.getActionCommand().equals(EDITNAME))
\r
103 EditNameDialog dialog = new EditNameDialog(
\r
104 aa[selectedRow].label,
\r
105 aa[selectedRow].description,
\r
106 " Annotation Label",
\r
107 "Annotation Description",
\r
109 "Edit Annotation Name / Description");
\r
113 aa[selectedRow].label = dialog.getName();
\r
114 aa[selectedRow].description = dialog.getDescription();
\r
118 if (evt.getActionCommand().equals(HIDE))
\r
120 aa[selectedRow].visible = false;
\r
122 else if (evt.getActionCommand().equals(SHOWALL))
\r
124 for (int i = 0; i < aa.length; i++)
\r
126 aa[i].visible = true;
\r
129 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
\r
131 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
\r
132 Frame frame = new Frame();
\r
134 jalview.bin.JalviewLite.addFrame(frame,
\r
135 ap.alignFrame.getTitle() + " - " +
\r
136 aa[selectedRow].label, 500, 100);
\r
137 cap.setText(aa[selectedRow].toString());
\r
139 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
\r
141 SequenceI cons = av.getConsensusSeq();
\r
144 copy_annotseqtoclipboard(cons);
\r
148 ap.annotationPanel.adjustPanelHeight();
\r
149 setSize(getSize().width, ap.annotationPanel.getSize().height);
\r
151 ap.paintAlignment(true);
\r
154 public void mouseMoved(MouseEvent evt)
\r
156 getSelectedRow(evt.getY() - scrollOffset);
\r
158 if (selectedRow > -1)
\r
160 if (tooltip == null)
\r
162 tooltip = new Tooltip(ap.av.alignment.
\r
163 getAlignmentAnnotation()[selectedRow].
\r
169 tooltip.setTip(ap.av.alignment.
\r
170 getAlignmentAnnotation()[selectedRow].description);
\r
173 else if (tooltip != null)
\r
175 tooltip.setTip("");
\r
180 public void mouseDragged(MouseEvent evt)
\r
183 public void mouseClicked(MouseEvent evt)
\r
186 public void mouseReleased(MouseEvent evt)
\r
189 public void mouseEntered(MouseEvent evt)
\r
192 public void mouseExited(MouseEvent evt)
\r
195 public void mousePressed(MouseEvent evt)
\r
197 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
199 PopupMenu pop = new PopupMenu("Annotations");
\r
201 MenuItem item = new MenuItem(EDITNAME);
\r
202 item.addActionListener(this);
\r
204 item = new MenuItem(HIDE);
\r
205 item.addActionListener(this);
\r
207 item = new MenuItem(SHOWALL);
\r
208 item.addActionListener(this);
\r
211 item = new MenuItem(OUTPUT_TEXT);
\r
212 item.addActionListener(this);
\r
215 if (aa[selectedRow] == ap.av.consensus)
\r
217 pop.addSeparator();
\r
218 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
\r
219 "Ignore Gaps In Consensus",
\r
220 ap.av.getIgnoreGapsConsensus());
\r
222 cbmi.addItemListener(new ItemListener()
\r
224 public void itemStateChanged(ItemEvent e)
\r
226 ap.av.setIgnoreGapsConsensus(cbmi.getState());
\r
227 ap.paintAlignment(true);
\r
231 final MenuItem cpcons = new MenuItem(COPYCONS_SEQ);
\r
232 cpcons.addActionListener(this);
\r
236 pop.show(this, evt.getX(), evt.getY());
\r
243 * @param e DOCUMENT ME!
\r
245 protected void copy_annotseqtoclipboard(SequenceI sq)
\r
247 if (sq == null || sq.getLength() < 1)
\r
251 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
\r
252 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
\r
253 sq.getStart() + "\t" +
\r
254 sq.getEnd() + "\t" +
\r
255 sq.getSequenceAsString() + "\n");
\r
256 if (av.hasHiddenColumns)
\r
258 jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
\r
259 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
\r
261 int[] region = (int[])
\r
262 av.getColumnSelection().getHiddenColumns().elementAt(i);
\r
264 jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]
\r
271 public void update(Graphics g)
\r
276 public void paint(Graphics g)
\r
278 int w = getSize().width;
\r
279 if (image == null || w != image.getWidth(this))
\r
281 image = createImage(w, ap.annotationPanel.getSize().height);
\r
284 drawComponent(image.getGraphics(), w);
\r
285 g.drawImage(image, 0, 0, this);
\r
288 public void drawComponent(Graphics g, int width)
\r
290 g.setFont(av.getFont());
\r
291 FontMetrics fm = g.getFontMetrics(av.getFont());
\r
292 g.setColor(Color.white);
\r
293 g.fillRect(0, 0, getSize().width, getSize().height);
\r
295 g.translate(0, scrollOffset);
\r
296 g.setColor(Color.black);
\r
298 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
299 int y = g.getFont().getSize();
\r
304 for (int i = 0; i < aa.length; i++)
\r
306 if (!aa[i].visible)
\r
311 x = width - fm.stringWidth(aa[i].label) - 3;
\r
313 if (aa[i].graph > 0)
\r
315 y += (aa[i].height / 3);
\r
318 g.drawString(aa[i].label, x, y);
\r
320 if (aa[i].graph > 0)
\r
322 y += (2 * aa[i].height / 3);
\r