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

📄 basictoolbarui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	break;      }    int newOrientation = SwingConstants.HORIZONTAL;    if ((aoc != -1)        && ((aoc == SwingConstants.EAST) || (aoc == SwingConstants.WEST)))      newOrientation = SwingConstants.VERTICAL;    if (aoc != -1)      {	constraintBeforeFloating = constraint;	lastGoodOrientation = newOrientation;      }    newParent.add(toolBar, constraint);    setFloating(aoc == -1, null);    toolBar.setOrientation(newOrientation);    Insets insets = floatFrame.getInsets();    Dimension dims = toolBar.getPreferredSize();    p = dragWindow.getOffset();    setFloatingLocation((position.x + origin.x) - p.x                        - ((insets.left + insets.right) / 2),                        (position.y + origin.y) - p.y                        - ((insets.top + insets.bottom) / 2));    if (aoc == -1)      {	floatFrame.pack();	floatFrame.setSize(dims.width + insets.left + insets.right,	                   dims.height + insets.top + insets.bottom);	floatFrame.show();      }    newParent.invalidate();    newParent.validate();    newParent.repaint();  }  /**   * This method returns the docking color.   *   * @return The docking color.   */  public Color getDockingColor()  {    return dockingColor;  }  /**   * This method returns the Color which is displayed when over a floating   * area.   *   * @return The color which is displayed when over a floating area.   */  public Color getFloatingColor()  {    return floatingColor;  }  /**   * This method returns the maximum size of the given JComponent for this UI.   *   * @param c The JComponent to find the maximum size for.   *   * @return The maximum size for this UI.   */  public Dimension getMaximumSize(JComponent c)  {    return getPreferredSize(c);  }  /**   * This method returns the minimum size of the given JComponent for this UI.   *   * @param c The JComponent to find a minimum size for.   *   * @return The minimum size for this UI.   */  public Dimension getMinimumSize(JComponent c)  {    return getPreferredSize(c);  }  /**   * This method installs the needed components for the JToolBar.   */  protected void installComponents()  {    floatFrame = (Window) createFloatingWindow(toolBar);    dragWindow = createDragWindow(toolBar);    nonRolloverBorder = createNonRolloverBorder();    rolloverBorder = createRolloverBorder();    borders = new Hashtable();    fillHashtable();  }  /**   * This method installs the defaults as specified by the look and feel.   */  protected void installDefaults()  {    LookAndFeel.installBorder(toolBar, "ToolBar.border");    LookAndFeel.installColorsAndFont(toolBar, "ToolBar.background",                                     "ToolBar.foreground", "ToolBar.font");    dockingBorderColor = UIManager.getColor("ToolBar.dockingForeground");    dockingColor = UIManager.getColor("ToolBar.dockingBackground");    floatingBorderColor = UIManager.getColor("ToolBar.floatingForeground");    floatingColor = UIManager.getColor("ToolBar.floatingBackground");    setRolloverBorders(toolBar.isRollover());  }  /**   * This method installs the keyboard actions for the JToolBar as specified   * by the look and feel.   */  protected void installKeyboardActions()  {    // FIXME: implement.  }  /**   * This method installs listeners for the JToolBar.   */  protected void installListeners()  {    dockingListener = createDockingListener();    toolBar.addMouseListener(dockingListener);    toolBar.addMouseMotionListener(dockingListener);    propertyListener = createPropertyListener();    toolBar.addPropertyChangeListener(propertyListener);    toolBarContListener = createToolBarContListener();    toolBar.addContainerListener(toolBarContListener);    windowListener = createFrameListener();    floatFrame.addWindowListener(windowListener);    toolBarFocusListener = createToolBarFocusListener();    toolBar.addFocusListener(toolBarFocusListener);  }  /**   * This method installs non rollover borders for each component inside the   * given JComponent.   *   * @param c The JComponent whose children need to have non rollover borders   *        installed.   */  protected void installNonRolloverBorders(JComponent c)  {    Component[] components = toolBar.getComponents();    for (int i = 0; i < components.length; i++)      setBorderToNonRollover(components[i]);  }  /**   * This method installs normal (or their original) borders for each   * component inside the given JComponent.   *   * @param c The JComponent whose children need to have their original   *        borders installed.   */  protected void installNormalBorders(JComponent c)  {    Component[] components = toolBar.getComponents();    for (int i = 0; i < components.length; i++)      setBorderToNormal(components[i]);  }  /**   * This method install rollover borders for each component inside the given   * JComponent.   *   * @param c The JComponent whose children need to have rollover borders   *        installed.   */  protected void installRolloverBorders(JComponent c)  {    Component[] components = toolBar.getComponents();    for (int i = 0; i < components.length; i++)      setBorderToRollover(components[i]);  }  /**   * This method fills the borders hashtable with a list of components that   * are JButtons and their borders.   */  private void fillHashtable()  {    Component[] c = toolBar.getComponents();    for (int i = 0; i < c.length; i++)      {	if (c[i] instanceof JButton)	  {	    // Don't really care about anything other than JButtons	    JButton b = (JButton) c[i];	    if (b.getBorder() != null)	      borders.put(b, b.getBorder());	  }      }  }  /**   * This method installs the UI for the given JComponent.   *   * @param c The JComponent to install a UI for.   */  public void installUI(JComponent c)  {    super.installUI(c);    if (c instanceof JToolBar)      {	toolBar = (JToolBar) c;	toolBar.setOpaque(true);	installDefaults();	installComponents();	installListeners();	installKeyboardActions();      }  }  /**   * This method returns whether the JToolBar is floating.   *   * @return Whether the JToolBar is floating.   */  public boolean isFloating()  {    return floatFrame.isVisible();  }  /**   * This method returns whether rollover borders have been set.   *   * @return Whether rollover borders have been set.   */  public boolean isRolloverBorders()  {    return toolBar.isRollover();  }  /**   * This method navigates in the given direction giving focus to the next   * component in the given direction.   *   * @param direction The direction to give focus to.   */  protected void navigateFocusedComp(int direction)  {    // FIXME: Implement.  }  /**   * This method sets the border of the given component to a non rollover   * border.   *   * @param c The Component whose border needs to be set.   */  protected void setBorderToNonRollover(Component c)  {    if (c instanceof JButton)      {	JButton b = (JButton) c;	b.setRolloverEnabled(false);	b.setBorder(nonRolloverBorder);      }  }  /**   * This method sets the border of the given component to its original value.   *   * @param c The Component whose border needs to be set.   */  protected void setBorderToNormal(Component c)  {    if (c instanceof JButton)      {	JButton b = (JButton) c;	Border border = (Border) borders.get(b);	b.setBorder(border);      }  }  /**   * This method sets the border of the given component to a rollover border.   *   * @param c The Component whose border needs to be set.   */  protected void setBorderToRollover(Component c)  {    if (c instanceof JButton)      {	JButton b = (JButton) c;	b.setRolloverEnabled(true);	b.setBorder(rolloverBorder);      }  }  /**   * This method sets the docking color.   *   * @param c The docking color.   */  public void setDockingColor(Color c)  {    dockingColor = c;  }  /**   * This method sets the floating property for the JToolBar.   *   * @param b Whether the JToolBar is floating.   * @param p FIXME   */  public void setFloating(boolean b, Point p)  {    // FIXME: use p for something. It's not location    // since we already have setFloatingLocation.    floatFrame.setVisible(b);  }  /**   * This method sets the color displayed when the JToolBar is not in a   * dockable area.   *   * @param c The floating color.   */  public void setFloatingColor(Color c)  {    floatingColor = c;  }  /**   * This method sets the floating location of the JToolBar.   *   * @param x The x coordinate for the floating frame.   * @param y The y coordinate for the floating frame.   */  public void setFloatingLocation(int x, int y)  {    // x,y are the coordinates of the new JFrame created to store the toolbar    // XXX: The floating location is bogus is not floating.    floatFrame.setLocation(x, y);    floatFrame.invalidate();    floatFrame.validate();    floatFrame.repaint();  }  /**   * This is a convenience method for changing the orientation of the   * JToolBar.   *   * @param orientation The new orientation.   */  public void setOrientation(int orientation)  {    toolBar.setOrientation(orientation);  }  /**   * This method changes the child components to have rollover borders if the   * given parameter is true. Otherwise, the components are set to have non   * rollover borders.   *   * @param rollover Whether the children will have rollover borders.   */  public void setRolloverBorders(boolean rollover)  {    if (rollover)      installRolloverBorders(toolBar);    else      installNonRolloverBorders(toolBar);  }  /**   * This method uninstall UI installed components from the JToolBar.   */  protected void uninstallComponents()  {    installNormalBorders(toolBar);    borders = null;    rolloverBorder = null;    nonRolloverBorder = null;    cachedBounds = null;    floatFrame = null;    dragWindow = null;  }  /**   * This method removes the defaults installed by the Look and Feel.   */  protected void uninstallDefaults()  {    toolBar.setBackground(null);    toolBar.setForeground(null);    toolBar.setFont(null);    dockingBorderColor = null;    dockingColor = null;    floatingBorderColor = null;    floatingColor = null;  }  /**   * This method uninstalls keyboard actions installed by the UI.   */  protected void uninstallKeyboardActions()  {    // FIXME: implement.  }  /**   * This method uninstalls listeners installed by the UI.   */  protected void uninstallListeners()  {    toolBar.removeFocusListener(toolBarFocusListener);    toolBarFocusListener = null;    floatFrame.removeWindowListener(windowListener);    windowListener = null;    toolBar.removeContainerListener(toolBarContListener);    toolBarContListener = null;    toolBar.removeMouseMotionListener(dockingListener);    toolBar.removeMouseListener(dockingListener);    dockingListener = null;  }  /**   * This method uninstalls the UI.   *   * @param c The JComponent that is having this UI removed.   */  public void uninstallUI(JComponent c)  {    uninstallKeyboardActions();    uninstallListeners();    uninstallComponents();    uninstallDefaults();    toolBar = null;  }  /**   * This is the MouseHandler class that allows the user to drag the JToolBar   * in and out of the parent and dock it if it can.   */  public class DockingListener implements MouseInputListener  {    /** Whether the JToolBar is being dragged. */    protected boolean isDragging;    /**     * The origin point. This point is saved from the beginning press and is     * used until the end of the drag session.     */    protected Point origin;    /** The JToolBar being dragged. */    protected JToolBar toolBar;    /**     * Creates a new DockingListener object.     *

⌨️ 快捷键说明

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