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