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

📄 popupdialog.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * Return a boolean indicating whether this dialog will persist its bounds.	 * This value is initially set in the dialog's constructor, but can be	 * modified if the persist bounds action is shown on the menu and the user	 * has changed its value. Subclasses may override this method.	 * 	 * @return <true> if the dialogs bounds will be persisted, false if it will	 *         not.	 */	protected boolean getPersistBounds() {		return persistBounds;	}	/**	 * Opens this window, creating it first if it has not yet been created.	 * <p>	 * This method is reimplemented for special configuration of PopupDialogs.	 * It never blocks on open, immediately returning <code>OK</code> if the	 * open is successful, or <code>CANCEL</code> if it is not. It provides	 * framework hooks that allow subclasses to set the focus and tab order, and	 * avoids the use of <code>shell.open()</code> in cases where the focus	 * should not be given to the shell initially.	 * 	 * @return the return code	 * 	 * @see org.eclipse.jface.window.Window#open()	 */	public int open() {		Shell shell = getShell();		if (shell == null || shell.isDisposed()) {			shell = null;			// create the window			create();			shell = getShell();		}		// provide a hook for adjusting the bounds. This is only		// necessary when there is content driven sizing that must be		// adjusted each time the dialog is opened.		adjustBounds();		// limit the shell size to the display size		constrainShellSize();		// set up the tab order for the dialog		setTabOrder((Composite) getContents());		// initialize flags for listening to deactivate		listenToDeactivate = false;		listenToParentDeactivate = false;		// open the window		if (takeFocusOnOpen) {			shell.open();			getFocusControl().setFocus();		} else {			shell.setVisible(true);		}		return OK;	}	/**	 * Closes this window, disposes its shell, and removes this window from its	 * window manager (if it has one).	 * <p>	 * This method is extended to save the dialog bounds and initialize widget	 * state so that the widgets can be recreated if the dialog is reopened.	 * This method may be extended (<code>super.close</code> must be called).	 * </p>	 * 	 * @return <code>true</code> if the window is (or was already) closed, and	 *         <code>false</code> if it is still open	 */	public boolean close() {		// If already closed, there is nothing to do.		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=127505		if (getShell() == null || getShell().isDisposed()) {			return true;		}				saveDialogBounds(getShell());		// Widgets are about to be disposed, so null out any state		// related to them that was not handled in dispose listeners.		// We do this before disposal so that any received activate or		// deactivate events are duly ignored.		initializeWidgetState();				if (parentDeactivateListener != null) {			getShell().getParent().removeListener(SWT.Deactivate, parentDeactivateListener);			parentDeactivateListener = null;		}		return super.close();	}	/**	 * Gets the dialog settings that should be used for remembering the bounds	 * of the dialog. Subclasses should override this method when they wish to	 * persist the bounds of the dialog.	 * 	 * @return settings the dialog settings used to store the dialog's location	 *         and/or size, or <code>null</code> if the dialog's bounds should	 *         never be stored.	 */	protected IDialogSettings getDialogSettings() {		return null;	}	/**	 * Saves the bounds of the shell in the appropriate dialog settings. The	 * bounds are recorded relative to the parent shell, if there is one, or	 * display coordinates if there is no parent shell. Subclasses typically	 * need not override this method, but may extend it (calling	 * <code>super.saveDialogBounds</code> if additional bounds information	 * should be stored. Clients may also call this method to persist the bounds	 * at times other than closing the dialog.	 * 	 * @param shell	 *            The shell whose bounds are to be stored	 */	protected void saveDialogBounds(Shell shell) {		IDialogSettings settings = getDialogSettings();		if (settings != null) {			Point shellLocation = shell.getLocation();			Point shellSize = shell.getSize();			Shell parent = getParentShell();			if (parent != null) {				Point parentLocation = parent.getLocation();				shellLocation.x -= parentLocation.x;				shellLocation.y -= parentLocation.y;			}			if (persistBounds) {				String prefix = getClass().getName();				settings.put(prefix + DIALOG_ORIGIN_X, shellLocation.x);				settings.put(prefix + DIALOG_ORIGIN_Y, shellLocation.y);				settings.put(prefix + DIALOG_WIDTH, shellSize.x);				settings.put(prefix + DIALOG_HEIGHT, shellSize.y);			}			if (showPersistAction && showDialogMenu) {				settings.put(						getClass().getName() + DIALOG_USE_PERSISTED_BOUNDS,						persistBounds);			}		}	}	/*	 * (non-Javadoc)	 * 	 * @see org.eclipse.jface.window.Window#getInitialSize()	 */	protected Point getInitialSize() {		Point result = super.getInitialSize();		if (persistBounds) {			IDialogSettings settings = getDialogSettings();			if (settings != null) {				try {					int width = settings.getInt(getClass().getName()							+ DIALOG_WIDTH);					int height = settings.getInt(getClass().getName()							+ DIALOG_HEIGHT);					result = new Point(width, height);				} catch (NumberFormatException e) {				}			}		}		// No attempt is made to constrain the bounds. The default		// constraining behavior in Window will be used.		return result;	}	/**	 * Adjust the bounds of the popup as necessary prior to opening the dialog.	 * Default is to do nothing, which honors any bounds set directly by clients	 * or those that have been saved in the dialog settings. Subclasses should	 * override this method when there are bounds computations that must be	 * checked each time the dialog is opened.	 */	protected void adjustBounds() {	}	/**	 * (non-Javadoc)	 * 	 * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)	 */	protected Point getInitialLocation(Point initialSize) {		Point result = super.getInitialLocation(initialSize);		if (persistBounds) {			IDialogSettings settings = getDialogSettings();			if (settings != null) {				try {					int x = settings.getInt(getClass().getName()							+ DIALOG_ORIGIN_X);					int y = settings.getInt(getClass().getName()							+ DIALOG_ORIGIN_Y);					result = new Point(x, y);					// The coordinates were stored relative to the parent shell.					// Convert to display coordinates.					Shell parent = getParentShell();					if (parent != null) {						Point parentLocation = parent.getLocation();						result.x += parentLocation.x;						result.y += parentLocation.y;					}				} catch (NumberFormatException e) {				}			}		}		// No attempt is made to constrain the bounds. The default		// constraining behavior in Window will be used.		return result;	}	/**	 * Apply any desired color to the specified composite and its children.	 * 	 * @param composite	 *            the contents composite	 */	private void applyColors(Composite composite) {		applyForegroundColor(getShell().getDisplay().getSystemColor(				SWT.COLOR_INFO_FOREGROUND), composite,				getForegroundColorExclusions());		applyBackgroundColor(getShell().getDisplay().getSystemColor(				SWT.COLOR_INFO_BACKGROUND), composite,				getBackgroundColorExclusions());	}	/**	 * Apply any desired fonts to the specified composite and its children.	 * 	 * @param composite	 *            the contents composite	 */	private void applyFonts(Composite composite) {		Dialog.applyDialogFont(composite);	}	/**	 * Set the specified foreground color for the specified control and all of	 * its children, except for those specified in the list of exclusions.	 * 	 * @param color	 *            the color to use as the foreground color	 * @param control	 *            the control whose color is to be changed	 * @param exclusions	 *            a list of controls who are to be excluded from getting their	 *            color assigned	 */	private void applyForegroundColor(Color color, Control control,			List exclusions) {		if (!exclusions.contains(control)) {			control.setForeground(color);		}		if (control instanceof Composite) {			Control[] children = ((Composite) control).getChildren();			for (int i = 0; i < children.length; i++) {				applyForegroundColor(color, children[i], exclusions);			}		}	}	/**	 * Set the specified background color for the specified control and all of	 * its children.	 * 	 * @param color	 *            the color to use as the background color	 * @param control	 *            the control whose color is to be changed	 * @param exclusions	 *            a list of controls who are to be excluded from getting their	 *            color assigned	 */	private void applyBackgroundColor(Color color, Control control,			List exclusions) {		if (!exclusions.contains(control)) {			control.setBackground(color);		}		if (control instanceof Composite) {			Control[] children = ((Composite) control).getChildren();			for (int i = 0; i < children.length; i++) {				applyBackgroundColor(color, children[i], exclusions);			}		}	}	/**	 * Set the specified foreground color for the specified control and all of	 * its children. Subclasses may override this method, but typically do not.	 * If a subclass wishes to exclude a particular control in its contents from	 * getting the specified foreground color, it may instead override	 * <code>PopupDialog.getForegroundColorExclusions</code>.	 * 	 * @param color	 *            the color to use as the background color	 * @param control	 *            the control whose color is to be changed	 * @see PopupDialog#getBackgroundColorExclusions()	 */	protected void applyForegroundColor(Color color, Control control) {		applyForegroundColor(color, control, getForegroundColorExclusions());	}	/**	 * Set the specified background color for the specified control and all of	 * its children. Subclasses may override this method, but typically do not.	 * If a subclass wishes to exclude a particular control in its contents from	 * getting the specified background color, it may instead override	 * <code>PopupDialog.getBackgroundColorExclusions</code>.	 * 	 * @param color	 *            the color to use as the background color	 * @param control	 *            the control whose color is to be changed	 * @see PopupDialog#getBackgroundColorExclusions()	 */	protected void applyBackgroundColor(Color color, Control control) {		applyBackgroundColor(color, control, getBackgroundColorExclusions());	}	/**	 * Return a list of controls which should never have their foreground color	 * reset. Subclasses may extend this method (should always call	 * <code>super.getForegroundColorExclusions</code> to aggregate the list.	 * 	 * 	 * @return the List of controls	 */	protected List getForegroundColorExclusions() {		List list = new ArrayList(3);		if (infoLabel != null) {			list.add(infoLabel);		}		if (titleSeparator != null) {			list.add(titleSeparator);		}		if (infoSeparator != null) {			list.add(infoSeparator);		}		return list;	}	/**	 * Return a list of controls which should never have their background color	 * reset. Subclasses may extend this method (should always call	 * <code>super.getBackgroundColorExclusions</code> to aggregate the list.	 * 	 * @return the List of controls	 */	protected List getBackgroundColorExclusions() {		List list = new ArrayList(2);		if (titleSeparator != null) {			list.add(titleSeparator);		}		if (infoSeparator != null) {			list.add(infoSeparator);		}		return list;	}	/**	 * Initialize any state related to the widgetry that should be set up each	 * time widgets are created.	 */	private void initializeWidgetState() {		menuManager = null;		dialogArea = null;		titleLabel = null;		titleSeparator = null;		infoSeparator = null;		infoLabel = null;		toolBar = null;		// If the menu item for persisting bounds is displayed, use the stored		// value to determine whether any persisted bounds should be honored at		// all.		if (showDialogMenu && showPersistAction) {			IDialogSettings settings = getDialogSettings();			if (settings != null) {				persistBounds = settings.getBoolean(getClass().getName()						+ DIALOG_USE_PERSISTED_BOUNDS);			}		}	}		/**	 * The dialog is being disposed.  Dispose of any resources allocated.	 *	 */	private void handleDispose() {		if (infoFont != null && !infoFont.isDisposed()) {			infoFont.dispose();		}		infoFont = null;		if (titleFont != null && !titleFont.isDisposed()) {			titleFont.dispose();		}		titleFont = null;	}}

⌨️ 快捷键说明

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