@Override
  protected void paintBackground(Graphics g, JComponent component) {
    getGlassParameters();
    Graphics2D g2d = (Graphics2D) g.create();

    if (getOrientation().isHorizontal()) {
      paintBackground(
          g2d,
          0,
          0,
          component.getWidth(),
          component.getHeight(),
          getOrientation().isHorizontal(),
          component);
    } else {
      paintBackground(
          g2d,
          0,
          0,
          component.getHeight(),
          component.getWidth(),
          getOrientation().isHorizontal(),
          component);
    }

    g2d.dispose();
  }
  /**
   * Moves the visible location of the frame being dragged to the location specified. The means by
   * which this occurs can vary depending on the dragging algorithm being used. The actual logical
   * location of the frame might not change until <code>endDraggingFrame</code> is called.
   */
  public void dragFrame(JComponent f, int newX, int newY) {

    if (dragMode == OUTLINE_DRAG_MODE) {
      JDesktopPane desktopPane = getDesktopPane(f);
      if (desktopPane != null) {
        Graphics g = JComponent.safelyGetGraphics(desktopPane);

        g.setXORMode(Color.white);
        if (currentLoc != null) {
          g.drawRect(currentLoc.x, currentLoc.y, f.getWidth() - 1, f.getHeight() - 1);
        }
        g.drawRect(newX, newY, f.getWidth() - 1, f.getHeight() - 1);
        /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
         * Swing doesn't expect that its XOR drawRect did
         * not complete, so believes that on re-entering at
         * the next update location, that there is an XOR rect
         * to draw out at "currentLoc". But in fact
         * it's now got a new clean surface without that rect,
         * so drawing it "out" in fact draws it on, leaving garbage.
         * So only update/set currentLoc if the draw completed.
         */
        sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData();

        if (!sData.isSurfaceLost()) {
          currentLoc = new Point(newX, newY);
        }
        g.dispose();
      }
    } else if (dragMode == FASTER_DRAG_MODE) {
      dragFrameFaster(f, newX, newY);
    } else {
      setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
    }
  }
Exemple #3
0
  @Override
  public void paint(Graphics g, JComponent c) {
    JButton button = (JButton) c;
    String text = button.getText();
    Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    FontMetrics fm = g.getFontMetrics();
    paintViewInsets = c.getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;

    // Use inverted height &amp; width
    paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform tr = g2.getTransform();

    if (angle == 90) {
      g2.rotate(Math.PI / 2);
      g2.translate(0, -c.getWidth());
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    } else if (angle == 270) {
      g2.rotate(-Math.PI / 2);
      g2.translate(-c.getHeight(), 0);
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    }

    if (icon != null) {
      icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      int textX = paintTextR.x;
      int textY = paintTextR.y + fm.getAscent();

      if (button.isEnabled()) {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      } else {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      }
    }

    g2.setTransform(tr);
  }
Exemple #4
0
 public void update(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     g.setColor(c.getBackground());
     g.fillRect(0, 0, c.getWidth(), c.getHeight());
     if (is3D()) {
       Rectangle bounds = new Rectangle(0, 0, c.getWidth(), c.getHeight());
       boolean isHorizontal = ((JToolBar) c).getOrientation() == SwingConstants.HORIZONTAL;
       PlasticUtils.addLight3DEffekt(g, bounds, isHorizontal);
     }
   }
   paint(g, c);
 }
 /** This moves the <code>JComponent</code> and repaints the damaged areas. */
 public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
   boolean didResize = (f.getWidth() != newWidth || f.getHeight() != newHeight);
   f.setBounds(newX, newY, newWidth, newHeight);
   if (didResize) {
     f.validate();
   }
 }
Exemple #6
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {

      JScrollPane scroll = (JScrollPane) c;
      JComponent colHeader = scroll.getColumnHeader();
      int colHeaderHeight = 0;
      if (colHeader != null) colHeaderHeight = colHeader.getHeight();

      JComponent rowHeader = scroll.getRowHeader();
      int rowHeaderWidth = 0;
      if (rowHeader != null) rowHeaderWidth = rowHeader.getWidth();

      g.translate(x, y);

      g.setColor(MetalLookAndFeel.getControlDarkShadow());
      g.drawRect(0, 0, w - 2, h - 2);
      g.setColor(MetalLookAndFeel.getControlHighlight());

      g.drawLine(w - 1, 1, w - 1, h - 1);
      g.drawLine(1, h - 1, w - 1, h - 1);

      g.setColor(MetalLookAndFeel.getControl());
      g.drawLine(w - 2, 2 + colHeaderHeight, w - 2, 2 + colHeaderHeight);
      g.drawLine(1 + rowHeaderWidth, h - 2, 1 + rowHeaderWidth, h - 2);

      g.translate(-x, -y);
    }
    /**
     * Reinitialize the insets parameter with this Border's current Insets.
     *
     * @param c the component for which this border insets value applies
     * @param insets the object to be reinitialized
     */
    public Insets getBorderInsets(Component c, Insets insets) {
      Border border = getBorder();
      if (border != null) {
        if (border instanceof AbstractBorder) {
          ((AbstractBorder) border).getBorderInsets(c, insets);
        } else {
          // Can't reuse border insets because the Border interface
          // can't be enhanced.
          Insets i = border.getBorderInsets(c);
          insets.top = i.top;
          insets.right = i.right;
          insets.bottom = i.bottom;
          insets.left = i.left;
        }
      } else {
        insets.left = insets.top = insets.right = insets.bottom = 0;
      }

      insets.left += EDGE_SPACING + TEXT_SPACING;
      insets.right += EDGE_SPACING + TEXT_SPACING;
      insets.top += EDGE_SPACING + TEXT_SPACING;
      insets.bottom += EDGE_SPACING + TEXT_SPACING;

      if (c == null || label == null) {
        return insets;
      }

      insets.top += label.getHeight();

      return insets;
    }
  /**
   * Notifies this UI delegate to repaint the specified component. This method paints the component
   * background, then calls the {@link #paint(SynthContext,Graphics)} method.
   *
   * <p>In general, this method does not need to be overridden by subclasses. All Look and Feel
   * rendering code should reside in the {@code paint} method.
   *
   * @param g the {@code Graphics} object used for painting
   * @param c the component being painted
   * @see #paint(SynthContext,Graphics)
   */
  @Override
  public void update(Graphics g, JComponent c) {
    SynthContext context = getContext(c);

    SynthLookAndFeel.update(context, g);
    context.getPainter().paintScrollPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight());
    paint(context, g);
  }
 @Override
 public void paint(Graphics g, JComponent c) {
   Gripper gripper = (Gripper) c;
   paintBackground(g, gripper);
   int state = gripper.isSelected() ? ThemePainter.STATE_SELECTED : ThemePainter.STATE_DEFAULT;
   if (_gripperPainter == null) {
     getPainter()
         .paintGripper(
             c,
             g,
             new Rectangle(0, 0, c.getWidth(), c.getHeight()),
             gripper.getOrientation(),
             state);
   } else {
     _gripperPainter.paint(
         c, g, new Rectangle(0, 0, c.getWidth(), c.getHeight()), gripper.getOrientation(), state);
   }
 }
Exemple #10
0
 public void paintBackground(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     if (c.getBackground() instanceof ColorUIResource) {
       g.setColor(AbstractLookAndFeel.getBackgroundColor());
     } else {
       g.setColor(c.getBackground());
     }
     g.fillRect(0, 0, c.getWidth(), c.getHeight());
   }
 }
 public void update(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     g.setColor(c.getBackground());
     g.fillRect(0, 0, c.getWidth(), c.getHeight());
     if (isToolBarComboBox(c)) {
       c.setOpaque(false);
     }
   }
   paint(g, c);
 }
 public void paintBackground(Graphics g, JComponent c) {
   if (c.isOpaque()) {
     if ((c.getBackground().equals(AbstractLookAndFeel.getBackgroundColor()))
         && (c.getBackground() instanceof ColorUIResource)) {
       HiFiUtils.fillComponent(g, c);
     } else {
       g.setColor(c.getBackground());
       g.fillRect(0, 0, c.getWidth(), c.getHeight());
     }
   }
 }
 protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
   int w = c.getWidth();
   int h = c.getHeight();
   if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
     JTattooUtilities.fillVerGradient(
         g, AbstractLookAndFeel.getTheme().getTrackColors(), 0, 0, w, h);
   } else {
     JTattooUtilities.fillHorGradient(
         g, AbstractLookAndFeel.getTheme().getTrackColors(), 0, 0, w, h);
   }
 }
Exemple #14
0
 /**
  * If necessary paints the background of the component, then invokes <code>paint</code>.
  *
  * @param g Graphics to paint to
  * @param c JComponent painting on
  * @throws NullPointerException if <code>g</code> or <code>c</code> is null
  * @see javax.swing.plaf.ComponentUI#update
  * @see javax.swing.plaf.ComponentUI#paint
  * @since 1.5
  */
 public void update(Graphics g, JComponent c) {
   AbstractButton button = (AbstractButton) c;
   if ((c.getBackground() instanceof UIResource)
       && button.isContentAreaFilled()
       && c.isEnabled()) {
     ButtonModel model = button.getModel();
     if (!MetalUtils.isToolBarButton(c)) {
       if (!model.isArmed()
           && !model.isPressed()
           && MetalUtils.drawGradient(
               c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
         paint(g, c);
         return;
       }
     } else if (model.isRollover()
         && MetalUtils.drawGradient(
             c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
       paint(g, c);
       return;
     }
   }
   super.update(g, c);
 }
Exemple #15
0
 @Override
 public int getIconHeight(SynthContext context) {
   if (context == null) {
     return height;
   }
   JComponent c = context.getComponent();
   if (c instanceof JToolBar) {
     JToolBar toolbar = (JToolBar) c;
     if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
       // we only do the -1 hack for UIResource borders, assuming
       // that the border is probably going to be our border
       if (toolbar.getBorder() instanceof UIResource) {
         return c.getHeight() - 1;
       } else {
         return c.getHeight();
       }
     } else {
       return scale(context, width);
     }
   } else {
     return scale(context, height);
   }
 }
 // implements javax.swing.DesktopManager
 public void endDraggingFrame(JComponent f) {
   if (dragMode == OUTLINE_DRAG_MODE && currentLoc != null) {
     setBoundsForFrame(f, currentLoc.x, currentLoc.y, f.getWidth(), f.getHeight());
     currentLoc = null;
   } else if (dragMode == FASTER_DRAG_MODE) {
     currentBounds = null;
     if (desktopGraphics != null) {
       desktopGraphics.dispose();
       desktopGraphics = null;
     }
     desktopBounds = null;
     ((JInternalFrame) f).isDragging = false;
   }
 }
Exemple #17
0
 @Override
 public void paint(Graphics g, JComponent c) {
   final Border border = c.getBorder();
   final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
   final boolean square = isSquare(c);
   if (c.isEnabled() && border != null) {
     final Insets ins = border.getBorderInsets(c);
     final int yOff = (ins.top + ins.bottom) / 4;
     if (!square) {
       if (((JButton) c).isDefaultButton()) {
         ((Graphics2D) g)
             .setPaint(
                 UIUtil.getGradientPaint(
                     0,
                     0,
                     getSelectedButtonColor1(),
                     0,
                     c.getHeight(),
                     getSelectedButtonColor2()));
       } else {
         ((Graphics2D) g)
             .setPaint(
                 UIUtil.getGradientPaint(
                     0, 0, getButtonColor1(), 0, c.getHeight(), getButtonColor2()));
       }
     }
     g.fillRoundRect(
         square ? 2 : 4,
         yOff,
         c.getWidth() - 2 * 4,
         c.getHeight() - 2 * yOff,
         square ? 3 : 5,
         square ? 3 : 5);
   }
   config.restore();
   super.paint(g, c);
 }
 private void _update(Graphics2D graphics2D, JComponent jComponent) {
   GFX ctx = new Java2DGFX(graphics2D);
   graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
   graphics2D.setRenderingHint(
       RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   graphics2D.setRenderingHint(
       RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
   // graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
   // RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
   ctx.setPaint(backgroundFill);
   ctx.fillRect(0, 0, jComponent.getWidth(), jComponent.getHeight());
   // draw the scene
   root.draw(ctx);
 }
  /**
   * Show the window.
   *
   * @param container - Window of JFrame to show
   */
  private void showPopup(Window container) {
    if (visibleComponent.isEnabled()) {
      Point pt = visibleComponent.getLocationOnScreen();
      pt.translate(0, visibleComponent.getHeight());
      container.setLocation(pt);
      container.toFront();

      ApplicationManager.setCurrentlySelectedField(fieldName);
      if (container instanceof OntologySelector) {
        ((OntologySelector) container).makeVisible();
      } else {
        container.setVisible(true);
        container.requestFocusInWindow();
      }
    }
  }
  public DropDownComponent(
      String fieldName, JComponent visibleComponent, Window dropDownComponent, int type) {
    this.fieldName = fieldName;
    this.visibleComponent = visibleComponent;
    this.visibleComponent.setPreferredSize(
        new Dimension(visibleComponent.getWidth(), visibleComponent.getHeight()));
    this.hideableWindow = dropDownComponent;

    ResourceInjector.get("common-package.style").inject(this);

    createIcon(dropDownComponent, type);

    addAncestorListener(this);

    setupLayout();
  }
Exemple #21
0
  /**
   * Draws an emblem (based on current theme) in the bottom left of the given component. Call this
   * in paintComponent() of the component.
   *
   * @param component the component to draw on
   * @param g the Graphics object from paintComponent()
   */
  public static void drawEmblem(JComponent component, Graphics g) {
    Themes currentTheme = Themes.getCurrentTheme();
    ImageIcon image = GUI.createImageIcon("translucent/" + currentTheme.getImageIconPath());

    /*if(Themes.getCurrentTheme() == Themes.SNOW){
        image = GUI.createImageIcon("translucent/snow.png");
    }*/

    int imageWidth = image.getIconWidth();
    int imageHeight = image.getIconHeight();
    // top left corner of where to start drawing
    int topLeftX = component.getWidth() - imageWidth; // x (horizontal) coordinate
    int topLeftY = component.getHeight() - imageHeight; // y (vertical) coordinate

    // draw in bottom right corner
    g.drawImage(image.getImage(), topLeftX, topLeftY, (java.awt.image.ImageObserver) null);
    // g.drawImage(image.getImage(), 0,0, (java.awt.image.ImageObserver)null);
  }
  @Override
  protected void paintForeground(Graphics g, JComponent component) {
    // paint icon (if there is any)
    paintIcon(g, component);

    Insets ins = getOutsideInsets();

    int w = component.getWidth();
    int h = component.getHeight();

    // paint knob (if there is any)
    // TODO colors
    if (behavior.isShowKnob()) {
      Insets insets = getInnerInsets();

      if (getOrientation().isHorizontal()) {
        int x = ins.left + insets.left - KNOB_SIZE + 3;
        int y1 = ins.top + insets.top + 3;
        int y2 = h - insets.bottom - ins.bottom - 4;

        g.setColor(Color.WHITE);
        g.drawLine(x, y1, x, y2);
        g.drawLine(x, y1, x + 1, y1);

        g.setColor(Color.DARK_GRAY);
        g.drawLine(x, y2, x + 1, y2);
        g.drawLine(x + 1, y1 + 1, x + 1, y2);
      } else {
        int y = ins.top + insets.top - KNOB_SIZE + 3;
        int x1 = ins.left + insets.left + 3;
        int x2 = w - insets.right - ins.right - 4;

        g.setColor(Color.WHITE);
        g.drawLine(x1, y, x2, y);
        g.drawLine(x1, y, x1, y + 1);

        g.setColor(Color.DARK_GRAY);
        g.drawLine(x1 + 1, y + 1, x2, y + 1);
        g.drawLine(x2, y, x2, y + 1);
      }
    }
  }
  public void paint(Graphics g, JComponent c) {
    boolean hasFocus = comboBox.hasFocus();
    Rectangle r;

    if (comboBox.isEnabled()) {
      g.setColor(comboBox.getBackground());
    } else {
      g.setColor(UIManager.getColor("ComboBox.disabledBackground"));
    }
    g.fillRect(0, 0, c.getWidth(), c.getHeight());

    if (!comboBox.isEditable()) {
      r = rectangleForCurrentValue();
      paintCurrentValue(g, r, hasFocus);
    }
    r = rectangleForArrowIcon();
    arrowIcon.paintIcon(c, g, r.x, r.y);
    if (!comboBox.isEditable()) {
      Border border = comboBox.getBorder();
      Insets in;
      if (border != null) {
        in = border.getBorderInsets(comboBox);
      } else {
        in = new Insets(0, 0, 0, 0);
      }
      // Draw the separation
      if (MotifGraphicsUtils.isLeftToRight(comboBox)) {
        r.x -= (HORIZ_MARGIN + 2);
      } else {
        r.x += r.width + HORIZ_MARGIN + 1;
      }
      r.y = in.top;
      r.width = 1;
      r.height = comboBox.getBounds().height - in.bottom - in.top;
      g.setColor(UIManager.getColor("controlShadow"));
      g.fillRect(r.x, r.y, r.width, r.height);
      r.x++;
      g.setColor(UIManager.getColor("controlHighlight"));
      g.fillRect(r.x, r.y, r.width, r.height);
    }
  }
Exemple #24
0
 public void paint(Graphics g, JComponent c) {
   boolean horizontal = true;
   if (c instanceof JSeparator) {
     horizontal = (((JSeparator) c).getOrientation() == JSeparator.HORIZONTAL);
   }
   if (horizontal) {
     int w = c.getWidth();
     g.setColor(AbstractLookAndFeel.getBackgroundColor());
     g.drawLine(0, 0, w, 0);
     g.setColor(ColorHelper.darker(AbstractLookAndFeel.getBackgroundColor(), 30));
     g.drawLine(0, 1, w, 1);
     g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getBackgroundColor(), 50));
     g.drawLine(0, 2, w, 2);
   } else {
     int h = c.getHeight();
     g.setColor(ColorHelper.darker(AbstractLookAndFeel.getBackgroundColor(), 30));
     g.drawLine(0, 0, 0, h);
     g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getBackgroundColor(), 50));
     g.drawLine(1, 0, 1, h);
   }
 }
  @Override
  public void paint(Graphics g, JComponent c) {

    String style = (String) c.getClientProperty("Quaqua.Button.style");
    if (style != null && style.equals("help")) {
      Insets insets = c.getInsets();
      UIManager.getIcon("Button.helpIcon").paintIcon(c, g, insets.left, insets.top);
      return;
    }

    Object oldHints = QuaquaUtilities.beginGraphics((Graphics2D) g);
    if (((AbstractButton) c).isBorderPainted()) {
      Border b = c.getBorder();
      if (b != null && b instanceof BackgroundBorder) {
        ((BackgroundBorder) b)
            .getBackgroundBorder()
            .paintBorder(c, g, 0, 0, c.getWidth(), c.getHeight());
      }
    }
    super.paint(g, c);
    QuaquaUtilities.endGraphics((Graphics2D) g, oldHints);
    Debug.paint(g, c, this);
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paint(java.awt.Graphics
   * , javax.swing.JComponent)
   */
  @Override
  public void paint(Graphics g, JComponent c) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setFont(
        FlamingoUtilities.getFont(this.commandButton, "Ribbon.font", "Button.font", "Panel.font"));

    this.layoutInfo = this.layoutManager.getLayoutInfo(this.commandButton, g);
    commandButton.putClientProperty("icon.bounds", layoutInfo.iconRect);
    commandButton.putClientProperty("icon", commandButton.getIcon());

    if (this.isPaintingBackground()) {
      this.paintButtonBackground(g2d, new Rectangle(0, 0, c.getWidth(), c.getHeight()));
    }

    // decide which command button model should be used to
    // compute the foreground color of the command button's text
    boolean useActionAreaForFg = layoutInfo.isTextInActionArea;
    StateTransitionTracker transitionTrackerForFg =
        useActionAreaForFg ? this.getActionTransitionTracker() : this.getPopupTransitionTracker();
    ModelStateInfo modelStateInfoForFg = transitionTrackerForFg.getModelStateInfo();
    ComponentState currStateForFg = modelStateInfoForFg.getCurrModelState();
    Color fgColor = this.commandButton.getForeground();

    if (fgColor instanceof UIResource) {
      float buttonAlpha =
          SubstanceColorSchemeUtilities.getAlpha(this.commandButton, currStateForFg);
      fgColor =
          SubstanceTextUtilities.getForegroundColor(
              this.commandButton, this.commandButton.getText(), modelStateInfoForFg, buttonAlpha);
    }

    if (layoutInfo.textLayoutInfoList != null) {
      for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo :
          layoutInfo.textLayoutInfoList) {
        if (mainTextLayoutInfo.text != null) {
          SubstanceTextUtilities.paintText(
              g2d,
              c,
              mainTextLayoutInfo.textRect,
              mainTextLayoutInfo.text,
              -1,
              g2d.getFont(),
              fgColor,
              g2d.getClipBounds());
        }
      }
    }

    if (layoutInfo.extraTextLayoutInfoList != null) {
      Color disabledFgColor =
          SubstanceColorSchemeUtilities.getColorScheme(
                  this.commandButton, ComponentState.DISABLED_UNSELECTED)
              .getForegroundColor();
      float buttonAlpha =
          SubstanceColorSchemeUtilities.getAlpha(
              this.commandButton, ComponentState.DISABLED_UNSELECTED);
      if (buttonAlpha < 1.0f) {
        Color bgFillColor = SubstanceColorUtilities.getBackgroundFillColor(this.commandButton);
        disabledFgColor =
            SubstanceColorUtilities.getInterpolatedColor(disabledFgColor, bgFillColor, buttonAlpha);
      }
      if (currStateForFg.isDisabled()) {
        disabledFgColor =
            SubstanceColorUtilities.getInterpolatedColor(
                disabledFgColor, SubstanceColorUtilities.getBackgroundFillColor(c), 0.5);
      }
      for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo :
          layoutInfo.extraTextLayoutInfoList) {
        if (extraTextLayoutInfo.text != null) {
          SubstanceTextUtilities.paintText(
              g2d,
              c,
              extraTextLayoutInfo.textRect,
              extraTextLayoutInfo.text,
              -1,
              g2d.getFont(),
              disabledFgColor,
              g2d.getClipBounds());
        }
      }
    }

    if (layoutInfo.iconRect != null) {
      this.paintButtonIcon(g2d, layoutInfo.iconRect);
    }
    if (layoutInfo.popupActionRect.getWidth() > 0) {
      paintPopupActionIcon(g2d, layoutInfo.popupActionRect);
    }

    if (this.isPaintingSeparators() && (layoutInfo.separatorArea != null)) {
      if (layoutInfo.separatorOrientation == CommandButtonSeparatorOrientation.HORIZONTAL) {
        this.paintButtonHorizontalSeparator(g2d, layoutInfo.separatorArea);
      } else {
        this.paintButtonVerticalSeparator(g2d, layoutInfo.separatorArea);
      }
    }

    // g2d.setColor(Color.red);
    // g2d.draw(layoutInfo.iconRect);
    // g2d.setColor(Color.blue);
    // if (layoutInfo.textLayoutInfoList != null) {
    // for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo :
    // layoutInfo.textLayoutInfoList) {
    // if (mainTextLayoutInfo.text != null) {
    // g2d.draw(mainTextLayoutInfo.textRect);
    // }
    // }
    // }
    // g2d.setColor(Color.magenta);
    // if (layoutInfo.extraTextLayoutInfoList != null) {
    // for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo :
    // layoutInfo.extraTextLayoutInfoList) {
    // if (extraTextLayoutInfo.text != null) {
    // g2d.draw(extraTextLayoutInfo.textRect);
    // }
    // }
    // }
    // g2d.setColor(Color.green);
    // g2d.draw(layoutInfo.popupActionRect);

    g2d.dispose();
  }
Exemple #27
0
 public void update(Graphics g, JComponent c) {
   paintBackground(g, c, 0, 0, c.getWidth(), c.getHeight());
   paint(g, c);
 }
 void paintBackground(SynthContext context, Graphics g, JComponent c) {
   context
       .getPainter()
       .paintPasswordFieldBackground(context, g, 0, 0, c.getWidth(), c.getHeight());
 }
 void paintBackground(SynthContext context, Graphics g, JComponent c) {
   context.getPainter().paintEditorPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight());
 }
  public void paint(final Graphics g, final JComponent c) {
    final AnchoredButton button = (AnchoredButton) c;

    final String text = button.getText();
    final Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    final FontMetrics fm = button.getFontMetrics(button.getFont());
    ourViewInsets = c.getInsets(ourViewInsets);

    ourViewRect.x = ourViewInsets.left;
    ourViewRect.y = ourViewInsets.top;

    final ToolWindowAnchor anchor = button.getAnchor();

    // Use inverted height & width
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      ourViewRect.height = c.getWidth() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getHeight() - (ourViewInsets.top + ourViewInsets.bottom);
    } else {
      ourViewRect.height = c.getHeight() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getWidth() - (ourViewInsets.top + ourViewInsets.bottom);
    }

    ourIconRect.x = ourIconRect.y = ourIconRect.width = ourIconRect.height = 0;
    ourTextRect.x = ourTextRect.y = ourTextRect.width = ourTextRect.height = 0;

    final String clippedText =
        SwingUtilities.layoutCompoundLabel(
            c,
            fm,
            text,
            icon,
            button.getVerticalAlignment(),
            button.getHorizontalAlignment(),
            button.getVerticalTextPosition(),
            button.getHorizontalTextPosition(),
            ourViewRect,
            ourIconRect,
            ourTextRect,
            button.getText() == null ? 0 : button.getIconTextGap());

    // Paint button's background

    final Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    final ButtonModel model = button.getModel();

    final Color background = button.getBackground();

    Color toBorder = model.isRollover() ? new Color(0, 0, 0, 50) : null;
    final boolean vertical = anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT;

    if (model.isArmed() && model.isPressed() || model.isSelected()) {
      g2.setColor(new Color(0, 0, 0, 30));
      g2.fillRect(3, 3, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);

      g2.setColor(new Color(0, 0, 0, 120));
      g2.drawLine(2, 2, 3 + button.getWidth() - (vertical ? 7 : 6), 2);
      g2.drawLine(2, 3, 2, 3 + button.getHeight() - 7);

      g2.setColor(new Color(0, 0, 0, 40));
      g2.drawRect(3, 3, button.getWidth() - (vertical ? 7 : 6), button.getHeight() - 7);

      g2.setColor(new Color(255, 255, 255, 110));
      g2.drawLine(
          3,
          button.getHeight() - 3,
          3 + button.getWidth() - (vertical ? 6 : 5),
          button.getHeight() - 3);
      g2.drawLine(
          3 + button.getWidth() - (vertical ? 6 : 5),
          2,
          3 + button.getWidth() - (vertical ? 6 : 5),
          3 + button.getHeight() - 7);

      toBorder = null;
    }

    if (toBorder != null) {
      g.setColor(toBorder);
      g.drawRect(2, 2, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);
    }

    AffineTransform tr = null;
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      tr = g2.getTransform();
      if (ToolWindowAnchor.RIGHT == anchor) {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(c, g2, ourIconRect.y, ourIconRect.x);
        }
        g2.rotate(Math.PI / 2);
        g2.translate(0, -c.getWidth());
      } else {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(
              c, g2, ourIconRect.y, c.getHeight() - ourIconRect.x - icon.getIconHeight());
        }
        g2.rotate(-Math.PI / 2);
        g2.translate(-c.getHeight(), 0);
      }
    } else {
      if (icon != null) {
        icon.paintIcon(c, g2, ourIconRect.x, ourIconRect.y);
      }
    }

    // paint text

    if (text != null) {
      if (model.isEnabled()) {
        if (model.isArmed() && model.isPressed() || model.isSelected()) {
          g.setColor(background);
        } else {
          g.setColor(button.getForeground());
        }
      } else {
        g.setColor(background.darker());
      }
      /* Draw the Text */
      if (model.isEnabled()) {
        /** * paint the text normally */
        g.setColor(button.getForeground());
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      } else {
        /** * paint the text disabled ** */
        if (model.isSelected()) {
          g.setColor(c.getBackground());
        } else {
          g.setColor(getDisabledTextColor());
        }
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      }
    }
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      g2.setTransform(tr);
    }
  }