Example usage for org.eclipse.jface.resource JFaceColors setColors

List of usage examples for org.eclipse.jface.resource JFaceColors setColors

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceColors setColors.

Prototype

public static void setColors(Control control, Color foreground, Color background) 

Source Link

Document

Set the foreground and background colors of the control to the specified values.

Usage

From source file:com.architexa.org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog.java

License:Open Source License

/**
 * A convenient method to create CLabel titles (like the ones used in the
 * Preferences dialog in the Eclipse workbench) throughout the dialog.
 * /*  w ww  .j a  va 2 s . com*/
 * @param composite   The composite in which the title is to be created (it must have a
 *                   GridLayout with two columns).
 * @param text         The title to be displayed
 * @return          The newly created CLabel for convenience
 */
protected CLabel createSectionTitle(Composite composite, String text) {
    CLabel cTitle = new CLabel(composite, SWT.LEFT);
    Color background = JFaceColors.getBannerBackground(composite.getDisplay());
    Color foreground = JFaceColors.getBannerForeground(composite.getDisplay());
    JFaceColors.setColors(cTitle, foreground, background);
    cTitle.setFont(JFaceResources.getBannerFont());
    cTitle.setText(text);
    cTitle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

    if (titleImage == null) {
        titleImage = new Image(composite.getDisplay(), ImageDescriptor
                .createFromFile(Internal.class, "icons/customizer_dialog_title.gif").getImageData()); //$NON-NLS-1$
        composite.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
                titleImage.dispose();
                titleImage = null;
            }
        });
    }

    Label imageLabel = new Label(composite, SWT.LEFT);
    imageLabel.setBackground(background);
    imageLabel.setImage(titleImage);
    imageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));

    Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.horizontalSpan = 2;
    separator.setLayoutData(data);

    return cTitle;
}

From source file:com.gorillalogic.monkeyconsole.editors.utils.TitleAreaDialogStyledTextMessage.java

License:Open Source License

/**
 * Creates the dialog's title area./*from w  w w.j  a v a2  s  . c  o m*/
 * 
 * @param parent
 *            the SWT parent for the title area widgets
 * @return Control with the highest x axis value.
 */
private Control createTitleArea(Composite parent) {

    // add a dispose listener
    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            if (titleAreaColor != null) {
                titleAreaColor.dispose();
            }
        }
    });
    // Determine the background color of the title bar
    Display display = parent.getDisplay();
    Color background;
    Color foreground;
    if (titleAreaRGB != null) {
        titleAreaColor = new Color(display, titleAreaRGB);
        background = titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }

    parent.setBackground(background);
    int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    // Dialog image @ right
    titleImageLabel = new Label(parent, SWT.CENTER);
    titleImageLabel.setBackground(background);
    if (titleAreaImage == null)
        titleImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    else
        titleImageLabel.setImage(titleAreaImage);

    FormData imageData = new FormData();
    imageData.top = new FormAttachment(0, 0);
    // Note: do not use horizontalSpacing on the right as that would be a
    // regression from
    // the R2.x style where there was no margin on the right and images are
    // flush to the right
    // hand side. see reopened comments in 41172
    imageData.right = new FormAttachment(100, 0); // horizontalSpacing
    titleImageLabel.setLayoutData(imageData);
    // Title label @ top, left
    titleLabel = new Label(parent, SWT.LEFT);
    JFaceColors.setColors(titleLabel, foreground, background);
    titleLabel.setFont(JFaceResources.getBannerFont());
    titleLabel.setText(" ");//$NON-NLS-1$
    FormData titleData = new FormData();
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(titleImageLabel);
    titleData.left = new FormAttachment(0, horizontalSpacing);
    titleLabel.setLayoutData(titleData);
    // Message image @ bottom, left
    messageImageLabel = new Label(parent, SWT.CENTER);
    messageImageLabel.setBackground(background);
    // Message label @ bottom, center
    messageLabel = new Link(parent, SWT.WRAP | SWT.READ_ONLY);
    JFaceColors.setColors(messageLabel, foreground, background);
    messageLabel.setText(" \n "); // two lines//$NON-NLS-1$
    messageLabel.setFont(JFaceResources.getDialogFont());
    messageLabelHeight = messageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    // Filler labels
    leftFillerLabel = new Label(parent, SWT.CENTER);
    leftFillerLabel.setBackground(background);
    bottomFillerLabel = new Label(parent, SWT.CENTER);
    bottomFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();
    if (titleImageLargest)
        return titleImageLabel;
    return messageLabel;
}

From source file:net.heartsome.cat.common.ui.wizard.TSTitleAreaDialog.java

License:Open Source License

/**
 * Creates the dialog's title area.//from w  w w  .  ja  v a  2s .com
 * 
 * @param parent
 *            the SWT parent for the title area widgets
 * @return Control with the highest x axis value.
 */
private Control createTitleArea(Composite parent) {

    // add a dispose listener
    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            if (titleAreaColor != null) {
                titleAreaColor.dispose();
            }
        }
    });
    // Determine the background color of the title bar
    Display display = parent.getDisplay();
    Color background;
    Color foreground;
    if (titleAreaRGB != null) {
        titleAreaColor = new Color(display, titleAreaRGB);
        background = titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }

    parent.setBackground(background);
    int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    // Dialog image @ right
    titleImageLabel = new Label(parent, SWT.CENTER);
    titleImageLabel.setBackground(background);
    if (titleAreaImage == null)
        titleImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    else
        titleImageLabel.setImage(titleAreaImage);

    FormData imageData = new FormData();
    imageData.top = new FormAttachment(0, 0);
    // Note: do not use horizontalSpacing on the right as that would be a
    // regression from
    // the R2.x style where there was no margin on the right and images are
    // flush to the right
    // hand side. see reopened comments in 41172
    imageData.right = new FormAttachment(100, 0); // horizontalSpacing
    titleImageLabel.setLayoutData(imageData);
    // Title label @ top, left
    titleLabel = new Label(parent, SWT.LEFT);
    JFaceColors.setColors(titleLabel, foreground, background);
    titleLabel.setFont(JFaceResources.getBannerFont());
    titleLabel.setText(" ");//$NON-NLS-1$
    FormData titleData = new FormData();
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(titleImageLabel);
    titleData.left = new FormAttachment(0, horizontalSpacing);
    titleLabel.setLayoutData(titleData);
    // Message image @ bottom, left
    messageImageLabel = new Label(parent, SWT.CENTER);
    messageImageLabel.setBackground(background);
    // Message label @ bottom, center
    messageLabel = new Label(parent, SWT.WRAP | SWT.READ_ONLY);
    JFaceColors.setColors(messageLabel, foreground, background);
    messageLabel.setText(" \n "); // two lines//$NON-NLS-1$
    messageLabel.setFont(JFaceResources.getDialogFont());
    messageLabel.setBackground(JFaceColors.getBannerBackground(Display.getDefault()));

    messageLabelHeight = messageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    // Filler labels
    leftFillerLabel = new Label(parent, SWT.CENTER);
    leftFillerLabel.setBackground(background);
    bottomFillerLabel = new Label(parent, SWT.CENTER);
    bottomFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();
    if (titleImageLargest)
        return titleImageLabel;
    return messageLabel;
}

From source file:org.eclipse.birt.report.designer.data.ui.property.AbstractTitlePropertyDialog.java

License:Open Source License

private void createDialogTitleArea(Composite parent) {
    Composite contents = new Composite(parent, SWT.NONE);
    contents.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    FormLayout layout = new FormLayout();
    contents.setLayout(layout);/*from   ww  w  .java  2  s.co  m*/

    titleArea = new Composite(contents, SWT.NONE);
    initializeDialogUnits(titleArea);

    FormData titleAreaData = new FormData();
    titleAreaData.top = new FormAttachment(0, 0);
    titleAreaData.left = new FormAttachment(0, 0);
    titleAreaData.right = new FormAttachment(100, 0);
    titleArea.setLayoutData(titleAreaData);

    layout = new FormLayout();
    titleArea.setLayout(layout);

    // add a dispose listener
    titleArea.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            if (titleAreaColor != null) {
                titleAreaColor.dispose();
            }
        }
    });
    // Determine the background color of the title bar
    Display display = titleArea.getDisplay();
    Color background;
    Color foreground;
    if (titleAreaRGB != null) {
        titleAreaColor = new Color(display, titleAreaRGB);
        background = titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    titleArea.setBackground(background);
    // Dialog image @ right
    titleImageLabel = new Label(titleArea, SWT.CENTER);
    titleImageLabel.setBackground(background);
    if (titleImage == null || titleImage.isDisposed()) {
        titleImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    } else {
        titleImageLabel.setImage(titleImage);
    }
    FormData imageData = new FormData();
    imageData.top = new FormAttachment(0, 0);
    // Note: do not use horizontalSpacing on the right as that would be a
    // regression from
    // the R2.x style where there was no margin on the right and images are
    // flush to the right
    // hand side. see reopened comments in 41172
    imageData.right = new FormAttachment(100, 0); // horizontalSpacing
    titleImageLabel.setLayoutData(imageData);
    // Title label @ top, left
    titleLabel = new Label(titleArea, SWT.LEFT);
    JFaceColors.setColors(titleLabel, foreground, background);
    titleLabel.setFont(JFaceResources.getBannerFont());
    titleLabel.setText(" ");//$NON-NLS-1$
    FormData titleData = new FormData();
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(titleImageLabel);
    titleData.left = new FormAttachment(0, horizontalSpacing);
    titleLabel.setLayoutData(titleData);
    messageImageLabel = new Label(titleArea, SWT.CENTER);
    messageImageLabel.setBackground(background);
    messageLabel = new Text(titleArea, SWT.WRAP | SWT.READ_ONLY);
    JFaceColors.setColors(messageLabel, foreground, background);
    messageLabel.setText(" \n "); // two lines//$NON-NLS-1$
    messageLabel.setFont(JFaceResources.getDialogFont());
    messageLabelHeight = messageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    leftFillerLabel = new Label(titleArea, SWT.CENTER);
    leftFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();

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

From source file:org.eclipse.birt.report.designer.ui.dialogs.StyleBuilder.java

License:Open Source License

private void createDialogTitleArea(Composite parent) {

    Composite contents = new Composite(parent, SWT.NONE);
    contents.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    FormLayout layout = new FormLayout();
    contents.setLayout(layout);//from ww  w  . ja v a2  s .  co m

    dialogTitleArea = new Composite(contents, SWT.NONE);
    initializeDialogUnits(dialogTitleArea);

    FormData titleAreaData = new FormData();
    titleAreaData.top = new FormAttachment(0, 0);
    titleAreaData.left = new FormAttachment(0, 0);
    titleAreaData.right = new FormAttachment(100, 0);
    dialogTitleArea.setLayoutData(titleAreaData);

    layout = new FormLayout();
    dialogTitleArea.setLayout(layout);

    // add a dispose listener
    dialogTitleArea.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            if (titleAreaColor != null) {
                titleAreaColor.dispose();
            }
        }
    });
    // Determine the background color of the title bar
    Display display = dialogTitleArea.getDisplay();
    Color background;
    Color foreground;
    if (titleAreaRGB != null) {
        titleAreaColor = new Color(display, titleAreaRGB);
        background = titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }

    dialogTitleArea.setBackground(background);
    int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    // Dialog image @ right
    titleImageLabel = new Label(dialogTitleArea, SWT.CENTER);
    titleImageLabel.setBackground(background);
    if (titleAreaImage == null)
        titleImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    else
        titleImageLabel.setImage(titleAreaImage);

    FormData imageData = new FormData();
    imageData.top = new FormAttachment(0, 0);
    // Note: do not use horizontalSpacing on the right as that would be a
    // regression from
    // the R2.x style where there was no margin on the right and images are
    // flush to the right
    // hand side. see reopened comments in 41172
    imageData.right = new FormAttachment(100, 0); // horizontalSpacing
    titleImageLabel.setLayoutData(imageData);
    // Title label @ top, left
    titleLabel = new Label(dialogTitleArea, SWT.LEFT);
    JFaceColors.setColors(titleLabel, foreground, background);
    titleLabel.setFont(JFaceResources.getBannerFont());
    titleLabel.setText(" ");//$NON-NLS-1$
    FormData titleData = new FormData();
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(titleImageLabel);
    titleData.left = new FormAttachment(0, horizontalSpacing);
    titleLabel.setLayoutData(titleData);
    // Message image @ bottom, left
    messageImageLabel = new Label(dialogTitleArea, SWT.CENTER);
    messageImageLabel.setBackground(background);
    // Message label @ bottom, center
    messageLabel = new Text(dialogTitleArea, SWT.WRAP | SWT.READ_ONLY);
    JFaceColors.setColors(messageLabel, foreground, background);
    messageLabel.setText(" \n "); // two lines//$NON-NLS-1$
    messageLabel.setFont(JFaceResources.getDialogFont());
    messageLabelHeight = messageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    // Filler labels
    leftFillerLabel = new Label(dialogTitleArea, SWT.CENTER);
    leftFillerLabel.setBackground(background);
    bottomFillerLabel = new Label(dialogTitleArea, SWT.CENTER);
    bottomFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();

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

From source file:org.eclipse.contribution.visualiser.internal.preference.VisualiserPreferencesDialog.java

License:Open Source License

/**
 * Creates the dialog's title area.//w w w.  j  a  va  2s. c  om
 *
 * @param parent the SWT parent for the title area composite
 * @return the created title area composite
 */
private Composite createTitleArea(Composite parent) {
    // Create the title area which will contain
    // a title, message, and image.
    titleArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 2;
    layout.marginWidth = 2;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    layout.numColumns = 2;

    // Get the background color for the title area
    Display display = parent.getDisplay();
    Color background = JFaceColors.getBannerBackground(display);
    final Color foreground = JFaceColors.getBannerForeground(display);

    GridData layoutData = new GridData(GridData.FILL_BOTH);
    titleArea.setLayout(layout);
    titleArea.setLayoutData(layoutData);
    titleArea.setBackground(background);

    RGB rgb = new RGB(171, 168, 165);
    final Color borderColor = new Color(titleArea.getDisplay(), rgb);

    titleArea.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(borderColor);
            Rectangle bounds = titleArea.getClientArea();
            bounds.height = bounds.height - 2;
            bounds.width = bounds.width - 1;
            e.gc.drawRectangle(bounds);
        }
    });

    // Add a dispose listener
    titleArea.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            if (titleAreaColor != null)
                titleAreaColor.dispose();
            if (errorMsgAreaBackground != null)
                errorMsgAreaBackground.dispose();
            borderColor.dispose();
        }
    });

    // Message label
    messageLabel = new CLabel(titleArea, SWT.LEFT);
    JFaceColors.setColors(messageLabel, foreground, background);
    messageLabel.setText(" "); //$NON-NLS-1$
    messageLabel.setFont(JFaceResources.getBannerFont());
    GridData gd = new GridData(GridData.FILL_BOTH);
    messageLabel.setLayoutData(gd);

    // Title image
    titleImage = new Label(titleArea, SWT.LEFT);
    titleImage.setBackground(background);
    titleImage.setImage(JFaceResources.getImage(PREF_DLG_TITLE_IMG));
    gd = new GridData();
    gd.horizontalAlignment = GridData.END;
    titleImage.setLayoutData(gd);

    return titleArea;
}

From source file:org.eclipse.ui.internal.ide.dialogs.WelcomeEditor.java

License:Open Source License

/**
 * Creates the wizard's title area./*from  w w w  . j av  a  2 s .c  o m*/
 *
 * @param parent the SWT parent for the title area composite
 * @return the created info area composite
 */
private Composite createInfoArea(Composite parent) {
    // Create the title area which will contain
    // a title, message, and image.
    this.scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    this.scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    final Composite infoArea = new Composite(this.scrolledComposite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 10;
    layout.verticalSpacing = 5;
    layout.numColumns = 2;
    infoArea.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    infoArea.setLayoutData(data);
    boolean wrapped = parser.isFormatWrapped();
    int HINDENT = 20;

    // Get the background color for the title area
    Display display = parent.getDisplay();
    Color background = JFaceColors.getBannerBackground(display);
    Color foreground = JFaceColors.getBannerForeground(display);
    infoArea.setBackground(background);

    int textStyle = SWT.MULTI | SWT.READ_ONLY;
    if (wrapped) {
        textStyle = textStyle | SWT.WRAP;
    }
    StyledText sampleStyledText = null;
    // Create the intro item
    WelcomeItem item = getIntroItem();
    if (item != null) {
        StyledText styledText = new StyledText(infoArea, textStyle);
        this.texts.add(styledText);
        sampleStyledText = styledText;
        styledText.setCursor(null);
        JFaceColors.setColors(styledText, foreground, background);
        styledText.setText(getIntroItem().getText());
        setBoldRanges(styledText, item.getBoldRanges());
        setLinkRanges(styledText, item.getActionRanges());
        setLinkRanges(styledText, item.getHelpRanges());
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        gd.horizontalIndent = HINDENT;
        gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
        styledText.setLayoutData(gd);
        styledText.setData(item);
        addListeners(styledText);

        Label spacer = new Label(infoArea, SWT.NONE);
        spacer.setBackground(background);
        gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
        gd.horizontalSpan = 2;
        spacer.setLayoutData(gd);
    }
    firstText = sampleStyledText;

    // Create the welcome items
    Label imageLabel = null;
    WelcomeItem[] items = getItems();
    for (int i = 0; i < items.length; i++) {
        Label label = new Label(infoArea, SWT.NONE);
        label.setBackground(background);
        label.setImage(PlatformUI.getWorkbench().getSharedImages()
                .getImage(IDEInternalWorkbenchImages.IMG_OBJS_WELCOME_ITEM));
        GridData gd = new GridData();
        gd.horizontalIndent = HINDENT;
        gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
        label.setLayoutData(gd);
        if (imageLabel == null) {
            imageLabel = label;
        }

        StyledText styledText = new StyledText(infoArea, textStyle);
        this.texts.add(styledText);
        sampleStyledText = styledText;
        styledText.setCursor(null);
        JFaceColors.setColors(styledText, foreground, background);
        styledText.setText(items[i].getText());
        setBoldRanges(styledText, items[i].getBoldRanges());
        setLinkRanges(styledText, items[i].getActionRanges());
        setLinkRanges(styledText, items[i].getHelpRanges());
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
        gd.verticalSpan = 2;
        styledText.setLayoutData(gd);
        styledText.setData(items[i]);
        addListeners(styledText);

        Label spacer = new Label(infoArea, SWT.NONE);
        spacer.setBackground(background);
        gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
        gd.horizontalSpan = 2;
        spacer.setLayoutData(gd);

        // create context menu
        MenuManager menuMgr = new MenuManager("#PopUp"); //$NON-NLS-1$
        menuMgr.add(copyAction);
        styledText.setMenu(menuMgr.createContextMenu(styledText));
    }

    lastText = sampleStyledText;
    this.scrolledComposite.setContent(infoArea);
    Point p = infoArea.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    this.scrolledComposite.setMinHeight(p.y);
    if (wrapped) {
        // introduce a horizontal scroll bar after a minimum width is reached
        this.scrolledComposite.setMinWidth(WRAP_MIN_WIDTH);
    } else {
        this.scrolledComposite.setMinWidth(p.x);
    }
    this.scrolledComposite.setExpandHorizontal(true);
    this.scrolledComposite.setExpandVertical(true);

    // When the welcome editor is resized, we need to set the width hint for
    // wrapped StyledText widgets so that the wrapped height will be recalculated.
    if (wrapped && (imageLabel != null)) {
        // figure out how wide the StyledText widgets should be, do this by first
        // calculating the width of the area not used by styled text widgets
        Rectangle bounds = imageLabel.getBounds();
        final int adjust = HINDENT + bounds.width + layout.verticalSpacing + (layout.marginWidth * 2);
        final int adjustFirst = HINDENT + (layout.marginWidth * 2);
        infoArea.addListener(SWT.Resize, new Listener() {
            public void handleEvent(Event event) {
                int w = scrolledComposite.getClientArea().width;
                // if the horizontal scroll bar exists, we want to wrap to the
                // minimum wrap width
                if (w < WRAP_MIN_WIDTH) {
                    w = WRAP_MIN_WIDTH;
                }
                for (int i = 0; i < texts.size(); i++) {
                    int extent;
                    if (i == 0) {
                        extent = w - adjustFirst;
                    } else {
                        extent = w - adjust;
                    }
                    StyledText text = (StyledText) texts.get(i);
                    Point p = text.computeSize(extent, SWT.DEFAULT, false);
                    ((GridData) text.getLayoutData()).widthHint = p.x;
                }
                // reset the scrolled composite height since the height of the 
                // styled text widgets have changed
                Point p = infoArea.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
                scrolledComposite.setMinHeight(p.y);
            }
        });
    }

    // Adjust the scrollbar increments
    if (sampleStyledText == null) {
        this.scrolledComposite.getHorizontalBar().setIncrement(HORZ_SCROLL_INCREMENT);
        this.scrolledComposite.getVerticalBar().setIncrement(VERT_SCROLL_INCREMENT);
    } else {
        GC gc = new GC(sampleStyledText);
        int width = gc.getFontMetrics().getAverageCharWidth();
        gc.dispose();
        this.scrolledComposite.getHorizontalBar().setIncrement(width);
        this.scrolledComposite.getVerticalBar().setIncrement(sampleStyledText.getLineHeight());
    }
    return infoArea;
}

From source file:org.eclipse.ui.internal.ide.dialogs.WelcomeEditor.java

License:Open Source License

/**
 * Creates the wizard's title area.//from   w  w  w .  j  av a 2s  . c  om
 *
 * @param parent the SWT parent for the title area composite
 * @return the created title area composite
 */
private Composite createTitleArea(Composite parent) {
    // Get the background color for the title area
    Display display = parent.getDisplay();
    Color background = JFaceColors.getBannerBackground(display);
    Color foreground = JFaceColors.getBannerForeground(display);

    // Create the title area which will contain
    // a title, message, and image.
    Composite titleArea = new Composite(parent, SWT.NONE | SWT.NO_FOCUS);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    layout.numColumns = 2;
    titleArea.setLayout(layout);
    titleArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    titleArea.setBackground(background);

    // Message label
    final CLabel messageLabel = new CLabel(titleArea, SWT.LEFT) {
        protected String shortenText(GC gc, String text, int width) {
            if (gc.textExtent(text, SWT.DRAW_MNEMONIC).x <= width) {
                return text;
            }
            final String ellipsis = "..."; //$NON-NLS-1$
            int ellipseWidth = gc.textExtent(ellipsis, SWT.DRAW_MNEMONIC).x;
            int length = text.length();
            int end = length - 1;
            while (end > 0) {
                text = text.substring(0, end);
                int l1 = gc.textExtent(text, SWT.DRAW_MNEMONIC).x;
                if (l1 + ellipseWidth <= width) {
                    return text + ellipsis;
                }
                end--;
            }
            return text + ellipsis;
        }
    };
    JFaceColors.setColors(messageLabel, foreground, background);
    messageLabel.setText(getBannerTitle());
    messageLabel.setFont(JFaceResources.getHeaderFont());

    final IPropertyChangeListener fontListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (JFaceResources.HEADER_FONT.equals(event.getProperty())) {
                messageLabel.setFont(JFaceResources.getHeaderFont());
            }
        }
    };

    messageLabel.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            JFaceResources.getFontRegistry().removeListener(fontListener);
        }
    });

    JFaceResources.getFontRegistry().addListener(fontListener);

    GridData gd = new GridData(GridData.FILL_BOTH);
    messageLabel.setLayoutData(gd);

    // Title image
    Label titleImage = new Label(titleArea, SWT.LEFT);
    titleImage.setBackground(background);
    titleImage.setImage(PlatformUI.getWorkbench().getSharedImages()
            .getImage(IDEInternalWorkbenchImages.IMG_OBJS_WELCOME_BANNER));
    gd = new GridData();
    gd.horizontalAlignment = GridData.END;
    titleImage.setLayoutData(gd);

    return titleArea;
}

From source file:org.kalypso.contribs.eclipse.jface.wizard.view.WizardView.java

License:Open Source License

/**
 * @see org.eclipse.jface.wizard.IWizardContainer#updateTitleBar()
 *//* w w  w. j  a v  a  2s.  c  om*/
@Override
public void updateTitleBar() {
    // update title-bar colors
    final RGB backgroundRGB;
    final RGB foregroundRGB = m_defaultTitleForeground;
    if (m_wizard != null)
        backgroundRGB = m_wizard.getTitleBarColor();
    else
        backgroundRGB = m_defaultTitleBackground;

    final ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    colorRegistry.put(m_backgroundRgbId, backgroundRGB);
    colorRegistry.put(m_foregroundRgbId, foregroundRGB);

    final Color background = colorRegistry.get(m_backgroundRgbId);
    final Color foreground = colorRegistry.get(m_foregroundRgbId);

    if (m_parent != null && !m_parent.isDisposed())
        m_parent.setBackground(background);
    if (m_titleImage != null && !m_titleImage.isDisposed())
        m_titleImage.setBackground(background);
    if (m_titleLabel != null && !m_titleLabel.isDisposed())
        JFaceColors.setColors(m_titleLabel, foreground, background);
    if (m_messageImageLabel != null && !m_messageImageLabel.isDisposed())
        m_messageImageLabel.setBackground(background);
    if (m_messageLabel != null && !m_messageLabel.isDisposed())
        JFaceColors.setColors(m_messageLabel, foreground, background);
    if (m_leftFillerLabel != null && !m_leftFillerLabel.isDisposed())
        m_leftFillerLabel.setBackground(background);
    if (m_bottomFillerLabel != null && !m_bottomFillerLabel.isDisposed())
        m_bottomFillerLabel.setBackground(background);

    String s = null;
    if (m_currentPage != null)
        s = m_currentPage.getTitle();
    if (s == null)
        s = ""; //$NON-NLS-1$
    setWizardTitle(s);
    if (m_currentPage != null)
        setWizardTitleImage(m_currentPage.getImage());

    updateDescriptionMessage();
    updateMessage();
}

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/*  w  w  w .j a v a  2  s . co  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;
}