List of usage examples for org.eclipse.swt.widgets Button setLayoutData
public void setLayoutData(Object layoutData)
From source file:DNDExample.java
private void createDragTypes(Composite parent) { parent.setLayout(new GridLayout()); Button b = new Button(parent, SWT.CHECK); b.setText("Text Transfer"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDragTransfer(TextTransfer.getInstance()); } else { removeDragTransfer(TextTransfer.getInstance()); }// www .j av a 2 s . com } }); b = new Button(parent, SWT.CHECK); b.setText("RTF Transfer"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDragTransfer(RTFTransfer.getInstance()); } else { removeDragTransfer(RTFTransfer.getInstance()); } } }); b = new Button(parent, SWT.CHECK); b.setText("HTML Transfer"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDragTransfer(HTMLTransfer.getInstance()); } else { removeDragTransfer(HTMLTransfer.getInstance()); } } }); b = new Button(parent, SWT.CHECK); b.setText("File Transfer"); b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDragTransfer(FileTransfer.getInstance()); } else { removeDragTransfer(FileTransfer.getInstance()); } } }); b = new Button(parent, SWT.PUSH); b.setText("Select File(s)"); b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(fileList.getShell(), SWT.OPEN | SWT.MULTI); String result = dialog.open(); if (result != null && result.length() > 0) { fileList.removeAll(); String separator = System.getProperty("file.separator"); String path = dialog.getFilterPath(); String[] names = dialog.getFileNames(); for (int i = 0; i < names.length; i++) { fileList.add(path + separator + names[i]); } } } }); fileList = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.BEGINNING; fileList.setLayoutData(data); }
From source file:org.eclipse.swt.examples.dnd.DNDExample.java
private void createDragTypes(Composite parent) { parent.setLayout(new GridLayout()); Button textButton = new Button(parent, SWT.CHECK); textButton.setText("Text Transfer"); textButton.addSelectionListener(widgetSelectedAdapter(e -> { Button b = (Button) e.widget; if (b.getSelection()) { addDragTransfer(TextTransfer.getInstance()); } else {/*from ww w . java 2 s. c o m*/ removeDragTransfer(TextTransfer.getInstance()); } })); Button b = new Button(parent, SWT.CHECK); b.setText("RTF Transfer"); b.addSelectionListener(widgetSelectedAdapter(e -> { Button b1 = (Button) e.widget; if (b1.getSelection()) { addDragTransfer(RTFTransfer.getInstance()); } else { removeDragTransfer(RTFTransfer.getInstance()); } })); b = new Button(parent, SWT.CHECK); b.setText("HTML Transfer"); b.addSelectionListener(widgetSelectedAdapter(e -> { Button b2 = (Button) e.widget; if (b2.getSelection()) { addDragTransfer(HTMLTransfer.getInstance()); } else { removeDragTransfer(HTMLTransfer.getInstance()); } })); b = new Button(parent, SWT.CHECK); b.setText("URL Transfer"); b.addSelectionListener(widgetSelectedAdapter(e -> { Button b3 = (Button) e.widget; if (b3.getSelection()) { addDragTransfer(URLTransfer.getInstance()); } else { removeDragTransfer(URLTransfer.getInstance()); } })); b = new Button(parent, SWT.CHECK); b.setText("File Transfer"); b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); b.addSelectionListener(widgetSelectedAdapter(e -> { Button b4 = (Button) e.widget; if (b4.getSelection()) { addDragTransfer(FileTransfer.getInstance()); } else { removeDragTransfer(FileTransfer.getInstance()); } })); b = new Button(parent, SWT.PUSH); b.setText("Select File(s)"); b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); b.addSelectionListener(widgetSelectedAdapter(e -> { FileDialog dialog = new FileDialog(fileList.getShell(), SWT.OPEN | SWT.MULTI); String result = dialog.open(); if (result != null && result.length() > 0) { fileList.removeAll(); String path = dialog.getFilterPath(); String[] names = dialog.getFileNames(); for (String name : names) { fileList.add(path + File.separatorChar + name); } } })); fileList = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.BEGINNING; fileList.setLayoutData(data); // initialize state textButton.setSelection(true); addDragTransfer(TextTransfer.getInstance()); }
From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java
/** * Creates the impact list page./* ww w . j a v a 2 s . co m*/ */ 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"); }
From source file:PaintExample.java
/** * Handles a mouseDown event.// w w w. java 2s . co m * * @param event the mouse event detail information */ 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(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { drawText = field.getText(); dialog.dispose(); } }); Button cancel = new Button(buttons, SWT.PUSH); cancel.setText(PaintExample.getResourceString("Cancel")); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent 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:PrintKTableExample.java
/** * Fugt einen Button zur Leiste hinzu. Gibt eine Referenz auf den angelegten * Button zuruck.//from ww w. ja v a 2 s. c o m */ public Button addButton(String name, String toolTip, SelectionListener selListener) { Button b = new Button(this, SWT.PUSH); b.setText(name); b.setToolTipText(toolTip); b.setLayoutData(new RowData(myButtonWidth, 25)); if (selListener != null) b.addSelectionListener(selListener); myButtons.add(b); return b; }
From source file:PrintKTableExample.java
public PrintSWTTableExample() { // create some gui with a SWT table display = new Display(); final Shell shell = new Shell(display); final org.eclipse.swt.layout.GridLayout gridLayout = new org.eclipse.swt.layout.GridLayout(); gridLayout.numColumns = 2;/*from ww w . j a v a 2 s . co m*/ shell.setLayout(gridLayout); final Color red = display.getSystemColor(SWT.COLOR_RED); final Table table_swt = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); final GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 2; table_swt.setLayoutData(gridData); table_swt.setLinesVisible(true); TableColumn column1 = new TableColumn(table_swt, SWT.NONE); TableColumn column2 = new TableColumn(table_swt, SWT.NONE); TableColumn column3 = new TableColumn(table_swt, SWT.NONE); column1.setText("Column1"); column2.setText("Column2"); column3.setText("Column3"); for (int i = 0; i < 100; i++) { TableItem item = new TableItem(table_swt, SWT.NONE); item.setText(new String[] { "cell " + i + " 0", "cell " + i + " 1", "cell " + i + "2" }); } column1.pack(); column2.pack(); column3.pack(); final Button butPrint = new Button(shell, SWT.NONE); butPrint.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // create a document with default settings from PageSetup final PDocument doc = new PDocument("SWT Table Printing Example"); // put some header text on it PTextBox t; t = new PTextBox(doc); t.setText("SWT Table Printing Example"); new PVSpace(doc, 0.1); new PHLine(doc, 0.02, SWT.COLOR_BLACK); new PVSpace(doc, 0.5); // create the table SWTPTable table = new SWTPTable(doc); table.setTable(table_swt); table.setBoxProvider(new PTableBoxProvider()); PrintPreview pr = new PrintPreview(null, "Test", IconSource.getImage("print"), doc); pr.open(); } }); butPrint.setText("Print Preview"); final Button butClose = new Button(shell, SWT.NONE); butClose.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.dispose(); } }); butClose.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); butClose.setText("Close"); // Show the shell shell.setSize(300, 400); shell.setText("SWT Table Printing Example"); shell.setVisible(true); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CustomControlExample.java
/** * Append the Set/Get API controls to the "Other" group. *//*ww w . j ava 2 s . c o m*/ void createSetGetGroup() { /* * Create the button to access set/get API functionality. */ final String[] methodNames = getMethodNames(); if (methodNames != null) { Button setGetButton = new Button(otherGroup, SWT.PUSH); setGetButton.setText(ControlExample.getResourceString("Set_Get")); setGetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); setGetButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button button = (Button) e.widget; Point pt = button.getLocation(); pt = e.display.map(button, null, pt); createSetGetDialog(pt.x, pt.y, methodNames); } }); } }
From source file:PrintKTableExample.java
protected Button addButton(boolean rightAdjusted, String text, String tip) { Button erg = new Button(guiButtonArea, SWT.PUSH); erg.setText(text);/* w w w . j ava 2s .com*/ erg.setToolTipText(tip); Point butPrefferedSize = erg.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd = new FormData(); fd.bottom = new FormAttachment(100, -3); if (butPrefferedSize.x > 70) fd.width = butPrefferedSize.x + 4; else fd.width = 70; fd.height = 24; erg.setLayoutData(fd); if (rightAdjusted) { if (guiLastRightBut == null) fd.right = new FormAttachment(100, -3); else fd.right = new FormAttachment(guiLastRightBut, -3); guiLastRightBut = erg; } else { if (guiLastLeftBut == null) fd.left = new FormAttachment(0, 3); else fd.left = new FormAttachment(guiLastLeftBut, 3); guiLastLeftBut = erg; } erg.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { onButton((Button) arg0.widget, ((Button) arg0.widget).getText()); } }); return erg; }
From source file:CustomControlExample.java
/** * Creates and opens the "Listener selection" dialog. *///from ww w .j a v a 2 s.co m void createListenerSelectionDialog() { final Shell dialog = new Shell(tabFolderPage.getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setText(ControlExample.getResourceString("Select_Listeners")); dialog.setLayout(new GridLayout(2, false)); final Table table = new Table(dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK); GridData data = new GridData(GridData.FILL_BOTH); data.verticalSpan = 2; table.setLayoutData(data); for (int i = 0; i < EVENT_NAMES.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(EVENT_NAMES[i]); item.setChecked(eventsFilter[i]); } final String[] customNames = getCustomEventNames(); for (int i = 0; i < customNames.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(customNames[i]); item.setChecked(eventsFilter[EVENT_NAMES.length + i]); } Button selectAll = new Button(dialog, SWT.PUSH); selectAll.setText(ControlExample.getResourceString("Select_All")); selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); selectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_NAMES.length; i++) { items[i].setChecked(true); } for (int i = 0; i < customNames.length; i++) { items[EVENT_NAMES.length + i].setChecked(true); } } }); Button deselectAll = new Button(dialog, SWT.PUSH); deselectAll.setText(ControlExample.getResourceString("Deselect_All")); deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); deselectAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_NAMES.length; i++) { items[i].setChecked(false); } for (int i = 0; i < customNames.length; i++) { items[EVENT_NAMES.length + i].setChecked(false); } } }); new Label(dialog, SWT.NONE); /* Filler */ Button ok = new Button(dialog, SWT.PUSH); ok.setText(ControlExample.getResourceString("OK")); dialog.setDefaultButton(ok); ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] items = table.getItems(); for (int i = 0; i < EVENT_NAMES.length; i++) { eventsFilter[i] = items[i].getChecked(); } for (int i = 0; i < customNames.length; i++) { eventsFilter[EVENT_NAMES.length + i] = items[EVENT_NAMES.length + i].getChecked(); } dialog.dispose(); } }); dialog.pack(); dialog.open(); while (!dialog.isDisposed()) { if (!dialog.getDisplay().readAndDispatch()) dialog.getDisplay().sleep(); } }
From source file:CustomControlExample.java
/** * Creates the "Listeners" group. The "Listeners" group goes below the * "Example" and "Control" groups./*from w w w .j a va 2 s .com*/ */ void createListenersGroup() { listenersGroup = new Group(tabFolderPage, SWT.NONE); listenersGroup.setLayout(new GridLayout(3, false)); listenersGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1)); listenersGroup.setText(ControlExample.getResourceString("Listeners")); /* * Create the button to access the 'Listeners' dialog. */ Button listenersButton = new Button(listenersGroup, SWT.PUSH); listenersButton.setText(ControlExample.getResourceString("Select_Listeners")); listenersButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { createListenerSelectionDialog(); recreateExampleWidgets(); } }); /* * Create the checkbox to add/remove listeners to/from the example * widgets. */ final Button listenCheckbox = new Button(listenersGroup, SWT.CHECK); listenCheckbox.setText(ControlExample.getResourceString("Listen")); listenCheckbox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { logging = listenCheckbox.getSelection(); recreateExampleWidgets(); } }); /* * Create the button to clear the text. */ Button clearButton = new Button(listenersGroup, SWT.PUSH); clearButton.setText(ControlExample.getResourceString("Clear")); clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); clearButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { eventConsole.setText(""); } }); /* Initialize the eventsFilter to log all events. */ int customEventCount = getCustomEventNames().length; eventsFilter = new boolean[EVENT_NAMES.length + customEventCount]; for (int i = 0; i < EVENT_NAMES.length + customEventCount; i++) { eventsFilter[i] = true; } /* Create the event console Text. */ eventConsole = new Text(listenersGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 3; data.heightHint = 80; eventConsole.setLayoutData(data); createEventConsolePopup(); eventConsole.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if ((e.keyCode == 'A' || e.keyCode == 'a') && (e.stateMask & SWT.MOD1) != 0) { eventConsole.selectAll(); e.doit = false; } } }); }