| 1 21 22 package org.opensubsystems.patterns.thickclient.application.swt; 23 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.graphics.Point; 30 import org.eclipse.swt.graphics.Rectangle; 31 import org.eclipse.swt.layout.FormAttachment; 32 import org.eclipse.swt.layout.FormData; 33 import org.eclipse.swt.layout.FormLayout; 34 import org.eclipse.swt.widgets.Label; 35 import org.opensubsystems.core.application.ThickClient; 36 import org.opensubsystems.core.application.ThickClientDialog; 37 import org.opensubsystems.core.application.swt.ResourceManager; 38 import org.opensubsystems.core.application.swt.SWTThickClientDialogGuiImpl; 39 40 48 public class NumberPadDialog extends SWTThickClientDialogGuiImpl 49 { 50 52 56 protected Set m_setListeners = new HashSet (); 57 58 61 protected String m_text = null; 62 63 66 protected NumberPad m_npad = null; 67 68 70 86 public void displayDialog( 87 ThickClient client, 88 String strTitle, 89 String strFirstLineText, 90 String strSpecialButtonText, 91 int strMaxTextLength, 92 String strInitialText, 93 boolean bBigButtons, 94 boolean bDecimalDot, 95 NumberPadListener specialButtonListener 96 ) 97 { 98 createDialogWindow(client, strTitle, 99 SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); 100 displayDialog(strFirstLineText, strSpecialButtonText, strMaxTextLength, 101 strInitialText, bBigButtons, bDecimalDot, 102 specialButtonListener); 103 } 104 105 121 public void displayDialog( 122 ThickClientDialog parentDialog, 123 String strTitle, 124 String strFirstLineText, 125 String strSpecialButtonText, 126 int strMaxTextLength, 127 String strInitialText, 128 boolean bBigButtons, 129 boolean bDecimalDot, 130 NumberPadListener specialButtonListener 131 ) 132 { 133 createDialogWindow( 134 parentDialog.getClient(), 135 ((SWTThickClientDialogGuiImpl)parentDialog.getGui()).getShell(), 136 strTitle, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); 137 138 displayDialog(strFirstLineText, strSpecialButtonText, strMaxTextLength, 139 strInitialText, bBigButtons, bDecimalDot, 140 specialButtonListener); 141 } 142 143 148 public String getText() 149 { 150 return m_text; 151 } 152 153 156 public void setText( 157 String string 158 ) 159 { 160 m_text = null; 161 if (m_npad != null) 162 { 163 m_npad.setText(string); 164 m_text = m_npad.getText(); 165 } 166 } 167 168 174 175 public boolean setTextLimit( 176 int iLimit 177 ) 178 { 179 if (m_npad != null) 180 { 181 return m_npad.setTextLimit(iLimit); 182 } 183 return false; 184 } 185 186 191 public void addNumberPadListener( 192 NumberPadListener listener 193 ) 194 { 195 m_setListeners.add(listener); 196 } 197 198 203 public void removeNumberPadListener( 204 NumberPadListener listener 205 ) 206 { 207 m_setListeners.remove(listener); 208 } 209 210 212 226 protected void displayDialog( 227 String strFirstLineText, 228 String strSpecialButtonText, 229 int strMaxTextLength, 230 String strInitialText, 231 boolean bBigButtons, 232 boolean bDecimalDot, 233 NumberPadListener specialButtonListener 234 ) 235 { 236 Point bugfixSize = createClientArea(strFirstLineText, strSpecialButtonText, 237 strInitialText, bBigButtons, 238 bDecimalDot); 239 addNumberPadListener(specialButtonListener); 240 setTextLimit(strMaxTextLength); 242 setText(strInitialText); 243 244 displayDialogWindow(null); 245 246 System.out.println("bugfixSize " + bugfixSize); 249 Rectangle clientArea; 250 Point shellSize; 251 252 clientArea = m_shell.getClientArea(); 253 if (bugfixSize.x < clientArea.width) 254 { 255 bugfixSize.x = clientArea.width; 256 } 257 if (bugfixSize.y < clientArea.height) 258 { 259 bugfixSize.y = clientArea.height; 260 } 261 shellSize = m_shell.getSize(); 262 System.out.println("shellSize " + shellSize); 263 bugfixSize.x += 2 * (shellSize.x - clientArea.width); 264 bugfixSize.y += (shellSize.y - clientArea.height); 265 System.out.println("new bugfixSize " + bugfixSize); 266 m_shell.setSize(bugfixSize); 267 269 interactWithUser(); 270 } 271 272 291 protected Point createClientArea( 292 String strFirstLineText, 293 String strSpecialButtonText, 294 String strInitialText, 295 boolean bBigButtons, 296 boolean bDecimalDot 297 ) 298 { 299 m_shell.setLayout(new FormLayout()); 300 301 Label loginLabel = new Label(m_shell, SWT.NONE); 302 loginLabel.setText(strFirstLineText); 303 ResourceManager.getInstance().setBigLabelFont(loginLabel); 304 FormData loginLabelData = new FormData(); 305 loginLabelData.top = new FormAttachment(0, 5); 306 loginLabelData.left = new FormAttachment(0, 5); 307 loginLabelData.right = new FormAttachment(100, -5); 308 loginLabel.setLayoutData(loginLabelData); 309 310 m_npad = new NumberPad(m_shell, SWT.NONE, strSpecialButtonText, 311 "Cancel", null, bBigButtons, bDecimalDot); 315 316 FormData npadData; 317 Point preferredSize; 318 319 preferredSize = m_npad.getPreferredSize(); 320 321 npadData = new FormData(preferredSize.x, preferredSize.y); 322 npadData.top = new FormAttachment(loginLabel, 5); 323 npadData.left = new FormAttachment(loginLabel, 0, SWT.LEFT); 324 npadData.bottom = new FormAttachment(100, -5); 325 npadData.right = new FormAttachment(loginLabel, 0, SWT.RIGHT); 326 m_npad.setLayoutData(npadData); 327 m_npad.addNumberPadListener(new NumberPadListener() 328 { 329 public boolean takeAction( 330 NumberPad npad, 331 String strText 332 ) 333 { 334 boolean bShouldClose = true; 335 336 if ((strText == null) || (strText.length() == 0)) 337 { 338 m_text = strText; 339 } 340 else 341 { 342 m_text = null; 343 } 344 345 for (Iterator items = m_setListeners.iterator(); items.hasNext();) 346 { 347 bShouldClose &= ((NumberPadListener)items.next()).takeAction( 348 npad, strText); 349 } 350 351 if (bShouldClose) 352 { 353 m_shell.close(); 354 } 355 356 return bShouldClose; 357 } 358 }); 359 360 return m_npad.computeSize(SWT.DEFAULT, SWT.DEFAULT); 361 } 362 } 363 | Popular Tags |