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

The following examples show how to use org.eclipse.swt.graphics.GC#getForeground() . 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: CompositeFreezeLayer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configRegistry) {
	super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry);
	
	gc.setClipping(rectangle);
	Color oldFg = gc.getForeground();
	gc.setForeground(GUIHelper.COLOR_BLUE);
	final int freezeWidth = freezeLayer.getWidth() - 1;
	if (freezeWidth > 0) {
		gc.drawLine(xOffset + freezeWidth, yOffset, xOffset + freezeWidth, yOffset + getHeight() - 1);
	}
	final int freezeHeight = freezeLayer.getHeight() - 1;
	if (freezeHeight > 0) {
		gc.drawLine(xOffset, yOffset + freezeHeight, xOffset + getWidth() - 1, yOffset + freezeHeight);
	}
	gc.setForeground(oldFg);
}
 
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: IndentGuidePainter.java    From IndentGuide with MIT License 6 votes vote down vote up
private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
	int startLine = fTextWidget.getLineIndex(y);
	int endLine = fTextWidget.getLineIndex(y + h - 1);
	if (startLine <= endLine && startLine < fTextWidget.getLineCount()) {
		Color fgColor = gc.getForeground();
		LineAttributes lineAttributes = gc.getLineAttributes();
		gc.setForeground(Activator.getDefault().getColor());
		gc.setLineStyle(lineStyle);
		gc.setLineWidth(lineWidth);
		spaceWidth = gc.getAdvanceWidth(' ');
		if (fIsAdvancedGraphicsPresent) {
			int alpha = gc.getAlpha();
			gc.setAlpha(this.lineAlpha);
			drawLineRange(gc, startLine, endLine, x, w);
			gc.setAlpha(alpha);
		} else {
			drawLineRange(gc, startLine, endLine, x, w);
		}
		gc.setForeground(fgColor);
		gc.setLineAttributes(lineAttributes);
	}
}
 
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: CellRendererBase.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Draw focus marking. Should be called with the corrected drawing area.
     * 
     * @param gc GC
     * @param drawingArea corrected drawing area
     */
    protected void drawFocus(GC gc, Rectangle drawingArea) {
        Color bg = gc.getBackground();
        Color fg = gc.getForeground();
        gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
        gc.drawFocus(drawingArea.x + FOCUSINSETS, drawingArea.y + FOCUSINSETS, drawingArea.width - 2 * FOCUSINSETS,
                drawingArea.height - 2 * FOCUSINSETS - 1);
// gc.drawRectangle(drawingArea.x + 2, drawingArea.y + 2, drawingArea.width - 4, drawingArea.height - 3);
        gc.setForeground(fg);
        gc.setBackground(bg);
    }
 
Example 6
Source File: XYChartLegendImageProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void drawStyleLine(GC gc, Color lineColor, int imageWidth, int imageHeight, @NonNull OutputElementStyle appearance) {
    Color prev = gc.getForeground();
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider2();
    LineStyle lineStyle = LineStyle.valueOf((String) presProvider.getStyleOrDefault(appearance, StyleProperties.SERIES_STYLE, StyleProperties.SeriesStyle.SOLID));
    if (lineStyle != LineStyle.NONE) {
        gc.setForeground(lineColor);
        gc.setLineWidth(((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.WIDTH, 1.0f)).intValue());
        gc.setLineStyle(lineStyle.ordinal());
        gc.drawLine(0, imageHeight / 2, imageWidth, imageHeight / 2);
        gc.setForeground(prev);
    }
}
 
Example 7
Source File: CommonLineNumberChangeRulerColumn.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
void doPaint(GC gc, ILineRange visibleLines) {
	Color foreground= gc.getForeground();
	if (visibleLines != null) {
		if (fRevisionPainter.hasInformation())
			fRevisionPainter.paint(gc, visibleLines);
		else if (fDiffPainter.hasInformation()) // don't paint quick diff colors if revisions are painted
			fDiffPainter.paint(gc, visibleLines);
	}
	gc.setForeground(foreground);
	if (fShowNumbers || fCharacterDisplay)
		super.doPaint(gc, visibleLines);
}
 
Example 8
Source File: XYChartLegendImageProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void drawStyledDot(GC gc, Color lineColor, int imageWidth, int imageHeight, @NonNull OutputElementStyle appearance) {
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider2();
    String symbolStyle = (String) presProvider.getStyleOrDefault(appearance, StyleProperties.SYMBOL_TYPE, StyleProperties.SymbolType.NONE);
    int symbolSize = ((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.HEIGHT, 1.0f)).intValue();
    int centerX = imageWidth / 2;
    int centerY = imageHeight / 2;
    Color prevBg = gc.getBackground();
    Color prevFg = gc.getForeground();
    switch(symbolStyle) {
    case StyleProperties.SymbolType.CIRCLE:
        SymbolHelper.drawCircle(gc, lineColor, symbolSize, centerX, centerY);
        break;
    case StyleProperties.SymbolType.DIAMOND:
        SymbolHelper.drawDiamond(gc, lineColor, symbolSize, centerX, centerY);
        break;
    case StyleProperties.SymbolType.SQUARE:
        SymbolHelper.drawSquare(gc, lineColor, symbolSize, centerX, centerY);
        break;
    case StyleProperties.SymbolType.CROSS:
        SymbolHelper.drawCross(gc, lineColor, symbolSize, centerX, centerY);
        break;
    case StyleProperties.SymbolType.PLUS:
        SymbolHelper.drawPlus(gc, lineColor, symbolSize, centerX, centerY);
        break;

    case StyleProperties.SymbolType.INVERTED_TRIANGLE:
        SymbolHelper.drawInvertedTriangle(gc, lineColor, symbolSize, centerX, centerY);
        break;
    case StyleProperties.SymbolType.TRIANGLE:
        SymbolHelper.drawTriangle(gc, lineColor, symbolSize, centerX, centerY);
        break;

    default:
        // Default is nothing
        break;
    }
    gc.setForeground(prevFg);
    gc.setBackground(prevBg);
}
 
Example 9
Source File: DaySelectionCanvas.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a day on the canvas.
 * @param gc GC used to draw
 * @param days item to be drawn
 * @param days array with days
 * @param columnWidth width of a column
 * @param rowHeight height of a row
 */
private void drawDay(GC gc, int item, int[] days, int columnWidth, int rowHeight) {
	Color tempBackground = null;
	Color tempForeground = null;
	boolean validSelection = isValidSelection(item);
	if (validSelection && (item == selection)) {
		tempBackground = gc.getBackground();
		tempForeground = gc.getForeground();
		gc.setBackground(selectionBackgroundColor);
		gc.setForeground(SELECTION_FOREGROUND);
		int height = rowHeight;
		int width = columnWidth;
		int x = columnWidth * (item % 7);
		if (x > 0) {
			x++;
			width--;
		}
		int y = rowHeight * (item / 7 + 1) + 1;
		height--;
		if (y == rowHeight) {
			y++;
			height--;
		}
		gc.fillRectangle(x, y, width, height);
		gc.setBackground(tempBackground);
	}
 			String dayString = String.valueOf(days[item]);
 			Point position = getDayPosition(gc, item, days, columnWidth, rowHeight);
 			gc.drawText(dayString, position.x, position.y, SWT.DRAW_TRANSPARENT);
 			if (validSelection && (item == selection)) {
		gc.setForeground(tempForeground);
 			}
}
 
Example 10
Source File: BeveledBorderDecorator.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4, rectangle.height - 4);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
	
	// Save GC settings
	Color originalForeground = gc.getForeground();
	
	//TODO: Need to look at the border style
	
	// Up
	gc.setForeground(GUIHelper.COLOR_WIDGET_LIGHT_SHADOW);
	gc.drawLine(rectangle.x, rectangle.y, rectangle.x + rectangle.width - 1, rectangle.y);
	gc.drawLine(rectangle.x, rectangle.y, rectangle.x, rectangle.y + rectangle.height - 1);

	gc.setForeground(GUIHelper.COLOR_WIDGET_HIGHLIGHT_SHADOW);
	gc.drawLine(rectangle.x + 1, rectangle.y + 1, rectangle.x + rectangle.width - 1, rectangle.y + 1);
	gc.drawLine(rectangle.x + 1, rectangle.y + 1, rectangle.x + 1, rectangle.y + rectangle.height - 1);

	// Down
	gc.setForeground(GUIHelper.COLOR_WIDGET_DARK_SHADOW);
	gc.drawLine(rectangle.x, rectangle.y + rectangle.height - 1, rectangle.x + rectangle.width - 1, rectangle.y + rectangle.height - 1);
	gc.drawLine(rectangle.x + rectangle.width - 1, rectangle.y, rectangle.x + rectangle.width - 1, rectangle.y + rectangle.height - 1);

	gc.setForeground(GUIHelper.COLOR_WIDGET_NORMAL_SHADOW);
	gc.drawLine(rectangle.x, rectangle.y + rectangle.height - 2, rectangle.x + rectangle.width - 1, rectangle.y + rectangle.height - 2);
	gc.drawLine(rectangle.x + rectangle.width - 2, rectangle.y, rectangle.x + rectangle.width - 2, rectangle.y + rectangle.height - 2);
	
	// Restore GC settings
	gc.setForeground(originalForeground);
}
 
Example 11
Source File: XYChartLegendImageProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void drawStyleLine(GC gc, Color lineColor, int imageWidth, int imageHeight, @NonNull OutputElementStyle appearance) {
    Color prev = gc.getForeground();
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider();
    LineStyle lineStyle = LineStyle.valueOf((String) presProvider.getStyleOrDefault(appearance, StyleProperties.SERIES_STYLE, StyleProperties.SeriesStyle.SOLID));
    if (lineStyle != LineStyle.NONE) {
        gc.setForeground(lineColor);
        gc.setLineWidth(((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.WIDTH, 1.0f)).intValue());
        gc.setLineStyle(lineStyle.ordinal());
        gc.drawLine(0, imageHeight / 2, imageWidth, imageHeight / 2);
        gc.setForeground(prev);
    }
}
 
Example 12
Source File: JobGraph.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected void drawArrow( GC gc, int[] line ) {
  int mx, my;
  int x1 = line[0] + offset.x;
  int y1 = line[1] + offset.y;
  int x2 = line[2] + offset.x;
  int y2 = line[3] + offset.y;
  int x3;
  int y3;
  int x4;
  int y4;
  int a, b, dist;
  double factor;
  double angle;

  // gc.setLineWidth(1);
  // WuLine(gc, black, x1, y1, x2, y2);

  gc.drawLine( x1, y1, x2, y2 );

  // What's the distance between the 2 points?
  a = Math.abs( x2 - x1 );
  b = Math.abs( y2 - y1 );
  dist = (int) Math.sqrt( a * a + b * b );

  // determine factor (position of arrow to left side or right side 0-->100%)
  if ( dist >= 2 * iconsize ) {
    factor = 1.5;
  } else {
    factor = 1.2;
  }

  // in between 2 points
  mx = (int) ( x1 + factor * ( x2 - x1 ) / 2 );
  my = (int) ( y1 + factor * ( y2 - y1 ) / 2 );

  // calculate points for arrowhead
  angle = Math.atan2( y2 - y1, x2 - x1 ) + Math.PI;

  x3 = (int) ( mx + Math.cos( angle - theta ) * size );
  y3 = (int) ( my + Math.sin( angle - theta ) * size );

  x4 = (int) ( mx + Math.cos( angle + theta ) * size );
  y4 = (int) ( my + Math.sin( angle + theta ) * size );

  // draw arrowhead
  // gc.drawLine(mx, my, x3, y3);
  // gc.drawLine(mx, my, x4, y4);
  // gc.drawLine( x3, y3, x4, y4 );
  Color fore = gc.getForeground();
  Color back = gc.getBackground();
  gc.setBackground( fore );
  gc.fillPolygon( new int[] { mx, my, x3, y3, x4, y4 } );
  gc.setBackground( back );
}
 
Example 13
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 14
Source File: RemoteCursorStrategy.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param annotation An RemoteCursorAnnotation passed by the {@link AnnotationPainter}
 * @param offset offset of the end of the Selection
 * @param length always 0, will be ignored
 */
@Override
public void draw(
    Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
  Point currentCursorPosition = textWidget.getLocationAtOffset(offset);

  // clearing mode
  if (gc == null) {
    /*
     * Redraw the surrounding area of the cursor. Because we draw a line
     * with a width larger than 1, we have to clear the area around the
     * actual coordinates (start a bit more left, and extend a bit to
     * the right).
     */
    textWidget.redraw(
        currentCursorPosition.x - CURSOR_WIDTH / 2,
        currentCursorPosition.y,
        CURSOR_WIDTH + 1,
        textWidget.getLineHeight(),
        false);

    return;
  }

  final Color oldBackground = gc.getBackground();
  final Color oldForeground = gc.getForeground();

  /*
   * Draw the cursor line
   */
  gc.setBackground(color);
  gc.setForeground(color);

  gc.setLineWidth(CURSOR_WIDTH);
  gc.drawLine(
      currentCursorPosition.x,
      currentCursorPosition.y,
      currentCursorPosition.x,
      currentCursorPosition.y + textWidget.getLineHeight());

  // set back the colors like they were before
  gc.setBackground(oldBackground);
  gc.setForeground(oldForeground);
}
 
Example 15
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 16
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 17
Source File: TextPiece.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void paint(final GC gc, final int x, final int y) {
	Font oldFont = gc.getFont();
	Color oldForeground = gc.getForeground();
	Color oldBackground = gc.getBackground();

	final int width = getSize().x;
	final int align = style.getAlignment();

	try {
		boolean transparent = initGC(gc);

		FontMetrics fm = gc.getFontMetrics();
		int lineHeight = fm.getHeight();

		boolean strikeout = style.getStrikeout();
		boolean underline = style.getUnderline();
		int lineThickness = Math.max(1, fm.getDescent() / 3);
		int strikeoutOffset = fm.getLeading() + fm.getAscent() / 2;
		int underlineOffset = ascent + lineThickness;

		for (int i = 0; i < lines.length; i++) {
			String line = lines[i];
			int lineWidth = gc.stringExtent(line).x;
			int offset = getHorzAlignmentOffset(align, lineWidth, width);

			gc.drawString(lines[i], x + offset, y + lineHeight * i,
					transparent);
			if (strikeout || underline) {
				Color saveBackground = gc.getBackground();
				gc.setBackground(gc.getForeground());
				if (strikeout)
					gc.fillRectangle(x + offset, y + lineHeight * i
							+ strikeoutOffset, lineWidth, lineThickness);
				if (underline)
					gc.fillRectangle(x + offset, y + lineHeight * i
							+ underlineOffset, lineWidth, lineThickness);
				gc.setBackground(saveBackground);
			}
		}
	} finally {
		restoreGC(gc, oldFont, oldForeground, oldBackground);
	}
}
 
Example 18
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 19
Source File: InnerTagRender.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public void draw(GC gc, InnerTagBean innerTagBean, int x, int y) {
	Point tagSize = calculateTagSize(innerTagBean);
	if (tag != null && tag.isSelected()) {
		Color b = gc.getBackground();
		gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
		gc.fillRectangle(0, 0, tagSize.x, tagSize.y);
		gc.setBackground(b);
	}
	int[] tagAreaPoints = calculateTagArea(tagSize, innerTagBean, x, y);
	String strInx = String.valueOf(innerTagBean.getIndex());
	Color gcBgColor = gc.getBackground();
	Color gcFgColor = gc.getForeground();
	Font gcFont = gc.getFont();
	gc.setFont(TAG_FONT);
	// gc.setBackground(ColorConfigBean.getInstance().getTm90Color());
	// Point p = calculateTagSize(innerTagBean);
	// gc.fillRectangle(x, y, p.x, p.y);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	gc.fillPolygon(tagAreaPoints);
	// gc.drawPolygon(tagAreaPoints);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	switch (innerTagBean.getType()) {
	case START:
		gc.drawText(strInx, tagAreaPoints[0] + MARGIN_H, tagAreaPoints[1] + MARGIN_V);
		break;
	default:
		gc.drawText(strInx, tagAreaPoints[2] + MARGIN_H, tagAreaPoints[3] + MARGIN_V);
		break;
	}
	gc.setBackground(gcBgColor);
	gc.setForeground(gcFgColor);
	gc.setFont(gcFont);
}
 
Example 20
Source File: XferStatsPanel.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
private boolean
draw(
	GC		gc )
{
	boolean above = source.y_pos > target.y_pos;
	
	int x1 = source.x_pos + flag_width/2;
	int x2 = target.x_pos + flag_width/2;

	int y1;
	int y2;
	
	if ( above ){
		y1 = source.y_pos - text_height;		
		y2 = target.y_pos + flag_height + text_height;
	}else{
		y1 = source.y_pos + flag_height + text_height;			
		y2 = target.y_pos - text_height;	
	}
	
	int[] xy1 = scale.getXY( x1, y1 );
	int[] xy2 = scale.getXY( x2, y2 );
	
	Color old = gc.getForeground();
	
	boolean hovering =  hover_node != null && (source.cc.equals( hover_node.cc ) || target.cc.equals( hover_node.cc ));
	
	if ( hovering ){
		
		gc.setForeground( Colors.fadedGreen );
		
		gc.setLineWidth( 2 );
		
	}else{
	
		long	per_sec = count/60;
		
		int kinb = DisplayFormatters.getKinB();

		if ( per_sec > 10*kinb*kinb ){
			
			gc.setForeground( Colors.blue );
			
		}else{
			int	blues_index ;
			
			if ( per_sec > kinb*kinb ){
				blues_index = Colors.BLUES_DARKEST;
			}else if ( per_sec > 100*kinb ){
				blues_index = Colors.BLUES_MIDDARK;
			}else if ( per_sec > 10*kinb ){
				blues_index = 5;
			}else{
				blues_index = 3;
			}				
		
			gc.setForeground( Colors.blues[ blues_index ]);
		}
		
		gc.setLineWidth( 1 );
	}
	
	gc.drawLine(xy1[0],xy1[1],xy2[0],xy2[1] );
				
	gc.setForeground( old );
	
	return( hovering );
}