All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.laures.cewolf.cpp.DialEnhancer Maven / Gradle / Ivy

package de.laures.cewolf.cpp;

import java.awt.Color;
import java.awt.Font;
import java.io.Serializable;
import java.util.Map;

import de.laures.cewolf.ChartPostProcessor;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.dial.*;

/**
* A postprocessor for changing details of a Dial plot.
* 
pointerType "pin" or "pointer"; default pointer *
dialText text to display on the dial; optional *
lowerBound optional; default 0; starting value for the scale *
upperBound optional; default 100; end value for the scale *
majorTickIncrement optional; default 10; value increment between major tick marks *
minorTickCount optional; default 4; minor tick marks to put between major tick marks *

* Usage:

* <chart:chartpostprocessor id="dialEnhancer">
*   <chart:param name="pointerType" value="pin"/>
*   <chart:param name="dialText" value="(km/h)"/>
*   <chart:param name="lowerBound" value="0.1"/>
*   <chart:param name="upperBound" value="0.1"/>
*   <chart:param name="majorTickIncrement" value="20"/>
*   <chart:param name="minorTickCount" value="9"/>
* </chart:chartpostprocessor> */ // TODO: capFill, capRadius and capOutline don't work yet /* *
capFill optional; default #000000 (i.e., black) *
capOutline optional; default #FFFFFF (i.e., white) *
capRadius optional; 0.0 < radius < 1.0; default 0.05 *   <chart:param name="capFill" value="#FF8800"/>
*   <chart:param name="capOutline" value="#0088FF"/>
*   <chart:param name="capRadius" value="0.1"/>
*/ public class DialEnhancer implements ChartPostProcessor, Serializable { static final long serialVersionUID = 6708371054518325470L; public void processChart (JFreeChart chart, Map params) { String pointerType = "pointer"; String dialText = null; Color capFillPaint = new Color(0, 0, 0); Color capOutlinePaint = new Color(255, 255, 255); double capRadius = 0.05; boolean setCap = false; double lowerBound = 0.0; double upperBound = 100.0; double majorTickIncrement = 10.0; int minorTickCount = 4; boolean setScale = false; String str = params.get("pointerType"); if (str != null && str.trim().length() > 0) pointerType = str.trim(); str = params.get("dialText"); if (str != null && str.trim().length() > 0) dialText = str.trim(); str = params.get("capRadius"); if (str != null) { try { capRadius = Double.parseDouble(str); setCap = true; } catch (NumberFormatException nfex) { } } str = params.get("capFill"); if (str != null && str.trim().length() > 0) { try { capFillPaint = Color.decode(str); setCap = true; } catch (NumberFormatException nfex) { } } str = params.get("capOutline"); if (str != null && str.trim().length() > 0) { try { capOutlinePaint = Color.decode(str); setCap = true; } catch (NumberFormatException nfex) { } } str = params.get("lowerBound"); if (str != null) { try { lowerBound = Double.parseDouble(str); setScale = true; } catch (NumberFormatException nfex) { } } str = params.get("upperBound"); if (str != null) { try { upperBound = Double.parseDouble(str); setScale = true; } catch (NumberFormatException nfex) { } } str = params.get("majorTickIncrement"); if (str != null) { try { majorTickIncrement = Double.parseDouble(str); setScale = true; } catch (NumberFormatException nfex) { } } str = params.get("minorTickCount"); if (str != null) { try { minorTickCount = Integer.parseInt(str); setScale = true; } catch (NumberFormatException nfex) { } } Plot plot = chart.getPlot(); if (plot instanceof DialPlot) { DialPlot dplot = (DialPlot) plot; if ("pin".equals(pointerType)) { dplot.removePointer(0); dplot.addPointer(new DialPointer.Pin()); } else if ("pointer".equals(pointerType)) { dplot.removePointer(0); dplot.addPointer(new DialPointer.Pointer()); } if (setCap) { DialCap cap = new DialCap(); cap.setRadius(capRadius); cap.setFillPaint(capFillPaint); cap.setOutlinePaint(capOutlinePaint); dplot.setCap(cap); } if (setScale) { StandardDialScale scale = (StandardDialScale) dplot.getScale(0); scale.setLowerBound(lowerBound); scale.setUpperBound(upperBound); scale.setMajorTickIncrement(majorTickIncrement); scale.setMinorTickCount(minorTickCount); } if (dialText != null) { DialTextAnnotation annotation = new DialTextAnnotation(dialText); annotation.setFont(new Font("Dialog", Font.BOLD, 10)); annotation.setRadius(0.35); annotation.setAngle(90.0); dplot.addLayer(annotation); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy