3 * Jalview - A Sequence Alignment Editor and Viewer
\r
4 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
11 * This program is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program; if not, write to the Free Software
\r
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
21 package jalview.gui;
\r
23 import javax.swing.*;
\r
24 import java.awt.event.*;
\r
26 import java.awt.image.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.io.FormatAdapter;
\r
30 public class AnnotationLabels extends JPanel implements MouseListener, MouseMotionListener, ActionListener
\r
32 boolean active = false;
\r
35 boolean resizing = false;
\r
37 static String ADDNEW = "Add New Row";
\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 int selectedRow = 0;
\r
43 int scrollOffset = 0;
\r
45 public AnnotationLabels(AlignmentPanel ap)
\r
49 java.net.URL url = getClass().getResource("/images/idwidth.gif");
\r
52 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
56 MediaTracker mt = new MediaTracker(this);
\r
57 mt.addImage(temp, 0);
\r
60 catch (Exception ex) {}
\r
62 BufferedImage bi = new BufferedImage(temp.getHeight(this), temp.getWidth(this),
\r
63 BufferedImage.TYPE_INT_RGB);
\r
64 Graphics2D g = (Graphics2D) bi.getGraphics();
\r
65 g.rotate(Math.toRadians(90));
\r
66 g.drawImage(temp, 0, -bi.getWidth(this), this);
\r
69 addMouseListener(this);
\r
70 addMouseMotionListener(this);
\r
73 public void setScrollOffset(int y)
\r
79 public void actionPerformed(ActionEvent evt)
\r
81 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
83 if(evt.getActionCommand().equals(ADDNEW))
\r
85 String label = JOptionPane.showInputDialog(this, "Label for annotation");
\r
88 ap.av.alignment.addAnnotation(new AlignmentAnnotation
\r
91 new Annotation[ap.av.alignment.getWidth()]));
\r
93 else if(evt.getActionCommand().equals(HIDE))
\r
95 aa[selectedRow].visible = false;
\r
96 if(aa[selectedRow].label.equals("Conservation"))
\r
97 ap.av.showConservation = false;
\r
98 if(aa[selectedRow].label.equals("Quality"))
\r
99 ap.av.showQuality = false;
\r
100 if(aa[selectedRow].label.equals("Consensus"))
\r
101 ap.av.showIdentity = false;
\r
103 else if(evt.getActionCommand().equals(DELETE))
\r
105 ap.av.alignment.deleteAnnotation(aa[selectedRow]);
\r
107 else if(evt.getActionCommand().equals(SHOWALL))
\r
109 for(int i=0; i<aa.length; i++)
\r
110 aa[i].visible = true;
\r
112 else if(evt.getActionCommand().equals(OUTPUT_TEXT))
\r
114 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
115 Desktop.addInternalFrame(cap, ap.alignFrame.getTitle()+" - "+ aa[selectedRow].label, 500, 100);
\r
116 cap.setText( aa[selectedRow].toString() );
\r
119 ap.annotationPanel.adjustPanelHeight();
\r
124 public void mousePressed(MouseEvent evt)
\r
126 int y = evt.getY() - scrollOffset;
\r
128 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
129 if(aa==null || aa.length==0)
\r
131 JPopupMenu pop = new JPopupMenu("Annotations");
\r
132 JMenuItem item = new JMenuItem(ADDNEW);
\r
133 item.addActionListener(this);
\r
135 pop.show(this, evt.getX(), evt.getY());
\r
140 for (int i = 0; i < aa.length; i++)
\r
145 height += aa[i].height;
\r
153 JPopupMenu pop = new JPopupMenu("Annotations");
\r
154 JMenuItem item = new JMenuItem(ADDNEW);
\r
155 item.addActionListener(this);
\r
157 item = new JMenuItem(HIDE);
\r
158 item.addActionListener(this);
\r
160 item = new JMenuItem(DELETE);
\r
161 item.addActionListener(this);
\r
163 item = new JMenuItem(SHOWALL);
\r
164 item.addActionListener(this);
\r
166 item = new JMenuItem(OUTPUT_TEXT);
\r
167 item.addActionListener(this);
\r
169 pop.show(this, evt.getX(), evt.getY());
\r
174 public void mouseReleased(MouseEvent evt){ active = false; repaint(); }
\r
175 public void mouseEntered(MouseEvent evt) { active = true; repaint();}
\r
176 public void mouseExited(MouseEvent evt) { active = false; repaint();}
\r
177 public void mouseDragged(MouseEvent evt)
\r
180 Dimension d = ap.annotationScroller.getPreferredSize();
\r
181 int dif = evt.getY() - oldY;
\r
183 dif /= ap.av.charHeight;
\r
184 dif *= ap.av.charHeight;
\r
186 if(d.height-dif>20)
\r
188 ap.annotationScroller.setPreferredSize(new Dimension(d.width,d.height - dif));
\r
189 d = ap.annotationSpaceFillerHolder.getPreferredSize();
\r
190 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(d.width,d.height - dif));
\r
196 public void mouseMoved(MouseEvent evt) {}
\r
197 public void mouseClicked(MouseEvent evt) {}
\r
199 public void paintComponent(Graphics g1)
\r
201 Graphics2D g = (Graphics2D)g1;
\r
202 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
\r
207 public void drawComponent(Graphics2D g)
\r
209 FontMetrics fm = g.getFontMetrics(g.getFont());
\r
210 g.setColor(Color.white);
\r
211 g.fillRect(0,0, getWidth(), getHeight());
\r
213 g.translate(0, scrollOffset);
\r
214 g.setColor(Color.black);
\r
216 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
217 int y = g.getFont().getSize();
\r
221 for(int i=0; i<aa.length; i++)
\r
226 x = getWidth() - fm.stringWidth(aa[i].label)-3;
\r
229 y+=(aa[i].height/3);
\r
231 g.drawString(aa[i].label, x, y);
\r
234 y+=(2*aa[i].height/3);
\r
242 g.drawImage(image, 2, 0, this);
\r
245 if (aa == null || aa.length<1)
\r
247 g.drawString("Right click", 2, 8);
\r
248 g.drawString("to add annotation", 2, 18);
\r