/*

 * 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.JaxoLineOptionsPanel;
import japlot.jaxodraw.JaxoMainPanel;

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


import japlot.jaxodraw.*;


/**
 * Class to build a gluon line
 *
 */


public class JaGlLine extends JaLineObject {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int angamp;

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


        setAmp(JaxoPrefs.getIntPref(JaxoPrefs.PREF_AMPLITUDE));
        setFreq(20.0f);
        setColor(JaxoColor.getColor(JaxoPrefs.getPref(
                    JaxoPrefs.PREF_COLOR)));
        setStroke(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_LINEWIDTH));
        setSymm(false);
        setDoubleLine(false);
        setDLSeparation(JaxoPrefs.getFloatPref(JaxoPrefs.PREF_DLSEP));
 




    }

    /** Returns an exact copy of this JaGlLine.
     * @return A copy of this JaGlLine.
     */
    public final JaObject copy() {
        JaGlLine temp = new JaGlLine();
        temp.setX(getX());
        temp.setY(getY());
        temp.setAmp(getAmp());
        temp.setFreq(getFreq());
        temp.setColor(getColor());
        temp.setStroke(getStroke());
        temp.setSymm(isSymm());
        temp.setDoubleLine(getDoubleLine());
        temp.setDLSeparation(getDLSeparation());
        temp.setSize(getWidth(), getHeight(), getRelw(), getRelh());
        temp.setBoundingBox(getBoundingBox());

        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 JaGlLine) {
            JaGlLine line = (JaGlLine) comp;
            if ((line.getX() == getX()) && (line.getY() == getY())
                    && (line.getAmp() == getAmp())
                    && (line.getFreq() == getFreq())
                    && line.getColor().equals(getColor())
                    && (line.getStroke() == getStroke())
                    && (line.isSymm() == isSymm())
                    && (line.getDoubleLine() == getDoubleLine())
                    && (line.getDLSeparation() == getDLSeparation())
                    && (line.getRelw() == getRelw())
                    && (line.getRelh() == getRelh())) {
                isCopy = true;
            }
        }

        return isCopy;

    }

    /** Returns the angamp property of this JaGlLine.
     * @return The angamp property of this JaGlLine.
     */
    public final int getAngamp() {
        return angamp;
    }

    /** Sets the angamp property of this JaGlLine.
     * @param amp The angamp property to be set.
     */
    public final void setAngamp(int amp) {
        this.angamp = amp;
    }

    /** The method that draws this JaGlLine.
     * @param g2 The graphics context where the JaGlLine 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(getStroke()));

        float boh = 0.6f;

        GeneralPath gp = getGeneralPath();
        gp.reset();
        angamp = -180;

        if (((getAmp() > 0) && isBack()) || ((getAmp() < 0) && !isBack())) {
            angamp = 180;
        }

        int a = Math.abs(getAmp());

        int n;
        float ts;
        double length =
            Math.sqrt(((double) getWidth() * (double) getWidth())
                + ((double) getHeight() * (double) getHeight()));

        n = (int) Math.round(((length - getFreq()) / getFreq() / boh));
        ts = (float) (length / (1 + (boh * n)));

        Arc2D arc = new Arc2D.Float();
        if (getDoubleLine()) {
            for (int i = 0; i < n; i++) {
                arc.setArc(i * ts * boh, (-a / 2) + getDLSeparation(), ts, a,
                    180, angamp, Arc2D.OPEN);
                gp.append(arc, true);
                arc.setArc(i * ts * boh, (-a / 2) - getDLSeparation(), ts, a,
                    180, angamp, Arc2D.OPEN);
                gp.append(arc, false);
                arc.setArc((i + 1) * ts * boh, (-a / 2) + getDLSeparation(),
                    ts * (1 - boh), a, 0, angamp, Arc2D.OPEN);
                gp.append(arc, true);
                arc.setArc((i + 1) * ts * boh, (-a / 2) - getDLSeparation(),
                    ts * (1 - boh), a, 0, angamp, Arc2D.OPEN);
                gp.append(arc, false);
            }

            arc.setArc(n * ts * boh, (-a / 2) + getDLSeparation(), ts, a, 180,
                angamp, Arc2D.OPEN);
            gp.append(arc, true);
            arc.setArc(n * ts * boh, (-a / 2) - getDLSeparation(), ts, a, 180,
                angamp, Arc2D.OPEN);
            gp.append(arc, false);
        } else {
            for (int i = 0; i < n; i++) {
                arc.setArc(i * ts * boh, -a / 2, ts, a, 180, angamp, Arc2D.OPEN);
                gp.append(arc, true);
                arc.setArc((i + 1) * ts * boh, -a / 2, ts * (1 - boh), a, 0,
                    angamp, Arc2D.OPEN);
                gp.append(arc, true);
            }

            arc.setArc(n * ts * boh, -a / 2, ts, a, 180, angamp, Arc2D.OPEN);
            gp.append(arc, true);
        }

        gp = trans(gp, 1.f);
        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 this JaGlLine
     * 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 startPoint = getLaTexStartPoint(scale, canvasHeight);
        Point2D endPoint = getLaTexEndPoint(scale, canvasHeight);
        float amplitude = getLaTexAmplitude(2.f * scale);
        float windings = getLaTexWindingNumber(1.0f);
        String command = "";

        String base = "\\Gluon";

        if (((int) endPoint.getX() == (int) startPoint.getX())
                && ((int) endPoint.getY() == (int) startPoint.getY())) {
            command = "%";
        } else if (getDoubleLine()) {
            Point2D offSet = getOffSet(scale);

            String command1 =
                base + "("
                + D_FORMAT.format(startPoint.getX() + offSet.getX()) + ","
                + D_FORMAT.format(startPoint.getY() + offSet.getY()) + ")"
                + "(" + D_FORMAT.format(endPoint.getX() + offSet.getX()) + ","
                + D_FORMAT.format(endPoint.getY() + offSet.getY()) + ")" + "{"
                + D_FORMAT.format(amplitude) + "}" + "{"
                + D_FORMAT.format(windings) + "}";
            String command2 =
                base + "("
                + D_FORMAT.format(startPoint.getX() - offSet.getX()) + ","
                + D_FORMAT.format(startPoint.getY() - offSet.getY()) + ")"
                + "(" + D_FORMAT.format(endPoint.getX() - offSet.getX()) + ","
                + D_FORMAT.format(endPoint.getY() - offSet.getY()) + ")" + "{"
                + D_FORMAT.format(amplitude) + "}" + "{"
                + D_FORMAT.format(windings) + "}";

            command =
                command1.concat(command2.concat("%%JaxoDrawID:DoubleLine"
                        + "(" + D_FORMAT.format(getDLSeparation()) + ")"));
        } else {
            command =
                base + "(" + D_FORMAT.format(startPoint.getX()) + ","
                + D_FORMAT.format(startPoint.getY()) + ")" + "("
                + D_FORMAT.format(endPoint.getX()) + ","
                + D_FORMAT.format(endPoint.getY()) + ")" + "{"
                + D_FORMAT.format(amplitude) + "}" + "{"
                + D_FORMAT.format(windings) + "}";
        }

        return command;
    }

    /////////////////////////////////////////////////////////////////////////
    //
    //   private auxiliary methods  //
    //
    /////////////////////////////////////////////////////////////////////////
    private Point2D getLaTexStartPoint(float scaleFactor, int canvasHeight) {
        Point2D startVec = new Point2D.Float();
        float x1;
        float y1;

        if (getRelw() <= 0) {
            x1 = getX() - getRelw();
        } else {
            x1 = getX();
        }

        if (getRelh() >= 0) {
            y1 = getY();
        } else {
            y1 = getY() - getRelh();
        }

        startVec.setLocation(x1 / scaleFactor,
            (canvasHeight - y1) / scaleFactor);

        return startVec;
    }

    private Point2D getLaTexEndPoint(float scaleFactor, int canvasHeight) {
        Point2D endVec = new Point2D.Float();
        float x2;
        float y2;

        if (getRelw() >= 0) {
            x2 = getX() + getRelw();
        } else {
            x2 = getX();
        }

        if (getRelh() <= 0) {
            y2 = getY();
        } else {
            y2 = getY() + getRelh();
        }

        endVec.setLocation(x2 / scaleFactor, (canvasHeight - y2) / scaleFactor);

        return endVec;
    }

    private float getLaTexAmplitude(float scaleFactor) {
        float a = getAmp() / scaleFactor;

        return a;
    }

    private float getLaTexWindingNumber(float scaleFactor) {
        double length =
            Math.sqrt(((double) getWidth() * (double) getWidth())
                + ((double) getHeight() * (double) getHeight()));

        float n = (float) (length - getFreq()) / getFreq() / 0.7f;

        n = n / scaleFactor;

        return n;
    }

    private Point2D getOffSet(float scaleFactor) {
        Point2D offSet = new Point2D.Float();
        float lSep = getDLSeparation() / scaleFactor;
        double theta =
            (double) Math.atan2((float) getRelh(), (float) getRelw());

        offSet.setLocation((float) lSep * Math.sin(theta),
            (float) lSep * Math.cos(theta));

        return offSet;
    }

    /** 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() {
        JaxoLineOptionsPanel lineop =
            new JaxoLineOptionsPanel(JaxoMainPanel.GLLINE);
        lineop.initParams(this);
        lineop.setPanelIcon("japlot/jaxodraw/icons/gluon.gif");
        lineop.setPanelTitle("Gluon_line_parameters");
        baseEditPanel(lineop);
        lineop.addFinalAwSPanel(1, 0);
        lineop.addDlPanel(2, 0);

        boolean hasChanged = lineop.showPanel();

        return hasChanged;
    }
}

 

Ads help maintain this website.