4 import javax.swing.*;
\r
5 import java.awt.event.*;
\r
7 import java.awt.image.*;
\r
8 import jalview.datamodel.*;
\r
10 public class AnnotationLabels extends JPanel implements MouseListener, MouseMotionListener, ActionListener
\r
12 boolean active = false;
\r
15 boolean resizing = false;
\r
17 static String ADDNEW = "Add new row";
\r
18 static String HIDE = "Hide this row";
\r
19 static String DELETE = "Delete this row";
\r
20 static String SHOWALL="Show all hidden rows";
\r
21 int selectedRow = 0;
\r
22 int scrollOffset = 0;
\r
24 public AnnotationLabels(AlignmentPanel ap)
\r
28 java.net.URL url = getClass().getResource("/images/idwidth.gif");
\r
31 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
\r
35 MediaTracker mt = new MediaTracker(this);
\r
36 mt.addImage(temp, 0);
\r
39 catch (Exception ex) {}
\r
41 BufferedImage bi = new BufferedImage(temp.getHeight(this), temp.getWidth(this),
\r
42 BufferedImage.TYPE_INT_RGB);
\r
43 Graphics2D g = (Graphics2D) bi.getGraphics();
\r
44 g.rotate(Math.toRadians(90));
\r
45 g.drawImage(temp, 0, -bi.getWidth(this), this);
\r
48 addMouseListener(this);
\r
49 addMouseMotionListener(this);
\r
52 public void setScrollOffset(int y)
\r
58 public void actionPerformed(ActionEvent evt)
\r
60 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
62 if(evt.getActionCommand().equals(ADDNEW))
\r
64 String label = JOptionPane.showInputDialog(this, "Label for annotation");
\r
67 ap.av.alignment.addAnnotation(new AlignmentAnnotation
\r
70 new Annotation[ap.av.alignment.getWidth()]));
\r
72 else if(evt.getActionCommand().equals(HIDE))
\r
74 aa[selectedRow].visible = false;
\r
76 else if(evt.getActionCommand().equals(DELETE))
\r
78 ap.av.alignment.deleteAnnotation(aa[selectedRow]);
\r
80 else if(evt.getActionCommand().equals(SHOWALL))
\r
82 for(int i=0; i<aa.length; i++)
\r
83 aa[i].visible = true;
\r
86 ap.annotationPanel.adjustPanelHeight();
\r
91 public void mousePressed(MouseEvent evt)
\r
93 int y = evt.getY() - scrollOffset;
\r
95 if (SwingUtilities.isRightMouseButton(evt))
\r
97 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
98 if(aa==null || aa.length==0)
\r
100 JPopupMenu pop = new JPopupMenu("Annotations");
\r
101 JMenuItem item = new JMenuItem(ADDNEW);
\r
102 item.addActionListener(this);
\r
104 pop.show(this, evt.getX(), evt.getY());
\r
109 for (int i = 0; i < aa.length; i++)
\r
114 height += aa[i].height;
\r
122 JPopupMenu pop = new JPopupMenu("Annotations");
\r
123 JMenuItem item = new JMenuItem(ADDNEW);
\r
124 item.addActionListener(this);
\r
126 item = new JMenuItem(HIDE);
\r
127 item.addActionListener(this);
\r
129 item = new JMenuItem(DELETE);
\r
130 item.addActionListener(this);
\r
132 item = new JMenuItem(SHOWALL);
\r
133 item.addActionListener(this);
\r
135 pop.show(this, evt.getX(), evt.getY());
\r
142 public void mouseReleased(MouseEvent evt){ active = false; repaint(); }
\r
143 public void mouseEntered(MouseEvent evt) { active = true; repaint();}
\r
144 public void mouseExited(MouseEvent evt) { active = false; repaint();}
\r
145 public void mouseDragged(MouseEvent evt)
\r
148 Dimension d = ap.annotationScroller.getPreferredSize();
\r
149 int dif = evt.getY() - oldY;
\r
151 dif /= ap.av.charHeight;
\r
152 dif *= ap.av.charHeight;
\r
154 if(d.height-dif>20)
\r
156 ap.annotationScroller.setPreferredSize(new Dimension(d.width,d.height - dif));
\r
157 d = ap.annotationSpaceFillerHolder.getPreferredSize();
\r
158 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(d.width,d.height - dif));
\r
159 ap.RefreshPanels();
\r
164 public void mouseMoved(MouseEvent evt) {}
\r
165 public void mouseClicked(MouseEvent evt) {}
\r
167 public void paintComponent(Graphics g1)
\r
169 Graphics2D g = (Graphics2D)g1;
\r
170 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
\r
175 public void drawComponent(Graphics2D g)
\r
177 FontMetrics fm = g.getFontMetrics(g.getFont());
\r
178 g.setColor(Color.white);
\r
179 g.fillRect(0,0, getWidth(), getHeight());
\r
181 g.translate(0, scrollOffset);
\r
182 g.setColor(Color.black);
\r
184 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
185 int y = g.getFont().getSize();
\r
189 for(int i=0; i<aa.length; i++)
\r
194 x = getWidth() - fm.stringWidth(aa[i].label)-3;
\r
196 g.drawString(aa[i].label, x, y);
\r
204 g.drawImage(image, 2, 0, this);
\r
207 if (aa == null || aa.length<1)
\r
209 g.drawString("Right click", 2, 8);
\r
210 g.drawString("to add annotation", 2, 18);
\r