private String getLowValue() { return format(this.low); }
/** * Creates a new {@code ColorKeyPanel} between the colors and the range * specified. * * @param lowColor the low color of the gradient. * @param highColor the high color of the gradient. * @param lowValue the low value of the range. * @param highValue the high value of the range. */ public ColorKeyLegend(Color lowColor, Color highColor, double lowValue, double highValue ) { this.lowColor = lowColor; this.highColor = highColor; this.low = lowValue; this.high = highValue; this.init(); }
/** * Sets the low color of the gradient. * * @param color the low color of the gradient. */ public void setLowColor(Color color) { this.lowColor = color; this.repaint(); }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setFont(getFont()); String min = getLowValue(); double height = s.getHeight(min); double width = s.getWidth(min); (float) (LEGEND_HEIGHT + 12 + 2 + height)); String middle = getMiddle(); height = s.getHeight(middle); width = s.getWidth(middle); (float) (LEGEND_HEIGHT + 12 + 2 + height)); String max = getHighValue(); height = s.getHeight(max); width = s.getWidth(max);
public static void main(String[] args) { ColorKeyLegend colorKeyPanel = new ColorKeyLegend(GREEN, RED, 0d, 100d); showComponent(colorKeyPanel, "ColorKeyLegend demo"); } }
/** * Sets the decimal format. * * @param decimalFormat the decimal format */ public void setDecimalFormat(DecimalFormat decimalFormat) { this.decimalFormat = decimalFormat; this.colorKey.setDecimalFormat(decimalFormat); }
private String format(double d) { return getDecimalFormatter().format(d); }
private Component getColorKey() { colorKey = new ColorKeyLegend( this.lowColor, this.highColor, min(this.data), max(this.data) ); return new CenteredJPanel(colorKey); }
/** * Sets the low high of the gradient. * * @param color the high color of the gradient. */ public void setHighColor(Color color) { this.highColor = color; this.repaint(); }
private String getMiddle(){ return format((low + high) / 2); }
/** * Sets the low value of the gradient. * * @param low the low value of the gradient. */ public void setLowValue(double low) { this.low = low; this.repaint(); }
private String getHighValue() { return format(this.high); }
/** * Sets the high value of the gradient. * * @param high the low value of the gradient. */ public void setHighValue(double high) { this.high = high; this.repaint(); }
/** * Sets the decimal format to format gradient values. * * @param decimalFormat the decimal format to format gradient values. */ public void setDecimalFormat(DecimalFormat decimalFormat) { this.decimalFormat = decimalFormat; this.repaint(); }
@Override public void setFont(Font f) { super.setFont(f); this.repaint(); } }