Ejemplo n.º 1
0
  @Override
  public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
    System.out.println("PageFormat: width=" + pf.getWidth() + ", height=" + pf.getHeight());
    Logger.getGlobal().log(Level.INFO, "PageFormat {0}", pf);
    System.out.println("pageIndex " + pageIndex);
    Logger.getGlobal().log(Level.INFO, "pageIndex {0}", pageIndex);

    if (pageIndex == 0) {
      Graphics2D g2d = (Graphics2D) g;
      Font font = g2d.getFont();
      g2d.setFont(font.deriveFont((float) fontSize));

      g2d.translate(pf.getImageableX(), pf.getImageableY());
      g2d.setColor(Color.black);
      int step = g2d.getFont().getSize();
      step += step / 4;
      double y = paddingTop + g2d.getFont().getSize();
      for (String s : printStringList) {
        Logger.getGlobal().log(Level.INFO, "printStringList: {0}", s);
        g2d.drawString(s, (float) paddingLeft, (float) y);
        y += step;
      }

      // g2d.fillRect(0, 0, 200, 200);
      return Printable.PAGE_EXISTS;

    } else {
      return Printable.NO_SUCH_PAGE;
    }
  }
Ejemplo n.º 2
0
  public void draw(Graphics2D graphics, DrawingProperties properties) {
    Color startingcol = graphics.getColor();
    Font startingfont = graphics.getFont();
    graphics.setColor(Constants.COLOR_ERROR);
    graphics.setFont(Constants.FONT_CANVAS_SMALL);

    int w = cmptodraw.getWidth();
    int h = cmptodraw.getHeight();
    if (componentName == null) componentName = cmptodraw.getTypeName().toString();

    // draw a rectangle
    graphics.setColor(Color.WHITE);
    graphics.fillRect(EDGE_OFFSET, EDGE_OFFSET, w - 2 * EDGE_OFFSET, h - 2 * EDGE_OFFSET);
    graphics.setColor(Constants.COLOR_ERROR);
    graphics.drawRect(EDGE_OFFSET, EDGE_OFFSET, w - 2 * EDGE_OFFSET, h - 2 * EDGE_OFFSET);

    // draw invalidated sign
    graphics.drawLine(EDGE_OFFSET, EDGE_OFFSET, w - EDGE_OFFSET, h - EDGE_OFFSET);
    graphics.drawLine(EDGE_OFFSET, h - EDGE_OFFSET, w - EDGE_OFFSET, EDGE_OFFSET);

    // draw border
    int wmeo = w - EDGE_OFFSET;
    int hmeo = h - EDGE_OFFSET;
    for (int j = BORDER_LINES_STEP * 2; j <= hmeo; j += BORDER_LINES_STEP) {
      graphics.drawLine(0, j, EDGE_OFFSET, j - BORDER_LINES_STEP);
      graphics.drawLine(wmeo, j, w, j - BORDER_LINES_STEP);
    }
    for (int i = 0; i <= wmeo; i += BORDER_LINES_STEP) {
      graphics.drawLine(i, EDGE_OFFSET, i + BORDER_LINES_STEP, 0);
      graphics.drawLine(i, h, i + BORDER_LINES_STEP, hmeo);
    }

    // draw component type name and instance name
    if (properties.drawingComponentNames) {
      Font oldf = graphics.getFont();
      Color oldc = graphics.getColor();

      Font f = new Font(Constants.TEXT_FONT_CANVAS, Font.PLAIN, Constants.TEXT_NORMAL_FONT_SIZE);
      graphics.setFont(f);
      graphics.drawString(
          cmptodraw.getName().toString(), 0, -Constants.TEXT_NORMAL_FONT_SIZE * 1.5f);

      f = new Font(Constants.TEXT_FONT_CANVAS, Font.PLAIN, Constants.TEXT_SMALL_FONT_SIZE);
      int r = oldc.getRed() + 140;
      r = (r > 230) ? (230) : (r);
      int g = oldc.getGreen() + 140;
      g = (g > 230) ? (230) : (g);
      int b = oldc.getBlue() + 140;
      b = (b > 230) ? (230) : (b);
      graphics.setColor(new Color(r, g, b));
      graphics.setFont(f);
      graphics.drawString(componentName, 0, -Constants.TEXT_NORMAL_FONT_SIZE * 0.5f);

      graphics.setFont(oldf);
      graphics.setColor(oldc);
    }

    graphics.setColor(startingcol);
    graphics.setFont(startingfont);
  }
 protected void drawMultiplier(int xpix, int ypix, int exponent, Graphics2D g2) {
   Font oldFont = g2.getFont();
   g2.drawString("10", xpix, ypix); // $NON-NLS-1$
   g2.setFont(g2.getFont().deriveFont(Font.PLAIN, 9.0f));
   g2.drawString("" + exponent, xpix + 16, ypix - 6); // $NON-NLS-1$
   g2.setFont(oldFont);
 }
Ejemplo n.º 4
0
  @Override
  void myRendering(Graphics2D display, AffineTransform boxTransform) {

    Rectangle visRect = getComponent().getVisibleRect();

    display.setBackground(Color.WHITE);
    display.clearRect(visRect.x, visRect.y, visRect.width, visRect.height);

    final String logo = getVisConfig().getLogo();
    if (logo != null && logo.length() > 0) {

      int targetLogoHeight = visRect.height * 8 / 10;
      int targetLogoWidth = visRect.width * 9 / 10;

      display.setFont(new Font(display.getFont().getName(), Font.BOLD, targetLogoHeight));
      int trueLogoWidth = display.getFontMetrics().stringWidth(logo);

      double scaling = Math.min((double) targetLogoWidth / trueLogoWidth, 1);

      int scaledLogoHeight = (int) Math.round(scaling * targetLogoHeight);
      display.setFont(new Font(display.getFont().getName(), Font.PLAIN, scaledLogoHeight));
      int scaledLogoWidth = display.getFontMetrics().stringWidth(logo);

      display.setColor(Color.LIGHT_GRAY);

      int xCoord = visRect.x + (visRect.width - scaledLogoWidth) / 2;
      int yCoord = visRect.y + (visRect.height + scaledLogoHeight) / 2;

      display.drawString(logo, xCoord, yCoord);
    }
  }
  public int getBitmapFontRAMUsage() {
    BufferedImage image = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(
        RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, bitmapAntialiasing);
    g2d.setFont(java.awt.Font.decode(lookupFont));
    FontMetrics metrics = g2d.getFontMetrics();
    FontRenderContext context = g2d.getFontRenderContext();
    int baseline = (int) Math.ceil(metrics.getMaxAscent());
    int[] offsets = new int[bitmapCharset.length()];
    int[] widths = new int[offsets.length];
    int currentOffset = 0;
    for (int iter = 0; iter < bitmapCharset.length(); iter++) {
      offsets[iter] = currentOffset;
      String currentChar = bitmapCharset.substring(iter, iter + 1);
      g2d.drawString(currentChar, currentOffset, baseline);
      Rectangle2D rect = g2d.getFont().getStringBounds(currentChar, context);
      widths[iter] = (int) Math.ceil(rect.getWidth());

      // max advance works but it makes a HUGE image in terms of width which
      // occupies more ram
      if (g2d.getFont().isItalic()) {
        currentOffset += metrics.getMaxAdvance();
      } else {
        currentOffset += widths[iter] + 1;
      }
    }
    g2d.dispose();
    return currentOffset * getHeight() * 4;
  }
  @Override
  public void drawString(String string, BoundingBox2d bounds, double padding) {
    FontMetrics metrics = pipe.getFontMetrics(pipe.getFont());

    final double stringWidth = metrics.stringWidth(string);
    final double stringHeight = metrics.getHeight();

    // calculate scale, so that bb fits into bounds - padding
    final double sx = bounds.getWidth() / (stringWidth + padding);
    final double sy = bounds.getHeight() / (stringHeight + padding);

    final double scale = Math.min(sx, sy);

    java.awt.Font oldFont = pipe.getFont();
    java.awt.Font scaledFont = oldFont.deriveFont((float) (oldFont.getSize2D() * scale));

    // position b inside bounds
    final double x = bounds.getLocation().getX() + (bounds.getWidth() - stringWidth * scale) / 2;
    final double y =
        bounds.getLocation().getY()
            + bounds.getHeight()
            - (bounds.getHeight() - scaledFont.getSize2D()) / 2;

    pipe.setFont(scaledFont);
    try {
      pipe.drawString(string, (float) x, (float) y);
    } finally {
      pipe.setFont(oldFont);
    }
  }
Ejemplo n.º 7
0
  @Override
  public Point paint(Graphics2D g2, Point p) {

    Position = p;

    Font tmp = g2.getFont();
    g2.setFont(new Font("SansSerif", Font.PLAIN, 18));
    Rectangle2D NBounds =
        g2.getFont().getStringBounds(Integer.toString(currentNumber), g2.getFontRenderContext());

    g2.draw(
        Arrow2D.getArrow(
            new Point(
                (int) (getPosition().getX() + NBounds.getCenterX()),
                (int) (getPosition().getY() - NBounds.getHeight())),
            new Point(
                (int) (getPosition().getX() + NBounds.getCenterX()), (int) getPosition().getY()),
            8,
            30));

    g2.drawString(
        Integer.toString(currentNumber),
        (float) Position.getX(),
        (float) (Position.getY() - NBounds.getHeight()));

    g2.setFont(tmp);

    ShapeSize =
        new Rectangle2D.Double(0, 0, NBounds.getWidth(), NBounds.getHeight() + NBounds.getHeight());

    return new Point((int) (p.getX() + ShapeSize.getWidth()), (int) p.getY());
  }
  /** @return the bitmapFont */
  public Font getBitmapFont() {
    Font bitmapFont = Font.getBitmapFont(lookupFont);
    if (bitmapFont != null) {
      return bitmapFont;
    }

    BufferedImage image = new BufferedImage(5000, 50, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(
        RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, bitmapAntialiasing);
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
    g2d.setColor(new Color(0xff0000));
    g2d.setFont(java.awt.Font.decode(lookupFont.split(";")[0]));
    FontMetrics metrics = g2d.getFontMetrics();
    FontRenderContext context = g2d.getFontRenderContext();
    int height = (int) Math.ceil(metrics.getMaxDescent() + metrics.getMaxAscent());
    int baseline = (int) Math.ceil(metrics.getMaxAscent());
    String charsetStr = bitmapCharset;
    int[] offsets = new int[charsetStr.length()];
    int[] widths = new int[offsets.length];
    int currentOffset = 0;
    for (int iter = 0; iter < charsetStr.length(); iter++) {
      offsets[iter] = currentOffset;
      String currentChar = charsetStr.substring(iter, iter + 1);
      g2d.drawString(currentChar, currentOffset, baseline);
      Rectangle2D rect = g2d.getFont().getStringBounds(currentChar, context);
      widths[iter] = (int) Math.ceil(rect.getWidth());

      // max advance works but it makes a HUGE image in terms of width which
      // occupies more ram
      if (g2d.getFont().isItalic()) {
        currentOffset += metrics.getMaxAdvance();
      } else {
        currentOffset += widths[iter] + 1;
      }
    }

    g2d.dispose();
    BufferedImage shrunk = new BufferedImage(currentOffset, height, BufferedImage.TYPE_INT_RGB);
    g2d = (Graphics2D) shrunk.getGraphics();
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();

    int[] rgb = new int[shrunk.getWidth() * shrunk.getHeight()];
    shrunk.getRGB(0, 0, shrunk.getWidth(), shrunk.getHeight(), rgb, 0, shrunk.getWidth());
    com.sun.lwuit.Image bitmap =
        com.sun.lwuit.Image.createImage(rgb, shrunk.getWidth(), shrunk.getHeight());

    return com.sun.lwuit.Font.createBitmapFont(lookupFont, bitmap, offsets, widths, charsetStr);
  }
Ejemplo n.º 9
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);
   }
 }
Ejemplo n.º 10
0
  /**
   * Get the text layouts for display if the string has changed since last call to this method
   * regenerate them.
   *
   * @param g2d Graphics2D display context
   * @return a list of text layouts for rendering
   */
  public LinkedList<LineInfo> getLines(Graphics2D g2d) {
    if (font != g2d.getFont()) {
      setFont(g2d.getFont());
      invalidText = true;
    }
    if (invalidText) {
      styledText = new AttributedString(plainText);
      setFont(font);
      applyAttributes();
      invalidText = false;
      invalidLayout = true;
    }
    if (invalidLayout) {
      linesInfo.clear();
      if (plainText.length() > 0) {
        textHeight = 0;
        maxLineLength = 0;
        maxLineHeight = 0;
        nbrLines = 0;
        AttributedCharacterIterator paragraph = styledText.getIterator(null, 0, plainText.length());
        FontRenderContext frc = g2d.getFontRenderContext();
        lineMeasurer = new LineBreakMeasurer(paragraph, frc);
        float yposinpara = 0;
        int charssofar = 0;
        while (lineMeasurer.getPosition() < plainText.length()) {
          TextLayout layout = lineMeasurer.nextLayout(wrapWidth);
          float advance = layout.getVisibleAdvance();
          if (justify) {
            if (justify && advance > justifyRatio * wrapWidth) {
              // If advance > breakWidth then we have a line break
              float jw = (advance > wrapWidth) ? advance - wrapWidth : wrapWidth;
              layout = layout.getJustifiedLayout(jw);
            }
          }
          // Remember the longest and tallest value for a layout so far.
          float lh = getHeight(layout);
          if (lh > maxLineHeight) maxLineHeight = lh;
          textHeight += lh;
          if (advance <= wrapWidth && advance > maxLineLength) maxLineLength = advance;

          // Store layout and line info
          linesInfo.add(
              new LineInfo(nbrLines, layout, charssofar, layout.getCharacterCount(), yposinpara));
          charssofar += layout.getCharacterCount();
          yposinpara += lh;
          nbrLines++;
        }
      }
      invalidLayout = false;
    }
    return linesInfo;
  }
Ejemplo n.º 11
0
  public void init(Graphics2D g, float scale, int width, int height) {
    if (this.METRICS == null) {
      AffineTransform transform = g.getTransform();
      if (Double.compare(transform.getScaleX(), 1) != 0
          || Double.compare(transform.getScaleY(), 1) != 0) {
        throw new IllegalStateException("Illegal Transform");
      }

      this.METRICS = new FontMetrics[FONTS.length];
      Font defaultFont = g.getFont();
      for (int i = 0; i < FONTS.length; i++) {
        g.setFont(FONTS[i]);
        this.METRICS[i] = g.getFontMetrics();
      }
      g.setFont(defaultFont);
    }

    this.g = g;
    this.scale = scale;
    this.screen.width = width;
    this.screen.height = height;
    this.lapList.clear();
    this.fixedLabelMap.clear();

    this.r = (int) (2 / this.scale + 0.5);
    this.r2 = (int) (4 / this.scale + 0.5);
  }
Ejemplo n.º 12
0
  @Override
  public void renderHUD(Graphics2D g) {
    // TODO Auto-generated method stub
    super.renderHUD(g);

    g.drawImage(HUDBg, 0, 0, null);

    if (player.weapon != null) {

      g.drawImage(player.weapon.getHUDImage(), 123, 121, null);

      float wh = (player.weapon.bulletsLeft / (float) player.weapon.bulletsCapacity);
      drawHealth(g, wh, 121, 137, 36, 4);
    }

    // player health
    drawHealth(g, player.health / (float) player.maxHealth, 3, 137, 36, 4);

    Font f = g.getFont();
    g.setColor(Color.black);
    g.setFont(f.deriveFont(4));
    Text.drawText(g, String.format("%05d", score), 130, 5);

    Text.drawText(
        g, String.format("Day: %d", (int) Math.ceil(realtime / (float) secondsPerDay)), 66, 136);

    if (menu != null) {
      menu.render(g);
    }
  }
Ejemplo n.º 13
0
 public static void drawAtPoint(String texttodisplay, CGPoint point, UIFont font) {
   Graphics2D graphicsContext = CGContext.UICurrentContext().xmlvmGetGraphics2D();
   Font savedFont = graphicsContext.getFont();
   graphicsContext.setFont(font.xmlvmGetFont());
   graphicsContext.drawString(texttodisplay, point.x, point.y);
   graphicsContext.setFont(savedFont);
 }
Ejemplo n.º 14
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    final Graphics2D g2d = (Graphics2D) g;

    // Turn AA on
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final Font original = g2d.getFont();

    if (value != null) {
      String text = value.toString();
      final int textLen = text.length();

      g2d.translate(leftPad, (c.getHeight()) / 2);

      g2d.setColor(color);
      if (textLen > MAX_TEXT_LEN) {
        text = text.substring(0, 5) + "...";
        g2d.setFont(FONT_SMALL);
      } else g2d.setFont(FONT);

      g2d.drawString(text, 0, 0);
      g2d.translate(-leftPad, -((c.getHeight()) / 2));
    }

    g2d.setFont(original);
  }
Ejemplo n.º 15
0
  @Override
  public final void pintar(Graphics2D g) {

    Graphics2D gBloque = (Graphics2D) g.create();
    pintarBloque(gBloque);
    gBloque.dispose();

    if (ayudaVisible) {
      final int altura = FUENTE * (ayudasMST.size() + ayudasBloque.size()) + MARGEN;
      int y = MetalSlugT.getAlto() - altura;
      g.setColor(Color.BLACK);
      g.fillRect(0, y, MetalSlugT.getAncho(), altura);

      g.setColor(Color.GREEN);
      g.setFont(g.getFont().deriveFont((float) FUENTE));
      for (String str : ayudasMST) {
        y += FUENTE;
        g.drawString(str, MARGEN, y);
      }
      for (String str : ayudasBloque) {
        y += FUENTE;
        g.drawString(str, MARGEN, y);
      }
    }
  }
Ejemplo n.º 16
0
    private static void drawChain(
        GrandFinale.Graph g, GrandFinale.Node n, List<GrandFinale.Node> ignore) {
      MazeGridPanel panel = getPanel();
      Color c = panel.getGraphics().getColor();
      Graphics2D g2 = (Graphics2D) panel.getGraphics();
      Font fOld = g2.getFont();
      g2.setFont(new Font("Arial", Font.BOLD, fOld.getSize()));
      ignore.add(n);

      Set<GrandFinale.Edge> edges = g.getEdges(n);
      if (edges == null) {
        return;
      }
      for (GrandFinale.Edge e : edges) {
        GrandFinale.Node b = e.other(n);
        if (ignore.contains(b)) {
          continue;
        }
        int hs = b.hashCode();
        g2.setColor(new Color(((hs << 13) + (hs << 5) + hs) & 0xFFFFFFFF));
        g2.setStroke(new BasicStroke(5));
        Point pos1 = offset(panel, n.getPoint(), 2, 2);
        Point pos2 = offset(panel, b.getPoint(), 2, 2);
        g2.draw(new Line2D.Float(pos1.x, pos1.y, pos2.x, pos2.y));
        g2.setColor(Color.red);
        Point p = new Point((pos1.x + pos2.x) / 2, (pos1.y + pos2.y) / 2);
        g2.drawString(String.valueOf(e.getWeight()), p.x, p.y);
        ignore.add(b);
        drawChain(g, b, ignore);
      }
      g2.setFont(fOld);
      g2.setColor(c);
    }
Ejemplo n.º 17
0
 public static void drawAdHoc(Graphics2D g2, int x, int y) {
   Font oldFont = g2.getFont();
   g2.setFont(new Font("Arial", Font.BOLD, 28));
   g2.setPaint(Color.BLACK);
   g2.drawString("~", x - MARKER_ICON_SIZE, y + MARKER_ICON_SIZE);
   g2.setFont(oldFont);
 }
  /**
   * Gets the bounds of the label text
   *
   * @param g2 the graphics context
   * @return the bounds of the label text
   */
  private Rectangle2D getLabelBounds() {
    BufferedImage dummy = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    // need a dummy image to get a Graphics to
    // measure the size
    Graphics2D g2 = (Graphics2D) dummy.getGraphics();

    label.setText("<html>" + labelText + "</html>");
    label.setFont(g2.getFont());
    Dimension d = label.getPreferredSize();
    label.setBounds(0, 0, d.width, d.height);

    Line2D line = getConnectionPoints();
    Point2D control = getControlPoint();
    double x = control.getX() / 2 + line.getX1() / 4 + line.getX2() / 4;
    double y = control.getY() / 2 + line.getY1() / 4 + line.getY2() / 4;

    final int GAP = 3;
    if (line.getY1() == line.getY2()) x -= d.getWidth() / 2;
    else if (line.getY1() <= line.getY2()) x += GAP;
    else x -= d.getWidth() + GAP;

    if (line.getX1() == line.getX2()) y += d.getHeight() / 2;
    else if (line.getX1() <= line.getX2()) y -= d.getHeight() + GAP;
    else y += GAP;
    if (Math.abs(line.getX1() - line.getX2()) >= Math.abs(line.getY1() - line.getY2())) {
      x = x - d.getWidth() / 2;
    }
    if (Math.abs(line.getX1() - line.getX2()) <= Math.abs(line.getY1() - line.getY2())) {
      y = y - d.getHeight() / 2;
    }
    return new Rectangle2D.Double(x, y, d.width, d.height);
  }
Ejemplo n.º 19
0
  /**
   * Draw a string with given reference point and rotation angle. (0.5, 0.5) is center, (0, 0) is
   * lower left, (1, 0) is upper left, etc. The angle of rotation is in radians. The logical are
   * proportional to the base coordinates.
   */
  public void drawTextBaseRatio(
      String label,
      double horizontalReference,
      double verticalReference,
      double rotation,
      double[] coord) {
    int[] sc = projection.screenProjectionBaseRatio(coord);
    int x = sc[0];
    int y = sc[1];

    AffineTransform transform = g2d.getTransform();

    // Corner offset adjustment : Text Offset is used Here
    FontRenderContext frc = g2d.getFontRenderContext();
    Font font = g2d.getFont();
    double w = font.getStringBounds(label, frc).getWidth();
    double h = font.getSize2D();

    if (rotation != 0) {
      g2d.rotate(rotation, x, y);
    }

    x -= (int) (w * horizontalReference);
    y += (int) (h * verticalReference);

    g2d.drawString(label, x, y);

    g2d.setTransform(transform);
  }
Ejemplo n.º 20
0
  @Override
  public final void paint(Graphics g) {

    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    Composite old = g2.getComposite(); // Store non-transparent composite

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); // 40% transparency
    g2.drawRect(0, 0, getWidth() - 1, getHeight() - 1);

    Font drawFont = g2.getFont();
    g2.setFont(notificationFont);
    adaptDimensions();

    int textX = 5;
    int textY = (getHeight() / 2 + 3);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); // 70% transparency
    g2.drawString(message, textX, textY);

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.05f)); // 5% transparency
    g2.setColor(java.awt.Color.blue);
    g2.fillRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
    g2.setComposite(old);
    g2.setFont(drawFont);
  }
Ejemplo n.º 21
0
  public void render(Graphics2D g, Dimension d) {
    int n = this.problemScore.getAttempts();
    n += this.problemScore.getPendings();
    String text = "" + n;
    Color baseColor;
    if (this.problemScore.isSolved()) {
      baseColor = Color.GREEN;
      text += " / " + this.problemScore.getSolutionTime();
    } else if (this.problemScore.isPending()) {
      baseColor = Color.BLUE.brighter();
    } else if (this.problemScore.getAttempts() > 0) {
      baseColor = Color.RED;
    } else {
      baseColor = new Color(0, 0, 0, 0);
    }
    // g.fillRect(0, 0, d.width, d.height);
    ShadedRectangle.drawShadedRoundRect(g, baseColor, 0, 0, d.width, d.height, d.height / 3f);
    g.setColor(Color.BLACK);

    Font backup = g.getFont();
    double magicScale = d.height / 20f;
    Font nfont = backup.deriveFont(AffineTransform.getScaleInstance(magicScale, magicScale));
    Rectangle2D rect = new Rectangle2D.Float(0, 0, d.width, d.height);
    Utility.drawString3D(g, text, rect, nfont, Alignment.center);
  }
Ejemplo n.º 22
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();
  }
Ejemplo n.º 23
0
  public void paint(Graphics2D g) {
    Font origFont = g.getFont();

    g.setRenderingHint(
        java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);

    // 1) create scaled font
    Font font = origFont.deriveFont(AffineTransform.getScaleInstance(1.5, 3));
    g.setFont(font);
    g.drawString("Scaled Font", 20, 40);

    // 2) create translated font
    font = origFont.deriveFont(AffineTransform.getTranslateInstance(50, 20));
    g.setFont(font);
    g.drawString("Translated Font", 20, 80);
    g.drawLine(20, 80, 120, 80);

    // 3) create sheared font
    font = origFont.deriveFont(AffineTransform.getShearInstance(.5, .5));
    g.setFont(font);
    g.drawString("Sheared Font", 20, 120);

    // 4) create rotated font
    font = origFont.deriveFont(AffineTransform.getRotateInstance(Math.PI / 4));
    g.setFont(font);
    g.drawString("Rotated Font", 220, 120);
  }
Ejemplo n.º 24
0
  @Override
  protected void paintIcon(
      java.awt.Component c,
      java.awt.Graphics2D g2,
      int width,
      int height,
      java.awt.Paint fillPaint,
      java.awt.Paint drawPaint) {
    java.awt.Font prevFont = g2.getFont();
    g2.setFont(font);

    String text = "A";
    java.awt.FontMetrics fm = g2.getFontMetrics();
    int messageWidth = fm.stringWidth(text);
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDescent();
    int x = (width / 2) - (messageWidth / 2);
    int y = ((height / 2) + (ascent / 2)) - (descent / 2);

    java.awt.font.GlyphVector glyphVector = font.createGlyphVector(g2.getFontRenderContext(), text);
    java.awt.Shape outline = glyphVector.getOutline(x, y);
    g2.setPaint(drawPaint);
    g2.draw(outline);

    g2.setPaint(fillPaint);
    g2.fill(outline);
    //		g2.drawString( text, x, y );

    g2.setFont(prevFont);
  }
Ejemplo n.º 25
0
  public void drawPoolOrLane(String name, int x, int y, int width, int height) {
    g.drawRect(x, y, width, height);

    // Add the name as text, vertical
    if (name != null && name.length() > 0) {
      // Include some padding
      int availableTextSpace = height - 6;

      // Create rotation for derived font
      AffineTransform transformation = new AffineTransform();
      transformation.setToIdentity();
      transformation.rotate(270 * Math.PI / 180);

      Font currentFont = g.getFont();
      Font theDerivedFont = currentFont.deriveFont(transformation);
      g.setFont(theDerivedFont);

      String truncated = fitTextToWidth(name, availableTextSpace);
      int realWidth = fontMetrics.stringWidth(truncated);

      g.drawString(
          truncated,
          x + 2 + fontMetrics.getHeight(),
          3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2);
      g.setFont(currentFont);
    }
  }
Ejemplo n.º 26
0
  @Override
  public void draw(Graphics2D g) {
    for (BBox box : walls) {
      camera.draw(box);
    }

    for (BBox box : platforms) {
      camera.draw(box);
    }

    camera.draw(character1);

    camera.drawCamera();
    if (black) {
      camera.drawClear(g);
      g.setColor(Color.WHITE);
    } else {
      camera.drawWhite(g);
    }
    g.setFont(g.getFont().deriveFont(Font.PLAIN, 12));
    g.drawString("Max speed: " + character1.getMaxSpeed(), 10, 10);
    g.drawString("Acceleration: " + character1.getAcceleration(), 10, 20);
    g.drawString("Friction: " + character1.getFriction(), 10, 30);
    g.drawString("Jump: " + character1.getJump(), 10, 40);
    g.drawString("Gravity: " + character1.getGravity(), 10, 50);
    g.drawString("----------------" + character1.getGravity(), 10, 60);
    g.drawString("Controls: ", 10, 70);
    g.drawString("--------", 10, 80);
    g.drawString("q, a, w, s, e, d", 10, 90);
    g.drawString("r, f, t, g, c, v, b", 10, 100);
  }
Ejemplo n.º 27
0
 /**
  * Renders the given range in the model as normal unselected text. This is implemented to paint
  * colors based upon the token-to-color translations.
  *
  * @param g the graphics context
  * @param x the starting X coordinate
  * @param y the starting Y coordinate
  * @param start the beginning position in the model
  * @param end the ending position in the model
  * @returns the location of the end of the range
  * @exception BadLocationException if the range is invalid
  */
 @Override
 protected int drawUnselectedText(Graphics g, int x, int y, int start, int end)
     throws BadLocationException {
   DocumentImpl doc = (DocumentImpl) getDocument();
   Graphics2D g2 = (Graphics2D) g;
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
   g2.setRenderingHint(
       RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
   int mark = start;
   Segment text = new Segment();
   for (Token token : doc.getTokensInRange(start, end)) {
     int endPosition = Math.min(token.getEndOffset(), end);
     token.accept(gd.setGraphics(g2));
     doc.getText(mark, endPosition - mark, text);
     x = Utilities.drawTabbedText(text, x, y, g, this, mark);
     mark = endPosition;
   }
   // tokens may not reach to the end of the area we want rendered
   // so this will make up the remaining space
   if (end != mark) {
     doc.getText(mark, end - mark, text);
     x = Utilities.drawTabbedText(text, x, y, g, this, mark);
   }
   g2.setFont(g2.getFont().deriveFont(Font.PLAIN));
   return x;
 }
  @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();
  }
Ejemplo n.º 29
0
 /**
  * Draws this multi-line string inside a given rectangle.
  *
  * @param pGraphics2D the graphics context
  * @param pRectangle the rectangle into which to place this multi-line string
  */
 public void draw(Graphics2D pGraphics2D, Rectangle2D pRectangle) {
   JLabel label = getLabel();
   label.setFont(pGraphics2D.getFont());
   label.setBounds(0, 0, (int) pRectangle.getWidth(), (int) pRectangle.getHeight());
   pGraphics2D.translate(pRectangle.getX(), pRectangle.getY());
   label.paint(pGraphics2D);
   pGraphics2D.translate(-pRectangle.getX(), -pRectangle.getY());
 }
Ejemplo n.º 30
0
  @Override
  public void draw(Graphics2D g) {
    g.setColor(Color.WHITE);

    Font oldfont = g.getFont();
    g.setFont(oldfont.deriveFont((float) oldfont.getSize()));
    g.drawString("Score: " + Long.toString(GameEngine.getInstance().getP2Score()), x, y);
    g.setFont(oldfont);
  }