Exemplo n.º 1
0
  public static Insets flipInsets(Component c, Insets i) {
    if (c instanceof ShapedPanel) {
      if (((ShapedPanel) c).isHorizontalFlip()) i = InsetsUtil.flipHorizontal(i);
      if (((ShapedPanel) c).isVerticalFlip()) i = InsetsUtil.flipVertical(i);
    }

    return i;
  }
Exemplo n.º 2
0
  private Insets getRealTabInsets(
      Direction areaOrientation, Direction tabDirection, Insets insets) {
    Insets insetsTemp = insets;
    insetsTemp = InsetsUtil.rotate(tabDirection, insetsTemp);

    if (swapWidthHeights[getDirectionIndex(areaOrientation)]) {

      insetsTemp = InsetsUtil.rotate(areaOrientation.getNextCCW(), insetsTemp);
    }

    return insetsTemp;
  }
Exemplo n.º 3
0
  private boolean findShapedBorder(Border border, Insets i) {
    if (border == null) return false;
    else if (border instanceof ShapedBorder) {
      shapedBorder = (ShapedBorder) border;
      shapedInsets = i;
      return true;
    } else if (border instanceof CompoundBorder) {
      CompoundBorder c = (CompoundBorder) border;

      if (findShapedBorder(c.getOutsideBorder(), i)) return true;

      return findShapedBorder(
          c.getInsideBorder(), InsetsUtil.add(c.getOutsideBorder().getBorderInsets(this), i));
    } else return false;
  }
Exemplo n.º 4
0
  private void initValues(PanePainter pane, int index, Direction direction) {
    estimateSwappedTabDirection(pane, index);

    reset(pane);

    pane.setSize(1000, 1000);

    boolean upDown = !direction.isHorizontal();

    for (int i = 0; i < DEFAULT_TAB_COUNT; i++) {
      pane.addTab(EMPTY_STRING, getComponent());
    }

    pane.setSelectedIndex(DEFAULT_SELECTED_INDEX);

    pane.doValidation();

    // Tab insets if any from UImanager
    Insets insets = UIManager.getInsets("TabbedPane.tabInsets");
    if (insets == null) insets = new Insets(0, 0, 0, 0);

    if (!upDown) tabInsets[index] = new Insets(0, insets.left, 0, insets.right);
    else tabInsets[index] = InsetsUtil.EMPTY_INSETS;

    // Raised
    Rectangle bounds = pane.getBoundsAt(0);
    Rectangle bounds2 = pane.getBoundsAt(pane.getSelectedIndex());

    if (direction == Direction.UP) raiseds[index] = Math.max(0, bounds.y - bounds2.y);
    else if (direction == Direction.LEFT) raiseds[index] = Math.max(0, bounds.x - bounds2.x);
    else if (direction == Direction.DOWN) raiseds[index] = raiseds[getDirectionIndex(Direction.UP)];
    else raiseds[index] = raiseds[getDirectionIndex(Direction.LEFT)];

    // Spacing
    Insets normal = getCalculatedInsets(pane, 0, false, direction);
    Insets selected = getCalculatedInsets(pane, 0, true, direction);

    if (upDown) spacings[index] = normal.left + normal.right - selected.left - selected.right;
    else spacings[index] = normal.top + normal.bottom - selected.top - selected.bottom;

    // Normal insets
    normalInsets[index] = getCalculatedInsets(pane, 0, false, direction);

    // Selected insets
    Insets insetsTemp = getCalculatedInsets(pane, 0, true, direction);
    int spacing = spacings[index];
    int spaceFirst = spacing / 2;
    int spaceAfter = spacing / 2 + spacing % 2;

    if (direction == Direction.UP) {
      insetsTemp.bottom = normalInsets[index].bottom;
      insetsTemp.top = normalInsets[index].top;
      insetsTemp.left += spaceFirst;
      insetsTemp.right += spaceAfter;
    } else if (direction == Direction.LEFT) {
      insetsTemp.right = normalInsets[index].right;
      insetsTemp.left = normalInsets[index].left;
      insetsTemp.top += spaceFirst;
      insetsTemp.bottom += spaceAfter;
    } else if (direction == Direction.RIGHT) {
      insetsTemp.right = normalInsets[index].right;
      insetsTemp.left = normalInsets[index].left;
      insetsTemp.top += spaceFirst;
      insetsTemp.bottom += spaceAfter;
    } else {
      insetsTemp.bottom = normalInsets[index].bottom;
      insetsTemp.top = normalInsets[index].top;
      insetsTemp.left += spaceFirst;
      insetsTemp.right += spaceAfter;
    }

    selectedInsets[index] = insetsTemp;

    // Content insets
    JPanel c = new JPanel();
    pane.addTab(EMPTY_STRING, c);
    pane.setSelectedIndex(pane.getTabCount() - 1);
    pane.doValidation();

    Point l = SwingUtilities.convertPoint(c.getParent(), c.getLocation(), pane);

    Rectangle boundsTemp = pane.getBoundsAt(0);
    int top = 0;
    int left = 0;
    int bottom = 0;
    int right = 0;

    if (direction == Direction.UP) {
      top = l.y - boundsTemp.height - boundsTemp.y;
      left = l.x;
      bottom = pane.getHeight() - l.y - c.getHeight();
      right = pane.getWidth() - l.x - c.getWidth();
    } else if (direction == Direction.DOWN) {
      top = l.y;
      left = l.x;
      bottom = pane.getHeight() - c.getHeight() - l.y - (pane.getHeight() - boundsTemp.y);
      right = pane.getWidth() - l.x - c.getWidth();
    } else if (direction == Direction.LEFT) {
      top = l.y;
      left = l.x - boundsTemp.width - boundsTemp.x;
      bottom = pane.getHeight() - l.y - c.getHeight();
      right = pane.getWidth() - l.x - c.getWidth();
    } else {
      top = l.y;
      left = l.x;
      bottom = pane.getHeight() - l.y - c.getHeight();
      right = pane.getWidth() - c.getWidth() - l.x - (pane.getWidth() - boundsTemp.x);
    }

    contentInsets[index] = new Insets(top, left, bottom, right);

    Insets i = contentInsets[0];
    Insets i2 = InsetsUtil.rotate(direction.getNextCW(), i);
    Insets adjustedInsets = InsetsUtil.max(i, i2);
    adjustedContentInsets[index] = adjustedInsets;
    adjustedContentInsetsTabAreaHidden[index] =
        new Insets(
            direction == Direction.UP ? adjustedInsets.left : adjustedInsets.top,
            direction == Direction.LEFT ? adjustedInsets.top : adjustedInsets.left,
            direction == Direction.DOWN ? adjustedInsets.right : adjustedInsets.bottom,
            direction == Direction.RIGHT ? adjustedInsets.bottom : adjustedInsets.right);

    pane.removeTabAt(pane.getTabCount() - 1);
    pane.setSelectedIndex(DEFAULT_SELECTED_INDEX);

    pane.doValidation();

    // Minimum sizes
    Rectangle rectangleBounds = pane.getBoundsAt(DEFAULT_SELECTED_INDEX);
    tabMinimumSizes[index] = new Dimension(rectangleBounds.width, rectangleBounds.height);
    minimumSizes[index] =
        new Dimension(
            rectangleBounds.width - tabInsets[index].left - tabInsets[index].right,
            rectangleBounds.height - tabInsets[index].top - tabInsets[index].bottom);

    calculateAreaInsets(pane, index, direction);

    estimateContentTabAreaBorderColor(pane, index, direction);
  }
Exemplo n.º 5
0
 public static Insets transformInsets(Component c, Insets insets) {
   return InsetsUtil.rotate(getDirection(c), flipInsets(c, insets));
 }