KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > chart > ChartFactory


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * ChartFactory.java
28  *
29  * Created on 28 settembre 2004, 23.55
30  *
31  */

32
33 package it.businesslogic.ireport.chart;
34 import java.util.*;
35 import java.awt.*;
36 /**
37  *
38  * @author Administrator
39  */

40 public abstract class ChartFactory {
41     
42    static public java.awt.Image JavaDoc drawChart(String JavaDoc[] parameters, it.businesslogic.ireport.IReportScriptlet scriptlet)
43    {
44        /* redefine it!! */
45        return null;
46    }
47    
48    
49     protected static int getParameterAsInteger(String JavaDoc name, java.util.Properties JavaDoc props, int defaultValue)
50     {
51         String JavaDoc val = props.getProperty(name, ""+defaultValue);
52         try {
53             return Integer.parseInt(val);
54         } catch (Exception JavaDoc ex) { }
55         return defaultValue;
56     }
57     
58     protected static double getParameterAsDouble(String JavaDoc name, java.util.Properties JavaDoc props, double defaultValue)
59     {
60         String JavaDoc val = props.getProperty(name, ""+defaultValue);
61         try {
62             return Double.parseDouble(val);
63         } catch (Exception JavaDoc ex) { }
64         return defaultValue;
65     }
66     
67     
68     protected static boolean getParameterAsBoolean(String JavaDoc name, java.util.Properties JavaDoc props, boolean defaultValue)
69     {
70         String JavaDoc val = props.getProperty(name, ""+defaultValue);
71         try {
72             return val.toUpperCase().equals("TRUE"); // from java 1.5.0 only... = Boolean.parseBoolean(val);
73
} catch (Exception JavaDoc ex) { }
74         return defaultValue;
75     }
76     
77     protected static java.awt.Color JavaDoc getParameterAsColor(String JavaDoc name, java.util.Properties JavaDoc props, java.awt.Color JavaDoc defaultValue)
78     {
79         String JavaDoc val = props.getProperty(name,"");
80         try {
81             
82             java.awt.Color JavaDoc c = parseColorString(val);
83             if (c != null) return c;
84             
85         } catch (Exception JavaDoc ex) { }
86         return defaultValue;
87     }
88     
89     protected static java.util.Vector JavaDoc getSeries(String JavaDoc name, java.util.Properties JavaDoc props, it.businesslogic.ireport.IReportScriptlet scriptlet)
90     {
91
92         if (scriptlet == null)
93         {
94             Vector v = new Vector();
95             v.add(new Double JavaDoc(1));
96             v.add(new Double JavaDoc(5));
97             v.add(new Double JavaDoc(3));
98             v.add(new Double JavaDoc(8));
99             v.add(new Double JavaDoc(3));
100             v.add(new Double JavaDoc(5));
101             v.add(new Double JavaDoc(1));
102             v.add(new Double JavaDoc(7));
103             v.add(new Double JavaDoc(6));
104             v.add(new Double JavaDoc(9));
105             
106             return v;
107         }
108         if (!props.containsKey( name ) ) return new Vector();
109         String JavaDoc varName = (String JavaDoc)props.getProperty(name);
110         
111         
112         return scriptlet.getSerie( varName );
113     }
114     
115     public static java.awt.Color JavaDoc parseColorString(String JavaDoc newValue)
116     {
117         if (newValue == null) return null;
118         
119         newValue = newValue.trim();
120         if (!newValue.startsWith("[") || !newValue.endsWith("]"))
121         {
122             return null;
123         }
124         
125         int r = 0;
126         int g = 0;
127         int b = 0;
128         String JavaDoc rgbValues = newValue.substring(1,newValue.length()-1);
129         try {
130         
131             StringTokenizer st = new StringTokenizer(rgbValues, ",",false);
132             r = Integer.parseInt( st.nextToken() );
133             g = Integer.parseInt( st.nextToken() );
134             b = Integer.parseInt( st.nextToken() );
135         } catch (Exception JavaDoc ex) { return null; }
136         
137         Color c = new Color(r,g,b);
138         return c;
139         
140     }
141 }
142
Popular Tags