1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.gauger;
21
22 import java.awt.Graphics;
23 import java.awt.Rectangle;
24 import java.awt.geom.Point2D;
25
26
27
28
29
30
31
32
33 public class LinearVerticalTransform extends ScaleTransform
34 {
35 private static final int MAXIMUM_WIDTH = 80;
36 private static final int MINIMUM_WIDTH = 25;
37 private static final double RELATIVE_X_OFFSET = 0.1;
38 private static final double RELATIVE_Y_OFFSET = 0.05;
39 private int width = 0;
40 private int height = 0;
41 private int xOffset = 0;
42 private int yOffset = 0;
43 private int tickOffset = 0;
44
45
46
47
48 public void setParameters(int w, int h, int marginX, int marginY,
49 int tickOffset)
50 {
51 this.tickOffset = tickOffset;
52
53 width = w - (int)(2 * w * RELATIVE_X_OFFSET) - 5;
54 height = h - (int)(2 * h * RELATIVE_Y_OFFSET) - 5;
55 width = Math.min(width, MAXIMUM_WIDTH);
56 width = Math.max(width, MINIMUM_WIDTH);
57
58 xOffset = (int)(0.5 * (w - width));
59 yOffset = (int)(0.5 * (h - height));
60
61 Rectangle outline = new Rectangle(xOffset, yOffset, width, height);
62 addSegment(new RectangleSegment(outline));
63
64 setLabelPosition((int)(w / 2), (int)(0.5 * (h - height - yOffset)));
65 }
66
67
68
69
70 public void mapUVtoXY(Point2D scaleSpace, Point2D cartesianSpace)
71 {
72 double x = (xOffset + width * scaleSpace.getY());
73 double y = (yOffset + scaleWidth(0.0) * (scaleSpace.getX())
74 + tickOffset);
75 cartesianSpace.setLocation(x, y);
76 }
77
78
79
80
81 public void mapXYtoUV(Point2D cartesianSpace, Point2D scaleScape)
82 {
83 }
84
85
86
87
88 public double scaleWidth(double v)
89 {
90 return Math.abs(height - 2 * tickOffset);
91 }
92
93
94
95
96 public double scaleHeight(double u)
97 {
98 return width;
99 }
100
101
102
103
104
105 public int measureTick(Graphics g, double x, String text)
106 {
107 return g.getFontMetrics().getHeight();
108 }
109 }
110
111