All Downloads are FREE. Search and download functionalities are using the official Maven repository.

JSci.swing.JArcDial Maven / Gradle / Ivy

Go to download

JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software. It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ... Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).

The newest version!
package JSci.swing;

import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.util.*;

/** A round dial, where the pointer can rotate many turns; the turns are indicated 
    by digits inside the dial. JPointer s must be added. */
public class JArcDial extends JPanel {

    private double oneTurn;
    private double zero;
    private double startValue;	
    private double endValue;
    private double startAngle = -2*Math.PI/6;
    private double endAngle = 2*Math.PI/6;
    // form of the bounding box
    private double ha;
    private double hb;
    private double va;
    private double vb;
    private double minorTic = 5;
    private double majorTic = 20;
    private boolean setPaintMinorTicks = true;
    private boolean setPaintMajorTicks = true;
    private boolean setPaintLabels = true;
    private double radius = 70;
    private ArrayList pointers = new ArrayList();
    private ChangeListener changeListener = new ChangeListener() {	
	    public void stateChanged(ChangeEvent event) {	
		repaint();
	    }
	};

    /** constructs a dial with no pointers; the pointers will move
     * inside a given range.
     * @param start starting value of the dial
     * @param end end value of the dial 
     */
    public JArcDial(double start,double end) {
	startValue=start;
	endValue=end;
	oneTurn = (endValue-startValue)*2.0*Math.PI/(endAngle-startAngle);
	zero = startAngle-2.0*Math.PI*startValue/oneTurn;
	setArc(-2*Math.PI/6,2*Math.PI/6);
	setSize((int)(2*radius),(int)(2*radius));
	addMouseListener(new TheMouseListener());
	addMouseMotionListener(new TheMouseMotionListener());
    }

    /** Define the positions at which the the dial scale will start and stop.
     * The angles must be such that stop>start.
     * Counter-clockwise dials can be created by inverting the start and stop values
     * (not angles!) in the constructor.
     * @param start the angle (from the top, clockwise, in rads) where the
     *          scale start
     * @param stop  the angle (from the top, clockwise, in rads) where the
     *          scale will end
     */
    public void setArc(double start,double stop) {
	if (start>stop) { throw new IllegalArgumentException("start angle >stop angle"); }
	startAngle = start;
	endAngle = stop;
	oneTurn = (endValue-startValue)*2.0*Math.PI/(endAngle-startAngle);
	zero = startAngle-2.0*Math.PI*startValue/oneTurn;

	double f;

	f=-Math.PI/2+2.0*Math.PI*Math.round(start);
	while (f>start) f-=2.0*Math.PI;while (fstart) f-=2.0*Math.PI;while (fstart) f-=2.0*Math.PI;while (fstart) f-=2.0*Math.PI;while (f=0;j--)
		if (((JPointer)pointers.get(j)).contains(e.getPoint())) {
		    dragged=(JPointer)pointers.get(j);
		    dragDelta=2.0*Math.PI*dragged.getValue()/oneTurn-theta(e);
		    dragged.setAdjusting(true);
		    break;
		}
	}
	public void mouseReleased(MouseEvent e) {
	    if (dragged!=null) dragged.setAdjusting(false);
	    dragged = null;
	    boolean inside = false;
	    for (int j=0;jendAngle) to=endAngle-zero;
		if (zero+to




© 2015 - 2024 Weber Informatics LLC | Privacy Policy