001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.extension.openide.awt;
043:
044: import java.awt.event.MouseEvent;
045:
046: /** Originally copied from openide/src/org/openide/awt/MouseUtils,
047: * to hack isDoubleClick method, there are some rave specific probs. */
048: public class MouseUtils_RAVE extends Object {
049: private static int DOUBLE_CLICK_DELTA = 300;
050:
051: /** variable for double click */
052: private static int tempx = 0;
053: private static int tempy = 0;
054: private static long temph = 0;
055: private static int tempm = 0;
056: // <RAVE>
057: private static MouseEvent tempe;
058:
059: // </RAVE>
060:
061: // <RAVE>
062: /** Provide access to the double click interval; this is used
063: * by isDoubleClick for example
064: */
065: public static int getDoubleClickInterval() {
066: return DOUBLE_CLICK_DELTA;
067: }
068:
069: // </RAVE>
070:
071: /** Returns true if parametr is a 'doubleclick event'
072: * @param e MouseEvent
073: * @return true if the event is a doubleclick
074: */
075: public static boolean isDoubleClick(MouseEvent e) {
076: // even number of clicks is considered like doubleclick
077: // it works as well as 'normal testing against 2'
078: // but on solaris finaly works and on Win32 works better
079: //System.out.println ("Click COunt: "+e.getClickCount ()); // NOI18N
080: // <RAVE>
081: // If you don't do this, then if anyone calls isDoubleClick from
082: // say a mouseReleased method, then the immediately following mouseClicked
083: // method from a single mouse click will give isDoubleClick=true
084: if (e.getID() != MouseEvent.MOUSE_CLICKED) {
085: return false;
086: }
087:
088: if (e.getClickCount() == 0) {
089: return false;
090: }
091: // </RAVE>
092: return (e.getClickCount() % 2 == 0) || isDoubleClickImpl(e);
093: }
094:
095: /** Tests the positions.
096: */
097: private static boolean isDoubleClickImpl(MouseEvent e) {
098: int x = e.getX();
099: int y = e.getY();
100: long h = e.getWhen();
101: int m = e.getModifiers();
102: //System.out.println ("When:: "+h); // NOI18N
103: // same position at short time
104: if (tempx == x && tempy == y && h - temph < DOUBLE_CLICK_DELTA
105: &&
106: // <RAVE>
107: // Without this, calling isDoubleClick() twice on the same
108: // mouse event will return true the second time!
109: // I considered two fixes:
110: // (1) checking that h != temph - e.g. if the buttons were
111: // clicked -simultaneously- then it's probably just a second
112: // call on the same mouse event. Do we have any users fast
113: // enough to click the button so rapidly?
114: // (2) checking that this is a different mouse event than
115: // the last call. This will not work in the presence of
116: // mutable events which are used in a few places in Swing,
117: // but apparently not for mouse click events
118:
119: //h != temph &&
120: e != tempe &&
121: // </RAVE>
122:
123: m == tempm) {
124: // OK forget all
125: tempx = 0;
126: tempy = 0;
127: temph = 0;
128: tempm = 0;
129: // <RAVE>
130: tempe = null;
131: // </RAVE>
132: return true;
133: } else {
134: // remember
135: tempx = x;
136: tempy = y;
137: temph = h;
138: tempm = m;
139: // <RAVE>
140: tempe = e;
141: // </RAVE>
142: return false;
143: }
144: }
145:
146: }
|