⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 *            the property change event detailing what changed	 */	protected void handleFontChange(PropertyChangeEvent event) {		// do nothing	}	/**	 * Notifies that the window's close button was pressed, the close menu was	 * selected, or the ESCAPE key pressed.	 * <p>	 * The default implementation of this framework method sets the window's	 * return code to <code>CANCEL</code> and closes the window using	 * <code>close</code>. Subclasses may extend or reimplement.	 * </p>	 */	protected void handleShellCloseEvent() {		setReturnCode(CANCEL);		close();	}	/**	 * Initializes the location and size of this window's SWT shell after it has	 * been created.	 * <p>	 * This framework method is called by the <code>create</code> framework	 * method. The default implementation calls <code>getInitialSize</code>	 * and <code>getInitialLocation</code> and passes the results to	 * <code>Shell.setBounds</code>. This is only done if the bounds of the	 * shell have not already been modified. Subclasses may extend or	 * reimplement.	 * </p>	 */	protected void initializeBounds() {		if (resizeListener != null) {			shell.removeListener(SWT.Resize, resizeListener);		}		if (resizeHasOccurred) { // Check if shell size has been set already.			return;		}		Point size = getInitialSize();		Point location = getInitialLocation(size);		shell.setBounds(getConstrainedShellBounds(new Rectangle(location.x,				location.y, size.x, size.y)));	}	/**	 * Opens this window, creating it first if it has not yet been created.	 * <p>	 * If this window has been configured to block on open (	 * <code>setBlockOnOpen</code>), this method waits until the window is	 * closed by the end user, and then it returns the window's return code;	 * otherwise, this method returns immediately. A window's return codes are	 * window-specific, although two standard return codes are predefined:	 * <code>OK</code> and <code>CANCEL</code>.	 * </p>	 * 	 * @return the return code	 * 	 * @see #create()	 */	public int open() {        		if (shell == null || shell.isDisposed()) {            shell = null;			// create the window			create();		}		// limit the shell size to the display size		constrainShellSize();		// open the window		shell.open();		// run the event loop if specified		if (block) {			runEventLoop(shell);		}		return returnCode;	}	/**	 * Runs the event loop for the given shell.	 * 	 * @param loopShell	 *            the shell	 */	private void runEventLoop(Shell loopShell) {		//Use the display provided by the shell if possible		Display display;		if (shell == null) {			display = Display.getCurrent();		} else {			display = loopShell.getDisplay();		}		while (loopShell != null && !loopShell.isDisposed()) {			try {				if (!display.readAndDispatch()) {					display.sleep();				}			} catch (Throwable e) {				exceptionHandler.handleException(e);			}		}		display.update();	}	/**	 * Sets whether the <code>open</code> method should block until the window	 * closes.	 * 	 * @param shouldBlock	 *            <code>true</code> if the <code>open</code> method should	 *            not return until the window closes, and <code>false</code>	 *            if the <code>open</code> method should return immediately	 */	public void setBlockOnOpen(boolean shouldBlock) {		block = shouldBlock;	}	/**	 * Sets 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 this method.	 * 	 * @param image	 *            the default image, or <code>null</code> if none	 */	public static void setDefaultImage(Image image) {		defaultImages = image == null ? null : new Image[] { image };	}	/**	 * Sets 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[])	 * 	 * @param images	 *            the array of images to be used when this window is opened	 * @since 3.0	 */	public static void setDefaultImages(Image[] images) {		Image[] newArray = new Image[images.length];		System.arraycopy(images, 0, newArray, 0, newArray.length);		defaultImages = newArray;	}		/**     * Changes the parent shell. This is only safe to use when the shell is not     * yet realized (i.e., created). Once the shell is created, it must be     * disposed (i.e., closed) before this method can be called.     *      * @param newParentShell     *            The new parent shell; this value may be <code>null</code> if     *            there is to be no parent.     * @since 3.1     */    protected void setParentShell(final Shell newParentShell) {        Assert.isTrue((shell == null), "There must not be an existing shell."); //$NON-NLS-1$        parentShell = new SameShellProvider(newParentShell);    }	/**	 * Sets this window's return code. The return code is automatically returned	 * by <code>open</code> if block on open is enabled. For non-blocking	 * opens, the return code needs to be retrieved manually using	 * <code>getReturnCode</code>.	 * 	 * @param code	 *            the return code	 */	protected void setReturnCode(int code) {		returnCode = code;	}	/**	 * Returns the monitor whose client area contains the given point. If no	 * monitor contains the point, returns the monitor that is closest to the	 * point. If this is ever made public, it should be moved into a separate	 * utility class.	 * 	 * @param toSearch	 *            point to find (display coordinates)	 * @param toFind	 *            point to find (display coordinates)	 * @return the montor closest to the given point	 */	private static Monitor getClosestMonitor(Display toSearch, Point toFind) {		int closest = Integer.MAX_VALUE;		Monitor[] monitors = toSearch.getMonitors();		Monitor result = monitors[0];		for (int idx = 0; idx < monitors.length; idx++) {			Monitor current = monitors[idx];			Rectangle clientArea = current.getClientArea();			if (clientArea.contains(toFind)) {				return current;			}			int distance = Geometry.distanceSquared(Geometry					.centerPoint(clientArea), toFind);			if (distance < closest) {				closest = distance;				result = current;			}		}		return result;	}	/**	 * Given the desired position of the window, this method returns an adjusted	 * position such that the window is no larger than its monitor, and does not	 * extend beyond the edge of the monitor. This is used for computing the	 * initial window position, and subclasses can use this as a utility method	 * if they want to limit the region in which the window may be moved.	 * 	 * @param preferredSize	 *            the preferred position of the window	 * @return a rectangle as close as possible to preferredSize that does not	 *         extend outside the monitor	 * 	 * @since 3.0	 */	protected Rectangle getConstrainedShellBounds(Rectangle preferredSize) {		Rectangle result = new Rectangle(preferredSize.x, preferredSize.y,				preferredSize.width, preferredSize.height);		Monitor mon = getClosestMonitor(getShell().getDisplay(), Geometry				.centerPoint(result));		Rectangle bounds = mon.getClientArea();		if (result.height > bounds.height) {			result.height = bounds.height;		}		if (result.width > bounds.width) {			result.width = bounds.width;		}		result.x = Math.max(bounds.x, Math.min(result.x, bounds.x				+ bounds.width - result.width));		result.y = Math.max(bounds.y, Math.min(result.y, bounds.y				+ bounds.height - result.height));		return result;	}	/**	 * Sets the shell style bits. This method has no effect after the shell is	 * created.	 * <p>	 * The shell style bits are used by the framework method	 * <code>createShell</code> when creating this window's shell.	 * </p>	 * 	 * @param newShellStyle	 *            the new shell style bits	 */	protected void setShellStyle(int newShellStyle) {		shellStyle = newShellStyle;	}	/**	 * Sets the window manager of this window.	 * <p>	 * Note that this method is used by <code>WindowManager</code> to maintain	 * a backpointer. Clients must not call the method directly.	 * </p>	 * 	 * @param manager	 *            the window manager, or <code>null</code> if none	 */	public void setWindowManager(WindowManager manager) {		windowManager = manager;		// Code to detect invalid usage		if (manager != null) {			Window[] windows = manager.getWindows();			for (int i = 0; i < windows.length; i++) {				if (windows[i] == this) {					return;				}			}			manager.add(this);		}	}	/**	 * Sets the exception handler for this application.	 * <p>	 * Note that only one handler may be set. Other calls to this method will be	 * ignored.	 * <p>	 * 	 * @param handler	 *            the exception handler for the application.	 */	public static void setExceptionHandler(IExceptionHandler handler) {		if (exceptionHandler instanceof DefaultExceptionHandler) {			exceptionHandler = handler;		}	}        /**     * Sets the default parent for modal Windows. This will be used to locate     * the parent for any modal Window constructed with a null parent.     *      * @param provider shell provider that will be used to locate the parent shell     * whenever a Window is created with a null parent     * @since 3.1     */    public static void setDefaultModalParent(IShellProvider provider) {        defaultModalParent = provider;    }    	/**	 * Gets the default orientation for windows. If it is not	 * set the default value will be unspecified (SWT#NONE).	 * 	 * 	 * @return SWT#NONE, SWT.RIGHT_TO_LEFT or SWT.LEFT_TO_RIGHT	 * @see SWT#RIGHT_TO_LEFT	 * @see SWT#LEFT_TO_RIGHT	 * @see SWT#NONE	 * @since 3.1	 */	public static int getDefaultOrientation() {		return orientation;	}	/**	 * Sets the default orientation of windows.	 * @param defaultOrientation one of 	 * 	SWT#RIGHT_TO_LEFT, SWT#LEFT_TO_RIGHT ,SWT#NONE	 * @see SWT#RIGHT_TO_LEFT	 * @see SWT#LEFT_TO_RIGHT	 * @see SWT#NONE	 * @since 3.1	 */	public static void setDefaultOrientation(int defaultOrientation) {		orientation = defaultOrientation;			}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -