PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/JaxoDraw-2.0-1/src/main/java/net/sf/jaxodraw/io/imports/JaxoAxodraw.java

#
Java | 1714 lines | 1476 code | 116 blank | 122 comment | 204 complexity | 32e40a9eaf36ac5017ac2ac6d37b2db0 MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /**
  2. * Licensed under GPL. For more information, see
  3. * http://jaxodraw.sourceforge.net/license.html
  4. * or the LICENSE file in the jaxodraw distribution.
  5. */
  6. package net.sf.jaxodraw.io.imports;
  7. import java.awt.Color;
  8. import java.awt.geom.Point2D;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import net.sf.jaxodraw.object.JaxoObject;
  12. import net.sf.jaxodraw.object.JaxoObjectFactory;
  13. import net.sf.jaxodraw.util.JaxoColor;
  14. import net.sf.jaxodraw.util.JaxoConstants;
  15. /** Defines a number of axodraw LaTeX commands and all the methods to convert
  16. * them into JaxoObjects. This is responsible for the import option.
  17. * @since 2.0
  18. */
  19. public class JaxoAxodraw {
  20. private static final String[] KNOWN_COMMANDS =
  21. {
  22. "\\ArrowArcn", "\\ArrowArc", "\\ArrowLine", "\\CArc", "\\CBox",
  23. "\\CCirc", "\\COval", "\\CTri", "\\DashArrowArcn", "\\DashArrowArc",
  24. "\\DashArrowLine", "\\DashCArc", "\\DashLine", "\\GBox", "\\GCirc",
  25. "\\GlueArc", "\\Gluon", "\\GOval", "\\GTri", "\\Line",
  26. "\\LongArrowArcn", "\\LongArrowArc", "\\LongArrow", "\\PhotonArc",
  27. "\\Photon", "\\SetColor", "\\SetWidth", "\\Text", "\\Vertex",
  28. "\\ZigZag", "\\EBox", "\\Oval", "\\ETri"
  29. };
  30. private static final int N_OF_COMMANDS = KNOWN_COMMANDS.length;
  31. private static final String[] REQUIRED_COMMANDS =
  32. {"\\documentclass", "\\begin{document}", "\\begin{picture}"};
  33. private static final int N_OF_REQUIRED = REQUIRED_COMMANDS.length;
  34. private final boolean[] isValid = new boolean[3];
  35. private String string = "";
  36. private int index;
  37. private Color color = JaxoColor.BLACK;
  38. private float stroke = 0.5f;
  39. private float scaleFactor = 1.f; // default, will be set later
  40. private String comment = "";
  41. private float bBoxHeight; // set when a \begin{picture} command is read
  42. private final List packageList;
  43. /** Constructor: Initializes the list of Latex packages
  44. * (axodraw and color).
  45. */
  46. public JaxoAxodraw() {
  47. this.packageList = new ArrayList(3);
  48. packageList.add("axodraw");
  49. packageList.add("color");
  50. }
  51. /**
  52. * Returns a JaxoObject corresponding to a axodraw command.
  53. *
  54. * @param newString One line of a latex file
  55. * @return A JaxoObject the corresponds to the axodraw command
  56. * of the input line, or null, if nothing corresponds
  57. */
  58. public JaxoObject getJaxoObject(String newString) {
  59. this.string = newString;
  60. if (!isValidJaxoCommand(string)) {
  61. return null;
  62. }
  63. JaxoObject newOb = null;
  64. if (index == -5) { // Circle cross unfilled
  65. newOb = newVertexT2Unfilled();
  66. } else if (index == -4) { // Circle cross gray
  67. newOb = newVertexT2Gray();
  68. } else if (index == -3) { // Diamond
  69. newOb = newVertexT6();
  70. } else if (index == -2) { // Cross
  71. newOb = newVertexT4();
  72. } else if (index == -1) { // Circle Cross
  73. newOb = newVertexT2();
  74. } else if (index == getIndex("\\ArrowArcn")) { // ArrowArcn
  75. newOb = newFLoop(true, true, false);
  76. } else if (index == getIndex("\\ArrowArc")) { // ArrowArc
  77. newOb = newFLoop(false, true, false);
  78. } else if (index == getIndex("\\ArrowLine")) { // ArrowLine
  79. newOb = newLine(true, false);
  80. } else if (index == getIndex("\\CArc")) { // CArc
  81. newOb = newFLoop(false, false, false);
  82. } else if (index == getIndex("\\CBox")) { // CBox
  83. newOb = newCBox();
  84. } else if (index == getIndex("\\CCirc")) { // CCirc
  85. newOb = newCCirc();
  86. } else if (index == getIndex("\\COval")) { // COval
  87. newOb = newCOval();
  88. } else if (index == getIndex("\\CTri")) { // CTri
  89. newOb = newCTri();
  90. } else if (index == getIndex("\\DashArrowArcn")) { // DashArrowArcn
  91. newOb = newDashArc(true, true);
  92. } else if (index == getIndex("\\DashArrowArc")) { // DashArrowArc
  93. newOb = newDashArc(false, true);
  94. } else if (index == getIndex("\\DashArrowLine")) { // DashArrowLine
  95. newOb = newDashLine(true);
  96. } else if (index == getIndex("\\DashCArc")) { // DashCArc
  97. newOb = newDashArc(false, false);
  98. } else if (index == getIndex("\\DashLine")) { // DashLine
  99. newOb = newDashLine(false);
  100. } else if (index == getIndex("\\GBox")) { // GBox
  101. newOb = newGBox();
  102. } else if (index == getIndex("\\GCirc")) { // GCirc
  103. newOb = newGCirc();
  104. } else if (index == getIndex("\\GlueArc")) { // GlueArc
  105. newOb = newGlArc();
  106. } else if (index == getIndex("\\Gluon")) { // Gluon
  107. newOb = newGlLine();
  108. } else if (index == getIndex("\\GOval")) { // GOval
  109. newOb = newGOval();
  110. } else if (index == getIndex("\\GTri")) { // GTri
  111. newOb = newGTri();
  112. } else if (index == getIndex("\\Line")) { // Line
  113. newOb = newLine(false, false);
  114. } else if (index == getIndex("\\LongArrowArcn")) { // ArrowArc with clockwise arrow at the end
  115. newOb = newFLoop(true, true, true);
  116. } else if (index == getIndex("\\LongArrowArc")) { // ArrowArc with counterclockwise arrow at the end
  117. newOb = newFLoop(false, true, true);
  118. } else if (index == getIndex("\\LongArrow")) { // ArrowLine with arrow at the end
  119. newOb = newLine(true, true);
  120. } else if (index == getIndex("\\PhotonArc")) { // PhotonArc
  121. newOb = newPArc();
  122. } else if (index == getIndex("\\Photon")) { // Photon
  123. newOb = newPLine();
  124. } else if (index == getIndex("\\SetColor")) { // SetColor
  125. this.color = JaxoColor.getColor(getOneCurl(string));
  126. } else if (index == getIndex("\\SetWidth")) { // SetWidth
  127. this.stroke = Float.parseFloat(getOneCurl(string));
  128. } else if (index == getIndex("\\Text")) { // Text
  129. newOb = newText();
  130. } else if (index == getIndex("\\Vertex")) { // Vertex
  131. newOb = newVertexT1();
  132. } else if (index == getIndex("\\ZigZag")) { // ZigZag
  133. newOb = newZigZagLine();
  134. } else if (index == getIndex("\\EBox")) { // unfilled Box
  135. newOb = newEBox();
  136. } else if (index == getIndex("\\Oval")) { // unfilled Blob
  137. newOb = newOval();
  138. } else if (index == getIndex("\\ETri")) { // unfilled vertex T5
  139. newOb = newETri();
  140. }
  141. return newOb;
  142. }
  143. /**
  144. * Checks whether the given string starts with one of "\documentclass",
  145. * "\begin{document}" or "\begin{picture}".
  146. *
  147. * @param newString The input string.
  148. */
  149. public final void checkRequired(String newString) {
  150. this.string = newString;
  151. if (string.startsWith("\\usepackage")) {
  152. addPackage(getOneCurl(string));
  153. } else if (string.startsWith("%%JaxoComment:")) {
  154. this.comment = string.replaceFirst("%%JaxoComment:", "").trim();
  155. } else if (string.startsWith("%%JaxoScale")) {
  156. this.scaleFactor = Float.parseFloat(getOneCurl(string));
  157. } else {
  158. boolean isRequiredCommand = false;
  159. int i = 0;
  160. while (!string.startsWith(REQUIRED_COMMANDS[i])
  161. && (i < (N_OF_REQUIRED - 1))) {
  162. i++;
  163. }
  164. if ((i == (N_OF_REQUIRED - 1))
  165. && !string.startsWith(REQUIRED_COMMANDS[i])) {
  166. i++;
  167. }
  168. isRequiredCommand = (i < N_OF_REQUIRED);
  169. if (isRequiredCommand) {
  170. isValid[i] = true;
  171. if (i == 2) { // read the \begin(picture) parameters
  172. int[] pic = getTwoInts(string);
  173. this.bBoxHeight = (float) pic[1] * getScaleFactor();
  174. }
  175. }
  176. }
  177. }
  178. /**
  179. * Returns an array that indicates which required LaTeX commands
  180. * were found.
  181. *
  182. * @return An array of three boolean variables, the first is true
  183. * if "\documentclass" was found, the second is true if
  184. * "\begin{document}" was found, the third is true if
  185. * "\begin{picture}" was found
  186. */
  187. public final boolean[] getValid() {
  188. int length = isValid.length;
  189. boolean[] newArray = new boolean[length];
  190. System.arraycopy(isValid, 0, newArray, 0, length);
  191. return newArray;
  192. }
  193. /**
  194. * Returns the current list of LaTeX packages included in the graph.
  195. *
  196. * @return A List that contains strings of latex packages.
  197. */
  198. public final List getPackages() {
  199. return packageList;
  200. }
  201. /**
  202. * Adds a latex package if it is not already contained in the package list.
  203. *
  204. * @param pack the package to add.
  205. */
  206. public final void addPackage(String pack) {
  207. if (!this.packageList.contains(pack)) {
  208. this.packageList.add(pack);
  209. }
  210. }
  211. /**
  212. * Removes a latex package if it is contained in the package list.
  213. *
  214. * @param pack the package to remove.
  215. * @return true if the list contained the package, ie the list was modified.
  216. */
  217. public final boolean removePackage(String pack) {
  218. return this.packageList.remove(pack);
  219. }
  220. /**
  221. * Returns the comment (description) of this axodraw object.
  222. *
  223. * @return The axodraw comment
  224. */
  225. public final String getComment() {
  226. return comment;
  227. }
  228. /** Returns the scale factor of this axodraw object.
  229. * @return The axodraw scale factor.
  230. */
  231. public final float getScaleFactor() {
  232. return scaleFactor;
  233. }
  234. //
  235. // private
  236. //
  237. private boolean isValidJaxoCommand(String s) {
  238. int i = 0;
  239. while (!s.startsWith(KNOWN_COMMANDS[i]) && (i < (N_OF_COMMANDS - 1))) {
  240. i++;
  241. }
  242. if ((i == (N_OF_COMMANDS - 1)) && !s.startsWith(KNOWN_COMMANDS[i])) {
  243. i++;
  244. }
  245. this.index = i;
  246. // check for CircleCross, Cross vertex and diamonds
  247. if (i == getIndex("\\COval")) {
  248. if (s.indexOf("\\Line", 6) > 0) {
  249. this.index = -1;
  250. }
  251. } else if (i == getIndex("\\GOval")) {
  252. if (s.indexOf("\\Line", 6) > 0) {
  253. this.index = -4;
  254. }
  255. } else if (i == getIndex("\\Line")) {
  256. if ((s.indexOf("\\Line", 6) > 0) && (s.indexOf('%') == -1)) {
  257. this.index = -2;
  258. }
  259. } else if (i == getIndex("\\CTri")) {
  260. if (s.indexOf("\\CTri", 6) > 0) {
  261. this.index = -3;
  262. }
  263. } else if (i == getIndex("\\Oval")) {
  264. if (s.indexOf("\\Line", 6) > 0) {
  265. this.index = -5;
  266. }
  267. }
  268. return (i < N_OF_COMMANDS);
  269. }
  270. private int getIndex(String s) {
  271. int i = 0;
  272. while ((KNOWN_COMMANDS[i].compareTo(s) != 0)
  273. && (i < (N_OF_COMMANDS - 1))) {
  274. i++;
  275. }
  276. if (KNOWN_COMMANDS[i].compareTo(s) == 0) {
  277. return i;
  278. } else {
  279. return N_OF_COMMANDS;
  280. }
  281. }
  282. /*
  283. private String getLatexCommand(int i) {
  284. if (i < N_OF_COMMANDS) {
  285. return KNOWN_COMMANDS[i];
  286. } else {
  287. return "?";
  288. }
  289. }
  290. private boolean isAxodrawCommand(String s) {
  291. int i = getIndex(s);
  292. return (i < N_OF_COMMANDS);
  293. }
  294. */
  295. protected int[] getLineParams(int[] in, String st) {
  296. // xi = in[0], yi = in[1], xf = in[2], yf = in[3],
  297. int[] out = new int[4];
  298. out[0] = Math.round(in[0] * getScaleFactor());
  299. out[1] = Math.round(getBBoxHeight() - (in[1] * getScaleFactor()));
  300. out[2] = Math.round((in[2] - in[0]) * getScaleFactor());
  301. out[3] = Math.round((in[1] - in[3]) * getScaleFactor());
  302. if (!(st.indexOf('%') == -1)) {
  303. double theta =
  304. Math.atan2((in[1] - in[3]) * getScaleFactor(),
  305. (in[2] - in[0]) * getScaleFactor());
  306. float dlSep = theDLSeparation(st);
  307. out[0] = Math.round(out[0] - (float) (dlSep * Math.sin(theta)));
  308. out[1] = Math.round(out[1] + (float) (dlSep * Math.cos(theta)));
  309. }
  310. return out;
  311. }
  312. private int[] getBoxParams(int[] in) {
  313. // xi = in[0], yi = in[1], xf = in[2], yf = in[3],
  314. int[] out = new int[4];
  315. out[2] = Math.round((in[2] - in[0]) * getScaleFactor());
  316. out[3] = Math.round((in[3] - in[1]) * getScaleFactor());
  317. out[0] = Math.round(in[0] * getScaleFactor());
  318. out[1] = Math.round(getBBoxHeight() - (in[3] * getScaleFactor()));
  319. return out;
  320. }
  321. private int[] getCircParams(int[] in, String rad) {
  322. int[] out = new int[3];
  323. out[0] = Math.round(in[0] * getScaleFactor());
  324. out[1] = Math.round(getBBoxHeight() - (in[1] * getScaleFactor()));
  325. out[2] = Math.round(Float.parseFloat(rad) * getScaleFactor());
  326. return out;
  327. }
  328. private int[] getBlobParams(String[] in) {
  329. // xi = in[0], yi = in[1], xf = in[2], yf = in[3],
  330. int[] out = new int[5];
  331. out[2] = Math.round(Float.parseFloat(in[2]) * getScaleFactor());
  332. out[3] = Math.round(Float.parseFloat(in[3]) * getScaleFactor());
  333. out[0] = Math.round(Float.parseFloat(in[0]) * getScaleFactor());
  334. out[1] =
  335. Math.round(getBBoxHeight() - (Float.parseFloat(in[1]) * getScaleFactor()));
  336. out[4] = Math.round(Float.parseFloat(in[4]));
  337. return out;
  338. }
  339. private int[] getT1Params(String[] st) {
  340. int[] out = new int[2];
  341. float x = Float.parseFloat(st[0]);
  342. float y = Float.parseFloat(st[1]);
  343. out[0] = Math.round(x * getScaleFactor());
  344. out[1] = Math.round(getBBoxHeight() - (y * getScaleFactor()));
  345. return out;
  346. }
  347. private int[] getT2Params(String[] st) {
  348. int[] out = new int[4];
  349. float radius = Float.parseFloat(st[2]) * getScaleFactor();
  350. float angle = (float) Math.toRadians(Float.parseFloat(st[4]));
  351. float cx = Float.parseFloat(st[0]) * getScaleFactor();
  352. float cy = Float.parseFloat(st[1]) * getScaleFactor();
  353. out[2] = (int) Math.round(radius * Math.sin(angle));
  354. out[3] = (int) Math.round(radius * Math.cos(angle));
  355. if ((out[2] > 0) && (out[3] >= 0)) {
  356. out[0] = Math.round(cx);
  357. out[1] = Math.round(getBBoxHeight() - cy);
  358. } else if ((out[2] >= 0) && (out[3] < 0)) {
  359. out[0] = Math.round(cx + out[3]);
  360. out[1] = Math.round(getBBoxHeight() - cy);
  361. } else if ((out[2] <= 0) && (out[3] > 0)) {
  362. out[0] = Math.round(cx);
  363. out[1] = Math.round((getBBoxHeight() + out[2]) - cy);
  364. } else if ((out[2] < 0) && (out[3] <= 0)) {
  365. out[0] = Math.round(cx + out[3]);
  366. out[1] = Math.round((getBBoxHeight() + out[2]) - cy);
  367. }
  368. return out;
  369. }
  370. private int[] getT3Params(int[] in) {
  371. int[] out = new int[4];
  372. out[0] = Math.round((in[2] + in[0]) / 2.f);
  373. out[1] = Math.round(getBBoxHeight() - ((in[3] + in[1]) / 2.f));
  374. out[2] =
  375. (int) Math.round((
  376. Math.abs(in[2] - in[0]) * Math.sin(Math.toRadians(45))
  377. ) / 2);
  378. out[3] =
  379. (int) Math.round((
  380. Math.abs(in[2] - in[0]) * Math.cos(Math.toRadians(45))
  381. ) / 2);
  382. return out;
  383. }
  384. protected int[] getT4Params(int[] firstl, int[] secondl) {
  385. int[] out = new int[4];
  386. out[2] = Math.round(((secondl[2] - secondl[0]) * getScaleFactor()) / 2);
  387. out[3] = Math.round(((secondl[1] - secondl[3]) * getScaleFactor()) / 2);
  388. if (((secondl[2] - secondl[0]) > 0) && ((firstl[2] - firstl[0]) > 0)) {
  389. out[0] = Math.round((secondl[0] * getScaleFactor()) + out[2]);
  390. out[1] =
  391. Math.round(getBBoxHeight() - (secondl[1] * getScaleFactor()) + out[3]);
  392. } else if (((secondl[2] - secondl[0]) > 0)
  393. && ((firstl[2] - firstl[0]) < 0)) {
  394. out[0] = Math.round((secondl[0] * getScaleFactor()) + out[2]);
  395. out[1] =
  396. Math.round(getBBoxHeight() - (secondl[1] * getScaleFactor())
  397. + (2 * out[3]));
  398. } else if (((secondl[2] - secondl[0]) < 0)
  399. && ((firstl[2] - firstl[0]) < 0)) {
  400. out[0] = Math.round((secondl[0] * getScaleFactor()) + (2 * out[2]));
  401. out[1] =
  402. Math.round(getBBoxHeight() - (secondl[1] * getScaleFactor())
  403. + (2 * out[3]));
  404. } else if (((secondl[2] - secondl[0]) < 0)
  405. && ((firstl[2] - firstl[0]) > 0)) {
  406. out[0] = Math.round((secondl[0] * getScaleFactor()) + (2 * out[2]));
  407. out[1] =
  408. Math.round(getBBoxHeight() - (secondl[1] * getScaleFactor()) + out[3]);
  409. }
  410. return out;
  411. }
  412. protected Point2D[] getArcPoints(String[] st, boolean clock) {
  413. double cx = Double.parseDouble(st[0]) * getScaleFactor();
  414. double cy = getBBoxHeight() - (Double.parseDouble(st[1]) * getScaleFactor());
  415. double radius = Double.parseDouble(st[2]) * getScaleFactor();
  416. double phi1 = Double.parseDouble(st[3]);
  417. double phi2 = Double.parseDouble(st[4]);
  418. Point2D.Double cp = new Point2D.Double(cx, cy);
  419. Point2D.Double fpt =
  420. new Point2D.Double(cx + (
  421. radius * Math.cos(Math.toRadians(-phi1))
  422. ), cy + (radius * Math.sin(Math.toRadians(-phi1))));
  423. Point2D.Double tpt = new Point2D.Double(cx + (
  424. radius * Math.cos(Math.toRadians(-phi2))
  425. ), cy + (radius * Math.sin(Math.toRadians(-phi2))));
  426. Point2D.Double spt = getSecondArcPoint(cp, fpt, tpt, clock);
  427. return new Point2D[] {fpt, spt, tpt};
  428. }
  429. private Point2D.Double getSecondArcPoint(Point2D.Double cp,
  430. Point2D.Double p1, Point2D.Double p3, boolean clock) {
  431. double rsq = ((p1.x - cp.x) * (p1.x - cp.x)) + ((p1.y - cp.y) * (p1.y - cp.y));
  432. // to get the mid-arc point, we intersect the circle with the
  433. // perpendicular of the line P1-P3 going through the point between them
  434. double x13 = (p3.x + p1.x) / 2.d;
  435. double y13 = (p3.y + p1.y) / 2.d;
  436. double px1, px2, py1, py2;
  437. if (Math.round(p1.x) == Math.round(p3.x)) {
  438. py1 = y13;
  439. py2 = y13;
  440. px1 = cp.x - Math.sqrt(rsq - ((y13 - cp.y) * (y13 - cp.y)));
  441. px2 = cp.x + Math.sqrt(rsq - ((y13 - cp.y) * (y13 - cp.y)));
  442. } else if (Math.round(p1.y) == Math.round(p3.y)) {
  443. px1 = x13;
  444. px2 = x13;
  445. py1 = cp.y - Math.sqrt(rsq - ((x13 - cp.x) * (x13 - cp.x)));
  446. py2 = cp.y + Math.sqrt(rsq - ((x13 - cp.x) * (x13 - cp.x)));
  447. } else {
  448. double ma = (p3.y - p1.y) / (p3.x - p1.x);
  449. double a = 1.d + (1 / ma / ma);
  450. double b =
  451. ((2 * cp.y) / ma) - (2 * cp.x) - ((2 * y13) / ma)
  452. - ((2 * x13) / ma / ma);
  453. double c =
  454. (
  455. (
  456. (cp.x * cp.x) + ((x13 * x13) / ma / ma) + (y13 * y13)
  457. + ((2 * y13 * x13) / ma)
  458. ) - ((2 * cp.y * x13) / ma) - (2 * cp.y * y13)
  459. + (cp.y * cp.y)
  460. ) - rsq;
  461. double rad = Math.sqrt((b * b) - (4 * a * c));
  462. px1 = (-b + rad) / 2 / a;
  463. px2 = (-b - rad) / 2 / a;
  464. py1 = (-(px1 - x13) / ma) + y13;
  465. py2 = (-(px2 - x13) / ma) + y13;
  466. }
  467. // there are two solutions: (px1, py1) and (px2, py2),
  468. // we want the one that is in clock (parameter) direction
  469. double px = px1;
  470. double py = py1;
  471. double cross = (p1.x - cp.x) * (py1 - cp.y) - (p1.y - cp.y) * (px1 - cp.x);
  472. boolean cl = (cross < 0);
  473. if (cl == clock) {
  474. px = px2;
  475. py = py2;
  476. }
  477. return new Point2D.Double(px, py);
  478. }
  479. protected int[] getLoopPars(String[] st, String st1, boolean cntrclk) {
  480. int[] out = new int[4];
  481. float x = Float.parseFloat(st[0]);
  482. float y = Float.parseFloat(st[1]);
  483. float r = Float.parseFloat(st[2]);
  484. int phi1 = Math.round(Float.parseFloat(st[3]));
  485. int phi2 = Math.round(Float.parseFloat(st[4]));
  486. if (!(st1.indexOf('%') == -1)) {
  487. r = r - theDLSeparation(st1);
  488. }
  489. double alpha = 0;
  490. if (cntrclk) {
  491. if (phi1 > phi2) {
  492. alpha = Math.toRadians(-phi1 + 180);
  493. } else {
  494. alpha = Math.toRadians(-phi2 + 180);
  495. }
  496. } else {
  497. if (phi1 > phi2) {
  498. alpha = Math.toRadians(-phi2 + 180);
  499. } else {
  500. alpha = Math.toRadians(-phi1 + 180);
  501. }
  502. }
  503. out[0] = (int) (x * getScaleFactor());
  504. out[1] = (int) (getBBoxHeight() - (y * getScaleFactor()));
  505. out[2] = (int) Math.round(r * getScaleFactor() * Math.cos(alpha));
  506. out[3] = (int) Math.round(r * getScaleFactor() * Math.sin(alpha));
  507. return out;
  508. }
  509. /**
  510. * Returns the five strings s1-s5 contained in a string
  511. * of the form " # (s1, s2) (s3, s4) (s5) * " where * can be anything
  512. * and # doesn't contain any parenthesis.
  513. */
  514. private String[] getOvalBrackets(String str) {
  515. String[] st = new String[5];
  516. int start = str.indexOf('(');
  517. int comma = str.indexOf(',', start);
  518. int stop = str.indexOf(')', start);
  519. st[0] = str.substring(start + 1, comma);
  520. st[1] = str.substring(comma + 1, stop);
  521. int offset = stop + 1;
  522. start = str.indexOf('(', offset);
  523. comma = str.indexOf(',', offset);
  524. stop = str.indexOf(')', offset);
  525. st[2] = str.substring(start + 1, comma);
  526. st[3] = str.substring(comma + 1, stop);
  527. offset = stop + 1;
  528. start = str.indexOf('(', offset);
  529. stop = str.indexOf(')', offset);
  530. st[4] = str.substring(start + 1, stop);
  531. return st;
  532. }
  533. /**
  534. * Returns the four integers xi,yi,xf,yf contained in a string
  535. * of the form " # (xi,yi) (xf,yf) * " where * can be anything
  536. * and # doesn't contain any parenthesis.
  537. *
  538. * @param str the string.
  539. * @return the four ints.
  540. */
  541. protected int[] getFourInts(String str) {
  542. return getFourInts(str, 0);
  543. }
  544. /**
  545. * Returns the two integers xi,yi contained in a string
  546. * of the form " # (xi,yi) * " where * can be anything
  547. * and # doesn't contain any parenthesis.
  548. *
  549. * @param str the string.
  550. * @return the two ints.
  551. */
  552. protected int[] getTwoInts(String str) {
  553. int[] ints = new int[2];
  554. int start = str.indexOf('(');
  555. int comma = str.indexOf(',', start);
  556. int stop = str.indexOf(')', start);
  557. ints[0] =
  558. Math.round(Float.parseFloat(str.substring(start + 1, comma)));
  559. ints[1] = Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
  560. return ints;
  561. }
  562. /**
  563. * Returns the four integers xi,yi,xf,yf contained in a string
  564. * of the form " # (xi,yi) (xf,yf) * " where * can be anything
  565. * and # doesn't contain any parenthesis.
  566. *
  567. * @param str the string.
  568. * @param fromIndex the starting index.
  569. * @return the four ints.
  570. */
  571. protected int[] getFourInts(String str, int fromIndex) {
  572. int[] ints = new int[4];
  573. int start = str.indexOf('(', fromIndex);
  574. int comma = str.indexOf(',', start);
  575. int stop = str.indexOf(')', start);
  576. ints[0] =
  577. Math.round(Float.parseFloat(str.substring(start + 1, comma)));
  578. ints[1] = Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
  579. int offset = stop + 1;
  580. start = str.indexOf('(', offset);
  581. comma = str.indexOf(',', offset);
  582. stop = str.indexOf(')', offset);
  583. ints[2] =
  584. Math.round(Float.parseFloat(str.substring(start + 1, comma)));
  585. ints[3] = Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
  586. return ints;
  587. }
  588. /**
  589. * Returns the six integers x1, y1,x2,y2,x3,y3 contained in a string
  590. * of the form " # (x1, y1) (x2,y2) (x3,y3) * " where * can be anything
  591. * and # doesn't contain any parenthesis.
  592. *
  593. * @param str the string.
  594. * @return the six ints.
  595. */
  596. protected int[] getSixInts(String str) {
  597. int[] ints = new int[6];
  598. int start = str.indexOf('(');
  599. int comma = str.indexOf(',', start);
  600. int stop = str.indexOf(')', start);
  601. ints[0] =
  602. Math.round(Float.parseFloat(str.substring(start + 1, comma)));
  603. ints[1] = Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
  604. int offset = stop + 1;
  605. start = str.indexOf('(', offset);
  606. comma = str.indexOf(',', offset);
  607. stop = str.indexOf(')', offset);
  608. ints[2] =
  609. Math.round(Float.parseFloat(str.substring(start + 1, comma)));
  610. ints[3] = Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
  611. offset = stop + 1;
  612. start = str.indexOf('(', offset);
  613. comma = str.indexOf(',', offset);
  614. stop = str.indexOf(')', offset);
  615. ints[4] =
  616. Math.round(Float.parseFloat(str.substring(start + 1, comma)));
  617. ints[5] = Math.round(Float.parseFloat(str.substring(comma + 1, stop)));
  618. return ints;
  619. }
  620. private int[] getTriangleParameters(int[] coords) {
  621. int[] out = {0, 0, 0, 0, 0, 0};
  622. out[0] = Math.round(coords[0] * getScaleFactor());
  623. out[1] = Math.round(getBBoxHeight() - (coords[1] * getScaleFactor()));
  624. out[2] = Math.round(coords[2] * getScaleFactor());
  625. out[3] = Math.round(getBBoxHeight() - (coords[3] * getScaleFactor()));
  626. out[4] = Math.round(coords[4] * getScaleFactor());
  627. out[5] = Math.round(getBBoxHeight() - (coords[5] * getScaleFactor()));
  628. return out;
  629. }
  630. private int getTeXAllign(String str) {
  631. ArrayList possible = new ArrayList(9);
  632. possible.add("lt");
  633. possible.add("l");
  634. possible.add("lb");
  635. possible.add("t");
  636. possible.add("");
  637. possible.add("b");
  638. possible.add("rt");
  639. possible.add("r");
  640. possible.add("rb");
  641. return possible.indexOf(str);
  642. }
  643. private Color getTeXColor(String str) {
  644. int offset = str.indexOf("{\\");
  645. int start = str.indexOf("\\", offset);
  646. int stop = str.indexOf('$');
  647. if ((stop > start) && (start != -1)) {
  648. return JaxoColor.getColor(str.substring(start + 1, stop - 1));
  649. }
  650. return JaxoColor.BLACK;
  651. }
  652. private int getTeXSize(String str) {
  653. String st;
  654. int start = str.indexOf("\\");
  655. int stop = str.indexOf('{', start);
  656. if ((stop > start) && (start != -1)) {
  657. st = str.substring(start + 1, stop);
  658. ArrayList possible = new ArrayList(10);
  659. possible.add("tiny");
  660. possible.add("scriptsize");
  661. possible.add("footnotesize");
  662. possible.add("small");
  663. possible.add("normalsize");
  664. possible.add("large");
  665. possible.add("Large");
  666. possible.add("LARGE");
  667. possible.add("huge");
  668. possible.add("Huge");
  669. if (possible.indexOf(st) == -1) {
  670. return 4;
  671. } else {
  672. return possible.indexOf(st);
  673. }
  674. } else {
  675. return 4;
  676. }
  677. }
  678. private String getTeXText(String str) {
  679. String st;
  680. int start = str.indexOf('$');
  681. int stop = str.lastIndexOf('$');
  682. st = str.substring(start + 1, stop);
  683. return st;
  684. }
  685. private int getTexRotangle(String str) {
  686. int start = str.indexOf('{');
  687. int stop = str.indexOf('}', start + 1);
  688. int rotangle =
  689. Math.round(Float.parseFloat(str.substring(start + 1, stop)));
  690. return rotangle;
  691. }
  692. private String getRotatedTexText(String str, String fullstr) {
  693. int start = str.indexOf('{');
  694. int stop = str.indexOf('}', start + 1);
  695. int offset = fullstr.indexOf('$');
  696. int stop1 = fullstr.indexOf('$', offset + 1);
  697. String text = fullstr.substring(offset + stop + 3, stop1 - 1);
  698. return text;
  699. }
  700. /**
  701. * Returns the two integers xi,yi contained in a string
  702. * of the form " # (xi,yi) * " where * can be anything
  703. * and # doesn't contain any parenthesis.
  704. *
  705. * @param str the String.
  706. * @return the two ints.
  707. */
  708. protected String[] getOneBracket(String str) {
  709. String[] st = new String[2];
  710. int start = str.indexOf('(');
  711. int comma = str.indexOf(',', start);
  712. int stop = str.indexOf(')', start);
  713. st[0] = str.substring(start + 1, comma);
  714. st[1] = str.substring(comma + 1, stop);
  715. return st;
  716. }
  717. /**
  718. * Returns the four integers xi,yi,xf,yf contained in a string
  719. * of the form " # [String] * " where * can be anything
  720. * and # doesn't contain any braces.
  721. *
  722. * @param str the String.
  723. * @return the four ints.
  724. */
  725. protected String getOneBrace(String str) {
  726. String st = "";
  727. int start = str.indexOf('[');
  728. int stop = str.indexOf(']', start);
  729. st = str.substring(start + 1, stop);
  730. return st;
  731. }
  732. /**
  733. * Returns the string "String" contained in a string
  734. * of the form " # {String} * " where * can be anything
  735. * and # doesn't contain any curly brackets.
  736. *
  737. * @param str the String.
  738. * @return the String.
  739. */
  740. protected String getOneCurl(String str) {
  741. int start = str.indexOf('{');
  742. int stop = str.indexOf('}', start);
  743. String st = str.substring(start + 1, stop);
  744. return st;
  745. }
  746. /**
  747. * Returns the two strings s1, s2 contained in a string
  748. * of the form " # {s1}{s2} * " where * can be anything
  749. * and # doesn't contain any curly brackets.
  750. *
  751. * @param str the String.
  752. * @return the Strings.
  753. */
  754. protected String[] getTwoCurls(String str) {
  755. String[] st = new String[2];
  756. int start = str.indexOf('{');
  757. int stop = str.indexOf('}', start);
  758. st[0] = str.substring(start + 1, stop);
  759. int offset = stop + 1;
  760. start = str.indexOf('{', offset);
  761. stop = str.indexOf('}', offset);
  762. st[1] = str.substring(start + 1, stop);
  763. return st;
  764. }
  765. /**
  766. * Returns the three strings s1, s2, s3 contained in a string
  767. * of the form " # {s1}{s2}{s3} * " where * can be anything
  768. * and # doesn't contain any curly brackets.
  769. *
  770. * @param str the String.
  771. * @return the Strings.
  772. */
  773. protected String[] getThreeCurls(String str) {
  774. String[] st = new String[3];
  775. int start = str.indexOf('{');
  776. int stop = str.indexOf('}');
  777. st[0] = str.substring(start + 1, stop);
  778. int offset = stop + 1;
  779. start = str.indexOf('{', offset);
  780. stop = str.indexOf('}', offset);
  781. st[1] = str.substring(start + 1, stop);
  782. offset = stop + 1;
  783. start = str.indexOf('{', offset);
  784. stop = str.indexOf('}', offset);
  785. st[2] = str.substring(start + 1, stop);
  786. return st;
  787. }
  788. /**
  789. * Returns the five strings s1 - s5 contained in a string
  790. * of the form " # (s1, s2) (s3, s4, s5) * " where * can be anything
  791. * and # doesn't contain any parenthesis.
  792. *
  793. * @param str the String.
  794. * @return the Strings.
  795. */
  796. protected String[] getArcBrackets(String str) {
  797. String[] st = new String[5];
  798. int start = str.indexOf('(');
  799. int comma = str.indexOf(',', start);
  800. int stop = str.indexOf(')', start);
  801. st[0] = str.substring(start + 1, comma);
  802. st[1] = str.substring(comma + 1, stop);
  803. int offset = stop + 1;
  804. start = str.indexOf('(', offset);
  805. int comma1 = str.indexOf(',', offset);
  806. int comma2 = str.indexOf(',', comma1 + 1);
  807. stop = str.indexOf(')', offset);
  808. st[2] = str.substring(start + 1, comma1);
  809. st[3] = str.substring(comma1 + 1, comma2);
  810. st[4] = str.substring(comma2 + 1, stop);
  811. return st;
  812. }
  813. private float theDLSeparation(String str) {
  814. int offset = str.indexOf('%') + 1;
  815. int start = str.indexOf('(', offset);
  816. int stop = str.indexOf(')', offset);
  817. float sep = Float.parseFloat(str.substring(start + 1, stop));
  818. return sep;
  819. }
  820. private void setDoubleLine(JaxoObject newOb) {
  821. if (string.indexOf('%') == -1) {
  822. newOb.setParameter("doubleLine", false);
  823. newOb.setParameter("dLSeparation", 2.f);
  824. } else {
  825. newOb.setParameter("doubleLine", true);
  826. newOb.setParameter("dLSeparation", Math.abs(theDLSeparation(string)));
  827. }
  828. }
  829. private JaxoObject newVertexT4() {
  830. int[] firstl = getFourInts(string);
  831. int[] secondl = getFourInts(string, string.lastIndexOf("\\Line"));
  832. int[] pars = getT4Params(firstl, secondl);
  833. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.VERTEXT4);
  834. newOb.setParameter("x", pars[0]);
  835. newOb.setParameter("y", pars[1]);
  836. newOb.setParameter("relativeWidth", pars[2]);
  837. newOb.setParameter("relativeHeight", pars[3]);
  838. newOb.setParameter("strokeWidth", getStroke());
  839. newOb.setParameter("color", getColor());
  840. return newOb;
  841. }
  842. private JaxoObject newVertexT2() {
  843. int[] pars = getT2Params(getOvalBrackets(string));
  844. String[] colors = getTwoCurls(string);
  845. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.VERTEXT2);
  846. newOb.setParameter("x", pars[0]);
  847. newOb.setParameter("y", pars[1]);
  848. newOb.setParameter("relativeWidth", pars[3]);
  849. newOb.setParameter("relativeHeight", pars[2]);
  850. newOb.setParameter("color", JaxoColor.getColor(colors[0]));
  851. newOb.setParameter("strokeWidth", getStroke());
  852. newOb.setParameter("fillColor", JaxoColor.getColor(colors[1]));
  853. return newOb;
  854. }
  855. private JaxoObject newVertexT2Unfilled() {
  856. int[] pars = getT2Params(getOvalBrackets(string));
  857. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.VERTEXT2);
  858. newOb.setParameter("x", pars[0]);
  859. newOb.setParameter("y", pars[1]);
  860. newOb.setParameter("relativeWidth", pars[3]);
  861. newOb.setParameter("relativeHeight", pars[2]);
  862. newOb.setParameter("strokeWidth", getStroke());
  863. newOb.setParameter("color", JaxoColor.getColor("Black"));
  864. newOb.setParameter("fillColor", JaxoColor.WHITE);
  865. newOb.setParameter("filled", false);
  866. return newOb;
  867. }
  868. private JaxoObject newVertexT2Gray() {
  869. int[] pars = getT2Params(getOvalBrackets(string));
  870. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.VERTEXT2);
  871. newOb.setParameter("x", pars[0]);
  872. newOb.setParameter("y", pars[1]);
  873. newOb.setParameter("relativeWidth", pars[3]);
  874. newOb.setParameter("relativeHeight", pars[2]);
  875. newOb.setParameter("strokeWidth", getStroke());
  876. newOb.setParameter("color", JaxoColor.getColor("Black"));
  877. newOb.setParameter("fillColor", JaxoColor.getGrayScaleColor(Float.parseFloat(
  878. getOneCurl(string))));
  879. return newOb;
  880. }
  881. private JaxoObject newFLoop(boolean arcn, boolean arrow, boolean atend) {
  882. JaxoObject newOb = null;
  883. String[] st = getArcBrackets(string);
  884. int phi1 = Math.round(Float.parseFloat(st[3]));
  885. int phi2 = Math.round(Float.parseFloat(st[4]));
  886. if (Math.abs(phi1 - phi2) >= 360) {
  887. int[] pars = getLoopPars(st, string, arcn);
  888. newOb = JaxoObjectFactory.newObject(JaxoConstants.FLOOP);
  889. newOb.setParameter("x", pars[0]);
  890. newOb.setParameter("y", pars[1]);
  891. newOb.setParameter("relativeWidth", pars[2]);
  892. newOb.setParameter("relativeHeight", pars[3]);
  893. newOb.setParameter("strokeWidth", getStroke());
  894. newOb.setParameter("color", getColor());
  895. newOb.setParameter("paintArrow", arrow);
  896. if (arrow) {
  897. newOb.setParameter("arrowPosition", 0.5f);
  898. }
  899. newOb.setParameter("flip", arcn);
  900. setDoubleLine(newOb);
  901. } else {
  902. Point2D[] pts = getArcPoints(st, arcn);
  903. Point2D p0 = pts[0];
  904. Point2D p1 = pts[1];
  905. Point2D p2 = pts[2];
  906. newOb = JaxoObjectFactory.newObject(JaxoConstants.FARC);
  907. newOb.setParameter("x", (int) Math.round(p0.getX()));
  908. newOb.setParameter("y", (int) Math.round(p0.getY()));
  909. newOb.setParameter("x2", (int) Math.round(p1.getX()));
  910. newOb.setParameter("y2", (int) Math.round(p1.getY()));
  911. newOb.setParameter("x3", (int) Math.round(p2.getX()));
  912. newOb.setParameter("y3", (int) Math.round(p2.getY()));
  913. newOb.setParameter("strokeWidth", getStroke());
  914. newOb.setParameter("color", getColor());
  915. newOb.setParameter("paintArrow", arrow);
  916. newOb.setParameter("flip", false);
  917. if (atend) {
  918. newOb.setParameter("arrowPosition", 1.f);
  919. } else {
  920. newOb.setParameter("arrowPosition", 0.5f);
  921. }
  922. setDoubleLine(newOb);
  923. }
  924. return newOb;
  925. }
  926. private JaxoObject newLine(boolean arrow, boolean atend) {
  927. int[] pars = getLineParams(getFourInts(string), string);
  928. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.FLINE);
  929. newOb.setParameter("x", pars[0]);
  930. newOb.setParameter("y", pars[1]);
  931. newOb.setParameter("relativeWidth", pars[2]);
  932. newOb.setParameter("relativeHeight", pars[3]);
  933. newOb.setParameter("strokeWidth", getStroke());
  934. newOb.setParameter("color", getColor());
  935. newOb.setParameter("paintArrow", arrow);
  936. if (atend) {
  937. newOb.setParameter("arrowPosition", 1.f);
  938. } else {
  939. newOb.setParameter("arrowPosition", 0.5f);
  940. }
  941. newOb.setParameter("flip", false);
  942. setDoubleLine(newOb);
  943. return newOb;
  944. }
  945. private JaxoObject newCBox() {
  946. JaxoObject newOb = null;
  947. if (string.indexOf('%') == -1) {
  948. int[] pars = getBoxParams(getFourInts(string));
  949. String[] colors = getTwoCurls(string);
  950. newOb = JaxoObjectFactory.newObject(JaxoConstants.BOX);
  951. newOb.setParameter("x", pars[0]);
  952. newOb.setParameter("y", pars[1]);
  953. newOb.setParameter("relativeWidth", pars[2]);
  954. newOb.setParameter("relativeHeight", pars[3]);
  955. newOb.setParameter("strokeWidth", getStroke());
  956. newOb.setParameter("color", JaxoColor.getColor(colors[0]));
  957. newOb.setParameter("fillColor", JaxoColor.getColor(colors[1]));
  958. } else {
  959. int[] pars = getT3Params(getFourInts(string));
  960. String[] colors = getTwoCurls(string);
  961. newOb = JaxoObjectFactory.newObject(JaxoConstants.VERTEXT3);
  962. newOb.setParameter("x", pars[0]);
  963. newOb.setParameter("y", pars[1]);
  964. newOb.setParameter("relativeWidth", pars[2]);
  965. newOb.setParameter("relativeHeight", pars[3]);
  966. newOb.setParameter("color", JaxoColor.getColor(colors[0]));
  967. }
  968. return newOb;
  969. }
  970. private JaxoObject newCCirc() {
  971. String[] radcol = getThreeCurls(string);
  972. int[] pars = getCircParams(getTwoInts(string), radcol[0]);
  973. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.BLOB);
  974. newOb.setParameter("x", pars[0]);
  975. newOb.setParameter("y", pars[1]);
  976. newOb.setParameter("relativeWidth", pars[2]);
  977. newOb.setParameter("relativeHeight", pars[2]);
  978. newOb.setParameter("strokeWidth", getStroke());
  979. newOb.setParameter("rotationAngle", 0);
  980. newOb.setParameter("color", JaxoColor.getColor(radcol[1]));
  981. newOb.setParameter("fillColor", JaxoColor.getColor(radcol[2]));
  982. return newOb;
  983. }
  984. private JaxoObject newCOval() {
  985. int[] pars = getBlobParams(getOvalBrackets(string));
  986. String[] colors = getTwoCurls(string);
  987. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.BLOB);
  988. newOb.setParameter("x", pars[0]);
  989. newOb.setParameter("y", pars[1]);
  990. newOb.setParameter("relativeWidth", pars[3]);
  991. newOb.setParameter("relativeHeight", pars[2]);
  992. newOb.setParameter("strokeWidth", getStroke());
  993. newOb.setParameter("rotationAngle", -pars[4]);
  994. newOb.setParameter("color", JaxoColor.getColor(colors[0]));
  995. newOb.setParameter("fillColor", JaxoColor.getColor(colors[1]));
  996. return newOb;
  997. }
  998. private JaxoObject newCTri() {
  999. String[] colors = getTwoCurls(string);
  1000. int[] pars = getTriangleParameters(getSixInts(string));
  1001. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.VERTEXT5);
  1002. newOb.setParameter("x", pars[0]);
  1003. newOb.setParameter("y", pars[1]);
  1004. newOb.setParameter("x2", pars[2]);
  1005. newOb.setParameter("y2", pars[3]);
  1006. newOb.setParameter("x3", pars[4]);
  1007. newOb.setParameter("y3", pars[5]);
  1008. newOb.setParameter("strokeWidth", getStroke());
  1009. newOb.setParameter("color", JaxoColor.getColor(colors[0]));
  1010. newOb.setParameter("fillColor", JaxoColor.getColor(colors[1]));
  1011. return newOb;
  1012. }
  1013. private JaxoObject newDashArc(boolean arcn, boolean arrow) {
  1014. String[] st = getArcBrackets(string);
  1015. float dash = Float.parseFloat(getOneCurl(string)) * getScaleFactor();
  1016. JaxoObject newOb = null;
  1017. if (!arrow && !(string.indexOf('%') == -1)) {
  1018. float r = Float.parseFloat(st[2]);
  1019. dash =
  1020. (float) Math.round((dash * r) / (r + theDLSeparation(string)));
  1021. }
  1022. int phi1 = Math.round(Float.parseFloat(st[3]));
  1023. int phi2 = Math.round(Float.parseFloat(st[4]));
  1024. if (Math.abs(phi1 - phi2) >= 360) {
  1025. int[] pars = getLoopPars(st, string, arcn);
  1026. if (dash > 5.f) {
  1027. newOb = JaxoObjectFactory.newObject(JaxoConstants.SLOOP);
  1028. } else {
  1029. newOb = JaxoObjectFactory.newObject(JaxoConstants.GLOOP);
  1030. }
  1031. newOb.setParameter("x", pars[0]);
  1032. newOb.setParameter("y", pars[1]);
  1033. newOb.setParameter("relativeWidth", pars[2]);
  1034. newOb.setParameter("relativeHeight", pars[3]);
  1035. newOb.setParameter("strokeWidth", getStroke());
  1036. newOb.setParameter("color", getColor());
  1037. newOb.setParameter("paintArrow", arrow);
  1038. if (arrow) {
  1039. newOb.setParameter("arrowPosition", 0.5f);
  1040. }
  1041. newOb.setParameter("flip", arcn);
  1042. newOb.setParameter("dash", dash);
  1043. setDoubleLine(newOb);
  1044. } else {
  1045. Point2D[] pts = getArcPoints(st, arcn);
  1046. Point2D p0 = pts[0];
  1047. Point2D p1 = pts[1];
  1048. Point2D p2 = pts[2];
  1049. if (dash > 5.f) {
  1050. newOb = JaxoObjectFactory.newObject(JaxoConstants.SARC);
  1051. } else {
  1052. newOb = JaxoObjectFactory.newObject(JaxoConstants.GARC);
  1053. }
  1054. newOb.setParameter("x", (int) Math.round(p0.getX()));
  1055. newOb.setParameter("y", (int) Math.round(p0.getY()));
  1056. newOb.setParameter("x2", (int) Math.round(p1.getX()));
  1057. newOb.setParameter("y2", (int) Math.round(p1.getY()));
  1058. newOb.setParameter("x3", (int) Math.round(p2.getX()));
  1059. newOb.setParameter("y3", (int) Math.round(p2.getY()));
  1060. newOb.setParameter("strokeWidth", getStroke());
  1061. newOb.setParameter("color", getColor());
  1062. newOb.setParameter("paintArrow", arrow);
  1063. if (arrow) {
  1064. newOb.setParameter("arrowPosition", 0.5f);
  1065. }
  1066. newOb.setParameter("flip", arcn);
  1067. newOb.setParameter("dash", dash);
  1068. setDoubleLine(newOb);
  1069. }
  1070. return newOb;
  1071. }
  1072. private JaxoObject newDashLine(boolean arrow) {
  1073. int[] pars = getLineParams(getFourInts(string), string);
  1074. float dash = Float.parseFloat(getOneCurl(string)) * getScaleFactor();
  1075. JaxoObject newOb = null;
  1076. if (dash > 5.f) {
  1077. newOb = JaxoObjectFactory.newObject(JaxoConstants.SLINE);
  1078. } else {
  1079. newOb = JaxoObjectFactory.newObject(JaxoConstants.GLINE);
  1080. }
  1081. newOb.setParameter("x", pars[0]);
  1082. newOb.setParameter("y", pars[1]);
  1083. newOb.setParameter("relativeWidth", pars[2]);
  1084. newOb.setParameter("relativeHeight", pars[3]);
  1085. newOb.setParameter("strokeWidth", getStroke());
  1086. newOb.setParameter("color", getColor());
  1087. newOb.setParameter("paintArrow", arrow);
  1088. if (arrow) {
  1089. newOb.setParameter("arrowPosition", 0.5f);
  1090. }
  1091. newOb.setParameter("flip", false);
  1092. newOb.setParameter("dash", dash);
  1093. setDoubleLine(newOb);
  1094. return newOb;
  1095. }
  1096. private JaxoObject newGBox() {
  1097. int[] pars = getBoxParams(getFourInts(string));
  1098. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.BOX);
  1099. newOb.setParameter("x", pars[0]);
  1100. newOb.setParameter("y", pars[1]);
  1101. newOb.setParameter("relativeWidth", pars[2]);
  1102. newOb.setParameter("relativeHeight", pars[3]);
  1103. newOb.setParameter("strokeWidth", getStroke());
  1104. newOb.setParameter("color", getColor());
  1105. newOb.setParameter("fillColor", JaxoColor.getGrayScaleColor(Float.parseFloat(
  1106. getOneCurl(string))));
  1107. return newOb;
  1108. }
  1109. private JaxoObject newEBox() {
  1110. int[] pars = getBoxParams(getFourInts(string));
  1111. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.BOX);
  1112. newOb.setParameter("x", pars[0]);
  1113. newOb.setParameter("y", pars[1]);
  1114. newOb.setParameter("relativeWidth", pars[2]);
  1115. newOb.setParameter("relativeHeight", pars[3]);
  1116. newOb.setParameter("strokeWidth", getStroke());
  1117. newOb.setParameter("color", getColor());
  1118. newOb.setParameter("fillColor", JaxoColor.WHITE);
  1119. newOb.setParameter("filled", false);
  1120. return newOb;
  1121. }
  1122. private JaxoObject newGCirc() {
  1123. String[] radcol = getTwoCurls(string);
  1124. int[] pars = getCircParams(getTwoInts(string), radcol[0]);
  1125. JaxoObject newOb = JaxoObjectFactory.newObject(JaxoConstants.BLOB);
  1126. newOb.setParameter("x", pars[0]);
  1127. newOb.setParameter("y", pars[1]);
  1128. newOb.setParameter("relativeWidth", pars[2]);
  1129. newOb.setParameter("relativeHeight", pars[2]);
  1130. newOb.setParameter("strokeWidth", getStroke());
  1131. newOb.setParameter("rotationAngle", 0);
  1132. newOb.setParameter("color", getColor());
  1133. newOb.setParameter("fillColor", JaxoColor.getGrayScaleColor(Float.parseFloat(
  1134. radcol[1])));
  1135. return newOb;
  1136. }
  1137. private JaxoObject newGlArc() {
  1138. JaxoObject newOb = null;
  1139. String[] st = getArcBrackets(string);
  1140. String[] ampwig = getTwoCurls(string);
  1141. int phi1 = Math.round(Float.parseFloat(st[3]));
  1142. int phi2 = Math.round(Float.parseFloat(st[4]));
  1143. if (Math.abs(phi1 - phi2) >= 360) {
  1144. int[] pars = getLoopPars(st, string, false);
  1145. newOb = JaxoObjectFactory.newObject(JaxoConstants.GLLOOP);
  1146. newOb.setParameter("x", pars[0]);
  1147. newOb.setParameter("y", pars[1]);
  1148. newOb.setParameter("relativeWidth", -pars[2]);
  1149. newOb.setParameter("relativeHeight", -pars[3]);
  1150. newOb.setParameter("strokeWidth", getStroke());
  1151. newOb.setParameter("color", getColor());
  1152. newOb.setParameter("amp", Math.round(
  1153. Float.parseFloat(ampwig[0]) * 2 * getScaleFactor()));
  1154. float nOfWiggles = Float.parseFloat(ampwig[1]) * getScaleFactor();
  1155. newOb.setParameter("frequencyFromWiggles", Math.round(nOfWiggles));
  1156. setDoubleLine(newOb);
  1157. } else {
  1158. Point2D[] pts = getArcPoints(st, false);
  1159. Point2D p0 = pts[0];
  1160. Point2D p1 = pts[1];
  1161. Point2D p2 = pts[2];
  1162. newOb = JaxoObjectFactory.newObject(JaxoConstants.GLARC);
  1163. newOb.setParameter("x", (int) Math.round(p0.getX()));
  1164. newOb.setParameter("y", (int) Math.round(p0.getY()));
  1165. newOb.setParameter("x2", (int) Math.round(p1.getX()));
  1166. newOb.setParameter("y2", (int) Math.round(p1.getY()));
  1167. newOb.setParameter("x3", (int) Math.round(p2.getX()));
  1168. newOb.setParameter("y3", (int) Math.round(p2.getY()));
  1169. newOb.setParameter("strokeWidth", getStroke());
  1170. newOb.setParameter("color", getColor());
  1171. newOb.setParameter("amp", -Math.round(
  1172. Float.parseFloat(ampwig[0]) * 2 * getScaleFactor()));
  1173. float nOfWiggles = Float.parseFloat(ampwig[1]) * getScaleFactor();
  1174. newOb.setParameter("frequencyFromWiggles", Math.round(nOfWiggles));
  1175. setDoubleLine(newOb);
  1176. }
  1177. return newOb;

Large files files are truncated, but you can click here to view the full file