예제 #1
0
  public void paintText(Graphics2D g, ButtonInfo info) {
    ButtonModel model = info.button.getModel();
    FontMetrics fm = info.button.getFontMetrics(info.button.getFont());
    int mnemonicIndex = info.button.getDisplayedMnemonicIndex();
    String text = info.button.getText();
    int textShiftOffset = 0;

    g.setComposite(AlphaComposite.SrcOver);
    /* Draw the Text */
    if (isEnabled(info.button)) {
      /** * paint the text normally */
      g.setColor(info.button.getForeground());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          info.textRect.x + textShiftOffset,
          info.textRect.y + fm.getAscent() + textShiftOffset);
    } else {
      /** * paint the text disabled ** */
      g.setColor(info.button.getBackground().brighter());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, info.textRect.x, info.textRect.y + fm.getAscent());
      g.setColor(info.button.getBackground().darker());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, info.textRect.x - 1, info.textRect.y + fm.getAscent() - 1);
    }
  }
 public static void drawStringUnderlineCharAt(
     JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) {
   Graphics2D g2D = (Graphics2D) g;
   Object savedRenderingHint = null;
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
     g2D.setRenderingHint(
         RenderingHints.KEY_TEXT_ANTIALIASING,
         AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
   }
   if (getJavaVersion() >= 1.6) {
     try {
       Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2");
       Class classParams[] = {
         JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE
       };
       Method m = swingUtilities2Class.getMethod("drawStringUnderlineCharAt", classParams);
       Object methodParams[] = {
         c, g, text, new Integer(underlinedIndex), new Integer(x), new Integer(y)
       };
       m.invoke(null, methodParams);
     } catch (Exception ex) {
       BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
     }
   } else if (getJavaVersion() >= 1.4) {
     BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, underlinedIndex, x, y);
   } else {
     BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
   }
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
   }
 }
예제 #3
0
 protected void drawString(Graphics g, String s, int accChar, int textX, int textY) {
   if (s.indexOf('\n') == -1) BasicGraphicsUtils.drawString(g, s, accChar, textX, textY);
   else {
     String[] strs = splitStringByLines(s);
     int height = g.getFontMetrics().getHeight();
     // Only the first line can have the accel char
     BasicGraphicsUtils.drawString(g, strs[0], accChar, textX, textY);
     for (int i = 1; i < strs.length; i++) g.drawString(strs[i], textX, textY + (height * i));
   }
 }
  /**
   * Renders a text String in Windows without the mnemonic. This is here because the WindowsUI
   * hiearchy doesn't match the Component heirarchy. All the overriden paintText methods of the
   * ButtonUI delegates will call this static method.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   */
  public static void paintText(
      Graphics g, AbstractButton b, Rectangle textRect, String text, int textShiftOffset) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();

    int mnemIndex = b.getDisplayedMnemonicIndex();
    // W2K Feature: Check to see if the Underscore should be rendered.
    if (WindowsLookAndFeel.isMnemonicHidden() == true) {
      mnemIndex = -1;
    }

    /* Draw the Text */
    Color color = b.getForeground();
    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(color);
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemIndex,
          textRect.x + textShiftOffset,
          textRect.y + fm.getAscent() + textShiftOffset);
    } else {
        /** * paint the text disabled ** */
      color = UIManager.getColor("Button.disabledForeground");
      Color shadow = UIManager.getColor("Button.disabledShadow");

      XPStyle xp = XPStyle.getXP();
      if (xp != null) {
        color = xp.getColor("button.pushbutton(disabled).textcolor", color);
      } else {
        // Paint shadow only if not XP
        if (shadow == null) {
          shadow = b.getBackground().darker();
        }
        g.setColor(shadow);
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
      }
      if (color == null) {
        color = b.getBackground().brighter();
      }
      g.setColor(color);
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
예제 #5
0
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   if (comp.hasFocus() || focusLostTemporarily) {
     Color color = g.getColor();
     g.setColor(focusColor);
     BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
     g.setColor(color);
   }
 }
예제 #6
0
 @Override
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.translate(x, y);
   g2.setPaint(borderSelectionColor);
   g2.drawRect(0, 0, w - 1, h - 1);
   g2.setPaint(getLineColor());
   BasicGraphicsUtils.drawDashedRect(g2, 0, 0, w, h);
   g2.dispose();
 }
예제 #7
0
  protected void paintText(
      Graphics g,
      int tabPlacement,
      Font font,
      FontMetrics metrics,
      int tabIndex,
      String title,
      Rectangle textRect,
      boolean isSelected) {

    g.setFont(font);

    View v = getTextViewForTab(tabIndex);
    if (v != null) {
      // html
      v.paint(g, textRect);
    } else {
      // plain text
      int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

      if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
        if (isSelected) {
          Graphics2D g2d = (Graphics2D) g;
          g2d.setColor(nearBlack);
          g2d.drawString(title, textRect.x + 1, textRect.y + metrics.getAscent() + 1);
          g.setColor(whiteColor);
        } else g.setColor(tabPane.getForegroundAt(tabIndex));

        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());

      } else { // tabbedpanel2 disabled
        g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
        g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
      }
    }
  }
예제 #8
0
 protected void paintFocus(
     Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
   Graphics2D g2D = (Graphics2D) g;
   int width = b.getWidth();
   int height = b.getHeight();
   if (((width < 64) || (height < 16)) && ((b.getText() == null) || b.getText().length() == 0)) {
     g.setColor(AbstractLookAndFeel.getFocusColor());
     BasicGraphicsUtils.drawDashedRect(g, 4, 3, width - 8, height - 6);
   } else {
     Object savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
     g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     g2D.setColor(AbstractLookAndFeel.getFocusColor());
     int d = b.getHeight() - 4;
     g2D.drawRoundRect(2, 2, b.getWidth() - 5, b.getHeight() - 5, d, d);
     g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRenderingHint);
   }
 }
예제 #9
0
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setFont(getFont());
    FontMetrics fm = g2.getFontMetrics();

    Color iconC = getBackground();
    g2.setPaint(iconC);

    boolean filled =
        (model.isRollover() || model.isSelected() || model.isPressed() || isFocusOwner());

    if (filled) {
      Color cb = getBackground().brighter().brighter();
      Color ct = cb.brighter();

      if (model.isPressed() || model.isSelected() || isFocusOwner()) {
        ct = getBackground().brighter().brighter();
        cb = getBackground().brighter();
      }

      g2.setPaint(new GradientPaint(0, 0, ct, 0, getHeight(), cb));

      g2.fill(new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), getHeight(), getHeight()));

    } else {
      iconC = getBackground().brighter();
    }

    int iconw = fm.getHeight() * 2;
    int iconh = iconw;

    int mgn = (getHeight() - iconh) / 2;

    if (getIcon() != null) {
      iconw = getIcon().getIconWidth();
      iconh = getIcon().getIconHeight();

      mgn = (getHeight() - iconh) / 2;
      getIcon().paintIcon(this, g2, mgn, mgn);
      g2.setStroke(new BasicStroke(2));
      if (filled) {
        g2.draw(new Ellipse2D.Double(mgn, mgn, iconw, iconh));
      }

    } else {
      g2.setPaint(iconC);
      g2.fill(new Ellipse2D.Double(mgn, mgn, iconw, iconh));
    }

    g2.setPaint(getForeground());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    if (getText() != null && getText().length() > 0) {
      String[] sl = getText().split(System.getProperty("line.separator"));
      int l = iconw + mgn * 2;
      int w = getWidth() - l - mgn;
      int t = getHeight() / 2 - sl.length * fm.getHeight() / 2 + fm.getAscent();
      for (int i = 0; i < sl.length; i++) {
        int sw = 0;
        switch (getHorizontalAlignment()) {
          case JButton.RIGHT:
            sw = w - fm.stringWidth(sl[i]);
            break;
          case JButton.CENTER:
            sw = w / 2 - fm.stringWidth(sl[i]) / 2;
            break;
        }
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g2, sl[i], getDisplayedMnemonicIndex(), l + sw, t + i * fm.getHeight());
        //        g2.drawString(sl[i], l + sw, t + i * fm.getHeight());
      }
    }
  }
예제 #10
0
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    int lx = 10;
    super.paint(g);
    long time = System.currentTimeMillis();
    if (mapImage != null) {
      mapImage.paintIcon(this, g, 0, 0);
    }
    MapNode[] nodes = nodeList;
    if (nodes != null) {
      Line2D line = new Line2D.Double();
      for (int i = 0, m = nodes.length; i < m; i++) {
        MapNode n = nodes[i];
        int x, y;
        if (n.node.hasLocation()) {
          x = n.node.getX();
          y = n.node.getY();
        } else {
          x = lx;
          y = 10;
          lx += 30;
        }

        if (!hideNetwork) {
          FontMetrics fm = g.getFontMetrics();
          int fnHeight = fm.getHeight();
          int fnDescent = fm.getDescent();
          for (int j = 0, mu = n.node.getLinkCount(); j < mu; j++) {
            Link link = n.node.getLink(j);
            if (link.node.hasLocation()) {
              long age = (time - link.getLastActive()) / 100;
              int x2 = link.node.getX();
              int y2 = link.node.getY();
              if (n.isSelected) {
                if (age > LINK_COLOR.length) {
                  age = 100;
                } else {
                  age -= 50;
                }
              }
              line.setLine(x, y, x2, y2);
              if (age < LINK_COLOR.length) {
                g.setColor(age < 0 ? LINK_COLOR[0] : LINK_COLOR[(int) age]);
              } else {
                g.setColor(LINK_COLOR[LINK_COLOR.length - 1]);
              }
              g2d.draw(line);
              //              g.setColor(Color.lightGray);
              int xn1, xn2, yn1, yn2;
              if (x <= x2) {
                xn1 = x;
                xn2 = x2;
                yn1 = y;
                yn2 = y2;
              } else {
                xn1 = x2;
                xn2 = x;
                yn1 = y2;
                yn2 = y;
              }
              int dx = xn1 + (xn2 - xn1) / 2 + 4;
              int dy = yn1 + (yn2 - yn1) / 2 - fnDescent;
              if (yn2 < yn1) {
                dy += fnHeight - fnDescent;
              }
              g.drawString("ETX:" + (((int) (link.getETX() * 100 + 0.5)) / 100.0), dx, dy);
            }
          }
        }

        n.paint(g, x, y);

        g.setColor(Color.black);
        if (n.isSelected) {
          BasicGraphicsUtils.drawDashedRect(g, x - delta, y - delta, 2 * delta, 2 * delta);
        }
        if (selectedNode != null && selectedNode.message != null) {
          g.drawString(selectedNode.message, 10, 10);
        }
      }
    }
  }
예제 #11
0
  /**
   * Paints the track along which the thumb control moves.
   *
   * @param g the graphics device.
   */
  public void paintTrack(Graphics g) {
    Color shadowColor = MetalLookAndFeel.getControlShadow();
    if (slider.getOrientation() == JSlider.HORIZONTAL) {
      int trackX = trackRect.x;
      int trackY = trackRect.y + (trackRect.height - getTrackWidth()) / 2;
      int trackW = trackRect.width;
      int trackH = getTrackWidth();

      // draw border
      if (slider.isEnabled())
        BasicGraphicsUtils.drawEtchedRect(
            g,
            trackX,
            trackY,
            trackW,
            trackH,
            darkShadowColor,
            shadowColor,
            darkShadowColor,
            highlightColor);
      else {
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.drawRect(trackX, trackY, trackW - 2, trackH - 2);
      }

      // fill track (if required)
      if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) {
        if (slider.isEnabled()) {
          int xPos = xPositionForValue(slider.getValue());
          int x = slider.getInverted() ? xPos : trackRect.x;
          int w = slider.getInverted() ? trackX + trackW - xPos : xPos - trackRect.x;
          g.setColor(MetalLookAndFeel.getWhite());
          g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1);
          g.setColor(UIManager.getColor("Slider.altTrackColor"));
          g.drawLine(x + 1, trackY + 2, x + w - 3, trackY + 2);
          g.setColor(MetalLookAndFeel.getControlShadow());
          g.drawLine(x + 1, trackY + 3, x + w - 3, trackY + 3);
          g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
          g.drawLine(x + 1, trackY + 4, x + w - 3, trackY + 4);
        }
      } else if (filledSlider) {
        int xPos = xPositionForValue(slider.getValue());
        int x = slider.getInverted() ? xPos : trackRect.x;
        int w = slider.getInverted() ? trackX + trackW - xPos : xPos - trackRect.x;
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.fillRect(x + 1, trackY + 1, w - 3, getTrackWidth() - 3);
        if (slider.isEnabled()) {
          g.setColor(MetalLookAndFeel.getControl());
          g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1);
          g.drawLine(x + 1, trackY + 1, x + 1, trackY + getTrackWidth() - 3);
        }
      }
    } else {
      int trackX = trackRect.x + (trackRect.width - getTrackWidth()) / 2;
      int trackY = trackRect.y;
      int trackW = getTrackWidth();
      int trackH = trackRect.height;
      if (slider.isEnabled())
        BasicGraphicsUtils.drawEtchedRect(
            g,
            trackX,
            trackY,
            trackW,
            trackH,
            darkShadowColor,
            shadowColor,
            darkShadowColor,
            highlightColor);
      else {
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.drawRect(trackX, trackY, trackW - 2, trackH - 2);
      }

      // Fill track if necessary.
      if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) {
        if (slider.isEnabled()) {
          int yPos = yPositionForValue(slider.getValue());
          int y = slider.getInverted() ? trackY : yPos;
          int h = slider.getInverted() ? yPos - trackY : trackY + trackH - yPos;

          g.setColor(MetalLookAndFeel.getWhite());
          g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3);
          g.setColor(UIManager.getColor("Slider.altTrackColor"));
          g.drawLine(trackX + 2, y + 1, trackX + 2, y + h - 3);
          g.setColor(MetalLookAndFeel.getControlShadow());
          g.drawLine(trackX + 3, y + 1, trackX + 3, y + h - 3);
          g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
          g.drawLine(trackX + 4, y + 1, trackX + 4, y + h - 3);
        }
      } else if (filledSlider) {
        int yPos = yPositionForValue(slider.getValue());
        int y = slider.getInverted() ? trackY : yPos;
        int h = slider.getInverted() ? yPos - trackY : trackY + trackH - yPos;
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.fillRect(trackX + 1, y + 1, getTrackWidth() - 3, h - 3);
        if (slider.isEnabled()) {
          g.setColor(MetalLookAndFeel.getControl());
          g.drawLine(trackX + 1, y + 1, trackX + trackW - 3, y + 1);
          g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3);
        }
      }
    }
  }
  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);
    }
  }
  @Override
  protected void paintText(
      Graphics g,
      int tabPlacement,
      Font font,
      FontMetrics metrics,
      int tabIndex,
      String title,
      Rectangle textRect,
      boolean isSelected) {
    g.setFont(font);

    int titleWidth = SwingUtilities.computeStringWidth(metrics, title);

    int preferredWidth = 0;
    if (isOneActionButtonEnabled()) {
      preferredWidth = calculateTabWidth(tabPlacement, tabIndex, metrics) - WIDTHDELTA - 15;

      if (isCloseEnabled()) preferredWidth -= BUTTONSIZE;

      if (isMaxEnabled()) preferredWidth -= BUTTONSIZE;
    } else {
      preferredWidth = titleWidth;
    }

    while (titleWidth > preferredWidth) {
      if (title.endsWith("...")) title = title.substring(0, title.indexOf("...") - 1).concat("...");
      else title = title.substring(0, title.length() - 4).concat("...");

      titleWidth = SwingUtilities.computeStringWidth(metrics, title);
    }

    textRect.width = titleWidth;

    View v = getTextViewForTab(tabIndex);
    if (v != null) {
      // html
      v.paint(g, textRect);
    } else {
      // plain text
      int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

      if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
        if (isSelected) g.setColor(TAB_SELECTED_FOREGROUND_COLOR);
        else {
          if (this.isTabHighlighted(tabIndex)) {
            g.setColor(TAB_HIGHLIGHT_FOREGROUND_COLOR);
          } else g.setColor(tabPane.getForegroundAt(tabIndex));
        }

        BasicGraphicsUtils.drawString(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
      } else { // tab disabled
        g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());

        g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
      }
    }
  }
예제 #14
0
 public void paint(Graphics g, JComponent comp) {
   UIUtil.applyRenderingHints(g);
   JMenu jMenu = (JMenu) comp;
   ButtonModel buttonmodel = jMenu.getModel();
   int mnemonicIndex = jMenu.getDisplayedMnemonicIndex();
   Icon icon = getIcon();
   Icon allowedIcon = getAllowedIcon();
   Insets insets = comp.getInsets();
   resetRects();
   ourViewRect.setBounds(0, 0, jMenu.getWidth(), jMenu.getHeight());
   ourViewRect.x += insets.left;
   ourViewRect.y += insets.top;
   ourViewRect.width -= insets.right + ourViewRect.x;
   ourViewRect.height -= insets.bottom + ourViewRect.y;
   Font font = g.getFont();
   Font font1 = comp.getFont();
   g.setFont(font1);
   FontMetrics fontmetrics = g.getFontMetrics(font1);
   String s1 =
       layoutMenuItem(
           fontmetrics,
           jMenu.getText(),
           icon,
           allowedIcon,
           arrowIcon,
           jMenu.getVerticalAlignment(),
           jMenu.getHorizontalAlignment(),
           jMenu.getVerticalTextPosition(),
           jMenu.getHorizontalTextPosition(),
           ourViewRect,
           ourIconRect,
           ourTextRect,
           ourAcceleratorRect,
           ourCheckIconRect,
           ourArrowIconRect,
           jMenu.getText() != null ? defaultTextIconGap : 0,
           defaultTextIconGap);
   Color color2 = g.getColor();
   if (comp.isOpaque()) {
     g.setColor(jMenu.getBackground());
     g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight());
     if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
       if (UIUtil.isUnderAquaLookAndFeel()) {
         myAquaSelectedBackgroundPainter.paintBorder(
             comp, g, 0, 0, jMenu.getWidth(), jMenu.getHeight());
       } else {
         g.setColor(selectionBackground);
         if (allowedIcon != null) {
           g.fillRect(k, 0, jMenu.getWidth() - k, jMenu.getHeight());
         } else {
           g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight());
           g.setColor(selectionBackground);
         }
       }
     }
     g.setColor(color2);
   }
   if (allowedIcon != null) {
     if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
       g.setColor(selectionForeground);
     } else {
       g.setColor(jMenu.getForeground());
     }
     if (useCheckAndArrow()) {
       allowedIcon.paintIcon(comp, g, ourCheckIconRect.x, ourCheckIconRect.y);
     }
     g.setColor(color2);
     if (menuItem.isArmed()) {
       drawIconBorder(g);
     }
   }
   if (icon != null) {
     if (!buttonmodel.isEnabled()) {
       icon = jMenu.getDisabledIcon();
     } else if (buttonmodel.isPressed() && buttonmodel.isArmed()) {
       icon = jMenu.getPressedIcon();
       if (icon == null) {
         icon = jMenu.getIcon();
       }
     }
     if (icon != null) {
       icon.paintIcon(comp, g, ourIconRect.x, ourIconRect.y);
     }
   }
   if (s1 != null && s1.length() > 0) {
     if (buttonmodel.isEnabled()) {
       if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
         g.setColor(selectionForeground);
       } else {
         g.setColor(jMenu.getForeground());
       }
       BasicGraphicsUtils.drawStringUnderlineCharAt(
           g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent());
     } else {
       final Object disabledForeground = UIUtil.getMenuItemDisabledForeground();
       if (disabledForeground instanceof Color) {
         g.setColor((Color) disabledForeground);
         BasicGraphicsUtils.drawStringUnderlineCharAt(
             g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent());
       } else {
         g.setColor(jMenu.getBackground().brighter());
         BasicGraphicsUtils.drawStringUnderlineCharAt(
             g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent());
         g.setColor(jMenu.getBackground().darker());
         BasicGraphicsUtils.drawStringUnderlineCharAt(
             g,
             s1,
             mnemonicIndex,
             ourTextRect.x - 1,
             (ourTextRect.y + fontmetrics.getAscent()) - 1);
       }
     }
   }
   if (arrowIcon != null) {
     if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
       g.setColor(selectionForeground);
     }
     if (useCheckAndArrow()) {
       try {
         if (SystemInfo.isMac
             && myAquaInvertedArrowIcon != null
             && (buttonmodel.isArmed() || buttonmodel.isSelected())
             && UIUtil.isUnderAquaLookAndFeel()) {
           myAquaInvertedArrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y);
         } else if (SystemInfo.isMac
             && myAquaDisabledArrowIcon != null
             && !buttonmodel.isEnabled()
             && UIUtil.isUnderAquaLookAndFeel()) {
           myAquaDisabledArrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y);
         } else arrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y);
       } catch (NullPointerException npe) {
         // GTKIconFactory$MenuArrowIcon.paintIcon since it doesn't expect to be given a null
         // instead of SynthContext
         // http://www.jetbrains.net/jira/browse/IDEADEV-22360
       }
     }
   }
   g.setColor(color2);
   g.setFont(font);
 }