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

The following examples show how to use org.eclipse.swt.graphics.GC#getBackground() . 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: PercentageBarDecorator.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	Color originalBackground = gc.getBackground();

	double factor = Math.min(1.0, ((Double) cell.getDataValue()).doubleValue());
	factor = Math.max(0.0, factor);

	Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int)(rectangle.width * factor), rectangle.height);
	Rectangle bounds = cell.getBounds();
	gc.setBackgroundPattern(new Pattern(Display.getCurrent(),
			bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
			GUIHelper.getColor(new RGB(187, 216, 254)),
			GUIHelper.getColor(new RGB(255, 255, 255))));
	gc.fillRectangle(bar);

	gc.setBackground(originalBackground);

	super.paintCell(cell, gc, rectangle, configRegistry);
}
 
Example 2
Source File: PercentageBarDecorator.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	Color originalBackground = gc.getBackground();

	double factor = Math.min(1.0, ((Double) cell.getDataValue()).doubleValue());
	factor = Math.max(0.0, factor);

	Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int)(rectangle.width * factor), rectangle.height);
	Rectangle bounds = cell.getBounds();
	gc.setBackgroundPattern(new Pattern(Display.getCurrent(),
			bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
			GUIHelper.getColor(new RGB(187, 216, 254)),
			GUIHelper.getColor(new RGB(255, 255, 255))));
	gc.fillRectangle(bar);

	gc.setBackground(originalBackground);

	super.paintCell(cell, gc, rectangle, configRegistry);
}
 
Example 3
Source File: BackgroundImagePainter.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	// Save GC settings
	Color originalBackground = gc.getBackground();
	Color originalForeground = gc.getForeground();

	gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bgImage));

	gc.fillRectangle(rectangle);
	gc.setBackgroundPattern(null);

	if (isNotNull(separatorColor)) {
		gc.setForeground(separatorColor);
		gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1, rectangle.y + rectangle.height);
		gc.drawLine(rectangle.x - 1 + rectangle.width, rectangle.y, rectangle.x - 1 + rectangle.width, rectangle.y + rectangle.height);
	}

	// Restore original GC settings
	gc.setBackground(originalBackground);
	gc.setForeground(originalForeground);

	// Draw interior
	Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4,	rectangle.height - 4);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
}
 
Example 4
Source File: BackgroundImagePainter.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
	// Save GC settings
	Color originalBackground = gc.getBackground();
	Color originalForeground = gc.getForeground();

	gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bgImage));

	gc.fillRectangle(rectangle);
	gc.setBackgroundPattern(null);

	if (isNotNull(separatorColor)) {
		gc.setForeground(separatorColor);
		gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1, rectangle.y + rectangle.height);
		gc.drawLine(rectangle.x - 1 + rectangle.width, rectangle.y, rectangle.x - 1 + rectangle.width, rectangle.y + rectangle.height);
	}

	// Restore original GC settings
	gc.setBackground(originalBackground);
	gc.setForeground(originalForeground);

	// Draw interior
	Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4,	rectangle.height - 4);
	super.paintCell(cell, gc, interiorBounds, configRegistry);
}
 
Example 5
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 6
Source File: LineNumberPainter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
	Rectangle cellBounds = cell.getBounds();
	// Color backgroundColor = CellStyleUtil.getCellStyle(cell,
	// configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
	// if (backgroundColor != null) {
	Color originalBackground = gc.getBackground();

	gc.setBackground(GUIHelper.COLOR_WIDGET_BACKGROUND);
	gc.fillRectangle(bounds);

	gc.setBackground(originalBackground);
	// }
	if (checkSplit(cell, configRegistry)) {
		// Color originalBackground = gc.getBackground();
		// gc.setBackground(GUIHelper.COLOR_RED);
		// gc.fillRectangle(cellBounds);
		// gc.setBackground(originalBackground);
		// gc.setBackgroundPattern(new Pattern(Display.getCurrent(),
		// XliffEditorGUIHelper.getImage(XliffEditorGUIHelper.ImageName.SPLITPOINT)));
		Image image = XliffEditorGUIHelper.getImage(XliffEditorGUIHelper.ImageName.SPLITPOINT);
		gc.drawImage(image, cellBounds.width / 2 - image.getBounds().width / 2, cellBounds.y + cellBounds.height
				/ 2 - image.getBounds().height / 2);
		// gc.setBackgroundPattern(null);
		//
		// }
		// else {
	}
	super.paintCell(cell, gc, bounds, configRegistry);
}
 
Example 7
Source File: TableHierarchyRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
protected void drawTriangleDown(GC gc, int size, int x, int y) {
    Color bg = gc.getBackground();
    gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    int[] pArray = new int[] { x, y, x + size, y, x + size / 2, y + size - 3 };
    gc.fillPolygon(pArray);
    gc.setBackground(bg);
}
 
Example 8
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 9
Source File: CellRendererBase.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws a cell selection by overlaying alpha blended area using SELECTIONCOLOR.
 * 
 * @param gc GC
 * @param area area of the cell
 * @param style cellstyle
 * @param selected true if selecetd
 * @param printing true if printing - no selection will be drawn when printing
 */
protected void drawSelection(GC gc, Rectangle area, ICellStyle style, boolean selected, boolean printing) {
    Color c = gc.getBackground();
    Color bg;

    if (selected && !printing) {
        bg = SELECTIONCOLOR;
        gc.setBackground(bg);
        int alpha = gc.getAlpha();
        gc.setAlpha(SELECTIONALPHA);
        gc.fillRectangle(area);
        gc.setAlpha(alpha);
        gc.setBackground(c);
    }
}
 
Example 10
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 11
Source File: ImageCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 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);
    Object value = column.getValue(row);
    if (value != null) {
        if (value instanceof Image) {
            Image img = (Image) value;
            int x = rect.x + (rect.width - img.getBounds().width) / 2;
            int y = rect.y + (rect.height - img.getBounds().height) / 2;
            gc.drawImage(img, x, y);
        } else {
            // indicate error with red fill
            Color bg = gc.getBackground();
            gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
            gc.fillRectangle(rect);
            gc.setBackground(bg);
        }
    }
    if (drawFocus) {
        drawFocus(gc, drawingArea);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);

}
 
Example 12
Source File: TableHierarchyRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected void drawTriangleDown(GC gc, int size, int x, int y) {
    Color bg = gc.getBackground();
    gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    int[] pArray = new int[] { x, y, x + size, y, x + size / 2, y + size - 3 };
    gc.fillPolygon(pArray);
    gc.setBackground(bg);
}
 
Example 13
Source File: CellRendererBase.java    From translationstudio8 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 14
Source File: ClassImageRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 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);
    Object value = column.getValue(row);
    String key = getKeyForClass(value.getClass());

    if (key != null) {
        Image img = null;
        img = getImageRegistry().get(key);
        int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
        int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
        gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
                scaleY(img.getBounds().height));
    } else {
        // indicate error with red fill
        Color bg = gc.getBackground();
        gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
        gc.fillRectangle(rect);
        gc.setBackground(bg);
    }
    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);

}
 
Example 15
Source File: TreeThemer.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void addCustomTreeControlDrawing()
{
	// Hack to overdraw the native tree expand/collapse controls and use custom plus/minus box.
	if (isMacOSX || isUbuntu || controlIsDisposed())
	{
		return;
	}

	// FIXME The native control/arrow still shows through on OpenSuSE 11.4
	final Tree tree = getTree();
	customDrawingListener = new Listener()
	{
		public void handleEvent(Event event)
		{
			if (!invasiveThemesEnabled())
			{
				return;
			}
			GC gc = event.gc;
			Widget item = event.item;
			boolean isExpanded = false;
			boolean draw = false;
			if (item instanceof TreeItem)
			{
				TreeItem tItem = (TreeItem) item;
				isExpanded = tItem.getExpanded();
				draw = tItem.getItemCount() > 0;
			}
			if (!draw)
			{
				return;
			}
			final int width = 10;
			final int height = 12;
			final int x = event.x - 16;
			final int y = event.y + 4;
			Color oldBackground = gc.getBackground();
			gc.setBackground(getBackground());
			// wipe out the native control
			gc.fillRectangle(x, y, width + 1, height - 1); // +1 and -1 because of hovering selecting on windows
			// vista
			// draw a plus/minus based on expansion!
			gc.setBackground(getForeground());
			// draw surrounding box (with alpha so that it doesn't get too strong).
			gc.setAlpha(195);
			gc.drawRectangle(x + 1, y + 1, width - 2, width - 2); // make it smaller than the area erased
			gc.setAlpha(255);
			// draw '-'
			int halfWidth = width >> 1;
			gc.drawLine(x + 3, y + halfWidth, x + 7, y + halfWidth);
			if (!isExpanded)
			{
				// draw '|' to make it a plus
				gc.drawLine(x + halfWidth, y + 3, x + halfWidth, y + 7);
			}
			gc.setBackground(oldBackground);

			event.detail &= ~SWT.BACKGROUND;
		}
	};
	tree.addListener(SWT.PaintItem, customDrawingListener);
}
 
Example 16
Source File: RowResizeDragMode.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public void paintOverlay(GC gc, ILayer layer) {
    Color originalBackgroundColor = gc.getBackground();
    gc.setBackground(GUIHelper.COLOR_DARK_GRAY);
    gc.fillRectangle(0, currentY - (ROW_RESIZE_OVERLAY_HEIGHT / 2), layer.getWidth(), ROW_RESIZE_OVERLAY_HEIGHT);
    gc.setBackground(originalBackgroundColor);
}
 
Example 17
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 18
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 19
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 20
Source File: CellRendererBase.java    From translationstudio8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Draw the cell background.
 * 
 * @param gc GC
 * @param area cell drawing area
 * @param style cell style
 * @param selected true for selected
 * @param printing true if printing
 */
protected void drawBackground(GC gc, Rectangle area, ICellStyle style, boolean selected, boolean printing) {
    Color c = gc.getBackground();
    Color bg;
    bg = getBackgroundColor(style, printing);
    gc.setBackground(bg);
    gc.fillRectangle(area);
    gc.setBackground(c);
}