Commit | Line | Data |
---|---|---|
739b9fec AM |
1 | package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swtjfx.examples; |
2 | ||
3 | import org.eclipse.jdt.annotation.NonNullByDefault; | |
4 | import org.eclipse.swt.SWT; | |
5 | import org.eclipse.swt.events.SelectionAdapter; | |
6 | import org.eclipse.swt.events.SelectionEvent; | |
7 | import org.eclipse.swt.graphics.Point; | |
8 | import org.eclipse.swt.layout.FillLayout; | |
9 | import org.eclipse.swt.widgets.Display; | |
10 | import org.eclipse.swt.widgets.Menu; | |
11 | import org.eclipse.swt.widgets.MenuItem; | |
12 | import org.eclipse.swt.widgets.Shell; | |
13 | import org.eclipse.swt.widgets.ToolBar; | |
14 | import org.eclipse.swt.widgets.ToolItem; | |
15 | ||
16 | @NonNullByDefault({}) | |
17 | public class SwtToobar2 { | |
18 | ||
19 | private Shell shell; | |
20 | ||
21 | public SwtToobar2() { | |
22 | Display display = new Display(); | |
23 | shell = new Shell(display, SWT.SHELL_TRIM); | |
24 | shell.setLayout(new FillLayout(SWT.VERTICAL)); | |
25 | shell.setSize(50, 100); | |
26 | ||
27 | ToolBar toolbar = new ToolBar(shell, SWT.FLAT); | |
28 | ToolItem itemDrop = new ToolItem(toolbar, SWT.DROP_DOWN); | |
29 | itemDrop.setText("drop menu"); | |
30 | ||
31 | itemDrop.addSelectionListener(new SelectionAdapter() { | |
32 | ||
33 | Menu dropMenu = null; | |
34 | ||
35 | @Override | |
36 | public void widgetSelected(SelectionEvent e) { | |
37 | if (dropMenu == null) { | |
38 | dropMenu = new Menu(shell, SWT.POP_UP); | |
39 | shell.setMenu(dropMenu); | |
40 | MenuItem itemCheck = new MenuItem(dropMenu, SWT.CHECK); | |
41 | itemCheck.setText("checkbox"); | |
42 | MenuItem itemRadio = new MenuItem(dropMenu, SWT.RADIO); | |
43 | itemRadio.setText("radio1"); | |
44 | MenuItem itemRadio2 = new MenuItem(dropMenu, SWT.RADIO); | |
45 | itemRadio2.setText("radio2"); | |
46 | } | |
47 | ||
48 | if (e.detail == SWT.ARROW) { | |
49 | // Position the menu below and vertically aligned with the | |
50 | // the drop down tool button. | |
51 | final ToolItem toolItem = (ToolItem) e.widget; | |
52 | final ToolBar toolBar = toolItem.getParent(); | |
53 | ||
54 | Point point = toolBar.toDisplay(new Point(e.x, e.y)); | |
55 | dropMenu.setLocation(point.x, point.y); | |
56 | dropMenu.setVisible(true); | |
57 | } | |
58 | ||
59 | } | |
60 | ||
61 | }); | |
62 | ||
63 | shell.open(); | |
64 | ||
65 | while (!shell.isDisposed()) { | |
66 | if (!display.readAndDispatch()) { | |
67 | display.sleep(); | |
68 | } | |
69 | } | |
70 | ||
71 | display.dispose(); | |
72 | } | |
73 | ||
74 | public static void main(String[] args) { | |
75 | new SwtToobar2(); | |
76 | } | |
77 | ||
78 | } |