SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
SSJCategorySeriesCollection.java
1/*
2 * Class: SSJCategorySeriesCollection
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.charts;
26
27import org.jfree.data.category.CategoryDataset;
28import org.jfree.chart.renderer.category.CategoryItemRenderer;
29
30import java.util.Locale;
31import java.util.Formatter;
32import java.awt.Color;
33
41public abstract class SSJCategorySeriesCollection {
42 protected CategoryItemRenderer renderer;
43 protected CategoryDataset seriesCollection;
44
48
55 public String getCategory(int series) {
56 return seriesCollection.getColumnKey(series).toString();
57 }
58
66 public double getValue(int series, int index) {
67 return (Double) seriesCollection.getValue(series, index);
68 }
69
75 public CategoryDataset getSeriesCollection() {
76 return seriesCollection;
77 }
78
84 public abstract double[] getRangeBounds();
85
91 public abstract String toString();
92
96
100
106 public CategoryItemRenderer getRenderer() {
107 return renderer;
108 }
109
117 public void setRenderer(CategoryItemRenderer renderer) {
118 this.renderer = renderer;
119 }
120
126 public Color getColor(int series) {
127 return (Color) renderer.getSeriesPaint(series);
128 }
129
136 public void setColor(int series, Color color) {
137 renderer.setSeriesPaint(series, color);
138 }
139
152 public abstract String toLatex(double YScale, double YShift, double ymin, double ymax);
153
161 protected static String detectXColorClassic(Color color) {
162 String retour = null;
163
164 int red = color.getRed();
165 int green = color.getGreen();
166 int blue = color.getBlue();
167
168 // On utilise pas la method Color.equals(Color ) car on ne veut pas tester le
169 // parametre de transparence : Alpha
170 if (red == Color.GREEN.getRed() && blue == Color.GREEN.getBlue() && green == Color.GREEN.getGreen())
171 return "green";
172 else if (red == Color.RED.getRed() && blue == Color.RED.getBlue() && green == Color.RED.getGreen())
173 return "red";
174 else if (red == Color.WHITE.getRed() && blue == Color.WHITE.getBlue() && green == Color.WHITE.getGreen())
175 return "white";
176 else if (red == Color.GRAY.getRed() && blue == Color.GRAY.getBlue() && green == Color.GRAY.getGreen())
177 return "gray";
178 else if (red == Color.BLACK.getRed() && blue == Color.BLACK.getBlue() && green == Color.BLACK.getGreen())
179 return "black";
180 else if (red == Color.YELLOW.getRed() && blue == Color.YELLOW.getBlue() && green == Color.YELLOW.getGreen())
181 return "yellow";
182 else if (red == Color.MAGENTA.getRed() && blue == Color.MAGENTA.getBlue() && green == Color.MAGENTA.getGreen())
183 return "magenta";
184 else if (red == Color.CYAN.getRed() && blue == Color.CYAN.getBlue() && green == Color.CYAN.getGreen())
185 return "cyan";
186 else if (red == Color.BLUE.getRed() && blue == Color.BLUE.getBlue() && green == Color.BLUE.getGreen())
187 return "blue";
188 else if (red == Color.DARK_GRAY.getRed() && blue == Color.DARK_GRAY.getBlue()
189 && green == Color.DARK_GRAY.getGreen())
190 return "darkgray";
191 else if (red == Color.LIGHT_GRAY.getRed() && blue == Color.LIGHT_GRAY.getBlue()
192 && green == Color.LIGHT_GRAY.getGreen())
193 return "lightgray";
194 else if (red == Color.ORANGE.getRed() && blue == Color.ORANGE.getBlue() && green == Color.ORANGE.getGreen())
195 return "orange";
196 else if (red == Color.PINK.getRed() && blue == Color.PINK.getBlue() && green == Color.PINK.getGreen())
197 return "pink";
198
199 if (red == 192 && blue == 128 && green == 64)
200 return "brown";
201 else if (red == 128 && blue == 128 && green == 0)
202 return "olive";
203 else if (red == 128 && blue == 0 && green == 128)
204 return "violet";
205 else if (red == 192 && blue == 0 && green == 64)
206 return "purple";
207 else
208 return null;
209 }
210
217 protected static Color getDefaultColor(int index) {
218 if (index % 6 == 0)
219 return Color.RED;
220 else if (index % 6 == 1)
221 return Color.BLUE;
222 else if (index % 6 == 2)
223 return Color.GREEN;
224 else if (index % 6 == 3)
225 return Color.YELLOW;
226 else if (index % 6 == 4)
227 return Color.MAGENTA;
228 else
229 return Color.CYAN;
230 }
231
232 // Returns maximum value in table t
233 protected static double max(double[] t) {
234 double aux = t[0];
235 for (int i = 1; i < t.length; i++)
236 if (t[i] > aux)
237 aux = t[i];
238 return aux;
239 }
240
241 // Returns minimum value in table t
242 protected static double min(double[] t) {
243 double aux = t[0];
244 for (int i = 1; i < t.length; i++)
245 if (t[i] < aux)
246 aux = t[i];
247 return aux;
248 }
249}
250
CategoryDataset getSeriesCollection()
Returns the CategoryDataset object associated with the current object.
static Color getDefaultColor(int index)
Gives the default color associated with a series.
abstract String toString()
Returns in a String all data contained in the current object.
CategoryItemRenderer getRenderer()
Returns the CategoryItemRenderer object associated with the current object.
String getCategory(int series)
Returns the category-value in the specified series.
double getValue(int series, int index)
Returns the -value at the specified index in the specified series.
void setColor(int series, Color color)
Sets a new plotting color to the series .
void setRenderer(CategoryItemRenderer renderer)
Sets the CategoryItemRenderer object associated with the current variable.
abstract String toLatex(double YScale, double YShift, double ymin, double ymax)
Formats and returns a string containing a LaTeX-compatible source code which represents this data ser...
abstract double[] getRangeBounds()
Returns range ( -coordinates) min and max values.
static String detectXColorClassic(Color color)
Converts a java Color object into a friendly and readable LaTeX/xcolor string.
Color getColor(int series)
Gets the current plotting color of the selected series.