private boolean showDialog() { shell.open(); while (!shell.isDisposed()) { if (!shell.getDisplay().readAndDispatch()) shell.getDisplay().sleep(); } return result; }
private void doEventLoop() { Shell splash = getSplash(); while (fAuthenticated == false) { if (splash.getDisplay().readAndDispatch() == false) { splash.getDisplay().sleep(); } } for (Control control : splash.getChildren()) { control.dispose(); } String progressRectString = null; String messageRectString = null; String foregroundColorString = null; IProduct product = Platform.getProduct(); if (product != null) { progressRectString = product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT); messageRectString = product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT); foregroundColorString = product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR); } Rectangle progressRect = StringConverter.asRectangle(progressRectString, new Rectangle(5, 275, 445, 15)); setProgressRect(progressRect); Rectangle messageRect = StringConverter.asRectangle(messageRectString, new Rectangle(0, 0, 0, 0)); // new Rectangle(7, 252, 445, 20)); setMessageRect(messageRect); getContent(); }
public Image getImage(Object element) { if (element instanceof Language) { Language lang = (Language) element; String code = lang.getCode(); String imagePath = lang.getImagePath(); if (imagePath != null && !imagePath.equals("")) { imagePath = bundlePath + imagePath; Image image = new Image(shell.getDisplay(), imagePath); if (image != null) { ImageData data = image.getImageData().scaledTo(16, 12); image = new Image(shell.getDisplay(), data); // 销毁原来的图片 Image im = imageCache.remove(code); if (im != null && !im.isDisposed()) { im.dispose(); } // 添加新的图片 imageCache.put(code, image); return image; } } } return null; }
private void doEventLoop() { Shell splash = getSplash(); while (fAuthenticated == false) { if (splash.getDisplay().readAndDispatch() == false) { splash.getDisplay().sleep(); } } }
private void formatHostName(int start, int end) { StyleRange style = new StyleRange(); style.start = start; style.length = end - start; style.font = new Font(sShell.getDisplay(), "Courier New", 9, SWT.BOLD); style.foreground = sShell.getDisplay().getSystemColor(SWT.COLOR_BLUE); activeHostsFileStyledText.setStyleRange(style); }
private void createLoadingBar() { new ProgressMonitorDialog(parent); Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); shell.setText("Report Loading"); shell.addDisposeListener( new org.eclipse.swt.events.DisposeListener() { @Override public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) { if (thread.isAlive()) { thread.interrupt(); reportFinished = true; } } }); Label label = new Label(shell, SWT.NONE); label.setSize(new Point(260, 20)); label.setLocation(20, 30); label.setText("Please wait while the report loads."); label.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8)); label.setAlignment(SWT.CENTER); Label timelabel = new Label(shell, SWT.NONE); timelabel.setSize(new Point(260, 20)); timelabel.setLocation(20, 50); // timelabel.setText("(approx " + timeEst + ")"); timelabel.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8)); timelabel.setAlignment(SWT.CENTER); ProgressBar progressBar = new ProgressBar(shell, SWT.HORIZONTAL | SWT.INDETERMINATE); progressBar.setSize(new Point(200, 20)); progressBar.setLocation(50, 80); Button button = new Button(shell, SWT.NONE); button.setSize(new Point(100, 30)); button.setLocation(100, 120); button.setText("Cancel"); button.setFont(ResourceUtils.getFont(iDartFont.VERASANS_8)); button.setAlignment(SWT.CENTER); button.addSelectionListener( new org.eclipse.swt.events.SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { if ((thread != null) && thread.isAlive()) { thread.interrupt(); reportFinished = true; } } }); shell.setSize(new Point(300, 200)); LayoutUtils.centerGUI(shell); shell.open(); while (!reportFinished) { if (!parent.getDisplay().readAndDispatch()) { parent.getDisplay().sleep(); } } if (!shell.isDisposed()) { shell.close(); } }
private void formatRemark(int start, int end) { StyleRange style = new StyleRange(); style.start = start; style.length = end - start; style.font = new Font(sShell.getDisplay(), "Courier New", 9, SWT.NORMAL); style.foreground = new Color(sShell.getDisplay(), 0, 128, 0); // Green activeHostsFileStyledText.setStyleRange(style); }
public void open() { shell.open(); while (!shell.isDisposed()) { if (!shell.getDisplay().readAndDispatch()) { shell.getDisplay().sleep(); } } }
private void formatIpAddress(int start, int end) { StyleRange style = new StyleRange(); style.start = start; style.length = end - start; style.font = new Font(sShell.getDisplay(), "Courier New", 9, SWT.BOLD); style.foreground = new Color(sShell.getDisplay(), 255, 127, 0); // Orange activeHostsFileStyledText.setStyleRange(style); }
public void init(Shell parentShell) { shell = ShellFactory.createShell(parentShell, SWT.BORDER | SWT.TITLE | SWT.CLOSE | SWT.RESIZE); Utils.setShellIcon(shell); if (Constants.isOSX) monospace = new Font(shell.getDisplay(), "Courier", 12, SWT.NORMAL); else monospace = new Font(shell.getDisplay(), "Courier New", 8, SWT.NORMAL); shell.setText( MessageText.getString("window.welcome.title", new String[] {Constants.AZUREUS_VERSION})); display = shell.getDisplay(); GridLayout layout = new GridLayout(); shell.setLayout(layout); GridData data; cWhatsNew = new Composite(shell, SWT.BORDER); data = new GridData(GridData.FILL_BOTH); cWhatsNew.setLayoutData(data); cWhatsNew.setLayout(new FillLayout()); Button bClose = new Button(shell, SWT.PUSH); bClose.setText(MessageText.getString("Button.close")); data = new GridData(); data.widthHint = 70; data.horizontalAlignment = Constants.isOSX ? SWT.CENTER : SWT.RIGHT; bClose.setLayoutData(data); Listener closeListener = new Listener() { public void handleEvent(Event event) { close(); } }; bClose.addListener(SWT.Selection, closeListener); shell.addListener(SWT.Close, closeListener); shell.setDefaultButton(bClose); shell.addListener( SWT.Traverse, new Listener() { public void handleEvent(Event e) { if (e.character == SWT.ESC) { close(); } } }); shell.setSize(750, 500); Utils.centreWindow(shell); shell.layout(); shell.open(); pullWhatsNew(cWhatsNew); }
public void open() { createShell(); shell.open(); shell.setFocus(); while (!shell.isDisposed()) { if (!shell.getDisplay().readAndDispatch()) { shell.getDisplay().sleep(); } } }
static void open(final Shell shell) { shell.setText("Testing"); shell.setLayout(new FillLayout()); shell.setSize(200, 250); shell.open(); while (!shell.isDisposed()) { while (!shell.getDisplay().readAndDispatch()) { shell.getDisplay().sleep(); } } }
@SuppressWarnings("unused") /* would block when running tests */ private void open(final Shell shell) { shell.setText("Testing"); // $NON-NLS-1$ shell.setLayout(new FillLayout()); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { while (!shell.getDisplay().readAndDispatch()) { shell.getDisplay().sleep(); } } }
/** * Initialize the toolbar with icons and selection listeners in the appropriate part of the window */ public void initToolbar() { Device dev = shell.getDisplay(); try { exitImg = new Image(dev, "img/exit.png"); // openImg = new Image(dev, "img/open.png"); playImg = new Image(dev, "img/play.png"); // pauseImg = new Image(dev, "img/pause.png"); } catch (Exception e) { System.out.println("Cannot load images"); System.out.println(e.getMessage()); System.exit(1); } ToolBar toolBar = new ToolBar(shell, SWT.BORDER); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; toolBar.setLayoutData(gridData); ToolItem exit = new ToolItem(toolBar, SWT.PUSH); exit.setImage(exitImg); // ToolItem open = new ToolItem(toolBar, SWT.PUSH); // exit.setImage(openImg); ToolItem play = new ToolItem(toolBar, SWT.PUSH); play.setImage(playImg); // ToolItem pause = new ToolItem(toolBar, SWT.PUSH); // pause.setImage(pauseImg); toolBar.pack(); exit.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.exit(0); } }); // open.addSelectionListener(new SelectionAdapter() { // @Override // public void widgetSelected(SelectionEvent e) { // FileDialog dialog = new FileDialog(shell, SWT.NULL); // String path = dialog.open(); // } // }); play.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { controller.RunAnimation(); } }); }
/** * Convenience method that prompts to save changes in the given dirty model. * * @param shell a shell * @param saveable a dirty saveable model * @param allowCancel whether canceling the action is an option * @return whether the user choose to save (<code>true</code>) or revert (<code>false</code>() the * model * @throws InterruptedException thrown if the user choose to cancel */ public static boolean promptToSaveChanges( final Shell shell, final SaveableComparison saveable, final boolean allowCancel) throws InterruptedException { final int[] result = new int[] {0}; Runnable runnable = new Runnable() { @Override public void run() { String[] options; if (allowCancel) { options = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; } else { options = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}; } MessageDialog dialog = new MessageDialog( shell, TeamUIMessages.ModelParticipantAction_0, null, NLS.bind(TeamUIMessages.ModelParticipantAction_1, saveable.getName()), MessageDialog.QUESTION, options, result[0]); result[0] = dialog.open(); } }; shell.getDisplay().syncExec(runnable); if (result[0] == 2) throw new InterruptedException(); return result[0] == 0; }
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); } }
private void createBranch(final String textForBranch, RevCommit commit, IProgressMonitor monitor) throws CoreException, GitAPIException { monitor.setTaskName(UIText.FetchGerritChangePage_CreatingBranchTaskName); CreateLocalBranchOperation bop = new CreateLocalBranchOperation(repository, textForBranch, commit); bop.execute(monitor); CheckoutCommand co = new Git(repository).checkout(); try { co.setName(textForBranch).call(); } catch (CheckoutConflictException e) { final CheckoutResult result = co.getResult(); if (result.getStatus() == Status.CONFLICTS) { final Shell shell = getWizard().getContainer().getShell(); shell .getDisplay() .asyncExec( new Runnable() { public void run() { new CheckoutConflictDialog(shell, repository, result.getConflictList()).open(); } }); } } monitor.worked(1); }
private void notifyToolsNeedsToBeRestarted(int flags) { String msg = null; if ((flags & TOOLS_MSG_UPDATED_FROM_ADT) != 0) { msg = "The Android SDK and AVD Manager that you are currently using has been updated. " + "Please also run Eclipse > Help > Check for Updates to see if the Android " + "plug-in needs to be updated."; } else if ((flags & TOOLS_MSG_UPDATED_FROM_SDKMAN) != 0) { msg = "The Android SDK and AVD Manager that you are currently using has been updated. " + "It is recommended that you now close the manager window and re-open it. " + "If you use Eclipse, please run Help > Check for Updates to see if the Android " + "plug-in needs to be updated."; } final String msg2 = msg; final Shell shell = getWindowShell(); if (msg2 != null && shell != null && !shell.isDisposed()) { shell .getDisplay() .syncExec( new Runnable() { @Override public void run() { if (!shell.isDisposed()) { MessageDialog.openInformation(shell, "Android Tools Updated", msg2); } } }); } }
/** * Implementation of the <code>IAction</code> prototype. Checks if the selected lines are all * commented or not and uncomments/comments them respectively. */ public void run() { if (fOperationTarget == null || fDocumentPartitioning == null || fPrefixesMap == null) return; ITextEditor editor = getTextEditor(); if (editor == null) return; if (!validateEditorInputState()) return; final int operationCode; if (isSelectionCommented(editor.getSelectionProvider().getSelection())) operationCode = ITextOperationTarget.STRIP_PREFIX; else operationCode = ITextOperationTarget.PREFIX; Shell shell = editor.getSite().getShell(); if (!fOperationTarget.canDoOperation(operationCode)) { if (shell != null) // MessageDialog.openError(shell, // JavaEditorMessages.getString("ToggleComment.error.title"), // JavaEditorMessages.getString("ToggleComment.error.message")); // //$NON-NLS-1$ //$NON-NLS-2$ return; } Display display = null; if (shell != null && !shell.isDisposed()) display = shell.getDisplay(); BusyIndicator.showWhile( display, new Runnable() { public void run() { fOperationTarget.doOperation(operationCode); } }); }
private void worked() { Shell shell = container.getShell(); Display display = shell.getDisplay(); if (display != null && !shell.isDisposed()) { display.readAndDispatch(); } }
private Display getDisplay() { Shell shell = getShell(); if (shell != null) { return shell.getDisplay(); } return null; }
private static void showMessage(Shell shell, IActionBars actionBars, String msg) { if (actionBars != null) { IStatusLineManager statusLine = actionBars.getStatusLineManager(); if (statusLine != null) statusLine.setMessage(msg); } shell.getDisplay().beep(); }
/** * Adds this as element state listener in the UI thread as it can otherwise conflict with other * listener additions, since DocumentProvider is not thread-safe. * * @param editor the editor to get the display from * @param provider the document provider to register as element state listener */ private void addElementStateListener(ITextEditor editor, final IDocumentProvider provider) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=66686 and // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56871 Runnable runnable = new Runnable() { public void run() { synchronized (fLock) { if (fDocumentProvider == provider) // addElementStateListener adds at most once - no problem to call repeatedly provider.addElementStateListener(LastSaveReferenceProvider.this); } } }; Display display = null; if (editor != null) { IWorkbenchPartSite site = editor.getSite(); if (site != null) { IWorkbenchWindow window = site.getWorkbenchWindow(); if (window != null) { Shell shell = window.getShell(); if (shell != null) display = shell.getDisplay(); } } } if (display != null && !display.isDisposed()) { display.asyncExec(runnable); } else { runnable.run(); } }
private boolean findEntry() { Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT); shell.setCursor(waitCursor); boolean matchCase = searchDialog.getMatchCase(); boolean matchWord = searchDialog.getMatchWord(); String searchString = searchDialog.getSearchString(); int column = searchDialog.getSelectedSearchArea(); searchString = matchCase ? searchString : searchString.toLowerCase(); boolean found = false; if (searchDialog.getSearchDown()) { for (int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) { if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) { table.setSelection(i); break; } } } else { for (int i = table.getSelectionIndex() - 1; i > -1; i--) { if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) { table.setSelection(i); break; } } } shell.setCursor(null); return found; }
/** * Attempts to restart ADB. * * <p>If the "ask before restart" setting is set (the default), prompt the user whether now is a * good time to restart ADB. * * @param monitor */ private void askForAdbRestart(ITaskMonitor monitor) { final boolean[] canRestart = new boolean[] {true}; if (getWindowShell() != null && getSettingsController().getSettings().getAskBeforeAdbRestart()) { // need to ask for permission first final Shell shell = getWindowShell(); if (shell != null && !shell.isDisposed()) { shell .getDisplay() .syncExec( new Runnable() { @Override public void run() { if (!shell.isDisposed()) { canRestart[0] = MessageDialog.openQuestion( shell, "ADB Restart", "A package that depends on ADB has been updated. \n" + "Do you want to restart ADB now?"); } } }); } } if (canRestart[0]) { AdbWrapper adb = new AdbWrapper(getOsSdkRoot(), monitor); adb.stopAdb(); adb.startAdb(); } }
/** * Get an <code>Image</code> from the provide SWT image constant. * * @param imageID the SWT image constant * @return image the image */ private Image getSWTImage(final int imageID) { Shell shell = getShell(); final Display display; if (!Widgets.isDisposed(shell)) { shell = shell.getParent().getShell(); } if (Widgets.isDisposed(shell)) { display = Display.getCurrent(); // The dialog should be always instantiated in UI thread. // However it was possible to instantiate it in other threads // (the code worked in most cases) so the assertion covers // only the failing scenario. See bug 107082 for details. Assert.isNotNull(display, "The dialog should be created in UI thread"); // $NON-NLS-1$ } else { display = shell.getDisplay(); } final Image[] image = new Image[1]; display.syncExec( new Runnable() { @Override public void run() { image[0] = display.getSystemImage(imageID); } }); return image[0]; }
/** * Update the presentation. * * @param textPresentation the text presentation * @param addedPositions the added positions * @param removedPositions the removed positions */ private void updatePresentation( TextPresentation textPresentation, List<Position> addedPositions, List<Position> removedPositions) { Runnable runnable = fJobPresenter.createUpdateRunnable(textPresentation, addedPositions, removedPositions); if (runnable == null) { return; } DartEditor editor = fEditor; if (editor == null) { return; } IWorkbenchPartSite site = editor.getSite(); if (site == null) { return; } Shell shell = site.getShell(); if (shell == null || shell.isDisposed()) { return; } Display display = shell.getDisplay(); if (display == null || display.isDisposed()) { return; } display.asyncExec(runnable); }
private void drawBorder(GC gc) { gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); gc.setLineWidth(1); gc.setLineStyle(SWT.LINE_SOLID); gc.drawRectangle( pageClientArea.x, pageClientArea.y, pageClientArea.width - 1, pageClientArea.height - 1); }
private void createControls() { GridLayout gLayout = new GridLayout(); gLayout.marginHeight = 0; gLayout.marginWidth = 0; gLayout.verticalSpacing = 0; shell.setLayout(gLayout); Utils.setShellIcon(shell); topPanel = new Composite(shell, SWT.NONE); topPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout gLayout1 = new GridLayout(); gLayout1.marginBottom = 10; topPanel.setLayout(gLayout1); topPanel.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); topPanel.setBackgroundMode(SWT.INHERIT_FORCE); Label separator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); separator1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); contentPanel = new Composite(shell, SWT.NONE); contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); contentStackLayout = new StackLayout(); contentPanel.setLayout(contentStackLayout); titleLabel = new Label(topPanel, SWT.NONE); titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); Utils.setFontHeight(titleLabel, 16, SWT.NORMAL); descriptionLabel = new Label(topPanel, SWT.WRAP); GridData gData = new GridData(SWT.FILL, SWT.FILL, true, true); gData.horizontalIndent = 10; descriptionLabel.setLayoutData(gData); shell.layout(true, true); }
private void updateShellStructure() { Region region = new Region(mShell.getDisplay()); int maxX = mShell.getBounds().width; int maxY = mShell.getBounds().height; region.add(0, 0, maxX, maxY); if (!getMaximized()) { // top left region.subtract(0, 0, 4, 1); region.subtract(0, 1, 2, 1); region.subtract(0, 2, 1, 1); region.subtract(0, 3, 1, 1); // bottom right region.subtract(maxX - 1, maxY - 4, 1, 4); region.subtract(maxX - 2, maxY - 2, 1, 2); region.subtract(maxX - 3, maxY - 1, 1, 1); region.subtract(maxX - 4, maxY - 1, 1, 1); // bottom left region.subtract(0, maxY - 4, 1, 4); region.subtract(1, maxY - 2, 1, 2); region.subtract(2, maxY - 1, 1, 1); region.subtract(3, maxY - 1, 1, 1); // top right region.subtract(maxX - 4, 0, 4, 1); region.subtract(maxX - 2, 1, 2, 1); region.subtract(maxX - 1, 2, 1, 1); region.subtract(maxX - 1, 3, 1, 1); } mShell.setRegion(region); }