[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / provisional / tmf / ui / views / timegraph2 / swtjfx / examples / TestSwtToolbar.java
1 package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swtjfx.examples;
2
3 /*******************************************************************************
4 * Copyright (c) 2000, 2016 IBM Corporation and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors:
11 * IBM Corporation - initial API and implementation
12 *******************************************************************************/
13
14 /*
15 * ToolBar example snippet: place a drop down menu in a tool bar
16 *
17 * For a list of all SWT example snippets see
18 * http://www.eclipse.org/swt/snippets/
19 */
20 import org.eclipse.swt.*;
21 import org.eclipse.swt.graphics.*;
22 import org.eclipse.swt.widgets.*;
23
24 public class TestSwtToolbar {
25
26 public static void main(String[] args) {
27 final Display display = new Display();
28 final Shell shell = new Shell(display);
29
30 final ToolBar toolBar = new ToolBar(shell, SWT.NONE);
31 Rectangle clientArea = shell.getClientArea();
32 toolBar.setLocation(clientArea.x, clientArea.y);
33
34 final Menu menu = new Menu(shell, SWT.POP_UP);
35 for (int i = 0; i < 8; i++) {
36 MenuItem item = new MenuItem(menu, SWT.PUSH);
37 item.setText("Item " + i);
38 }
39
40 final ToolItem item = new ToolItem(toolBar, SWT.DROP_DOWN);
41 item.addListener(SWT.Selection, event -> {
42 if (event.detail == SWT.ARROW) {
43 Rectangle rect = item.getBounds();
44 Point pt = new Point(rect.x, rect.y + rect.height);
45 pt = toolBar.toDisplay(pt);
46 menu.setLocation(pt.x, pt.y);
47 menu.setVisible(true);
48 }
49 });
50
51 toolBar.pack();
52 shell.pack();
53 shell.open();
54 while (!shell.isDisposed()) {
55 if (!display.readAndDispatch()) {
56 display.sleep();
57 }
58 }
59 menu.dispose();
60 display.dispose();
61 }
62 }
This page took 0.032279 seconds and 5 git commands to generate.