本文整理了Java中org.eclipse.swt.graphics.GC
类的一些代码示例,展示了GC
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GC
类的具体详情如下:
包路径:org.eclipse.swt.graphics.GC
类名称:GC
[英]Class GC
is where all of the drawing capabilities that are supported by SWT are located. Instances are used to draw on either an Image
, a Control
, or directly on a Display
. Styles: LEFT_TO_RIGHT, RIGHT_TO_LEFT
The SWT drawing coordinate system is the two-dimensional space with the origin (0,0) at the top left corner of the drawing area and with (x,y) values increasing to the right and downward respectively.
The result of drawing on an image that was created with an indexed palette using a color that is not in the palette is platform specific. Some platforms will match to the nearest color while other will draw the color itself. This happens because the allocated image might use a direct palette on platforms that do not support indexed palette.
Application code must explicitly invoke the GC.dispose()
method to release the operating system resources managed by each instance when those instances are no longer required. This is particularly important on Windows95 and Windows98 where the operating system has a limited number of device contexts available.
Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
[中]类GC
是SWT支持的所有绘图功能所在的位置。实例用于在Image
、Control
或直接在Display
上绘制。样式:从左到右,从右到左
SWT图形坐标系是二维空间,原点(0,0)位于绘图区域的左上角,(x,y)值分别向右和向下增加。
在使用索引调色板创建的图像上使用调色板中不存在的颜色进行绘制的结果是平台特定的。一些平台将匹配最近的颜色,而其他平台将绘制颜色本身。这是因为分配的映像可能在不支持索引调色板的平台上使用直接调色板。
当不再需要由每个实例管理的操作系统资源时,应用程序代码必须显式调用GC.dispose()
方法来释放这些资源。这在Windows95和Windows98上尤其重要,因为操作系统的可用设备上下文数量有限。
注意:只能指定左至右和右至左中的一个。
代码示例来源:origin: pentaho/pentaho-kettle
@Override
protected Image renderSimple( Device device, int width, int height ) {
int xsize = bitmap.getBounds().width;
int ysize = bitmap.getBounds().height;
Image result = new Image( device, width, height );
GC gc = new GC( result );
gc.drawImage( bitmap, 0, 0, xsize, ysize, 0, 0, width, height );
gc.dispose();
return result;
}
代码示例来源:origin: pentaho/pentaho-kettle
public void paintControl( final PaintEvent event ) {
if ( transGraph.trans != null && transGraph.trans.isFinished() ) {
refreshImage( event.gc );
if ( image != null && !image.isDisposed() ) {
event.gc.drawImage( image, 0, 0 );
}
} else {
Rectangle bounds = canvas.getBounds();
if ( bounds.width <= 0 || bounds.height <= 0 ) {
return;
}
event.gc.setForeground( GUIResource.getInstance().getColorWhite() );
event.gc.setBackground( GUIResource.getInstance().getColorWhite() );
event.gc.fillRectangle( new Rectangle( 0, 0, bounds.width, bounds.height ) );
event.gc.setForeground( GUIResource.getInstance().getColorBlack() );
String metricsMessage =
BaseMessages.getString( PKG, "TransMetricsDelegate.TransformationIsNotRunning.Message" );
org.eclipse.swt.graphics.Point extent = event.gc.textExtent( metricsMessage );
event.gc.drawText( metricsMessage, ( bounds.width - extent.x ) / 2, ( bounds.height - extent.y ) / 2 );
}
}
} );
代码示例来源: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: pentaho/pentaho-kettle
private void drawMarker( GC gc, int x, int maxy ) {
int[] triangle =
new int[] {
LEFT + MARGIN + x * fontwidth + offset.x, TOP - 4, LEFT + MARGIN + x * fontwidth + offset.x + 3,
TOP + 1, LEFT + MARGIN + x * fontwidth + offset.x - 3, TOP + 1 };
gc.fillPolygon( triangle );
gc.drawPolygon( triangle );
gc
.drawLine(
LEFT + MARGIN + x * fontwidth + offset.x, TOP + 1, LEFT + MARGIN + x * fontwidth + offset.x, maxy );
}
代码示例来源:origin: pentaho/pentaho-kettle
public void switchForegroundBackgroundColors() {
Color fg = gc.getForeground();
Color bg = gc.getBackground();
gc.setForeground( bg );
gc.setBackground( fg );
}
代码示例来源:origin: pentaho/pentaho-kettle
public void drawUp( GC gc ) {
if ( hover_up ) {
gc.setBackground( gray );
gc.fillRectangle( size_up );
}
gc.drawRectangle( size_up );
gc.drawText( STRING_UP, size_up.x + 1 + offsetx, size_up.y + 1 + offsety, SWT.DRAW_TRANSPARENT );
}
代码示例来源:origin: pentaho/pentaho-kettle
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN );
props.setLook( shell );
setShellImage( shell, input );
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout( formLayout );
shell.setText( BaseMessages.getString( PKG, "MonetDBBulkLoaderDialog.Shell.Title" ) );
.setText( BaseMessages.getString( PKG, "MonetDBBulkLoaderDialog.Tab.GeneralSettings.Label" ) );
wGeneralSettingsComp = new Composite( wTabFolder, SWT.NONE );
props.setLook( wGeneralSettingsComp );
wGeneralSettingsComp.layout();
wGeneralSettingsTab.setControl( wGeneralSettingsComp );
GC gc = new GC( text );
FontMetrics fm = gc.getFontMetrics();
int charWidth = fm.getAverageCharWidth();
int fieldWidth = text.computeSize( charWidth * 20, SWT.DEFAULT ).x;
gc.dispose();
代码示例来源:origin: stackoverflow.com
composite.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
changeImage();
composite.setLayout(new FormLayout());
composite.setBackgroundMode(SWT.INHERIT_DEFAULT);
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 {
gc.dispose();
composite.setBackgroundImage(imageGradient);
oldImage.dispose();
imageGradient.dispose();
代码示例来源:origin: stackoverflow.com
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new FillLayout());
treeItem.setText(String.format("item %d long name", i));
tree.addListener(SWT.DefaultSelection, new Listener() {
@Override
public void handleEvent(Event event) {
loader.data = new ImageData[]{image.getImageData()};
final String pathToSave = "out.png";
System.out.println(new File(pathToSave).getAbsolutePath());
loader.save(pathToSave, SWT.IMAGE_PNG);
gc.dispose();
image.dispose();
tree.getParent().setRedraw(true);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
代码示例来源:origin: stackoverflow.com
Display display = new Display ();
Shell shell = new Shell (display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
shell.setLayout(new FillLayout ());
final Image image = new Image(display, "C:\\temp\\flyimage1.png");
shell.addListener (SWT.Paint, new Listener ()
gc.drawImage (image, x, y);
gc.dispose();
shell.setSize (600, 400);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
if(image != null && !image.isDisposed())
image.dispose();
display.dispose ();
代码示例来源:origin: stackoverflow.com
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
final Image image = display.getSystemImage(SWT.ICON_ERROR);
final String text = "Button";
float fontHeight = shell.getFont().getFontData()[0].height;
data.heightHint = image.getImageData().height + (int)fontHeight + 20;
data.widthHint = 100;
button.addListener(SWT.Paint, new Listener() {
Point textSize = gc.textExtent(text);
gc.drawText(text, width / 2 - textSize.x / 2, image.getImageData().height - image.getImageData().height / 2 - textSize.y, true);
gc.drawImage(image, width / 2 - image.getImageData().width / 2, height / 2 - image.getImageData().height / 2 + textSize.y / 2);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
代码示例来源:origin: org.eclipse.swt.cocoa.macosx/x86_64
public void setBackground (Color color) {
super.setBackground(color);
table.setBackground(color);
if (sizeImage != null) {
GC gc = new GC (sizeImage);
gc.setBackground(getBackground());
Rectangle size = sizeImage.getBounds();
gc.fillRectangle(size);
gc.dispose();
}
}
public void setEnabled (boolean enabled) {
代码示例来源:origin: pentaho/pentaho-kettle
public void paintControl( PaintEvent e ) {
Point area = getArea();
if ( area.x == 0 || area.y == 0 ) {
return; // nothing to do!
}
Display disp = shell.getDisplay();
Image img = getTransformationImage( disp, area.x, area.y, magnification );
e.gc.drawImage( img, 0, 0 );
if ( transMeta.nrSteps() == 0 ) {
e.gc.setForeground( GUIResource.getInstance().getColorCrystalTextPentaho() );
e.gc.setFont( GUIResource.getInstance().getFontMedium() );
Image pentahoImage = GUIResource.getInstance().getImageTransCanvas();
int leftPosition = ( area.x - pentahoImage.getBounds().width ) / 2;
int topPosition = ( area.y - pentahoImage.getBounds().height ) / 2;
e.gc.drawImage( pentahoImage, leftPosition, topPosition );
}
img.dispose();
// spoon.setShellText();
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args)
{
final Display display = Display.getDefault();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
GC gc = new GC(display);
System.out.println(gc.textExtent("Hi").y);
gc.dispose();
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench
@Override
public void initialize(AnimationEngine engine) {
display = getAnimationShell().getDisplay();
Rectangle psRect = getAnimationShell().getBounds();
theShell = new Shell(getAnimationShell(), SWT.NO_TRIM | SWT.ON_TOP);
theShell.setBounds(getAnimationShell().getBounds());
// Capture the background image
backingStore = new Image(theShell.getDisplay(), psRect);
GC gc = new GC(display);
gc.copyArea(backingStore, psRect.x, psRect.y);
gc.dispose();
// changeCoordinates();
// captureImages();
theShell.setBackgroundImage(backingStore);
theShell.setVisible(true);
display.update();
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.e4.ui.workbench.addons.swt
public Overlay(Shell shell) {
baseShell = shell;
Rectangle cr = baseShell.getClientArea();
Rectangle trim = baseShell.computeTrim(cr.x, cr.y, cr.width, cr.height);
offsetX = -trim.x;
offsetY = -trim.y;
overlayShell = new Shell(baseShell, SWT.NO_TRIM | SWT.ON_TOP);
overlayShell.setBounds(baseShell.getBounds());
overlayShell.setBackground(baseShell.getDisplay().getSystemColor(
SWT.COLOR_DARK_GREEN));
overlayShell.setAlpha(128);
blue = new Color(baseShell.getDisplay(), 0, 0, 128);
overlayShell.addPaintListener(e -> {
e.gc.setForeground(blue);
e.gc.setBackground(blue);
for (Adornment adornment : adornments) {
adornment.drawAdornment(e.gc);
}
});
}
代码示例来源:origin: pentaho/pentaho-kettle
public void printImage( Shell sh, Image img ) {
if ( printerdata != null ) {
Rectangle imgbounds = img.getBounds();
Point max = new Point( imgbounds.width, imgbounds.height );
Point dpi_screen = Display.getCurrent().getDPI();
GC gc_printer = new GC( printer );
gc_printer.drawImage(
img, fromx, fromy, imx, imy, (int) page_left, (int) page_top, (int) printx, (int) printy );
System.out.println( "img dept = " + img.getImageData().depth );
System.out.println( "prn dept = " + printer.getDepth() );
System.out.println( "img size = ("
+ img.getBounds().x + "," + img.getBounds().y + ") : (" + img.getBounds().width + ","
+ img.getBounds().height + ")" );
System.out.println( "fromx="
gc_printer.dispose();
代码示例来源:origin: caoxinyu/RedisClient
/**
* @return the small {@link Image} that can be used as placeholder for missing image.
*/
private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
//
GC gc = new GC(image);
gc.setBackground(getColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
gc.dispose();
//
return image;
}
/**
代码示例来源: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: org.eclipse.jdt/org.eclipse.jdt.ui
public PixelConverter(Font font) {
GC gc = new GC(font.getDevice());
gc.setFont(font);
fFontMetrics= gc.getFontMetrics();
gc.dispose();
}
内容来源于网络,如有侵权,请联系作者删除!