Example usage for org.eclipse.swt.widgets Label Label

List of usage examples for org.eclipse.swt.widgets Label Label

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Label Label.

Prototype

public Label(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:CustomControlExample.java

/**
 * Creates the "Example" widgets.//from w  w  w  .jav  a  2  s . c o  m
 */
void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (borderButton.getSelection())
        style |= SWT.BORDER;

    /* Create the example widgets */
    try {
        link1 = new Link(linkGroup, style);
        link1.setText(ControlExample.getResourceString("LinkText"));
    } catch (SWTError e) {
        // temporary code for photon
        Label label = new Label(linkGroup, SWT.CENTER | SWT.WRAP);
        label.setText("Link widget not suported");
    }
}

From source file:CustomControlExample.java

/**
 * Creates the "Example" widgets.//  w ww.  j a v a  2s  . co  m
 */
void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (wrapButton.getSelection())
        style |= SWT.WRAP;
    if (separatorButton.getSelection())
        style |= SWT.SEPARATOR;
    if (horizontalButton.getSelection())
        style |= SWT.HORIZONTAL;
    if (verticalButton.getSelection())
        style |= SWT.VERTICAL;
    if (shadowInButton.getSelection())
        style |= SWT.SHADOW_IN;
    if (shadowOutButton.getSelection())
        style |= SWT.SHADOW_OUT;
    if (shadowNoneButton.getSelection())
        style |= SWT.SHADOW_NONE;
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (leftButton.getSelection())
        style |= SWT.LEFT;
    if (centerButton.getSelection())
        style |= SWT.CENTER;
    if (rightButton.getSelection())
        style |= SWT.RIGHT;

    /* Create the example widgets */
    label1 = new Label(textLabelGroup, style);
    label1.setText(ControlExample.getResourceString("One"));
    label2 = new Label(textLabelGroup, style);
    label2.setText(ControlExample.getResourceString("Two"));
    label3 = new Label(textLabelGroup, style);
    if (wrapButton.getSelection()) {
        label3.setText(ControlExample.getResourceString("Wrap_Text"));
    } else {
        label3.setText(ControlExample.getResourceString("Three"));
    }
    label4 = new Label(imageLabelGroup, style);
    label4.setImage(instance.images[ControlExample.ciClosedFolder]);
    label5 = new Label(imageLabelGroup, style);
    label5.setImage(instance.images[ControlExample.ciOpenFolder]);
    label6 = new Label(imageLabelGroup, style);
    label6.setImage(instance.images[ControlExample.ciTarget]);
}

From source file:CustomControlExample.java

/**
 * Creates the "Fonts" group./*from  ww  w  .j  a v a2s  .  co m*/
 */
void createColorGroup() {
    /* Create the group */
    colorGroup = new Group(controlGroup, SWT.NONE);
    colorGroup.setLayout(new GridLayout(2, false));
    colorGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    colorGroup.setText(ControlExample.getResourceString("Colors"));

    new Label(colorGroup, SWT.NONE).setText(ControlExample.getResourceString("Foreground_Color"));
    foregroundButton = new Button(colorGroup, SWT.PUSH);

    new Label(colorGroup, SWT.NONE).setText(ControlExample.getResourceString("Background_Color"));
    backgroundButton = new Button(colorGroup, SWT.PUSH);

    new Label(colorGroup, SWT.NONE).setText(ControlExample.getResourceString("Selection_Foreground_Color"));
    foregroundSelectionButton = new Button(colorGroup, SWT.PUSH);

    new Label(colorGroup, SWT.NONE).setText(ControlExample.getResourceString("Selection_Background_Color"));
    backgroundSelectionButton = new Button(colorGroup, SWT.PUSH);

    fontButton = new Button(colorGroup, SWT.PUSH);
    fontButton.setText(ControlExample.getResourceString("Font"));
    fontButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));

    itemFontButton = new Button(colorGroup, SWT.PUSH);
    itemFontButton.setText(ControlExample.getResourceString("Item_Font"));
    itemFontButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));

    Button defaultsButton = new Button(colorGroup, SWT.PUSH);
    defaultsButton.setText(ControlExample.getResourceString("Defaults"));

    Shell shell = controlGroup.getShell();
    final ColorDialog colorDialog = new ColorDialog(shell);
    final FontDialog fontDialog = new FontDialog(shell);

    /* Create images to display current colors */
    int imageSize = 12;
    Display display = shell.getDisplay();
    foregroundImage = new Image(display, imageSize, imageSize);
    backgroundImage = new Image(display, imageSize, imageSize);
    foregroundSelectionImage = new Image(display, imageSize, imageSize);
    backgroundSelectionImage = new Image(display, imageSize, imageSize);

    /* Add listeners to set the colors and font */
    foregroundButton.setImage(foregroundImage); // sets the size of the
    // button
    foregroundButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color oldColor = foregroundColor;
            if (oldColor == null) {
                Control[] controls = getExampleWidgets();
                if (controls.length > 0)
                    oldColor = controls[0].getForeground();
            }
            if (oldColor != null)
                colorDialog.setRGB(oldColor.getRGB()); // seed dialog with
            // current color
            RGB rgb = colorDialog.open();
            if (rgb == null)
                return;
            oldColor = foregroundColor; // save old foreground color to
            // dispose when done
            foregroundColor = new Color(event.display, rgb);
            setExampleWidgetForeground();
            if (oldColor != null)
                oldColor.dispose();
        }
    });
    backgroundButton.setImage(backgroundImage); // sets the size of the
    // button
    backgroundButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color oldColor = backgroundColor;
            if (oldColor == null) {
                Control[] controls = getExampleWidgets();
                if (controls.length > 0)
                    oldColor = controls[0].getBackground(); // seed dialog
                // with current
                // color
            }
            if (oldColor != null)
                colorDialog.setRGB(oldColor.getRGB());
            RGB rgb = colorDialog.open();
            if (rgb == null)
                return;
            oldColor = backgroundColor; // save old background color to
            // dispose when done
            backgroundColor = new Color(event.display, rgb);
            setExampleWidgetBackground();
            if (oldColor != null)
                oldColor.dispose();
        }
    });
    foregroundSelectionButton.setImage(foregroundSelectionImage); // sets
    // the
    // size
    // of
    // the
    // button
    foregroundSelectionButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color oldColor = foregroundSelectionColor;
            if (oldColor == null) {
                Control[] controls = getExampleWidgets();
                if (controls.length > 0)
                    oldColor = controls[0].getForeground();
            }
            if (oldColor != null)
                colorDialog.setRGB(oldColor.getRGB()); // seed dialog with
            // current color
            RGB rgb = colorDialog.open();
            if (rgb == null)
                return;
            oldColor = foregroundSelectionColor; // save old foreground
            // color to dispose when
            // done
            foregroundSelectionColor = new Color(event.display, rgb);
            setExampleWidgetForeground();
            if (oldColor != null)
                oldColor.dispose();
        }
    });
    backgroundSelectionButton.setImage(backgroundSelectionImage); // sets
    // the
    // size
    // of
    // the
    // button
    backgroundSelectionButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color oldColor = backgroundSelectionColor;
            if (oldColor == null) {
                Control[] controls = getExampleWidgets();
                if (controls.length > 0)
                    oldColor = controls[0].getBackground(); // seed dialog
                // with current
                // color
            }
            if (oldColor != null)
                colorDialog.setRGB(oldColor.getRGB());
            RGB rgb = colorDialog.open();
            if (rgb == null)
                return;
            oldColor = backgroundSelectionColor; // save old background
            // color to dispose when
            // done
            backgroundSelectionColor = new Color(event.display, rgb);
            setExampleWidgetBackground();
            if (oldColor != null)
                oldColor.dispose();
        }
    });
    fontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Font oldFont = font;
            if (oldFont == null) {
                Control[] controls = getExampleWidgets();
                if (controls.length > 0)
                    oldFont = controls[0].getFont();
            }
            if (oldFont != null)
                fontDialog.setFontList(oldFont.getFontData()); // seed
            // dialog
            // with
            // current
            // font
            FontData fontData = fontDialog.open();
            if (fontData == null)
                return;
            oldFont = font; // dispose old font when done
            font = new Font(event.display, fontData);
            setExampleWidgetFont();
            setExampleWidgetSize();
            if (oldFont != null)
                oldFont.dispose();
        }
    });

    /* Add listeners to set the colors and font */
    itemFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Font oldFont = itemFont;
            if (oldFont == null)
                oldFont = tabFolder1.getItem(0).getFont();
            fontDialog.setFontList(oldFont.getFontData());
            FontData fontData = fontDialog.open();
            if (fontData == null)
                return;
            oldFont = itemFont;
            itemFont = new Font(event.display, fontData);
            setItemFont();
            setExampleWidgetSize();
            if (oldFont != null)
                oldFont.dispose();
        }
    });

    defaultsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            resetColorsAndFonts();
        }
    });

    shell.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            if (foregroundImage != null)
                foregroundImage.dispose();
            if (backgroundImage != null)
                backgroundImage.dispose();
            if (foregroundColor != null)
                foregroundColor.dispose();
            if (backgroundColor != null)
                backgroundColor.dispose();
            if (font != null)
                font.dispose();
            foregroundColor = null;
            backgroundColor = null;
            font = null;
            if (foregroundSelectionImage != null)
                foregroundSelectionImage.dispose();
            if (backgroundSelectionImage != null)
                backgroundSelectionImage.dispose();
            if (foregroundSelectionColor != null)
                foregroundSelectionColor.dispose();
            if (backgroundSelectionColor != null)
                backgroundSelectionColor.dispose();
            foregroundSelectionColor = null;
            backgroundSelectionColor = null;
            if (itemFont != null)
                itemFont.dispose();
            itemFont = null;
        }
    });
}