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

📄 wizarddialog.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************* * 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.wizard;import java.lang.reflect.InvocationTargetException;import java.util.ArrayList;import java.util.HashMap;import java.util.Map;import org.eclipse.core.runtime.IProgressMonitor;import org.eclipse.core.runtime.IStatus;import org.eclipse.core.runtime.ListenerList;import org.eclipse.jface.dialogs.ControlEnableState;import org.eclipse.jface.dialogs.IDialogConstants;import org.eclipse.jface.dialogs.IMessageProvider;import org.eclipse.jface.dialogs.IPageChangeProvider;import org.eclipse.jface.dialogs.IPageChangedListener;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.jface.dialogs.PageChangedEvent;import org.eclipse.jface.dialogs.TitleAreaDialog;import org.eclipse.jface.operation.IRunnableWithProgress;import org.eclipse.jface.operation.ModalContext;import org.eclipse.jface.resource.JFaceResources;import org.eclipse.jface.util.Assert;import org.eclipse.jface.util.SafeRunnable;import org.eclipse.swt.SWT;import org.eclipse.swt.custom.BusyIndicator;import org.eclipse.swt.events.HelpEvent;import org.eclipse.swt.events.HelpListener;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.graphics.Cursor;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Layout;import org.eclipse.swt.widgets.Shell;/** * A dialog to show a wizard to the end user.  * <p> * In typical usage, the client instantiates this class with  * a particular wizard. The dialog serves as the wizard container * and orchestrates the presentation of its pages. * <p> * The standard layout is roughly as follows:  * it has an area at the top containing both the * wizard's title, description, and image; the actual wizard page * appears in the middle; below that is a progress indicator * (which is made visible if needed); and at the bottom * of the page is message line and a button bar containing  * Help, Next, Back, Finish, and Cancel buttons (or some subset). * </p> * <p> * Clients may subclass <code>WizardDialog</code>, although this * is rarely required. * </p> */public class WizardDialog extends TitleAreaDialog implements IWizardContainer2, IPageChangeProvider {    /**     * Image registry key for error message image (value <code>"dialog_title_error_image"</code>).     */    public static final String WIZ_IMG_ERROR = "dialog_title_error_image"; //$NON-NLS-1$    // The wizard the dialog is currently showing.    private IWizard wizard;    // Wizards to dispose    private ArrayList createdWizards = new ArrayList();    // Current nested wizards    private ArrayList nestedWizards = new ArrayList();    // The currently displayed page.    private IWizardPage currentPage = null;    // The number of long running operation executed from the dialog.	    private long activeRunningOperations = 0;    // The current page message and description    private String pageMessage;    private int pageMessageType = IMessageProvider.NONE;    private String pageDescription;    // The progress monitor    private ProgressMonitorPart progressMonitorPart;    private Cursor waitCursor;    private Cursor arrowCursor;    private MessageDialog windowClosingDialog;    // Navigation buttons    private Button backButton;    private Button nextButton;    private Button finishButton;    private Button cancelButton;    private Button helpButton;    private SelectionAdapter cancelListener;    private boolean isMovingToPreviousPage = false;    private Composite pageContainer;    private PageContainerFillLayout pageContainerLayout = new PageContainerFillLayout(            5, 5, 300, 225);    private int pageWidth = SWT.DEFAULT;    private int pageHeight = SWT.DEFAULT;    private static final String FOCUS_CONTROL = "focusControl"; //$NON-NLS-1$    private boolean lockedUI = false;	    private ListenerList pageChangedListeners = new ListenerList();    /**     * A layout for a container which includes several pages, like     * a notebook, wizard, or preference dialog. The size computed by     * this layout is the maximum width and height of all pages currently     * inserted into the container.     */    protected class PageContainerFillLayout extends Layout {        /**         * The margin width; <code>5</code> pixels by default.         */        public int marginWidth = 5;        /**         * The margin height; <code>5</code> pixels by default.         */        public int marginHeight = 5;        /**         * The minimum width; <code>0</code> pixels by default.         */        public int minimumWidth = 0;        /**         * The minimum height; <code>0</code> pixels by default.         */        public int minimumHeight = 0;        /**         * Creates new layout object.         *         * @param mw the margin width         * @param mh the margin height         * @param minW the minimum width         * @param minH the minimum height         */        public PageContainerFillLayout(int mw, int mh, int minW, int minH) {            marginWidth = mw;            marginHeight = mh;            minimumWidth = minW;            minimumHeight = minH;        }        /* (non-Javadoc)         * Method declared on Layout.         */        public Point computeSize(Composite composite, int wHint, int hHint,                boolean force) {            if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {				return new Point(wHint, hHint);			}            Point result = null;            Control[] children = composite.getChildren();            if (children.length > 0) {                result = new Point(0, 0);                for (int i = 0; i < children.length; i++) {                    Point cp = children[i].computeSize(wHint, hHint, force);                    result.x = Math.max(result.x, cp.x);                    result.y = Math.max(result.y, cp.y);                }                result.x = result.x + 2 * marginWidth;                result.y = result.y + 2 * marginHeight;            } else {                Rectangle rect = composite.getClientArea();                result = new Point(rect.width, rect.height);            }            result.x = Math.max(result.x, minimumWidth);            result.y = Math.max(result.y, minimumHeight);            if (wHint != SWT.DEFAULT) {				result.x = wHint;			}            if (hHint != SWT.DEFAULT) {				result.y = hHint;			}            return result;        }        /**         * Returns the client area for the given composite according to this layout.         *         * @param c the composite         * @return the client area rectangle         */        public Rectangle getClientArea(Composite c) {            Rectangle rect = c.getClientArea();            rect.x = rect.x + marginWidth;            rect.y = rect.y + marginHeight;            rect.width = rect.width - 2 * marginWidth;            rect.height = rect.height - 2 * marginHeight;            return rect;        }        /* (non-Javadoc)         * Method declared on Layout.         */        public void layout(Composite composite, boolean force) {            Rectangle rect = getClientArea(composite);            Control[] children = composite.getChildren();            for (int i = 0; i < children.length; i++) {                children[i].setBounds(rect);            }        }        /**         * Lays outs the page according to this layout.         *         * @param w the control         */        public void layoutPage(Control w) {            w.setBounds(getClientArea(w.getParent()));        }        /**         * Sets the location of the page so that its origin is in the         * upper left corner.         *         * @param w the control         */        public void setPageLocation(Control w) {            w.setLocation(marginWidth, marginHeight);        }    }    /**     * Creates a new wizard dialog for the given wizard.      *     * @param parentShell the parent shell     * @param newWizard the wizard this dialog is working on     */    public WizardDialog(Shell parentShell, IWizard newWizard) {        super(parentShell);        setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER                | SWT.APPLICATION_MODAL | SWT.RESIZE | getDefaultOrientation());        setWizard(newWizard);        // since VAJava can't initialize an instance var with an anonymous        // class outside a constructor we do it here:        cancelListener = new SelectionAdapter() {            public void widgetSelected(SelectionEvent e) {                cancelPressed();            }        };    }    /**     * About to start a long running operation triggered through     * the wizard. Shows the progress monitor and disables the wizard's     * buttons and controls.     *     * @param enableCancelButton <code>true</code> if the Cancel button should     *   be enabled, and <code>false</code> if it should be disabled     * @return the saved UI state     */    private Object aboutToStart(boolean enableCancelButton) {        Map savedState = null;        if (getShell() != null) {            // Save focus control            Control focusControl = getShell().getDisplay().getFocusControl();            if (focusControl != null && focusControl.getShell() != getShell()) {				focusControl = null;			}            boolean needsProgressMonitor = wizard.needsProgressMonitor();            cancelButton.removeSelectionListener(cancelListener);            // Set the busy cursor to all shells.            Display d = getShell().getDisplay();            waitCursor = new Cursor(d, SWT.CURSOR_WAIT);            setDisplayCursor(waitCursor);            // Set the arrow cursor to the cancel component.            arrowCursor = new Cursor(d, SWT.CURSOR_ARROW);            cancelButton.setCursor(arrowCursor);            // Deactivate shell            savedState = saveUIState(needsProgressMonitor && enableCancelButton);            if (focusControl != null) {				savedState.put(FOCUS_CONTROL, focusControl);			}            // Attach the progress monitor part to the cancel button            if (needsProgressMonitor) {                progressMonitorPart.attachToCancelComponent(cancelButton);                progressMonitorPart.setVisible(true);            }        }        return savedState;    }    /**     * The Back button has been pressed.     */    protected void backPressed() {        IWizardPage page = currentPage.getPreviousPage();        if (page == null) {			// should never happen since we have already visited the page            return;		}        // set flag to indicate that we are moving back        isMovingToPreviousPage = true;        // show the page        showPage(page);    }

⌨️ 快捷键说明

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