Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,727 +1,727 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets;
3 -
4 - import org.litesoft.GWT.client.nonpublic.*;
5 - import org.litesoft.GWT.client.widgets.nonpublic.*;
6 - import org.litesoft.GWT.client.widgets.nonpublic.external.*;
7 - import org.litesoft.commonfoundation.typeutils.Objects;
8 -
9 - import com.google.gwt.core.client.*;
10 - import com.google.gwt.dom.client.Element;
11 - import com.google.gwt.user.client.*;
12 - import com.google.gwt.user.client.ui.*;
13 - import com.google.gwt.user.client.ui.impl.*;
14 -
15 - import java.util.*;
16 -
17 - public class SizeableFloatingPanel extends AbstractFloaterPanel implements SizeableFloater,
18 - IFloaterPanelMoveAndSize {
19 - protected static final int MIN_SHOWING_VERTICAL = 20;
20 - protected static final int MIN_SHOWING_HORIZONTAL = 40;
21 -
22 - private static final PopupImpl sImpl = (PopupImpl) GWT.create( PopupImpl.class );
23 -
24 - private static final String REGULAR_BORDER = "RegularBorder";
25 - private static final String CLEAR_BORDER = "ClearBorder";
26 - private static final String HIDDEN_FLOATER = "HiddenFloater";
27 -
28 - private List<ChromeListener> mListeners = null;
29 -
30 - private boolean mChromed = false;
31 -
32 - private boolean mPinned = false;
33 -
34 - private boolean mActive = false;
35 -
36 - private boolean mHidden = false;
37 -
38 - private void LLsetActive( boolean pActive ) {
39 - mActive = stateStyle( pActive, getStyleElement(), "Active", "Inactive" );
40 - }
41 -
42 - private void LLsetPinned( boolean pPinned ) {
43 - mPinned = stateStyle( pPinned, getTR_Pinning(), "Pinned", "UnPinned" );
44 - }
45 -
46 - private class XYData {
47 - private ISizeableDimensionHelper mDimensionHelper;
48 - private Element mStyleElement;
49 - private String mPrefixAnchorStyle;
50 - private boolean mAnchored = false;
51 - private Integer mAnchorOffset = null;
52 - private Integer mContainerSize = null;
53 - private int mPos = 0;
54 -
55 - public XYData( ISizeableDimensionHelper pDimensionHelper, Element pStyleElement,
56 - String pPrefixAnchorStyle ) {
57 - mDimensionHelper = pDimensionHelper;
58 - mStyleElement = pStyleElement;
59 - mPrefixAnchorStyle = pPrefixAnchorStyle;
60 -
61 - setAnchored( false );
62 - }
63 -
64 - private void determineAnchorOffset() {
65 - Integer zContainerSize = getContainerSize();
66 - if ( zContainerSize != null ) {
67 - int zOurSize = mDimensionHelper.getDimension( getElement() );
68 - mAnchorOffset = zContainerSize - (getPos() + zOurSize);
69 - return;
70 - }
71 - mAnchorOffset = null;
72 - }
73 -
74 - public void changedContainerSize() {
75 - if ( isAnchored() ) {
76 - if ( mAnchorOffset == null ) {
77 - determineAnchorOffset();
78 - }
79 - Integer zNewContainerSize = getCurrentContainerSize();
80 - if ( !Objects.areNonArraysEqual( mContainerSize, zNewContainerSize ) ) {
81 - Integer zOldContainerSize = mContainerSize;
82 - mContainerSize = zNewContainerSize;
83 - if ( (zOldContainerSize != null) && (zNewContainerSize != null) ) {
84 - int zDelta = zNewContainerSize - zOldContainerSize;
85 - if ( isPinned() ) {
86 - // Change Size
87 - mDimensionHelper.adjustSizeBy( zDelta );
88 - } else {
89 - // Change Position
90 - if ( "Width".equals( mDimensionHelper.getWhat() ) ) {
91 - setPosLeft( getPos() + zDelta );
92 - } else {
93 - setPosTop( getPos() + zDelta );
94 - }
95 - }
96 - }
97 - }
98 - }
99 - }
100 -
101 - private Integer getContainerSize() {
102 - return (mContainerSize != null) ? mContainerSize : (mContainerSize = getCurrentContainerSize());
103 - }
104 -
105 - private Integer getCurrentContainerSize() {
106 - SizeableFloatableContainerPanel containerPanel = getContainerPanel();
107 - if ( containerPanel != null ) {
108 - if ( containerPanel.getOffsetHeight() > 20 ) {
109 - return mDimensionHelper.getDimension( containerPanel );
110 - }
111 - }
112 - return null;
113 - }
114 -
115 - public void setAnchored( boolean pAnchored ) {
116 - if ( mAnchored = stateStyle( pAnchored, mStyleElement, //
117 - mPrefixAnchorStyle + "Anchor", //
118 - mPrefixAnchorStyle + "Free" ) ) {
119 - determineAnchorOffset();
120 - }
121 - }
122 -
123 - public int getPos() {
124 - return mPos;
125 - }
126 -
127 - public boolean setPos( int pPos ) {
128 - if ( mPos != pPos ) {
129 - mPos = pPos;
130 - return true;
131 - }
132 - return false;
133 - }
134 -
135 - public boolean isAnchored() {
136 - return mAnchored;
137 - }
138 -
139 - public void possiblySetAnchored( boolean pAnchor ) {
140 - if ( mAnchored != pAnchor ) {
141 - setAnchored( pAnchor );
142 - }
143 - }
144 - }
145 -
146 - private XYData mXData, mYData;
147 -
148 - private boolean stateStyle( boolean pState, Element pElement, String pSuffixTrue, String pSuffixFalse ) {
149 - setStyleName( pElement, mBaseCSSclassname + "-" + pSuffixTrue, pState );
150 - setStyleName( pElement, mBaseCSSclassname + "-" + pSuffixFalse, !pState );
151 - return pState;
152 - }
153 -
154 - public SizeableFloatingPanel() {
155 - super( "Floater" );
156 -
157 - finishContainerTable( this ); // This call must occur BEFORE the next 4 lines
158 - LLsetActive( false );
159 - LLsetPinned( false );
160 - mXData = new XYData( getWidthHelper(), getTR_RightAnchoring(), "Right" );
161 - mYData = new XYData( getHeightHelper(), getTR_BottomAnchoring(), "Bottom" );
162 -
163 - DOM.setStyleAttribute( getElement(), "position", "absolute" );
164 -
165 - setVisible( false );
166 -
167 - mTitleBarPanel.addController( mDragController = createTitleBarDragController( this ) );
168 -
169 - setupRegularBorder();
170 -
171 - sinkEvents( Event.MOUSEEVENTS );
172 - }
173 -
174 - public void onBrowserEvent( Event event ) {
175 - switch ( DOM.eventGetType( event ) ) {
176 - case Event.ONMOUSEDOWN:
177 - forceToFront();
178 - default:
179 - break;
180 - }
181 - super.onBrowserEvent( event );
182 - }
183 -
184 - protected boolean allowDragging() {
185 - return isChromed();
186 - }
187 -
188 - private DragController createTitleBarDragController( UiPositionable pUiPositionable ) {
189 - return createDragController( new BringToFrontGesture(
190 - createThresholdFilter( createTitleBarDragGesture( pUiPositionable ) ) ) );
191 - }
192 -
193 - protected DragController createBorderDragController( DragGesture pResizer ) {
194 - return createDragController( new BringToFrontGesture( createThresholdFilter( pResizer ) ) );
195 - }
196 -
197 - public boolean isVisible() {
198 - return !"hidden".equals( DOM.getStyleAttribute( getElement(), "visibility" ) );
199 - }
200 -
201 - public void setVisible( boolean visible ) {
202 - DOM.setStyleAttribute( getElement(), "visibility", visible ? "visible" : "hidden" );
203 - sImpl.setVisible( getElement(), visible );
204 - }
205 -
206 - protected void onAttach() {
207 - super.onAttach();
208 - sImpl.onShow( getElement() );
209 - }
210 -
211 - protected void onDetach() {
212 - sImpl.onHide( getElement() );
213 - super.onDetach();
214 - }
215 -
216 - public int getArea() {
217 - return getOffsetHeight() * getOffsetWidth();
218 - }
219 -
220 - public int minPosLeft() {
221 - return MIN_SHOWING_HORIZONTAL - getOffsetWidth();
222 - }
223 -
224 - public int minPosTop() {
225 - return 0 - (getTitleBarHeight() + BORDER_T_H - 3);
226 - }
227 -
228 - public int maxPosLeft() {
229 - Widget zParent = getParent();
230 - return ((zParent == null) ? 0 : zParent.getOffsetWidth()) - MIN_SHOWING_HORIZONTAL;
231 - }
232 -
233 - public int maxPosTop() {
234 - Widget zParent = getParent();
235 - return ((zParent == null) ? 0 : zParent.getOffsetHeight()) - MIN_SHOWING_VERTICAL;
236 - }
237 -
238 - public int getPosLeft() {
239 - return mXData.getPos();
240 - }
241 -
242 - public void setPosLeft( int pPosLeft ) {
243 - if ( mXData.setPos( pPosLeft ) ) {
244 - DOM.setIntStyleAttribute( getHelper().getOuterElement(), "left", pPosLeft );
245 - }
246 - }
247 -
248 - public int getPosTop() {
249 - return mYData.getPos();
250 - }
251 -
252 - public void setPosTop( int pPosTop ) {
253 - if ( mYData.setPos( pPosTop ) ) {
254 - DOM.setIntStyleAttribute( getHelper().getOuterElement(), "top", pPosTop );
255 - }
256 - }
257 -
258 - private void removePositionLock() {
259 - setPinned( false );
260 - setRightAnchor( false );
261 - setBottomAnchor( false );
262 - }
263 -
264 - public boolean isPositionLocked() {
265 - return isPinned() || isRightAnchor() || isBottomAnchor() || !isChromed();
266 - }
267 -
268 - private static int sCascadeUniqueID = 0;
269 -
270 - private int mCascadeUniqueID = ++sCascadeUniqueID;
271 -
272 - public int getCascadeUniqueID() {
273 - return mCascadeUniqueID;
274 - }
275 -
276 - private int mZindex;
277 -
278 - public int getZindex() {
279 - return mZindex;
280 - }
281 -
282 - public void setZindex( int pZindex ) {
283 - if ( mZindex != pZindex ) {
284 - mZindex = pZindex;
285 - DOM.setIntStyleAttribute( getHelper().getOuterElement(), "zIndex", pZindex );
286 - }
287 - }
288 -
289 - public boolean isActive() {
290 - return mActive;
291 - }
292 -
293 - public void setActive( boolean pActive ) {
294 - if ( mActive != pActive ) {
295 - LLsetActive( pActive );
296 - }
297 - }
298 -
299 - public void maximizeVisibility() {
300 - mHeightHandler.maximizeVisibility();
301 - mWidthHandler.maximizeVisibility();
302 - }
303 -
304 - public void changedContainerWidth() {
305 - mXData.changedContainerSize();
306 - }
307 -
308 - public void changedContainerHeight() {
309 - mYData.changedContainerSize();
310 - }
311 -
312 - public String getCurrentTitle() {
313 - return getTitle();
314 - }
315 -
316 - public IFloaterPanelMoveAndSize[] getAllFloaters() {
317 - SizeableFloater[] zFloaters = getContainerPanel().getFloatersSortedByTitle();
318 - List<IFloaterPanelMoveAndSize> zList = new ArrayList<IFloaterPanelMoveAndSize>( zFloaters.length );
319 -
320 - for ( SizeableFloater zFloater : zFloaters ) {
321 - if ( zFloater instanceof IFloaterPanelMoveAndSize ) {
322 - zList.add( (IFloaterPanelMoveAndSize) zFloater );
323 - }
324 - }
325 - return zList.toArray( new IFloaterPanelMoveAndSize[zList.size()] );
326 - }
327 -
328 - public void setActive() {
329 - getContainerPanel().makeTop( this );
330 - }
331 -
332 - public String getRegisteredFactoryName() {
333 - return null;
334 - }
335 -
336 - public boolean isChromed() {
337 - return mChromed;
338 - }
339 -
340 - public void setChromed( boolean pChromed ) {
341 - if ( mChromed != pChromed ) {
342 - if ( mChromed ) {
343 - hideBorder();
344 - } else {
345 - restoreBorder();
346 - }
347 - fireChromeChanged();
348 - }
349 - }
350 -
351 - public boolean isPinned() {
352 - return mPinned;
353 - }
354 -
355 - public void setPinned( boolean pPinned ) {
356 - if ( mPinned != pPinned ) {
357 - LLsetPinned( pPinned );
358 - }
359 - }
360 -
361 - public boolean isRightAnchor() {
362 - return mXData.isAnchored();
363 - }
364 -
365 - public void setRightAnchor( boolean pRightAnchor ) {
366 - mXData.possiblySetAnchored( pRightAnchor );
367 - }
368 -
369 - public boolean isBottomAnchor() {
370 - return mYData.isAnchored();
371 - }
372 -
373 - public void setBottomAnchor( boolean pBottomAnchor ) {
374 - mYData.possiblySetAnchored( pBottomAnchor );
375 - }
376 -
377 - public void moveN( int pPixels ) {
378 - chromeAwareAdjustPosTopBy( pPixels, -pPixels );
379 - }
380 -
381 - public void moveE( int pPixels ) {
382 - chromeAwareAdjustPosLeftBy( pPixels, pPixels );
383 - }
384 -
385 - public void moveW( int pPixels ) {
386 - chromeAwareAdjustPosLeftBy( pPixels, -pPixels );
387 - }
388 -
389 - public void moveS( int pPixels ) {
390 - chromeAwareAdjustPosTopBy( pPixels, pPixels );
391 - }
392 -
393 - public void moveNW( int pPixels ) {
394 - moveN( pPixels );
395 - moveW( pPixels );
396 - }
397 -
398 - public void moveNE( int pPixels ) {
399 - moveN( pPixels );
400 - moveE( pPixels );
401 - }
402 -
403 - public void moveSW( int pPixels ) {
404 - moveS( pPixels );
405 - moveW( pPixels );
406 - }
407 -
408 - public void moveSE( int pPixels ) {
409 - moveS( pPixels );
410 - moveE( pPixels );
411 - }
412 -
413 - public void moveToMaxN() {
414 - chromeAwareAdjustPosTopBy( -MAX_RESOLUTION_SUPPORTED );
415 - }
416 -
417 - public void moveToMaxE() {
418 - chromeAwareAdjustPosLeftBy( MAX_RESOLUTION_SUPPORTED );
419 - }
420 -
421 - public void moveToMaxW() {
422 - chromeAwareAdjustPosLeftBy( -MAX_RESOLUTION_SUPPORTED );
423 - }
424 -
425 - public void moveToMaxS() {
426 - chromeAwareAdjustPosTopBy( MAX_RESOLUTION_SUPPORTED );
427 - }
428 -
429 - public void moveToMaxNW() {
430 - moveToMaxN();
431 - moveToMaxW();
432 - }
433 -
434 - public void moveToMaxNE() {
435 - moveToMaxN();
436 - moveToMaxE();
437 - }
438 -
439 - public void moveToMaxSW() {
440 - moveToMaxS();
441 - moveToMaxW();
442 - }
443 -
444 - public void moveToMaxSE() {
445 - moveToMaxS();
446 - moveToMaxE();
447 - }
448 -
449 - public void increaseWidthBy( int pPixels ) {
450 - chromeAwareAdjustWidthBy( pPixels, pPixels );
451 - }
452 -
453 - public void decreaseWidthBy( int pPixels ) {
454 - chromeAwareAdjustWidthBy( pPixels, -pPixels );
455 - }
456 -
457 - public void increaseHeightBy( int pPixels ) {
458 - chromeAwareAdjustHeightBy( pPixels, pPixels );
459 - }
460 -
461 - public void decreaseHeightBy( int pPixels ) {
462 - chromeAwareAdjustHeightBy( pPixels, -pPixels );
463 - }
464 -
465 - public void expandToMaxWidth() {
466 - setWidth( MAX_RESOLUTION_SUPPORTED );
467 - }
468 -
469 - public void expandToMaxHeight() {
470 - setHeight( MAX_RESOLUTION_SUPPORTED );
471 - }
472 -
473 - public void setWidth( int pNewWidth ) {
474 - removePositionLock();
475 - setWidth( "" + chromeAwareConstrainWidth( pNewWidth ) );
476 - }
477 -
478 - public void setHeight( int pNewHeight ) {
479 - removePositionLock();
480 - setHeight( "" + chromeAwareConstrainHeight( pNewHeight ) );
481 - }
482 -
483 - private void chromeAwareAdjustPosTopBy( int pPixels, int pDirectionPixels ) {
484 - if ( pPixels > 0 ) {
485 - chromeAwareAdjustPosTopBy( pDirectionPixels );
486 - }
487 - }
488 -
489 - private void chromeAwareAdjustPosTopBy( int pDirectionPixels ) {
490 - removePositionLock();
491 - setPosTop( chromeAwareConstrainPosTop( getPosTop() + pDirectionPixels ) );
492 - }
493 -
494 - private void chromeAwareAdjustPosLeftBy( int pPixels, int pDirectionPixels ) {
495 - if ( pPixels > 0 ) {
496 - chromeAwareAdjustPosLeftBy( pDirectionPixels );
497 - }
498 - }
499 -
500 - private void chromeAwareAdjustPosLeftBy( int pDirectionPixels ) {
501 - removePositionLock();
502 - setPosLeft( chromeAwareConstrainPosLeft( getPosLeft() + pDirectionPixels ) );
503 - }
504 -
505 - private void chromeAwareAdjustWidthBy( int pPixels, int pDirectionPixels ) {
506 - if ( pPixels > 0 ) {
507 - chromeAwareAdjustWidthBy( pDirectionPixels );
508 - }
509 - }
510 -
511 - private void chromeAwareAdjustWidthBy( int pDirectionPixels ) {
512 - setWidth( getOffsetWidth() + pDirectionPixels );
513 - }
514 -
515 - private void chromeAwareAdjustHeightBy( int pPixels, int pDirectionPixels ) {
516 - if ( pPixels > 0 ) {
517 - chromeAwareAdjustHeightBy( pDirectionPixels );
518 - }
519 - }
520 -
521 - private void chromeAwareAdjustHeightBy( int pDirectionPixels ) {
522 - setHeight( getOffsetHeight() + pDirectionPixels );
523 - }
524 -
525 - private int getChromeAwareMaxPotentialWidth() {
526 - return getMaxPotentialWidth() + (isChromed() ? 0 : BORDER_R_W);
527 - }
528 -
529 - private int chromeAwareConstrainPosLeft( int pPosLeft ) {
530 - int zMaxPosLeft = getChromeAwareMaxPotentialWidth() - getOffsetWidth();
531 - if ( pPosLeft > zMaxPosLeft ) {
532 - pPosLeft = zMaxPosLeft;
533 - }
534 -
535 - int zMinPosLeft = isChromed() ? 0 : -BORDER_L_W;
536 - if ( pPosLeft < zMinPosLeft ) {
537 - pPosLeft = zMinPosLeft;
538 - }
539 -
540 - return pPosLeft;
541 - }
542 -
543 - private int chromeAwareConstrainWidth( int pWidth ) {
544 - int zMaxWidth = getChromeAwareMaxPotentialWidth() - getPosLeft();
545 - if ( pWidth > zMaxWidth ) {
546 - pWidth = zMaxWidth;
547 - }
548 -
549 - int zMinWidth = getMinContentWidth() + (isChromed() ? 0 : BORDER_L_W + BORDER_R_W);
550 - if ( pWidth < zMinWidth ) {
551 - pWidth = zMinWidth;
552 - }
553 -
554 - return pWidth;
555 - }
556 -
557 - private int getChromeAwareMaxPotentialHeight() {
558 - return getMaxPotentialHeight() + (isChromed() ? 0 : BORDER_B_H);
559 - }
560 -
561 - private int chromeAwareConstrainPosTop( int pPosTop ) {
562 - int zMaxPosTop = getChromeAwareMaxPotentialHeight() - getOffsetHeight();
563 - if ( pPosTop > zMaxPosTop ) {
564 - pPosTop = zMaxPosTop;
565 - }
566 -
567 - int zMinPosTop = isChromed() ? 0 : -(BORDER_T_H + getTitleBarHeight());
568 - if ( pPosTop < zMinPosTop ) {
569 - pPosTop = zMinPosTop;
570 - }
571 -
572 - return pPosTop;
573 - }
574 -
575 - private int chromeAwareConstrainHeight( int pHeight ) {
576 - int zMaxHeight = getChromeAwareMaxPotentialHeight() - getPosTop();
577 - if ( pHeight > zMaxHeight ) {
578 - pHeight = zMaxHeight;
579 - }
580 -
581 - int zMinHeight =
582 - getMinContentHeight() + (isChromed() ? 0 : BORDER_T_H + getTitleBarHeight() + BORDER_B_H);
583 - if ( pHeight < zMinHeight ) {
584 - pHeight = zMinHeight;
585 - }
586 -
587 - return pHeight;
588 - }
589 -
590 - private int getMinContentWidth() {
591 - return 60; // todo: Will need to dynamically determine
592 - }
593 -
594 - private int getMinContentHeight() {
595 - return 40; // todo: Will need to dynamically determine
596 - }
597 -
598 - protected int getMaxPotentialWidth() {
599 - SizeableFloatableContainerPanel containerPanel = getContainerPanel();
600 - if ( containerPanel != null ) {
601 - if ( containerPanel.getOffsetHeight() > 20 ) {
602 - return containerPanel.getOffsetWidth();
603 - }
604 - }
605 - return super.getMaxPotentialWidth();
606 - }
607 -
608 - protected int getMaxPotentialHeight() {
609 - SizeableFloatableContainerPanel containerPanel = getContainerPanel();
610 - if ( containerPanel != null ) {
611 - if ( containerPanel.getOffsetHeight() > 20 ) {
612 - return containerPanel.getOffsetHeight();
613 - }
614 - }
615 - return super.getMaxPotentialHeight();
616 - }
617 -
618 - private SizeableFloatableContainerPanel getContainerPanel() {
619 - Widget zParent = getParent();
620 - return (zParent instanceof SizeableFloatableContainerPanel) ?
621 - (SizeableFloatableContainerPanel) zParent : null;
622 - }
623 -
624 - public void hideFloater() {
625 - Element zBorderElement = DOM.getParent( getStyleElement() );
626 - setStyleName( zBorderElement, REGULAR_BORDER, false );
627 - setStyleName( zBorderElement, CLEAR_BORDER, false );
628 - setStyleName( zBorderElement, HIDDEN_FLOATER, true );
629 - mHidden = true;
630 - setVisible( false );
631 - }
632 -
633 - public void showFloater() {
634 - Element zBorderElement = DOM.getParent( getStyleElement() );
635 - setStyleName( zBorderElement, HIDDEN_FLOATER, false );
636 - setBorderStyle( mChromed );
637 - mHidden = false;
638 - setVisible( true );
639 - }
640 -
641 - public boolean isHidden() {
642 - return mHidden;
643 - }
644 -
645 - public void hideBorder() {
646 - if ( mChromed ) {
647 - getTitleBar().hide();
648 - teardownRegularBorder();
649 - setupClearBorder();
650 - }
651 - }
652 -
653 - public void restoreBorder() {
654 - if ( !mChromed ) {
655 - getTitleBar().unhide();
656 - teardownClearBorder();
657 - setupRegularBorder();
658 - }
659 - }
660 -
661 - private void setupClearBorder() {
662 - setBorderStyle( false );
663 - }
664 -
665 - private void teardownClearBorder() {
666 - }
667 -
668 - private void setupRegularBorder() {
669 - setBorderStyle( true );
670 - mTitleBarPanel.addController( mDragController );
671 - }
672 -
673 - private void teardownRegularBorder() {
674 - mTitleBarPanel.removeController( mDragController );
675 - }
676 -
677 - protected void setBorderStyle( boolean pNewState ) {
678 - mChromed = pNewState;
679 - Element zBorderElement = DOM.getParent( getStyleElement() );
680 - setStyleName( zBorderElement, REGULAR_BORDER, mChromed );
681 - setStyleName( zBorderElement, CLEAR_BORDER, !mChromed );
682 - }
683 -
684 - private void forceToFront() {
685 - if ( isChromed() ) {
686 - SizeableFloatableContainerPanel containerPanel = getContainerPanel();
687 - if ( containerPanel != null ) {
688 - containerPanel.makeTop( this );
689 - }
690 - }
691 - }
692 -
693 - public void addListener( ChromeListener listener ) {
694 - if ( mListeners == null ) {
695 - mListeners = new ArrayList<ChromeListener>();
696 - }
697 - assert !mListeners.contains( listener );
698 - mListeners.add( listener );
699 - }
700 -
701 - public void removeListener( ChromeListener listener ) {
702 - if ( mListeners != null ) {
703 - assert mListeners.contains( listener );
704 - mListeners.remove( listener );
705 - }
706 - }
707 -
708 - protected void fireChromeChanged() {
709 - if ( mListeners != null && mListeners.size() > 0 ) {
710 - ChromeListener[] listeners = mListeners.toArray( new ChromeListener[mListeners.size()] );
711 - for ( ChromeListener listener : listeners ) {
712 - listener.chromeChanged( this );
713 - }
714 - }
715 - }
716 -
717 - private class BringToFrontGesture extends DragGestureWrapper {
718 - public BringToFrontGesture( DragGesture delegate ) {
719 - super( delegate );
720 - }
721 -
722 - public void start( MouseEvent e ) {
723 - forceToFront();
724 - super.start( e );
725 - }
726 - }
727 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets;
3 +
4 + import org.litesoft.GWT.client.nonpublic.*;
5 + import org.litesoft.GWT.client.widgets.nonpublic.*;
6 + import org.litesoft.GWT.client.widgets.nonpublic.external.*;
7 + import org.litesoft.commonfoundation.base.*;
8 +
9 + import com.google.gwt.core.client.*;
10 + import com.google.gwt.dom.client.Element;
11 + import com.google.gwt.user.client.*;
12 + import com.google.gwt.user.client.ui.*;
13 + import com.google.gwt.user.client.ui.impl.*;
14 +
15 + import java.util.*;
16 +
17 + public class SizeableFloatingPanel extends AbstractFloaterPanel implements SizeableFloater,
18 + IFloaterPanelMoveAndSize {
19 + protected static final int MIN_SHOWING_VERTICAL = 20;
20 + protected static final int MIN_SHOWING_HORIZONTAL = 40;
21 +
22 + private static final PopupImpl sImpl = (PopupImpl) GWT.create( PopupImpl.class );
23 +
24 + private static final String REGULAR_BORDER = "RegularBorder";
25 + private static final String CLEAR_BORDER = "ClearBorder";
26 + private static final String HIDDEN_FLOATER = "HiddenFloater";
27 +
28 + private List<ChromeListener> mListeners = null;
29 +
30 + private boolean mChromed = false;
31 +
32 + private boolean mPinned = false;
33 +
34 + private boolean mActive = false;
35 +
36 + private boolean mHidden = false;
37 +
38 + private void LLsetActive( boolean pActive ) {
39 + mActive = stateStyle( pActive, getStyleElement(), "Active", "Inactive" );
40 + }
41 +
42 + private void LLsetPinned( boolean pPinned ) {
43 + mPinned = stateStyle( pPinned, getTR_Pinning(), "Pinned", "UnPinned" );
44 + }
45 +
46 + private class XYData {
47 + private ISizeableDimensionHelper mDimensionHelper;
48 + private Element mStyleElement;
49 + private String mPrefixAnchorStyle;
50 + private boolean mAnchored = false;
51 + private Integer mAnchorOffset = null;
52 + private Integer mContainerSize = null;
53 + private int mPos = 0;
54 +
55 + public XYData( ISizeableDimensionHelper pDimensionHelper, Element pStyleElement,
56 + String pPrefixAnchorStyle ) {
57 + mDimensionHelper = pDimensionHelper;
58 + mStyleElement = pStyleElement;
59 + mPrefixAnchorStyle = pPrefixAnchorStyle;
60 +
61 + setAnchored( false );
62 + }
63 +
64 + private void determineAnchorOffset() {
65 + Integer zContainerSize = getContainerSize();
66 + if ( zContainerSize != null ) {
67 + int zOurSize = mDimensionHelper.getDimension( getElement() );
68 + mAnchorOffset = zContainerSize - (getPos() + zOurSize);
69 + return;
70 + }
71 + mAnchorOffset = null;
72 + }
73 +
74 + public void changedContainerSize() {
75 + if ( isAnchored() ) {
76 + if ( mAnchorOffset == null ) {
77 + determineAnchorOffset();
78 + }
79 + Integer zNewContainerSize = getCurrentContainerSize();
80 + if ( !Currently.areEqual( mContainerSize, zNewContainerSize ) ) {
81 + Integer zOldContainerSize = mContainerSize;
82 + mContainerSize = zNewContainerSize;
83 + if ( (zOldContainerSize != null) && (zNewContainerSize != null) ) {
84 + int zDelta = zNewContainerSize - zOldContainerSize;
85 + if ( isPinned() ) {
86 + // Change Size
87 + mDimensionHelper.adjustSizeBy( zDelta );
88 + } else {
89 + // Change Position
90 + if ( "Width".equals( mDimensionHelper.getWhat() ) ) {
91 + setPosLeft( getPos() + zDelta );
92 + } else {
93 + setPosTop( getPos() + zDelta );
94 + }
95 + }
96 + }
97 + }
98 + }
99 + }
100 +
101 + private Integer getContainerSize() {
102 + return (mContainerSize != null) ? mContainerSize : (mContainerSize = getCurrentContainerSize());
103 + }
104 +
105 + private Integer getCurrentContainerSize() {
106 + SizeableFloatableContainerPanel containerPanel = getContainerPanel();
107 + if ( containerPanel != null ) {
108 + if ( containerPanel.getOffsetHeight() > 20 ) {
109 + return mDimensionHelper.getDimension( containerPanel );
110 + }
111 + }
112 + return null;
113 + }
114 +
115 + public void setAnchored( boolean pAnchored ) {
116 + if ( mAnchored = stateStyle( pAnchored, mStyleElement, //
117 + mPrefixAnchorStyle + "Anchor", //
118 + mPrefixAnchorStyle + "Free" ) ) {
119 + determineAnchorOffset();
120 + }
121 + }
122 +
123 + public int getPos() {
124 + return mPos;
125 + }
126 +
127 + public boolean setPos( int pPos ) {
128 + if ( mPos != pPos ) {
129 + mPos = pPos;
130 + return true;
131 + }
132 + return false;
133 + }
134 +
135 + public boolean isAnchored() {
136 + return mAnchored;
137 + }
138 +
139 + public void possiblySetAnchored( boolean pAnchor ) {
140 + if ( mAnchored != pAnchor ) {
141 + setAnchored( pAnchor );
142 + }
143 + }
144 + }
145 +
146 + private XYData mXData, mYData;
147 +
148 + private boolean stateStyle( boolean pState, Element pElement, String pSuffixTrue, String pSuffixFalse ) {
149 + setStyleName( pElement, mBaseCSSclassname + "-" + pSuffixTrue, pState );
150 + setStyleName( pElement, mBaseCSSclassname + "-" + pSuffixFalse, !pState );
151 + return pState;
152 + }
153 +
154 + public SizeableFloatingPanel() {
155 + super( "Floater" );
156 +
157 + finishContainerTable( this ); // This call must occur BEFORE the next 4 lines
158 + LLsetActive( false );
159 + LLsetPinned( false );
160 + mXData = new XYData( getWidthHelper(), getTR_RightAnchoring(), "Right" );
161 + mYData = new XYData( getHeightHelper(), getTR_BottomAnchoring(), "Bottom" );
162 +
163 + DOM.setStyleAttribute( getElement(), "position", "absolute" );
164 +
165 + setVisible( false );
166 +
167 + mTitleBarPanel.addController( mDragController = createTitleBarDragController( this ) );
168 +
169 + setupRegularBorder();
170 +
171 + sinkEvents( Event.MOUSEEVENTS );
172 + }
173 +
174 + public void onBrowserEvent( Event event ) {
175 + switch ( DOM.eventGetType( event ) ) {
176 + case Event.ONMOUSEDOWN:
177 + forceToFront();
178 + default:
179 + break;
180 + }
181 + super.onBrowserEvent( event );
182 + }
183 +
184 + protected boolean allowDragging() {
185 + return isChromed();
186 + }
187 +
188 + private DragController createTitleBarDragController( UiPositionable pUiPositionable ) {
189 + return createDragController( new BringToFrontGesture(
190 + createThresholdFilter( createTitleBarDragGesture( pUiPositionable ) ) ) );
191 + }
192 +
193 + protected DragController createBorderDragController( DragGesture pResizer ) {
194 + return createDragController( new BringToFrontGesture( createThresholdFilter( pResizer ) ) );
195 + }
196 +
197 + public boolean isVisible() {
198 + return !"hidden".equals( DOM.getStyleAttribute( getElement(), "visibility" ) );
199 + }
200 +
201 + public void setVisible( boolean visible ) {
202 + DOM.setStyleAttribute( getElement(), "visibility", visible ? "visible" : "hidden" );
203 + sImpl.setVisible( getElement(), visible );
204 + }
205 +
206 + protected void onAttach() {
207 + super.onAttach();
208 + sImpl.onShow( getElement() );
209 + }
210 +
211 + protected void onDetach() {
212 + sImpl.onHide( getElement() );
213 + super.onDetach();
214 + }
215 +
216 + public int getArea() {
217 + return getOffsetHeight() * getOffsetWidth();
218 + }
219 +
220 + public int minPosLeft() {
221 + return MIN_SHOWING_HORIZONTAL - getOffsetWidth();
222 + }
223 +
224 + public int minPosTop() {
225 + return 0 - (getTitleBarHeight() + BORDER_T_H - 3);
226 + }
227 +
228 + public int maxPosLeft() {
229 + Widget zParent = getParent();
230 + return ((zParent == null) ? 0 : zParent.getOffsetWidth()) - MIN_SHOWING_HORIZONTAL;
231 + }
232 +
233 + public int maxPosTop() {
234 + Widget zParent = getParent();
235 + return ((zParent == null) ? 0 : zParent.getOffsetHeight()) - MIN_SHOWING_VERTICAL;
236 + }
237 +
238 + public int getPosLeft() {
239 + return mXData.getPos();
240 + }
241 +
242 + public void setPosLeft( int pPosLeft ) {
243 + if ( mXData.setPos( pPosLeft ) ) {
244 + DOM.setIntStyleAttribute( getHelper().getOuterElement(), "left", pPosLeft );
245 + }
246 + }
247 +
248 + public int getPosTop() {
249 + return mYData.getPos();
250 + }
251 +
252 + public void setPosTop( int pPosTop ) {
253 + if ( mYData.setPos( pPosTop ) ) {
254 + DOM.setIntStyleAttribute( getHelper().getOuterElement(), "top", pPosTop );
255 + }
256 + }
257 +
258 + private void removePositionLock() {
259 + setPinned( false );
260 + setRightAnchor( false );
261 + setBottomAnchor( false );
262 + }
263 +
264 + public boolean isPositionLocked() {
265 + return isPinned() || isRightAnchor() || isBottomAnchor() || !isChromed();
266 + }
267 +
268 + private static int sCascadeUniqueID = 0;
269 +
270 + private int mCascadeUniqueID = ++sCascadeUniqueID;
271 +
272 + public int getCascadeUniqueID() {
273 + return mCascadeUniqueID;
274 + }
275 +
276 + private int mZindex;
277 +
278 + public int getZindex() {
279 + return mZindex;
280 + }
281 +
282 + public void setZindex( int pZindex ) {
283 + if ( mZindex != pZindex ) {
284 + mZindex = pZindex;
285 + DOM.setIntStyleAttribute( getHelper().getOuterElement(), "zIndex", pZindex );
286 + }
287 + }
288 +
289 + public boolean isActive() {
290 + return mActive;
291 + }
292 +
293 + public void setActive( boolean pActive ) {
294 + if ( mActive != pActive ) {
295 + LLsetActive( pActive );
296 + }
297 + }
298 +
299 + public void maximizeVisibility() {
300 + mHeightHandler.maximizeVisibility();
301 + mWidthHandler.maximizeVisibility();
302 + }
303 +
304 + public void changedContainerWidth() {
305 + mXData.changedContainerSize();
306 + }
307 +
308 + public void changedContainerHeight() {
309 + mYData.changedContainerSize();
310 + }
311 +
312 + public String getCurrentTitle() {
313 + return getTitle();
314 + }
315 +
316 + public IFloaterPanelMoveAndSize[] getAllFloaters() {
317 + SizeableFloater[] zFloaters = getContainerPanel().getFloatersSortedByTitle();
318 + List<IFloaterPanelMoveAndSize> zList = new ArrayList<IFloaterPanelMoveAndSize>( zFloaters.length );
319 +
320 + for ( SizeableFloater zFloater : zFloaters ) {
321 + if ( zFloater instanceof IFloaterPanelMoveAndSize ) {
322 + zList.add( (IFloaterPanelMoveAndSize) zFloater );
323 + }
324 + }
325 + return zList.toArray( new IFloaterPanelMoveAndSize[zList.size()] );
326 + }
327 +
328 + public void setActive() {
329 + getContainerPanel().makeTop( this );
330 + }
331 +
332 + public String getRegisteredFactoryName() {
333 + return null;
334 + }
335 +
336 + public boolean isChromed() {
337 + return mChromed;
338 + }
339 +
340 + public void setChromed( boolean pChromed ) {
341 + if ( mChromed != pChromed ) {
342 + if ( mChromed ) {
343 + hideBorder();
344 + } else {
345 + restoreBorder();
346 + }
347 + fireChromeChanged();
348 + }
349 + }
350 +
351 + public boolean isPinned() {
352 + return mPinned;
353 + }
354 +
355 + public void setPinned( boolean pPinned ) {
356 + if ( mPinned != pPinned ) {
357 + LLsetPinned( pPinned );
358 + }
359 + }
360 +
361 + public boolean isRightAnchor() {
362 + return mXData.isAnchored();
363 + }
364 +
365 + public void setRightAnchor( boolean pRightAnchor ) {
366 + mXData.possiblySetAnchored( pRightAnchor );
367 + }
368 +
369 + public boolean isBottomAnchor() {
370 + return mYData.isAnchored();
371 + }
372 +
373 + public void setBottomAnchor( boolean pBottomAnchor ) {
374 + mYData.possiblySetAnchored( pBottomAnchor );
375 + }
376 +
377 + public void moveN( int pPixels ) {
378 + chromeAwareAdjustPosTopBy( pPixels, -pPixels );
379 + }
380 +
381 + public void moveE( int pPixels ) {
382 + chromeAwareAdjustPosLeftBy( pPixels, pPixels );
383 + }
384 +
385 + public void moveW( int pPixels ) {
386 + chromeAwareAdjustPosLeftBy( pPixels, -pPixels );
387 + }
388 +
389 + public void moveS( int pPixels ) {
390 + chromeAwareAdjustPosTopBy( pPixels, pPixels );
391 + }
392 +
393 + public void moveNW( int pPixels ) {
394 + moveN( pPixels );
395 + moveW( pPixels );
396 + }
397 +
398 + public void moveNE( int pPixels ) {
399 + moveN( pPixels );
400 + moveE( pPixels );
401 + }
402 +
403 + public void moveSW( int pPixels ) {
404 + moveS( pPixels );
405 + moveW( pPixels );
406 + }
407 +
408 + public void moveSE( int pPixels ) {
409 + moveS( pPixels );
410 + moveE( pPixels );
411 + }
412 +
413 + public void moveToMaxN() {
414 + chromeAwareAdjustPosTopBy( -MAX_RESOLUTION_SUPPORTED );
415 + }
416 +
417 + public void moveToMaxE() {
418 + chromeAwareAdjustPosLeftBy( MAX_RESOLUTION_SUPPORTED );
419 + }
420 +
421 + public void moveToMaxW() {
422 + chromeAwareAdjustPosLeftBy( -MAX_RESOLUTION_SUPPORTED );
423 + }
424 +
425 + public void moveToMaxS() {
426 + chromeAwareAdjustPosTopBy( MAX_RESOLUTION_SUPPORTED );
427 + }
428 +
429 + public void moveToMaxNW() {
430 + moveToMaxN();
431 + moveToMaxW();
432 + }
433 +
434 + public void moveToMaxNE() {
435 + moveToMaxN();
436 + moveToMaxE();
437 + }
438 +
439 + public void moveToMaxSW() {
440 + moveToMaxS();
441 + moveToMaxW();
442 + }
443 +
444 + public void moveToMaxSE() {
445 + moveToMaxS();
446 + moveToMaxE();
447 + }
448 +
449 + public void increaseWidthBy( int pPixels ) {
450 + chromeAwareAdjustWidthBy( pPixels, pPixels );
451 + }
452 +
453 + public void decreaseWidthBy( int pPixels ) {
454 + chromeAwareAdjustWidthBy( pPixels, -pPixels );
455 + }
456 +
457 + public void increaseHeightBy( int pPixels ) {
458 + chromeAwareAdjustHeightBy( pPixels, pPixels );
459 + }
460 +
461 + public void decreaseHeightBy( int pPixels ) {
462 + chromeAwareAdjustHeightBy( pPixels, -pPixels );
463 + }
464 +
465 + public void expandToMaxWidth() {
466 + setWidth( MAX_RESOLUTION_SUPPORTED );
467 + }
468 +
469 + public void expandToMaxHeight() {
470 + setHeight( MAX_RESOLUTION_SUPPORTED );
471 + }
472 +
473 + public void setWidth( int pNewWidth ) {
474 + removePositionLock();
475 + setWidth( "" + chromeAwareConstrainWidth( pNewWidth ) );
476 + }
477 +
478 + public void setHeight( int pNewHeight ) {
479 + removePositionLock();
480 + setHeight( "" + chromeAwareConstrainHeight( pNewHeight ) );
481 + }
482 +
483 + private void chromeAwareAdjustPosTopBy( int pPixels, int pDirectionPixels ) {
484 + if ( pPixels > 0 ) {
485 + chromeAwareAdjustPosTopBy( pDirectionPixels );
486 + }
487 + }
488 +
489 + private void chromeAwareAdjustPosTopBy( int pDirectionPixels ) {
490 + removePositionLock();
491 + setPosTop( chromeAwareConstrainPosTop( getPosTop() + pDirectionPixels ) );
492 + }
493 +
494 + private void chromeAwareAdjustPosLeftBy( int pPixels, int pDirectionPixels ) {
495 + if ( pPixels > 0 ) {
496 + chromeAwareAdjustPosLeftBy( pDirectionPixels );
497 + }
498 + }
499 +
500 + private void chromeAwareAdjustPosLeftBy( int pDirectionPixels ) {
501 + removePositionLock();
502 + setPosLeft( chromeAwareConstrainPosLeft( getPosLeft() + pDirectionPixels ) );
503 + }
504 +
505 + private void chromeAwareAdjustWidthBy( int pPixels, int pDirectionPixels ) {
506 + if ( pPixels > 0 ) {
507 + chromeAwareAdjustWidthBy( pDirectionPixels );
508 + }
509 + }
510 +
511 + private void chromeAwareAdjustWidthBy( int pDirectionPixels ) {
512 + setWidth( getOffsetWidth() + pDirectionPixels );
513 + }
514 +
515 + private void chromeAwareAdjustHeightBy( int pPixels, int pDirectionPixels ) {
516 + if ( pPixels > 0 ) {
517 + chromeAwareAdjustHeightBy( pDirectionPixels );
518 + }
519 + }
520 +
521 + private void chromeAwareAdjustHeightBy( int pDirectionPixels ) {
522 + setHeight( getOffsetHeight() + pDirectionPixels );
523 + }
524 +
525 + private int getChromeAwareMaxPotentialWidth() {
526 + return getMaxPotentialWidth() + (isChromed() ? 0 : BORDER_R_W);
527 + }
528 +
529 + private int chromeAwareConstrainPosLeft( int pPosLeft ) {
530 + int zMaxPosLeft = getChromeAwareMaxPotentialWidth() - getOffsetWidth();
531 + if ( pPosLeft > zMaxPosLeft ) {
532 + pPosLeft = zMaxPosLeft;
533 + }
534 +
535 + int zMinPosLeft = isChromed() ? 0 : -BORDER_L_W;
536 + if ( pPosLeft < zMinPosLeft ) {
537 + pPosLeft = zMinPosLeft;
538 + }
539 +
540 + return pPosLeft;
541 + }
542 +
543 + private int chromeAwareConstrainWidth( int pWidth ) {
544 + int zMaxWidth = getChromeAwareMaxPotentialWidth() - getPosLeft();
545 + if ( pWidth > zMaxWidth ) {
546 + pWidth = zMaxWidth;
547 + }
548 +
549 + int zMinWidth = getMinContentWidth() + (isChromed() ? 0 : BORDER_L_W + BORDER_R_W);
550 + if ( pWidth < zMinWidth ) {
551 + pWidth = zMinWidth;
552 + }
553 +
554 + return pWidth;
555 + }
556 +
557 + private int getChromeAwareMaxPotentialHeight() {
558 + return getMaxPotentialHeight() + (isChromed() ? 0 : BORDER_B_H);
559 + }
560 +
561 + private int chromeAwareConstrainPosTop( int pPosTop ) {
562 + int zMaxPosTop = getChromeAwareMaxPotentialHeight() - getOffsetHeight();
563 + if ( pPosTop > zMaxPosTop ) {
564 + pPosTop = zMaxPosTop;
565 + }
566 +
567 + int zMinPosTop = isChromed() ? 0 : -(BORDER_T_H + getTitleBarHeight());
568 + if ( pPosTop < zMinPosTop ) {
569 + pPosTop = zMinPosTop;
570 + }
571 +
572 + return pPosTop;
573 + }
574 +
575 + private int chromeAwareConstrainHeight( int pHeight ) {
576 + int zMaxHeight = getChromeAwareMaxPotentialHeight() - getPosTop();
577 + if ( pHeight > zMaxHeight ) {
578 + pHeight = zMaxHeight;
579 + }
580 +
581 + int zMinHeight =
582 + getMinContentHeight() + (isChromed() ? 0 : BORDER_T_H + getTitleBarHeight() + BORDER_B_H);
583 + if ( pHeight < zMinHeight ) {
584 + pHeight = zMinHeight;
585 + }
586 +
587 + return pHeight;
588 + }
589 +
590 + private int getMinContentWidth() {
591 + return 60; // todo: Will need to dynamically determine
592 + }
593 +
594 + private int getMinContentHeight() {
595 + return 40; // todo: Will need to dynamically determine
596 + }
597 +
598 + protected int getMaxPotentialWidth() {
599 + SizeableFloatableContainerPanel containerPanel = getContainerPanel();
600 + if ( containerPanel != null ) {
601 + if ( containerPanel.getOffsetHeight() > 20 ) {
602 + return containerPanel.getOffsetWidth();
603 + }
604 + }
605 + return super.getMaxPotentialWidth();
606 + }
607 +
608 + protected int getMaxPotentialHeight() {
609 + SizeableFloatableContainerPanel containerPanel = getContainerPanel();
610 + if ( containerPanel != null ) {
611 + if ( containerPanel.getOffsetHeight() > 20 ) {
612 + return containerPanel.getOffsetHeight();
613 + }
614 + }
615 + return super.getMaxPotentialHeight();
616 + }
617 +
618 + private SizeableFloatableContainerPanel getContainerPanel() {
619 + Widget zParent = getParent();
620 + return (zParent instanceof SizeableFloatableContainerPanel) ?
621 + (SizeableFloatableContainerPanel) zParent : null;
622 + }
623 +
624 + public void hideFloater() {
625 + Element zBorderElement = DOM.getParent( getStyleElement() );
626 + setStyleName( zBorderElement, REGULAR_BORDER, false );
627 + setStyleName( zBorderElement, CLEAR_BORDER, false );
628 + setStyleName( zBorderElement, HIDDEN_FLOATER, true );
629 + mHidden = true;
630 + setVisible( false );
631 + }
632 +
633 + public void showFloater() {
634 + Element zBorderElement = DOM.getParent( getStyleElement() );
635 + setStyleName( zBorderElement, HIDDEN_FLOATER, false );
636 + setBorderStyle( mChromed );
637 + mHidden = false;
638 + setVisible( true );
639 + }
640 +
641 + public boolean isHidden() {
642 + return mHidden;
643 + }
644 +
645 + public void hideBorder() {
646 + if ( mChromed ) {
647 + getTitleBar().hide();
648 + teardownRegularBorder();
649 + setupClearBorder();
650 + }
651 + }
652 +
653 + public void restoreBorder() {
654 + if ( !mChromed ) {
655 + getTitleBar().unhide();
656 + teardownClearBorder();
657 + setupRegularBorder();
658 + }
659 + }
660 +
661 + private void setupClearBorder() {
662 + setBorderStyle( false );
663 + }
664 +
665 + private void teardownClearBorder() {
666 + }
667 +
668 + private void setupRegularBorder() {
669 + setBorderStyle( true );
670 + mTitleBarPanel.addController( mDragController );
671 + }
672 +
673 + private void teardownRegularBorder() {
674 + mTitleBarPanel.removeController( mDragController );
675 + }
676 +
677 + protected void setBorderStyle( boolean pNewState ) {
678 + mChromed = pNewState;
679 + Element zBorderElement = DOM.getParent( getStyleElement() );
680 + setStyleName( zBorderElement, REGULAR_BORDER, mChromed );
681 + setStyleName( zBorderElement, CLEAR_BORDER, !mChromed );
682 + }
683 +
684 + private void forceToFront() {
685 + if ( isChromed() ) {
686 + SizeableFloatableContainerPanel containerPanel = getContainerPanel();
687 + if ( containerPanel != null ) {
688 + containerPanel.makeTop( this );
689 + }
690 + }
691 + }
692 +
693 + public void addListener( ChromeListener listener ) {
694 + if ( mListeners == null ) {
695 + mListeners = new ArrayList<ChromeListener>();
696 + }
697 + assert !mListeners.contains( listener );
698 + mListeners.add( listener );
699 + }
700 +
701 + public void removeListener( ChromeListener listener ) {
702 + if ( mListeners != null ) {
703 + assert mListeners.contains( listener );
704 + mListeners.remove( listener );
705 + }
706 + }
707 +
708 + protected void fireChromeChanged() {
709 + if ( mListeners != null && mListeners.size() > 0 ) {
710 + ChromeListener[] listeners = mListeners.toArray( new ChromeListener[mListeners.size()] );
711 + for ( ChromeListener listener : listeners ) {
712 + listener.chromeChanged( this );
713 + }
714 + }
715 + }
716 +
717 + private class BringToFrontGesture extends DragGestureWrapper {
718 + public BringToFrontGesture( DragGesture delegate ) {
719 + super( delegate );
720 + }
721 +
722 + public void start( MouseEvent e ) {
723 + forceToFront();
724 + super.start( e );
725 + }
726 + }
727 + }