litesoft
@ 948
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 221 222 223 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.widgets.nonpublic; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; import java.util.*; public abstract class AbstractSizeableOneDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel { private WidgetCollection mChildren = new WidgetCollection( this ); @Override public boolean anyChildren() { return (mChildren.size() != 0); } /** * Gets the list of children contained in this panel. * * @return a collection of child widgets */ protected WidgetCollection getChildren() { return mChildren; } // vvvvvvvvvvv HasWidgets /** * Removes all child widgets. */ @Override public void clear() { // Reverse order for SplitPairs while ( anyChildren() ) { remove( getWidgetCount() - 1 ); } } /** * Gets an iterator for the contained widgets. This iterator is required to * implement {@link Iterator#remove()}. */ @Override public Iterator<Widget> iterator() { return mChildren.iterator(); } /** * Adds a child widget. * * @param pWidget the widget to be added * * @throws UnsupportedOperationException if this method is not supported (most * often this means that a specific overload must be called) */ @Override public void add( Widget pWidget ) { insert( pWidget, getWidgetCount() ); } /** * Removes a child widget. * * @param pWidget the widget to be removed * * @return <code>true</code> if the widget was present */ @Override public boolean remove( Widget pWidget ) { // Make sure this panel actually contains the child widget. if ( !mChildren.contains( pWidget ) ) { return false; } // Disown it. disown( pWidget ); return true; } // ^^^^^^^^^^^ HasWidgets /** * Inserts a widget before the specified index. * * @param pWidget the widget to be inserted * @param pBeforeIndex the index before which it will be inserted * * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of * range */ public void insert( Widget pWidget, int pBeforeIndex ) { if ( pWidget != null ) { adopt( pWidget, pBeforeIndex ); } } protected Widget getFirstWidget() { return anyChildren() ? getWidget( 0 ) : null; } protected Widget getLastWidget() { return anyChildren() ? getWidget( getWidgetCount() - 1 ) : null; } // vvvvvvvvvvv IndexedPanel @Override public Widget getWidget( int pIndex ) { return getChildren().get( pIndex ); } @Override public int getWidgetCount() { return getChildren().size(); } @Override public int getWidgetIndex( Widget pChild ) { return getChildren().indexOf( pChild ); } @Override public boolean remove( int pIndex ) { return remove( getWidget( pIndex ) ); } // ^^^^^^^^^^^ IndexedPanel @Override protected final Element adopt( Widget w, Element container ) { throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" ); } /** * Do everything to insert pWidget at the appropriate place * * @param pWidget !null */ protected void adopt( Widget pWidget, int pBeforeIndex ) { if ( aboutToAdopt( pWidget, pBeforeIndex ) ) { LLadopt( pWidget, pBeforeIndex ); justAdopted( pWidget, pBeforeIndex ); } } /** * Do everything to remove pWidget * * @param pWidget !null */ @Override protected Element disown( Widget pWidget ) { int index = mChildren.indexOf( pWidget ); if ( index == -1 ) { throw new IllegalStateException( "Attempt to 'disown' widget (" + pWidget + ") not owned by: " + this ); } if ( aboutToDisown( pWidget, index ) ) { LLdisown( pWidget, index ); justDisowned( pWidget, index ); } return null; // We Don't Care } protected void LLdisown( Widget pWidget, int pIndex ) { Element td = abstractSizeablePanel_disown( pWidget ); // remove Widget from td DOM.removeChild( getContainerElement(), unwrap( td ) ); mChildren.remove( pIndex ); } protected void LLadopt( Widget pWidget, int pBeforeIndex ) { pWidget.removeFromParent(); Element td = DOM.createTD(); abstractSizeablePanel_adopt( pWidget, td ); // put Widget in TD DOM.insertChild( getContainerElement(), wrap( td ), pBeforeIndex ); mChildren.insert( pWidget, pBeforeIndex ); } protected Element abstractSizeablePanel_disown( Widget pWidget ) { return super.disown( pWidget ); } protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer ) { super.adopt( pWidget, pContainer ); } /** * Override point for special behavior of index based addition, before adding. * Could throw an exception! * * @return true if OK to add */ protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex ) { return true; } /** * Override point for special behavior of index based addition. * Should not throw an exception! */ protected void justAdopted( Widget pWidget, int pWidgetIndex ) { } /** * Override point for special behavior of index based removal, before removing. * Could throw an exception! * * @return true if OK to add */ protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex ) { return true; } /** * Override point for special behavior of index based removal. * Should not throw an exception! */ protected void justDisowned( Widget pWidget, int pWidgetIndex ) { } abstract protected Element unwrap( Element pTD ); abstract protected Element wrap( Element pTD ); } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableOneDimensionalPanel.java
Revision | Author | Commited | Message |
---|---|---|---|
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
23 Diff | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |