/*

 * Title: japlot.jaxodraw
 * Description: Graphical user interface for drawing Feynman diagrams
 * @author Daniele Binosi 
 * @author Lukas Theussl  

 Copyright (C) 2003-2006,  Daniele Binosi and Lukas Theussl

 See the file LICENSE in the source distribution home directory
 for a full copy of the GPL (GNU General Public License).

    This file is part of japlot.jaxodraw.

    japlot.jaxodraw is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    japlot.jaxodraw 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


 */
package jhplot.jadraw;


import japlot.jaxodraw.JaxoColor;
import japlot.jaxodraw.JaxoVertexT2OptionsPanel;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import org.freehep.graphics2d.VectorGraphics;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;



/** A vertex type 2 object (a cross with a circle). */
public class JaVertexT2 extends JaVertex {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/** The rotation angle of the Vertex */
    private int rotAngle;

    /** The fill color of this fillObject. */
    private Color fillcolor;

    /** Constructor: sets the width, height, relative width and height to a
     *  default value of 3 and initializes the firsttime variable to true.
     */
    public JaVertexT2() {
        super();
        setRotAngle(0);
    }

    // Bean getter and setter methods

    /** Returns the rotation angle of this vertex.
     * @return The rotation angle of this vertex.
     */
    public final int getRotAngle() {
        return rotAngle;
    }

    /** Sets the rotation angle of this vertex.
     * @param angle The rotation angle of this vertex.
     */
    public final void setRotAngle(int angle) {
        this.rotAngle = angle;
    }

    /** Returns the fill color of the fillColor object.
     * @return The fill color of this fillColor object.
     */
    public final Color getFillColor() {
        return fillcolor;
    }

    /** Sets the fill color of this fillColor object.
     * @param color The color to be set as fill color.
     */
    public final void setFillColor(Color color) {
        this.fillcolor = color;
    }

    /** Returns an exact copy of this JaVertexT1.
     * @return A copy of this JaVertexT1.
     */
    public final JaObject copy() {
        JaVertexT2 temp = (JaVertexT2) copy(new JaVertexT2());
        temp.setFillColor(getFillColor());

        return temp;
    }

    /** Returns true if all serializable variables of this JaObject
     *  and those of the specified one are equal.
     * @param comp A JaObject to compare with.
     * @return True if the objects are equal, false otherwise.
     */
    public final boolean isCopy(JaObject comp) {
        boolean isCopy = false;

        if (comp instanceof JaVertexT2) {
            if (super.isCopy(comp)
                    && ((JaVertexT2) comp).getFillColor().equals(getFillColor())) {
                isCopy = true;
            }
        }

        return isCopy;

    }

    /** The method that draws this JaVertexT2.
     * @param g2 The graphics context where the JaVertexT2 has to be drawn.
     * @param drawToScreen A boolean variable that indicates whether
     * the drawing is done on the screen or somewhere else. This is used
     * for exporting/printing, where the object handles should not be painted,
     * even if they are visible on the screen.
     */
    public final void jaxoDraw(VectorGraphics g2, boolean drawToScreen) {
        GeneralPath gp = getGeneralPath();
        gp.reset();

        double length =
            Math.sqrt(((double) getWidth() * (double) getWidth())
                + ((double) getHeight() * (double) getHeight()));

        Ellipse2D blob = new Ellipse2D.Float();
        blob.setFrame(-length, -length, 2 * length, 2 * length);
        g2.setColor(getFillColor());
        g2.setStroke(new BasicStroke(0.0f));
        gp.append(blob, false);
        gp = trans(gp, 1.f);
        g2.fill(gp);
        g2.draw(gp);

        Rectangle2D bb = gp.getBounds2D();
        double[] bbox =
        {bb.getMinX(), bb.getMinY(), bb.getMaxX(), bb.getMaxY()};
        setBoundingBox(bbox);

        gp.reset();

        gp.append(blob, false);
        g2.setColor(getColor());
        g2.setStroke(new BasicStroke(getStroke()));
        gp = trans(gp, 1.f);
        g2.draw(gp);

        gp.reset();

        gp.moveTo(0.f, -((float) length));
        gp.lineTo(0.f, ((float) length));
        gp.moveTo(-((float) length), 0.f);
        gp.lineTo(((float) length), 0.f);
        gp = trans(gp, 0.7f);
        g2.draw(gp);
    }

    /** The LaTeX command that is necessary to draw the given JaVertexT2
     * using the axodraw.sty package.
     * @param scale A scale factor to translate Java coordinates
     * to LaTeX coordinates.
     * @param canvasDim The current dimension of the canvas.
     * @return The corresponding axodraw LaTeX command.
     */
    public final String latexCommand(float scale, Dimension canvasDim) {
        int canvasHeight = canvasDim.height;

        Point2D center = getLaTexCenter(scale, canvasHeight);
        Point2D axes = getLaTexAxes(scale);
        float radius = getLaTexRadius(scale);
        String command = "";

        float angle =
            (float) Math.toDegrees(Math.atan2((float) getRelh(),
                    (float) getRelw()));

        if ((int) radius == 0) {
            command = "%";
        } else {
            String command1 = "";
            String tlc = JaxoColor.getColorName(getColor());

            if (JaxoColor.isGrayScale(getFillColor())) {
                String grayScale = JaxoColor.getGreyScale(getFillColor());
                command1 =
                    "\\GOval" + "(" + D_FORMAT.format(center.getX()) + ","
                    + D_FORMAT.format(center.getY()) + ")" + "("
                    + D_FORMAT.format(axes.getY()) + ","
                    + D_FORMAT.format(axes.getX()) + ")" + "(" + angle + ")"
                    + "{" + grayScale + "}";
            } else {
                String tfc = JaxoColor.getColorName(getFillColor());
                command1 =
                    "\\COval" + "(" + D_FORMAT.format(center.getX()) + ","
                    + D_FORMAT.format(center.getY()) + ")" + "("
                    + D_FORMAT.format(axes.getY()) + ","
                    + D_FORMAT.format(axes.getX()) + ")" + "(" + angle + ")"
                    + "{" + tlc + "}" + "{" + tfc + "}";
            }

            Point2D invec1 =
                new Point2D.Float((float) (center.getX() - (radius * 0.5f)),
                    (float) (center.getY() - (radius * 0.5f)));
            Point2D finvec1 =
                new Point2D.Float((float) (center.getX() + (radius * 0.5f)),
                    (float) (center.getY() + (radius * 0.5f)));
            Point2D invec2 =
                new Point2D.Float((float) (center.getX() - (radius * 0.5f)),
                    (float) (center.getY() + (radius * 0.5f)));
            Point2D finvec2 =
                new Point2D.Float((float) (center.getX() + (radius * 0.5f)),
                    (float) (center.getY() - (radius * 0.5f)));

            //             float length =
            //                 (float) Math.sqrt(
            //                     ((double) getWidth() * (double) getWidth())
            //                     + ((double) getHeight() * (double) getHeight()));
            double theta =
                ((double) Math.PI / 4)
                - Math.atan2((float) getRelh(), (float) getRelw());

            AffineTransform at = new AffineTransform();
            at.rotate(theta, center.getX(), center.getY());

            Point2D invect1 = new Point2D.Float();
            Point2D finvect1 = new Point2D.Float();
            Point2D invect2 = new Point2D.Float();
            Point2D finvect2 = new Point2D.Float();

            invect1 = at.transform(invec1, invect1);
            finvect1 = at.transform(finvec1, finvect1);
            invect2 = at.transform(invec2, invect2);
            finvect2 = at.transform(finvec2, finvect2);

            String command2 =
                "\\Line" + "(" + D_FORMAT.format(invect1.getX()) + ","
                + D_FORMAT.format(invect1.getY()) + ")" + "("
                + D_FORMAT.format(finvect1.getX()) + ","
                + D_FORMAT.format(finvect1.getY()) + ")";

            String command3 =
                "\\Line" + "(" + D_FORMAT.format(invect2.getX()) + ","
                + D_FORMAT.format(invect2.getY()) + ")" + "("
                + D_FORMAT.format(finvect2.getX()) + ","
                + D_FORMAT.format(finvect2.getY()) + ")";

            command = command1 + command2 + command3;
        }

        return command;
    }

    private Point2D getLaTexAxes(float scaleFactor) {
        Point2D axesVec = new Point2D.Float();
        float wdt;

        float length =
            (float) Math.sqrt(((double) getWidth() * (double) getWidth())
                + ((double) getHeight() * (double) getHeight()));
        wdt = length / scaleFactor;
        axesVec.setLocation(wdt, wdt);

        return axesVec;
    }

    /** Brings up the edit panel that allows to change the parameters of
     * this object.
     * @return True if the editing actually changed the object, false if
     * the object has not been changed.
     */
    public final boolean editPanel() {
        JaxoVertexT2OptionsPanel vert2op = new JaxoVertexT2OptionsPanel(this);

        return vert2op.hasChanged();
    }
}

 

Ads help maintain this website.