Commit 3ce7fa59 authored by Nico Mack's avatar Nico Mack

Cleanup of ColourScaleRenderer API

parent 907f8f6a
......@@ -13,6 +13,8 @@
*/
package lu.list.itis.dkd.tui.utility.scales;
import lu.list.itis.dkd.tui.widget.corona.ShapeFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
......@@ -24,12 +26,8 @@ import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
......@@ -47,9 +45,8 @@ public class ColourScaleRenderer {
private Shape mappingShape;
private Color fontColour;
private Font mappingFont;
private int horizontalGap = 5;
private int verticalGap = 5;
private double lineHeight;
private int horizontalGap;
private int verticalGap;
// ***************************************************************************
// * Constants *
......@@ -57,16 +54,23 @@ public class ColourScaleRenderer {
private static final RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
private static final int DEFAULT_GAP = 5;
private static final Shape DEFAULT_SHAPE = ShapeFactory.buildCircle(15);
private static final Font DEFAULT_FONT = new Font("Arial", Font.PLAIN, 13);
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public ColourScaleRenderer(ColourScale<?> scale, Shape shape, Font font) {
public ColourScaleRenderer(ColourScale<?> scale) {
this.scale = scale;
this.mappingShape = shape;
this.mappingFont = font;
this.horizontalGap = DEFAULT_GAP;
this.verticalGap = DEFAULT_GAP;
this.mappingShape = DEFAULT_SHAPE;
this.mappingFont = DEFAULT_FONT;
this.fontColour = Color.BLACK;
}
......@@ -99,7 +103,6 @@ public class ColourScaleRenderer {
widest = Math.max(width, widest);
}
lineHeight = highest;
int height = (highest + verticalGap) * mappings.size();
int width = (int) shapeBounds.getWidth() + horizontalGap + widest;
......@@ -108,7 +111,7 @@ public class ColourScaleRenderer {
// ---------------------------------------------------------------------------
public <T extends Comparable<T>> BufferedImage renderScale(ColourScale<T> scale) {
private <T extends Comparable<T>> BufferedImage renderScale(ColourScale<T> scale) {
BufferedImage rendered;
Dimension required = this.determineRequiredDimensions(scale);
......@@ -126,7 +129,6 @@ public class ColourScaleRenderer {
offscreen.translate(-shapeBounds.getX(), (offset / 2));
offscreen.setFont(mappingFont);
for (ColourMapping<T> mapping : mappings) {
offscreen.setPaint(mapping.getColour());
offscreen.fill(mappingShape);
......@@ -135,29 +137,56 @@ public class ColourScaleRenderer {
offscreen.translate(0, offset);
}
return rendered;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
File outputfile = new File("/Users/mack/Desktop/dump.png");
try {
ImageIO.write(rendered, "png", outputfile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void setVerticalGap(int gap) {
this.verticalGap = gap;
}
// ---------------------------------------------------------------------------
public void setHorizontalGap(int gap) {
this.horizontalGap = gap;
}
return rendered;
// ---------------------------------------------------------------------------
public void setFont(Font font) {
this.mappingFont = font;
}
// ---------------------------------------------------------------------------
public void setFontColour(Color colour) {
this.fontColour = colour;
}
// ---------------------------------------------------------------------------
public void setShape(Shape shape) {
this.mappingShape = shape;
}
// ---------------------------------------------------------------------------
public BufferedImage render() {
return this.renderScale(this.scale);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment