Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 3630:28be160b5870
Add a module service. It's now possible to configure the modules which are
available for a client. With the selected attribute it is possible to give
a hint for the client which module should be pre selected by default
flys-artifacts/trunk@5330 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 31 Aug 2012 13:17:16 +0000 |
parents | 63ef889eea2b |
children | d8f2ab5b61c3 |
rev | line source |
---|---|
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.jfree; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
3109
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
3 import de.intevation.flys.artifacts.math.Function; |
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
4 |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
5 import java.awt.Shape; |
3109
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
6 |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
7 import java.awt.geom.Rectangle2D; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
8 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
9 import java.util.Iterator; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 import org.jfree.chart.entity.ChartEntity; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 import org.jfree.chart.entity.EntityCollection; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
13 |
3109
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
14 import org.w3c.dom.Document; |
3105
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
15 |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 public class JFreeUtil { |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3023
diff
changeset
|
17 |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
18 /** Do not instantiate. */ |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 private JFreeUtil() { |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 } |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 /** |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 * True if \param hotspot collides with a Entity in \param entities. |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 * @param hotspot Shape to compare against other shapes (bounds only). |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 * @param entities entities against which to compare shape. |
3023
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
27 * @param exclusiveEntityClass If not null, consider only entities of |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
28 * given class. |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
29 * @return true if a collision (non-zero intersection) exists between |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 * shapes. |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 */ |
3023
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
32 public static boolean collides(Shape hotspot, EntityCollection entities, |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
33 Class exclusiveEntityClass) { |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 if (entities == null) return false; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 Rectangle2D hotspotBox = hotspot.getBounds2D(); |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3023
diff
changeset
|
37 |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 for (Iterator i = entities.iterator(); i.hasNext(); ) { |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
39 Object next = i.next(); |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 ChartEntity entity = (ChartEntity) next; |
3023
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
41 if (exclusiveEntityClass == null |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
42 || exclusiveEntityClass.isInstance(entity)) |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
43 { |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
44 if (entity.getArea().intersects(hotspotBox)) { |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
45 // Found collision, early stop. |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
46 return true; |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
47 } |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
48 } |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
49 } |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
50 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
51 return false; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
52 } |
3105
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
53 |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
54 |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
55 public static StyledXYSeries sampleFunction2D( |
3109
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
56 Function func, |
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
57 Document theme, |
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
58 String seriesKey, |
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
59 int samples, |
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
60 double start, |
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
61 double end |
3105
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
62 ) { |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
63 StyledXYSeries series = new StyledXYSeries(seriesKey, theme); |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
64 |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
65 double step = (end - start) / (samples - 1); |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
66 |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
67 for (int i = 0; i < samples; i++) { |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
68 double x = start + (step * i); |
3109
63ef889eea2b
SQ: Directly sample our Function objects instead of Function2D from JFreeChart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3105
diff
changeset
|
69 series.add(x, func.value(x)); |
3105
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
70 } |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
71 |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
72 return series; |
9592b7d76633
Generate fake data for SQ curves; Implemented the Facet and Generator stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3083
diff
changeset
|
73 } |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
74 } |
3083
4bd3d8bbb60c
Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |