[Home] Restricted access for guests. The link to Java source code is disabled
Java source code of 'jhplot.jadraw.JaGArc'
/*
* 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 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.Rectangle2D;
/** A ghost arc. */
public class JaGArc extends JaArcObject {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Constructor: just calls super(). */
public JaGArc() {
super();
}
/** Returns an exact copy of this JaGArc.
* @return A copy of this JaGArc.
*/
public final JaObject copy() {
JaGArc temp = new JaGArc();
temp.setArcPts(getX1(), getY1(), getX2(), getY2(), getX(), getY());
temp.setX(getX());
temp.setY(getY());
temp.setColor(getColor());
temp.setStroke(getStroke());
temp.setArrow(isArrow());
temp.setFlip(isFlip());
temp.setStangle(getStangle());
temp.setDash(getDash());
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 JaGArc) {
JaGArc arc = (JaGArc) comp;
if ((arc.getX1() == getX1()) && (arc.getX2() == getX2())
&& (arc.getY1() == getY1()) && (arc.getY2() == getY2())
&& (arc.getX() == getX()) && (arc.getY() == getY())
&& (arc.getColor().equals(getColor()))
&& (arc.getStroke() == getStroke())
&& (arc.isArrow() == isArrow())
&& (arc.isFlip() == isFlip())
&& (arc.getStangle() == getStangle())
&& (arc.getDash() == getDash())
&& (arc.getDoubleLine() == getDoubleLine())
&& (arc.getDLSeparation() == getDLSeparation())
&& (arc.getRelw() == getRelw())
&& (arc.getRelh() == getRelh())) {
isCopy = true;
}
}
return isCopy;
}
/** The method that draws this JaGArc.
* @param g2 The graphics context where the JaGArc 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();
if (testArea()) {
return;
} else {
g2.setColor(getColor());
g2.setStroke(new BasicStroke(getStroke()));
GeneralPath gptmp = new GeneralPath();
gp.reset();
double[] par = getArcParameters();
if (isArrow() && !isResizing()) {
if (getDoubleLine()) {
gp = dArcArrow(g2, getColor(), par[2],
(float) 3 * getStroke(), isFlip(),
getDLSeparation());
gp = newtransarc(gp, par[0], par[1],
((Math.PI - par[3]) / 2.d) + par[4], 1.f);
g2.fill(gp);
gptmp.append(gp, false);
gp.reset();
gp = dArcArrow(g2, getColor(), par[2],
(float) 3 * getStroke(), isFlip(),
-getDLSeparation());
gp = newtransarc(gp, par[0], par[1],
((Math.PI - par[3]) / 2.d) + par[4], 1.f);
g2.fill(gp);
gptmp.append(gp, false);
} else {
gp = arcArrow(g2, getColor(), par[2],
(float) 4 * getStroke(), isFlip());
gp = newtransarc(gp, par[0], par[1],
((Math.PI - par[3]) / 2.d) + par[4], 1.f);
g2.fill(gp);
gptmp.append(gp, false);
}
}
if (isResizing()) {
g2.setColor(JaxoColor.RED);
g2.setStroke(new BasicStroke(1.f));
} else {
g2.setStroke(new BasicStroke(getStroke()));
}
gp.reset();
Arc2D arc = new Arc2D.Double();
if (getDoubleLine()) {
float cf1 = (float) ((par[2] + getDLSeparation()) / par[2]);
float cf2 = (float) ((par[2] - getDLSeparation()) / par[2]);
float[] dashes1 = {cf1 * getDash(), 4 * cf1 * getDash()};
float[] dashes2 = {cf2 * getDash(), 4 * cf2 * getDash()};
arc.setArc(-par[2] + getDLSeparation(),
-par[2] + getDLSeparation(),
2 * (par[2] - getDLSeparation()),
2 * (par[2] - getDLSeparation()), 0,
Math.toDegrees(par[3]), Arc2D.OPEN);
gp.append(arc, false);
gp = newtransarc(gp, par[0], par[1], par[4], 1.f);
g2.setStroke(new BasicStroke(getStroke(),
BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
dashes2, 0.0f));
gptmp.append(gp, false);
gp.reset();
arc.setArc(-par[2] - getDLSeparation(),
-par[2] - getDLSeparation(),
2 * (par[2] + getDLSeparation()),
2 * (par[2] + getDLSeparation()), 0,
Math.toDegrees(par[3]), Arc2D.OPEN);
gp.append(arc, false);
gp = newtransarc(gp, par[0], par[1], par[4], 1.f);
g2.setStroke(new BasicStroke(getStroke(),
BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
dashes1, 0.0f));
gptmp.append(gp, false);
} else {
float[] dashes = {getDash(), 4 * getDash()};
arc.setArc(-par[2], -par[2], 2 * par[2], 2 * par[2], 0,
Math.toDegrees(par[3]), Arc2D.OPEN);
gp.append(arc, false);
gp = newtransarc(gp, par[0], par[1], par[4], 1.f);
g2.setStroke(new BasicStroke(getStroke(),
BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f,
dashes, 0.0f));
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 JaGArc
* 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) {
double[] par = getArcParameters();
double cx = par[0] / scale;
double cy = (canvasDim.height - par[1]) / scale;
double r = par[2] / scale;
double sa = -Math.toDegrees(par[4]);
double ea = Math.toDegrees(par[3] - par[4]);
float dashSize = getLaTexDashSize(scale);
String command = "";
String base = "\\DashCArc";
if (isArrow()) {
if (isFlip()) {
base = "\\DashArrowArcn";
double swap;
swap = ea;
ea = sa;
sa = swap;
} else {
base = "\\DashArrowArc";
}
}
if (getDoubleLine()) {
float offSet = getDLSeparation() / scale;
float dashSize1 = (float) ((r + offSet) / r) * dashSize;
float dashSize2 = (float) ((r - offSet) / r) * dashSize;
String command1 =
base + "(" + D_FORMAT.format(cx) + "," + D_FORMAT.format(cy)
+ ")" + "(" + D_FORMAT.format(r + offSet) + ","
+ D_FORMAT.format(sa) + "," + D_FORMAT.format(ea) + ")" + "{"
+ D_FORMAT.format(dashSize1) + "}";
String command2 =
base + "(" + D_FORMAT.format(cx) + "," + D_FORMAT.format(cy)
+ ")" + "(" + D_FORMAT.format(r - offSet) + ","
+ D_FORMAT.format(sa) + "," + D_FORMAT.format(ea) + ")" + "{"
+ D_FORMAT.format(dashSize2) + "}";
command =
command1.concat(command2.concat("%%JaxoDrawID:DoubleLine"
+ "(" + D_FORMAT.format(getDLSeparation()) + ")"));
} else {
command =
base + "(" + D_FORMAT.format(cx) + "," + D_FORMAT.format(cy)
+ ")" + "(" + D_FORMAT.format(r) + "," + D_FORMAT.format(sa)
+ "," + D_FORMAT.format(ea) + ")" + "{"
+ D_FORMAT.format(dashSize) + "}";
}
return command;
}
/////////////////////////////////////////////////////////////////////////
//
// private auxiliary methods //
//
/////////////////////////////////////////////////////////////////////////
private float getLaTexDashSize(float scaleFactor) {
float dshSize = getDash() / scaleFactor;
return dshSize;
}
}