Skip to main content

Tooltip (popup) bug

1 reply [Last post]
mortennobel
Offline
Joined: 2004-11-03
Points: 0

I have found out that the tooltip popup may be clipped by the JSGPanel

The problem does only occur in the southern and eastern part of the window (since the popup is showed south-east of the mouse curser).

I have created a small applet that shows the bug:

import com.sun.scenario.scenegraph.*;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public class TooltipBug extends JApplet {
public void init() {
JSGPanel panel = new JSGPanel();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);

SGGroup group = new SGGroup();

Random colorGenerator = new Random();

String longTooltiptext = "<html>Lorem ipsum dolor sit amet,<br>" +
"consectetuer adipiscing elit.<br>" +
"Sed nec enim vel odio bibendum<br>" +
"rhoncus. Ut risus. Suspendisse<br>" +
"pulvinar pharetra purus. Mauris<br>" +
"hendrerit dignissim massa. <br>" +
"Aliquam sed ante. Aliquam ut diam.</html>";
for (int x=0;x<getWidth();x+=getWidth()/2){
for (int y=0;y<getHeight();y+=getHeight()/2){
JLabel label = new JLabel("test "+x+" "+y);
label.setBackground(new Color(colorGenerator.nextInt(0xffffff)));
label.setToolTipText(longTooltiptext);
label.setPreferredSize(new Dimension(getWidth()/2,getHeight()/2));
SGComponent component = new SGComponent();
component.setComponent(label);
component.setSize(label.getPreferredSize());
group.add(SGTransform.createTranslation(x,y,component));
}
}

panel.setScene(group);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mortennobel
Offline
Joined: 2004-11-03
Points: 0

I have found a solution to this problem. Just force the popup to keep within the JSGPanel.

SGPopupFactory.SGPopup. SGPopup(Component owner, Component contents, int x, int y)

private SGPopup(Component owner, Component contents, int x, int y) {
sgComponent = new SGComponent();
sgTransform = SGTransform.createAffine(null, sgComponent);

sgComponent.setComponent(contents);
AffineTransform accTransform = new AffineTransform();
SGGroup topSGGroup = null;
Point p = new Point(x, y);
SGShell sgShell = (SGShell) SwingUtilities.getAncestorOfClass(
SGShell.class, owner);
SwingUtilities.convertPointFromScreen(p, sgShell);
int jsgPanelHeight = 0;
int jsgPanelWidth = 0;
while (sgShell != null) {
SGLeaf leaf = sgShell.getNode();
accTransform.preConcatenate(
AffineTransform.getTranslateInstance(p.getX(), p.getY()));
accTransform.preConcatenate(leaf.getCumulativeTransform());
JSGPanel jsgPanel = leaf.getPanel();
SGShell parent = null;
if (jsgPanel!=null){
jsgPanelHeight = jsgPanel.getHeight();
jsgPanelWidth = jsgPanel.getWidth();
topSGGroup = jsgPanel.getSceneGroup();

// check if it is an embedded JSGPanel
parent =(SGShell) SwingUtilities.getAncestorOfClass(
SGShell.class, jsgPanel);
}

if (parent != null) {
p = SwingUtilities.convertPoint(sgShell, 0, 0, parent);
}

sgShell = parent;
}

Point2D transformedPoint = accTransform.transform(new Point2D.Double(0,0),null );
if (transformedPoint.getY()+contents.getPreferredSize().getHeight()>jsgPanelHeight){
double adjustY = transformedPoint.getY()+contents.getPreferredSize().getHeight()-jsgPanelHeight;
accTransform.preConcatenate(AffineTransform.getTranslateInstance(0,-adjustY));
}
if (transformedPoint.getX()+contents.getPreferredSize().getWidth()>jsgPanelWidth){
double adjustX = transformedPoint.getX()+contents.getPreferredSize().getWidth()-jsgPanelWidth;
accTransform.preConcatenate(AffineTransform.getTranslateInstance(-adjustX,0));
}
if (topSGGroup != null) {
sgTransform.setAffine(accTransform);
sgTransform.setVisible(false);

topSGGroup.add(sgTransform);
}
}