Java Code Examples for org.eclipse.swt.widgets.Display.getCurrent()

The following are Jave code examples for showing how to use getCurrent() of the org.eclipse.swt.widgets.Display class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: vertigo-chroma-kspplugin   File: KspOutlinePage.java   Source Code and License Vote up 6 votes
private void setStyledText(ViewerCell cell, TreeObject obj) {
	/* Calcul du texte. */
	String mainText = obj.getMainText();
	if (mainText == null) {
		return;
	}
	String subText = obj.getSubText();
	String subTextFinal = subText == null ? "" : (" : " + subText);
	String fullText = mainText + subTextFinal;
	cell.setText(fullText);

	/* Calcul du style. */
	List<StyleRange> styles = new ArrayList<>();
	StyleRange styleMainText = new StyleRange(0, mainText.length(), null, null);
	styles.add(styleMainText);
	if (!subTextFinal.isEmpty()) {
		Display display = Display.getCurrent();
		Color blue = display.getSystemColor(SWT.COLOR_DARK_YELLOW);
		StyleRange styleSubText = new StyleRange(mainText.length(), subTextFinal.length(), blue, null);
		styles.add(styleSubText);
	}
	cell.setStyleRanges(styles.toArray(new StyleRange[0]));
}
 
Example 2
Project: convertigo-eclipse   File: SWTX.java   Source Code and License Vote up 6 votes
public static void drawButtonDeepDown(GC gc, String text, int textAlign,
      Image image, int imageAlign, int x, int y, int w, int h) {
    Display display = Display.getCurrent();
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    gc.drawLine(x, y, x + w - 2, y);
    gc.drawLine(x, y, x, y + h - 2);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gc.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
    gc.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
    gc.drawLine(x + w - 2, y + h - 2, x + w - 2, y + 1);
    //
gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
gc.fillRectangle(x + 2, y + 2, w - 4, 1);
gc.fillRectangle(x + 1, y + 2, 2, h - 4);
//
    gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    drawTextImage(gc, text, textAlign, image, imageAlign, x + 2 + 1,
        y + 2 + 1, w - 4, h - 3 - 1);
  }
 
Example 3
Project: JTouchBar   File: JTouchBarSWTTest.java   Source Code and License Vote up 6 votes
@Test
public void test() {
	JTouchBar jTouchBar = JTouchBarTestUtils.constructTouchBar();
	assertNotNull(jTouchBar);
	
	Display display = Display.getCurrent();

       Shell shell = new Shell(display);
       shell.setLayout(new FillLayout());

       shell.open();
       
       jTouchBar.show( shell );
       
       while (!shell.isDisposed()) {
           if (!display.readAndDispatch()) {
               display.sleep();
               break;
           }
       }
       
       display.dispose();
}
 
Example 4
Project: eclipse-batch-editor   File: AbstractQuickDialog.java   Source Code and License Vote up 6 votes
private void runEventLoop(Shell loopShell) {
	Display display;
	if (getShell() == null) {
		display = Display.getCurrent();
	} else {
		display = loopShell.getDisplay();
	}

	while (loopShell != null && !loopShell.isDisposed()) {
		try {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		} catch (Throwable e) {
			EclipseUtil.logError("UI problems on dispatch",e);
		}
	}
	if (!display.isDisposed()) {
		display.update();
	}
}
 
Example 5
Project: Hydrograph   File: SaveJobFileBeforeRunDialog.java   Source Code and License Vote up 5 votes
private Image getSWTImage() {
	Shell shell = getShell();
	final Display display;
	if (shell == null || shell.isDisposed()) {
		shell = getParentShell();
	}
	if (shell == null || shell.isDisposed()) {
		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() {
		public void run() {
			image[0] = display.getSystemImage(SWT.ICON_QUESTION);
		}
	});

	return image[0];

}
 
Example 6
Project: convertigo-eclipse   File: EngineLogViewLabelProvider.java   Source Code and License Vote up 5 votes
public Color getBackground(Object element, int columnIndex) {
	LogLine line = (LogLine) element;
	String level = line.getLevel();
	if (level.equals(Level.ERROR.toString())) {
		if (line.getCounter() % 2 == 0) {
			return new Color(Display.getCurrent(), 255, 158, 147);
		} else {
			return new Color(Display.getCurrent(), 255, 186, 178);
		}
	} else if (level.equals(Level.INFO.toString())) {
		if (line.getCounter() % 2 == 0) {
			return new Color(Display.getCurrent(), 225, 242, 228);
		} else {
			return new Color(Display.getCurrent(), 237, 255, 241);
		}
	} else if (level.equals(Level.DEBUG.toString())) {
		if (line.getCounter() % 2 == 0) {
			return new Color(Display.getCurrent(), 249, 249, 177);
		} else {
			return new Color(Display.getCurrent(), 255, 255, 196);
		}
	} else if (level.equals(Level.WARN.toString())) {
		if (line.getCounter() % 2 == 0) {
			return new Color(Display.getCurrent(), 242, 196, 208);
		} else {
			return new Color(Display.getCurrent(), 255, 204, 217);
		}
	}
	return null;
}
 
Example 7
Project: visuflow-plugin   File: UnitView.java   Source Code and License Vote up 5 votes
public static Display getDisplay() {
	Display display = Display.getCurrent();
	if (display == null) {
		display = Display.getDefault();
	}
	return display;
}
 
Example 8
Project: n4js   File: DisplaySafeSyncer.java   Source Code and License Vote up 5 votes
public void awaitSignal(long timeout) throws TimeoutException, InterruptedException {
	if (latch == null)
		throw new IllegalStateException("Syncher must be initialized");
	long waitTime = 0;
	while (waitTime < timeout) {
		if (latch.await(10, TimeUnit.MILLISECONDS)) {
			latch = null;
			return;
		}
		waitTime += 10;
		if (Display.getCurrent() != null)
			Display.getCurrent().readAndDispatch();
	}
	throw new TimeoutException("Timeout in Syncer (timeout " + timeout + " ms)");
}
 
Example 9
Project: gw4e.project   File: JUnitGW4ETestUIPage.java   Source Code and License Vote up 5 votes
/**
 * 
 */
private void loadVertices() {
	Display display = Display.getCurrent();
	Runnable longJob = new Runnable() {
		public void run() {
			display.syncExec(new Runnable() {
				public void run() {
					IFile ifile = ResourceManager.toIFile(selection);
					String modelFileName = null;

					try {
						modelFileName = ResourceManager.getAbsolutePath(ifile);
						context = GraphWalkerFacade.getContext(modelFileName);
						updateUI();
					} catch (Exception e) {
						ResourceManager.logException(e);
						JUnitGW4ETestUIPage.this.setErrorMessage(
								"Unable to load the graph model. See error logs in the Error View.");
						return;
					}

					comboReachedVertexViewer.setInput(_loadVertices(context));
				}
			});
			display.wake();
		}
	};
	BusyIndicator.showWhile(display, longJob);
}
 
Example 10
Project: Hydrograph   File: SWTResourceManager.java   Source Code and License Vote up 5 votes
/**
 * Returns an {@link Image} encoded by the specified {@link InputStream}.
 * 
 * @param stream
 *            the {@link InputStream} encoding the image data
 * @return the {@link Image} encoded by the specified input stream
 */
protected static Image getImage(InputStream stream) throws IOException {
	try {
		Display display = Display.getCurrent();
		ImageData data = new ImageData(stream);
		if (data.transparentPixel > 0) {
			return new Image(display, data, data.getTransparencyMask());
		}
		return new Image(display, data);
	} finally {
		stream.close();
	}
}
 
Example 11
Project: n4js   File: CFEdge.java   Source Code and License Vote up 5 votes
/** Sets the color of the {@link GC} depending on the edge type. */
void setColor(GC gc) {
	Display displ = Display.getCurrent();
	Color color = GraphUtils.getColor(50, 50, 50);

	if (isDead || cfTypes.contains(ControlFlowType.DeadCode)) {
		color = displ.getSystemColor(SWT.COLOR_GRAY);
	} else {
		for (ControlFlowType cfType : cfTypes) {
			switch (cfType) {
			case LoopEnter:
			case LoopReenter:
			case LoopInfinite:
			case Break:
			case Continue:
			case Return:
				color = displ.getSystemColor(SWT.COLOR_BLUE);
				break;
			case Throw:
				color = displ.getSystemColor(SWT.COLOR_RED);
				break;
			default:
				break;
			}
		}
	}
	gc.setForeground(color);
}
 
Example 12
Project: neoscada   File: KeyInstanceManager.java   Source Code and License Vote up 5 votes
private void checkDisplay ()
{
    if ( Display.getCurrent () != this.display )
    {
        SWT.error ( SWT.ERROR_THREAD_INVALID_ACCESS );
    }
}
 
Example 13
Project: AgentWorkbench   File: SWTResourceManager.java   Source Code and License Vote up 5 votes
/**
 * Returns an {@link Image} encoded by the specified {@link InputStream}.
 * 
 * @param stream
 *            the {@link InputStream} encoding the image data
 * @return the {@link Image} encoded by the specified input stream
 */
protected static Image getImage(InputStream stream) throws IOException {
	try {
		Display display = Display.getCurrent();
		ImageData data = new ImageData(stream);
		if (data.transparentPixel > 0) {
			return new Image(display, data, data.getTransparencyMask());
		}
		return new Image(display, data);
	} finally {
		stream.close();
	}
}
 
Example 14
Project: neoscada   File: FigureRenderer.java   Source Code and License Vote up 5 votes
public FigureRenderer ( final ChartFigure chartFigure, final ResourceManager resourceManager )
{
    super ( resourceManager );

    this.realm = new DisplayRealm ( Display.getCurrent () );

    this.chartFigure = chartFigure;
    this.figureListener = new FigureListenerImpl ();
    this.chartFigure.addFigureListener ( this.figureListener );
}
 
Example 15
Project: convertigo-eclipse   File: SWTX.java   Source Code and License Vote up 5 votes
public static void drawButtonDown(GC gc, String text, int textAlign,
    Image image, int imageAlign, int x, int y, int w, int h, Color face) {
  Display display = Display.getCurrent();
  drawButtonDown(gc, text, textAlign, image, imageAlign, x, y, w, h,
      face, display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
      2, 2);
}
 
Example 16
Project: Hydrograph   File: SWTResourceManager.java   Source Code and License Vote up 5 votes
/**
 * Returns an {@link Image} encoded by the specified {@link InputStream}.
 * 
 * @param stream
 *            the {@link InputStream} encoding the image data
 * @return the {@link Image} encoded by the specified input stream
 */
protected static Image getImage(InputStream stream) throws IOException {
	try {
		Display display = Display.getCurrent();
		ImageData data = new ImageData(stream);
		if (data.transparentPixel > 0) {
			return new Image(display, data, data.getTransparencyMask());
		}
		return new Image(display, data);
	} finally {
		stream.close();
	}
}
 
Example 17
Project: xcalendar   File: SwtUtils.java   Source Code and License Vote up 4 votes
/**
 * Dispatch
 */
public static void dispatch(final Supplier<Boolean> condition) {
	final Display display = Display.getCurrent();
	while (!condition.get()) if(!display.readAndDispatch()) display.sleep(); 
}
 
Example 18
Project: Tarski   File: ValuesScanner.java   Source Code and License Vote up 4 votes
public ValuesScanner() {
	final IToken valuesToken = new Token(
			new TextAttribute(new Color(Display.getCurrent(), new RGB(160, 160, 160))));
	this.setDefaultReturnToken(valuesToken);
}
 
Example 19
Project: Tarski   File: TraceScanner.java   Source Code and License Vote up 4 votes
public TraceScanner() {
  final IToken traceToken =
      new Token(new TextAttribute(new Color(Display.getCurrent(), RGBStorage.TRACE_RGB)));
  this.setDefaultReturnToken(traceToken);
}
 
Example 20
Project: convertigo-eclipse   File: KTable.java   Source Code and License Vote up 4 votes
/**
 * Creates a new KTable.
 * 
 * possible styles: SWT.V_SCROLL - show vertical scrollbar and allow
 * vertical scrolling by arrow keys SWT.H_SCROLL - show horizontal scrollbar
 * and allow horizontal scrolling by arrow keys SWT.FLAT - no border
 * drawing.
 * 
 * After creation a table model should be added using setModel().
 */
public KTable(Composite parent, int style) {
  // Oberklasse initialisieren
  super(parent, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | style);

  // inits
  m_GC = new GC(this);
  m_Display = Display.getCurrent();
  m_Selection = new HashMap<Object, Object>();
  m_CellEditor = null;

  flatStyleSpecified = ((style | SWT.FLAT) == style);

  m_RowSelectionMode = false;
  m_MultiSelectMode = false;
  m_TopRow = 0;
  m_LeftColumn = 0;
  m_FocusRow = 0;
  m_FocusCol = 0;
  m_RowsVisible = 0;
  m_RowsFullyVisible = 0;
  m_ColumnsVisible = 0;
  m_ColumnsFullyVisible = 0;
  m_ResizeColumnIndex = -1;
  m_ResizeRowIndex = -1;
  m_ResizeRowTop = -1;
  m_NewRowSize = -1;
  m_ResizeColumnLeft = -1;
  m_Capture = false;
  m_ClickColumnIndex = -1;
  m_ClickRowIndex = -1;

  m_LineRestore = null;
  m_LineX = 0;
  m_LineY = 0;

  cellSelectionListeners = new ArrayList<KTableCellSelectionListener>(10);
  cellResizeListeners = new ArrayList<KTableCellResizeListener>(10);

  // Listener
  createListeners();

}