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

📄 basicscrollpaneui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   */  MouseWheelListener mouseWheelListener;  public static ComponentUI createUI(final JComponent c)   {    return new BasicScrollPaneUI();  }  protected void installDefaults(JScrollPane p)  {    scrollpane = p;    LookAndFeel.installColorsAndFont(p, "ScrollPane.background",                                     "ScrollPane.foreground",                                     "ScrollPane.font");    LookAndFeel.installBorder(p, "ScrollPane.border");    p.setOpaque(true);  }  protected void uninstallDefaults(JScrollPane p)  {    p.setForeground(null);    p.setBackground(null);    p.setFont(null);    p.setBorder(null);    scrollpane = null;  }      public void installUI(final JComponent c)   {    super.installUI(c);    installDefaults((JScrollPane) c);    installListeners((JScrollPane) c);    installKeyboardActions((JScrollPane) c);  }  /**   * Installs the listeners on the scrollbars, the viewport and the scrollpane.   *   * @param sp the scrollpane on which to install the listeners   */  protected void installListeners(JScrollPane sp)  {    if (spPropertyChangeListener == null)      spPropertyChangeListener = createPropertyChangeListener();    sp.addPropertyChangeListener(spPropertyChangeListener);    if (hsbChangeListener == null)      hsbChangeListener = createHSBChangeListener();    sp.getHorizontalScrollBar().getModel().addChangeListener(hsbChangeListener);        if (vsbChangeListener == null)      vsbChangeListener = createVSBChangeListener();    sp.getVerticalScrollBar().getModel().addChangeListener(vsbChangeListener);    if (viewportChangeListener == null)      viewportChangeListener = createViewportChangeListener();    sp.getViewport().addChangeListener(viewportChangeListener);    if (mouseWheelListener == null)      mouseWheelListener = createMouseWheelListener();    sp.addMouseWheelListener(mouseWheelListener);  }  /**   * Installs additional keyboard actions on the scrollpane. This is a hook   * method provided to subclasses in order to install their own keyboard   * actions.   *   * @param sp the scrollpane to install keyboard actions on   */  protected void installKeyboardActions(JScrollPane sp)  {    // TODO: Is this only a hook method or should we actually do something    // here? If the latter, than figure out what and implement this.  }  /**   * Creates and returns the change listener for the horizontal scrollbar.   *   * @return the change listener for the horizontal scrollbar   */  protected ChangeListener createHSBChangeListener()  {    return new HSBChangeListener();  }  /**   * Creates and returns the change listener for the vertical scrollbar.   *   * @return the change listener for the vertical scrollbar   */  protected ChangeListener createVSBChangeListener()  {    return new VSBChangeListener();  }  /**   * Creates and returns the change listener for the viewport.   *   * @return the change listener for the viewport   */  protected ChangeListener createViewportChangeListener()  {    return new ViewportChangeHandler();  }  /**   * Creates and returns the property change listener for the scrollpane.   *   * @return the property change listener for the scrollpane   */  protected PropertyChangeListener createPropertyChangeListener()  {    return new PropertyChangeHandler();  }  /**   * Creates and returns the mouse wheel listener for the scrollpane.   *   * @return the mouse wheel listener for the scrollpane   */  protected MouseWheelListener createMouseWheelListener()  {    return new MouseWheelHandler();  }  public void uninstallUI(final JComponent c)   {    super.uninstallUI(c);    this.uninstallDefaults((JScrollPane)c);    uninstallListeners((JScrollPane) c);    installKeyboardActions((JScrollPane) c);  }  /**   * Uninstalls all the listeners that have been installed in   * {@link #installListeners(JScrollPane)}.   *   * @param c the scrollpane from which to uninstall the listeners    */  protected void uninstallListeners(JComponent c)  {    JScrollPane sp = (JScrollPane) c;    sp.removePropertyChangeListener(spPropertyChangeListener);    sp.getHorizontalScrollBar().getModel()                               .removeChangeListener(hsbChangeListener);    sp.getVerticalScrollBar().getModel()                             .removeChangeListener(vsbChangeListener);    sp.getViewport().removeChangeListener(viewportChangeListener);    sp.removeMouseWheelListener(mouseWheelListener);  }  /**   * Uninstalls all keyboard actions from the JScrollPane that have been   * installed by {@link #installKeyboardActions}. This is a hook method   * provided to subclasses to add their own keyboard actions.   *   * @param sp the scrollpane to uninstall keyboard actions from   */  protected void uninstallKeyboardActions(JScrollPane sp)  {    // TODO: Is this only a hook method or should we actually do something    // here? If the latter, than figure out what and implement this.  }  public Dimension getMinimumSize(JComponent c)   {    JScrollPane p = (JScrollPane ) c;    ScrollPaneLayout sl = (ScrollPaneLayout) p.getLayout();    return sl.minimumLayoutSize(c);  }  public void paint(Graphics g, JComponent c)  {          // do nothing; the normal painting-of-children algorithm, along with    // ScrollPaneLayout, does all the relevant work.  }  /**   * Synchronizes the scrollbars with the viewport's extents.   */  protected void syncScrollPaneWithViewport()  {    JViewport vp = scrollpane.getViewport();    // Update the horizontal scrollbar.    JScrollBar hsb = scrollpane.getHorizontalScrollBar();    hsb.setMaximum(vp.getViewSize().width);    hsb.setValue(vp.getViewPosition().x);    hsb.setVisibleAmount(vp.getExtentSize().width);        // Update the vertical scrollbar.    JScrollBar vsb = scrollpane.getVerticalScrollBar();    vsb.setMaximum(vp.getViewSize().height);    vsb.setValue(vp.getViewPosition().y);    vsb.setVisibleAmount(vp.getExtentSize().height);  }  /**   * Receives notification when the <code>columnHeader</code> property has   * changed on the scrollpane.   *   * @param ev the property change event   */  protected void updateColumnHeader(PropertyChangeEvent ev)  {    // TODO: Find out what should be done here. Or is this only a hook?  }  /**   * Receives notification when the <code>rowHeader</code> property has changed   * on the scrollpane.   *   * @param ev the property change event   */  protected void updateRowHeader(PropertyChangeEvent ev)  {    // TODO: Find out what should be done here. Or is this only a hook?  }  /**   * Receives notification when the <code>scrollBarDisplayPolicy</code>   * property has changed on the scrollpane.   *   * @param ev the property change event   */  protected void updateScrollBarDisplayPolicy(PropertyChangeEvent ev)  {    // TODO: Find out what should be done here. Or is this only a hook?  }  /**   * Receives notification when the <code>viewport</code> property has changed   * on the scrollpane.   *   * This method sets removes the viewportChangeListener from the old viewport   * and adds it to the new viewport.   *   * @param ev the property change event   */  protected void updateViewport(PropertyChangeEvent ev)  {    JViewport oldViewport = (JViewport) ev.getOldValue();    oldViewport.removeChangeListener(viewportChangeListener);    JViewport newViewport = (JViewport) ev.getNewValue();    oldViewport.addChangeListener(viewportChangeListener);  }}

⌨️ 快捷键说明

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