KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > widget > ButtonAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget;
21
22 import org.netbeans.api.visual.action.WidgetAction;
23 import org.netbeans.api.visual.widget.Widget;
24
25 /**
26  *
27  * @author anjeleevich
28  */

29 public class ButtonAction extends WidgetAction.Adapter {
30     
31     private ButtonWidget currentButton = null;
32     private ButtonWidget pressedButton = null;
33
34     
35     private long lastId = Long.MIN_VALUE;
36     
37     
38     public ButtonAction() {
39         
40     }
41
42     
43     
44     private boolean isProcessed(WidgetAction.WidgetMouseEvent event) {
45         long currentId = event.getEventID();
46         
47         if (currentId != lastId) {
48             lastId = currentId;
49             return false;
50         }
51         
52         return true;
53     }
54     
55     
56     public WidgetAction.State mouseReleased(Widget widget,
57             WidgetAction.WidgetMouseEvent event)
58     {
59         if (isProcessed(event)) {
60             return State.REJECTED;
61         }
62         
63         if (pressedButton != null) {
64             pressedButton.mouseReleased(pressedButton == currentButton);
65             pressedButton = null;
66         }
67         
68         return State.REJECTED;
69     }
70
71     
72     public WidgetAction.State mousePressed(Widget widget,
73             WidgetAction.WidgetMouseEvent event)
74     {
75         if (isProcessed(event)) {
76             return State.REJECTED;
77         }
78         
79         if (currentButton != null) {
80             pressedButton = currentButton;
81             pressedButton.mousePressed();
82         }
83         
84         return State.REJECTED;
85     }
86
87     
88     public WidgetAction.State mouseMoved(Widget widget,
89             WidgetAction.WidgetMouseEvent event)
90     {
91         if (isProcessed(event)) {
92             return State.REJECTED;
93         }
94         
95         
96         if (widget != currentButton) {
97             if (currentButton != null) {
98                 currentButton.mouseExited();
99                 currentButton = null;
100             }
101
102             if (widget instanceof ButtonWidget) {
103                 currentButton = (ButtonWidget) widget;
104                 currentButton.mouseEntered();
105             }
106         }
107         
108         return State.REJECTED;
109     }
110     
111     
112     public WidgetAction.State mouseDragged(Widget widget, WidgetAction.WidgetMouseEvent event) {
113         return mouseMoved(widget, event);
114     }
115     
116     
117     public WidgetAction.State mouseEntered(Widget widget,
118             WidgetAction.WidgetMouseEvent event)
119     {
120         if (isProcessed(event)) {
121             return State.REJECTED;
122         }
123         
124         if (currentButton != null) {
125             currentButton.mouseExited();
126             currentButton = null;
127         }
128         
129         if (widget instanceof ButtonWidget) {
130             currentButton = (ButtonWidget) widget;
131             currentButton.mouseEntered();
132         }
133         
134         return State.REJECTED;
135     }
136
137     
138     public WidgetAction.State mouseExited(Widget widget,
139             WidgetAction.WidgetMouseEvent event)
140     {
141         if (isProcessed(event)) {
142             return State.REJECTED;
143         }
144         
145         if (currentButton != null) {
146             currentButton.mouseExited();
147             currentButton = null;
148         }
149         return State.REJECTED;
150     }
151
152
153     
154     
155     
156 }
157
Popular Tags