List of usage examples for org.eclipse.swt.widgets Composite setLayoutData
public void setLayoutData(Object layoutData)
From source file:ControlSizeLocation.java
private void init() { GridLayout gridLayout = new GridLayout(2, true); shell.setLayout(gridLayout);/* ww w . ja v a 2 s . co m*/ Composite left = new Composite(shell, SWT.NULL); left.setLayout(new GridLayout()); //left.setLayout(new FillLayout()); left.setLayoutData(new GridData(GridData.FILL_BOTH)); left.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); button = new Button(left, SWT.PUSH); button.setText("Button"); button.setLayoutData(new GridData()); Composite right = new Composite(shell, SWT.NULL); right.setLayout(new GridLayout(4, true)); right.setLayoutData(new GridData(GridData.FILL_BOTH)); Label label = new Label(right, SWT.NULL); label.setText("X"); label = new Label(right, SWT.NULL); label.setText("Y"); label = new Label(right, SWT.NULL); label.setText("Width"); label = new Label(right, SWT.NULL); label.setText("Height"); x = new Text(right, SWT.BORDER); y = new Text(right, SWT.BORDER); w = new Text(right, SWT.BORDER); h = new Text(right, SWT.BORDER); SelectionListener selectionListener = new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b == get) { System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); } else if (b == set) { int vx = getNumber(x); int vy = getNumber(y); int vw = getNumber(w); int vh = getNumber(h); if (vx != -1 && vy != -1) { if (vw != -1 && vh != -1) { Rectangle rectangle = new Rectangle(vx, vy, vw, vh); button.setBounds(rectangle); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setBounds: " + rectangle); } else { Point point = new Point(vx, vy); button.setLocation(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setLocation: " + point); } } else if (vw != -1 && vh != -1) { Point point = new Point(vw, vh); button.setSize(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setSize: " + point); } } } public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }; get = new Button(right, SWT.PUSH); get.setText("Get"); get.addSelectionListener(selectionListener); set = new Button(right, SWT.PUSH); set.setText("Set"); set.addSelectionListener(selectionListener); }
From source file:SimpleBrowser.java
/** * Creates the main window's contents//w ww.jav a2 s. c om * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FormLayout()); // Create the composite to hold the buttons and text field Composite controls = new Composite(shell, SWT.NONE); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); controls.setLayoutData(data); // Create the web browser final Browser browser = new Browser(shell, SWT.NONE); data = new FormData(); data.top = new FormAttachment(controls); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); browser.setLayoutData(data); // Create the controls and wire them to the browser controls.setLayout(new GridLayout(6, false)); // Create the back button Button button = new Button(controls, SWT.PUSH); button.setText("Back"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.back(); } }); // Create the forward button button = new Button(controls, SWT.PUSH); button.setText("Forward"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.forward(); } }); // Create the refresh button button = new Button(controls, SWT.PUSH); button.setText("Refresh"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.refresh(); } }); // Create the stop button button = new Button(controls, SWT.PUSH); button.setText("Stop"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.stop(); } }); // Create the address entry field and set focus to it final Text url = new Text(controls, SWT.BORDER); url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); url.setFocus(); // Create the go button button = new Button(controls, SWT.PUSH); button.setText("Go"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.setUrl(url.getText()); } }); // Allow users to hit enter to go to the typed URL shell.setDefaultButton(button); }
From source file:ch.unibe.iam.scg.archie.controller.ProviderChartFactory.java
/** * Creates a chart from the currently set chart model and attaches it to the * given parent.// w w w . j av a 2s . com * * @param parent * Chart composite cotainer. * @return Composite containing the chart just created. */ public Composite createChart(Composite parent) { // set layout of parent container parent.setLayout(new GridLayout()); parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // create an error message if no model present if (this.model == null) { return new GraphicalMessage(parent, ArchieActivator.getImage(ArchieActivator.IMG_ERROR), Messages.NO_CHART_MODEL); } // else return a chart composite based on the chart type if (this.model.getChartType() == ChartModel.CHART_PIE) { return this.createPieChart(parent); } return this.createBarChart(parent); }
From source file:BackupFiles.java
/** * Helper method to create the label/text/button for a directory * //from w w w. ja va 2 s . c om * @param composite * the parent composite * @param label * the text for the label * @return Text */ private Text createFilePanelHelper(Composite composite, String label) { // Create the composite to hold the controls Composite panel = new Composite(composite, SWT.BORDER); panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); panel.setLayout(new GridLayout(3, false)); // Create the controls new Label(panel, SWT.LEFT).setText(label); Text text = new Text(panel, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button browse = new Button(panel, SWT.PUSH); // Add browsing browse.setText("..."); browse.addSelectionListener(new DirectoryBrowser(text)); // Return the Text that holds the directory return text; }
From source file:ProgressBarDialog.java
protected void createContents() { shell = new Shell(getParent(), SWT.TITLE | SWT.PRIMARY_MODAL); display = shell.getDisplay();// w ww . j a v a 2s . co m final GridLayout gridLayout = new GridLayout(); gridLayout.verticalSpacing = 10; shell.setLayout(gridLayout); shell.setSize(483, 181); shell.setText(shellTitle); final Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); composite.setLayout(new GridLayout()); message = new CLabel(composite, SWT.NONE); message.setImage(processImage); message.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); message.setText(processMessage); progressBarComposite = new Composite(shell, SWT.NONE); progressBarComposite.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); progressBarComposite.setLayout(new FillLayout()); progressBar = new ProgressBar(progressBarComposite, processBarStyle); progressBar.setMaximum(executeTime); processMessageLabel = new Label(shell, SWT.NONE); processMessageLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); lineLabel = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR); lineLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); cancelComposite = new Composite(shell, SWT.NONE); cancelComposite.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); final GridLayout gridLayout_1 = new GridLayout(); gridLayout_1.numColumns = 2; cancelComposite.setLayout(gridLayout_1); cancelButton = new Button(cancelComposite, SWT.NONE); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { isClosed = true; //System.out.println(isClosed); } }); cancelButton.setLayoutData(new GridData(78, SWT.DEFAULT)); cancelButton.setText("cancel"); cancelButton.setEnabled(this.mayCancel); }
From source file:org.eclipse.swt.examples.paint.TextTool.java
/** * Handles a mouseDown event./*from ww w . j a va 2 s . c o m*/ * * @param event the mouse event detail information */ @Override public void mouseDown(MouseEvent event) { if (event.button == 1) { // draw with left mouse button getPaintSurface().commitRubberbandSelection(); } else { // set text with right mouse button getPaintSurface().clearRubberbandSelection(); Shell shell = getPaintSurface().getShell(); final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setText(PaintExample.getResourceString("tool.Text.dialog.title")); dialog.setLayout(new GridLayout()); Label label = new Label(dialog, SWT.NONE); label.setText(PaintExample.getResourceString("tool.Text.dialog.message")); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); final Text field = new Text(dialog, SWT.SINGLE | SWT.BORDER); field.setText(drawText); field.selectAll(); field.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Composite buttons = new Composite(dialog, SWT.NONE); GridLayout layout = new GridLayout(2, true); layout.marginWidth = 0; buttons.setLayout(layout); buttons.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); Button ok = new Button(buttons, SWT.PUSH); ok.setText(PaintExample.getResourceString("OK")); ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); ok.addSelectionListener(widgetSelectedAdapter(e -> { drawText = field.getText(); dialog.dispose(); })); Button cancel = new Button(buttons, SWT.PUSH); cancel.setText(PaintExample.getResourceString("Cancel")); cancel.addSelectionListener(widgetSelectedAdapter(e -> dialog.dispose())); dialog.setDefaultButton(ok); dialog.pack(); dialog.open(); Display display = dialog.getDisplay(); while (!shell.isDisposed() && !dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }
From source file:eu.stratosphere.addons.visualization.swt.SWTVertexToolTip.java
public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver, ManagementVertex managementVertex, int x, int y) { super(parent, x, y); this.managementVertex = managementVertex; final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex .getAttachment();/*from w w w. java 2 s .com*/ int height; final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); // Set the title final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1) + " of " + managementVertex.getNumberOfVerticesInGroup() + ")"; setTitle(taskName); // Only create chart if profiling is enabled if (vertexVisualizationData.isProfilingEnabledForJob()) { this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor); this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 240; // should be 265 when cancel button is enabled } else { this.threadChart = null; height = 125; } final Composite tableComposite = new Composite(getShell(), SWT.NONE); tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableComposite.setBackground(backgroundColor); tableComposite.setForeground(foregroundColor); final GridLayout tableGridLayout = new GridLayout(3, false); tableGridLayout.marginHeight = 0; tableGridLayout.marginLeft = 0; tableComposite.setLayout(tableGridLayout); final GridData gridData1 = new GridData(); gridData1.horizontalSpan = 2; gridData1.grabExcessHorizontalSpace = true; gridData1.widthHint = 200; final GridData gridData2 = new GridData(); gridData2.grabExcessHorizontalSpace = true; // Instance type final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE); instanceTypeTextLabel.setBackground(backgroundColor); instanceTypeTextLabel.setForeground(foregroundColor); instanceTypeTextLabel.setText("Instance type:"); this.instanceTypeLabel = new Label(tableComposite, SWT.NONE); this.instanceTypeLabel.setBackground(backgroundColor); this.instanceTypeLabel.setForeground(foregroundColor); this.instanceTypeLabel.setText(this.managementVertex.getInstanceType()); this.instanceTypeLabel.setLayoutData(gridData1); // Instance ID final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE); instanceIDTextLabel.setBackground(backgroundColor); instanceIDTextLabel.setForeground(foregroundColor); instanceIDTextLabel.setText("Instance ID:"); this.instanceIDLabel = new Label(tableComposite, SWT.NONE); this.instanceIDLabel.setBackground(backgroundColor); this.instanceIDLabel.setForeground(foregroundColor); this.instanceIDLabel.setText(this.managementVertex.getInstanceName()); this.instanceIDLabel.setLayoutData(gridData2); final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH); switchToInstanceButton.setText("Switch to instance..."); switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob()); switchToInstanceButton.setVisible(false); /* * final String instanceName = this.managementVertex.getInstanceName(); * switchToInstanceButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.switchToInstance(instanceName); * } * }); */ // Execution state final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE); executionStateTextLabel.setBackground(backgroundColor); executionStateTextLabel.setForeground(foregroundColor); executionStateTextLabel.setText("Execution state:"); this.executionStateLabel = new Label(tableComposite, SWT.NONE); this.executionStateLabel.setBackground(backgroundColor); this.executionStateLabel.setForeground(foregroundColor); this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString()); this.executionStateLabel.setLayoutData(gridData1); final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex(); final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex .getAttachment(); if (groupVertexVisualizationData.isCPUBottleneck()) { this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING); height += ICONSIZE; } else { this.warningComposite = null; } // Available task actions final Composite taskActionComposite = new Composite(getShell(), SWT.NONE); taskActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); taskActionComposite.setBackground(backgroundColor); taskActionComposite.setForeground(foregroundColor); /* * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH); * final ManagementVertexID vertexID = this.managementVertex.getID(); * cancelTaskButton.setText("Cancel task"); * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING); * cancelTaskButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.cancelTask(vertexID, taskName); * } * }); */ getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
From source file:MainClass.java
public void createContents(Shell shell, String location) { shell.setLayout(new FormLayout()); Composite controls = new Composite(shell, SWT.NONE); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); controls.setLayoutData(data); Label status = new Label(shell, SWT.NONE); data = new FormData(); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); status.setLayoutData(data);/*from ww w . j a v a 2s .c om*/ final Browser browser = new Browser(shell, SWT.BORDER); data = new FormData(); data.top = new FormAttachment(controls); data.bottom = new FormAttachment(status); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); browser.setLayoutData(data); controls.setLayout(new GridLayout(7, false)); Button button = new Button(controls, SWT.PUSH); button.setText("Back"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.back(); } }); button = new Button(controls, SWT.PUSH); button.setText("Forward"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.forward(); } }); button = new Button(controls, SWT.PUSH); button.setText("Refresh"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.refresh(); } }); button = new Button(controls, SWT.PUSH); button.setText("Stop"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.stop(); } }); final Text url = new Text(controls, SWT.BORDER); url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); url.setFocus(); button = new Button(controls, SWT.PUSH); button.setText("Go"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.setUrl(url.getText()); } }); Label throbber = new Label(controls, SWT.NONE); throbber.setText(AT_REST); shell.setDefaultButton(button); browser.addCloseWindowListener(new AdvancedCloseWindowListener()); browser.addLocationListener(new AdvancedLocationListener(url)); browser.addProgressListener(new AdvancedProgressListener(throbber)); browser.addStatusTextListener(new AdvancedStatusTextListener(status)); if (location != null) { browser.setUrl(location); } }
From source file:org.eclipse.swt.examples.controlexample.TextTab.java
/** * Creates the "Style" group.// ww w .j a v a2s . c o m */ @Override void createStyleGroup() { super.createStyleGroup(); /* Create the extra widgets */ wrapButton = new Button(styleGroup, SWT.CHECK); wrapButton.setText("SWT.WRAP"); readOnlyButton = new Button(styleGroup, SWT.CHECK); readOnlyButton.setText("SWT.READ_ONLY"); passwordButton = new Button(styleGroup, SWT.CHECK); passwordButton.setText("SWT.PASSWORD"); searchButton = new Button(styleGroup, SWT.CHECK); searchButton.setText("SWT.SEARCH"); iconCancelButton = new Button(styleGroup, SWT.CHECK); iconCancelButton.setText("SWT.ICON_CANCEL"); iconSearchButton = new Button(styleGroup, SWT.CHECK); iconSearchButton.setText("SWT.ICON_SEARCH"); Composite alignmentGroup = new Composite(styleGroup, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginWidth = layout.marginHeight = 0; alignmentGroup.setLayout(layout); alignmentGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); leftButton = new Button(alignmentGroup, SWT.RADIO); leftButton.setText("SWT.LEFT"); centerButton = new Button(alignmentGroup, SWT.RADIO); centerButton.setText("SWT.CENTER"); rightButton = new Button(alignmentGroup, SWT.RADIO); rightButton.setText("SWT.RIGHT"); }
From source file:SWTBrowser.java
public SWTBrowser() { shell.setLayout(new GridLayout()); ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT); final ToolBarManager manager = new ToolBarManager(toolBar); Composite compositeLocation = new Composite(shell, SWT.NULL); compositeLocation.setLayout(new GridLayout(3, false)); compositeLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label labelAddress = new Label(compositeLocation, SWT.NULL); labelAddress.setText("Address"); textLocation = new Text(compositeLocation, SWT.SINGLE | SWT.BORDER); textLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button buttonGo = new Button(compositeLocation, SWT.NULL); buttonGo.setImage(new Image(shell.getDisplay(), "java2s.gif")); browser = new Browser(shell, SWT.BORDER); browser.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite compositeStatus = new Composite(shell, SWT.NULL); compositeStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); compositeStatus.setLayout(new GridLayout(2, false)); labelStatus = new Label(compositeStatus, SWT.NULL); labelStatus.setText("Ready"); labelStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final ProgressBar progressBar = new ProgressBar(compositeStatus, SWT.SMOOTH); Listener openURLListener = new Listener() { public void handleEvent(Event event) { browser.setUrl(textLocation.getText()); }// w w w .j a v a 2s . c o m }; buttonGo.addListener(SWT.Selection, openURLListener); textLocation.addListener(SWT.DefaultSelection, openURLListener); // Adds tool bar items using actions. final Action actionBackward = new Action("&Backword", ImageDescriptor.createFromFile(null, "java2s.gif")) { public void run() { browser.back(); } }; actionBackward.setEnabled(false); // action is disabled at start up. final Action actionForward = new Action("&Forward", ImageDescriptor.createFromFile(null, "icons/web/forward.gif")) { public void run() { browser.forward(); } }; actionForward.setEnabled(false); // action is disabled at start up. Action actionStop = new Action("&Stop", ImageDescriptor.createFromFile(null, "icons/web/stop.gif")) { public void run() { browser.stop(); } }; Action actionRefresh = new Action("&Refresh", ImageDescriptor.createFromFile(null, "icons/web/refresh.gif")) { public void run() { browser.refresh(); } }; Action actionHome = new Action("&Home", ImageDescriptor.createFromFile(null, "icons/web/home.gif")) { public void run() { browser.setUrl("http://www.eclipse.org"); } }; manager.add(actionBackward); manager.add(actionForward); manager.add(actionStop); manager.add(actionRefresh); manager.add(actionHome); manager.update(true); toolBar.pack(); browser.addLocationListener(new LocationListener() { public void changing(LocationEvent event) { // Displays the new location in the text field. textLocation.setText(event.location); } public void changed(LocationEvent event) { // Update tool bar items. actionBackward.setEnabled(browser.isBackEnabled()); actionForward.setEnabled(browser.isForwardEnabled()); manager.update(false); } }); browser.addProgressListener(new ProgressListener() { public void changed(ProgressEvent event) { progressBar.setMaximum(event.total); progressBar.setSelection(event.current); } public void completed(ProgressEvent event) { progressBar.setSelection(0); } }); browser.addStatusTextListener(new StatusTextListener() { public void changed(StatusTextEvent event) { labelStatus.setText(event.text); } }); browser.addTitleListener(new TitleListener() { public void changed(TitleEvent event) { shell.setText(event.title + " - powered by SWT"); } }); initialize(display, browser); shell.setSize(500, 400); shell.open(); //textUser.forceFocus(); //browser.setText( // "<html><body>" + "<h1>SWT & JFace </h1>" + "</body/html>"); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }