/*
* 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 japlot.jaxodraw;
import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Vector;
import jhplot.jadraw.JaBlob;
import jhplot.jadraw.JaBox;
import jhplot.jadraw.JaFArc;
import jhplot.jadraw.JaFLine;
import jhplot.jadraw.JaFLoop;
import jhplot.jadraw.JaGArc;
import jhplot.jadraw.JaGLine;
import jhplot.jadraw.JaGLoop;
import jhplot.jadraw.JaGlArc;
import jhplot.jadraw.JaGlLine;
import jhplot.jadraw.JaGlLoop;
import jhplot.jadraw.JaLatexText;
import jhplot.jadraw.JaObject;
import jhplot.jadraw.JaPArc;
import jhplot.jadraw.JaPLine;
import jhplot.jadraw.JaPLoop;
import jhplot.jadraw.JaSArc;
import jhplot.jadraw.JaSLine;
import jhplot.jadraw.JaSLoop;
import jhplot.jadraw.JaVertexT1;
import jhplot.jadraw.JaVertexT2;
import jhplot.jadraw.JaVertexT3;
import jhplot.jadraw.JaVertexT4;
import jhplot.jadraw.JaVertexT5;
import jhplot.jadraw.JaVertexT6;
import jhplot.jadraw.JaZigZagLine;
/** Defines a number of axodraw LaTeX commands and all the methods to convert
* them into JaxoObjects. This is responsible for the import option.
*/
public class JaxoAxodraw {
private static final String[] KNOWN_COMMANDS =
{
"\\ArrowArcn", "\\ArrowArc", "\\ArrowLine", "\\CArc", "\\CBox",
"\\CCirc", "\\COval", "\\CTri", "\\DashArrowArcn", "\\DashArrowArc",
"\\DashArrowLine", "\\DashCArc", "\\DashLine", "\\GBox", "\\GCirc",
"\\GlueArc", "\\Gluon", "\\GOval", "\\GTri", "\\Line", "\\PhotonArc",
"\\Photon", "\\SetColor", "\\SetWidth", "\\Text", "\\Vertex",
"\\ZigZag"
};
private static final int N_OF_COMMANDS = KNOWN_COMMANDS.length;
private static final String[] REQUIRED_COMMANDS =
{"\\documentclass", "\\begin{document}", "\\begin{picture}"};
private static final int N_OF_REQUIRED = REQUIRED_COMMANDS.length;
private final boolean[] isValid = new boolean[3];
private String string = "";
private int index = 0;
private Color color = JaxoColor.BLACK;
private float stroke = 1.0f;
private float scaleFactor = 1.f; // default, will be set later
private String comment = "";
private float bBoxHeight = 0.f; // reset when a \begin{picture}
private ArrayList packageList; // command is read
/** Constructor: Initializes the list of Latex packages
* (axodraw and color).
*/
public JaxoAxodraw() {
this.packageList = new ArrayList(3);
packageList.add("axodraw");
packageList.add("color");
}
/** Returns a JaObject corresponding to a axodraw command.
* @param newString One line of a latex file
* @return A JaObject the corresponds to the axodraw command
* of the input line, or null, if nothing corresponds
*/
public final JaObject getJaxoObject(String newString) {
this.string = newString;
JaObject newob = null;
boolean valid = isValidJaxoCommand(string);
if (!valid) {
newob = null;
} else if (index == -3) { // Diamond
newob = newVertexT6();
} else if (index == -2) { // Cross
newob = newVertexT4();
} else if (index == -1) { // Circle Cross
newob = newVertexT2();
} else if (index == getIndex("\\ArrowArcn")) { // ArrowArcn
newob = newFLoop(true, true);
} else if (index == getIndex("\\ArrowArc")) { // ArrowArc
newob = newFLoop(false, true);
} else if (index == getIndex("\\ArrowLine")) { // ArrowLine
newob = newLine(true);
} else if (index == getIndex("\\CArc")) { // CArc
newob = newFLoop(false, false);
} else if (index == getIndex("\\CBox")) { // CBox
newob = newCBox();
} else if (index == getIndex("\\CCirc")) { // CCirc
newob = newCCirc();
} else if (index == getIndex("\\COval")) { // COval
newob = newCOval();
} else if (index == getIndex("\\CTri")) { // CTri
newob = newCTri();
} else if (index == getIndex("\\DashArrowArcn")) { // DashArrowArcn
newob = newDashArc(true, true);
} else if (index == getIndex("\\DashArrowArc")) { // DashArrowArc
newob = newDashArc(false, true);
} else if (index == getIndex("\\DashArrowLine")) { // DashArrowLine
newob = newDashLine(true);
} else if (index == getIndex("\\DashCArc")) { // DashCArc
newob = newDashArc(true, false);
} else if (index == getIndex("\\DashLine")) { // DashLine
newob = newDashLine(false);
} else if (index == getIndex("\\GBox")) { // GBox
newob = newGBox();
} else if (index == getIndex("\\GCirc")) { // GCirc
newob = newGCirc();
} else if (index == getIndex("\\GlueArc")) { // GlueArc
newob = newGlArc();
} else if (index == getIndex("\\Gluon")) { // Gluon
newob = newGlLine();
} else if (index == getIndex("\\GOval")) { // GOval
newob = newGOval();
} else if (index == getIndex("\\GTri")) { // GTri
newob = newGTri();
} else if (index == getIndex("\\Line")) { // Line
newob = newLine(false);
} else if (index == getIndex("\\PhotonArc")) { // PhotonArc
newob = newPArc();
} else if (index == getIndex("\\Photon")) { // Photon
newob = newPLine();
} else if (index == getIndex("\\SetColor")) { // SetColor
this.color = JaxoColor.getColor(getOneCurl(string));
} else if (index == getIndex("\\SetWidth")) { // SetWidth
this.stroke = Float.parseFloat(getOneCurl(string)) * 2.f;
} else if (index == getIndex("\\Text")) { // Text
newob = newText();
} else if (index == getIndex("\\Vertex")) { // Vertex
newob = newVertexT1();
} else if (index == getIndex("\\ZigZag")) { // ZigZag
newob = newZigZagLine();
}
return newob;
}
/** Checks whether the given string starts with one of "\documentclass",
* "\begin{document}" or "\begin{picture}".
* @param newString The input string.
*/
public final void checkRequired(String newString) {
this.string = newString;
if (string.startsWith("\\usepackage")) {
String pack = getOneCurl(string);
if (!(pack.equals("axodraw") || pack.equals("color"))) {
packageList.add(pack);
}
} else if (string.startsWith("%%JaxoComment:")) {
this.comment = string.replaceFirst("%%JaxoComment:", "").trim();
} else if (string.startsWith("%%JaxoScale")) {
this.scaleFactor = Float.parseFloat(getOneCurl(string));
} else {
boolean isRequiredCommand = false;
int i = 0;
while (!string.startsWith(REQUIRED_COMMANDS[i])
&& (i < (N_OF_REQUIRED - 1))) {
i++;
}
if ((i == (N_OF_REQUIRED - 1))
&& !string.startsWith(REQUIRED_COMMANDS[i])) {
i++;
}
isRequiredCommand = (i < N_OF_REQUIRED);
if (isRequiredCommand) {
isValid[i] = true;
if (i == 2) { // read the \begin(picture) parameters
int[] pic = getFourInts(string);
this.bBoxHeight = (float) pic[1] * scaleFactor;
}
}
}
}
/** Returns an array that indicates which required LaTeX commands
* were found.
* @return An array of three boolean variables, the first is true
* if "\documentclass" was found, the second is true if
* "\begin{document}" was found, the third is true if
* "\begin{picture}" was found
*/
public final boolean[] getValid() {
int length = isValid.length;
boolean[] newArray = new boolean[length];
System.arraycopy(isValid, 0, newArray, 0, length);
return newArray;
}
/** Returns the current list of LaTeX packages included in the graph.
* @return A vector that contains strings of packages, "axodraw" and
* "color" are always included
*/
public final ArrayList getPackages() {
return packageList;
}
/** Returns the comment (description) of this axodraw object.
* @return The axodraw comment
*/
public final String getComment() {
return comment;
}
// auxiliary private methods
private boolean isValidJaxoCommand(String s) {
int i = 0;
while (!s.startsWith(KNOWN_COMMANDS[i]) && (i < (N_OF_COMMANDS - 1))) {
i++;
}
if ((i == (N_OF_COMMANDS - 1)) && !s.startsWith(KNOWN_COMMANDS[i])) {
i++;
}
this.index = i;
// check for CircleCross, Cross vertex and diamonds
if (i == getIndex("\\COval")) {
if (s.indexOf("\\Line", 6) > 0) {
this.index = -1;
}
} else if (i == getIndex("\\Line")) {
if ((s.indexOf("\\Line", 6) > 0) && (s.indexOf("%") == -1)) {
this.index = -2;
}
} else if (i == getIndex("\\CTri")) {
if (s.indexOf("\\CTri", 6) > 0) {
this.index = -3;
}
}
return (i < N_OF_COMMANDS);
}
private int getIndex(String s) {
int i = 0;
while ((KNOWN_COMMANDS[i].compareTo(s) != 0)
&& (i < (N_OF_COMMANDS - 1))) {
i++;
}
if (KNOWN_COMMANDS[i].compareTo(s) == 0) {
return i;
} else {
return N_OF_COMMANDS;
}
}
/*
private String getLatexCommand(int i) {
if (i < N_OF_COMMANDS) {
return KNOWN_COMMANDS[i];
} else {
return "?";
}
}
private boolean isAxodrawCommand(String s) {
int i = getIndex(s);
return (i < N_OF_COMMANDS);
}
*/
private int[] getLineParams(int[] in, String st) {
// xi = in[0], yi = in[1], xf = in[2], yf = in[3],
int[] out = new int[4];
out[2] = Math.round((in[2] - in[0]) * scaleFactor);
out[3] = Math.round((in[1] - in[3]) * scaleFactor);
if ((out[2] > 0) && (out[3] >= 0)) {
out[0] = Math.round(in[0] * scaleFactor);
out[1] = Math.round(bBoxHeight - (in[1] * scaleFactor));
} else if ((out[2] >= 0) && (out[3] < 0)) {
out[0] = Math.round(in[0] * scaleFactor);
out[1] = Math.round(bBoxHeight - (in[3] * scaleFactor));
} else if ((out[2] <= 0) && (out[3] > 0)) {
out[0] = Math.round(in[2] * scaleFactor);
out[1] = Math.round(bBoxHeight - (in[1] * scaleFactor));
} else if ((out[2] < 0) && (out[3] <= 0)) {
out[0] = Math.round(in[2] * scaleFactor);
out[1] = Math.round(bBoxHeight - (in[3] * scaleFactor));
}
if (!(st.indexOf("%") == -1)) {
double theta =
Math.atan2((in[1] - in[3]) * scaleFactor,
(in[2] - in[0]) * scaleFactor);
float dlSep = theDLSeparation(st);
out[0] =
(int) Math.round(out[0] - ((float) dlSep * Math.sin(theta)));
out[1] =
(int) Math.round(out[1] + ((float) dlSep * Math.cos(theta)));
}
return out;
}
private int[] getBoxParams(int[] in) {
// xi = in[0], yi = in[1], xf = in[2], yf = in[3],
int[] out = new int[4];
out[2] = Math.round((in[2] - in[0]) * scaleFactor);
out[3] = Math.round((in[3] - in[1]) * scaleFactor);
out[0] = Math.round(in[0] * scaleFactor);
out[1] = Math.round(bBoxHeight - (in[3] * scaleFactor));
return out;
}
private int[] getCircParams(int[] in, String rad) {
int[] out = new int[3];
out[0] = Math.round(in[0] * scaleFactor);
out[1] = Math.round(bBoxHeight - (in[1] * scaleFactor));
out[2] = (int) Math.round(Float.parseFloat(rad) * scaleFactor);
return out;
}
private int[] getBlobParams(String[] in) {
// xi = in[0], yi = in[1], xf = in[2], yf = in[3],
int[] out = new int[5];
out[2] = Math.round(Float.parseFloat(in[2]) * scaleFactor);
out[3] = Math.round(Float.parseFloat(in[3]) * scaleFactor);
out[0] = Math.round(Float.parseFloat(in[0]) * scaleFactor);
out[1] =
Math.round(bBoxHeight - (Float.parseFloat(in[1]) * scaleFactor));
out[4] = Math.round(Float.parseFloat(in[4]));
return out;
}
private int[] getT1Params(String[] st) {
int[] out = new int[2];
float x = Float.parseFloat(st[0]);
float y = Float.parseFloat(st[1]);
out[0] = (int) Math.round(x * scaleFactor);
out[1] = (int) Math.round(bBoxHeight - (y * scaleFactor));
return out;
}
private int[] getT2Params(String[] st) {
int[] out = new int[4];
float radius = Float.parseFloat(st[2]) * scaleFactor;
float angle = (float) Math.toRadians(Float.parseFloat(st[4]));
float cx = Float.parseFloat(st[0]) * scaleFactor;
float cy = Float.parseFloat(st[1]) * scaleFactor;
out[2] = (int) Math.round(radius * Math.sin(angle));
out[3] = (int) Math.round(radius * Math.cos(angle));
if ((out[2] > 0) && (out[3] >= 0)) {
out[0] = Math.round(cx);
out[1] = Math.round(bBoxHeight - cy);
} else if ((out[2] >= 0) && (out[3] < 0)) {
out[0] = Math.round(cx + out[3]);
out[1] = Math.round(bBoxHeight - cy);
} else if ((out[2] <= 0) && (out[3] > 0)) {
out[0] = Math.round(cx);
out[1] = Math.round((bBoxHeight + out[2]) - cy);
} else if ((out[2] < 0) && (out[3] <= 0)) {
out[0] = Math.round(cx + out[3]);
out[1] = Math.round((bBoxHeight + out[2]) - cy);
}
return out;
}
private int[] getT3Params(int[] in) {
int[] out = new int[4];
out[0] = (int) Math.round((in[2] + in[0]) / 2);
out[1] = (int) Math.round(bBoxHeight - ((in[3] + in[1]) / 2));
out[2] =
(int) Math.round((
Math.abs(in[2] - in[0]) * Math.sin(Math.toRadians(45))
) / 2);
out[3] =
(int) Math.round((
Math.abs(in[2] - in[0]) * Math.cos(Math.toRadians(45))
) / 2);
return out;
}
private int[] getT4Params(int[] firstl, int[] secondl) {
int[] out = new int[4];
out[2] =
(int) Math.round(((secondl[2] - secondl[0]) * scaleFactor) / 2);
out[3] =
(int) Math.round(((secondl[1] - secondl[3]) * scaleFactor) / 2);
if (((secondl[2] - secondl[0]) > 0) && ((firstl[2] - firstl[0]) > 0)) {
out[0] = (int) Math.round((secondl[0] * scaleFactor) + out[2]);
out[1] =
(int) Math.round(bBoxHeight - (secondl[1] * scaleFactor)
+ out[3]);
} else if (((secondl[2] - secondl[0]) > 0)
&& ((firstl[2] - firstl[0]) < 0)) {
out[0] = (int) Math.round((secondl[0] * scaleFactor) + out[2]);
out[1] =
(int) Math.round(bBoxHeight - (secondl[1] * scaleFactor)
+ (2 * out[3]));
} else if (((secondl[2] - secondl[0]) < 0)
&& ((firstl[2] - firstl[0]) < 0)) {
out[0] =
(int) Math.round((secondl[0] * scaleFactor) + (2 * out[2]));
out[1] =
(int) Math.round(bBoxHeight - (secondl[1] * scaleFactor)
+ (2 * out[3]));
} else if (((secondl[2] - secondl[0]) < 0)
&& ((firstl[2] - firstl[0]) > 0)) {
out[0] =
(int) Math.round((secondl[0] * scaleFactor) + (2 * out[2]));
out[1] =
(int) Math.round(bBoxHeight - (secondl[1] * scaleFactor)
+ out[3]);
}
return out;
}
private Vector getPoints(String[] st, boolean cntrclk) {
double cx = Double.parseDouble(st[0]) * scaleFactor;
double cy = bBoxHeight - (Double.parseDouble(st[1]) * scaleFactor);
double radius = Double.parseDouble(st[2]) * scaleFactor;
double phi1 = 0.d;
double phi2 = 0.d;
if (cntrclk) {
phi1 = Double.parseDouble(st[4]);
phi2 = Double.parseDouble(st[3]);
} else {
phi1 = Double.parseDouble(st[3]);
phi2 = Double.parseDouble(st[4]);
}
Point2D fpt =
new Point2D.Double(cx + (
radius * Math.cos(Math.toRadians(-phi1))
), cy + (radius * Math.sin(Math.toRadians(-phi1))));
Point2D spt = new Point2D.Double(0.d, 0.d);
AffineTransform at = new AffineTransform();
at.rotate(Math.toRadians(-phi2 + phi1) / 2.d, cx, cy);
at.transform(fpt, spt);
Point2D tpt = new Point2D.Double(0.d, 0.d);
AffineTransform at1 = new AffineTransform();
at1.rotate(Math.toRadians(-phi2 + phi1), cx, cy);
at1.transform(fpt, tpt);
Vector pts = new Vector(3, 1);
pts.add(fpt);
pts.add(spt);
pts.add(tpt);
return pts;
}
private int[] getLoopPars(String[] st, String st1, boolean cntrclk) {
int[] out = new int[4];
float x = Float.parseFloat(st[0]);
float y = Float.parseFloat(st[1]);
float r = Float.parseFloat(st[2]);
int phi1 = Math.round(Float.parseFloat(st[3]));
int phi2 = Math.round(Float.parseFloat(st[4]));
if (!(st1.indexOf("%") == -1)) {
r = r - theDLSeparation(st1);
}
double alpha = 0;
if (cntrclk) {
if (phi1 > phi2) {
alpha = Math.toRadians(-phi1 + 180);
} else {
alpha = Math.toRadians(-phi2 + 180);
}
} else {
if (phi1 > phi2) {
alpha = Math.toRadians(-phi2 + 180);
} else {
alpha = Math.toRadians(-phi1 + 180);
}
}
out[2] = (int) Math.round(r * scaleFactor * Math.cos(alpha));
out[3] = (int) Math.round(r * scaleFactor * Math.sin(alpha));
if ((out[2] > 0) && (out[3] >= 0)) {
out[0] = (int) (x * scaleFactor);
out[1] = (int) (bBoxHeight - (y * scaleFactor));
} else if ((out[2] >= 0) && (out[3] < 0)) {
out[0] = (int) (x * scaleFactor);
out[1] = (int) (
bBoxHeight - Math.abs(out[3]) - (y * scaleFactor)
);
} else if ((out[2] <= 0) && (out[3] > 0)) {
out[0] = (int) ((x * scaleFactor) - Math.abs(out[2]));
out[1] = (int) (bBoxHeight - (y * scaleFactor));
} else if ((out[2] < 0) && (out[3] <= 0)) {
out[0] = (int) ((x * scaleFactor) - Math.abs(out[2]));
out[1] = (int) (
bBoxHeight - Math.abs(out[3]) - (y * scaleFactor)
);
}
return out;
}
private float getPhotonFreq(int[] looppars, float nOfWiggles) {
float offset = 0.1f;
float freq =
(float) (
(
Math.sqrt((looppars[2] * looppars[2])
+ (looppars[3] * looppars[3])) * 2 * Math.PI
) / nOfWiggles
);
freq = freq - offset;
return freq;
}
/**
* Returns the five strings s1-s5 contained in a string
* of the form " # (s1, s2) (s3, s4) (s5) * " where * can be anything
* and # doesn't contain any parenthesis.
*/
private String[] getOvalBrackets(String str) {
String[] st = new String[5];
int start = str.indexOf("(");
int comma = str.indexOf(",");
int stop = str.indexOf(")");
st[0] = str.substring(start + 1, comma);
st[1] = str.substring(comma + 1, stop);
int offset = stop + 1;
start = str.indexOf("(", offset);
comma = str.indexOf(",", offset);
stop = str.indexOf(")", offset);
st[2] = str.substring(start + 1, comma);
st[3] = str.substring(comma + 1, stop);
offset = stop + 1;
start = str.indexOf("(", offset);
stop = str.indexOf(")", offset);
st[4] = str.substring(start + 1, stop);
return st;
}
/**
* Returns the four integers xi,yi,xf,yf contained in a string
* of the form " # (xi,yi) (xf,yf) * " where * can be anything
* and # doesn't contain any parenthesis.
*/
private int[] getFourInts(String str) {
int[] ints = new int[4];
int start = str.indexOf("(");
int comma = str.indexOf(",");
int stop = str.indexOf(")");
ints[0] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[1] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
int offset = stop + 1;
start = str.indexOf("(", offset);
comma = str.indexOf(",", offset);
stop = str.indexOf(")", offset);
ints[2] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[3] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
return ints;
}
/**
* Returns the two integers xi,yi contained in a string
* of the form " # (xi,yi) * " where * can be anything
* and # doesn't contain any parenthesis.
*/
private int[] getTwoInts(String str) {
int[] ints = new int[2];
int start = str.indexOf("(");
int comma = str.indexOf(",");
int stop = str.indexOf(")");
ints[0] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[1] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
return ints;
}
/**
* Returns the four integers xi,yi,xf,yf contained in a string
* of the form " # (xi,yi) (xf,yf) * " where * can be anything
* and # doesn't contain any parenthesis.
*/
private int[] getFourInts(String str, int fromIndex) {
int[] ints = new int[4];
int start = str.indexOf("(", fromIndex);
int comma = str.indexOf(",", fromIndex);
int stop = str.indexOf(")", fromIndex);
ints[0] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[1] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
int offset = stop + 1;
start = str.indexOf("(", offset);
comma = str.indexOf(",", offset);
stop = str.indexOf(")", offset);
ints[2] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[3] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
return ints;
}
/**
* Returns the six integers x1, y1,x2,y2,x3,y3 contained in a string
* of the form " # (x1, y1) (x2,y2) (x3,y3) * " where * can be anything
* and # doesn't contain any parenthesis.
*/
private int[] getSixInts(String str) {
int[] ints = new int[6];
int start = str.indexOf("(");
int comma = str.indexOf(",");
int stop = str.indexOf(")");
ints[0] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[1] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
int offset = stop + 1;
start = str.indexOf("(", offset);
comma = str.indexOf(",", offset);
stop = str.indexOf(")", offset);
ints[2] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[3] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
offset = stop + 1;
start = str.indexOf("(", offset);
comma = str.indexOf(",", offset);
stop = str.indexOf(")", offset);
ints[4] =
(int) Math.round(Float.parseFloat(str.substring(start + 1, comma)));
ints[5] =
(int) Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
return ints;
}
private int[] getTriangleParameters(int[] coords) {
int[] out = {0, 0, 0, 0, 0, 0};
out[0] = (int) Math.round(coords[0] * scaleFactor);
out[1] = (int) Math.round(bBoxHeight - (coords[1] * scaleFactor));
out[2] = (int) Math.round(coords[2] * scaleFactor);
out[3] = (int) Math.round(bBoxHeight - (coords[3] * scaleFactor));
out[4] = (int) Math.round(coords[4] * scaleFactor);
out[5] = (int) Math.round(bBoxHeight - (coords[5] * scaleFactor));
return out;
}
private int getTeXAllign(String str) {
Vector possible = new Vector(10, 1);
possible.add("lt");
possible.add("l");
possible.add("lb");
possible.add("t");
possible.add("");
possible.add("b");
possible.add("rt");
possible.add("r");
possible.add("rb");
return possible.indexOf(str);
}
private Color getTeXColor(String str) {
int offset = str.indexOf("{\\");
int start = str.indexOf("\\", offset);
int stop = str.indexOf("$");
if ((stop > start) && (start != -1)) {
return JaxoColor.getColor(str.substring(start + 1, stop - 1));
}
return JaxoColor.BLACK;
}
private int getTeXSize(String str) {
String st;
int start = str.indexOf("\\");
int stop = str.indexOf("{", start);
if ((stop > start) && (start != -1)) {
st = str.substring(start + 1, stop);
Vector possible = new Vector(10, 1);
possible.add("tiny");
possible.add("scriptsize");
possible.add("footnotesize");
possible.add("small");
possible.add("normalsize");
possible.add("large");
possible.add("Large");
possible.add("LARGE");
possible.add("huge");
possible.add("Huge");
if (possible.indexOf(st) != -1) {
return possible.indexOf(st);
} else {
return 4;
}
} else {
return 4;
}
}
private String getTeXText(String str) {
String st;
int start = str.indexOf("$");
int stop = str.indexOf("$", start + 1);
st = str.substring(start + 1, stop);
return st;
}
/**
* Returns the two integers xi,yi contained in a string
* of the form " # (xi,yi) * " where * can be anything
* and # doesn't contain any parenthesis.
*/
private String[] getOneBracket(String str) {
String[] st = new String[2];
int start = str.indexOf("(");
int comma = str.indexOf(",");
int stop = str.indexOf(")");
st[0] = str.substring(start + 1, comma);
st[1] = str.substring(comma + 1, stop);
return st;
}
/**
* Returns the four integers xi,yi,xf,yf contained in a string
* of the form " # [String] * " where * can be anything
* and # doesn't contain any braces.
*/
private String getOneBrace(String str) {
String st = "";
int start = str.indexOf("[");
int stop = str.indexOf("]");
st = str.substring(start + 1, stop);
return st;
}
/**
* Returns the string "String" contained in a string
* of the form " # {String} * " where * can be anything
* and # doesn't contain any curly brackets.
*/
private String getOneCurl(String str) {
int start = str.indexOf("{");
int stop = str.indexOf("}");
String st = str.substring(start + 1, stop);
return st;
}
/**
* Returns the two strings s1, s2 contained in a string
* of the form " # {s1}{s2} * " where * can be anything
* and # doesn't contain any curly brackets.
*/
private String[] getTwoCurls(String str) {
String[] st = new String[2];
int start = str.indexOf("{");
int stop = str.indexOf("}");
st[0] = str.substring(start + 1, stop);
int offset = stop + 1;
start = str.indexOf("{", offset);
stop = str.indexOf("}", offset);
st[1] = str.substring(start + 1, stop);
return st;
}
/**
* Returns the three strings s1, s2, s3 contained in a string
* of the form " # {s1}{s2}{s3} * " where * can be anything
* and # doesn't contain any curly brackets.
*/
private String[] getThreeCurls(String str) {
String[] st = new String[2];
int start = str.indexOf("{");
int stop = str.indexOf("}");
st[0] = str.substring(start + 1, stop);
int offset = stop + 1;
start = str.indexOf("{", offset);
stop = str.indexOf("}", offset);
st[1] = str.substring(start + 1, stop);
offset = stop + 1;
start = str.indexOf("{", offset);
stop = str.indexOf("}", offset);
st[2] = str.substring(start + 1, stop);
return st;
}
/**
* Returns the five strings s1 - s5 contained in a string
* of the form " # (s1, s2) (s3, s4, s5) * " where * can be anything
* and # doesn't contain any parenthesis.
*/
private String[] getArcBrackets(String str) {
String[] st = new String[5];
int start = str.indexOf("(");
int comma = str.indexOf(",");
int stop = str.indexOf(")");
st[0] = str.substring(start + 1, comma);
st[1] = str.substring(comma + 1, stop);
int offset = stop + 1;
start = str.indexOf("(", offset);
int comma1 = str.indexOf(",", offset);
int comma2 = str.indexOf(",", comma1 + 1);
stop = str.indexOf(")", offset);
st[2] = str.substring(start + 1, comma1);
st[3] = str.substring(comma1 + 1, comma2);
st[4] = str.substring(comma2 + 1, stop);
return st;
}
private float theDLSeparation(String str) {
int offset = str.indexOf("%") + 1;
int start = str.indexOf("(", offset);
int stop = str.indexOf(")", offset);
float sep = Float.parseFloat(str.substring(start + 1, stop));
return sep;
}
private JaObject newVertexT4() {
int[] firstl = getFourInts(string);
int[] secondl = getFourInts(string, string.lastIndexOf("\\Line"));
int[] vertexpars = getT4Params(firstl, secondl);
JaVertexT4 newVertexT4 = new JaVertexT4();
newVertexT4.setLocation(vertexpars[0], vertexpars[1]);
newVertexT4.setRelWAndH(vertexpars[2], vertexpars[3]);
newVertexT4.setStroke(stroke);
newVertexT4.setColor(color);
return (JaObject) newVertexT4;
}
private JaObject newVertexT2() {
int[] vertexpars = getT2Params(getOvalBrackets(string));
String[] colors = getTwoCurls(string);
JaVertexT2 newVertexT2 = new JaVertexT2();
newVertexT2.setLocation(vertexpars[0], vertexpars[1]);
newVertexT2.setRelWAndH(vertexpars[3], vertexpars[2]);
newVertexT2.setStroke(stroke);
newVertexT2.setColor(JaxoColor.getColor(colors[0]));
newVertexT2.setFillColor(JaxoColor.getColor(colors[1]));
return (JaObject) newVertexT2;
}
private JaObject newFLoop(boolean arcn, boolean arrow) {
JaObject newob = null;
String[] st = getArcBrackets(string);
int phi1 = Math.round(Float.parseFloat(st[3]));
int phi2 = Math.round(Float.parseFloat(st[4]));
if (Math.abs(phi1 - phi2) >= 360) {
int[] looppars = getLoopPars(st, string, arcn);
JaFLoop newFLoop = new JaFLoop();
newFLoop.setLocation(looppars[0], looppars[1]);
newFLoop.setRelWAndH(looppars[2], looppars[3]);
newFLoop.setColor(color);
newFLoop.setStroke(stroke);
newFLoop.setArrow(arrow);
newFLoop.setFlip(arcn);
if (string.indexOf("%") == -1) {
newFLoop.setDoubleLine(false);
newFLoop.setDLSeparation(2.f);
} else {
newFLoop.setDoubleLine(true);
newFLoop.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newFLoop;
} else {
Vector pts = getPoints(st, arcn);
Point2D p0 = (Point2D) pts.elementAt(0);
Point2D p1 = (Point2D) pts.elementAt(1);
Point2D p2 = (Point2D) pts.elementAt(2);
JaFArc newFArc = new JaFArc();
newFArc.setArcPts((int) Math.round(p0.getX()),
(int) Math.round(p0.getY()), (int) Math.round(p1.getX()),
(int) Math.round(p1.getY()), (int) Math.round(p2.getX()),
(int) Math.round(p2.getY()));
newFArc.setColor(color);
newFArc.setStroke(stroke);
newFArc.setArrow(arrow);
newFArc.setFlip(arcn);
if (string.indexOf("%") == -1) {
newFArc.setDoubleLine(false);
newFArc.setDLSeparation(2.f);
} else {
newFArc.setDoubleLine(true);
newFArc.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newFArc;
}
return newob;
}
private JaObject newLine(boolean arrow) {
int[] linepars = getLineParams(getFourInts(string), string);
JaFLine newFLine = new JaFLine();
newFLine.setLocation(linepars[0], linepars[1]);
newFLine.setRelWAndH(linepars[2], linepars[3]);
newFLine.setColor(color);
newFLine.setStroke(stroke);
newFLine.setArrow(arrow);
newFLine.setFlip(false);
if (string.indexOf("%") == -1) {
newFLine.setDoubleLine(false);
newFLine.setDLSeparation(2.f);
} else {
newFLine.setDoubleLine(true);
newFLine.setDLSeparation(Math.abs(theDLSeparation(string)));
}
return (JaObject) newFLine;
}
private JaObject newCBox() {
JaObject newob = null;
if (string.indexOf("%") == -1) {
int[] boxpars = getBoxParams(getFourInts(string));
String[] colors = getTwoCurls(string);
JaBox newBox = new JaBox();
newBox.setLocation(boxpars[0], boxpars[1]);
newBox.setRelWAndH(boxpars[2], boxpars[3]);
newBox.setStroke(stroke);
newBox.setColor(JaxoColor.getColor(colors[0]));
newBox.setFillColor(JaxoColor.getColor(colors[1]));
newob = (JaObject) newBox;
} else {
int[] vertexT3pars = getT3Params(getFourInts(string));
String[] colors = getTwoCurls(string);
JaVertexT3 newVertexT3 = new JaVertexT3();
newVertexT3.setLocation(vertexT3pars[0], vertexT3pars[1]);
newVertexT3.setRelWAndH(vertexT3pars[2], vertexT3pars[3]);
newVertexT3.setColor(JaxoColor.getColor(colors[0]));
newob = (JaObject) newVertexT3;
}
return newob;
}
private JaObject newCCirc() {
String[] radcol = getThreeCurls(string);
int[] circpars = getCircParams(getTwoInts(string), radcol[0]);
JaBlob newBlob = new JaBlob();
newBlob.setLocation(circpars[0], circpars[1]);
newBlob.setRelWAndH(circpars[2], circpars[2]);
newBlob.setStroke(stroke);
newBlob.setRotAngle(0);
newBlob.setColor(JaxoColor.getColor(radcol[1]));
newBlob.setFillColor(JaxoColor.getColor(radcol[2]));
return (JaObject) newBlob;
}
private JaObject newCOval() {
int[] blobpars = getBlobParams(getOvalBrackets(string));
String[] colors = getTwoCurls(string);
JaBlob newBlob = new JaBlob();
newBlob.setLocation(blobpars[0], blobpars[1]);
newBlob.setRelWAndH(blobpars[3], blobpars[2]);
newBlob.setStroke(stroke);
newBlob.setRotAngle(-blobpars[4]);
newBlob.setColor(JaxoColor.getColor(colors[0]));
newBlob.setFillColor(JaxoColor.getColor(colors[1]));
return (JaObject) newBlob;
}
private JaObject newCTri() {
String[] colors = getTwoCurls(string);
int[] tripars = getTriangleParameters(getSixInts(string));
JaVertexT5 newVertexT5 = new JaVertexT5();
newVertexT5.setVertexPts(tripars[0], tripars[1], tripars[2],
tripars[3], tripars[4], tripars[5]);
newVertexT5.setStroke(stroke);
newVertexT5.setColor(JaxoColor.getColor(colors[0]));
newVertexT5.setFillColor(JaxoColor.getColor(colors[1]));
return (JaObject) newVertexT5;
}
private JaObject newDashArc(boolean arcn, boolean arrow) {
String[] st = getArcBrackets(string);
float dash = Float.parseFloat(getOneCurl(string)) * scaleFactor;
JaObject newob = null;
if (!arrow && !(string.indexOf("%") == -1)) {
float r = Float.parseFloat(st[2]);
dash =
(float) Math.round((dash * r) / (r + theDLSeparation(string)));
}
int phi1 = Math.round(Float.parseFloat(st[3]));
int phi2 = Math.round(Float.parseFloat(st[4]));
if (Math.abs(phi1 - phi2) >= 360) {
int[] looppars = getLoopPars(st, string, arcn);
if (dash > 5.f) {
JaSLoop newSLoop = new JaSLoop();
newSLoop.setLocation(looppars[0], looppars[1]);
newSLoop.setRelWAndH(looppars[2], looppars[3]);
newSLoop.setColor(color);
newSLoop.setStroke(stroke);
newSLoop.setArrow(arrow);
newSLoop.setFlip(arcn);
newSLoop.setDash(dash);
if (string.indexOf("%") == -1) {
newSLoop.setDoubleLine(false);
newSLoop.setDLSeparation(2.f);
} else {
newSLoop.setDoubleLine(true);
newSLoop.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newSLoop;
} else {
JaGLoop newGLoop = new JaGLoop();
newGLoop.setLocation(looppars[0], looppars[1]);
newGLoop.setRelWAndH(looppars[2], looppars[3]);
newGLoop.setColor(color);
newGLoop.setStroke(stroke);
newGLoop.setArrow(arrow);
newGLoop.setFlip(arcn);
newGLoop.setDash(dash);
if (string.indexOf("%") == -1) {
newGLoop.setDoubleLine(false);
newGLoop.setDLSeparation(2.f);
} else {
newGLoop.setDoubleLine(true);
newGLoop.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newGLoop;
}
} else {
Vector pts = getPoints(st, arcn);
if (dash > 5.f) {
JaSArc newSArc = new JaSArc();
Point2D p0 = (Point2D) pts.elementAt(0);
Point2D p1 = (Point2D) pts.elementAt(1);
Point2D p2 = (Point2D) pts.elementAt(2);
newSArc.setArcPts((int) Math.round(p0.getX()),
(int) Math.round(p0.getY()), (int) Math.round(p1.getX()),
(int) Math.round(p1.getY()), (int) Math.round(p2.getX()),
(int) Math.round(p2.getY()));
newSArc.setColor(color);
newSArc.setStroke(stroke);
newSArc.setArrow(arrow);
newSArc.setFlip(arcn);
newSArc.setDash(dash);
if (string.indexOf("%") == -1) {
newSArc.setDoubleLine(false);
newSArc.setDLSeparation(2.f);
} else {
newSArc.setDoubleLine(true);
newSArc.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newSArc;
} else {
JaGArc newGArc = new JaGArc();
Point2D p0 = (Point2D) pts.elementAt(0);
Point2D p1 = (Point2D) pts.elementAt(1);
Point2D p2 = (Point2D) pts.elementAt(2);
newGArc.setArcPts((int) Math.round(p0.getX()),
(int) Math.round(p0.getY()), (int) Math.round(p1.getX()),
(int) Math.round(p1.getY()), (int) Math.round(p2.getX()),
(int) Math.round(p2.getY()));
newGArc.setColor(color);
newGArc.setStroke(stroke);
newGArc.setArrow(arrow);
newGArc.setFlip(arcn);
newGArc.setDash(dash);
if (string.indexOf("%") == -1) {
newGArc.setDoubleLine(false);
newGArc.setDLSeparation(2.f);
} else {
newGArc.setDoubleLine(true);
newGArc.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newGArc;
}
}
return newob;
}
private JaObject newDashLine(boolean arrow) {
int[] linepars = getLineParams(getFourInts(string), string);
float dash = Float.parseFloat(getOneCurl(string)) * scaleFactor;
JaObject newob = null;
if (dash > 5.f) {
JaSLine newSLine = new JaSLine();
newSLine.setLocation(linepars[0], linepars[1]);
newSLine.setRelWAndH(linepars[2], linepars[3]);
newSLine.setColor(color);
newSLine.setStroke(stroke);
newSLine.setArrow(arrow);
newSLine.setFlip(false);
newSLine.setDash(dash);
if (string.indexOf("%") == -1) {
newSLine.setDoubleLine(false);
newSLine.setDLSeparation(2.f);
} else {
newSLine.setDoubleLine(true);
newSLine.setDLSeparation(Math.abs(theDLSeparation(string)));
}
newob = (JaObject) newSLine;
} else {
JaGLine newGLine = new JaGLine();
newGLine.setLocation(linepars[0], linepars[1]);
newGLine.setRelWAndH(linepars[2], linepars[3]);
newGLine.setColor(color);
newGLine.setStroke(stroke);
newGLine.setArrow(arrow);
newGLine.setFlip(false);
newGLine.setDash(dash);
if (string.indexOf("%") == -1) {
newGLine.setDoubleLine(false);
newGLine.setDLSeparation(2.f);
} else {
newGLine.setDoubleLine(true);
newGLine.setDLSeparation(Math.abs(theDLSeparation(string)));
}
newob = (JaObject) newGLine;
}
return newob;
}
private JaObject newGBox() {
int[] boxpars = getBoxParams(getFourInts(string));
JaBox newBox = new JaBox();
newBox.setLocation(boxpars[0], boxpars[1]);
newBox.setRelWAndH(boxpars[2], boxpars[3]);
newBox.setStroke(stroke);
newBox.setColor(color);
newBox.setFillColor(JaxoColor.getGrayScale(Float.parseFloat(getOneCurl(
string))));
return (JaObject) newBox;
}
private JaObject newGCirc() {
String[] radcol = getTwoCurls(string);
int[] circpars = getCircParams(getTwoInts(string), radcol[0]);
JaBlob newBlob = new JaBlob();
newBlob.setLocation(circpars[0], circpars[1]);
newBlob.setRelWAndH(circpars[2], circpars[2]);
newBlob.setStroke(stroke);
newBlob.setRotAngle(0);
newBlob.setColor(color);
newBlob.setFillColor(JaxoColor.getGrayScale(Float.parseFloat(radcol[1])));
return (JaObject) newBlob;
}
private JaObject newGlArc() {
JaObject newob = null;
String[] st = getArcBrackets(string);
String[] ampwig = getTwoCurls(string);
int phi1 = Math.round(Float.parseFloat(st[3]));
int phi2 = Math.round(Float.parseFloat(st[4]));
if (Math.abs(phi1 - phi2) >= 360) {
int[] looppars = getLoopPars(st, string, false);
JaGlLoop newGlLoop = new JaGlLoop();
newGlLoop.setLocation(looppars[0] - looppars[2],
looppars[1] - looppars[3]);
newGlLoop.setRelWAndH(-looppars[2], -looppars[3]);
newGlLoop.setColor(color);
newGlLoop.setStroke(stroke);
newGlLoop.setAmp(Math.round(
Float.parseFloat(ampwig[0]) * 2 * scaleFactor));
float nOfWiggles = Float.parseFloat(ampwig[1]) * scaleFactor;
newGlLoop.setFreq((float) (
(
Math.sqrt((looppars[2] * looppars[2])
+ (looppars[3] * looppars[3])) * 2 * Math.PI
) / nOfWiggles / 0.7f
));
if (string.indexOf("%") == -1) {
newGlLoop.setDoubleLine(false);
newGlLoop.setDLSeparation(2.f);
} else {
newGlLoop.setDoubleLine(true);
newGlLoop.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newGlLoop;
} else {
Vector pts = getPoints(st, false);
float r = Float.parseFloat(st[2]) * scaleFactor;
JaGlArc newGlArc = new JaGlArc();
Point2D p0 = (Point2D) pts.elementAt(0);
Point2D p1 = (Point2D) pts.elementAt(1);
Point2D p2 = (Point2D) pts.elementAt(2);
newGlArc.setArcPts((int) Math.round(p0.getX()),
(int) Math.round(p0.getY()), (int) Math.round(p1.getX()),
(int) Math.round(p1.getY()), (int) Math.round(p2.getX()),
(int) Math.round(p2.getY()));
newGlArc.setColor(color);
newGlArc.setStroke(stroke);
newGlArc.setAmp(Math.round(
Float.parseFloat(ampwig[0]) * 2 * scaleFactor));
float nOfWiggles = Float.parseFloat(ampwig[1]) * scaleFactor;
newGlArc.setFreq((float) (
(r * 2 * Math.toRadians(Math.abs((phi2 - phi1) / 2))) / (
(nOfWiggles * 0.7f) + 1.0f
)
));
if (string.indexOf("%") == -1) {
newGlArc.setDoubleLine(false);
newGlArc.setDLSeparation(2.f);
} else {
newGlArc.setDoubleLine(true);
newGlArc.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newGlArc;
}
return newob;
}
private JaObject newGlLine() {
int[] linepars = getLineParams(getFourInts(string), string);
String[] ampwig = getTwoCurls(string);
JaGlLine newGlLine = new JaGlLine();
newGlLine.setLocation(linepars[0], linepars[1]);
newGlLine.setRelWAndH(linepars[2], linepars[3]);
newGlLine.setColor(color);
newGlLine.setStroke(stroke);
newGlLine.setAmp(Math.round(
Float.parseFloat(ampwig[0]) * 2 * scaleFactor));
float nOfWiggles = Float.parseFloat(ampwig[1]) * scaleFactor;
newGlLine.setFreq((float) (
Math.sqrt((linepars[2] * linepars[2])
+ (linepars[3] * linepars[3])) / (
(nOfWiggles * 0.7f) + 1.0f
)
));
if (string.indexOf("%") == -1) {
newGlLine.setDoubleLine(false);
newGlLine.setDLSeparation(2.f);
} else {
newGlLine.setDoubleLine(true);
newGlLine.setDLSeparation(theDLSeparation(string));
}
return (JaObject) newGlLine;
}
private JaObject newGOval() {
int[] blobpars = getBlobParams(getOvalBrackets(string));
JaBlob newBlob = new JaBlob();
newBlob.setLocation(blobpars[0], blobpars[1]);
newBlob.setRelWAndH(blobpars[3], blobpars[2]);
newBlob.setStroke(stroke);
newBlob.setRotAngle(-blobpars[4]);
newBlob.setColor(color);
newBlob.setFillColor(JaxoColor.getGrayScale(Float.parseFloat(
getOneCurl(string))));
return (JaObject) newBlob;
}
private JaObject newGTri() {
int[] tripars = getTriangleParameters(getSixInts(string));
JaVertexT5 newVertexT5 = new JaVertexT5();
newVertexT5.setVertexPts(tripars[0], tripars[1], tripars[2],
tripars[3], tripars[4], tripars[5]);
newVertexT5.setStroke(stroke);
newVertexT5.setColor(color);
newVertexT5.setFillColor(JaxoColor.getGrayScale(Float.parseFloat(
getOneCurl(string))));
return (JaObject) newVertexT5;
}
private JaObject newPArc() {
JaObject newob = null;
String[] st = getArcBrackets(string);
String[] ampwig = getTwoCurls(string);
int phi1 = Math.round(Float.parseFloat(st[3]));
int phi2 = Math.round(Float.parseFloat(st[4]));
if (Math.abs(phi1 - phi2) >= 360) {
int[] looppars = getLoopPars(st, string, false);
JaPLoop newPLoop = new JaPLoop();
newPLoop.setLocation(looppars[0] - looppars[2],
looppars[1] - looppars[3]);
newPLoop.setRelWAndH(-looppars[2], -looppars[3]);
newPLoop.setColor(color);
newPLoop.setStroke(stroke);
newPLoop.setAmp(Math.round(
Float.parseFloat(ampwig[0]) * 2 * scaleFactor));
float nOfWiggles = Float.parseFloat(ampwig[1]); // * scaleFactor;
newPLoop.setFreq(getPhotonFreq(looppars, nOfWiggles));
if (string.indexOf("%") == -1) {
newPLoop.setDoubleLine(false);
newPLoop.setDLSeparation(2.f);
} else {
newPLoop.setDoubleLine(true);
newPLoop.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newPLoop;
} else {
Vector pts = getPoints(st, false);
float r = Float.parseFloat(st[2]) * scaleFactor;
JaPArc newPArc = new JaPArc();
Point2D p0 = (Point2D) pts.elementAt(0);
Point2D p1 = (Point2D) pts.elementAt(1);
Point2D p2 = (Point2D) pts.elementAt(2);
newPArc.setArcPts((int) Math.round(p0.getX()),
(int) Math.round(p0.getY()), (int) Math.round(p1.getX()),
(int) Math.round(p1.getY()), (int) Math.round(p2.getX()),
(int) Math.round(p2.getY()));
newPArc.setColor(color);
newPArc.setStroke(stroke);
newPArc.setAmp(Math.round(
Float.parseFloat(ampwig[0]) * 2 * scaleFactor));
float nOfWiggles = (Float.parseFloat(ampwig[1]) - 0.5f);
newPArc.setFreq((float) (
(r * 2 * Math.toRadians(Math.abs((phi2 - phi1) / 2))) / nOfWiggles
));
if (string.indexOf("%") == -1) {
newPArc.setDoubleLine(false);
newPArc.setDLSeparation(2.f);
} else {
newPArc.setDoubleLine(true);
newPArc.setDLSeparation(theDLSeparation(string));
}
newob = (JaObject) newPArc;
}
return newob;
}
private JaObject newPLine() {
int[] linepars = getLineParams(getFourInts(string), string);
String[] ampwig = getTwoCurls(string);
JaPLine newPLine = new JaPLine();
newPLine.setLocation(linepars[0], linepars[1]);
newPLine.setRelWAndH(linepars[2], linepars[3]);
newPLine.setColor(color);
newPLine.setStroke(stroke);
newPLine.setAmp(Math.round(
Float.parseFloat(ampwig[0]) * 2 * scaleFactor));
float nOfWiggles = Float.parseFloat(ampwig[1]);
int symm = Math.round(nOfWiggles);
if ((symm - nOfWiggles) > 0.001) {
newPLine.setSymm(true);
newPLine.setFreq((float) (
Math.sqrt((linepars[2] * linepars[2])
+ (linepars[3] * linepars[3])) / (nOfWiggles - 0.5)
));
} else {
newPLine.setSymm(false);
newPLine.setFreq((float) (
Math.sqrt((linepars[2] * linepars[2])
+ (linepars[3] * linepars[3])) / nOfWiggles
));
}
if (string.indexOf("%") == -1) {
newPLine.setDoubleLine(false);
newPLine.setDLSeparation(2.f);
} else {
newPLine.setDoubleLine(true);
newPLine.setDLSeparation(theDLSeparation(string));
}
return (JaObject) newPLine;
}
private JaObject newText() {
int[] pos = getT1Params(getOneBracket(string));
int allign = getTeXAllign(getOneBrace(string));
int size = getTeXSize(getOneCurl(string));
String text = getTeXText(string);
Color txtcolor = getTeXColor(getOneCurl(string));
JaLatexText newText = new JaLatexText();
newText.setX(pos[0]);
newText.setY(pos[1]);
newText.setColor(txtcolor);
newText.setTextString(text);
newText.setAllign(allign);
newText.setLatexFS(size);
newText.createLatexPanel();
return (JaObject) newText;
}
private JaObject newVertexT1() {
int[] center = getT1Params(getOneBracket(string));
String radius = getOneCurl(string);
JaVertexT1 newVertexT1 = new JaVertexT1();
newVertexT1.setLocation(center[0], center[1]);
newVertexT1.setRelWAndH((int) Math.round(
(Float.parseFloat(radius) * scaleFactor) / Math.sqrt(2)),
(int) Math.round(
(Float.parseFloat(radius) * scaleFactor) / Math.sqrt(2)));
newVertexT1.setColor(JaxoColor.BLACK);
return (JaObject) newVertexT1;
}
private JaObject newVertexT6() {
int[] tripars = getTriangleParameters(getSixInts(string));
String[] colors = getTwoCurls(string);
JaVertexT6 newVertexT6 = new JaVertexT6();
double length = (double) ((tripars[4] - tripars[0]) / 2.d);
newVertexT6.setLocation((int) Math.round(tripars[0] + length),
tripars[1]);
newVertexT6.setRelWAndH((int) Math.round(
length * 0.5d * Math.sqrt(2.d)),
(int) Math.round(length * 0.5d * Math.sqrt(2.d)));
newVertexT6.setStroke(stroke);
newVertexT6.setColor(JaxoColor.getColor(colors[0]));
return (JaObject) newVertexT6;
}
private JaObject newZigZagLine() {
int[] linepars = getLineParams(getFourInts(string), string);
String[] ampwig = getTwoCurls(string);
JaZigZagLine newZigZagLine = new JaZigZagLine();
newZigZagLine.setLocation(linepars[0], linepars[1]);
newZigZagLine.setRelWAndH(linepars[2], linepars[3]);
newZigZagLine.setColor(color);
newZigZagLine.setStroke(stroke);
newZigZagLine.setAmp(Math.round(
Float.parseFloat(ampwig[0]) * 2 * scaleFactor));
float nOfWiggles = Float.parseFloat(ampwig[1]) * scaleFactor;
int symm = Math.round(nOfWiggles);
if ((symm - nOfWiggles) > 0.001) {
newZigZagLine.setSymm(true);
newZigZagLine.setFreq((float) (
Math.sqrt((linepars[2] * linepars[2])
+ (linepars[3] * linepars[3])) / (nOfWiggles - 0.5)
));
} else {
newZigZagLine.setSymm(false);
newZigZagLine.setFreq((float) (
Math.sqrt((linepars[2] * linepars[2])
+ (linepars[3] * linepars[3])) / nOfWiggles
));
}
if (string.indexOf("%") == -1) {
newZigZagLine.setDoubleLine(false);
newZigZagLine.setDLSeparation(2.f);
} else {
newZigZagLine.setDoubleLine(true);
newZigZagLine.setDLSeparation(theDLSeparation(string));
}
return (JaObject) newZigZagLine;
}
}
Ads help maintain this website.