コード例 #1
0
    /**
     * Updates the <code>Toolbar</code> represented by this folder.
     *
     * @param cookies array of instance cookies for the folder
     * @return the updated <code>ToolbarPool</code> representee
     */
    protected Object createInstance(InstanceCookie[] cookies)
        throws java.io.IOException, ClassNotFoundException {
      // refresh the toolbar's content
      getToolbar().removeAll();
      for (int i = 0; i < cookies.length; i++) {
        try {
          Object obj = cookies[i].instanceCreate();
          if (obj instanceof Presenter.Toolbar) {
            obj = ((Presenter.Toolbar) obj).getToolbarPresenter();
          }
          if (obj instanceof Component) {
            Component comp = (Component) obj;
            getToolbar().add(comp);
          }
        } catch (java.io.IOException ex) {
        } catch (ClassNotFoundException ex) {
        }
      }

      // invalidate the toolbar and its parent
      toolbar.invalidate();
      java.awt.Container parent = toolbar.getParent();
      if (parent != null) {
        parent.validate();
        parent.repaint();
      }
      return toolbar;
    }
コード例 #2
0
    /**
     * This method is called when the mouse is pressed in the JToolBar. If the press doesn't occur
     * in a place where it causes the JToolBar to be dragged, it returns. Otherwise, it starts a
     * drag session.
     *
     * @param e The MouseEvent.
     */
    public void mousePressed(MouseEvent e) {
      if (!toolBar.isFloatable()) return;

      Point ssd = e.getPoint();
      Insets insets = toolBar.getInsets();

      // Verify that this click occurs in the top inset.
      if (toolBar.getOrientation() == SwingConstants.HORIZONTAL) {
        if (e.getX() > insets.left) return;
      } else {
        if (e.getY() > insets.top) return;
      }

      origin = new Point(0, 0);
      if (toolBar.isShowing()) SwingUtilities.convertPointToScreen(ssd, toolBar);

      if (!(SwingUtilities.getAncestorOfClass(Window.class, toolBar) instanceof UIResource))
        // Need to know who keeps the toolBar if it gets dragged back into it.
        origParent = toolBar.getParent();

      if (toolBar.isShowing()) SwingUtilities.convertPointToScreen(origin, toolBar);

      isDragging = true;

      if (dragWindow != null)
        dragWindow.setOffset(new Point(cachedBounds.width / 2, cachedBounds.height / 2));

      dragTo(e.getPoint(), origin);
    }
コード例 #3
0
 /**
  * Package private method which returns either BorderLayout.NORTH, BorderLayout.SOUTH,
  * BorderLayout.EAST, or BorderLayout.WEST depending on the location of the toolbar in its parent.
  * The toolbar might be in PAGE_START, PAGE_END, CENTER, or some other position, but will be
  * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar actually IS, with
  * CENTER being NORTH.
  *
  * <p>This code is used to determine where the border line should be drawn by the custom toolbar
  * states, and also used by NimbusIcon to determine whether the handle icon needs to be shifted to
  * look correct.
  *
  * <p>Toollbars are unfortunately odd in the way these things are handled, and so this code exists
  * to unify the logic related to toolbars so it can be shared among the static files such as
  * NimbusIcon and generated files such as the ToolBar state classes.
  */
 public static Object resolveToolbarConstraint(JToolBar toolbar) {
   // NOTE: we don't worry about component orientation or PAGE_END etc
   // because the BasicToolBarUI always uses an absolute position of
   // NORTH/SOUTH/EAST/WEST.
   if (toolbar != null) {
     Container parent = toolbar.getParent();
     if (parent != null) {
       LayoutManager m = parent.getLayout();
       if (m instanceof BorderLayout) {
         BorderLayout b = (BorderLayout) m;
         Object con = b.getConstraints(toolbar);
         if (con == SOUTH || con == EAST || con == WEST) {
           return con;
         }
         return NORTH;
       }
     }
   }
   return NORTH;
 }
コード例 #4
0
  /**
   * This method is used at the end of a drag session to place the frame in either its original
   * parent as a docked JToolBar or in its floating frame.
   *
   * @param position The position of the mouse cursor relative to the JToolBar.
   * @param origin The screen position of the JToolBar before the drag session started.
   */
  protected void floatAt(Point position, Point origin) {
    Point p = new Point(position);
    int aoc = areaOfClick(origParent, SwingUtilities.convertPoint(toolBar, p, origParent));

    Container oldParent = toolBar.getParent();

    oldParent.remove(toolBar);
    oldParent.doLayout();
    oldParent.repaint();

    Container newParent;

    if (aoc == -1) newParent = ((RootPaneContainer) floatFrame).getContentPane();
    else {
      floatFrame.hide();
      newParent = origParent;
    }

    String constraint;
    switch (aoc) {
      case SwingConstants.EAST:
        constraint = BorderLayout.EAST;
        break;
      case SwingConstants.NORTH:
        constraint = BorderLayout.NORTH;
        break;
      case SwingConstants.SOUTH:
        constraint = BorderLayout.SOUTH;
        break;
      case SwingConstants.WEST:
        constraint = BorderLayout.WEST;
        break;
      default:
        constraint = BorderLayout.CENTER;
        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();
  }