Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/OldClient/src/org/litesoft/GWT/client/widgets/SizeableSelectorPanel.java

Diff revisions: vs.
  @@ -1,184 +1,184 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets;
3 -
4 - import com.google.gwt.user.client.ui.*;
5 -
6 - public class SizeableSelectorPanel extends SizeableHorizontalSplitPairPanel implements ISizeableTabPanel {
7 - private SizeableVerticalPanel mSelectorPanel = new SizeableVerticalPanel( true ).stretchable();
8 - private SizeableSpacer mSelectorRest = new SizeableSpacer().width( 80 ).stretchable();
9 - protected SizeableDeckPanel mDeckPanel = new SizeableDeckPanel().stretchable();
10 - private static final String STYLE_TAB_SELECTED = "litesoft-VerticalTab-Selected";
11 - private static final String STYLE_TAB_UNSELECTED = "litesoft-VerticalTab-Unselected";
12 - private static final String STYLE_TAB_ERROR = "litesoft-VerticalTab-Error";
13 - private static final String STYLE_TAB_NON_ERROR = "litesoft-VerticalTab-NonError";
14 - private boolean mErrorable;
15 -
16 - public SizeableSelectorPanel() {
17 - this( false );
18 - }
19 -
20 - public SizeableSelectorPanel( boolean pErrorable ) {
21 - mErrorable = pErrorable;
22 - stretchable();
23 - addStyleName( "litesoft-SizeableSelectorPanel" );
24 -
25 - mSelectorPanel.addStyleName( "litesoft-SelectorPanel" );
26 - mSelectorRest.addStyleName( "litesoft-VerticalTabRest" );
27 - mDeckPanel.addStyleName( "litesoft-DeckPanel" );
28 -
29 - mSelectorPanel.add( mSelectorRest );
30 - add( mSelectorPanel );
31 - add( mDeckPanel );
32 - }
33 -
34 - public void insertTab( int pBeforeIndex, String pLabelText, final Widget pWidget ) {
35 - insertTab( pBeforeIndex, pLabelText, false, pWidget );
36 - }
37 -
38 - public void insertTab( int pBeforeIndex, String pLabelText, boolean pAsHTML, final Widget pWidget ) {
39 - VerticalTabLabel tabLabel = new VerticalTabLabel( pLabelText, mErrorable );
40 -
41 - boolean zFirstTab = (mDeckPanel.getWidgetCount() == 0);
42 -
43 - tabLabel.addStyleName( zFirstTab ? STYLE_TAB_SELECTED : STYLE_TAB_UNSELECTED );
44 -
45 - tabLabel.addStyleName( STYLE_TAB_NON_ERROR );
46 -
47 - tabLabel.addClickListener( new ClickListener() {
48 - public void onClick( Widget sender ) {
49 - selectTab( mDeckPanel.getWidgetIndex( pWidget ) );
50 - }
51 - } );
52 -
53 - LLinsertTab( pBeforeIndex, tabLabel, pWidget );
54 - }
55 -
56 - public void removeTab( int pIndex ) {
57 - System.out.println( "Selector removeTab: " + pIndex );
58 - if ( Helper.indexOK( pIndex, this ) ) {
59 - int zSelectedTab = getSelectedTab();
60 - if ( (getTabCount() > 1) && (zSelectedTab == pIndex) ) {
61 - selectTab( (pIndex == 0) ? 1 : pIndex - 1 );
62 - }
63 - if ( !mSelectorPanel.remove( pIndex ) ) {
64 - System.out.println( "*** Unable to remove Selector: " + pIndex );
65 - }
66 - if ( !mDeckPanel.remove( pIndex ) ) {
67 - System.out.println( "*** Unable to remove Deck: " + pIndex );
68 - }
69 - mSelectorPanel.getHeightHelper().contentChangedResizeToParent();
70 - }
71 - }
72 -
73 - public void addTab( String pLabelText, Widget pWidget ) {
74 - insertTab( getTabCount(), pLabelText, pWidget );
75 - }
76 -
77 - public void addTab( String pLabelText, boolean pAsHTML, Widget pWidget ) {
78 - insertTab( getTabCount(), pLabelText, pAsHTML, pWidget );
79 - }
80 -
81 - public int getTabCount() {
82 - return mDeckPanel.getWidgetCount();
83 - }
84 -
85 - public int getSelectedTab() {
86 - return mDeckPanel.getVisibleWidget();
87 - }
88 -
89 - public void selectTab( int pIndex ) {
90 - if ( Helper.indexOK( pIndex, this ) ) {
91 - Widget widget = mSelectorPanel.getWidget( getSelectedTab() );
92 - widget.removeStyleName( STYLE_TAB_SELECTED );
93 - widget.addStyleName( STYLE_TAB_UNSELECTED );
94 - mDeckPanel.showWidget( pIndex );
95 - widget = mSelectorPanel.getWidget( pIndex );
96 - widget.removeStyleName( STYLE_TAB_UNSELECTED );
97 - widget.addStyleName( STYLE_TAB_SELECTED );
98 - }
99 - }
100 -
101 - public void setError( int pIndex, boolean pError ) {
102 - if ( Helper.indexOK( pIndex, this ) ) {
103 - Widget widget = mSelectorPanel.getWidget( pIndex );
104 - if ( pError ) {
105 - widget.removeStyleName( STYLE_TAB_NON_ERROR );
106 - widget.addStyleName( STYLE_TAB_ERROR );
107 - } else {
108 - widget.removeStyleName( STYLE_TAB_ERROR );
109 - widget.addStyleName( STYLE_TAB_NON_ERROR );
110 - }
111 - }
112 - }
113 -
114 - public void setTabText( int pIndex, String pLabelText ) {
115 - setTabText( pIndex, pLabelText, false );
116 - }
117 -
118 - public void setTabText( int pIndex, String pLabelText, boolean pAsHTML ) {
119 - if ( Helper.indexOK( pIndex, this ) ) {
120 - VerticalTabLabel tabLabel = (VerticalTabLabel) mSelectorPanel.getWidget( pIndex );
121 - tabLabel.setText( pLabelText, pAsHTML );
122 - tabLabel.setWidth( "" + mSelectorRest.getOffsetWidth() );
123 - }
124 - }
125 -
126 - public int indexOfTabBodyWith( Widget pWidget ) {
127 - return mDeckPanel.getWidgetIndex( pWidget );
128 - }
129 -
130 - public void moveTab( int pFromIndex, int pToBeforeIndex ) {
131 - if ( Helper.indexOK( pFromIndex, this ) ) {
132 - pToBeforeIndex = Helper.normalizeBeforeIndex( pToBeforeIndex, this );
133 - if ( pToBeforeIndex != pFromIndex ) {
134 - VerticalTabLabel zLabel = (VerticalTabLabel) mSelectorPanel.getWidget( pFromIndex );
135 - Widget zBody = mDeckPanel.getWidget( pFromIndex );
136 - boolean zCurrentlySelected = (pFromIndex == mDeckPanel.getVisibleWidget());
137 - mSelectorPanel.insert( zLabel, pToBeforeIndex );
138 - mDeckPanel.insert( zBody, pToBeforeIndex );
139 - if ( zCurrentlySelected ) {
140 - mDeckPanel.showWidget( mDeckPanel.getWidgetIndex( zBody ) );
141 - }
142 - }
143 - }
144 - }
145 -
146 - private void LLinsertTab( int pBeforeIndex, VerticalTabLabel pTabLabel, Widget pWidget ) {
147 - boolean zCurrentlySelected = false;
148 - int zExistingBodyIndex = mDeckPanel.getWidgetIndex( pWidget );
149 -
150 - if ( zExistingBodyIndex != -1 ) // Body Existing
151 - {
152 - zCurrentlySelected = (zExistingBodyIndex == mDeckPanel.getVisibleWidget());
153 - mSelectorPanel.remove( zExistingBodyIndex );
154 - mDeckPanel.remove( zExistingBodyIndex );
155 - }
156 -
157 - pBeforeIndex = Helper.normalizeBeforeIndex( pBeforeIndex, this );
158 -
159 - mSelectorPanel.insert( pTabLabel, pBeforeIndex );
160 - mDeckPanel.insert( pWidget, pBeforeIndex );
161 -
162 - mSelectorPanel.getHeightHelper().contentChangedResizeToParent();
163 - pTabLabel.setWidth( "" + mSelectorRest.getOffsetWidth() );
164 -
165 - if ( zCurrentlySelected ) {
166 - selectTab( mDeckPanel.getWidgetIndex( pWidget ) );
167 - }
168 - }
169 -
170 - private static class VerticalTabLabel extends SizeableLabel {
171 - private boolean mErrorable;
172 -
173 - public VerticalTabLabel( String pLabelText, boolean pErrorable ) {
174 - super( Helper.augment( pLabelText, pErrorable ), true );
175 - LLstretchableHorizontally();
176 - mErrorable = pErrorable;
177 - addStyleName( "litesoft-VerticalTab" );
178 - }
179 -
180 - public void setText( String pLabelText, boolean pAsHTML ) {
181 - super.setText( Helper.augment( pLabelText, mErrorable ), true );
182 - }
183 - }
184 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets;
3 +
4 + import com.google.gwt.user.client.ui.*;
5 +
6 + public class SizeableSelectorPanel extends SizeableHorizontalSplitPairPanel implements ISizeableTabPanel {
7 + private SizeableVerticalPanel mSelectorPanel = new SizeableVerticalPanel( true ).stretchable();
8 + private SizeableSpacer mSelectorRest = new SizeableSpacer().width( 80 ).stretchable();
9 + protected SizeableDeckPanel mDeckPanel = new SizeableDeckPanel().stretchable();
10 + private static final String STYLE_TAB_SELECTED = "litesoft-VerticalTab-Selected";
11 + private static final String STYLE_TAB_UNSELECTED = "litesoft-VerticalTab-Unselected";
12 + private static final String STYLE_TAB_ERROR = "litesoft-VerticalTab-Error";
13 + private static final String STYLE_TAB_NON_ERROR = "litesoft-VerticalTab-NonError";
14 + private boolean mErrorable;
15 +
16 + public SizeableSelectorPanel() {
17 + this( false );
18 + }
19 +
20 + public SizeableSelectorPanel( boolean pErrorable ) {
21 + mErrorable = pErrorable;
22 + stretchable();
23 + addStyleName( "litesoft-SizeableSelectorPanel" );
24 +
25 + mSelectorPanel.addStyleName( "litesoft-SelectorPanel" );
26 + mSelectorRest.addStyleName( "litesoft-VerticalTabRest" );
27 + mDeckPanel.addStyleName( "litesoft-DeckPanel" );
28 +
29 + mSelectorPanel.add( mSelectorRest );
30 + add( mSelectorPanel );
31 + add( mDeckPanel );
32 + }
33 +
34 + public void insertTab( int pBeforeIndex, String pLabelText, final Widget pWidget ) {
35 + insertTab( pBeforeIndex, pLabelText, false, pWidget );
36 + }
37 +
38 + public void insertTab( int pBeforeIndex, String pLabelText, boolean pAsHTML, final Widget pWidget ) {
39 + VerticalTabLabel tabLabel = new VerticalTabLabel( pLabelText, mErrorable );
40 +
41 + boolean zFirstTab = (mDeckPanel.getWidgetCount() == 0);
42 +
43 + tabLabel.addStyleName( zFirstTab ? STYLE_TAB_SELECTED : STYLE_TAB_UNSELECTED );
44 +
45 + tabLabel.addStyleName( STYLE_TAB_NON_ERROR );
46 +
47 + tabLabel.addClickListener( new ClickListener() {
48 + public void onClick( Widget sender ) {
49 + selectTab( mDeckPanel.getWidgetIndex( pWidget ) );
50 + }
51 + } );
52 +
53 + LLinsertTab( pBeforeIndex, tabLabel, pWidget );
54 + }
55 +
56 + public void removeTab( int pIndex ) {
57 + System.out.println( "Selector removeTab: " + pIndex );
58 + if ( Helper.indexOK( pIndex, this ) ) {
59 + int zSelectedTab = getSelectedTab();
60 + if ( (getTabCount() > 1) && (zSelectedTab == pIndex) ) {
61 + selectTab( (pIndex == 0) ? 1 : pIndex - 1 );
62 + }
63 + if ( !mSelectorPanel.remove( pIndex ) ) {
64 + System.out.println( "*** Unable to remove Selector: " + pIndex );
65 + }
66 + if ( !mDeckPanel.remove( pIndex ) ) {
67 + System.out.println( "*** Unable to remove Deck: " + pIndex );
68 + }
69 + mSelectorPanel.getHeightHelper().contentChangedResizeToParent();
70 + }
71 + }
72 +
73 + public void addTab( String pLabelText, Widget pWidget ) {
74 + insertTab( getTabCount(), pLabelText, pWidget );
75 + }
76 +
77 + public void addTab( String pLabelText, boolean pAsHTML, Widget pWidget ) {
78 + insertTab( getTabCount(), pLabelText, pAsHTML, pWidget );
79 + }
80 +
81 + public int getTabCount() {
82 + return mDeckPanel.getWidgetCount();
83 + }
84 +
85 + public int getSelectedTab() {
86 + return mDeckPanel.getVisibleWidget();
87 + }
88 +
89 + public void selectTab( int pIndex ) {
90 + if ( Helper.indexOK( pIndex, this ) ) {
91 + Widget widget = mSelectorPanel.getWidget( getSelectedTab() );
92 + widget.removeStyleName( STYLE_TAB_SELECTED );
93 + widget.addStyleName( STYLE_TAB_UNSELECTED );
94 + mDeckPanel.showWidget( pIndex );
95 + widget = mSelectorPanel.getWidget( pIndex );
96 + widget.removeStyleName( STYLE_TAB_UNSELECTED );
97 + widget.addStyleName( STYLE_TAB_SELECTED );
98 + }
99 + }
100 +
101 + public void setError( int pIndex, boolean pError ) {
102 + if ( Helper.indexOK( pIndex, this ) ) {
103 + Widget widget = mSelectorPanel.getWidget( pIndex );
104 + if ( pError ) {
105 + widget.removeStyleName( STYLE_TAB_NON_ERROR );
106 + widget.addStyleName( STYLE_TAB_ERROR );
107 + } else {
108 + widget.removeStyleName( STYLE_TAB_ERROR );
109 + widget.addStyleName( STYLE_TAB_NON_ERROR );
110 + }
111 + }
112 + }
113 +
114 + public void setTabText( int pIndex, String pLabelText ) {
115 + setTabText( pIndex, pLabelText, false );
116 + }
117 +
118 + public void setTabText( int pIndex, String pLabelText, boolean pAsHTML ) {
119 + if ( Helper.indexOK( pIndex, this ) ) {
120 + VerticalTabLabel tabLabel = (VerticalTabLabel) mSelectorPanel.getWidget( pIndex );
121 + tabLabel.setText( pLabelText, pAsHTML );
122 + tabLabel.setWidth( "" + mSelectorRest.getOffsetWidth() );
123 + }
124 + }
125 +
126 + public int indexOfTabBodyWith( Widget pWidget ) {
127 + return mDeckPanel.getWidgetIndex( pWidget );
128 + }
129 +
130 + public void moveTab( int pFromIndex, int pToBeforeIndex ) {
131 + if ( Helper.indexOK( pFromIndex, this ) ) {
132 + pToBeforeIndex = Helper.normalizeBeforeIndex( pToBeforeIndex, this );
133 + if ( pToBeforeIndex != pFromIndex ) {
134 + VerticalTabLabel zLabel = (VerticalTabLabel) mSelectorPanel.getWidget( pFromIndex );
135 + Widget zBody = mDeckPanel.getWidget( pFromIndex );
136 + boolean zCurrentlySelected = (pFromIndex == mDeckPanel.getVisibleWidget());
137 + mSelectorPanel.insert( zLabel, pToBeforeIndex );
138 + mDeckPanel.insert( zBody, pToBeforeIndex );
139 + if ( zCurrentlySelected ) {
140 + mDeckPanel.showWidget( mDeckPanel.getWidgetIndex( zBody ) );
141 + }
142 + }
143 + }
144 + }
145 +
146 + private void LLinsertTab( int pBeforeIndex, VerticalTabLabel pTabLabel, Widget pWidget ) {
147 + boolean zCurrentlySelected = false;
148 + int zExistingBodyIndex = mDeckPanel.getWidgetIndex( pWidget );
149 +
150 + if ( zExistingBodyIndex != -1 ) // Body Existing
151 + {
152 + zCurrentlySelected = (zExistingBodyIndex == mDeckPanel.getVisibleWidget());
153 + mSelectorPanel.remove( zExistingBodyIndex );
154 + mDeckPanel.remove( zExistingBodyIndex );
155 + }
156 +
157 + pBeforeIndex = Helper.normalizeBeforeIndex( pBeforeIndex, this );
158 +
159 + mSelectorPanel.insert( pTabLabel, pBeforeIndex );
160 + mDeckPanel.insert( pWidget, pBeforeIndex );
161 +
162 + mSelectorPanel.getHeightHelper().contentChangedResizeToParent();
163 + pTabLabel.setWidth( "" + mSelectorRest.getOffsetWidth() );
164 +
165 + if ( zCurrentlySelected ) {
166 + selectTab( mDeckPanel.getWidgetIndex( pWidget ) );
167 + }
168 + }
169 +
170 + private static class VerticalTabLabel extends SizeableLabel {
171 + private boolean mErrorable;
172 +
173 + public VerticalTabLabel( String pLabelText, boolean pErrorable ) {
174 + super( Helper.augment( pLabelText, pErrorable ), true );
175 + LLstretchableHorizontally();
176 + mErrorable = pErrorable;
177 + addStyleName( "litesoft-VerticalTab" );
178 + }
179 +
180 + public void setText( String pLabelText, boolean pAsHTML ) {
181 + super.setText( Helper.augment( pLabelText, mErrorable ), true );
182 + }
183 + }
184 + }