001: /* ============================================================================
002: * GNU Lesser General Public License
003: * ============================================================================
004: *
005: * Copyright (C) 2001-2007 JasperSoft Corporation http://www.jaspersoft.com
006: *
007: * This class is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This class is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this class; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * JasperSoft Corporation
022: * 303 Second Street, Suite 450 North
023: * San Francisco, CA 94107
024: * http://www.jaspersoft.com
025: *
026: *
027: *
028: * ChartFactory.java
029: *
030: * Created on 28 settembre 2004, 23.55
031: *
032: */
033:
034: package it.businesslogic.ireport.chart;
035:
036: import java.util.*;
037: import java.awt.*;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public abstract class ChartFactory {
044:
045: static public java.awt.Image drawChart(String[] parameters,
046: it.businesslogic.ireport.IReportScriptlet scriptlet) {
047: /* redefine it!! */
048: return null;
049: }
050:
051: protected static int getParameterAsInteger(String name,
052: java.util.Properties props, int defaultValue) {
053: String val = props.getProperty(name, "" + defaultValue);
054: try {
055: return Integer.parseInt(val);
056: } catch (Exception ex) {
057: }
058: return defaultValue;
059: }
060:
061: protected static double getParameterAsDouble(String name,
062: java.util.Properties props, double defaultValue) {
063: String val = props.getProperty(name, "" + defaultValue);
064: try {
065: return Double.parseDouble(val);
066: } catch (Exception ex) {
067: }
068: return defaultValue;
069: }
070:
071: protected static boolean getParameterAsBoolean(String name,
072: java.util.Properties props, boolean defaultValue) {
073: String val = props.getProperty(name, "" + defaultValue);
074: try {
075: return val.toUpperCase().equals("TRUE"); // from java 1.5.0 only... = Boolean.parseBoolean(val);
076: } catch (Exception ex) {
077: }
078: return defaultValue;
079: }
080:
081: protected static java.awt.Color getParameterAsColor(String name,
082: java.util.Properties props, java.awt.Color defaultValue) {
083: String val = props.getProperty(name, "");
084: try {
085:
086: java.awt.Color c = parseColorString(val);
087: if (c != null)
088: return c;
089:
090: } catch (Exception ex) {
091: }
092: return defaultValue;
093: }
094:
095: protected static java.util.Vector getSeries(String name,
096: java.util.Properties props,
097: it.businesslogic.ireport.IReportScriptlet scriptlet) {
098:
099: if (scriptlet == null) {
100: Vector v = new Vector();
101: v.add(new Double(1));
102: v.add(new Double(5));
103: v.add(new Double(3));
104: v.add(new Double(8));
105: v.add(new Double(3));
106: v.add(new Double(5));
107: v.add(new Double(1));
108: v.add(new Double(7));
109: v.add(new Double(6));
110: v.add(new Double(9));
111:
112: return v;
113: }
114: if (!props.containsKey(name))
115: return new Vector();
116: String varName = (String) props.getProperty(name);
117:
118: return scriptlet.getSerie(varName);
119: }
120:
121: public static java.awt.Color parseColorString(String newValue) {
122: if (newValue == null)
123: return null;
124:
125: newValue = newValue.trim();
126: if (!newValue.startsWith("[") || !newValue.endsWith("]")) {
127: return null;
128: }
129:
130: int r = 0;
131: int g = 0;
132: int b = 0;
133: String rgbValues = newValue.substring(1, newValue.length() - 1);
134: try {
135:
136: StringTokenizer st = new StringTokenizer(rgbValues, ",",
137: false);
138: r = Integer.parseInt(st.nextToken());
139: g = Integer.parseInt(st.nextToken());
140: b = Integer.parseInt(st.nextToken());
141: } catch (Exception ex) {
142: return null;
143: }
144:
145: Color c = new Color(r, g, b);
146: return c;
147:
148: }
149: }
|