package NET.worlds.scape; import NET.worlds.console.Console; import NET.worlds.console.DefaultConsole; import NET.worlds.console.MultiLineLabel; import NET.worlds.core.IniFile; import java.awt.Color; import java.awt.Font; import java.awt.Frame; import java.awt.Window; public class ToolTipManager { private static ToolTipManager manager_ = null; private static final int FRAME_DELAY = 15; private int savedX; private int savedY; private int savedLoops; private boolean toolTipActive; private WObject savedObject; private Window toolTipWindow; private MultiLineLabel toolTipTextArea; private Font toolTipFont; private ToolTipManager() { this.savedX = this.savedY = this.savedLoops = 0; this.toolTipActive = false; this.savedObject = null; this.toolTipFont = new Font("Arial", 0, 10); Console.getActive(); this.toolTipWindow = new Window((Frame)Console.getFrame()); this.toolTipTextArea = new MultiLineLabel(); this.toolTipTextArea.setBackground(Color.yellow); this.toolTipTextArea.setForeground(Color.black); this.toolTipTextArea.setMarginWidth(2); this.toolTipTextArea.setMarginHeight(2); this.toolTipWindow.setFont(this.toolTipFont); this.toolTipWindow.add(this.toolTipTextArea); } public static ToolTipManager toolTipManager() { if (manager_ == null) { manager_ = new ToolTipManager(); } return manager_; } public void heartbeat() { if (IniFile.gamma().getIniInt("DisableToolTips", 0) != 1) { WObject obj = Camera.getMousePickWObject(); int x = (int)Camera.getMousePickX(); int y = (int)Camera.getMousePickY(); if (obj != null && x > 0 && y > 0 && x == this.savedX && y == this.savedY && this.savedObject == obj) { this.savedLoops++; } else { if (this.toolTipActive) { this.removeToolTip(); this.toolTipActive = false; } this.savedLoops = 0; } if (!this.toolTipActive && obj != null && this.savedLoops > 15) { this.toolTipActive = true; if (obj != null) { this.savedObject = obj; if (obj.getToolTipText() != null) { String oldText = obj.getToolTipText(); String newText = oldText.replace('|', '\n'); this.createToolTip(this.savedX, this.savedY, newText); } } } this.savedX = x; this.savedY = y; this.savedObject = obj; } } void createToolTip(int winX, int winY, String text) { int baseX = ((DefaultConsole)Console.getActive()).getRender().getLocationOnScreen().x; int baseY = ((DefaultConsole)Console.getActive()).getRender().getLocationOnScreen().y; int offsetX = 16; int offsetY = 16; this.toolTipWindow.setLocation(winX + baseX + offsetX, winY + baseY + offsetY); this.toolTipTextArea.setLabel(text); this.toolTipWindow.setSize(this.toolTipTextArea.preferredSize()); this.toolTipWindow.setEnabled(false); this.toolTipWindow.show(); } public void removeToolTip() { this.toolTipWindow.hide(); } public void killToolTip() { this.savedLoops = 0; this.toolTipWindow.hide(); } }