Cache the JGoLink's paint method

I have many links (thousands) having a same to and from point (but
different ports) and some other links that do not. Drawing and
dragging is slow. I tried to improve this by caching the last
draw of the same from and to point. If so repeat is detected, I
skip drawing. This works fine for most case, but some cases (such
as drawing 1 link near another) do not work (it wipes out neighboring
links somehow).
Could someone please tell me what the right way to do override the paint method in this situation?

Thank you very much for your consideration.

Are you saying that you have thousands of links that connect the same two ports? Do they all have exactly the same stroke points?
If so, it might be best to detect whenever you create the second link between the same set of ports, and avoid creating the duplicate link. (Use the static JGoPort.isLinked method.) You might then want to increase the width of the link’s pen, just to indicate to the user that there’s more than one link there.

Thank you for helping. These links do not share a same two port
(from and to). They just happen to lay on top of each other (when
I get the from port’s link point and to port link point, the “to”
points are at a same place and the “from” points are at a same
place).
getFromPort().getFromLinkPoint();

getToPort().getToLinkPoint();

To be more clearly, I have thousand of ports, so I used scroll bar to
drag them. Using one of the example from JGo, I created a
customized node which hide the ports either from left or right of the
node (set to invisible). Many of these different ports ends up on
a same location (left or right of the scroll bar). Many of them
link to a few other nodes, so many links (straight lines) are on top of
each other.

I partly successfully cache them by detecting of the previous link was
drawn on the same spot (using the above points). However, when
connect a new link for example, it’s slowly wiping out the neighboring
links as you drag and I don’t know how to prevent that. Just to
drag a node slightly would redraw everything good. The
performance shoot up from many seconds to instaneous. I also
observer that the link was not drawn out in a line, but actually
clipping in a rectangle. I think there could be an more efficient
way to do this (such as when dragging, use inverse mode (so thing can
easily be reversed versus redraw the whole thing in the effected
clipping rect).

Thanks,

Songha

I suspect that drawing in xor mode wouldn’t really help much, since the overhead is in drawing each link, which would be done anyway.
When dragging a node with so many ports, maybe you should set JGoView.setDragsRealtime(false).
Equally, when using a scrollbar in a RecordNode (actually ListArea), maybe you should change the implementation so that it doesn’t update in realtime as you drag, but only at the end with the mouse up of the scroll bar.

I was speculating on the xor mode, but not really using it to improve
the performance. I only tried to remember the last JGoLink’s
paint call and store the 2 points. When these same points are
called again, I don’t draw them. The flaw about this is that what
if something else wipe out the area. So I need a better
caching algorithm on when to skip and when to draw.

I tried to setDragsRealtime to false, but the performance wasn’t
good. It slows down when the JGoView’s scroll bar is dragged, or
when I do anything anywhere else. I am sure that the JGoLink is
the cause of slowness. By not having them, but retaining the
number of ports, things go very fast. As the result, I tried to
cache the draw of the JGoLink.

Things go well as I said except the part of when you use mouse to
connect to ports, the neighboring link get partially wiped out without
redrawn. I don’t know how to fix this. There maybe a
different way to achieve this. So it’s all boilded down to how to
not draw another link on top of an existing link.