changeset 534:e08777967bad

Added a first implementation of a MousePositionPanel - work is not finished yet. flys-client/trunk@2025 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 May 2011 15:38:24 +0000
parents 34103ab9fe60
children 017371801479
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java
diffstat 4 files changed, 224 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri May 27 13:48:25 2011 +0000
+++ b/flys-client/ChangeLog	Fri May 27 15:38:24 2011 +0000
@@ -1,3 +1,17 @@
+2011-05-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java:
+	  Added a public method that returns the chart panel.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java:
+	  New. A panel that displays the mouse position relative to a element.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java:
+	  Added the MousePositionPanel.
+
+	  NOTE: The MousePositionPanel does NOT show the correct position and it
+	  does NOT show the x|y coordinates in chart dimension yet!
+
 2011-05-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Fri May 27 13:48:25 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java	Fri May 27 15:38:24 2011 +0000
@@ -64,7 +64,7 @@
 
         left      = new Canvas();
         right     = new Canvas();
-        tbarPanel = new ChartToolbar(collectionView);
+        tbarPanel = new ChartToolbar(collectionView, this);
 
         left.setBorder("1px solid black");
         left.setWidth(THEMEPANEL_MIN_WIDTH);
@@ -129,6 +129,11 @@
     }
 
 
+    public Canvas getChartPanel() {
+        return right;
+    }
+
+
     protected Canvas createChartPanel() {
         return createChartPanel(DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT);
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java	Fri May 27 13:48:25 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java	Fri May 27 15:38:24 2011 +0000
@@ -2,7 +2,9 @@
 
 import com.google.gwt.core.client.GWT;
 
+import com.smartgwt.client.core.Rectangle;
 import com.smartgwt.client.widgets.Button;
+import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.events.ClickEvent;
 import com.smartgwt.client.widgets.events.ClickHandler;
@@ -29,13 +31,20 @@
 
     protected CollectionView view;
 
-    protected Button datacage;
+    protected ChartOutputTab chartTab;
 
 
-    public ChartToolbar(CollectionView view) {
+    protected Button datacage;
+
+    protected MousePositionPanel position;
+
+
+
+    public ChartToolbar(CollectionView view, ChartOutputTab chartTab) {
         super();
 
-        this.view = view;
+        this.view     = view;
+        this.chartTab = chartTab;
 
         datacage = new Button(MSG.databasket());
         datacage.addClickHandler(new ClickHandler() {
@@ -45,6 +54,13 @@
             }
         });
 
+        // TODO determine the correct viewport of the chart!
+        position = new MousePositionPanel(
+            chartTab.getChartPanel(),
+            new Rectangle(65, 35, 50, 70));
+        chartTab.getChartPanel().addMouseMoveHandler(position);
+        chartTab.getChartPanel().addResizedHandler(position);
+
         initLayout();
     }
 
@@ -61,7 +77,15 @@
         setPadding(5);
         setBorder("1px solid black");
 
+        // TODO do this dynamic
+        Label spacer = new Label();
+        spacer.setWidth("450px");
+        datacage.setWidth("95px");
+        position.setWidth("150px");
+
         addMember(datacage);
+        addMember(spacer);
+        addMember(position);
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/MousePositionPanel.java	Fri May 27 15:38:24 2011 +0000
@@ -0,0 +1,177 @@
+package de.intevation.flys.client.client.ui.chart;
+
+import com.smartgwt.client.core.Rectangle;
+import com.smartgwt.client.types.Alignment;
+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 com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MousePositionPanel
+extends      HLayout
+implements   MouseMoveHandler, ResizedHandler
+{
+    protected Canvas    window;
+    protected Rectangle viewport;
+
+    protected Label x;
+    protected Label y;
+
+
+    public MousePositionPanel(Canvas window,  Rectangle viewport) {
+        super();
+
+        this.window   = window;
+        this.viewport = viewport;
+
+        x = new Label();
+        y = new Label();
+
+        initLayout();
+    }
+
+
+    /**
+     * Initializes the layout of this component.
+     */
+    protected void initLayout() {
+        setLayoutAlign(Alignment.RIGHT);
+        setMembersMargin(5);
+
+        Label xDesc = new Label("Position: X = ");
+        Label yDesc  = new Label("Y = ");
+
+        xDesc.setWidth(60);
+        x.setWidth(25);
+        yDesc.setWidth(20);
+        y.setWidth(25);
+
+        addMember(xDesc);
+        addMember(x);
+        addMember(yDesc);
+        addMember(y);
+    }
+
+
+    /**
+     * Computes the x|y position (in chart coordinates) and updates the position
+     * in the UI.
+     *
+     * @param event The MouseMoveEvent.
+     */
+    public void onMouseMove(MouseMoveEvent event) {
+        int posX = event.getX();
+        int posY = event.getY();
+
+        if (!validX(posX) || !validY(posY)) {
+            return;
+        }
+
+        x.setContents(String.valueOf(getXPosition(posX)));
+        y.setContents(String.valueOf(getYPosition(posY)));
+    }
+
+
+    public void onResized(ResizedEvent event) {
+    }
+
+
+    /**
+     * Computes the left coordinate of the chart.
+     *
+     * @return the left coordinate of the chart.
+     */
+    protected int computeMinX() {
+        return window.getPageLeft() + viewport.getLeft();
+    }
+
+
+    /**
+     * Computes the right coordinate of the chart.
+     *
+     * @return the right coordinate of the chart.
+     */
+    protected int computeMaxX() {
+        return window.getPageLeft() + window.getWidth() - viewport.getWidth();
+    }
+
+
+    /**
+     * Computes the upper Y coordinate of the chart.
+     *
+     * @return the lower Y coordinate of the chart.
+     */
+    protected int computeMinY() {
+        return window.getPageTop() + viewport.getTop();
+    }
+
+
+    /**
+     * Computes the lower Y coordinate of the chart.
+     *
+     * @return the lower Y coordinate of the chart.
+     */
+    protected int computeMaxY() {
+        return window.getPageBottom() - viewport.getHeight();
+    }
+
+
+    /**
+     * Determines if the x value is in the valid range of the chart.
+     *
+     * @param x A pixel.
+     *
+     * @return true if the x position is valid, otherwise false.
+     */
+    protected boolean validX(int x) {
+        return (x > computeMinX() && x < computeMaxX());
+    }
+
+
+    /**
+     * Determines if the y value is in the valid range of the chart.
+     *
+     * @param y A pixel.
+     *
+     * @return true if the y position is valid, otherwise false.
+     */
+    protected boolean validY(int y) {
+        return (y > computeMinY() && y < computeMaxY());
+    }
+
+
+    /**
+     * Computes the X coordinate in a chart based on the current mouse position.
+     *
+     * @param pixel A pixel on the screen.
+     *
+     * @return the computed X value.
+     */
+    protected double getXPosition(int pixel) {
+        // TODO Compute the x relative to the chart range
+
+        return pixel - computeMinX();
+    }
+
+
+    /**
+     * Computes the Y coordinate in a chart based on the current mouse position.
+     *
+     * @param pixel A pixel on the screen.
+     *
+     * @return the computed Y value.
+     */
+    protected double getYPosition(int pixel) {
+        // TODO Compute the y relative to the chart range
+
+        return pixel - computeMinY();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org