graphstream / gs-ui-swing

GraphStream Swing user interface
http://graphstream-project.org/
Other
25 stars 12 forks source link

ToolTips #9

Open hoijui opened 4 years ago

hoijui commented 4 years ago

This works, but really is only a proof of concept.

one needs to activate it with: (view as DefaultView).setToolTips(true)

And one needs to use gs-ui-swing of course.

Then, the String attributes "ui.tooltip" set on nodes, edges and sprites are shown as Swing JToolTips.

(I do not think this should be merges as is)

hichbra commented 4 years ago

Thanks for your contribution. I haven't tested it yet, but the code in itself looks pretty good to me.

However, is this code need to be in DefaultView ? I see it more in DefaultMouseManager, with the InteractiveElement defined in the constructor. What do you think ?

hoijui commented 4 years ago

the main code is in two methods that are part of JComponent, just overriden here. they need to be overridden here, it would not work in DefaultMouseManager. I actually first reid to go that way too, doing it through the mouse manager/mouse events, and it works, until where you want to actually display the tooltip. Because JToolTip -- or generally how tool-tips work in Swing -- is fixed on ToolTipManager and these methods in JComponent. Of course, one could create a kind of Swing modal dialog without window decorations, without buttons, without a window border and many other special settings, and it might look the same like tooltips, and work more or less similarly (on the systems we are able to test on), but I would guess it would be 5+ times the amount of code and complexity, and might come with problems we can't imagine yet. ... it would probably be more modular though.

hoijui commented 4 years ago

I have to say... while many things in Java and also Swing are more or less well designed, the tool-tip system looks like quite an exception to that. ;-) so.. might make sense to go more the way of reinventing the wheel. ... or maybe others did that already?

hoijui commented 4 years ago

sounds like even inside the JDK itsself, other methods are sometimes used: https://stackoverflow.com/a/9522754/586229

hichbra commented 4 years ago

A custom JDialog seems to be a good idea. You can use the mouseOverElement and mouseLeftElement methods of the MouseOverMouseManager class to create and remove the tooltip.

To use this class, the addition of viewer.getDefaultView().enableMouseOptions(); will be required for the user though.