Exemplo n.º 1
0
  /**
   * This method is called to drag the DragWindow around when the JToolBar is being dragged around.
   *
   * @param position The mouse cursor coordinates relative to the JToolBar.
   * @param origin The screen position of the JToolBar.
   */
  protected void dragTo(Point position, Point origin) {
    int loc = areaOfClick(origParent, SwingUtilities.convertPoint(toolBar, position, origParent));

    if (loc != -1) {
      dragWindow.setBorderColor(dockingBorderColor);
      dragWindow.setBackground(dockingColor);
    } else {
      dragWindow.setBorderColor(floatingBorderColor);
      dragWindow.setBackground(floatingColor);
    }

    int w = 0;
    int h = 0;

    boolean tmp = (loc == SwingConstants.NORTH) || (loc == SwingConstants.SOUTH) || (loc == -1);

    cachedOrientation = toolBar.getOrientation();
    cachedBounds = toolBar.getSize();
    if (((cachedOrientation == SwingConstants.HORIZONTAL) && tmp)
        || ((cachedOrientation == VERTICAL) && !tmp)) {
      w = cachedBounds.width;
      h = cachedBounds.height;
    } else {
      w = cachedBounds.height;
      h = cachedBounds.width;
    }

    Point p = dragWindow.getOffset();
    Insets insets = toolBar.getInsets();

    dragWindow.setBounds(
        (origin.x + position.x) - p.x - ((insets.left + insets.right) / 2),
        (origin.y + position.y) - p.y - ((insets.top + insets.bottom) / 2),
        w,
        h);

    if (!dragWindow.isVisible()) dragWindow.show();
  }
Exemplo n.º 2
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();
  }