Denny Lee wrote:
>
> Hello,
> Thanks for your reply. I guess I did not make question clear. I am trying to write
>a program that works with network nodes, basically a icon, and network links. In the
>Visual Basic program that I wrote, during run time I can drag nodes around a canvas
>and connect nodes together with links. Both nodes and links respond to right botton
>clicks. The problem I am having is that I have not seen any books or tutorial that
>talks about how to move around during run time.
>
I did the exact same thing a year ago. However, I didn't use drag and
drop at all. I used the Component.move() function to move things around
by hand. I am not at liberty to mail you source code, but with swing and
lightweight components, it isn't too hard. I wish I could mail you the
source, because I spent countless hours making it infinitely extendable,
but since the company i worked for changed focus, the project was pretty
much trashed.
Here is some of the basic problems that I remember i ran into.
I made my own "components": Nodes, Wires, and the Canvas. For you, you
might not need to create wire components if you are handling only point
to point links. You can render them in the canvas. For me I had to,
because I had many different types of wires, (ethernet wires that
connect to multple nodes, FDDI rings, point to point links, etc).
I've had problems with different components getting the right mouse
events, so i had to do the following hack. I had the canvas handle the
moving and creation and selection of nodes and I had the nodes
themselves handle anything else special (like popup menus, etc.). But if
you add a mouse listener to the node, the parent no longer gets the
events. So when you get a mouse event, you have to duplicate it,
translate it to the parent's xy viewpoint and then call mousePressed()
-- or whatever to the parent. There may be a way to do it using
processMouseEvent() interface, but I couldn't figure it out.
Listeners played a huge role in my program. I wrote my own listeners /
events -- very easy to do. The wires listened to the nodes it was
connected to and resized / repainted when the node was moved. It also
listened to "deletion" events so it could also fire its own death. If
you are doing this for production, you might want to watch out for
memory leaks due to listeners not being cleaned up properly.
When dragging wires from one place to another, take a look at the
Graphics.setXORmode or something, it is extremely useful in making the
performance good.
When selecting wires, take a look at the function contains() in
Component.
I don't remember any other serious problems i had, except for some bugs
in swing. A lot of them have been fixed in the latest releases.
Good luck!
-rchit
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]