org.eclipse.swt.widgets.Canvas Java Examples
The following examples show how to use
org.eclipse.swt.widgets.Canvas.
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: PolygonQuadraticCurveIntersection.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected AbstractControllableShape createControllableShape2( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(300, 100)); addControlPoint(new Point(300, 300)); } @Override public QuadraticCurve createGeometry() { return new QuadraticCurve(getControlPoints()); } @Override public void drawShape(GC gc) { QuadraticCurve c = createGeometry(); gc.drawPath( new org.eclipse.swt.graphics.Path(Display.getCurrent(), Geometry2SWT.toSWTPathData(c.toPath()))); } }; }
Example #2
Source File: SpeedGraphic.java From BiglyBT with GNU General Public License v2.0 | 6 votes |
@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 #3
Source File: EllipseCubicCurveIntersection.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected AbstractControllableShape createControllableShape2( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { addControlPoint(new Point(100, 150)); addControlPoint(new Point(400, 200)); addControlPoint(new Point(300, 400)); addControlPoint(new Point(550, 300)); } @Override public CubicCurve createGeometry() { return new CubicCurve(getControlPoints()); } @Override public void drawShape(GC gc) { CubicCurve c = createGeometry(); gc.drawPath( new org.eclipse.swt.graphics.Path(Display.getCurrent(), Geometry2SWT.toSWTPathData(c.toPath()))); } }; }
Example #4
Source File: EllipseQuadraticCurveIntersection.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected AbstractControllableShape createControllableShape2( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { addControlPoint(new Point(100, 150)); addControlPoint(new Point(400, 200)); addControlPoint(new Point(550, 300)); } @Override public QuadraticCurve createGeometry() { return new QuadraticCurve(getControlPoints()); } @Override public void drawShape(GC gc) { QuadraticCurve c = createGeometry(); gc.drawPath( new org.eclipse.swt.graphics.Path(Display.getCurrent(), Geometry2SWT.toSWTPathData(c.toPath()))); } }; }
Example #5
Source File: EllipseLineIntersection.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected AbstractControllableShape createControllableShape2( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(300, 300)); } @Override public Line createGeometry() { Point[] points = getControlPoints(); return new Line(points[0], points[1]); } @Override public void drawShape(GC gc) { Line line = createGeometry(); gc.drawPolyline(Geometry2SWT.toSWTPointArray(line)); } }; }
Example #6
Source File: DiskMapTab.java From AppleCommander with GNU General Public License v2.0 | 6 votes |
/** * 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 #7
Source File: DiskMapTab.java From AppleCommander with GNU General Public License v2.0 | 6 votes |
/** * Handle paint requests for vertical ruler. */ protected void paintVerticalRuler(PaintEvent event) { // FIXME - not i18n safe!! String label = (disk.getBitmapLabels()[0] + "s").toUpperCase(); //$NON-NLS-1$ if (disk.getBitmapLabels().length == 2) { label = (disk.getBitmapLabels()[1] + "s").toUpperCase(); //$NON-NLS-1$ } StringBuffer buf = new StringBuffer(); for (int i=0; i<label.length(); i++) { if (i>0) buf.append("\n"); //$NON-NLS-1$ buf.append(label.charAt(i)); } label = buf.toString(); Canvas canvas = (Canvas) event.widget; Rectangle area = canvas.getClientArea(); event.gc.drawLine(area.x + area.width/2, area.y, area.x + area.width/2, area.y + area.height); Point size = event.gc.textExtent(label); event.gc.drawText(label, area.x + area.width/2 - size.x/2, area.y + area.height/2 - size.y/2); }
Example #8
Source File: AbstractEllipseContainmentExample.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected AbstractControllableShape createControllableShape1( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { // the ellipse does not have any control points } @Override public Ellipse createGeometry() { double w5 = getCanvas().getClientArea().width / 5; double h5 = getCanvas().getClientArea().height / 5; return new Ellipse(w5, h5, 3 * w5, 3 * h5); } @Override public void drawShape(GC gc) { Ellipse ellipse = createGeometry(); gc.drawOval((int) ellipse.getX(), (int) ellipse.getY(), (int) ellipse.getWidth(), (int) ellipse.getHeight()); } }; }
Example #9
Source File: TimelineComposite.java From nebula with Eclipse Public License 2.0 | 6 votes |
public TimelineComposite(Composite parent, int style) { super(parent, style); fResourceManager = new LocalResourceManager(JFaceResources.getResources(), this); final FillLayout layout = new FillLayout(); layout.marginHeight = 10; layout.marginWidth = 10; setLayout(layout); setBackground(ColorConstants.black); final Canvas canvas = new Canvas(this, SWT.DOUBLE_BUFFERED); canvas.setBackground(ColorConstants.black); final LightweightSystem lightWeightSystem = new LightweightSystem(canvas); fRootFigure = new RootFigure(fResourceManager); fRootFigure.setFont(parent.getFont()); lightWeightSystem.setContents(fRootFigure); // draw2d does not directly support mouseWheelEvents, so register on canvas canvas.addMouseWheelListener(new TimelineScaler(this)); }
Example #10
Source File: AnnotationExpansionControl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void mouseExit(MouseEvent e) { Item item= (Item) ((Widget) e.getSource()).getData(); if (item != null) item.deselect(); // if the event lies outside the entire popup, dispose org.eclipse.swt.graphics.Region region= fShell.getRegion(); Canvas can= (Canvas) e.getSource(); Point p= can.toDisplay(e.x, e.y); if (region == null) { Rectangle bounds= fShell.getBounds(); // p= fShell.toControl(p); if (!bounds.contains(p)) dispose(); } else { p= fShell.toControl(p); if (!region.contains(p)) dispose(); } }
Example #11
Source File: GraphicalViewer.java From eclipsegraphviz with Eclipse Public License 1.0 | 6 votes |
public GraphicalViewer(Composite parent) { canvas = new Canvas(parent, SWT.NONE); parent.addListener(SWT.Resize, new Listener() { public void handleEvent(Event event) { canvas.setBounds(canvas.getParent().getClientArea()); requestImageRedraw(); } }); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { redrawImageIfRequested(); GC gc = e.gc; paintCanvas(gc); } }); }
Example #12
Source File: DarkPanel.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Show the dark panel */ public void show() { if (parent.isDisposed()) { SWT.error(SWT.ERROR_WIDGET_DISPOSED); } panel = new Shell(parent, SWT.APPLICATION_MODAL | SWT.NO_TRIM); panel.setLayout(new FillLayout()); panel.setAlpha(alpha); panel.addListener(SWT.KeyUp, event -> { event.doit = false; }); canvas = new Canvas(panel, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED); canvas.addPaintListener(event -> { paintCanvas(event); }); panel.setBounds(panel.getDisplay().map(parent, null, parent.getClientArea())); panel.open(); }
Example #13
Source File: MapView.java From olca-app with Mozilla Public License 2.0 | 6 votes |
public MapView(Composite parent) { this.canvas = new Canvas(parent, SWT.NONE); this.white = canvas.getDisplay().getSystemColor(SWT.COLOR_WHITE); canvas.addPaintListener(e -> render(e.gc)); // add mouse listeners canvas.addMouseWheelListener(e -> { translation.updateCenter(e.x, e.y, zoom); if (e.count > 0) { zoomIn(); } else { zoomOut(); } }); canvas.addMouseListener(new DragSupport()); }
Example #14
Source File: HoverInfoWithSpellingAnnotation.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
private void createAnnotationInformation(Composite parent, final Annotation annotation) { Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); GridLayout layout= new GridLayout(2, false); layout.marginHeight= 2; layout.marginWidth= 2; layout.horizontalSpacing= 0; composite.setLayout(layout); final Canvas canvas= new Canvas(composite, SWT.NO_FOCUS); GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gridData.widthHint= 17; gridData.heightHint= 16; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.setFont(null); fMarkerAnnotationAccess.paint(annotation, e.gc, canvas, new Rectangle(0, 0, 16, 16)); } }); StyledText text= new StyledText(composite, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY); GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); text.setLayoutData(data); text.setText(annotation.getText()); }
Example #15
Source File: IndentFoldingStrategy.java From typescript.java with MIT License | 6 votes |
/** * Does not paint hidden annotations. Annotations are hidden when they * only span one line. * * @see ProjectionAnnotation#paint(org.eclipse.swt.graphics.GC, * org.eclipse.swt.widgets.Canvas, * org.eclipse.swt.graphics.Rectangle) */ @Override public void paint(GC gc, Canvas canvas, Rectangle rectangle) { /* workaround for BUG85874 */ /* * only need to check annotations that are expanded because hidden * annotations should never have been given the chance to collapse. */ if (!isCollapsed()) { // working with rectangle, so line height FontMetrics metrics = gc.getFontMetrics(); if (metrics != null) { // do not draw annotations that only span one line and // mark them as not visible if ((rectangle.height / metrics.getHeight()) <= 1) { visible = false; return; } } } visible = true; super.paint(gc, canvas, rectangle); }
Example #16
Source File: MarkerEditorComposite.java From birt with Eclipse Public License 1.0 | 6 votes |
void mouseDown( MouseEvent e ) { if ( e.widget instanceof Canvas ) { if ( e.widget.getData( ) != null ) { int markerIndex = ( (Integer) e.widget.getData( ) ).intValue( ); switchMarkerType( markerIndex ); if ( !this.isDisposed( ) && !this.getShell( ).isDisposed( ) ) { this.getShell( ).close( ); } } } }
Example #17
Source File: AbstractWidgetTest.java From nebula with Eclipse Public License 2.0 | 6 votes |
@Test public void testAll() throws Exception { shell = new Shell(); shell.open(); shell.setLayout(new GridLayout(1, false)); final Canvas canvas = new Canvas(shell, SWT.None); canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); text = new Text(shell, SWT.READ_ONLY); text.setFont(XYGraphMediaFactory.getInstance().getFont("default", 18, SWT.BOLD)); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); final LightweightSystem lws = new LightweightSystem(canvas); lws.setContents(getTestBench()); shell.setSize(800, 500); testGetBeanInfo(); testWidget(); }
Example #18
Source File: PolygonLineIntersection.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected AbstractControllableShape createControllableShape2( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(300, 300)); } @Override public Line createGeometry() { Point[] points = getControlPoints(); return new Line(points[0], points[1]); } @Override public void drawShape(GC gc) { Line line = createGeometry(); gc.drawPolyline(Geometry2SWT.toSWTPointArray(line)); } }; }
Example #19
Source File: PlatformWin32GLCanvas.java From lwjgl3-swt with MIT License | 6 votes |
public long create(GLCanvas canvas, GLData attribs, GLData effective) { Canvas dummycanvas = new Canvas(canvas.getParent(), checkStyle(canvas.getParent(), canvas.getStyle())); long context = 0L; MemoryStack stack = MemoryStack.stackGet(); int ptr = stack.getPointer(); try { context = create(canvas.handle, dummycanvas.handle, attribs, effective); } catch (SWTException e) { stack.setPointer(ptr); SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH, e); } final long finalContext = context; dummycanvas.dispose(); Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.Dispose: deleteContext(canvas, finalContext); break; } } }; canvas.addListener(SWT.Dispose, listener); return context; }
Example #20
Source File: ShowUnitTestMenuExtensionPoint.java From pentaho-pdi-dataset with Apache License 2.0 | 6 votes |
/** * Find the canvas of TransGraph. For some reason it's not exposed. * * @param composite * @return Canvas of null if it can't be found. */ private Canvas findCanvas( Composite composite ) { for ( Control child : composite.getChildren() ) { if ( child instanceof Canvas ) { return (Canvas) child; } if ( child instanceof Composite ) { Canvas look = findCanvas( (Composite) child ); if ( look != null ) { return look; } } } return null; }
Example #21
Source File: TaskSelectData.java From birt with Eclipse Public License 1.0 | 6 votes |
private void createPreviewArea( Composite parent ) { Composite cmpPreview = ChartUIUtil.createCompositeWrapper( parent ); { GridData gridData = new GridData( GridData.FILL_BOTH ); gridData.widthHint = CENTER_WIDTH_HINT; gridData.heightHint = 200; cmpPreview.setLayoutData( gridData ); } Label label = new Label( cmpPreview, SWT.NONE ); { label.setFont( JFaceResources.getBannerFont( ) ); label.setText( Messages.getString( "TaskSelectData.Label.ChartPreview" ) ); //$NON-NLS-1$ } previewCanvas = new Canvas( cmpPreview, SWT.BORDER ); { GridData gd = new GridData( GridData.FILL_BOTH ); previewCanvas.setLayoutData( gd ); previewCanvas.setBackground( Display.getDefault( ) .getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) ); } }
Example #22
Source File: AbstractPolygonContainmentExample.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override protected AbstractControllableShape createControllableShape1( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { // no control points => user cannot change it } @Override public Polygon createGeometry() { Rectangle ca = getCanvas().getClientArea(); double w = ca.width; double wg = w / 6; double h = ca.height; double hg = h / 6; return new Polygon(new Point[] { new Point(wg, hg), new Point(w - wg, h - hg), new Point(wg, h - hg), new Point(w - wg, hg) }); } @Override public void drawShape(GC gc) { Polygon polygon = createGeometry(); for (Line segment : polygon.getOutlineSegments()) { gc.drawLine((int) segment.getX1(), (int) segment.getY1(), (int) segment.getX2(), (int) segment.getY2()); } } }; }
Example #23
Source File: AnnotationExpansionControl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void refresh() { adjustItemNumber(); if (fInput == null) return; if (fInput.fAnnotations == null) return; if (fInput.fViewer != null) fInput.fViewer.addViewportListener(fViewportListener); fShell.setRegion(fLayouter.getShellRegion(fInput.fAnnotations.length)); Layout layout= fLayouter.getLayout(fInput.fAnnotations.length); fComposite.setLayout(layout); Control[] children= fComposite.getChildren(); for (int i= 0; i < fInput.fAnnotations.length; i++) { Canvas canvas= (Canvas) children[i]; Item item= new Item(); item.canvas= canvas; item.fAnnotation= fInput.fAnnotations[i]; canvas.setData(item); canvas.redraw(); } }
Example #24
Source File: ControllableShapeViewer.java From gef with Eclipse Public License 2.0 | 5 votes |
public ControllableShapeViewer(Canvas pCanvas) { canvas = pCanvas; canvas.addPaintListener(this); canvas.addMouseListener(this); canvas.addMouseMoveListener(this); canvas.addListener(SWT.Resize, this); }
Example #25
Source File: CheckBoxCellEditor.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * As soon as the editor is activated, flip the current data value and commit it.<br/> * The repaint will pick up the new value and flip the image. */ @Override protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) { setCanonicalValue(originalCanonicalValue); checked = !checked; canvas = new Canvas(parent, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent paintEvent) { Rectangle bounds = canvas.getBounds(); Rectangle rect = new Rectangle(0, 0, bounds.width, bounds.height); checkBoxCellPainter.paintIconImage(paintEvent.gc, rect, bounds.height / 2 - checkBoxCellPainter.getPreferredHeight(checked) / 2, checked); } }); canvas.addMouseListener(new MouseAdapter() { @Override public void mouseUp(MouseEvent e) { checked = !checked; canvas.redraw(); } }); commit(MoveDirectionEnum.NONE, false); return canvas; }
Example #26
Source File: SankeyMiniViewAction.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override protected Control createContents(Composite parent) { Composite composite = createForm(parent); createScale(composite); Canvas canvas = new Canvas(composite, SWT.BORDER); canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); LightweightSystem lws = new LightweightSystem(canvas); ScrollableThumbnail thumbnail = createThumbnail(); lws.setContents(thumbnail); viewer.getControl().addDisposeListener((e) -> { if (!closed) close(); }); return super.createContents(parent); }
Example #27
Source File: PolygonCubicCurveIntersection.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override protected AbstractControllableShape createControllableShape2( Canvas canvas) { return new AbstractControllableShape(canvas) { @Override public void createControlPoints() { addControlPoint(new Point(200, 100)); addControlPoint(new Point(190, 310)); addControlPoint(new Point(410, 90)); addControlPoint(new Point(400, 300)); } @Override public CubicCurve createGeometry() { Point[] controlPoints = getControlPoints(); System.out.println("new CubicCurve(" + controlPoints[0] + ", " + controlPoints[1] + ", " + controlPoints[2] + ", " + controlPoints[3] + ")"); return new CubicCurve(controlPoints); } @Override public void drawShape(GC gc) { CubicCurve c = createGeometry(); gc.drawPath( new org.eclipse.swt.graphics.Path(Display.getCurrent(), Geometry2SWT.toSWTPathData(c.toPath()))); } }; }
Example #28
Source File: AbstractIntersectionExample.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new ControlPoint object. Adds event listeners to the given * Canvas object, so that the user can drag the control point with the * mouse. * * @param canvas * Drawing area */ public ControlPoint(Canvas canvas) { this.canvas = canvas; canvas.addMouseListener(this); canvas.addMouseMoveListener(this); canvas.addListener(SWT.Resize, this); oldShellWidth = canvas.getClientArea().width; oldShellHeight = canvas.getClientArea().height; p = new Point(0, 0); updateLinks = new ArrayList<>(); forbidden = new ArrayList<>(); update(); }
Example #29
Source File: ChartView.java From slr-toolkit with Eclipse Public License 1.0 | 5 votes |
private void setUpDrawing(Composite parent) { paintCanvas = new Canvas(parent, SWT.BACKGROUND); preview = new ChartPreview(); paintCanvas.addPaintListener(preview); paintCanvas.addControlListener(preview); preview.setPreview(paintCanvas); preview.setDataPresent(false); preview.setTextToShow(noDataToDisplay); }
Example #30
Source File: ERDiagramOutlinePage.java From ermaster-b with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void createControl(Composite parent) { this.sash = new SashForm(parent, SWT.VERTICAL); // �R���X�g���N�^�Ŏw�肵���r���[���̍쐬 this.viewer.createControl(this.sash); editPartFactory = new ERDiagramOutlineEditPartFactory(); editPartFactory.setQuickMode(quickMode); this.viewer.setEditPartFactory(editPartFactory); // �O���t�B�J���E�G�f�B�^�̃��[�g�E���f�����c���[�E�r���[���ɂ��ݒ� this.viewer.setContents(this.diagram); if (!quickMode) { Canvas canvas = new Canvas(this.sash, SWT.BORDER); // �T���l�C���E�t�B�M���A��z�u����ׂ� LightweightSystem this.lws = new LightweightSystem(canvas); } this.resetView(this.registry); AbstractTransferDragSourceListener dragSourceListener = new ERDiagramTransferDragSourceListener( this.viewer, TemplateTransfer.getInstance()); this.viewer.addDragSourceListener(dragSourceListener); }