tooltipmanager.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 642 行 · 第 1/2 页
JAVA
642 行
/* ToolTipManager.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.LayoutManager;import java.awt.Panel;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseMotionListener;/** * This class is responsible for the registration of JToolTips to Components * and for displaying them when appropriate. */public class ToolTipManager extends MouseAdapter implements MouseMotionListener{ /** * This ActionListener is associated with the Timer that listens to whether * the JToolTip can be hidden after four seconds. */ protected class stillInsideTimerAction implements ActionListener { /** * This method creates a new stillInsideTimerAction object. */ protected stillInsideTimerAction() { } /** * This method hides the JToolTip when the Timer has finished. * * @param event The ActionEvent. */ public void actionPerformed(ActionEvent event) { hideTip(); } } /** * This Actionlistener is associated with the Timer that listens to whether * the mouse cursor has re-entered the JComponent in time for an immediate * redisplay of the JToolTip. */ protected class outsideTimerAction implements ActionListener { /** * This method creates a new outsideTimerAction object. */ protected outsideTimerAction() { } /** * This method is called when the Timer that listens to whether the mouse * cursor has re-entered the JComponent has run out. * * @param event The ActionEvent. */ public void actionPerformed(ActionEvent event) { } } /** * This ActionListener is associated with the Timer that listens to whether * it is time for the JToolTip to be displayed after the mouse has entered * the JComponent. */ protected class insideTimerAction implements ActionListener { /** * This method creates a new insideTimerAction object. */ protected insideTimerAction() { } /** * This method displays the JToolTip when the Mouse has been still for the * delay. * * @param event The ActionEvent. */ public void actionPerformed(ActionEvent event) { showTip(); if (insideTimer != null) insideTimer.start(); } } /** * The Timer that determines whether the Mouse has been still long enough * for the JToolTip to be displayed. */ Timer enterTimer; /** * The Timer that determines whether the Mouse has re-entered the JComponent * quickly enough for the JToolTip to be displayed immediately. */ Timer exitTimer; /** * The Timer that determines whether the JToolTip has been displayed long * enough for it to be hidden. */ Timer insideTimer; /** A global enabled setting for the ToolTipManager. */ private transient boolean enabled = true; /** lightWeightPopupEnabled */ protected boolean lightWeightPopupEnabled = true; /** heavyWeightPopupEnabled */ protected boolean heavyWeightPopupEnabled = false; /** The shared instance of the ToolTipManager. */ private static ToolTipManager shared; /** The current component the tooltip is being displayed for. */ private static Component currentComponent; /** The current tooltip. */ private static JToolTip currentTip; /** The last known position of the mouse cursor. */ private static Point currentPoint; /** * The panel that holds the tooltip when the tooltip is displayed fully * inside the current container. */ private static Container containerPanel; /** * The window used when the tooltip doesn't fit inside the current * container. */ private static JWindow tooltipWindow; /** * Creates a new ToolTipManager and sets up the timers. */ ToolTipManager() { enterTimer = new Timer(750, new insideTimerAction()); enterTimer.setRepeats(false); insideTimer = new Timer(4000, new stillInsideTimerAction()); insideTimer.setRepeats(false); exitTimer = new Timer(500, new outsideTimerAction()); exitTimer.setRepeats(false); } /** * This method returns the shared instance of ToolTipManager used by all * JComponents. * * @return The shared instance of ToolTipManager. */ public static ToolTipManager sharedInstance() { if (shared == null) shared = new ToolTipManager(); return shared; } /** * This method sets whether ToolTips are enabled or disabled for all * JComponents. * * @param enabled Whether ToolTips are enabled or disabled for all * JComponents. */ public void setEnabled(boolean enabled) { if (! enabled) { enterTimer.stop(); exitTimer.stop(); insideTimer.stop(); } this.enabled = enabled; } /** * This method returns whether ToolTips are enabled. * * @return Whether ToolTips are enabled. */ public boolean isEnabled() { return enabled; } /** * This method returns whether LightweightToolTips are enabled. * * @return Whether LighweightToolTips are enabled. */ public boolean isLightWeightPopupEnabled() { return lightWeightPopupEnabled; } /** * This method sets whether LightweightToolTips are enabled. If you mix * Lightweight and Heavyweight components, you must set this to false to * ensure that the ToolTips popup above all other components. * * @param enabled Whether LightweightToolTips will be enabled. */ public void setLightWeightPopupEnabled(boolean enabled) { lightWeightPopupEnabled = enabled; heavyWeightPopupEnabled = ! enabled; } /** * This method returns the initial delay before the ToolTip is shown when * the mouse enters a Component. * * @return The initial delay before the ToolTip is shown. */ public int getInitialDelay() { return enterTimer.getDelay(); } /** * This method sets the initial delay before the ToolTip is shown when the * mouse enters a Component. * * @param delay The initial delay before the ToolTip is shown. */ public void setInitialDelay(int delay) { enterTimer.setDelay(delay); } /** * This method returns the time the ToolTip will be shown before being * hidden. * * @return The time the ToolTip will be shown before being hidden. */ public int getDismissDelay() { return insideTimer.getDelay(); } /** * This method sets the time the ToolTip will be shown before being hidden. * * @param delay The time the ToolTip will be shown before being hidden. */ public void setDismissDelay(int delay) { insideTimer.setDelay(delay); } /** * This method returns the amount of delay where if the mouse re-enters a * Component, the tooltip will be shown immediately. * * @return The reshow delay. */ public int getReshowDelay() { return exitTimer.getDelay(); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?