Skip to content

Commit

Permalink
ttools: add old-style frame zoom functionality to plot2 windows
Browse files Browse the repository at this point in the history
The PtPlot-style zoom GUI where you drag out a band and on drag
termination the plot is re-drawn to cover the given region is
now added, it uses the middle mouse button (or shift) drag in
plane, time and sky plots.
  • Loading branch information
mbtaylor committed Mar 20, 2014
1 parent ad23f59 commit cfb3c11
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 28 deletions.
44 changes: 43 additions & 1 deletion topcat/src/docs/sun253.xml
Expand Up @@ -6929,6 +6929,14 @@ However, as a rule, the actions when used on the body of the plot are these:
In 3d, the zoom is along the two plot directions most closely
aligned with the plane of the screen.
</p></dd>
<dt>&IMG.DRAG2; Middle drag</dt>
<dd><p>Frame zoom.
Dragging down-and-right drags out a frame;
when the button is released, the plot will be zoomed in
to cover area enclosed by the frame.
Dragging up-and-left does something like the opposite, you can zoom out
using a similar (though not quite the same) mechanism.
</p></dd>
<dt>&IMG.MOUSE_WHEEL; Mouse wheel</dt>
<dd><p>Spinning the mouse wheel forwards/backwards will zoom in/out.
In 2d the zoom is around the current position of the mouse,
Expand Down Expand Up @@ -8908,6 +8916,16 @@ tab of the <ref id="PlaneAxisControl">Axes control</ref>.
To zoom only vertically, drag on the left of the Y axis.
To zoom only horizontally, drag below the X axis.
</p></dd>
<dt>&GESTURE.DRAG2;</dt>
<dd><p><em>Frame zoom.</em>
On the body of the plot, dragging down-and-right drags out a frame;
when the button is released, the plot will be zoomed in
to cover the area enclosed by the frame.
Dragging up-and-left does something like the opposite, you can zoom out
using a similar (though not quite the same) mechanism.
To zoom in/out only vertically, drag down/up on the left of the Y axis.
To zoom in/out only vertically, drag right/left below the X axis.
</p></dd>
<dt>&GESTURE.WHEEL;</dt>
<dd><p><em>Isotropic zoom.</em>
Spinning the mouse wheel forwards/backwards will zoom in/out
Expand Down Expand Up @@ -9179,10 +9197,18 @@ tab of the <ref id="SkyAxisControl">Axes control</ref>.
effect of rotating the sphere to keep North vertical on the screen.
</p></dd>
<dt>&GESTURE.DRAG3;</dt>
<dd><p><em>Zoom.</em>
<dd><p><em>Stretch zoom.</em>
Dragging with the right mouse button up-and-right/down-and-left
has just the same effect as spinning the mouse button forwards/backwards.
</p></dd>
<dt>&GESTURE.DRAG2;</dt>
<dd><p><em>Frame zoom.</em>
Dragging with the middle button down or right drags out a frame;
when the button is released, the plot will be zoomed in
to cover (roughly) the area enclosed by the frame.
Dragging up or left does something like the opposite, you can zoom out
using a similar (though not quite the same) mechanism.
</p></dd>
<dt>&GESTURE.CLICK1;</dt>
<dd><p><em>Select.</em>
If there is a plotted point near the cursor,
Expand Down Expand Up @@ -10016,6 +10042,20 @@ tab of the <ref id="TimeAxisControl">Axes control</ref>.
to be in both directions using the <label>Pan/Zoom Axes</label>
in the <label>Navigation</label> axis configuration tab.
</p></dd>
<dt>&GESTURE.DRAG2;</dt>
<dd><p><em>Frame zoom.</em>
On the body of the plot, dragging right usually drags out a frame;
when the button is released, the plot will be zoomed in
to cover the area enclosed by the frame.
Dragging left does something like the opposite, you can zoom out
using a similar (though not quite the same) mechanism.
By default, vertical zooming is inhibited sine you don't normally
want it for a time plot.
To zoom in/out vertically, drag down/up on the left of the Y axis.
It is also possible to configure zooming on the body of the plot
to be in both directions using the <label>Pan/Zoom Axes</label>
in the <label>Navigation</label> axis configuration tab.
</p></dd>
<dt>&GESTURE.WHEEL;</dt>
<dd><p><em>Zoom.</em>
Spinning the mouse wheel forwards/backwards will zoom in/out
Expand Down Expand Up @@ -19936,6 +19976,8 @@ introduced since the last version:
in the (now possibly misnamed) "Text Syntax" item
in Font configuration. This now affects the Aux axis and Legend
labelling as well as the grid labelling.</li>
<li>Add old-style frame zooming on new-style plots using middle button
(or shift) drag.</li>
</ul>
</p></dd>

Expand Down
Expand Up @@ -150,9 +150,33 @@ public void mouseDragged( MouseEvent evt ) {

public void mouseReleased( MouseEvent evt ) {

/* Eliminate any drag decoration. */
/* Handle the end of a drag action, if one is pending. */
if ( dragSurface_ != null ) {
updateDecoration( null, false );

/* Pass on the endDrag action, if appropriate. */
Navigator<A> navigator = getNavigator();
final NavAction<A> navact;
if ( navigator != null ) {
Point pos = evt.getPoint();
int ibutt = PlotUtil.getButtonChangedIndex( evt );
navact =
navigator.endDrag( dragSurface_, pos, ibutt, startPoint_ );
}
else {
navact = null;
}
Decoration dec = navact == null ? null : navact.getDecoration();

/* Eliminate any decorations associated with a current drag. */
updateDecoration( dec, false );

/* Update aspect if the endDrag produced a new one. */
if ( navact != null ) {
A aspect = navact.getAspect();
if ( aspect != null ) {
setAspect( aspect );
}
}
}

/* Terminate any current drag gesture. */
Expand Down
14 changes: 14 additions & 0 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/Navigator.java
Expand Up @@ -36,6 +36,20 @@ public interface Navigator<A> {
*/
NavAction<A> drag( Surface surface, Point pos, int ibutton, Point origin );

/**
* Terminating drag gesture. This method is invoked following a sequence
* of drags when the mouse button has been released.
*
* @param surface initial plot surface
* @param pos current mouse position
* @param ibutton logical mouse button index of terminated drag
* @param origin starting point of drag gesture
* @return navigation action indicated by the gesture,
* or null for no change
*/
NavAction<A> endDrag( Surface surface, Point pos, int ibutton,
Point origin );

/**
* Mouse wheel gesture.
*
Expand Down
@@ -0,0 +1,46 @@
package uk.ac.starlink.ttools.plot2.geom;

import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.Icon;
import uk.ac.starlink.ttools.plot2.Decoration;

/**
* Decoration subclass that also provides a target rectangle.
* This target indicates a graphics surface region to which zooming
* is intended.
*
* <p>Note that the target rectangle is not assessed as part of the
* equality conditions for this object; it is considered to be
* an annotation of the icon, completely determined by its existing
* characteristics.
*
* @author Mark Taylor
* @since 18 Mar 2014
*/
public class BandDecoration extends Decoration {

private final Rectangle targetRect_;

/**
* Constructor.
*
* @param icon decoration content; this icon must have equality semantics
* @param gx x position for icon
* @param gy y position for icon
* @param targetRect target rectangle
*/
public BandDecoration( Icon icon, int gx, int gy, Rectangle targetRect ) {
super( icon, gx, gy );
targetRect_ = targetRect;
}

/**
* Returns the target rectangle for this object.
*
* @return target rectangle
*/
public Rectangle getTargetRectangle() {
return targetRect_;
}
}
Expand Up @@ -86,6 +86,11 @@ else if ( ibutt == 3 ) {
}
}

public NavAction<CubeAspect> endDrag( Surface surface, Point pos,
int ibutt, Point origin ) {
return null;
}

public NavAction<CubeAspect> wheel( Surface surface, Point pos,
int wheelrot ) {
final boolean xZoom;
Expand Down

0 comments on commit cfb3c11

Please sign in to comment.