import java.awt.*; /** * A class which shows a piece of a real line for the graphical display * and entry of axis distances. * * @author Jonathan A. Poritz * @version 1.7, 10 Sep 1998 */ public class DistLinePanel extends Plane { /** * A reference to the containing inputpanel. * * @see FDBApplet#inputpanel */ public InputPanel inputpanel; /** * The location of a mousedown in this plane, to compute the extent of * a drag that may occur; in pixel coordinates. */ protected int[] previ = new int[2]; /** * The abstract x-coordinate of the left side of the axis distance display. */ public static final double CX = -1D; /** * The abstract y-coordinate of the upper edge of the axis distance display. */ public static final double CY = 5D; /** * The width, in abstract units, of the axis distance display. */ public static final double SX = 2D; /** * The height, in abstract units, of the axis distance display. */ public static final double SY = 5D; /** * The width, in pixels, of the axis distance display. Good defaults are: * */ public static final int X = 50; /** * The height, in pixels, of the axis distance display. Good defaults are: * */ public static final int Y = 300; /** * Constructor for DistLinePanels. * * @param nptpnl the ambient inputpanel */ public DistLinePanel(InputPanel nptpnl) { // make the basic plane with axes but no xticks super(CX, CY, SX, SY, X, Y); draw_axes = true; show_xticks = false; // save a reference to the inputpanel inputpanel = nptpnl; } /** * Java 1.0 handling of mouseDown events. * * @param e the event to be handled * @param x the x-coordinate (in pixels) of the mouseDown * @param y the y-coordinate (in pixels) of the mouseDown */ public boolean mouseDown(Event e, int x, int y) { // convert to abstract coordinates double xx = (pixelsToAbstract(x, y))[0]; double yy = (pixelsToAbstract(x, y))[1]; // axis distances are non-negative, so if (yy < 0D) yy = 0D; if ((e.modifiers & e.META_MASK) != 0) { // right button: zoom, so save mouse down location previ[0] = x; previ[1] = y; } else if ((yy != 0D) || (inputpanel.trace.y != 0D) || (Math.abs(inputpanel.trace.x) >= 2D)) { // left or middle button AD selection: only make the change if allowed, // i.e., no change of AD if the trace is elliptic or parabolic and the // new selected AD is 0 inputpanel.traceplanepanel.decomposed = false; inputpanel.traceplanepanel.draw_axes= true; inputpanel.traceplanepanel.repaint(); inputpanel.dist = yy; inputpanel.update(); repaint(); } return true; } /** * Java 1.0 handling of mouseDrag events. * * @param e the event to be handled * @param x the x-coordinate (in pixels) of the mouseDrag * @param y the y-coordinate (in pixels) of the mouseDrag */ public boolean mouseDrag(Event e, int x, int y) { // convert to abstract coordinates double xx = (pixelsToAbstract(x, y))[0]; double yy = (pixelsToAbstract(x, y))[1]; // never go negative if (yy < 0D) yy = 0D; if ((e.modifiers & e.META_MASK) != 0) { // right button zoom by amount proportional to the distance from // previous location zoom(1D - ((double)(previ[1] - y)) / 50D); } else if ((yy != 0D) || (inputpanel.trace.y != 0D) || (Math.abs(inputpanel.trace.x) >= 2D)) { // left or middle button AD selection: only make the change if allowed, // i.e., no change of AD if the trace is elliptic or parabolic and the // new selected AD is 0 inputpanel.traceplanepanel.decomposed = false; inputpanel.traceplanepanel.draw_axes = true; inputpanel.traceplanepanel.repaint(); inputpanel.dist = yy; inputpanel.update(); repaint(); } previ[0] = x; previ[1] = y; return true; } /** * Paint the DistLinePanel, by painting the parent Plane, putting a mark * at the currently selected axis distance and making tickmarks. * * @param g the Graphics object upon which to paint the DistLinePanel */ public void paint(Graphics g) { // paint the parent Plane super.paint(g); // draw a small disk on the site of the axis distance g.setColor(Color.black); int[] tp = abstractToPixels(0, inputpanel.dist); g.fillOval(tp[0] - 2, tp[1] - 2, 4, 4); // draw the tickmarks on the y-axis drawTickmarks(g); } /** * Scales the size of the visible window onto the line of axis distances * * @param factor the scaling factor, can be any positive number */ public void zoom(double factor) { corner[0] = corner[0] + .5D * size[0] - .5D * size[0] * factor; size[0] *= factor; corner[1] = corner[1] - size[1] + size[1] * factor; size[1] *= factor; repaint(); } }