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

The following examples show how to use org.eclipse.swt.graphics.GC#setAdvanced() . 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: OscilloscopeDispatcher.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private Image createGridImage() {
	Display display = Display.getDefault();
	int width = getOscilloscope().getGridSquareSize();
	Image image = new Image(display, width, width);
	GC gc = new GC(image);

	gc.setAdvanced(true);
	gc.setBackground(getOscilloscope().getGridBackground());
	gc.fillRectangle(0, 0, width, width);

	gc.setForeground(getOscilloscope().getGridForeground());
	gc.setLineWidth(getOscilloscope().getGridLineWidth());
	gc.drawLine(width/2, 0, width/2, width);
	gc.drawLine(0, width/2, width, width/2);
	gc.dispose();
	return image;
}
 
Example 2
Source File: ToolbarItem.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Calculate size of item.
 */
public void calculateSize()
{
	Image calcSizeImage = new Image(Display.getDefault(), 1, 1);

	GC gc = new GC(calcSizeImage);
	gc.setAdvanced(true);
	gc.setAntialias(SWT.OFF);
	gc.setFont(parent.getFont());

	width = 10;

	if (image != null)
	{
		width += image.getImageData().width;
	}

	if (text.length() > 0)
	{
		width += getTextWidth(gc, text) + 9;
	}

	gc.dispose();
	calcSizeImage.dispose();
}
 
Example 3
Source File: SComposite.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public SComposite(Composite parent, int style) {
	super(parent, SWT.NONE);

	borderStyle = style;
	borderWidth = 0;

	updateBackground();
	setBackground(parent.getBackground());

	// setup graphics support
	GC gc = new GC(Display.getCurrent());
	gc.setAdvanced(true);
	advancedGraphics = gc.getAdvanced();
	gc.dispose();

	setLayout(new GridLayout());
	setMargins(0,0);

	addListener(SWT.Paint, this);
}
 
Example 4
Source File: AdvancedGC.java    From swt-bling with MIT License 6 votes vote down vote up
public static void setAdvanced(GC gc, boolean targetSetting) {
    if (targetSetting) {
        try {
            gc.setAdvanced(true);
            gc.setAntialias(SWT.ON);
            gc.setTextAntialias(SWT.ON);
            gc.setInterpolation(SWT.HIGH);
        } catch (SWTException e) {
            if (!loggedAdvanced) {
                log.log(Level.WARNING, "Unable to set advanced drawing", e);
                loggedAdvanced = true;
            }
        }
    } else {
        gc.setAdvanced(false);
    }

}
 
Example 5
Source File: ContentAssistText.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void paintControlBorder(final PaintEvent e) {
    final GC gc = e.gc;
    final Display display = e.display;
    if (display != null && gc != null && !gc.isDisposed()) {
        final Control focused = display.getFocusControl();
        final GC parentGC = gc;
        parentGC.setAdvanced(true);
        final Rectangle r = ContentAssistText.this.getBounds();
        if (focused == null || focused.getParent() != null && !focused.getParent().equals(ContentAssistText.this)) {
            parentGC.setForeground(display.getSystemColor(SWT.COLOR_GRAY));
        } else {
            parentGC.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_BORDER));
        }
        parentGC.setLineWidth(1);
        parentGC.drawRectangle(0, 0, r.width - 1, r.height - 1);
    }
}
 
Example 6
Source File: IndentGuidePainter.java    From IndentGuide with MIT License 6 votes vote down vote up
/**
 * Creates a new painter for the given text viewer.
 * 
 * @param textViewer
 *            the text viewer the painter should be attached to
 */
public IndentGuidePainter(ITextViewer textViewer) {
	super();
	fTextViewer = textViewer;
	fTextWidget = textViewer.getTextWidget();
	GC gc = new GC(fTextWidget);
	gc.setAdvanced(true);
	fIsAdvancedGraphicsPresent = gc.getAdvanced();
	gc.dispose();

	IPreferenceStore store = Activator.getDefault().getPreferenceStore();
	lineAlpha = store.getInt(PreferenceConstants.LINE_ALPHA);
	lineStyle = store.getInt(PreferenceConstants.LINE_STYLE);
	lineWidth = store.getInt(PreferenceConstants.LINE_WIDTH);
	lineShift = store.getInt(PreferenceConstants.LINE_SHIFT);
	drawLeftEnd = store.getBoolean(PreferenceConstants.DRAW_LEFT_END);
	drawBlankLine = store.getBoolean(PreferenceConstants.DRAW_BLANK_LINE);
	skipCommentBlock = store
			.getBoolean(PreferenceConstants.SKIP_COMMENT_BLOCK);
}
 
Example 7
Source File: WhitespaceCharacterPainter.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new painter for the given text viewer.
 * 
 * @param textViewer
 *            the text viewer the painter should be attached to
 */
public WhitespaceCharacterPainter(ITextViewer textViewer)
{
	super();
	fTextViewer = textViewer;
	fTextWidget = textViewer.getTextWidget();
	GC gc = new GC(fTextWidget);
	gc.setAdvanced(true);
	fIsAdvancedGraphicsPresent = gc.getAdvanced();
	gc.dispose();
}
 
Example 8
Source File: IndentGuidesPainter.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new painter for the given text viewer.
 * 
 * @param textViewer
 *            the text viewer the painter should be attached to
 * @param iXdsModuleIndentModel 
 */
private IndentGuidesPainter(ITextViewer textViewer, IndentGuidesModel indentsModel) {
	super();
	fTextViewer = textViewer;
	fTextWidget = textViewer.getTextWidget();
	GC gc = new GC(fTextWidget);
	try {
		gc.setAdvanced(true);
		fIsAdvancedGraphicsPresent = gc.getAdvanced();
	} finally {
		gc.dispose();
	}
	
	this.indentsModel = indentsModel;
}
 
Example 9
Source File: EyeButton.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawEye(final GC gc, final Color clr) {
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setLineWidth(2);

	final Rectangle rect = getClientArea();
	final int eyeWidth = (int) (rect.width * .7);
	final int eyeHeight = (int) (rect.height * .5);
	gc.setForeground(clr);
	gc.drawOval((int) (rect.width * .15), (int) (rect.height * .25), eyeWidth, eyeHeight);

	gc.setBackground(clr);
	gc.fillOval(rect.width / 2 - CIRCLE_RAY / 2, rect.height / 2 - CIRCLE_RAY / 2, CIRCLE_RAY, CIRCLE_RAY);
}
 
Example 10
Source File: MainSplash.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Paint.
 *
 * @param gc
 */
private void paint(GC gc) {
	Point size = shell.getSize();
    Point offsets = gc.textExtent(version);
    gc.setAdvanced(true);
    gc.setAntialias(SWT.ON);
    gc.setInterpolation(SWT.ON);
    gc.drawImage(splash, 0,  0, splash.getBounds().width, splash.getBounds().height, 0, 0, size.x,  size.y);
    gc.setForeground(GUIHelper.COLOR_BLACK);
    gc.drawString(version, size.x - (int)offsets.x - 10, size.y - (int)offsets.y - 10, true);
}
 
Example 11
Source File: PrintPreview.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void configureAntialiasing(GC printerGC) {
	printerGC.setAdvanced(true);
	printerGC.setAntialias(SWT.ON);
	printerGC.setTextAntialias(SWT.ON);
	printerGC.setInterpolation(SWT.HIGH);
}
 
Example 12
Source File: AbstractPaintManager.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void drawScope(final GanttComposite ganttComposite, final ISettings settings, final IColorManager colorManager, final GanttEvent event, final GC gc, final boolean threeDee, final int dayWidth, final int x, final int y, final int eventWidth, final Rectangle bounds) {
    final List scopeEvents = event.getScopeEvents();

    // empty scope
    if (scopeEvents.isEmpty()) {
        return;
    }

    gc.setForeground(colorManager.getScopeGradientColorTop());
    gc.setBackground(colorManager.getScopeGradientColorBottom());

    gc.fillGradientRectangle(x, y, eventWidth, settings.getEventHeight() - 5, true);
    gc.setForeground(colorManager.getScopeBorderColor());
    gc.drawRectangle(new Rectangle(x, y, eventWidth, settings.getEventHeight() - 5));

    gc.setForeground(colorManager.getScopeGradientColorTop());
    gc.setBackground(colorManager.getScopeGradientColorBottom());
    gc.fillGradientRectangle(x, y, dayWidth / 2, settings.getEventHeight(), true);
    gc.fillGradientRectangle(x + eventWidth + (dayWidth / 2) - dayWidth, y, dayWidth / 2, settings.getEventHeight(), true);

    gc.setForeground(colorManager.getScopeBorderColor());
    gc.drawRectangle(x, y, dayWidth / 2, settings.getEventHeight());
    gc.drawRectangle(x + eventWidth + (dayWidth / 2) - dayWidth, y, dayWidth / 2, settings.getEventHeight());

    if (threeDee) {
        final boolean alpha = (colorManager.useAlphaDrawing() || colorManager.useAlphaDrawingOn3DEventDropShadows());
        if (alpha) {
            gc.setAlpha(200);
        }

        gc.setForeground(colorManager.getFadeOffColor1());
        gc.drawLine(x, y + settings.getEventHeight() + 1, x + dayWidth / 2, y + settings.getEventHeight() + 1);
        gc.drawLine(x + eventWidth - (dayWidth / 2), y + settings.getEventHeight() + 1, x + eventWidth, y + settings.getEventHeight() + 1);
        gc.drawLine(x + (dayWidth / 2) + 1, y + settings.getEventHeight() - 4, x + eventWidth - (dayWidth / 2) - 1, y + settings.getEventHeight() - 4);

        if (alpha) {
            gc.setAlpha(100);
        }

        gc.setForeground(colorManager.getFadeOffColor2());
        gc.drawLine(x, y + settings.getEventHeight() + 2, x + dayWidth / 2, y + settings.getEventHeight() + 2);
        gc.drawLine(x + eventWidth - (dayWidth / 2), y + settings.getEventHeight() + 2, x + eventWidth, y + settings.getEventHeight() + 2);
        gc.drawLine(x + (dayWidth / 2) + 1, y + settings.getEventHeight() - 3, x + eventWidth - (dayWidth / 2) - 1, y + settings.getEventHeight() - 3);

        if (alpha) {
            gc.setAlpha(50);
        }

        gc.setForeground(colorManager.getFadeOffColor3());
        gc.drawLine(x, y + settings.getEventHeight() + 3, x + dayWidth / 2, y + settings.getEventHeight() + 3);
        gc.drawLine(x + eventWidth - (dayWidth / 2), y + settings.getEventHeight() + 3, x + eventWidth, y + settings.getEventHeight() + 3);
        gc.drawLine(x + (dayWidth / 2) + 1, y + settings.getEventHeight() - 2, x + eventWidth - (dayWidth / 2) - 1, y + settings.getEventHeight() - 2);

        if (alpha) {
            gc.setAlpha(255);
            gc.setAdvanced(false);
        }

    }

}
 
Example 13
Source File: AbstractPaintManager.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void drawCheckpointMarker(final GC gc, final ISettings settings, final IColorManager colorManager, final GanttEvent event, final boolean threeDee, final int x, final int y, final int width, final int height, final Rectangle bounds) {
    final float fHoriSpacer = width * 0.17f;
    final int hSpacer = (int) fHoriSpacer;

    final float fVertiSpacer = height * 0.23f;
    final int vSpacer = (int) fVertiSpacer;

    final Rectangle topToBottom = new Rectangle(x + hSpacer, y, width - (hSpacer * 2), height + vSpacer);
    final Rectangle leftToRight = new Rectangle(x, y + vSpacer, width, height - vSpacer);
    final Rectangle inner = new Rectangle(x + hSpacer, y + vSpacer, width - (hSpacer * 2), height - (vSpacer * 2));

    Color cEvent = event.getStatusColor();
    Color gradient = event.getGradientStatusColor();

    if (cEvent == null) {
        cEvent = settings.getDefaultEventColor();
    }
    if (gradient == null) {
        gradient = settings.getDefaultGradientEventColor();
    }

    gc.setForeground(gradient);
    gc.setBackground(cEvent);
    gc.fillRectangle(topToBottom);
    gc.fillRectangle(leftToRight);
    gc.fillGradientRectangle(inner.x, inner.y, inner.width, inner.height, true);

    gc.setForeground(colorManager.getBlack());

    gc.drawRectangle(topToBottom);
    gc.drawRectangle(leftToRight);

    if (threeDee) {
        final boolean alpha = (colorManager.useAlphaDrawing() || colorManager.useAlphaDrawingOn3DEventDropShadows());
        if (alpha) {
            gc.setAlpha(200);
        }

        gc.setForeground(colorManager.getFadeOffColor1());
        // horizontal line.. ends a few pixles right of bottom right corner
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 1, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 1);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 1, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 1);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 1, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 1);

        // vertical line at end, starts slightly below top right corner
        gc.drawLine(leftToRight.x + leftToRight.width + 1, leftToRight.y + 2, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(100);
        }

        gc.setForeground(colorManager.getFadeOffColor2());
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 2, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 2);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 2, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 2);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 2, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 2);

        gc.drawLine(leftToRight.x + leftToRight.width + 2, leftToRight.y + 3, leftToRight.x + leftToRight.width + 2, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(50);
        }

        gc.setForeground(colorManager.getFadeOffColor3());
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 3, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 3);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 3, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 3);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 3, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 3);

        gc.drawLine(leftToRight.x + leftToRight.width + 3, leftToRight.y + 4, leftToRight.x + leftToRight.width + 3, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(255);
            gc.setAdvanced(false);
        }

    }
}
 
Example 14
Source File: AbstractPaintManager.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void drawCheckpoint(final GanttComposite ganttComposite, final ISettings settings, final IColorManager colorManager, final GanttEvent event, final GC gc, final boolean threeDee, final int dayWidth, final int x, final int y, final Rectangle bounds) {
    Color cEvent = event.getStatusColor();

    if (cEvent == null) {
        cEvent = settings.getDefaultEventColor();
    }

    gc.setBackground(cEvent);

    final int height = settings.getEventHeight();

    // draw a special fun thing! (tm)
    final long days = DateHelper.daysBetween(event.getActualStartDate(), event.getActualEndDate());

    drawCheckpointMarker(gc, settings, colorManager, event, threeDee, x, y, dayWidth, height, bounds);

    // multi day checkpoint
    if (days != 0) {
        final int width = (int) days * dayWidth;
        drawCheckpointMarker(gc, settings, colorManager, event, threeDee, x + width, y, dayWidth, height, bounds);

        // draw center
        final int neg = height / 2 - 1;
        final Rectangle rect = new Rectangle(x + dayWidth, y + neg, width - dayWidth, neg);
        gc.setForeground(colorManager.getBlack());
        gc.fillRectangle(rect);
        gc.drawRectangle(rect);

        if (settings.showBarsIn3D()) {
            final boolean alpha = (colorManager.useAlphaDrawing() || colorManager.useAlphaDrawingOn3DEventDropShadows());
            if (alpha) {
                gc.setAlpha(200);
            }

            gc.setForeground(colorManager.getFadeOffColor1());
            gc.drawLine(rect.x + 1, rect.y + rect.height + 1, rect.x + rect.width - 1, rect.y + rect.height + 1);

            if (alpha) {
                gc.setAlpha(100);
            }

            gc.setForeground(colorManager.getFadeOffColor2());
            gc.drawLine(rect.x + 1, rect.y + rect.height + 2, rect.x + rect.width - 1, rect.y + rect.height + 2);

            if (alpha) {
                gc.setAlpha(50);
            }

            gc.setForeground(colorManager.getFadeOffColor3());
            gc.drawLine(rect.x + 1, rect.y + rect.height + 3, rect.x + rect.width - 1, rect.y + rect.height + 3);

            if (alpha) {
                gc.setAlpha(255);
                gc.setAdvanced(false);
            }
        }
    }
}
 
Example 15
Source File: LoginDialog.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create a default image. It is a port of the image used by the Login Box
 * in the project SwingX
 *
 * @param w width
 * @param h height
 * @return a default image (blue wave)
 */
private Image createDefaultImage(final int w, final int h) {
	final Display display = Display.getCurrent();
	final Color backgroundColor = new Color(display, 49, 121, 242);
	final Color gradientColor1 = new Color(display, 155, 185, 245);
	final Color gradientColor2 = new Color(display, 53, 123, 242);

	final Image img = new Image(display, w, h);
	final GC gc = new GC(img);
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setBackground(backgroundColor);
	gc.fillRectangle(0, 0, w, h);

	final Path curveShape = new Path(display);
	curveShape.moveTo(0, h * .6f);
	curveShape.cubicTo(w * .167f, h * 1.2f, w * .667f, h * -.5f, w, h * .75f);
	curveShape.lineTo(w, h);
	curveShape.lineTo(0, h);
	curveShape.lineTo(0, h * .8f);
	curveShape.close();

	final Pattern pattern = new Pattern(display, 0, 0, 1, h * 1.2f, gradientColor1, gradientColor2);
	gc.setBackgroundPattern(pattern);
	gc.fillPath(curveShape);

	final Font font = new Font(display, "Arial Bold", 30, SWT.NONE);
	gc.setFont(font);
	gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
	final Point textSize = gc.stringExtent(ResourceManager.getLabel(ResourceManager.LOGIN));
	gc.drawString(ResourceManager.getLabel(ResourceManager.LOGIN), (int) (w * .05f), (h - textSize.y) / 2, true);

	font.dispose();
	curveShape.dispose();
	pattern.dispose();
	backgroundColor.dispose();
	gradientColor1.dispose();
	gradientColor2.dispose();
	gc.dispose();
	return img;
}
 
Example 16
Source File: ProgressCircle.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void paintControl(final PaintEvent e) {
	firstDisplay = false;
	final GC gc = e.gc;
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);

	// Draw the selected part
	final Path pathHighlight = new Path(getDisplay());
	float ratio = 1.0f * value / (maximum - minimum);
	if (minimum < 0 && maximum < 0) {
		ratio = -1.0f * (minimum - value) / (maximum - minimum);
	}

	float angle = ratio * 360f;
	if (minimum < 0 && maximum > 0) {
		angle += 180;
	}

	pathHighlight.addArc(MARGIN, MARGIN, circleSize, circleSize, 90, -angle);
	pathHighlight.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2);
	pathHighlight.close();

	gc.setBackground(getHighlightColor());
	gc.fillPath(pathHighlight);
	pathHighlight.dispose();

	// Draw the unselected part
	final Path path = new Path(getDisplay());
	final float unselectedAngle = 360f - angle;

	path.addArc(MARGIN, MARGIN, circleSize, circleSize, 90 - angle, -unselectedAngle);
	path.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2);
	path.close();

	gc.setBackground(getForeground());
	gc.fillPath(path);
	pathHighlight.dispose();

	// Draw the hole
	gc.setBackground(getBackground());
	gc.fillOval(MARGIN + thickness, MARGIN + thickness, circleSize - thickness * 2, circleSize - thickness * 2);

	if (showText) {
		gc.setForeground(getHighlightColor());
		final String text;
		if (isTimer) {
			final LocalTime time = LocalTime.ofSecondOfDay(value);
			if (time.getHour() == 0) {
				if (time.getMinute() == 0) {
					// Seconds only
					text = String.format("%02d", time.getSecond());
				} else {
					// Minutes+secondes
					text = String.format("%02d:%02d", time.getMinute(), time.getSecond());
				}
			} else {
				// Hour/Min/sec
				text = String.format("%02d:%02d:%02d", time.getHour(), time.getMinute(), time.getSecond());
			}
		} else {
			text = String.format(textPattern, value);
		}
		final Point textSize = gc.stringExtent(text);
		final int x = MARGIN + (circleSize - textSize.x) / 2;
		final int y = (circleSize - textSize.y) / 2;
		gc.drawText(text, x, y, true);
	}
}
 
Example 17
Source File: NavigationPageGraphics.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void onPaint(GC gc) {
	gc.setAdvanced(true);
	if (gc.getAdvanced())
		gc.setTextAntialias(SWT.ON);
	if (items == null) {
		return;
	}
	computeBoundsIfNeeded(gc);

	Color fg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
	Color bg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);

	boolean separator = false;
	int x, y, width, height = 0;
	boolean selected = false;
	boolean enabled = false;

	for (NavigationPageGraphicsItem pageItem : items) {
		selected = pageItem.equals(selectedItem);
		enabled = pageItem.isEnabled();
		separator = pageItem.isSeparator();

		x = pageItem.getBounds().x;
		y = pageItem.getBounds().y;
		width = pageItem.getBounds().width;
		height = pageItem.getBounds().height;

		// Fill rectangle
		Color filledRectangleColor = getFilledRectangleColor(selected,
				!separator ? enabled : true, bg);
		if (filledRectangleColor != null) {
			gc.setBackground(filledRectangleColor);
			if (round != null) {
				gc.fillRoundRectangle(x, y, width, height, round, round);
			} else {
				gc.fillRectangle(x, y, width, height);
			}
		}

		// Border rectangle
		if (!separator) {
			Color borderRectangleColor = getBorderRectangleColor(selected,
					enabled, bg);
			if (borderRectangleColor != null) {
				gc.setForeground(borderRectangleColor);
				if (round != null) {
					gc.drawRoundRectangle(x, y, width, height, round, round);
				} else {
					gc.drawRectangle(x, y, width, height);
				}
			}
		}

		// Foreground text
		Color textColor = getTextColor(selected, enabled);
		if (textColor != null) {
			gc.setForeground(textColor);
		} else {
			gc.setForeground(fg);
		}
		gc.drawString(pageItem.getText(), x + 3, y, true);
	}
}
 
Example 18
Source File: Plotter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < this.chan.length; c++) {

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			PositionPolyLine(l1);
			PositionPolyLine(l2);

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(this.chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && this.chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0
					&& l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}
 
Example 19
Source File: Oscilloscope.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < chan.length; c++) {

			if (chan[c].tailSize <= 0) {
				chan[c].stack.popNegate(0);
				continue;
			}

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0 && l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}
 
Example 20
Source File: Gallery.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
void onPaint(GC gc) {
	if (DEBUG)
		System.out.println("paint"); //$NON-NLS-1$

	boolean lowQualityPaint = lowQualityOnUserAction
			&& (translate != lastTranslateValue
					|| (lastControlWidth != getSize().x
							|| lastControlHeight != getSize().y
							|| lastContentHeight != this.gHeight
							|| lastContentWidth != this.gWidth));
	try {
		// Linux-GTK Bug 174932
		if (!SWT.getPlatform().equals(BUG_PLATFORM_LINUX_GTK_174932)) {
			gc.setAdvanced(true);
		}

		if (gc.getAdvanced()) {
			if (lowQualityPaint) {
				gc.setAntialias(SWT.OFF);
				gc.setInterpolation(SWT.OFF);
			} else {
				gc.setAntialias(antialias);
				gc.setInterpolation(interpolation);
			}
		}
		// End of Bug 174932

		Rectangle clipping = gc.getClipping();

		gc.setBackground(this.getBackground());
		drawBackground(gc, clipping.x, clipping.y, clipping.width,
				clipping.height);

		int[] indexes = getVisibleItems(clipping);

		if (indexes != null && indexes.length > 0) {

			// Call preDraw for optimization
			if (groupRenderer != null)
				groupRenderer.preDraw(gc);
			if (itemRenderer != null)
				itemRenderer.preDraw(gc);

			for (int i = indexes.length - 1; i >= 0; i--) {
				if (DEBUG)
					System.out.println("Drawing group " + indexes[i]); //$NON-NLS-1$

				_drawGroup(gc, indexes[i]);
			}

			// Call postDraw for optimization / cleanup
			if (groupRenderer != null)
				groupRenderer.postDraw(gc);
			if (itemRenderer != null)
				itemRenderer.postDraw(gc);
		}
	} catch (Exception e) {
		// We can't let onPaint throw an exception because unexpected
		// results may occur in SWT.
		e.printStackTrace();
	}

	// When lowQualityOnUserAction is enabled, keep last state and wait
	// before updating with a higher quality
	if (lowQualityOnUserAction) {
		lastTranslateValue = translate;
		lastControlWidth = getSize().x;
		lastControlHeight = getSize().y;
		lastContentHeight = gHeight;
		lastContentWidth = gWidth;

		if (lowQualityPaint) {
			// Calling timerExec with the same object just delays the
			// execution (doesn't run twice)
			Display.getCurrent().timerExec(higherQualityDelay, redrawTimer);
		}
	}
}