/** * This method draws the gradient patterns that make up the image. The image * consists of 4 rows, each consisting of 4 gradient patterns (total of 16). */ @Override public void paint(GC gc, int width, int height) { if (!example.checkAdvancedGraphics()) return; Device device = gc.getDevice(); Image image = createImage(device, colorGB1.getBgColor1(), colorGB2.getBgColor1(), width, height); Pattern p = new Pattern(device, image); gc.setBackgroundPattern(p); gc.fillRectangle(0, 0, width, height); p.dispose(); image.dispose(); }
/** * Creates an image based on a gradient pattern made up of two colors. * * @param device - The Device * @param color1 - The first color used to create the image * @param color2 - The second color used to create the image * * */ static Image createImage(Device device, Color color1, Color color2, int width, int height) { Image image = new Image(device, width, height); GC gc = new GC(image); Rectangle rect = image.getBounds(); Pattern pattern = new Pattern(device, rect.x, rect.y, rect.width - 1, rect.height - 1, color1, color2); gc.setBackgroundPattern(pattern); gc.fillRectangle(rect); gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); gc.dispose(); pattern.dispose(); return image; }
path.dispose(); if (pattern != null) pattern.dispose();
if (pattern != null) pattern.dispose();
void createCanvas(Composite parent) { int style = SWT.NO_BACKGROUND; if (dbItem.getSelection()) style |= SWT.DOUBLE_BUFFERED; canvas = new Canvas(parent, style); canvas.addListener(SWT.Paint, event -> { GC gc = event.gc; Rectangle rect = canvas.getClientArea(); Device device = gc.getDevice(); Pattern pattern = null; if (background.getBgColor1() != null) { if (background.getBgColor2() != null) { // gradient pattern = new Pattern(device, 0, 0, rect.width, rect.height, background.getBgColor1(), background.getBgColor2()); gc.setBackgroundPattern(pattern); } else { // solid color gc.setBackground(background.getBgColor1()); } } else if (background.getBgImage() != null) { // image pattern = new Pattern(device, background.getBgImage()); gc.setBackgroundPattern(pattern); } gc.fillRectangle(rect); GraphicsTab tab = getTab(); if (tab != null) tab.paint(gc, rect.width, rect.height); if (pattern != null) pattern.dispose(); }); }
pattern.dispose(); pattern = new Pattern(device, 0, 0, 50, height, device.getSystemColor(SWT.COLOR_DARK_CYAN), 0x7f, pattern.dispose(); pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_GREEN), 0x7f, pattern.dispose(); pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device.getSystemColor(SWT.COLOR_DARK_RED), 0x7f, gc.fillPath(path); gc.drawPath(path); pattern.dispose(); path.dispose();
if (pattern != null) pattern.dispose();
path.dispose(); if (pattern != null) pattern.dispose();
path.dispose(); if (pattern != null) pattern.dispose();
gc.drawLine(3*width/16, 4*height/6, 13*width/16, 4*height/6); if (pattern != null) pattern.dispose();
if (pattern != null) pattern.dispose();