Example usage for org.eclipse.jface.resource JFaceResources getImage

List of usage examples for org.eclipse.jface.resource JFaceResources getImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getImage.

Prototype

public static Image getImage(String key) 

Source Link

Document

Returns the image in JFace's image registry with the given key, or null if none.

Usage

From source file:org.locationtech.udig.ui.filter.FilterViewer.java

License:Open Source License

/**
 * Creates an FilterViewer using the provided style.
 * <ul>/*from w  w w  .  j a v a  2  s  . c  o  m*/
 * <li>SWT.SINGLE - A simple text field showing the expression using extended CQL notation
 * <li>
 * <li>SWT.MULTI - A multi line text field</li>
 * <li>SWT.READ_ONLY - read only display of a filter</li>
 * </ul>
 * 
 * @param parent
 * @param style
 */
public FilterViewer(Composite parent, int style) {
    control = new Composite(parent, SWT.NO_SCROLL) {
        @Override
        public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
            config.setEnabled(enabled);
            if (delegate != null) {
                config.setEnabled(enabled);
            }
            if (input != null && input.getFeedback() != null && input.getFeedback().getControl() != null) {
                Control feedbackLabel = input.getFeedback().getControl();
                Display display = feedbackLabel.getDisplay();
                feedbackLabel.setEnabled(enabled);
                if (enabled) {
                    feedbackLabel.setForeground(display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
                } else {
                    feedbackLabel.setForeground(display.getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
                }
            }
        }
    };
    control.setLayout(new MigLayout("insets 0", "[fill][]", "[fill]"));

    pageBook = new PageBook(control, SWT.NO_SCROLL);
    pageBook.setLayoutData("cell 0 0,grow,width 200:100%:100%,height 18:75%:100%");

    placeholder = new Label(pageBook, SWT.SINGLE);
    placeholder.setText("Choose filter editor");

    delegate = new CQLFilterViewer(pageBook, style);
    delegate.addSelectionChangedListener(listener);
    pageBook.showPage(delegate.getControl());

    this.pages = new HashMap<String, IFilterViewer>();
    pages.put(FilterViewerFactory.CQL_FILTER_VIEWER, delegate);

    config = new Label(control, SWT.SINGLE);
    config.setImage(JFaceResources.getImage(PopupDialog.POPUP_IMG_MENU));
    config.setLayoutData("cell 1 0,aligny top,height 16!, width 16!");

    createContextMenu(config);

    config.addMouseListener(new MouseAdapter() {
        public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
            Menu menu = config.getMenu();
            if (menu != null) {
                menu.setVisible(true);
            }
        }
    });
    this.style = style;
}

From source file:org.mailster.gui.prefs.widgets.DialogMessageArea.java

License:Open Source License

/**
 * Create the contents for the receiver.
 * /*from  w w  w .  ja  v  a 2  s.c  o m*/
 * @param parent the Composite that the children will be created in
 */
public void createContents(Composite parent) {
    /* Create the title label */
    this.titleLabel = new CLabel(parent, SWT.LEFT);
    int[] alpha = new int[] { 75, 100 };
    this.titleLabel.setBackground(DEFAULT_GRADIENT_BACKGROUND, alpha);
    this.titleLabel.setFont(JFaceResources.getBannerFont());
    this.titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    this.titleLabel.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY));
            Rectangle bounds = titleLabel.getClientArea();
            bounds.height -= 2;
            bounds.width -= 1;
            e.gc.drawRectangle(bounds);
        }
    });

    /* Create the message container */
    this.messageComposite = new Composite(parent, SWT.NONE);
    GridLayout messageLayout = new GridLayout(2, false);
    messageLayout.marginWidth = 0;
    messageLayout.marginHeight = 0;
    this.messageComposite.setLayout(messageLayout);

    /* Create the message image holder */
    this.messageImageLabel = new Label(this.messageComposite, SWT.NONE);
    this.messageImageLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
    this.messageImageLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    /* Create the message text holder */
    this.messageText = new Text(this.messageComposite, SWT.NONE);
    this.messageText.setEditable(false);

    GridData textData = new GridData(
            GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    this.messageText.setLayoutData(textData);
}

From source file:org.mailster.gui.prefs.widgets.DialogMessageArea.java

License:Open Source License

/**
 * Show the new message in the message text and update the image. Base the
 * background color on whether or not there are errors.
 * //  w w w .j a  v a  2 s. c  o m
 * @param newMessage The new value for the message
 * @param newType One of the IMessageProvider constants. If newType is
 *            IMessageProvider.NONE show the title.
 * @see org.eclipse.jface.dialogs.IMessageProvider
 */
public void updateText(String newMessage, int newType) {
    Image newImage = null;
    switch (newType) {
    case IMessageProvider.NONE:
        if (newMessage == null) {
            this.restoreTitle();
        } else {
            this.showTitle(newMessage, null);
        }
        return;
    case IMessageProvider.INFORMATION:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
        break;
    case IMessageProvider.WARNING:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
        break;
    case IMessageProvider.ERROR:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
        break;
    }

    this.messageComposite.setVisible(true);
    this.titleLabel.setVisible(false);
    // Any more updates required?
    // If the message text equals the tooltip (i.e. non-shortened text is
    // the same)
    // and shortened text is the same (i.e. not a resize)
    // and the image is the same then nothing to do
    String shortText = Dialog.shortenText(newMessage, messageText);
    if (newMessage.equals(messageText.getToolTipText()) && newImage == messageImageLabel.getImage()
            && shortText.equals(messageText.getText())) {
        return;
    }
    this.messageImageLabel.setImage(newImage);
    this.messageText.setText(Dialog.shortenText(newMessage, messageText));
    this.messageText.setToolTipText(newMessage);
    this.lastMessageText = newMessage;
}

From source file:org.modelio.api.ui.ModelioDialog.java

License:Apache License

/**
 * Set an error message that will display in the message area on top of the
 * header of the dialog, with an error small icon.<br>
 * Removes the message if null is passed .
 * @param newErrorMessage The error message or null to remove the error message.
 */// w  ww  . j a  v a 2s  .  c  o m
@objid("7c15376f-704b-11dd-933a-001ec947cd2a")
protected void setErrorMessage(String newErrorMessage) {
    if ((this.errorMessage != null) ? this.errorMessage.equals(newErrorMessage) : newErrorMessage == null)
        return;
    this.errorMessage = newErrorMessage;
    if (this.errorMessage == null) {
        if (this.messageArea != null && !this.showingWarning)
            setMessageAreaVisible(false);
        if (this.showingError)
            this.showingError = false;
        if (this.message == null)
            this.message = "";
        updateMessage(this.message);
        this.messageImageLabel.setImage(this.messageImage);
        setImageLabelVisible(this.messageImage != null);
        if (this.showingWarning)
            setWarningMessage(this.warningMessage);
    } else {
        if (!this.showingError)
            this.showingError = true;
        if (this.showingWarning)
            setWarningMessage(null);
        if (this.messageArea == null) {
            this.messageArea = new ImageAndMessageArea(this.titleArea, 64);
            this.messageArea.setBackground(this.messageLabel.getBackground());
            this.animator = Policy.getAnimatorFactory().createAnimator(this.messageArea);
        }
        this.messageArea.setToolTipText(this.errorMessage);
        this.messageArea.setText(this.errorMessage);
        this.messageArea.setImage(JFaceResources.getImage("dialog_message_error_image"));
        setMessageAreaVisible(true);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(1);
    int horizontalSpacing = convertHorizontalDLUsToPixels(4);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
}

From source file:org.modelio.api.ui.ModelioDialog.java

License:Apache License

/**
 * Set a warning message that will display in the message area on top of the dialog,
 * with a warning small icon.<br>//w w w  .ja v  a2  s  . c o  m
 * Removes the message if null is passed .
 * @param newMessage The warning message or null to remove the warning message.
 */
@objid("7c12d579-704b-11dd-933a-001ec947cd2a")
protected void setWarningMessage(String newMessage) {
    // @SuppressWarnings("deprecation") added to
    if (this.warningMessage != null ? this.warningMessage.equals(newMessage) : newMessage == null)
        return;
    this.warningMessage = newMessage;
    if (this.warningMessage == null) {
        if (this.messageArea != null && !this.showingError)
            setMessageAreaVisible(false);
        if (this.showingWarning)
            this.showingWarning = false;
    } else {
        if (!this.showingWarning)
            this.showingWarning = true;
        this.warningMessage = newMessage;
        if (this.messageArea == null) {
            this.messageArea = new ImageAndMessageArea(this.titleArea, 64);
            this.messageArea.setBackground(this.messageLabel.getBackground());
            this.animator = Policy.getAnimatorFactory().createAnimator(this.messageArea);
        }
        this.messageArea.setToolTipText(this.warningMessage);
        this.messageArea.setText(this.warningMessage);
        this.messageArea.setImage(JFaceResources.getImage("dialog_messasge_warning_image"));
        setMessageAreaVisible(true);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(1);
    int horizontalSpacing = convertHorizontalDLUsToPixels(4);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
}

From source file:org.modelio.api.ui.ModelioDialog.java

License:Apache License

@objid("7c153772-704b-11dd-933a-001ec947cd2a")
protected void setMessage(String newMessage, int newType) {
    Image newImage = null;//from w  w w  .j a  va2s . c  o m
    if (newMessage != null)
        switch (newType) {
        case 1: // '\001'
            newImage = JFaceResources.getImage("dialog_messasge_info_image");
            break;

        case 2: // '\002'
            newImage = JFaceResources.getImage("dialog_messasge_warning_image");
            break;

        case 3: // '\003'
            newImage = JFaceResources.getImage("dialog_message_error_image");
            break;
        }
    if (newType == 2) {
        setWarningMessage(newMessage);
    } else {
        setWarningMessage(null);
        showMessage(newMessage, newImage);
    }
}

From source file:org.modelio.api.ui.ModelioDialog.java

License:Apache License

@objid("bc2b30d0-120f-11e2-b5c6-002564c97630")
private Control createTitleArea(Composite parent) {
    this.titleArea = new Composite(parent, SWT.NONE);
    initializeDialogUnits(this.titleArea);
    FormData titleAreaData = new FormData();
    titleAreaData.top = new FormAttachment(0, 0);
    titleAreaData.left = new FormAttachment(0, 0);
    titleAreaData.right = new FormAttachment(100, 0);
    this.titleArea.setLayoutData(titleAreaData);
    FormLayout layout = new FormLayout();
    this.titleArea.setLayout(layout);
    this.titleArea.addDisposeListener(new DisposeListener() {
        @Override//from www . j  a v a2s. c  o  m
        public void widgetDisposed(DisposeEvent e) {
            if (ModelioDialog.this.titleAreaColor != null)
                ModelioDialog.this.titleAreaColor.dispose();
        }
    });

    org.eclipse.swt.widgets.Display display = this.titleArea.getDisplay();
    Color background;
    Color foreground;
    if (this.titleAreaRGB != null) {
        this.titleAreaColor = new Color(display, this.titleAreaRGB);
        background = this.titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(1);
    int horizontalSpacing = convertHorizontalDLUsToPixels(4);
    this.titleArea.setBackground(background);

    this.titleRightImageLabel = new Label(this.titleArea, SWT.NONE);
    this.titleRightImageLabel.setBackground(background);
    if (this.titleRightImage != null && !this.titleRightImage.isDisposed())
        this.titleRightImageLabel.setImage(this.titleRightImage);

    this.titleLeftImageLabel = new Label(this.titleArea, SWT.NONE);
    this.titleLeftImageLabel.setBackground(background);
    if (this.titleLeftImage == null || this.titleLeftImage.isDisposed())
        this.titleLeftImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    else
        this.titleLeftImageLabel.setImage(this.titleLeftImage);

    FormData rightImageData = new FormData();
    rightImageData.top = new FormAttachment(0, 0);
    rightImageData.right = new FormAttachment(100, 0);
    this.titleRightImageLabel.setLayoutData(rightImageData);

    FormData leftImageData = new FormData();
    leftImageData.top = new FormAttachment(0, 0);
    leftImageData.left = new FormAttachment(0, 0);
    this.titleLeftImageLabel.setLayoutData(leftImageData);

    this.titleLabel = new Label(this.titleArea, SWT.NONE);
    JFaceColors.setColors(this.titleLabel, foreground, background);
    this.titleLabel.setFont(JFaceResources.getBannerFont());
    this.titleLabel.setText(" ");
    FormData titleData = new FormData();
    titleData.left = new FormAttachment(this.titleLeftImageLabel, 5);
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(this.titleRightImageLabel, -5);
    this.titleLabel.setLayoutData(titleData);
    this.messageImageLabel = new Label(this.titleArea, SWT.NONE);
    this.messageImageLabel.setBackground(background);
    this.messageLabel = new Text(this.titleArea, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
    //this.messageLabel.setEnabled(false);
    this.messageLabel.setEditable(false);
    JFaceColors.setColors(this.messageLabel, foreground, background);
    this.messageLabel.setFont(JFaceResources.getDialogFont());
    this.messageLabelHeight = this.messageLabel.computeSize(-1, -1).y;
    this.leftFillerLabel = new Label(this.titleArea, SWT.NONE);
    this.leftFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();
    return this.titleArea;
}

From source file:org.modelio.app.preferences.ModelioPreferenceDialog.java

License:Open Source License

@objid("30b98bd5-cab0-4393-b635-b2702b1f80ed")
private void createTitle(Composite parent) {
    // image from plugin
    ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin("org.modelio.app.preferences",
            "icons/headerleft.png");

    Image image = imageDescriptor.createImage();
    setTitleLeftImage(image);/* ww w . j  a  va 2s .  co  m*/

    // _titleArea = new Composite(parent, SWT.NONE);
    this._titleArea = new Composite(parent, SWT.NONE);
    initializeDialogUnits(this._titleArea);
    GridData titleAreaData = new GridData(SWT.FILL, SWT.TOP, true, false);
    /*
     * titleAreaData.top = new FormAttachment(0, 0); titleAreaData.left = new FormAttachment(0, 0); titleAreaData.right = new
     * FormAttachment(100, 0);
     */
    this._titleArea.setLayoutData(titleAreaData);
    FormLayout layout = new FormLayout();
    this._titleArea.setLayout(layout);
    this._titleArea.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (ModelioPreferenceDialog.this._titleAreaColor != null)
                ModelioPreferenceDialog.this._titleAreaColor.dispose();
        }
    });

    org.eclipse.swt.widgets.Display display = this._titleArea.getDisplay();
    Color background;
    Color foreground;
    if (this._titleAreaRGB != null) {
        this._titleAreaColor = new Color(display, this._titleAreaRGB);
        background = this._titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(1);
    int horizontalSpacing = convertHorizontalDLUsToPixels(4);
    this._titleArea.setBackground(background);

    this._titleRightImageLabel = new Label(this._titleArea, SWT.NONE);
    this._titleRightImageLabel.setBackground(background);
    if (this._titleRightImage != null && !this._titleRightImage.isDisposed())
        this._titleRightImageLabel.setImage(this._titleRightImage);

    this._titleLeftImageLabel = new Label(this._titleArea, SWT.NONE);
    this._titleLeftImageLabel.setBackground(background);
    if (this._titleLeftImage == null || this._titleLeftImage.isDisposed())
        this._titleLeftImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    else
        this._titleLeftImageLabel.setImage(this._titleLeftImage);

    FormData rightImageData = new FormData();
    rightImageData.top = new FormAttachment(0, 0);
    rightImageData.right = new FormAttachment(100, 0);
    this._titleRightImageLabel.setLayoutData(rightImageData);

    FormData leftImageData = new FormData();
    leftImageData.top = new FormAttachment(0, 0);
    leftImageData.left = new FormAttachment(0, 0);
    this._titleLeftImageLabel.setLayoutData(leftImageData);

    this._titleLabel = new Label(this._titleArea, SWT.NONE);
    JFaceColors.setColors(this._titleLabel, foreground, background);
    this._titleLabel.setFont(JFaceResources.getBannerFont());
    this._titleLabel.setText(" ");
    FormData titleData = new FormData();
    titleData.left = new FormAttachment(this._titleLeftImageLabel, 5);
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(this._titleRightImageLabel, -5);
    this._titleLabel.setLayoutData(titleData);
    this._messageImageLabel = new Label(this._titleArea, SWT.NONE);
    this._messageImageLabel.setBackground(background);
    this._messageLabel = new Text(this._titleArea, SWT.READ_ONLY | SWT.MULTI);
    this._messageLabel.setEnabled(false);
    this._messageLabel.setEditable(false);
    JFaceColors.setColors(this._messageLabel, foreground, background);
    this._messageLabel.setFont(JFaceResources.getDialogFont());
    this._messageLabelHeight = this._messageLabel.computeSize(-1, -1).y;
    this._leftFillerLabel = new Label(this._titleArea, SWT.NONE);
    this._leftFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();

    Label titleBarSeparator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData barData = new GridData(768);
    titleBarSeparator.setLayoutData(barData);
}

From source file:org.modelio.core.ui.dialog.ModelioDialog.java

License:Open Source License

/**
 * Set an error message that will display in the message area on top of the
 * header of the dialog, with an error small icon.<br>
 * Removes the message if null is passed .
 * @param newErrorMessage The error message or null to remove the error message.
 *///  w  ww . j a  va 2  s .  c  o  m
@objid("00493ef0-4a05-1fe0-bf4c-001ec947cd2a")
protected void setErrorMessage(String newErrorMessage) {
    if ((this.errorMessage != null) ? this.errorMessage.equals(newErrorMessage) : newErrorMessage == null)
        return;
    this.errorMessage = newErrorMessage;
    if (this.errorMessage == null) {
        if (this.messageArea != null && !this.showingWarning)
            setMessageAreaVisible(false);
        if (this.showingError)
            this.showingError = false;
        if (this.message == null)
            this.message = "";
        updateMessage(this.message);
        this.messageImageLabel.setImage(this.messageImage);
        setImageLabelVisible(this.messageImage != null);
        if (this.showingWarning)
            setWarningMessage(this.warningMessage);
    } else {
        if (!this.showingError)
            this.showingError = true;
        if (this.showingWarning)
            setWarningMessage(null);
        if (this.messageArea == null) {
            this.messageArea = new ImageAndMessageArea(this.titleArea, 64);
            this.messageArea.setBackground(this.messageLabel.getBackground());
            this.animator = Policy.getAnimatorFactory().createAnimator(this.messageArea);
        }
        this.messageArea.setToolTipText(this.errorMessage);
        this.messageArea.setText(this.errorMessage);
        this.messageArea.setImage(JFaceResources.getImage("dialog_message_error_image"));
        setMessageAreaVisible(true);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(1);
    int horizontalSpacing = convertHorizontalDLUsToPixels(4);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
}

From source file:org.modelio.core.ui.dialog.ModelioDialog.java

License:Open Source License

/**
 * Set a warning message that will display in the message area on top of the
 * dialog, with a warning small icon.<br>
 * Removes the message if null is passed .
 * @param newMessage The warning message or null to remove the warning message.
 *///  w  w  w . j  ava 2s  . co m
@objid("0049ec10-4a05-1fe0-bf4c-001ec947cd2a")
protected void setWarningMessage(String newMessage) {
    // @SuppressWarnings("deprecation") added to
    if (this.warningMessage != null ? this.warningMessage.equals(newMessage) : newMessage == null)
        return;
    this.warningMessage = newMessage;
    if (this.warningMessage == null) {
        if (this.messageArea != null && !this.showingError)
            setMessageAreaVisible(false);
        if (this.showingWarning)
            this.showingWarning = false;
    } else {
        if (!this.showingWarning)
            this.showingWarning = true;
        this.warningMessage = newMessage;
        if (this.messageArea == null) {
            this.messageArea = new ImageAndMessageArea(this.titleArea, 64);
            this.messageArea.setBackground(this.messageLabel.getBackground());
            this.animator = Policy.getAnimatorFactory().createAnimator(this.messageArea);
        }
        this.messageArea.setToolTipText(this.warningMessage);
        this.messageArea.setText(this.warningMessage);
        this.messageArea.setImage(JFaceResources.getImage("dialog_messasge_warning_image"));
        setMessageAreaVisible(true);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(1);
    int horizontalSpacing = convertHorizontalDLUsToPixels(4);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
}