litesoft
@ 948
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / widget / dialog / PopUpDialogBox.java
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 |
package com.temp.client.foundation.widget.dialog; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; import com.temp.client.foundation.widget.*; import com.temp.shared.utils.*; import java.util.*; public class PopUpDialogBox extends DialogBox { private static final int POPUP_CONTENTS_HEIGHT_PX = 400; private static final String HEADER_STYLE_NAME = "popUpDialogBox-header"; private static final String HEADER_CONTENTS_STYLE_NAME = "popUpDialogBox-header-contents"; private static final String TITLE_STYLE_NAME = "popUpDialogBox-title"; private static final String CONTENTS_STYLE_NAME = "popUpDialogBox-contents"; private VerticalPanel contentsPanel = new VerticalPanel(); private VerticalPanel headerWidgetPanel = new VerticalPanel(); private ScrollPanel contentsScrollPanel = new ScrollPanel( contentsPanel ); private int contentsPanelInitialSize = 0; private VerticalPanel mainPanel = new VerticalPanel(); private Label titleLabel = new Label(); private boolean donotScroll = false; public PopUpDialogBox() { this( null, false, false, true ); } public PopUpDialogBox( boolean donotScroll ) { this( null, donotScroll, false, true ); } public PopUpDialogBox( Widget headerWidget ) { this( headerWidget, false, false, true ); } public PopUpDialogBox( Widget headerWidget, boolean donotScroll, boolean showCloseButton ) { this( headerWidget, donotScroll, false, showCloseButton ); } // todo: headerWidget never used! public PopUpDialogBox( Widget headerWidget, boolean donotScroll, boolean noHeader, boolean showCloseButton ) { if ( !noHeader ) { titleLabel.setStylePrimaryName( TITLE_STYLE_NAME ); HorizontalPanel titleDownloadPanel = new HorizontalPanel(); titleDownloadPanel.add( titleLabel ); titleDownloadPanel.setCellVerticalAlignment( titleLabel, HasVerticalAlignment.ALIGN_BOTTOM ); titleDownloadPanel.add( headerWidgetPanel ); titleDownloadPanel.setCellVerticalAlignment( headerWidgetPanel, HasVerticalAlignment.ALIGN_BOTTOM ); ButtonBase closeButton = new OurPushButton( "x" ).add( new ClickHandler() { public void onClick( ClickEvent e ) { hide(); } } ); closeButton.setVisible( showCloseButton ); HorizontalPanel headerContents = new HorizontalPanel(); headerContents.setWidth( "100%" ); headerContents.setStylePrimaryName( HEADER_CONTENTS_STYLE_NAME ); headerContents.add( titleDownloadPanel ); headerContents.add( new LeftRightSiblings() ); headerContents.add( closeButton ); headerContents.setCellVerticalAlignment( closeButton, HasVerticalAlignment.ALIGN_MIDDLE ); HorizontalPanel headerPanel = new HorizontalPanel(); headerPanel.setWidth( "100%" ); headerPanel.setStylePrimaryName( HEADER_STYLE_NAME ); headerPanel.add( headerContents ); contentsPanel.setStylePrimaryName( CONTENTS_STYLE_NAME ); contentsPanel.setWidth( "100%" ); mainPanel.add( headerPanel ); mainPanel.setCellHorizontalAlignment( headerPanel, HasHorizontalAlignment.ALIGN_CENTER ); } if ( donotScroll ) { mainPanel.add( contentsPanel ); mainPanel.setCellHorizontalAlignment( contentsPanel, HasHorizontalAlignment.ALIGN_CENTER ); } else { contentsScrollPanel.setHeight( "" + POPUP_CONTENTS_HEIGHT_PX + "px" ); mainPanel.add( contentsScrollPanel ); mainPanel.setCellHorizontalAlignment( contentsScrollPanel, HasHorizontalAlignment.ALIGN_CENTER ); } mainPanel.setWidth( "100%" ); setWidget( mainPanel ); setAnimationEnabled( true ); setGlassEnabled( true ); hide(); contentsPanelInitialSize = contentsPanel.getElement().getOffsetHeight(); } protected void setHeaderWidget( Widget headerWidget ) { headerWidgetPanel.clear(); if ( headerWidget != null ) { headerWidgetPanel.add( headerWidget ); } } protected void setContentsAndShow( String title, List<Widget> contents ) { setContentsAndShow( title, (contents == null) ? null : contents.toArray( new Widget[contents.size()] ) ); } protected void setContentsAndShow( String title, Widget... contents ) { setContents( title, contents ); centerAndShow(); } public void centerAndShow() { setPopupPositionAndShow( new PositionCallback() { @Override public void setPosition( int offsetWidth, int offsetHeight ) { int left = (Window.getClientWidth() - offsetWidth) / 2; int top = (Window.getClientHeight() - offsetHeight) / 2; setPopupPosition( left, top ); } } ); final Timer resizeTimer = new Timer() { public void run() { if ( resizeViewPanel() ) { cancel(); } } }; resizeTimer.scheduleRepeating( 100 ); } private void recenter() { int left = (Window.getClientWidth() - getElement().getClientWidth()) / 2; int top = (Window.getClientHeight() - getElement().getClientHeight()) / 2; setPopupPosition( left, top ); } private boolean resizeViewPanel() { Element e = contentsPanel.getElement(); int contentsHeight = e.getOffsetHeight(); if ( contentsHeight <= contentsPanelInitialSize ) { return false; } if ( contentsHeight >= POPUP_CONTENTS_HEIGHT_PX ) { int scrollPanelWidth = e.getOffsetWidth(); scrollPanelWidth += 20; contentsScrollPanel.setWidth( "" + scrollPanelWidth + "px" ); recenter(); } return true; } protected void setContents( String title, Widget... contents ) { if ( donotScroll ) { contentsPanel.setWidth( "" ); } else { contentsScrollPanel.setWidth( "" ); } setTitle( title ); contentsPanel.clear(); if ( contents != null ) { for ( Widget c : contents ) { contentsPanel.add( c ); } } } public void setTitle( String title ) { if ( !StringUtils.isBlank( title ) ) { titleLabel.setText( title ); } else { titleLabel.setText( "" ); } } } |