/*

 * 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.JaxoVertexT1OptionsPanel;

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



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

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

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

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

        return isCopy;

    }

    /** The method that draws this JaVertexT1.
     * @param g2 The graphics context where the JaVertexT1 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();
        gp.moveTo(0.f, 0.f);

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

        Ellipse2D vertex = new Ellipse2D.Float();
        vertex.setFrame(-length, -length, 2 * length, 2 * length);
        gp.append(vertex, 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);
    }

    /** The LaTeX command that is necessary to draw the given JaVertexT1
     * 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);

        String base = "\\Vertex";
        String command = "";

        if ((int) radius == 0) {
            command = "%";
        } else {
            command =
                base + "(" + D_FORMAT.format(center.getX()) + ","
                + D_FORMAT.format(center.getY()) + ")" + "{"
                + D_FORMAT.format(radius) + "}";
        }

        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() {
        JaxoVertexT1OptionsPanel vert1op = new JaxoVertexT1OptionsPanel(this);

        return vert1op.hasChanged();
    }
}

 

Ads help maintain this website.