/*
* 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.JaxoVertexT3OptionsPanel;
import java.awt.BasicStroke;
import java.awt.Dimension;
import org.freehep.graphics2d.VectorGraphics;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
/** A vertex (a filled square). */
public class JaVertexT3 extends JaVertex {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Constructor: just calls super(). */
public JaVertexT3() {
super();
}
/** Returns an exact copy of this JaVertexT3.
* @return A copy of this JaVertexT3.
*/
public final JaObject copy() {
JaVertexT3 temp = (JaVertexT3) copy(new JaVertexT3());
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 JaVertexT3) {
isCopy = super.isCopy(comp);
}
return isCopy;
}
/** The method that draws this JaVertexT3.
* @param g2 The graphics context where the JaVertexT3 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);
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 JaVertexT3
* 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 command = "";
if ((int) radius == 0) {
command = "%";
} else {
float xi;
float yi;
float xf;
float yf;
xi = (float) center.getX() - radius;
yi = (float) center.getY() + radius;
xf = (float) center.getX() + radius;
yf = (float) center.getY() - radius;
String tlc = JaxoColor.getColorName(getColor());
command =
"\\CBox" + "(" + D_FORMAT.format(xf) + ","
+ D_FORMAT.format(yf) + ")" + "(" + D_FORMAT.format(xi) + ","
+ D_FORMAT.format(yi) + ")" + "{" + tlc + "}" + "{" + tlc
+ "}" + "%%JaxoDrawID:Vertex";
}
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() {
JaxoVertexT3OptionsPanel vert3op = new JaxoVertexT3OptionsPanel(this);
return vert3op.hasChanged();
}
}
Ads help maintain this website.