Exemplo n.º 1
0
 void drawCenteredString(Graphics2D g2d, String string, int x0, int y0, float angle) {
   FontRenderContext frc = g2d.getFontRenderContext();
   Rectangle2D bounds = g2d.getFont().getStringBounds(string, frc);
   LineMetrics metrics = g2d.getFont().getLineMetrics(string, frc);
   if (angle == 0) {
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
   } else {
     g2d.rotate(angle, x0, y0);
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
     g2d.rotate(-angle, x0, y0);
   }
 }
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g.create();

    int width = getWidth();
    int height = getHeight();

    // rendering hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // formatter
    DecimalFormat format = new DecimalFormat("##.#%");
    // text to display
    String percentage =
        (value == null || Double.parseDouble(value.toString()) == -1)
            ? ""
            : format.format(Double.parseDouble(value.toString()));

    // paint text
    g2.setColor(Color.black);
    g2.setFont(g2.getFont().deriveFont(Font.BOLD));
    FontMetrics fontMetrics = g2.getFontMetrics();
    int textWidth = fontMetrics.stringWidth(percentage);
    int xPos = (width - textWidth) / 2;
    int yPos = height / 2 + fontMetrics.getDescent() + 2;
    g2.drawString(percentage, xPos, yPos);

    g2.dispose();
  }
Exemplo n.º 3
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
 private void doDrawString(Graphics2D g, int fragmentIndex, int x, int y) {
   String text = myFragments.get(fragmentIndex);
   if (StringUtil.isEmpty(text)) return;
   TextLayout layout = getTextLayout(fragmentIndex, g.getFont(), g.getFontRenderContext());
   if (layout != null) {
     layout.draw(g, x, y);
   } else {
     g.drawString(text, x, y);
   }
 }
 /**
  * Drawer : draw the variable label of the component.
  *
  * @param g Graphics2D of the component (casted from getGraphics).
  * @param x x-cordinates of the label
  * @param y y-cordinates of the label
  * @param theta rotation (radians) of the label
  * @param label Drawn String.
  */
 private void drawString2(Graphics2D g, double x, double y, double theta, String label) {
   g.setPaint(grid);
   AffineTransform fontAT = new AffineTransform();
   Font theFont = g.getFont();
   fontAT.rotate(theta);
   Font theDerivedFont = theFont.deriveFont(fontAT);
   g.setFont(theDerivedFont);
   g.drawString(label, (int) x, (int) y);
   g.setFont(theFont);
 }
  /** Part of print code coped from Sun */
  public void printTablePart(Graphics2D g2, PageFormat pageFormat, int rowIndex, int columnIndex) {

    String pageNumber = "Page: " + (rowIndex + 1);
    if (subTableSplitSize > 1) {
      pageNumber += "-" + (columnIndex + 1);
    }

    int pageLeft = subTableSplit[columnIndex];
    int pageRight = subTableSplit[columnIndex + 1];

    int pageWidth = pageRight - pageLeft;

    // page number message (in smaller type)
    g2.setFont(new Font(g2.getFont().getName(), g2.getFont().getStyle(), 8));
    g2.drawString(pageNumber, pageWidth / 2 - 35, (int) (pageHeight - fontHeight));

    double clipHeight =
        Math.min(tableHeightOnFullPage, tableHeight - rowIndex * tableHeightOnFullPage);

    g2.translate(-subTableSplit[columnIndex], 0);
    g2.setClip(pageLeft, 0, pageWidth, (int) headerHeight);

    g2.scale(scale, scale);
    tableHeader.paint(g2); // draw the header on every page
    g2.scale(1 / scale, 1 / scale);
    g2.translate(0, headerHeight);
    g2.translate(0, -tableHeightOnFullPage * rowIndex);

    // cut table image and draw on the page

    g2.setClip(pageLeft, (int) tableHeightOnFullPage * rowIndex, pageWidth, (int) clipHeight);
    g2.scale(scale, scale);
    _table.paint(g2);
    g2.scale(1 / scale, 1 / scale);

    double pageTop = tableHeightOnFullPage * rowIndex - headerHeight;
    //		double pageBottom = pageTop +  clipHeight + headerHeight;
    g2.drawRect(pageLeft, (int) pageTop, pageWidth, (int) (clipHeight + headerHeight));
  }
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   int w = getWidth();
   int h = getHeight();
   // Draw ordinate.
   g2.draw(new Line2D.Double(Points, Points, Points, h - Points));
   // Draw abcissa.
   g2.draw(new Line2D.Double(Points, h - Points, w - Points, h - Points));
   // Draw labels.
   Font font = g2.getFont();
   FontRenderContext frc = g2.getFontRenderContext();
   LineMetrics lm = font.getLineMetrics("0", frc);
   float sh = lm.getAscent() + lm.getDescent();
   // Ordinate label.
   String s = "Strecke";
   float sy = Points + ((h - 2 * Points) - s.length() * sh) / 2 + lm.getAscent();
   for (int i = 0; i < s.length(); i++) {
     String letter = String.valueOf(s.charAt(i));
     float sw = (float) font.getStringBounds(letter, frc).getWidth();
     float sx = (Points - sw) / 2;
     g2.drawString(letter, sx, sy);
     sy += sh;
   }
   // Abcissa label.
   s = "Datum";
   sy = h - Points + (Points - sh) / 2 + lm.getAscent();
   float sw = (float) font.getStringBounds(s, frc).getWidth();
   float sx = (w - sw) / 2;
   g2.drawString(s, sx, sy);
   // Draw lines.
   double xInc = (double) (w - 2 * Points) / (data.length - 1);
   double scale = (double) (h - 2 * Points) / getMax();
   g2.setPaint(Color.green.darker());
   for (int i = 0; i < data.length - 1; i++) {
     double x1 = Points + i * xInc;
     double y1 = h - Points - scale * data[i];
     double x2 = Points + (i + 1) * xInc;
     double y2 = h - Points - scale * data[i + 1];
     g2.draw(new Line2D.Double(x1, y1, x2, y2));
   }
   // Mark data points.
   g2.setPaint(Color.red);
   for (int i = 0; i < data.length; i++) {
     double x = Points + i * xInc;
     double y = h - Points - scale * data[i];
     g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
   }
 }
    @Override
    public void _setTextBadge(IdeFrame frame, String text) {
      if (!isValid(frame)) {
        return;
      }

      Object icon = null;

      if (text != null) {
        try {
          int size = 55;
          BufferedImage image = UIUtil.createImage(size, size, BufferedImage.TYPE_INT_ARGB);
          Graphics2D g = image.createGraphics();

          int roundSize = 40;
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setPaint(ERROR_COLOR);
          g.fillRoundRect(
              size / 2 - roundSize / 2, size / 2 - roundSize / 2, roundSize, roundSize, size, size);

          g.setColor(Color.white);
          Font font = g.getFont();
          g.setFont(new Font(font.getName(), font.getStyle(), 22));
          FontMetrics fontMetrics = g.getFontMetrics();
          int width = fontMetrics.stringWidth(text);
          g.drawString(
              text,
              size / 2 - width / 2,
              size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent());

          ByteArrayOutputStream bytes = new ByteArrayOutputStream();
          Sanselan.writeImage(image, bytes, ImageFormat.IMAGE_FORMAT_ICO, new HashMap());
          icon = Win7TaskBar.createIcon(bytes.toByteArray());
        } catch (Throwable e) {
          LOG.error(e);
        }
      }

      try {
        Win7TaskBar.setOverlayIcon(frame, icon, icon != null);
      } catch (Throwable e) {
        LOG.error(e);
      }
    }
Exemplo n.º 9
0
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(
       RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   Font font = g2.getFont();
   FontRenderContext frc = g2.getFontRenderContext();
   float y = PAD;
   for (int j = 0; j < data.length; j++) {
     for (int k = 0; k < data[j].length; k++) {
       String s = data[j][k];
       LineMetrics lm = font.getLineMetrics(s, frc);
       float x = PAD + offsets[j][k];
       y += lm.getAscent();
       g2.drawString(s, x, y);
       y += lm.getDescent();
     }
   }
 }
Exemplo n.º 10
0
  public void render(int w, int h, Graphics2D g2) {

    int w2 = w / 2;
    int h2 = h / 2;
    g2.setPaint(new GradientPaint(0, 0, outerC, w * .35f, h * .35f, innerC));
    g2.fillRect(0, 0, w2, h2);
    g2.setPaint(new GradientPaint(w, 0, outerC, w * .65f, h * .35f, innerC));
    g2.fillRect(w2, 0, w2, h2);
    g2.setPaint(new GradientPaint(0, h, outerC, w * .35f, h * .65f, innerC));
    g2.fillRect(0, h2, w2, h2);
    g2.setPaint(new GradientPaint(w, h, outerC, w * .65f, h * .65f, innerC));
    g2.fillRect(w2, h2, w2, h2);

    g2.setColor(Color.black);
    TextLayout tl = new TextLayout("GradientPaint", g2.getFont(), g2.getFontRenderContext());
    tl.draw(
        g2,
        (int) (w / 2 - tl.getBounds().getWidth() / 2),
        (int) (h / 2 + tl.getBounds().getHeight() / 2));
  }
Exemplo n.º 11
0
    public void paintLogo(Component c, Graphics g, int x, int y, int w, int h) {
      if (hasLogo(c)) {
        Graphics2D g2D = (Graphics2D) g;

        Font savedFont = g2D.getFont();
        g.setFont(logoFont);
        FontMetrics fm = JTattooUtilities.getFontMetrics((JComponent) c, g, c.getFont());
        String logo =
            JTattooUtilities.getClippedText(
                AbstractLookAndFeel.getTheme().getLogoString(), fm, h - 16);

        AffineTransform savedTransform = g2D.getTransform();

        Color fc = getLogoColorHi();
        Color bc = getLogoColorLo();

        if (JTattooUtilities.isLeftToRight(c)) {
          g2D.translate(fm.getAscent() + 1, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        } else {
          g2D.translate(w - shadowSize - 4, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        }

        g2D.setTransform(savedTransform);
        g2D.setFont(savedFont);
      }
    }
  /*
   * (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();
  }
Exemplo n.º 13
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    double xScale = (w - 2 * PAD) / (xMax - xMin);
    double yScale = (h - 2 * PAD) / (yMax - yMin);
    if (firstTime) System.out.printf("xScale = %.1f  yScale = %.1f%n", xScale, yScale);
    Point2D.Double origin = new Point2D.Double(); // Axes origin.
    Point2D.Double offset = new Point2D.Double(); // Locate data.
    if (xMax < 0) {
      origin.x = w - PAD;
      offset.x = origin.x - xScale * xMax;
    } else if (xMin < 0) {
      origin.x = PAD - xScale * xMin;
      offset.x = origin.x;
    } else {
      origin.x = PAD;
      offset.x = PAD - xScale * xMin;
    }
    if (yMax < 0) {
      origin.y = h - PAD;
      offset.y = origin.y - yScale * yMax;
    } else if (yMin < 0) {
      origin.y = PAD - yScale * yMin;
      offset.y = origin.y;
    } else {
      origin.y = PAD;
      offset.y = PAD - yScale * yMin;
    }
    if (firstTime) {
      System.out.printf("origin = [%6.1f, %6.1f]%n", origin.x, origin.y);
      System.out.printf("offset = [%6.1f, %6.1f]%n", offset.x, offset.y);
    }

    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, origin.y, w - PAD, origin.y));
    // Draw ordinate.
    g2.draw(new Line2D.Double(origin.x, PAD, origin.x, h - PAD));
    g2.setPaint(Color.red);
    // Mark origin.
    g2.fill(new Ellipse2D.Double(origin.x - 2, origin.y - 2, 4, 4));

    // Plot data.
    g2.setPaint(Color.blue);
    for (int i = 0; i < x.length; i++) {
      double x1 = offset.x + xScale * x[i];
      double y1 = offset.y + yScale * y[i];
      if (firstTime) System.out.printf("i = %d  x1 = %6.1f  y1 = %.1f%n", i, x1, y1);
      g2.fill(new Ellipse2D.Double(x1 - 2, y1 - 2, 4, 4));
      g2.drawString(String.valueOf(i), (float) x1 + 3, (float) y1 - 3);
    }

    // Draw extreme data values.
    g2.setPaint(Color.black);
    Font font = g2.getFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = font.getLineMetrics("0", frc);
    String s = String.format("%.1f", xMin);
    float width = (float) font.getStringBounds(s, frc).getWidth();
    double x = offset.x + xScale * xMin;
    g2.drawString(s, (float) x, (float) origin.y + lm.getAscent());
    s = String.format("%.1f", xMax);
    width = (float) font.getStringBounds(s, frc).getWidth();
    x = offset.x + xScale * xMax;
    g2.drawString(s, (float) x - width, (float) origin.y + lm.getAscent());
    s = String.format("%.1f", yMin);
    width = (float) font.getStringBounds(s, frc).getWidth();
    double y = offset.y + yScale * yMin;
    g2.drawString(s, (float) origin.x + 1, (float) y + lm.getAscent());
    s = String.format("%.1f", yMax);
    width = (float) font.getStringBounds(s, frc).getWidth();
    y = offset.y + yScale * yMax;
    g2.drawString(s, (float) origin.x + 1, (float) y);
    if (firstTime) System.out.println("------------------------------");
    firstTime = false;
  }
  protected int doPaintText(Graphics2D g, int offset, boolean focusAroundIcon) {
    // If there is no icon, then we have to add left internal padding
    if (offset == 0) {
      offset = myIpad.left;
    }

    int textStart = offset;
    if (myBorder != null) {
      offset += myBorder.getBorderInsets(this).left;
    }

    final List<Object[]> searchMatches = new ArrayList<>();

    applyAdditionalHints(g);
    final Font baseFont = getBaseFont();
    g.setFont(baseFont);
    offset += computeTextAlignShift(baseFont);
    int baseSize = baseFont.getSize();
    FontMetrics baseMetrics = g.getFontMetrics();
    Rectangle area = computePaintArea();
    final int textBaseline = area.y + getTextBaseLine(baseMetrics, area.height);
    boolean wasSmaller = false;
    for (int i = 0; i < myFragments.size(); i++) {
      final SimpleTextAttributes attributes = myAttributes.get(i);

      Font font = g.getFont();
      boolean isSmaller = attributes.isSmaller();
      if (font.getStyle() != attributes.getFontStyle()
          || isSmaller != wasSmaller) { // derive font only if it is necessary
        font =
            font.deriveFont(
                attributes.getFontStyle(),
                isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
      }
      wasSmaller = isSmaller;

      g.setFont(font);
      final FontMetrics metrics = g.getFontMetrics(font);

      final int fragmentWidth = computeStringWidth(i, font);

      final int fragmentPadding = myFragmentPadding.get(i);

      final Color bgColor = attributes.isSearchMatch() ? null : attributes.getBgColor();
      if ((attributes.isOpaque() || isOpaque()) && bgColor != null) {
        g.setColor(bgColor);
        g.fillRect(offset, 0, fragmentWidth, getHeight());
      }

      Color color = attributes.getFgColor();
      if (color
          == null) { // in case if color is not defined we have to get foreground color from Swing
                     // hierarchy
        color = getForeground();
      }
      if (!isEnabled()) {
        color = UIUtil.getInactiveTextColor();
      }
      g.setColor(color);

      final int fragmentAlignment = myFragmentAlignment.get(i);

      final int endOffset;
      if (fragmentPadding > 0 && fragmentPadding > fragmentWidth) {
        endOffset = fragmentPadding;
        if (fragmentAlignment == SwingConstants.RIGHT
            || fragmentAlignment == SwingConstants.TRAILING) {
          offset = fragmentPadding - fragmentWidth;
        }
      } else {
        endOffset = offset + fragmentWidth;
      }

      if (!attributes.isSearchMatch()) {
        if (shouldDrawMacShadow()) {
          g.setColor(SHADOW_COLOR);
          doDrawString(g, i, offset, textBaseline + 1);
        }

        if (shouldDrawDimmed()) {
          color = ColorUtil.dimmer(color);
        }

        g.setColor(color);
        doDrawString(g, i, offset, textBaseline);
      }

      // for some reason strokeState here may be incorrect, resetting the stroke helps
      g.setStroke(g.getStroke());

      // 1. Strikeout effect
      if (attributes.isStrikeout() && !attributes.isSearchMatch()) {
        EffectPainter.STRIKE_THROUGH.paint(
            g, offset, textBaseline, fragmentWidth, getCharHeight(g), font);
      }
      // 2. Waved effect
      if (attributes.isWaved()) {
        if (attributes.getWaveColor() != null) {
          g.setColor(attributes.getWaveColor());
        }
        EffectPainter.WAVE_UNDERSCORE.paint(
            g, offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent()), font);
      }
      // 3. Underline
      if (attributes.isUnderline()) {
        EffectPainter.LINE_UNDERSCORE.paint(
            g, offset, textBaseline, fragmentWidth, metrics.getDescent(), font);
      }
      // 4. Bold Dotted Line
      if (attributes.isBoldDottedLine()) {
        final int dottedAt = SystemInfo.isMac ? textBaseline : textBaseline + 1;
        final Color lineColor = attributes.getWaveColor();
        UIUtil.drawBoldDottedLine(
            g, offset, offset + fragmentWidth, dottedAt, bgColor, lineColor, isOpaque());
      }

      if (attributes.isSearchMatch()) {
        searchMatches.add(
            new Object[] {
              offset,
              offset + fragmentWidth,
              textBaseline,
              myFragments.get(i),
              g.getFont(),
              attributes
            });
      }

      offset = endOffset;
    }

    // Paint focus border around the text and icon (if necessary)
    if (myPaintFocusBorder && myBorder != null) {
      if (focusAroundIcon) {
        myBorder.paintBorder(this, g, 0, 0, getWidth(), getHeight());
      } else {
        myBorder.paintBorder(this, g, textStart, 0, getWidth() - textStart, getHeight());
      }
    }

    // draw search matches after all
    for (final Object[] info : searchMatches) {
      Integer x1 = (Integer) info[0];
      Integer x2 = (Integer) info[1];
      UIUtil.drawSearchMatch(g, x1, x2, getHeight());
      g.setFont((Font) info[4]);

      Integer baseline = (Integer) info[2];
      String text = (String) info[3];
      if (shouldDrawMacShadow()) {
        g.setColor(SHADOW_COLOR);
        g.drawString(text, x1, baseline + 1);
      }

      g.setColor(new JBColor(Gray._50, Gray._0));
      g.drawString(text, x1, baseline);

      if (((SimpleTextAttributes) info[5]).isStrikeout()) {
        EffectPainter.STRIKE_THROUGH.paint(g, x1, baseline, x2 - x1, getCharHeight(g), g.getFont());
      }
    }
    return offset;
  }
Exemplo n.º 15
0
 /**
  * Returns the current font of the canvas.
  *
  * @return the font currently in use
  */
 public Font getFont() {
   return graphic.getFont();
 }
Exemplo n.º 16
0
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
Exemplo n.º 17
0
  public boolean paint(Graphics graphics) {
    if (!Game.isLoggedIn()) return false;
    try {
      Graphics2D g = (Graphics2D) graphics;
      PComponent clayout = null;
      try {
        clayout =
            new PColumnLayout(
                227,
                404,
                infoColumnValues,
                infoColumnData,
                new Font("Arial", 0, 9),
                PColumnLayout.ColorScheme.WHITE);
      } catch (Exception e) {
        e.printStackTrace();
      }
      getFrame("options").removeComponent(firstLayout);
      getFrame("options").removeComponent(secondLayout);
      int secondColx = -1;
      int bestLength = -1;
      firstColumn.clear();
      secondColumn.clear();
      if (checkBoxes.size() <= 6) firstColumn.putAll(checkBoxes);
      else {
        for (int i = 0; i < checkBoxes.size(); i++) {
          if (i <= 5) {
            String text;
            Iterator it = checkBoxes.keySet().iterator();
            for (int j = 0; j < i; j++) it.next();
            text = (String) it.next();
            int length = SwingUtilities.computeStringWidth(g.getFontMetrics(g.getFont()), text);
            if (length > bestLength) bestLength = length;
            firstColumn.put(text, checkBoxes.get(text));
          } else {
            String text;
            Iterator it = checkBoxes.keySet().iterator();
            for (int j = 0; j < i; j++) it.next();
            text = (String) it.next();
            secondColumn.put(text, checkBoxes.get(text));
          }
        }
      }
      secondColx = 8 + bestLength;
      firstLayout =
          new PCheckBoxLayout(
              8,
              407,
              firstColumn
                  .keySet()
                  .toArray(new String[(firstColumn.size() > 6) ? 6 : firstColumn.size()]),
              firstColumn
                  .values()
                  .toArray(new PCheckBox[(firstColumn.size() > 6) ? 6 : firstColumn.size()]),
              new Font("Arial", 0, 11),
              PCheckBoxLayout.ColorScheme.WHITE);
      secondLayout =
          new PCheckBoxLayout(
              secondColx + 12,
              407,
              secondColumn
                  .keySet()
                  .toArray(new String[(secondColumn.size() > 6) ? 6 : secondColumn.size()]),
              secondColumn
                  .values()
                  .toArray(new PCheckBox[(secondColumn.size() > 6) ? 6 : secondColumn.size()]),
              new Font("Arial", 0, 11),
              PCheckBoxLayout.ColorScheme.WHITE);
      getFrame("options").addComponent(firstLayout);
      getFrame("options").addComponent(secondLayout);
      if (showPaint) {
        Paint p = g.getPaint();
        g.setPaint(
            new GradientPaint(
                0, 1000, new Color(55, 55, 55, 240), 512, 472, new Color(15, 15, 15, 240)));
        g.fillRect(7, 396, 505, 128);
        final Point loc = Mouse.getLocation();
        if (Mouse.isPressed()) {
          g.fillOval(loc.x - 5, loc.y - 5, 10, 10);
          g.drawOval(loc.x - 5, loc.y - 5, 10, 10);
        }
        g.drawLine(0, loc.y + 1, 766, loc.y + 1);
        g.drawLine(0, loc.y - 1, 766, loc.y - 1);
        g.drawLine(loc.x + 1, 0, loc.x + 1, 505);
        g.drawLine(loc.x - 1, 0, loc.x - 1, 505);
        g.setPaint(p);
      }
      if (clayout != null) getFrame("info").addComponent(clayout);
      PaintController.onRepaint(graphics);
      if (clayout != null) getFrame("info").removeComponent(clayout);
      if (!showPaint) return false;
      String infoTxt = name + " - " + "v" + version;
      g.drawString(
          infoTxt,
          510 - SwingUtilities.computeStringWidth(g.getFontMetrics(g.getFont()), infoTxt),
          468);

      int offset = 0;
      for (Skill skill : skills) {
        if (skill.xpGained() > 0) {
          PSkill skillComp =
              new PSkill(8, 397 + offset, skill.getSkill(), PSkill.ColorScheme.GRAPHITE);
          if (!getFrame("info").containsComponent(skillComp)) {
            getFrame("info").addComponent(skillComp);
          }
          offset += 20;
        }
      }

      // == Mouse ==
      if (Mouse.isPressed()) {
        g.setColor(new Color(255, 252, 0, 150));

        g.setColor(new Color(255, 252, 0, 100));
      } else {
        g.setColor(new Color(255, 252, 0, 50));
      }

      g.setColor(new Color(0, 0, 0, 50));

      // == End mouse ==
    } catch (Exception ignored) {
      // if (Utils.isDevMode())
      //    ignored.printStackTrace();
    }
    return true;
  }
  /*
   * (non-Javadoc)
   *
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  @Override
  public void paintComponent(Graphics g) {
    // if (this.isPalette) {
    // this.paintPalette(g);
    // return;
    // }

    DecorationAreaType decorationType = getThisDecorationType();

    Graphics2D graphics = (Graphics2D) g.create();
    // Desktop icon is translucent.
    final float coef = (this.getParent() instanceof JDesktopIcon) ? 0.6f : 1.0f;
    graphics.setComposite(LafWidgetUtilities.getAlphaComposite(this.frame, coef, g));

    boolean leftToRight = this.frame.getComponentOrientation().isLeftToRight();

    int width = this.getWidth();
    int height = this.getHeight() + 2;

    SubstanceColorScheme scheme =
        SubstanceCoreUtilities.getSkin(this.frame).getEnabledColorScheme(decorationType);
    JInternalFrame hostFrame =
        (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class, this);
    JComponent hostForColorization = hostFrame;
    if (hostFrame == null) {
      // try desktop icon
      JDesktopIcon desktopIcon =
          (JDesktopIcon) SwingUtilities.getAncestorOfClass(JDesktopIcon.class, this);
      if (desktopIcon != null) hostFrame = desktopIcon.getInternalFrame();
      hostForColorization = desktopIcon;
    }
    // if ((hostFrame != null) && SubstanceCoreUtilities.hasColorization(
    // this)) {
    Color backgr = hostFrame.getBackground();
    if (!(backgr instanceof UIResource)) {
      double colorization = SubstanceCoreUtilities.getColorizationFactor(hostForColorization);
      scheme = ShiftColorScheme.getShiftedScheme(scheme, backgr, colorization, null, 0.0);
    }
    // }
    String theTitle = this.frame.getTitle();

    // offset of border
    int xOffset;
    int leftEnd;
    int rightEnd;

    if (leftToRight) {
      xOffset = 5;
      Icon icon = this.frame.getFrameIcon();
      if (icon != null) {
        xOffset += icon.getIconWidth() + 5;
      }

      leftEnd = (this.menuBar == null) ? 0 : (this.menuBar.getWidth() + 5);
      xOffset += leftEnd;
      if (icon != null) leftEnd += (icon.getIconWidth() + 5);

      rightEnd = width - 5;

      // find the leftmost button for the right end
      AbstractButton leftmostButton = null;
      if (this.frame.isIconifiable()) {
        leftmostButton = this.iconButton;
      } else {
        if (this.frame.isMaximizable()) {
          leftmostButton = this.maxButton;
        } else {
          if (this.frame.isClosable()) {
            leftmostButton = this.closeButton;
          }
        }
      }

      if (leftmostButton != null) {
        Rectangle rect = leftmostButton.getBounds();
        rightEnd = rect.getBounds().x - 5;
      }
      if (theTitle != null) {
        FontMetrics fm = this.frame.getFontMetrics(graphics.getFont());
        int titleWidth = rightEnd - leftEnd;
        String clippedTitle = SubstanceCoreUtilities.clipString(fm, titleWidth, theTitle);
        // show tooltip with full title only if necessary
        if (theTitle.equals(clippedTitle)) this.setToolTipText(null);
        else this.setToolTipText(theTitle);
        theTitle = clippedTitle;
      }
    } else {
      xOffset = width - 5;

      Icon icon = this.frame.getFrameIcon();
      if (icon != null) {
        xOffset -= (icon.getIconWidth() + 5);
      }

      rightEnd = (this.menuBar == null) ? xOffset : xOffset - this.menuBar.getWidth() - 5;

      // find the rightmost button for the left end
      AbstractButton rightmostButton = null;
      if (this.frame.isIconifiable()) {
        rightmostButton = this.iconButton;
      } else {
        if (this.frame.isMaximizable()) {
          rightmostButton = this.maxButton;
        } else {
          if (this.frame.isClosable()) {
            rightmostButton = this.closeButton;
          }
        }
      }

      leftEnd = 5;
      if (rightmostButton != null) {
        Rectangle rect = rightmostButton.getBounds();
        leftEnd = rect.getBounds().x + 5;
      }
      if (theTitle != null) {
        FontMetrics fm = this.frame.getFontMetrics(graphics.getFont());
        int titleWidth = rightEnd - leftEnd;
        String clippedTitle = SubstanceCoreUtilities.clipString(fm, titleWidth, theTitle);
        // show tooltip with full title only if necessary
        if (theTitle.equals(clippedTitle)) {
          this.setToolTipText(null);
        } else {
          this.setToolTipText(theTitle);
        }
        theTitle = clippedTitle;
        xOffset = rightEnd - fm.stringWidth(theTitle);
      }
    }

    BackgroundPaintingUtils.update(
        graphics, SubstanceInternalFrameTitlePane.this, false, decorationType);
    // DecorationPainterUtils.paintDecorationBackground(graphics,
    // SubstanceInternalFrameTitlePane.this, false);

    // draw the title (if needed)
    if (theTitle != null) {
      JRootPane rootPane = this.getRootPane();
      FontMetrics fm = rootPane.getFontMetrics(graphics.getFont());
      int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent();

      SubstanceTextUtilities.paintTextWithDropShadow(
          this,
          graphics,
          SubstanceColorUtilities.getForegroundColor(scheme),
          theTitle,
          width,
          height,
          xOffset,
          yOffset);
    }

    Icon icon = this.frame.getFrameIcon();
    if (icon != null) {
      if (leftToRight) {
        int iconY = ((height / 2) - (icon.getIconHeight() / 2));
        icon.paintIcon(this.frame, graphics, 5, iconY);
      } else {
        int iconY = ((height / 2) - (icon.getIconHeight() / 2));
        icon.paintIcon(this.frame, graphics, width - 5 - icon.getIconWidth(), iconY);
      }
    }

    graphics.dispose();
  }