2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
23 import java.awt.event.*;
\r
24 import java.util.Vector;
\r
26 import jalview.datamodel.*;
\r
28 public class AnnotationLabels
\r
29 extends Panel implements ActionListener, MouseListener, MouseMotionListener
\r
32 boolean active = false;
\r
35 boolean resizing = false;
\r
37 static String EDITNAME = "Edit label/description";
\r
38 static String HIDE = "Hide this row";
\r
39 static String DELETE = "Delete this row";
\r
40 static String SHOWALL = "Show all hidden rows";
\r
41 static String OUTPUT_TEXT = "Show Values In Textbox";
\r
42 static String COPYCONS_SEQ = "Copy Consensus Sequence";
\r
44 int selectedRow = 0;
\r
45 int scrollOffset = 0;
\r
49 public AnnotationLabels(AlignmentPanel ap)
\r
54 addMouseListener(this);
\r
55 addMouseMotionListener(this);
\r
58 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
79 for (int i = 0; i < aa.length; i++)
\r
86 height += aa[i].height;
\r
95 public void actionPerformed(ActionEvent evt)
\r
97 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
99 if(evt.getActionCommand().equals(EDITNAME))
\r
101 EditNameDialog dialog = new EditNameDialog(
\r
102 aa[selectedRow].label,
\r
103 aa[selectedRow].description,
\r
104 " Annotation Label",
\r
105 "Annotation Description",
\r
107 "Edit Annotation Name / Description");
\r
111 aa[selectedRow].label = dialog.getName();
\r
112 aa[selectedRow].description = dialog.getDescription();
\r
116 if (evt.getActionCommand().equals(HIDE))
\r
118 aa[selectedRow].visible = false;
\r
120 else if (evt.getActionCommand().equals(SHOWALL))
\r
122 for (int i = 0; i < aa.length; i++)
\r
124 aa[i].visible = true;
\r
127 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
\r
129 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
\r
130 Frame frame = new Frame();
\r
132 jalview.bin.JalviewLite.addFrame(frame,
\r
133 ap.alignFrame.getTitle() + " - " +
\r
134 aa[selectedRow].label, 500, 100);
\r
135 cap.setText(aa[selectedRow].toString());
\r
137 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
\r
139 SequenceI cons=av.getConsensusSeq();
\r
141 copy_annotseqtoclipboard(cons);
\r
144 ap.annotationPanel.adjustPanelHeight();
\r
145 setSize(getSize().width, ap.annotationPanel.getSize().height);
\r
150 public void mouseMoved(MouseEvent evt)
\r
152 getSelectedRow(evt.getY() - scrollOffset);
\r
154 if (selectedRow > -1)
\r
156 if (tooltip == null)
\r
157 tooltip = new Tooltip(ap.av.alignment.
\r
158 getAlignmentAnnotation()[selectedRow].
\r
162 tooltip.setTip(ap.av.alignment.
\r
163 getAlignmentAnnotation()[selectedRow].description);
\r
165 else if (tooltip != null)
\r
167 tooltip.setTip("");
\r
172 public void mouseDragged(MouseEvent evt)
\r
174 public void mouseClicked(MouseEvent evt)
\r
176 public void mouseReleased(MouseEvent evt)
\r
178 public void mouseEntered(MouseEvent evt)
\r
180 public void mouseExited(MouseEvent evt)
\r
182 public void mousePressed(MouseEvent evt)
\r
184 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
186 PopupMenu pop = new PopupMenu("Annotations");
\r
188 MenuItem item = new MenuItem(EDITNAME);
\r
189 item.addActionListener(this);
\r
191 item = new MenuItem(HIDE);
\r
192 item.addActionListener(this);
\r
194 item = new MenuItem(SHOWALL);
\r
195 item.addActionListener(this);
\r
198 item = new MenuItem(OUTPUT_TEXT);
\r
199 item.addActionListener(this);
\r
202 if (aa[selectedRow]==ap.av.consensus)
\r
204 pop.addSeparator();
\r
205 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
\r
206 "Ignore Gaps In Consensus",
\r
207 ap.av.getIgnoreGapsConsensus());
\r
209 cbmi.addItemListener(new ItemListener()
\r
211 public void itemStateChanged(ItemEvent e)
\r
213 ap.av.setIgnoreGapsConsensus(cbmi.getState());
\r
218 final MenuItem cpcons=new MenuItem(COPYCONS_SEQ);
\r
219 cpcons.addActionListener(this);
\r
223 pop.show(this, evt.getX(), evt.getY());
\r
229 * @param e DOCUMENT ME!
\r
231 protected void copy_annotseqtoclipboard(SequenceI sq)
\r
233 if (sq==null || sq.getLength()<1)
\r
235 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
\r
236 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
\r
237 sq.getStart() + "\t" +
\r
238 sq.getEnd() + "\t" +
\r
239 sq.getSequenceAsString() + "\n");
\r
240 if (av.hasHiddenColumns)
\r
242 jalview.appletgui.AlignFrame.copiedHiddenColumns=new Vector();
\r
243 for(int i=0; i<av.getColumnSelection().getHiddenColumns().size(); i++)
\r
245 int[] region = (int[])
\r
246 av.getColumnSelection().getHiddenColumns().elementAt(i);
\r
248 jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]{region[0],
\r
254 public void update(Graphics g)
\r
259 public void paint(Graphics g)
\r
261 int w = getSize().width;
\r
262 if (image == null || w != image.getWidth(this))
\r
264 image = createImage(w, ap.annotationPanel.getSize().height);
\r
267 drawComponent(image.getGraphics(), w);
\r
268 g.drawImage(image,0,0,this);
\r
271 public void drawComponent(Graphics g, int width)
\r
273 g.setFont(av.getFont());
\r
274 FontMetrics fm = g.getFontMetrics(av.getFont());
\r
275 g.setColor(Color.white);
\r
276 g.fillRect(0, 0, getSize().width, getSize().height);
\r
278 g.translate(0, scrollOffset);
\r
279 g.setColor(Color.black);
\r
281 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
282 int y = g.getFont().getSize();
\r
287 for (int i = 0; i < aa.length; i++)
\r
289 if (!aa[i].visible)
\r
294 x = width - fm.stringWidth(aa[i].label) - 3;
\r
298 y += (aa[i].height / 3);
\r
301 g.drawString(aa[i].label, x, y);
\r
305 y += (2 * aa[i].height / 3);
\r