List of usage examples for org.eclipse.swt.widgets Display getDefault
public static Display getDefault()
From source file:JavaViewer.java
void createStyledText() { text = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); GridData spec = new GridData(); spec.horizontalAlignment = GridData.FILL; spec.grabExcessHorizontalSpace = true; spec.verticalAlignment = GridData.FILL; spec.grabExcessVerticalSpace = true; text.setLayoutData(spec);/*from ww w.ja v a 2 s . c om*/ text.addLineStyleListener(lineStyler); text.setEditable(false); Color bg = Display.getDefault().getSystemColor(SWT.COLOR_GRAY); text.setBackground(bg); }
From source file:msi.gama.gui.swt.controls.SWTChartEditor.java
/** * Creates a new editor.//from w w w . j av a 2 s.c o m * * @param display the display. * @param chart2edit the chart to edit. */ public SWTChartEditor(final Display display, final JFreeChart chart2edit, final Point position) { this.shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.NO_TRIM); this.shell.setSize(400, 500); this.shell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); // this.shell.setAlpha(140); this.chart = chart2edit; this.shell.setText("Chart properties"); this.shell.setLocation(position); GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5; this.shell.setLayout(layout); Composite main = new Composite(this.shell, SWT.NONE); main.setLayout(new FillLayout()); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabFolder tab = new TabFolder(main, SWT.BORDER); // build first tab TabItem item1 = new TabItem(tab, SWT.NONE); item1.setText(" " + "Title" + " "); this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle()); item1.setControl(this.titleEditor); // build second tab TabItem item2 = new TabItem(tab, SWT.NONE); item2.setText(" " + "Plot" + " "); this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot()); item2.setControl(this.plotEditor); // build the third tab TabItem item3 = new TabItem(tab, SWT.NONE); item3.setText(" " + "Other" + " "); this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart); item3.setControl(this.otherEditor); // ok and cancel buttons Button cancel = new Button(this.shell, SWT.PUSH); cancel.setText(" Cancel "); cancel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); cancel.pack(); cancel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { SWTChartEditor.this.shell.dispose(); } }); Button ok = new Button(this.shell, SWT.PUSH | SWT.OK); ok.setText(" Ok "); ok.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); ok.pack(); ok.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { updateChart(SWTChartEditor.this.chart); SWTChartEditor.this.shell.dispose(); } }); }
From source file:org.mwc.cmap.LiveDataMonitor.views.LiveDataMonitor.java
/** * The constructor./* w w w . j a va 2s. co m*/ */ public LiveDataMonitor() { _attListener = new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { // aah, is this for the scenario we're watching if (_myIndexedAttr != null) if (evt.getSource() == _myIndexedAttr.index) { final DataDoublet newD = (DataDoublet) evt.getNewValue(); final long time = newD.getTime(); final Object newValue = newD.getValue(); if (newValue instanceof Number) { final Number value = (Number) newValue; // and store it final TimeSeriesCollection coll = (TimeSeriesCollection) _chart.getXYPlot() .getDataset(); TimeSeries tmpSeries; if (coll == null) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); tmpSeries = new TimeSeries(_watchedAttr.getName()); dataset.addSeries(tmpSeries); // add to series in different thread... Display.getDefault().asyncExec(new Runnable() { public void run() { _chart.getXYPlot().setDataset(dataset); } }); } else { tmpSeries = coll.getSeries(0); } final TimeSeries series = tmpSeries; // add to series in current thread, accepting it will slow down // the // UI Display.getDefault().syncExec(new Runnable() { public void run() { // are we still open?i if (!_chartFrame.isDisposed()) { // sure, go for it, series.addOrUpdate(new Millisecond(new Date(time)), value); } } }); } } } }; }
From source file:KalendarDialog.java
public Object open() { Shell parent = getParent();/* w w w. j a va2s . c om*/ display = Display.getDefault(); shell = new Shell(parent, SWT.TITLE | SWT.PRIMARY_MODAL); shell.setText("Calendar ver0.02"); shell.setSize(230, 220); gridLayout = new GridLayout(); gridLayout.numColumns = 7; shell.setLayout(gridLayout); gridData = new GridData(GridData.FILL_HORIZONTAL); yearUp = new Button(shell, SWT.PUSH | SWT.FLAT); yearUp.setText("<"); yearUp.setLayoutData(gridData); yearUp.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { previousYear(); } }); gridData = new GridData(GridData.FILL_HORIZONTAL); monthUp = new Button(shell, SWT.PUSH | SWT.FLAT); monthUp.setText("<<"); monthUp.setLayoutData(gridData); monthUp.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { previousMonth(); } }); nowLabel = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 3; nowLabel.setLayoutData(gridData); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); nowLabel.setText(formatter.format(new Date())); gridData = new GridData(GridData.FILL_HORIZONTAL); monthNext = new Button(shell, SWT.PUSH | SWT.FLAT); monthNext.setText(">>"); monthNext.setLayoutData(gridData); monthNext.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { nextMonth(); } }); gridData = new GridData(GridData.FILL_HORIZONTAL); yearNext = new Button(shell, SWT.PUSH | SWT.FLAT); yearNext.setText(">"); yearNext.setLayoutData(gridData); yearNext.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { nextYear(); } }); sunday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.widthHint = 20; gridData.heightHint = 20; sunday.setLayoutData(gridData); sunday.setText("Sun"); monday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.widthHint = 20; gridData.heightHint = 20; monday.setLayoutData(gridData); monday.setText("Mon"); tuesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.widthHint = 20; gridData.heightHint = 20; tuesday.setLayoutData(gridData); tuesday.setText("Tue"); wednesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.widthHint = 20; gridData.heightHint = 20; wednesday.setLayoutData(gridData); wednesday.setText("Wed"); thursday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.widthHint = 20; gridData.heightHint = 20; thursday.setLayoutData(gridData); thursday.setText("Thu"); friday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.widthHint = 20; gridData.heightHint = 20; friday.setLayoutData(gridData); friday.setText("Fri"); saturday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.widthHint = 20; gridData.heightHint = 20; saturday.setLayoutData(gridData); saturday.setText("Sat"); for (int i = 0; i < 42; i++) { days[i] = new CLabel(shell, SWT.FLAT | SWT.CENTER); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); days[i].setLayoutData(gridData); days[i].setBackground(display.getSystemColor(SWT.COLOR_WHITE)); days[i].addMouseListener(this); days[i].setToolTipText("double click get current date."); } Calendar now = Calendar.getInstance(); // nowDate = new Date(now.getTimeInMillis()); setDayForDisplay(now); shell.open(); Display display = parent.getDisplay(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return selectedDate; }
From source file:org.gumtree.vis.swt.PlotComposite.java
public void setPlot(final IPlot plot) { final IPlot oldPlot = this.plot; if (oldPlot != null) { oldPlot.cleanUp();/*from ww w.ja va2 s .co m*/ frame.remove((JPanel) oldPlot); } this.plot = plot; final Composite composite = this; Display display = Display.getCurrent(); if (display == null) { display = Display.getDefault(); } display.asyncExec(new Runnable() { @Override public void run() { if (!composite.isDisposed()) { embedPlot(plot); removeListeners(oldPlot); addListeners(); composite.pack(); composite.getParent().layout(true, true); } } }); }
From source file:JavaViewer.java
void initializeColors() { Display display = Display.getDefault(); colors = new Color[] { new Color(display, new RGB(0, 0, 0)), // black new Color(display, new RGB(255, 0, 0)), // red new Color(display, new RGB(0, 255, 0)), // green new Color(display, new RGB(0, 0, 255)) // blue };/*from w ww. j a va 2 s . co m*/ tokenColors = new int[MAXIMUM_TOKEN]; tokenColors[WORD] = 0; tokenColors[WHITE] = 0; tokenColors[KEY] = 3; tokenColors[COMMENT] = 1; tokenColors[STRING] = 2; tokenColors[OTHER] = 0; tokenColors[NUMBER] = 0; }
From source file:org.amanzi.splash.chart.Charts.java
public static void openChartEditor(final IEditorInput editorInput, final String editorId) { IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchPage page = workbench.getWorkbenchWindows()[0].getActivePage(); Display display = Display.getCurrent(); if (display == null) { display = Display.getDefault(); }//from ww w . jav a2 s . com display.syncExec(new Runnable() { @Override public void run() { try { NeoSplashUtil.logn("Try to open editor " + editorId); page.openEditor(editorInput, editorId); } catch (PartInitException e) { NeoSplashUtil.logn(e.getMessage()); } } }); }
From source file:org.gumtree.vis.plot1d.Plot1D.java
private void createStatusBar() { Composite statusComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(6, false); layout.marginLeft = 6;// w ww .j a v a 2s .c o m layout.marginRight = 6; layout.marginTop = 1; layout.marginBottom = 1; layout.horizontalSpacing = 3; layout.verticalSpacing = 1; statusComposite.setLayout(layout); GridData gridData = new GridData(SWT.FILL); gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = false; statusComposite.setLayoutData(gridData); final Label xLabel = new Label(statusComposite, SWT.NONE); xLabel.setText("X:"); gridData = new GridData(SWT.DEFAULT); xLabel.setLayoutData(gridData); // GridDataFactory.swtDefaults().applyTo(xLabel); final Text xText = new Text(statusComposite, SWT.BORDER); gridData = new GridData(SWT.FILL); gridData.widthHint = 50; xText.setLayoutData(gridData); // GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(xText); xText.setEditable(false); final Label yLabel = new Label(statusComposite, SWT.NONE); yLabel.setText("Y:"); gridData = new GridData(SWT.DEFAULT); yLabel.setLayoutData(gridData); // GridDataFactory.swtDefaults().applyTo(yLabel); final Text yText = new Text(statusComposite, SWT.BORDER); gridData = new GridData(SWT.FILL); gridData.widthHint = 50; yText.setLayoutData(gridData); // GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(yText); yText.setEditable(false); final Composite composite = this; panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent event) { if (event instanceof XYChartMouseEvent) { final String xString = String.format("%.2f", ((XYChartMouseEvent) event).getX()); final String yString = String.format("%.2f", ((XYChartMouseEvent) event).getY()); // panel.requestFocus(); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { xText.setText(xString); yText.setText(yString); if (!composite.isFocusControl()) { composite.setFocus(); } } }); } } @Override public void chartMouseClicked(ChartMouseEvent event) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { if (!composite.isFocusControl()) { composite.setFocus(); } } }); } }); }
From source file:SWTTest.java
/** * Transfer a rectangular region from the AWT image to the SWT image. *///ww w. ja v a 2 s .co m private void transferPixels(int clipX, int clipY, int clipW, int clipH) { int step = swtImageData.depth / 8; byte[] data = swtImageData.data; awtImage.getRGB(clipX, clipY, clipW, clipH, awtPixels, 0, clipW); for (int i = 0; i < clipH; i++) { int idx = (clipY + i) * swtImageData.bytesPerLine + clipX * step; for (int j = 0; j < clipW; j++) { int rgb = awtPixels[j + i * clipW]; for (int k = swtImageData.depth - 8; k >= 0; k -= 8) { data[idx++] = (byte) ((rgb >> k) & 0xFF); } } } if (swtImage != null) swtImage.dispose(); swtImage = new Image(Display.getDefault(), swtImageData); }
From source file:tools.descartes.bungee.viewer.RunResultView.java
@Override public void createPartControl(final Composite parent) { VerifyListener numberVerifier = new VerifyListener() { @Override/* w w w .j a v a 2 s . c om*/ public void verifyText(VerifyEvent event) { switch (event.keyCode) { case SWT.BS: // Backspace case SWT.DEL: // Delete case SWT.HOME: // Home case SWT.END: // End case SWT.ARROW_LEFT: // Left arrow case SWT.ARROW_RIGHT: // Right arrow return; } if (!Character.isDigit(event.character)) { event.doit = false; // disallow the action } } }; Composite composite = new Composite(parent, SWT.NONE); GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; Composite compositeChecks1 = new Composite(composite, SWT.NONE); compositeChecks1.setLayout(new GridLayout(2, false)); Text sanityText = new Text(compositeChecks1, SWT.NONE); sanityText.setText("Passed Sanity Check:"); sanityCheckValue = new Button(compositeChecks1, SWT.CHECK); sanityCheckValue.setEnabled(false); Composite compositeSChecks2 = new Composite(composite, SWT.NONE); compositeSChecks2.setLayout(new GridLayout(2, false)); Text scheduleText = new Text(compositeSChecks2, SWT.NONE); scheduleText.setText("Passed Schedule Check:"); scheduleCheckValue = new Button(compositeSChecks2, SWT.CHECK); scheduleCheckValue.setEnabled(false); Text completedText = new Text(compositeChecks1, SWT.NONE); completedText.setText("Run completed:"); completedCheckValue = new Button(compositeChecks1, SWT.CHECK); completedCheckValue.setEnabled(false); Text successText = new Text(compositeSChecks2, SWT.NONE); successText.setText("Run successful:"); successCheckValue = new Button(compositeSChecks2, SWT.CHECK); successCheckValue.setEnabled(false); Text timingMeanText = new Text(composite, SWT.NONE); timingMeanText.setText("Schedule deviation mean: "); timingMeanValue = new Text(composite, SWT.SINGLE); timingMeanValue.setText(""); Text timingStdText = new Text(composite, SWT.NONE); timingStdText.setText("Schedule deviation std: "); timingStdValue = new Text(composite, SWT.SINGLE); timingStdValue.setText(""); Text responseTimeMeanText = new Text(composite, SWT.NONE); responseTimeMeanText.setText("Responsetime mean: "); responseTimeMeanValue = new Text(composite, SWT.SINGLE); responseTimeMeanValue.setText(""); Text responseTimeStdText = new Text(composite, SWT.NONE); responseTimeStdText.setText("Responsetime std: "); responseTimeStdValue = new Text(composite, SWT.SINGLE); responseTimeStdValue.setText(""); Text chartWidthText = new Text(composite, SWT.NONE); chartWidthText.setText("Chart width: "); final Text chartWidthValue = new Text(composite, SWT.BORDER); chartWidthValue.setText("800"); chartWidthValue.addVerifyListener(numberVerifier); Text chartHeightText = new Text(composite, SWT.NONE); chartHeightText.setText("Chart height: "); final Text chartHeightValue = new Text(composite, SWT.BORDER); chartHeightValue.setText("400"); chartHeightValue.addVerifyListener(numberVerifier); showScheduleChartButton = new Button(composite, SWT.NONE); showScheduleChartButton.setText("Show Schedule Chart"); showScheduleChartButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { switch (e.type) { case SWT.Selection: showScheduleChart(Integer.parseInt(chartWidthValue.getText()), Integer.parseInt(chartHeightValue.getText())); break; } } }); saveScheduleChartButton = new Button(composite, SWT.NONE); saveScheduleChartButton.setText("Save Schedule Chart"); saveScheduleChartButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { // optional window Display display = Display.getDefault(); Shell dialogShell = new Shell(display, SWT.APPLICATION_MODAL); MessageBox dialog = new MessageBox(dialogShell, SWT.ICON_WARNING | SWT.OK); dialog.setText("Licence Problem"); dialog.setMessage( "This feature is currently disabled! \n If you want to reenable it, check out the code."); dialog.open(); // end of optional window switch (e.type) { case SWT.Selection: saveScheduleChart(Integer.parseInt(chartWidthValue.getText()), Integer.parseInt(chartHeightValue.getText())); break; } } }); showResponseChartButton = new Button(composite, SWT.NONE); showResponseChartButton.setText("Show Response Chart"); showResponseChartButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { switch (e.type) { case SWT.Selection: showResponseChart(Integer.parseInt(chartWidthValue.getText()), Integer.parseInt(chartHeightValue.getText())); break; } } }); saveResponseChartButton = new Button(composite, SWT.NONE); saveResponseChartButton.setText("Save Response Chart"); saveResponseChartButton.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { // optional window Display display = Display.getDefault(); Shell dialogShell = new Shell(display, SWT.APPLICATION_MODAL); MessageBox dialog = new MessageBox(dialogShell, SWT.ICON_WARNING | SWT.OK); dialog.setText("Licence problem"); dialog.setMessage( "This feature is currently disabled! \n If you want to reenable it, check out the code."); dialog.open(); // end of optional window switch (e.type) { case SWT.Selection: saveResponseChart(Integer.parseInt(chartWidthValue.getText()), Integer.parseInt(chartHeightValue.getText())); break; } } }); getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this); composite.setLayout(new GridLayout(2, false)); this.parent = parent; }