Example usage for org.eclipse.swt.widgets Display getDefault

List of usage examples for org.eclipse.swt.widgets Display getDefault

Introduction

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

Prototype

public static Display getDefault() 

Source Link

Document

Returns the default display.

Usage

From source file:Draw2D_Example.java

public static void main(String args[]) {
    final Label label = new Label("Press a button!");
    Shell shell = new Shell();

    LightweightSystem lws = new LightweightSystem(shell);
    Figure parent = new Figure();
    parent.setLayoutManager(new XYLayout());
    lws.setContents(parent);// w w  w. j  ava  2  s .co m

    Clickable above = new CheckBox("I'm above!");
    parent.add(above, new Rectangle(10, 10, 80, 20));
    ButtonModel aModel = new ToggleModel();
    aModel.addChangeListener(new ChangeListener() {
        public void handleStateChanged(ChangeEvent e) {
            label.setText("Above");
        }
    });
    above.setModel(aModel);

    Clickable below = new CheckBox("I'm below!");
    parent.add(below, new Rectangle(10, 40, 80, 20));
    ButtonModel bModel = new ToggleModel();
    bModel.addChangeListener(new ChangeListener() {
        public void handleStateChanged(ChangeEvent e) {
            label.setText("Below");
        }
    });
    below.setModel(bModel);

    ButtonGroup bGroup = new ButtonGroup();
    bGroup.add(aModel);
    bGroup.add(bModel);
    bGroup.setDefault(bModel);

    parent.add(label, new Rectangle(10, 70, 80, 20));
    shell.setSize(130, 120);
    shell.open();
    shell.setText("Example");
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:Flowchart.java

public static void main(String args[]) {
    Shell shell = new Shell();
    shell.setSize(200, 300);//from   w  ww . j  a va2  s .co m
    shell.open();
    shell.setText("Flowchart");
    LightweightSystem lws = new LightweightSystem(shell);
    ChartFigure flowchart = new ChartFigure();
    lws.setContents(flowchart);

    TerminatorFigure start = new TerminatorFigure();
    start.setName("Start");
    start.setBounds(new Rectangle(40, 20, 80, 20));
    DecisionFigure dec = new DecisionFigure();
    dec.setName("Should I?");
    dec.setBounds(new Rectangle(30, 60, 100, 60));
    ProcessFigure proc = new ProcessFigure();
    proc.setName("Do it!");
    proc.setBounds(new Rectangle(40, 140, 80, 40));
    TerminatorFigure stop = new TerminatorFigure();
    stop.setName("End");
    stop.setBounds(new Rectangle(40, 200, 80, 20));

    PathFigure path1 = new PathFigure();
    path1.setSourceAnchor(start.outAnchor);
    path1.setTargetAnchor(dec.inAnchor);
    PathFigure path2 = new PathFigure();
    path2.setSourceAnchor(dec.yesAnchor);
    path2.setTargetAnchor(proc.inAnchor);
    PathFigure path3 = new PathFigure();
    path3.setSourceAnchor(dec.noAnchor);
    path3.setTargetAnchor(stop.inAnchor);
    PathFigure path4 = new PathFigure();
    path4.setSourceAnchor(proc.outAnchor);
    path4.setTargetAnchor(stop.inAnchor);

    flowchart.add(start);
    flowchart.add(dec);
    flowchart.add(proc);
    flowchart.add(stop);
    flowchart.add(path1);
    flowchart.add(path2);
    flowchart.add(path3);
    flowchart.add(path4);

    new Dnd(start);
    new Dnd(proc);
    new Dnd(dec);
    new Dnd(stop);

    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:code.google.gclogviewer.GCLogViewer.java

public static void main(String[] args) {
    Display display = Display.getDefault();
    GCLogViewer thisClass = new GCLogViewer();
    thisClass.createShell();//from   ww w .  ja  va 2s.  c  o  m
    thisClass.shell.open();

    while (!thisClass.shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Draw2DTest.java

public static void main(String[] args) {
    final Graphics2DRenderer renderer = new Graphics2DRenderer();
    Shell shell = new Shell();
    shell.setSize(350, 350);//from w  w w.  j a v a 2 s .  c o  m

    shell.open();
    shell.setText("Draw2d Hello World");
    LightweightSystem lws = new LightweightSystem(shell);
    IFigure figure = new Figure() {
        protected void paintClientArea(org.eclipse.draw2d.Graphics graphics) {
            Dimension controlSize = getSize();

            renderer.prepareRendering(graphics);
            // prepares the Graphics2D renderer

            // gets the Graphics2D context and switch on the antialiasing
            Graphics2D g2d = renderer.getGraphics2D();
            g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

            // paints the background with a color gradient
            g2d.setPaint(new GradientPaint(0.0f, 0.0f, java.awt.Color.yellow, (float) controlSize.width,
                    (float) controlSize.width, java.awt.Color.white));
            g2d.fillRect(0, 0, controlSize.width, controlSize.width);

            // draws rotated text
            g2d.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 16));
            g2d.setColor(java.awt.Color.blue);

            g2d.translate(controlSize.width / 2, controlSize.width / 2);
            int nbOfSlices = 18;
            for (int i = 0; i < nbOfSlices; i++) {
                g2d.drawString("Angle = " + (i * 360 / nbOfSlices) + "\u00B0", 30, 0);
                g2d.rotate(-2 * Math.PI / nbOfSlices);
            }

            // now that we are done with Java2D, renders Graphics2D
            // operation
            // on the SWT graphics context
            renderer.render(graphics);

            // now we can continue with pure SWT paint operations
            graphics.drawOval(0, 0, controlSize.width, controlSize.width);
        }
    };
    lws.setContents(figure);
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    renderer.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet365.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet365 - Transparent Background");
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.spacing = 20;/*from   w  w  w.  ja v a  2  s. c om*/
    layout.marginWidth = 10;
    layout.marginHeight = 10;
    shell.setLayout(layout);
    // Standard color background for Shell
    // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // Gradient background for Shell
    shell.addListener(SWT.Resize, event -> {
        Rectangle rect = shell.getClientArea();
        Image newImage = new Image(display, Math.max(1, rect.width), 1);
        GC gc = new GC(newImage);
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
        gc.dispose();
        shell.setBackgroundImage(newImage);
        if (oldImage != null)
            oldImage.dispose();
        oldImage = newImage;
    });

    // Transparent
    buttonCheckBox = new Button(shell, SWT.CHECK | SWT.None);
    buttonCheckBox.setText("SET TRANSPARENT");
    buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
    buttonCheckBox.setSelection(false);
    buttonCheckBox.addSelectionListener(widgetSelectedAdapter(e -> {
        boolean transparent = ((Button) e.getSource()).getSelection();
        if (transparent) {
            // ContainerGroup
            containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            for (TabItem item : tabFolder.getItems()) {
                item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            }

            // Native
            nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));

            // Custom
            customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            for (Control control : sashForm.getChildren()) {
                control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            }
            // Default
            push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));

            // ItemGroup
            itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
        } else {
            // Native
            nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            toolBar.setBackground(null);
            coolBar.setBackground(null);
            label.setBackground(null);
            link.setBackground(null);
            scale.setBackground(null);
            RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB();
            radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255)));
            check.setBackgroundImage(getBackgroundImage(display));
            group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
            slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

            // ContainerGroup
            containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            for (TabItem item : tabFolder.getItems()) {
                item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            }
            // Custom
            customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            cLabel.setBackground((Color) null);
            styledText.setBackground((Color) null);
            sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            for (Control control : sashForm.getChildren()) {
                control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            }
            cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

            gradientCTab.setBackground(new Color[] { display.getSystemColor(SWT.COLOR_RED),
                    display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true);

            // Default
            defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            dateTime.setBackground(null);
            progressBar.setBackground(null);
            expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

            // ItemGroup
            itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        }

    }));

    // ContainerGroup
    containerGroup = new Composite(shell, SWT.NONE);
    containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    containerGroup.setToolTipText("CONTAINER");
    layout = new RowLayout();
    layout.spacing = 20;
    containerGroup.setLayout(layout);

    // Native
    nativeGroup = new Composite(shell, SWT.NONE);
    nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    nativeGroup.setToolTipText("NATIVE");
    layout = new RowLayout();
    layout.spacing = 20;
    nativeGroup.setLayout(layout);

    // Custom
    customGroup = new Composite(shell, SWT.NONE);
    customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    customGroup.setToolTipText("CUSTOM");
    layout = new RowLayout();
    layout.spacing = 20;
    customGroup.setLayout(layout);

    // AsDesigned
    defaultBackgroundGroup = new Composite(shell, SWT.NONE);
    defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    defaultBackgroundGroup.setToolTipText("Default Background");
    layout = new RowLayout();
    layout.spacing = 20;
    defaultBackgroundGroup.setLayout(layout);

    // ItemGroup
    itemGroup = new Composite(shell, SWT.NONE);
    itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    itemGroup.setToolTipText("ITEM");
    layout = new RowLayout();
    layout.spacing = 20;
    itemGroup.setLayout(layout);

    // Label
    label = new Label(nativeGroup, SWT.NONE);
    label.setText("Label");

    // Radio button
    radio = new Button(nativeGroup, SWT.RADIO);
    radio.setText("Radio Button");
    radio.setSelection(true);
    radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // Checkbox button with image
    check = new Button(nativeGroup, SWT.CHECK);
    check.setText("CheckBox Image");
    check.setSelection(true);
    check.setBackgroundImage(getBackgroundImage(display));

    // Push Button
    push = new Button(defaultBackgroundGroup, SWT.PUSH);
    push.setText("Push Button");

    // Toolbar
    toolBar = new ToolBar(nativeGroup, SWT.FLAT);
    toolBar.pack();
    ToolItem item = new ToolItem(toolBar, SWT.PUSH);
    item.setText("ToolBar_Item");

    // Coolbar
    coolBar = new CoolBar(nativeGroup, SWT.BORDER);
    for (int i = 0; i < 2; i++) {
        CoolItem item2 = new CoolItem(coolBar, SWT.NONE);
        Button button = new Button(coolBar, SWT.PUSH);
        button.setText("Button " + i);
        Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        item2.setPreferredSize(item2.computeSize(size.x, size.y));
        item2.setControl(button);
    }
    // Scale
    scale = new Scale(nativeGroup, SWT.None);
    scale.setMaximum(100);
    scale.setSelection(20);

    // Link
    link = new Link(nativeGroup, SWT.NONE);
    link.setText("<a>Sample link</a>");

    // List
    list = new List(nativeGroup, SWT.BORDER);
    list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    list.add("List_one");
    list.add("List_two");
    list.add("List_three");
    list.add("List_four");

    // Canvas
    canvas = new Canvas(containerGroup, SWT.NONE);
    canvas.setToolTipText("Canvas");
    canvas.addPaintListener(e -> {
        GC gc = e.gc;
        gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
        gc.drawRectangle(e.x + 1, e.y + 1, e.width - 2, e.height - 2);
        gc.drawArc(2, 2, e.width - 4, e.height - 4, 0, 360);
    });

    // Composite
    composite = new Composite(containerGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    composite.setToolTipText("Composite");

    // TabFolder
    tabFolder = new TabFolder(containerGroup, SWT.BORDER);
    tabFolder.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    for (int i = 0; i < 2; i++) {
        TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
        tabItem.setText("TabItem " + i);
        Label label = new Label(tabFolder, SWT.PUSH);
        label.setText("Page " + i);
        tabItem.setControl(label);
        tabItem.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    }
    tabFolder.pack();

    // Group
    group = new Group(containerGroup, SWT.NONE);
    group.setText("Group");

    // Sash
    sash = new Sash(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
    sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
    sash.setLayoutData(new RowData(100, 100));
    sash.setToolTipText("Sash");

    // SashForm
    sashForm = new SashForm(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
    Label leftLabel = new Label(sashForm, SWT.NONE);
    leftLabel.setText("SashForm\nLeft\n...\n...\n...\n...\n...");
    Label rightLabel = new Label(sashForm, SWT.NONE);
    rightLabel.setText("SashForm\nRight\n...\n...\n...\n...\n...");

    // DateTime
    dateTime = new DateTime(defaultBackgroundGroup, SWT.NONE);
    dateTime.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // Text
    text = new Text(nativeGroup, SWT.BORDER);
    text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    text.setText("text");

    // ProgressBar
    progressBar = new ProgressBar(defaultBackgroundGroup, SWT.NONE);
    progressBar.setMaximum(100);
    progressBar.setSelection(80);

    // Combo
    combo = new Combo(defaultBackgroundGroup, SWT.BORDER);
    combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    combo.add("combo");
    combo.setText("combo");

    // Slider
    slider = new Slider(nativeGroup, SWT.HORIZONTAL | SWT.BORDER);
    slider.setSelection(20);
    slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // CCombo
    ccombo = new CCombo(defaultBackgroundGroup, SWT.BORDER);
    ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    ccombo.add("ccombo");
    ccombo.setText("ccombo");

    // CLable
    cLabel = new CLabel(customGroup, SWT.NONE);
    cLabel.setText("CLabel");

    // Text
    styledText = new StyledText(customGroup, SWT.BORDER);
    styledText.setFont(new Font(display, "Tahoma", 18, SWT.BOLD | SWT.ITALIC));
    styledText.setForeground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
    styledText.setText("Styled Text");
    styledText.append("\n");
    styledText.append("Example_string");
    styledText.append("\n");
    styledText.append("One_Two");
    styledText.append("\n");
    styledText.append("Two_Three");

    // CTabFolder
    cTab = new CTabFolder(containerGroup, SWT.BORDER);
    for (int i = 0; i < 2; i++) {
        CTabItem cTabItem = new CTabItem(cTab, SWT.CLOSE, i);
        cTabItem.setText("CTabItem " + (i + 1));
    }
    cTab.setSelection(0);

    // Gradient CTabFolder
    gradientCTab = new CTabFolder(customGroup, SWT.BORDER);
    gradientCTab.setBackground(
            new Color[] { display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_RED) },
            new int[] { 90 }, true);
    for (int i = 0; i < 2; i++) {
        CTabItem cTabItem = new CTabItem(gradientCTab, SWT.CLOSE, i);
        cTabItem.setText("CTabItem " + (i + 1));
    }
    gradientCTab.setSelection(0);

    // Table
    table = new Table(itemGroup, SWT.V_SCROLL);
    table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    TableItem tableItem = new TableItem(table, SWT.NONE);
    tableItem.setText("TableItem - One");
    tableItem = new TableItem(table, SWT.NONE);
    tableItem.setText("TableItem - Two");

    // Tree
    tree = new Tree(itemGroup, SWT.NONE);
    TreeItem treeItem = new TreeItem(tree, SWT.NONE);
    treeItem.setText("Parent");
    TreeItem childItem = new TreeItem(treeItem, SWT.NONE);
    childItem.setText("Child1");
    childItem = new TreeItem(treeItem, SWT.NONE);
    childItem.setText("Child2");
    treeItem.setExpanded(true);
    tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // ExpandBar
    expandBar = new ExpandBar(itemGroup, SWT.V_SCROLL);
    expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    for (int i = 1; i <= 2; i++) {
        ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE, 0);
        item1.setText("Expand_Bar_Entry " + i);
        item1.setExpanded(true);
        item1.setHeight(20);
    }

    shell.open();
    shell.pack();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ProgressBarDialog.java

public static void main(String args[]) {
    try {//  w w  w.j av  a 2s  .co  m
        Display display = Display.getDefault();
        PBDialogDemo shell = new PBDialogDemo(display, SWT.SHELL_TRIM);
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.talend.dataprofiler.chart.util.HideSeriesChartDialog.java

private Composite createUtilityControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.BORDER);
    comp.setLayout(new RowLayout());
    comp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    if (isCountAvgNull) {
        XYDataset dataset = chart.getXYPlot().getDataset();
        int count = dataset.getSeriesCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getSeriesKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }/*from www  . j av  a 2  s  . com*/
    }

    if (isMinMaxDate) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryDataset dataset = plot.getDataset();
        int count = dataset.getRowCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getRowKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }
    }

    return comp;
}

From source file:org.talend.dataprofiler.chart.util.ChartUtils.java

/**
 * Create a AWT_SWT bridge composite for displaying the <CODE>ChartPanel</CODE>.
 * /*from  ww  w  . ja v  a2 s. com*/
 * @param composite
 * @param gd
 * @param chartPanel
 */
public static ChartPanel createAWTSWTComp(Composite composite, GridData gd, JFreeChart chart) {

    ChartPanel chartPanel = new ChartPanel(chart);
    Composite frameComp = new Composite(composite, SWT.EMBEDDED);
    frameComp.setLayout(new GridLayout());
    frameComp.setLayoutData(gd);
    frameComp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    Frame frame = SWT_AWT.new_Frame(frameComp);
    frame.setLayout(new java.awt.GridLayout());
    frame.add(chartPanel);
    frame.validate();

    return chartPanel;
}

From source file:org.gumtree.vis.core.internal.StaticValues.java

public static Image getImage(String path) {
    synchronized (StaticValues.class) {
        if (imageStorage == null) {
            imageStorage = new HashMap<String, Image>();
        }/*from   ww  w  . j  a v a  2s .  c o m*/
    }
    if (imageStorage.containsKey(path)) {
        return imageStorage.get(path);
    }
    Image newImage = new Image(Display.getDefault(),
            StaticValues.class.getClassLoader().getResourceAsStream(path));
    imageStorage.put(path, newImage);
    return newImage;
}

From source file:org.jfree.experimental.chart.swt.editor.SWTChartEditor.java

/**
 * Creates a new editor.//  www  .java  2s .  c om
 * 
 * @param shell2 the display.
 * @param chart2edit the chart to edit.
 */
public SWTChartEditor(Shell shell2, JFreeChart chart2edit) {

    this.shell = new Shell(Display.getDefault(), SWT.DIALOG_TRIM);
    this.shell.setSize(400, 500);
    this.chart = chart2edit;
    this.shell.setText(
            ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle").getString("Chart_Properties"));
    GridLayout layout = new GridLayout(2, true);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5;
    this.shell.setLayout(layout);
    Composite main = new Composite(this.shell, SWT.NONE);
    main.setLayout(new FillLayout());
    main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    TabFolder tab = new TabFolder(main, SWT.BORDER);
    // build first tab
    TabItem item1 = new TabItem(tab, SWT.NONE);
    item1.setText(" " + localizationResources.getString("Title") + " ");
    this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle());
    item1.setControl(this.titleEditor);
    // build second tab
    TabItem item2 = new TabItem(tab, SWT.NONE);
    item2.setText(" " + localizationResources.getString("Plot") + " ");
    this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot());
    item2.setControl(this.plotEditor);
    // build the third tab
    TabItem item3 = new TabItem(tab, SWT.NONE);
    item3.setText(" " + localizationResources.getString("Other") + " ");
    this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart);
    item3.setControl(this.otherEditor);

    // ok and cancel buttons
    Button ok = new Button(this.shell, SWT.PUSH | SWT.OK);
    ok.setText(" Ok ");
    ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            updateChart(SWTChartEditor.this.chart);
            SWTChartEditor.this.shell.dispose();
        }
    });
    Button cancel = new Button(this.shell, SWT.PUSH);
    cancel.setText(" Cancel ");
    cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            SWTChartEditor.this.shell.dispose();
        }
    });
}