av.sendSelection();
}
+ /**
+ * Action on dragging the mouse in the scale panel is to expand or shrink the
+ * selection group range (including any hidden columns that it spans)
+ *
+ * @param evt
+ */
@Override
public void mouseDragged(MouseEvent evt)
{
mouseDragging = true;
+ ColumnSelection cs = av.getColumnSelection();
int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
- if (res < 0)
- {
- res = 0;
- }
-
- if (av.hasHiddenColumns())
- {
- res = av.getColumnSelection().adjustForHiddenColumns(res);
- }
-
- if (res > av.getAlignment().getWidth())
- {
- res = av.getAlignment().getWidth() - 1;
- }
-
- if (res < min)
- {
- min = res;
- }
-
- if (res > max)
- {
- max = res;
- }
+ res = Math.max(0, res);
+ res = cs.adjustForHiddenColumns(res);
+ res = Math.min(res, av.getAlignment().getWidth() - 1);
+ min = Math.min(res, min);
+ max = Math.max(res, max);
SequenceGroup sg = av.getSelectionGroup();
-
if (sg != null)
{
stretchingGroup = true;
-
- if (!av.getColumnSelection().contains(res))
- {
- av.getColumnSelection().addElement(res);
- }
-
- if (res > sg.getStartRes())
- {
- sg.setEndRes(res);
- }
- if (res < sg.getStartRes())
- {
- sg.setStartRes(res);
- }
-
- int col;
- for (int i = min; i <= max; i++)
- {
- col = av.getColumnSelection().adjustForHiddenColumns(i);
-
- if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
- {
- av.getColumnSelection().removeElement(col);
- }
- else
- {
- av.getColumnSelection().addElement(col);
- }
- }
-
+ cs.stretchGroup(res, sg, min, max);
ap.paintAlignment(false);
}
}
return changed;
}
+ /**
+ * Adjusts column selections, and the given selection group, to match the
+ * range of a stretch (e.g. mouse drag) operation
+ * <p>
+ * Method refactored from ScalePanel.mouseDragged
+ *
+ * @param res
+ * current column position, adjusted for hidden columns
+ * @param sg
+ * current selection group
+ * @param min
+ * start position of the stretch group
+ * @param max
+ * end position of the stretch group
+ */
+ public void stretchGroup(int res, SequenceGroup sg, int min, int max)
+ {
+ if (!contains(res))
+ {
+ addElement(res);
+ }
+
+ if (res > sg.getStartRes())
+ {
+ // expand selection group to the right
+ sg.setEndRes(res);
+ }
+ if (res < sg.getStartRes())
+ {
+ // expand selection group to the left
+ sg.setStartRes(res);
+ }
+
+ /*
+ * expand or shrink column selection to match the
+ * range of the drag operation
+ */
+ for (int col = min; col <= max; col++)
+ {
+ if (col < sg.getStartRes() || col > sg.getEndRes())
+ {
+ // shrinking drag - remove from selection
+ removeElement(col);
+ }
+ else
+ {
+ // expanding drag - add to selection
+ addElement(col);
+ }
+ }
+ }
}
}
/**
- * DOCUMENT ME!
+ * Action on dragging the mouse in the scale panel is to expand or shrink the
+ * selection group range (including any hidden columns that it spans)
*
* @param evt
- * DOCUMENT ME!
*/
@Override
public void mouseDragged(MouseEvent evt)
{
mouseDragging = true;
+ ColumnSelection cs = av.getColumnSelection();
int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
- if (res < 0)
- {
- res = 0;
- }
-
- if (av.hasHiddenColumns())
- {
- res = av.getColumnSelection().adjustForHiddenColumns(res);
- }
-
- if (res >= av.getAlignment().getWidth())
- {
- res = av.getAlignment().getWidth() - 1;
- }
-
- if (res < min)
- {
- min = res;
- }
-
- if (res > max)
- {
- max = res;
- }
+ res = Math.max(0, res);
+ res = cs.adjustForHiddenColumns(res);
+ res = Math.min(res, av.getAlignment().getWidth() - 1);
+ min = Math.min(res, min);
+ max = Math.max(res, max);
SequenceGroup sg = av.getSelectionGroup();
-
if (sg != null)
{
stretchingGroup = true;
-
- if (!av.getColumnSelection().contains(res))
- {
- av.getColumnSelection().addElement(res);
- }
-
- if (res > sg.getStartRes())
- {
- sg.setEndRes(res);
- }
- if (res < sg.getStartRes())
- {
- sg.setStartRes(res);
- }
-
- int col;
- for (int i = min; i <= max; i++)
- {
- col = i; // av.getColumnSelection().adjustForHiddenColumns(i);
-
- if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
- {
- av.getColumnSelection().removeElement(col);
- }
- else
- {
- av.getColumnSelection().addElement(col);
- }
- }
-
+ cs.stretchGroup(res, sg, min, max);
ap.paintAlignment(false);
}
}