2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
24 import java.awt.event.*;
\r
25 import java.awt.image.*;
\r
27 import javax.swing.*;
\r
34 * @version $Revision$
\r
36 public class AnnotationLabels extends JPanel implements MouseListener,
\r
37 MouseMotionListener, ActionListener
\r
39 static String ADDNEW = "Add New Row";
\r
40 static String HIDE = "Hide This Row";
\r
41 static String DELETE = "Delete This Row";
\r
42 static String SHOWALL = "Show All Hidden Rows";
\r
43 static String OUTPUT_TEXT = "Show Values In Textbox";
\r
44 boolean active = false;
\r
47 boolean resizing = false;
\r
50 int selectedRow = 0;
\r
51 int scrollOffset = 0;
\r
54 * Creates a new AnnotationLabels object.
\r
56 * @param ap DOCUMENT ME!
\r
58 public AnnotationLabels(AlignmentPanel ap)
\r
62 java.net.URL url = getClass().getResource("/images/idwidth.gif");
\r
67 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
72 MediaTracker mt = new MediaTracker(this);
\r
73 mt.addImage(temp, 0);
\r
76 catch (Exception ex)
\r
80 BufferedImage bi = new BufferedImage(temp.getHeight(this),
\r
81 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
\r
82 Graphics2D g = (Graphics2D) bi.getGraphics();
\r
83 g.rotate(Math.toRadians(90));
\r
84 g.drawImage(temp, 0, -bi.getWidth(this), this);
\r
87 addMouseListener(this);
\r
88 addMouseMotionListener(this);
\r
94 * @param y DOCUMENT ME!
\r
96 public void setScrollOffset(int y)
\r
105 * @param evt DOCUMENT ME!
\r
107 public void actionPerformed(ActionEvent evt)
\r
110 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
112 if (evt.getActionCommand().equals(ADDNEW))
\r
114 String label = JOptionPane.showInputDialog(this,
\r
115 "Label for annotation");
\r
122 ap.av.alignment.addAnnotation(new AlignmentAnnotation(label,
\r
124 new Annotation[ap.av.alignment.getWidth()]));
\r
126 dif = aa[aa.length - 1].height;
\r
128 else if (evt.getActionCommand().equals(HIDE))
\r
130 aa[selectedRow].visible = false;
\r
132 if (aa[selectedRow].label.equals("Conservation"))
\r
134 ap.av.showConservation = false;
\r
137 if (aa[selectedRow].label.equals("Quality"))
\r
139 ap.av.showQuality = false;
\r
142 if (aa[selectedRow].label.equals("Consensus"))
\r
144 ap.av.showIdentity = false;
\r
147 dif = aa[selectedRow].height * -1;
\r
149 else if (evt.getActionCommand().equals(DELETE))
\r
151 ap.av.alignment.deleteAnnotation(aa[selectedRow]);
\r
152 dif = aa[selectedRow].height * -1;
\r
154 else if (evt.getActionCommand().equals(SHOWALL))
\r
156 for (int i = 0; i < aa.length; i++)
\r
158 if (!aa[i].visible)
\r
160 dif += aa[i].height;
\r
161 aa[i].visible = true;
\r
165 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
\r
167 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
168 Desktop.addInternalFrame(cap,
\r
169 ap.alignFrame.getTitle() + " - " + aa[selectedRow].label, 500,
\r
171 cap.setText(aa[selectedRow].toString());
\r
174 ap.annotationPanel.adjustPanelHeight();
\r
176 Dimension d = ap.annotationScroller.getPreferredSize();
\r
177 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
\r
179 d = ap.annotationSpaceFillerHolder.getPreferredSize();
\r
180 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(d.width,
\r
189 * @param evt DOCUMENT ME!
\r
191 public void mousePressed(MouseEvent evt)
\r
199 * @param evt DOCUMENT ME!
\r
201 public void mouseReleased(MouseEvent evt)
\r
210 * @param evt DOCUMENT ME!
\r
212 public void mouseEntered(MouseEvent evt)
\r
221 * @param evt DOCUMENT ME!
\r
223 public void mouseExited(MouseEvent evt)
\r
232 * @param evt DOCUMENT ME!
\r
234 public void mouseDragged(MouseEvent evt)
\r
238 Dimension d = ap.annotationScroller.getPreferredSize();
\r
239 int dif = evt.getY() - oldY;
\r
241 dif /= ap.av.charHeight;
\r
242 dif *= ap.av.charHeight;
\r
244 if ((d.height - dif) > 20)
\r
246 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
\r
248 d = ap.annotationSpaceFillerHolder.getPreferredSize();
\r
249 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
\r
250 d.width, d.height - dif));
\r
260 * @param evt DOCUMENT ME!
\r
262 public void mouseMoved(MouseEvent evt)
\r
269 * @param evt DOCUMENT ME!
\r
271 public void mouseClicked(MouseEvent evt)
\r
273 int y = evt.getY() - scrollOffset;
\r
274 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
276 if ((aa == null) || (aa.length == 0))
\r
278 JPopupMenu pop = new JPopupMenu("Annotations");
\r
279 JMenuItem item = new JMenuItem(ADDNEW);
\r
280 item.addActionListener(this);
\r
282 pop.show(this, evt.getX(), evt.getY());
\r
289 for (int i = 0; i < aa.length; i++)
\r
291 if (!aa[i].visible)
\r
296 height += aa[i].height;
\r
306 JPopupMenu pop = new JPopupMenu("Annotations");
\r
307 JMenuItem item = new JMenuItem(ADDNEW);
\r
308 item.addActionListener(this);
\r
310 item = new JMenuItem(HIDE);
\r
311 item.addActionListener(this);
\r
313 item = new JMenuItem(DELETE);
\r
314 item.addActionListener(this);
\r
316 item = new JMenuItem(SHOWALL);
\r
317 item.addActionListener(this);
\r
319 item = new JMenuItem(OUTPUT_TEXT);
\r
320 item.addActionListener(this);
\r
322 pop.show(this, evt.getX(), evt.getY());
\r
328 * @param g1 DOCUMENT ME!
\r
330 public void paintComponent(Graphics g1)
\r
332 Graphics2D g = (Graphics2D) g1;
\r
333 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
334 RenderingHints.VALUE_ANTIALIAS_ON);
\r
342 * @param g DOCUMENT ME!
\r
344 public void drawComponent(Graphics2D g)
\r
346 FontMetrics fm = g.getFontMetrics(g.getFont());
\r
347 g.setColor(Color.white);
\r
348 g.fillRect(0, 0, getWidth(), getHeight());
\r
350 g.translate(0, scrollOffset);
\r
351 g.setColor(Color.black);
\r
353 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
354 int y = g.getFont().getSize();
\r
356 int width = getWidth();
\r
358 width = ap.calculateIdWidth().width + 4;
\r
362 for (int i = 0; i < aa.length; i++)
\r
364 if (!aa[i].visible)
\r
369 x = width - fm.stringWidth(aa[i].label) - 3;
\r
373 y += (aa[i].height / 3);
\r
376 g.drawString(aa[i].label, x, y);
\r
380 y += ((2 * aa[i].height) / 3);
\r
393 g.drawImage(image, 2, 0, this);
\r
397 if ((aa == null) || (aa.length < 1))
\r
399 g.drawString("Right click", 2, 8);
\r
400 g.drawString("to add annotation", 2, 18);
\r