org.eclipse.swt.graphics.Color Java Examples

The following examples show how to use org.eclipse.swt.graphics.Color. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpecProcessPage.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private String displayMessage(String msg, Color color) {
	String formattedDate = dateFormatter.format(System.currentTimeMillis());
	String timeMsg = formattedDate + msg;
	Message m = null;
	synchronized (msgStack) {
		if (!msgStack.isEmpty()) { // merge messages for better performance
			Message lastM = msgStack.lastElement();
			if (lastM != null && lastM.color == color) {
				msgStack.remove(msgStack.size() - 1);
				m = new Message(lastM.msg + "\n" + timeMsg, color);
			}
		}
		if (m == null) {
			m = new Message(timeMsg, color);
		}
		msgStack.push(m);
	}

	Display.getDefault().asyncExec(new Runnable() {
		@Override
		public void run() {
			asyncDisplayMessages();
		}
	});
	return msg;
}
 
Example #2
Source File: TextColorDrawingStrategy.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Annotation annotation, GC gc, StyledText textWidget, int start, int length, Color color) {
  if (length > 0) {
    if (annotation instanceof EclipseAnnotationPeer) {
      if (gc != null) {

        int end = start + length - 1;

        Rectangle bounds = textWidget.getTextBounds(start, end);

        gc.setForeground(color);

        gc.drawText(textWidget.getText(start, end), bounds.x, bounds.y, true);

      } else {
        textWidget.redrawRange(start, length, true);
      }
    }
  }
}
 
Example #3
Source File: MDXValuesHighlight.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
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( 63, 127, 95 ) ), // green
    new Color( display, new RGB( 0, 0, 255 ) ), // blue
    new Color( display, new RGB( 255, 0, 255 ) ) // SQL Functions / Rose

  };
  tokenColors = new int[MAXIMUM_TOKEN];
  tokenColors[WORD] = 0;
  tokenColors[WHITE] = 0;
  tokenColors[KEY] = 3;
  tokenColors[COMMENT] = 2;
  tokenColors[STRING] = 1;
  tokenColors[OTHER] = 0;
  tokenColors[NUMBER] = 0;
  tokenColors[FUNCTIONS] = 4;
}
 
Example #4
Source File: UserDefinedJavaClassHighlight.java    From hop with Apache License 2.0 6 votes vote down vote up
void initializeColors() {
  // Display display = Display.getDefault();
  colors = new Color[] { GUIResource.getInstance().getColor( 0, 0, 0 ), // black
    GUIResource.getInstance().getColor( 63, 127, 95 ), // red
    GUIResource.getInstance().getColor( 0, 0, 192 ), // green
    GUIResource.getInstance().getColor( 127, 0, 85 ), // blue
    GUIResource.getInstance().getColor( 255, 102, 0 ) // Hop Functions / Orange
  };
  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;
  tokenColors[ FUNCTIONS ] = 4;
}
 
Example #5
Source File: TestProgressBar.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create instance.
 */
public TestProgressBar(Composite parent, int style) {
	super(parent, style);

	// damn you, SWT color management
	// Color sample is form: http://www.colorpicker.com/c6f2b1
	colorSkipped = new Color(Display.getCurrent(), 230, 232, 235);
	colorPassed = new Color(Display.getCurrent(), 198, 242, 177);
	colorFailed = new Color(Display.getCurrent(), 242, 188, 177);
	colorError = new Color(Display.getCurrent(), 242, 188, 177);
	colorFixme = new Color(Display.getCurrent(), 177, 231, 242);

	addPaintListener((ev) -> {
		onPaint(ev.gc);
	});
	addDisposeListener((ev) -> {
		onDispose();
	});
}
 
Example #6
Source File: AbstractDynamicNotationHandler.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void updatePreferences() {
	IPreferenceStore store = SimulationActivator.getDefault().getPreferenceStore();
	// read out the new colors
	RGB foregroundColor = PreferenceConverter.getColor(store, STATE_FOREGROUND_HIGHLIGHTING_COLOR);
	RGB backgroundColor = PreferenceConverter.getColor(store, STATE_BACKGROUND_HIGHLIGHTING_COLOR);
	RGB vertexForegroundColor = PreferenceConverter.getColor(store, VERTEX_FOREGROUND_TRANSIENT_COLOR);
	RGB vertexBackgroundColor = PreferenceConverter.getColor(store, VERTEX_BACKGROUND_TRANSIENT_COLOR);
	RGB transitionColor = PreferenceConverter.getColor(store, TRANSITION_HIGHLIGHTING_COLOR);

	// Set the new colors
	STATE_HIGHLIGHT_PARAMS.foregroundFadingColor = new Color(Display.getDefault(), foregroundColor);
	STATE_HIGHLIGHT_PARAMS.backgroundFadingColor = new Color(Display.getDefault(), backgroundColor);
	SUSPENDED_PARAMS.backgroundFadingColor = STATE_HIGHLIGHT_PARAMS.backgroundFadingColor;
	SUSPENDED_PARAMS.foregroundFadingColor = green;
	VERTEX_TRANSIENT_PARAMS.foregroundFadingColor = new Color(Display.getDefault(), vertexForegroundColor);
	VERTEX_TRANSIENT_PARAMS.backgroundFadingColor = new Color(Display.getDefault(), vertexBackgroundColor);
	TRANSITION_PARAMS.foregroundFadingColor = new Color(Display.getDefault(), transitionColor);
}
 
Example #7
Source File: TimeGraphBaseControl.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
    if (e.widget != this) {
        return;
    }

    // we will use advanced graphics, set now for consistent output
    e.gc.setAdvanced(true);

    fFontHeight = e.gc.getFontMetrics().getHeight();
    Rectangle bound = getClientArea();
    if (!bound.isEmpty()) {
        Color colBackup = e.gc.getBackground();
        paint(bound, e);
        e.gc.setBackground(colBackup);
    }
}
 
Example #8
Source File: FigureController.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected ColorHandler makeColorHandler ( final String color, final ColorApplier applier )
{
    if ( color == null || color.isEmpty () )
    {
        return new DefaultColor ( getPropertyFigure (), applier );
    }

    if ( color.startsWith ( "#" ) && !color.contains ( "|" ) ) //$NON-NLS-1$ //$NON-NLS-2$
    {
        return new StaticColor ( getPropertyFigure (), applier, createColor ( Helper.makeColor ( color ) ) );
    }
    else if ( ( color.startsWith ( "#" ) || color.startsWith ( "|" ) ) && color.contains ( "|" ) ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    {
        final String tok[] = color.split ( "\\|", -1 ); //$NON-NLS-1$

        final Color[] colors = new Color[tok.length];
        int i = 0;
        for ( final String colorString : tok )
        {
            colors[i] = createColor ( Helper.makeColor ( colorString ) );
            i++;
        }
        return new BlinkingColor ( getPropertyFigure (), applier, colors );
    }
    return new DefaultColor ( getPropertyFigure (), applier );
}
 
Example #9
Source File: RiskRenderer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public RiskRenderer(Printer printer) {
    super(printer);
    if (printer != null) {
        _yellow = printer.getSystemColor(SWT.COLOR_YELLOW);
        _green = printer.getSystemColor(SWT.COLOR_GREEN);
        _red = printer.getSystemColor(SWT.COLOR_RED);
        _black = printer.getSystemColor(SWT.COLOR_BLACK);
        _redInactive = new Color(printer, INACTIVE_RED);
        _yellowInactive = new Color(printer, INACTIVE_YELLOW);
        _greenInactive = new Color(printer, INACTIVE_GREEN);
    }
    Color[][] inactiveColors = { { _yellowInactive, _redInactive, _redInactive },
            { _greenInactive, _yellowInactive, _redInactive }, { _greenInactive, _greenInactive, _yellowInactive } };
    _inactiveColors = inactiveColors;
    Color[][] colors = { { _yellow, _red, _red }, { _green, _yellow, _red }, { _green, _green, _yellow } };
    _colors = colors;
}
 
Example #10
Source File: DefaultTimelineLabelProvider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Color getForeground(Object element) {
	if (element instanceof IColored) {
		final RGB rgb = ((IColored) element).getRgb();
		if (rgb != null)
			return fResourceManager.createColor(rgb);
	}

	return null;
}
 
Example #11
Source File: ObjectImageRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
        IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    drawBackground(gc, drawingArea, cellStyle, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    Object value = column.getValue(row);
    String key = _keyMap.get(value);

    if (key != null) {
        Image img = null;
        img = getImageRegistry().get(key);
        int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
        int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
        gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
                scaleY(img.getBounds().height));
    } else {
        // indicate error with red fill
        Color bg = gc.getBackground();
        gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
        gc.fillRectangle(rect);
        gc.setBackground(bg);
    }
    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);

}
 
Example #12
Source File: CSSTokenProvider.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Color getEditorForeground() {
	IStyle style = parser.getBestStyle("editor");
	if (style != null && style.getColor() != null) {
		return ColorManager.getInstance().getColor(style.getColor());
	}
	return null;
}
 
Example #13
Source File: AbstractDebugVariableCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) {
	// increment x with 3 spaces width
	x += 3 * (int) gc.getFontMetrics().getAverageCharacterWidth();
	Point p = super.draw(gc, textWidget, color, x, y);
	if (fRgb != null) {
		int width = drawSquare(fRgb, gc, textWidget, x + p.x, y);
		p.x += width;
	}
	return p;
}
 
Example #14
Source File: UpdateDescriptionPage.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void createControl(Composite parent) {
	Text text = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
	Color color = text.getBackground();
	text.setEditable(false);
	text.setBackground(color);
	text.setText(getUpdateDescDetailText());
	setControl(text);
}
 
Example #15
Source File: Gallery.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.swt.widgets.Control#setForeground(org.eclipse.swt.graphics
 *      .Color)
 */
public void setForeground(Color color) {
	// Cache color locally
	if (!useControlColors) {
		this.foregroundColor = color;
	}

	// Always call Control#setForeground(); Additionally, this will trigger
	// a redraw.
	super.setForeground(color);
}
 
Example #16
Source File: TimelineViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void update(Object element, String[] properties) {
	final IFigure figure = fElementToFigureMap.get(element);
	if (figure != null) {

		if (isCursorElement(element))
			getControl().getRootFigure().updateCursorFigure(figure, toCursor(element));

		else if (isTrackElement(element))
			getControl().getRootFigure().updateTrackFigure(figure, getLabelProvider().getText(element));

		else if (isEventElement(element))
			getControl().getRootFigure().updateEventFigure(figure, toEvent(element));

		else if (isLaneElement(element)) {
			if (getLabelProvider() instanceof IColorProvider) {
				// color update for all elements
				Color foreground = ((IColorProvider) getLabelProvider()).getForeground(element);
				if (foreground == null)
					foreground = getStyleProvider().getLaneColor();

				figure.setForegroundColor(foreground);

				internalRefresh(element);
			}
		}
	}
}
 
Example #17
Source File: RepositoryDirectoryUI.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a directory tree on a TreeItem to work with.
 *
 * @param ti
 *          The TreeItem to set the directory tree on
 * @param dircolor
 *          The color of the directory tree item.
 */
public static void getDirectoryTree( TreeItem ti, Color dircolor, RepositoryDirectoryInterface dir ) {
  ti.setText( dir.getName() );
  ti.setForeground( dircolor );

  // First, we draw the directories
  for ( int i = 0; i < dir.getNrSubdirectories(); i++ ) {
    RepositoryDirectory subdir = dir.getSubdirectory( i );
    TreeItem subti = new TreeItem( ti, SWT.NONE );
    subti.setImage( GUIResource.getInstance().getImageFolder() );
    getDirectoryTree( subti, dircolor, subdir );
  }
}
 
Example #18
Source File: ParamTable.java    From http4e with Apache License 2.0 5 votes vote down vote up
public Color getForeground( Object element, int column){
   Param p = (Param) element;
   if (Param.DEFAULT_INSTANCE.equals(p)) {
      return ResourceUtils.getColor(Styles.LIGHT_RGB_TEXT);
   }
   return null;
}
 
Example #19
Source File: CoverageLabelProvider.java    From tlaplus with MIT License 5 votes vote down vote up
public Color getForeground(final Object element, final int columnIndex) {
	if (TLAEditorActivator.getDefault().isCurrentThemeDark() && (element instanceof ActionInformationItem)
			&& !RUNNING_WINDOWS) {	// RUNNING_WINDOWS check due to https://github.com/tlaplus/tlaplus/issues/341
		final ActionInformationItem aii = (ActionInformationItem) element;
		if ((aii.getCount() == 0) && (aii.getUnseen() == 0)) {
			return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
		}
	}
	return null; // Use default color
}
 
Example #20
Source File: BreadcrumbViewer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Color createColor( int color1, int color2, int ratio,
		Display display )
{
	RGB rgb1 = display.getSystemColor( color1 ).getRGB( );
	RGB rgb2 = display.getSystemColor( color2 ).getRGB( );

	RGB blend = FormColors.blend( rgb2, rgb1, ratio );

	return new Color( display, blend );
}
 
Example #21
Source File: StyleCombo.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setBackground( Color color )
{
	super.setBackground( color );
	background = color;
	if ( label != null )
		label.setBackground( color );
	if ( table != null )
		table.setBackground( color );
	if ( arrow != null )
		arrow.setBackground( color );
}
 
Example #22
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the color that should be used for the foreground.
 */
public Color getForegroundColor() {
    TextAttribute attribute = ColorManager.getDefault().getForegroundTextAttribute();
    if (attribute == null) {
        return null;
    }
    Color errorColor = attribute.getForeground();
    return errorColor;
}
 
Example #23
Source File: BreadcrumbItemDetails.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void updateSelection() {
  Color background;
  Color foreground;

  if (fSelected && fHasFocus) {
    background = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION);
    foreground = Display.getDefault().getSystemColor(
        SWT.COLOR_LIST_SELECTION_TEXT);
  } else {
    foreground = null;
    background = null;
  }

  if (isTextVisible()) {
    fTextComposite.setBackground(background);
    fElementText.setBackground(background);
    fElementText.setForeground(foreground);

    fImageComposite.setBackground(null);
    fElementImage.setBackground(null);
  } else {
    fImageComposite.setBackground(background);
    fElementImage.setBackground(background);

    fTextComposite.setBackground(null);
    fElementText.setBackground(null);
    fElementText.setForeground(null);
  }

  fTextComposite.redraw();
  fImageComposite.redraw();
}
 
Example #24
Source File: SWTResourceManager.java    From Rel with Apache License 2.0 5 votes vote down vote up
/**
 * Dispose of all the cached {@link Color}'s.
 */
public static void disposeColors() {
	for (Color color : m_colorMap.values()) {
		color.dispose();
	}
	m_colorMap.clear();
}
 
Example #25
Source File: NavigationPageGraphics.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private Color getBorderRectangleColor(boolean selected, boolean enabled,
		Color bg) {
	if (selected) {
		return selectedItemBorderColor;
	}
	if (!enabled) {
		return disabledItemBorderColor;
	}
	return itemBorderColor;
}
 
Example #26
Source File: CDateTime.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void setPickerActiveDayColor(Color pickerActiveDayColor) {
	checkWidget();
	this.pickerActiveDayColor = pickerActiveDayColor;
	if (picker != null) {
		picker.updateColorsAndFont();
	}
}
 
Example #27
Source File: GuiResource.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * @return Returns the colorBlueCustomGrid.
 */
public Color getColorBlueCustomGrid() {
  return colorBlueCustomGrid.getColor();
}
 
Example #28
Source File: GuiResource.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * @return Returns the colorYellow.
 */
public Color getColorYellow() {
  return colorYellow.getColor();
}
 
Example #29
Source File: GuiResource.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * @return Returns the colorTab.
 */
public Color getColorTab() {
  return colorTab.getColor();
}
 
Example #30
Source File: ColorThemeGrayBlue.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public Color getWeekdayBackgroundColorTop() {
	return ColorCache.getColor(236, 239, 244);
}