Source code: jplot/GraphPars.java
1 /*
2 * JPLOT -- Java Plotting Interface for any programme or
3 * as an independent GUI
4 *
5 * Copyright (C) 1999 Jan van der Lee
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 *
22 * Send bugs, suggestions or queries to <jplot@cig.ensmp.fr>
23 * The latest releases are found at
24 * http://www.cig.ensmp.fr/~vanderlee/jplot.html
25 *
26 * Initally developed for use by the Centre d'Informatique Geologique
27 * Ecole des Mines de Paris, Fontainebleau, France.
28 */
29
30 package jplot;
31
32 import java.awt.*;
33 import java.util.*;
34 import javax.swing.*;
35
36 /**
37 * <code>GraphPars</code> contains the parameters which are used to
38 * draw the graph such as number of tics, scaling values, offset
39 * parameters, axis lengths etc. All these parameters are settable
40 * by the GUI, and written to this class. Class <code>Graph</code>
41 * reads this class and draws the graph based on these parameters.
42 */
43 public class GraphPars extends DataChangeListener {
44
45 // some handy variables, if we need more than an boolean:
46 static final int DISABLE=0;
47 static final int ENABLE=1;
48 static final int AUTO=2;
49
50 static final Color[] color = {
51 new Color(0,0,102), // very dark blue
52 new Color(255,0,0), // red
53 //new Color(0,102,102), // very dark green
54 new Color(0,114,0), // very dark green
55 new Color(132,0,132), // dark-purple
56
57 new Color(102,0,255), // dark blue
58 new Color(255,0,102), // red-violet
59 //new Color(0,102,0), // dark green
60 new Color(0,145,0), // dark green
61 new Color(255,0,255), // light-purple
62
63 new Color(0,153,255), // medium-light blue
64 new Color(255,153,0), // orange
65 //new Color(0,205,153), // medium (sea) green
66 new Color(0,195,100), // medium green
67 new Color(255,188,255), // light-violet
68
69 new Color(0,255,255), // light blue
70 new Color(255,255,0), // yellow
71 new Color(102,255,0), // light green
72 new Color(255,220,226), // saumong
73
74 new Color(10,10,10), // black
75 new Color(100,100,100), // gray
76 new Color(160,160,160), // gray
77 new Color(220,220,220)}; // gray
78
79
80 public static final float[] dashLengths = {0.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,-1.0f};
81 // Very large number, used to initialize stuff:
82 static final double INF = 1e300;
83
84 // number of axis and symbolic constants to facilitate
85 // endless lists of axis-specific parameters:
86 static final int NAXES = 2;
87 static final int X_AXIS = 0;
88 static final int Y_AXIS = 1;
89 static final int Z_AXIS = 2;
90
91 // currently available graphstyles. Public, available from outside
92 // the current package (so you can use the function 'switchGraphType())
93 static public final int GRAPHTYPE_2D=0;
94 static public final int GRAPHTYPE_PIPER=1;
95 static public final int GRAPHTYPE_MULTI=2;
96
97 // symbolic constant used for no symbols (points) on the lines:
98 static final int NO_SYMBOL = 13;
99
100 // symbolic constant used for no lines:
101 static final int NO_LINE = 7;
102
103 // index pointing to the actual color and point indices,
104 // used by the plotpanels. Must be declared here in case
105 // there are different datasets:
106 //-------------------------------------------------------
107 public int colorIndex=0;
108 public int pointIndex=0;
109
110
111 // actual color. This color is used for previewing the color if
112 // different from one of the default colors:
113 // ------------------------------------------------------------
114 public Color actualColor;
115
116 // size of the graph panel:
117 private Dimension panelSize;
118
119 // offsets:
120 private double leftMargin;
121 private double rightMargin;
122 private double bottomMargin;
123 private double topMargin;
124
125 // tics:
126 private double[] ticLength = new double [NAXES];
127 private int maxNumberOfTics;
128 private int[] numberTics = new int [NAXES];
129 private boolean[] useNumberOfTics = new boolean [NAXES];
130 private boolean[] plotTics = new boolean [NAXES];
131 private boolean[] rotateTics = new boolean [NAXES];
132 private boolean[] mirrorTics = new boolean [NAXES];
133 private boolean[] plotTicLabels = new boolean [NAXES];
134
135 // labels:
136 private Vector labels = new Vector();
137 //private Vector dataLabels = new Vector();
138
139 // axes:
140 private double axesRatio;
141 private boolean[] plotAxis = new boolean [NAXES];
142 private boolean[] plotMirrorAxis = new boolean [NAXES];
143 private boolean[] rotTics = new boolean [NAXES];
144 private double[] inv = new double [NAXES];
145
146 // colors:
147 private Color backgroundColor;
148 private Color axesColor;
149 private Color[] labelColor = new Color [NAXES];
150 private Color titleColor;
151
152 // legend:
153 private Font legendFont;
154 private boolean useLegend;
155 private boolean useLegendPosition;
156 //private FontMetrics legendFontMetrics;
157 private double[] legendPos = new double [NAXES];
158 private double legendSpacing;
159
160 // scaling:
161 private boolean[] isLogarithmic = new boolean [NAXES];
162 private boolean[] autoRange = new boolean [NAXES];
163 private double[] minValue = new double[NAXES];
164 private double[] maxValue = new double[NAXES];
165 private float[] multiplier = new float[NAXES];
166 private float[] additioner = new float[NAXES];
167 private float[] globalDivider = new float[NAXES];
168 private float[] globalOffset = new float[NAXES];
169
170 // fonts, colors used by the tic-labels
171 private Font[] ticFont = new Font [NAXES];
172 private Color[] ticColor = new Color [NAXES];
173 //private FontMetrics[] ticFontMetrics = new FontMetrics [NAXES];
174
175 // grid:
176 private boolean[] grid = new boolean [NAXES];
177 private Color gridColor;
178 private boolean toFront;
179
180 // gadgets:
181 private boolean shadow;
182 private boolean useRatio;
183
184 // piper diagram stuff:
185 private Color triangleFillColor;
186 private boolean plotInner;
187
188 // bounding box:
189 private boolean plotBox;
190 private float boxOffset;
191 private Color graphBgColor;
192 private Color boxFillColor;
193 private Color boxColor;
194
195 // flags, used to avoid usless calculatations or updates:
196 private boolean updatePlot;
197 private boolean fontChanged;
198
199 // use points:
200 private int pointMode;
201 private int colorMode;
202
203 // graph types and linestyles:
204 private int graphType;
205 private int graphStyle;
206
207 private float tdsFac;
208 private boolean useTds;
209
210 private final String lf = System.getProperty("line.separator");
211
212 // accessibility methods:
213 //-----------------------
214 /**
215 * @return the panel dimension of the graph
216 */
217 Dimension getDimension() {
218 return panelSize;
219 }
220
221 /**
222 * Sets the dimension of the panel of the graph.
223 * @param d dimension of the graph panel
224 */
225 void setDimension(Dimension d) {
226 panelSize = d;
227 }
228
229 /**
230 * @return the panel width
231 */
232 int getPanelWidth() {
233 return panelSize.width;
234 }
235
236 /**
237 * @return the panel height
238 */
239 int getPanelHeight() {
240 return panelSize.height;
241 }
242
243 /**
244 * Returns the distance between the left panel border and the left Y-axis.
245 * @return the left margin.
246 */
247 double getLeftMargin() {
248 return leftMargin;
249 }
250
251 /**
252 * Sets the distance between the left panel border and the left Y-axis.
253 * @param lm the left margin in points.
254 */
255 void setLeftMargin(double lm) {
256 leftMargin = lm;
257 }
258
259 /**
260 * Returns the distance between the right panel border and the right Y-axis.
261 * @return the right margin.
262 */
263 double getRightMargin() {
264 return rightMargin;
265 }
266
267 /**
268 * Sets the distance between the right panel border and the right Y-axis.
269 * @param rm the right margin in points.
270 */
271 void setRightMargin(double rm) {
272 rightMargin = rm;
273 }
274
275 /**
276 * Returns the distance between the lower panel border and the bottom X-axis.
277 * @return the bottom margin.
278 */
279 double getBottomMargin() {
280 return bottomMargin;
281 }
282
283 /**
284 * Sets the distance between the lower panel border and the bottom X-axis.
285 * @param bm the bottom margin in points.
286 */
287 void setBottomMargin(double bm) {
288 bottomMargin = bm;
289 }
290
291 /**
292 * Returns the distance between the upper panel border and the top X-axis.
293 * @return the top margin.
294 */
295 double getTopMargin() {
296 return topMargin;
297 }
298
299 /**
300 * Sets the distance between the upper panel border and the top X-axis.
301 * @param tm the top margin in points.
302 */
303 void setTopMargin(double tm) {
304 topMargin = tm;
305 }
306
307 /**
308 * @returns the length of the tics.
309 * @param axis defines to which axis this function applies.
310 */
311 double getTicLength(int axis) {
312 return ticLength[axis];
313 }
314
315 /**
316 * Sets the length of the tics. In fact, the actual tic length is
317 * the value you set here multiplied by the axis length. By default,
318 * the tic-length is about 0.01 times the axis length.
319 * @param axis defines to which axis this function applies.
320 * @param tl tic length in points */
321 void setTicLength(int axis, double tl) {
322 ticLength[axis] = tl;
323 }
324
325 /**
326 * @returns the length of one of the axes.
327 * @param axis defines to which axis this function applies.
328 */
329 /*
330 double getAxisLength(int axis) {
331 return axisLength[axis];
332 }
333 */
334
335 /**
336 * Sets the length of one of the axes.
337 * @param axis defines to which axis this function applies.
338 * @param l length of the axis, in points */
339 /*
340 void setAxisLength(int axis, double l) {
341 axisLength[axis] = l;
342 }
343 */
344
345 /**
346 * Sets whether or not to use a fixed ratio between
347 * X- and Y-axes lengths.
348 * @param boolean, true if the ratio should be used.
349 */
350 void setUseAxesRatio(boolean b) {
351 useRatio = b;
352 }
353
354 /**
355 * Returns the whether or not to use a fixed ratio between
356 * X- and Y-axes lengths.
357 * @return true if the ratio should be used.
358 */
359 boolean useAxesRatio() {
360 return useRatio;
361 }
362
363 /**
364 * Returns the ratio between X- and Y-axes lengths.
365 * @return the ratio Y-axisLength/X-axisLength
366 */
367 double getAxesRatio() {
368 return axesRatio;
369 }
370
371 /**
372 * Sets the ratio between X- and Y-axes lengths. This ratio
373 * must be greater than 0.0, a value of 0.0 means that the
374 * ratio will be calculated automatically as a function of
375 * the size of the panel, used to plot the graph.
376 * @param r the ratio Y-axisLength/X-axisLength
377 */
378 void setAxesRatio(double r) {
379 axesRatio = (r > 0.0)? r:0.0;
380 }
381
382 /**
383 * Sets wether the user defines the number of tics.
384 * X- and Y-axes lengths.
385 * @param axis defines to which axis this function applies.
386 * @param boolean, true if the ratio should be used.
387 */
388 void setUseNumberOfTics(int axis, boolean b) {
389 useNumberOfTics[axis] = b;
390 }
391
392 /**
393 * Returns whether or not to use a user-defined number of tics.
394 * @param axis defines to which axis this function applies.
395 * @return true if the ratio should be used.
396 */
397 boolean useNumberOfTics(int axis) {
398 return useNumberOfTics[axis];
399 }
400
401 /**
402 * Returns the number of tics for the specfied axis.
403 * @param axis defines to which axis this function applies.
404 * @return the number of tics for the specfied axis.
405 */
406 int getNumberOfTics(int axis) {
407 return numberTics[axis];
408 }
409
410 /**
411 * Sets the number of tics for the specified axis.
412 * @param axis defines to which axis this function applies.
413 * @param n the number of tics
414 */
415 void setNumberOfTics(int axis, int n) {
416 numberTics[axis] = (n > 0)? n:0;
417 }
418
419 /**
420 * @return the maximum number of tics allowed.
421 */
422 int getMaxNumberOfTics() {
423 return maxNumberOfTics;
424 }
425
426 /**
427 * Sets the maximum number of tics allowed. Setting this parameter
428 * may change the number of tics, but the exact number of tics is
429 * a function of the start- and end values of the data.
430 * @param n an indicative number of tics
431 */
432 void setMaxNumberOfTics(int n) {
433 maxNumberOfTics = n;
434 }
435
436 /**
437 * sets the multiplier used to rescale all the data arrays.
438 * @param axis defines to which axis this function applies.
439 * @param val value of the multiplier
440 */
441 void setMultiplier(int axis, float val) {
442 multiplier[axis] = val;
443 }
444
445 /**
446 * @return the multiplier used to rescale all the data arrays.
447 * @param axis defines to which axis this function applies.
448 */
449 float getMultiplier(int axis) {
450 return multiplier[axis];
451 }
452
453 /**
454 * Sets a global divider used to rescale all the data arrays.
455 * @param axis defines to which axis this function applies.
456 * @param val value of the divider
457 */
458 void setGlobalDivider(int axis, float val) {
459 globalDivider[axis] = val;
460 }
461
462 /**
463 * @return the divider used to rescale all the data arrays.
464 * @param axis defines to which axis this function applies.
465 */
466 float getGlobalDivider(int axis) {
467 return globalDivider[axis];
468 }
469
470 /**
471 * Sets a global offset used to rescale all the data arrays.
472 * @param axis defines to which axis this function applies.
473 * @param val value of the offset
474 */
475 void setGlobalOffset(int axis, float val) {
476 globalOffset[axis] = val;
477 }
478
479 /**
480 * @return the offset used to rescale all the data arrays.
481 * @param axis defines to which axis this function applies.
482 */
483 float getGlobalOffset(int axis) {
484 return globalOffset[axis];
485 }
486
487 /**
488 * sets the additioner used to rescale all the data arrays.
489 * @param axis defines to which axis this function applies.
490 * @param val value of the additioner
491 */
492 void setAdditioner(int axis, float val) {
493 additioner[axis] = val;
494 }
495
496 /**
497 * @return the additioner used to rescale all the data arrays.
498 * @param axis defines to which axis this function applies.
499 */
500 float getAdditioner(int axis) {
501 return additioner[axis];
502 }
503
504 /**
505 * @return the start-value of the X, Y or Z range.
506 * @param axis defines to which axis this function applies.
507 */
508 double getMinValue(int axis) {
509 return minValue[axis];
510 }
511
512 /**
513 * Sets the start-value of the value range.
514 * @param axis defines to which axis this function applies.
515 * @param x minimum value of the X-range.
516 */
517 void setMinValue(int axis, double x) {
518 minValue[axis] = x;
519 }
520
521 /**
522 * @return the maximum value of the X,Y or Z range.
523 * @param axis defines to which axis this function applies.
524 */
525 double getMaxValue(int axis) {
526 return maxValue[axis];
527 }
528
529 /**
530 * Sets the maximum value of the X,Y or Z range.
531 * @param axis defines to which axis this function applies.
532 * @param x maximum value of the range.
533 */
534 void setMaxValue(int axis, double x) {
535 maxValue[axis] = x;
536 }
537
538 /**
539 * Returns whether an axis will be drawn or not.
540 * @param axis defines to which axis this function applies.
541 * @return true if the axis will be drawn.
542 */
543 boolean drawAxis(int axis) {
544 return plotAxis[axis];
545 }
546
547 /**
548 * Sets whether an axis will be drawn or not.
549 * @param axis defines to which axis this function applies.
550 * @param b toggle, true if the axis should be drawn.
551 */
552 void setDrawAxis(int axis, boolean b) {
553 plotAxis[axis] = b;
554 }
555
556 /**
557 * Returns whether the mirror of an axis will be drawn or not.
558 * @param axis defines to which axis this function applies.
559 * @return true if the mirror axis will be drawn.
560 */
561 boolean drawMirrorAxis(int axis) {
562 return plotMirrorAxis[axis];
563 }
564
565 /**
566 * Sets whether the mirror of an axis will be drawn or not.
567 * @param axis defines to which axis this function applies.
568 * @param b toggle, true if the mirror axis should be drawn.
569 */
570 void setDrawMirrorAxis(int axis, boolean b) {
571 plotMirrorAxis[axis] = b;
572 }
573
574 /**
575 * Returns whether or not to draw tic labels.
576 * @param axis defines to which axis this function applies.
577 * @return true if tic labels should be drawn.
578 */
579 boolean drawTicLabels(int axis) {
580 return plotTicLabels[axis];
581 }
582
583 /**
584 * Sets whether all ticlabels will be written or not.
585 * @param b toggle, true if the axis should be drawn.
586 */
587 void setDrawTicLabels(boolean b) {
588 plotTicLabels[X_AXIS] = plotTicLabels[Y_AXIS] = b;
589 }
590
591 /**
592 * Sets whether X, Y or Z ticlabels will be written or not.
593 * @param axis defines to which axis this function applies.
594 * @param b toggle, true if the axis should be drawn.
595 */
596 void setDrawTicLabels(int axis, boolean b) {
597 plotTicLabels[axis] = b;
598 }
599
600 /**
601 * Returns whether or not to draw tics.
602 * @param axis defines to which axis this function applies.
603 * @return true if tics should be drawn.
604 */
605 boolean drawTics(int axis) {
606 return plotTics[axis];
607 }
608
609 /**
610 * Sets whether ticlabels will be written or not. You know, these
611 * little lines indicating the dimensions of your plot.
612 * @param axis defines to which axis this function applies.
613 * @param b toggle, true if the tics should be drawn.
614 */
615 void setDrawTics(int axis, boolean b) {
616 plotTics[axis] = b;
617 }
618
619 /**
620 * Returns the actual background color of the graph.
621 * @return actual background color.
622 */
623 Color getBackgroundColor() {
624 return backgroundColor;
625 }
626
627 /**
628 * Sets the actual background color of the graph.
629 * @param color new background color.
630 */
631 void setBackgroundColor(Color color) {
632 backgroundColor = color;
633 }
634
635 /**
636 * Returns the actual color of the axes of the graph.
637 * @return actual color used to draw the axes.
638 */
639 Color getAxesColor() {
640 return axesColor;
641 }
642
643 /**
644 * Sets the actual color of the axes of the graph.
645 * @param color new color to draw the axes.
646 */
647 void setAxesColor(Color color) {
648 axesColor = color;
649 }
650
651 /**
652 * @return the list of labels currently defined
653 */
654 public Vector getLabels() {
655 return labels;
656 }
657
658 /*
659 * Returns a vector of labels which are defined by the dataset.
660 * @return the list of labels currently defined.
661 */
662 /*
663 public Vector getDataLabels() {
664 return dataLabels;
665 }*/
666
667 /**
668 * Add a label or, if already in the list, replaces a label
669 * with the current one.
670 * @param newgl new label
671 */
672 public void addLabel(GraphLabel newgl) {
673 labels.add(newgl);
674 }
675
676 /**
677 * Add a label or, if already in the list, replaces a label
678 * with the current one.
679 * @param gl new label
680 */
681 public void setLabel(GraphLabel gl) {
682 boolean labelFound=false;
683 for (Enumeration e=labels.elements(); e.hasMoreElements();) {
684 GraphLabel g = (GraphLabel) e.nextElement();
685 if (gl.equals(g.getText())) {
686 g.copy(gl);
687 labelFound = true;
688 break;
689 }
690 }
691 if (!labelFound) labels.add(gl);
692 }
693
694 /**
695 * Returns the font used by the labels drawn at each tic
696 * @param axis defines to which axis this function applies.
697 * @return actual font used by the tic labels.
698 */
699 public Font getTicFont(int axis) {
700 return ticFont[axis];
701 }
702
703 /**
704 * Sets the font used by the labels drawn at each tic
705 * @param axis defines to which axis this function applies.
706 * @param font the new font
707 */
708 public void setTicFont(int axis, Font font) {
709 ticFont[axis] = font;
710 fontChanged = true;
711 }
712
713 /**
714 * Returns the color used by the labels drawn at each tic
715 * @param axis defines to which axis this function applies.
716 * @return actual color used by the tic labels.
717 */
718 public Color getTicColor(int axis) {
719 return ticColor[axis];
720 }
721
722 /**
723 * Sets the color used by the labels drawn at each tic
724 * @param axis defines to which axis this function applies.
725 * @param color the new color
726 */
727 public void setTicColor(int axis, Color color) {
728 ticColor[axis] = color;
729 }
730
731 /**
732 * Returns the font metrics used by the labels drawn at each tic
733 * @param axis defines to which axis this function applies.
734 * @return actual font metrics used by the tic labels.
735 */
736 /*
737 public Font getTicFontMetrics(int axis) {
738 return ticFontMetrics[axis];
739 }
740 */
741
742 /**
743 * Returns the font used by the legend
744 * @return actual font used by the legend.
745 */
746 Font getLegendFont() {
747 return legendFont;
748 }
749
750 /**
751 * Sets the actual font of the legend.
752 * @param axis defines to which axis this function applies.
753 * @param font new font to draw the legend.
754 */
755 void setLegendFont(Font font) {
756 legendFont = font;
757 fontChanged = true;
758 }
759
760 /**
761 * @return the font metrics used by the legend
762 */
763 /*
764 public FontMetrics getLegendFontMetrics() {
765 return legendFontMetrics;
766 }
767 */
768
769 /**
770 * @return true if you want to show the legend
771 */
772 boolean drawLegend() {
773 return useLegend;
774 }
775
776 /**
777 * Sets whether or not to draw the legend.
778 * @param b true if you want to show the legend
779 */
780 void setDrawLegend(boolean b) {
781 useLegend = b;
782 }
783
784 /**
785 * Returns the x or y coordinates (defined in pixels, relative
786 * to the size of the panel showing the graph) of the legend.
787 * @param axis defines to which axis this function applies.
788 * @return the x- or y coordinates of the legend.
789 */
790 double getLegendPos(int axis) {
791 return legendPos[axis];
792 }
793
794 /*
795 private double xPixel2Data(double x) {
796 double d = inv[X]*diff[X]*(x-leftMargin)/axisLength[X];
797 if (useLogScale(X)) return getMinValue(X)*Math.pow(10.0,d);
798 else return getMinValue(X) + d;
799 }
800
801 private double yPixel2Data(double y) {
802 double d = inv[Y]*diff[Y]*(1.0-(y-topMargin)/axisLength[Y]);
803 if (useLogScale(Y)) return getMinValue(Y)*Math.pow(10.0,d);
804 else return getMinValue(Y) + d;
805 }
806 */
807
808 /**
809 * Sets the x or y coordinates (defined relative
810 * to the actual axes values) of the legend.
811 * @param axis defines to which axis this function applies.
812 * @param c the x/y coordinate of the legend.
813 */
814 void setLegendPos(int axis, double c) {
815 legendPos[axis] = c;
816 }
817
818 /**
819 * Sets the x and y coordinates (defined relative
820 * to the actual axes values) of the legend.
821 * @param x the x coordinate of the legend.
822 * @param y the y coordinate of the legend.
823 */
824 void setLegendPos(double x, double y) {
825 legendPos[X_AXIS] = x;
826 legendPos[Y_AXIS] = y;
827 }
828
829 /**
830 * @return true if you want to set the legend coordinates
831 */
832 boolean useLegendPos() {
833 return useLegendPosition;
834 }
835
836 /**
837 * Sets whether or not to set the legend position in X,Y
838 * coordinates as defined by the graph.
839 * @param b true if you want to set the position
840 */
841 void setUseLegendPos(boolean b) {
842 useLegendPosition = b;
843 }
844
845 /**
846 * Returns the vertical spacing, between each line of the legend.
847 * @return vertical spacing for the legend.
848 */
849 public double getLegendSpacing() {
850 return legendSpacing;
851 }
852
853 /**
854 * Sets the vertical spacing, between each line of the legend.
855 * @param dy vertical spacing for the legend.
856 */
857 public void setLegendSpacing(double dy) {
858 legendSpacing = dy;
859 }
860
861 /**
862 * Reset the positions of all the labels.
863 */
864 void resetLabels() {
865 for (Enumeration e=labels.elements(); e.hasMoreElements();) {
866 ((GraphLabel)e.nextElement()).setUsePosition(false);
867 }
868 }
869
870 /**
871 * Returns whether or not to plot using a logarithmic scale.
872 * @param axis defines to which axis this function applies.
873 * @return true if the scale is logarithmic.
874 */
875 boolean useLogScale(int axis) {
876 return isLogarithmic[axis];
877 }
878
879 /**
880 * Sets true or false to plot on a log scale.
881 * @param axis defines to which axis this function applies.
882 * @param b toggle, true if the scaling is logarithmic
883 */
884 void setLogScale(int axis, boolean b) {
885 isLogarithmic[axis] = b;
886 }
887
888 /**
889 * Returns whether or not we should use automatic scaling.
890 * @param axis defines to which axis this function applies.
891 * @return true if the scale is logarithmic.
892 */
893 boolean useAutoRange(int axis) {
894 return autoRange[axis];
895 }
896
897 /**
898 * Sets true or false to use automatic scaling.
899 * @param axis defines to which axis this function applies.
900 * @param b toggle, true if the the automatic scaling feature is enabled.
901 */
902 void setAutoRange(int axis, boolean b) {
903 autoRange[axis] = b;
904 }
905
906 /**
907 * Returns whether or not we should draw tics on the mirror axis.
908 * @param axis defines to which axis this function applies.
909 * @return true if the mirror tics should be drawn
910 */
911 boolean drawMirrorTics(int axis) {
912 return mirrorTics[axis];
913 }
914
915 /**
916 * Sets true or false to draw mirror tics
917 * @param axis defines to which axis this function applies.
918 * @param b toggle, true if the we should draw mirror tics
919 */
920 void setDrawMirrorTics(int axis, boolean b) {
921 mirrorTics[axis] = b;
922 }
923
924 /**
925 * Sets true or false to rotate tics
926 * @param axis defines to which axis this function applies.
927 * @param b toggle, true if the we should rotate the tics
928 */
929 void setRotateTics(int axis, boolean b) {
930 rotTics[axis] = b;
931 }
932
933 /**
934 * Returns whether or not we should rotate the tics.
935 * Rotated tics are drawn at the outer-side of the axes.
936 * @param axis defines to which axis this function applies.
937 * @return true if the tics will be rotated.
938 */
939 boolean rotateTics(int axis) {
940 return rotTics[axis];
941 }
942
943 /**
944 * Returns whether or not we should update the graph.
945 * @return true if the graph should be updated
946 */
947 boolean updateGraph() {
948 return updatePlot;
949 }
950
951 /**
952 * Sets true or false to update the graph.
953 * @param b toggle, true if the we should update.
954 */
955 void setUpdateGraph(boolean b) {
956 updatePlot = b;
957 }
958
959 /**
960 * Returns whether or not a shadow will be drawn at the panel border.
961 * @return true if the shadow should be drawn.
962 */
963 boolean drawShadow() {
964 return shadow;
965 }
966
967 /**
968 * Defines whether or not a shadow will be drawn at the panel border.
969 * @param b toggle, true if the shadow should be drawn.
970 */
971 void setShadow(boolean b) {
972 shadow = b;
973 }
974
975 /**
976 * Sets whether or not using grid lines.
977 * @param axis defines to which axis this function applies.
978 * @param b toggle, true if the the grid should be rotated.
979 */
980 void setDrawGrid(int axis, boolean b) {
981 grid[axis] = b;
982 }
983
984 /**
985 * Returns true if the grid should be drawn.
986 * @param axis defines to which axis this function applies.
987 * @return true if the grid lines should be used
988 */
989 boolean drawGrid(int axis) {
990 return grid[axis];
991 }
992
993 /**
994 * Sets whether or not plotting points
995 * @param b flag, indicates if the the points should be drawn.
996 * Note that the flag can take symbolic values such as ENABLE, AUTO etc.
997 */
998 void setPointMode(int b) {
999 pointMode = b;
1000 }
1001
1002 /**
1003 * Returns true if the points should be drawn.
1004 * @return true if the grid lines should be used
1005 */
1006 int getPointMode() {
1007 return pointMode;
1008 }
1009
1010 /**
1011 * Sets the way of defining the colors of the curves.
1012 * By default, the program takes, for each data-array, the colors
1013 * from the pre-defined color swatches. If there are more lines
1014 * than colors, than the first colors are re-used. This is the
1015 * auto-mode (flag = AUTO), which is the default. By seting the flag
1016 * to HIDE, no lines are drawn.
1017 * @param b flag, indicates how the program should color the curves
1018 * Note that the flag can take symbolic values such as DISABLE, AUTO etc.
1019 */
1020 void setColorMode(int b) {
1021 colorMode = b;
1022 }
1023
1024 /**
1025 * Returns the mode used to assign colors to the curves.
1026 * @return AUTO for the auto-selection mode (default), DISABLE
1027 * if the lines should be hidden.
1028 */
1029 int getColorMode() {
1030 return colorMode;
1031 }
1032
1033 /**
1034 * Sets the color used by the grid. As is common use, the same
1035 * color applies to horizontal and vertical, for the moment.
1036 * @param c color of the grid lines.
1037 */
1038 void setGridColor(Color c) {
1039 gridColor = c;
1040 }
1041
1042 /**
1043 * @return the grid color
1044 */
1045 Color getGridColor() {
1046 return gridColor;
1047 }
1048
1049 /**
1050 * @return whether or not to draw the grid at the front, i.e.,
1051 * in front of all the plotted stuff.
1052 */
1053 boolean gridToFront() {
1054 return toFront;
1055 }
1056
1057 /**
1058 * sets whether or not to draw the grid at the front.
1059 * @param b true if the grid will be moved to the front
1060 */
1061 void setGridToFront(boolean b) {
1062 toFront = b;
1063 }
1064
1065 /**
1066 * Sets the graph type. The integer is an symbolic constant,
1067 * must be one of the constants defined in class Data
1068 * (GRAPHTYPE_2D, GRAPHTYPE_PIPER, etc.).
1069 * @param s graph style (symbolic constant)
1070 */
1071 void setGraphType(int s) {
1072 graphType = s;
1073 if (s == GRAPHTYPE_PIPER) {
1074 gridColor = new Color(200,200,200);
1075 ticFont[X_AXIS] = Utils.getDefaultFont().deriveFont(9f);
1076 ticFont[Y_AXIS] = Utils.getDefaultFont().deriveFont(9f);
1077 }
1078 }
1079
1080 /**
1081 * Returns the current graph type.
1082 * @return the current graph type.
1083 */
1084 int getGraphType() {
1085 return graphType;
1086 }
1087
1088 /**
1089 * Sets the line drawing style for 2D graphs. The integer is an
1090 * symbolic constant, must be one of the constants defined in
1091 * class LinePars (LinePars.LINES, LinePars.HISTO, etc.).
1092 * @param s line style (symbolic constant)
1093 */
1094 void setGraphStyle(int s) {
1095 graphStyle = s;
1096 }
1097
1098 /**
1099 * Returns the current line style.
1100 * @return the current line style.
1101 */
1102 int getGraphStyle() {
1103 return graphStyle;
1104 }
1105
1106 /**
1107 * Returns the color used to fill the shaded triangles.
1108 * @return the color used to fill the shaded triangles.
1109 */
1110 public Color getInnerColor() {
1111 return triangleFillColor;
1112 }
1113
1114 /**
1115 * Sets the color used to fill the inner triangles.
1116 * @param c the color used to fill the shaded triangles.
1117 */
1118 public void setInnerColor(Color c) {
1119 triangleFillColor = c;
1120 }
1121
1122 /**
1123 * Sets whether or not to draw the filled triangles.
1124 * @param b true if the filled triangles should be drawn.
1125 */
1126 public void setShowInner(boolean b) {
1127 plotInner = b;
1128 }
1129
1130 /**
1131 * @return true if the filled triangles should be drawn.
1132 */
1133 public boolean showInner() {
1134 return plotInner;
1135 }
1136
1137 /**
1138 * Sets whether or not to draw the bounding box.
1139 * @param b true if the filled triangles should be drawn.
1140 */
1141 public void setShowBox(boolean b) {
1142 plotBox = b;
1143 }
1144
1145 /**
1146 * @return true if the bounding box should be drawn.
1147 */
1148 public boolean showBox() {
1149 return plotBox;
1150 }
1151
1152 /**
1153 * Sets the offset of the bounding box drawn around a graph.
1154 * @param f offset in pixels.
1155 */
1156 public void setBoxOffset(float f) {
1157 boxOffset = f;
1158 }
1159
1160 /**
1161 * @return the offset of the bounding box.
1162 */
1163 public float getBoxOffset() {
1164 return boxOffset;
1165 }
1166
1167 /**
1168 * Sets the fill color of the bounding box drawn around a graph.
1169 * @param c color.
1170 */
1171 public void setBoxFillColor(Color c) {
1172 boxFillColor = c;
1173 }
1174
1175 /**
1176 * @return the fill color of the bounding box.
1177 */
1178 public Color getBoxFillColor() {
1179 return boxFillColor;
1180 }
1181
1182 /**
1183 * Sets the color of the bounding box drawn around a graph.
1184 * @param c color.
1185 */
1186 public void setBoxColor(Color c) {
1187 boxColor = c;
1188 }
1189
1190 /**
1191 * @return the color of the bounding box.
1192 */
1193 public Color getBoxColor() {
1194 return boxColor;
1195 }
1196
1197 /**
1198 * Sets the background color of the graph.
1199 * @param c color.
1200 */
1201 public void setGraphBackgroundColor(Color c) {
1202 graphBgColor = c;
1203 }
1204
1205 /**
1206 * @return the color of the background of the graph.
1207 */
1208 public Color getGraphBackgroundColor() {
1209 return graphBgColor;
1210 }
1211
1212 /**
1213 * Sets the factor used to plot a TDS circle.
1214 * The size of the circle is proportional to the TDS but scaled
1215 * by some factor 100 or so. This factor is set by the user with
1216 * this method.
1217 * @param f scaling factor for the TDS circle.
1218 */
1219 public void setTdsFactor(float f) {
1220 tdsFac = f;
1221 }
1222
1223 /**
1224 * @return the factor used to plot a TDS circle.
1225 */
1226 public float getTdsFactor() {
1227 return tdsFac;
1228 }
1229
1230 /**
1231 * Sets whether the tds should be drawn or not.
1232 * @param b true if the TDS circle should be drawn on a piper diagram
1233 */
1234 public void setDrawTds(boolean b) {
1235 useTds = b;
1236 }
1237
1238 /**
1239 * @return true if the tds circle should be drawn.
1240 */
1241 public boolean drawTds() {
1242 return useTds;
1243 }
1244
1245 /**
1246 * Resets the class to all the default values.
1247 */
1248 public void reset() {
1249 for (int k=0; k<NAXES; k++) {
1250 minValue[k] = INF; // INF is 1e300
1251 maxValue[k] = -INF;
1252 autoRange[k] = true;
1253 isLogarithmic[k] = false;
1254 plotTicLabels[k] = true;
1255 plotTics[k] = true;
1256 plotAxis[k] = true;
1257 plotMirrorAxis[k] = true;
1258 rotateTics[k] = false;
1259 mirrorTics[k] = true;
1260 numberTics[k] = 0;
1261 useNumberOfTics[k] = false;
1262 ticColor[k] = Color.black;
1263 ticFont[k] = Utils.getDefaultFont();
1264 grid[k] = true;
1265 multiplier[k] = 1.0f;
1266 additioner[k] = 0.0f;
1267 globalDivider[k] = 1.0f;
1268 globalOffset[k] = 0.0f;
1269 legendPos[k] = 5.0f;
1270 ticLength[k] = 0.01;
1271 rotTics[k] = false;
1272 }
1273 setDataChanged(false);
1274 axesRatio = 0.0;
1275 panelSize = new Dimension(440,300);
1276 shadow = true;
1277 maxNumberOfTics = 20;
1278 //backgroundColor = new Color(255,255,220);
1279 axesColor = Color.black;
1280 leftMargin = 20;
1281 rightMargin = 27;
1282 bottomMargin = 15;
1283 topMargin = 15;
1284 useRatio = false;
1285 legendFont = Utils.getDefaultFont();
1286 legendSpacing = 1.0f;
1287 useLegendPosition = false;
1288 useLegend = true;
1289 gridColor = new Color(227,230,230);
1290 toFront = false;
1291 fontChanged = true;
1292 updatePlot = false;
1293 pointMode = DISABLE;
1294 colorMode = AUTO;
1295 graphStyle = LinePars.LINES;
1296 graphType = GRAPHTYPE_2D;
1297 triangleFillColor = new Color(224,223,221);
1298 plotInner = true;
1299 plotBox = false;
1300 boxFillColor = new Color(247,247,247);
1301 boxColor = Color.black;
1302 //backgroundColor = new Color(0,0,85);
1303 backgroundColor = new Color(247,247,247);
1304 graphBgColor = Color.white;
1305 boxOffset = 3.0f;
1306 tdsFac = 1000.0f;
1307 useTds = true;
1308 labels.clear();
1309 if (JPlot.debug) System.out.println("settings reset in GraphPars...");
1310 }
1311
1312 /**
1313 * Return the current parameter settings in a string.
1314 * This string is generally used to save the graph settings.
1315 * All settings are returned in some kind of keyword-based
1316 * format, i.e. keyword1 = value1 (separated by a newline).
1317 * @return graph settings in a string.
1318 */
1319 public String getSettings() {
1320 StringBuffer sb = new StringBuffer(1000);
1321 sb.append(" graph-parameters {");
1322 for (int k=0; k<NAXES; k++) {
1323 String sk = Integer.toString(k);
1324 sb.append(lf);
1325 sb.append(" min-axes ").append(sk).append(" = ").append(minValue[k]);
1326 sb.append(lf);
1327 sb.append(" max-axes ").append(sk).append(" = ").append(maxValue[k]);
1328 sb.append(lf);
1329 sb.append(" autorange ").append(sk).append(" = ").append(autoRange[k]);
1330 sb.append(lf);
1331 sb.append(" uselog ").append(sk).append(" = ").append(isLogarithmic[k]);
1332 sb.append(lf);
1333 sb.append(" showticlabels ").append(sk).append(" = ").append(plotTicLabels[k]);
1334 sb.append(lf);
1335 sb.append(" showtics ").append(sk).append(" = ").append(plotTics[k]);
1336 sb.append(lf);
1337 sb.append(" showaxis ").append(sk).append(" = ").append(plotAxis[k]);
1338 sb.append(lf);
1339 sb.append(" showmirroraxis ").append(sk).append(" = ").append(plotMirrorAxis[k]);
1340 sb.append(lf);
1341 sb.append(" rotatetics ").append(sk).append(" = ").append(rotateTics[k]);
1342 sb.append(lf);
1343 sb.append(" mirrortics ").append(sk).append(" = ").append(mirrorTics[k]);
1344 sb.append(lf);
1345 sb.append(" rotatetics ").append(sk).append(" = ").append(rotTics[k]);
1346 sb.append(lf);
1347 sb.append(" numoftics ").append(sk).append(" = ").append(numberTics[k]);
1348 sb.append(lf);
1349 sb.append(" fixnumoftics ").append(sk).append(" = ").append(useNumberOfTics[k]);
1350 sb.append(lf);
1351 sb.append(" ticcolor ").append(sk).append(" = ");
1352 sb.append(ticColor[k].getRed()).append(",");
1353 sb.append(ticColor[k].getGreen()).append(",");
1354 sb.append(ticColor[k].getBlue());
1355 sb.append(lf);
1356 sb.append(" ticfont ").append(sk).append(" = \"");
1357 sb.append(ticFont[k].getName()).append("\",");
1358 sb.append(ticFont[k].getStyle()).append(",");
1359 sb.append(ticFont[k].getSize());
1360 sb.append(lf);
1361 sb.append(" showgrid ").append(sk).append(" = ").append(grid[k]);
1362 sb.append(lf);
1363 sb.append(" legendpos ").append(sk).append(" = ").append(legendPos[k]);
1364 sb.append(lf);
1365 sb.append(" multiply ").append(sk).append(" = ").append(multiplier[k]);
1366 sb.append(lf);
1367 sb.append(" additioner ").append(sk).append(" = ").append(additioner[k]);
1368 sb.append(lf);
1369 sb.append(" datadivide ").append(sk).append(" = ").append(globalDivider[k]);
1370 sb.append(lf);
1371 sb.append(" dataoffset ").append(sk).append(" = ").append(globalOffset[k]);
1372 sb.append(lf);
1373 sb.append(" ticlength ").append(sk).append(" = ").append(ticLength[k]);
1374 sb.append(lf);
1375 }
1376 sb.append(lf);
1377 sb.append(" panelsize = ").append(getPanelWidth()).append(",");
1378 sb.append(getPanelHeight());
1379 sb.append(lf);
1380 sb.append(" bgcolor = ").append(backgroundColor.getRed()).append(",");
1381 sb.append(backgroundColor.getGreen()).append(",").append(backgroundColor.getBlue());
1382 sb.append(lf);
1383 sb.append(" axescolor = ").append(axesColor.getRed()).append(",");
1384 sb.append(axesColor.getGreen()).append(",").append(axesColor.getBlue());
1385 sb.append(lf);
1386 sb.append(" uselegendpos = ").append(useLegendPosition);
1387 sb.append(lf);
1388 sb.append(" legendspacing = ").append(legendSpacing);
1389 sb.append(lf);
1390 sb.append(" showlegend = ").append(useLegend);
1391 sb.append(lf);
1392 sb.append(" legendfont ").append(" = \"");
1393 sb.append(legendFont.getName()).append("\",");
1394 sb.append(legendFont.getStyle()).append(",");
1395 sb.append(legendFont.getSize());
1396 sb.append(lf);
1397 sb.append(" axesratio = ").append(axesRatio);
1398 sb.append(lf);
1399 sb.append(" useratio = ").append(useRatio);
1400 sb.append(lf);
1401 sb.append(" gridcolor = ").append(gridColor.getRed()).append(",");
1402 sb.append(gridColor.getGreen()).append(",").append(gridColor.getBlue());
1403 sb.append(lf);
1404 sb.append(" gridtofront = ").append(toFront);
1405 sb.append(lf);
1406 sb.append(" graphtype = ").append(graphType);
1407 sb.append(lf);
1408 sb.append(" plotboundingbox = ").append(plotBox);
1409 sb.append(lf);
1410 sb.append(" offset = ").append(boxOffset);
1411 sb.append(lf);
1412 sb.append(" boundingboxbgcolor = ");
1413 sb.append(boxFillColor.getRed()).append(",");
1414 sb.append(boxFillColor.getGreen()).append(",");
1415 sb.append(boxFillColor.getBlue());
1416 sb.append(lf);
1417 sb.append(" boundingboxcolor = ");
1418 sb.append(boxColor.getRed()).append(",");
1419 sb.append(boxColor.getGreen()).append(",");
1420 sb.append(boxColor.getBlue());
1421 sb.append(lf);
1422 sb.append(" graphbgcolor = ");
1423 sb.append(graphBgColor.getRed()).append(",");
1424 sb.append(graphBgColor.getGreen()).append(",");
1425 sb.append(graphBgColor.getBlue());
1426 if (graphType == GRAPHTYPE_PIPER) {
1427 sb.append(lf);
1428 sb.append(" innertriangle = ");
1429 sb.append(triangleFillColor.getRed()).append(",");
1430 sb.append(triangleFillColor.getGreen()).append(",");
1431 sb.append(triangleFillColor.getBlue()).append(plotInner);
1432 sb.append(lf).append(" tdsfactor = ").append(tdsFac);
1433 sb.append(lf).append(" drawtds = ").append(useTds);
1434 }
1435 for (Enumeration e=labels.elements(); e.hasMoreElements();) {
1436 GraphLabel gl = (GraphLabel) e.nextElement();
1437 if (!gl.equals(GraphLabel.DATA)) sb.append(gl.getSettings());
1438 }
1439 sb.append(lf).append(" }");
1440 return sb.toString();
1441 }
1442
1443 /*
1444 * Parses stuff like 'max-value 1 = <double-value>'
1445 * @param st stringtokenizer instance with the tokens
1446 */
1447 private void parseDouble(StringTokenizer st, double[] a) {
1448 int axis = Integer.parseInt(st.nextToken());
1449 if (axis >= NAXES) return;
1450 st.nextToken(); // eat '='
1451 a[axis] = Double.parseDouble(st.nextToken());
1452 }
1453
1454 /*
1455 * Parses stuff like 'max-value 1 = <float-value>'
1456 * @param st stringtokenizer instance with the tokens
1457 */
1458 private void parseFloat(StringTokenizer st, float[] a) {
1459 int axis = Integer.parseInt(st.nextToken());
1460 if (axis >= NAXES) return;
1461 st.nextToken(); // eat '='
1462 a[axis] = Float.parseFloat(st.nextToken());
1463 }
1464
1465 /*
1466 * Parses stuff like 'isLog 1 = <boolean-value>'
1467 * @param st stringtokenizer instance with the tokens
1468 */
1469 private void parseBoolean(StringTokenizer st, boolean[] a) {
1470 int axis = Integer.parseInt(st.nextToken());
1471 if (axis >= NAXES) return;
1472 st.nextToken(); // eat '='
1473 a[axis] = Boolean.valueOf(st.nextToken()).booleanValue();
1474 }
1475
1476 /*
1477 * Parses stuff like 'numoftics 0 = <integer-value>'
1478 * @param st stringtokenizer instance with the tokens
1479 */
1480 private void parseInteger(StringTokenizer st, int[] a) {
1481 int axis = Integer.parseInt(st.nextToken());
1482 if (axis >= NAXES) return;
1483 st.nextToken(); // eat '='
1484 a[axis] = Integer.parseInt(st.nextToken());
1485 }
1486
1487 /*
1488 * Parses a string for an axis
1489 * @param st stringtokenizer instance with the tokens
1490 */
1491 private void parseString(StringTokenizer st, String[] a) {
1492 int axis = Integer.parseInt(st.nextToken());
1493 if (axis >= NAXES) return;
1494 st.nextToken(); // eat '='
1495 String n = st.nextToken();
1496 if (n.startsWith("\"")) { // is name between " and "
1497 while (!n.endsWith("\"")) n += " " + st.nextToken();
1498 n = n.substring(1,n.length()-1);
1499 }
1500 a[axis] = n;
1501 }
1502
1503 /*
1504 * Parses a color for an axis
1505 * @param st stringtokenizer instance with the tokens
1506 */
1507 private void parseColor(StringTokenizer st, Color[] a) {
1508 int axis = Integer.parseInt(st.nextToken());
1509 if (axis >= NAXES) return;
1510 st.nextToken(); // eat '='
1511 a[axis] = new Color(Integer.parseInt(st.nextToken()),
1512 Integer.parseInt(st.nextToken()),
1513 Integer.parseInt(st.nextToken()));
1514 }
1515
1516 /*
1517 * Parses a font for an axis
1518 * @param st stringtokenizer instance with the tokens
1519 */
1520 private void parseFont(StringTokenizer st, Font[] a) {
1521 int axis = Integer.parseInt(st.nextToken());
1522 if (axis >= NAXES) return;
1523 st.nextToken(); // eat '='
1524 String n = st.nextToken();
1525 if (n.startsWith("\"")) { // is name between " and "
1526 while (!n.endsWith("\"")) n += " " + st.nextToken();
1527 n = n.substring(1,n.length()-1);
1528 }
1529 a[axis] = new Font(n,Integer.parseInt(st.nextToken()),
1530 Integer.parseInt(st.nextToken()));
1531 }
1532
1533 /*
1534 * Parses stuff like 'showTitle = <boolean-value>'
1535 * @param st stringtokenizer instance with the tokens
1536 */
1537 private boolean getBoolean(StringTokenizer st) {
1538 st.nextToken(); // eat '='
1539 return Boolean.valueOf(st.nextToken()).booleanValue();
1540 }
1541
1542 /*
1543 * Parses stuff like 'title = <string>'
1544 * @param st stringtokenizer instance with the tokens
1545 */
1546 private String getString(StringTokenizer st) {
1547 st.nextToken(); // eat '='
1548 String n = st.nextToken();
1549 if (n.startsWith("\"")) { // is name between " and "
1550 while (!n.endsWith("\"")) n += " " + st.nextToken();
1551 n = n.substring(1,n.length()-1);
1552 }
1553 return n;
1554 }
1555
1556 /*
1557 * Parses stuff like 'axesratio = <double-value>'
1558 * @param st stringtokenizer instance with the tokens
1559 */
1560 private double getDouble(StringTokenizer st) {
1561 st.nextToken(); // eat '='
1562 return Double.parseDouble(st.nextToken());
1563 }
1564
1565 /*
1566 * Parses stuff like 'keyword = <float-value>'
1567 * @param st stringtokenizer instance with the tokens
1568 */
1569 private float getFloat(StringTokenizer st) {
1570 st.nextToken(); // eat '='
1571 return Float.parseFloat(st.nextToken());
1572 }
1573
1574 /*
1575 * Parses stuff like 'keyword = <int-value>'
1576 * @param st stringtokenizer instance with the tokens
1577 */
1578 private int getInteger(StringTokenizer st) {
1579 st.nextToken(); // eat '='
1580 return Integer.parseInt(st.nextToken());
1581 }
1582
1583 /*
1584 * Parses stuff like 'panelSize = <width>,<height>'
1585 * @param st stringtokenizer instance with the tokens
1586 */
1587 private Dimension getDimension(StringTokenizer st) {
1588 st.nextToken(); // eat '='
1589 return new Dimension(Integer.parseInt(st.nextToken()),
1590 Integer.parseInt(st.nextToken()));
1591 }
1592
1593 /*
1594 * Parses a font for an axis
1595 * @param st stringtokenizer instance with the tokens
1596 */
1597 private Font getFont(StringTokenizer st) {
1598 st.nextToken(); // eat '='
1599 String n = st.nextToken();
1600 if (n.startsWith("\"")) { // is name between " and "
1601 while (!n.endsWith("\"")) n += " " + st.nextToken();
1602 n = n.substring(1,n.length()-1);
1603 }
1604 return new Font(n,Integer.parseInt(st.nextToken()),
1605 Integer.parseInt(st.nextToken()));
1606 }
1607
1608 /*
1609 * Parses a color for an axis
1610 * @param st stringtokenizer instance with the tokens
1611 */
1612 private Color getColor(StringTokenizer st) {
1613 st.nextToken(); // eat '='
1614 return new Color(Integer.parseInt(st.nextToken()),
1615 Integer.parseInt(st.nextToken()),
1616 Integer.parseInt(st.nextToken()));
1617 }
1618
1619 /*
1620 * Parses stuff which contains all label parameters.
1621 * @param st stringtokenizer inst