List of usage examples for org.eclipse.swt.widgets Display getCurrent
public static Display getCurrent()
From source file:org.eclipse.swt.snippets.Snippet353.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 353"); GestureListener gl = ge -> {//from w w w.ja v a 2s .c o m if (ge.detail == SWT.GESTURE_BEGIN) { currentRotation = rotation; currentMagnification = magnification; } if (ge.detail == SWT.GESTURE_ROTATE) { rotation = currentRotation - ge.rotation; shell.redraw(); } if (ge.detail == SWT.GESTURE_MAGNIFY) { magnification = (float) (currentMagnification * ge.magnification); shell.redraw(); } if (ge.detail == SWT.GESTURE_SWIPE) { // xDirection and yDirection indicate direction for GESTURE_SWIPE. // For this example, just move in that direction to demonstrate it's working. origin.x += ge.xDirection * 50; origin.y += ge.yDirection * 50; shell.redraw(); } if (ge.detail == SWT.GESTURE_PAN) { origin.x += ge.xDirection; origin.y += ge.yDirection; shell.redraw(); } if (ge.detail == SWT.GESTURE_END) { } }; PaintListener pl = e -> { Transform t = new Transform(Display.getCurrent()); t.translate(origin.x, origin.y); t.translate(size.x / 2, size.y / 2); t.rotate((float) rotation); t.translate(-size.x / 2, -size.y / 2); t.translate(-origin.x, -origin.y); e.gc.setAntialias(SWT.ON); e.gc.setTransform(t); // Because of bug 253670, drawRectangle is incorrect when the rotation is near 45, 135, 225 or 315 degrees. // Uncomment this next line and adjust the bitfield for your platform. See GC#DRAW_OFFSET. //e.gc.getGCData().state |= 1 << 9; e.gc.drawRectangle(origin.x, origin.y, (int) (size.x * magnification), (int) (size.y * magnification)); t.dispose(); }; shell.addPaintListener(pl); shell.addGestureListener(gl); shell.setSize(400, 400); size = new Point(50, 50); origin = new Point((shell.getSize().x - size.x) / 2, (shell.getSize().y - size.y) / 2); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:AddressBookDemo.java
public static void main(String[] args) { AddressBookDemo book = new AddressBookDemo(); book.setBlockOnOpen(true);/*from w ww . j a v a 2 s. co m*/ book.open(); Display.getCurrent().dispose(); }
From source file:JFaceExplorer.java
public static void main(String[] args) { JFaceExplorer w = new JFaceExplorer(); w.setBlockOnOpen(true);/* w w w. j a va 2s . c om*/ w.open(); Display.getCurrent().dispose(); }
From source file:TemperatureConverterJFace.java
public static void main(String[] args) { TemperatureConverterJFace converter = new TemperatureConverterJFace(); converter.setBlockOnOpen(true);//from www . j a v a 2 s. c o m converter.open(); Display.getCurrent().dispose(); }
From source file:WordOLE.java
public static void main(String[] args) { WordOLE wordOLE = new WordOLE(null); wordOLE.setBlockOnOpen(true);// w w w .j av a 2s .co m wordOLE.open(); Display.getCurrent().dispose(); }
From source file:ClassFigure.java
public static void main(String[] args) { ClassAnalyzer window = new ClassAnalyzer(null); window.setBlockOnOpen(true);/*from w w w. j a v a 2 s. co m*/ window.open(); Display.getCurrent().dispose(); }
From source file:org.eclipse.swt.snippets.Snippet348.java
static void createMenuBar(Shell s) { Menu bar = Display.getCurrent().getMenuBar(); boolean hasAppMenuBar = (bar != null); if (bar == null) { bar = new Menu(s, SWT.BAR); }/*from w w w .j a v a 2 s. c o m*/ // Populate the menu bar once if this is a screen menu bar. // Otherwise, we need to make a new menu bar for each shell. if (!createdScreenBar || !hasAppMenuBar) { MenuItem item = new MenuItem(bar, SWT.CASCADE); item.setText("File"); Menu menu = new Menu(item); item.setMenu(menu); menu.addMenuListener(new MenuListener() { @Override public void menuHidden(MenuEvent e) { System.out.println("Menu closed: " + e); } @Override public void menuShown(MenuEvent e) { System.out.println("Menu open: " + e); } }); MenuItem newWindow = new MenuItem(menu, SWT.PUSH); newWindow.setText("New Window"); newWindow.setAccelerator(SWT.MOD1 | 'N'); newWindow.addListener(SWT.Selection, event -> { Shell s1 = createShell(); s1.open(); }); if (!SWT.getPlatform().equals("cocoa")) { MenuItem exit = new MenuItem(menu, SWT.PUSH); exit.setText("Exit"); exit.addListener(SWT.Selection, event -> { Display d = Display.getCurrent(); Shell[] shells = d.getShells(); for (Shell shell : shells) { shell.close(); } }); } if (!hasAppMenuBar) s.setMenuBar(bar); createdScreenBar = true; } }
From source file:ApplicationWindowJFrace.java
public MainWindow() { super(null);//from www . j ava 2 s . c om // Don't return from open() until window closes setBlockOnOpen(true); // Open the main window open(); // Dispose the display Display.getCurrent().dispose(); }
From source file:MainClass.java
public void run() { setBlockOnOpen(true); open(); Display.getCurrent().dispose(); }
From source file:ExampleGUI.java
public static void main(String[] args) { // create a shell... Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("KTable examples"); // put a tab folder in it... TabFolder tabFolder = new TabFolder(shell, SWT.NONE); // Item 1: a Text Table TabItem item1 = new TabItem(tabFolder, SWT.NONE); item1.setText("Text Table"); Composite comp1 = new Composite(tabFolder, SWT.NONE); item1.setControl(comp1);//from w w w .ja va 2 s .co m comp1.setLayout(new FillLayout()); // put a table in tabItem1... KTable table = new KTable(comp1, SWT.V_SCROLL | SWT.H_SCROLL); // table.setRowSelectionMode(true); table.setMultiSelectionMode(true); table.setModel(new KTableModelExample()); table.addCellSelectionListener(new KTableCellSelectionListener() { public void cellSelected(int col, int row, int statemask) { System.out.println("Cell [" + col + ";" + row + "] selected."); } public void fixedCellSelected(int col, int row, int statemask) { System.out.println("Header [" + col + ";" + row + "] selected."); } }); table.addCellResizeListener(new KTableCellResizeListener() { public void columnResized(int col, int newWidth) { System.out.println("Column " + col + " resized to " + newWidth); } public void rowResized(int newHeight) { System.out.println("Rows resized to " + newHeight); } }); // Item 2: a Color Palette TabItem item2 = new TabItem(tabFolder, SWT.NONE); item2.setText("Color Palette"); Composite comp2 = new Composite(tabFolder, SWT.NONE); item2.setControl(comp2); comp2.setLayout(new FillLayout()); // put a table in tabItem2... final KTable table2 = new KTable(comp2, SWT.NONE); table2.setModel(new PaletteExampleModel()); table2.setRowSelectionMode(false); table2.setMultiSelectionMode(false); final Label label = new Label(comp2, SWT.NONE); label.setText("Click a cell..."); table2.addCellSelectionListener(new KTableCellSelectionAdapter() { public void cellSelected(int col, int row, int statemask) { RGB rgb = (RGB) table2.getModel().getContentAt(col, row); label.setText("R: " + rgb.red + "\nG: " + rgb.green + "\nB: " + rgb.blue); } }); // Item 3: Town table TabItem item3 = new TabItem(tabFolder, SWT.NONE); item3.setText("Towns"); Composite comp3 = new Composite(tabFolder, SWT.NONE); item3.setControl(comp3); comp3.setLayout(new FillLayout()); // put a table in tabItem3... final KTable table3 = new KTable(comp3, SWT.FLAT | SWT.H_SCROLL); table3.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); table3.setModel(new TownExampleModel()); table3.setRowSelectionMode(true); table3.setMultiSelectionMode(false); // display the shell... shell.setSize(600, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }