public void paintBorder(final Graphics g, final int x, final int y, final int w, final int h) {
      ((Graphics2D) g)
          .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(focusColor);
      rect.setRoundRect(x + 0.6, y + 0.6, w - 1.2, h - 1.2, outsideRadius, outsideRadius);
      area.reset();
      area.add(new Area(rect));
      rect.setRoundRect(x + 2, y + 2, w - 4, h - 4, insideRadius, insideRadius);
      area.subtract(new Area(rect));
      ((Graphics2D) g).fill(area);
    }
 private RoundRectangle2D decodeRoundRect5() {
   roundRect.setRoundRect(
       decodeX(0.2857143f), // x
       decodeY(0.42857143f), // y
       decodeX(2.7142859f) - decodeX(0.2857143f), // width
       decodeY(2.857143f) - decodeY(0.42857143f), // height
       9.0f,
       9.0f); // rounding
   return roundRect;
 }
 private RoundRectangle2D decodeRoundRect4() {
   roundRect.setRoundRect(
       decodeX(0.08571429f), // x
       decodeY(0.08571429f), // y
       decodeX(2.914286f) - decodeX(0.08571429f), // width
       decodeY(2.914286f) - decodeY(0.08571429f), // height
       11.0f,
       11.0f); // rounding
   return roundRect;
 }
 private RoundRectangle2D decodeRoundRect3() {
   roundRect.setRoundRect(
       decodeX(0.42857143f), // x
       decodeY(0.42857143f), // y
       decodeX(2.5714285f) - decodeX(0.42857143f), // width
       decodeY(2.5714285f) - decodeY(0.42857143f), // height
       7.0f,
       7.0f); // rounding
   return roundRect;
 }
 private RoundRectangle2D decodeRoundRect3() {
   roundRect.setRoundRect(
       decodeX(1.0f), // x
       decodeY(1.6111112f), // y
       decodeX(2.0f) - decodeX(1.0f), // width
       decodeY(2.0f) - decodeY(1.6111112f), // height
       6.0f,
       6.0f); // rounding
   return roundRect;
 }
 private RoundRectangle2D decodeRoundRect2() {
   roundRect.setRoundRect(
       decodeX(1.0526316f), // x
       decodeY(1.0555556f), // y
       decodeX(1.9473684f) - decodeX(1.0526316f), // width
       decodeY(1.8888888f) - decodeY(1.0555556f), // height
       6.75f,
       6.75f); // rounding
   return roundRect;
 }
 private RoundRectangle2D decodeRoundRect1() {
   roundRect.setRoundRect(
       decodeX(1.0f), // x
       decodeY(1.0f), // y
       decodeX(2.0f) - decodeX(1.0f), // width
       decodeY(1.9444444f) - decodeY(1.0f), // height
       8.6f,
       8.6f); // rounding
   return roundRect;
 }
示例#8
0
  private void drawShadow(Graphics2D g2, RoundRectangle2D rect) {
    BufferedImage image =
        new BufferedImage(
            (int) rect.getWidth() + 8, (int) rect.getHeight() + 8, BufferedImage.TYPE_INT_ARGB);

    Graphics2D buffer = (Graphics2D) image.getGraphics();
    buffer.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    buffer.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    buffer.setColor(new Color(0.0f, 0.0f, 0.0f, 0.5f));
    buffer.translate(4, 4);
    buffer.fill(rect);

    ConvolveOp blur = new ConvolveOp(new Kernel(5, 5, BLUR_KERNEL));
    g2.drawImage(image, blur, 0, 0);

    buffer.dispose();
    image.flush();
  }
 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;
   }
 }
示例#10
0
 public boolean contains(Point p) {
   return rr.contains(p);
 }
示例#11
0
 public void setLocation(Point p) {
   rr.setRoundRect(p.x, p.y, rr.getWidth(), getHeight(), 20, 20);
 }
示例#12
0
 public Point getLocation() {
   return rr.getBounds().getLocation();
 }
 public static void fastFill(Graphics2D g2, RoundRectangle2D r) {
   Rectangle b = r.getBounds();
   g2.fillRoundRect(b.x, b.y, b.width, b.height, (int) r.getArcWidth(), (int) r.getArcHeight());
 }
示例#14
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;
 }
示例#15
0
  // <editor-fold defaultstate="collapsed" desc="Image related">
  private BufferedImage create_LCD_Image(final int WIDTH, final int HEIGHT) {
    if (WIDTH <= 0 || HEIGHT <= 0) {
      return null;
    }

    final BufferedImage IMAGE = UTIL.createImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    G2.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();

    // Background rectangle
    final Point2D BACKGROUND_START = new Point2D.Double(0.0, 0.0);
    final Point2D BACKGROUND_STOP = new Point2D.Double(0.0, IMAGE_HEIGHT);
    if (BACKGROUND_START.equals(BACKGROUND_STOP)) {
      BACKGROUND_STOP.setLocation(0.0, BACKGROUND_START.getY() + 1);
    }

    final float[] BACKGROUND_FRACTIONS = {0.0f, 0.08f, 0.92f, 1.0f};

    final Color[] BACKGROUND_COLORS = {
      new Color(0.4f, 0.4f, 0.4f, 1.0f),
      new Color(0.5f, 0.5f, 0.5f, 1.0f),
      new Color(0.5f, 0.5f, 0.5f, 1.0f),
      new Color(0.9f, 0.9f, 0.9f, 1.0f)
    };

    final LinearGradientPaint BACKGROUND_GRADIENT =
        new LinearGradientPaint(
            BACKGROUND_START, BACKGROUND_STOP, BACKGROUND_FRACTIONS, BACKGROUND_COLORS);
    // final double BACKGROUND_CORNER_RADIUS = WIDTH * 0.09375;
    final double BACKGROUND_CORNER_RADIUS = WIDTH > HEIGHT ? (HEIGHT * 0.095) : (WIDTH * 0.095);
    final java.awt.geom.RoundRectangle2D BACKGROUND =
        new java.awt.geom.RoundRectangle2D.Double(
            0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, BACKGROUND_CORNER_RADIUS, BACKGROUND_CORNER_RADIUS);
    G2.setPaint(BACKGROUND_GRADIENT);
    G2.fill(BACKGROUND);

    // Foreground rectangle
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, IMAGE_HEIGHT - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
      FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {0.0f, 0.03f, 0.49f, 0.5f, 1.0f};

    final Color[] FOREGROUND_COLORS = {
      lcdColor.GRADIENT_START_COLOR,
      lcdColor.GRADIENT_FRACTION1_COLOR,
      lcdColor.GRADIENT_FRACTION2_COLOR,
      lcdColor.GRADIENT_FRACTION3_COLOR,
      lcdColor.GRADIENT_STOP_COLOR
    };

    if (lcdColor == LcdColor.CUSTOM) {
      G2.setPaint(customLcdBackground);
    } else {
      final LinearGradientPaint FOREGROUND_GRADIENT =
          new LinearGradientPaint(
              FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
      G2.setPaint(FOREGROUND_GRADIENT);
    }
    final double FOREGROUND_CORNER_RADIUS = BACKGROUND.getArcWidth() - 1;
    final java.awt.geom.RoundRectangle2D FOREGROUND =
        new java.awt.geom.RoundRectangle2D.Double(
            1,
            1,
            IMAGE_WIDTH - 2,
            IMAGE_HEIGHT - 2,
            FOREGROUND_CORNER_RADIUS,
            FOREGROUND_CORNER_RADIUS);
    G2.fill(FOREGROUND);

    G2.dispose();

    return IMAGE;
  }
示例#16
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);
  }