/*
   *  Adjust the width of the scrollpane used by the popup
   */
  protected void popupWider(BasicComboPopup popup) {
    JList list = popup.getList();

    //  Determine the maximimum width to use:
    //  a) determine the popup preferred width
    //  b) limit width to the maximum if specified
    //  c) ensure width is not less than the scroll pane width

    int popupWidth =
        list.getPreferredSize().width
            + 5 // make sure horizontal scrollbar doesn't appear
            + getScrollBarWidth(popup, scrollPane);

    if (maximumWidth != -1) {
      popupWidth = Math.min(popupWidth, maximumWidth);
    }

    Dimension scrollPaneSize = scrollPane.getPreferredSize();
    popupWidth = Math.max(popupWidth, scrollPaneSize.width);

    //  Adjust the width

    scrollPaneSize.width = popupWidth;
    scrollPane.setPreferredSize(scrollPaneSize);
    scrollPane.setMaximumSize(scrollPaneSize);
  }
    public void layoutContainer(Container c) {
      JButton leftButton = getLeftButtonFromSuper();
      JButton rightButton = getRightButtonFromSuper();
      JSplitPane splitPane = getSplitPaneFromSuper();
      int orientation = getOrientationFromSuper();
      int oneTouchSize = getOneTouchSizeFromSuper();
      int oneTouchOffset = getOneTouchOffsetFromSuper();
      Insets insets = getInsets();

      // This layout differs from the one used in BasicSplitPaneDivider.
      // It does not center justify the oneTouchExpadable buttons.
      // This was necessary in order to meet the spec of the Metal
      // splitpane divider.
      if (leftButton != null && rightButton != null && c == MetalSplitPaneDivider.this) {
        if (splitPane.isOneTouchExpandable()) {
          if (orientation == JSplitPane.VERTICAL_SPLIT) {
            int extraY = (insets != null) ? insets.top : 0;
            int blockSize = getDividerSize();

            if (insets != null) {
              blockSize -= (insets.top + insets.bottom);
            }
            blockSize = Math.min(blockSize, oneTouchSize);
            leftButton.setBounds(oneTouchOffset, extraY, blockSize * 2, blockSize);
            rightButton.setBounds(
                oneTouchOffset + oneTouchSize * 2, extraY, blockSize * 2, blockSize);
          } else {
            int blockSize = getDividerSize();
            int extraX = (insets != null) ? insets.left : 0;

            if (insets != null) {
              blockSize -= (insets.left + insets.right);
            }
            blockSize = Math.min(blockSize, oneTouchSize);
            leftButton.setBounds(extraX, oneTouchOffset, blockSize, blockSize * 2);
            rightButton.setBounds(
                extraX, oneTouchOffset + oneTouchSize * 2, blockSize, blockSize * 2);
          }
        } else {
          leftButton.setBounds(-5, -5, 1, 1);
          rightButton.setBounds(-5, -5, 1, 1);
        }
      }
    }
Esempio n. 3
0
 private static Color getColorFromPallet(int[] pallet, float x) {
   if (x < 0f || x > 1f) {
     throw new IllegalArgumentException("Parameter outside of expected range");
   }
   int i = (int) (pallet.length * x);
   int max = pallet.length - 1;
   int index = Math.min(Math.max(i, 0), max);
   return new Color(pallet[index] & 0x00FFFFFF);
   // translucent
   // int pix = pallet[index] & 0x00FFFFFF | (0x64 << 24);
   // return new Color(pix), true);
 }
    @Override
    public void paint(Graphics g) {
      Color origColor;
      boolean isPressed, isRollOver, isEnabled;
      int w, h, size;

      w = getWidth();
      h = getHeight();
      origColor = g.getColor();
      isPressed = getModel().isPressed();
      isRollOver = getModel().isRollover();
      isEnabled = isEnabled();

      g.setColor(getBackground());
      g.fillRect(0, 0, w, h);

      g.setColor(shadow);
      // Using the background color set above
      if (direction == WEST) {
        g.drawLine(0, 0, 0, h - 1); // left
        g.drawLine(w - 1, 0, w - 1, 0); // right
      } else g.drawLine(w - 2, h - 1, w - 2, 0); // right

      g.drawLine(0, 0, w - 2, 0); // top

      if (isRollOver) {
        // do highlights or shadows
        Color color1;
        Color color2;

        if (isPressed) {
          color2 = Color.WHITE;
          color1 = shadow;
        } else {
          color1 = Color.WHITE;
          color2 = shadow;
        }

        g.setColor(color1);

        if (direction == WEST) {
          g.drawLine(1, 1, 1, h - 1); // left
          g.drawLine(1, 1, w - 2, 1); // top
          g.setColor(color2);
          g.drawLine(w - 1, h - 1, w - 1, 1); // right
        } else {
          g.drawLine(0, 1, 0, h - 1);
          g.drawLine(0, 1, w - 3, 1); // top
          g.setColor(color2);
          g.drawLine(w - 3, h - 1, w - 3, 1); // right
        }
      }

      // g.drawLine(0, h - 1, w - 1, h - 1); //bottom

      // If there's no room to draw arrow, bail
      if (h < 5 || w < 5) {
        g.setColor(origColor);
        return;
      }

      if (isPressed) {
        g.translate(1, 1);
      }

      // Draw the arrow
      size = Math.min((h - 4) / 3, (w - 4) / 3);
      size = Math.max(size, 2);

      boolean highlight = false;

      if (!highlightedTabs.isEmpty()
          && ((direction == WEST && tabScroller.scrollBackwardButton.isEnabled())
              || (direction == EAST && tabScroller.scrollForwardButton.isEnabled()))) {
        Rectangle viewRect = tabScroller.viewport.getViewRect();

        if (direction == WEST) {
          int leadingTabIndex = getClosestTab(viewRect.x, viewRect.y);

          for (int i = 0; i < leadingTabIndex; i++) {
            if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) {
              highlight = true;
              break;
            }
          }
        } else {
          int leadingTabIndex = getClosestTab(viewRect.x + viewRect.y, viewRect.y);

          for (int i = leadingTabIndex; i < tabPane.getTabCount(); i++) {
            if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) {
              highlight = true;
              break;
            }
          }
        }

        if (highlight) {
          Image img =
              DesktopUtilActivator.getImage(
                  direction == WEST
                      ? "service.gui.icons.TAB_UNREAD_BACKWARD_ICON"
                      : "service.gui.icons.TAB_UNREAD_FORWARD_ICON");

          int wi = img.getWidth(null);

          g.drawImage(img, (w - wi) / 2, (h - size) / 2 - 2 /* 2 borders 1px width*/, null);
        }
      }

      if (!highlight) paintTriangle(g, (w - size) / 2, (h - size) / 2, size, direction, isEnabled);

      // Reset the Graphics back to it's original settings
      if (isPressed) {
        g.translate(-1, -1);
      }
      g.setColor(origColor);
    }