⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicsliderui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      if (scrollTimer != null)	scrollTimer.stop();    }    /**     * Indicates whether the thumb should scroll in the given direction.     *     * @param direction The direction to check.     *     * @return True if the thumb should move in that direction.     */    public boolean shouldScroll(int direction)    {      int value;      if (slider.getOrientation() == JSlider.HORIZONTAL)	value = valueForXPosition(currentMouseX);      else	value = valueForYPosition(currentMouseY);      if (direction == POSITIVE_SCROLL)	return (value > slider.getValue());      else	return (value < slider.getValue());    }  }  /**   * This class is no longer used as of JDK1.3.   */  public class ActionScroller extends AbstractAction  {    /**     * Not used.     *     * @param slider not used     * @param dir not used     * @param block not used     */    public ActionScroller(JSlider slider, int dir, boolean block)    {      // Not used.    }    /**     * Not used.     *     * @param event not used     */    public void actionPerformed(ActionEvent event)    {      // Not used.    }  }  /** Listener for changes from the model. */  protected ChangeListener changeListener;  /** Listener for changes to the {@link JSlider}. */  protected PropertyChangeListener propertyChangeListener;  /** Listener for the scrollTimer. */  protected ScrollListener scrollListener;  /** Listener for component resizing. */  protected ComponentListener componentListener;  /** Listener for focus handling. */  protected FocusListener focusListener;  /** Listener for mouse events. */  protected TrackListener trackListener;  /** The insets between the FocusRectangle and the ContentRectangle. */  protected Insets focusInsets;  /** The {@link JSlider}'s insets. */  protected Insets insetCache;  /** Rectangle describing content bounds. See diagram above. */  protected Rectangle contentRect;  /** Rectangle describing focus bounds. See diagram above. */  protected Rectangle focusRect;  /** Rectangle describing the thumb's bounds. See diagram above. */  protected Rectangle thumbRect;  /** Rectangle describing the tick bounds. See diagram above. */  protected Rectangle tickRect;  /** Rectangle describing the label bounds. See diagram above. */  protected Rectangle labelRect;  /** Rectangle describing the track bounds. See diagram above. */  protected Rectangle trackRect;  /** FIXME: use this somewhere. */  public static final int MAX_SCROLL = 2;  /** FIXME: use this somewhere. */  public static final int MIN_SCROLL = -2;  /** A constant describing scrolling towards the minimum. */  public static final int NEGATIVE_SCROLL = -1;  /** A constant describing scrolling towards the maximum. */  public static final int POSITIVE_SCROLL = 1;  /** The gap between the edges of the contentRect and trackRect. */  protected int trackBuffer;  /** Whether this slider is actually drawn left to right. */  protected boolean leftToRightCache;  /** A timer that periodically moves the thumb. */  protected Timer scrollTimer;  /** A reference to the {@link JSlider} that this UI was created for. */  protected JSlider slider;  /** The shadow color. */  private transient Color shadowColor;  /** The highlight color. */  private transient Color highlightColor;  /** The focus color. */  private transient Color focusColor;  /**   * Creates a new Basic look and feel Slider UI.   *   * @param b The {@link JSlider} that this UI was created for.   */  public BasicSliderUI(JSlider b)  {    super();  }  /**   * Gets the shadow color to be used for this slider. The shadow color is the   * color used for drawing the top and left edges of the track.   *   * @return The shadow color.   */  protected Color getShadowColor()  {    return shadowColor;  }  /**   * Gets the highlight color to be used for this slider. The highlight color   * is the color used for drawing the bottom and right edges of the track.   *   * @return The highlight color.   */  protected Color getHighlightColor()  {    return highlightColor;  }  /**   * Gets the focus color to be used for this slider. The focus color is the   * color used for drawing the focus rectangle when the component gains   * focus.   *   * @return The focus color.   */  protected Color getFocusColor()  {    return focusColor;  }  /**   * Factory method to create a BasicSliderUI for the given {@link   * JComponent}, which should be a {@link JSlider}.   *   * @param b The {@link JComponent} a UI is being created for.   *   * @return A BasicSliderUI for the {@link JComponent}.   */  public static ComponentUI createUI(JComponent b)  {    return new BasicSliderUI((JSlider) b);  }  /**   * Installs and initializes all fields for this UI delegate. Any properties   * of the UI that need to be initialized and/or set to defaults will be   * done now. It will also install any listeners necessary.   *   * @param c The {@link JComponent} that is having this UI installed.   */  public void installUI(JComponent c)  {    super.installUI(c);    if (c instanceof JSlider)      {	slider = (JSlider) c;	focusRect = new Rectangle();	contentRect = new Rectangle();	thumbRect = new Rectangle();	trackRect = new Rectangle();	tickRect = new Rectangle();	labelRect = new Rectangle();	insetCache = slider.getInsets();	leftToRightCache = ! slider.getInverted();	scrollTimer = new Timer(200, null);	scrollTimer.setRepeats(true);	installDefaults(slider);	installListeners(slider);	installKeyboardActions(slider);	calculateFocusRect();	calculateContentRect();	calculateThumbSize();	calculateTrackBuffer();	calculateTrackRect();	calculateThumbLocation();	calculateTickRect();	calculateLabelRect();      }  }  /**   * Performs the opposite of installUI. Any properties or resources that need   * to be cleaned up will be done now. It will also uninstall any listeners   * it has. In addition, any properties of this UI will be nulled.   *   * @param c The {@link JComponent} that is having this UI uninstalled.   */  public void uninstallUI(JComponent c)  {    super.uninstallUI(c);    uninstallKeyboardActions(slider);    uninstallListeners(slider);    scrollTimer = null;    focusRect = null;    contentRect = null;    thumbRect = null;    trackRect = null;    tickRect = null;    labelRect = null;    focusInsets = null;  }  /**   * Initializes any default properties that this UI has from the defaults for   * the Basic look and feel.   *   * @param slider The {@link JSlider} that is having this UI installed.   */  protected void installDefaults(JSlider slider)  {    LookAndFeel.installColors(slider, "Slider.background",                              "Slider.foreground");    LookAndFeel.installBorder(slider, "Slider.border");    shadowColor = UIManager.getColor("Slider.shadow");    highlightColor = UIManager.getColor("Slider.highlight");    focusColor = UIManager.getColor("Slider.focus");    focusInsets = UIManager.getInsets("Slider.focusInsets");    slider.setOpaque(true);  }  /**   * Creates a new {@link TrackListener}.   *   * @param slider The {@link JSlider} that this {@link TrackListener} is   *        created for.   *   * @return A new {@link TrackListener}.   */  protected TrackListener createTrackListener(JSlider slider)  {    return new TrackListener();  }  /**   * Creates a new {@link ChangeListener}.   *   * @param slider The {@link JSlider} that this {@link ChangeListener} is   *        created for.   *   * @return A new {@link ChangeListener}.   */  protected ChangeListener createChangeListener(JSlider slider)  {    return new ChangeHandler();  }  /**   * Creates a new {@link ComponentListener}.   *   * @param slider The {@link JSlider} that this {@link ComponentListener} is   *        created for.   *   * @return A new {@link ComponentListener}.   */  protected ComponentListener createComponentListener(JSlider slider)  {    return new ComponentHandler();  }  /**   * Creates a new {@link FocusListener}.   *   * @param slider The {@link JSlider} that this {@link FocusListener} is   *        created for.   *   * @return A new {@link FocusListener}.   */  protected FocusListener createFocusListener(JSlider slider)  {    return new FocusHandler();  }  /**   * Creates a new {@link ScrollListener}.   *   * @param slider The {@link JSlider} that this {@link ScrollListener} is   *        created for.   *   * @return A new {@link ScrollListener}.   */  protected ScrollListener createScrollListener(JSlider slider)  {    return new ScrollListener();  }  /**   * Creates a new {@link PropertyChangeListener}.   *   * @param slider The {@link JSlider} that this {@link   *        PropertyChangeListener} is created for.   *   * @return A new {@link PropertyChangeListener}.   */  protected PropertyChangeListener createPropertyChangeListener(JSlider slider)  {    return new PropertyChangeHandler();  }  /**   * Creates and registers all the listeners for this UI delegate. This   * includes creating the ScrollListener and registering it to the timer.   *   * @param slider The {@link JSlider} is having listeners installed.   */  protected void installListeners(JSlider slider)  {    propertyChangeListener = createPropertyChangeListener(slider);    componentListener = createComponentListener(slider);    trackListener = createTrackListener(slider);    focusListener = createFocusListener(slider);    changeListener = createChangeListener(slider);    scrollListener = createScrollListener(slider);    slider.addPropertyChangeListener(propertyChangeListener);    slider.addComponentListener(componentListener);    slider.addMouseListener(trackListener);    slider.addMouseMotionListener(trackListener);    slider.addFocusListener(focusListener);    slider.getModel().addChangeListener(changeListener);    scrollTimer.addActionListener(scrollListener);  }  /**   * Unregisters all the listeners that this UI delegate was using. In   * addition, it will also null any listeners that it was using.   *   * @param slider The {@link JSlider} that is having listeners removed.   */  protected void uninstallListeners(JSlider slider)  {    slider.removePropertyChangeListener(propertyChangeListener);    slider.removeComponentListener(componentListener);    slider.removeMouseListener(trackListener);    slider.removeMouseMotionListener(trackListener);    slider.removeFocusListener(focusListener);    slider.getModel().removeChangeListener(changeListener);    scrollTimer.removeActionListener(scrollListener);    propertyChangeListener = null;    componentListener = null;    trackListener = null;    focusListener = null;    changeListener = null;    scrollListener = null;  }  /**   * Installs any keyboard actions. The list of keys that need to be bound are   * listed in Basic look and feel's defaults.   *   * @param slider The {@link JSlider} that is having keyboard actions   *        installed.   */  protected void installKeyboardActions(JSlider slider)  {    // FIXME: implement.  }  /**   * Uninstalls any keyboard actions. The list of keys used  are listed in   * Basic look and feel's defaults.   *   * @param slider The {@link JSlider} that is having keyboard actions   *        uninstalled.   */  protected void uninstallKeyboardActions(JSlider slider)  {    // FIXME: implement.  }  /* XXX: This is all after experimentation with SUN's implementation.     PreferredHorizontalSize seems to be 200x21.     PreferredVerticalSize seems to be 21x200.     MinimumHorizontalSize seems to be 36x21.     MinimumVerticalSize seems to be 21x36.     PreferredSize seems to be 200x63. Or Components.getBounds?     MinimumSize seems to be 36x63.     MaximumSize seems to be 32767x63.   */  /**   * This method returns the preferred size when the slider is horizontally   * oriented.   *   * @return The dimensions of the preferred horizontal size.   */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -