Java Code Examples for org.eclipse.swt.events.PaintEvent

The following examples show how to use org.eclipse.swt.events.PaintEvent. These examples are extracted from open source projects. 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 Project: nebula   Source File: PGroup.java    License: 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 2
Source Project: nebula   Source File: EmptyTablePlaceholder.java    License: 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 3
Source Project: nebula   Source File: HeaderLayout.java    License: 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 4
Source Project: nebula   Source File: Day.java    License: 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 5
Source Project: nebula   Source File: TitleControl.java    License: 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 6
Source Project: nebula   Source File: RichTextViewer.java    License: 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 7
Source Project: nebula   Source File: SwitchButton.java    License: 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 8
Source Project: slr-toolkit   Source File: ChartPreview.java    License: 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 9
@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 10
Source Project: AppleCommander   Source File: DiskMapTab.java    License: 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 11
Source Project: BiglyBT   Source File: SWTBGImagePainter2.java    License: 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 12
Source Project: tracecompass   Source File: TimeRangeHistogram.java    License: 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 13
Source Project: BiglyBT   Source File: SpeedGraphic.java    License: 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 14
/**
 * 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 15
Source Project: http4e   Source File: CustomSeparator.java    License: 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 16
Source Project: gef   Source File: AbstractIntersectionExample.java    License: 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 17
Source Project: gef   Source File: AbstractContainmentExample.java    License: 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 18
Source Project: tracecompass   Source File: TimeGraphBaseControl.java    License: 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 19
Source Project: SIMVA-SoS   Source File: SWTStrokeCanvas.java    License: 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 20
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 21
Source Project: openstock   Source File: SWTPaintCanvas.java    License: 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 22
Source Project: gama   Source File: SwitchButton.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Paint the widget
 *
 * @param event
 *            paint event
 */
private void onPaint(final PaintEvent event) {
	final Rectangle rect = this.getClientArea();
	if (rect.width == 0 || rect.height == 0) { return; }
	this.gc = event.gc;
	final Point buttonSize = this.computeButtonSize();
	this.drawSwitchButton(buttonSize);
	if (text != null && !text.isEmpty()) {
		this.drawText(buttonSize);
	}

}
 
Example 23
Source Project: hop   Source File: HopGuiWorkflowGraph.java    License: Apache License 2.0 5 votes vote down vote up
public void paintControl( PaintEvent e ) {
  Point area = getArea();
  if ( area.x == 0 || area.y == 0 ) {
    return; // nothing to do!
  }

  Display display = hopDisplay();

  try {
    Image img = getJobImage( display, area.x, area.y, magnification );
    e.gc.drawImage( img, 0, 0 );
    if ( workflowMeta.nrActions() == 0 ) {
      e.gc.setForeground( GuiResource.getInstance().getColorCrystalText() );
      e.gc.setBackground( GuiResource.getInstance().getColorBackground() );
      e.gc.setFont( GuiResource.getInstance().getFontMedium() );

      Image welcomeImage = GuiResource.getInstance().getImageWorkflowCanvas();
      int leftPosition = ( area.x - welcomeImage.getBounds().width ) / 2;
      int topPosition = ( area.y - welcomeImage.getBounds().height ) / 2;
      e.gc.drawImage( welcomeImage, leftPosition, topPosition );

    }
    img.dispose();
  } catch ( Exception ex ) {
    new ErrorDialog( hopGui.getShell(), "Error", "Error drawing workflow", ex );
  }
}
 
Example 24
@Override
public void paintControl(@Nullable PaintEvent e) {
    if (e == null || !isEmptySelection()) {
        return;
    }

    Display display = getControl().getDisplay();

    IAxis xAxis = getXAxis();
    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 25
public StepIndicatorComposite(Composite parent, String[] stepNames)
{
	super(parent, SWT.NONE);

	setBackground(normalColor);

	GridLayout layout = new GridLayout(1, false);
	layout.marginWidth = 0;
	layout.marginHeight = 0;
	layout.horizontalSpacing = 0;
	layout.marginBottom = 1;

	setLayout(layout);
	setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).create());

	if (stepNames != null)
	{
		createSteps(stepNames);
	}
	else
	{
		setVisible(false);
	}

	addPaintListener(new PaintListener()
	{

		public void paintControl(PaintEvent e)
		{
			GC gc = e.gc;
			gc.setForeground(borderColor);
			Composite stepComposite = (Composite) e.widget;
			Rectangle bounds = stepComposite.getClientArea();
			bounds.width--;
			bounds.height--;
			gc.drawRectangle(bounds);
		}
	});
}
 
Example 26
Source Project: gwt-eclipse-plugin   Source File: BorderPainter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void paintControl(PaintEvent e) {
  Composite composite = (Composite) e.widget;
  Rectangle bounds = composite.getBounds();
  GC gc = e.gc;
  gc.setLineStyle(SWT.LINE_DOT);
  gc.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
}
 
Example 27
Source Project: nebula   Source File: HeaderControl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void onPaint(PaintEvent e) {
	GC gc = e.gc;
	gc.setFont(font);
	gc.setForeground(foreground);
	gc.drawString(text, 0, TOP_SPACE, true);
	Point size = getSize();
	int w = size.x;
	int h = size.y;
	gc.drawLine(0, h - 1, w, h - 1);
}
 
Example 28
Source Project: nebula   Source File: DefaultMouseHandler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
	if (zoomRectangle != null) {
		Point mapPosition = geoMap.getMapPosition();
		e.gc.drawRectangle(zoomRectangle.x - mapPosition.x,
				zoomRectangle.y - mapPosition.y, zoomRectangle.width,
				zoomRectangle.height);
	}
}
 
Example 29
Source Project: nebula   Source File: Transition.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void paintControl(PaintEvent e) {
    if (_isEnabled) {
        initXitionImg(e.display);
        paintTransition(_xitionImgGC, _transition);
        e.gc.drawImage(_xitionImg, 0, 0);
        disposeXitionImg();
    }
}
 
Example 30
Source Project: nebula   Source File: RangeSlider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draws the widget
 *
 * @param e paint event
 */
private void drawWidget(final PaintEvent e) {
	final Rectangle rect = getClientArea();
	if (rect.width == 0 || rect.height == 0) {
		return;
	}
	e.gc.setAdvanced(true);
	e.gc.setAntialias(SWT.ON);
	if (orientation == SWT.HORIZONTAL) {
		drawHorizontalRangeSlider(e.gc);
	} else {
		drawVerticalRangeSlider(e.gc);
	}

}