Example #1
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();
      int pointSize = Math.max(Math.min(w, h) / 80, 4);

      double xInc = (double) (w - 2 * PAD) / (MAX_X - 1);
      double scale = (double) (h - 2 * PAD) / MAX_Y;
      // Draw abcissa.
      int tickInc = MAX_X / 10;
      for (int i = 0; i <= MAX_X; i += tickInc) {
        int x = PAD + (int) (i * xInc);
        int y = h - PAD;
        g.drawString(Integer.toString(i), x - 5, y + 20);
        g2.draw(new Line2D.Double(x, y - 5, x, y + 5));
      }
      g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD));
      AffineTransform orig = g2.getTransform();
      g2.rotate(-Math.PI / 2);
      g2.setColor(Color.black);
      g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3);
      g2.setTransform(orig);

      // Draw ordinate.
      tickInc = (h - PAD) / 10;

      for (int i = tickInc; i < h - PAD; i += tickInc) {
        int x = PAD;
        int closest_10 = ((int) (i / scale) / 10) * 10;

        int y = h - PAD - (int) (closest_10 * scale);
        if (y < PAD) break;
        String tickMark = Integer.toString(closest_10);
        int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth();
        g.drawString(tickMark, x - stringLen - 8, y + 5);
        g2.draw(new Line2D.Double(x - 5, y, x + 5, y));
      }
      g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD));
      g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40);

      for (int index = 0; index < plot_data.size(); index++) {
        int[] data = plot_data.get(index);

        // Mark data points.
        g2.setPaint(plot_colors.get(index));

        for (int i = 0; i < data.length; i++) {
          double x = PAD + i * xInc;
          double y = h - PAD - scale * data[i];
          g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize));
        }

        g2.setFont(textFont);
        int stringHeight =
            (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight();
        g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight);
      }
    }
  @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();
  }
  private boolean paintPlaceholderText(Graphics2D g) {
    CharSequence hintText = myEditor.getPlaceholder();
    EditorComponentImpl editorComponent = myEditor.getContentComponent();
    if (myDocument.getTextLength() > 0
        || hintText == null
        || hintText.length() == 0
        || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == editorComponent
            && !myEditor.getShowPlaceholderWhenFocused()) {
      return false;
    }

    hintText =
        SwingUtilities.layoutCompoundLabel(
            g.getFontMetrics(),
            hintText.toString(),
            null,
            0,
            0,
            0,
            0,
            editorComponent.getBounds(),
            new Rectangle(),
            new Rectangle(),
            0);
    g.setColor(myEditor.getFoldingModel().getPlaceholderAttributes().getForegroundColor());
    g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN));
    g.drawString(hintText.toString(), 0, myView.getAscent());
    return true;
  }
  @Override
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Color old = g2d.getColor();
    // Draw box
    g2d.setColor(
        clicked
            ? this.clickedBackColor
            : (hovering ? this.hoverBackColor : this.unclickedBackColor));
    g2d.fillRect(0, 0, getWidth(), getHeight());
    // Draw label
    g2d.setColor(
        clicked
            ? this.clickedForeColor
            : (hovering ? this.hoverForeColor : this.unclickedForeColor));
    g2d.setFont(getFont());
    int width = g2d.getFontMetrics().stringWidth(getText());
    int textHeight = getFont().getSize();
    int otherTextHeight = getFontMetrics(getFont()).getHeight();

    textHeight = textHeight - (otherTextHeight - textHeight);
    int height = textHeight + (getHeight() - textHeight) / 2;
    g2d.drawString(getText(), (getWidth() - width) / 2, height);

    g2d.setColor(old);
  }
Example #5
0
  @Override
  protected void paintWidget() {
    Graphics2D g = getGraphics();
    g.setStroke(Util.STROKE_2);
    g.setFont(getFont());
    Rectangle bounds = getBounds();

    String text = Util.node(this).toString();
    if (text.length() == 0) {
      g.setColor((Color) getBackground());
      g.fillOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
      g.setColor(getForeground());
      g.drawOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
    } else {
      g.setColor((Color) getBackground());
      int arc = (bounds.height - 1);
      g.fillRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
      g.setColor(getForeground());
      g.drawString(
          text,
          bounds.x + (bounds.height - 1) / 2,
          bounds.y + bounds.height - vborder - 1 - g.getFontMetrics().getMaxDescent());
      g.drawRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
    }
  }
Example #6
0
  public void paint(java.awt.Graphics g) {
    if (element != null) {
      Rectangle bounds = element.jGetBounds();
      Graphics2D g2 = (Graphics2D) g;

      g2.setFont(font);

      int mitteX = bounds.x + (bounds.width) / 2;
      int mitteY = bounds.y + (bounds.height) / 2;

      int distanceY = 10;

      g2.setColor(new Color(204, 204, 255));
      g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);
      g2.setColor(Color.BLACK);
      g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);

      String caption = "dec(" + variable.getValue() + ")";

      FontMetrics fm = g2.getFontMetrics();
      Rectangle2D r = fm.getStringBounds(caption, g2);

      g2.setColor(Color.BLACK);
      g.drawString(
          caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3);
    }
    super.paint(g);
  }
Example #7
0
  @Override
  public void paint(Graphics g) {
    super.paint(g);

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

    int textWidth = g2.getFontMetrics().stringWidth("00:00.00");
    int fontSize = getFont().getSize() * getWidth() / textWidth;
    g2.setFont(getFont().deriveFont((float) Math.min(fontSize, getHeight())));

    Rectangle2D bounds = g2.getFontMetrics().getStringBounds(this.text, g2);
    g2.drawString(
        this.text,
        (int) ((getWidth() - bounds.getWidth()) / 2 - bounds.getX()),
        (int) ((getHeight() - bounds.getHeight()) / 2 - bounds.getY()));
  }
Example #8
0
 /**
  * Write the given text string in the current font, left-aligned at (x, y).
  *
  * @param x the x-coordinate of the text
  * @param y the y-coordinate of the text
  * @param s the text
  */
 public static void textLeft(double x, double y, String s) {
   offscreen.setFont(font);
   FontMetrics metrics = offscreen.getFontMetrics();
   double xs = scaleX(x);
   double ys = scaleY(y);
   int hs = metrics.getDescent();
   offscreen.drawString(s, (float) (xs), (float) (ys + hs));
   draw();
 }
Example #9
0
  /**
   * Draw every char in separate terminal cell to guaranty equal width for different lines.
   * Nevertheless to improve kerning we draw word characters as one block for monospaced fonts.
   */
  private void drawChars(int x, int y, CharBuffer buf, TextStyle style, Graphics2D gfx) {
    final int blockLen = 1;
    int offset = 0;
    int drawCharsOffset = 0;

    // workaround to fix Swing bad rendering of bold special chars on Linux
    // TODO required for italic?
    CharBuffer renderingBuffer;
    if (mySettingsProvider.DECCompatibilityMode() && style.hasOption(TextStyle.Option.BOLD)) {
      renderingBuffer = CharUtils.heavyDecCompatibleBuffer(buf);
    } else {
      renderingBuffer = buf;
    }

    while (offset + blockLen <= buf.length()) {
      if (renderingBuffer.getBuf()[buf.getStart() + offset] == CharUtils.DWC) {
        offset += blockLen;
        drawCharsOffset += blockLen;
        continue; // dont' draw second part(fake one) of double width character
      }

      Font font = getFontToDisplay(buf.charAt(offset + blockLen - 1), style);
      //      while (myMonospaced && (offset + blockLen < buf.getLength()) &&
      // isWordCharacter(buf.charAt(offset + blockLen - 1))
      //              && (font == getFontToDisplay(buf.charAt(offset + blockLen - 1), style))) {
      //        blockLen++;
      //      }
      gfx.setFont(font);

      int descent = gfx.getFontMetrics(font).getDescent();
      int baseLine = (y + 1) * myCharSize.height - descent;
      int xCoord = (x + drawCharsOffset) * myCharSize.width;
      int textLength =
          CharUtils.getTextLengthDoubleWidthAware(
              buf.getBuf(),
              buf.getStart() + offset,
              blockLen,
              mySettingsProvider.ambiguousCharsAreDoubleWidth());

      int yCoord = y * myCharSize.height;

      gfx.setClip(
          xCoord,
          yCoord,
          Math.min(textLength * myCharSize.width, getWidth() - xCoord),
          Math.min(myCharSize.height, getHeight() - yCoord));

      gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));

      gfx.drawChars(renderingBuffer.getBuf(), buf.getStart() + offset, blockLen, xCoord, baseLine);

      drawCharsOffset += blockLen;
      offset += blockLen;
    }
    gfx.setClip(null);
  }
Example #10
0
  @Override
  protected void paintComponent(Graphics g) {
    java.util.List<Network> networks = getNetworkParts();
    positions = new int[networks.size()];
    Graphics2D g2 = (Graphics2D) g;

    g2.setFont(SMALL_BOLD_FONT);

    g2.setPaint(addressGradientPaint);
    g2.fill(g2.getClipBounds());
    // g2.drawImage(addressGradient, 0, 0, getWidth(), 26, null);

    int x = 14;

    for (int i = 0; i < networks.size(); i++) {
      Network part = networks.get(i);
      if (i == armed) {
        g2.setColor(TEXT_ARMED_COLOR);
      } else {
        g2.setColor(TEXT_NORMAL_COLOR);
      }
      String displayName = part.getDisplayName();
      SwingUtils.drawShadowText(g2, displayName, x, 16);

      int width = (int) g2.getFontMetrics().stringWidth(displayName);
      x += width + 5;
      positions[i] = x + 10;
      g2.drawImage(addressArrow, x, 0, null);
      x += 15;
    }

    String version = Application.getInstance().getVersion();
    int versionX = getWidth() - g2.getFontMetrics().stringWidth(version) - 10;
    SwingUtils.drawShadowText(g2, version, versionX, 16);

    if (renderException != null) {
      g2.drawImage(addressExclamation, versionX - 30, 0, null);
    }
  }
  @Override
  protected void paintComponent(final Graphics g) {
    String s = getText();
    final Rectangle bounds = getBounds();
    if (UIUtil.isUnderDarcula()) {
      g.setColor(UIUtil.getPanelBackground());
      g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
    }
    if (s == null) return;
    final Insets insets = getInsets();

    final Graphics2D g2 = (Graphics2D) g;
    g2.setFont(getFont());

    UIUtil.applyRenderingHints(g2);

    final FontMetrics fm = g2.getFontMetrics();
    final int sWidth = fm.stringWidth(s);

    int x = insets.left;
    if (myAlignment == Component.CENTER_ALIGNMENT || myAlignment == Component.RIGHT_ALIGNMENT) {
      x =
          myAlignment == Component.CENTER_ALIGNMENT
              ? (bounds.width - sWidth) / 2
              : bounds.width - insets.right - sWidth;
    }

    final Rectangle textR = new Rectangle();
    final Rectangle iconR = new Rectangle();
    final Rectangle viewR = new Rectangle(bounds);
    textR.x = textR.y = textR.width = textR.height = 0;

    viewR.width -= insets.left;
    viewR.width -= insets.right;

    final int maxWidth = bounds.width - insets.left - insets.right;
    if (sWidth > maxWidth) {
      s = truncateText(s, bounds, fm, textR, iconR, maxWidth);
    }

    final int y = UIUtil.getStringY(s, bounds, g2);
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula() && myDecorate) {
      g2.setColor(myCustomColor == null ? Gray._215 : myCustomColor);
      g2.drawString(s, x, y + 1);
    }

    g2.setColor(myCustomColor == null ? getForeground() : myCustomColor);
    g2.drawString(s, x, y);
  }
Example #12
0
  // draws the tree, starting from the given node, in the region with x values
  // ranging
  // from minX to maxX, with y value beginning at y, and next level at y +
  // yIncr.
  private void drawTree(Graphics2D g2, TreeNode<E> t, int minX, int maxX, int y, int yIncr) {
    // skip if empty
    if (t == null) return;

    // compute useful coordinates
    int x = (minX + maxX) / 2;
    int nextY = y + yIncr;

    // draw black lines
    g2.setPaint(Color.black);
    if (t.left != null) {
      int nextX = (minX + x) / 2;
      g2.draw(new Line2D.Double(x, y, nextX, nextY));
    }
    if (t.right != null) {
      int nextX = (x + maxX) / 2;
      g2.draw(new Line2D.Double(x, y, nextX, nextY));
    }

    // measure text
    FontMetrics font = g2.getFontMetrics();
    String text = t.data + "";
    int textHeight = font.getHeight();
    int textWidth = font.stringWidth(text);

    // draw the box around the node
    Rectangle2D.Double box =
        new Rectangle2D.Double(
            x - textWidth / 2 - ARC_PAD,
            y - textHeight / 2 - ARC_PAD,
            textWidth + 2 * ARC_PAD,
            textHeight + 2 * ARC_PAD);
    Color c = new Color(187, 224, 227);
    g2.setPaint(c);
    g2.fill(box);
    // draw black border
    g2.setPaint(Color.black);
    g2.draw(box);

    // draw text
    g2.drawString(text, x - textWidth / 2, y + textHeight / 2);

    // draw children
    drawTree(g2, t.left, minX, x, nextY, yIncr);
    drawTree(g2, t.right, x, maxX, nextY, yIncr);
  }
    @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);
      }
    }
  public void paint(@NotNull Graphics2D g2, int x, int y, int height) {
    if (myLabels.isEmpty()) return;

    GraphicsConfig config = GraphicsUtil.setupAAPainting(g2);
    g2.setFont(getReferenceFont());
    g2.setStroke(new BasicStroke(1.5f));

    FontMetrics fontMetrics = g2.getFontMetrics();

    x += PaintParameters.LABEL_PADDING;
    for (Pair<String, Color> label : myLabels) {
      Dimension size = myLabelPainter.calculateSize(label.first, fontMetrics);
      int paddingY = y + (height - size.height) / 2;
      myLabelPainter.paint(g2, label.first, x, paddingY, getLabelColor(label.second));
      x += size.width + PaintParameters.LABEL_PADDING;
    }

    config.restore();
  }
Example #15
0
  public void paintComponent(Graphics gr) {
    Graphics2D g = (Graphics2D) gr;
    Object oldHints = QuaquaUtilities.beginGraphics((Graphics2D) g);

    g.drawImage(crayonsImage, 0, 0, this);

    if (selectedCrayon != null) {
      /*
      g.setColor(new Color(0x60ffffff & selectedCrayon.color.getRGB(),true));
      g.fill(selectedCrayon.shape);
       */
      g.setColor(getForeground());
      FontMetrics fm = g.getFontMetrics();
      int nameWidth = fm.stringWidth(selectedCrayon.name);
      g.drawString(
          selectedCrayon.name, (crayonsImage.getWidth(this) - nameWidth) / 2, fm.getAscent() + 1);
    }
    QuaquaUtilities.endGraphics((Graphics2D) g, oldHints);
  }
Example #16
0
  private void establishFontMetrics() {
    final BufferedImage img = createBufferedImage(1, 1);
    final Graphics2D graphics = img.createGraphics();
    graphics.setFont(myNormalFont);

    final float lineSpace = mySettingsProvider.getLineSpace();
    final FontMetrics fo = graphics.getFontMetrics();

    myDescent = fo.getDescent();
    myCharSize.width = fo.charWidth('W');
    myCharSize.height = fo.getHeight() + (int) (lineSpace * 2);
    myDescent += lineSpace;

    myMonospaced = isMonospaced(fo);
    if (!myMonospaced) {
      LOG.info("WARNING: Font " + myNormalFont.getName() + " is non-monospaced");
    }

    img.flush();
    graphics.dispose();
  }
Example #17
0
    public void run() {

      Thread me = Thread.currentThread();

      while (thread == me && !isShowing() || getSize().width == 0) {
        try {
          thread.sleep(500);
        } catch (InterruptedException e) {
          return;
        }
      }

      while (thread == me && isShowing()) {
        Dimension d = getSize();
        if (d.width != w || d.height != h) {
          w = d.width;
          h = d.height;
          bimg = (BufferedImage) createImage(w, h);
          big = bimg.createGraphics();
          big.setFont(font);
          FontMetrics fm = big.getFontMetrics(font);
          ascent = (int) fm.getAscent();
          descent = (int) fm.getDescent();
        }
        repaint();
        try {
          thread.sleep(sleepAmount);
        } catch (InterruptedException e) {
          break;
        }
        if (MemoryMonitor.dateStampCB.isSelected()) {
          System.out.println(new Date().toString() + " " + usedStr);
        }
      }
      thread = null;
    }
 public void draw(
     Graphics2D g,
     Color stringColor,
     Color foreground,
     Color background,
     String info,
     double x,
     double y) {
   FontMetrics fm = g.getFontMetrics();
   int h = fm.getHeight();
   int w = fm.stringWidth(info);
   r1.setRect(
       x - w / 2 - in.left, y - in.top - h / 2, w + in.right + in.left, h + in.bottom + in.top);
   g.setColor(background);
   g.fill(r1);
   g.setColor(stringColor);
   g.draw(r1);
   g.setColor(foreground);
   r2.setRect(r1.getX() + 1, r1.getY() + 1, r1.getWidth() - 2, r1.getHeight() - 2);
   g.draw(r2);
   g.setColor(stringColor);
   g.drawString(
       info, (float) (r2.getX() + in.left), (float) (r2.getY() + h - (r2.getHeight() - h) / 2));
 }
Example #19
0
  // called whenever the TreeDisplay must be drawn on the screen
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension d = getSize();

    // draw white background
    g2.setPaint(Color.white);
    g2.fill(new Rectangle2D.Double(0, 0, d.width, d.height));

    int depth = h();

    if (root == null)
      // no tree to draw
      return;

    // hack to avoid division by zero, if only one level in tree
    if (depth == 1) depth = 2;

    // compute the size of the text
    FontMetrics font = g2.getFontMetrics();
    TreeNode<E> leftmost = root;
    while (leftmost.left != null) leftmost = leftmost.left;
    TreeNode<E> rightmost = root;
    while (rightmost.right != null) rightmost = rightmost.right;
    int leftPad = font.stringWidth(leftmost.data + "") / 2;
    int rightPad = font.stringWidth(rightmost.data + "") / 2;
    int textHeight = font.getHeight();

    // draw the actual tree
    drawTree(
        g2,
        root,
        leftPad + ARC_PAD,
        d.width - rightPad - ARC_PAD,
        textHeight / 2 + ARC_PAD,
        (d.height - textHeight - 2 * ARC_PAD) / (depth - 1));
  }
  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;
  }
Example #21
0
  public void paintComponent(Graphics g0) {
    super.paintComponent(g0);

    Graphics2D g = (Graphics2D) g0;
    g.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setFont(font);
    fontMetrics = g.getFontMetrics();
    g.setColor(this.model.getGridColor());
    g.setFont(new Font("Impact", Font.PLAIN, 11));

    xGrid = this.model.getXGrid();
    yGrid = this.model.getYGrid();
    xUnit = this.model.getXUnit();
    yUnit = this.model.getYUnit();
    graphPrecision = this.model.getGraphPrecision();

    // Draws grid
    g.drawLine(xGrid, 0, xGrid, height);
    g.drawLine(0, yGrid, width, yGrid);

    // Draws a white line on the x and y grids every 10 pixels
    for (int x = xGrid; x <= width; x += 10) g.drawLine(x, yGrid + 3, x, yGrid - 3);

    for (int x = xGrid; x >= 0; x -= 10) g.drawLine(x, yGrid + 3, x, yGrid - 3);

    for (int y = yGrid; y <= height; y += 10) g.drawLine(xGrid + 3, y, xGrid - 3, y);

    for (int y = yGrid; y >= 0; y -= 10) g.drawLine(xGrid + 3, y, xGrid - 3, y);

    // Draws an orange line on the grid for every (default = 5) white lines
    g.setColor(this.model.getGraphColor());
    int piUnit = (int) Math.round((double) xUnit * Math.PI);

    if (model.isIntegerScale()) {
      for (int x = xGrid + xUnit; x <= width; x += xUnit) {
        g.drawLine(x, yGrid + 5, x, yGrid - 5);
        xCoordinate = x - xGrid;
        xCoordinate /= xUnit;
        g.drawString("" + xCoordinate, x - 2, yGrid + 20);
      }

      for (int x = xGrid - xUnit; x >= 0; x -= xUnit) {
        g.drawLine(x, yGrid + 5, x, yGrid - 5);
        xCoordinate = x - xGrid;
        xCoordinate /= xUnit;
        g.drawString("" + xCoordinate, x - 5, yGrid + 20);
      }
    } else {
      /*
      int piScale = (int)Math.round(xUnit * Math.PI);
      for(int x = xGrid + piScale; x <= width; x += piScale)
      {
      	g.drawLine(x, yGrid + 5, x, yGrid - 5);
      	xCoordinate = x - (xGrid + piScale);
      	xCoordinate = (xCoordinate/piScale) + 1;
      	g.drawString(""+(xCoordinate == 1 ? "": xCoordinate) + "π", x-2, yGrid + 20);
      }

      for(int x = xGrid - piScale; x >= 0; x -= piScale)
      {
      	g.drawLine(x, yGrid + 5, x, yGrid - 5);
      	xCoordinate = x - (xGrid - piScale);
      	xCoordinate = (xCoordinate/piScale) - 1;
      	g.drawString(""+(xCoordinate == -1 ? "-": xCoordinate) + "π", x - 5, yGrid + 20);
      }
      */

      int piStandardDeno = 1;
      for (int x = piDenominators.length - 1; x >= 0; x--) {
        if (piUnit / piDenominators[x] < 40) continue;
        piStandardDeno = piDenominators[x];
        break;
      }

      if (piStandardDeno != 1) {
        int count = 1;
        for (int x = xGrid + (int) Math.round(((double) xUnit * Math.PI) / (double) piStandardDeno);
            x <= width;
            x =
                xGrid
                    + (int)
                        Math.round(
                            ((double) (count * xUnit) * Math.PI) / (double) piStandardDeno)) {
          if (count % piStandardDeno != 0) {
            g.drawLine(x, yGrid + 3, x, yGrid - 3);
            int fraction[] = Algebra.simplifyFraction(count, piStandardDeno);
            String label =
                (new StringBuilder())
                    .append(fraction[0] != 1 ? ((Integer.valueOf(fraction[0]))) : "")
                    .append("\u03C0/")
                    .append(fraction[1])
                    .toString();
            g.drawString(label, x - fontMetrics.stringWidth(label) / 2, yGrid + 20);
          }
          count++;
        }

        count = 1;
        for (int x = xGrid - (int) Math.round(((double) xUnit * Math.PI) / (double) piStandardDeno);
            x >= 0;
            x =
                xGrid
                    - (int)
                        Math.round(
                            ((double) (count * xUnit) * 3.1415926535897931D)
                                / (double) piStandardDeno)) {
          if (count % piStandardDeno != 0) {
            g.drawLine(x, yGrid + 3, x, yGrid - 3);
            int fraction[] = Algebra.simplifyFraction(count, piStandardDeno);
            String label =
                (new StringBuilder())
                    .append(fraction[0] != 1 ? ((Integer.valueOf(-fraction[0]))) : "-")
                    .append("\u03C0/")
                    .append(fraction[1])
                    .toString();
            g.drawString(label, x - fontMetrics.stringWidth(label) / 2, yGrid + 20);
          }
          count++;
        }
      }
    }
    for (int y = yGrid + yUnit; y <= height; y += yUnit) {
      g.drawLine(xGrid + 5, y, xGrid - 5, y);
      yCoordinate = yGrid - y;
      yCoordinate /= yUnit;
      g.drawString("" + yCoordinate, xGrid + 20, y + 5);
    }
    for (int y = yGrid - yUnit; y >= 0; y -= yUnit) {
      g.drawLine(xGrid + 5, y, xGrid - 5, y);
      g.drawLine(xGrid + 5, y, xGrid - 5, y);
      yCoordinate = yGrid - y;
      yCoordinate /= yUnit;
      g.drawString("" + yCoordinate, xGrid + 20, y + 5);
    }
    // if polynomials
  } // end paintComponent
Example #22
0
    @Override
    protected void paintComponent(Graphics g) {
      JRibbonFrame ribbonFrame = (JRibbonFrame) SwingUtilities.getWindowAncestor(this);
      if (!ribbonFrame.isShowingKeyTips()) return;

      // don't show keytips on inactive windows
      if (!ribbonFrame.isActive()) return;

      Collection<KeyTipManager.KeyTipLink> keyTips =
          KeyTipManager.defaultManager().getCurrentlyShownKeyTips();
      if (keyTips != null) {
        Graphics2D g2d = (Graphics2D) g.create();
        RenderingUtils.installDesktopHints(g2d);

        for (KeyTipManager.KeyTipLink keyTip : keyTips) {
          // don't display keytips on components in popup panels
          if (SwingUtilities.getAncestorOfClass(JPopupPanel.class, keyTip.comp) != null) continue;

          // don't display key tips on hidden components
          Rectangle compBounds = keyTip.comp.getBounds();
          if (!keyTip.comp.isShowing()
              || (compBounds.getWidth() == 0)
              || (compBounds.getHeight() == 0)) continue;

          Dimension pref =
              KeyTipRenderingUtilities.getPrefSize(g2d.getFontMetrics(), keyTip.keyTipString);

          Point prefCenter = keyTip.prefAnchorPoint;
          Point loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, this);
          Container bandControlPanel =
              SwingUtilities.getAncestorOfClass(AbstractBandControlPanel.class, keyTip.comp);
          if (bandControlPanel != null) {
            // special case for controls in threesome
            // ribbon band rows
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.TOP_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = 0;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = 0;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.MID_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight() / 2;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight() / 2;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.BOTTOM_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight();
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight();
            }
          }

          KeyTipRenderingUtilities.renderKeyTip(
              g2d,
              this,
              new Rectangle(
                  loc.x - pref.width / 2, loc.y - pref.height / 2, pref.width, pref.height),
              keyTip.keyTipString,
              keyTip.enabled);
        }

        g2d.dispose();
      }
    }
    @Override
    public void paintComponent(final Graphics g) {

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

      int width = getWidth() - 100;
      int height = getHeight() - 40;

      if (size.equals(BoxSize.MEDIUM)) {
        height -= 196;
        g2d.translate(0, 98);
      } else if (size.equals(BoxSize.LARGE)) {
        height -= 588;
        g2d.translate(0, 294);
      } else if (size.equals(BoxSize.LARGE_SINGLE)) {
        height -= 665;
        g2d.translate(0, 333);
      }

      g2d.setColor(clr1.getColor());
      g2d.setStroke(new BasicStroke(4));

      if (lineSide.equals(LineSide.LEFT) || lineSide.equals(LineSide.BOTH)) {
        g2d.drawLine(0, height / 2 + 20, 47, height / 2 + 20);
      }

      g2d.translate(50, 20);

      if (lineSide.equals(LineSide.RIGHT) || lineSide.equals(LineSide.BOTH)) {
        g2d.drawLine(width, height / 2, width + 65, height / 2);
        if (lineDir.equals(LineDirection.DOWN)) {
          g2d.drawLine(width + 48, height / 2, width + 48, height + 400);
        } else if (lineDir.equals(LineDirection.UP)) {
          g2d.drawLine(width + 48, height / 2, width + 48, -400);
        } else if (lineDir.equals(LineDirection.STRAIGHT)) {
          g2d.drawLine(width, height / 2, width + 45, height / 2);
        }
      }

      FSkin.setGraphicsGradientPaint(g2d, 0, 0, clr3, 0, height / 2 + 15, clr2);
      g2d.fillRect(0, 0, width, height / 2);

      FSkin.setGraphicsGradientPaint(g2d, 0, height / 2 - 15, clr2, 0, height, clr3);
      g2d.fillRect(0, height / 2, width, height / 2);

      g2d.setColor(clr1.getColor());
      g2d.setStroke(new BasicStroke(4));
      g2d.drawRect(1, 1, width - 2, height - 2);

      if (!singleBox) {
        FSkin.setGraphicsGradientPaint(
            g2d, 70, height / 2 - 1, clr1.alphaColor(0), width, height / 2 - 1, clr1);
        g2d.setStroke(new BasicStroke(2));
        g2d.drawRect(70, height / 2 - 1, width - 70, 2);
      }

      g2d.setColor(FSkin.getColor(Colors.CLR_TEXT).getColor());
      g2d.setStroke(new BasicStroke(1));

      if (!singleBox) {
        Rectangle2D textSize = g2d.getFontMetrics().getStringBounds("VS", g2d);
        g2d.drawString(
            "VS",
            (width + (int) textSize.getWidth()) / 2,
            (height + (int) textSize.getHeight()) / 2 - 2);
      }

      // Padding here
      g2d.translate(12, 12);

      g2d.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

      Dimension srcSize = img1.getSizeForPaint(g2d);
      int wSrc = srcSize.width;
      int hSrc = srcSize.height;

      FSkin.drawImage(
          g2d, img1, 0, 0, wImg, hImg, // Destination
          0, 0, wSrc, hSrc); // Source

      g2d.translate(0, 77);

      if (!singleBox) {
        FSkin.drawImage(
            g2d, img2, 0, 0, wImg, hImg, // Destination
            0, 0, wSrc, hSrc); // Source
      }

      g2d.dispose();
    }
Example #24
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;
  }