|
@@ -1,143 +1,142 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.*; |
5 |
|
- |
import org.litesoft.GWT.client.ui.inspection.*; |
6 |
|
- |
import org.litesoft.commonfoundation.base.*; |
7 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
8 |
|
- |
import org.litesoft.core.util.*; |
9 |
|
- |
import org.litesoft.logger.*; |
10 |
|
- |
|
11 |
|
- |
import com.google.gwt.dom.client.*; |
12 |
|
- |
import com.google.gwt.dom.client.Element; |
13 |
|
- |
import com.google.gwt.event.dom.client.*; |
14 |
|
- |
import com.google.gwt.user.client.*; |
15 |
|
- |
import com.google.gwt.user.client.ui.*; |
16 |
|
- |
|
17 |
|
- |
public abstract class Button extends ButtonBase implements Enableable { |
18 |
|
- |
public static final Logger LOGGER = LoggerFactory.getLogger( Button.class ); |
19 |
|
- |
|
20 |
|
- |
private final String mName; |
21 |
|
- |
|
22 |
|
- |
protected Button( String pName, Element pElement ) { |
23 |
|
- |
super( pElement ); |
24 |
|
- |
mName = Strings.assertNotNullNotEmpty( "Name", pName ); |
25 |
|
- |
} |
26 |
|
- |
|
27 |
|
- |
public static DefButtonNamed named( String pName ) { |
28 |
|
- |
return new DefButtonNamed( pName ); |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
public Button disable() { |
32 |
|
- |
setEnabled( false ); |
33 |
|
- |
return this; |
34 |
|
- |
} |
35 |
|
- |
|
36 |
|
- |
public abstract void setColorStyleClass( String pNewColorStyleClassName ); |
37 |
|
- |
|
38 |
|
- |
public String getName() { |
39 |
|
- |
return mName; |
40 |
|
- |
} |
41 |
|
- |
|
42 |
|
- |
public void simulateUserClick( KeyboardKeyModifier pModifiers ) { |
43 |
|
- |
if ( pModifiers == null ) { |
44 |
|
- |
pModifiers = KeyboardKeyModifier.None; |
45 |
|
- |
} |
46 |
|
- |
NativeEvent event = Document.get().createClickEvent( 0, 0, 0, 0, 0, // |
47 |
|
- |
pModifiers.isCtrl(), // |
48 |
|
- |
pModifiers.isAlt(), // |
49 |
|
- |
pModifiers.isShift(), // |
50 |
|
- |
pModifiers.isMeta() ); |
51 |
|
- |
getElement().dispatchEvent( event ); |
52 |
|
- |
} |
53 |
|
- |
|
54 |
|
- |
@Override |
55 |
|
- |
public String getHTML() { |
56 |
|
- |
throw badOperation( "getHTML" ); |
57 |
|
- |
} |
58 |
|
- |
|
59 |
|
- |
@Override |
60 |
|
- |
public String getText() { |
61 |
|
- |
throw badOperation( "getText" ); |
62 |
|
- |
} |
63 |
|
- |
|
64 |
|
- |
@Override |
65 |
|
- |
public void setHTML( String html ) { |
66 |
|
- |
throw badOperation( "setHTML" ); |
67 |
|
- |
} |
68 |
|
- |
|
69 |
|
- |
@Override |
70 |
|
- |
public void setText( String text ) { |
71 |
|
- |
throw badOperation( "setText" ); |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
protected void simulateMouseMove( Event pEvent ) { |
75 |
|
- |
final MousePoint zMP = new MousePoint( pEvent ); |
76 |
|
- |
|
77 |
|
- |
if ( !zMP.over( WindowSizingPanel.get() ) ) { |
78 |
|
- |
return; |
79 |
|
- |
} |
80 |
|
- |
|
81 |
|
- |
Widget zWidget = WidgetFinder.find( new WidgetSelector() { |
82 |
|
- |
@Override |
83 |
|
- |
public boolean isAcceptable( Widget pWidget ) { |
84 |
|
- |
if ( pWidget instanceof Button ) { |
85 |
|
- |
if ( zMP.over( pWidget ) ) { |
86 |
|
- |
return true; |
87 |
|
- |
} |
88 |
|
- |
} |
89 |
|
- |
return false; |
90 |
|
- |
} |
91 |
|
- |
} ); |
92 |
|
- |
|
93 |
|
- |
if ( zWidget != null ) { |
94 |
|
- |
LOGGER.trace.log( "Attempting to Fake MouseMove on: ", zWidget ); |
95 |
|
- |
zWidget.getElement().dispatchEvent( Document.get().createMouseMoveEvent( 0, // |
96 |
|
- |
pEvent.getScreenX(), pEvent.getScreenY(), // |
97 |
|
- |
zMP.getClientX(), zMP.getClientY(), // |
98 |
|
- |
false, false, false, false, // |
99 |
|
- |
NativeEvent.BUTTON_LEFT ) ); |
100 |
|
- |
} |
101 |
|
- |
} |
102 |
|
- |
|
103 |
|
- |
private static class MousePoint { |
104 |
|
- |
private int mClientX, mClientY; |
105 |
|
- |
|
106 |
|
- |
public MousePoint( Event pEvent ) { |
107 |
|
- |
mClientX = pEvent.getClientX(); |
108 |
|
- |
mClientY = pEvent.getClientY(); |
109 |
|
- |
} |
110 |
|
- |
|
111 |
|
- |
public int getClientX() { |
112 |
|
- |
return mClientX; |
113 |
|
- |
} |
114 |
|
- |
|
115 |
|
- |
public int getClientY() { |
116 |
|
- |
return mClientY; |
117 |
|
- |
} |
118 |
|
- |
|
119 |
|
- |
public boolean over( Widget pWidget ) { |
120 |
|
- |
return over( mClientX, pWidget.getAbsoluteLeft(), pWidget.getOffsetWidth() ) && // |
121 |
|
- |
over( mClientY, pWidget.getAbsoluteTop(), pWidget.getOffsetHeight() ); |
122 |
|
- |
} |
123 |
|
- |
|
124 |
|
- |
private boolean over( int pClientPoint, int pWidgetAt, int pOffsetSize ) { |
125 |
|
- |
return (pWidgetAt <= pClientPoint) && (pClientPoint < (pWidgetAt + pOffsetSize)); |
126 |
|
- |
} |
127 |
|
- |
} |
128 |
|
- |
|
129 |
|
- |
protected static class MyMouseMoveEvent extends MouseMoveEvent { |
130 |
|
- |
public MyMouseMoveEvent( Event pEvent ) { |
131 |
|
- |
setNativeEvent( pEvent ); |
132 |
|
- |
} |
133 |
|
- |
} |
134 |
|
- |
|
135 |
|
- |
private UnsupportedOperationException badOperation( String pWhat ) { |
136 |
|
- |
return new UnsupportedOperationException( "LiteSoft Button's do not support the '" + pWhat + "' method!" ); |
137 |
|
- |
} |
138 |
|
- |
|
139 |
|
- |
@Override |
140 |
|
- |
public String toString() { |
141 |
|
- |
return ClassName.simple( this ) + "( " + mName + " )"; |
142 |
|
- |
} |
143 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.*; |
|
5 |
+ |
import org.litesoft.GWT.client.ui.inspection.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
7 |
+ |
import org.litesoft.core.util.*; |
|
8 |
+ |
import org.litesoft.logger.*; |
|
9 |
+ |
|
|
10 |
+ |
import com.google.gwt.dom.client.*; |
|
11 |
+ |
import com.google.gwt.dom.client.Element; |
|
12 |
+ |
import com.google.gwt.event.dom.client.*; |
|
13 |
+ |
import com.google.gwt.user.client.*; |
|
14 |
+ |
import com.google.gwt.user.client.ui.*; |
|
15 |
+ |
|
|
16 |
+ |
public abstract class Button extends ButtonBase implements Enableable { |
|
17 |
+ |
public static final Logger LOGGER = LoggerFactory.getLogger( Button.class ); |
|
18 |
+ |
|
|
19 |
+ |
private final String mName; |
|
20 |
+ |
|
|
21 |
+ |
protected Button( String pName, Element pElement ) { |
|
22 |
+ |
super( pElement ); |
|
23 |
+ |
mName = Confirm.significant( "Name", pName ); |
|
24 |
+ |
} |
|
25 |
+ |
|
|
26 |
+ |
public static DefButtonNamed named( String pName ) { |
|
27 |
+ |
return new DefButtonNamed( pName ); |
|
28 |
+ |
} |
|
29 |
+ |
|
|
30 |
+ |
public Button disable() { |
|
31 |
+ |
setEnabled( false ); |
|
32 |
+ |
return this; |
|
33 |
+ |
} |
|
34 |
+ |
|
|
35 |
+ |
public abstract void setColorStyleClass( String pNewColorStyleClassName ); |
|
36 |
+ |
|
|
37 |
+ |
public String getName() { |
|
38 |
+ |
return mName; |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
public void simulateUserClick( KeyboardKeyModifier pModifiers ) { |
|
42 |
+ |
if ( pModifiers == null ) { |
|
43 |
+ |
pModifiers = KeyboardKeyModifier.None; |
|
44 |
+ |
} |
|
45 |
+ |
NativeEvent event = Document.get().createClickEvent( 0, 0, 0, 0, 0, // |
|
46 |
+ |
pModifiers.isCtrl(), // |
|
47 |
+ |
pModifiers.isAlt(), // |
|
48 |
+ |
pModifiers.isShift(), // |
|
49 |
+ |
pModifiers.isMeta() ); |
|
50 |
+ |
getElement().dispatchEvent( event ); |
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
@Override |
|
54 |
+ |
public String getHTML() { |
|
55 |
+ |
throw badOperation( "getHTML" ); |
|
56 |
+ |
} |
|
57 |
+ |
|
|
58 |
+ |
@Override |
|
59 |
+ |
public String getText() { |
|
60 |
+ |
throw badOperation( "getText" ); |
|
61 |
+ |
} |
|
62 |
+ |
|
|
63 |
+ |
@Override |
|
64 |
+ |
public void setHTML( String html ) { |
|
65 |
+ |
throw badOperation( "setHTML" ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
@Override |
|
69 |
+ |
public void setText( String text ) { |
|
70 |
+ |
throw badOperation( "setText" ); |
|
71 |
+ |
} |
|
72 |
+ |
|
|
73 |
+ |
protected void simulateMouseMove( Event pEvent ) { |
|
74 |
+ |
final MousePoint zMP = new MousePoint( pEvent ); |
|
75 |
+ |
|
|
76 |
+ |
if ( !zMP.over( WindowSizingPanel.get() ) ) { |
|
77 |
+ |
return; |
|
78 |
+ |
} |
|
79 |
+ |
|
|
80 |
+ |
Widget zWidget = WidgetFinder.find( new WidgetSelector() { |
|
81 |
+ |
@Override |
|
82 |
+ |
public boolean isAcceptable( Widget pWidget ) { |
|
83 |
+ |
if ( pWidget instanceof Button ) { |
|
84 |
+ |
if ( zMP.over( pWidget ) ) { |
|
85 |
+ |
return true; |
|
86 |
+ |
} |
|
87 |
+ |
} |
|
88 |
+ |
return false; |
|
89 |
+ |
} |
|
90 |
+ |
} ); |
|
91 |
+ |
|
|
92 |
+ |
if ( zWidget != null ) { |
|
93 |
+ |
LOGGER.trace.log( "Attempting to Fake MouseMove on: ", zWidget ); |
|
94 |
+ |
zWidget.getElement().dispatchEvent( Document.get().createMouseMoveEvent( 0, // |
|
95 |
+ |
pEvent.getScreenX(), pEvent.getScreenY(), // |
|
96 |
+ |
zMP.getClientX(), zMP.getClientY(), // |
|
97 |
+ |
false, false, false, false, // |
|
98 |
+ |
NativeEvent.BUTTON_LEFT ) ); |
|
99 |
+ |
} |
|
100 |
+ |
} |
|
101 |
+ |
|
|
102 |
+ |
private static class MousePoint { |
|
103 |
+ |
private int mClientX, mClientY; |
|
104 |
+ |
|
|
105 |
+ |
public MousePoint( Event pEvent ) { |
|
106 |
+ |
mClientX = pEvent.getClientX(); |
|
107 |
+ |
mClientY = pEvent.getClientY(); |
|
108 |
+ |
} |
|
109 |
+ |
|
|
110 |
+ |
public int getClientX() { |
|
111 |
+ |
return mClientX; |
|
112 |
+ |
} |
|
113 |
+ |
|
|
114 |
+ |
public int getClientY() { |
|
115 |
+ |
return mClientY; |
|
116 |
+ |
} |
|
117 |
+ |
|
|
118 |
+ |
public boolean over( Widget pWidget ) { |
|
119 |
+ |
return over( mClientX, pWidget.getAbsoluteLeft(), pWidget.getOffsetWidth() ) && // |
|
120 |
+ |
over( mClientY, pWidget.getAbsoluteTop(), pWidget.getOffsetHeight() ); |
|
121 |
+ |
} |
|
122 |
+ |
|
|
123 |
+ |
private boolean over( int pClientPoint, int pWidgetAt, int pOffsetSize ) { |
|
124 |
+ |
return (pWidgetAt <= pClientPoint) && (pClientPoint < (pWidgetAt + pOffsetSize)); |
|
125 |
+ |
} |
|
126 |
+ |
} |
|
127 |
+ |
|
|
128 |
+ |
protected static class MyMouseMoveEvent extends MouseMoveEvent { |
|
129 |
+ |
public MyMouseMoveEvent( Event pEvent ) { |
|
130 |
+ |
setNativeEvent( pEvent ); |
|
131 |
+ |
} |
|
132 |
+ |
} |
|
133 |
+ |
|
|
134 |
+ |
private UnsupportedOperationException badOperation( String pWhat ) { |
|
135 |
+ |
return new UnsupportedOperationException( "LiteSoft Button's do not support the '" + pWhat + "' method!" ); |
|
136 |
+ |
} |
|
137 |
+ |
|
|
138 |
+ |
@Override |
|
139 |
+ |
public String toString() { |
|
140 |
+ |
return ClassName.simple( this ) + "( " + mName + " )"; |
|
141 |
+ |
} |
|
142 |
+ |
} |