List of usage examples for org.eclipse.swt.widgets Composite computeSize
public Point computeSize(int wHint, int hHint)
From source file:org.eclipse.swt.snippets.Snippet188.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 188"); shell.setLayout(new GridLayout()); final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Composite c = new Composite(sc, SWT.NONE); c.setLayout(new GridLayout(10, true)); for (int i = 0; i < 300; i++) { Button b = new Button(c, SWT.PUSH); b.setText("Button " + i); }//from w ww .j a va 2 s . c o m sc.setContent(c); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); sc.setShowFocusedControl(true); shell.setSize(300, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScrollWidgetViewFocusIn.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Button b1 = new Button(shell, SWT.PUSH); b1.setText("top"); b1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Composite c = new Composite(sc, SWT.NONE); c.setLayout(new GridLayout(10, true)); for (int i = 0; i < 300; i++) { Button b = new Button(c, SWT.PUSH); b.setText("Button " + i); }/* www . ja v a 2 s. c om*/ Button b2 = new Button(shell, SWT.PUSH); b2.setText("bottom"); b2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); sc.setContent(c); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); Listener listener = new Listener() { public void handleEvent(Event e) { Control child = (Control) e.widget; Rectangle bounds = child.getBounds(); Rectangle area = sc.getClientArea(); Point origin = sc.getOrigin(); if (origin.x > bounds.x) origin.x = Math.max(0, bounds.x); if (origin.y > bounds.y) origin.y = Math.max(0, bounds.y); if (origin.x + area.width < bounds.x + bounds.width) origin.x = Math.max(0, bounds.x + bounds.width - area.width); if (origin.y + area.height < bounds.y + bounds.height) origin.y = Math.max(0, bounds.y + bounds.height - area.height); sc.setOrigin(origin); } }; Control[] controls = c.getChildren(); for (int i = 0; i < controls.length; i++) { controls[i].addListener(SWT.Activate, listener); } shell.setSize(300, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ExpandBarControlsAdding.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = new Image(display, "yourFile.gif"); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;//from w w w.java 2 s. c om composite.setLayout(layout); Button button = new Button(composite, SWT.PUSH); button.setText("SWT.PUSH"); button = new Button(composite, SWT.RADIO); button.setText("SWT.RADIO"); button = new Button(composite, SWT.CHECK); button.setText("SWT.CHECK"); button = new Button(composite, SWT.TOGGLE); button.setText("SWT.TOGGLE"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); item0.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet166.java
public static void main(String[] args) { Display display = new Display(); Image image1 = display.getSystemImage(SWT.ICON_WORKING); Image image2 = display.getSystemImage(SWT.ICON_QUESTION); Image image3 = display.getSystemImage(SWT.ICON_ERROR); Shell shell = new Shell(display); shell.setText("Snippet 166"); shell.setLayout(new FillLayout()); final ScrolledComposite scrollComposite = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER); final Composite parent = new Composite(scrollComposite, SWT.NONE); for (int i = 0; i <= 50; i++) { Label label = new Label(parent, SWT.NONE); if (i % 3 == 0) label.setImage(image1);//from w ww . j ava 2 s . co m if (i % 3 == 1) label.setImage(image2); if (i % 3 == 2) label.setImage(image3); } RowLayout layout = new RowLayout(SWT.HORIZONTAL); layout.wrap = true; parent.setLayout(layout); scrollComposite.setContent(parent); scrollComposite.setExpandVertical(true); scrollComposite.setExpandHorizontal(true); scrollComposite.addControlListener(ControlListener.controlResizedAdapter(e -> { Rectangle r = scrollComposite.getClientArea(); scrollComposite.setMinSize(parent.computeSize(r.width, SWT.DEFAULT)); })); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet223.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = display.getSystemImage(SWT.ICON_QUESTION); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;/* w ww . j a v a 2s .c o m*/ composite.setLayout(layout); Button button = new Button(composite, SWT.PUSH); button.setText("SWT.PUSH"); button = new Button(composite, SWT.RADIO); button.setText("SWT.RADIO"); button = new Button(composite, SWT.CHECK); button.setText("SWT.CHECK"); button = new Button(composite, SWT.TOGGLE); button.setText("SWT.TOGGLE"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); // Second item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item1 = new ExpandItem(bar, SWT.NONE, 1); item1.setText("What is your favorite icon"); item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item1.setControl(composite); item1.setImage(image); // Third item composite = new Composite(bar, SWT.NONE); layout = new GridLayout(2, true); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10; composite.setLayout(layout); label = new Label(composite, SWT.NONE); label.setText("Scale"); new Scale(composite, SWT.NONE); label = new Label(composite, SWT.NONE); label.setText("Spinner"); new Spinner(composite, SWT.BORDER); label = new Label(composite, SWT.NONE); label.setText("Slider"); new Slider(composite, SWT.NONE); ExpandItem item2 = new ExpandItem(bar, SWT.NONE, 2); item2.setText("What is your favorite range widget"); item2.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item2.setControl(composite); item2.setImage(image); item1.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:ScrolledCompositeCreate.java
public static void main(String[] args) { Display display = new Display(); Image image1 = display.getSystemImage(SWT.ICON_WORKING); Image image2 = display.getSystemImage(SWT.ICON_QUESTION); Image image3 = display.getSystemImage(SWT.ICON_ERROR); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final ScrolledComposite scrollComposite = new ScrolledComposite(shell, SWT.V_SCROLL | SWT.BORDER); final Composite parent = new Composite(scrollComposite, SWT.NONE); for (int i = 0; i <= 50; i++) { Label label = new Label(parent, SWT.NONE); if (i % 3 == 0) label.setImage(image1);//w ww. j ava 2 s . c om if (i % 3 == 1) label.setImage(image2); if (i % 3 == 2) label.setImage(image3); } RowLayout layout = new RowLayout(SWT.HORIZONTAL); layout.wrap = true; parent.setLayout(layout); scrollComposite.setContent(parent); scrollComposite.setExpandVertical(true); scrollComposite.setExpandHorizontal(true); scrollComposite.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { Rectangle r = scrollComposite.getClientArea(); scrollComposite.setMinSize(parent.computeSize(r.width, SWT.DEFAULT)); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ExpandBarIconAddingSystem.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = new Image(display, "yourFile.gif"); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;//from w w w . j a v a 2s .com composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); item0.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.examples.controlexample.ExpandBarTab.java
/** * Creates the "Example" widgets.//w w w . j ava 2s . c o m */ @Override void createExampleWidgets() { /* Compute the widget style */ int style = getDefaultStyle(); if (borderButton.getSelection()) style |= SWT.BORDER; if (verticalButton.getSelection()) style |= SWT.V_SCROLL; /* Create the example widgets */ expandBar1 = new ExpandBar(expandBarGroup, style); // First item Composite composite = new Composite(expandBar1, SWT.NONE); composite.setLayout(new GridLayout()); new Button(composite, SWT.PUSH).setText("SWT.PUSH"); new Button(composite, SWT.RADIO).setText("SWT.RADIO"); new Button(composite, SWT.CHECK).setText("SWT.CHECK"); new Button(composite, SWT.TOGGLE).setText("SWT.TOGGLE"); ExpandItem item = new ExpandItem(expandBar1, SWT.NONE, 0); item.setText(ControlExample.getResourceString("Item1_Text")); item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item.setControl(composite); item.setImage(instance.images[ControlExample.ciClosedFolder]); // Second item composite = new Composite(expandBar1, SWT.NONE); composite.setLayout(new GridLayout(2, false)); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_ERROR)); new Label(composite, SWT.NONE).setText("SWT.ICON_ERROR"); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_INFORMATION)); new Label(composite, SWT.NONE).setText("SWT.ICON_INFORMATION"); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_WARNING)); new Label(composite, SWT.NONE).setText("SWT.ICON_WARNING"); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_QUESTION)); new Label(composite, SWT.NONE).setText("SWT.ICON_QUESTION"); item = new ExpandItem(expandBar1, SWT.NONE, 1); item.setText(ControlExample.getResourceString("Item2_Text")); item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item.setControl(composite); item.setImage(instance.images[ControlExample.ciOpenFolder]); item.setExpanded(true); }
From source file:org.eclipse.swt.examples.controlexample.ControlExample.java
/** * Creates an instance of a ControlExample embedded inside * the supplied parent Composite./*from w w w . j a v a 2 s. co m*/ * * @param parent the container of the example */ public ControlExample(Composite parent) { initResources(); tabFolder = new TabFolder(parent, SWT.NONE); tabs = createTabs(); for (Tab tab : tabs) { TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText(tab.getTabText()); item.setControl(tab.createTabFolderPage(tabFolder)); item.setData(tab); } /* Workaround: if the tab folder is wider than the screen, * Mac platforms clip instead of somehow scrolling the tab items. * We try to recover some width by using shorter tab names. */ Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle monitorArea = parent.getMonitor().getClientArea(); boolean isMac = SWT.getPlatform().equals("cocoa"); if (size.x > monitorArea.width && isMac) { TabItem[] tabItems = tabFolder.getItems(); for (int i = 0; i < tabItems.length; i++) { tabItems[i].setText(tabs[i].getShortTabText()); } } startup = false; }
From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java
/** * Creates the impact list page.// w ww.j a v a 2s.c om */ void impactListPage() { final Composite composite = new Composite(getContainer(), SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); composite.setLayout(new GridLayout()); Label concernLabel = new Label(composite, SWT.BORDER); concernLabel.setText("Crosccuting Concerns(CCC)"); concernLabel.setToolTipText("This are the concern detected on the requierement document."); GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); concernLabel.setLayoutData(gridData); ///////////////////// ScrolledComposite sc = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); Composite parent = new Composite(sc, SWT.NONE); parent.setLayout(new GridLayout()); topViewLink = new TableViewer(parent, SWT.BORDER); createColumns(parent, topViewLink); final Table table = topViewLink.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); topViewLink.setContentProvider(new ArrayContentProvider()); getSite().setSelectionProvider(topViewLink); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); data.heightHint = 10 * table.getItemHeight(); table.setLayoutData(data); sc.setContent(parent); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); ///////////////////// Button button = new Button(composite, SWT.PUSH); button.setText("Remove"); button.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) { } public void widgetSelected(SelectionEvent event) { IStructuredSelection topSelection = (IStructuredSelection) topViewLink.getSelection(); IStructuredSelection bottomSelection = (IStructuredSelection) bottomViewLink.getSelection(); String[] crosscuttingConcern = (String[]) topSelection.getFirstElement(); String[] designDecision = (String[]) bottomSelection.getFirstElement(); if (topSelection.size() > 1) { MessageDialog.openError(composite.getShell(), "Error", "Please select one crosscutting concern"); } else { if ((crosscuttingConcern != null) && (designDecision != null)) { // create dialog with ok and cancel button and info icon MessageBox dialog = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); dialog.setText("Link confirmation"); dialog.setMessage("Do you want to remove the link between the selected items?"); // open dialog and await user selection int response = dialog.open(); if (response == SWT.OK) { PluginUtil.removeLink(crosscuttingConcern, designDecision, cp); dirty = true; firePropertyChange(IEditorPart.PROP_DIRTY); // update the list after the remove generateLinkViewData(); bottomViewLink.getTable().clearAll(); } } else { MessageDialog.openError(composite.getShell(), "Error", "Please select a crosscutting concern and a design decision to remove a traceability link"); } } } }); gridData = new GridData(SWT.CENTER, SWT.TOP, false, false, 2, 1); button.setLayoutData(gridData); Label ddsLabel = new Label(composite, SWT.BORDER); ddsLabel.setText("Architectural design decisions"); ddsLabel.setToolTipText("This are the design decisions detected on the architectural document"); gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); ddsLabel.setLayoutData(gridData); bottomViewLink = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); createColumns(composite, bottomViewLink); Table table2 = bottomViewLink.getTable(); table2.setHeaderVisible(true); table2.setLinesVisible(true); bottomViewLink.setContentProvider(new ArrayContentProvider()); topViewLink.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (!selection.isEmpty()) { String[] cccs = (String[]) selection.getFirstElement(); List<DesignDecision> dds = PluginUtil.getDesignDecisionsForCrossCuttingConcern(cp, cccs[1], cccs[0]); logger.info("Impact List for CCC (" + dds.size() + " DDD): " + cccs[0] + " - " + cccs[1]); List<String[]> designDecisions = new ArrayList<String[]>(); for (DesignDecision dd : dds) { String[] designDecision = { dd.getKind(), dd.getName() }; designDecisions.add(designDecision); } bottomViewLink.setInput(designDecisions); } } }); getSite().setSelectionProvider(bottomViewLink); gridData = new GridData(SWT.FILL, SWT.FILL, true, true); bottomViewLink.getControl().setLayoutData(gridData); int index = addPage(composite); setPageText(index, "Links"); }