Subversion Repository Public Repository

litesoft

Diff Revisions 948 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/nonpublic/AbstractFloaterPanel.java

Diff revisions: vs.
  @@ -1,736 +1,736 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.nonpublic;
3 -
4 - import org.litesoft.GWT.client.*;
5 - import org.litesoft.GWT.client.widgets.*;
6 - import org.litesoft.GWT.client.widgets.nonpublic.*;
7 - import org.litesoft.GWT.client.widgets.nonpublic.external.*;
8 - import org.litesoft.core.util.*;
9 - import org.litesoft.logger.*;
10 - import org.litesoft.logger.nonpublic.*;
11 -
12 - import com.google.gwt.user.client.*;
13 - import com.google.gwt.user.client.ui.*;
14 -
15 - import java.util.*;
16 -
17 - public abstract class AbstractFloaterPanel extends AbstractSizeablePanel implements UiPositionAndSizeAdjustable,
18 - IndexedPanel,
19 - SizeableSingleWidgetContainer {
20 - public static final int BORDER_T_H = 7;
21 - public static final int BORDER_B_H = 7;
22 -
23 - public static final int BORDER_L_W = 7;
24 - public static final int BORDER_R_W = 7;
25 -
26 - protected static final Logger LOGGER = LoggerFactory.getLogger( AbstractFloaterPanel.class );
27 -
28 - protected AbstractLogger mLogger = LOGGER.trace;
29 -
30 - protected String mBaseCSSclassname;
31 - protected String mForm;
32 - private WidgetCollection mChildren = new WidgetCollection( this );
33 - protected TitleBarPanel mTitleBarPanel;
34 - protected Controller mDragController;
35 - private ContentPanel mContent;
36 - private Element mTR_Pining, mTR_RightAchoring, mTR_BottomAchoring;
37 -
38 - protected AbstractFloaterPanel( String pForm ) {
39 - initializeElements( getHelper().create_OeTable_SeIeTBody(), null );
40 -
41 - /*
42 - * Bug 2454: vz's lose their edge! Force overflow:visible so that outer
43 - * table will not clip its children if wider than its parent container's
44 - * width (FFox, Opera). Currently commented out b/c it breaks pickled
45 - * sizing in Firefox.
46 - */
47 - // CommonElementHelper.setOverflowVisible( getHelper().getStyleElement() );
48 -
49 - addStyleName( mBaseCSSclassname = "litesoft-NoSizeAffectingCSS-" + (mForm = pForm) );
50 -
51 - mTitleBarPanel = new TitleBarPanel( "litesoft-" + pForm + "TitleBar" );
52 - mContent = new ContentPanel( pForm );
53 -
54 - LLstretchable();
55 - }
56 -
57 - protected DragGesture createTitleBarDragGesture( UiPositionable pUiPositionable ) {
58 - return new DragPositionableController( pUiPositionable );
59 - }
60 -
61 - private static class ContentPanel extends ClippingSimplePanel {
62 - public ContentPanel( String pForm ) {
63 - super( "litesoft-NoSizeAffectingCSS-" + pForm + "ContentPane" );
64 - }
65 - }
66 -
67 - @Override
68 - public void relayout() {
69 - mLogger.log( "relayout" );
70 - mWidthHandler.relayout();
71 - mHeightHandler.relayout();
72 - }
73 -
74 - public boolean isSizingPending() {
75 - return mWidthHandler.isPendingAny() || mHeightHandler.isPendingAny();
76 - }
77 -
78 - public Element getTR_Pinning() {
79 - return mTR_Pining;
80 - }
81 -
82 - public Element getTR_RightAnchoring() {
83 - return mTR_RightAchoring;
84 - }
85 -
86 - public Element getTR_BottomAnchoring() {
87 - return mTR_BottomAchoring;
88 - }
89 -
90 - public int getTitleBarHeight() {
91 - return mTitleBarPanel.getOffsetHeight();
92 - }
93 -
94 - @Override
95 - public String getTitle() {
96 - FloaterTitleBar zTitleBar = getTitleBar();
97 - return (zTitleBar != null) ? zTitleBar.getTitleBarTitle() : null;
98 - }
99 - // public String getTitle()
100 - // {
101 - // FloaterPanelTitleBar zTitleBar = getTitleBar();
102 - // return (zTitleBar != null) ? zTitleBar.getTitleBarTitle() : null;
103 - // }
104 -
105 - @Override
106 - public void setTitle( String title ) {
107 - FloaterTitleBar zTitleBar = getTitleBar();
108 - if ( zTitleBar == null ) {
109 - setTitleBar( zTitleBar = new OurTextOnlyTitleBar() );
110 - }
111 - zTitleBar.setTitleBarTitle( title );
112 - }
113 - // public void setTitle( String title )
114 - // {
115 - // FloaterPanelTitleBar zTitleBar = getTitleBar();
116 - // if ( zTitleBar == null )
117 - // {
118 - // setTitleBar( zTitleBar = new OurTextOnlyTitleBar() );
119 - // }
120 - // zTitleBar.setTitleBarTitle( title );
121 - // }
122 -
123 - @Override
124 - public void setPosition( int pLeft, int pTop ) {
125 - setPosLeft( pLeft );
126 - setPosTop( pTop );
127 - }
128 -
129 - public SizeWidthHeight getContentSize() {
130 - Widget w = getWidget();
131 - return (w != null) ? new SizeWidthHeight( w.getOffsetWidth(), w.getOffsetHeight() ) : null;
132 - }
133 -
134 - /**
135 - * Gets the panel's child widget.
136 - *
137 - * @return the child widget, or <code>null</code> if none is present
138 - */
139 - @Override
140 - public Widget getWidget() {
141 - return mContent.getWidget();
142 - }
143 -
144 - /**
145 - * Sets this panel's widget. Any existing child widget will be removed.
146 - */
147 - @Override
148 - public void setWidget( Widget pWidget ) {
149 - mContent.setWidget( pWidget );
150 - reinitializeSize();
151 - }
152 -
153 - public FloaterTitleBar getTitleBar() {
154 - return (FloaterTitleBar) mTitleBarPanel.getWidget();
155 - }
156 -
157 - public void setTitleBar( FloaterTitleBar pWidget ) {
158 - mTitleBarPanel.setWidget( pWidget );
159 - reinitializeSize();
160 - }
161 -
162 - public void initializeSize() {
163 - initializeWidth();
164 - initializeHeight();
165 - }
166 -
167 - protected void reinitializeSize() {
168 - mWidthHandler.reinitializeDimension();
169 - mHeightHandler.reinitializeDimension();
170 - }
171 -
172 - private boolean mSizingWorking = false;
173 -
174 - @Override
175 - public void setSizingWorking() {
176 - mSizingWorking = true;
177 - setVisible( true );
178 - }
179 -
180 - @Override
181 - public boolean isSizingWorking() {
182 - return mSizingWorking;
183 - }
184 -
185 - private int getPrefferredWidth( SizeableSimplePanel pOurWrapper ) {
186 - if ( pOurWrapper != null ) {
187 - Widget widget = pOurWrapper.getWidget();
188 - if ( widget != null ) {
189 - return widget.getOffsetWidth();
190 - }
191 - }
192 - return 0;
193 - }
194 -
195 - private int getPrefferredWidth( ContentPanel pOurWrapper ) {
196 - if ( pOurWrapper != null ) {
197 - Widget widget = pOurWrapper.getWidget();
198 - if ( widget != null ) {
199 - return widget.getOffsetWidth();
200 - }
201 - }
202 - return 0;
203 - }
204 -
205 - private int getPrefferredHeight( SizeableSimplePanel pOurWrapper ) {
206 - if ( pOurWrapper != null ) {
207 - Widget widget = pOurWrapper.getWidget();
208 - if ( widget != null ) {
209 - return widget.getOffsetHeight();
210 - }
211 - }
212 - return 0;
213 - }
214 -
215 - private int getPrefferredHeight( ContentPanel pOurWrapper ) {
216 - if ( pOurWrapper != null ) {
217 - Widget widget = pOurWrapper.getWidget();
218 - if ( widget != null ) {
219 - return widget.getOffsetHeight();
220 - }
221 - }
222 - return 0;
223 - }
224 -
225 - @Override
226 - public boolean setPrefferredWidth() {
227 - int w1 = getPrefferredWidth( mTitleBarPanel );
228 - int w2 = getPrefferredWidth( mContent );
229 - return (w1 > 0) && (w2 > 0) && setWidths( Math.max( w1, w2 ) );
230 - }
231 -
232 - @Override
233 - public boolean adjustWidthBy( int pDelta ) {
234 - // System.out.println( "adjustSizeBy(" + pDelta + ")" );
235 - if ( pDelta != 0 ) {
236 - int curWidth = mContent.getOffsetWidth();
237 - int newWidthContent = curWidth + pDelta;
238 - if ( (curWidth <= 0) || ((pDelta < 0) && (newWidthContent < MinContentWidth)) ) {
239 - return false;
240 - }
241 - setWidths( newWidthContent );
242 - }
243 - return true;
244 - }
245 -
246 - public void initializeWidth() {
247 - mWidthHandler.initializeDimension();
248 - }
249 -
250 - @Override
251 - public void setWidth( String pWidth ) {
252 - mWidthHandler.setDimension( pWidth );
253 - }
254 -
255 - protected int getMaxPotentialWidth() {
256 - return -1;
257 - }
258 -
259 - private FloaterPositionHandler createWidthPositionHandler() {
260 - return new FloaterPositionHandler() {
261 - @Override
262 - public int getPos() {
263 - return getPosLeft();
264 - }
265 -
266 - @Override
267 - public void setPos( int pNewPos ) {
268 - setPosLeft( pNewPos );
269 - }
270 -
271 - @Override
272 - public int getMaxPotentialSize() {
273 - return getMaxPotentialWidth();
274 - }
275 - };
276 - }
277 -
278 - protected DeferableFloaterDimensionHandler mWidthHandler = //
279 - new DeferableFloaterDimensionHandler( this, mLogger, getWidthHelper(), createWidthPositionHandler() );
280 -
281 - @Override
282 - public boolean setPrefferredHeight() {
283 - return setTitleBarPrefferredHeight() & setContentPrefferredHeight();
284 - }
285 -
286 - @Override
287 - public boolean adjustHeightBy( int pDelta ) {
288 - if ( pDelta != 0 ) {
289 - int curHeight = mContent.getOffsetHeight();
290 - int newHeightContent = curHeight + pDelta;
291 - if ( (curHeight <= 0) || ((pDelta < 0) && (newHeightContent < MinContentHeight)) ) {
292 - return false;
293 - }
294 - setContentHeight( newHeightContent );
295 - }
296 - return true;
297 - }
298 -
299 - public void initializeHeight() {
300 - mHeightHandler.initializeDimension();
301 - }
302 -
303 - @Override
304 - public void setHeight( String pHeight ) {
305 - mHeightHandler.setDimension( pHeight );
306 - }
307 -
308 - protected int getMaxPotentialHeight() {
309 - return -1;
310 - }
311 -
312 - private FloaterPositionHandler createHeightPositionHandler() {
313 - return new FloaterPositionHandler() {
314 - @Override
315 - public int getPos() {
316 - return getPosTop();
317 - }
318 -
319 - @Override
320 - public void setPos( int pNewPos ) {
321 - setPosTop( pNewPos );
322 - }
323 -
324 - @Override
325 - public int getMaxPotentialSize() {
326 - return getMaxPotentialHeight();
327 - }
328 - };
329 - }
330 -
331 - protected DeferableFloaterDimensionHandler mHeightHandler = //
332 - new DeferableFloaterDimensionHandler( this, mLogger, getHeightHelper(), createHeightPositionHandler() );
333 -
334 - private boolean setTitleBarPrefferredHeight() {
335 - int height = getPrefferredHeight( mTitleBarPanel );
336 - if ( height > 0 ) {
337 - setHeightOn( mTitleBarPanel, height, mTsLeftTitleBar, mTsRightTitleBar );
338 - return true;
339 - }
340 - return false;
341 - }
342 -
343 - private boolean setContentPrefferredHeight() {
344 - int height = getPrefferredHeight( mContent );
345 - if ( height > 0 ) {
346 - setContentHeight( height );
347 - return true;
348 - }
349 - return false;
350 - }
351 -
352 - private void setContentHeight( int pHeight ) {
353 - mHeightHandler.LLsetDimension( mTitleBarPanel.getOffsetHeight() + BORDER_TB_H + setHeightOn( mContent, pHeight, mTsLeftContent, mTsRightContent ) );
354 - }
355 -
356 - private int setHeightOn( Widget pWidget, int pHeight, Widget pLeftBorder, Widget pRightBorder ) {
357 - int zBorderHeight = pHeight - CplusSize;
358 - if ( zBorderHeight < 1 ) {
359 - pHeight = CplusSize + (zBorderHeight = 1); // MinContentHeight
360 - }
361 - pWidget.setHeight( "" + pHeight );
362 - pLeftBorder.setHeight( "" + zBorderHeight );
363 - pRightBorder.setHeight( "" + zBorderHeight );
364 - return pHeight;
365 - }
366 -
367 - @Override
368 - protected void distributeToChildrenChangedWidth() {
369 - setWidths( getOurInnerSize( getWidthHelper() ) - BORDER_LR_W );
370 - }
371 -
372 - @Override
373 - protected void distributeToChildrenChangedHeight() {
374 - int size = getOurInnerSize( getHeightHelper() ) - BORDER_TB_H;
375 - setContentHeight( size - mTitleBarPanel.getOffsetHeight() );
376 - }
377 -
378 - private int getOurInnerSize( ISizeableDimensionHelper pDimensionHelper ) {
379 - return pDimensionHelper.getDimension() - pDimensionHelper.getDecorationSize();
380 - }
381 -
382 - private boolean setWidths( int pDesiredWidth ) {
383 - int zBorderWidth = pDesiredWidth - CplusSize2;
384 - if ( zBorderWidth < 1 ) {
385 - pDesiredWidth = CplusSize + (zBorderWidth = 1); // MinContentWidth
386 - }
387 -
388 - mTsTop.setWidth( "" + zBorderWidth );
389 - mTsBottom.setWidth( "" + zBorderWidth );
390 - mTitleBarPanel.setWidth( "" + pDesiredWidth );
391 - mContent.setWidth( "" + pDesiredWidth );
392 - mWidthHandler.LLsetDimension( pDesiredWidth + BORDER_LR_W );
393 - return true;
394 - }
395 -
396 - /**
397 - * Adds a widget to this panel.
398 - *
399 - * @param w the child widget to be added
400 - */
401 - @Override
402 - public void add( Widget w ) {
403 - throw new IllegalStateException( "Use setWidget()" );
404 - }
405 -
406 - @Override
407 - public boolean remove( Widget w ) {
408 - throw new IllegalStateException( "Use setWidget()" );
409 - }
410 -
411 - @Override
412 - public boolean anyChildren() {
413 - return (mChildren.size() != 0);
414 - }
415 -
416 - @Override
417 - public Iterator<Widget> iterator() {
418 - return mChildren.iterator();
419 - }
420 -
421 - @Override
422 - public Widget getWidget( int index ) {
423 - return mChildren.get( index );
424 - }
425 -
426 - @Override
427 - public int getWidgetCount() {
428 - return mChildren.size();
429 - }
430 -
431 - @Override
432 - public int getWidgetIndex( Widget child ) {
433 - return mChildren.indexOf( child );
434 - }
435 -
436 - @Override
437 - public boolean remove( int index ) {
438 - return false;
439 - }
440 -
441 - private static class OurTextOnlyTitleBar extends FloaterTitleBar {
442 - private SizeableLabel mLabel = new SizeableLabel( "", false ).stretchableHorizontally();
443 -
444 - public OurTextOnlyTitleBar() {
445 - add( mLabel );
446 - add( new SizeableSpacer().width( 10 ).stretchableHorizontally() );
447 - }
448 -
449 - @Override
450 - public String getTitleBarTitle() {
451 - return mLabel.getText();
452 - }
453 -
454 - @Override
455 - public void setTitleBarTitle( String pTitle ) {
456 - mLabel.setText( pTitle );
457 - }
458 - }
459 -
460 - private abstract static class AbstractResizer extends AbstractDragger {
461 - private static final String MINIMUM_SIZE_REACHED = "Resizing Terminated, Minimum Size Reached";
462 -
463 - private final UiPositionAndSizeAdjustable mTarget;
464 -
465 - public AbstractResizer( UiPositionAndSizeAdjustable pTarget ) {
466 - mTarget = pTarget;
467 - }
468 -
469 - public UiPositionAndSizeAdjustable getTarget() {
470 - return mTarget;
471 - }
472 -
473 - protected boolean adjustPositionBy( int pDeltaX, int pDeltaY ) {
474 - // System.out.println( "adjustPositionBy(" + pDeltaX + "," + pDeltaY + ")" );
475 - getTarget().setPosition( getTarget().getPosLeft() + pDeltaX, getTarget().getPosTop() + pDeltaY );
476 - return true;
477 - }
478 -
479 - protected boolean adjustSizeBy( int pDeltaX, int pDeltaY ) {
480 - // System.out.println( "adjustSizeBy(" + pDeltaX + "," + pDeltaY + ")" );
481 - return getTarget().adjustWidthBy( pDeltaX ) && getTarget().adjustHeightBy( pDeltaY );
482 - }
483 -
484 - @Override
485 - public void start( MouseEvent e ) {
486 - super.start( e );
487 - StatusBar.remove( MINIMUM_SIZE_REACHED );
488 - }
489 -
490 - @Override
491 - protected final boolean dragBy( int pDeltaX, int pDeltaY ) {
492 - boolean success = dragByInner( pDeltaX, pDeltaY );
493 - if ( !success ) {
494 - StatusBar.add( MINIMUM_SIZE_REACHED );
495 - }
496 - return success;
497 - }
498 -
499 - abstract protected boolean dragByInner( int pDeltaX, int pDeltaY );
500 - }
501 -
502 - private static class ResizerTopLeft extends AbstractResizer {
503 - public ResizerTopLeft( UiPositionAndSizeAdjustable pTarget ) {
504 - super( pTarget );
505 - }
506 -
507 - @Override
508 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
509 - return adjustSizeBy( -pDeltaX, -pDeltaY ) && adjustPositionBy( pDeltaX, pDeltaY );
510 - }
511 - }
512 -
513 - private static class ResizerTopRight extends AbstractResizer {
514 - public ResizerTopRight( UiPositionAndSizeAdjustable pTarget ) {
515 - super( pTarget );
516 - }
517 -
518 - @Override
519 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
520 - return adjustSizeBy( pDeltaX, -pDeltaY ) && adjustPositionBy( 0, pDeltaY );
521 - }
522 - }
523 -
524 - private static class ResizerBottomRight extends AbstractResizer {
525 - public ResizerBottomRight( UiPositionAndSizeAdjustable pTarget ) {
526 - super( pTarget );
527 - }
528 -
529 - @Override
530 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
531 - return adjustSizeBy( pDeltaX, pDeltaY );
532 - }
533 - }
534 -
535 - private static class ResizerBottomLeft extends AbstractResizer {
536 - public ResizerBottomLeft( UiPositionAndSizeAdjustable pTarget ) {
537 - super( pTarget );
538 - }
539 -
540 - @Override
541 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
542 - return adjustSizeBy( -pDeltaX, pDeltaY ) && adjustPositionBy( pDeltaX, 0 );
543 - }
544 - }
545 -
546 - private static class ResizerTop extends AbstractResizer {
547 - public ResizerTop( UiPositionAndSizeAdjustable pTarget ) {
548 - super( pTarget );
549 - }
550 -
551 - @Override
552 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
553 - return adjustSizeBy( 0, -pDeltaY ) && adjustPositionBy( 0, pDeltaY );
554 - }
555 - }
556 -
557 - private static class ResizerBottom extends AbstractResizer {
558 - public ResizerBottom( UiPositionAndSizeAdjustable pTarget ) {
559 - super( pTarget );
560 - }
561 -
562 - @Override
563 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
564 - return adjustSizeBy( 0, pDeltaY );
565 - }
566 - }
567 -
568 - private static class ResizerRight extends AbstractResizer {
569 - public ResizerRight( UiPositionAndSizeAdjustable pTarget ) {
570 - super( pTarget );
571 - }
572 -
573 - @Override
574 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
575 - return adjustSizeBy( pDeltaX, 0 );
576 - }
577 - }
578 -
579 - private static class ResizerLeft extends AbstractResizer {
580 - public ResizerLeft( UiPositionAndSizeAdjustable pTarget ) {
581 - super( pTarget );
582 - }
583 -
584 - @Override
585 - protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
586 - return adjustSizeBy( -pDeltaX, 0 ) && adjustPositionBy( pDeltaX, 0 );
587 - }
588 - }
589 -
590 - private Element LLaddTD( Element pTR, Widget pWidget ) {
591 - mChildren.add( pWidget );
592 -
593 - Element zTD = DOM.createTD();
594 - DOM.appendChild( pTR, zTD );
595 -
596 - adopt( pWidget, zTD );
597 -
598 - return zTD;
599 - }
600 -
601 - private Element addTDWithColSpan3( Element pTR, Widget pWidget ) {
602 - Element zTD = LLaddTD( pTR, pWidget );
603 -
604 - DOM.setElementPropertyInt( zTD, "colSpan", 3 );
605 -
606 - return zTD;
607 - }
608 -
609 - private void addTD( Element pTR, Widget pWidget ) {
610 - Element zTD = addTDWithColSpan3( pTR, pWidget );
611 - DOM.setElementPropertyInt( zTD, "rowSpan", 2 );
612 - }
613 -
614 - private Widget addTD( Element pTR, String pBorderID, String pClassPlus, int pWidth, int pHeight, DragGesture pResizer ) {
615 - Border border = new Border( "litesoft-" + mForm + "Border" + pBorderID + pClassPlus );
616 - border.addController( createBorderDragController( pResizer ) );
617 - border.addController( PreventSelectionController.getInstance() );
618 -
619 - LLaddTD( pTR, border );
620 -
621 - if ( pWidth > 0 ) {
622 - border.setWidth( "" + pWidth );
623 - }
624 - if ( pHeight > 0 ) {
625 - border.setHeight( "" + pHeight );
626 - }
627 - return border;
628 - }
629 -
630 - private void addTDCorner( Element pTR, String pBorderID, int pWidth, int pHeight, DragGesture pResizer ) {
631 - addTD( pTR, pBorderID, "", pWidth, pHeight, pResizer );
632 - }
633 -
634 - private Widget addTDHorizontal( Element pTR, String pBorderID, int pHeight, DragGesture pResizer ) {
635 - return addTD( pTR, pBorderID, "", 0, pHeight, pResizer );
636 - }
637 -
638 - private Widget addTDVertical( Element pTR, String pBorderID, String pClassPlus, int pWidth, DragGesture pResizer ) {
639 - return addTD( pTR, pBorderID, pClassPlus, pWidth, 0, pResizer );
640 - }
641 -
642 - abstract protected DragController createBorderDragController( DragGesture pResizer );
643 -
644 - protected void finishContainerTable( UiPositionAndSizeAdjustable pTarget ) {
645 - Element zTR, tBody = getContainerElement();
646 -
647 - DragGesture resizerTopLeft = new ResizerTopLeft( pTarget );
648 - DragGesture resizerTop = new ResizerTop( pTarget );
649 - DragGesture resizerTopRight = new ResizerTopRight( pTarget );
650 - DragGesture resizerRight = new ResizerRight( pTarget );
651 - DragGesture resizerBottomRight = new ResizerBottomRight( pTarget );
652 - DragGesture resizerBottom = new ResizerBottom( pTarget );
653 - DragGesture resizerBottomLeft = new ResizerBottomLeft( pTarget );
654 - DragGesture resizerLeft = new ResizerLeft( pTarget );
655 -
656 - DOM.appendChild( tBody, mTR_Pining = DOM.createTR() );
657 - addTDCorner( mTR_Pining, "CornerTopLeft", BORDER_L_W, BORDER_T_H, resizerTopLeft );
658 - addTDCorner( mTR_Pining, "CornerTopLeftUp", CplusSize, BORDER_T_H, resizerTopLeft );
659 - mTsTop = addTDHorizontal( mTR_Pining, "StraightTop", BORDER_T_H, resizerTop );
660 - addTDCorner( mTR_Pining, "CornerTopRightUp", CplusSize, BORDER_T_H, resizerTopRight );
661 - addTDCorner( mTR_Pining, "CornerTopRight", BORDER_R_W, BORDER_T_H, resizerTopRight );
662 -
663 - DOM.appendChild( tBody, zTR = DOM.createTR() );
664 - addTDCorner( zTR, "CornerTopLeftDown", BORDER_L_W, CplusSize, resizerTopLeft );
665 - addTD( zTR, mTitleBarPanel );
666 - addTDCorner( zTR, "CornerTopRightDown", BORDER_R_W, CplusSize, resizerTopRight );
667 -
668 - DOM.appendChild( tBody, zTR = DOM.createTR() );
669 - mTsLeftTitleBar = addTDVertical( zTR, "StraightLeft", CPT, BORDER_L_W, resizerLeft );
670 - mTsRightTitleBar = addTDVertical( zTR, "StraightRight", CPT, BORDER_R_W, resizerRight );
671 -
672 - DOM.appendChild( tBody, zTR = DOM.createTR() );
673 - mTsLeftContent = addTDVertical( zTR, "StraightLeft", CPC, BORDER_L_W, resizerLeft );
674 - addTD( zTR, mContent );
675 - mTsRightContent = addTDVertical( zTR, "StraightRight", CPC, BORDER_R_W, resizerRight );
676 -
677 - DOM.appendChild( tBody, mTR_RightAchoring = zTR = DOM.createTR() );
678 - addTDCorner( zTR, "CornerBottomLeftUp", BORDER_L_W, CplusSize, resizerBottomLeft );
679 - addTDCorner( zTR, "CornerBottomRightUp", BORDER_R_W, CplusSize, resizerBottomRight );
680 -
681 - DOM.appendChild( tBody, mTR_BottomAchoring = DOM.createTR() );
682 - addTDCorner( mTR_BottomAchoring, "CornerBottomLeft", BORDER_L_W, BORDER_B_H, resizerBottomLeft );
683 - addTDCorner( mTR_BottomAchoring, "CornerBottomLeftDown", CplusSize, BORDER_B_H, resizerBottomLeft );
684 - mTsBottom = addTDHorizontal( mTR_BottomAchoring, "StraightBottom", BORDER_B_H, resizerBottom );
685 - addTDCorner( mTR_BottomAchoring, "CornerBottomRightDown", CplusSize, BORDER_B_H, resizerBottomRight );
686 - addTDCorner( mTR_BottomAchoring, "CornerBottomRight", BORDER_R_W, BORDER_B_H, resizerBottomRight );
687 - }
688 -
689 - private static final String CPT = "Caption";
690 - private static final String CPC = "Content";
691 -
692 - private static final int BORDER_TB_H = BORDER_T_H + BORDER_B_H;
693 -
694 - private static final int BORDER_LR_W = BORDER_L_W + BORDER_R_W;
695 -
696 - private static final int CplusSize = 5;
697 -
698 - private static final int CplusSize2 = CplusSize + CplusSize;
699 -
700 - private static final int MinContentWidth = CplusSize2 + 1;
701 - private static final int MinContentHeight = CplusSize + 1;
702 -
703 - private Widget mTsTop, mTsBottom, mTsLeftTitleBar, mTsRightTitleBar, mTsLeftContent, mTsRightContent;
704 -
705 - private static class Border extends CWrapper {
706 - public Border( String pStyle ) {
707 - super( new SimplePanel() );
708 - SimplePanel panel = (SimplePanel) getWidget();
709 - panel.setWidget( new Spacer( 0 ) );
710 - setStyleName( pStyle );
711 - }
712 - }
713 -
714 - protected boolean allowDragging() {
715 - return true;
716 - }
717 -
718 - protected DragController createDragController( DragGesture pDragGesture ) {
719 - return new DragController( new MousePerformanceFilter( new MouseDragHandler( pDragGesture ) ) ) {
720 - @Override
721 - public void onBrowserEvent( Widget widget, Event event ) {
722 - if ( allowDragging() ) {
723 - super.onBrowserEvent( widget, event );
724 - }
725 - }
726 - };
727 - }
728 -
729 - protected DragGesture createThresholdFilter( DragGesture pDragGesture ) {
730 - /*
731 - * using a 1px drag tolerance prevents drag style from being applied
732 - * (and scrollbar flickering in FF) when a window is brought to front
733 - */
734 - return new DragThresholdFilter( 1, pDragGesture );
735 - }
736 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.nonpublic;
3 +
4 + import org.litesoft.GWT.client.*;
5 + import org.litesoft.GWT.client.widgets.*;
6 + import org.litesoft.GWT.client.widgets.nonpublic.*;
7 + import org.litesoft.GWT.client.widgets.nonpublic.external.*;
8 + import org.litesoft.core.util.*;
9 + import org.litesoft.logger.*;
10 + import org.litesoft.logger.nonpublic.*;
11 +
12 + import com.google.gwt.user.client.*;
13 + import com.google.gwt.user.client.ui.*;
14 +
15 + import java.util.*;
16 +
17 + public abstract class AbstractFloaterPanel extends AbstractSizeablePanel implements UiPositionAndSizeAdjustable,
18 + IndexedPanel,
19 + SizeableSingleWidgetContainer {
20 + public static final int BORDER_T_H = 7;
21 + public static final int BORDER_B_H = 7;
22 +
23 + public static final int BORDER_L_W = 7;
24 + public static final int BORDER_R_W = 7;
25 +
26 + protected static final Logger LOGGER = LoggerFactory.getLogger( AbstractFloaterPanel.class );
27 +
28 + protected AbstractLogger mLogger = LOGGER.trace;
29 +
30 + protected String mBaseCSSclassname;
31 + protected String mForm;
32 + private WidgetCollection mChildren = new WidgetCollection( this );
33 + protected TitleBarPanel mTitleBarPanel;
34 + protected Controller mDragController;
35 + private ContentPanel mContent;
36 + private Element mTR_Pining, mTR_RightAchoring, mTR_BottomAchoring;
37 +
38 + protected AbstractFloaterPanel( String pForm ) {
39 + initializeElements( getHelper().create_OeTable_SeIeTBody(), null );
40 +
41 + /*
42 + * Bug 2454: vz's lose their edge! Force overflow:visible so that outer
43 + * table will not clip its children if wider than its parent container's
44 + * width (FFox, Opera). Currently commented out b/c it breaks pickled
45 + * sizing in Firefox.
46 + */
47 + // CommonElementHelper.setOverflowVisible( getHelper().getStyleElement() );
48 +
49 + addStyleName( mBaseCSSclassname = "litesoft-NoSizeAffectingCSS-" + (mForm = pForm) );
50 +
51 + mTitleBarPanel = new TitleBarPanel( "litesoft-" + pForm + "TitleBar" );
52 + mContent = new ContentPanel( pForm );
53 +
54 + LLstretchable();
55 + }
56 +
57 + protected DragGesture createTitleBarDragGesture( UiPositionable pUiPositionable ) {
58 + return new DragPositionableController( pUiPositionable );
59 + }
60 +
61 + private static class ContentPanel extends ClippingSimplePanel {
62 + public ContentPanel( String pForm ) {
63 + super( "litesoft-NoSizeAffectingCSS-" + pForm + "ContentPane" );
64 + }
65 + }
66 +
67 + @Override
68 + public void relayout() {
69 + mLogger.log( "relayout" );
70 + mWidthHandler.relayout();
71 + mHeightHandler.relayout();
72 + }
73 +
74 + public boolean isSizingPending() {
75 + return mWidthHandler.isPendingAny() || mHeightHandler.isPendingAny();
76 + }
77 +
78 + public Element getTR_Pinning() {
79 + return mTR_Pining;
80 + }
81 +
82 + public Element getTR_RightAnchoring() {
83 + return mTR_RightAchoring;
84 + }
85 +
86 + public Element getTR_BottomAnchoring() {
87 + return mTR_BottomAchoring;
88 + }
89 +
90 + public int getTitleBarHeight() {
91 + return mTitleBarPanel.getOffsetHeight();
92 + }
93 +
94 + @Override
95 + public String getTitle() {
96 + FloaterTitleBar zTitleBar = getTitleBar();
97 + return (zTitleBar != null) ? zTitleBar.getTitleBarTitle() : null;
98 + }
99 + // public String getTitle()
100 + // {
101 + // FloaterPanelTitleBar zTitleBar = getTitleBar();
102 + // return (zTitleBar != null) ? zTitleBar.getTitleBarTitle() : null;
103 + // }
104 +
105 + @Override
106 + public void setTitle( String title ) {
107 + FloaterTitleBar zTitleBar = getTitleBar();
108 + if ( zTitleBar == null ) {
109 + setTitleBar( zTitleBar = new OurTextOnlyTitleBar() );
110 + }
111 + zTitleBar.setTitleBarTitle( title );
112 + }
113 + // public void setTitle( String title )
114 + // {
115 + // FloaterPanelTitleBar zTitleBar = getTitleBar();
116 + // if ( zTitleBar == null )
117 + // {
118 + // setTitleBar( zTitleBar = new OurTextOnlyTitleBar() );
119 + // }
120 + // zTitleBar.setTitleBarTitle( title );
121 + // }
122 +
123 + @Override
124 + public void setPosition( int pLeft, int pTop ) {
125 + setPosLeft( pLeft );
126 + setPosTop( pTop );
127 + }
128 +
129 + public SizeWidthHeight getContentSize() {
130 + Widget w = getWidget();
131 + return (w != null) ? new SizeWidthHeight( w.getOffsetWidth(), w.getOffsetHeight() ) : null;
132 + }
133 +
134 + /**
135 + * Gets the panel's child widget.
136 + *
137 + * @return the child widget, or <code>null</code> if none is present
138 + */
139 + @Override
140 + public Widget getWidget() {
141 + return mContent.getWidget();
142 + }
143 +
144 + /**
145 + * Sets this panel's widget. Any existing child widget will be removed.
146 + */
147 + @Override
148 + public void setWidget( Widget pWidget ) {
149 + mContent.setWidget( pWidget );
150 + reinitializeSize();
151 + }
152 +
153 + public FloaterTitleBar getTitleBar() {
154 + return (FloaterTitleBar) mTitleBarPanel.getWidget();
155 + }
156 +
157 + public void setTitleBar( FloaterTitleBar pWidget ) {
158 + mTitleBarPanel.setWidget( pWidget );
159 + reinitializeSize();
160 + }
161 +
162 + public void initializeSize() {
163 + initializeWidth();
164 + initializeHeight();
165 + }
166 +
167 + protected void reinitializeSize() {
168 + mWidthHandler.reinitializeDimension();
169 + mHeightHandler.reinitializeDimension();
170 + }
171 +
172 + private boolean mSizingWorking = false;
173 +
174 + @Override
175 + public void setSizingWorking() {
176 + mSizingWorking = true;
177 + setVisible( true );
178 + }
179 +
180 + @Override
181 + public boolean isSizingWorking() {
182 + return mSizingWorking;
183 + }
184 +
185 + private int getPrefferredWidth( SizeableSimplePanel pOurWrapper ) {
186 + if ( pOurWrapper != null ) {
187 + Widget widget = pOurWrapper.getWidget();
188 + if ( widget != null ) {
189 + return widget.getOffsetWidth();
190 + }
191 + }
192 + return 0;
193 + }
194 +
195 + private int getPrefferredWidth( ContentPanel pOurWrapper ) {
196 + if ( pOurWrapper != null ) {
197 + Widget widget = pOurWrapper.getWidget();
198 + if ( widget != null ) {
199 + return widget.getOffsetWidth();
200 + }
201 + }
202 + return 0;
203 + }
204 +
205 + private int getPrefferredHeight( SizeableSimplePanel pOurWrapper ) {
206 + if ( pOurWrapper != null ) {
207 + Widget widget = pOurWrapper.getWidget();
208 + if ( widget != null ) {
209 + return widget.getOffsetHeight();
210 + }
211 + }
212 + return 0;
213 + }
214 +
215 + private int getPrefferredHeight( ContentPanel pOurWrapper ) {
216 + if ( pOurWrapper != null ) {
217 + Widget widget = pOurWrapper.getWidget();
218 + if ( widget != null ) {
219 + return widget.getOffsetHeight();
220 + }
221 + }
222 + return 0;
223 + }
224 +
225 + @Override
226 + public boolean setPrefferredWidth() {
227 + int w1 = getPrefferredWidth( mTitleBarPanel );
228 + int w2 = getPrefferredWidth( mContent );
229 + return (w1 > 0) && (w2 > 0) && setWidths( Math.max( w1, w2 ) );
230 + }
231 +
232 + @Override
233 + public boolean adjustWidthBy( int pDelta ) {
234 + // System.out.println( "adjustSizeBy(" + pDelta + ")" );
235 + if ( pDelta != 0 ) {
236 + int curWidth = mContent.getOffsetWidth();
237 + int newWidthContent = curWidth + pDelta;
238 + if ( (curWidth <= 0) || ((pDelta < 0) && (newWidthContent < MinContentWidth)) ) {
239 + return false;
240 + }
241 + setWidths( newWidthContent );
242 + }
243 + return true;
244 + }
245 +
246 + public void initializeWidth() {
247 + mWidthHandler.initializeDimension();
248 + }
249 +
250 + @Override
251 + public void setWidth( String pWidth ) {
252 + mWidthHandler.setDimension( pWidth );
253 + }
254 +
255 + protected int getMaxPotentialWidth() {
256 + return -1;
257 + }
258 +
259 + private FloaterPositionHandler createWidthPositionHandler() {
260 + return new FloaterPositionHandler() {
261 + @Override
262 + public int getPos() {
263 + return getPosLeft();
264 + }
265 +
266 + @Override
267 + public void setPos( int pNewPos ) {
268 + setPosLeft( pNewPos );
269 + }
270 +
271 + @Override
272 + public int getMaxPotentialSize() {
273 + return getMaxPotentialWidth();
274 + }
275 + };
276 + }
277 +
278 + protected DeferableFloaterDimensionHandler mWidthHandler = //
279 + new DeferableFloaterDimensionHandler( this, mLogger, getWidthHelper(), createWidthPositionHandler() );
280 +
281 + @Override
282 + public boolean setPrefferredHeight() {
283 + return setTitleBarPrefferredHeight() & setContentPrefferredHeight();
284 + }
285 +
286 + @Override
287 + public boolean adjustHeightBy( int pDelta ) {
288 + if ( pDelta != 0 ) {
289 + int curHeight = mContent.getOffsetHeight();
290 + int newHeightContent = curHeight + pDelta;
291 + if ( (curHeight <= 0) || ((pDelta < 0) && (newHeightContent < MinContentHeight)) ) {
292 + return false;
293 + }
294 + setContentHeight( newHeightContent );
295 + }
296 + return true;
297 + }
298 +
299 + public void initializeHeight() {
300 + mHeightHandler.initializeDimension();
301 + }
302 +
303 + @Override
304 + public void setHeight( String pHeight ) {
305 + mHeightHandler.setDimension( pHeight );
306 + }
307 +
308 + protected int getMaxPotentialHeight() {
309 + return -1;
310 + }
311 +
312 + private FloaterPositionHandler createHeightPositionHandler() {
313 + return new FloaterPositionHandler() {
314 + @Override
315 + public int getPos() {
316 + return getPosTop();
317 + }
318 +
319 + @Override
320 + public void setPos( int pNewPos ) {
321 + setPosTop( pNewPos );
322 + }
323 +
324 + @Override
325 + public int getMaxPotentialSize() {
326 + return getMaxPotentialHeight();
327 + }
328 + };
329 + }
330 +
331 + protected DeferableFloaterDimensionHandler mHeightHandler = //
332 + new DeferableFloaterDimensionHandler( this, mLogger, getHeightHelper(), createHeightPositionHandler() );
333 +
334 + private boolean setTitleBarPrefferredHeight() {
335 + int height = getPrefferredHeight( mTitleBarPanel );
336 + if ( height > 0 ) {
337 + setHeightOn( mTitleBarPanel, height, mTsLeftTitleBar, mTsRightTitleBar );
338 + return true;
339 + }
340 + return false;
341 + }
342 +
343 + private boolean setContentPrefferredHeight() {
344 + int height = getPrefferredHeight( mContent );
345 + if ( height > 0 ) {
346 + setContentHeight( height );
347 + return true;
348 + }
349 + return false;
350 + }
351 +
352 + private void setContentHeight( int pHeight ) {
353 + mHeightHandler.LLsetDimension( mTitleBarPanel.getOffsetHeight() + BORDER_TB_H + setHeightOn( mContent, pHeight, mTsLeftContent, mTsRightContent ) );
354 + }
355 +
356 + private int setHeightOn( Widget pWidget, int pHeight, Widget pLeftBorder, Widget pRightBorder ) {
357 + int zBorderHeight = pHeight - CplusSize;
358 + if ( zBorderHeight < 1 ) {
359 + pHeight = CplusSize + (zBorderHeight = 1); // MinContentHeight
360 + }
361 + pWidget.setHeight( "" + pHeight );
362 + pLeftBorder.setHeight( "" + zBorderHeight );
363 + pRightBorder.setHeight( "" + zBorderHeight );
364 + return pHeight;
365 + }
366 +
367 + @Override
368 + protected void distributeToChildrenChangedWidth() {
369 + setWidths( getOurInnerSize( getWidthHelper() ) - BORDER_LR_W );
370 + }
371 +
372 + @Override
373 + protected void distributeToChildrenChangedHeight() {
374 + int size = getOurInnerSize( getHeightHelper() ) - BORDER_TB_H;
375 + setContentHeight( size - mTitleBarPanel.getOffsetHeight() );
376 + }
377 +
378 + private int getOurInnerSize( ISizeableDimensionHelper pDimensionHelper ) {
379 + return pDimensionHelper.getDimension() - pDimensionHelper.getDecorationSize();
380 + }
381 +
382 + private boolean setWidths( int pDesiredWidth ) {
383 + int zBorderWidth = pDesiredWidth - CplusSize2;
384 + if ( zBorderWidth < 1 ) {
385 + pDesiredWidth = CplusSize + (zBorderWidth = 1); // MinContentWidth
386 + }
387 +
388 + mTsTop.setWidth( "" + zBorderWidth );
389 + mTsBottom.setWidth( "" + zBorderWidth );
390 + mTitleBarPanel.setWidth( "" + pDesiredWidth );
391 + mContent.setWidth( "" + pDesiredWidth );
392 + mWidthHandler.LLsetDimension( pDesiredWidth + BORDER_LR_W );
393 + return true;
394 + }
395 +
396 + /**
397 + * Adds a widget to this panel.
398 + *
399 + * @param w the child widget to be added
400 + */
401 + @Override
402 + public void add( Widget w ) {
403 + throw new IllegalStateException( "Use setWidget()" );
404 + }
405 +
406 + @Override
407 + public boolean remove( Widget w ) {
408 + throw new IllegalStateException( "Use setWidget()" );
409 + }
410 +
411 + @Override
412 + public boolean anyChildren() {
413 + return (mChildren.size() != 0);
414 + }
415 +
416 + @Override
417 + public Iterator<Widget> iterator() {
418 + return mChildren.iterator();
419 + }
420 +
421 + @Override
422 + public Widget getWidget( int index ) {
423 + return mChildren.get( index );
424 + }
425 +
426 + @Override
427 + public int getWidgetCount() {
428 + return mChildren.size();
429 + }
430 +
431 + @Override
432 + public int getWidgetIndex( Widget child ) {
433 + return mChildren.indexOf( child );
434 + }
435 +
436 + @Override
437 + public boolean remove( int index ) {
438 + return false;
439 + }
440 +
441 + private static class OurTextOnlyTitleBar extends FloaterTitleBar {
442 + private SizeableLabel mLabel = new SizeableLabel( "", false ).stretchableHorizontally();
443 +
444 + public OurTextOnlyTitleBar() {
445 + add( mLabel );
446 + add( new SizeableSpacer().width( 10 ).stretchableHorizontally() );
447 + }
448 +
449 + @Override
450 + public String getTitleBarTitle() {
451 + return mLabel.getText();
452 + }
453 +
454 + @Override
455 + public void setTitleBarTitle( String pTitle ) {
456 + mLabel.setText( pTitle );
457 + }
458 + }
459 +
460 + private abstract static class AbstractResizer extends AbstractDragger {
461 + private static final String MINIMUM_SIZE_REACHED = "Resizing Terminated, Minimum Size Reached";
462 +
463 + private final UiPositionAndSizeAdjustable mTarget;
464 +
465 + public AbstractResizer( UiPositionAndSizeAdjustable pTarget ) {
466 + mTarget = pTarget;
467 + }
468 +
469 + public UiPositionAndSizeAdjustable getTarget() {
470 + return mTarget;
471 + }
472 +
473 + protected boolean adjustPositionBy( int pDeltaX, int pDeltaY ) {
474 + // System.out.println( "adjustPositionBy(" + pDeltaX + "," + pDeltaY + ")" );
475 + getTarget().setPosition( getTarget().getPosLeft() + pDeltaX, getTarget().getPosTop() + pDeltaY );
476 + return true;
477 + }
478 +
479 + protected boolean adjustSizeBy( int pDeltaX, int pDeltaY ) {
480 + // System.out.println( "adjustSizeBy(" + pDeltaX + "," + pDeltaY + ")" );
481 + return getTarget().adjustWidthBy( pDeltaX ) && getTarget().adjustHeightBy( pDeltaY );
482 + }
483 +
484 + @Override
485 + public void start( MouseEvent e ) {
486 + super.start( e );
487 + StatusBar.remove( MINIMUM_SIZE_REACHED );
488 + }
489 +
490 + @Override
491 + protected final boolean dragBy( int pDeltaX, int pDeltaY ) {
492 + boolean success = dragByInner( pDeltaX, pDeltaY );
493 + if ( !success ) {
494 + StatusBar.add( MINIMUM_SIZE_REACHED );
495 + }
496 + return success;
497 + }
498 +
499 + abstract protected boolean dragByInner( int pDeltaX, int pDeltaY );
500 + }
501 +
502 + private static class ResizerTopLeft extends AbstractResizer {
503 + public ResizerTopLeft( UiPositionAndSizeAdjustable pTarget ) {
504 + super( pTarget );
505 + }
506 +
507 + @Override
508 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
509 + return adjustSizeBy( -pDeltaX, -pDeltaY ) && adjustPositionBy( pDeltaX, pDeltaY );
510 + }
511 + }
512 +
513 + private static class ResizerTopRight extends AbstractResizer {
514 + public ResizerTopRight( UiPositionAndSizeAdjustable pTarget ) {
515 + super( pTarget );
516 + }
517 +
518 + @Override
519 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
520 + return adjustSizeBy( pDeltaX, -pDeltaY ) && adjustPositionBy( 0, pDeltaY );
521 + }
522 + }
523 +
524 + private static class ResizerBottomRight extends AbstractResizer {
525 + public ResizerBottomRight( UiPositionAndSizeAdjustable pTarget ) {
526 + super( pTarget );
527 + }
528 +
529 + @Override
530 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
531 + return adjustSizeBy( pDeltaX, pDeltaY );
532 + }
533 + }
534 +
535 + private static class ResizerBottomLeft extends AbstractResizer {
536 + public ResizerBottomLeft( UiPositionAndSizeAdjustable pTarget ) {
537 + super( pTarget );
538 + }
539 +
540 + @Override
541 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
542 + return adjustSizeBy( -pDeltaX, pDeltaY ) && adjustPositionBy( pDeltaX, 0 );
543 + }
544 + }
545 +
546 + private static class ResizerTop extends AbstractResizer {
547 + public ResizerTop( UiPositionAndSizeAdjustable pTarget ) {
548 + super( pTarget );
549 + }
550 +
551 + @Override
552 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
553 + return adjustSizeBy( 0, -pDeltaY ) && adjustPositionBy( 0, pDeltaY );
554 + }
555 + }
556 +
557 + private static class ResizerBottom extends AbstractResizer {
558 + public ResizerBottom( UiPositionAndSizeAdjustable pTarget ) {
559 + super( pTarget );
560 + }
561 +
562 + @Override
563 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
564 + return adjustSizeBy( 0, pDeltaY );
565 + }
566 + }
567 +
568 + private static class ResizerRight extends AbstractResizer {
569 + public ResizerRight( UiPositionAndSizeAdjustable pTarget ) {
570 + super( pTarget );
571 + }
572 +
573 + @Override
574 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
575 + return adjustSizeBy( pDeltaX, 0 );
576 + }
577 + }
578 +
579 + private static class ResizerLeft extends AbstractResizer {
580 + public ResizerLeft( UiPositionAndSizeAdjustable pTarget ) {
581 + super( pTarget );
582 + }
583 +
584 + @Override
585 + protected boolean dragByInner( int pDeltaX, int pDeltaY ) {
586 + return adjustSizeBy( -pDeltaX, 0 ) && adjustPositionBy( pDeltaX, 0 );
587 + }
588 + }
589 +
590 + private Element LLaddTD( Element pTR, Widget pWidget ) {
591 + mChildren.add( pWidget );
592 +
593 + Element zTD = DOM.createTD();
594 + DOM.appendChild( pTR, zTD );
595 +
596 + adopt( pWidget, zTD );
597 +
598 + return zTD;
599 + }
600 +
601 + private Element addTDWithColSpan3( Element pTR, Widget pWidget ) {
602 + Element zTD = LLaddTD( pTR, pWidget );
603 +
604 + DOM.setElementPropertyInt( zTD, "colSpan", 3 );
605 +
606 + return zTD;
607 + }
608 +
609 + private void addTD( Element pTR, Widget pWidget ) {
610 + Element zTD = addTDWithColSpan3( pTR, pWidget );
611 + DOM.setElementPropertyInt( zTD, "rowSpan", 2 );
612 + }
613 +
614 + private Widget addTD( Element pTR, String pBorderID, String pClassPlus, int pWidth, int pHeight, DragGesture pResizer ) {
615 + Border border = new Border( "litesoft-" + mForm + "Border" + pBorderID + pClassPlus );
616 + border.addController( createBorderDragController( pResizer ) );
617 + border.addController( PreventSelectionController.getInstance() );
618 +
619 + LLaddTD( pTR, border );
620 +
621 + if ( pWidth > 0 ) {
622 + border.setWidth( "" + pWidth );
623 + }
624 + if ( pHeight > 0 ) {
625 + border.setHeight( "" + pHeight );
626 + }
627 + return border;
628 + }
629 +
630 + private void addTDCorner( Element pTR, String pBorderID, int pWidth, int pHeight, DragGesture pResizer ) {
631 + addTD( pTR, pBorderID, "", pWidth, pHeight, pResizer );
632 + }
633 +
634 + private Widget addTDHorizontal( Element pTR, String pBorderID, int pHeight, DragGesture pResizer ) {
635 + return addTD( pTR, pBorderID, "", 0, pHeight, pResizer );
636 + }
637 +
638 + private Widget addTDVertical( Element pTR, String pBorderID, String pClassPlus, int pWidth, DragGesture pResizer ) {
639 + return addTD( pTR, pBorderID, pClassPlus, pWidth, 0, pResizer );
640 + }
641 +
642 + abstract protected DragController createBorderDragController( DragGesture pResizer );
643 +
644 + protected void finishContainerTable( UiPositionAndSizeAdjustable pTarget ) {
645 + Element zTR, tBody = getContainerElement();
646 +
647 + DragGesture resizerTopLeft = new ResizerTopLeft( pTarget );
648 + DragGesture resizerTop = new ResizerTop( pTarget );
649 + DragGesture resizerTopRight = new ResizerTopRight( pTarget );
650 + DragGesture resizerRight = new ResizerRight( pTarget );
651 + DragGesture resizerBottomRight = new ResizerBottomRight( pTarget );
652 + DragGesture resizerBottom = new ResizerBottom( pTarget );
653 + DragGesture resizerBottomLeft = new ResizerBottomLeft( pTarget );
654 + DragGesture resizerLeft = new ResizerLeft( pTarget );
655 +
656 + DOM.appendChild( tBody, mTR_Pining = DOM.createTR() );
657 + addTDCorner( mTR_Pining, "CornerTopLeft", BORDER_L_W, BORDER_T_H, resizerTopLeft );
658 + addTDCorner( mTR_Pining, "CornerTopLeftUp", CplusSize, BORDER_T_H, resizerTopLeft );
659 + mTsTop = addTDHorizontal( mTR_Pining, "StraightTop", BORDER_T_H, resizerTop );
660 + addTDCorner( mTR_Pining, "CornerTopRightUp", CplusSize, BORDER_T_H, resizerTopRight );
661 + addTDCorner( mTR_Pining, "CornerTopRight", BORDER_R_W, BORDER_T_H, resizerTopRight );
662 +
663 + DOM.appendChild( tBody, zTR = DOM.createTR() );
664 + addTDCorner( zTR, "CornerTopLeftDown", BORDER_L_W, CplusSize, resizerTopLeft );
665 + addTD( zTR, mTitleBarPanel );
666 + addTDCorner( zTR, "CornerTopRightDown", BORDER_R_W, CplusSize, resizerTopRight );
667 +
668 + DOM.appendChild( tBody, zTR = DOM.createTR() );
669 + mTsLeftTitleBar = addTDVertical( zTR, "StraightLeft", CPT, BORDER_L_W, resizerLeft );
670 + mTsRightTitleBar = addTDVertical( zTR, "StraightRight", CPT, BORDER_R_W, resizerRight );
671 +
672 + DOM.appendChild( tBody, zTR = DOM.createTR() );
673 + mTsLeftContent = addTDVertical( zTR, "StraightLeft", CPC, BORDER_L_W, resizerLeft );
674 + addTD( zTR, mContent );
675 + mTsRightContent = addTDVertical( zTR, "StraightRight", CPC, BORDER_R_W, resizerRight );
676 +
677 + DOM.appendChild( tBody, mTR_RightAchoring = zTR = DOM.createTR() );
678 + addTDCorner( zTR, "CornerBottomLeftUp", BORDER_L_W, CplusSize, resizerBottomLeft );
679 + addTDCorner( zTR, "CornerBottomRightUp", BORDER_R_W, CplusSize, resizerBottomRight );
680 +
681 + DOM.appendChild( tBody, mTR_BottomAchoring = DOM.createTR() );
682 + addTDCorner( mTR_BottomAchoring, "CornerBottomLeft", BORDER_L_W, BORDER_B_H, resizerBottomLeft );
683 + addTDCorner( mTR_BottomAchoring, "CornerBottomLeftDown", CplusSize, BORDER_B_H, resizerBottomLeft );
684 + mTsBottom = addTDHorizontal( mTR_BottomAchoring, "StraightBottom", BORDER_B_H, resizerBottom );
685 + addTDCorner( mTR_BottomAchoring, "CornerBottomRightDown", CplusSize, BORDER_B_H, resizerBottomRight );
686 + addTDCorner( mTR_BottomAchoring, "CornerBottomRight", BORDER_R_W, BORDER_B_H, resizerBottomRight );
687 + }
688 +
689 + private static final String CPT = "Caption";
690 + private static final String CPC = "Content";
691 +
692 + private static final int BORDER_TB_H = BORDER_T_H + BORDER_B_H;
693 +
694 + private static final int BORDER_LR_W = BORDER_L_W + BORDER_R_W;
695 +
696 + private static final int CplusSize = 5;
697 +
698 + private static final int CplusSize2 = CplusSize + CplusSize;
699 +
700 + private static final int MinContentWidth = CplusSize2 + 1;
701 + private static final int MinContentHeight = CplusSize + 1;
702 +
703 + private Widget mTsTop, mTsBottom, mTsLeftTitleBar, mTsRightTitleBar, mTsLeftContent, mTsRightContent;
704 +
705 + private static class Border extends CWrapper {
706 + public Border( String pStyle ) {
707 + super( new SimplePanel() );
708 + SimplePanel panel = (SimplePanel) getWidget();
709 + panel.setWidget( new Spacer( 0 ) );
710 + setStyleName( pStyle );
711 + }
712 + }
713 +
714 + protected boolean allowDragging() {
715 + return true;
716 + }
717 +
718 + protected DragController createDragController( DragGesture pDragGesture ) {
719 + return new DragController( new MousePerformanceFilter( new MouseDragHandler( pDragGesture ) ) ) {
720 + @Override
721 + public void onBrowserEvent( Widget widget, Event event ) {
722 + if ( allowDragging() ) {
723 + super.onBrowserEvent( widget, event );
724 + }
725 + }
726 + };
727 + }
728 +
729 + protected DragGesture createThresholdFilter( DragGesture pDragGesture ) {
730 + /*
731 + * using a 1px drag tolerance prevents drag style from being applied
732 + * (and scrollbar flickering in FF) when a window is brought to front
733 + */
734 + return new DragThresholdFilter( 1, pDragGesture );
735 + }
736 + }