📄 window.java
字号:
} } if (nonDisposedImages.size() <= 0) { System.err.println("Window.configureShell: images disposed"); //$NON-NLS-1$ } else { Image[] array = new Image[nonDisposedImages.size()]; nonDisposedImages.toArray(array); newShell.setImages(array); } } Layout layout = getLayout(); if (layout != null) { newShell.setLayout(layout); } } /** * Creates the layout for the shell. The layout created here will be * attached to the composite passed into createContents. The default * implementation returns a GridLayout with no margins. Subclasses that * change the layout type by overriding this method should also override * createContents. * * <p> * A return value of null indicates that no layout should be attached to the * composite. In this case, the layout may be attached within * createContents. * </p> * * @return a newly created Layout or null if no layout should be attached. * @since 3.0 */ protected Layout getLayout() { GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; return layout; } /** * Constrain the shell size to be no larger than the display bounds. * * @since 2.0 */ protected void constrainShellSize() { // limit the shell size to the display size Rectangle bounds = shell.getBounds(); Rectangle constrained = getConstrainedShellBounds(bounds); if (!bounds.equals(constrained)) { shell.setBounds(constrained); } } /** * Creates this window's widgetry in a new top-level shell. * <p> * The default implementation of this framework method creates this window's * shell (by calling <code>createShell</code>), and its controls (by * calling <code>createContents</code>), then initializes this window's * shell bounds (by calling <code>initializeBounds</code>). * </p> */ public void create() { shell = createShell(); contents = createContents(shell); //initialize the bounds of the shell to that appropriate for the // contents initializeBounds(); } /** * Creates and returns this window's contents. Subclasses may attach any * number of children to the parent. As a convenience, the return value of * this method will be remembered and returned by subsequent calls to * getContents(). Subclasses may modify the parent's layout if they overload * getLayout() to return null. * * <p> * It is common practise to create and return a single composite that * contains the entire window contents. * </p> * * <p> * The default implementation of this framework method creates an instance * of <code>Composite</code>. Subclasses may override. * </p> * * @param parent * the parent composite for the controls in this window. The type * of layout used is determined by getLayout() * * @return the control that will be returned by subsequent calls to * getContents() */ protected Control createContents(Composite parent) { // by default, just create a composite return new Composite(parent, SWT.NONE); } /** * Creates and returns this window's shell. * <p> * The default implementation of this framework method creates a new shell * and configures it using <code/>configureShell</code>. Rather than * override this method, subclasses should instead override * <code/>configureShell</code>. * </p> * * @return the shell */ protected final Shell createShell() { Shell newParent = getParentShell(); if(newParent != null && newParent.isDisposed()){ parentShell = new SameShellProvider(null); newParent = getParentShell();//Find a better parent } //Create the shell Shell newShell = new Shell(newParent, getShellStyle()); resizeListener = new Listener() { public void handleEvent(Event e) { resizeHasOccurred = true; } }; newShell.addListener(SWT.Resize, resizeListener); newShell.setData(this); //Add a listener newShell.addShellListener(getShellListener()); //Set the layout configureShell(newShell); //Register for font changes if (fontChangeListener == null) { fontChangeListener = new FontChangeListener(); } JFaceResources.getFontRegistry().addListener(fontChangeListener); return newShell; } /** * Returns the top level control for this window. The parent of this control * is the shell. * * @return the top level control, or <code>null</code> if this window's * control has not been created yet */ protected Control getContents() { return contents; } /** * Returns the default image. This is the image that will be used for * windows that have no shell image at the time they are opened. There is no * default image unless one is installed via <code>setDefaultImage</code>. * * @return the default image, or <code>null</code> if none * @see #setDefaultImage */ public static Image getDefaultImage() { return (defaultImages == null || defaultImages.length < 1) ? null : defaultImages[0]; } /** * Returns the array of default images to use for newly opened windows. It * is expected that the array will contain the same icon rendered at * different resolutions. * * @see org.eclipse.swt.widgets.Decorations#setImages(org.eclipse.swt.graphics.Image[]) * * @return the array of images to be used when a new window is opened * @see #setDefaultImages * @since 3.0 */ public static Image[] getDefaultImages() { return (defaultImages == null ? new Image[0] : defaultImages); } /** * Returns the initial location to use for the shell. The default * implementation centers the shell horizontally (1/2 of the difference to * the left and 1/2 to the right) and vertically (1/3 above and 2/3 below) * relative to the parent shell, or display bounds if there is no parent * shell. * * @param initialSize * the initial size of the shell, as returned by * <code>getInitialSize</code>. * @return the initial location of the shell */ protected Point getInitialLocation(Point initialSize) { Composite parent = shell.getParent(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if (parent != null) { monitor = parent.getMonitor(); } Rectangle monitorBounds = monitor.getClientArea(); Point centerPoint; if (parent != null) { centerPoint = Geometry.centerPoint(parent.getBounds()); } else { centerPoint = Geometry.centerPoint(monitorBounds); } return new Point(centerPoint.x - (initialSize.x / 2), Math.max( monitorBounds.y, Math.min(centerPoint.y - (initialSize.y * 2 / 3), monitorBounds.y + monitorBounds.height - initialSize.y))); } /** * Returns the initial size to use for the shell. The default implementation * returns the preferred size of the shell, using * <code>Shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true)</code>. * * @return the initial size of the shell */ protected Point getInitialSize() { return shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); } /** * Returns the most specific modal child from the given list of Shells. * * @param toSearch shells to search for modal children * @return the most specific modal child, or null if none * * @since 3.1 */ private static Shell getModalChild(Shell[] toSearch) { int modal = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL | SWT.PRIMARY_MODAL; for (int i = toSearch.length - 1; i >= 0; i--) { Shell shell = toSearch[i]; // Check if this shell has a modal child Shell[] children = shell.getShells(); Shell modalChild = getModalChild(children); if (modalChild != null) { return modalChild; } // If not, check if this shell is modal itself if (shell.isVisible() && (shell.getStyle() & modal) != 0) { return shell; } } return null; } /** * Returns parent shell, under which this window's shell is created. * * @return the parent shell, or <code>null</code> if there is no parent * shell */ protected Shell getParentShell() { Shell parent = parentShell.getShell(); int modal = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL | SWT.PRIMARY_MODAL; if ((getShellStyle() & modal) != 0) { // If this is a modal shell with no parent, pick a shell using defaultModalParent. if (parent == null) { parent = defaultModalParent.getShell(); } } return parent; } /** * Returns this window's return code. A window's return codes are * window-specific, although two standard return codes are predefined: * <code>OK</code> and <code>CANCEL</code>. * * @return the return code */ public int getReturnCode() { return returnCode; } /** * Returns this window's shell. * * @return this window's shell, or <code>null</code> if this window's * shell has not been created yet */ public Shell getShell() { return shell; } /** * Returns a shell listener. This shell listener gets registered with this * window's shell. * <p> * The default implementation of this framework method returns a new * listener that makes this window the active window for its window manager * (if it has one) when the shell is activated, and calls the framework * method <code>handleShellCloseEvent</code> when the shell is closed. * Subclasses may extend or reimplement. * </p> * * @return a shell listener */ protected ShellListener getShellListener() { return new ShellAdapter() { public void shellClosed(ShellEvent event) { event.doit = false; // don't close now if (canHandleShellCloseEvent()) { handleShellCloseEvent(); } } }; } /** * Returns the shell style bits. * <p> * The default value is <code>SWT.CLOSE|SWT.MIN|SWT.MAX|SWT.RESIZE</code>. * Subclassers should call <code>setShellStyle</code> to change this * value, rather than overriding this method. * </p> * * @return the shell style bits */ protected int getShellStyle() { return shellStyle; } /** * Returns the window manager of this window. * * @return the WindowManager, or <code>null</code> if none */ public WindowManager getWindowManager() { return windowManager; } /** * Notifies of a font property change. * <p> * The default implementation of this framework method does nothing. * Subclasses may reimplement. * </p> * * @param event
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -