|
@@ -1,101 +1,101 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.client.components.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.Button; |
5 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
6 |
|
- |
|
7 |
|
- |
import com.google.gwt.dom.client.*; |
8 |
|
- |
import com.google.gwt.event.dom.client.*; |
9 |
|
- |
import com.google.gwt.user.client.ui.*; |
10 |
|
- |
|
11 |
|
- |
public class DialogButtonPanel extends HorizontalPanel { |
12 |
|
- |
private Button[] mButtons; |
13 |
|
- |
|
14 |
|
- |
public DialogButtonPanel( ClickHandler pClickHandler, Button... pButtons ) { |
15 |
|
- |
boolean anyAdded = false; |
16 |
|
- |
if ( null != (mButtons = pButtons) ) { |
17 |
|
- |
for ( Button zButton : pButtons ) { |
18 |
|
- |
if ( zButton != null ) { |
19 |
|
- |
if ( anyAdded ) { |
20 |
|
- |
add( new Spacer( 5 ) ); |
21 |
|
- |
} |
22 |
|
- |
zButton.addClickHandler( pClickHandler ); |
23 |
|
- |
add( zButton ); |
24 |
|
- |
anyAdded = true; |
25 |
|
- |
} |
26 |
|
- |
} |
27 |
|
- |
} |
28 |
|
- |
if ( !anyAdded ) { |
29 |
|
- |
throw new IllegalArgumentException( "No Buttons on the DialogButtonPanel" ); |
30 |
|
- |
} |
31 |
|
- |
getElement().getStyle().setMarginTop( 2, Style.Unit.PX ); // todo: Warning can mess up Sizeing |
32 |
|
- |
} |
33 |
|
- |
|
34 |
|
- |
public boolean isOurButton( Widget pSender ) { |
35 |
|
- |
for ( Button zButton : mButtons ) { |
36 |
|
- |
if ( pSender == zButton ) { |
37 |
|
- |
return true; |
38 |
|
- |
} |
39 |
|
- |
} |
40 |
|
- |
return false; |
41 |
|
- |
} |
42 |
|
- |
|
43 |
|
- |
private Button buildButton( String[] pButtonTexts, int pIndex, ClickHandler pClickHandler ) { |
44 |
|
- |
String zText = pButtonTexts[pIndex]; |
45 |
|
- |
if ( zText == null ) { |
46 |
|
- |
return null; |
47 |
|
- |
} |
48 |
|
- |
DefButtonNamedTypedAbstractTextable zDefButton; |
49 |
|
- |
|
50 |
|
- |
if ( pButtonTexts.length == 1 ) { |
51 |
|
- |
zDefButton = Button.named( "DialogButtonOnly" ).green(); |
52 |
|
- |
} else if ( (pButtonTexts.length - 1) == pIndex ) { |
53 |
|
- |
zDefButton = Button.named( "DialogButtonLast" ).green(); |
54 |
|
- |
} else if ( pIndex == 0 ) { |
55 |
|
- |
zDefButton = Button.named( "DialogButtonFirst" ).red(); |
56 |
|
- |
} else { |
57 |
|
- |
zDefButton = Button.named( "DialogButtonMiddle" ).blue(); |
58 |
|
- |
} |
59 |
|
- |
return zDefButton.text( zText ).add( pClickHandler ).create(); |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
@Override |
63 |
|
- |
protected void onAttach() { |
64 |
|
- |
super.onAttach(); |
65 |
|
- |
sizeAllButtons( mButtons ); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
public static void sizeAllButtons( Button[] pButtons ) { |
69 |
|
- |
boolean zAllSame = true; |
70 |
|
- |
int zFirstAt = -1; |
71 |
|
- |
int zMaxWidth = 0; |
72 |
|
- |
Integer[] zWidths = new Integer[pButtons.length]; |
73 |
|
- |
for ( int i = 0; i < pButtons.length; i++ ) { |
74 |
|
- |
Button zButton = pButtons[i]; |
75 |
|
- |
if ( zButton != null ) { |
76 |
|
- |
int zWidth = zButton.getOffsetWidth(); |
77 |
|
- |
if ( zWidth < 1 ) { |
78 |
|
- |
System.err.println( "************** DialogButtonPanel.sizeAllButtons **************" ); |
79 |
|
- |
return; |
80 |
|
- |
} |
81 |
|
- |
zWidths[i] = zWidth; |
82 |
|
- |
if ( zAllSame ) { |
83 |
|
- |
if ( zFirstAt == -1 ) { |
84 |
|
- |
zFirstAt = i; |
85 |
|
- |
zMaxWidth = zWidth; |
86 |
|
- |
} else if ( !(zAllSame = zWidth == zWidths[zFirstAt]) ) { |
87 |
|
- |
zMaxWidth = Math.max( zMaxWidth, zWidth ); |
88 |
|
- |
} |
89 |
|
- |
} |
90 |
|
- |
} |
91 |
|
- |
} |
92 |
|
- |
if ( !zAllSame ) { |
93 |
|
- |
for ( int i = 0; i < pButtons.length; i++ ) { |
94 |
|
- |
Integer zWidth = zWidths[i]; |
95 |
|
- |
if ( (zWidth != null) && (zMaxWidth != zWidth) ) { |
96 |
|
- |
pButtons[i].setWidth( "" + zMaxWidth ); |
97 |
|
- |
} |
98 |
|
- |
} |
99 |
|
- |
} |
100 |
|
- |
} |
101 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.client.components.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.Button; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
6 |
+ |
|
|
7 |
+ |
import com.google.gwt.dom.client.*; |
|
8 |
+ |
import com.google.gwt.event.dom.client.*; |
|
9 |
+ |
import com.google.gwt.user.client.ui.*; |
|
10 |
+ |
|
|
11 |
+ |
public class DialogButtonPanel extends HorizontalPanel { |
|
12 |
+ |
private Button[] mButtons; |
|
13 |
+ |
|
|
14 |
+ |
public DialogButtonPanel( ClickHandler pClickHandler, Button... pButtons ) { |
|
15 |
+ |
boolean anyAdded = false; |
|
16 |
+ |
if ( null != (mButtons = pButtons) ) { |
|
17 |
+ |
for ( Button zButton : pButtons ) { |
|
18 |
+ |
if ( zButton != null ) { |
|
19 |
+ |
if ( anyAdded ) { |
|
20 |
+ |
add( new Spacer( 5 ) ); |
|
21 |
+ |
} |
|
22 |
+ |
zButton.addClickHandler( pClickHandler ); |
|
23 |
+ |
add( zButton ); |
|
24 |
+ |
anyAdded = true; |
|
25 |
+ |
} |
|
26 |
+ |
} |
|
27 |
+ |
} |
|
28 |
+ |
if ( !anyAdded ) { |
|
29 |
+ |
throw new IllegalArgumentException( "No Buttons on the DialogButtonPanel" ); |
|
30 |
+ |
} |
|
31 |
+ |
getElement().getStyle().setMarginTop( 2, Style.Unit.PX ); // todo: Warning can mess up Sizeing |
|
32 |
+ |
} |
|
33 |
+ |
|
|
34 |
+ |
public boolean isOurButton( Widget pSender ) { |
|
35 |
+ |
for ( Button zButton : mButtons ) { |
|
36 |
+ |
if ( pSender == zButton ) { |
|
37 |
+ |
return true; |
|
38 |
+ |
} |
|
39 |
+ |
} |
|
40 |
+ |
return false; |
|
41 |
+ |
} |
|
42 |
+ |
|
|
43 |
+ |
private Button buildButton( String[] pButtonTexts, int pIndex, ClickHandler pClickHandler ) { |
|
44 |
+ |
String zText = pButtonTexts[pIndex]; |
|
45 |
+ |
if ( zText == null ) { |
|
46 |
+ |
return null; |
|
47 |
+ |
} |
|
48 |
+ |
DefButtonNamedTypedAbstractTextable zDefButton; |
|
49 |
+ |
|
|
50 |
+ |
if ( pButtonTexts.length == 1 ) { |
|
51 |
+ |
zDefButton = Button.named( "DialogButtonOnly" ).green(); |
|
52 |
+ |
} else if ( (pButtonTexts.length - 1) == pIndex ) { |
|
53 |
+ |
zDefButton = Button.named( "DialogButtonLast" ).green(); |
|
54 |
+ |
} else if ( pIndex == 0 ) { |
|
55 |
+ |
zDefButton = Button.named( "DialogButtonFirst" ).red(); |
|
56 |
+ |
} else { |
|
57 |
+ |
zDefButton = Button.named( "DialogButtonMiddle" ).blue(); |
|
58 |
+ |
} |
|
59 |
+ |
return zDefButton.text( zText ).add( pClickHandler ).create(); |
|
60 |
+ |
} |
|
61 |
+ |
|
|
62 |
+ |
@Override |
|
63 |
+ |
protected void onAttach() { |
|
64 |
+ |
super.onAttach(); |
|
65 |
+ |
sizeAllButtons( mButtons ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
public static void sizeAllButtons( Button[] pButtons ) { |
|
69 |
+ |
boolean zAllSame = true; |
|
70 |
+ |
int zFirstAt = -1; |
|
71 |
+ |
int zMaxWidth = 0; |
|
72 |
+ |
Integer[] zWidths = new Integer[pButtons.length]; |
|
73 |
+ |
for ( int i = 0; i < pButtons.length; i++ ) { |
|
74 |
+ |
Button zButton = pButtons[i]; |
|
75 |
+ |
if ( zButton != null ) { |
|
76 |
+ |
int zWidth = zButton.getOffsetWidth(); |
|
77 |
+ |
if ( zWidth < 1 ) { |
|
78 |
+ |
System.err.println( "************** DialogButtonPanel.sizeAllButtons **************" ); |
|
79 |
+ |
return; |
|
80 |
+ |
} |
|
81 |
+ |
zWidths[i] = zWidth; |
|
82 |
+ |
if ( zAllSame ) { |
|
83 |
+ |
if ( zFirstAt == -1 ) { |
|
84 |
+ |
zFirstAt = i; |
|
85 |
+ |
zMaxWidth = zWidth; |
|
86 |
+ |
} else if ( !(zAllSame = zWidth == zWidths[zFirstAt]) ) { |
|
87 |
+ |
zMaxWidth = Math.max( zMaxWidth, zWidth ); |
|
88 |
+ |
} |
|
89 |
+ |
} |
|
90 |
+ |
} |
|
91 |
+ |
} |
|
92 |
+ |
if ( !zAllSame ) { |
|
93 |
+ |
for ( int i = 0; i < pButtons.length; i++ ) { |
|
94 |
+ |
Integer zWidth = zWidths[i]; |
|
95 |
+ |
if ( (zWidth != null) && (zMaxWidth != zWidth) ) { |
|
96 |
+ |
pButtons[i].setWidth( "" + zMaxWidth ); |
|
97 |
+ |
} |
|
98 |
+ |
} |
|
99 |
+ |
} |
|
100 |
+ |
} |
|
101 |
+ |
} |