From 0d326d33340305d0eaa539cbf903f778001ebeb7 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 20 Oct 2022 10:49:21 +0100 Subject: [PATCH] JAL-2349 debugged click/drag and added yellow rubber banding (like Alphafold) --- src/jalview/gui/AnnotationPanel.java | 69 ++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index ba02a3f..ccc086c 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -56,6 +56,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.datamodel.ContactListI; +import jalview.datamodel.ContactRange; import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import jalview.gui.JalviewColourChooser.ColourChooserListener; @@ -584,25 +585,35 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (graphStretch != -1) { + if (aa[graphStretch].graph == AlignmentAnnotation.CUSTOMRENDERER) { - int currentX = getColumnForXPos(evt.getX()); - ContactListI forCurrentX = av.getContactList(aa[graphStretch], - currentX); - if (forCurrentX != null) + if (evt.isAltDown() || evt.isAltGraphDown()) + { + dragMode = DragMode.MatrixSelect; + firstDragX = mouseDragLastX; + firstDragY = mouseDragLastY; + } + else { - ContactGeometry cXcgeom = new ContactGeometry(forCurrentX, - aa[graphStretch].graphHeight); - ContactGeometry.contactInterval cXci = cXcgeom.mapFor(yOffset, - yOffset); - int fr, to; - fr = Math.min(cXci.cStart, cXci.cEnd); - to = Math.max(cXci.cStart, cXci.cEnd); - for (int c = fr; c <= to; c++) + int currentX = getColumnForXPos(evt.getX()); + ContactListI forCurrentX = av.getContactList(aa[graphStretch], + currentX); + if (forCurrentX != null) { - av.getColumnSelection().addElement(c); + ContactGeometry cXcgeom = new ContactGeometry(forCurrentX, + aa[graphStretch].graphHeight); + ContactGeometry.contactInterval cXci = cXcgeom.mapFor(yOffset, + yOffset); + int fr, to; + fr = Math.min(cXci.cStart, cXci.cEnd); + to = Math.max(cXci.cStart, cXci.cEnd); + for (int c = fr; c <= to; c++) + { + av.getColumnSelection().addElement(c); + } + av.getColumnSelection().addElement(currentX); } - av.getColumnSelection().addElement(currentX); } } } @@ -676,6 +687,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, graphStretch = -1; mouseDragLastX = -1; mouseDragLastY = -1; + firstDragX = -1; + firstDragY = -1; mouseDragging = false; if (dragMode == DragMode.Resize) { @@ -813,6 +826,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, /* * TODO draw a rubber band for range */ + mouseDragLastX = x; + mouseDragLastY = y; + ap.paintAlignment(false, false); } else { @@ -835,11 +851,23 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, * get geometry of drag */ int fromY = Math.min(firstDragY, evt.getY()); - int deltaY = Math.abs(firstDragY - evt.getY()); int toY = Math.max(firstDragY, evt.getY()); + int deltaY = toY - fromY; int[] rowIndex = getRowIndexAndOffset(fromY, av.getAlignment().getAlignmentAnnotation()); + int[] toRowIndex = getRowIndexAndOffset(toY, + av.getAlignment().getAlignmentAnnotation()); + + if (rowIndex == null || toRowIndex == null) + { + System.out.println("Drag out of range. needs to be clipped"); + + } + if (rowIndex[0] != toRowIndex[0]) + { + System.out.println("Drag went to another row. needs to be clipped"); + } // rectangular selection on matrix style annotation AlignmentAnnotation cma = av.getAlignment() @@ -1408,6 +1436,17 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { fadedImage = oldFaded; } + if (dragMode == DragMode.MatrixSelect) + { + g.setColor(Color.yellow); + g.drawRect(Math.min(firstDragX, mouseDragLastX), + Math.min(firstDragY, mouseDragLastY), + Math.max(firstDragX, mouseDragLastX) + - Math.min(firstDragX, mouseDragLastX), + Math.max(firstDragY, mouseDragLastY) + - Math.min(firstDragY, mouseDragLastY)); + + } } @Override -- 1.7.10.2