private static final Color GRAY = new Color(100, 100, 100);
protected Boolean enabled = true;
protected double gridSize = 1.0;
private static final Color GRAY = new Color(100, 100, 100);
protected Boolean enabled = true;
protected double gridSize = 1.0;
//g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setStroke(new BasicStroke(1));
//g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setStroke(new BasicStroke(1));
- Rectangle2D vertical = new Rectangle2D.Double(bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMinY()+20);
+ int rulerPixelSize = (int) DPIUtil.upscale(rulerSize);
+ int u7 = DPIUtil.upscale(7);
+ int u4 = DPIUtil.upscale(4);
+ int u2 = DPIUtil.upscale(2);
+
+ Rectangle2D vertical = new Rectangle2D.Double(bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMinY()+rulerPixelSize);
- Rectangle2D horizontal = new Rectangle2D.Double(bounds.getMinX(), bounds.getMinY()+20, bounds.getMinX()+20, bounds.getMaxY());
+ Rectangle2D horizontal = new Rectangle2D.Double(bounds.getMinX(), bounds.getMinY()+rulerPixelSize, bounds.getMinX()+rulerPixelSize, bounds.getMaxY());
- if(x > 20) {
- String str = formatValue((x-offsetX)/scaleX);
- FontMetrics fm = g.getFontMetrics();
+ if(x > rulerPixelSize) {
+ double val = (x-offsetX)/scaleX / getTransform().getScaleX();
+ double modifiedValue = modifyHorizontalValue(val);
+ String str = formatValue(modifiedValue, getMaxDigits());
Rectangle2D r = fm.getStringBounds(str, g);
if((x-r.getWidth()/2) > previousText) {
g.setColor(Color.BLACK);
Rectangle2D r = fm.getStringBounds(str, g);
if((x-r.getWidth()/2) > previousText) {
g.setColor(Color.BLACK);
- g.drawLine((int)x, (int)bounds.getMinY()+12, (int)x, (int)bounds.getMinY()+19);
+ g.drawLine((int)x, (int)bounds.getMinY()+rulerPixelSize-1-u7, (int)x, (int)bounds.getMinY()+rulerPixelSize-1);
- if(x2 > 20) {
- g.drawLine((int)x2, (int)bounds.getMinY()+15, (int)x2, (int)bounds.getMinY()+19);
+ if(x2 > rulerPixelSize) {
+ g.drawLine((int)x2, (int)bounds.getMinY()+rulerPixelSize-1-u4, (int)x2, (int)bounds.getMinY()+rulerPixelSize-1);
- if(x2 > 20) {
- g.drawLine((int)x2, (int)bounds.getMinY()+17, (int)x2, (int)bounds.getMinY()+19);
+ if(x2 > rulerPixelSize) {
+ g.drawLine((int)x2, (int)bounds.getMinY()+rulerPixelSize-1-u2, (int)x2, (int)bounds.getMinY()+rulerPixelSize-1);
- if(y > 20) {
- double val = (y-offsetY)/scaleY;
- if (MAP_Y_SCALING)
- val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));
- String str = formatValue(val);
- FontMetrics fm = g.getFontMetrics();
+ if(y > rulerPixelSize) {
+ double val = (y-offsetY)/scaleY / getTransform().getScaleY();
+ double modifiedValue = modifyVerticalValue(val);
+ String str = formatValue(modifiedValue, getMaxDigits());
Rectangle2D r = fm.getStringBounds(str, g);
if(y-1+r.getHeight()/2 > previousText) {
g.setColor(Color.BLACK);
Rectangle2D r = fm.getStringBounds(str, g);
if(y-1+r.getHeight()/2 > previousText) {
g.setColor(Color.BLACK);
- g.drawLine((int)bounds.getMinX()+12, (int)y, (int)bounds.getMinX()+19, (int)y);
+ g.drawLine((int)bounds.getMinX()+rulerPixelSize-1-u7, (int)y, (int)bounds.getMinX()+rulerPixelSize-1, (int)y);
- if(y2 > 20) {
- g.drawLine((int)bounds.getMinX()+15, (int)y2, (int)bounds.getMinX()+19, (int)y2);
+ if(y2 > rulerPixelSize) {
+ g.drawLine((int)bounds.getMinX()+rulerPixelSize-1-u4, (int)y2, (int)bounds.getMinX()+rulerPixelSize-1, (int)y2);
- if(y2 > 20) {
- g.drawLine((int)bounds.getMinX()+17, (int)y2, (int)bounds.getMinX()+19, (int)y2);
+ if(y2 > rulerPixelSize) {
+ g.drawLine((int)bounds.getMinX()+rulerPixelSize-1-u2, (int)y2, (int)bounds.getMinX()+rulerPixelSize-1, (int)y2);
+ /**
+ * A method for subclasses to alter the actual X-value of the ruler
+ *
+ * @param value
+ * @return possibly modified X-value
+ */
+ protected double modifyHorizontalValue(double value) {
+ return value;
+ }
+
+ /**
+ * A method for subclasses to alter the actual Y-value of the ruler
+ *
+ * @param value
+ * @return possibly modified Y-value
+ */
+ protected double modifyVerticalValue(double value) {
+ return value;
+ }
+
private static final transient int MAX_DIGITS = 5;
private static final transient double EPSILON = 0.01;
private static final transient double TRIM_THRESHOLD_MAX_VALUE = Math.pow(10, 4);
private static final transient String[] SI_UNIT_LARGE_PREFIXES = {
"k", "M", "G", "T", "P", "E", "Z", "Y"
};
private static final transient int MAX_DIGITS = 5;
private static final transient double EPSILON = 0.01;
private static final transient double TRIM_THRESHOLD_MAX_VALUE = Math.pow(10, 4);
private static final transient String[] SI_UNIT_LARGE_PREFIXES = {
"k", "M", "G", "T", "P", "E", "Z", "Y"
};
int magnitude = (int) Math.round(Math.log10(value));
//System.out.println("magnitude: " + magnitude + ", " + value);
int magnitude = (int) Math.round(Math.log10(value));
//System.out.println("magnitude: " + magnitude + ", " + value);