Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Using "Pan" with a BehaviorBase (Read 4130 times)
Dunedan
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 14
Joined: Apr 14th, 2009
Using "Pan" with a BehaviorBase
Mar 27th, 2014 at 3:05pm
Print Post  
Hi,

I want a special behavior on my diagram that will allow only Moving a node, else it will do a PAN.
I'm trying to write a custom behavior. But I don't find the "CursorHit.Pan" and I don't know what kind of InteractionState I should create.

Is it possible ?
Thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Using "Pan" with a BehaviorBase
Reply #1 - Mar 27th, 2014 at 6:01pm
Print Post  
InteractionState only helps you delegate item's modification to the diagram control. You will have to implement panning by changing scroll position yourself, e.g. try this:

Code
Select All
package tests;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;

import javax.swing.SwingUtilities;

import com.mindfusion.diagramming.Action;
import com.mindfusion.diagramming.DiagramNode;
import com.mindfusion.diagramming.DiagramView;
import com.mindfusion.diagramming.InteractionState;
import com.mindfusion.diagramming.ModifyBehavior;


public class MoveOrPanBehavior extends ModifyBehavior
{
	Point2D.Float panPos;
	Point mouseDownPos;

	protected MoveOrPanBehavior(DiagramView view)
	{
		super(view);
	}

	@Override
	protected InteractionState startDraw(Point2D point, MouseEvent e)
	{
		DiagramNode node = getDiagram().getNodeAt(point);
		if (node != null)
			return new InteractionState(node, 8, Action.Modify);

		DiagramView v = getDiagramView();
		panPos = new Point2D.Float(v.getScrollX(), v.getScrollY());
		return null;
	}

	@Override
	protected void pointerDown(Point mousePosition, MouseEvent e)
	{
		super.pointerDown(mousePosition, e);
		mouseDownPos = (Point) mousePosition.clone();
		SwingUtilities.convertPointToScreen(mouseDownPos, getDiagramView());
	}

	@Override
	protected void pointerMove(Point mousePosition, MouseEvent e)
	{
		if (panPos != null)
		{
			mousePosition = (Point) mousePosition.clone();
			SwingUtilities.convertPointToScreen(mousePosition, getDiagramView());

			DiagramView v = getDiagramView();

			Point newPos = v.docToDevice(panPos);
			newPos.x += mouseDownPos.x - mousePosition.x;
			newPos.y += mouseDownPos.y - mousePosition.y;

			Point2D.Float scrollPos = v.deviceToDoc(newPos);
			v.scrollTo(scrollPos.x, scrollPos.y);

			v.setCursor(getDiagramView().getPanCursor());
			return;
		}
		super.pointerMove(mousePosition, e);
	}

	@Override
	protected void pointerUp(Point mousePosition, MouseEvent e)
	{
		super.pointerUp(mousePosition, e);
		panPos = null;
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Dunedan
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 14
Joined: Apr 14th, 2009
Re: Using "Pan" with a BehaviorBase
Reply #2 - Mar 28th, 2014 at 3:54pm
Print Post  
Thanks,
Exactly what I was looking for.
I think I will have to move to JDiagram 4.x.x.
  
Back to top
 
IP Logged
 
Dunedan
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 14
Joined: Apr 14th, 2009
Re: Using "Pan" with a BehaviorBase
Reply #3 - Apr 2nd, 2014 at 1:07pm
Print Post  
I have one small bug: at the end of the PAN, when mouse is up, the selection is cleared.
@Override
protected void pointerUp(Point mousePosition, MouseEvent e)
{
     System.out.println("Before : "+getDiagram().getSelection().size());
     super.pointerUp(mousePosition, e);
     System.out.println("After : "+getDiagram().getSelection().size());
     panPos = null;
}
Is there anything to do to avoid this ?
Thanks
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Using "Pan" with a BehaviorBase
Reply #4 - Apr 3rd, 2014 at 8:30am
Print Post  
Try this new beta build:
https://mindfusion.eu/_beta/JDiagram405.zip

The old version always changed selection upon mouse-up if there's no InteractionState created. Now it will select only if the mouse hasn't moved.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Dunedan
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 14
Joined: Apr 14th, 2009
Re: Using "Pan" with a BehaviorBase
Reply #5 - Apr 4th, 2014 at 1:00pm
Print Post  
Thanks,

it works !

There were just a little problem of cursor: it stays as pan on mouse release.

I have update this function:
protected void pointerUp(Point mousePosition, MouseEvent e) {
     super.pointerUp(mousePosition, e);
     panPos = null;
     DiagramView v = getDiagramView();
     v.setCursor(v.getPointerCursor());
}

Thank you !
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint