Пример #1
0
 public RoundRectangle2D evaluate(RoundRectangle2D v0, RoundRectangle2D v1, float fraction) {
   double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction);
   double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction);
   double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction);
   double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction);
   double arcw = v0.getArcWidth() + ((v1.getArcWidth() - v0.getArcWidth()) * fraction);
   double arch = v0.getArcHeight() + ((v1.getArcHeight() - v0.getArcHeight()) * fraction);
   RoundRectangle2D value = (RoundRectangle2D) v0.clone();
   value.setRoundRect(x, y, w, h, arcw, arch);
   return value;
 }
 RoundRectIterator(RoundRectangle2D rr, AffineTransform at) {
   this.x = rr.getX();
   this.y = rr.getY();
   this.w = rr.getWidth();
   this.h = rr.getHeight();
   this.aw = Math.min(w, Math.abs(rr.getArcWidth()));
   this.ah = Math.min(h, Math.abs(rr.getArcHeight()));
   this.affine = at;
   if (aw < 0 || ah < 0) {
     // Don't draw anything...
     index = ctrlpts.length;
   }
 }
Пример #3
0
  @Override
  public void paint(Graphics g) {
    BufferedImage buffer =
        new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g2 = (Graphics2D) buffer.getGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    if (Words.isLoaded()) {

      int tX = 0;
      if (previous != null) {
        g2.setColor(previous.getBackground());
        long lapse = System.currentTimeMillis() - previousSet;
        if (lapse > TRANSISTION_TIME) {
          previous = null;
        } else {
          double percentage = (TRANSISTION_TIME - (double) lapse) / TRANSISTION_TIME;
          tX = (int) (getWidth() * percentage);
        }
        g2.fillRect(getWidth() - tX, 0, getWidth(), getHeight());
      }
      g2.setColor(mode.getBackground());
      g2.fillRect(tX, 0, getWidth(), getHeight());
    } else {

      g2.setColor(
          new Color(
              mode.getBackground().getRed(),
              (int) (mode.getBackground().getGreen() * Words.getPercent()),
              (int) (mode.getBackground().getBlue() * Words.getPercent())));
      g2.fillRect(0, 0, getWidth(), getHeight());
      g2.setColor(
          new Color(
              mode.getBackground().getRed(),
              mode.getBackground().getGreen(),
              (int) (mode.getBackground().getBlue() * Words.getPercent())));
      int tX = (int) (getWidth() * Words.getPercent());
      setSize((int) (width * Words.getPercent()) + 1, getHeight());
      g2.fillRect(getWidth() - tX, 0, getWidth(), getHeight());
    }
    g2.setColor(Color.WHITE);
    int y = COLLAPSE_LENGTH - PADDING;
    if (word != null) {
      FontMetrics metrics = g2.getFontMetrics();
      y = COLLAPSE_LENGTH + PADDING;
      int x = PADDING * 2;
      int maxX = getWidth() - PADDING * 2;
      if (word.getPronunciation() != null) {
        g2.drawString(
            word.getPronunciation(),
            getWidth() / 2 - metrics.stringWidth(word.getPronunciation()) / 2,
            y);
        x = PADDING * 2;
        y += metrics.getHeight() + PADDING;
      }
      if (mode.equals(Theme.DICT)) {
        for (String string : word.getDefinitions()) {
          String[] division = string.split(" ");
          for (String append : division) {
            int width = metrics.stringWidth(append + " ");
            if (x + width >= maxX) {
              x = PADDING * 2;
              y += metrics.getHeight();
            }
            g2.drawString(append, x, y);
            x += width;
          }
          x = PADDING * 2;
          y += metrics.getHeight() + PADDING;
        }
      } else if (mode.equals(Theme.THES)) {
        if (!word.getSynonyms().isEmpty()) {
          x = PADDING * 4 + metrics.stringWidth(word.getText());
        }
        int storedY = y;
        int height = 0;
        int count = 0;
        for (String string : word.getSynonyms()) {
          if (count == 10) {
            break;
          }
          int width = metrics.stringWidth(string + "->");
          if (x + width >= maxX) {
            x = PADDING * 4 + metrics.stringWidth(word.getText());
            y += metrics.getHeight();
            height += metrics.getHeight();
          }
          g2.drawString(string, x, y);
          x += width;
          count++;
        }

        if (!word.getSynonyms().isEmpty()) {
          y += metrics.getHeight() + PADDING;
          x = PADDING * 2;
          int tY = (storedY += height / 2) - metrics.getHeight() / 2;
          g2.drawString(word.getText(), x, tY);
          g2.setColor(Color.YELLOW);
          g2.drawLine(
              x + metrics.stringWidth(word.getText()),
              tY - metrics.getHeight() / 4,
              x + metrics.stringWidth(word.getText()) + PADDING,
              tY);
          g2.drawLine(
              x + metrics.stringWidth(word.getText()),
              tY - metrics.getHeight() / 4,
              x + metrics.stringWidth(word.getText()) + PADDING,
              tY - metrics.getHeight() / 2);
        }
      } else {
        y -= word.getPronunciation() != null ? PADDING : 0;
      }
    }
    if (!(Math.max(y, getHeight()) - Math.min(y, getHeight()) <= (INTERVAL + 1))) {
      setSize(getWidth(), (int) (getHeight() + Math.abs(INTERVAL) * (y >= getHeight() ? 1 : -1)));
    }
    g2.setColor(Color.WHITE);
    g2.fill(tBounds);
    g2.setColor(Color.BLACK);
    g2.draw(tBounds);
    g2.setFont(INPUT_FONT);
    String text = input.toString() + "";
    float sY = (float) (tBounds.getY() + 22);
    float x = (float) (tBounds.getX() + PADDING / 2D);
    Rectangle2D bounds = g2.getFontMetrics().getStringBounds(text, g2);
    g2.drawString(text, x, sY);
    g2.setColor(Color.BLUE);
    if (suggestion != null) g2.drawString(suggestion, (float) (x + bounds.getWidth()), sY);
    g.drawImage(buffer, 0, 0, null);
  }