001    /*
002     * Copyright (C) 2008-2010 by Holger Arndt
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * UJMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with UJMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.ujmp.gui.plot;
025    
026    import java.awt.BasicStroke;
027    import java.awt.Color;
028    import java.awt.Stroke;
029    import java.util.ArrayList;
030    import java.util.List;
031    
032    import org.ujmp.gui.MatrixGUIObject;
033    
034    public class PlotSettings {
035    
036            private MatrixGUIObject matrixGUIObject = null;
037    
038            private long timeLimit = 5000;
039    
040            private int height = 600;
041    
042            private int width = 800;
043    
044            private Color axisColor = new Color(0, 0, 0, 100);
045    
046            private Color zeroAxisColor = new Color(0, 0, 0, 150);
047    
048            private Color plotBackGroundColor = new Color(216, 213, 196);
049    
050            private boolean showXAxis = true;
051    
052            private boolean showYAxis = true;
053    
054            private boolean showZeroAxis = true;
055    
056            private boolean showSelection = true;
057    
058            private boolean showPlotBackGround = true;
059    
060            private double minXValue = 0;
061    
062            private double maxXValue = 0;
063    
064            private double minYValue = -2;
065    
066            private double maxYValue = 2;
067    
068            private List<Color> plotColors = new ArrayList<Color>();
069    
070            private List<Stroke> plotStrokes = new ArrayList<Stroke>();
071    
072            private Stroke axisStroke = new BasicStroke(0.5f);
073    
074            private Stroke zeroAxisStroke = new BasicStroke(1.5f);
075    
076            public static final float[] DASHPATTERN = { 2f, 2f };
077    
078            public static final Stroke DASHEDSTROKE = new BasicStroke(0.5f,
079                            BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, DASHPATTERN, 0);
080    
081            private Stroke yGridStroke = DASHEDSTROKE;
082    
083            private Stroke xGridStroke = DASHEDSTROKE;
084    
085            private Color xGridColor = new Color(255, 255, 255, 180);
086    
087            private Color yGridColor = new Color(255, 255, 255, 180);
088    
089            private Color selectionColor = new Color(150, 150, 255, 80);
090    
091            private Color selectionLineColor = new Color(80, 80, 255);
092    
093            private List<Boolean> plotTraces = new ArrayList<Boolean>();
094    
095            private boolean showXGrid = true;
096    
097            private boolean showYGrid = true;
098    
099            private boolean showRunningAverage = false;
100    
101            private int runningAverageLength = 60;
102    
103            private Color runningAverageLineColor = new Color(100, 70, 0);
104    
105            private Stroke runningAverageStroke = new BasicStroke(0.5f);
106    
107            public void setAxisColor(Color axisColor) {
108                    this.axisColor = axisColor;
109            }
110    
111            public PlotSettings(MatrixGUIObject m) {
112                    this();
113                    this.matrixGUIObject = m;
114            }
115    
116            public PlotSettings() {
117                    plotColors.add(Color.BLUE);
118                    plotColors.add(Color.RED);
119                    plotColors.add(Color.GREEN);
120                    plotColors.add(Color.YELLOW);
121                    plotColors.add(Color.BLACK);
122                    plotColors.add(Color.WHITE);
123                    plotColors.add(Color.cyan);
124                    plotColors.add(Color.MAGENTA);
125                    plotColors.add(Color.orange);
126                    plotColors.add(Color.pink);
127                    plotStrokes.add(new BasicStroke(0.5f));
128                    plotStrokes.add(new BasicStroke(0.5f));
129                    plotStrokes.add(new BasicStroke(0.5f));
130                    plotStrokes.add(new BasicStroke(0.5f));
131                    plotStrokes.add(new BasicStroke(0.5f));
132                    plotStrokes.add(new BasicStroke(0.5f));
133                    plotStrokes.add(new BasicStroke(0.5f));
134                    plotStrokes.add(new BasicStroke(0.5f));
135                    plotStrokes.add(new BasicStroke(0.5f));
136                    plotStrokes.add(new BasicStroke(0.5f));
137                    plotTraces.add(true);
138                    plotTraces.add(true);
139                    plotTraces.add(true);
140                    plotTraces.add(true);
141                    plotTraces.add(true);
142                    plotTraces.add(true);
143                    plotTraces.add(true);
144                    plotTraces.add(true);
145                    plotTraces.add(true);
146                    plotTraces.add(true);
147            }
148    
149            public int getHeight() {
150                    return height;
151            }
152    
153            public void setHeight(int height) {
154                    this.height = height;
155            }
156    
157            public MatrixGUIObject getMatrixGUIObject() {
158                    return matrixGUIObject;
159            }
160    
161            public void setMatrixGUIObject(MatrixGUIObject matrixGUIObject) {
162                    this.matrixGUIObject = matrixGUIObject;
163            }
164    
165            public int getWidth() {
166                    return width;
167            }
168    
169            public void setWidth(int width) {
170                    this.width = width;
171            }
172    
173            public Color getAxisColor() {
174                    return axisColor;
175            }
176    
177            public boolean isShowXAxis() {
178                    return showXAxis;
179            }
180    
181            public void setShowXAxis(boolean showXAxis) {
182                    this.showXAxis = showXAxis;
183            }
184    
185            public boolean isShowYAxis() {
186                    return showYAxis;
187            }
188    
189            public void setShowYAxis(boolean showYAxis) {
190                    this.showYAxis = showYAxis;
191            }
192    
193            public Stroke getAxisStroke() {
194                    return axisStroke;
195            }
196    
197            public Color getPlotBackGroundColor() {
198                    return plotBackGroundColor;
199            }
200    
201            public void setPlotBackGroundColor(Color plotBackGroundColor) {
202                    this.plotBackGroundColor = plotBackGroundColor;
203            }
204    
205            public void setAxisStroke(Stroke axisStroke) {
206                    this.axisStroke = axisStroke;
207            }
208    
209            public boolean isShowPlotBackGround() {
210                    return showPlotBackGround;
211            }
212    
213            public double getMaxXValue() {
214                    return maxXValue;
215            }
216    
217            public void setMaxXValue(double maxX) {
218                    this.maxXValue = maxX;
219            }
220    
221            public double getMaxYValue() {
222                    return maxYValue;
223            }
224    
225            public void setMaxYValue(double maxY) {
226                    this.maxYValue = maxY;
227            }
228    
229            public double getMinXValue() {
230                    return minXValue;
231            }
232    
233            public void setMinXValue(double minX) {
234                    this.minXValue = minX;
235            }
236    
237            public double getMinYValue() {
238                    return minYValue;
239            }
240    
241            public void setMinYValue(double minY) {
242                    this.minYValue = minY;
243            }
244    
245            public void setShowPlotBackGround(boolean showPlotBackGround) {
246                    this.showPlotBackGround = showPlotBackGround;
247            }
248    
249            public double getXStepSize() {
250                    double xs = (maxXValue - minXValue) / getWidth() / 2.0;
251                    return xs < 1 ? 1 : xs;
252            }
253    
254            public double getXGridStepSize() {
255                    return 25.0 * (getMaxXValue() - getMinXValue()) / getWidth();
256            }
257    
258            public double getXStepCount() {
259                    return (maxXValue - minXValue) / getXStepSize();
260            }
261    
262            public Stroke getXGridStroke() {
263                    return xGridStroke;
264            }
265    
266            public Stroke getYGridStroke() {
267                    return yGridStroke;
268            }
269    
270            public void setXGridStroke(Stroke gridStroke) {
271                    xGridStroke = gridStroke;
272            }
273    
274            public void setYGridStroke(Stroke gridStroke) {
275                    yGridStroke = gridStroke;
276            }
277    
278            public Color getXGridColor() {
279                    return xGridColor;
280            }
281    
282            public Color getYGridColor() {
283                    return yGridColor;
284            }
285    
286            public double getXFactor() {
287                    return getWidth() / (getMaxXValue() - getMinXValue());
288            }
289    
290            public double getYGridStepSize() {
291                    return 25.0 * (getMaxYValue() - getMinYValue()) / getHeight();
292            }
293    
294            public boolean isShowXGrid() {
295                    return showXGrid;
296            }
297    
298            public boolean isShowYGrid() {
299                    return showYGrid;
300            }
301    
302            public double getYFactor() {
303                    return getHeight() / (getMaxYValue() - getMinYValue());
304            }
305    
306            public boolean isShowTrace(int i) {
307                    return plotTraces.get(i);
308            }
309    
310            public Stroke getTraceStroke(int t) {
311                    return plotStrokes.get(t);
312            }
313    
314            public Color getTraceColor(int t) {
315                    return plotColors.get(t);
316            }
317    
318            public List<Color> getPlotColors() {
319                    return plotColors;
320            }
321    
322            public void setPlotColors(List<Color> plotColors) {
323                    this.plotColors = plotColors;
324            }
325    
326            public List<Stroke> getPlotStrokes() {
327                    return plotStrokes;
328            }
329    
330            public void setPlotStrokes(List<Stroke> plotStrokes) {
331                    this.plotStrokes = plotStrokes;
332            }
333    
334            public List<Boolean> getPlotTraces() {
335                    return plotTraces;
336            }
337    
338            public void setPlotTraces(List<Boolean> plotTraces) {
339                    this.plotTraces = plotTraces;
340            }
341    
342            public void setShowXGrid(boolean showXGrid) {
343                    this.showXGrid = showXGrid;
344            }
345    
346            public void setShowYGrid(boolean showYGrid) {
347                    this.showYGrid = showYGrid;
348            }
349    
350            public void setXGridColor(Color gridColor) {
351                    xGridColor = gridColor;
352            }
353    
354            public void setYGridColor(Color gridColor) {
355                    yGridColor = gridColor;
356            }
357    
358            public long getTimeLimit() {
359                    return timeLimit;
360            }
361    
362            public void setTimeLimit(long timeLimit) {
363                    this.timeLimit = timeLimit;
364            }
365    
366            public Color getSelectionColor() {
367                    return selectionColor;
368            }
369    
370            public void setSelectionColor(Color selectionColor) {
371                    this.selectionColor = selectionColor;
372            }
373    
374            public boolean isShowSelection() {
375                    return showSelection;
376            }
377    
378            public Color getSelectionLineColor() {
379                    return selectionLineColor;
380            }
381    
382            public void setSelectionLineColor(Color selectionLineColor) {
383                    this.selectionLineColor = selectionLineColor;
384            }
385    
386            public void setShowSelection(boolean showSelection) {
387                    this.showSelection = showSelection;
388            }
389    
390            public boolean isShowZeroAxis() {
391                    return showZeroAxis;
392            }
393    
394            public void setShowZeroAxis(boolean showZeroAxis) {
395                    this.showZeroAxis = showZeroAxis;
396            }
397    
398            public Color getZeroAxisColor() {
399                    return zeroAxisColor;
400            }
401    
402            public void setZeroAxisColor(Color zeroAxisColor) {
403                    this.zeroAxisColor = zeroAxisColor;
404            }
405    
406            public Stroke getZeroAxisStroke() {
407                    return zeroAxisStroke;
408            }
409    
410            public void setZeroAxisStroke(Stroke zeroAxisStroke) {
411                    this.zeroAxisStroke = zeroAxisStroke;
412            }
413    
414            public boolean isShowRunningAverage() {
415                    return showRunningAverage;
416            }
417    
418            public int getRunningAverageLength() {
419                    return runningAverageLength;
420            }
421    
422            public Color getRunningAverageLineColor() {
423                    return runningAverageLineColor;
424            }
425    
426            public Stroke getRunningAverageStroke() {
427                    return runningAverageStroke;
428            }
429    
430            public void setShowRunningAverage(boolean showRunningAverage) {
431                    this.showRunningAverage = showRunningAverage;
432            }
433    
434            public void setRunningAverageLength(int runningAverageLength) {
435                    this.runningAverageLength = runningAverageLength;
436            }
437    
438            public void setRunningAverageLineColor(Color runningAverageLineColor) {
439                    this.runningAverageLineColor = runningAverageLineColor;
440            }
441    
442            public void setRunningAverageStroke(Stroke runningAverageStroke) {
443                    this.runningAverageStroke = runningAverageStroke;
444            }
445    
446    }