From 7de411b46c3c042377995234fbaf347df8728882 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 14 Jun 2005 15:03:02 +0000 Subject: [PATCH] mouse pressed moved to mouseclicked --- src/jalview/gui/AnnotationLabels.java | 126 ++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 1b9fd8f..9b9e2db 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -85,21 +85,21 @@ public class AnnotationLabels public void actionPerformed(ActionEvent evt) { + int dif = 0; AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); if (evt.getActionCommand().equals(ADDNEW)) { String label = JOptionPane.showInputDialog(this, "Label for annotation"); - if (label == null) - { label = ""; - } ap.av.alignment.addAnnotation(new AlignmentAnnotation(label, "New description", new Annotation[ap.av.alignment.getWidth()])); + + dif = aa[aa.length-1].height; } else if (evt.getActionCommand().equals(HIDE)) { @@ -119,16 +119,23 @@ public class AnnotationLabels { ap.av.showIdentity = false; } + + dif = aa[selectedRow].height*-1; } else if (evt.getActionCommand().equals(DELETE)) { ap.av.alignment.deleteAnnotation(aa[selectedRow]); + dif = aa[selectedRow].height*-1; } else if (evt.getActionCommand().equals(SHOWALL)) { for (int i = 0; i < aa.length; i++) { - aa[i].visible = true; + if(!aa[i].visible) + { + dif+=aa[i].height; + aa[i].visible = true; + } } } else if (evt.getActionCommand().equals(OUTPUT_TEXT)) @@ -142,63 +149,20 @@ public class AnnotationLabels } ap.annotationPanel.adjustPanelHeight(); - ap.repaint(); - } - - public void mousePressed(MouseEvent evt) - { - int y = evt.getY() - scrollOffset; - - AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); - - if ( (aa == null) || (aa.length == 0)) - { - JPopupMenu pop = new JPopupMenu("Annotations"); - JMenuItem item = new JMenuItem(ADDNEW); - item.addActionListener(this); - pop.add(item); - pop.show(this, evt.getX(), evt.getY()); - - return; - } - - int height = 0; - for (int i = 0; i < aa.length; i++) - { - if (!aa[i].visible) - { - continue; - } - - height += aa[i].height; + Dimension d = ap.annotationScroller.getPreferredSize(); + ap.annotationScroller.setPreferredSize(new Dimension(d.width, d.height+dif)); + d = ap.annotationSpaceFillerHolder.getPreferredSize(); + ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension( + d.width, d.height+dif)); - if (y < height) - { - selectedRow = i; + ap.addNotify(); - break; - } - } - JPopupMenu pop = new JPopupMenu("Annotations"); - JMenuItem item = new JMenuItem(ADDNEW); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(HIDE); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(DELETE); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(SHOWALL); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(OUTPUT_TEXT); - item.addActionListener(this); - pop.add(item); - pop.show(this, evt.getX(), evt.getY()); + } + public void mousePressed(MouseEvent evt) + { oldY = evt.getY(); } @@ -249,6 +213,56 @@ public class AnnotationLabels public void mouseClicked(MouseEvent evt) { + int y = evt.getY() - scrollOffset; + AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); + + if ( (aa == null) || (aa.length == 0)) + { + JPopupMenu pop = new JPopupMenu("Annotations"); + JMenuItem item = new JMenuItem(ADDNEW); + item.addActionListener(this); + pop.add(item); + pop.show(this, evt.getX(), evt.getY()); + + return; + } + + int height = 0; + + for (int i = 0; i < aa.length; i++) + { + if (!aa[i].visible) + { + continue; + } + + height += aa[i].height; + + if (y < height) + { + selectedRow = i; + + break; + } + } + + JPopupMenu pop = new JPopupMenu("Annotations"); + JMenuItem item = new JMenuItem(ADDNEW); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(HIDE); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(DELETE); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(SHOWALL); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(OUTPUT_TEXT); + item.addActionListener(this); + pop.add(item); + pop.show(this, evt.getX(), evt.getY()); } public void paintComponent(Graphics g1) -- 1.7.10.2