org.eclipse.swt.events.PaintEvent Java Examples

The following examples show how to use org.eclipse.swt.events.PaintEvent. 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: DiskMapTab.java    From AppleCommander with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Paint a block map.
 */	
private void paintBlockMap(PaintEvent event) {
	Canvas canvas = (Canvas) event.widget;
	Rectangle area = canvas.getClientArea();

	double blocks = disk.getBitmapLength();
	double width = area.width;
	double height = area.height;
	double factor = Math.sqrt(blocks / (width * height));
	int xdim = (int) (width * factor + 0.5);
	int ydim = (int) (height * factor + 0.5);
	if (xdim * ydim < blocks) {
		xdim++;
	}
	if (xdim * ydim < blocks) {
		ydim++;
	}
	
	paintDiskMap(xdim, ydim, event);
}
 
Example #2
Source File: TimeGraphBaseControl.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
    if (e.widget != this) {
        return;
    }

    // we will use advanced graphics, set now for consistent output
    e.gc.setAdvanced(true);

    fFontHeight = e.gc.getFontMetrics().getHeight();
    Rectangle bound = getClientArea();
    if (!bound.isEmpty()) {
        Color colBackup = e.gc.getBackground();
        paint(bound, e);
        e.gc.setBackground(colBackup);
    }
}
 
Example #3
Source File: PGroup.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void onPaint(PaintEvent e)
{
    Color back = e.gc.getBackground();
    Color fore = e.gc.getForeground();

    strategy.paint(e.gc);

    e.gc.setBackground(back);
    e.gc.setForeground(fore);

    if (toggleRenderer != null)
    {
        toggleRenderer.setExpanded(expanded);
        toggleRenderer.setFocus(isFocusControl());
        toggleRenderer.setHover(overToggle);
        toggleRenderer.paint(e.gc, this);
    }

    if( toolItemRenderer != null && toolitems.size() > 0 ) {
    	paintToolItems(e.gc);
    }
}
 
Example #4
Source File: HeaderLayout.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
protected void layout(final Composite child, boolean flushCache) {
    storeHeader(child);
    
    int childWidth = child.getSize().x;
    int shellWidth = child.getShell().getSize().x;
    
    if (childWidth == lastChildWidth && shellWidth > lastShellWidth) return;
    
    if (childWidth > lastChildWidth) {
        final Table headerTable = getHeader(child).headerTable;
        headerTable.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                headerTable.removePaintListener(this);
                layout(child);
            }
        });
    } else {
        layout(child);
    }
    lastChildWidth = childWidth;
    lastShellWidth = shellWidth;
}
 
Example #5
Source File: AbstractContainmentExample.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
	e.gc.setAntialias(SWT.ON);

	IGeometry cs1geometry = controllableShape1.createGeometry();
	IGeometry cs2geometry = controllableShape2.createGeometry();

	if (computeIntersects(cs1geometry, cs2geometry)) {
		e.gc.setBackground(
				Display.getCurrent().getSystemColor(INTERSECTS_COLOR));
		controllableShape2.fillShape(e.gc);
	}

	if (computeContains(cs1geometry, cs2geometry)) {
		e.gc.setBackground(
				Display.getCurrent().getSystemColor(CONTAINS_COLOR));
		controllableShape2.fillShape(e.gc);
	}

	controllableShape1.drawShape(e.gc);
	controllableShape2.drawShape(e.gc);

	controllableShape1.drawControlPoints(e.gc);
	controllableShape2.drawControlPoints(e.gc);
}
 
Example #6
Source File: EmptyTablePlaceholder.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void paintControl(PaintEvent e) {
	Color oldColor = e.gc.getForeground();
	int oldLineStyle = e.gc.getLineStyle();
	int oldLineWidth = e.gc.getLineWidth();
	try {
		if (focusControl) {
			e.gc.setLineStyle(SWT.LINE_DASH);
			e.gc.setLineWidth(2);
			Point parentSize = getSize();
			e.gc.drawRectangle(1, 2, parentSize.x-2, parentSize.y-3);
		}

		e.gc.setForeground(RED);
		e.gc.drawText(getMessage(), 3, 3);
	} finally {
		e.gc.setForeground(oldColor);
		e.gc.setLineStyle(oldLineStyle);
		e.gc.setLineWidth(oldLineWidth);
	}
}
 
Example #7
Source File: SWTStrokeCanvas.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example #8
Source File: AbstractIntersectionExample.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
	e.gc.setAntialias(SWT.ON);

	controllableShape1.drawShape(e.gc);
	controllableShape2.drawShape(e.gc);

	controllableShape1.drawControlPoints(e.gc);
	controllableShape2.drawControlPoints(e.gc);

	e.gc.setBackground(
			Display.getCurrent().getSystemColor(INTERSECTION_POINT_COLOR));

	for (Point p : computeIntersections(controllableShape1.createGeometry(),
			controllableShape2.createGeometry())) {
		e.gc.fillOval((int) p.x - INTERSECTION_POINT_RADIUS,
				(int) p.y - INTERSECTION_POINT_RADIUS,
				INTERSECTION_POINT_RADIUS * 2,
				INTERSECTION_POINT_RADIUS * 2);
	}
}
 
Example #9
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 #10
Source File: TitleControl.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void onPaint(PaintEvent e) {
	GC gc = e.gc;
	Point s = getSize();
	int w = s.x;
	int h = s.y;

	gc.setForeground(gradient1Color);
	gc.setBackground(gradient2Color);
	gc.fillGradientRectangle(0, 0, w, h - 1, true);

	Rectangle imgsize = new Rectangle(0, 0, 0, 0);
	if (image != null) {
		imgsize = image.getBounds();
		gc.drawImage(image, 12, 0);
	}
	gc.setForeground(bottomLineColor);
	gc.drawLine(0, h - 1, w, h - 1);

	gc.setFont(font);
	gc.setForeground(writingColor);
	Point textSize = gc.stringExtent(text);
	int ty = (h - textSize.y) / 2;
	gc.drawString(text, 22 + imgsize.width, TOP_SPACE + ty, true);
}
 
Example #11
Source File: RichTextViewer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 
 * @param parent
 * @param style
 *            The style bits to use.
 * 
 * @see SWT#WRAP
 */
public RichTextViewer(Composite parent, int style) {
	super(parent, style | SWT.DOUBLE_BUFFERED);

	final boolean wordWrap = (getStyle() & SWT.WRAP) != 0;
	this.painter = new RichTextPainter(wordWrap);

	addPaintListener(new PaintListener() {

		@Override
		public void paintControl(PaintEvent e) {
			painter.paintHTML(htmlText != null ? htmlText : "", e.gc, getClientArea());
		}
	});

}
 
Example #12
Source File: SWTCustomScale.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void paintControl(PaintEvent e) {
	UIRectangle bounds = this.getTrackBounds();
	
	// value
	float value = (this.value - this.minimum);
	float maximum = (this.maximum - this.minimum);
	float percent = (value > 0 && maximum > 0 ? (value / maximum) : 0f);
	float valueX = (bounds.getX() + (this.horizontal ? (bounds.getWidth() * percent) : (bounds.getWidth() / 2f)));
	float valueY = (bounds.getY() + (this.horizontal ? (bounds.getHeight() / 2f) : (bounds.getHeight() - (bounds.getHeight() * percent))));
	
	UIPainter uiPainter = new SWTPainter(e.gc);
	uiPainter.initPath(UIPainter.PATH_DRAW);
	uiPainter.moveTo(bounds.getX(), bounds.getY());
	uiPainter.addRectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight());
	uiPainter.closePath();
	
	uiPainter.initPath(UIPainter.PATH_DRAW | UIPainter.PATH_FILL);
	uiPainter.moveTo(valueX, valueY);
	uiPainter.addCircle(valueX, valueY, INDICATOR_WIDTH);
	uiPainter.closePath();
}
 
Example #13
Source File: TmfMouseDragZoomProvider.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
    if (fIsUpdate && (fStartTime != fEndTime)) {
        IAxis xAxis = getChart().getAxisSet().getXAxis(0);
        int startX = xAxis.getPixelCoordinate(fStartTime);
        int endX = xAxis.getPixelCoordinate(fEndTime);
        int prevAlpha = e.gc.getAlpha();
        e.gc.setAlpha(64);
        e.gc.setBackground(TmfXYChartViewer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        if (fStartTime < fEndTime) {
            e.gc.fillRectangle(startX, 0, endX - startX, e.height);
        } else {
            e.gc.fillRectangle(endX, 0, startX - endX, e.height);
        }
        e.gc.setAlpha(prevAlpha);
        e.gc.drawLine(startX, 0, startX, e.height);
        e.gc.drawLine(endX, 0, endX, e.height);
    }
}
 
Example #14
Source File: ChartPreview.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public void paintControl(PaintEvent pe) {
	GC gc = pe.gc;
	if (dataPresent) {
		if (buffer != null) {
			gc.drawImage(buffer, 0, 0);
		}
	} else {
		// Get the width of the canvas
		int canvasWidth = preview.getSize().x;
		int canvasHeight = preview.getSize().y;

		// Plot centred by subtracting half the width of the string from
		// the centre of the Canvas width
		gc.drawText(textToShow, canvasWidth / 2, canvasHeight / 2);
	}

}
 
Example #15
Source File: SwitchButton.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Paint the widget
 *
 * @param event paint event
 */
private void onPaint(final PaintEvent event) {
	final Rectangle rect = getClientArea();
	if (rect.width == 0 || rect.height == 0) {
		return;
	}
	gc = event.gc;
	gc.setAntialias(SWT.ON);

	final Point buttonSize = computeButtonSize();
	drawSwitchButton(buttonSize);
	drawText(buttonSize);

	if (borderColor != null) {
		drawBorder();
	}

}
 
Example #16
Source File: SWTBGImagePainter2.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
	Display display = Display.getDefault();
	Shell shell = new Shell(display, SWT.DIALOG_TRIM);
	shell.setLayout(new FillLayout());

	Composite c = new Composite(shell, SWT.BORDER);
	c.setLayout(new FillLayout());
	c.addPaintListener(new PaintListener() {
		@Override
		public void paintControl(PaintEvent e) {
			e.gc.drawLine(0, 0, 100, 50);
		}
	});

	Label lbl = new Label(c, SWT.NONE);
	lbl.setText("text");

	shell.open();

	while (!shell.isDisposed()) {
		if (display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example #17
Source File: TimeRangeHistogram.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent event) {
    super.paintControl(event);

    if (fDragState == DRAG_ZOOM) {
        Image image = Objects.requireNonNull((Image) fCanvas.getData(IMAGE_KEY));

        Image rangeRectangleImage = new Image(image.getDevice(), image, SWT.IMAGE_COPY);
        GC rangeWindowGC = new GC(rangeRectangleImage);

        drawTimeRangeWindow(rangeWindowGC, fRangeStartTime, fRangeDuration);

        // Draws the buffer image onto the canvas.
        event.gc.drawImage(rangeRectangleImage, 0, 0);

        rangeWindowGC.dispose();
        rangeRectangleImage.dispose();
    }
}
 
Example #18
Source File: SpeedGraphic.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void initialize(Canvas canvas) {
	super.initialize(canvas);

	drawCanvas.addPaintListener(new PaintListener() {
	@Override
	public void paintControl(PaintEvent e) {
		if (bufferImage != null && !bufferImage.isDisposed()) {
			Rectangle bounds = bufferImage.getBounds();
			if (bounds.width >= ( e.width + e.x ) && bounds.height >= ( e.height + e.y )) {

				e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y,
						e.width, e.height);
			}
		}
	}
});

	drawCanvas.addListener(SWT.Resize, new Listener() {
	@Override
	public void handleEvent(Event event) {
		drawChart(true);
	}
});
}
 
Example #19
Source File: SWTStrokeCanvas.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example #20
Source File: CustomSeparator.java    From http4e with Apache License 2.0 6 votes vote down vote up
public CustomSeparator( Composite parent, int style) {
   super(parent, style = checkStyle(style));

   this.style = style;

   if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0)
      lineSize = 2;
   else
      lineSize = 1;

   addPaintListener(new PaintListener() {
      public void paintControl( PaintEvent event){
         onPaint(event);
      }
   });
}
 
Example #21
Source File: MouseSelectionProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void paintControl(@Nullable PaintEvent e) {
    if (e == null || !isEmptySelection()) {
        return;
    }

    Display display = getChart().getDisplay();

    IAxis xAxis = getChart().getAxisSet().getXAxis(0);
    e.gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
    e.gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    e.gc.setLineStyle(SWT.LINE_SOLID);
    int begin = xAxis.getPixelCoordinate(fStartCoordinate);
    e.gc.drawLine(begin, 0, begin, e.height);

    int end = xAxis.getPixelCoordinate(fEndCoordinate);
    e.gc.drawLine(end, 0, end, e.height);

    e.gc.setAlpha(64);
    if (Math.abs(fEndCoordinate - fStartCoordinate) > 1) {
        e.gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        int beginX = xAxis.getPixelCoordinate(fStartCoordinate);
        int endX = xAxis.getPixelCoordinate(fEndCoordinate);
        if (fEndCoordinate > fStartCoordinate) {
            e.gc.fillRectangle(beginX + 1, 0, endX - beginX - 1, e.height);
        } else {
            e.gc.fillRectangle(endX + 1, 0, beginX - endX - 1, e.height);
        }
    }
}
 
Example #22
Source File: Breadcrumb.java    From SWET with MIT License 5 votes vote down vote up
private void addListeners() {
	addMouseDownListener();
	addMouseUpListener();
	addMouseHoverListener();
	addPaintListener(new PaintListener() {
		@Override
		public void paintControl(final PaintEvent e) {
			Breadcrumb.this.paintControl(e);
		}
	});
}
 
Example #23
Source File: DiskMapTab.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paint a track/sector map.
 */	
private void paintSectorMap(PaintEvent event) {
	int[] dimensions = disk.getBitmapDimensions();
	int ydim = dimensions[1];
	int xdim = dimensions[0];
	
	paintDiskMap(xdim, ydim, event);
}
 
Example #24
Source File: LineBackgroundPainter.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the current line highlight (over top using theme colors and alpha). If the line highlight is fully opaque,
 * then this method will not do anything and we'll fall back to using the mechanism eclipse does in
 * CursorLinePainter with a little modification.
 */
public void paintControl(PaintEvent e)
{
	// if highlight current line is disabled, don't draw!
	if (!fEnabled)
	{
		return;
	}
	// If there's no alpha value for the line highlight, then we need to force the bg color of the whole line
	// to the rgb value!
	RGBa lineHighlight = getCurrentTheme().getLineHighlight();
	if (lineHighlight.isFullyOpaque())
	{
		return;
	}

	Rectangle rect = new Rectangle(e.x, e.y, e.width, e.height);
	Rectangle lineRect = getLineRectangle(getCurrentLinePosition());
	if (lineRect == null || !lineRect.intersects(rect))
	{
		return;
	}

	int previousAlpha = e.gc.getAlpha();
	Color previousBG = e.gc.getBackground();

	e.gc.setAlpha(lineHighlight.getAlpha());
	e.gc.setBackground(getColorManager().getColor(lineHighlight.toRGB()));
	// Only paint the part of lineRect that is contained in rect!
	e.gc.fillRectangle(lineRect.intersection(rect));

	// BUGFIX: need to set alpha and background color back to what they were before or it breaks
	// the painting of pair matching!
	e.gc.setAlpha(previousAlpha);
	e.gc.setBackground(previousBG);
}
 
Example #25
Source File: WhitespaceCharacterPainter.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void paintControl(PaintEvent event)
{
	if (fTextWidget != null)
	{
		handleDrawRequest(event.gc, event.x, event.y, event.width, event.height);
	}
}
 
Example #26
Source File: ImageCanvas.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle paint events.
 */
public void paintControl(PaintEvent event) {
	GC gc = event.gc;
	gc.drawImage (image, 0, 0);
	Rectangle rect = image.getBounds ();
	Rectangle client = getClientArea();
	int marginWidth = client.width - rect.width;
	if (marginWidth > 0) {
		gc.fillRectangle (rect.width, 0, marginWidth, client.height);
	}
	int marginHeight = client.height - rect.height;
	if (marginHeight > 0) {
		gc.fillRectangle (0, rect.height, client.width, marginHeight);
	}
}
 
Example #27
Source File: DiskMapTab.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle paint requests for horizontal ruler.
 */
protected void paintHorizontalRuler(PaintEvent event) {
	// FIXME - not i18n safe!!
	String label = (disk.getBitmapLabels()[0] + "s").toUpperCase(); //$NON-NLS-1$
	Canvas canvas = (Canvas) event.widget;
	Rectangle area = canvas.getClientArea();
	event.gc.drawLine(area.x, area.y + area.height/2, area.x + area.width, area.y + area.height/2);
	Point size = event.gc.textExtent(label);
	event.gc.drawString(label, area.x + area.width/2 - size.x, area.y + area.height/2 - size.y/2);
}
 
Example #28
Source File: SWTPaintCanvas.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTPaintCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            e.gc.setForeground(e.gc.getDevice().getSystemColor(
                    SWT.COLOR_BLACK));
            e.gc.setBackground(SWTPaintCanvas.this.myColor);
            e.gc.fillRectangle(getClientArea());
            e.gc.drawRectangle(getClientArea().x, getClientArea().y, 
                    getClientArea().width - 1, getClientArea().height - 1);
        }
    });
}
 
Example #29
Source File: DiskMapTab.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle paint requests for disk map.
 */
protected void paintMap(PaintEvent event) {
	if (disk.getDiskUsage() == null) {
		paintNoMap(event);
	} else if (disk.getBitmapDimensions() == null) {
		paintBlockMap(event);
	} else {
		paintSectorMap(event);
	}
}
 
Example #30
Source File: DoubleBufferedLabel.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void
paintControl(
	PaintEvent e)
{
	e.gc.setAdvanced(true);

	Rectangle clientArea = getClientArea();

	GCStringPrinter sp =
		new GCStringPrinter(e.gc, getText(), clientArea, true, true, style);

	sp.printString(e.gc, clientArea, style);
}