Mouse Still Down Handler (Smart GWT) : Mouse « GWT « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » GWT » MouseScreenshots 
Mouse Still Down Handler (Smart GWT)
Mouse Still Down Handler (Smart GWT)
  
/*
 * SmartGWT (GWT for SmartClient)
 * Copyright 2008 and beyond, Isomorphic Software, Inc.
 *
 * SmartGWT is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation.  SmartGWT is also
 * available under typical commercial license terms - see
 * http://smartclient.com/license
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */

package com.smartgwt.sample.showcase.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.util.EventHandler;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.MouseMoveEvent;
import com.smartgwt.client.widgets.events.MouseMoveHandler;
import com.smartgwt.client.widgets.events.MouseOutEvent;
import com.smartgwt.client.widgets.events.MouseOutHandler;
import com.smartgwt.client.widgets.events.MouseStillDownEvent;
import com.smartgwt.client.widgets.events.MouseStillDownHandler;
import com.smartgwt.client.widgets.events.MouseUpEvent;
import com.smartgwt.client.widgets.events.MouseUpHandler;
import com.smartgwt.client.widgets.events.MouseWheelEvent;
import com.smartgwt.client.widgets.events.MouseWheelHandler;

public class Showcase implements EntryPoint{

    public void onModuleLoad() {
       RootPanel.get().add(getViewPanel());
    }


    public Canvas getViewPanel() {

      Canvas canvas = new Canvas();

      final TrackerLabel eventTrackerLabel = new TrackerLabel();
      eventTrackerLabel.setContents("<nobr>Last event: (mouse over the canvas below...)</nobr>");
      eventTrackerLabel.setHeight(20);

      final MouserLabel label = new MouserLabel();
      label.setContents("<b>Mouse Me</b>");
      label.setAlign(Alignment.CENTER);
      label.setOverflow(Overflow.HIDDEN);
      label.setShowEdges(true);
      label.setBackgroundColor("lightblue");
      label.setWidth(200);
      label.setHeight(200);
      label.setTop(40);
      label.addMouseWheelHandler(new MouseWheelHandler() {
          public void onMouseWheel(MouseWheelEvent event) {
              int wheelDelta = EventHandler.getWheelDelta();

              int newSize = label.getWidth() + wheelDelta * label.getZoomMultiplier();
              if (newSize < label.getMinSize()) {
                  newSize = label.getMinSize();
              else if (newSize > label.getMaxSize()) {
                  newSize = label.getMaxSize();
              }
              label.setWidth(newSize);
              label.setHeight(newSize);
              eventTrackerLabel.setLastEvent("mouseWheel", label);
          }
      });

      label.addMouseStillDownHandler(new MouseStillDownHandler() {
          public void onMouseStillDown(MouseStillDownEvent event) {
              Integer opacity = label.getOpacity();
              if (opacity == nullopacity = 100;
              label.setOpacity(Math.max(0, opacity - 5));
              eventTrackerLabel.setLastEvent("mouseStillDown", label);
          }
      });

      label.addMouseUpHandler(new MouseUpHandler() {
          public void onMouseUp(MouseUpEvent event) {
              label.setOpacity(100);
              eventTrackerLabel.setLastEvent("mouseUp", label);
          }
      });

      label.addMouseMoveHandler(new MouseMoveHandler() {
          public void onMouseMove(MouseMoveEvent event) {
              //scale to 1
              float xScale = (label.getOffsetX() 1f/ label.getWidth();
              float yScale = (label.getOffsetY() 1f/ label.getHeight();

              // increasing red intensity on the x axis, green on the y axis.  Blue stays at zero.
              label.setBackgroundColor("rgb(0," + Math.round(255 * xScale"," + Math.round(255 * yScale")");
              eventTrackerLabel.setLastEvent("mouseMove", label);
          }
      });

      label.addMouseOutHandler(new MouseOutHandler() {
          public void onMouseOut(MouseOutEvent event) {
              //restore settings
              label.setBackgroundColor("lightblue");
              label.setOpacity(100);
              eventTrackerLabel.setLastEvent("mouseOut", label);
          }
      });

      canvas.addChild(eventTrackerLabel);
      canvas.addChild(label);
      return canvas;
  }
  class TrackerLabel extends Label {

      public void setLastEvent(String eventName, MouserLabel label) {
          int localX = label.getOffsetX();
          int localY = label.getOffsetY();
          setContents("<nobr>Last event: <b>" + eventName + "</b> (" + localX + ", " + localY + ")</nobr>");
      }
  }


  class MouserLabel extends Label {
      private int minSize = 40;
      private int maxSize = 400;
      private int zoomMultiplier = 15;

      public int getMinSize() {
          return minSize;
      }

      public void setMinSize(int minSize) {
          this.minSize = minSize;
      }

      public int getMaxSize() {
          return maxSize;
      }

      public void setMaxSize(int maxSize) {
          this.maxSize = maxSize;
      }

      public int getZoomMultiplier() {
          return zoomMultiplier;
      }

      public void setZoomMultiplier(int zoomMultiplier) {
          this.zoomMultiplier = zoomMultiplier;
      }
  }
}

   
    
  
SmartGWT.zip( 9,880 k)
Related examples in the same category
1.Using Mouse Wheel Handler (Smart GWT)Using Mouse Wheel Handler (Smart GWT)
2.Mouse up handler (Smart GWT)Mouse up handler (Smart GWT)
3.Mouse move handler (Smart GWT)Mouse move handler (Smart GWT)
4.Mouse out handler (Smart GWT)Mouse out handler (Smart GWT)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.