private void runSession() { while (true) { shell = arseGUI.open(display); initializeARSE(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (gameMasterMode) { gameMasterSession = new GameMasterSession(display); gameMasterSession.open(); gameMasterMode = false; } else if (playerMode) { playerLoginGUI = new PlayerLoginGUI(); playerSession = new PlayerSession(display); shell = playerLoginGUI.open(display); initializePlayerLoginGUI(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (playerSession.loggedIn()) { playerSession.open(); } playerMode = false; } else break; } }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); DateTime calendar = new DateTime(shell, SWT.CALENDAR); calendar.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println("calendar date changed"); } }); DateTime time = new DateTime(shell, SWT.TIME); time.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println("time changed"); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
private void createDialog(Shell applicationShell) { if (dialog == null || dialog.isDisposed()) { dialog = new Shell(applicationShell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); if (applicationShell.getImage() != null) { dialog.setImage(applicationShell.getImage()); } dialog.addListener( SWT.Close, new Listener() { public void handleEvent(Event event) { hideCustomPanelChildren(); } }); dialog.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent arg0) { disposeImages(); } }); if (fileDialogMode != VFS_DIALOG_SAVEAS) { dialog.setText(Messages.getString("VfsFileChooserDialog.openFile")); // $NON-NLS-1$ } else { dialog.setText(Messages.getString("VfsFileChooserDialog.saveAs")); // $NON-NLS-1$ } dialog.setLayout(new GridLayout()); dialog.setBackgroundMode(SWT.INHERIT_FORCE); dialog.setBackground(dialog.getDisplay().getSystemColor(SWT.COLOR_WHITE)); createCustomUIPanel(dialog); } }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Text text = new Text(shell, SWT.MULTI | SWT.BORDER); String modifier = SWT.MOD1 == SWT.CTRL ? "Ctrl" : "Command"; text.setText("Hit " + modifier + "+Return\nto see\nthe default button\nrun"); text.addTraverseListener( e -> { switch (e.detail) { case SWT.TRAVERSE_RETURN: if ((e.stateMask & SWT.MOD1) != 0) e.doit = true; } }); Button button = new Button(shell, SWT.PUSH); button.pack(); button.setText("OK"); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println("OK selected"); } }); shell.setDefaultButton(button); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
public static void runInUI(@Nullable Shell shell, @NotNull Runnable runnable) { final Display display = shell == null || shell.isDisposed() ? Display.getDefault() : shell.getDisplay(); if (display.getThread() != Thread.currentThread()) { display.syncExec(runnable); } else { runnable.run(); } }
public static void main(String[] args) { Display display = new Display(); AddressBook application = new AddressBook(); Shell shell = application.open(display); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/** Initialize all ui elements, and then display the window */ public void Initialize() { initMenu(); initToolbar(); initCanvas(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
public static void main(String[] args) { Display display = new Display(); MessageWindow application = new MessageWindow(); Shell shell = application.open(display); if (args.length != 0) { application.openAddressBook(args[0]); } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
public static void main(String[] args) { Display display = Display.getDefault(); Shell shell = new Shell(display); @SuppressWarnings("unused") MainWindow inst = new MainWindow(shell, SWT.NULL); shell.setLayout(new FillLayout()); shell.setImage(SWTResourceManager.getImage("images/16x16.png")); shell.setText("Change This Title"); shell.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif")); shell.layout(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
/** * Opens the dialog and returns the input * * @return String */ public String open() { // Create the dialog window Shell shell = new Shell(getParent(), getStyle()); shell.setText(getText()); shell.setImage(UIUtils.getImageRegistry().get("sfdc_icon")); // $NON-NLS-1$ createContents(shell); shell.pack(); shell.open(); Display display = getParent().getDisplay(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } // Return the entered value, or null return input; }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); final Text text = new Text(shell, SWT.SEARCH | SWT.ICON_CANCEL); Image image = null; if ((text.getStyle() & SWT.ICON_CANCEL) == 0) { image = display.getSystemImage(SWT.ICON_ERROR); ToolBar toolBar = new ToolBar(shell, SWT.FLAT); ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setImage(image); item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { text.setText(""); System.out.println("Search cancelled"); } }); } text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.setText("Search text"); text.addSelectionListener( new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { if (e.detail == SWT.CANCEL) { System.out.println("Search cancelled"); } else { System.out.println("Searching for: " + text.getText() + "..."); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
public boolean isDisposed() { return mapShell.isDisposed(); }
public FileObject open( Shell applicationShell, String[] schemeRestrictions, String initialScheme, boolean showFileScheme, String fileName, String[] fileFilters, String[] fileFilterNames, boolean returnUserAuthenticatedFile, int fileDialogMode, boolean showLocation, boolean showCustomUI) { this.fileDialogMode = fileDialogMode; this.fileFilters = fileFilters; this.fileFilterNames = fileFilterNames; this.applicationShell = applicationShell; this.showFileScheme = showFileScheme; this.initialScheme = initialScheme; this.schemeRestrictions = schemeRestrictions; this.showLocation = showLocation; this.showCustomUI = showCustomUI; FileObject tmpInitialFile = initialFile; if (defaultInitialFile != null && rootFile == null) { try { rootFile = defaultInitialFile.getFileSystem().getRoot(); initialFile = defaultInitialFile; } catch (FileSystemException ignored) { // well we tried } } createDialog(applicationShell); if (!showLocation) { comboPanel.setParent(fakeShell); } else { comboPanel.setParent(customUIPanel); } if (!showCustomUI) { customUIPanel.setParent(fakeShell); } else { customUIPanel.setParent(dialog); } // create our file chooser tool bar, contains parent folder combo and various controls createToolbarPanel(dialog); // create our vfs browser component createVfsBrowser(dialog); populateCustomUIPanel(dialog); if (fileDialogMode == VFS_DIALOG_SAVEAS) { createFileNamePanel(dialog, fileName); } else { // create file filter panel createFileFilterPanel(dialog); } // create our ok/cancel buttons createButtonPanel(dialog); initialFile = tmpInitialFile; // set the initial file selection try { if (initialFile != null || rootFile != null) { vfsBrowser.selectTreeItemByFileObject(initialFile != null ? initialFile : rootFile, true); updateParentFileCombo(initialFile != null ? initialFile : rootFile); setSelectedFile(initialFile != null ? initialFile : rootFile); openFileCombo.setText( initialFile != null ? initialFile.getName().getURI() : rootFile.getName().getURI()); } } catch (FileSystemException e) { MessageBox box = new MessageBox(dialog.getShell()); box.setText(Messages.getString("VfsFileChooserDialog.error")); // $NON-NLS-1$ box.setMessage(e.getMessage()); box.open(); } // set the size and show the dialog int height = 550; int width = 800; dialog.setSize(width, height); Rectangle bounds = dialog.getDisplay().getPrimaryMonitor().getClientArea(); int x = (bounds.width - width) / 2; int y = (bounds.height - height) / 2; dialog.setLocation(x, y); dialog.open(); if (rootFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) { if (!rootFile.getFileSystem().hasCapability(Capability.WRITE_CONTENT)) { MessageBox messageDialog = new MessageBox(dialog.getShell(), SWT.OK); messageDialog.setText(Messages.getString("VfsFileChooserDialog.warning")); // $NON-NLS-1$ messageDialog.setMessage( Messages.getString("VfsFileChooserDialog.noWriteSupport")); // $NON-NLS-1$ messageDialog.open(); } } vfsBrowser.fileSystemTree.forceFocus(); while (!dialog.isDisposed()) { if (!dialog.getDisplay().readAndDispatch()) dialog.getDisplay().sleep(); } // we just woke up, we are probably disposed already.. if (!dialog.isDisposed()) { hideCustomPanelChildren(); dialog.dispose(); } if (okPressed) { FileObject returnFile = vfsBrowser.getSelectedFileObject(); if (returnFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) { try { if (returnFile.getType().equals(FileType.FILE)) { returnFile = returnFile.getParent(); } returnFile = returnFile.resolveFile(enteredFileName); } catch (FileSystemException e) { e.printStackTrace(); } } // put user/pass on the filename so it comes out in the getUri call. if (!returnUserAuthenticatedFile) { // make sure to put the user/pass on the url if it's not there if (returnFile != null && returnFile.getName() instanceof URLFileName) { URLFileName urlFileName = (URLFileName) returnFile.getName(); if (urlFileName.getUserName() == null || urlFileName.getPassword() == null) { // set it String user = ""; String pass = ""; UserAuthenticator userAuthenticator = DefaultFileSystemConfigBuilder.getInstance() .getUserAuthenticator(returnFile.getFileSystem().getFileSystemOptions()); if (userAuthenticator != null) { UserAuthenticationData data = userAuthenticator.requestAuthentication(AUTHENTICATOR_TYPES); user = String.valueOf(data.getData(UserAuthenticationData.USERNAME)); pass = String.valueOf(data.getData(UserAuthenticationData.PASSWORD)); try { user = URLEncoder.encode(user, "UTF-8"); pass = URLEncoder.encode(pass, "UTF-8"); } catch (UnsupportedEncodingException e) { // ignore, just use the un encoded values } } // build up the url with user/pass on it int port = urlFileName.getPort(); String portString = (port < 1) ? "" : (":" + port); String urlWithUserPass = urlFileName.getScheme() + "://" + user + ":" + pass + "@" + urlFileName.getHostName() + portString + urlFileName.getPath(); try { returnFile = currentPanel.resolveFile(urlWithUserPass); } catch (FileSystemException e) { // couldn't resolve with user/pass on url??? interesting e.printStackTrace(); } } } } return returnFile; } else { return null; } }
public static void main(String[] args) { final ImageFileNameProvider filenameProvider = new ImageFileNameProvider() { @Override public String getImagePath(int zoom) { switch (zoom) { case 150: return IMAGE_PATH_150; case 200: return IMAGE_PATH_200; default: return IMAGE_PATH_100; } } }; final ImageDataProvider imageDataProvider = new ImageDataProvider() { @Override public ImageData getImageData(int zoom) { switch (zoom) { case 150: return new ImageData(IMAGE_PATH_150); case 200: return new ImageData(IMAGE_PATH_200); default: return new ImageData(IMAGE_PATH_100); } } }; final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); new Label(shell, SWT.NONE).setText(IMAGE_200 + ":"); new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_200)); new Label(shell, SWT.NONE).setText(IMAGE_150 + ":"); new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_150)); new Label(shell, SWT.NONE).setText(IMAGE_100 + ":"); new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_100)); new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL) .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); new Label(shell, SWT.NONE).setText("ImageFileNameProvider:"); new Label(shell, SWT.NONE).setImage(new Image(display, filenameProvider)); new Label(shell, SWT.NONE).setText("ImageDataProvider:"); new Label(shell, SWT.NONE).setImage(new Image(display, imageDataProvider)); new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL) .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); new Label(shell, SWT.NONE).setText("Canvas\n(PaintListener)"); final Point size = new Point(550, 35); final Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addPaintListener( new PaintListener() { @Override public void paintControl(PaintEvent e) { Point size = canvas.getSize(); paintImage(e.gc, size); } }); canvas.setLayoutData(new GridData(size.x, size.y)); new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL) .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); new Label(shell, SWT.NONE).setText("Painted image\n (default resolution)"); Image image = new Image(display, size.x, size.y); GC gc = new GC(image); try { paintImage(gc, size); } finally { gc.dispose(); } new Label(shell, SWT.NONE).setImage(image); new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL) .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); new Label(shell, SWT.NONE).setText("Painted image\n(multi-res, unzoomed paint)"); new Label(shell, SWT.NONE) .setImage( new Image( display, new ImageDataProvider() { @Override public ImageData getImageData(int zoom) { Image temp = new Image(display, size.x * zoom / 100, size.y * zoom / 100); GC gc = new GC(temp); try { paintImage(gc, size); return temp.getImageData(); } finally { gc.dispose(); temp.dispose(); } } })); new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL) .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); new Label(shell, SWT.NONE).setText("Painted image\n(multi-res, zoomed paint)"); new Label(shell, SWT.NONE) .setImage( new Image( display, new ImageDataProvider() { @Override public ImageData getImageData(int zoom) { Image temp = new Image(display, size.x * zoom / 100, size.y * zoom / 100); GC gc = new GC(temp); try { paintImage2( gc, new Point(size.x * zoom / 100, size.y * zoom / 100), zoom / 100); return temp.getImageData(); } finally { gc.dispose(); temp.dispose(); } } })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/** * Constructor to create an editor to update/create an ontology entry * * @param display - points back to the display * @param oureditOntEntry - the entry being edited * @param ontParent - the edited item's parent in the hierarchy * @param newItem - true if this is a new item */ public EditOntEntry( Display display, OntEntry oureditOntEntry, OntEntry ontParent, boolean newItem) { super(); shell = new Shell(display, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL); shell.setText("OntEntry Information"); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; gridLayout.marginHeight = 5; gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); ourOntEntry = oureditOntEntry; ourParent = ontParent; if (newItem) { ourOntEntry.setName(""); ourOntEntry.setImportance(Importance.MODERATE); } new Label(shell, SWT.NONE).setText("Name:"); nameField = new Text(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL); nameField.setText(ourOntEntry.getName()); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); DisplayUtilities.setTextDimensions(nameField, gridData, 75); gridData.horizontalSpan = 2; nameField.setLayoutData(gridData); new Label(shell, SWT.NONE).setText("Description:"); descArea = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); descArea.setText(ourOntEntry.getDescription()); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); DisplayUtilities.setTextDimensions(descArea, gridData, 75, 5); gridData.horizontalSpan = 2; gridData.heightHint = descArea.getLineHeight() * 3; descArea.setLayoutData(gridData); new Label(shell, SWT.NONE).setText("Importance:"); importanceBox = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); Enumeration impEnum = Importance.elements(); int l = 0; Importance itype; while (impEnum.hasMoreElements()) { itype = (Importance) impEnum.nextElement(); importanceBox.add(itype.toString()); if (itype.toString().compareTo(ourOntEntry.getImportance().toString()) == 0) { importanceBox.select(l); } l++; } // Error checking: if no such selection is valid, set it to select index 0 if (importanceBox.getSelectionIndex() == -1) { importanceBox.select(0); } importanceBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); new Label(shell, SWT.NONE).setText(" "); new Label(shell, SWT.NONE).setText(" "); addButton = new Button(shell, SWT.PUSH); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); addButton.setLayoutData(gridData); if (newItem) { addButton.setText("Add"); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = false; if (!nameField.getText().trim().equals("")) { ConsistencyChecker checker = new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries"); if (ourOntEntry.getName() == nameField.getText() || checker.check()) { ourParent.addChild(ourOntEntry); ourOntEntry.setLevel(ourParent.getLevel() + 1); ourOntEntry.setName(nameField.getText()); ourOntEntry.setDescription(descArea.getText()); ourOntEntry.setImportance( Importance.fromString( importanceBox.getItem(importanceBox.getSelectionIndex()))); // comment before this made no sense... ourOntEntry.setID(ourOntEntry.toDatabase(ourParent.getID())); System.out.println("Name of added item = " + ourOntEntry.getName()); shell.close(); shell.dispose(); } } else { MessageBox mbox = new MessageBox(shell, SWT.ICON_ERROR); mbox.setMessage("Need to provide the OntEntry name"); mbox.open(); } } }); } else { addButton.setText("Save"); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = false; ConsistencyChecker checker = new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries"); if (ourOntEntry.getName() == nameField.getText() || checker.check()) { ourOntEntry.setName(nameField.getText()); ourOntEntry.setDescription(descArea.getText()); ourOntEntry.setImportance( Importance.fromString( importanceBox.getItem(importanceBox.getSelectionIndex()))); // since this is a save, not an add, the type and parent are ignored ourOntEntry.setID(ourOntEntry.toDatabase(0)); // RationaleDB db = RationaleDB.getHandle(); // db.addOntEntry(ourOntEntry); shell.close(); shell.dispose(); } } }); } cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Cancel"); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); cancelButton.setLayoutData(gridData); cancelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = true; shell.close(); shell.dispose(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }