List of usage examples for org.eclipse.swt.widgets Composite setLayout
public void setLayout(Layout layout)
From source file:SWTTreeExample.java
private void createContents(Composite composite) { // Set the single-selection tree in the upper left, // the multi-selection tree in the upper right, // and the checkbox tree across the bottom. // To do this, create a 1x2 grid, and in the top // cell, a 2x1 grid. composite.setLayout(new GridLayout(1, true)); Composite top = new Composite(composite, SWT.NONE); GridData data = new GridData(GridData.FILL_BOTH); top.setLayoutData(data);//w w w . ja va 2s .c o m top.setLayout(new GridLayout(2, true)); Tree single = new Tree(top, SWT.SINGLE | SWT.BORDER); data = new GridData(GridData.FILL_BOTH); single.setLayoutData(data); fillTree(single); Tree multi = new Tree(top, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_BOTH); multi.setLayoutData(data); fillTree(multi); Tree check = new Tree(composite, SWT.CHECK | SWT.BORDER); data = new GridData(GridData.FILL_BOTH); check.setLayoutData(data); fillTree(check); }
From source file:org.eclipse.swt.examples.graphics.TextAntialiasTab.java
@Override public void createControlPanel(Composite parent) { Composite comp; // create drop down combo for antialiasing comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$ aliasCombo = new Combo(comp, SWT.DROP_DOWN); aliasCombo.add("OFF"); aliasCombo.add("DEFAULT"); aliasCombo.add("ON"); aliasCombo.select(0);/*from w w w . j av a 2 s. c om*/ aliasCombo.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setColorItems(true); menu = cm.createMenu(parent.getParent(), gb -> { textColor = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); // initialize the color to black textColor = (GraphicsBackground) menu.getItem(1).getData(); colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(textColor.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.ietr.preesm.mapper.ui.GanttPlotter.java
/** * Gantt chart plotting function in a given composite */// www.j av a2 s . c o m public void plotInComposite(Composite parent) { Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.FILL); parent.setLayout(new FillLayout()); Frame frame = SWT_AWT.new_Frame(composite); frame.add(getContentPane()); MouseClickedListener listener = new MouseClickedListener(frame); chartPanel.addChartMouseListener(listener); chartPanel.addMouseMotionListener(listener); chartPanel.addMouseListener(listener); }
From source file:org.eclipse.swt.examples.graphics.PathClippingTab.java
/** * Creates the widgets used to control the drawing. *///w w w. j a v a2 s .c o m @Override public void createControlPanel(Composite parent) { // create drop down combo for choosing clipping Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Clipping")); //$NON-NLS-1$ clippingCb = new Combo(comp, SWT.DROP_DOWN); clippingCb.add(GraphicsExample.getResourceString("Circles")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Rectangle")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Oval")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Word")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Star")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Triangles")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Default")); //$NON-NLS-1$ clippingCb.select(0); clippingCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { background = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the background to the 5th item in the menu (blue) background = (GraphicsBackground) menu.getItem(4).getData(); // color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(background.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.eclipse.swt.examples.paint.TextTool.java
/** * Handles a mouseDown event.// www . j ava 2s .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:org.eclipse.swt.examples.ole.win32.OLEExample.java
public void open(Display display) { Shell shell = new Shell(display); shell.setText("OLE Example"); shell.setLayout(new FillLayout()); Composite parent = new Composite(shell, SWT.NONE); parent.setLayout(new GridLayout(4, true)); Composite buttons = new Composite(parent, SWT.NONE); buttons.setLayout(new GridLayout()); GridData gridData = new GridData(SWT.BEGINNING, SWT.FILL, false, false); buttons.setLayoutData(gridData);//w w w .j a va2 s. com Composite displayArea = new Composite(parent, SWT.BORDER); displayArea.setLayout(new FillLayout()); displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); Button excelButton = new Button(buttons, SWT.RADIO); excelButton.setText("New Excel Sheet"); excelButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("Excel.Sheet"); })); Button mediaPlayerButton = new Button(buttons, SWT.RADIO); mediaPlayerButton.setText("New MPlayer"); mediaPlayerButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("MPlayer"); })); Button powerPointButton = new Button(buttons, SWT.RADIO); powerPointButton.setText("New PowerPoint Slide"); powerPointButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("PowerPoint.Slide"); })); Button wordButton = new Button(buttons, SWT.RADIO); wordButton.setText("New Word Document"); wordButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("Word.Document"); })); new Label(buttons, SWT.NONE); Button openButton = new Button(buttons, SWT.RADIO); openButton.setText("Open file..."); openButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) fileOpen(); })); new Label(buttons, SWT.NONE); closeButton = new Button(buttons, SWT.RADIO); closeButton.setText("Close file"); closeButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) disposeClient(); })); closeButton.setSelection(true); oleFrame = new OleFrame(displayArea, SWT.NONE); addFileMenu(oleFrame); shell.setSize(800, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:org.jcryptool.visual.verifiablesecretsharing.views.ReconstructionChartComposite.java
/** * Generates the head of the tab. The head has a title and a description. */// w ww . j a va 2 s. c o m private void createHead() { final Composite head = new Composite(this, SWT.NONE); head.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); head.setLayout(new GridLayout()); final Label label = new Label(head, SWT.NONE); label.setFont(FontService.getHeaderFont()); label.setText(Messages.VerifiableSecretSharingComposite_tab_title); stDescription = new StyledText(head, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP); stDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); if (reconstructedPolynom.toString().compareTo("0") == 0) { stDescription.setText(Messages.ChartComposite_noGraph); } else { stDescription.setText(reconstructedPolynom.toString()); } }
From source file:org.eclipse.swt.examples.graphics.InterpolationTab.java
@Override public void createControlPanel(Composite parent) { Composite comp; GridLayout gridLayout = new GridLayout(2, false); // create drop down combo comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Image")); //$NON-NLS-1$ imageCb = new Combo(comp, SWT.DROP_DOWN); imageCb.add(GraphicsExample.getResourceString("House")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Question")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Task")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Font")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Cube")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("SWT")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Ovals")); //$NON-NLS-1$ imageCb.select(0);/* w w w.ja v a2 s. com*/ imageCb.addListener(SWT.Selection, event -> example.redraw()); }
From source file:org.eclipse.swt.snippets.Snippet319.java
public void go() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 319"); shell.setBounds(10, 10, 600, 200);/* w w w. jav a2 s .c o m*/ /* Create SWT controls and add drag source */ final Label swtLabel = new Label(shell, SWT.BORDER); swtLabel.setBounds(10, 10, 580, 50); swtLabel.setText("SWT drag source"); DragSource dragSource = new DragSource(swtLabel, DND.DROP_COPY); dragSource.setTransfer(new MyTypeTransfer()); dragSource.addDragListener(new DragSourceAdapter() { @Override public void dragSetData(DragSourceEvent event) { MyType object = new MyType(); object.name = "content dragged from SWT"; object.time = System.currentTimeMillis(); event.data = object; } }); /* Create AWT/Swing controls */ Composite embeddedComposite = new Composite(shell, SWT.EMBEDDED); embeddedComposite.setBounds(10, 100, 580, 50); embeddedComposite.setLayout(new FillLayout()); Frame frame = SWT_AWT.new_Frame(embeddedComposite); final JLabel jLabel = new JLabel("AWT/Swing drop target"); frame.add(jLabel); /* Register the custom data flavour */ final DataFlavor flavor = new DataFlavor(MIME_TYPE, "MyType custom flavor"); /* * Note that according to jre/lib/flavormap.properties, the preferred way to * augment the default system flavor map is to specify the AWT.DnD.flavorMapFileURL * property in an awt.properties file. * * This snippet uses the alternate approach below in order to provide a simple * stand-alone snippet that demonstrates the functionality. This implementation * works well, but if the instanceof check below fails for some reason when used * in a different context then the drop will not be accepted. */ FlavorMap map = SystemFlavorMap.getDefaultFlavorMap(); if (map instanceof SystemFlavorMap) { SystemFlavorMap systemMap = (SystemFlavorMap) map; systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor); } /* add drop target */ DropTargetListener dropTargetListener = new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dropTargetDropEvent) { try { dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY); ByteArrayInputStream inStream = (ByteArrayInputStream) dropTargetDropEvent.getTransferable() .getTransferData(flavor); int available = inStream.available(); byte[] bytes = new byte[available]; inStream.read(bytes); MyType object = restoreFromByteArray(bytes); String string = object.name + ": " + new Date(object.time).toString(); jLabel.setText(string); } catch (Exception e) { e.printStackTrace(); } } }; new DropTarget(jLabel, dropTargetListener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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()); }//from w w w . j a v a 2 s . 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(); }