From 14bad6b2390493bb6ad030c6f3ea7cde4cba1b53 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 4 Apr 2006 09:32:28 +0000 Subject: [PATCH] Scrolls if dragged off the screen --- src/jalview/gui/AnnotationPanel.java | 95 ++++++++++++++++++++++++++-------- src/jalview/gui/ScalePanel.java | 31 ++++++++--- 2 files changed, 98 insertions(+), 28 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index a10d58b..c5708ee 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -57,6 +57,9 @@ public class AnnotationPanel extends JPanel implements MouseListener, //Used For mouse Dragging and resizing graphs int graphStretch = -1; int graphStretchY = -1; + int min; //used by mouseDragged to see if user + int max; //used by mouseDragged to see if user + boolean mouseDragging = false; /** * Creates a new AnnotationPanel object. @@ -335,34 +338,28 @@ public class AnnotationPanel extends JPanel implements MouseListener, int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - if (evt.isShiftDown()) - { - /*int start = Integer.parseInt(activeRes.get(activeRes.size() - - 1).toString()); - int end = res; - - if (end < start) - { - int temp = end; - end = start; - start = temp; - } + min = res; + max = res; - for (int n = start; n <= end; n++) - { - addEditableColumn(n); - } */ - } + if (av.getColumnSelection().contains(res)) + av.getColumnSelection().removeElement(res); else { - if (av.getColumnSelection().contains(res)) - av.getColumnSelection().removeElement(res); - else av.getColumnSelection().addElement(res); + SequenceGroup sg = new SequenceGroup(); - ap.repaint(); + for (int i = 0; i < av.alignment.getSequences().size(); i++) + { + sg.addSequence(av.alignment.getSequenceAt(i), false); + } + sg.setStartRes(res); + sg.setEndRes(res); + av.setSelectionGroup(sg); } + + ap.repaint(); + } /** @@ -374,6 +371,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, { graphStretch = -1; graphStretchY = -1; + mouseDragging = false; } /** @@ -383,6 +381,8 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void mouseEntered(MouseEvent evt) { + if(mouseDragging) + ap.seqPanel.scrollCanvas(null); } /** @@ -392,8 +392,11 @@ public class AnnotationPanel extends JPanel implements MouseListener, */ public void mouseExited(MouseEvent evt) { + if(mouseDragging) + ap.seqPanel.scrollCanvas(evt); } + /** * DOCUMENT ME! * @@ -410,6 +413,56 @@ public class AnnotationPanel extends JPanel implements MouseListener, adjustPanelHeight(); ap.repaint(); } + else + { + mouseDragging = true; + + int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + + SequenceGroup sg = av.getSelectionGroup(); + + if (res < min) + { + min = res; + } + + if (res > max) + { + max = res; + } + + if (sg != null) + { + if (!av.getColumnSelection().contains(res)) + { + av.getColumnSelection().addElement(res); + } + + if (res > sg.getStartRes()) + { + sg.setEndRes(res); + } + else if (res < sg.getStartRes()) + { + sg.setStartRes(res); + } + + for (int i = min; i <= max; i++) + { + if ((i < sg.getStartRes()) || (i > sg.getEndRes())) + { + av.getColumnSelection().removeElement(i); + } + else + { + av.getColumnSelection().addElement(i); + } + } + + ap.repaint(); + } + + } } /** diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 07be3d0..8f32d8c 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -43,6 +43,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList boolean stretchingGroup = false; int min; //used by mouseDragged to see if user int max; //used by mouseDragged to see if user + boolean mouseDragging = false; // wants to delete columns public ScalePanel(AlignViewport av, AlignmentPanel ap) @@ -72,7 +73,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList min = res; max = res; - if(reveal != null && SwingUtilities.isRightMouseButton(evt)) + /* if(reveal != null && SwingUtilities.isRightMouseButton(evt)) { JPopupMenu pop = new JPopupMenu(); JMenuItem item = new JMenuItem("Reveal"); @@ -109,9 +110,10 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList pop.show(this, evt.getX(), evt.getY()); } - else if (av.getColumnSelection().contains(res)) + else*/ + if (av.getColumnSelection().contains(res)) { - if( SwingUtilities.isRightMouseButton(evt)) + /* if( SwingUtilities.isRightMouseButton(evt)) { JPopupMenu pop = new JPopupMenu(); JMenuItem item = new JMenuItem("Hide Columns"); @@ -129,7 +131,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList pop.show(this, evt.getX(), evt.getY()); } - else + else*/ { av.getColumnSelection().removeElement(res); av.setSelectionGroup(null); @@ -161,6 +163,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList */ public void mouseReleased(MouseEvent evt) { + mouseDragging = false; + int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); if(av.hasHiddenColumns) @@ -195,6 +199,8 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList */ public void mouseDragged(MouseEvent evt) { + mouseDragging = true; + int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); if(av.hasHiddenColumns) @@ -210,6 +216,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList max = res; } + SequenceGroup sg = av.getSelectionGroup(); if (sg != null) @@ -225,7 +232,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList { sg.setEndRes(res); } - else if (res < sg.getStartRes()) + if (res < sg.getStartRes()) { sg.setStartRes(res); } @@ -246,8 +253,18 @@ public class ScalePanel extends JPanel implements MouseMotionListener, MouseList } } - public void mouseEntered(MouseEvent evt){} - public void mouseExited(MouseEvent evt){} + public void mouseEntered(MouseEvent evt) + { + if(mouseDragging) + ap.seqPanel.scrollCanvas(null); + } + + public void mouseExited(MouseEvent evt) + { + if(mouseDragging) + ap.seqPanel.scrollCanvas(evt); + } + public void mouseClicked(MouseEvent evt){} public void mouseMoved(MouseEvent evt) -- 1.7.10.2