List of usage examples for org.eclipse.swt.widgets Composite getDisplay
public Display getDisplay()
Display
that is associated with the receiver. From source file:WidgetTest2.java
public static Button createImageButton(Composite composite) { final Button button = new Button(composite, SWT.PUSH); Display display = composite.getDisplay(); final Image image = new Image(display, "images/button1.gif"); button.setImage(image);/*w w w . j a v a2s . c om*/ // React to click events button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { System.out.println("Key was pressed"); } }); // Dispose image when button is disposed button.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { image.dispose(); } }); return button; }
From source file:widgetTest3.java
/** * Fonts ** */ public static void drawItalic(Composite composite, GC gc) { // Get Display instance Display display = composite.getDisplay(); // Fetch system font Font systemFont = display.getSystemFont(); // FontData objects contain the font properties. // With some operating systems a font may possess multiple // FontData instances. We only use the first one. FontData[] data = systemFont.getFontData(); FontData data0 = data[0];//from w ww . jav a 2s . c o m // Set the font style to italic data0.setStyle(SWT.ITALIC); // Create a new font Font italicFont = new Font(display, data0); // Set the new font in the graphics context gc.setFont(italicFont); // TODO: call italicFont.dispose() in the DisposeListener // of composite // Draw text at position (4,4) with a transparent background (true). gc.drawText("Hello", 4, 4, true); }
From source file:org.eclipse.swt.examples.graphics.AnimatedGraphicsTab.java
/** * Creates the toolbar controls: play, pause and animation timer. * * @param parent A composite/*from ww w. j a va 2 s. c o m*/ */ void createToolBar(final Composite parent) { final Display display = parent.getDisplay(); toolBar = new ToolBar(parent, SWT.FLAT); Listener toolBarListener = event -> { switch (event.type) { case SWT.Selection: { if (event.widget == playItem) { animate = true; playItem.setEnabled(!animate); pauseItem.setEnabled(animate); } else if (event.widget == pauseItem) { animate = false; playItem.setEnabled(!animate); pauseItem.setEnabled(animate); } } break; } }; // play tool item playItem = new ToolItem(toolBar, SWT.PUSH); playItem.setText(GraphicsExample.getResourceString("Play")); //$NON-NLS-1$ playItem.setImage(example.loadImage(display, "play.gif")); //$NON-NLS-1$ playItem.addListener(SWT.Selection, toolBarListener); // pause tool item pauseItem = new ToolItem(toolBar, SWT.PUSH); pauseItem.setText(GraphicsExample.getResourceString("Pause")); //$NON-NLS-1$ pauseItem.setImage(example.loadImage(display, "pause.gif")); //$NON-NLS-1$ pauseItem.addListener(SWT.Selection, toolBarListener); // timer spinner Composite comp = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(2, false); comp.setLayout(gridLayout); Label label = new Label(comp, SWT.CENTER); label.setText(GraphicsExample.getResourceString("Animation")); //$NON-NLS-1$ timerSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); timerSpinner.setMaximum(1000); playItem.setEnabled(false); animate = true; timerSpinner.setSelection(getInitialAnimationTime()); }
From source file:org.eclipse.swt.examples.graphics.GradientTab.java
@Override public void createControlPanel(final Composite parent) { final Display display = parent.getDisplay(); toolBar = new ToolBar(parent, SWT.FLAT); ColorMenu colorMenu = new ColorMenu(); // menu for colorItem1 menu1 = colorMenu.createMenu(parent.getParent(), gb -> { colorGB1 = gb;// w ww .j av a2s .co m colorItem1.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the background to the 5th item in the menu (blue) colorGB1 = (GraphicsBackground) menu1.getItem(4).getData(); // toolbar item for color1 colorItem1 = new ToolItem(toolBar, SWT.PUSH); colorItem1.setText(GraphicsExample.getResourceString("GradientTabItem1")); colorItem1.setImage(colorGB1.getThumbNail()); colorItem1.addListener(SWT.Selection, event -> { final ToolItem toolItem = (ToolItem) event.widget; final ToolBar toolBar = toolItem.getParent(); Rectangle toolItemBounds = toolItem.getBounds(); Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); menu1.setLocation(point.x, point.y + toolItemBounds.height); menu1.setVisible(true); }); // menu for colorItem2 menu2 = colorMenu.createMenu(parent.getParent(), gb -> { colorGB2 = gb; colorItem2.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the background to the 3rd item in the menu (red) colorGB2 = (GraphicsBackground) menu2.getItem(2).getData(); // toolbar item for color2 colorItem2 = new ToolItem(toolBar, SWT.PUSH); colorItem2.setText(GraphicsExample.getResourceString("GradientTabItem2")); colorItem2.setImage(colorGB2.getThumbNail()); colorItem2.addListener(SWT.Selection, event -> { final ToolItem toolItem = (ToolItem) event.widget; final ToolBar toolBar = toolItem.getParent(); Rectangle toolItemBounds = toolItem.getBounds(); Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); menu2.setLocation(point.x, point.y + toolItemBounds.height); menu2.setVisible(true); }); // toolbar item for swapping colors ToolItem swapItem = new ToolItem(toolBar, SWT.PUSH); swapItem.setText(GraphicsExample.getResourceString("SwapColors")); //$NON-NLS-1$ swapItem.setImage(example.loadImage(display, "swap.gif")); swapItem.addListener(SWT.Selection, event -> { GraphicsBackground tmp = colorGB1; colorGB1 = colorGB2; colorGB2 = tmp; colorItem1.setImage(colorGB1.getThumbNail()); colorItem2.setImage(colorGB2.getThumbNail()); example.redraw(); }); }
From source file:org.eclipse.swt.examples.graphics.CurvesTab.java
/** * Creates the widgets used to control the drawing. *///from ww w . j a v a2s. co m @Override public void createControlPanel(Composite parent) { if (cursor == null) { cursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND); } mouseMoveListener = e -> { if (hovering && mouseDown) { example.canvas.setCursor(cursor); } else if (isHovering(e)) { example.canvas.setCursor(cursor); hovering = true; } else { example.canvas.setCursor(null); hovering = false; } if (quadPtMoved) { quadDiffX = quadDiffX + e.x - (int) quadXPos - quadHndl.x; quadDiffY = quadDiffY + e.y - (int) quadYPos - quadHndl.y; quadHndl.x = e.x - (int) quadXPos; quadHndl.y = e.y - (int) quadYPos; } else if (quadEndPtMoved) { quadEndDiffX = quadEndDiffX + e.x - (int) quadXPos - quadEndHndl.x; quadEndDiffY = quadEndDiffY + e.y - (int) quadYPos - quadEndHndl.y; quadEndHndl.x = e.x - (int) quadXPos; quadEndHndl.y = e.y - (int) quadYPos; } else if (cubPt1Moved) { cubDiffX1 = cubDiffX1 + e.x - (int) cubXPos - cubHndl1.x; cubDiffY1 = cubDiffY1 + e.y - (int) cubYPos - cubHndl1.y; cubHndl1.x = e.x - (int) cubXPos; cubHndl1.y = e.y - (int) cubYPos; } else if (cubPt2Moved) { cubDiffX2 = cubDiffX2 + e.x - (int) cubXPos - cubHndl2.x; cubDiffY2 = cubDiffY2 + e.y - (int) cubYPos - cubHndl2.y; cubHndl2.x = e.x - (int) cubXPos; cubHndl2.y = e.y - (int) cubYPos; } else if (cubEndPtMoved) { cubEndDiffX = cubEndDiffX + e.x - (int) cubXPos - cubEndHndl.x; cubEndDiffY = cubEndDiffY + e.y - (int) cubYPos - cubEndHndl.y; cubEndHndl.x = e.x - (int) cubXPos; cubEndHndl.y = e.y - (int) cubYPos; } example.redraw(); }; mouseListener = new MouseListener() { @Override public void mouseDoubleClick(MouseEvent e) { } /** * Sent when a mouse button is pressed. * * @param e an event containing information about the mouse button press */ @Override public void mouseDown(MouseEvent e) { Rectangle quad = new Rectangle(quadHndl.x + (int) quadXPos - 1, quadHndl.y + (int) quadYPos - 1, quadHndl.width + 2, quadHndl.height + 2); Rectangle quadEnd = new Rectangle(quadEndHndl.x + (int) quadXPos - 1, quadEndHndl.y + (int) quadYPos - 1, quadEndHndl.width + 2, quadEndHndl.height + 2); Rectangle cub1 = new Rectangle(cubHndl1.x + (int) cubXPos - 1, cubHndl1.y + (int) cubYPos - 1, cubHndl1.width + 2, cubHndl1.height + 2); Rectangle cub2 = new Rectangle(cubHndl2.x + (int) cubXPos - 1, cubHndl2.y + (int) cubYPos - 1, cubHndl2.width + 2, cubHndl2.height + 2); Rectangle cubEnd = new Rectangle(cubEndHndl.x + (int) cubXPos - 1, cubEndHndl.y + (int) cubYPos - 1, cubEndHndl.width + 2, cubEndHndl.height + 2); if (quad.contains(e.x, e.y)) { quadPtMoved = true; mouseDown = true; } else if (quadEnd.contains(e.x, e.y)) { quadEndPtMoved = true; mouseDown = true; } else if (cub1.contains(e.x, e.y)) { cubPt1Moved = true; mouseDown = true; } else if (cub2.contains(e.x, e.y)) { cubPt2Moved = true; mouseDown = true; } else if (cubEnd.contains(e.x, e.y)) { cubEndPtMoved = true; mouseDown = true; } } /** * Sent when a mouse button is released. * * @param e an event containing information about the mouse button release */ @Override public void mouseUp(MouseEvent e) { mouseDown = false; if (isHovering(e)) { example.canvas.setCursor(cursor); } else { example.canvas.setCursor(null); } if (quadPtMoved) quadPtMoved = false; if (quadEndPtMoved) quadEndPtMoved = false; if (cubPt1Moved) cubPt1Moved = false; if (cubPt2Moved) cubPt2Moved = false; if (cubEndPtMoved) cubEndPtMoved = false; example.redraw(); } }; example.canvas.addMouseMoveListener(mouseMoveListener); example.canvas.addMouseListener(mouseListener); }
From source file:BrowserExample.java
/** * Creates an instance of a ControlExample embedded inside the supplied * parent Composite./* w w w . j a va2 s.c o m*/ * * @param parent * the container of the example */ public BrowserExample(Composite parent) { final Display display = parent.getDisplay(); FormLayout layout = new FormLayout(); parent.setLayout(layout); ToolBar toolbar = new ToolBar(parent, SWT.NONE); final ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH); itemBack.setText(getResourceString("Back")); final ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH); itemForward.setText(getResourceString("Forward")); final ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH); itemStop.setText(getResourceString("Stop")); final ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH); itemRefresh.setText(getResourceString("Refresh")); final ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH); itemGo.setText(getResourceString("Go")); location = new Text(parent, SWT.BORDER); images = new Image[] { new Image(display, "java2s.gif") }; final Canvas canvas = new Canvas(parent, SWT.NO_BACKGROUND); final Rectangle rect = images[0].getBounds(); canvas.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { Point pt = canvas.getSize(); e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y); } }); canvas.addListener(SWT.MouseDown, new Listener() { public void handleEvent(Event e) { browser.setUrl(getResourceString("Startup")); } }); display.asyncExec(new Runnable() { public void run() { if (canvas.isDisposed()) return; if (busy) { index++; if (index == images.length) index = 0; canvas.redraw(); } display.timerExec(150, this); } }); final Label status = new Label(parent, SWT.NONE); final ProgressBar progressBar = new ProgressBar(parent, SWT.NONE); FormData data = new FormData(); data.top = new FormAttachment(0, 5); toolbar.setLayoutData(data); data = new FormData(); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(canvas, 5, SWT.DEFAULT); data.bottom = new FormAttachment(status, -5, SWT.DEFAULT); try { browser = new Browser(parent, SWT.NONE); browser.setLayoutData(data); } catch (SWTError e) { /* Browser widget could not be instantiated */ Label label = new Label(parent, SWT.CENTER | SWT.WRAP); label.setText(getResourceString("BrowserNotCreated")); label.setLayoutData(data); } data = new FormData(); data.width = 24; data.height = 24; data.top = new FormAttachment(0, 5); data.right = new FormAttachment(100, -5); canvas.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(toolbar, 0, SWT.TOP); data.left = new FormAttachment(toolbar, 5, SWT.RIGHT); data.right = new FormAttachment(canvas, -5, SWT.DEFAULT); location.setLayoutData(data); data = new FormData(); data.left = new FormAttachment(0, 5); data.right = new FormAttachment(progressBar, 0, SWT.DEFAULT); data.bottom = new FormAttachment(100, -5); status.setLayoutData(data); data = new FormData(); data.right = new FormAttachment(100, -5); data.bottom = new FormAttachment(100, -5); progressBar.setLayoutData(data); if (browser != null) { itemBack.setEnabled(browser.isBackEnabled()); itemForward.setEnabled(browser.isForwardEnabled()); Listener listener = new Listener() { public void handleEvent(Event event) { ToolItem item = (ToolItem) event.widget; if (item == itemBack) browser.back(); else if (item == itemForward) browser.forward(); else if (item == itemStop) browser.stop(); else if (item == itemRefresh) browser.refresh(); else if (item == itemGo) browser.setUrl(location.getText()); } }; browser.addLocationListener(new LocationListener() { public void changed(LocationEvent event) { busy = true; if (event.top) location.setText(event.location); } public void changing(LocationEvent event) { } }); browser.addProgressListener(new ProgressListener() { public void changed(ProgressEvent event) { if (event.total == 0) return; int ratio = event.current * 100 / event.total; progressBar.setSelection(ratio); busy = event.current != event.total; if (!busy) { index = 0; canvas.redraw(); } } public void completed(ProgressEvent event) { itemBack.setEnabled(browser.isBackEnabled()); itemForward.setEnabled(browser.isForwardEnabled()); progressBar.setSelection(0); busy = false; index = 0; canvas.redraw(); } }); browser.addStatusTextListener(new StatusTextListener() { public void changed(StatusTextEvent event) { status.setText(event.text); } }); if (parent instanceof Shell) { final Shell shell = (Shell) parent; browser.addTitleListener(new TitleListener() { public void changed(TitleEvent event) { shell.setText(event.title + " - " + getResourceString("window.title")); } }); } itemBack.addListener(SWT.Selection, listener); itemForward.addListener(SWT.Selection, listener); itemStop.addListener(SWT.Selection, listener); itemRefresh.addListener(SWT.Selection, listener); itemGo.addListener(SWT.Selection, listener); location.addListener(SWT.DefaultSelection, new Listener() { public void handleEvent(Event e) { browser.setUrl(location.getText()); } }); initialize(display, browser); browser.setUrl(getResourceString("Startup")); } }
From source file:net.bioclipse.chart.ChartUtils.java
/** * Utility method for converting JFreeChart to an image * @param parent used for color correction * @param chart the chart to be made into an image * @param width image width/* w ww . ja v a2 s . c o m*/ * @param height image height * @return SWT Image of the chart */ public static Image createChartImage(Composite parent, JFreeChart chart, int width, int height) { // Color adjustment Color swtBackground = parent.getBackground(); java.awt.Color awtBackground = new java.awt.Color(swtBackground.getRed(), swtBackground.getGreen(), swtBackground.getRed()); chart.setBackgroundPaint(awtBackground); // Draw the chart in an AWT buffered image BufferedImage bufferedImage = chart.createBufferedImage(width, height, null); // Get the data buffer of the image DataBuffer buffer = bufferedImage.getRaster().getDataBuffer(); DataBufferInt intBuffer = (DataBufferInt) buffer; // Copy the data from the AWT buffer to a SWT buffer PaletteData paletteData = new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF); ImageData imageData = new ImageData(width, height, 32, paletteData); for (int bank = 0; bank < intBuffer.getNumBanks(); bank++) { int[] bankData = intBuffer.getData(bank); imageData.setPixels(0, bank, bankData.length, bankData, 0); } // Create an SWT image return new Image(parent.getDisplay(), imageData); }
From source file:org.eclipse.swt.examples.graphics.CurvesSWTTab.java
/** * Creates the widgets used to control the drawing. *//*from w ww . ja va 2 s.c o m*/ @Override public void createControlPanel(Composite parent) { if (cursor == null) { cursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND); } mouseMoveListener = e -> { if (hovering && mouseDown) { example.canvas.setCursor(cursor); } else if (isHovering(e)) { example.canvas.setCursor(cursor); hovering = true; } else { example.canvas.setCursor(null); hovering = false; } if (sLeftPtMoved) { sDiffX1 = sDiffX1 + e.x - (int) sXPos - sRect1.x; sDiffY1 = sDiffY1 + e.y - (int) sYPos - sRect1.y; sRect1.x = e.x - (int) sXPos; sRect1.y = e.y - (int) sYPos; } else if (sRightPtMoved) { sDiffX2 = sDiffX2 + e.x - (int) sXPos - sRect2.x; sDiffY2 = sDiffY2 + e.y - (int) sYPos - sRect2.y; sRect2.x = e.x - (int) sXPos; sRect2.y = e.y - (int) sYPos; } else if (wPt1Moved) { wDiffX1 = wDiffX1 + e.x - (int) wXPos - wRect1.x; wDiffY1 = wDiffY1 + e.y - (int) wYPos - wRect1.y; wRect1.x = e.x - (int) wXPos; wRect1.y = e.y - (int) wYPos; } else if (wPt2Moved) { wDiffX2 = wDiffX2 + e.x - (int) wXPos - wRect2.x; wDiffY2 = wDiffY2 + e.y - (int) wYPos - wRect2.y; wRect2.x = e.x - (int) wXPos; wRect2.y = e.y - (int) wYPos; } else if (tTopPt1Moved) { tTopDiffX1 = tTopDiffX1 + e.x - (int) topTXPos - tTopRect1.x; tTopDiffY1 = tTopDiffY1 + e.y - (int) topTYPos - tTopRect1.y; tTopRect1.x = e.x - (int) topTXPos; tTopRect1.y = e.y - (int) topTYPos; } else if (tTopPt2Moved) { tTopDiffX2 = tTopDiffX2 + e.x - (int) topTXPos - tTopRect2.x; tTopDiffY2 = tTopDiffY2 + e.y - (int) topTYPos - tTopRect2.y; tTopRect2.x = e.x - (int) topTXPos; tTopRect2.y = e.y - (int) topTYPos; } else if (tBotPt1Moved) { tBotDiffX1 = tBotDiffX1 + e.x - (int) botTXPos - tBottomRect1.x; tBotDiffY1 = tBotDiffY1 + e.y - (int) botTYPos - tBottomRect1.y; tBottomRect1.x = e.x - (int) botTXPos; tBottomRect1.y = e.y - (int) botTYPos; } else if (tBotPt2Moved) { tBotDiffX2 = tBotDiffX2 + e.x - (int) botTXPos - tBottomRect2.x; tBotDiffY2 = tBotDiffY2 + e.y - (int) botTYPos - tBottomRect2.y; tBottomRect2.x = e.x - (int) botTXPos; tBottomRect2.y = e.y - (int) botTYPos; } example.redraw(); }; mouseListener = new MouseListener() { @Override public void mouseDoubleClick(MouseEvent e) { } /** * Sent when a mouse button is pressed. * * @param e an event containing information about the mouse button press */ @Override public void mouseDown(MouseEvent e) { Rectangle r1 = new Rectangle(sRect1.x + (int) sXPos - 1, sRect1.y + (int) sYPos - 1, sRect1.width + 2, sRect1.height + 2); Rectangle r2 = new Rectangle(sRect2.x + (int) sXPos - 1, sRect2.y + (int) sYPos - 1, sRect2.width + 2, sRect2.height + 2); Rectangle w1 = new Rectangle(wRect1.x + (int) wXPos - 1, wRect1.y + (int) wYPos - 1, wRect1.width + 2, wRect1.height + 2); Rectangle w2 = new Rectangle(wRect2.x + (int) wXPos - 1, wRect2.y + (int) wYPos - 1, wRect2.width + 2, wRect2.height + 2); Rectangle tTop1 = new Rectangle(tTopRect1.x + (int) topTXPos - 1, tTopRect1.y + (int) topTYPos - 1, tTopRect1.width + 2, tTopRect1.height + 2); Rectangle tTop2 = new Rectangle(tTopRect2.x + (int) topTXPos - 1, tTopRect2.y + (int) topTYPos - 1, tTopRect2.width + 2, tTopRect2.height + 2); Rectangle tBot1 = new Rectangle(tBottomRect1.x + (int) botTXPos - 1, tBottomRect1.y + (int) botTYPos - 1, tBottomRect1.width + 2, tBottomRect1.height + 2); Rectangle tBot2 = new Rectangle(tBottomRect2.x + (int) botTXPos - 1, tBottomRect2.y + (int) botTYPos - 1, tBottomRect2.width + 2, tBottomRect2.height + 2); if (r1.contains(e.x, e.y)) { sLeftPtMoved = true; mouseDown = true; } else if (r2.contains(e.x, e.y)) { sRightPtMoved = true; mouseDown = true; } else if (w1.contains(e.x, e.y)) { wPt1Moved = true; mouseDown = true; } else if (w2.contains(e.x, e.y)) { wPt2Moved = true; mouseDown = true; } else if (tTop1.contains(e.x, e.y)) { tTopPt1Moved = true; mouseDown = true; } else if (tTop2.contains(e.x, e.y)) { tTopPt2Moved = true; mouseDown = true; } else if (tBot1.contains(e.x, e.y)) { tBotPt1Moved = true; mouseDown = true; } else if (tBot2.contains(e.x, e.y)) { tBotPt2Moved = true; mouseDown = true; } } /** * Sent when a mouse button is released. * * @param e an event containing information about the mouse button release */ @Override public void mouseUp(MouseEvent e) { mouseDown = false; if (isHovering(e)) { example.canvas.setCursor(cursor); } else { example.canvas.setCursor(null); } if (sLeftPtMoved) sLeftPtMoved = false; if (sRightPtMoved) sRightPtMoved = false; if (wPt1Moved) wPt1Moved = false; if (wPt2Moved) wPt2Moved = false; if (tTopPt1Moved) tTopPt1Moved = false; if (tTopPt2Moved) tTopPt2Moved = false; if (tBotPt1Moved) tBotPt1Moved = false; if (tBotPt2Moved) tBotPt2Moved = false; example.redraw(); } }; example.canvas.addMouseMoveListener(mouseMoveListener); example.canvas.addMouseListener(mouseListener); }
From source file:org.eclipse.swt.examples.graphics.GraphicsExample.java
void createToolBar(final Composite parent) { final Display display = parent.getDisplay(); toolBar = new ToolBar(parent, SWT.FLAT); ToolItem back = new ToolItem(toolBar, SWT.PUSH); back.setText(getResourceString("Back")); //$NON-NLS-1$ back.setImage(loadImage(display, "back.gif")); //$NON-NLS-1$ back.addListener(SWT.Selection, event -> { int index = tabs_in_order.indexOf(tab) - 1; if (index < 0) index = tabs_in_order.size() - 1; setTab(tabs_in_order.get(index)); });/*from w w w.j av a 2 s.co m*/ ToolItem next = new ToolItem(toolBar, SWT.PUSH); next.setText(getResourceString("Next")); //$NON-NLS-1$ next.setImage(loadImage(display, "next.gif")); //$NON-NLS-1$ next.addListener(SWT.Selection, event -> { int index = (tabs_in_order.indexOf(tab) + 1) % tabs_in_order.size(); setTab(tabs_in_order.get(index)); }); ColorMenu colorMenu = new ColorMenu(); // setup items to be contained in the background menu colorMenu.setColorItems(true); colorMenu.setPatternItems(checkAdvancedGraphics()); colorMenu.setGradientItems(checkAdvancedGraphics()); // create the background menu backMenu = colorMenu.createMenu(parent, gb -> { background = gb; backItem.setImage(gb.getThumbNail()); if (canvas != null) canvas.redraw(); }); // initialize the background to the first item in the menu background = (GraphicsBackground) backMenu.getItem(0).getData(); // background tool item backItem = new ToolItem(toolBar, SWT.PUSH); backItem.setText(getResourceString("Background")); //$NON-NLS-1$ backItem.setImage(background.getThumbNail()); backItem.addListener(SWT.Selection, event -> { if (event.widget == backItem) { final ToolItem toolItem = (ToolItem) event.widget; final ToolBar toolBar = toolItem.getParent(); Rectangle toolItemBounds = toolItem.getBounds(); Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); backMenu.setLocation(point.x, point.y + toolItemBounds.height); backMenu.setVisible(true); } }); // double buffer tool item dbItem = new ToolItem(toolBar, SWT.CHECK); dbItem.setText(getResourceString("DoubleBuffer")); //$NON-NLS-1$ dbItem.setImage(loadImage(display, "db.gif")); //$NON-NLS-1$ dbItem.addListener(SWT.Selection, event -> setDoubleBuffered(dbItem.getSelection())); }
From source file:org.eclipse.swt.examples.browserexample.BrowserExample.java
public BrowserExample(Composite parent, boolean top) { this.parent = parent; try {/*from ww w. j a v a 2 s . c o 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")); 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(); }); } }