1 32 33 package it.businesslogic.ireport.chart; 34 import java.util.*; 35 import java.awt.*; 36 40 public abstract class ChartFactory { 41 42 static public java.awt.Image drawChart(String [] parameters, it.businesslogic.ireport.IReportScriptlet scriptlet) 43 { 44 45 return null; 46 } 47 48 49 protected static int getParameterAsInteger(String name, java.util.Properties props, int defaultValue) 50 { 51 String val = props.getProperty(name, ""+defaultValue); 52 try { 53 return Integer.parseInt(val); 54 } catch (Exception ex) { } 55 return defaultValue; 56 } 57 58 protected static double getParameterAsDouble(String name, java.util.Properties props, double defaultValue) 59 { 60 String val = props.getProperty(name, ""+defaultValue); 61 try { 62 return Double.parseDouble(val); 63 } catch (Exception ex) { } 64 return defaultValue; 65 } 66 67 68 protected static boolean getParameterAsBoolean(String name, java.util.Properties props, boolean defaultValue) 69 { 70 String val = props.getProperty(name, ""+defaultValue); 71 try { 72 return val.toUpperCase().equals("TRUE"); } catch (Exception ex) { } 74 return defaultValue; 75 } 76 77 protected static java.awt.Color getParameterAsColor(String name, java.util.Properties props, java.awt.Color defaultValue) 78 { 79 String val = props.getProperty(name,""); 80 try { 81 82 java.awt.Color c = parseColorString(val); 83 if (c != null) return c; 84 85 } catch (Exception ex) { } 86 return defaultValue; 87 } 88 89 protected static java.util.Vector getSeries(String name, java.util.Properties props, it.businesslogic.ireport.IReportScriptlet scriptlet) 90 { 91 92 if (scriptlet == null) 93 { 94 Vector v = new Vector(); 95 v.add(new Double (1)); 96 v.add(new Double (5)); 97 v.add(new Double (3)); 98 v.add(new Double (8)); 99 v.add(new Double (3)); 100 v.add(new Double (5)); 101 v.add(new Double (1)); 102 v.add(new Double (7)); 103 v.add(new Double (6)); 104 v.add(new Double (9)); 105 106 return v; 107 } 108 if (!props.containsKey( name ) ) return new Vector(); 109 String varName = (String )props.getProperty(name); 110 111 112 return scriptlet.getSerie( varName ); 113 } 114 115 public static java.awt.Color parseColorString(String 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 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 ex) { return null; } 136 137 Color c = new Color(r,g,b); 138 return c; 139 140 } 141 } 142 | Popular Tags |