org.eclipse.draw2d.FigureCanvas Java Examples

The following examples show how to use org.eclipse.draw2d.FigureCanvas. 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: MapFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Minimal standalone example, used for testing
 * 
 * @param args
 */
@SuppressWarnings("nls")
public static void main(String[] args) {

	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());

	FigureCanvas canvas = new FigureCanvas(shell);
	MapFigure mapFigure = new MapFigure();
	mapFigure.setZoomLevel(8);
	mapFigure.setLocation(10.4234, 63.4242);
	canvas.setContents(mapFigure);

	shell.setText("MapFigure example");
	shell.setSize(600, 600);
	shell.open();

	while (!shell.isDisposed()) {
		while (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example #2
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Scroll to bottom.
 */
public void scrollToBottom() {
    UIThreadRunnable.syncExec(new VoidResult() {

        @Override
        public void run() {
            final ProcessDiagramEditor processEditor = (ProcessDiagramEditor) gmfEditor.getReference().getEditor(false);
            final FigureCanvas canvas = (FigureCanvas) processEditor.getDiagramGraphicalViewer().getControl();
            Point current;
            Point next = canvas.getViewport().getViewLocation();
            do {
                current = next.getCopy();
                canvas.getViewport().setVerticalLocation(current.y + 10);
                next = canvas.getViewport().getViewLocation();
            } while (!current.equals(next));
        }
    });
}
 
Example #3
Source File: EditorDragGuidePolicy.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private Dimension getDistance( )
	{
//		Point p = getStartLocation( );
//		
//		Control canvas = getGuideEditPart( ).getViewer( ).getControl( );
//		org.eclipse.swt.graphics.Rectangle rect = canvas.getBounds( );
//	
//		Dimension retValue = new Dimension(rect.width - p.x, p.y);
//		
//		return retValue;
		
		Point p = getStartLocation( );
		
		FigureCanvas canvas = ((DeferredGraphicalViewer)getGuideEditPart().getViewer( ).getProperty( GraphicalViewer.class.toString( ))).getFigureCanvas( );
		org.eclipse.swt.graphics.Rectangle rect = canvas.getBounds( );
	
		Dimension retValue = new Dimension(rect.width - p.x, p.y);
		if (canvas.getVerticalBar( ).isVisible( ))
		{
			retValue.width = retValue.width - canvas.getVerticalBar( ).getSize( ).x;
		}
		return retValue;
	}
 
Example #4
Source File: EditorRulerComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void disposeRulerViewer( GraphicalViewer viewer )
{
	if ( viewer == null )
		return;
	/*
	 * There's a tie from the editor's range model to the RulerViewport (via
	 * a listener) to the RulerRootEditPart to the RulerViewer. Break this
	 * tie so that the viewer doesn't leak and can be garbage collected.
	 */

	RangeModel rModel = new DefaultRangeModel( );
	Viewport port = ( (FigureCanvas) viewer.getControl( ) ).getViewport( );
	port.setHorizontalRangeModel( new RulerDefaultRangeModel( rModel ) );
	port.setVerticalRangeModel( new RulerDefaultRangeModel( rModel ) );
	rulerEditDomain.removeViewer( viewer );
	viewer.getControl( ).dispose( );
}
 
Example #5
Source File: TableCellKeyDelegate.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
void scrollViewer( KeyEvent event )
{
	if ( !( getViewer( ).getControl( ) instanceof FigureCanvas ) )
		return;
	FigureCanvas figCanvas = (FigureCanvas) getViewer( ).getControl( );
	Point loc = figCanvas.getViewport( ).getViewLocation( );
	Rectangle area = figCanvas.getViewport( )
			.getClientArea( Rectangle.SINGLETON )
			.scale( .1 );
	switch ( event.keyCode )
	{
		case SWT.ARROW_DOWN :
			figCanvas.scrollToY( loc.y + area.height );
			break;
		case SWT.ARROW_UP :
			figCanvas.scrollToY( loc.y - area.height );
			break;
		case SWT.ARROW_LEFT :
			figCanvas.scrollToX( loc.x - area.width );
			break;
		case SWT.ARROW_RIGHT :
			figCanvas.scrollToX( loc.x + area.width );
	}
}
 
Example #6
Source File: ReportViewerKeyHandler.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private boolean scrollPageIncrement( GraphicalEditPart part, int code )
{
	if ( !( part.getViewer( ) instanceof DeferredGraphicalViewer ) )
	{
		return false;
	}
	DeferredGraphicalViewer viewer = (DeferredGraphicalViewer) part.getViewer( );
	FigureCanvas canvas = viewer.getFigureCanvas( );

	int increment = 0;
	if ( code == SWT.PAGE_DOWN )
	{
		increment = canvas.getVerticalBar( ).getSelection( )
				+ canvas.getVerticalBar( ).getPageIncrement( );
	}
	else if ( code == SWT.PAGE_UP )
	{
		increment = canvas.getVerticalBar( ).getSelection( )
				- canvas.getVerticalBar( ).getPageIncrement( );
	}
	canvas.scrollToY( increment );
	return true;
}
 
Example #7
Source File: PlaceTableAction.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Event event) throws Exception {
    final ERDiagram diagram = getDiagram();

    final List<ERTable> input = new ArrayList<>();
    input.addAll(diagram.getDiagramContents().getDiagramWalkers().getTableSet().getList());

    final NodeSelectionDialog dialog =
            new NodeSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), diagram);

    final FigureCanvas canvas = (FigureCanvas) oneEditor.getGraphicalViewer().getControl();
    final Point point =
            new Point(canvas.getHorizontalBar().getSelection() + canvas.getClientArea().width / 2, canvas.getVerticalBar()
                    .getSelection() + canvas.getClientArea().height / 2);

    if (dialog.open() == IDialogConstants.OK_ID) {
        final Object[] results = dialog.getResult();
        for (final Object result : results) {
            final ERTable curTable = (ERTable) result;
            final ERVirtualTable virtualTable = new ERVirtualTable(oneEditor.getVirtualDiagram(), curTable);
            virtualTable.setPoint(point.x, point.y);
            getDiagram().addWalkerPlainly(virtualTable);
        }
    }
}
 
Example #8
Source File: AbstractBaseDraw2DDetailsPart.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createPart ( final Composite parent )
{
    super.createPart ( parent );

    this.canvas = new FigureCanvas ( parent );
    this.canvas.setBackground ( Display.getDefault ().getSystemColor ( SWT.COLOR_LIST_BACKGROUND ) );

    this.canvas.setContents ( createRoot () );
}
 
Example #9
Source File: PlaceTableAction.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
@Override
	public void execute(Event event) throws Exception {
		ERDiagram diagram = this.getDiagram();
		ERModel model = oneEditor.getModel();
		
		List<ERTable> input = new ArrayList<ERTable>();
		input.addAll(diagram.getDiagramContents().getContents().getTableSet().getList());
		
		NodeSelectionDialog dialog = new NodeSelectionDialog(
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
				diagram);
		
		FigureCanvas canvas = (FigureCanvas) oneEditor.getGraphicalViewer().getControl();
		Point point = new Point(
				canvas.getHorizontalBar().getSelection() + canvas.getClientArea().width / 2,
				canvas.getVerticalBar().getSelection() + canvas.getClientArea().height / 2);
		
		if (dialog.open() == IDialogConstants.OK_ID) {
			Object[] results = dialog.getResult();
			for (Object result : results) {
				ERTable curTable = (ERTable) result;
				ERVirtualTable virtualTable = new ERVirtualTable(model, curTable);
				virtualTable.setPoint(point.x, point.y);
				model.addTable(virtualTable);
//				oneEditor.setContents(model);
//				oneEditor.refreshContents();
//				model.changeAll();
			}
			
		}

	}
 
Example #10
Source File: Activator.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
public void run() {
	Shell shell = new Shell(display);
	shell.setLayout(new GridLayout(1, false));

	ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
	viewer = new ScrollingGraphicalViewer();
	viewer.setControl(new FigureCanvas(shell));
	ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(
			diagram);
	viewer.setRootEditPart(rootEditPart);

	viewer.setEditPartFactory(editPartFactory);
	viewer.setContents(diagram);
}
 
Example #11
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Scroll to top.
 */
public void scrollToTop() {
    UIThreadRunnable.syncExec(new VoidResult() {

        @Override
        public void run() {
            final ProcessDiagramEditor processEditor = (ProcessDiagramEditor) gmfEditor.getReference().getEditor(false);
            final FigureCanvas canvas = (FigureCanvas) processEditor.getDiagramGraphicalViewer().getControl();
            canvas.getViewport().setVerticalLocation(0);
        }
    });
}
 
Example #12
Source File: ShowDragInfomationProcessor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Dimension getDistance( Point p )
{
	FigureCanvas canvas = ( (DeferredGraphicalViewer) editpart.getViewer( ) ).getFigureCanvas( );
	org.eclipse.swt.graphics.Rectangle rect = canvas.getBounds( );

	Dimension retValue = new Dimension( rect.width - p.x, p.y );
	if ( canvas.getVerticalBar( ).isVisible( ) )
	{
		retValue.width = retValue.width
				- canvas.getVerticalBar( ).getSize( ).x;
	}
	return retValue;
}
 
Example #13
Source File: DeferredGraphicalViewer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 */
public void initStepDat( )
{
	Viewport port = ( (FigureCanvas) getControl( ) ).getViewport( );
	stepData.minX = port.getHorizontalRangeModel( ).getMinimum( );
	stepData.maxX = port.getHorizontalRangeModel( ).getMaximum( );
	stepData.valueX = port.getHorizontalRangeModel( ).getValue( );
	stepData.extendX = port.getHorizontalRangeModel( ).getExtent( );

	stepData.minY = port.getVerticalRangeModel( ).getMinimum( );
	stepData.maxY = port.getVerticalRangeModel( ).getMaximum( );
	stepData.valueY = port.getVerticalRangeModel( ).getValue( );
	stepData.extendY = port.getVerticalRangeModel( ).getExtent( );
}
 
Example #14
Source File: GodClassDiagram.java    From JDeodorant with MIT License 5 votes vote down vote up
public FigureCanvas createDiagram(){

		canvas.setBackground(ColorConstants.white);
		LightweightSystem lws = new LightweightSystem(canvas);
		lws.setContents(this.root);
		return canvas;
	}
 
Example #15
Source File: NoWindowTest.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private static void run(final Display display, final int x) {
    final Shell shell = new Shell(display);
    shell.setBounds(0, 0, 350, 350);

    shell.setLayout(new FillLayout(SWT.VERTICAL));

    // display.syncExec(new Runnable() {
    // public void run() {

    final ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
    final GraphicalViewer viewer = new ScrollingGraphicalViewer();
    viewer.setControl(new FigureCanvas(shell));

    final ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(diagram);
    viewer.setRootEditPart(rootEditPart);

    viewer.setEditPartFactory(editPartFactory);
    viewer.setContents(diagram);

    viewer.getContents().refresh();

    // }
    // });

    shell.pack();
    shell.open();
    int count = 0;
    while (count < x) {
        if (!display.readAndDispatch()) {
            try {
                Thread.sleep(1000);
                count++;
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    viewer.getContents().deactivate();
    // display.dispose();
}
 
Example #16
Source File: VisualInterfaceViewer.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected FigureCanvas createCanvas ()
{
    final FigureCanvas canvas = new FigureCanvas ( this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE );

    addControlListener ( new ControlAdapter () {
        @Override
        public void controlResized ( final ControlEvent e )
        {
            handleResize ( getBounds () );
        }
    } );

    return canvas;
}
 
Example #17
Source File: TextController.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public TextController ( final FigureCanvas canvas, final SymbolController controller, final Text element, final ResourceManager manager )
{
    super ( controller, manager );
    this.canvas = canvas;
    this.figure = new Label ( element.getText ()) {
        @Override
        public void addNotify ()
        {
            super.addNotify ();
            start ();
        }

        @Override
        protected void paintFigure ( final Graphics graphics )
        {
            final Double alpha = getAlpha ();
            if ( alpha != null )
            {
                graphics.setAlpha ( (int) ( Math.max ( 0.0, Math.min ( 1.0, alpha ) ) * 255.0 ) );
            }
            super.paintFigure ( graphics );
        }

        @Override
        public void removeNotify ()
        {
            stop ();
            super.removeNotify ( );
        }
    };
    controller.addElement ( element, this );

    applyCommon ( element );
}
 
Example #18
Source File: ImageController.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public ImageController ( final FigureCanvas canvas, final SymbolController controller, final Image element, final SymbolLoader symbolLoader, final ResourceManager manager, final FactoryContext factoryContext )
{
    super ( controller, manager );
    this.factoryContext = factoryContext;

    this.symbolLoader = symbolLoader;

    this.figure = new Label () {
        @Override
        public void addNotify ()
        {
            super.addNotify ();
            start ();
        }

        @Override
        public void removeNotify ()
        {
            stop ();
            super.removeNotify ();
        }
    };
    controller.addElement ( element, this );

    applyCommon ( element );
    setImage ( element.getUri () );
}
 
Example #19
Source File: RailroadView.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	canvas = new FigureCanvas(parent, SWT.V_SCROLL | SWT.H_SCROLL);
	rootFigure = new Figure();
	rootFigure.addMouseListener(selectionProvider);
	rootFigure.setLayoutManager(new StackLayout());
	rootFigure.setVisible(true);
	canvas.setContents(rootFigure);
	getSite().setSelectionProvider(selectionProvider);
	createActions();
}
 
Example #20
Source File: BasicViewElementFactory.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public BasicViewElementFactory ( final FigureCanvas canvas, final ResourceManager manager, final SymbolLoader symbolLoader, final FactoryContext factoryContext, final Map<URI, XMISymbolLoader> symbolCache )
{
    this.manager = manager;
    this.canvas = canvas;
    this.symbolLoader = symbolLoader;
    this.symbolCache = symbolCache;

    this.factoryContext = factoryContext == null ? FactoryContext.DEFAULT : factoryContext;
}
 
Example #21
Source File: BasicViewElementFactory.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public BasicViewElementFactory ( final FigureCanvas canvas, final ResourceManager manager, final SymbolLoader symbolLoader, final FactoryContext factoryContext )
{
    this.manager = manager;
    this.canvas = canvas;
    this.symbolLoader = symbolLoader;
    this.symbolCache = new HashMap<URI, XMISymbolLoader> ();

    this.factoryContext = factoryContext == null ? FactoryContext.DEFAULT : factoryContext;
}
 
Example #22
Source File: ERDiagramEditor.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public void setLocation(int x, int y) {
	FigureCanvas canvas = (FigureCanvas) this.getGraphicalViewer()
			.getControl();
	canvas.scrollTo(x, y);
}
 
Example #23
Source File: DragAndDropUtil.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
SWTBotGefFigureCanvasForDnd(final FigureCanvas canvas) {
  super(canvas);
}
 
Example #24
Source File: ERDiagramEditor.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public Point getLocation() {
	FigureCanvas canvas = (FigureCanvas) this.getGraphicalViewer()
			.getControl();
	return canvas.getViewport().getViewLocation();
}
 
Example #25
Source File: VisualInterfaceViewer.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public void setZooming ( final Boolean zooming )
{
    this.zooming = zooming;
    this.canvas.setScrollBarVisibility ( isZooming () ? FigureCanvas.NEVER : FigureCanvas.AUTOMATIC );
}
 
Example #26
Source File: NoWindowTest.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
private static void run(Display display, int x) {
	Shell shell = new Shell(display);
	shell.setBounds(0, 0, 350, 350);

	shell.setLayout(new FillLayout(SWT.VERTICAL));

	// display.syncExec(new Runnable() {
	// public void run() {

	ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
	GraphicalViewer viewer = new ScrollingGraphicalViewer();
	viewer.setControl(new FigureCanvas(shell));

	ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(
			diagram);
	viewer.setRootEditPart(rootEditPart);

	viewer.setEditPartFactory(editPartFactory);
	viewer.setContents(diagram);

	viewer.getContents().refresh();

	// }
	// });

	shell.pack();
	shell.open();
	int count = 0;
	while (count < x) {
		if (!display.readAndDispatch()) {
			try {
				Thread.sleep(1000);
				count++;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	viewer.getContents().deactivate();
	// display.dispose();
}
 
Example #27
Source File: BotGefProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private Point getCurrentScroll() {
    final ProcessDiagramEditor processEditor = (ProcessDiagramEditor) gmfEditor.getReference().getEditor(false);
    final FigureCanvas canvas = (FigureCanvas) processEditor.getDiagramGraphicalViewer().getControl();
    return canvas.getViewport().getViewLocation();
}
 
Example #28
Source File: BasicViewElementFactory.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public BasicViewElementFactory ( final FigureCanvas canvas, final ResourceManager manager, final SymbolLoader symbolLoader )
{
    this ( canvas, manager, symbolLoader, null );
}
 
Example #29
Source File: ERDiagramEditor.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
public Point getLocation() {
    final FigureCanvas canvas = (FigureCanvas) getGraphicalViewer().getControl();
    return canvas.getViewport().getViewLocation();
}
 
Example #30
Source File: ReportViewerKeyHandler.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private boolean scrollIncrement( GraphicalEditPart part, KeyEvent event )
{
	if ( ( event.stateMask & SWT.CONTROL ) == 0 )
	{
		return false;
	}
	if ( !( part.getViewer( ) instanceof DeferredGraphicalViewer ) )
	{
		return false;
	}
	DeferredGraphicalViewer viewer = (DeferredGraphicalViewer) part.getViewer( );
	FigureCanvas canvas = viewer.getFigureCanvas( );
	int code = event.keyCode;
	int increment = 0;
	if ( code == SWT.ARROW_RIGHT )
	{
		increment = canvas.getHorizontalBar( ).getSelection( )
				+ canvas.getHorizontalBar( ).getIncrement( );
	}
	else if ( code == SWT.ARROW_LEFT )
	{
		increment = canvas.getHorizontalBar( ).getSelection( )
				- canvas.getHorizontalBar( ).getIncrement( );
	}
	else if ( code == SWT.ARROW_DOWN )
	{
		increment = canvas.getVerticalBar( ).getSelection( )
				+ canvas.getVerticalBar( ).getIncrement( );
	}
	else if ( code == SWT.ARROW_UP )
	{
		increment = canvas.getVerticalBar( ).getSelection( )
				- canvas.getVerticalBar( ).getIncrement( );
	}

	if ( code == SWT.ARROW_RIGHT || code == SWT.ARROW_LEFT )
	{
		canvas.scrollToX( increment );
	}
	if ( code == SWT.ARROW_UP || code == SWT.ARROW_DOWN )
	{
		canvas.scrollToY( increment );
	}
	return true;

}