1 25 package org.jrobin.graph; 26 27 import java.awt.*; 28 import java.util.HashMap ; 29 30 import org.jrobin.core.RrdException; 31 import org.jrobin.core.XmlWriter; 32 33 40 abstract class PlotDef 41 { 42 protected static final int PLOT_LINE = 0; 46 protected static final int PLOT_AREA = 1; 47 protected static final int PLOT_STACK = 2; 48 protected static final BasicStroke STROKE = new BasicStroke(); 49 50 protected boolean visible = true; 51 protected boolean stacked = false; 52 protected int plotType = PLOT_LINE; 54 protected String sourceName = ""; 55 protected Source source = null; 56 protected Color color = Color.BLACK; 58 protected double[] values = null; 59 60 PlotDef() { 64 } 65 66 71 PlotDef( String sourceName, Color color ) 72 { 73 this.sourceName = sourceName; 74 this.color = color; 75 76 if ( color == null ) 78 visible = false; 79 } 80 81 90 PlotDef( Source source, double[] values, Color color, boolean stacked, boolean visible ) 91 { 92 this.source = source; 93 this.values = values; 94 this.color = color; 95 this.stacked = stacked; 96 this.visible = visible; 97 } 98 99 108 void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException 109 { 110 if ( sourceIndex.containsKey(sourceName) ) { 111 source = sources[ ((Integer ) sourceIndex.get(sourceName)).intValue() ]; 112 } 113 else 114 throw new RrdException( "Invalid DEF or CDEF: " + sourceName ); 115 } 116 117 void prepareValues( int arraySize ) 118 { 119 values = new double[ arraySize ]; 120 } 121 122 void setValue( int tableRow, long preciseTime, long[] reducedTimestamps ) 123 { 124 values[ tableRow ] = source.get( preciseTime, reducedTimestamps ); 125 } 126 127 133 double getValue( int tblPos, long[] timestamps ) 134 { 135 return source.get( tblPos ); 136 } 137 138 142 abstract void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException; 143 144 Source getSource() { 145 return source; 146 } 147 148 String getSourceName() { 149 return sourceName; 150 } 151 152 int getType() { 153 return plotType; 154 } 155 156 Color getColor() { 157 return color; 158 } 159 160 void exportXmlTemplate(XmlWriter xml, String legend) { 161 162 } 163 } 164 | Popular Tags |