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

The following examples show how to use org.eclipse.swt.graphics.GC#getLineStyle() . 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: Day.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void paintControl(PaintEvent e) {
	GC gc = e.gc;

	// Save stuff we're about to change so we can restore it later
	int oldLineStyle = gc.getLineStyle();
	int oldLineWidth = gc.getLineWidth();

	// Draw focus rubberband if we're focused
	try {
		if (focusState != Day.NO_FOCUS) {
			if (focusState == Day.NONACTIVE_FOCUS) {
				gc.setForeground(NONACTIVE_FOCUS_RUBBERBAND);
			} else {
				gc.setForeground(FOCUS_RUBBERBAND);
			}
			gc.setLineStyle(SWT.LINE_DASH);
			gc.setLineWidth(FOCUS_LINE_WIDTH);
			Point parentSize = getSize();
			gc.drawRectangle(FOCUS_LINE_WIDTH, FOCUS_LINE_WIDTH, parentSize.x - 4, parentSize.y - 3);
		}
	} finally {
		gc.setLineStyle(oldLineStyle);
		gc.setLineWidth(oldLineWidth);
	}
}
 
Example 2
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 3
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 4
Source File: TimeSlot.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void paintControl(PaintEvent e) {
			GC gc = e.gc;
			Color oldForeground = gc.getForeground();
			Color oldBackground = gc.getBackground();
			Point controlSize = getSize();

			// Draw basic background here
			try {
				// Draw "time bar" on left side
				gc.setBackground(WHITE);
				gc.setForeground(WHITE);
				gc.fillRectangle(0, 0, TIME_BAR_WIDTH, controlSize.y);
				gc.setForeground(CELL_BORDER_LIGHT);
				int lineStyle = gc.getLineStyle();
				gc.setLineStyle(SWT.LINE_DOT);
				gc.drawLine(TIME_BAR_WIDTH + 1, 0, TIME_BAR_WIDTH + 1,
						controlSize.y);
				gc.setLineStyle(lineStyle);
				gc.setForeground(TIME_BAR_COLOR);
				gc.drawLine(controlSize.x - 1, 0, controlSize.x - 1,
						controlSize.y);
				if (isMinutesAfterHour(0)) {
					gc.setForeground(CELL_BORDER_EMPHASIZED);
				} else {
					gc.setForeground(CELL_BORDER_LIGHT);
				}
//				gc.drawLine(TIME_BAR_WIDTH + 2, 0, controlSize.x - 2, 0);
				if (isMinutesAfterHour(0) || isMinutesAfterHour(30) && !isAllDay()) {
					gc.drawLine(0, 0, controlSize.x, 0);
				}
			} finally {
				gc.setBackground(oldBackground);
				gc.setForeground(oldForeground);
			}

			// Draw focus rubberband if we're focused
			int oldLineStyle = gc.getLineStyle();
			int oldLineWidth = gc.getLineWidth();
			try {
				if (focusControl) {
					gc.setLineStyle(SWT.LINE_DASH);
					gc.setLineWidth(FOCUS_LINE_WIDTH);
					gc.setForeground(FOCUS_RUBBERBAND);
					Point parentSize = getSize();
					gc.drawRectangle(FOCUS_LINE_WIDTH,
							FOCUS_LINE_WIDTH, parentSize.x - 4,
							parentSize.y - 3);
				}

				gc.setForeground(CELL_BACKGROUND_LIGHT);
			} finally {
				gc.setForeground(oldForeground);
				gc.setLineStyle(oldLineStyle);
				gc.setLineWidth(oldLineWidth);
			}
		}
 
Example 5
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 6
Source File: LineBorderDecorator.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
	int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
	
	Rectangle interiorBounds =
		new Rectangle(
				rectangle.x + borderThickness,
				rectangle.y + borderThickness,
				rectangle.width - (borderThickness * 2),
				rectangle.height - (borderThickness * 2)
		);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
	
	if (borderStyle == null || borderThickness <= 0) {
		return;
	}
	
	// Save GC settings
	Color originalForeground = gc.getForeground();
	int originalLineWidth = gc.getLineWidth();
	int originalLineStyle = gc.getLineStyle();

	gc.setLineWidth(borderThickness);

	Rectangle borderArea = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
	if (borderThickness >= 1) {
		int shift = 0;
		int areaShift = 0;
		if ((borderThickness % 2) == 0) {
			shift = borderThickness / 2;
			areaShift = (shift * 2);
		} else {
			shift = borderThickness / 2;
			areaShift = (shift * 2) + 1;
		}
		borderArea.x += shift;
		borderArea.y += shift;
		borderArea.width -= areaShift;
		borderArea.height -= areaShift;
	}

	gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
	gc.setForeground(borderStyle.getColor());
	gc.drawRectangle(borderArea);

	// Restore GC settings
	gc.setForeground(originalForeground);
	gc.setLineWidth(originalLineWidth);
	gc.setLineStyle(originalLineStyle);
}
 
Example 7
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);
}
 
Example 8
Source File: LineBorderDecorator.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
	int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
	
	Rectangle interiorBounds =
		new Rectangle(
				rectangle.x + borderThickness,
				rectangle.y + borderThickness,
				rectangle.width - (borderThickness * 2),
				rectangle.height - (borderThickness * 2)
		);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
	
	if (borderStyle == null || borderThickness <= 0) {
		return;
	}
	
	// Save GC settings
	Color originalForeground = gc.getForeground();
	int originalLineWidth = gc.getLineWidth();
	int originalLineStyle = gc.getLineStyle();

	gc.setLineWidth(borderThickness);

	Rectangle borderArea = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
	if (borderThickness >= 1) {
		int shift = 0;
		int areaShift = 0;
		if ((borderThickness % 2) == 0) {
			shift = borderThickness / 2;
			areaShift = (shift * 2);
		} else {
			shift = borderThickness / 2;
			areaShift = (shift * 2) + 1;
		}
		borderArea.x += shift;
		borderArea.y += shift;
		borderArea.width -= areaShift;
		borderArea.height -= areaShift;
	}

	gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
	gc.setForeground(borderStyle.getColor());
	gc.drawRectangle(borderArea);

	// Restore GC settings
	gc.setForeground(originalForeground);
	gc.setLineWidth(originalLineWidth);
	gc.setLineStyle(originalLineStyle);
}
 
Example 9
Source File: SwtTextRenderer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private final void renderBorder( IChartComputation cComp, GC gc, Label la, int iLabelLocation,
		Location lo ) throws ChartException
{
	// RENDER THE OUTLINE/BORDER
	final LineAttributes lia = la.getOutline( );
	if ( lia != null
			&& lia.isVisible( )
			&& lia.getColor( ) != null )
	{
		RotatedRectangle rr = cComp.computePolygon( _sxs,
				iLabelLocation,
				la,
				lo.getX( ),
				lo.getY( ),
				null );

		final int iOldLineStyle = gc.getLineStyle( );
		final int iOldLineWidth = gc.getLineWidth( );

		final Color cFG = (Color) _sxs.getColor( lia.getColor( ) );
		gc.setForeground( cFG );

		R31Enhance.setAlpha( gc, lia.getColor( ) );

		int iLineStyle = SWT.LINE_SOLID;
		switch ( lia.getStyle( ).getValue( ) )
		{
			case ( LineStyle.DOTTED                      ) :
				iLineStyle = SWT.LINE_DOT;
				break;
			case ( LineStyle.DASH_DOTTED                      ) :
				iLineStyle = SWT.LINE_DASHDOT;
				break;
			case ( LineStyle.DASHED                      ) :
				iLineStyle = SWT.LINE_DASH;
				break;
		}
		gc.setLineStyle( iLineStyle );
		gc.setLineWidth( lia.getThickness( ) );

		gc.drawPolygon( rr.getSwtPoints( ) );

		gc.setLineStyle( iOldLineStyle );
		gc.setLineWidth( iOldLineWidth );
		cFG.dispose( );
	}
}
 
Example 10
Source File: DataTableDecorator.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) {
    BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
    int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;

    // check how many border lines are configured for that cell
    List<String> labels = cell.getConfigLabels().getLabels();

    int leftBorderThickness = 0;
    int rightBorderThickness = 0;
    int topBorderThickness = 0;
    int bottomBorderThickness = 0;

    if (labels.contains(LEFT_LINE_BORDER_LABEL)) leftBorderThickness = borderThickness;
    if (labels.contains(RIGHT_LINE_BORDER_LABEL)) rightBorderThickness = borderThickness;
    if (labels.contains(TOP_LINE_BORDER_LABEL)) topBorderThickness = borderThickness;
    if (labels.contains(BOTTOM_LINE_BORDER_LABEL)) bottomBorderThickness = borderThickness;

    Rectangle interiorBounds = new Rectangle(rectangle.x + leftBorderThickness,
                                             rectangle.y + topBorderThickness,
                                             (rectangle.width - leftBorderThickness - rightBorderThickness),
                                             (rectangle.height - topBorderThickness - bottomBorderThickness));
    super.paintCell(cell, gc, interiorBounds, configRegistry);

    if (borderStyle == null ||
        borderThickness <= 0 ||
        (leftBorderThickness == 0 && rightBorderThickness == 0 && topBorderThickness == 0 && bottomBorderThickness == 0)) { return; }

    // Save GC settings
    Color originalForeground = gc.getForeground();
    int originalLineWidth = gc.getLineWidth();
    int originalLineStyle = gc.getLineStyle();

    gc.setLineWidth(borderThickness);

    Rectangle borderArea = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
    if (borderThickness >= 1) {
        int shift = 0;
        int correction = 0;

        if ((borderThickness % 2) == 0) {
            shift = borderThickness / 2;
        } else {
            shift = borderThickness / 2;
            correction = 1;
        }

        if (leftBorderThickness >= 1) {
            borderArea.x += shift;
            borderArea.width -= shift;
        }

        if (rightBorderThickness >= 1) {
            borderArea.width -= shift + correction;
        }

        if (topBorderThickness >= 1) {
            borderArea.y += shift;
            borderArea.height -= shift;
        }

        if (bottomBorderThickness >= 1) {
            borderArea.height -= shift + correction;
        }
    }

    gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
    gc.setForeground(borderStyle.getColor());

    // if all borders are set draw a rectangle
    if (leftBorderThickness > 0 && rightBorderThickness > 0 && topBorderThickness > 0 && bottomBorderThickness > 0) {
        gc.drawRectangle(borderArea);
    }
    // else draw a line for every set border
    else {
        Point topLeftPos = new Point(borderArea.x, borderArea.y);
        Point topRightPos = new Point(borderArea.x + borderArea.width, borderArea.y);
        Point bottomLeftPos = new Point(borderArea.x, borderArea.y + borderArea.height);
        Point bottomRightPos = new Point(borderArea.x + borderArea.width, borderArea.y + borderArea.height);

        if (leftBorderThickness > 0) {
            gc.drawLine(topLeftPos.x, topLeftPos.y, bottomLeftPos.x, bottomLeftPos.y);
        }
        if (rightBorderThickness > 0) {
            gc.drawLine(topRightPos.x, topRightPos.y, bottomRightPos.x, bottomRightPos.y);
        }
        if (topBorderThickness > 0) {
            gc.drawLine(topLeftPos.x, topLeftPos.y, topRightPos.x, topRightPos.y);
        }
        if (bottomBorderThickness > 0) {
            gc.drawLine(bottomLeftPos.x, bottomLeftPos.y, bottomRightPos.x, bottomRightPos.y);
        }
    }

    // Restore GC settings
    gc.setForeground(originalForeground);
    gc.setLineWidth(originalLineWidth);
    gc.setLineStyle(originalLineStyle);
}
 
Example 11
Source File: SymbolHelper.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Draw a plus
 *
 * @param gc
 *            the graphics context to draw to
 * @param color
 *            the color of the symbol
 * @param symbolSize
 *            the size of the symbol (radius in pixels)
 * @param centerX
 *            the center point x coordinate
 * @param centerY
 *            the center point y coordinate
 */
public static void drawPlus(GC gc, Color color, int symbolSize, int centerX, int centerY) {
    int prevLs = gc.getLineStyle();
    int prevLw = gc.getLineWidth();
    Color oldColor = gc.getForeground();
    gc.setForeground(color);
    gc.setLineWidth(Math.max(2, symbolSize / 4));
    gc.drawLine(centerX - symbolSize, centerY, centerX + symbolSize, centerY);
    gc.drawLine(centerX, centerY - symbolSize, centerX, centerY + symbolSize);
    gc.setLineStyle(prevLs);
    gc.setLineWidth(prevLw);
    gc.setBackground(oldColor);
}
 
Example 12
Source File: SymbolHelper.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Draw a cross, an X symbol
 *
 * @param gc
 *            the graphics context to draw to
 * @param color
 *            the color of the symbol
 * @param symbolSize
 *            the size of the symbol (radius in pixels)
 * @param centerX
 *            the center point x coordinate
 * @param centerY
 *            the center point y coordinate
 */
public static void drawCross(GC gc, Color color, int symbolSize, int centerX, int centerY) {
    int prevLs = gc.getLineStyle();
    int prevLw = gc.getLineWidth();
    Color oldColor = gc.getForeground();
    gc.setForeground(color);
    gc.setLineWidth(Math.max(2, symbolSize / 4));
    gc.drawLine(centerX - symbolSize, centerY - symbolSize, centerX + symbolSize, centerY + symbolSize);
    gc.drawLine(centerX - symbolSize, centerY + symbolSize, centerX + symbolSize, centerY - symbolSize);
    gc.setLineStyle(prevLs);
    gc.setLineWidth(prevLw);
    gc.setForeground(oldColor);
}