Source Code Cross Referenced for GraphChartArea.java in  » Chart » Chart2D_1.9.6k » net » sourceforge » chart2d » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » Chart2D_1.9.6k » net.sourceforge.chart2d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Chart2D, a java library for drawing two dimensional charts.
003:         * Copyright (C) 2001 Jason J. Simas
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         *
018:         * The author of this library may be contacted at:
019:         * E-mail:  jjsimas@users.sourceforge.net
020:         * Street Address:  J J Simas, 887 Tico Road, Ojai, CA 93023-3555 USA
021:         */package net.sourceforge.chart2d;
022:
023:        import java.awt.*;
024:        import java.util.*;
025:
026:        /**
027:         * A container containing information and components for cartesian coordinate
028:         * charts.  That is, charts that are plotted on a parralelogram surface.
029:         */
030:        class GraphChartArea extends ChartArea {
031:
032:            private Vector datasetVector;
033:            private Vector graphVector;
034:
035:            private XAxisArea xAxis;
036:            private YAxisArea yAxis;
037:            private Rectangle maxBounds;
038:            private Rectangle minBounds;
039:
040:            private int numPlotAxisLabels;
041:
042:            private float yAxisToWidthRatio;
043:            private float yAxisToHeightRatio;
044:
045:            private float xAxisToWidthRatio;
046:            private float xAxisToHeightRatio;
047:
048:            private float graphToWidthRatio;
049:            private float graphToHeightRatio;
050:            private float graphableToAvailableRatio;
051:
052:            private boolean graphLinesThicknessAssociation;
053:            private boolean graphHorizontalLinesExistence;
054:            private int graphHorizontalLinesThicknessModel;
055:            private float[] graphHorizontalLinesStyle;
056:            private Color graphHorizontalLinesColor;
057:
058:            private boolean graphVerticalLinesExistence;
059:            private int graphVerticalLinesThicknessModel;
060:            private float[] graphVerticalLinesStyle;
061:            private Color graphVerticalLinesColor;
062:
063:            private boolean customizeGreatestValue;
064:            private float customGreatestValue;
065:            private boolean customizeLeastValue;
066:            private float customLeastValue;
067:
068:            private float numbersAxisRangeHigh;
069:            private float numbersAxisRangeLow;
070:
071:            private int numbersAxisLabelsType;
072:            private Vector warningRegions;
073:
074:            private boolean graphComponentsColoringByCat;
075:            private Color[] graphComponentsColorsByCat;
076:
077:            private boolean needsUpdate;
078:
079:            /**
080:             * Creates a Graph Chart Area with the default values of a TitledArea,
081:             * and its own default values.
082:             */
083:            GraphChartArea() {
084:
085:                xAxis = new XAxisArea();
086:                yAxis = new YAxisArea();
087:                maxBounds = new Rectangle();
088:                minBounds = new Rectangle();
089:                needsUpdate = true;
090:
091:                setNumPlotAxisLabels(5);
092:                setCustomGreatestValue(false, 0f);
093:                setCustomLeastValue(false, 0f);
094:                setGraphableToAvailableRatio(.95f);
095:
096:                setYAxisToWidthRatio(.25f);
097:                setXAxisToWidthRatio(.50f);
098:                setGraphToWidthRatio(.50f);
099:
100:                setYAxisToHeightRatio(.75f);
101:                setGraphToHeightRatio(.75f);
102:                setXAxisToHeightRatio(.25f);
103:
104:                setWarningRegions(new Vector(0, 0));
105:
106:                setGraphComponentsColoringByCat(false);
107:                setGraphComponentsColorsByCat(new Color[0]);
108:
109:                resetGraphChartAreaModel(true);
110:            }
111:
112:            /**
113:             * Sets whether the graph components are colored by category or by set.
114:             * @param b If true, then colored by category.
115:             */
116:            final void setGraphComponentsColoringByCat(boolean b) {
117:
118:                needsUpdate = true;
119:                graphComponentsColoringByCat = b;
120:            }
121:
122:            /**
123:             * Sets the color array for the graph component coloring.
124:             * @param colors The color array for the category coloring.
125:             */
126:            final void setGraphComponentsColorsByCat(Color[] colors) {
127:
128:                needsUpdate = true;
129:                graphComponentsColorsByCat = colors;
130:            }
131:
132:            /**
133:             * Sets the warning regions vector for applying to each graph area.
134:             * @param v the warning regions vector.
135:             */
136:            final void setWarningRegions(Vector v) {
137:
138:                warningRegions = v;
139:                needsUpdate = true;
140:            }
141:
142:            /**
143:             * Sets the dataset vector.
144:             * @param vector A vector of datasets.
145:             */
146:            final void setDatasetVector(Vector vector) {
147:
148:                needsUpdate = true;
149:                datasetVector = vector;
150:            }
151:
152:            /**
153:             * Sets the number of labels for the plot axis.  For every graph chart, there
154:             * are two axes.  One axis you specify the labels (ex. June, July, August);
155:             * the other axis, this library figures out the labels (ex. 250 or 1.95).
156:             * The axis the library labels is the plot axis.
157:             * @param num The number of plot axis labels.
158:             */
159:            final void setNumPlotAxisLabels(int num) {
160:
161:                needsUpdate = true;
162:                numPlotAxisLabels = num;
163:            }
164:
165:            /**
166:             * Specifies how much of the maximum width less borders and gaps to make
167:             * availalble to the y axis maximum size.
168:             * @param ratio The ratio to the width, to make available to the y axis.
169:             */
170:            final void setYAxisToWidthRatio(float ratio) {
171:
172:                needsUpdate = true;
173:                yAxisToWidthRatio = ratio;
174:            }
175:
176:            /**
177:             * Specifies how much of the maximum height less borders, gaps, and title to
178:             * make availalble to the y axis maximum size.
179:             * @param ratio The ratio to the height, to make available to the y axis.
180:             */
181:            final void setYAxisToHeightRatio(float ratio) {
182:
183:                needsUpdate = true;
184:                yAxisToHeightRatio = ratio;
185:            }
186:
187:            /**
188:             * Specifies how much of the maximum width less borders and gaps to make
189:             * availalble to the x axis maximum size.
190:             * @param ratio The ratio to the width, to make available to the x axis.
191:             */
192:            final void setXAxisToWidthRatio(float ratio) {
193:
194:                needsUpdate = true;
195:                xAxisToWidthRatio = ratio;
196:            }
197:
198:            /**
199:             * Specifies how much of the maximum height less borders, gaps, and title to
200:             * make availalble to the x axis maximum size.
201:             * @param ratio The ratio to the height, to make available to the x axis.
202:             */
203:            final void setXAxisToHeightRatio(float ratio) {
204:
205:                needsUpdate = true;
206:                xAxisToHeightRatio = ratio;
207:            }
208:
209:            /**
210:             * Specifies how much of the maximum width less borders and gaps to make
211:             * availalble to the graph maximum size.
212:             * @param ratio The ratio to the width, to make available to the graph.
213:             */
214:            final void setGraphToWidthRatio(float ratio) {
215:
216:                needsUpdate = true;
217:                graphToWidthRatio = ratio;
218:            }
219:
220:            /**
221:             * Specifies how much of the maximum height less borders, gaps, and title to
222:             * make availalble to the graph maximum size.
223:             * @param ratio The ratio to the height, to make available to the graph.
224:             */
225:            final void setGraphToHeightRatio(float ratio) {
226:
227:                needsUpdate = true;
228:                graphToHeightRatio = ratio;
229:            }
230:
231:            /**
232:             * Influences the plot axis' label with the highest value.
233:             * Does this by tricking chart2d into thinking that the passed value is the
234:             * largest value in the dataset.
235:             * Then if setGraphableToAvailableRatio (1f), the plot axis' label with the
236:             * the highest value will be the custom greatest value.
237:             * So, in order to control what the highest value plot axis label is, then
238:             * use this method, the setGraphableToAvailableRatio method, and the
239:             * setLabelsPrecisionNum method.
240:             * Note:  If there are both positive and negative numbers in the dataset
241:             * then you may need to set both custom greatest and custom least methods
242:             * since labels are always equally far from zero.
243:             * @param customize Whether this value is used.
244:             * @param value The value to use.
245:             */
246:            final void setCustomGreatestValue(boolean customize, float value) {
247:
248:                needsUpdate = true;
249:                customizeGreatestValue = customize;
250:                customGreatestValue = value;
251:            }
252:
253:            /**
254:             * Influences the plot axis' label with the lowest value.
255:             * Does this by tricking chart2d into thinking that the passed value is the
256:             * largest value in the dataset.
257:             * Then if setGraphableToAvailableRatio (1f), the plot axis' label with the
258:             * the highest value will be the custom greatest value.
259:             * So, in order to control what the highest value plot axis label is, then
260:             * use this method, the setGraphableToAvailableRatio method, and the
261:             * setLabelsPrecisionNum method.
262:             * Note:  If there are both positive and negative numbers in the dataset
263:             * then you may need to set both custom greatest and custom least methods
264:             * since labels are always equally far from zero.
265:             * @param customize Whether this value is used.
266:             * @param value The value to use.
267:             */
268:            final void setCustomLeastValue(boolean customize, float value) {
269:
270:                needsUpdate = true;
271:                customizeLeastValue = customize;
272:                customLeastValue = value;
273:            }
274:
275:            /**
276:             * Specifies how much of he height <b>of the graph</b> to make available to
277:             * the components plot area.  If this ratio is set to one, then the highest
278:             * value of all the data sets will touch the top of the graph area.
279:             * @param ratio The ratio of the graph height to the greatest value in the
280:             * data set.  [Must be between 0.0 and 1.0]
281:             */
282:            final void setGraphableToAvailableRatio(float ratio) {
283:
284:                needsUpdate = true;
285:                graphableToAvailableRatio = ratio;
286:            }
287:
288:            /**
289:             * Gets whether the graph components are colored by category or by set.
290:             * @return If true, then colored by category.
291:             */
292:            final boolean getGraphComponentsColoringByCat() {
293:                return graphComponentsColoringByCat;
294:            }
295:
296:            /**
297:             * Gets the color array for the graph component coloring.
298:             * @return The color array for the category coloring.
299:             */
300:            final Color[] getGraphComponentsColorsByCat() {
301:                return graphComponentsColorsByCat;
302:            }
303:
304:            /**
305:             * Gets the warning regions vector for applying to each graph area.
306:             * @return the warning regions vector.
307:             */
308:            final Vector getWarningRegions() {
309:                return warningRegions;
310:            }
311:
312:            /**
313:             * Returns all the Dataset objects added to this object.
314:             * @return Vector The Dataset objects.
315:             */
316:            final Vector getDatasetVector() {
317:                return datasetVector;
318:            }
319:
320:            /**
321:             * Returns the x Axis in order to allow customizations of it.
322:             * @return The x axis of this chart.
323:             */
324:            final XAxisArea getXAxis() {
325:
326:                return xAxis;
327:            }
328:
329:            /**
330:             * Returns the y axis in order to allow customization of it.
331:             * @return The y axis of this chart.
332:             */
333:            final YAxisArea getYAxis() {
334:
335:                return yAxis;
336:            }
337:
338:            /**
339:             * Sets the vector of graphs for this chart.
340:             * @param vector The vector of graphs.
341:             */
342:            final void setGraphVector(Vector vector) {
343:
344:                needsUpdate = true;
345:                graphVector = vector;
346:            }
347:
348:            /**
349:             * Returns a vector with all the graphs that were added by the addGraph method.
350:             * @return Vector A vector of graphs.
351:             */
352:            final Vector getGraphVector() {
353:
354:                return graphVector;
355:            }
356:
357:            /**
358:             * Gets the number of labels for the plot axis.  For every graph chart, there
359:             * are two axes.  One axis you specify the labels (ex. June, July, August);
360:             * the other axis, this library figures out the labels (ex. 250 or 1.95).
361:             * The axis the library labels is the plot axis.
362:             * @return The number of plot axis labels.
363:             */
364:            final int getNumPlotAxisLabels() {
365:
366:                return numPlotAxisLabels;
367:            }
368:
369:            /**
370:             * Returns this property in order for subclasses to have access to it.
371:             * @return The specified property.
372:             */
373:            final float getYAxisToWidthRatio() {
374:
375:                return yAxisToWidthRatio;
376:            }
377:
378:            /**
379:             * Returns this property in order for subclasses to have access to it.
380:             * @return The specified property.
381:             */
382:            final float getYAxisToHeightRatio() {
383:
384:                return yAxisToHeightRatio;
385:            }
386:
387:            /**
388:             * Returns this property in order for subclasses to have access to it.
389:             * @return The specified property.
390:             */
391:            final float getXAxisToWidthRatio() {
392:
393:                return xAxisToWidthRatio;
394:            }
395:
396:            /**
397:             * Returns this property in order for subclasses to have access to it.
398:             * @return The specified property.
399:             */
400:            final float getXAxisToHeightRatio() {
401:
402:                return xAxisToHeightRatio;
403:            }
404:
405:            /**
406:             * Returns this property in order for subclasses to have access to it.
407:             * @return The specified property.
408:             */
409:            float getGraphToWidthRatio() {
410:
411:                return graphToWidthRatio;
412:            }
413:
414:            /**
415:             * Returns this property in order for subclasses to have access to it.
416:             * @return The specified property.
417:             */
418:            final float getGraphToHeightRatio() {
419:
420:                return graphToHeightRatio;
421:            }
422:
423:            /**
424:             * Gets the boolean value passed to setCustomGreatestValue (boolean, float).
425:             * @return True if the max value is being customized.
426:             */
427:            final boolean getCustomizeGreatestValue() {
428:
429:                return customizeGreatestValue;
430:            }
431:
432:            /**
433:             * Gets the float value passed to setCustomGreatestValue (boolean, float).
434:             * @return The max value.
435:             */
436:            final float getCustomGreatestValue() {
437:
438:                return customGreatestValue;
439:            }
440:
441:            /**
442:             * Gets the boolean value passed to setCustomLeastValue (boolean, float).
443:             * @return True if the min value is being customized.
444:             */
445:            final boolean getCustomizeLeastValue() {
446:
447:                return customizeLeastValue;
448:            }
449:
450:            /**
451:             * Gets the float value passed to setCustomLeastValue (boolean, float).
452:             * @return The min value.
453:             */
454:            final float getCustomLeastValue() {
455:
456:                return customLeastValue;
457:            }
458:
459:            /**
460:             * Returns this property in order for subclasses to have access to it.
461:             * @return The specified property.
462:             */
463:            final float getGraphableToAvailableRatio() {
464:
465:                return graphableToAvailableRatio;
466:            }
467:
468:            /**
469:             * Indicates whether some property of this class has changed.
470:             * @return boolean true if some property has changed.
471:             */
472:            final boolean getGraphChartAreaNeedsUpdate() {
473:
474:                for (int i = 0; i < warningRegions.size(); ++i) {
475:                    needsUpdate = needsUpdate
476:                            || ((WarningRegion) warningRegions.get(i))
477:                                    .getWarningRegionNeedsUpdate();
478:                }
479:                return (needsUpdate || getChartAreaNeedsUpdate()
480:                        || xAxis.getXAxisAreaNeedsUpdate() || yAxis
481:                        .getYAxisAreaNeedsUpdate());
482:            }
483:
484:            /**
485:             * Resets the model for this class.  The model is used for shrinking and
486:             * growing of its components based on the maximum size of this class.  If this
487:             * method is called, then the next time the maximum size is set, this classes
488:             * model maximum size will be made equal to the new maximum size.  Effectively
489:             * what this does is ensure that whenever this objects maximum size is equal
490:             * to the one given, then all of the components will take on their default
491:             * model sizes.  Note:  This is only useful when auto model max sizing is
492:             * disabled.
493:             * @param reset True resets the max model upon the next max sizing.
494:             */
495:            final void resetGraphChartAreaModel(boolean reset) {
496:
497:                needsUpdate = true;
498:                resetChartAreaModel(reset);
499:                xAxis.resetXAxisModel(reset);
500:                yAxis.resetYAxisModel(reset);
501:            }
502:
503:            /**
504:             * Updates this parent's variables, and this' variables.
505:             * @param g2D The graphics context to use for calculations.
506:             */
507:            final void updateGraphChartArea(Graphics2D g2D) {
508:
509:                if (getGraphChartAreaNeedsUpdate()) {
510:                    updateChartArea(g2D);
511:                    //update warning regions after graphs are updated
512:                }
513:                needsUpdate = false;
514:            }
515:
516:            /**
517:             * Updates this parent's variables, and this' variables.
518:             * @param g2D The graphics context to use for calculations.
519:             */
520:            void paintComponent(Graphics2D g2D) {
521:
522:                updateGraphChartArea(g2D);
523:                super .paintComponent(g2D);
524:                for (int i = 0; i < warningRegions.size(); ++i) {
525:                    ((WarningRegion) warningRegions.get(i)).paintComponent(g2D);
526:                }
527:                xAxis.paintComponent(g2D);
528:                yAxis.paintComponent(g2D);
529:            }
530:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.