org.eclipse.swt.graphics.Color类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(335)

本文整理了Java中org.eclipse.swt.graphics.Color类的一些代码示例,展示了Color类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Color类的具体详情如下:
包路径:org.eclipse.swt.graphics.Color
类名称:Color

Color介绍

[英]Instances of this class manage the operating system resources that implement SWT's RGB color model. To create a color you can either specify the individual color components as integers in the range 0 to 255 or provide an instance of an RGB or RGBA.

Application code must explicitly invoke the Color.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.
[中]此类的实例管理实现SWT的RGB颜色模型的操作系统资源。要创建颜色,可以将各个颜色组件指定为0到255范围内的整数,也可以提供RGBRGBA的实例。
当不再需要由每个实例管理的操作系统资源时,应用程序代码必须显式调用Color.dispose()方法来释放这些资源。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Get the image for when all other fallbacks have failed.  This is an image
 * drawn on the canvas, a square with a red X.
 *
 * @param display the device to render the image to
 * @return the missing image
 */
public static SwtUniversalImage getMissingImage( Display display ) {
 Image img = new Image( display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE );
 GC gc = new GC( img );
 gc.setForeground( new Color( display, 0, 0, 0 ) );
 gc.drawRectangle( 4, 4, ConstUI.ICON_SIZE - 8, ConstUI.ICON_SIZE - 8 );
 gc.setForeground( new Color( display, 255, 0, 0 ) );
 gc.drawLine( 4, 4, ConstUI.ICON_SIZE - 4, ConstUI.ICON_SIZE - 4 );
 gc.drawLine( ConstUI.ICON_SIZE - 4, 4, 4, ConstUI.ICON_SIZE - 4 );
 gc.dispose();
 return new SwtUniversalImageBitmap( img );
}

代码示例来源:origin: pentaho/pentaho-kettle

private Color getColor( int r, int g, int b ) {
 Color color = new Color( PropsUI.getDisplay(), new RGB( r, g, b ) );
 int index = colors.indexOf( color );
 if ( index < 0 ) {
  colors.add( color );
 } else {
  color.dispose();
  color = colors.get( index );
 }
 return color;
}

代码示例来源:origin: pentaho/pentaho-kettle

public void getData() {
 fixedFontData = props.getFixedFont();
 fixedFont = new Font( display, fixedFontData );
 graphFontData = props.getGraphFont();
 graphFont = new Font( display, graphFontData );
 noteFontData = props.getNoteFont();
 noteFont = new Font( display, noteFontData );
 backgroundRGB = props.getBackgroundRGB();
 if ( backgroundRGB == null ) {
  backgroundRGB = display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ).getRGB();
 }
 background = new Color( display, backgroundRGB );
 graphColorRGB = props.getGraphColorRGB();
 graphColor = new Color( display, graphColorRGB );
 tabColorRGB = props.getTabColorRGB();
 tabColor = new Color( display, tabColorRGB );
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Free the managed resource if it hasn't already been done and if this is not a system color
 *
 */
public void dispose() {
 // System color and already disposed off colors don't need to be disposed!
 if ( !systemColor && !color.isDisposed() ) {
  color.dispose();
 }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench

/**
 * Build a 1x1 px gray image to be used as separator. This color, halfway
 * between white and black, looks good both in Classic and in Dark Theme
 */
private Image getSeparatorBgImage() {
  Image backgroundImage = new Image(Display.getDefault(), 1, 1);
  GC gc = new GC(backgroundImage);
  gc.setBackground(new Color(dialog.getDisplay(), 127, 127, 127));
  gc.fillRectangle(0, 0, 1, 1);
  gc.dispose();
  return backgroundImage;
}

代码示例来源:origin: pentaho/pentaho-kettle

Object object = objects[index];
if ( object instanceof Color ) {
 if ( ( (Color) object ).isDisposed() ) {
  return;
 gc.setBackground( (Color) object );
 gc.fillRectangle( canvas.getClientArea() );
 return;
 if ( ( (Font) object ).isDisposed() ) {
  return;
 gc.setFont( (Font) object );
 FontData[] array = gc.getFont().getFontData();
 String string = "";
 String lf = text.getLineDelimiter();
 if ( ( (Image) object ).isDisposed() ) {
  return;

代码示例来源:origin: pentaho/pentaho-kettle

e.gc.drawImage( kettle_image, 0, 0 );
 fullVersionText =  fullVersionText + " "  + buildVersion;
e.gc.setFont( verFont );
e.gc.setForeground( new Color( display, 65, 65, 65 ) );
e.gc.drawText( fullVersionText, 290, 205, true );
e.gc.setFont( licFont );
e.gc.setForeground( new Color( display, 65, 65, 65 ) );
 licFontSize--;
 if ( licFont != null ) {
  licFont.dispose();
 licFont = new Font( e.display, "Helvetica", licFontSize, SWT.NORMAL );
 e.gc.setFont( licFont );
e.gc.setForeground( new Color( display, 65, 65, 65 ) );
e.gc.drawText( version, 290, 235, true );
e.gc.drawText( buildDate, 290, 250, true );

代码示例来源:origin: pentaho/pentaho-kettle

void initializeColors() {
 Display display = Display.getDefault();
 colors = new Color[] { new Color( display, new RGB( 0, 0, 0 ) ), // black
  new Color( display, new RGB( 63, 127, 95 ) ), // red
  new Color( display, new RGB( 0, 0, 192 ) ), // green
  new Color( display, new RGB( 127, 0, 85 ) ), // blue
  new Color( display, new RGB( 255, 102, 0 ) ) // Kettle 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;
}

代码示例来源:origin: pentaho/pentaho-kettle

private void drawVersionWarning( GC gc, Display display ) {
 gc.setBackground( versionWarningBackgroundColor );
 gc.setForeground( new Color( display, 65, 65, 65 ) );
 // gc.fillRectangle(290, 231, 367, 49);
 // gc.drawRectangle(290, 231, 367, 49);
 gc.drawImage( exclamation_image, 304, 243 );
 gc.setFont( devWarningFont );
 gc.drawText( BaseMessages.getString( PKG, "SplashDialog.DevelopmentWarning" ), 335, 241, true );
}

代码示例来源:origin: com.github.rinde/rinsim-problem

static Image createNewTransparentImg(Display d, int w, int h) {
 final Color white = d.getSystemColor(SWT.COLOR_WHITE);
 final Color black = d.getSystemColor(SWT.COLOR_BLACK);
 final PaletteData palette = new PaletteData(new RGB[] { white.getRGB(),
   black.getRGB() });
 final ImageData sourceData = new ImageData(w, h, 1, palette);
 sourceData.transparentPixel = 0;
 return new Image(d, sourceData);
}

代码示例来源:origin: pentaho/pentaho-kettle

private Color getDisabledColor() {
 Device device = Display.getCurrent();
 return new Color( device, 188, 188, 188 );
}

代码示例来源:origin: com.github.insubstantial/trident

Color getInterpolatedColor(Color color1, Color color2,
      float color1Likeness) {
    if (color1.equals(color2))
      return color1;
    if (color1Likeness == 1.0)
      return color1;
    if (color1Likeness == 0.0)
      return color2;
    return new Color(Display.getDefault(), getInterpolatedRGB(color1,
        color2, color1Likeness));
  }
}

代码示例来源:origin: stackoverflow.com

Color color2 = new Color(display, 255, 255, 255);
  try {
    gc.setForeground(color1);
    gc.setBackground(color2);
    gc.fillGradientRectangle(rect.x, rect.y, rect.width,
        rect.height, true);
  } finally {
    color2.dispose();
  color1.dispose();
oldImage.dispose();
imageGradient.dispose();

代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.jface

private void initializeDefaultColors() {
   // TODO This is temporary.
   // These should be initialized by the workbench theme, but not yet.
   // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133731
   Display display = Display.getCurrent();
   colorRegistry.put(JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR,
       display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
   colorRegistry.put(JFacePreferences.CONTENT_ASSIST_FOREGROUND_COLOR,
       display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB());
 }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.linux.s390x

/**
 * Returns a string containing a concise, human-readable
 * description of the receiver.
 *
 * @return a string representation of the receiver
 */
@Override
public String toString () {
  if (isDisposed()) return "Color {*DISPOSED*}";
  return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + ", " + getAlpha() +"}";
}

代码示例来源:origin: pentaho/pentaho-kettle

public void widgetSelected( SelectionEvent e ) {
  ColorDialog cd = new ColorDialog( shell );
  cd.setText( BaseMessages.getString( PKG, "NotePadDialog.Font.Color.Dialog.Label" ) );
  cd.setRGB( wBorderColor.getBackground().getRGB() );
  RGB newColor = cd.open();
  if ( newColor == null ) {
   return;
  }
  borderColor.dispose();
  borderColor = new Color( shell.getDisplay(), newColor );
  wBorderColor.setBackground( borderColor );
 }
} );

代码示例来源:origin: org.eclipse.pde/org.eclipse.pde.ui

private void putColor(String property, RGB setting) {
  Color oldColor = fColorTable.get(property);
  if (oldColor != null) {
    if (oldColor.getRGB().equals(setting))
      return;
    oldColor.dispose();
  }
  fColorTable.put(property, new Color(Display.getCurrent(), setting));
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

@Override
public void widgetDisposed(DisposeEvent event) {
  if (fStatusTextFont != null && !fStatusTextFont.isDisposed())
    fStatusTextFont.dispose();
  fStatusTextFont= null;
  if (fStatusTextForegroundColor != null && !fStatusTextForegroundColor.isDisposed())
    fStatusTextForegroundColor.dispose();
  fStatusTextForegroundColor= null;
  fTextFont= null;
  fShell= null;
  fText= null;
}

代码示例来源:origin: pentaho/pentaho-kettle

public void widgetDisposed( DisposeEvent arg0 ) {
  kettle_image.dispose();
  kettle_icon.dispose();
  exclamation_image.dispose();
  verFont.dispose();
  licFont.dispose();
  devWarningFont.dispose();
  versionWarningForegroundColor.dispose();
  versionWarningBackgroundColor.dispose();
 }
} );

代码示例来源:origin: pentaho/pentaho-kettle

public void dispose() {
 gc.dispose();
 if ( transform != null && transform.isDisposed() == false ) {
  transform.dispose();
 }
 for ( Color color : colors ) {
  color.dispose();
 }
 for ( Font font : fonts ) {
  font.dispose();
 }
}

相关文章