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

📄 applicationwindow.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.jface.window;import java.lang.reflect.InvocationTargetException;import org.eclipse.core.runtime.NullProgressMonitor;import org.eclipse.jface.action.CoolBarManager;import org.eclipse.jface.action.ICoolBarManager;import org.eclipse.jface.action.IToolBarManager;import org.eclipse.jface.action.MenuManager;import org.eclipse.jface.action.StatusLineManager;import org.eclipse.jface.action.ToolBarManager;import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;import org.eclipse.jface.internal.provisional.action.IToolBarManager2;import org.eclipse.jface.operation.IRunnableContext;import org.eclipse.jface.operation.IRunnableWithProgress;import org.eclipse.jface.operation.ModalContext;import org.eclipse.jface.resource.JFaceResources;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.BusyIndicator;import org.eclipse.swt.graphics.Font;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.CoolBar;import org.eclipse.swt.widgets.Decorations;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Layout;import org.eclipse.swt.widgets.Menu;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.ToolBar;/** * An application window is a high-level "main window", with built-in * support for an optional menu bar with standard menus, an optional toolbar, * and an optional status line. * <p> * Creating an application window involves the following steps: * <ul> *   <li>creating an instance of <code>ApplicationWindow</code> *   </li> *   <li>assigning the window to a window manager (optional) *   </li> *   <li>opening the window by calling <code>open</code> *   </li> * </ul> * Only on the last step, when the window is told to open, are * the window's shell and widget tree created. When the window is * closed, the shell and widget tree are disposed of and are no longer * referenced, and the window is automatically removed from its window * manager. Like all windows, an application window may be reopened. * </p> * <p> * An application window is also a suitable context in which to perform  * long-running operations (that is, it implements <code>IRunnableContext</code>). * </p> */public class ApplicationWindow extends Window implements IRunnableContext {    /**     * Menu bar manager, or <code>null</code> if none (default).     *     * @see #addMenuBar     */    private MenuManager menuBarManager = null;    /**     * Tool bar manager, or <code>null</code> if none (default).     *     * @see #addToolBar     */    private IToolBarManager toolBarManager = null;    /**     * Status line manager, or <code>null</code> if none (default).     *     * @see #addStatusLine     */    private StatusLineManager statusLineManager = null;    /**     * Cool bar manager, or <code>null</code> if none (default).     *      * @see #addCoolBar     * @since 3.0     */    private ICoolBarManager coolBarManager = null;    /**     * The seperator between the menu bar and the rest of the window.     */    protected Label seperator1;    /**     * A flag indicating that an operation is running.     */    private boolean operationInProgress = false;    /**     * Internal application window layout class.     * This vertical layout supports a tool bar area (fixed size),     * a separator line, the content area (variable size), and a      * status line (fixed size).     */    /*package*/class ApplicationWindowLayout extends Layout {        static final int VGAP = 2;        static final int BAR_SIZE = 23;        protected Point computeSize(Composite composite, int wHint, int hHint,                boolean flushCache) {            if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {				return new Point(wHint, hHint);			}            Point result = new Point(0, 0);            Control[] ws = composite.getChildren();            for (int i = 0; i < ws.length; i++) {                Control w = ws[i];                boolean hide = false;                if (getToolBarControl() == w) {                    if (!toolBarChildrenExist()) {                        hide = true;                        result.y += BAR_SIZE; // REVISIT                    }                } else if (getCoolBarControl() == w) {                    if (!coolBarChildrenExist()) {                        hide = true;                        result.y += BAR_SIZE;                    }                } else if (statusLineManager != null                        && statusLineManager.getControl() == w) {                } else if (i > 0) { /* we assume this window is contents */                    hide = false;                }                if (!hide) {                    Point e = w.computeSize(wHint, hHint, flushCache);                    result.x = Math.max(result.x, e.x);                    result.y += e.y + VGAP;                }            }            if (wHint != SWT.DEFAULT) {				result.x = wHint;			}            if (hHint != SWT.DEFAULT) {				result.y = hHint;			}            return result;        }        protected void layout(Composite composite, boolean flushCache) {            Rectangle clientArea = composite.getClientArea();            Control[] ws = composite.getChildren();            for (int i = 0; i < ws.length; i++) {                Control w = ws[i];                if (i == 0) { // Separator                    Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,                            flushCache);                    w.setBounds(clientArea.x, clientArea.y, clientArea.width,                            e.y);                    clientArea.y += e.y;                    clientArea.height -= e.y;                } else if (getToolBarControl() == w) {                    if (toolBarChildrenExist()) {                        Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,                                flushCache);                        w.setBounds(clientArea.x, clientArea.y,                                clientArea.width, e.y);                        clientArea.y += e.y + VGAP;                        clientArea.height -= e.y + VGAP;                    }                } else if (getCoolBarControl() == w) {                    if (coolBarChildrenExist()) {                        Point e = w.computeSize(clientArea.width, SWT.DEFAULT,                                flushCache);                        w.setBounds(clientArea.x, clientArea.y,                                clientArea.width, e.y);                        clientArea.y += e.y + VGAP;                        clientArea.height -= e.y + VGAP;                    }                } else if (statusLineManager != null                        && statusLineManager.getControl() == w) {                    Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,                            flushCache);                    w.setBounds(clientArea.x, clientArea.y + clientArea.height                            - e.y, clientArea.width, e.y);                    clientArea.height -= e.y + VGAP;                } else {                    w.setBounds(clientArea.x, clientArea.y + VGAP,                            clientArea.width, clientArea.height - VGAP);                }            }        }    }    /**     * Return the top seperator.     * @return Label     */    protected Label getSeperator1() {        return seperator1;    }    /**     * Create an application window instance, whose shell will be created under the     * given parent shell.     * Note that the window will have no visual representation (no widgets)     * until it is told to open. By default, <code>open</code> does not block.     *     * @param parentShell the parent shell, or <code>null</code> to create a top-level shell     */    public ApplicationWindow(Shell parentShell) {        super(parentShell);    }    /**     * Configures this window to have a menu bar.     * Does nothing if it already has one.     * This method must be called before this window's shell is created.     */    protected void addMenuBar() {        if ((getShell() == null) && (menuBarManager == null)) {            menuBarManager = createMenuManager();        }    }    /**     * Configures this window to have a status line.     * Does nothing if it already has one.     * This method must be called before this window's shell is created.     */    protected void addStatusLine() {        if ((getShell() == null) && (statusLineManager == null)) {            statusLineManager = createStatusLineManager();        }    }    /**     * Configures this window to have a tool bar.     * Does nothing if it already has one.     * This method must be called before this window's shell is created.     */    protected void addToolBar(int style) {        if ((getShell() == null) && (toolBarManager == null)                && (coolBarManager == null)) {            toolBarManager = createToolBarManager2(style);        }    }    /**     * Configures this window to have a cool bar.     * Does nothing if it already has one.     * This method must be called before this window's shell is created.     *      * @param style the cool bar style     * @since 3.0     */    protected void addCoolBar(int style) {        if ((getShell() == null) && (toolBarManager == null)                && (coolBarManager == null)) {            coolBarManager = createCoolBarManager2(style);        }	    }    /* (non-Javadoc)     * Method declared on Window.     */    protected boolean canHandleShellCloseEvent() {        return super.canHandleShellCloseEvent() && !operationInProgress;    }    /* (non-Javadoc)     * Method declared on Window.     */    public boolean close() {        if (operationInProgress) {			return false;		}        if (super.close()) {            if (menuBarManager != null) {                menuBarManager.dispose();                menuBarManager = null;            }            if (toolBarManager != null) {            	if (toolBarManager instanceof IToolBarManager2) {					((IToolBarManager2) toolBarManager).dispose();				} else if (toolBarManager instanceof ToolBarManager) {					((ToolBarManager) toolBarManager).dispose();				}                toolBarManager = null;            }            if (statusLineManager != null) {                statusLineManager.dispose();                statusLineManager = null;            }            if (coolBarManager != null) {            	if (coolBarManager instanceof ICoolBarManager2) {					((ICoolBarManager2) coolBarManager).dispose();				} else if (coolBarManager instanceof CoolBarManager) {					((CoolBarManager) coolBarManager).dispose();				}                coolBarManager = null;            }            return true;        }        return false;    }    /**     * Extends the super implementation by creating the trim widgets using <code>createTrimWidgets</code>.      */    protected void configureShell(Shell shell) {        super.configureShell(shell);        createTrimWidgets(shell);    }    /**     * Creates the trim widgets around the content area.     *      * @param shell the shell     * @since 3.0     */    protected void createTrimWidgets(Shell shell) {        if (menuBarManager != null) {            menuBarManager.updateAll(true);            shell.setMenuBar(menuBarManager.createMenuBar((Decorations) shell));        }        if (showTopSeperator()) {			seperator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);		}        // will create either a cool bar or a tool bar        createToolBarControl(shell);        createCoolBarControl(shell);        createStatusLine(shell);    }    /* (non-Javadoc)     * @see org.eclipse.jface.window.Window#getLayout()     */    protected Layout getLayout() {        return new ApplicationWindowLayout();    }    /**     * Returns whether to show a top separator line between the menu bar     * and the rest of the window contents.  On some platforms such as the Mac,     * the menu is separated from the main window already, so a separator line     * is not desired.      *      * @return <code>true</code> to show the top separator, <code>false</code>     *   to not show it     * @since 3.0     */    protected boolean showTopSeperator() {        return !"carbon".equals(SWT.getPlatform()); //$NON-NLS-1$    }    /**     * Create the status line if required.     * @param shell     */    protected void createStatusLine(Shell shell) {        if (statusLineManager != null) {            statusLineManager.createControl(shell, SWT.NONE);        }    }    /**     * Returns a new menu manager for the window.     * <p>     * Subclasses may override this method to customize the menu manager.     * </p>     * @return a menu manager     */    protected MenuManager createMenuManager() {        return new MenuManager();    }    /**     * Returns a new status line manager for the window.     * <p>     * Subclasses may override this method to customize the status line manager.     * </p>     * @return a status line manager     */    protected StatusLineManager createStatusLineManager() {        return new StatusLineManager();    }    /**     * Returns a new tool bar manager for the window.     * <p>     * Subclasses may override this method to customize the tool bar manager.     * </p>     * @return a tool bar manager     */    protected ToolBarManager createToolBarManager(int style) {        return new ToolBarManager(style);    }        /**     * Returns a new tool bar manager for the window.      * <p>      * By default this method calls <code>createToolBarManager</code>.  Subclasses     * may override this method to provide an alternative implementation for the     * tool bar manager.     * </p>

⌨️ 快捷键说明

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