Java Code Examples for org.eclipse.swt.graphics.GC#setBackgroundPattern()

The following examples show how to use org.eclipse.swt.graphics.GC#setBackgroundPattern() . 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 File: BackgroundImagePainter.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	// Save GC settings
	Color originalBackground = gc.getBackground();
	Color originalForeground = gc.getForeground();

	gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bgImage));

	gc.fillRectangle(rectangle);
	gc.setBackgroundPattern(null);

	if (isNotNull(separatorColor)) {
		gc.setForeground(separatorColor);
		gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1, rectangle.y + rectangle.height);
		gc.drawLine(rectangle.x - 1 + rectangle.width, rectangle.y, rectangle.x - 1 + rectangle.width, rectangle.y + rectangle.height);
	}

	// Restore original GC settings
	gc.setBackground(originalBackground);
	gc.setForeground(originalForeground);

	// Draw interior
	Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4,	rectangle.height - 4);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
}
 
Example 2
Source File: PercentageBarDecorator.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	Color originalBackground = gc.getBackground();

	double factor = Math.min(1.0, ((Double) cell.getDataValue()).doubleValue());
	factor = Math.max(0.0, factor);

	Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int)(rectangle.width * factor), rectangle.height);
	Rectangle bounds = cell.getBounds();
	gc.setBackgroundPattern(new Pattern(Display.getCurrent(),
			bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
			GUIHelper.getColor(new RGB(187, 216, 254)),
			GUIHelper.getColor(new RGB(255, 255, 255))));
	gc.fillRectangle(bar);

	gc.setBackground(originalBackground);

	super.paintCell(cell, gc, rectangle, configRegistry);
}
 
Example 3
Source File: BackgroundImagePainter.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	// Save GC settings
	Color originalBackground = gc.getBackground();
	Color originalForeground = gc.getForeground();

	gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bgImage));

	gc.fillRectangle(rectangle);
	gc.setBackgroundPattern(null);

	if (isNotNull(separatorColor)) {
		gc.setForeground(separatorColor);
		gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1, rectangle.y + rectangle.height);
		gc.drawLine(rectangle.x - 1 + rectangle.width, rectangle.y, rectangle.x - 1 + rectangle.width, rectangle.y + rectangle.height);
	}

	// Restore original GC settings
	gc.setBackground(originalBackground);
	gc.setForeground(originalForeground);

	// Draw interior
	Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4,	rectangle.height - 4);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
}
 
Example 4
Source File: PercentageBarDecorator.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	Color originalBackground = gc.getBackground();

	double factor = Math.min(1.0, ((Double) cell.getDataValue()).doubleValue());
	factor = Math.max(0.0, factor);

	Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int)(rectangle.width * factor), rectangle.height);
	Rectangle bounds = cell.getBounds();
	gc.setBackgroundPattern(new Pattern(Display.getCurrent(),
			bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
			GUIHelper.getColor(new RGB(187, 216, 254)),
			GUIHelper.getColor(new RGB(255, 255, 255))));
	gc.fillRectangle(bar);

	gc.setBackground(originalBackground);

	super.paintCell(cell, gc, rectangle, configRegistry);
}
 
Example 5
Source File: PatternImageEditorDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static void drawItem( GC gc, PatternImage patternImage, int x,
		int y )
{
	int width = VIEW_WIDTH;
	int height = VIEW_HEIGHT;
	Device device = gc.getDevice( );
	Image image = createImageFromPattern( patternImage );
	Pattern pattern = new Pattern( device, image );
	gc.setBackgroundPattern( pattern );
	gc.fillRectangle( x, y, width, height );
	pattern.dispose( );
	image.dispose( );
}
 
Example 6
Source File: TabBar.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void onPaint(PaintEvent e)
    {
        GC gc = e.gc;
        
        int y = getBounds().height - barHeight;
        
        int totalWidth = horzMargin + (itemWidth * items.size()) + (itemSpacing * items.size()) - itemSpacing + horzMargin;
        int croppedWidth = Math.max(totalWidth,getBounds().width);
        
//        Region reg = createRoundedTopRegion(0,y,croppedWidth,getClientArea().height - y);

//        gc.setClipping(reg);

        Pattern p = new Pattern(getDisplay(), 0, y, 0, y + barHeight,
                                bottom, 255, getBackground(), 0);
        gc.setBackgroundPattern(p);
        
        gc.fillRectangle(0, y,croppedWidth, barHeight);
        
        p.dispose();
//        reg.dispose();
        
        gc.setClipping((Region)null);
        gc.setBackgroundPattern(null);
        
        
        int x = horzMargin; 
        if ((getStyle() & SWT.RIGHT) != 0)
        {
            if (getBounds().width > totalWidth)
            {
                x += getBounds().width - totalWidth;
            }
        }
        
        y = (getBounds().height - barHeight) - itemHeight;
        
        for (Iterator iterator = items.iterator(); iterator.hasNext();)
        {
            TabBarItem item = (TabBarItem)iterator.next();
            
            renderer.setBounds(new Rectangle(x,y,itemWidth,itemHeight));
            renderer.setSelected(item == selectedItem);
            renderer.paint(gc, item);
            
            x += itemWidth + itemSpacing;
        }
    }
 
Example 7
Source File: NebulaToolbar.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Paint widgets using Windows Seven mode on graphical canvas.
 * 
 * @param gc GC
 */
private void paintSeven(GC gc)
{
	Color defaultForeground = gc.getForeground();
	Color defaultBackground = gc.getBackground();

	Rectangle rect = getClientArea();
	Device device = gc.getDevice();

	Color c1 = new Color(device, 249, 252, 255);
	Color c2 = new Color(device, 230, 240, 250);
	Color c3 = new Color(device, 220, 230, 244);
	Color c4 = new Color(device, 221, 233, 247);

	Color ca = new Color(device, 205, 218, 234);
	Color cb = new Color(device, 160, 175, 195);

	int middle = (int) Math.ceil(rect.height / 2);

	Pattern patternBg1 = new Pattern(device, 0, 0, 0, middle, c1, c2);
	gc.setBackgroundPattern(patternBg1);
	gc.fillRectangle(new Rectangle(0, 0, rect.width, middle));
	gc.setBackgroundPattern(null);

	Pattern patternBg2 = new Pattern(device, 0, middle, 0, rect.height - middle, c3, c4);
	gc.setBackgroundPattern(patternBg2);
	gc.fillRectangle(new Rectangle(0, middle, rect.width, rect.height - middle));
	gc.setBackgroundPattern(null);

	gc.setForeground(ca);
	gc.drawLine(0, rect.height - 2, rect.width - 1, rect.height - 2);

	gc.setForeground(cb);
	gc.drawLine(0, rect.height - 1, rect.width - 1, rect.height - 1);

	gc.setForeground(defaultForeground);
	gc.setBackground(defaultBackground);
	gc.setAlpha(255);

	c1.dispose();
	c2.dispose();
	c3.dispose();
	c4.dispose();

	ca.dispose();
	cb.dispose();
}
 
Example 8
Source File: NebulaToolbar.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Paint widget using Windows Vista mode on graphical canvas.
 * 
 * @param gc GC
 */
private void paintVista(GC gc)
{
	Color defaultForeground = gc.getForeground();
	Color defaultBackground = gc.getBackground();

	Rectangle rect = getClientArea();
	Device device = gc.getDevice();

	Color c1 = new Color(device, 5, 72, 117);
	Color c2 = new Color(device, 25, 108, 119);
	Color c3 = new Color(device, 28, 122, 134);
	Color wh = getDisplay().getSystemColor(SWT.COLOR_WHITE);

	int middle = (int) Math.ceil(rect.height / 2);

	Pattern patternBg1 = new Pattern(device, 0, 0, rect.width, middle, c1, 255, c3, 255);
	gc.setBackgroundPattern(patternBg1);
	gc.fillRectangle(new Rectangle(0, 0, rect.width, middle));
	gc.setBackgroundPattern(null);

	Pattern patternBg2 = new Pattern(device, 0, middle, rect.width, rect.height - middle, c1, 255, c2, 255);
	gc.setBackgroundPattern(patternBg2);
	gc.fillRectangle(new Rectangle(0, middle, rect.width, rect.height - middle));
	gc.setBackgroundPattern(null);

	Pattern patternTopGrad = new Pattern(device, 0, 0, 0, middle, wh, 120, wh, 50);
	gc.setBackgroundPattern(patternTopGrad);
	gc.fillRectangle(new Rectangle(0, 0, rect.width, middle));
	gc.setBackgroundPattern(null);

	Pattern patternBtmGrad = new Pattern(device, 0, middle + 5, 0, rect.height, c1, 0, wh, 125);
	gc.setBackgroundPattern(patternBtmGrad);
	gc.fillRectangle(new Rectangle(0, middle + 5, rect.width, rect.height));
	gc.setBackgroundPattern(null);

	gc.setAlpha(125);
	gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
	gc.drawPolygon(new int[]{0, 0, rect.width - 1, 0, rect.width - 1, rect.height - 2, 0, rect.height - 2});

	gc.setAlpha(200);
	gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
	gc.drawLine(0, rect.height - 1, rect.width - 1, rect.height - 1);

	gc.setForeground(defaultForeground);
	gc.setBackground(defaultBackground);
	gc.setAlpha(255);

	c1.dispose();
	c2.dispose();
	c3.dispose();

	patternBg1.dispose();
	patternBg2.dispose();
	patternTopGrad.dispose();
	patternBtmGrad.dispose();
}
 
Example 9
Source File: LoginDialog.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create a default image. It is a port of the image used by the Login Box
 * in the project SwingX
 *
 * @param w width
 * @param h height
 * @return a default image (blue wave)
 */
private Image createDefaultImage(final int w, final int h) {
	final Display display = Display.getCurrent();
	final Color backgroundColor = new Color(display, 49, 121, 242);
	final Color gradientColor1 = new Color(display, 155, 185, 245);
	final Color gradientColor2 = new Color(display, 53, 123, 242);

	final Image img = new Image(display, w, h);
	final GC gc = new GC(img);
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setBackground(backgroundColor);
	gc.fillRectangle(0, 0, w, h);

	final Path curveShape = new Path(display);
	curveShape.moveTo(0, h * .6f);
	curveShape.cubicTo(w * .167f, h * 1.2f, w * .667f, h * -.5f, w, h * .75f);
	curveShape.lineTo(w, h);
	curveShape.lineTo(0, h);
	curveShape.lineTo(0, h * .8f);
	curveShape.close();

	final Pattern pattern = new Pattern(display, 0, 0, 1, h * 1.2f, gradientColor1, gradientColor2);
	gc.setBackgroundPattern(pattern);
	gc.fillPath(curveShape);

	final Font font = new Font(display, "Arial Bold", 30, SWT.NONE);
	gc.setFont(font);
	gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
	final Point textSize = gc.stringExtent(ResourceManager.getLabel(ResourceManager.LOGIN));
	gc.drawString(ResourceManager.getLabel(ResourceManager.LOGIN), (int) (w * .05f), (h - textSize.y) / 2, true);

	font.dispose();
	curveShape.dispose();
	pattern.dispose();
	backgroundColor.dispose();
	gradientColor1.dispose();
	gradientColor2.dispose();
	gc.dispose();
	return img;
}
 
Example 10
Source File: DataTableBackgroundImagePainter.java    From arx with Apache License 2.0 4 votes vote down vote up
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {

    if (this.bgImage != null) {
        
        // Save GC settings
        Color originalBackground = gc.getBackground();
        Color originalForeground = gc.getForeground();

        // Ugly hack
        Pattern pattern = new Pattern(Display.getCurrent(), getImage(rectangle.height));
        gc.setBackgroundPattern(pattern);

        gc.fillRectangle(rectangle);

        gc.setBackgroundPattern(null);
        pattern.dispose();

        if (isNotNull(this.separatorColor)) {
            gc.setForeground(this.separatorColor);
            gc.drawLine(
                    rectangle.x - 1,
                    rectangle.y,
                    rectangle.x - 1,
                    rectangle.y + rectangle.height);
            gc.drawLine(
                    rectangle.x - 1 + rectangle.width,
                    rectangle.y,
                    rectangle.x - 1 + rectangle.width,
                    rectangle.y + rectangle.height);
        }

        // Restore original GC settings
        gc.setBackground(originalBackground);
        gc.setForeground(originalForeground);
    }

    // Draw interior
    Rectangle interiorBounds = new Rectangle(
            rectangle.x + 2,
            rectangle.y + 2,
            rectangle.width - 4,
            rectangle.height - 4);
    super.paintCell(cell, gc, interiorBounds, configRegistry);
}