import com.micronova.mnfc.*; import netscape.application.*; // a view with dynamic tooltip class TestToolTipSource extends View implements IToolTipSource { int offset = 20; TestToolTipSource(int x, int y, int width, int height) { super(x, y, width, height); } Rect getToolTipArea() { Rect r = bounds(); return new Rect(offset, offset, r.width - 2 * offset, r.height - 2 * offset); } public void drawView(Graphics g) { g.setColor(Color.black); Rect r = getToolTipArea(); g.fillRect(r); } boolean isInToolTipArea(int x, int y) { Rect r = getToolTipArea(); return r.contains(x, y); } public String getToolTipText(MouseEvent event) { if (isInToolTipArea(event.x, event.y)) { return event.x + ":" + event.y; } else { return null; } } } // test application public class Test extends IApplication { public void init() { Rect workspace = mainRootView().bounds(); int unitHeight = 20; TextField textField = new TextField(0, 0, workspace.width, unitHeight); textField.setJustification(Graphics.CENTERED); textField.setStringValue("TextField"); textField.setEditable(true); Button button = new Button(0, unitHeight, workspace.width, unitHeight); button.setTitle("Button"); TestToolTipSource toolTipSource = new TestToolTipSource(0, unitHeight * 2, workspace.width, workspace.height - 2 * unitHeight); mainRootView().addSubview(textField); mainRootView().addSubview(button); mainRootView().addSubview(toolTipSource); // register tooltips IToolTip.registerToolTip(textField, "This is a TextField"); IToolTip.registerToolTip(button, "This is a Button"); IToolTip.registerToolTip(toolTipSource, null); } }