| Method from javax.swing.ToolTipManager Detail: |
static Frame frameForComponent(Component component) {
while (!(component instanceof Frame)) {
component = component.getParent();
}
return (Frame)component;
}
|
public int getDismissDelay() {
return insideTimer.getInitialDelay();
}
Returns the dismissal delay value. |
public int getInitialDelay() {
return enterTimer.getInitialDelay();
}
Returns the initial delay value. |
public int getReshowDelay() {
return exitTimer.getInitialDelay();
}
Returns the reshow delay property. |
void hideTipWindow() {
if (tipWindow != null) {
if (window != null) {
window.removeMouseListener(this);
window = null;
}
tipWindow.hide();
tipWindow = null;
tipShowing = false;
tip = null;
insideTimer.stop();
}
}
|
public boolean isEnabled() {
return enabled;
}
Returns true if this object is enabled. |
public boolean isLightWeightPopupEnabled() {
return lightWeightPopupEnabled;
}
Returns true if lightweight (all-Java) Tooltips
are in use, or false if heavyweight (native peer)
Tooltips are being used. |
public void mouseDragged(MouseEvent event) {
}
Called when the mouse is pressed and dragged.
Does nothing. |
public void mouseEntered(MouseEvent event) {
initiateToolTip(event);
}
Called when the mouse enters the region of a component.
This determines whether the tool tip should be shown. |
public void mouseExited(MouseEvent event) {
boolean shouldHide = true;
if (insideComponent == null) {
// Drag exit
}
if (window != null && event.getSource() == window) {
// if we get an exit and have a heavy window
// we need to check if it if overlapping the inside component
Container insideComponentWindow = insideComponent.getTopLevelAncestor();
// insideComponent may be removed after tooltip is made visible
if (insideComponentWindow != null) {
Point location = event.getPoint();
SwingUtilities.convertPointToScreen(location, window);
location.x -= insideComponentWindow.getX();
location.y -= insideComponentWindow.getY();
location = SwingUtilities.convertPoint(null, location, insideComponent);
if (location.x >= 0 && location.x < insideComponent.getWidth() &&
location.y >= 0 && location.y < insideComponent.getHeight()) {
shouldHide = false;
} else {
shouldHide = true;
}
}
} else if(event.getSource() == insideComponent && tipWindow != null) {
Window win = SwingUtilities.getWindowAncestor(insideComponent);
if (win != null) { // insideComponent may have been hidden (e.g. in a menu)
Point location = SwingUtilities.convertPoint(insideComponent,
event.getPoint(),
win);
Rectangle bounds = insideComponent.getTopLevelAncestor().getBounds();
location.x += bounds.x;
location.y += bounds.y;
Point loc = new Point(0, 0);
SwingUtilities.convertPointToScreen(loc, tip);
bounds.x = loc.x;
bounds.y = loc.y;
bounds.width = tip.getWidth();
bounds.height = tip.getHeight();
if (location.x >= bounds.x && location.x < (bounds.x + bounds.width) &&
location.y >= bounds.y && location.y < (bounds.y + bounds.height)) {
shouldHide = false;
} else {
shouldHide = true;
}
}
}
if (shouldHide) {
enterTimer.stop();
if (insideComponent != null) {
insideComponent.removeMouseMotionListener(this);
}
insideComponent = null;
toolTipText = null;
mouseEvent = null;
hideTipWindow();
exitTimer.restart();
}
}
Called when the mouse exits the region of a component.
Any tool tip showing should be hidden. |
public void mouseMoved(MouseEvent event) {
if (tipShowing) {
checkForTipChange(event);
}
else if (showImmediately) {
JComponent component = (JComponent)event.getSource();
toolTipText = component.getToolTipText(event);
if (toolTipText != null) {
preferredLocation = component.getToolTipLocation(event);
mouseEvent = event;
insideComponent = component;
exitTimer.stop();
showTipWindow();
}
}
else {
// Lazily lookup the values from within insideTimerAction
insideComponent = (JComponent)event.getSource();
mouseEvent = event;
toolTipText = null;
enterTimer.restart();
}
}
Called when the mouse is moved.
Determines whether the tool tip should be displayed. |
public void mousePressed(MouseEvent event) {
hideTipWindow();
enterTimer.stop();
showImmediately = false;
insideComponent = null;
mouseEvent = null;
}
Called when the mouse is pressed.
Any tool tip showing should be hidden. |
public void registerComponent(JComponent component) {
component.removeMouseListener(this);
component.addMouseListener(this);
component.removeMouseMotionListener(moveBeforeEnterListener);
component.addMouseMotionListener(moveBeforeEnterListener);
component.removeKeyListener(accessibilityKeyListener);
component.addKeyListener(accessibilityKeyListener);
}
Registers a component for tooltip management.
This will register key bindings to show and hide the tooltip text
only if component has focus bindings. This is done
so that components that are not normally focus traversable, such
as JLabel, are not made focus traversable as a result
of invoking this method. |
public void setDismissDelay(int milliseconds) {
insideTimer.setInitialDelay(milliseconds);
}
Specifies the dismissal delay value. |
public void setEnabled(boolean flag) {
enabled = flag;
if (!flag) {
hideTipWindow();
}
}
Enables or disables the tooltip. |
public void setInitialDelay(int milliseconds) {
enterTimer.setInitialDelay(milliseconds);
}
Specifies the initial delay value. |
public void setLightWeightPopupEnabled(boolean aFlag) {
lightWeightPopupEnabled = aFlag;
}
When displaying the JToolTip, the
ToolTipManager chooses to use a lightweight
JPanel if it fits. This method allows you to
disable this feature. You have to do disable it if your
application mixes light weight and heavy weights components. |
public void setReshowDelay(int milliseconds) {
exitTimer.setInitialDelay(milliseconds);
}
Used to specify the amount of time before the user has to wait
initialDelay milliseconds before a tooltip will be
shown. That is, if the tooltip is hidden, and the user moves into
a region of the same Component that has a valid tooltip within
milliseconds milliseconds the tooltip will immediately
be shown. Otherwise, if the user moves into a region with a valid
tooltip after milliseconds milliseconds, the user
will have to wait an additional initialDelay
milliseconds before the tooltip is shown again. |
public static ToolTipManager sharedInstance() {
return sharedInstance;
}
Returns a shared ToolTipManager instance. |
void showTipWindow() {
if(insideComponent == null || !insideComponent.isShowing())
return;
String mode = UIManager.getString("ToolTipManager.enableToolTipMode");
if ("activeApplication".equals(mode)) {
KeyboardFocusManager kfm =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
if (kfm.getFocusedWindow() == null) {
return;
}
}
if (enabled) {
Dimension size;
Point screenLocation = insideComponent.getLocationOnScreen();
Point location = new Point();
GraphicsConfiguration gc;
gc = insideComponent.getGraphicsConfiguration();
Rectangle sBounds = gc.getBounds();
Insets screenInsets = Toolkit.getDefaultToolkit()
.getScreenInsets(gc);
// Take into account screen insets, decrease viewport
sBounds.x += screenInsets.left;
sBounds.y += screenInsets.top;
sBounds.width -= (screenInsets.left + screenInsets.right);
sBounds.height -= (screenInsets.top + screenInsets.bottom);
boolean leftToRight
= SwingUtilities.isLeftToRight(insideComponent);
// Just to be paranoid
hideTipWindow();
tip = insideComponent.createToolTip();
tip.setTipText(toolTipText);
size = tip.getPreferredSize();
if(preferredLocation != null) {
location.x = screenLocation.x + preferredLocation.x;
location.y = screenLocation.y + preferredLocation.y;
if (!leftToRight) {
location.x -= size.width;
}
} else {
location.x = screenLocation.x + mouseEvent.getX();
location.y = screenLocation.y + mouseEvent.getY() + 20;
if (!leftToRight) {
if(location.x - size.width >=0) {
location.x -= size.width;
}
}
}
// we do not adjust x/y when using awt.Window tips
if (popupRect == null){
popupRect = new Rectangle();
}
popupRect.setBounds(location.x,location.y,
size.width,size.height);
// Fit as much of the tooltip on screen as possible
if (location.x < sBounds.x) {
location.x = sBounds.x;
}
else if (location.x - sBounds.x + size.width > sBounds.width) {
location.x = sBounds.x + Math.max(0, sBounds.width - size.width)
;
}
if (location.y < sBounds.y) {
location.y = sBounds.y;
}
else if (location.y - sBounds.y + size.height > sBounds.height) {
location.y = sBounds.y + Math.max(0, sBounds.height - size.height);
}
PopupFactory popupFactory = PopupFactory.getSharedInstance();
if (lightWeightPopupEnabled) {
int y = getPopupFitHeight(popupRect, insideComponent);
int x = getPopupFitWidth(popupRect,insideComponent);
if (x >0 || y >0) {
popupFactory.setPopupType(PopupFactory.MEDIUM_WEIGHT_POPUP);
} else {
popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
}
}
else {
popupFactory.setPopupType(PopupFactory.MEDIUM_WEIGHT_POPUP);
}
tipWindow = popupFactory.getPopup(insideComponent, tip,
location.x,
location.y);
popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
tipWindow.show();
Window componentWindow = SwingUtilities.windowForComponent(
insideComponent);
window = SwingUtilities.windowForComponent(tip);
if (window != null && window != componentWindow) {
window.addMouseListener(this);
}
else {
window = null;
}
insideTimer.start();
tipShowing = true;
}
}
|
public void unregisterComponent(JComponent component) {
component.removeMouseListener(this);
component.removeMouseMotionListener(moveBeforeEnterListener);
component.removeKeyListener(accessibilityKeyListener);
}
Removes a component from tooltip control. |