Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Creating floating Shape
Creating floating Shape [message #1768534] Wed, 19 July 2017 18:30 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 526
Registered: November 2009
Senior Member
I'd like to create a floating image button similar to what is currently in XSD Editor (upper left corner). How can I achieve this is in Graphiti? I haven't looks at XSD Editor code, but I presume they are keeping track of coordinates delta when viewport is panned or scroll bars are used to change coordinates of the button?

Re: Creating floating Shape [message #1768641 is a reply to message #1768534] Thu, 20 July 2017 21:05 Go to previous message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 526
Registered: November 2009
Senior Member
Here is my unoptimized solution - setFocus in method in DiagramEditor:
	public void setFocus() {
		// TODO Auto-generated method stub
		GraphicalViewer graphicalViewer2 = getGraphicalViewer();
		FigureCanvas control = (FigureCanvas) graphicalViewer2.getControl();
		control.getViewport().addPropertyChangeListener(new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent evt) {
				Point p = control.getViewport().getViewLocation();
				DiagramEditPart part = (DiagramEditPart) getDiagramBehavior().getContentEditPart();
				Diagram model = (Diagram) part.getModel();
				EList<Shape> children = model.getChildren();
				ContainerShape shape = (ContainerShape) children.get(0);
				GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
				int x = p.x;
				int y = p.y;
				System.out.println(x + ", " + y);
new SetCommand(getDiagramBehavior().getEditingDomain(), ga, AlgorithmsPackage.Literals.GRAPHICS_ALGORITHM__X, x));
new SetCommand(getDiagramBehavior().getEditingDomain(), ga, AlgorithmsPackage.Literals.GRAPHICS_ALGORITHM__Y, y));

This code will always keep the Shape you control static when editor's canvas is resized:
I still need to smooth things out as there is quite a bit jerkiness going on when editor is scrolled. But so far I got what I needed.
Previous Topic:Quartz Composer-like style
Next Topic:ScrollBar doesn't appear until resize
Goto Forum:

Current Time: Mon Mar 19 18:29:37 GMT 2018

Powered by FUDForum. Page generated in 0.01938 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software