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

The following examples show how to use org.eclipse.swt.graphics.GC#getDevice() . 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: XGridCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public TextLayout getTextLayout(GC gc, GridItem item, int columnIndex, boolean innerTagStyled, boolean drawInnerTag) {
	TextLayout layout = new TextLayout(gc.getDevice());
	layout.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
	innerTagFactory.reset();
	
	String displayStr = "";
	try{
		displayStr = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag(item.getText(columnIndex)));
	}catch (NullPointerException e) {
		return null;
	}
	layout.setText(displayStr);
	int width = getBounds().width - leftMargin - rightMargin;
	layout.setWidth(width < 1 ? 1 : width);
	layout.setSpacing(Constants.SEGMENT_LINE_SPACING);
	layout.setAlignment(SWT.LEFT);

	if (displayStr.length() != 0 && innerTagStyled) {
		attachInnertTagStyle(gc, layout, drawInnerTag);
	}
	return layout;
}
 
Example 2
Source File: TwisteToggleRenderer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void paint(GC gc, Object value)
{
    Transform transform = new Transform(gc.getDevice());
    transform.translate(getBounds().x, getBounds().y);
    gc.setTransform(transform);

    Color back = gc.getBackground();
    Color fore = gc.getForeground();

    if (!isHover())
    {
        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
    }
    else
    {
        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
    }

    gc.setBackground(gc.getForeground());
    if (isExpanded())
    {
        gc.drawPolygon(new int[] {1, 3, 4, 6, 5, 6, 8, 3 });
        gc.fillPolygon(new int[] {1, 3, 4, 6, 5, 6, 8, 3 });
    }
    else
    {
        gc.drawPolygon(new int[] {3, 1, 6, 4, 6, 5, 3, 8 });
        gc.fillPolygon(new int[] {3, 1, 6, 4, 6, 5, 3, 8 });
    }

    if (isFocus())
    {
        gc.setBackground(back);
        gc.setForeground(fore);
        gc.drawFocus(-1, -1, 12, 12);
    }

    gc.setTransform(null);
    transform.dispose();
}
 
Example 3
Source File: MinMaxToggleRenderer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void paint(GC gc, Object value)
{

    Transform transform = new Transform(gc.getDevice());
    transform.translate(getBounds().x, getBounds().y);
    gc.setTransform(transform);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));

    if (isHover())
    {
        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
        gc.drawRoundRectangle(0, 0, 17, 17, 5, 5);
    }

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));

    if (isExpanded())
    {
        gc.fillRectangle(4, 3, 9, 3);
        gc.drawRectangle(4, 3, 9, 3);
    }
    else
    {
        gc.fillRectangle(4, 3, 9, 9);
        gc.drawRectangle(4, 3, 9, 9);
        gc.drawLine(4, 5, 13, 5);
    }

    gc.setTransform(null);
    transform.dispose();

}
 
Example 4
Source File: GraphUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public static void drawArrowHead(GC gc, Point referencePoint, Point p) {
	final double angle = Math.atan2(p.y - referencePoint.y, p.x - referencePoint.x) * 180.0 / Math.PI;
	final Transform tf = new Transform(gc.getDevice());
	tf.rotate(Double.valueOf(angle).floatValue());
	tf.scale(7, 3);
	final float[] pnts = new float[] { -1, 1, -1, -1 };
	tf.transform(pnts);
	gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[0]), Math.round(p.y + pnts[1]));
	gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[2]), Math.round(p.y + pnts[3]));
	tf.dispose();
}
 
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: GraphUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Paints an arc from src to tgt.
 * <p/>
 * <b>Assumption:</b> The tgt is located below of the src.
 */
public static float[] arcReversed(GC gc, Point src, Point tgt) {
	Path path = new Path(gc.getDevice());
	int ydiff = (int) ((tgt.y - src.y) / 3);
	path.moveTo((int) src.x, (int) src.y);
	path.cubicTo((int) src.x, (int) src.y + ydiff, (int) tgt.x, (int) tgt.y - ydiff * 2, (int) tgt.x, (int) tgt.y);
	gc.drawPath(path);

	float[] pp = path.getPathData().points;
	return pp;
}
 
Example 7
Source File: GraphUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Paints an arc from src to tgt using the given control point ctr. */
public static float[] arc(GC gc, Point ctr, Point src, Point tgt) {
	Path path = new Path(gc.getDevice());
	path.moveTo((int) src.x, (int) src.y);
	path.quadTo((int) ctr.x, (int) ctr.y, (int) tgt.x, (int) tgt.y);
	gc.drawPath(path);

	float[] pp = path.getPathData().points;
	return pp;
}
 
Example 8
Source File: SvgShape.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns whether or not the given point is contained by this shape.
 * @param x
 * @param y
 * @param gc
 * @param outline
 * @return true if the given point is contained, false otherwise
 * @see Path#contains(float, float, GC, boolean)
 */
public boolean contains(float x, float y, GC gc, boolean outline) {
	Transform t = new Transform(gc.getDevice());
	gc.getTransform(t);
	t.invert();
	float[] pts = new float[] { x, y };
	t.transform(pts);
	t.dispose();
	return path.contains(pts[0], pts[1], gc, outline);
}
 
Example 9
Source File: SourceColunmCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 10
Source File: TextCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
        IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    
    drawBackground(gc, drawingArea, cellStyle, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);

    // convert the value to a string
    String s = convertValue(row, column);

    Color fg = gc.getForeground();
    Color bg = gc.getBackground();
    Font font = gc.getFont();

   

    // draw comment marker if comment is present and not printing
    if (!printing && getComment(row, column) != null) {
        drawCommentMarker(gc, drawingArea, _commentColor, COMMENTMARKER_SIZE);
    }

    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);

    gc.setForeground(fg);
    gc.setBackground(bg);
    gc.setFont(font);
    if (s != null) {
        if (selected && !printing) {
            gc.setBackground(SELECTIONCOLOR);
        } else {
            gc.setBackground(getBackgroundColor(cellStyle, printing));
        }
        gc.setForeground(getForegroundColor(cellStyle, printing));
        gc.setFont(getFont(cellStyle, printing, gc.getFont()));

        drawCellString(gc, rect, s, cellStyle);
        if (s.indexOf("we") != -1) {
            TextLayout textLayout = new TextLayout(gc.getDevice());
            textLayout.setText(s);
            textLayout.setFont(gc.getFont());
            textLayout.setWidth(rect.width);
            Color color = new Color(gc.getDevice(), 150, 100, 100);
    		Font font2 = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont()
    				.getFontData()[0].getHeight(), SWT.ITALIC);
    		TextStyle style = new TextStyle(font2, color, null);
    		for (int i = 1; i < s.length(); i++) {
    			int j = indexOf(s, "we", i, false);
    			if (j != -1) {
    				textLayout.setStyle(style, j, j + 3);
    			} else {
    				break;
    			}

    		}
    		gc.fillRectangle(rect);
    		textLayout.draw(gc, rect.x, rect.y);
    		gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
            }
    }
}
 
Example 11
Source File: TextCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
        IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    
    drawBackground(gc, drawingArea, cellStyle, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);

    // convert the value to a string
    String s = convertValue(row, column);

    Color fg = gc.getForeground();
    Color bg = gc.getBackground();
    Font font = gc.getFont();

   

    // draw comment marker if comment is present and not printing
    if (!printing && getComment(row, column) != null) {
        drawCommentMarker(gc, drawingArea, _commentColor, COMMENTMARKER_SIZE);
    }

    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);

    gc.setForeground(fg);
    gc.setBackground(bg);
    gc.setFont(font);
    if (s != null) {
        if (selected && !printing) {
            gc.setBackground(SELECTIONCOLOR);
        } else {
            gc.setBackground(getBackgroundColor(cellStyle, printing));
        }
        gc.setForeground(getForegroundColor(cellStyle, printing));
        gc.setFont(getFont(cellStyle, printing, gc.getFont()));

        drawCellString(gc, rect, s, cellStyle);
        if (s.indexOf("we") != -1) {
            TextLayout textLayout = new TextLayout(gc.getDevice());
            textLayout.setText(s);
            textLayout.setFont(gc.getFont());
            textLayout.setWidth(rect.width);
            Color color = new Color(gc.getDevice(), 150, 100, 100);
    		Font font2 = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont()
    				.getFontData()[0].getHeight(), SWT.ITALIC);
    		TextStyle style = new TextStyle(font2, color, null);
    		for (int i = 1; i < s.length(); i++) {
    			int j = indexOf(s, "we", i, false);
    			if (j != -1) {
    				textLayout.setStyle(style, j, j + 3);
    			} else {
    				break;
    			}

    		}
    		gc.fillRectangle(rect);
    		textLayout.draw(gc, rect.x, rect.y);
    		gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
            }
    }
}
 
Example 12
Source File: CellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + insideMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells
	// in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() +
	// bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 13
Source File: DefaultCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
     * {@inheritDoc}
     */
    public Point computeSize(GC gc, int wHint, int hHint, Object value)
    {
        GridItem item = (GridItem)value;

        gc.setFont(item.getFont(getColumn()));

        int x = 0;

        x += leftMargin;

        if (isTree())
        {
            x += getToggleIndent(item);

            x += toggleRenderer.getBounds().width + insideMargin;

        }

        if (isCheck())
        {
            x += checkRenderer.getBounds().width + insideMargin;
        }

        int y = 0;

        Image image = item.getImage(getColumn());
        if (image != null)
        {
            y = topMargin + image.getBounds().height + bottomMargin;

            x += image.getBounds().width + insideMargin;
        }

// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
//       x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
//        y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:

        int textHeight = 0;
        if(!isWordWrap())
        {
            x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

            textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
        }
        else
        {
        	int plainTextWidth;
        	if (wHint == SWT.DEFAULT)
        	  plainTextWidth = getBounds().width - x - rightMargin;
        	else
        		plainTextWidth = wHint - x - rightMargin;

            TextLayout currTextLayout = new TextLayout(gc.getDevice());
            currTextLayout.setFont(gc.getFont());
            currTextLayout.setText(item.getText(getColumn()));
            currTextLayout.setAlignment(getAlignment());
            currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

            x += plainTextWidth + rightMargin;

            textHeight += topMargin + textTopMargin;
            for(int cnt=0;cnt<currTextLayout.getLineCount();cnt++)
                textHeight += currTextLayout.getLineBounds(cnt).height;
            textHeight += textBottomMargin + bottomMargin;

            currTextLayout.dispose();
        }

        y = Math.max(y, textHeight);

        return new Point(x, y);
    }
 
Example 14
Source File: DefaultCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
     * {@inheritDoc}
     */
    public Point computeSize(GC gc, int wHint, int hHint, Object value)
    {
        GridItem item = (GridItem)value;

        gc.setFont(item.getFont(getColumn()));

        int x = 0;

        x += leftMargin;

        if (isTree())
        {
            x += getToggleIndent(item);

            x += toggleRenderer.getBounds().width + insideMargin;

        }

        if (isCheck())
        {
            x += checkRenderer.getBounds().width + insideMargin;
        }

        int y = 0;

        Image image = item.getImage(getColumn());
        if (image != null)
        {
            y = topMargin + image.getBounds().height + bottomMargin;

            x += image.getBounds().width + insideMargin;
        }

// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
//       x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
//        y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:

        int textHeight = 0;
        if(!isWordWrap())
        {
            x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

            textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
        }
        else
        {
        	int plainTextWidth;
        	if (wHint == SWT.DEFAULT)
        	  plainTextWidth = getBounds().width - x - rightMargin;
        	else
        		plainTextWidth = wHint - x - rightMargin;

            TextLayout currTextLayout = new TextLayout(gc.getDevice());
            currTextLayout.setFont(gc.getFont());
            currTextLayout.setText(item.getText(getColumn()));
            currTextLayout.setAlignment(getAlignment());
            currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

            x += plainTextWidth + rightMargin;

            textHeight += topMargin + textTopMargin;
            for(int cnt=0;cnt<currTextLayout.getLineCount();cnt++)
                textHeight += currTextLayout.getLineBounds(cnt).height;
            textHeight += textBottomMargin + bottomMargin;

            currTextLayout.dispose();
        }

        y = Math.max(y, textHeight);

        return new Point(x, y);
    }
 
Example 15
Source File: ViewLattice.java    From arx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a node.
 *
 * @param g
 */
private void drawNodes(final GC g) {

    // Prepare
    Rectangle bounds = new Rectangle(0, 0, (int)nodeWidth, (int)nodeHeight);
    Transform transform = new Transform(g.getDevice());
    
    // Set style
    g.setLineWidth(STROKE_WIDTH_NODE);
    g.setFont(font);

    // Draw nodes
    for (List<ARXNode> level : lattice) {
        for (ARXNode node : level) {
            
            // Obtain coordinates
            double[] center = (double[]) node.getAttributes().get(ATTRIBUTE_CENTER);
            bounds.x = (int)(center[0] - nodeWidth / 2d);
            bounds.y = (int)(center[1] - nodeHeight / 2d);
            
            // Clipping
            if (bounds.intersects(new Rectangle(0, 0, screen.x, screen.y))) { 
                
                // Retrieve/compute text rendering data
                SerializablePath path = (SerializablePath) node.getAttributes().get(ATTRIBUTE_PATH);
                Point extent = (Point) node.getAttributes().get(ATTRIBUTE_EXTENT);
                if (path == null || path.getPath() == null) {
                    String text = (String) node.getAttributes().get(ATTRIBUTE_LABEL);
                    path = new SerializablePath(new Path(canvas.getDisplay()));
                    path.getPath().addString(text, 0, 0, font);
                    node.getAttributes().put(ATTRIBUTE_PATH, path);
                    extent = g.textExtent(text);
                    node.getAttributes().put(ATTRIBUTE_EXTENT, extent);
                }
        
                // Degrade if too far away
                if (bounds.width <= 4) {
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
        
                    // Draw real node
                } else {
                    
                    // Fill background
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    if (node != getSelectedNode()) {
                        g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw line
                    g.setLineWidth(getOuterStrokeWidth(node, bounds.width));
                    g.setForeground(getOuterColor(node));
                    g.setAntialias(SWT.ON);
                    if (node != getSelectedNode()) {
                        g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw text
                    if (bounds.width >= 20) {
                        
                        // Enable anti-aliasing
                        g.setTextAntialias(SWT.ON);
                        
                        // Compute position and factor
                        float factor1 = (bounds.width * 0.7f) / (float)extent.x;
                        float factor2 = (bounds.height * 0.7f) / (float)extent.y;
                        float factor = Math.min(factor1, factor2);
                        int positionX = bounds.x + (int)(((float)bounds.width - (float)extent.x * factor) / 2f); 
                        int positionY = bounds.y + (int)(((float)bounds.height - (float)extent.y * factor) / 2f);
                        
                        // Initialize transformation
                        transform.identity();
                        transform.translate(positionX, positionY);
                        transform.scale(factor, factor);
                        g.setTransform(transform);
                        
                        // Draw and reset
                        g.setBackground(COLOR_BLACK);
                        g.fillPath(path.getPath());
                        g.setTransform(null);
                        g.setTextAntialias(SWT.OFF);
                    }
                }
            }
        }
    }
    
    // Clean up
    transform.dispose();
}
 
Example 16
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 17
Source File: TBSearchCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + insideMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 18
Source File: TBSearchCellRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	if (isTree()) {
		x += getToggleIndent(item);

		x += toggleRenderer.getBounds().width + insideMargin;

	}

	if (isCheck()) {
		x += checkRenderer.getBounds().width + insideMargin;
	}

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + insideMargin;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 19
Source File: TargetColunmCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
	GridItem item = (GridItem) value;

	gc.setFont(item.getFont(getColumn()));

	int x = 0;

	x += leftMargin;

	int y = 0;

	Image image = item.getImage(getColumn());
	if (image != null) {
		y = topMargin + image.getBounds().height + bottomMargin;

		x += image.getBounds().width + 3;
	}

	// MOPR-DND
	// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
	//
	// x += gc.stringExtent(item.getText(column)).x + rightMargin;
	//
	// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
	//
	// with this code:

	int textHeight = 0;
	if (!isWordWrap()) {
		x += gc.textExtent(item.getText(getColumn())).x + rightMargin;

		textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
	} else {
		int plainTextWidth;
		if (wHint == SWT.DEFAULT)
			plainTextWidth = getBounds().width - x - rightMargin;
		else
			plainTextWidth = wHint - x - rightMargin;

		TextLayout currTextLayout = new TextLayout(gc.getDevice());
		currTextLayout.setFont(gc.getFont());
		currTextLayout.setText(item.getText(getColumn()));
		currTextLayout.setAlignment(getAlignment());
		currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);

		x += plainTextWidth + rightMargin;

		textHeight += topMargin + textTopMargin;
		for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++)
			textHeight += currTextLayout.getLineBounds(cnt).height;
		textHeight += textBottomMargin + bottomMargin;

		currTextLayout.dispose();
	}

	y = Math.max(y, textHeight);

	return new Point(x, y);
}
 
Example 20
Source File: PieUtils.java    From BiglyBT with GNU General Public License v2.0 2 votes vote down vote up
public static void
drawPie(
	GC gc,Image image, int x, int y,int width,int height,int percent, boolean draw_border )
{
	Rectangle image_size = image.getBounds();

	int	width_pad 	= ( width - image_size.width  )/2;
	int	height_pad 	= ( height - image_size.height  )/2;

    int angle = (percent * 360) / 100;
    if(angle<4){
    	angle = 0; // workaround fillArc rendering bug
    }

	Region old_clipping = new Region();

	gc.getClipping(old_clipping);

	Path path_done = new Path(gc.getDevice());

	path_done.addArc(x,y,width,height,90,-angle);
	path_done.lineTo( x+width/2, y+height/2);
	path_done.close();

	gc.setClipping( path_done );

	gc.drawImage(image, x+width_pad, y+height_pad+1);

	Path path_undone = new Path(gc.getDevice());

	path_undone.addArc(x,y,width,height,90-angle,angle-360);
	path_undone.lineTo( x+width/2, y+height/2);
	path_undone.close();

	gc.setClipping( path_undone );

	gc.setAlpha( 75 );
	gc.drawImage(image, x+width_pad, y+height_pad+1);
	gc.setAlpha( 255 );

	gc.setClipping( old_clipping );

	if ( draw_border ){

		gc.setForeground(Colors.blue);

		if ( percent == 100 ){

			gc.drawOval(x , y , width-1, height-1);

		}else{

			if ( angle > 0 ){

				gc.drawPath( path_done );
			}
		}
	}

	path_done.dispose();
	path_undone.dispose();
	old_clipping.dispose();

}