1 21 22 package org.opensubsystems.core.application.swt; 23 24 import org.eclipse.swt.events.FocusAdapter; 25 import org.eclipse.swt.events.FocusEvent; 26 import org.eclipse.swt.events.ShellAdapter; 27 import org.eclipse.swt.events.ShellEvent; 28 import org.eclipse.swt.graphics.Point; 29 import org.eclipse.swt.graphics.Rectangle; 30 import org.eclipse.swt.widgets.Shell; 31 import org.eclipse.swt.widgets.Table; 32 import org.opensubsystems.core.util.GlobalConstants; 33 34 42 public final class ShellUtils 43 { 44 46 50 public static final int SPACE_BETWEEN_DIALOGS = 10; 51 52 54 57 private ShellUtils( 58 ) 59 { 60 } 62 63 65 72 public static Rectangle getAdjustedClientArea( 73 Shell client 74 ) 75 { 76 Rectangle clientRect; 77 Point clientLocation; 78 79 clientRect = client.getClientArea(); 80 clientLocation = client.getLocation(); 81 82 clientRect.x = clientLocation.x; 83 clientRect.y = clientLocation.y; 84 85 return clientRect; 86 } 87 88 94 public static void centerShell( 95 Shell client, 96 Shell parent 97 ) 98 { 99 centerShell(client, getAdjustedClientArea(parent)); 100 } 101 102 108 public static void centerShell( 109 Shell client, 110 Rectangle parentRect 111 ) 112 { 113 Point clientSize; 114 115 clientSize = client.getSize(); 116 client.setLocation(parentRect.x + (parentRect.width - clientSize.x) / 2, 117 parentRect.y + (parentRect.height - clientSize.y) / 2); 118 } 119 120 127 public static void runAfterOpened( 128 final Shell window, 129 final Runnable startupCode 130 ) 131 { 132 window.addShellListener(new ShellAdapter() 137 { 138 public void shellActivated(ShellEvent e) 139 { 140 if (window.isVisible()) 143 { 144 startupCode.run(); 145 } 146 } 147 148 public void shellClosed(ShellEvent e) 149 { 150 window.removeShellListener(this); 151 } 152 }); 153 window.getShell().addFocusListener(new FocusAdapter() 155 { 156 public void focusLost(FocusEvent e) 157 { 158 startupCode.run(); 159 } 160 }); 161 } 162 163 176 public static Point centerParentChilShells( 177 Shell parent, 178 Shell dialog, 179 Rectangle outsideBoundingArea 180 ) 181 { 182 Rectangle client; 183 Point dialogSize; 184 Point oldClientLocation; 185 186 client = parent.getClientArea(); 187 dialogSize = dialog.getSize(); 188 oldClientLocation = parent.getLocation(); 189 190 int iFreeSpace; 191 iFreeSpace = outsideBoundingArea.height - dialogSize.y - client.height; 194 if (iFreeSpace < SPACE_BETWEEN_DIALOGS) 195 { 196 iFreeSpace = 0; 199 } 200 else 201 { 202 iFreeSpace = (iFreeSpace - SPACE_BETWEEN_DIALOGS) / 2; 205 } 206 207 parent.setLocation(oldClientLocation.x, outsideBoundingArea.y + iFreeSpace); 208 dialog.setLocation(outsideBoundingArea.x + (outsideBoundingArea.width 211 - dialogSize.x) / 2, 212 outsideBoundingArea.y + outsideBoundingArea.height 213 - dialogSize.y - iFreeSpace); 214 215 return oldClientLocation; 216 } 217 218 225 public static int getTableClientWidth( 226 Table source 227 ) 228 { 229 Rectangle area = source.getParent().getClientArea(); 230 int width = area.width - 2 * source.getBorderWidth(); 232 233 Point vBarSize = source.getVerticalBar().getSize(); 242 width -= vBarSize.x; 243 245 if (GlobalConstants.isLinux()) 246 { 247 width -= 3; 252 } 253 254 return width; 255 } 256 } 257 | Popular Tags |