import jalview.datamodel.*;\r
\r
public class AnnotationPanel\r
- extends Panel implements AdjustmentListener\r
+ extends Panel\r
+ implements AdjustmentListener, ActionListener, MouseListener, MouseMotionListener\r
{\r
AlignViewport av;\r
AlignmentPanel ap;\r
setLayout(null);\r
adjustPanelHeight();\r
\r
- addMouseMotionListener(new MouseMotionAdapter()\r
- {\r
- public void mouseMoved(MouseEvent evt)\r
- {\r
- doMouseMoved(evt);\r
- }\r
- });\r
+ addMouseMotionListener(this);\r
+\r
+ addMouseListener(this);\r
+\r
\r
// ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );\r
}\r
ap.alabels.setScrollOffset( -evt.getValue());\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void actionPerformed(ActionEvent evt)\r
+ {\r
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
+ Annotation[] anot = aa[activeRow].annotations;\r
+\r
+ if (anot.length < av.getColumnSelection().getMax())\r
+ {\r
+ Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];\r
+ System.arraycopy(anot, 0, temp, 0, anot.length);\r
+ anot = temp;\r
+ aa[activeRow].annotations = anot;\r
+ }\r
+\r
+ String label = "";\r
+ if (av.colSel != null && av.colSel.size() > 0\r
+ && anot[av.colSel.getMin()] != null)\r
+ label = anot[av.getColumnSelection().getMin()].displayCharacter;\r
+\r
+\r
+ if (evt.getActionCommand().equals(REMOVE))\r
+ {\r
+ for (int i = 0; i < av.getColumnSelection().size(); i++)\r
+ {\r
+ anot[av.getColumnSelection().columnAt(i)] = null;\r
+ }\r
+ }\r
+ else if (evt.getActionCommand().equals(LABEL))\r
+ {\r
+ label = enterLabel(label, "Enter Label");\r
+\r
+ if (label == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ if ( (label.length() > 0) && !aa[activeRow].hasText)\r
+ {\r
+ aa[activeRow].hasText = true;\r
+ }\r
+\r
+ for (int i = 0; i < av.getColumnSelection().size(); i++)\r
+ {\r
+ int index = av.getColumnSelection().columnAt(i);\r
+\r
+ if(!av.colSel.isVisible(index))\r
+ continue;\r
+\r
+ if (anot[index] == null)\r
+ {\r
+ anot[index] = new Annotation(label, "", ' ', 0);\r
+ }\r
+\r
+ anot[index].displayCharacter = label;\r
+ }\r
+ }\r
+ else if (evt.getActionCommand().equals(COLOUR))\r
+ {\r
+ UserDefinedColours udc = new UserDefinedColours(\r
+ this,\r
+ Color.black, ap.alignFrame);\r
+\r
+ Color col = udc.getColor();\r
+\r
+ for (int i = 0; i < av.getColumnSelection().size(); i++)\r
+ {\r
+ int index = av.getColumnSelection().columnAt(i);\r
+\r
+ if(!av.colSel.isVisible(index))\r
+ continue;\r
+\r
+ if (anot[index] == null)\r
+ {\r
+ anot[index] = new Annotation("", "", ' ', 0);\r
+ }\r
+\r
+ anot[index].colour = col;\r
+ }\r
+ }\r
+ else // HELIX OR SHEET\r
+ {\r
+ char type = 0;\r
+ String symbol = "\u03B1";\r
+\r
+ if (evt.getActionCommand().equals(HELIX))\r
+ {\r
+ type = 'H';\r
+ }\r
+ else if (evt.getActionCommand().equals(SHEET))\r
+ {\r
+ type = 'E';\r
+ symbol = "\u03B2";\r
+ }\r
+\r
+ if (!aa[activeRow].hasIcons)\r
+ {\r
+ aa[activeRow].hasIcons = true;\r
+ }\r
+\r
+ label = enterLabel(symbol, "Enter Label");\r
+\r
+ if (label == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ if ( (label.length() > 0) && !aa[activeRow].hasText)\r
+ {\r
+ aa[activeRow].hasText = true;\r
+ }\r
+\r
+ for (int i = 0; i < av.getColumnSelection().size(); i++)\r
+ {\r
+ int index = av.getColumnSelection().columnAt(i);\r
+\r
+ if(!av.colSel.isVisible(index))\r
+ continue;\r
+\r
+ if (anot[index] == null)\r
+ {\r
+ anot[index] = new Annotation(label, "", type, 0);\r
+ }\r
+\r
+ anot[index].secondaryStructure = type;\r
+ anot[index].displayCharacter = label;\r
+ }\r
+ }\r
+\r
+ adjustPanelHeight();\r
+ repaint();\r
+\r
+ return;\r
+ }\r
+\r
+ String enterLabel(String text, String label)\r
+ {\r
+ EditNameDialog dialog = new EditNameDialog(text,null,label,null,\r
+ ap.alignFrame,"Enter Label", 400,200);\r
+\r
+ if(dialog.accept)\r
+ return dialog.getName();\r
+ else\r
+ return null;\r
+ }\r
+\r
+ public void mousePressed(MouseEvent evt)\r
+ {\r
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
+ if (aa == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ int height = 0;\r
+ activeRow = -1;\r
+\r
+\r
+ for (int i = 0; i < aa.length; i++)\r
+ {\r
+ if (aa[i].visible)\r
+ {\r
+ height += aa[i].height;\r
+ }\r
+\r
+ if (evt.getY() < height)\r
+ {\r
+ if (aa[i].editable)\r
+ {\r
+ activeRow = i;\r
+ }\r
+\r
+ break;\r
+ }\r
+ }\r
+\r
+ if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) ==\r
+ InputEvent.BUTTON3_MASK && activeRow != -1)\r
+ {\r
+ if (av.getColumnSelection() == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ PopupMenu pop = new PopupMenu("Structure type");\r
+ MenuItem item = new MenuItem(HELIX);\r
+ item.addActionListener(this);\r
+ pop.add(item);\r
+ item = new MenuItem(SHEET);\r
+ item.addActionListener(this);\r
+ pop.add(item);\r
+ item = new MenuItem(LABEL);\r
+ item.addActionListener(this);\r
+ pop.add(item);\r
+ item = new MenuItem(COLOUR);\r
+ item.addActionListener(this);\r
+ pop.add(item);\r
+ item = new MenuItem(REMOVE);\r
+ item.addActionListener(this);\r
+ pop.add(item);\r
+ ap.alignFrame.add(pop);\r
+ pop.show(this, evt.getX(), evt.getY());\r
+\r
+ return;\r
+ }\r
+\r
+ if (aa == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ ap.scalePanel.mousePressed(evt);\r
+ }\r
+\r
+ public void mouseReleased(MouseEvent evt)\r
+ {\r
+ ap.scalePanel.mouseReleased(evt);\r
+ }\r
+\r
+ public void mouseClicked(MouseEvent evt)\r
+ {}\r
+\r
+ public void mouseDragged(MouseEvent evt)\r
+ {\r
+ ap.scalePanel.mouseDragged(evt);\r
+ }\r
+\r
+ public void mouseMoved(MouseEvent evt)\r
+ {\r
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
+ if (aa == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ int row = -1;\r
+ int height = 0;\r
+ for (int i = 0; i < aa.length; i++)\r
+ {\r
+\r
+ if (aa[i].visible)\r
+ {\r
+ height += aa[i].height;\r
+ }\r
+\r
+ if (evt.getY() < height)\r
+ {\r
+ row = i;\r
+ break;\r
+ }\r
+ }\r
+\r
+ int res = evt.getX() / av.getCharWidth() + av.getStartRes();\r
+\r
+ if (av.hasHiddenColumns)\r
+ {\r
+ res = av.getColumnSelection().adjustForHiddenColumns(res);\r
+ }\r
+\r
+ if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)\r
+ {\r
+ StringBuffer text = new StringBuffer("Sequence position " + (res + 1));\r
+ if (aa[row].annotations[res].description != null)\r
+ {\r
+ text.append(" " + aa[row].annotations[res].description);\r
+ }\r
+ ap.alignFrame.statusBar.setText(text.toString());\r
+ }\r
+ }\r
+ public void mouseEntered(MouseEvent evt)\r
+ {\r
+ ap.scalePanel.mouseEntered(evt);\r
+ }\r
+ public void mouseExited(MouseEvent evt)\r
+ {\r
+ ap.scalePanel.mouseExited(evt);\r
+ }\r
+\r
+\r
public int adjustPanelHeight()\r
{\r
// setHeight of panels\r
activeRes.addElement(String.valueOf(i));\r
}\r
\r
- public void doMouseMoved(MouseEvent evt)\r
- {\r
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
- if (aa == null)\r
- {\r
- return;\r
- }\r
-\r
- int row = -1;\r
- int height = 0;\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
-\r
- if (aa[i].visible)\r
- {\r
- height += aa[i].height;\r
- }\r
-\r
- if (evt.getY() < height)\r
- {\r
- row = i;\r
- break;\r
- }\r
- }\r
-\r
- int res = evt.getX() / av.getCharWidth() + av.getStartRes();\r
-\r
- if (av.hasHiddenColumns)\r
- {\r
- res = av.getColumnSelection().adjustForHiddenColumns(res);\r
- }\r
-\r
- if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)\r
- {\r
- StringBuffer text = new StringBuffer("Sequence position " + (res + 1));\r
- if (aa[row].annotations[res].description != null)\r
- {\r
- text.append(" " + aa[row].annotations[res].description);\r
- }\r
- ap.alignFrame.statusBar.setText(text.toString());\r
- }\r
- }\r
\r
public void update(Graphics g)\r
{\r
validRes = true;\r
}\r
\r
+ if (activeRow == i)\r
+ {\r
+ g.setColor(Color.red);\r
+\r
+ if (av.getColumnSelection() != null)\r
+ {\r
+ for (int n = 0; n < av.getColumnSelection().size(); n++)\r
+ {\r
+ int v = av.getColumnSelection().columnAt(n);\r
+\r
+ if (v == column)\r
+ {\r
+ g.fillRect(x * av.charWidth, y,\r
+ av.charWidth, av.charHeight);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+\r
if (av.validCharWidth && validRes &&\r
(row.annotations[column].displayCharacter.length() > 0))\r
{\r