basicsplitpaneui.java

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 1,522 行 · 第 1/3 页

JAVA
1,522
字号
     * @param insets The Insets to use.     *     * @return The top inset.     */    protected int getInitialLocation(Insets insets)    {      return insets.top;    }    /**     * This method returns the preferred height of the component.     *     * @param c The component to measure.     *     * @return The preferred height of the component.     */    protected int getPreferredSizeOfComponent(Component c)    {      Dimension dims = c.getPreferredSize();      if (dims != null)	return dims.height;      return 0;    }    /**     * This method returns the current height of the component.     *     * @param c The component to measure.     *     * @return The current height of the component.     */    protected int getSizeOfComponent(Component c)    {      return c.getHeight();    }    /**     * This method returns the minimum layout size. The minimum height is the     * sum of all the components' minimum heights. The minimum width is the     * maximum of all the  components' minimum widths.     *     * @param container The container to measure.     *     * @return The minimum size.     */    public Dimension minimumLayoutSize(Container container)    {      if (container instanceof JSplitPane)        {	  JSplitPane split = (JSplitPane) container;	  Insets insets = container.getInsets();	  int height = 0;	  int width = 0;	  for (int i = 0; i < components.length; i++)	    {	      if (components[i] == null)		continue;	      Dimension dims = components[i].getMinimumSize();	      if (dims != null)	        {		  height += dims.height;		  width = Math.max(width, dims.width);	        }	    }	  return new Dimension(width, height);        }      return null;    }    /**     * This method returns the preferred layout size. The preferred height is     * the sum of all the components'  preferred heights. The preferred width     * is the maximum of  all the components' preferred widths.     *     * @param container The container to measure.     *     * @return The preferred size.     */    public Dimension preferredLayoutSize(Container container)    {      if (container instanceof JSplitPane)        {	  JSplitPane split = (JSplitPane) container;	  Insets insets = container.getInsets();	  int height = 0;	  int width = 0;	  for (int i = 0; i < components.length; i++)	    {	      if (components[i] == null)		continue;	      Dimension dims = components[i].getPreferredSize();	      if (dims != null)	        {		  height += dims.height;		  width = Math.max(width, dims.width);	        }	    }	  return new Dimension(500, 500); //width, height);        }      return null;    }    /**     * This method sets the bounds of the given component. The y coordinate is     * the location given. The x coordinate is the left inset. The height is     * the size given. The width is the container size minus the left and     * right inset.     *     * @param c The component to set bounds for.     * @param size The height.     * @param location The y coordinate.     * @param insets The insets to use.     * @param containerSize The container's size.     */    protected void setComponentToSize(Component c, int size, int location,                                      Insets insets, Dimension containerSize)    {      int y = location;      int x = insets.left;      int h = size;      int w = containerSize.width - insets.left - insets.right;      c.setBounds(x, y, w, h);    }    /**     * This method returns the minimum height of the component at the given     * index.     *     * @param index The index of the component to check.     *     * @return The minimum height of the given component.     */    int minimumSizeOfComponent(int index)    {      Dimension dims = components[index].getMinimumSize();      if (dims != null)	return dims.height;      else	return 0;    }  }  /**   * This class handles FocusEvents from the JComponent.   */  protected class FocusHandler extends FocusAdapter  {    /**     * This method is called when the JSplitPane gains focus.     *     * @param ev The FocusEvent.     */    public void focusGained(FocusEvent ev)    {      // FIXME: implement.    }    /**     * This method is called when the JSplitPane loses focus.     *     * @param ev The FocusEvent.     */    public void focusLost(FocusEvent ev)    {      // FIXME: implement.    }  }  /**   * This is a deprecated class. It is supposed to be used for handling down   * and right key presses.   */  public class KeyboardDownRightHandler implements ActionListener  {    /**     * This method is called when the down or right keys are pressed.     *     * @param ev The ActionEvent     */    public void actionPerformed(ActionEvent ev)    {      // FIXME: implement.    }  }  /**   * This is a deprecated class. It is supposed to be used for handling end   * key presses.   */  public class KeyboardEndHandler implements ActionListener  {    /**     * This method is called when the end key is pressed.     *     * @param ev The ActionEvent.     */    public void actionPerformed(ActionEvent ev)    {      // FIXME: implement.    }  }  /**   * This is a deprecated class. It is supposed to be used for handling home   * key presses.   */  public class KeyboardHomeHandler implements ActionListener  {    /**     * This method is called when the home key is pressed.     *     * @param ev The ActionEvent.     */    public void actionPerformed(ActionEvent ev)    {      // FIXME: implement.    }  }  /**   * This is a deprecated class. It is supposed to be used for handling resize   * toggles.   */  public class KeyboardResizeToggleHandler implements ActionListener  {    /**     * This method is called when a resize is toggled.     *     * @param ev The ActionEvent.     */    public void actionPerformed(ActionEvent ev)    {      // FIXME: implement.    }  }  /**   * This is a deprecated class. It is supposed to be used for handler up and   * left key presses.   */  public class KeyboardUpLeftHandler implements ActionListener  {    /**     * This method is called when the left or up keys are pressed.     *     * @param ev The ActionEvent.     */    public void actionPerformed(ActionEvent ev)    {      // FIXME: implement.    }  }  /**   * This helper class handles PropertyChangeEvents from the JSplitPane. When   * a property changes, this will update the UI accordingly.   */  public class PropertyHandler implements PropertyChangeListener  {    /**     * This method is called whenever one of the JSplitPane's properties     * change.     *     * @param e DOCUMENT ME!     */    public void propertyChange(PropertyChangeEvent e)    {      if (e.getPropertyName().equals(JSplitPane.DIVIDER_SIZE_PROPERTY))        {	  int newSize = splitPane.getDividerSize();	  int[] tmpSizes = layoutManager.getSizes();	  dividerSize = tmpSizes[2];	  Component left = splitPane.getLeftComponent();	  Component right = splitPane.getRightComponent();	  int newSpace = newSize - tmpSizes[2];	  tmpSizes[2] = newSize;	  tmpSizes[0] += newSpace / 2;	  tmpSizes[1] += newSpace / 2;	  layoutManager.setSizes(tmpSizes);        }      else if (e.getPropertyName().equals(JSplitPane.ORIENTATION_PROPERTY))        {	  int max = layoutManager.getAvailableSize(splitPane.getSize(),	                                           splitPane.getInsets());	  int dividerLoc = getDividerLocation(splitPane);	  double prop = ((double) dividerLoc) / max;	  resetLayoutManager();	  if (prop <= 1 && prop >= 0)	    splitPane.setDividerLocation(prop);        }      layoutManager.layoutContainer(splitPane);      splitPane.repaint();      // Don't have to deal with continuous_layout - only      // necessary in dragging modes (and it's checked      // every time you drag there)      // Don't have to deal with resize_weight (as there      // will be no extra space associated with this      // event - the changes to the weighting will      // be taken into account the next time the       // sizes change.)      // Don't have to deal with divider_location       // The method in JSplitPane calls our setDividerLocation      // so we'll know about those anyway.      // Don't have to deal with last_divider_location      // Although I'm not sure why, it doesn't seem to       // have any effect on Sun's JSplitPane.      // one_touch_expandable changes are dealt with      // by our divider.    }  }  /** The location of the divider when dragging began. */  protected int beginDragDividerLocation;  /** The size of the divider while dragging. */  protected int dividerSize;  /** The location where the last drag location ended. */  transient int lastDragLocation = -1;  /** The distance the divider is moved when moved by keyboard actions. */  protected static int KEYBOARD_DIVIDER_MOVE_OFFSET;  /** The divider that divides this JSplitPane. */  protected BasicSplitPaneDivider divider;  /** The listener that listens for PropertyChangeEvents from the JSplitPane. */  protected PropertyChangeListener propertyChangeListener;  /** The JSplitPane's focus handler. */  protected FocusListener focusListener;  /** @deprecated The handler for down and right key presses. */  protected ActionListener keyboardDownRightListener;  /** @deprecated The handler for end key presses. */  protected ActionListener keyboardEndListener;  /** @deprecated The handler for home key presses. */  protected ActionListener keyboardHomeListener;  /** @deprecated The handler for toggling resizes. */  protected ActionListener keyboardResizeToggleListener;  /** @deprecated The handler for up and left key presses. */  protected ActionListener keyboardUpLeftListener;  /** The JSplitPane's current layout manager. */  protected BasicHorizontalLayoutManager layoutManager;  /** @deprecated The divider resize toggle key. */  protected KeyStroke dividerResizeToggleKey;  /** @deprecated The down key. */  protected KeyStroke downKey;  /** @deprecated The end key. */  protected KeyStroke endKey;  /** @deprecated The home key. */  protected KeyStroke homeKey;  /** @deprecated The left key. */  protected KeyStroke leftKey;  /** @deprecated The right key. */  protected KeyStroke rightKey;  /** @deprecated The up key. */  protected KeyStroke upKey;  /** Set to true when dragging heavy weight components. */  protected boolean draggingHW;  /**   * The constraints object used when adding the non-continuous divider to the   * JSplitPane.   */  protected static final String NON_CONTINUOUS_DIVIDER    = "nonContinuousDivider";  /** The dark divider used when dragging in non-continuous layout mode. */  protected Component nonContinuousLayoutDivider;  /** The JSplitPane that this UI draws. */  protected JSplitPane splitPane;  /**   * Creates a new BasicSplitPaneUI object.   */  public BasicSplitPaneUI()  {  }  /**   * This method creates a new BasicSplitPaneUI for the given JComponent.   *   * @param x The JComponent to create a UI for.   *   * @return A new BasicSplitPaneUI.   */  public static ComponentUI createUI(JComponent x)  {    return new BasicSplitPaneUI();  }  /**   * This method installs the BasicSplitPaneUI for the given JComponent.   *   * @param c The JComponent to install the UI for.   */  public void installUI(JComponent c)  {    if (c instanceof JSplitPane)      {	splitPane = (JSplitPane) c;	installDefaults();	installListeners();	installKeyboardActions();      }  }  /**   * This method uninstalls the BasicSplitPaneUI for the given JComponent.   *   * @param c The JComponent to uninstall the UI for.   */  public void uninstallUI(JComponent c)  {    uninstallKeyboardActions();    uninstallListeners();    uninstallDefaults();    splitPane = null;  }  /**   * This method installs the defaults given by the Look and Feel.   */  protected void installDefaults()  {    resetLayoutManager();    divider = createDefaultDivider();    nonContinuousLayoutDivider = createDefaultNonContinuousLayoutDivider();    splitPane.add(divider, JSplitPane.DIVIDER);    // There is no need to add the nonContinuousLayoutDivider    UIDefaults defaults = UIManager.getLookAndFeelDefaults();    splitPane.setBackground(defaults.getColor("SplitPane.background"));    splitPane.setBorder(defaults.getBorder("SplitPane.border"));    splitPane.setDividerSize(defaults.getInt("SplitPane.dividerSize"));  }  /**   * This method uninstalls the defaults and nulls any objects created during   * install.   */  protected void uninstallDefaults()  {    layoutManager = null;    splitPane.remove(divider);    divider = null;    nonContinuousLayoutDivider = null;    splitPane.setBackground(null);    splitPane.setBorder(null);  }  /**   * This method installs the listeners needed for this UI to function.   */  protected void installListeners()  {    propertyChangeListener = createPropertyChangeListener();    focusListener = createFocusListener();    splitPane.addPropertyChangeListener(propertyChangeListener);    splitPane.addFocusListener(focusListener);  }  /**   * This method uninstalls all listeners registered for the UI.   */  protected void uninstallListeners()  {    splitPane.removePropertyChangeListener(propertyChangeListener);    splitPane.removeFocusListener(focusListener);    focusListener = null;    propertyChangeListener = null;  }  /**   * This method installs the keyboard actions for the JSplitPane.   */  protected void installKeyboardActions()  {    // FIXME: implement.  }  /**

⌨️ 快捷键说明

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