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 Project: n4js   Author: eclipse   File: SpecProcessPage.java    License: 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 Project: translationstudio8   Author: heartsome   File: RiskRenderer.java    License: 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 #3
Source Project: pentaho-kettle   Author: pentaho   File: MDXValuesHighlight.java    License: 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 Project: statecharts   Author: Yakindu   File: AbstractDynamicNotationHandler.java    License: 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 #5
Source Project: n4js   Author: eclipse   File: TestProgressBar.java    License: 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 Project: tracecompass   Author: tracecompass   File: TimeGraphBaseControl.java    License: 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 #7
Source Project: neoscada   Author: eclipse   File: FigureController.java    License: 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 #8
Source Project: hop   Author: project-hop   File: UserDefinedJavaClassHighlight.java    License: 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 #9
Source Project: uima-uimaj   Author: apache   File: TextColorDrawingStrategy.java    License: 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 #10
Source Project: tlaplus   Author: tlaplus   File: CoverageLabelProvider.java    License: 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 #11
Source Project: nebula   Author: eclipse   File: TimelineViewer.java    License: 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 #12
Source Project: pentaho-kettle   Author: pentaho   File: RepositoryDirectoryUI.java    License: 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 #13
Source Project: tmxeditor8   Author: heartsome   File: UpdateDescriptionPage.java    License: 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 #14
Source Project: nebula   Author: eclipse   File: Gallery.java    License: 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 #15
Source Project: jdt-codemining   Author: angelozerr   File: AbstractDebugVariableCodeMining.java    License: 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 #16
Source Project: tm4e   Author: eclipse   File: CSSTokenProvider.java    License: 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 #17
Source Project: nebula   Author: eclipse   File: DefaultTimelineLabelProvider.java    License: 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 #18
Source Project: http4e   Author: nextinterfaces   File: ParamTable.java    License: 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 Project: tmxeditor8   Author: heartsome   File: ObjectImageRenderer.java    License: 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 #20
Source Project: birt   Author: eclipse   File: BreadcrumbViewer.java    License: 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 Project: birt   Author: eclipse   File: StyleCombo.java    License: 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 Project: Pydev   Author: fabioz   File: PyUnitView.java    License: 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 Project: gwt-eclipse-plugin   Author: gwt-plugins   File: BreadcrumbItemDetails.java    License: 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 Project: Rel   Author: DaveVoorhis   File: SWTResourceManager.java    License: 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 Project: nebula   Author: eclipse   File: NavigationPageGraphics.java    License: 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 Project: nebula   Author: eclipse   File: CDateTime.java    License: 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 Project: BiglyBT   Author: BiglySoftware   File: Plot3D.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void
initialize(
	Canvas 		_canvas )
{
	canvas 	= _canvas;

	Device device = canvas.getDisplay();

	colours = new Color[16];

	HSLColor hsl = new HSLColor();

	hsl.initHSLbyRGB( 130,240,240 );

	int	step = 128 / colours.length;

	int	hue = colours.length * step;

	for (int i=0;i<colours.length;i++){

		hsl.setHue( hue );

		hue -= step;

		colours[i] = new Color( device, hsl.getRed(), hsl.getGreen(), hsl.getBlue());
	}
	
	canvas.addPaintListener(new PaintListener() {

		@Override
		public void paintControl(PaintEvent e) {
			if (bufferImage != null && !bufferImage.isDisposed()) {
				Rectangle bounds = bufferImage.getBounds();
				if (bounds.width >= ( e.width + e.x ) && bounds.height >= ( e.height + e.y )) {

					e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y,
							e.width, e.height);
				}
			}
		}
	});

	canvas.addListener(SWT.Resize, new Listener() {
		@Override
		public void handleEvent(Event event) {
			drawPlot();
		}
	});
}
 
Example #28
Source Project: gama   Author: gama-platform   File: GamaColors.java    License: GNU General Public License v3.0 4 votes vote down vote up
public GamaUIColor(final Color c) {
	active = c;
}
 
Example #29
Source Project: nebula   Author: eclipse   File: ColorThemeSilver.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public Color getSundayBackgroundColorTop() {
    return getSaturdayBackgroundColorTop();
}
 
Example #30
Source Project: nebula   Author: eclipse   File: ColorThemeSilver.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public Color getWeekdayBackgroundColorBottom() {
    return ColorCache.getColor(240, 240, 240);
}