|
@@ -1,10 +1,8 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget; |
2 |
2 |
|
|
3 |
|
- |
import com.google.gwt.dom.client.TableCellElement; |
4 |
|
- |
import com.google.gwt.dom.client.TableElement; |
|
3 |
+ |
import com.google.gwt.dom.client.*; |
5 |
4 |
|
import com.google.gwt.user.client.Element; |
6 |
|
- |
import com.google.gwt.user.client.ui.HorizontalPanel; |
7 |
|
- |
import com.google.gwt.user.client.ui.Widget; |
|
5 |
+ |
import com.google.gwt.user.client.ui.*; |
8 |
6 |
|
|
9 |
7 |
|
/** |
10 |
8 |
|
* LeftRightSiblings is basically a Single Pixel Transparent Image that is used |
|
@@ -17,51 +15,51 @@ |
17 |
15 |
|
|
18 |
16 |
|
private boolean shouldVerticallyCenter; |
19 |
17 |
|
|
20 |
|
- |
public LeftRightSiblings(boolean shouldVerticallyCenter) { |
|
18 |
+ |
public LeftRightSiblings( boolean shouldVerticallyCenter ) { |
21 |
19 |
|
this.shouldVerticallyCenter = shouldVerticallyCenter; |
22 |
20 |
|
} |
23 |
21 |
|
|
24 |
22 |
|
public LeftRightSiblings() { |
25 |
|
- |
this(true); |
|
23 |
+ |
this( true ); |
26 |
24 |
|
} |
27 |
25 |
|
|
28 |
26 |
|
@Override |
29 |
27 |
|
protected void onAttach() { |
30 |
28 |
|
super.onAttach(); |
31 |
|
- |
if (!(getParent() instanceof HorizontalPanel)) { |
32 |
|
- |
throw new IllegalArgumentException("LeftRightSiblings may only be used as a direct child of a HorizontalPanel!"); |
|
29 |
+ |
if ( !(getParent() instanceof HorizontalPanel) ) { |
|
30 |
+ |
throw new IllegalArgumentException( "LeftRightSiblings may only be used as a direct child of a HorizontalPanel!" ); |
33 |
31 |
|
} |
34 |
32 |
|
HorizontalPanel parent = (HorizontalPanel) getParent(); |
35 |
33 |
|
Widget left = null; |
36 |
34 |
|
Widget right = null; |
37 |
|
- |
int ourIndex = parent.getWidgetIndex(this); |
38 |
|
- |
switch (parent.getWidgetCount()) { |
|
35 |
+ |
int ourIndex = parent.getWidgetIndex( this ); |
|
36 |
+ |
switch ( parent.getWidgetCount() ) { |
39 |
37 |
|
case 1: |
40 |
|
- |
throw new IllegalArgumentException("LeftRightSiblings has NO Siblings!"); |
|
38 |
+ |
throw new IllegalArgumentException( "LeftRightSiblings has NO Siblings!" ); |
41 |
39 |
|
case 3: |
42 |
|
- |
if (ourIndex != 1) { |
43 |
|
- |
throw new IllegalArgumentException("LeftRightSiblings is NOT the Center Widget!"); |
|
40 |
+ |
if ( ourIndex != 1 ) { |
|
41 |
+ |
throw new IllegalArgumentException( "LeftRightSiblings is NOT the Center Widget!" ); |
44 |
42 |
|
} |
45 |
|
- |
left = parent.getWidget(0); |
46 |
|
- |
right = parent.getWidget(2); |
|
43 |
+ |
left = parent.getWidget( 0 ); |
|
44 |
+ |
right = parent.getWidget( 2 ); |
47 |
45 |
|
break; |
48 |
46 |
|
case 2: |
49 |
|
- |
if (ourIndex == 1) { |
50 |
|
- |
left = parent.getWidget(0); |
|
47 |
+ |
if ( ourIndex == 1 ) { |
|
48 |
+ |
left = parent.getWidget( 0 ); |
51 |
49 |
|
} else { |
52 |
|
- |
right = parent.getWidget(1); |
|
50 |
+ |
right = parent.getWidget( 1 ); |
53 |
51 |
|
} |
54 |
52 |
|
break; |
55 |
53 |
|
default: |
56 |
|
- |
throw new IllegalArgumentException("LeftRightSiblings has more than 2 Siblings!"); |
|
54 |
+ |
throw new IllegalArgumentException( "LeftRightSiblings has more than 2 Siblings!" ); |
57 |
55 |
|
} |
58 |
|
- |
TableElement element = getTableElement(parent.getElement()); |
59 |
|
- |
setBorder(element, 0); |
60 |
|
- |
setCellPadding(element, 0); |
61 |
|
- |
setCellSpacing(element, 0); |
62 |
|
- |
setWidth(element, "100%"); |
63 |
|
- |
setTD(left, "left"); |
64 |
|
- |
setTD(right, "right"); |
|
56 |
+ |
TableElement element = getTableElement( parent.getElement() ); |
|
57 |
+ |
setBorder( element, 0 ); |
|
58 |
+ |
setCellPadding( element, 0 ); |
|
59 |
+ |
setCellSpacing( element, 0 ); |
|
60 |
+ |
setWidth( element, "100%" ); |
|
61 |
+ |
setTD( left, "left" ); |
|
62 |
+ |
setTD( right, "right" ); |
65 |
63 |
|
|
66 |
64 |
|
// <table border=0 cellpadding=0 cellspacing=0 width='100%'><tr> |
67 |
65 |
|
// <td align='left' valign='middle'>widget</td> |
|
@@ -69,41 +67,41 @@ |
69 |
67 |
|
// </tr></table> |
70 |
68 |
|
} |
71 |
69 |
|
|
72 |
|
- |
private void setTD(Widget widget, String align) { |
73 |
|
- |
if (widget != null) { |
74 |
|
- |
TableCellElement element = getTDElement(widget.getElement().getParentElement()); |
75 |
|
- |
if (shouldVerticallyCenter) { |
76 |
|
- |
setVAlign(element, "middle"); |
|
70 |
+ |
private void setTD( Widget widget, String align ) { |
|
71 |
+ |
if ( widget != null ) { |
|
72 |
+ |
TableCellElement element = getTDElement( widget.getElement().getParentElement() ); |
|
73 |
+ |
if ( shouldVerticallyCenter ) { |
|
74 |
+ |
setVAlign( element, "middle" ); |
77 |
75 |
|
} |
78 |
|
- |
element.setAlign(align); |
|
76 |
+ |
element.setAlign( align ); |
79 |
77 |
|
} |
80 |
78 |
|
} |
81 |
79 |
|
|
82 |
|
- |
protected TableElement getTableElement(Element element) { |
|
80 |
+ |
protected TableElement getTableElement( Element element ) { |
83 |
81 |
|
return element.cast(); |
84 |
82 |
|
} |
85 |
83 |
|
|
86 |
|
- |
protected TableCellElement getTDElement(com.google.gwt.dom.client.Element element) { |
|
84 |
+ |
protected TableCellElement getTDElement( com.google.gwt.dom.client.Element element ) { |
87 |
85 |
|
return element.cast(); |
88 |
86 |
|
} |
89 |
87 |
|
|
90 |
|
- |
protected void setBorder(TableElement tableElement, int width) { |
91 |
|
- |
tableElement.setBorder(width); |
|
88 |
+ |
protected void setBorder( TableElement tableElement, int width ) { |
|
89 |
+ |
tableElement.setBorder( width ); |
92 |
90 |
|
} |
93 |
91 |
|
|
94 |
|
- |
protected void setCellPadding(TableElement tableElement, int width) { |
95 |
|
- |
tableElement.setCellPadding(width); |
|
92 |
+ |
protected void setCellPadding( TableElement tableElement, int width ) { |
|
93 |
+ |
tableElement.setCellPadding( width ); |
96 |
94 |
|
} |
97 |
95 |
|
|
98 |
|
- |
protected void setCellSpacing(TableElement tableElement, int width) { |
99 |
|
- |
tableElement.setCellSpacing(width); |
|
96 |
+ |
protected void setCellSpacing( TableElement tableElement, int width ) { |
|
97 |
+ |
tableElement.setCellSpacing( width ); |
100 |
98 |
|
} |
101 |
99 |
|
|
102 |
|
- |
protected void setWidth(TableElement tableElement, String width) { |
103 |
|
- |
tableElement.setWidth(width); |
|
100 |
+ |
protected void setWidth( TableElement tableElement, String width ) { |
|
101 |
+ |
tableElement.setWidth( width ); |
104 |
102 |
|
} |
105 |
103 |
|
|
106 |
|
- |
protected void setVAlign(TableCellElement tableCellElement, String vAlign) { |
107 |
|
- |
tableCellElement.setVAlign(vAlign); |
|
104 |
+ |
protected void setVAlign( TableCellElement tableCellElement, String vAlign ) { |
|
105 |
+ |
tableCellElement.setVAlign( vAlign ); |
108 |
106 |
|
} |
109 |
107 |
|
} |