Extending JGoViewCanvas

Hi,

I extended JGoView.java and overridden the method getTooltipLocation(MouseEvent) of JComponent. But I found that the call does not reach this method when the tooltip gets invoked.
Now I am trying to extend JGoViewCanvas.java to override getTooltipLocation(MouseEvent). But overriding JGoViewCanvas.java results in exception.
Can anyone tell me a way to override this method for a JGoView. I want to add some customizations to it.

Overrideing JGoView.getTooltipLocation(MouseEvent) is the right thing to do. This is in fact how tooltips are supported in all of JGo. Take a look at this override in the Demo1 sample application for an example.

Hi ssmith,

Thanks forthe reply. Actually I had overridden JGoView.getTooltipLocation(MouseEvent), but I verified that the flow does not reach this overridden method when the tooltip gets invoked. I could override createTooltip() method though. I think the reason is that JGoViewCanvas.java has a createTooltip() method which delegates the flow to createToolTip() method of JGoView.
JGoViewCanvas does not have getTooltipLocation(MouseEvent) method in it. So that's why, like creaeTooltip() method, I cannot override getTooltipLocation(MouseEvent) in my JGoView.
JGoViewCanvas is a JComponent added "over" JGoView, so all method calls first reach JGoViewCanvas and that's why the flow never reaches the overridden getTooltipLocation(MouseEvent) of JGoView. This is what I feel. Hope my doubt is clear.

Also I could not find JGoView.getTooltipLocation(MouseEvent) overridden in Demo1 sample application. I am having JGo version 5.32

I’m sorry, I meant to say:

getToolTipText(MouseEvent)
You will find this in Demo1View.

Actually my problem is that, by default, the tooltips that appear on JGoIconicNodes in my JGoPalette, are sometimes slightly away from the actual mouse location. This may be because of the size of the JGoIconicNode that I am using in JGoPalette.

In the tooltip I am having a clickable hyperlink, but because of this gap between mouse location and the tooltip, I am never able to reach the hyperlink. As soon as I reach the tooptip it disappears.
So that's why I wanted to override getTooltipLocation(MouseEvent) to customize the tooptip location.
Any help on this will be very much appreciated.

You can override getToolTipLocation(MouseEvent) in JGoViewCanvas as follows:

public Point getToolTipLocation(MouseEvent e) {
return e.getPoint();
}
That will put the tooltip right under the mouse rather than using the standard offset for Swing tooltips.

Hi,

But I am unable to extend JGoViewCanvas.java to override getToolTipLocation(MouseEvent), may be because JGoViewCanvas is an inner class inside JGoView. I am overriding JGoView and JGoViewCanvas as follows:
-------------------------------------------------------------------------------------------
public class WECanvas extends JGoView {
// instance variable to store my JGoViewCanvas
private WEViewCanvas myViewCanvas = nul;
// WECanvas constructor
public WECanvas() {
myViewCanvas = new WEViewCanvas(this); ----> error is thrown here itself
}
// Overriding getCanvas() of JGoView
public JGoViewCanvas getCanvas() {
return myViewCanvas;
}
public class WEViewCanvas extends JGoView.JGoViewCanvas {
public WEViewCanvas(JGoView view) {
super(view);
}
// Overriding getToolTipLocation() in JGoViewCanvas as mentioned by you.
public Point getToolTipLocation(MouseEvent e) {
return e.getPoint();
}
}
}
--------------------------------------------------------------------------------------
Please let me know if this is the right way to override JGoViewCanvas. Please let me know the correction if I am wrong. The above code is not working and throwing exception as I have shown in the code above.
And when I override getToolTipLocation(MouseEvent) of JGoView (in WECanvas), it does not have any effect. The code doesn't reach th method at runtime.
We will put the following definition of JGoViewCanvas.getToolTipText(MouseEvent) into the next release of JGo:
public Point getToolTipLocation(MouseEvent e) {return myView.getToolTipLocation(e);}
and we will put the following in JGoView:
public Point getToolTipLocation(MouseEvent e) {return null;}
This will allow you to specify the tooltip location by overriding JGoView.
In the meantime, you can make the same modification to JGoViewCanvas yourself, as the source code for JGoViewCanvas is included in JGoView.java in the JGo kit.