/*

 * 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.JaxoVertexT6OptionsPanel;
import org.freehep.graphics2d.VectorGraphics;

import java.awt.BasicStroke;
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;



/** A vertex (a filled diamond). */
public class JaVertexT6 extends JaVertex {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/** Constructor: just calls super(). */
    public JaVertexT6() {
        super();
    }

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

        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 JaVertexT6) {
            isCopy = super.isCopy(comp);
        }

        return isCopy;

    }

    /** The method that draws this JaVertexT6.
     * @param g2 The graphics context where the JaVertexT6 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) {
        g2.setColor(getColor());
        g2.setStroke(new BasicStroke(0.0f));

        GeneralPath gp = getGeneralPath();
        gp.reset();

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

        Rectangle2D square = new Rectangle2D.Float();
        square.setFrame(-length, -length, 2 * length, 2 * length);
        gp.append(square, false);

        AffineTransform at = new AffineTransform();
        at.rotate(Math.toRadians(45), 0.d, 0.d);
        gp.transform(at);

        gp = transv(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);
    }

    /** The LaTeX command that is necessary to draw the given JaVertexT6
     * 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);
        float radius = getLaTexRadius(scale) * ((float) Math.sqrt(2));
        String command = "";

        if ((int) radius == 0) {
            command = "%";
        } else {
            Point2D p1;
            Point2D p2;
            Point2D p3;
            Point2D p4;
            p1 = new Point2D.Float((float) (center.getX() - radius),
                    (float) center.getY());
            p2 = new Point2D.Float((float) center.getX(),
                    (float) (center.getY() + radius));
            p3 = new Point2D.Float((float) (center.getX() + radius),
                    (float) center.getY());
            p4 = new Point2D.Float((float) center.getX(),
                    (float) (center.getY() - radius));

            String tlc = JaxoColor.getColorName(getColor());

            command =
                "\\CTri" + "(" + D_FORMAT.format(p1.getX()) + ","
                + D_FORMAT.format(p1.getY()) + ")" + "("
                + D_FORMAT.format(p2.getX()) + ","
                + D_FORMAT.format(p2.getY()) + ")" + "("
                + D_FORMAT.format(p3.getX()) + ","
                + D_FORMAT.format(p3.getY()) + ")" + "{" + tlc + "}" + "{"
                + tlc + "}" + "\\CTri" + "(" + D_FORMAT.format(p1.getX())
                + "," + D_FORMAT.format(p1.getY()) + ")" + "("
                + D_FORMAT.format(p4.getX()) + ","
                + D_FORMAT.format(p4.getY()) + ")" + "("
                + D_FORMAT.format(p3.getX()) + ","
                + D_FORMAT.format(p3.getY()) + ")" + "{" + tlc + "}" + "{"
                + tlc + "}";
        }

        return command;
    }

    /** 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() {
        JaxoVertexT6OptionsPanel vert6op = new JaxoVertexT6OptionsPanel(this);

        return vert6op.hasChanged();
    }
}

 

Ads help maintain this website.