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