Urgent question about the compass

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Guest

Urgent question about the compass

Post by Guest » Wed Jun 09, 2004 3:53 am

who can tell me how to put the root of the pin needle in the centre of the
compass?thanks

Bryan.Scott
Posts: 26
Joined: Fri May 09, 2003 4:55 am
Location: Tasmania, Australia
Contact:

RE: Pin Needle

Post by Bryan.Scott » Wed Jun 09, 2004 5:02 am

In the compass plot as it stands this is not achievable.

There would be two ways of achieve
a) Simply write a new needle
b) Write a new needle which scales and translates an existing needle.

I am just doing a CVS checkout at the moment, and I will see if I can get some code posted shortly

NB. What are you try to do this for?
Bryan

Bryan.Scott
Posts: 26
Joined: Fri May 09, 2003 4:55 am
Location: Tasmania, Australia
Contact:

RE : Pin

Post by Bryan.Scott » Wed Jun 09, 2004 5:31 am

Code: Select all

/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 *
 * --------------
 * PinNeedle.java
 * --------------
 * (C) Copyright 2002, 2003, by the Australian Antarctic Division and Contributors.
 *
 * Original Author:  Bryan Scott (for the Australian Antarctic Division);
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * $Id: MiddlePinNeedle.java,v 1.1 2004/06/09 04:28:44 aadbryanscott Exp $
 *
 * Changes:
 * --------
 * 09-Jun-2004 : Version 1, contributed by Bryan Scott (DG);
 *
 */

package org.jfree.chart.needle;

import java.awt.Graphics2D;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;

/**
 * A needle that is drawn as a pin shape.
 *
 * @author Bryan Scott
 */
public class MiddlePinNeedle extends MeterNeedle implements Serializable {

    /**
     * Draws the needle.
     *
     * @param g2  the graphics device.
     * @param plotArea  the plot area.
     * @param rotate  the rotation point.
     * @param angle  the angle.
     */
    protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

        Area shape;
        GeneralPath pointer = new GeneralPath();

        int minY = (int) (plotArea.getMinY());
        //int maxX = (int) (plotArea.getMaxX());
        int maxY = (int) (plotArea.getMaxY());
        int midY = (int) ((maxY - minY) / 2) + minY ;

        int midX = (int) (plotArea.getMinX() + (plotArea.getWidth() / 2));
        //int midY = (int) (plotArea.getMinY() + (plotArea.getHeight() / 2));
        int lenX = (int) (plotArea.getWidth() / 10);
        if (lenX < 2) {
            lenX = 2;
        }

        pointer.moveTo(midX - lenX, midY - lenX);
        pointer.lineTo(midX + lenX, midY - lenX);
        pointer.lineTo(midX, minY );
        pointer.closePath();

        lenX = 4 * lenX;
        Ellipse2D circle = new Ellipse2D.Double(midX - lenX / 2,
                                                midY - lenX, lenX, lenX);

        shape = new Area(circle);
        shape.add(new Area(pointer));
        if ((rotate != null) && (angle != 0)) {
            /// we have rotation
            getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
            shape.transform(getTransform());
        }

        defaultDisplay(g2, shape);

    }

    /**
     * Tests another object for equality with this object.
     *
     * @param object  the object to test.
     *
     * @return A boolean.
     */
    public boolean equals(Object object) {
        if (object == null) {
            return false;
        }
        if (object == this) {
            return true;
        }
        if (super.equals(object) && object instanceof MiddlePinNeedle) {
            return true;
        }
        return false;
    }

}

Bryan

Guest

Post by Guest » Wed Jun 09, 2004 8:44 am

Thank you ,Bryan!
I'm just trying to put the root of the pin needle in the centre of the
compass and make it go round and round according to it's root.
Your code works well.
I live in Beijing!Welcome to Beijing :D

urmaniac
Posts: 5
Joined: Wed Dec 15, 2004 4:30 am
Contact:

Need help(newbie)

Post by urmaniac » Thu Dec 16, 2004 2:54 am

Sorry if my english is bad..... i got an error when i tried to run the coding, for your information there is no errror during the compilation. This is the error, hope you can help me.....

Exception in thread "main" java.lang.NoClassDefFoundError: MiddlePinNeedle (wron
g name: org/jfree/chart/needle/MiddlePinNeedle)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)



do you have compassdemo2 ? Some of the demos that they were talking about in the forum, i don't have it

Guest

Re: Urgent question about the compass

Post by Guest » Thu Dec 16, 2004 7:36 am

Anonymous wrote:who can tell me how to put the root of the pin needle in the centre of the
compass?thanks
Is it possible to have two needles in the meter grpah. If yes, how can i do it.

thanx in advance

cassidyh
Posts: 10
Joined: Mon Jun 27, 2005 1:19 pm
Location: MD
Contact:

two needles in compass

Post by cassidyh » Tue Jul 19, 2005 12:39 pm

ALl you have to do is declare a new dataset, and than call the plot.

dataset1 = new DefaultValueDataset(new Double(45.0));
dataset2 = new DefaultValueDataset(new Double(60.0));
plot = new CompassPlot();
plot.addData(dataset1) ;
plot.addData(dataset2);

What I don't know is how to change the needle to the middlepoint needle, and how to manipulate the colors of the needle.

Locked