Example #1
0
    public void paint(Graphics g) {
      Dimension size = getSize();
      Color colors[];
      if (isEnabled()) {
        if (getModel().isArmed() && getModel().isPressed()) {
          colors = BaseLookAndFeel.getTheme().getPressedColors();
        } else if (getModel().isRollover()) {
          colors = BaseLookAndFeel.getTheme().getRolloverColors();
        } else {
          colors = BaseLookAndFeel.getTheme().getButtonColors();
        }
      } else {
        colors = BaseLookAndFeel.getTheme().getDisabledColors();
      }
      Utilities.fillHorGradient(g, colors, 0, 0, size.width, size.height);

      boolean inverse = ColorHelper.getGrayValue(colors) < 128;

      Icon icon = inverse ? BaseIcons.getComboBoxInverseIcon() : BaseIcons.getComboBoxIcon();
      int x = (size.width - icon.getIconWidth()) / 2;
      int y = (size.height - icon.getIconHeight()) / 2;

      Graphics2D g2D = (Graphics2D) g;
      Composite savedComposite = g2D.getComposite();
      g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
      if (getModel().isPressed() && getModel().isArmed()) {
        icon.paintIcon(this, g, x + 2, y + 1);
      } else {
        icon.paintIcon(this, g, x + 1, y);
      }
      g2D.setComposite(savedComposite);
      paintBorder(g2D);
    }
Example #2
0
  protected void paintIndeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
      return;
    }
    Graphics2D g2D = (Graphics2D) g;

    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - (b.right + b.left);
    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);

    Color colors[];
    if (progressBar.getForeground() instanceof UIResource) {
      if (!Utilities.isActive(c)) {
        colors = BaseLookAndFeel.getTheme().getInActiveColors();
      } else if (c.isEnabled()) {
        colors = BaseLookAndFeel.getTheme().getProgressBarColors();
      } else {
        colors = BaseLookAndFeel.getTheme().getDisabledColors();
      }
    } else {
      Color hiColor = ColorHelper.brighter(progressBar.getForeground(), 40);
      Color loColor = ColorHelper.darker(progressBar.getForeground(), 20);
      colors = ColorHelper.createColorArr(hiColor, loColor, 20);
    }

    Color cHi = ColorHelper.darker(colors[colors.length - 1], 5);
    Color cLo = ColorHelper.darker(colors[colors.length - 1], 10);

    // Paint the bouncing box.
    Rectangle box = getBox(null);
    if (box != null) {
      g2D.setColor(progressBar.getForeground());
      Utilities.draw3DBorder(g, cHi, cLo, box.x + 1, box.y + 1, box.width - 2, box.height - 2);
      if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        Utilities.fillHorGradient(g, colors, box.x + 2, box.y + 2, box.width - 4, box.height - 4);
      } else {
        Utilities.fillVerGradient(g, colors, box.x + 2, box.y + 2, box.width - 4, box.height - 4);
      }

      // Deal with possible text painting
      if (progressBar.isStringPainted()) {
        Object savedRenderingHint = null;
        if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) {
          savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
          g2D.setRenderingHint(
              RenderingHints.KEY_TEXT_ANTIALIASING,
              BaseLookAndFeel.getTheme().getTextAntiAliasingHint());
        }
        if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
          paintString(g2D, b.left, b.top, barRectWidth, barRectHeight, box.width, b);
        } else {
          paintString(g2D, b.left, b.top, barRectWidth, barRectHeight, box.height, b);
        }
        if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) {
          g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
        }
      }
    }
  }
Example #3
0
  protected void installListeners() {
    super.installListeners();
    propertyChangeListener = new PropertyChangeHandler();
    comboBox.addPropertyChangeListener(propertyChangeListener);

    if (BaseLookAndFeel.getTheme().doShowFocusFrame()) {
      focusListener =
          new FocusListener() {

            public void focusGained(FocusEvent e) {
              if (comboBox != null) {
                orgBorder = comboBox.getBorder();
                orgBackgroundColor = comboBox.getBackground();
                LookAndFeel laf = UIManager.getLookAndFeel();
                if (laf instanceof BaseLookAndFeel) {
                  if (orgBorder instanceof UIResource) {
                    Border focusBorder =
                        ((BaseLookAndFeel) laf).getBorderFactory().getFocusFrameBorder();
                    comboBox.setBorder(focusBorder);
                  }
                  Color backgroundColor = BaseLookAndFeel.getTheme().getFocusBackgroundColor();
                  comboBox.setBackground(backgroundColor);
                }
              }
            }

            public void focusLost(FocusEvent e) {
              if (comboBox != null) {
                if (orgBorder instanceof UIResource) {
                  comboBox.setBorder(orgBorder);
                }
                comboBox.setBackground(orgBackgroundColor);
              }
            }
          };
      comboBox.addFocusListener(focusListener);
    }
  }
Example #4
0
  protected void paintDeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2D = (Graphics2D) g;
    Insets b = progressBar.getInsets(); // area for border
    int w = progressBar.getWidth() - (b.right + b.left);
    int h = progressBar.getHeight() - (b.top + b.bottom);

    // amount of progress to draw
    int amountFull = getAmountFull(b, w, h);
    Color colors[];
    if (progressBar.getForeground() instanceof UIResource) {
      if (!Utilities.isActive(c)) {
        colors = BaseLookAndFeel.getTheme().getInActiveColors();
      } else if (c.isEnabled()) {
        colors = BaseLookAndFeel.getTheme().getProgressBarColors();
      } else {
        colors = BaseLookAndFeel.getTheme().getDisabledColors();
      }
    } else {
      Color hiColor = ColorHelper.brighter(progressBar.getForeground(), 40);
      Color loColor = ColorHelper.darker(progressBar.getForeground(), 20);
      colors = ColorHelper.createColorArr(hiColor, loColor, 20);
    }
    Color cHi = ColorHelper.darker(colors[colors.length - 1], 5);
    Color cLo = ColorHelper.darker(colors[colors.length - 1], 10);
    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      if (Utilities.isLeftToRight(progressBar)) {
        Utilities.draw3DBorder(g, cHi, cLo, 1 + b.left, 2, amountFull - 2, h - 2);
        Utilities.fillHorGradient(g, colors, 2 + b.left, 3, amountFull - 4, h - 4);
      } else {
        Utilities.draw3DBorder(
            g,
            cHi,
            cLo,
            progressBar.getWidth() - amountFull - b.right + 2,
            2,
            amountFull - 2,
            h - 2);
        Utilities.fillHorGradient(
            g, colors, progressBar.getWidth() - amountFull - b.right + 3, 3, amountFull - 4, h - 4);
      }
    } else { // VERTICAL
      Utilities.draw3DBorder(g, cHi, cLo, 2, h - amountFull + 2, w - 2, amountFull - 2);
      Utilities.fillVerGradient(g, colors, 3, h - amountFull + 3, w - 4, amountFull - 4);
    }

    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      Object savedRenderingHint = null;
      if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) {
        savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
        g2D.setRenderingHint(
            RenderingHints.KEY_TEXT_ANTIALIASING,
            BaseLookAndFeel.getTheme().getTextAntiAliasingHint());
      }
      paintString(g, b.left, b.top, w, h, amountFull, b);
      if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) {
        g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
      }
    }
  }