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

The following examples show how to use org.eclipse.swt.graphics.GC#getLineDash() . 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: VerticalIndentGuidesPainter.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private AutoCloseable configGC(final GC gc) {
    final int lineStyle = gc.getLineStyle();
    final int alpha = gc.getAlpha();
    final int[] lineDash = gc.getLineDash();

    final Color foreground = gc.getForeground();
    final Color background = gc.getBackground();

    gc.setForeground(this.indentGuide.getColor(styledText));
    gc.setBackground(styledText.getBackground());
    gc.setAlpha(this.indentGuide.getTransparency());
    gc.setLineStyle(SWT.LINE_CUSTOM);
    gc.setLineDash(new int[] { 1, 2 });
    return new AutoCloseable() {

        @Override
        public void close() throws Exception {
            gc.setForeground(foreground);
            gc.setBackground(background);
            gc.setAlpha(alpha);
            gc.setLineStyle(lineStyle);
            gc.setLineDash(lineDash);
        }
    };
}
 
Example 2
Source File: BranchRenderer.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void paint(GC gc, Object value) {
	Rectangle bounds = getBounds();
	
	int xLeft = bounds.x;
	int yTop = bounds.y - 1;
	
	int yBottom = yTop + bounds.height;
	int yMiddle = toggleBounds.y + toggleBounds.height / 2;
	int yToggleBottom = toggleBounds.y + toggleBounds.height - 1;
	int yToggleTop = toggleBounds.y;
	
	int oldStyle = gc.getLineStyle();
	Color oldForeground = gc.getForeground();
	int[] oldLineDash = gc.getLineDash();
	
	gc.setForeground(getDisplay().getSystemColor(
			isSelected() ? 
					SWT.COLOR_LIST_SELECTION_TEXT 
					: SWT.COLOR_WIDGET_NORMAL_SHADOW));

	int dy = bounds.y % 2;

	// Set line style to dotted
	gc.setLineDash(LINE_STYLE);
	
	// Adjust line positions by a few pixels to create correct effect
	yToggleTop --;
	yTop ++;
	yToggleBottom ++;
	
	// Adjust full height
	// If height is even, we shorten to an odd number of pixels, and start at the original y offset
	if (bounds.height % 2 == 0) {
		yBottom -= 1;
	}
	// If height is odd, we alternate based on the row offset
	else {
		yTop += dy;
		yBottom -= dy;
	}

	// Adjust ascender and descender
	yToggleBottom += dy;

	if ((yToggleTop - yTop + 1) % 2 == 0)
		yToggleTop -= 1;
	if ((yToggleBottom - yBottom + 1) % 2 == 0)
		yToggleBottom += dy == 1 ? -1 : 1;
	
	for (int i = 0; i < branches.length; i++) {
		// Calculate offsets for this branch
		int xRight = xLeft + indent;
		int xMiddle = xLeft + toggleBounds.width / 2;
		int xMiddleBranch = xMiddle;
		int xToggleRight = xLeft + toggleBounds.width;

		int dx = 0;
		xRight --;
		xMiddleBranch += 2;
		xToggleRight --;
		
		if (indent % 2 == 0) {
			xRight -= 1;
		}
		else {
			dx = xLeft % 2;
			xLeft += dx;
			xRight -= dx;
		}
		
		// Render line segments
		if ((branches[i] & H_FULL) == H_FULL)
			gc.drawLine(xLeft, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_RIGHT) == H_RIGHT)
			gc.drawLine(xMiddleBranch, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_CENTRE_TOGGLE) == H_CENTRE_TOGGLE)
			gc.drawLine(xMiddleBranch, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & H_LEFT_TOGGLE) == H_LEFT_TOGGLE)
			gc.drawLine(xLeft, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & V_FULL) == V_FULL)
			gc.drawLine(xMiddle, yTop, xMiddle, yBottom);
		if ((branches[i] & V_TOP) == V_TOP)
			gc.drawLine(xMiddle, yTop, xMiddle, yMiddle);
		if ((branches[i] & ASCENDER) == ASCENDER)
			gc.drawLine(xMiddle, yTop, xMiddle, yToggleTop);
		if ((branches[i] & DESCENDER) == DESCENDER)
			gc.drawLine(xMiddle, yToggleBottom, xMiddle, yBottom);
		
		xLeft += indent - dx;
	}

	gc.setLineDash(oldLineDash);
	gc.setLineStyle(oldStyle);
	gc.setForeground(oldForeground);
}
 
Example 3
Source File: BranchRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void paint(GC gc, Object value) {
	Rectangle bounds = getBounds();
	
	int xLeft = bounds.x;
	int yTop = bounds.y - 1;
	
	int yBottom = yTop + bounds.height;
	int yMiddle = toggleBounds.y + toggleBounds.height / 2;
	int yToggleBottom = toggleBounds.y + toggleBounds.height - 1;
	int yToggleTop = toggleBounds.y;
	
	int oldStyle = gc.getLineStyle();
	Color oldForeground = gc.getForeground();
	int[] oldLineDash = gc.getLineDash();
	
	gc.setForeground(getDisplay().getSystemColor(
			isSelected() ? 
					SWT.COLOR_LIST_SELECTION_TEXT 
					: SWT.COLOR_WIDGET_NORMAL_SHADOW));

	int dy = bounds.y % 2;

	// Set line style to dotted
	gc.setLineDash(LINE_STYLE);
	
	// Adjust line positions by a few pixels to create correct effect
	yToggleTop --;
	yTop ++;
	yToggleBottom ++;
	
	// Adjust full height
	// If height is even, we shorten to an odd number of pixels, and start at the original y offset
	if (bounds.height % 2 == 0) {
		yBottom -= 1;
	}
	// If height is odd, we alternate based on the row offset
	else {
		yTop += dy;
		yBottom -= dy;
	}

	// Adjust ascender and descender
	yToggleBottom += dy;

	if ((yToggleTop - yTop + 1) % 2 == 0)
		yToggleTop -= 1;
	if ((yToggleBottom - yBottom + 1) % 2 == 0)
		yToggleBottom += dy == 1 ? -1 : 1;
	
	for (int i = 0; i < branches.length; i++) {
		// Calculate offsets for this branch
		int xRight = xLeft + indent;
		int xMiddle = xLeft + toggleBounds.width / 2;
		int xMiddleBranch = xMiddle;
		int xToggleRight = xLeft + toggleBounds.width;

		int dx = 0;
		xRight --;
		xMiddleBranch += 2;
		xToggleRight --;
		
		if (indent % 2 == 0) {
			xRight -= 1;
		}
		else {
			dx = xLeft % 2;
			xLeft += dx;
			xRight -= dx;
		}
		
		// Render line segments
		if ((branches[i] & H_FULL) == H_FULL)
			gc.drawLine(xLeft, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_RIGHT) == H_RIGHT)
			gc.drawLine(xMiddleBranch, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_CENTRE_TOGGLE) == H_CENTRE_TOGGLE)
			gc.drawLine(xMiddleBranch, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & H_LEFT_TOGGLE) == H_LEFT_TOGGLE)
			gc.drawLine(xLeft, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & V_FULL) == V_FULL)
			gc.drawLine(xMiddle, yTop, xMiddle, yBottom);
		if ((branches[i] & V_TOP) == V_TOP)
			gc.drawLine(xMiddle, yTop, xMiddle, yMiddle);
		if ((branches[i] & ASCENDER) == ASCENDER)
			gc.drawLine(xMiddle, yTop, xMiddle, yToggleTop);
		if ((branches[i] & DESCENDER) == DESCENDER)
			gc.drawLine(xMiddle, yToggleBottom, xMiddle, yBottom);
		
		xLeft += indent - dx;
	}

	gc.setLineDash(oldLineDash);
	gc.setLineStyle(oldStyle);
	gc.setForeground(oldForeground);
}
 
Example 4
Source File: BranchRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void paint(GC gc, Object value) {
	Rectangle bounds = getBounds();
	
	int xLeft = bounds.x;
	int yTop = bounds.y - 1;
	
	int yBottom = yTop + bounds.height;
	int yMiddle = toggleBounds.y + toggleBounds.height / 2;
	int yToggleBottom = toggleBounds.y + toggleBounds.height - 1;
	int yToggleTop = toggleBounds.y;
	
	int oldStyle = gc.getLineStyle();
	Color oldForeground = gc.getForeground();
	int[] oldLineDash = gc.getLineDash();
	
	gc.setForeground(getDisplay().getSystemColor(
			isSelected() ? 
					SWT.COLOR_LIST_SELECTION_TEXT 
					: SWT.COLOR_WIDGET_NORMAL_SHADOW));

	int dy = bounds.y % 2;

	// Set line style to dotted
	gc.setLineDash(LINE_STYLE);
	
	// Adjust line positions by a few pixels to create correct effect
	yToggleTop --;
	yTop ++;
	yToggleBottom ++;
	
	// Adjust full height
	// If height is even, we shorten to an odd number of pixels, and start at the original y offset
	if (bounds.height % 2 == 0) {
		yBottom -= 1;
	}
	// If height is odd, we alternate based on the row offset
	else {
		yTop += dy;
		yBottom -= dy;
	}

	// Adjust ascender and descender
	yToggleBottom += dy;

	if ((yToggleTop - yTop + 1) % 2 == 0)
		yToggleTop -= 1;
	if ((yToggleBottom - yBottom + 1) % 2 == 0)
		yToggleBottom += dy == 1 ? -1 : 1;
	
	for (int i = 0; i < branches.length; i++) {
		// Calculate offsets for this branch
		int xRight = xLeft + indent;
		int xMiddle = xLeft + toggleBounds.width / 2;
		int xMiddleBranch = xMiddle;
		int xToggleRight = xLeft + toggleBounds.width;

		int dx = 0;
		xRight --;
		xMiddleBranch += 2;
		xToggleRight --;
		
		if (indent % 2 == 0) {
			xRight -= 1;
		}
		else {
			dx = xLeft % 2;
			xLeft += dx;
			xRight -= dx;
		}
		
		// Render line segments
		if ((branches[i] & H_FULL) == H_FULL)
			gc.drawLine(xLeft, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_RIGHT) == H_RIGHT)
			gc.drawLine(xMiddleBranch, yMiddle, xRight, yMiddle);
		if ((branches[i] & H_CENTRE_TOGGLE) == H_CENTRE_TOGGLE)
			gc.drawLine(xMiddleBranch, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & H_LEFT_TOGGLE) == H_LEFT_TOGGLE)
			gc.drawLine(xLeft, yMiddle, xToggleRight, yMiddle);
		if ((branches[i] & V_FULL) == V_FULL)
			gc.drawLine(xMiddle, yTop, xMiddle, yBottom);
		if ((branches[i] & V_TOP) == V_TOP)
			gc.drawLine(xMiddle, yTop, xMiddle, yMiddle);
		if ((branches[i] & ASCENDER) == ASCENDER)
			gc.drawLine(xMiddle, yTop, xMiddle, yToggleTop);
		if ((branches[i] & DESCENDER) == DESCENDER)
			gc.drawLine(xMiddle, yToggleBottom, xMiddle, yBottom);
		
		xLeft += indent - dx;
	}

	gc.setLineDash(oldLineDash);
	gc.setLineStyle(oldStyle);
	gc.setForeground(oldForeground);
}