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 import org.opensubsystems.core.util.GlobalConstants; 40 41 49 public class CharacterPadDialog extends SWTThickClientDialogGuiImpl 50 { 51 53 57 protected Set m_setListeners = new HashSet (); 58 59 62 protected CharacterPad m_chpad = null; 63 64 67 protected String m_initialText = null; 68 69 72 protected int m_iCancelButtonId; 73 74 76 91 public void displayDialog( 92 ThickClient client, 93 String strTitle, 94 String strFirstLineText, 95 String [] arSpecialButtonText, 96 CharacterPad.CharacterPadLayout keyboardLayout, 97 int strMaxTextLength, 98 String strInitialText, 99 boolean bBigButtons, 100 CharacterPadListener specialButtonListener 101 ) 102 { 103 createDialogWindow(client, strTitle, 104 SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); 105 displayDialog(strFirstLineText, arSpecialButtonText, keyboardLayout, 106 strMaxTextLength, strInitialText, bBigButtons, 107 specialButtonListener); 108 } 109 110 125 public void displayDialog( 126 ThickClientDialog parentDialog, 127 String strTitle, 128 String strFirstLineText, 129 String [] arSpecialButtonText, 130 CharacterPad.CharacterPadLayout keyboardLayout, 131 int strMaxTextLength, 132 String strInitialText, 133 boolean bBigButtons, 134 CharacterPadListener specialButtonListener 135 ) 136 { 137 createDialogWindow( 138 parentDialog.getClient(), 139 ((SWTThickClientDialogGuiImpl)parentDialog.getGui()).getShell(), 140 strTitle, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); 141 142 displayDialog(strFirstLineText, arSpecialButtonText, keyboardLayout, 143 strMaxTextLength, strInitialText, bBigButtons, 144 specialButtonListener); 145 } 146 147 152 public void setText( 153 String initialText 154 ) 155 { 156 if (GlobalConstants.ERROR_CHECKING) 157 { 158 assert m_chpad != null : "CharacterPad not created"; 159 } 160 161 m_chpad.setInitialText(initialText); 162 } 163 164 170 171 public boolean setTextLimit( 172 int iLimit 173 ) 174 { 175 if (m_chpad != null) 176 { 177 return m_chpad.setTextLimit(iLimit); 178 } 179 return false; 180 } 181 182 187 public void addCharacterPadListener( 188 CharacterPadListener listener 189 ) 190 { 191 m_setListeners.add(listener); 192 } 193 194 199 public void removeCharacterPadListener( 200 CharacterPadListener listener 201 ) 202 { 203 m_setListeners.remove(listener); 204 } 205 206 208 221 protected void displayDialog( 222 String strFirstLineText, 223 String [] arSpecialButtonText, 224 CharacterPad.CharacterPadLayout keyboardLayout, 225 int strMaxTextLength, 226 String strInitialText, 227 boolean bBigButtons, 228 CharacterPadListener specialButtonListener 229 ) 230 { 231 Point bugfixSize = createClientArea(strFirstLineText, arSpecialButtonText, 232 keyboardLayout, 233 CharacterPad.CHP_UPPERCASE 234 | CharacterPad.CHP_SWITCHTOLOWERCASE, 235 bBigButtons); 236 237 addCharacterPadListener(specialButtonListener); 238 setTextLimit(strMaxTextLength); 240 setText(strInitialText); 241 242 displayDialogWindow(null); 243 244 System.out.println("bugfixSize " + bugfixSize); 247 Rectangle clientArea; 248 Point shellSize; 249 250 clientArea = m_shell.getClientArea(); 251 if (bugfixSize.x < clientArea.width) 252 { 253 bugfixSize.x = clientArea.width; 254 } 255 if (bugfixSize.y < clientArea.height) 256 { 257 bugfixSize.y = clientArea.height; 258 } 259 shellSize = m_shell.getSize(); 260 System.out.println("shellSize " + shellSize); 261 bugfixSize.x += 2 * (shellSize.x - clientArea.width); 262 bugfixSize.y += (shellSize.y - clientArea.height); 263 System.out.println("new bugfixSize " + bugfixSize); 264 m_shell.setSize(bugfixSize); 265 267 interactWithUser(); 268 } 269 270 290 protected Point createClientArea( 291 String strFirstLineText, 292 String [] specialButtons, 293 CharacterPad.CharacterPadLayout keyboardLayout, 294 int specialFlags, 295 boolean bBigButtons 296 ) 297 { 298 299 String [] extendedButtons; 301 302 if (specialButtons != null) 303 { 304 extendedButtons = new String [specialButtons.length + 1]; 305 System.arraycopy(specialButtons, 0, extendedButtons, 0, 306 specialButtons.length); 307 } 308 else 309 { 310 extendedButtons = new String [1]; 311 } 312 extendedButtons[extendedButtons.length - 1] = "Cancel"; 313 m_iCancelButtonId = extendedButtons.length - 1; 314 315 m_shell.setLayout(new FormLayout()); 316 317 Label textLabel = new Label(m_shell, SWT.NONE); 318 textLabel.setText(strFirstLineText); 319 ResourceManager.getInstance().setBigLabelFont(textLabel); 320 FormData textLabelData = new FormData(); 321 textLabelData.top = new FormAttachment(0, 5); 322 textLabelData.left = new FormAttachment(0, 5); 323 textLabelData.right = new FormAttachment(100, -5); 324 textLabel.setLayoutData(textLabelData); 325 326 m_chpad = new CharacterPad(m_shell, SWT.NONE, extendedButtons, 327 keyboardLayout, specialFlags, bBigButtons); 328 329 FormData chpadData; 330 Point preferredSize; 331 332 preferredSize = m_chpad.getPreferredSize(); 333 chpadData = new FormData(preferredSize.x, preferredSize.y); 334 chpadData.top = new FormAttachment(textLabel, 5); 335 chpadData.left = new FormAttachment(textLabel, 0, SWT.LEFT); 336 chpadData.bottom = new FormAttachment(100, -5); 337 chpadData.right = new FormAttachment(textLabel, 0, SWT.RIGHT); 338 m_chpad.setLayoutData(chpadData); 339 m_chpad.addCharacterPadListener(new CharacterPadListener() 340 { 341 public boolean takeAction( 342 CharacterPad chpad, 343 int numberValue, 344 String strButtonName, 345 String strText 346 ) 347 { 348 boolean bShouldClose = true; 349 350 if (numberValue != m_iCancelButtonId) 351 { 352 if ((strText == null) || (strText.length() == 0)) 353 { 354 strText = ""; 355 } 356 for (Iterator items = m_setListeners.iterator(); items.hasNext();) 357 { 358 bShouldClose &= ((CharacterPadListener) items.next()).takeAction( 359 chpad, numberValue, strButtonName, strText); 360 } 361 } 362 363 if (bShouldClose) 364 { 365 m_shell.close(); 366 } 367 368 return bShouldClose; 369 } 370 }); 371 372 return m_chpad.computeSize(SWT.DEFAULT, SWT.DEFAULT); 373 } 374 } 375 | Popular Tags |