| 1 21 22 package org.opensubsystems.core.application.swt; 23 24 import org.eclipse.swt.graphics.Image; 25 import org.eclipse.swt.graphics.Point; 26 import org.eclipse.swt.graphics.Rectangle; 27 import org.eclipse.swt.widgets.Display; 28 import org.eclipse.swt.widgets.Shell; 29 import org.opensubsystems.core.application.ThickClient; 30 import org.opensubsystems.core.application.ThickClientDialog; 31 import org.opensubsystems.core.application.ThickClientDialogGui; 32 import org.opensubsystems.core.util.GlobalConstants; 33 34 42 public abstract class SWTThickClientDialogGuiImpl implements ThickClientDialogGui 43 { 44 46 49 protected ThickClient m_client; 50 51 54 protected Shell m_shell; 55 56 60 protected Shell m_parent; 61 62 69 protected Rectangle m_outsideBoundingArea; 70 71 74 protected Point m_oldClientLocation; 75 76 78 81 public Object displayMessage( 82 String strTitle, 83 String strMessage, 84 Object additionalInfo 85 ) 86 { 87 return ((SWTThickClientGui)m_client.getGui()).displayMessage(m_shell, 88 strTitle, strMessage, 89 additionalInfo); 90 } 91 92 97 public ThickClient getClient() 98 { 99 return m_client; 100 } 101 102 107 public Shell getShell( 108 ) 109 { 110 return m_shell; 111 } 112 113 115 122 protected void createDialogWindow( 123 ThickClient client, 124 String strTitle, 125 int iStyle 126 ) 127 { 128 SWTThickClientGui gui = (SWTThickClientGui)client.getGui(); 129 Shell parentShell = gui.getShell(); 130 131 createDialogWindow(client, parentShell, strTitle, iStyle); 132 } 134 135 142 protected void createDialogWindow( 143 ThickClientDialog dialog, 144 String strTitle, 145 int iStyle 146 ) 147 { 148 ThickClient client; 149 ThickClientDialog parentDialog; 150 Shell parentShell = null; 151 152 client = dialog.getClient(); 153 parentDialog = dialog.getParentDialog(); 154 if (parentDialog != null) 155 { 156 SWTThickClientDialogGuiImpl gui; 157 158 gui = (SWTThickClientDialogGuiImpl)parentDialog.getGui(); 161 parentShell = gui.getShell(); 162 } 163 else 164 { 165 SWTThickClientGui gui; 168 169 gui = (SWTThickClientGui)client.getGui(); 170 if (gui != null) 171 { 172 parentShell = gui.getShell(); 173 } 174 } 175 createDialogWindow(client, parentShell, strTitle, iStyle); 176 } 177 178 186 protected void createDialogWindow( 187 ThickClient client, 188 Shell parentShell, 189 String strTitle, 190 int iStyle 191 ) 192 { 193 m_client = client; 194 m_parent = parentShell; 195 196 SWTThickClientGui gui = (SWTThickClientGui)m_client.getGui(); 197 Image iconImage = gui.getIconImage(); 198 Display display = gui.getDisplay(); 199 200 if (m_parent == null) 201 { 202 m_shell = new Shell(display, iStyle); 203 } 204 else 205 { 206 m_shell = new Shell(parentShell, iStyle); 207 208 Shell clientAreaShell; 213 214 clientAreaShell = gui.getShell(); 215 if (clientAreaShell != parentShell) 218 { 219 if (clientAreaShell == null) 224 { 225 m_outsideBoundingArea = gui.determineClientArea(display, 226 m_client.getScreenPosition(), 227 m_client.isFixedSize()); 228 } 229 else 230 { 231 m_outsideBoundingArea = ShellUtils.getAdjustedClientArea( 239 clientAreaShell); 240 } 241 } 242 } 243 244 ResourceManager.getInstance().setDefaultCursor(m_shell); 247 if (iconImage != null) 248 { 249 m_shell.setImage(iconImage); 250 } 251 m_shell.setText(strTitle); 252 } 253 254 261 protected void displayDialogWindow( 262 Point ptSize 263 ) 264 { 265 displayDialogWindow(ptSize, m_outsideBoundingArea); 266 } 267 268 286 private void displayDialogWindow( 287 Point ptSize, 288 Rectangle outsideBoundingArea 289 ) 290 { 291 SWTThickClientGui gui = (SWTThickClientGui)m_client.getGui(); 292 Display display = gui.getDisplay(); 293 294 m_shell.pack(true); 295 if (ptSize != null) 296 { 297 m_shell.setSize(ptSize); 298 } 299 300 if (m_parent == null) 301 { 302 Rectangle area = null; 303 304 area = gui.determineClientArea(display, 305 m_client.getScreenPosition(), 306 m_client.isFixedSize()); 307 ShellUtils.centerShell(m_shell, area); 308 } 309 else 310 { 311 if (outsideBoundingArea == null) 312 { 313 ShellUtils.centerShell(m_shell, m_parent); 314 } 315 else 316 { 317 m_oldClientLocation = ShellUtils.centerParentChilShells(m_parent, 318 m_shell, outsideBoundingArea); 319 } 320 } 321 322 m_shell.open(); 323 } 324 325 329 protected void interactWithUser( 330 ) 331 { 332 try 333 { 334 SWTThickClientGui gui = (SWTThickClientGui)m_client.getGui(); 335 Display display = gui.getDisplay(); 336 337 while (!m_shell.isDisposed()) 338 { 339 if (!display.readAndDispatch()) 340 { 341 display.sleep(); 342 } 343 } 344 } 345 finally 346 { 347 if (m_oldClientLocation != null) 349 { 350 if (GlobalConstants.ERROR_CHECKING) 351 { 352 assert m_parent != null 353 : "If old location is initialized parent has to be as well."; 354 } 355 356 m_parent.setLocation(m_oldClientLocation); 357 } 358 } 359 } 360 } 361 | Popular Tags |