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 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.taskbar.nonpublic; import org.litesoft.GWT.client.*; import org.litesoft.GWT.client.commands.*; import org.litesoft.GWT.client.taskbar.*; import org.litesoft.GWT.client.widgets.*; import org.litesoft.GWT.client.widgets.nonpublic.*; import org.litesoft.core.delayed.*; import org.litesoft.core.util.*; import com.google.gwt.user.client.ui.*; import com.google.gwt.user.client.*; public class DockablePanelHelper implements OnBrowserEventListener { public static final int COLLAPSABLE_BAR_SIZE = 9; private AbstractSizeableOneDimensionalPanel mDockablePanel; private GwtDomDimensionHelper mDimensionHelper; private TaskbarHelper mTaskbarHelper; private Widget mDecoratedContent; private MoveNEWScommands mContextMenu; private CommonRectangularPoint mPopupRelativeMeetingPoint; private RectangleContainmentStrategy mRectangleContainmentStrategy; private String[] mArrows; private Image mArrow; private int mIndexArrow; private boolean mShowing = true; private Integer mDecoratedContentSize = null; public DockablePanelHelper( AbstractSizeableOneDimensionalPanel pDockablePanel, GwtDomDimensionHelper pDimensionHelper, TaskbarHelper pTaskbarHelper, NEWSposition pPosition, String pSeparatorURL, MoveNEWScommands pContextMenu, AbstractSizeableOneDimensionalPanel pDecoratedContent, AbstractSizeableOneDimensionalPanel pInnerDecoratedContent, AbstractSizeableOneDimensionalPanel pContent, AbstractSizeableOneDimensionalPanel pCollapsableBar, boolean pContentThenCollapsableBar, String pDefaultUrl, CommonRectangularPoint pPopupRelativeMeetingPoint, String[] pArrows, RectangleContainmentStrategy pRectangleContainmentStrategy ) { mDockablePanel = pDockablePanel; mDimensionHelper = pDimensionHelper; (mTaskbarHelper = pTaskbarHelper).setPosition( pPosition ); mDecoratedContent = pDecoratedContent; mTaskbarHelper.addTo( pContent, pSeparatorURL ); mContextMenu = pContextMenu; mPopupRelativeMeetingPoint = pPopupRelativeMeetingPoint; mRectangleContainmentStrategy = pRectangleContainmentStrategy; mArrows = pArrows; mArrow = new Image( pDefaultUrl ); mIndexArrow = mArrows[0].equals( pDefaultUrl ) ? 0 : 1; pInnerDecoratedContent.add( pContent ); // pInnerDecoratedContent.add( new SizeableSpacer( 1 ).stretchable() ); pDecoratedContent.add( new TransparentImage( "TaskBarPreItems" + pPosition ) ); pInnerDecoratedContent.addStyleName( "taskbar_bg" + pPosition ); pDecoratedContent.add( pInnerDecoratedContent ); pDecoratedContent.add( new TransparentImage( "TaskBarPostItems" + pPosition ) ); pCollapsableBar.addStyleName( "collapsablebar_bg" + pPosition ); pCollapsableBar.add( new SizeableSpacer( COLLAPSABLE_BAR_SIZE ).stretchable() ); pCollapsableBar.add( mArrow ); pCollapsableBar.add( new SizeableSpacer( COLLAPSABLE_BAR_SIZE ).stretchable() ); if ( pContentThenCollapsableBar ) { mDockablePanel.add( pDecoratedContent ); mDockablePanel.add( pCollapsableBar ); } else { mDockablePanel.add( pCollapsableBar ); mDockablePanel.add( pDecoratedContent ); } pCollapsableBar.setOnBrowserEventListener( Event.MOUSEEVENTS, this ); } public void updateArrow() { mArrow.setUrl( mArrows[mIndexArrow = (mIndexArrow + 1) & 1] ); } public boolean onBrowserEvent( Event event ) { switch ( DOM.eventGetType( event ) ) { case Event.ONMOUSEUP: UtilsGwt.eventPreventDefaultAndCancelBubble( event ); if ( UtilsGwt.wasAltKeyDownOnCurrentEvent() ) { AbstractContextPopup zPopup = new MoveDockedWidgetContextPopup( mContextMenu ); zPopup.addStyleName( "DockPopupMenu" ); zPopup.showContextPopup( event, mRectangleContainmentStrategy, null, mPopupRelativeMeetingPoint ); } else { setOpen( !isOpen() ); } case Event.ONMOUSEOVER: case Event.ONMOUSEOUT: case Event.ONMOUSEDOWN: case Event.ONMOUSEMOVE: default: break; } return false; } public TaskbarHelper getTaskbarHelper() { return mTaskbarHelper; } public boolean isOpen() { return mShowing; } private class SetOpenDelayedProcess implements DelayedProcess { private boolean mRequestedOpenState; public boolean isRequestedOpenState() { return mRequestedOpenState; } public void setRequestedOpenState( boolean pRequestedOpenState ) { mRequestedOpenState = pRequestedOpenState; } public boolean process() { mPendingSetOpen = false; return LLsetOpen( mRequestedOpenState ); } } private SetOpenDelayedProcess mSetOpenDelayedProcess = new SetOpenDelayedProcess(); private EscalatingProcess mSetOpenEscalatingProcess = null; private boolean mPendingSetOpen = false; private void cancelPendingSetOpen() { if ( mPendingSetOpen && (mSetOpenEscalatingProcess != null) ) { mPendingSetOpen = false; mSetOpenEscalatingProcess.cancel(); } } private void schedulePendingSetOpen( boolean pRequestedOpenState ) { mSetOpenDelayedProcess.setRequestedOpenState( pRequestedOpenState ); if ( !mPendingSetOpen ) { if ( mSetOpenEscalatingProcess == null ) { mSetOpenEscalatingProcess = new EscalatingProcess( mSetOpenDelayedProcess ); } mPendingSetOpen = true; } mSetOpenEscalatingProcess.schedule(); } public void setOpen( boolean pOpen ) { if ( LLsetOpen( pOpen ) ) { cancelPendingSetOpen(); } else { schedulePendingSetOpen( pOpen ); } } private boolean LLsetOpen( boolean pOpen ) { if ( isOpen() != pOpen ) { if ( !isContentReady() ) { return false; } updateArrow(); int zNewSize = COLLAPSABLE_BAR_SIZE + (pOpen ? mDecoratedContentSize : 0); mDecoratedContent.setVisible( mShowing = pOpen ); mDimensionHelper.setDimension( mDockablePanel, zNewSize ); mDockablePanel.relayout(); } return true; } private boolean isContentReady() { if ( mDecoratedContentSize == null ) { int zContentSize = mDimensionHelper.getOffsetDimension( mDecoratedContent.getElement() ); if ( zContentSize < 15 ) { return false; } mDecoratedContentSize = zContentSize; } return true; } } |