List of usage examples for org.eclipse.swt.widgets Composite setLayout
public void setLayout(Layout layout)
From source file:AddressBook.java
/** * Creates the contents of the page/*from w ww.ja v a2s .c om*/ * * @param parent * the parent composite */ public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); // Create the label and text box to hold email address new Label(composite, SWT.LEFT).setText("E-mail Address:"); final Text ea = new Text(composite, SWT.BORDER); ea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Add handler to update e-mail based on input ea.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { email = ea.getText(); setPageComplete(email.length() > 0); } }); setControl(composite); }
From source file:PersonEditor.java
/** * Creates the main window's contents/*from w ww . j ava 2 s .c om*/ * * @param parent * the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); // Add a button to create the new person Button newPerson = new Button(composite, SWT.PUSH); newPerson.setText("Create New Person"); // Add the TableViewer final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION); tv.setContentProvider(new PersonContentProvider()); tv.setLabelProvider(new PersonLabelProvider()); tv.setInput(people); // Set up the table Table table = tv.getTable(); table.setLayoutData(new GridData(GridData.FILL_BOTH)); new TableColumn(table, SWT.CENTER).setText(NAME); new TableColumn(table, SWT.CENTER).setText(MALE); new TableColumn(table, SWT.CENTER).setText(AGE); new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR); for (int i = 0, n = table.getColumnCount(); i < n; i++) { table.getColumn(i).pack(); } table.setHeaderVisible(true); table.setLinesVisible(true); // Add a new person when the user clicks button newPerson.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Person p = new Person(); p.setName("Name"); p.setMale(true); p.setAgeRange(Integer.valueOf("0")); p.setShirtColor(new RGB(255, 0, 0)); people.add(p); tv.refresh(); } }); // Create the cell editors CellEditor[] editors = new CellEditor[4]; editors[0] = new TextCellEditor(table); editors[1] = new CheckboxCellEditor(table); editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES, SWT.READ_ONLY); editors[3] = new ColorCellEditor(table); // Set the editors, cell modifier, and column properties tv.setColumnProperties(PROPS); tv.setCellModifier(new PersonCellModifier(tv)); tv.setCellEditors(editors); return composite; }
From source file:grafici.MediciBarChart.java
/** * Creates a new demo instance./* ww w . ja va2s.c o m*/ * * @param title * the frame title. */ public MediciBarChart(String title, Composite parent, int style, int tipo) { super(parent, style); try { this.titolo = title; GridData gdThis = new GridData(SWT.FILL); gdThis.horizontalAlignment = SWT.FILL; gdThis.verticalAlignment = SWT.FILL; gdThis.grabExcessHorizontalSpace = true; gdThis.grabExcessVerticalSpace = true; this.setLayoutData(gdThis); this.setLayout(new GridLayout(1, false)); Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED); GridData gdCmp = new GridData(SWT.FILL); gdCmp.horizontalAlignment = SWT.FILL; gdCmp.verticalAlignment = SWT.FILL; gdCmp.grabExcessHorizontalSpace = true; gdCmp.grabExcessVerticalSpace = true; cmp.setLayoutData(gdCmp); cmp.setLayout(new GridLayout(1, false)); CategoryDataset dataset = createDataset(tipo); JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setFillZoomRectangle(true); // chartPanel.setMouseWheelEnabled(true); // chartPanel.setPreferredSize(new Dimension(1000, 700)); Frame graphFrame = SWT_AWT.new_Frame(cmp); graphFrame.add(chartPanel); graphFrame.pack(); } catch (Exception e) { e.printStackTrace(); } }
From source file:AddressBook.java
/** * Creates the page contents/*from w w w . ja va 2 s .co m*/ * * @param parent * the parent composite */ public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); // Create the label and text field for first name new Label(composite, SWT.LEFT).setText("First Name:"); final Text first = new Text(composite, SWT.BORDER); first.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the label and text field for last name new Label(composite, SWT.LEFT).setText("Last Name:"); final Text last = new Text(composite, SWT.BORDER); last.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Add the handler to update the first name based on input first.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { firstName = first.getText(); setPageComplete(firstName.length() > 0 && lastName.length() > 0); } }); // Add the handler to update the last name based on input last.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { lastName = last.getText(); setPageComplete(firstName.length() > 0 && lastName.length() > 0); } }); setControl(composite); }
From source file:org.eclipse.swt.examples.browserexample.BrowserExample.java
public BrowserExample(Composite parent, boolean top) { this.parent = parent; try {//from w w w . j a v a 2 s . c om browser = new Browser(parent, SWT.BORDER); } catch (SWTError e) { error = e; /* Browser widget could not be instantiated */ parent.setLayout(new FillLayout()); Label label = new Label(parent, SWT.CENTER | SWT.WRAP); label.setText(getResourceString("BrowserNotCreated")); label.requestLayout(); return; } initResources(); final Display display = parent.getDisplay(); browser.setData("org.eclipse.swt.examples.browserexample.BrowserApplication", this); browser.addOpenWindowListener(event -> { Shell shell = new Shell(display); if (icon != null) shell.setImage(icon); shell.setLayout(new FillLayout()); BrowserExample app = new BrowserExample(shell, false); app.setShellDecoration(icon, true); event.browser = app.getBrowser(); }); if (top) { browser.setUrl(getResourceString("Startup")); show(false, null, null, true, true, true, true); } else { browser.addVisibilityWindowListener(VisibilityWindowListener.showAdapter(e -> { Browser browser = (Browser) e.widget; BrowserExample app = (BrowserExample) browser .getData("org.eclipse.swt.examples.browserexample.BrowserApplication"); app.show(true, e.location, e.size, e.addressBar, e.menuBar, e.statusBar, e.toolBar); })); browser.addCloseWindowListener(event -> { Browser browser = (Browser) event.widget; Shell shell = browser.getShell(); shell.close(); }); } }
From source file:ReservationData.java
public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new GridLayout(2, false)); new Label(composite, SWT.NULL).setText("Credit card type: "); comboCreditCardTypes = new Combo(composite, SWT.READ_ONLY | SWT.BORDER); comboCreditCardTypes.add("American Express"); comboCreditCardTypes.add("Master Card"); comboCreditCardTypes.add("Visa"); comboCreditCardTypes.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(composite, SWT.NULL).setText("Credit card number: "); textCreditCardNumber = new Text(composite, SWT.SINGLE | SWT.BORDER); textCreditCardNumber.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(composite, SWT.NULL).setText("Expiration (MM/YY)"); textCreditCardExpiration = new Text(composite, SWT.SINGLE | SWT.BORDER); textCreditCardExpiration.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); comboCreditCardTypes.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { ((ReservationWizard) getWizard()).data.creditCardType = comboCreditCardTypes.getSelectionIndex(); if (((ReservationWizard) getWizard()).data.creditCardNumber != null && ((ReservationWizard) getWizard()).data.creditCardExpiration != null) setPageComplete(true);/*w w w .ja va 2 s . c om*/ else setPageComplete(false); } }); textCreditCardNumber.addListener(SWT.Modify, new Listener() { public void handleEvent(Event event) { ((ReservationWizard) getWizard()).data.creditCardNumber = textCreditCardNumber.getText(); if (((ReservationWizard) getWizard()).data.creditCardNumber != null && ((ReservationWizard) getWizard()).data.creditCardExpiration != null) setPageComplete(true); else setPageComplete(false); } }); textCreditCardExpiration.addListener(SWT.Modify, new Listener() { public void handleEvent(Event event) { String text = textCreditCardExpiration.getText().trim(); if (text.length() == 5 && text.charAt(2) == '/') { ((ReservationWizard) getWizard()).data.creditCardExpiration = text; setErrorMessage(null); } else { ((ReservationWizard) getWizard()).data.creditCardExpiration = null; setErrorMessage("Invalid expiration date: " + text); } if (((ReservationWizard) getWizard()).data.creditCardNumber != null && ((ReservationWizard) getWizard()).data.creditCardExpiration != null) setPageComplete(true); else setPageComplete(false); } }); setControl(composite); }
From source file:grafici.PrenotazioniBarChart.java
/** * Creates a new demo instance.//from w w w. j a v a 2 s . c om * * @param title * the frame title. */ public PrenotazioniBarChart(String title, Composite parent, int style, int tipo) { super(parent, style); try { this.titolo = title; GridData gdThis = new GridData(SWT.FILL); gdThis.horizontalAlignment = SWT.FILL; gdThis.verticalAlignment = SWT.FILL; gdThis.grabExcessHorizontalSpace = true; gdThis.grabExcessVerticalSpace = true; this.setLayoutData(gdThis); this.setLayout(new GridLayout(1, false)); Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED); GridData gdCmp = new GridData(SWT.FILL); gdCmp.horizontalAlignment = SWT.FILL; gdCmp.verticalAlignment = SWT.FILL; gdCmp.grabExcessHorizontalSpace = true; gdCmp.grabExcessVerticalSpace = true; cmp.setLayoutData(gdCmp); cmp.setLayout(new GridLayout(1, false)); CategoryDataset dataset = createDataset(tipo); JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setFillZoomRectangle(true); // chartPanel.setMouseWheelEnabled(true); // chartPanel.setPreferredSize(new Dimension(1000, 700)); Frame graphFrame = SWT_AWT.new_Frame(cmp); graphFrame.add(chartPanel); graphFrame.pack(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ReservationData.java
public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new GridLayout(2, false)); new Label(composite, SWT.NULL).setText("Full name: "); textName = new Text(composite, SWT.SINGLE | SWT.BORDER); textName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(composite, SWT.NULL).setText("Phone Number: "); textPhone = new Text(composite, SWT.SINGLE | SWT.BORDER); textPhone.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(composite, SWT.NULL).setText("Email address: "); textEmail = new Text(composite, SWT.SINGLE | SWT.BORDER); textEmail.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(composite, SWT.NULL).setText("Address: "); textAddress = new Text(composite, SWT.MULTI | SWT.BORDER); textAddress.setText("\r\n\r\n\r\n"); textAddress.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Listener listener = new Listener() { public void handleEvent(Event event) { if (event.widget == null || !(event.widget instanceof Text)) return; String string = ((Text) event.widget).getText(); if (event.widget == textName) { ((ReservationWizard) getWizard()).data.customerName = string; } else if (event.widget == textPhone) { ((ReservationWizard) getWizard()).data.customerPhone = string; } else if (event.widget == textEmail) { if (string.indexOf('@') < 0) { setErrorMessage("Invalid email address: " + string); ((ReservationWizard) getWizard()).data.customerEmail = null; } else { setErrorMessage(null); ((ReservationWizard) getWizard()).data.customerEmail = string; }/*from w ww .jav a2 s . com*/ } else if (event.widget == textAddress) { ((ReservationWizard) getWizard()).data.customerAddress = string; } ReservationData data = ((ReservationWizard) getWizard()).data; if (data.customerName != null && data.customerPhone != null && data.customerEmail != null && data.customerAddress != null) { setPageComplete(true); } else { setPageComplete(false); } } }; textName.addListener(SWT.Modify, listener); textPhone.addListener(SWT.Modify, listener); textEmail.addListener(SWT.Modify, listener); textAddress.addListener(SWT.Modify, listener); if (getDialogSettings() != null && validDialogSettings()) { textName.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_NAME)); textPhone.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_PHONE)); textEmail.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_EMAIL)); textAddress.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_ADDRESS)); } setControl(composite); }
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 www .ja v a2s.c o m 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:SWTBrowserDemo.java
public SWTBrowserDemo(Composite parent, boolean top) { this.parent = parent; try {/*from w ww . ja v a 2s . co m*/ browser = new Browser(parent, SWT.BORDER); } catch (SWTError e) { error = e; /* Browser widget could not be instantiated */ parent.setLayout(new FillLayout()); Label label = new Label(parent, SWT.CENTER | SWT.WRAP); label.setText(getResourceString("BrowserNotCreated")); parent.layout(true); return; } initResources(); final Display display = parent.getDisplay(); browser.setData("org.eclipse.swt.examples.browserexample.BrowserApplication", this); browser.addOpenWindowListener(new OpenWindowListener() { public void open(WindowEvent event) { Shell shell = new Shell(display); if (icon != null) shell.setImage(icon); shell.setLayout(new FillLayout()); SWTBrowserDemo app = new SWTBrowserDemo(shell, false); app.setShellDecoration(icon, true); event.browser = app.getBrowser(); } }); if (top) { browser.setUrl(getResourceString("Startup")); show(false, null, null, true, true, true, true); } else { browser.addVisibilityWindowListener(new VisibilityWindowListener() { public void hide(WindowEvent e) { } public void show(WindowEvent e) { Browser browser = (Browser) e.widget; SWTBrowserDemo app = (SWTBrowserDemo) browser .getData("org.eclipse.swt.examples.browserexample.BrowserApplication"); app.show(true, e.location, e.size, e.addressBar, e.menuBar, e.statusBar, e.toolBar); } }); browser.addCloseWindowListener(new CloseWindowListener() { public void close(WindowEvent event) { Browser browser = (Browser) event.widget; Shell shell = browser.getShell(); shell.close(); } }); } }