ed3967d1647f22e9a7ebb8fc22a95125f9cdf177
[jalviewjs.git] / site / swingjs / j2s / swingjs / plaf / JSButtonListener.js
1 Clazz.declarePackage ("swingjs.plaf");\r
2 Clazz.load (["java.awt.event.FocusListener", "$.MouseListener", "$.MouseMotionListener", "java.beans.PropertyChangeListener", "javax.swing.event.ChangeListener", "jssun.swing.UIAction"], "swingjs.plaf.JSButtonListener", ["javax.swing.AbstractButton", "$.KeyStroke", "$.SwingUtilities", "javax.swing.plaf.ComponentInputMapUIResource", "swingjs.plaf.LazyActionMap"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.lastPressedTimestamp = -1;\r
5 this.shouldDiscardRelease = false;\r
6 this.btn = null;\r
7 Clazz.instantialize (this, arguments);\r
8 }, swingjs.plaf, "JSButtonListener", null, [java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.FocusListener, javax.swing.event.ChangeListener, java.beans.PropertyChangeListener]);\r
9 c$.loadActionMap = Clazz.defineMethod (c$, "loadActionMap", \r
10 function (map) {\r
11 map.put ( new swingjs.plaf.JSButtonListener.Actions ("pressed"));\r
12 map.put ( new swingjs.plaf.JSButtonListener.Actions ("released"));\r
13 }, "swingjs.plaf.LazyActionMap");\r
14 Clazz.makeConstructor (c$, \r
15 function (b) {\r
16 this.btn = b;\r
17 }, "javax.swing.AbstractButton");\r
18 Clazz.overrideMethod (c$, "propertyChange", \r
19 function (e) {\r
20 var prop = e.getPropertyName ();\r
21 if (prop === "mnemonic") {\r
22 this.updateMnemonicBinding (e.getSource ());\r
23 } else if (prop === "contentAreaFilled") {\r
24 this.checkOpacity (e.getSource ());\r
25 } else if (prop === "text" || "font" === prop || "foreground" === prop) {\r
26 var b = e.getSource ();\r
27 (b.getUI ()).notifyPropertyChanged (prop);\r
28 }}, "java.beans.PropertyChangeEvent");\r
29 Clazz.defineMethod (c$, "checkOpacity", \r
30 function (b) {\r
31 b.setOpaque (b.isContentAreaFilled ());\r
32 }, "javax.swing.AbstractButton");\r
33 Clazz.defineMethod (c$, "installKeyboardActions", \r
34 function (c) {\r
35 var b = c;\r
36 this.updateMnemonicBinding (b);\r
37 swingjs.plaf.LazyActionMap.installLazyActionMap (c, swingjs.plaf.JSButtonListener, "Button.actionMap");\r
38 var km = this.getInputMap (0, c);\r
39 javax.swing.SwingUtilities.replaceUIInputMap (c, 0, km);\r
40 }, "javax.swing.JComponent");\r
41 Clazz.defineMethod (c$, "uninstallKeyboardActions", \r
42 function (c) {\r
43 javax.swing.SwingUtilities.replaceUIInputMap (c, 2, null);\r
44 javax.swing.SwingUtilities.replaceUIInputMap (c, 0, null);\r
45 javax.swing.SwingUtilities.replaceUIActionMap (c, null);\r
46 }, "javax.swing.JComponent");\r
47 Clazz.defineMethod (c$, "getInputMap", \r
48 function (condition, c) {\r
49 return null;\r
50 }, "~N,javax.swing.JComponent");\r
51 Clazz.defineMethod (c$, "updateMnemonicBinding", \r
52 function (b) {\r
53 var m = b.getMnemonic ();\r
54 if (m != 0) {\r
55 var map = javax.swing.SwingUtilities.getUIInputMap (b, 2);\r
56 if (map == null) {\r
57 map =  new javax.swing.plaf.ComponentInputMapUIResource (b);\r
58 javax.swing.SwingUtilities.replaceUIInputMap (b, 2, map);\r
59 }map.clear ();\r
60 map.put (javax.swing.KeyStroke.getKeyStroke (m, 8, false), "pressed");\r
61 map.put (javax.swing.KeyStroke.getKeyStroke (m, 8, true), "released");\r
62 map.put (javax.swing.KeyStroke.getKeyStroke (m, 0, true), "released");\r
63 } else {\r
64 var map = javax.swing.SwingUtilities.getUIInputMap (b, 2);\r
65 if (map != null) {\r
66 map.clear ();\r
67 }}}, "javax.swing.AbstractButton");\r
68 Clazz.overrideMethod (c$, "stateChanged", \r
69 function (e) {\r
70 var b = e.getSource ();\r
71 b.repaint ();\r
72 }, "javax.swing.event.ChangeEvent");\r
73 Clazz.overrideMethod (c$, "focusGained", \r
74 function (e) {\r
75 }, "java.awt.event.FocusEvent");\r
76 Clazz.overrideMethod (c$, "focusLost", \r
77 function (e) {\r
78 var b = e.getSource ();\r
79 var model = b.getModel ();\r
80 model.setArmed (false);\r
81 model.setPressed (false);\r
82 }, "java.awt.event.FocusEvent");\r
83 Clazz.overrideMethod (c$, "mouseMoved", \r
84 function (e) {\r
85 }, "java.awt.event.MouseEvent");\r
86 Clazz.overrideMethod (c$, "mouseDragged", \r
87 function (e) {\r
88 }, "java.awt.event.MouseEvent");\r
89 Clazz.overrideMethod (c$, "mouseClicked", \r
90 function (e) {\r
91 }, "java.awt.event.MouseEvent");\r
92 Clazz.overrideMethod (c$, "mousePressed", \r
93 function (e) {\r
94 if (javax.swing.SwingUtilities.isLeftMouseButton (e)) {\r
95 var b = e.getSource ();\r
96 if (!b.contains (e.getX (), e.getY ())) return;\r
97 (b.getUI ()).verifyButtonClick (false);\r
98 var multiClickThreshhold = b.getMultiClickThreshhold ();\r
99 var lastTime = this.lastPressedTimestamp;\r
100 var currentTime = this.lastPressedTimestamp = e.getWhen ();\r
101 if (lastTime != -1 && currentTime - lastTime < multiClickThreshhold) {\r
102 this.shouldDiscardRelease = true;\r
103 return;\r
104 }var model = b.getModel ();\r
105 if (!model.isEnabled ()) {\r
106 return;\r
107 }if (!model.isArmed ()) {\r
108 model.setArmed (true);\r
109 }model.setPressed (true);\r
110 if (!b.hasFocus () && b.isRequestFocusEnabled ()) {\r
111 b.requestFocus ();\r
112 }}}, "java.awt.event.MouseEvent");\r
113 Clazz.overrideMethod (c$, "mouseReleased", \r
114 function (e) {\r
115 if (javax.swing.SwingUtilities.isLeftMouseButton (e)) {\r
116 if (this.shouldDiscardRelease) {\r
117 this.shouldDiscardRelease = false;\r
118 return;\r
119 }var b = e.getSource ();\r
120 if (!(b.getUI ()).verifyButtonClick (true)) return;\r
121 var model = b.getModel ();\r
122 model.setPressed (false);\r
123 model.setArmed (false);\r
124 }}, "java.awt.event.MouseEvent");\r
125 Clazz.overrideMethod (c$, "mouseEntered", \r
126 function (e) {\r
127 var b = e.getSource ();\r
128 var model = b.getModel ();\r
129 if (b.isRolloverEnabled () && !javax.swing.SwingUtilities.isLeftMouseButton (e)) {\r
130 model.setRollover (true);\r
131 }if (model.isPressed ()) model.setArmed (true);\r
132 }, "java.awt.event.MouseEvent");\r
133 Clazz.overrideMethod (c$, "mouseExited", \r
134 function (e) {\r
135 var b = e.getSource ();\r
136 var model = b.getModel ();\r
137 if (b.isRolloverEnabled ()) {\r
138 model.setRollover (false);\r
139 }model.setArmed (false);\r
140 }, "java.awt.event.MouseEvent");\r
141 Clazz.pu$h(self.c$);\r
142 c$ = Clazz.declareType (swingjs.plaf.JSButtonListener, "Actions", jssun.swing.UIAction);\r
143 Clazz.overrideMethod (c$, "actionPerformed", \r
144 function (a) {\r
145 var b = a.getSource ();\r
146 var c = this.getName ();\r
147 if (c === "pressed") {\r
148 var d = b.getModel ();\r
149 d.setArmed (true);\r
150 d.setPressed (true);\r
151 if (!b.hasFocus ()) {\r
152 b.requestFocus ();\r
153 }} else if (c === "released") {\r
154 var d = b.getModel ();\r
155 d.setPressed (false);\r
156 d.setArmed (false);\r
157 }}, "java.awt.event.ActionEvent");\r
158 Clazz.defineMethod (c$, "isEnabled", \r
159 function (a) {\r
160 if (a != null && (Clazz.instanceOf (a, javax.swing.AbstractButton)) && !(a).getModel ().isEnabled ()) {\r
161 return false;\r
162 } else {\r
163 return true;\r
164 }}, "~O");\r
165 Clazz.defineStatics (c$,\r
166 "PRESS", "pressed",\r
167 "RELEASE", "released");\r
168 c$ = Clazz.p0p ();\r
169 });\r