|
@@ -1,118 +1,118 @@ |
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.widgets.nonpublic.*; |
6 |
|
- |
import org.litesoft.core.simpletypes.*; |
7 |
|
- |
import org.litesoft.core.util.*; |
8 |
|
- |
import org.litesoft.uipopupsupport.*; |
9 |
|
- |
|
10 |
|
- |
import com.google.gwt.user.client.*; |
11 |
|
- |
import com.google.gwt.user.client.ui.*; |
12 |
|
- |
|
13 |
|
- |
public abstract class AbstractContextPopup extends PopupPanel { |
14 |
|
- |
private static final String ERROR_FROM = "AbstractContextPopup"; |
15 |
|
- |
|
16 |
|
- |
protected AbstractContextPopup( boolean pAutoHide ) { |
17 |
|
- |
super( pAutoHide ); |
18 |
|
- |
} |
19 |
|
- |
|
20 |
|
- |
protected void error( String pProblem, RuntimeException pRTE ) { |
21 |
|
- |
AlertManager.alert( ERROR_FROM, "Contextual Options Error", pProblem, pRTE ); |
22 |
|
- |
} |
23 |
|
- |
|
24 |
|
- |
abstract protected Widget createPopupWidget(); |
25 |
|
- |
|
26 |
|
- |
/** |
27 |
|
- |
* Show the Context Popup, positioning it based on the pEvent's Client X & Y positions, and |
28 |
|
- |
* the two provided Relative Rectangular "meeting" Points. |
29 |
|
- |
* |
30 |
|
- |
* @param pEvent !null - used to get the Target (Source) Element & the Mouse |
31 |
|
- |
* location (Client X & Y) |
32 |
|
- |
* @param pRectangleContainmentStrategy !null - Controls Popup location should any of the Popup be off screen. |
33 |
|
- |
* @param pSourceElementRelativeMeetingPoint if not null then indicates to use the clicked on element's |
34 |
|
- |
* location, size, and this "point" as the "meeting" point |
35 |
|
- |
* @param pPopupRelativeMeetingPoint the Popup's "meeting" point. null defaults to "CornerTopLeft" |
36 |
|
- |
*/ |
37 |
|
- |
public void showContextPopup( Event pEvent, // |
38 |
|
- |
RectangleContainmentStrategy pRectangleContainmentStrategy, // |
39 |
|
- |
CommonRectangularPoint pSourceElementRelativeMeetingPoint, CommonRectangularPoint pPopupRelativeMeetingPoint ) { |
40 |
|
- |
Widget zWidget; |
41 |
|
- |
try { |
42 |
|
- |
if ( null == (zWidget = createPopupWidget()) ) { |
43 |
|
- |
error( "No Widget", null ); |
44 |
|
- |
return; |
45 |
|
- |
} |
46 |
|
- |
} |
47 |
|
- |
catch ( RuntimeException e ) { |
48 |
|
- |
error( e.getMessage(), e ); |
49 |
|
- |
return; |
50 |
|
- |
} |
51 |
|
- |
|
52 |
|
- |
setWidget( zWidget ); |
53 |
|
- |
|
54 |
|
- |
setPopupPositionAndShow( new MyPositionCallback( pRectangleContainmentStrategy, pSourceElementRelativeMeetingPoint, pEvent, // |
55 |
|
- |
(pPopupRelativeMeetingPoint != null) ? // |
56 |
|
- |
pPopupRelativeMeetingPoint : // |
57 |
|
- |
CommonRectangularPoint.LeftTop ) ); |
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
@Override |
61 |
|
- |
public void show() { |
62 |
|
- |
super.show(); |
63 |
|
- |
mSavedCaptureElement = DOM.getCaptureElement(); |
64 |
|
- |
if ( mSavedCaptureElement != null ) { |
65 |
|
- |
DOM.releaseCapture( mSavedCaptureElement ); |
66 |
|
- |
} |
67 |
|
- |
} |
68 |
|
- |
|
69 |
|
- |
private Element mSavedCaptureElement = null; |
70 |
|
- |
|
71 |
|
- |
@Override |
72 |
|
- |
public void hide() { |
73 |
|
- |
if ( mSavedCaptureElement != null ) { |
74 |
|
- |
DOM.setCapture( mSavedCaptureElement ); |
75 |
|
- |
mSavedCaptureElement = null; |
76 |
|
- |
} |
77 |
|
- |
super.hide(); |
78 |
|
- |
} |
79 |
|
- |
|
80 |
|
- |
private class MyPositionCallback implements PositionCallback { |
81 |
|
- |
private ContextPopupPositioner mPositioner; |
82 |
|
- |
|
83 |
|
- |
public MyPositionCallback( RectangleContainmentStrategy pRectangleContainmentStrategy, CommonRectangularPoint pSourceElementRelativeMeetingPoint, |
84 |
|
- |
Event pEvent, CommonRectangularPoint pPopupRelativeMeetingPoint ) { |
85 |
|
- |
SizeXY zClientSize = new SizeXY( Window.getClientWidth(), Window.getClientHeight() ); |
86 |
|
- |
PointXY zClientPos = new PointXY( DOM.eventGetClientX( pEvent ), DOM.eventGetClientY( pEvent ) ); |
87 |
|
- |
|
88 |
|
- |
if ( pSourceElementRelativeMeetingPoint == null ) { |
89 |
|
- |
mPositioner = new ContextPopupPositioner( pRectangleContainmentStrategy, pPopupRelativeMeetingPoint,// |
90 |
|
- |
zClientPos, zClientSize ); |
91 |
|
- |
} else { |
92 |
|
- |
Element zTargetElement = DOM.eventGetTarget( pEvent ); |
93 |
|
- |
int zSrcElementXpos = DOM.getAbsoluteLeft( zTargetElement ); |
94 |
|
- |
int zSrcElementYpos = DOM.getAbsoluteTop( zTargetElement ); |
95 |
|
- |
int zSrcElementXsize = CommonElementHelper.getOffsetWidth( zTargetElement ); |
96 |
|
- |
int zSrcElementYsize = CommonElementHelper.getOffsetHeight( zTargetElement ); |
97 |
|
- |
Rect zSourceElementRect = new Rect( zSrcElementXpos, zSrcElementYpos, // |
98 |
|
- |
zSrcElementXsize, zSrcElementYsize ); |
99 |
|
- |
mPositioner = new SourceRelativeContextPopupPositioner( pRectangleContainmentStrategy, pPopupRelativeMeetingPoint, zClientPos, zClientSize, |
100 |
|
- |
pSourceElementRelativeMeetingPoint, zSourceElementRect ); |
101 |
|
- |
} |
102 |
|
- |
} |
103 |
|
- |
|
104 |
|
- |
@Override |
105 |
|
- |
public String toString() { |
106 |
|
- |
return mPositioner.toString(); |
107 |
|
- |
} |
108 |
|
- |
|
109 |
|
- |
@Override |
110 |
|
- |
public void setPosition( int pPopupXsize, int pPopupYsize ) { |
111 |
|
- |
adjustPopup( mPositioner.determinePosition( new Rect( 0, 0, pPopupXsize, pPopupYsize ) ) ); |
112 |
|
- |
} |
113 |
|
- |
|
114 |
|
- |
protected void adjustPopup( Rect pRect ) { |
115 |
|
- |
setPopupPosition( pRect.getXpos(), pRect.getYpos() ); |
116 |
|
- |
} |
117 |
|
- |
} |
118 |
|
- |
} |
|
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.widgets.nonpublic.*; |
|
6 |
+ |
import org.litesoft.core.simpletypes.*; |
|
7 |
+ |
import org.litesoft.core.util.*; |
|
8 |
+ |
import org.litesoft.uipopupsupport.*; |
|
9 |
+ |
|
|
10 |
+ |
import com.google.gwt.user.client.*; |
|
11 |
+ |
import com.google.gwt.user.client.ui.*; |
|
12 |
+ |
|
|
13 |
+ |
public abstract class AbstractContextPopup extends PopupPanel { |
|
14 |
+ |
private static final String ERROR_FROM = "AbstractContextPopup"; |
|
15 |
+ |
|
|
16 |
+ |
protected AbstractContextPopup( boolean pAutoHide ) { |
|
17 |
+ |
super( pAutoHide ); |
|
18 |
+ |
} |
|
19 |
+ |
|
|
20 |
+ |
protected void error( String pProblem, RuntimeException pRTE ) { |
|
21 |
+ |
AlertManager.alert( ERROR_FROM, "Contextual Options Error", pProblem, pRTE ); |
|
22 |
+ |
} |
|
23 |
+ |
|
|
24 |
+ |
abstract protected Widget createPopupWidget(); |
|
25 |
+ |
|
|
26 |
+ |
/** |
|
27 |
+ |
* Show the Context Popup, positioning it based on the pEvent's Client X & Y positions, and |
|
28 |
+ |
* the two provided Relative Rectangular "meeting" Points. |
|
29 |
+ |
* |
|
30 |
+ |
* @param pEvent !null - used to get the Target (Source) Element & the Mouse |
|
31 |
+ |
* location (Client X & Y) |
|
32 |
+ |
* @param pRectangleContainmentStrategy !null - Controls Popup location should any of the Popup be off screen. |
|
33 |
+ |
* @param pSourceElementRelativeMeetingPoint if not null then indicates to use the clicked on element's |
|
34 |
+ |
* location, size, and this "point" as the "meeting" point |
|
35 |
+ |
* @param pPopupRelativeMeetingPoint the Popup's "meeting" point. null defaults to "CornerTopLeft" |
|
36 |
+ |
*/ |
|
37 |
+ |
public void showContextPopup( Event pEvent, // |
|
38 |
+ |
RectangleContainmentStrategy pRectangleContainmentStrategy, // |
|
39 |
+ |
CommonRectangularPoint pSourceElementRelativeMeetingPoint, CommonRectangularPoint pPopupRelativeMeetingPoint ) { |
|
40 |
+ |
Widget zWidget; |
|
41 |
+ |
try { |
|
42 |
+ |
if ( null == (zWidget = createPopupWidget()) ) { |
|
43 |
+ |
error( "No Widget", null ); |
|
44 |
+ |
return; |
|
45 |
+ |
} |
|
46 |
+ |
} |
|
47 |
+ |
catch ( RuntimeException e ) { |
|
48 |
+ |
error( e.getMessage(), e ); |
|
49 |
+ |
return; |
|
50 |
+ |
} |
|
51 |
+ |
|
|
52 |
+ |
setWidget( zWidget ); |
|
53 |
+ |
|
|
54 |
+ |
setPopupPositionAndShow( new MyPositionCallback( pRectangleContainmentStrategy, pSourceElementRelativeMeetingPoint, pEvent, // |
|
55 |
+ |
(pPopupRelativeMeetingPoint != null) ? // |
|
56 |
+ |
pPopupRelativeMeetingPoint : // |
|
57 |
+ |
CommonRectangularPoint.LeftTop ) ); |
|
58 |
+ |
} |
|
59 |
+ |
|
|
60 |
+ |
@Override |
|
61 |
+ |
public void show() { |
|
62 |
+ |
super.show(); |
|
63 |
+ |
mSavedCaptureElement = DOM.getCaptureElement(); |
|
64 |
+ |
if ( mSavedCaptureElement != null ) { |
|
65 |
+ |
DOM.releaseCapture( mSavedCaptureElement ); |
|
66 |
+ |
} |
|
67 |
+ |
} |
|
68 |
+ |
|
|
69 |
+ |
private Element mSavedCaptureElement = null; |
|
70 |
+ |
|
|
71 |
+ |
@Override |
|
72 |
+ |
public void hide() { |
|
73 |
+ |
if ( mSavedCaptureElement != null ) { |
|
74 |
+ |
DOM.setCapture( mSavedCaptureElement ); |
|
75 |
+ |
mSavedCaptureElement = null; |
|
76 |
+ |
} |
|
77 |
+ |
super.hide(); |
|
78 |
+ |
} |
|
79 |
+ |
|
|
80 |
+ |
private class MyPositionCallback implements PositionCallback { |
|
81 |
+ |
private ContextPopupPositioner mPositioner; |
|
82 |
+ |
|
|
83 |
+ |
public MyPositionCallback( RectangleContainmentStrategy pRectangleContainmentStrategy, CommonRectangularPoint pSourceElementRelativeMeetingPoint, |
|
84 |
+ |
Event pEvent, CommonRectangularPoint pPopupRelativeMeetingPoint ) { |
|
85 |
+ |
SizeXY zClientSize = new SizeXY( Window.getClientWidth(), Window.getClientHeight() ); |
|
86 |
+ |
PointXY zClientPos = new PointXY( DOM.eventGetClientX( pEvent ), DOM.eventGetClientY( pEvent ) ); |
|
87 |
+ |
|
|
88 |
+ |
if ( pSourceElementRelativeMeetingPoint == null ) { |
|
89 |
+ |
mPositioner = new ContextPopupPositioner( pRectangleContainmentStrategy, pPopupRelativeMeetingPoint,// |
|
90 |
+ |
zClientPos, zClientSize ); |
|
91 |
+ |
} else { |
|
92 |
+ |
Element zTargetElement = DOM.eventGetTarget( pEvent ); |
|
93 |
+ |
int zSrcElementXpos = DOM.getAbsoluteLeft( zTargetElement ); |
|
94 |
+ |
int zSrcElementYpos = DOM.getAbsoluteTop( zTargetElement ); |
|
95 |
+ |
int zSrcElementXsize = CommonElementHelper.getOffsetWidth( zTargetElement ); |
|
96 |
+ |
int zSrcElementYsize = CommonElementHelper.getOffsetHeight( zTargetElement ); |
|
97 |
+ |
Rect zSourceElementRect = new Rect( zSrcElementXpos, zSrcElementYpos, // |
|
98 |
+ |
zSrcElementXsize, zSrcElementYsize ); |
|
99 |
+ |
mPositioner = new SourceRelativeContextPopupPositioner( pRectangleContainmentStrategy, pPopupRelativeMeetingPoint, zClientPos, zClientSize, |
|
100 |
+ |
pSourceElementRelativeMeetingPoint, zSourceElementRect ); |
|
101 |
+ |
} |
|
102 |
+ |
} |
|
103 |
+ |
|
|
104 |
+ |
@Override |
|
105 |
+ |
public String toString() { |
|
106 |
+ |
return mPositioner.toString(); |
|
107 |
+ |
} |
|
108 |
+ |
|
|
109 |
+ |
@Override |
|
110 |
+ |
public void setPosition( int pPopupXsize, int pPopupYsize ) { |
|
111 |
+ |
adjustPopup( mPositioner.determinePosition( new Rect( 0, 0, pPopupXsize, pPopupYsize ) ) ); |
|
112 |
+ |
} |
|
113 |
+ |
|
|
114 |
+ |
protected void adjustPopup( Rect pRect ) { |
|
115 |
+ |
setPopupPosition( pRect.getXpos(), pRect.getYpos() ); |
|
116 |
+ |
} |
|
117 |
+ |
} |
|
118 |
+ |
} |