1 45 46 package org.jfree.chart.plot; 47 48 import java.awt.CardLayout ; 49 import java.awt.Color ; 50 import java.awt.Font ; 51 import java.awt.Paint ; 52 import java.io.Serializable ; 53 import java.text.DecimalFormat ; 54 55 import javax.swing.JPanel ; 56 57 import org.jfree.chart.ChartPanel; 58 import org.jfree.chart.JFreeChart; 59 import org.jfree.chart.axis.ValueAxis; 60 import org.jfree.chart.title.TextTitle; 61 import org.jfree.chart.title.Title; 62 import org.jfree.data.general.DefaultValueDataset; 63 import org.jfree.ui.RectangleInsets; 64 65 74 public class JThermometer extends JPanel implements Serializable { 75 76 77 private static final long serialVersionUID = 1079905665515589820L; 78 79 80 private DefaultValueDataset data; 81 82 83 private JFreeChart chart; 84 85 86 private ChartPanel panel; 87 88 89 private ThermometerPlot plot = new ThermometerPlot(); 90 91 94 public JThermometer() { 95 super(new CardLayout ()); 96 this.plot.setInsets(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); 97 this.data = new DefaultValueDataset(); 98 this.plot.setDataset(this.data); 100 this.chart = new JFreeChart( 101 null, JFreeChart.DEFAULT_TITLE_FONT, this.plot, false 102 ); 103 this.panel = new ChartPanel(this.chart); 104 add(this.panel, "Panel"); 105 setBackground(getBackground()); 106 } 107 108 113 public void addSubtitle(Title subtitle) { 114 this.chart.addSubtitle(subtitle); 115 } 116 117 122 public void addSubtitle(String subtitle) { 123 this.chart.addSubtitle(new TextTitle(subtitle)); 124 } 125 126 132 public void addSubtitle(String subtitle, Font font) { 133 this.chart.addSubtitle(new TextTitle(subtitle, font)); 134 } 135 136 141 public void setValueFormat(DecimalFormat df) { 142 this.plot.setValueFormat(df); 143 } 144 145 151 public void setRange(double lower, double upper) { 152 this.plot.setRange(lower, upper); 153 } 154 155 162 public void setSubrangeInfo(int range, double displayLow, 163 double displayHigh) { 164 this.plot.setSubrangeInfo(range, displayLow, displayHigh); 165 } 166 167 176 public void setSubrangeInfo(int range, 177 double rangeLow, double rangeHigh, 178 double displayLow, double displayHigh) { 179 180 this.plot.setSubrangeInfo(range, rangeLow, rangeHigh, displayLow, 181 displayHigh); 182 183 } 184 185 190 public void setValueLocation(int loc) { 191 this.plot.setValueLocation(loc); 192 this.panel.repaint(); 193 } 194 195 200 public void setValuePaint(Paint paint) { 201 this.plot.setValuePaint(paint); 202 } 203 204 209 public Number getValue() { 210 if (this.data != null) { 211 return this.data.getValue(); 212 } 213 else { 214 return null; 215 } 216 } 217 218 223 public void setValue(double value) { 224 setValue(new Double (value)); 225 } 226 227 232 public void setValue(Number value) { 233 if (this.data != null) { 234 this.data.setValue(value); 235 } 236 } 237 238 243 public void setUnits(int i) { 244 if (this.plot != null) { 245 this.plot.setUnits(i); 246 } 247 } 248 249 254 public void setOutlinePaint(Paint p) { 255 if (this.plot != null) { 256 this.plot.setOutlinePaint(p); 257 } 258 } 259 260 265 public void setForeground(Color fg) { 266 super.setForeground(fg); 267 if (this.plot != null) { 268 this.plot.setThermometerPaint(fg); 269 } 270 } 271 272 277 public void setBackground(Color bg) { 278 super.setBackground(bg); 279 if (this.plot != null) { 280 this.plot.setBackgroundPaint(bg); 281 } 282 if (this.chart != null) { 283 this.chart.setBackgroundPaint(bg); 284 } 285 if (this.panel != null) { 286 this.panel.setBackground(bg); 287 } 288 } 289 290 295 public void setValueFont(Font f) { 296 if (this.plot != null) { 297 this.plot.setValueFont(f); 298 } 299 } 300 301 306 public Font getTickLabelFont() { 307 ValueAxis axis = this.plot.getRangeAxis(); 308 return axis.getTickLabelFont(); 309 } 310 311 316 public void setTickLabelFont(Font font) { 317 ValueAxis axis = this.plot.getRangeAxis(); 318 axis.setTickLabelFont(font); 319 } 320 321 326 public void changeTickFontSize(int delta) { 327 Font f = getTickLabelFont(); 328 String fName = f.getFontName(); 329 Font newFont = new Font (fName, f.getStyle(), (f.getSize() + delta)); 330 setTickLabelFont(newFont); 331 } 332 333 338 public void setTickFontStyle(int style) { 339 Font f = getTickLabelFont(); 340 String fName = f.getFontName(); 341 Font newFont = new Font (fName, style, f.getSize()); 342 setTickLabelFont(newFont); 343 } 344 345 351 public void setFollowDataInSubranges(boolean flag) { 352 this.plot.setFollowDataInSubranges(flag); 353 } 354 355 360 public void setShowValueLines(boolean b) { 361 this.plot.setShowValueLines(b); 362 } 363 364 369 public void setShowAxisLocation(int location) { 370 this.plot.setAxisLocation(location); 371 } 372 373 378 public int getShowAxisLocation() { 379 return this.plot.getAxisLocation(); 380 } 381 382 } 383 | Popular Tags |