Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java @ 593:c0477626ae6a
#156 Do not display report modes as tabs in the project view.
flys-client/trunk@2189 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 21 Jun 2011 17:29:18 +0000 |
parents | 78907f0fb939 |
children | ef745bc6bed9 |
line wrap: on
line source
package de.intevation.flys.client.client.ui.chart; import com.google.gwt.i18n.client.NumberFormat; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.events.MouseMoveEvent; import com.smartgwt.client.widgets.events.MouseMoveHandler; import de.intevation.flys.client.shared.Transform2D; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class MousePositionPanel extends HLayout implements MouseMoveHandler { protected ChartOutputTab chartTab; protected NumberFormat nf; protected Label x; protected Label y; public MousePositionPanel(ChartOutputTab chartTab) { super(); this.chartTab = chartTab; x = new Label(); y = new Label(); nf = NumberFormat.getDecimalFormat(); chartTab.getChartPanel().addMouseMoveHandler(this); initLayout(); } /** * Initializes the layout of this component. <b>Note:</b> This layout has a * fixed width of 195px plus a margin of 5px. */ protected void initLayout() { setMembersMargin(5); Label xDesc = new Label("Position: X = "); Label yDesc = new Label("Y = "); HLayout xLayout = new HLayout(); xLayout.setWidth(125); xLayout.addMember(xDesc); xLayout.addMember(x); HLayout yLayout = new HLayout(); yLayout.setWidth(70); yLayout.addMember(yDesc); yLayout.addMember(y); xDesc.setWidth(70); x.setWidth(55); yDesc.setWidth(20); y.setWidth(50); addMember(xLayout); addMember(yLayout); } /** * /Updates the X value displayed in the <i>x</i> label. * * @param x the new x value. */ public void setX(double x) { this.x.setContents(nf.format(x)); } /** * /Updates the Y value displayed in the <i>y</i> label. * * @param y the new y value. */ public void setY(double y) { this.y.setContents(nf.format(y)); } /** * Listens to mouse move events to refresh the xy position. * * @param event The move event. */ public void onMouseMove(MouseMoveEvent event) { updateMousePosition(event.getX(), event.getY()); } /** * This method takes pixel coordinates, transforms those values into chart * coordinates using the Transform2D class and updates the mouse position. * * @param x The x part of the pixel. * @param y The y part of the pixel. */ public void updateMousePosition(double x, double y) { Transform2D transformer = chartTab.getTransformer(); if (transformer == null) { return; } Canvas chart = chartTab.getChartPanel(); int xOffset = chart.getPageLeft(); int yOffset = chart.getPageTop(); x = x - xOffset; y = y - yOffset; double[] xy = transformer.transform(x,y); setX(xy[0]); setY(xy[1]); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :