Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/MousePositionPanel.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java@651b93c10dc5 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | |
2 | |
3 import java.util.ArrayList; | |
4 | |
5 import com.smartgwt.client.widgets.Canvas; | |
6 import com.smartgwt.client.widgets.Label; | |
7 import com.smartgwt.client.widgets.layout.HLayout; | |
8 import com.smartgwt.client.widgets.events.MouseMoveEvent; | |
9 import com.smartgwt.client.widgets.events.MouseMoveHandler; | |
10 | |
11 import de.intevation.flys.client.shared.Transform2D; | |
12 | |
13 | |
14 /** | |
15 * Panel showing the mouse position in data space. | |
16 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
17 */ | |
18 public class MousePositionPanel extends HLayout implements MouseMoveHandler { | |
19 | |
20 /** Is associated to a ChartTab. */ | |
21 protected ChartOutputTab chartTab; | |
22 | |
23 protected HLayout xLayout; | |
24 protected ArrayList<HLayout> yLayouts; | |
25 | |
26 | |
27 public MousePositionPanel(ChartOutputTab chartTab) { | |
28 super(); | |
29 | |
30 this.chartTab = chartTab; | |
31 | |
32 chartTab.getChartPanel().addMouseMoveHandler(this); | |
33 | |
34 initLayout(); | |
35 } | |
36 | |
37 | |
38 /** | |
39 * Initializes the layout of this component. <b>Note:</b> This layout has a | |
40 * fixed width of 195px plus a margin of 5px. | |
41 */ | |
42 protected void initLayout() { | |
43 setMembersMargin(5); | |
44 | |
45 xLayout = null; | |
46 yLayouts = new ArrayList<HLayout>(); | |
47 } | |
48 | |
49 | |
50 /** | |
51 * Listens to mouse move events to refresh the xy position. | |
52 * | |
53 * @param event The move event. | |
54 */ | |
55 public void onMouseMove(MouseMoveEvent event) { | |
56 updateMousePosition(event.getX(), event.getY()); | |
57 } | |
58 | |
59 | |
60 /** | |
61 * This method takes pixel coordinates, transforms those values into chart | |
62 * coordinates using the Transform2D class and updates the mouse position. | |
63 * | |
64 * @param x The x part of the pixel. | |
65 * @param y The y part of the pixel. | |
66 */ | |
67 public void updateMousePosition(double x, double y) { | |
68 int transformerCount = chartTab.getTransformerCount(); | |
69 | |
70 Canvas chart = chartTab.getChartPanel(); | |
71 int xOffset = chart.getPageLeft(); | |
72 int yOffset = chart.getPageTop(); | |
73 | |
74 x = x - xOffset; | |
75 y = y - yOffset; | |
76 | |
77 // Create Layout for x coordinates. | |
78 if (xLayout == null){ | |
79 Label xDesc = new Label("Position: X = "); | |
80 Label xLabel = new Label(); | |
81 xLayout = new HLayout(); | |
82 xLayout.setWidth(125); | |
83 xLayout.addMember(xDesc); | |
84 xLayout.addMember(xLabel); | |
85 xDesc.setWidth(70); | |
86 xLabel.setWidth(55); | |
87 addMember(xLayout); | |
88 } | |
89 | |
90 for (int i = 0; i < transformerCount; i++) { | |
91 HLayout yLayout = null; | |
92 // If no layout exists for this y axis, create one. | |
93 // else use the existing one. | |
94 if (yLayouts.size() <= i) { | |
95 Label yDesc = new Label("Y" + (i+1) + " = "); | |
96 Label yLabel = new Label(); | |
97 yLayout = new HLayout(); | |
98 yLayout.setWidth(80); | |
99 yLayout.addMember(yDesc); | |
100 yLayout.addMember(yLabel); | |
101 yDesc.setWidth(30); | |
102 yLabel.setWidth(50); | |
103 addMember(yLayout); | |
104 yLayouts.add(i, yLayout); | |
105 } | |
106 else { | |
107 yLayout = yLayouts.get(i); | |
108 } | |
109 | |
110 Transform2D transformer = chartTab.getTransformer(i); | |
111 | |
112 if (transformer == null) { | |
113 return; | |
114 } | |
115 | |
116 // Get the label for the coordinates. | |
117 Canvas xLabel = xLayout.getMember(1); | |
118 Canvas yLabel = yLayout.getMember(1); | |
119 | |
120 double[] xy = transformer.transform(x, y); | |
121 String[] xyStr = transformer.format(new Number[] { | |
122 new Double(xy[0]), new Double(xy[1]) }); | |
123 // Set the coordinates. | |
124 xLabel.setContents(xyStr[0]); | |
125 yLabel.setContents(xyStr[1]); | |
126 } | |
127 | |
128 // Remove y coordinates. | |
129 if (yLayouts.size() > transformerCount) { | |
130 for (int i = yLayouts.size() - 1; i >= transformerCount; i--) { | |
131 removeMember(yLayouts.get(i)); | |
132 yLayouts.remove(i); | |
133 } | |
134 } | |
135 } | |
136 } | |
137 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |