/*
* 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 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 fermion loop. */
public class JaFLoop extends JaLoopObject {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Constructor: just calls super(). */
public JaFLoop() {
super();
}
/** Returns an exact copy of this JaFLoop.
* @return A copy of this JaFLoop.
*/
public final JaObject copy() {
JaFLoop temp = (JaFLoop) copy(new JaFLoop());
temp.setArrow(isArrow());
temp.setFlip(isFlip());
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 JaFLoop) {
if (super.isCopy(comp)
&& (((JaFLoop) comp).isArrow() == isArrow())
&& (((JaFLoop) comp).isFlip() == isFlip())) {
isCopy = true;
}
}
return isCopy;
}
/** The method that draws this JaFLoop.
* @param g2 The graphics context where the JaFLoop 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()));
GeneralPath gptmp = new GeneralPath();
GeneralPath gp = getGeneralPath();
gp.reset();
double length =
Math.sqrt(((double) getWidth() * (double) getWidth())
+ ((double) getHeight() * (double) getHeight()));
if (isArrow()) {
if (getDoubleLine()) {
gp = dLoopArrow(g2, getColor(), length,
(float) 3 * getStroke(), getFlip(), getDLSeparation());
gptmp.append(gp, false);
gp.reset();
gp = dLoopArrow(g2, getColor(), length,
(float) 3 * getStroke(), getFlip(), -getDLSeparation());
gptmp.append(gp, false);
} else {
gp = loopArrow(g2, getColor(), length,
(float) 4 * getStroke(), getFlip());
gptmp.append(gp, false);
}
}
gp.reset();
gp.moveTo(0.f, 0.f);
g2.setStroke(new BasicStroke(getStroke()));
Ellipse2D loop = new Ellipse2D.Double();
if (getDoubleLine()) {
loop.setFrame(-length - getDLSeparation(),
-length - getDLSeparation(), 2 * (length + getDLSeparation()),
2 * (length + getDLSeparation()));
gp.append(loop, false);
loop.setFrame(-length + getDLSeparation(),
-length + getDLSeparation(), 2 * (length - getDLSeparation()),
2 * (length - getDLSeparation()));
gp.append(loop, false);
} else {
loop.setFrame(-length, -length, 2 * length, 2 * length);
gp.append(loop, false);
}
gp = trans(gp, 1.f);
gptmp.append(gp, false);
g2.draw(gptmp);
Rectangle2D bb = gptmp.getBounds2D();
double[] bbox =
{bb.getMinX(), bb.getMinY(), bb.getMaxX(), bb.getMaxY()};
setBoundingBox(bbox);
}
/** The LaTeX command that is necessary to draw this JaFLoop
* 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);
Point2D angles = getLaTexAngles();
String command = "";
String base = "\\CArc";
if (isArrow()) {
if (isFlip()) {
base = "\\ArrowArcn";
} else {
base = "\\ArrowArc";
}
}
if ((int) radius == 0) {
command = "%";
} else if (getDoubleLine()) {
float offSet = getDLSeparation() / scale;
String command1 =
base + "(" + D_FORMAT.format(center.getX()) + ","
+ D_FORMAT.format(center.getY()) + ")" + "("
+ D_FORMAT.format(radius + offSet) + ","
+ D_FORMAT.format(angles.getX()) + ","
+ D_FORMAT.format(angles.getY()) + ")";
String command2 =
base + "(" + D_FORMAT.format(center.getX()) + ","
+ D_FORMAT.format(center.getY()) + ")" + "("
+ D_FORMAT.format(radius - offSet) + ","
+ D_FORMAT.format(angles.getX()) + ","
+ D_FORMAT.format(angles.getY()) + ")";
command =
command1.concat(command2.concat("%%JaxoDrawID:DoubleLine"
+ "(" + D_FORMAT.format(getDLSeparation()) + ")"));
} else {
command =
base + "(" + D_FORMAT.format(center.getX()) + ","
+ D_FORMAT.format(center.getY()) + ")" + "("
+ D_FORMAT.format(radius) + ","
+ D_FORMAT.format(angles.getX()) + ","
+ D_FORMAT.format(angles.getY()) + ")";
}
return command;
}
}
Ads help maintain this website.