Example usage for org.eclipse.swt.widgets Composite getSize

List of usage examples for org.eclipse.swt.widgets Composite getSize

Introduction

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

Prototype

public Point getSize() 

Source Link

Document

Returns a point describing the receiver's size.

Usage

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL);
    shell.setText("Snippet 9");
    final Composite composite = new Composite(shell, SWT.BORDER);
    composite.setSize(700, 600);/*from w  ww  .  j a  v a 2s.  c om*/
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    composite.addPaintListener(e -> {
        e.gc.setBackground(red);
        e.gc.fillOval(5, 5, 690, 590);
    });
    final ScrollBar hBar = shell.getHorizontalBar();
    hBar.addListener(SWT.Selection, e -> {
        Point location = composite.getLocation();
        location.x = -hBar.getSelection();
        composite.setLocation(location);
    });
    final ScrollBar vBar = shell.getVerticalBar();
    vBar.addListener(SWT.Selection, e -> {
        Point location = composite.getLocation();
        location.y = -vBar.getSelection();
        composite.setLocation(location);
    });
    shell.addListener(SWT.Resize, e -> {
        Point size = composite.getSize();
        Rectangle rect = shell.getClientArea();
        hBar.setMaximum(size.x);
        vBar.setMaximum(size.y);
        hBar.setThumb(Math.min(size.x, rect.width));
        vBar.setThumb(Math.min(size.y, rect.height));
        int hPage = size.x - rect.width;
        int vPage = size.y - rect.height;
        int hSelection = hBar.getSelection();
        int vSelection = vBar.getSelection();
        Point location = composite.getLocation();
        if (hSelection >= hPage) {
            if (hPage <= 0)
                hSelection = 0;
            location.x = -hSelection;
        }
        if (vSelection >= vPage) {
            if (vPage <= 0)
                vSelection = 0;
            location.y = -vSelection;
        }
        composite.setLocation(location);
    });
    shell.setSize(600, 500);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet9.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL);
    final Composite composite = new Composite(shell, SWT.BORDER);
    composite.setSize(200, 400);//  w w  w.java  2  s .c o  m
    final ScrollBar hBar = shell.getHorizontalBar();
    hBar.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            Point location = composite.getLocation();
            location.x = -hBar.getSelection();
            composite.setLocation(location);
        }
    });
    final ScrollBar vBar = shell.getVerticalBar();
    vBar.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            Point location = composite.getLocation();
            location.y = -vBar.getSelection();
            composite.setLocation(location);
        }
    });
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Point size = composite.getSize();
            Rectangle rect = shell.getClientArea();
            hBar.setMaximum(size.x);
            vBar.setMaximum(size.y);
            hBar.setThumb(Math.min(size.x, rect.width));
            vBar.setThumb(Math.min(size.y, rect.height));
            int hPage = size.x - rect.width;
            int vPage = size.y - rect.height;
            int hSelection = hBar.getSelection();
            int vSelection = vBar.getSelection();
            Point location = composite.getLocation();
            if (hSelection >= hPage) {
                if (hPage <= 0)
                    hSelection = 0;
                location.x = -hSelection;
            }
            if (vSelection >= vPage) {
                if (vPage <= 0)
                    vSelection = 0;
                location.y = -vSelection;
            }
            composite.setLocation(location);
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:CoolBarExamples.java

public CoolBarExamples() {
    shell.setLayout(new GridLayout());

    final CoolBar coolBar = new CoolBar(shell, SWT.NONE);

    coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // cool item with a text field.
    CoolItem textItem = new CoolItem(coolBar, SWT.NONE);

    Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN);
    text.setText("TEXT");
    text.pack();/*ww w . j av  a2 s .  c  o m*/

    Point size = text.getSize();
    textItem.setControl(text);
    textItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a label.
    CoolItem labelItem = new CoolItem(coolBar, SWT.NONE);

    Label label = new Label(coolBar, SWT.NONE);
    label.setText("LABEL");
    label.pack();

    size = label.getSize();
    labelItem.setControl(label);
    labelItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a button.
    CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN);

    Composite composite = new Composite(coolBar, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    button1.pack();

    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");
    button2.pack();

    composite.pack();

    size = composite.getSize();
    buttonItem.setControl(composite);
    buttonItem.setSize(buttonItem.computeSize(size.x, size.y));

    //      // Test cool item adding method.
    //      Label label2 = new Label(coolBar, SWT.NONE);
    //      label2.setText("label2");
    //      addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar);

    try {
        setState(coolBar, new File("coolbar.state"));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    shell.addListener(SWT.Close, new Listener() {
        public void handleEvent(Event event) {
            try {
                saveState(coolBar, new File("coolbar.state"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    shell.setSize(300, 120);
    // shell.pack();
    shell.open();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java

private void createInputTab(final CTabFolder parentTabFolder) {
    inputTab = new CTabItem(parentTabFolder, SWT.NONE);
    inputTab.setText(Messages.ProcessExecutionDialog_tabparameters);

    ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL);
    scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite container = new Composite(scroller, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // local moran's i
    Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$
    uiBuilder.createLabel(container, Messages.ScatterPlotDialog_InputLayer, EMPTY, image, 1);
    cboLayer = uiBuilder.createCombo(container, 1, true);
    fillLayers(map, cboLayer, VectorLayerType.ALL);

    uiBuilder.createLabel(container, Messages.ScatterPlotDialog_IndependentField, EMPTY, image, 1);
    cboXField = uiBuilder.createCombo(container, 1, true);

    uiBuilder.createLabel(container, Messages.ScatterPlotDialog_DependentField, EMPTY, image, 1);
    cboYField = uiBuilder.createCombo(container, 1, true);

    uiBuilder.createLabel(container, null, null, 1);
    chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 1);
    chkPearson = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_Pearson, null, 1);

    // register events
    cboLayer.addModifyListener(new ModifyListener() {
        @Override//from  w  w  w.  j a va  2 s . co m
        public void modifyText(ModifyEvent e) {
            inputLayer = MapUtils.getLayer(map, cboLayer.getText());
            if (inputLayer != null) {
                fillFields(cboXField, inputLayer.getSchema(), FieldType.Number);
                fillFields(cboYField, inputLayer.getSchema(), FieldType.Number);
            }
        }
    });

    // finally
    scroller.setContent(container);
    inputTab.setControl(scroller);

    scroller.setMinSize(450, container.getSize().y - 2);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);

    scroller.pack();
    container.pack();
}

From source file:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java

private void createInputTab(final CTabFolder parentTabFolder) {
    inputTab = new CTabItem(parentTabFolder, SWT.NONE);
    inputTab.setText(Messages.ProcessExecutionDialog_tabparameters);

    ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL);
    scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite container = new Composite(scroller, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // local moran's i
    Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$
    uiBuilder.createLabel(container, Messages.ScatterPlotDialog_InputLayer, EMPTY, image, 1);
    cboLayer = uiBuilder.createCombo(container, 1, true);
    fillLayers(map, cboLayer, VectorLayerType.ALL);

    uiBuilder.createLabel(container, Messages.BubbleChartDialog_XField, EMPTY, image, 1);
    cboXField = uiBuilder.createCombo(container, 1, true);

    uiBuilder.createLabel(container, Messages.BubbleChartDialog_YField, EMPTY, image, 1);
    cboYField = uiBuilder.createCombo(container, 1, true);

    uiBuilder.createLabel(container, Messages.BubbleChartDialog_SizeField, EMPTY, image, 1);
    cboSize = uiBuilder.createCombo(container, 1, true);

    uiBuilder.createLabel(container, null, null, 1);
    chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 1);

    // register events
    cboLayer.addModifyListener(new ModifyListener() {
        @Override//from   w w w.  ja v a2s.  c  om
        public void modifyText(ModifyEvent e) {
            inputLayer = MapUtils.getLayer(map, cboLayer.getText());
            if (inputLayer != null) {
                fillFields(cboXField, inputLayer.getSchema(), FieldType.Number);
                fillFields(cboYField, inputLayer.getSchema(), FieldType.Number);
                fillFields(cboSize, inputLayer.getSchema(), FieldType.Number);
            }
        }
    });

    // finally
    scroller.setContent(container);
    inputTab.setControl(scroller);

    scroller.setMinSize(450, container.getSize().y - 2);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);

    scroller.pack();
    container.pack();
}

From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java

private void createInputTab(final CTabFolder parentTabFolder) {
    inputTab = new CTabItem(parentTabFolder, SWT.NONE);
    inputTab.setText(Messages.ProcessExecutionDialog_tabparameters);

    ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL);
    scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite container = new Composite(scroller, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // local moran's i
    Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$
    uiBuilder.createLabel(container, Messages.ScatterPlotDialog_InputLayer, EMPTY, image, 1);
    cboLayer = uiBuilder.createCombo(container, 1, true);
    fillLayers(map, cboLayer, VectorLayerType.ALL);

    uiBuilder.createLabel(container, Messages.BoxPlotDialog_Fields, EMPTY, image, 1);
    schemaTable = uiBuilder.createTable(container, new String[] { Messages.General_Name }, 1);
    schemaTable.addSelectionListener(new SelectionAdapter() {
        @Override/*ww w.j av  a  2s  . c om*/
        public void widgetSelected(SelectionEvent event) {
            StringBuffer buffer = new StringBuffer();
            for (TableItem item : schemaTable.getItems()) {
                if (item.getChecked()) {
                    if (buffer.length() > 0) {
                        buffer.append(",").append(item.getText()); //$NON-NLS-1$
                    } else {
                        buffer.append(item.getText());
                    }
                }
            }
            selectedFields = buffer.toString();
        }
    });

    uiBuilder.createLabel(container, null, null, 1);
    chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 1);

    // register events
    cboLayer.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            schemaTable.removeAll();
            inputLayer = MapUtils.getLayer(map, cboLayer.getText());
            if (inputLayer != null) {
                for (AttributeDescriptor dsc : inputLayer.getSchema().getAttributeDescriptors()) {
                    Class<?> binding = dsc.getType().getBinding();
                    if (Number.class.isAssignableFrom(binding)) {
                        TableItem item = new TableItem(schemaTable, SWT.NULL);
                        item.setText(dsc.getLocalName());
                    }
                }
            }
        }
    });

    // finally
    scroller.setContent(container);
    inputTab.setControl(scroller);

    scroller.setMinSize(450, container.getSize().y - 2);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);

    scroller.pack();
    container.pack();
}

From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java

private void createInputTab(final CTabFolder parentTabFolder) {
    inputTab = new CTabItem(parentTabFolder, SWT.NONE);
    inputTab.setText(Messages.ProcessExecutionDialog_tabparameters);

    ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL);
    scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite container = new Composite(scroller, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // local moran's i
    Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$
    uiBuilder.createLabel(container, Messages.HistogramDialog_InputLayer, EMPTY, image, 2);
    cboLayer = uiBuilder.createCombo(container, 2, true);
    fillLayers(map, cboLayer, VectorLayerType.ALL);

    uiBuilder.createLabel(container, Messages.HistogramDialog_InputField, EMPTY, image, 2);
    cboField = uiBuilder.createCombo(container, 2, true);

    uiBuilder.createLabel(container, Messages.HistogramDialog_BinCount, EMPTY, image, 2);
    spinner = uiBuilder.createSpinner(container, 10, 1, 50, 0, 1, 5, 2);

    // yXais Type
    uiBuilder.createLabel(container, Messages.HistogramDialog_YAxisType, EMPTY, image, 1);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;//from w w  w . j  ava 2  s.c om

    Composite subCon = new Composite(container, SWT.NONE);
    subCon.setLayout(layout);
    subCon.setLayoutData(new GridData(SWT.LEFT_TO_RIGHT, SWT.CENTER, false, false, 1, 1));
    final Button chkRatio = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Ratio, null, 1);
    final Button chkFrequency = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Frequency, null,
            1);
    chkFrequency.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (chkFrequency.getSelection()) {
                histogramType = HistogramType.FREQUENCY;
            }
        }
    });
    chkRatio.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (chkRatio.getSelection()) {
                histogramType = HistogramType.RELATIVE_FREQUENCY;
            }
        }
    });
    chkRatio.setSelection(true);

    uiBuilder.createLabel(container, null, null, 2);
    chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 2);

    // register events
    cboLayer.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            inputLayer = MapUtils.getLayer(map, cboLayer.getText());
            if (inputLayer != null) {
                fillFields(cboField, inputLayer.getSchema(), FieldType.Number);
            }
        }
    });

    // finally
    scroller.setContent(container);
    inputTab.setControl(scroller);

    scroller.setMinSize(450, container.getSize().y - 2);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);

    scroller.pack();
    container.pack();
}

From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java

private void createInputTab(final CTabFolder parentTabFolder) {
    inputTab = new CTabItem(parentTabFolder, SWT.NONE);
    inputTab.setText(Messages.ProcessExecutionDialog_tabparameters);

    ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL);
    scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite container = new Composite(scroller, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // local moran's i
    Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$
    uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_InputLayer, EMPTY, image, 1);
    cboLayer = uiBuilder.createCombo(container, 1, true);
    fillLayers(map, cboLayer, VectorLayerType.ALL);

    uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_InputField, EMPTY, image, 1);
    cboField = uiBuilder.createCombo(container, 1, true);

    uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_Conceptualization, EMPTY, 1);
    cboConcept = uiBuilder.createCombo(container, 1, true);
    cboConcept.addModifyListener(new ModifyListener() {
        @Override//from w  w w  .  j a va  2 s.c om
        public void modifyText(ModifyEvent e) {
            for (Object enumVal : SpatialConcept.class.getEnumConstants()) {
                if (enumVal.toString().equalsIgnoreCase(cboConcept.getText())) {
                    params.put(GlobalMoransIProcessFactory.spatialConcept.key, enumVal);
                    break;
                }
            }
        }
    });
    fillEnum(cboConcept, SpatialConcept.class);

    uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_DistanceMethod, EMPTY, 1);
    cboDistance = uiBuilder.createCombo(container, 1, true);
    cboDistance.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            for (Object enumVal : DistanceMethod.class.getEnumConstants()) {
                if (enumVal.toString().equalsIgnoreCase(cboDistance.getText())) {
                    params.put(GlobalMoransIProcessFactory.distanceMethod.key, enumVal);
                    break;
                }
            }
        }
    });
    fillEnum(cboDistance, DistanceMethod.class);

    uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_Standardization, EMPTY, 1);
    cboStandard = uiBuilder.createCombo(container, 1, true);
    cboStandard.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            for (Object enumVal : StandardizationMethod.class.getEnumConstants()) {
                if (enumVal.toString().equalsIgnoreCase(cboStandard.getText())) {
                    params.put(GlobalMoransIProcessFactory.standardization.key, enumVal);
                    break;
                }
            }
        }
    });
    fillEnum(cboStandard, StandardizationMethod.class);

    uiBuilder.createLabel(container, Messages.MoranScatterPlotDialog_DistanceBand, EMPTY, 1);
    final Text txtDistance = uiBuilder.createText(container, EMPTY, 1, true);
    txtDistance.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            Object obj = Converters.convert(txtDistance.getText(), Double.class);
            if (obj == null) {
                params.put(GlobalMoransIProcessFactory.searchDistance.key, Double.valueOf(0d));
            } else {
                params.put(GlobalMoransIProcessFactory.searchDistance.key, obj);
            }
        }
    });

    // register events
    cboLayer.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            inputLayer = MapUtils.getLayer(map, cboLayer.getText());
            if (inputLayer == null) {
                return;
            }
            SimpleFeatureCollection features = MapUtils.getFeatures(inputLayer);
            params.put(GlobalMoransIProcessFactory.inputFeatures.key, features);
            fillFields(cboField, inputLayer.getSchema(), FieldType.Number);
        }
    });

    cboField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            params.put(GlobalMoransIProcessFactory.inputField.key, cboField.getText());
        }
    });

    // finally
    scroller.setContent(container);
    inputTab.setControl(scroller);

    scroller.setMinSize(450, container.getSize().y - 2);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);

    scroller.pack();
    container.pack();
}