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

📄 messagedialog.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *      * @param index     *            the index of the button in the dialog's button bar     * @return a button in the dialog's button bar     */    protected Button getButton(int index) {        return buttons[index];    }    /**     * Returns the minimum message area width in pixels This determines the     * minimum width of the dialog.     * <p>     * Subclasses may override.     * </p>     *      * @return the minimum message area width (in pixels)     */    protected int getMinimumMessageWidth() {        return convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);    }    /**     * Handle the shell close. Set the return code to <code>SWT.DEFAULT</code>     * as there has been no explicit close by the user.     *      * @see org.eclipse.jface.window.Window#handleShellCloseEvent()     */    protected void handleShellCloseEvent() {        //Sets a return code of SWT.DEFAULT since none of the dialog buttons        // were pressed to close the dialog.        super.handleShellCloseEvent();        setReturnCode(SWT.DEFAULT);    }    /**     * Convenience method to open a simple confirm (OK/Cancel) dialog.     *      * @param parent     *            the parent shell of the dialog, or <code>null</code> if none     * @param title     *            the dialog's title, or <code>null</code> if none     * @param message     *            the message     * @return <code>true</code> if the user presses the OK button,     *         <code>false</code> otherwise     */    public static boolean openConfirm(Shell parent, String title, String message) {        MessageDialog dialog = new MessageDialog(parent, title, null, // accept                // the                // default                // window                // icon                message, QUESTION, new String[] { IDialogConstants.OK_LABEL,                        IDialogConstants.CANCEL_LABEL }, 0); // OK is the        // default        return dialog.open() == 0;    }    /**     * Convenience method to open a standard error dialog.     *      * @param parent     *            the parent shell of the dialog, or <code>null</code> if none     * @param title     *            the dialog's title, or <code>null</code> if none     * @param message     *            the message     */    public static void openError(Shell parent, String title, String message) {        MessageDialog dialog = new MessageDialog(parent, title, null, // accept                // the                // default                // window                // icon                message, ERROR, new String[] { IDialogConstants.OK_LABEL }, 0); // ok        // is        // the        // default        dialog.open();        return;    }    /**     * Convenience method to open a standard information dialog.     *      * @param parent     *            the parent shell of the dialog, or <code>null</code> if none     * @param title     *            the dialog's title, or <code>null</code> if none     * @param message     *            the message     */    public static void openInformation(Shell parent, String title,            String message) {        MessageDialog dialog = new MessageDialog(parent, title, null, // accept                // the                // default                // window                // icon                message, INFORMATION,                new String[] { IDialogConstants.OK_LABEL }, 0);        // ok is the default        dialog.open();        return;    }    /**     * Convenience method to open a simple Yes/No question dialog.     *      * @param parent     *            the parent shell of the dialog, or <code>null</code> if none     * @param title     *            the dialog's title, or <code>null</code> if none     * @param message     *            the message     * @return <code>true</code> if the user presses the OK button,     *         <code>false</code> otherwise     */    public static boolean openQuestion(Shell parent, String title,            String message) {        MessageDialog dialog = new MessageDialog(parent, title, null, // accept                // the                // default                // window                // icon                message, QUESTION, new String[] { IDialogConstants.YES_LABEL,                        IDialogConstants.NO_LABEL }, 0); // yes is the default        return dialog.open() == 0;    }    /**     * Convenience method to open a standard warning dialog.     *      * @param parent     *            the parent shell of the dialog, or <code>null</code> if none     * @param title     *            the dialog's title, or <code>null</code> if none     * @param message     *            the message     */    public static void openWarning(Shell parent, String title, String message) {        MessageDialog dialog = new MessageDialog(parent, title, null, // accept                // the                // default                // window                // icon                message, WARNING, new String[] { IDialogConstants.OK_LABEL }, 0); // ok        // is        // the        // default        dialog.open();        return;    }    /*     * @see org.eclipse.jface.dialogs.Dialog#createButton(org.eclipse.swt.widgets.Composite,     *      int, java.lang.String, boolean)     */    protected Button createButton(Composite parent, int id, String label,            boolean defaultButton) {        Button button = super.createButton(parent, id, label, defaultButton);        //Be sure to set the focus if the custom area cannot so as not        //to lose the defaultButton.        if (defaultButton && !customShouldTakeFocus()) {			button.setFocus();		}        return button;    }    /**     * Return whether or not we should apply the workaround where we take focus     * for the default button or if that should be determined by the dialog. By     * default only return true if the custom area is a label or CLabel that     * cannot take focus.     *      * @return boolean     */    protected boolean customShouldTakeFocus() {        if (customArea instanceof Label) {			return false;		}        if (customArea instanceof CLabel) {			return (customArea.getStyle() & SWT.NO_FOCUS) > 0;		}        return true;    }    /*     *  (non-Javadoc)     * @see org.eclipse.jface.dialogs.IconAndMessageDialog#getImage()     */    public Image getImage() {        return image;    }    /**     * An accessor for the labels to use on the buttons.     *      * @return The button labels to used; never <code>null</code>.     */    protected String[] getButtonLabels() {        return buttonLabels;    }    /**     * An accessor for the index of the default button in the button array.     *      * @return The default button index.     */    protected int getDefaultButtonIndex() {        return defaultButtonIndex;    }    /**     * A mutator for the array of buttons in the button bar.     *      * @param buttons     *            The buttons in the button bar; must not be <code>null</code>.     */    protected void setButtons(Button[] buttons) {        if (buttons == null) {            throw new NullPointerException(                    "The array of buttons cannot be null.");} //$NON-NLS-1$        this.buttons = buttons;    }    /**     * A mutator for the button labels.     *      * @param buttonLabels     *            The button labels to use; must not be <code>null</code>.     */    protected void setButtonLabels(String[] buttonLabels) {        if (buttonLabels == null) {            throw new NullPointerException(                    "The array of button labels cannot be null.");} //$NON-NLS-1$        this.buttonLabels = buttonLabels;    }}

⌨️ 快捷键说明

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