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

The following examples show how to use org.eclipse.swt.graphics.GC#getLineWidth() . 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: TimeGraphRender.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public final void draw(@Nullable ITimeGraphPresentationProvider provider, GC gc) {
    Rectangle bounds = getBounds();
    // basic sanity
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    int prevAlpha = gc.getAlpha();
    Color prevBgColor = gc.getBackground();
    Color prevFgColor = gc.getForeground();
    int prevLineWidth = gc.getLineWidth();
    setContext(gc);
    innerDraw(gc);
    if (fLineWidth != NO_BORDER) {
        setContext(gc);
        gc.setAlpha(fBorderColor.getAlpha());
        drawBorder(gc);
    }
    setContext(gc);
    drawLabel(gc);
    if (provider != null) {
        gc.setLineWidth(prevLineWidth);
        gc.setBackground(prevBgColor);
        gc.setForeground(prevFgColor);
        gc.setAlpha(prevAlpha);
        postDraw(provider, gc);
    }
    // reset context
    gc.setLineWidth(prevLineWidth);
    gc.setBackground(prevBgColor);
    gc.setForeground(prevFgColor);
    gc.setAlpha(prevAlpha);
}
 
Example 3
Source File: RendererBase.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method saving several GC attributes to loal variables. The values can be restored with
 * <code>restoreGCAttributes</code>.
 * 
 * @param gc GC to save attributes for
 */
protected void saveGCAttributes(GC gc) {
    _bgColor = gc.getBackground();
    _fgColor = gc.getForeground();
    _font = gc.getFont();
    _lineWidth = gc.getLineWidth();
}
 
Example 4
Source File: RendererBase.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method saving several GC attributes to loal variables. The values can be restored with
 * <code>restoreGCAttributes</code>.
 * 
 * @param gc GC to save attributes for
 */
protected void saveGCAttributes(GC gc) {
    _bgColor = gc.getBackground();
    _fgColor = gc.getForeground();
    _font = gc.getFont();
    _lineWidth = gc.getLineWidth();
}
 
Example 5
Source File: PaintUtils.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
public static void drawRoundedBorder(GC gc, Rectangle bounds, Color borderColor) {
  Color backupBackground = gc.getBackground();
  int backupLineWidth = gc.getLineWidth();

  gc.setLineWidth(LINE_WEIGHT);
  gc.setForeground(borderColor);
  gc.drawRoundRectangle(
      bounds.x, bounds.y, bounds.width - LINE_WEIGHT, bounds.height - LINE_WEIGHT, ARC, ARC);

  gc.setBackground(backupBackground);
  gc.setLineWidth(backupLineWidth);
}
 
Example 6
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 7
Source File: RingOutlineExample.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ControllableShape[] getControllableShapes() {
	return new ControllableShape[] { new ControllableShape() {
		{
			addControlPoints(new Point(100, 100), new Point(400, 100),
					new Point(400, 200));
			addControlPoints(new Point(400, 100), new Point(400, 400),
					new Point(300, 400));
			addControlPoints(new Point(400, 400), new Point(100, 400),
					new Point(100, 300));
			addControlPoints(new Point(100, 400), new Point(100, 100),
					new Point(200, 100));
		}

		@Override
		public Ring getShape() {
			Point[] cp = getPoints();

			Polygon[] polygons = new Polygon[cp.length / 3];
			for (int i = 0; i < polygons.length; i++) {
				polygons[i] = new Polygon(cp[3 * i], cp[3 * i + 1],
						cp[3 * i + 2]);
			}

			return new Ring(polygons);
		}

		@Override
		public void onDraw(GC gc) {
			Ring ring = getShape();

			gc.setForeground(
					Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
			int lineWidth = gc.getLineWidth();
			gc.setLineWidth(1);

			for (Polyline outline : ring.getOutlines()) {
				gc.drawPolyline(Geometry2SWT.toSWTPointArray(outline));
				gc.setLineWidth(gc.getLineWidth() + 1);
			}

			gc.setLineWidth(lineWidth);
		}
	} };
}
 
Example 8
Source File: TimeGraphControl.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw many items at once
 *
 * @param bounds
 *            The bounds of the control
 * @param timeProvider
 *            The time provider
 * @param items
 *            The array items to draw
 * @param topIndex
 *            The index of the first element to draw
 * @param nameSpace
 *            The name space width
 * @param gc
 *            Graphics context
 */
public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider,
        Item[] items, int topIndex, int nameSpace, GC gc) {
    int bottomIndex = Integer.min(topIndex + countPerPage() + 1, items.length);
    for (int i = topIndex; i < bottomIndex; i++) {
        Item item = items[i];
        drawItem(item, bounds, timeProvider, i, nameSpace, gc);
    }
    TraceCompassLogUtils.traceCounter(LOGGER, Level.FINER, fDrawItemsCountLabel, bottomIndex - topIndex);

    if (gc == null) {
        return;
    }

    /*
     * Draw entries, entries contain events
     */
    for (DeferredEntry entry : fPostDrawEntries) {
        entry.draw(fTimeGraphProvider, gc);
    }

    // Defer line drawing
    for (DeferredLine line : fLines) {
        line.draw(fTimeGraphProvider, gc);
    }

    Color prev = gc.getForeground();
    Color black = TimeGraphRender.getColor(BLACK.toInt());
    gc.setForeground(black);
    int prevAA = gc.getAntialias();
    /*
     * BUG: Doesn't work in certain distros of Linux the end result is
     * anti-aliased points. They may actually look better but are not as
     * accurate.
     */
    gc.setAntialias(SWT.OFF);
    int prevLineWidth = gc.getLineWidth();
    gc.setLineWidth(1);
    // Deferred point drawing, they are aggregated into segments
    for (DeferredSegment seg : fPoints) {
        seg.draw(fTimeGraphProvider, gc);
    }
    gc.setLineWidth(prevLineWidth);
    gc.setAntialias(prevAA);
    // Draw selection at very end
    for (Rectangle rectangle : fSelectedRectangles) {
        int arc = Math.min(rectangle.height + 1, rectangle.width) / 2;
        gc.drawRoundRectangle(rectangle.x - 1, rectangle.y - 1, rectangle.width, rectangle.height + 1, arc, arc);
    }
    gc.setForeground(prev);
}
 
Example 9
Source File: TimeGraphControl.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw an arrow
 *
 * @param colors
 *            Color scheme
 * @param event
 *            Time event for which we're drawing the arrow
 * @param rect
 *            The arrow rectangle
 * @param gc
 *            Graphics context
 * @return true if the arrow was drawn
 */
protected boolean drawArrow(TimeGraphColorScheme colors, @NonNull ITimeEvent event,
        Rectangle rect, GC gc) {

    if (rect == null || ((rect.height == 0) && (rect.width == 0))) {
        return false;
    }
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(event);
    if (elementStyle == null) {
        return false;
    }

    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    rgba = (rgba != null) ? rgba : BLACK;
    int colorInt = rgba.toInt();
    Color color = TimeGraphRender.getColor(colorInt);
    int alpha = rgba.getAlpha();
    int prevAlpha = gc.getAlpha();
    gc.setAlpha(alpha);

    gc.setForeground(color);
    gc.setBackground(color);
    int old = gc.getLineWidth();
    Float widthFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.WIDTH);
    if (widthFactor == null) {
        Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
        widthFactor = (heightFactor != null) ? heightFactor * 10.0f : 1.0f;
    }
    widthFactor = Math.max(1.0f, Math.min(10.0f, widthFactor));
    gc.setLineWidth(widthFactor.intValue());
    /* Draw the arrow */
    Point newEndpoint = drawArrowHead(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, widthFactor, gc);
    gc.drawLine(rect.x, rect.y, newEndpoint.x, newEndpoint.y);
    gc.setLineWidth(old);
    gc.setAlpha(prevAlpha);
    if (!Boolean.TRUE.equals(styleManager.getStyle(elementStyle, ITimeEventStyleStrings.annotated()))) {
        fPostDrawArrows.add(new PostDrawEvent(event, rect));
    }
    return true;
}
 
Example 10
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 11
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 12
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 13
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 14
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 15
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);
}