Java Code Examples for org.eclipse.swt.graphics.Color#getDevice()

The following examples show how to use org.eclipse.swt.graphics.Color#getDevice() . These examples are extracted from open source projects. 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: hop   File: PropsUi.java    License: Apache License 2.0 4 votes vote down vote up
public void setLook( final Control control, int style ) {
  if ( this.isOSLookShown() && style != WIDGET_STYLE_FIXED ) {
    return;
  }

  final GuiResource gui = GuiResource.getInstance();
  Font font = null;
  Color background = null;

  switch ( style ) {
    case WIDGET_STYLE_DEFAULT:
      background = gui.getColorBackground();
      if ( control instanceof Group && OS.indexOf( "mac" ) > -1 ) {
        control.addPaintListener( paintEvent -> {
          paintEvent.gc.setBackground( gui.getColorBackground() );
          paintEvent.gc.fillRectangle( 2, 0, control.getBounds().width - 8, control.getBounds().height - 20 );
        } );
      }
      font = null; // GuiResource.getInstance().getFontDefault();
      break;
    case WIDGET_STYLE_FIXED:
      if ( !this.isOSLookShown() ) {
        background = gui.getColorBackground();
      }
      font = gui.getFontFixed();
      break;
    case WIDGET_STYLE_TABLE:
      background = gui.getColorBackground();
      font = null; // gui.getFontGrid();
      break;
    case WIDGET_STYLE_NOTEPAD:
      background = gui.getColorBackground();
      font = gui.getFontNote();
      break;
    case WIDGET_STYLE_GRAPH:
      background = gui.getColorBackground();
      font = gui.getFontGraph();
      break;
    case WIDGET_STYLE_TOOLBAR:
      background = GuiResource.getInstance().getColorDemoGray();
      break;
    case WIDGET_STYLE_TAB:
      background = GuiResource.getInstance().getColorWhite();
      CTabFolder tabFolder = (CTabFolder) control;
      tabFolder.setSimple( false );
      tabFolder.setBorderVisible( true );
      // need to make a copy of the tab selection background color to get around PDI-13940
      Color c = GuiResource.getInstance().getColorTab();
      Color tabColor = new Color( c.getDevice(), c.getRed(), c.getGreen(), c.getBlue() );
      tabFolder.setSelectionBackground( tabColor );
      break;
    default:
      background = gui.getColorBackground();
      font = null; // gui.getFontDefault();
      break;
  }

  if ( font != null && !font.isDisposed() ) {
    control.setFont( font );
  }

  if ( background != null && !background.isDisposed() ) {
    if ( control instanceof Button ) {
      Button b = (Button) control;
      if ( ( b.getStyle() & SWT.PUSH ) != 0 ) {
        return;
      }
    }
    control.setBackground( background );
  }
}
 
Example 2
Source Project: Rel   File: PercentDisplay.java    License: Apache License 2.0 4 votes vote down vote up
private static Color redder(Color c) {
	return new Color(c.getDevice(), cr(c.getRed() + 30), cr(c.getGreen() - 30), cr(c.getBlue() - 30));
}
 
Example 3
Source Project: Rel   File: PercentDisplay.java    License: Apache License 2.0 4 votes vote down vote up
private static Color yellower(Color c) {
	return new Color(c.getDevice(), cr(c.getRed() + 30), cr(c.getGreen() + 30), cr(c.getBlue() - 30));
}
 
Example 4
Source Project: Rel   File: PercentDisplay.java    License: Apache License 2.0 4 votes vote down vote up
private static Color greener(Color c) {
	return new Color(c.getDevice(), cr(c.getRed() - 30), cr(c.getGreen() + 30), cr(c.getBlue() - 30));		
}
 
Example 5
Source Project: e4macs   File: Flasher.java    License: Eclipse Public License 1.0 4 votes vote down vote up
static Color invertColor(Color c) {
	RGB rgb = c.getRGB();
	return new Color(c.getDevice(), 255 - rgb.red, 255 - rgb.green, 255 - rgb.blue);
}
 
Example 6
Source Project: pentaho-kettle   File: PropsUI.java    License: Apache License 2.0 4 votes vote down vote up
public void setLook( final Control control, int style ) {
  if ( this.isOSLookShown() && style != WIDGET_STYLE_FIXED ) {
    return;
  }

  final GUIResource gui = GUIResource.getInstance();
  Font font = null;
  Color background = null;

  switch ( style ) {
    case WIDGET_STYLE_DEFAULT:
      background = gui.getColorBackground();
      if ( control instanceof Group && OS.indexOf( "mac" ) > -1 ) {
        control.addPaintListener( new PaintListener() {
          @Override
          public void paintControl( PaintEvent paintEvent ) {
            paintEvent.gc.setBackground( gui.getColorBackground() );
            paintEvent.gc.fillRectangle( 2, 0, control.getBounds().width - 8, control.getBounds().height - 20 );
          }
        } );
      }
      font = null; // GUIResource.getInstance().getFontDefault();
      break;
    case WIDGET_STYLE_FIXED:
      if ( !this.isOSLookShown() ) {
        background = gui.getColorBackground();
      }
      font = gui.getFontFixed();
      break;
    case WIDGET_STYLE_TABLE:
      background = gui.getColorBackground();
      font = null; // gui.getFontGrid();
      break;
    case WIDGET_STYLE_NOTEPAD:
      background = gui.getColorBackground();
      font = gui.getFontNote();
      break;
    case WIDGET_STYLE_GRAPH:
      background = gui.getColorBackground();
      font = gui.getFontGraph();
      break;
    case WIDGET_STYLE_TOOLBAR:
      background = GUIResource.getInstance().getColorDemoGray();
      break;
    case WIDGET_STYLE_TAB:
      background = GUIResource.getInstance().getColorWhite();
      CTabFolder tabFolder = (CTabFolder) control;
      tabFolder.setSimple( false );
      tabFolder.setBorderVisible( true );
      // need to make a copy of the tab selection background color to get around PDI-13940
      Color c = GUIResource.getInstance().getColorTab();
      Color tabColor = new Color( c.getDevice(), c.getRed(), c.getGreen(), c.getBlue() );
      tabFolder.setSelectionBackground( tabColor );
      break;
    default:
      background = gui.getColorBackground();
      font = null; // gui.getFontDefault();
      break;
  }

  if ( font != null && !font.isDisposed() ) {
    control.setFont( font );
  }

  if ( background != null && !background.isDisposed() ) {
    if ( control instanceof Button ) {
      Button b = (Button) control;
      if ( ( b.getStyle() & SWT.PUSH ) != 0 ) {
        return;
      }
    }
    control.setBackground( background );
  }
}
 
Example 7
Source Project: tracecompass   File: Utils.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Get the system color with the given ID.
 *
 * @param id
 *            The color ID
 * @return The resulting color
 */
public static Color getSysColor(int id) {
    Color col = Display.getCurrent().getSystemColor(id);
    return new Color(col.getDevice(), col.getRGB());
}
 
Example 8
/**
 * Calculates a mixed color from two colors by interpolating the rgb parts
 * using a mix ratio.
 * 
 * @param baseColor
 * @param mixinColor
 * @param ratio
 *            a value from 0 to 255 that defines the mix ratio. Using 0 will
 *            return the base color and 255 the mixin color.
 * @return
 */
public static Color mixColor(Color baseColor, Color mixinColor, int ratio) {
	return new Color(baseColor.getDevice(), baseColor.getRed() + (mixinColor.getRed() - baseColor.getRed()) * ratio
			/ 255, baseColor.getGreen() + (mixinColor.getGreen() - baseColor.getGreen()) * ratio / 255,
			baseColor.getBlue() + (mixinColor.getBlue() - baseColor.getBlue()) * ratio / 255);
}
 
Example 9
Source Project: saros   File: ColorUtils.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Increases a color's lightness
 *
 * @param color
 * @param lightness by which the color's lightness should be increased;<br>
 *     range: -1 (results in black) to +1 (+1 results in white)
 * @return the new color
 *     <p>Note: Please keep in mind that a <strong>new</strong> color is created. Both the already
 *     existing and the scaled need to be disposed after usage!
 * @see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV">HSL and HSV</a>
 */
public static Color addLightness(Color color, float lightness) {
  RGB newRGB = addLightness(color.getRGB(), lightness);
  Color newColor = new Color(color.getDevice(), newRGB);
  return newColor;
}
 
Example 10
Source Project: saros   File: ColorUtils.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Scales a color's lightness; the higher the ratio the lighter the color
 *
 * @param color to be scaled
 * @param scale non-negative whereas 0 results in zero lightness = black color
 * @return the scaled color
 *     <p>Note: Please keep in mind that a <strong>new</strong> color is created. Both the already
 *     existing and the scaled need to be disposed after usage!
 * @see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV">HSL and HSV</a>
 */
public static Color scaleColorBy(Color color, float scale) {
  RGB scaledRGB = scaleColorBy(color.getRGB(), scale);
  Color newColor = new Color(color.getDevice(), scaledRGB);
  return newColor;
}