org.eclipse.swt.graphics.Pattern Java Examples

The following examples show how to use org.eclipse.swt.graphics.Pattern. 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: 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 #2
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 #3
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 #4
Source File: GaugeFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	Pattern pattern = null;
	graphics.setBackgroundColor(GRAY_COLOR);
	if(support3D == null)
		support3D = GraphicsUtil.testPatternSupported(graphics);
	if(effect3D && support3D){		
			pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), bounds.x, bounds.y,
					bounds.x + bounds.width, bounds.y + bounds.height, WHITE_COLOR, BORDER_COLOR);
			graphics.setBackgroundPattern(pattern);							
	}			
	super.fillShape(graphics);
	if(effect3D && support3D)
		pattern.dispose();			
}
 
Example #5
Source File: CollapsableEventSubprocessFigure.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	if(useGradient){
		Rectangle r = getBounds().getCopy();
		Point topLeft = r.getTopLeft();
		Point bottomRight = r.getBottomRight();
		Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x +2,
				topLeft.y+2 , bottomRight.x-2, bottomRight.y-2,gradientColor,255,getBackgroundColor(),90);
		graphics.setBackgroundPattern(pattern);
		graphics.fillRectangle(r.crop(new Insets(2,2,2,2)));
		graphics.setBackgroundPattern(null);
		pattern.dispose();
	}else{
		super.fillShape(graphics) ;
	}

}
 
Example #6
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 #7
Source File: KnobFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	Pattern pattern = null;
	graphics.setBackgroundColor(thumbColor);
	boolean support3D = GraphicsUtil.testPatternSupported(graphics);
	if(support3D && effect3D){
		try {
			graphics.setBackgroundColor(thumbColor);
			super.fillShape(graphics);
			pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), bounds.x, bounds.y,
					bounds.x + bounds.width, bounds.y + bounds.height, 
					WHITE_COLOR, 0, WHITE_COLOR, 255);
			graphics.setBackgroundPattern(pattern);
		} catch (Exception e) {
			support3D = false;
			pattern.dispose();
		}				
	}			
	super.fillShape(graphics);
	if(effect3D && support3D)
		pattern.dispose();
	graphics.setForegroundColor(thumbColor);
}
 
Example #8
Source File: Bulb.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintClientArea(Graphics graphics) {		
	graphics.setAntialias(SWT.ON);
	
	if(effect3D && GraphicsUtil.testPatternSupported(graphics)) {			
		// Fills the circle with solid bulb color
        graphics.setBackgroundColor(bulbColor);
        graphics.fillOval(bounds);
        
		//diagonal linear gradient
			Pattern p = new Pattern(Display.getCurrent(), bounds.x,	bounds.y,
					bounds.x + getWidth(), bounds.y + getHeight(),
					COLOR_WHITE, 255, bulbColor, 0);
        try {				
			graphics.setBackgroundPattern(p);
			graphics.fillOval(bounds);		
			p.dispose();
		} catch (Exception e) {
			p.dispose();				
		}
		
	} else {			
		graphics.setBackgroundColor(bulbColor);
		graphics.fillOval(bounds);
	}		
	
	super.paintClientArea(graphics);
}
 
Example #9
Source File: ScaledSliderFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics g) {	
	g.setAntialias(SWT.ON);
	g.setClip(new Rectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height));
	g.setBackgroundColor(WHITE_COLOR);
	super.fillShape(g);
	Point leftPoint = getPoints().getPoint(0);
	Point rightPoint;
	if(horizontal) 
		rightPoint = getPoints().getPoint(4);
	else
		rightPoint = getPoints().getPoint(1);//.translate(0, -BREADTH/2);
	Pattern thumbPattern = null;
	boolean support3D = GraphicsUtil.testPatternSupported(g);
	if(effect3D && support3D) {
		thumbPattern = GraphicsUtil.createScaledPattern(g, Display.getCurrent(),
			leftPoint.x, leftPoint.y, rightPoint.x, rightPoint.y, WHITE_COLOR, 0, 
			thumbColor, 255);
		g.setBackgroundPattern(thumbPattern);		
	}else
		g.setBackgroundColor(thumbColor);
		
	g.fillPolygon(getPoints());
	
	if(effect3D && support3D)
		thumbPattern.dispose();
			
}
 
Example #10
Source File: ThermometerFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	boolean support3D = false;
	if(effect3D)
		 support3D = GraphicsUtil.testPatternSupported(graphics);
	
	if(effect3D && support3D){
		graphics.setBackgroundColor(fillColor);
		super.fillShape(graphics);
		//int l = (int) ((bounds.width - lineWidth)*0.293/2);
		Pattern backPattern = null;
		
		 backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
			bounds.x + lineWidth, bounds.y + lineWidth, 
			bounds.x+bounds.width-lineWidth, bounds.y+bounds.height-lineWidth,
			WHITE_COLOR,255, fillColor, 0);			
		graphics.setBackgroundPattern(backPattern);
		super.fillShape(graphics);
		backPattern.dispose();
		
	}else{
		graphics.setBackgroundColor(fillColor);				
		super.fillShape(graphics);
	}				
	
	String valueString = getValueText();
	Dimension valueSize = 
		FigureUtilities.getTextExtents(valueString, getFont());
	if(valueSize.width < bounds.width) {				
		graphics.setForegroundColor(contrastFillColor);
		graphics.drawText(valueString, new Point(
				bounds.x + bounds.width/2 - valueSize.width/2,
				bounds.y + bounds.height/2 - valueSize.height/2));				
	}			
}
 
Example #11
Source File: ThermometerFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void outlineShape(Graphics graphics) {
	boolean support3D = false;
	if(effect3D)
		 support3D = GraphicsUtil.testPatternSupported(graphics);
	
	if(effect3D && support3D)
		graphics.setForegroundColor(EFFECT3D_BULB_COLOR);
	else
		graphics.setForegroundColor(BLACK_COLOR);
	super.outlineShape(graphics);			
	//draw a small rectangle to hide the joint  
	
	
	if(effect3D && support3D) {
		graphics.setBackgroundColor(fillColor);
		graphics.fillRectangle(new Rectangle(pipe.getBounds().x + pipe.getLineWidth(),
			((LinearScale) scale).getValuePosition(scale.getRange().getLower(), false),
			Pipe.PIPE_WIDTH- pipe.getLineWidth() *2, 2));
		Pattern backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
			pipe.getBounds().x, ((LinearScale) scale).getValuePosition(scale.getRange().getLower(), false),
			pipe.getBounds().x + Pipe.PIPE_WIDTH,
			((LinearScale) scale).getValuePosition(scale.getRange().getLower(), false),
			WHITE_COLOR,255, fillColor, 0);					
		graphics.setBackgroundPattern(backPattern);
		graphics.fillRectangle(new Rectangle(pipe.getBounds().x + pipe.getLineWidth(),
			((LinearScale) scale).getValuePosition(scale.getRange().getLower(), false),
			Pipe.PIPE_WIDTH- pipe.getLineWidth() *2, 2));
		backPattern.dispose();

	}else{
		graphics.setBackgroundColor(fillColor);
		
		graphics.fillRoundRectangle(new Rectangle(pipe.getBounds().x + pipe.getLineWidth(),
				((LinearScale) scale).getValuePosition(scale.getRange().getLower(), false),
				Pipe.PIPE_WIDTH- pipe.getLineWidth() *2, ((LinearScale) scale).getMargin()),
				Pipe.FILL_CORNER, Pipe.FILL_CORNER);			
	}
		
}
 
Example #12
Source File: ProgressBarFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics g) {	
	g.setAntialias(SWT.ON);
	g.setClip(new Rectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height));
	g.setBackgroundColor(WHITE_COLOR);
	super.fillShape(g);
	Point leftPoint = getPoints().getPoint(0);
	Point rightPoint;
	//if(horizontal) 
		rightPoint = getPoints().getPoint(2);
	//else
	//	rightPoint = getPoints().getPoint(1);//.translate(0, -BREADTH/2);
	Pattern thumbPattern = null;
	boolean support3D = GraphicsUtil.testPatternSupported(g);
	setOutline(effect3D && support3D);
	if(effect3D && support3D) {
		thumbPattern = GraphicsUtil.createScaledPattern(g, Display.getCurrent(),
			leftPoint.x, leftPoint.y, rightPoint.x, rightPoint.y, WHITE_COLOR, 0, 
			fillColor, 255);
		g.setBackgroundPattern(thumbPattern);		
	}else
		g.setBackgroundColor(fillColor);
		
	g.fillPolygon(getPoints());
	
	if(effect3D && support3D)
		thumbPattern.dispose();
			
}
 
Example #13
Source File: GraphicsUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static Pattern createScaledPattern(Graphics graphics, Device device,
		float x1, float y1, float x2, float y2, Color color1, int alpha1,
		Color color2, int alpha2) {
	double scale = graphics.getAbsoluteScale();
	return new Pattern(device, (float) (x1 * scale), (float) (y1 * scale),
			(float) (x2 * scale), (float) (y2 * scale), color1, alpha1, color2,
			alpha2);
}
 
Example #14
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 #15
Source File: SvgGradient.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void create(SvgShape shape, GC gc) {
	this.gc = gc;
	if(boundingBox) {
		bounds = shape.getBounds();
	} else {
		bounds = shape.getViewport();
	}
	try {
		Class<?> c = Class.forName("org.eclipse.nebula.cwt.SwtAdapter"); //$NON-NLS-1$
		Method m = c.getMethod("createPattern", SvgGradient.class); //$NON-NLS-1$
		pattern = (Pattern) m.invoke(c, this);
	} catch(Exception e) {
		System.out.println("Could not create pattern - fragment must be missing"); //$NON-NLS-1$
	}
}
 
Example #16
Source File: SwtRendererImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void fillPathImage( Path path,
		org.eclipse.birt.chart.model.attribute.Image g )
		throws ChartException
{
	org.eclipse.swt.graphics.Image img = null;
	if ( g instanceof EmbeddedImage )
	{
		try
		{
			String imageData = ( (EmbeddedImage) g ).getData( );
			if ( imageData != null )
			{
				ByteArrayInputStream bis = new ByteArrayInputStream( Base64.decodeBase64( ( (EmbeddedImage) g ).getData( )
						.getBytes( ) ) );

				img = new org.eclipse.swt.graphics.Image( ( (SwtDisplayServer) _ids ).getDevice( ),
						bis );
			}
			else
			{
				img = createEmptyImage( );
			}
		}
		catch ( Exception ilex )
		{
			throw new ChartException( ChartDeviceSwtActivator.ID,
					ChartException.RENDERING,
					ilex );
		}
	}
	else if ( g instanceof PatternImage )
	{
		PatternImage patternImage = (PatternImage) g;
		img = createImageFromPattern( patternImage );
	}
	else
	{
		if ( g.getSource( ) == ImageSourceType.STATIC )
		{
			final String sUrl = g.getURL( );
			try
			{
				img = (org.eclipse.swt.graphics.Image) _ids.loadImage( SecurityUtil.newURL( sUrl ) );
			}
			catch ( MalformedURLException muex )
			{
				throw new ChartException( ChartDeviceSwtActivator.ID,
						ChartException.RENDERING,
						muex );
			}
		}
		else
		{
			img = createEmptyImage( );
		}

	}

	Pattern pattern = new Pattern( _gc.getDevice( ), img );
	_gc.setBackgroundPattern( pattern );
	_gc.fillPath( path );

	pattern.dispose( );
	img.dispose( );
}
 
Example #17
Source File: SwtRendererImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void fillPathGradient( Path path, Gradient g, Rectangle r )
		throws ChartException
{
	final ColorDefinition cdStart = g.getStartColor( );
	final ColorDefinition cdEnd = g.getEndColor( );
	double dAngleInDegrees = g.getDirection( );

	if ( dAngleInDegrees < -90 || dAngleInDegrees > 90 )
	{
		throw new ChartException( ChartDeviceSwtActivator.ID,
				ChartException.RENDERING,
				"SwtRendererImpl.exception.gradient.angle", //$NON-NLS-1$
				new Object[]{
					new Double( dAngleInDegrees )
				},
				Messages.getResourceBundle( getULocale( ) ) );
	}

	final Color cPreviousFG = _gc.getForeground( );
	final Color cPreviousBG = _gc.getBackground( );
	Color cFG = (Color) _ids.getColor( cdStart );
	Color cBG = (Color) _ids.getColor( cdEnd );
	
	float x1, y1, x2, y2;
	
	// #232647
	// The maximal round-off error to calculate x2 and y2 here can be 2.
	// And if the pattern value is less than the forground, it is very obvious.
	// So we add 2 here to overcome this error. 
	final int iMaxError = 2; 
	
	if ( dAngleInDegrees == 0 )
	{
		x1 = r.x;
		x2 = r.x + r.width + iMaxError;
		y1 = y2 = r.y;
	}
	else if ( dAngleInDegrees == 90 )
	{
		x1 = x2 = r.x;
		y1 = r.y + r.height + iMaxError;
		y2 = r.y;
	}
	else if ( dAngleInDegrees == -90 )
	{
		x1 = x2 = r.x;
		y1 = r.y;
		y2 = r.y + r.height + iMaxError;
	}
	else if ( dAngleInDegrees > 0 )
	{
		x1 = r.x;
		y1 = r.y + r.height;
		x2 = r.x + r.width + iMaxError;
		y2 = r.y;
	}
	else
	{
		x1 = r.x;
		y1 = r.y;
		x2 = r.x + r.width;
		y2 = r.y + r.height;
	}
	
	_gc.setForeground( cFG );
	_gc.setBackground( cBG );

	R31Enhance.setAlpha( _gc, g );

	Pattern pattern = new Pattern( _gc.getDevice( ),
			x1,
			y1,
			x2,
			y2,
			cFG,
			cdStart.getTransparency( ),
			cBG,
			cdEnd.getTransparency( ) );
	_gc.setBackgroundPattern( pattern );
	_gc.fillPath( path );

	_gc.setForeground( cPreviousFG );
	_gc.setBackground( cPreviousBG );
	cFG.dispose( );
	cBG.dispose( );
	pattern.dispose( );
}
 
Example #18
Source File: GraphicsUtil.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static Pattern createScaledPattern(Graphics graphics, Device device,
		float x1, float y1, float x2, float y2, Color color1, Color color2) {
	double scale = graphics.getAbsoluteScale();
	return new Pattern(device, (float) (x1 * scale), (float) (y1 * scale),
			(float) (x2 * scale), (float) (y2 * scale), color1, color2);
}
 
Example #19
Source File: SelectionFeedbackEditPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public SelectionFeedbackEditPolicy(final EClass eClass) {

	feedBackFigure = new RoundedRectangle(){
		protected void fillShape(Graphics graphics) {
			Rectangle r = getBounds() ;

			Point topLeft = r.getTopLeft();
			Point bottomRight = r.getBottomRight();
			Color backGroundColor = null ;
			if(useSelectionColor){
				backGroundColor = ColorRegistry.getInstance().getColor(selectionColor) ;
			}else{
				backGroundColor=FiguresHelper.getFeedbackColor(eClass) ;
			}


			Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
					topLeft.y, bottomRight.x, bottomRight.y,
					backGroundColor,30, backGroundColor,60);

			graphics.setBackgroundPattern(pattern);
			graphics.fillRoundRectangle(r, 20, 20) ;
			graphics.setAlpha(0) ;
			graphics.setBackgroundPattern(null);	
			pattern.dispose();

		};
	} ;


	figureListener = new FigureListener() {

		public void figureMoved(IFigure source) {
			hideFeedback();
			List<?> selectedEditPart = getHost().getViewer().getSelectedEditParts() ;
			if(selectedEditPart.contains(getHost())){

				if(!figureIsDisplayed()){
					showFeedback(zoomManager.getZoom());
				}
			}
		}
	};

}
 
Example #20
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);
}
 
Example #21
Source File: Sleak.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
void refreshLabel() {
  int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
  int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
  for ( int i = 0; i < objects.length; i++ ) {
    Object object = objects[i];
    if ( object instanceof Color ) {
      colors++;
    }
    if ( object instanceof Cursor ) {
      cursors++;
    }
    if ( object instanceof Font ) {
      fonts++;
    }
    if ( object instanceof GC ) {
      gcs++;
    }
    if ( object instanceof Image ) {
      images++;
    }
    if ( object instanceof Path ) {
      paths++;
    }
    if ( object instanceof Pattern ) {
      patterns++;
    }
    if ( object instanceof Region ) {
      regions++;
    }
    if ( object instanceof TextLayout ) {
      textLayouts++;
    }
    if ( object instanceof Transform ) {
      transforms++;
    }
  }
  String string = "";
  if ( colors != 0 ) {
    string += colors + " Color(s)\n";
  }
  if ( cursors != 0 ) {
    string += cursors + " Cursor(s)\n";
  }
  if ( fonts != 0 ) {
    string += fonts + " Font(s)\n";
  }
  if ( gcs != 0 ) {
    string += gcs + " GC(s)\n";
  }
  if ( images != 0 ) {
    string += images + " Image(s)\n";
  }
  if ( paths != 0 ) {
    string += paths + " Paths(s)\n";
  }
  if ( patterns != 0 ) {
    string += patterns + " Pattern(s)\n";
  }
  if ( regions != 0 ) {
    string += regions + " Region(s)\n";
  }
  if ( textLayouts != 0 ) {
    string += textLayouts + " TextLayout(s)\n";
  }
  if ( transforms != 0 ) {
    string += transforms + " Transform(s)\n";
  }
  if ( string.length() != 0 ) {
    string = string.substring( 0, string.length() - 1 );
  }
  label.setText( string );
}
 
Example #22
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 #23
Source File: Sleak.java    From hop with Apache License 2.0 4 votes vote down vote up
void refreshLabel() {
  int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
  int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
  for ( int i = 0; i < objects.length; i++ ) {
    Object object = objects[ i ];
    if ( object instanceof Color ) {
      colors++;
    }
    if ( object instanceof Cursor ) {
      cursors++;
    }
    if ( object instanceof Font ) {
      fonts++;
    }
    if ( object instanceof GC ) {
      gcs++;
    }
    if ( object instanceof Image ) {
      images++;
    }
    if ( object instanceof Path ) {
      paths++;
    }
    if ( object instanceof Pattern ) {
      patterns++;
    }
    if ( object instanceof Region ) {
      regions++;
    }
    if ( object instanceof TextLayout ) {
      textLayouts++;
    }
    if ( object instanceof Transform ) {
      transforms++;
    }
  }
  String string = "";
  if ( colors != 0 ) {
    string += colors + " Color(s)\n";
  }
  if ( cursors != 0 ) {
    string += cursors + " Cursor(s)\n";
  }
  if ( fonts != 0 ) {
    string += fonts + " Font(s)\n";
  }
  if ( gcs != 0 ) {
    string += gcs + " GC(s)\n";
  }
  if ( images != 0 ) {
    string += images + " Image(s)\n";
  }
  if ( paths != 0 ) {
    string += paths + " Paths(s)\n";
  }
  if ( patterns != 0 ) {
    string += patterns + " Pattern(s)\n";
  }
  if ( regions != 0 ) {
    string += regions + " Region(s)\n";
  }
  if ( textLayouts != 0 ) {
    string += textLayouts + " TextLayout(s)\n";
  }
  if ( transforms != 0 ) {
    string += transforms + " Transform(s)\n";
  }
  if ( string.length() != 0 ) {
    string = string.substring( 0, string.length() - 1 );
  }
  label.setText( string );
}
 
Example #24
Source File: ThermometerFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	corner.height =PIPE_WIDTH/2;
	corner.width = PIPE_WIDTH/2;
	graphics.setBackgroundColor(fillBackgroundColor);
	
	int valuePosition = ((LinearScale) scale).getValuePosition(getCoercedValue(), false);
	if(maximum > minimum){
		if(value > maximum)
			valuePosition -= 10;
		else if(value < minimum)
			valuePosition +=10;
	}else{
		if(value > minimum)
			valuePosition += 10;
		else if(value < maximum)
			valuePosition -=10;
	}
	boolean support3D = false;
	if(effect3D)
		 support3D = GraphicsUtil.testPatternSupported(graphics);
	
	if(effect3D && support3D){
		graphics.setForegroundColor(EFFECT3D_PIPE_COLOR);
		//fill back
		super.fillShape(graphics);
		Pattern backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
				bounds.x, bounds.y, bounds.x+bounds.width, bounds.y, 
				WHITE_COLOR,255, fillBackgroundColor, 0);
		graphics.setBackgroundPattern(backPattern);
		super.fillShape(graphics);
		backPattern.dispose();
		
		//fill value
		graphics.setBackgroundColor(fillColor);
		graphics.fillRoundRectangle(new Rectangle(bounds.x + lineWidth, 
				valuePosition,
				bounds.width - 2* lineWidth, 
				bounds.height - (valuePosition - bounds.y)),
				FILL_CORNER, FILL_CORNER);		
		backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
				bounds.x, bounds.y, bounds.x+bounds.width, bounds.y, 
				WHITE_COLOR,255, fillColor, 0);
		graphics.setBackgroundPattern(backPattern);
		graphics.fillRoundRectangle(new Rectangle(bounds.x + lineWidth, 
				valuePosition,
				bounds.width - 2* lineWidth, 
				bounds.height - (valuePosition - bounds.y)),
				FILL_CORNER, FILL_CORNER);
		backPattern.dispose();			
	} else {
		super.fillShape(graphics);
		graphics.setBackgroundColor(fillColor);
		graphics.fillRoundRectangle(new Rectangle(bounds.x + lineWidth, 
			valuePosition,
			bounds.width - 2* lineWidth, 
			bounds.height - (valuePosition - bounds.y)),
			FILL_CORNER, FILL_CORNER);
	}
	
	
	
}
 
Example #25
Source File: ScaledSliderFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
		protected void fillShape(Graphics graphics) {		
			
			graphics.setAntialias(SWT.ON);			
			int valuePosition = ((LinearScale) scale).getValuePosition(getCoercedValue(), false);
			boolean support3D = GraphicsUtil.testPatternSupported(graphics);
			if(effect3D && support3D) {		
				//fill background
				graphics.setBackgroundColor(fillBackgroundColor);
				super.fillShape(graphics);
				Pattern backGroundPattern; 
				if(horizontal)
					backGroundPattern= GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x, bounds.y + bounds.height,
						WHITE_COLOR, 255,
						fillBackgroundColor, 0);
				else
					backGroundPattern= GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x + bounds.width, bounds.y,
						WHITE_COLOR, 255,
						fillBackgroundColor, 0);
				graphics.setBackgroundPattern(backGroundPattern);
				super.fillShape(graphics);
				graphics.setForegroundColor(fillBackgroundColor);
				outlineShape(graphics);
				backGroundPattern.dispose();
				
				//fill value
				if(horizontal)
					backGroundPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x, bounds.y + bounds.height,
						WHITE_COLOR, 255,
						fillColor, 0);
				else
					backGroundPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x + bounds.width, bounds.y,
						WHITE_COLOR, 255,
						fillColor, 0);
				
				graphics.setBackgroundColor(fillColor);
				graphics.setForegroundColor(fillColor);
				if(horizontal){
					int fillWidth = valuePosition - bounds.x;				
					graphics.fillRectangle(new Rectangle(bounds.x,
						bounds.y, fillWidth, bounds.height));
					graphics.setBackgroundPattern(backGroundPattern);
					graphics.fillRectangle(new Rectangle(bounds.x,
						bounds.y, fillWidth, bounds.height));
					
					graphics.drawRectangle(new Rectangle(bounds.x + lineWidth / 2,
						bounds.y + lineWidth / 2, 
						fillWidth - Math.max(1, lineWidth),
						bounds.height - Math.max(1, lineWidth)));
					
					
				}else {
					int fillHeight = bounds.height - (valuePosition - bounds.y);				
					graphics.fillRectangle(new Rectangle(bounds.x,
						valuePosition, bounds.width, fillHeight));
					graphics.setBackgroundPattern(backGroundPattern);
					graphics.fillRectangle(new Rectangle(bounds.x,
						valuePosition, bounds.width, fillHeight));
					
					graphics.drawRectangle(new Rectangle(bounds.x + lineWidth / 2,
						valuePosition+ lineWidth / 2, 
						bounds.width- Math.max(1, lineWidth),
						fillHeight - Math.max(1, lineWidth)));
				}		
				
				backGroundPattern.dispose();
				
				
				
				
			}else {
				graphics.setBackgroundColor(fillBackgroundColor);
				super.fillShape(graphics);				
				graphics.setBackgroundColor(fillColor);
				if(horizontal)
					graphics.fillRectangle(new Rectangle(bounds.x,
							bounds.y, 						
							valuePosition - bounds.x, 
							bounds.height));
				else
					graphics.fillRectangle(new Rectangle(bounds.x,
							valuePosition,
							bounds.width,
							bounds.height - (valuePosition - bounds.y)));
//				graphics.setForegroundColor(outlineColor);
			}			
		}
 
Example #26
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 #27
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 #28
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;
        }
    }