Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) ItemModifying and BehaviorType (Read 11434 times)
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
ItemModifying and BehaviorType
Aug 14th, 2007 at 12:27am
Print Post  
Hi,

I had two questions in this post.

1. The item modifying event does not give a fine grained control over the item.
For example, if an item is being dragged, and I want to stop it from moving altogether, I cannot do it, it allows for the drag to happen, but on release of the mouse my cancellation will take effect. Is there a way I can control it further?

2. To overcome this problem, I have thought of changing the BehaviorType to DoNothing on a mouse press. Then I handle mouse drag event and show the symbol anywhere else if required.

I have tried the following code:

private void testBehavior() {
flowChart = new FlowChart();
this.getContentPane().add(flowChart);

flowChart.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
Point2D.Float point = flowChart.deviceToDoc(me.getPoint());

Item test = flowChart.getItemAt(point, true);
if (test != null) {
flowChart.setBehavior(BehaviorType.DoNothing);
test.setSelected(true);
} else {
flowChart.setBehavior(BehaviorType.Modify);
}
}
});
}

The problem is after setting the BehaviorType to DoNothing, programatically selecting the box shows the box with a dashed border. Can I take this as a bug? If so, can this be fixed anytime soon?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ItemModifying and BehaviorType
Reply #1 - Aug 14th, 2007 at 5:37am
Print Post  
Hi,

1. We can add a cancelDrag() method to the event object that will immediately stop the modification.

2. Maybe the Box.HandlesStyle is set to DashedFrame?

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: ItemModifying and BehaviorType
Reply #2 - Aug 14th, 2007 at 6:40am
Print Post  
About the point 2,

The handleStyle is not set to anything. The function I have written is the entire code. You can add that code to your own sample and see the problem I am talking about.

When the symbol is not selected, it shows the border of the symbol alright without dashes. I think the dashes that appear are the ones that appears on dragging on the flowchart in modify mode, to select multiple objects.

Thanks,
Praveen
  
Back to top
 
IP Logged
 
kirtesh
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 40
Joined: Jul 24th, 2007
Re: ItemModifying and BehaviorType
Reply #3 - Aug 14th, 2007 at 7:36am
Print Post  
hi

right, your same problem is coming with me ...
when node is rendered first time ...it contains dash border...even i didnt set any value.

kirtesh
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ItemModifying and BehaviorType
Reply #4 - Aug 14th, 2007 at 9:14am
Print Post  
If SelectAfterCreate is enabled, the node might be selected automatically. Even if you don't set the Box.HandlesStyle explicitly, it is initialized form the flowchart's BoxHandlesStyle property.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: ItemModifying and BehaviorType
Reply #5 - Aug 14th, 2007 at 10:32am
Print Post  
Hi Stoyan,

I don't think this problem I have has anything to do with the border of the box.

I have posted my entire code below and to see the problem I am facing

1. Put it inside a class
2. Create a box
3. Click on an empty area of the flowchart
4. Select the box
5. Drag the Box.

You will see that the box will move and the selection of the box is left at its erstwhile location.



private FlowChart flowChart;
private Box currentBox = null;

private void testBehavior() {
flowChart = new FlowChart();
this.getContentPane().add(flowChart);

flowChart.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
Point2D.Float point = flowChart.deviceToDoc(me.getPoint());

Item test = flowChart.getItemAt(point, true);
if (test != null) {
flowChart.setBehavior(BehaviorType.DoNothing);
test.setSelected(true);
if (test instanceof Box) {
currentBox = (Box)test;
}
} else {
flowChart.setBehavior(BehaviorType.Modify);
}
}
});

flowChart.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
if (currentBox != null) {
Point2D.Float position = flowChart.deviceToDoc(e.getPoint().x, e.getPoint().y);
currentBox.setBounds(position.x, position.y, currentBox.getBounds().width, currentBox.getBounds().height);
}
}
});
}

Doing a repaint on the flowchart also did not clear up the dashed trace left behind.

Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ItemModifying and BehaviorType
Reply #6 - Aug 15th, 2007 at 11:37am
Print Post  
We have added ValidationEvent.cancelDrag() method that lets you immediately stop the operation from itemModifying() and itemCreating() handlers. Look for the download link in the private messages page.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: ItemModifying and BehaviorType
Reply #7 - Aug 19th, 2007 at 7:39am
Print Post  
Hi Stoyan,

That the object not move was just one example I gave. I have many other requirements because of which I cannot manipulate the box with the canvas in modify behavior. I need to use the DoNothing and then programatically update the box.

This is why I have given the example.

The example (just a sample of the whole thing I want) works as I want it to. The only problem is that it leaves behind a dashed selection area. I was wondering if this can be avoided somehow.

And, as in the example, I need to switch between Modify and DoNothing behaviors.

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ItemModifying and BehaviorType
Reply #8 - Aug 20th, 2007 at 5:47am
Print Post  
Hi Praveen,

There were other problems when I tested this, such as the selection rectangle being drawn following the mouse movement. It seems the control already starts some interaction when the click event is raised, and it messes up with the node being moved from your code.

If you are using your own node class, the best place to implement your logic might be the updateRect() method.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: ItemModifying and BehaviorType
Reply #9 - Aug 31st, 2007 at 2:40am
Print Post  
Hi Stoyan,

I would like to continue using Box class, but I would like to minimize the amount of change I do to your code.

If I need the behavior I have explained in the example, would there be a way I can do this without changing your code?

Can this behavior - Selection rectangle being drawn on a click - be taken as a bug?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ItemModifying and BehaviorType
Reply #10 - Aug 31st, 2007 at 5:19am
Print Post  
Hi Praveen,

If what you need is to change the box position while it is being dragged by the user, we can add some method to the itemModifying event object that will let you do that, e.g. ValidationEvent.setItemRect(...).

The control starts drawing a selection rectangle when using the Modify behavior, and it does not know that meanwhile you have switched to DoNothing. I guess we can change this to cancel the current interaction when the control detects that Behavior is set to DoNothing after the MousePressed message.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: ItemModifying and BehaviorType
Reply #11 - Sep 8th, 2007 at 3:18pm
Print Post  
Hi Stoyan,

The interaction setting stuff is giving me some more problems.

First, I need the switching between BehaviorTypes when I handle the events.

When I do this, none of my other events get fired  as you can see from this example of itemDeleting event.

[code]
private void testBehavior() {
flowChart = new FlowChart();
this.getContentPane().add(flowChart);

flowChart.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
Point2D.Float point = flowChart.deviceToDoc(me.getPoint());

Item test = flowChart.getItemAt(point, true);
if (test != null) {
flowChart.setBehavior(BehaviorType.DoNothing);
test.setSelected(true);
if (test instanceof Box) {
currentBox = (Box)test;
}
} else {
flowChart.setBehavior(BehaviorType.FlowChart);
}
}
});

flowChart.addFlowChartListener(new FlowChartAdapter() {
@Override
public void itemDeleting(ValidationEvent e) {
int x = 0;
super.itemDeleting(e);
}
});
}

[/code]

1. Drag and create a Box on the canvas.
2. Click outside the Box.
3. Click inside the Box (At this point you will notice that a small point has appeared at the place where the box was clicked. This looks like the start of an interaction).
4. Press the delete key.

The item doesn't get deleted.

Also, mousePress anywhere outside the box and an arrow gets drawn to that point.

I would really think this is a bug. I also hope this can be fixed soon.
My deadline is soon approaching. I can override the processKeyEvent to work around this, but that will make my code so much harder to work with future releases of your product.

So, can I expect a change in this behavior anytime soon?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ItemModifying and BehaviorType
Reply #12 - Sep 10th, 2007 at 7:14am
Print Post  
Hi Praveen,

This happens because of the same reason - the control believes there is an interaction being carried out. Until we make it cancelled automatically from setBehavior, you could use the cancelDrag method to cancel the interaction yourself. You might need to make cancelDrag public in your copy of the code.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: ItemModifying and BehaviorType
Reply #13 - Sep 18th, 2007 at 12:26am
Print Post  
Hi Stoyan,

I cannot see a cancelDrag in my version of the code. I have searched through all the files. Do I have an older version again?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ItemModifying and BehaviorType
Reply #14 - Sep 18th, 2007 at 6:48am
Print Post  
Hi Praveen,

I have sent you a link to the latest source with a private message.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint