/**
   * Draws as much as possible of a given string into a 2d square region in a graphical space.
   *
   * @param g component onto which to draw
   * @param f font to use in drawing the string
   * @param s string to be drawn
   * @param xPos
   * @param yPos
   * @param width
   * @param height
   */
  public static void drawStringMultiline(
      Graphics2D g, Font f, String s, double xPos, double yPos, double width, double height) {
    FontMetrics fm = g.getFontMetrics(f);
    int w = fm.stringWidth(s);
    int h = fm.getAscent();
    // g.setColor(Color.LIGHT_GRAY);
    g.setColor(Color.BLACK);
    g.setFont(f);

    Scanner lineSplitter = new Scanner(s);
    // draw as much as can fit in each item
    // read all content from scanner, storing in string lists (where each string == 1 line), each
    // string should be as long as possible without overflowing the space
    int maxRows = (int) height / h;
    List<String> textRows = new ArrayList<>();
    while (lineSplitter.hasNextLine() && textRows.size() < maxRows) {
      String line = lineSplitter.nextLine();
      // if line is blank, insert to maintain paragraph seps
      if (line.trim().equals("")) {
        textRows.add("");
      }
      // else, pass to inner loop
      StringBuilder currentBuilder = new StringBuilder();
      int currentStrWidth = 0;
      Scanner splitter = new Scanner(line);
      while (splitter.hasNext() && textRows.size() < maxRows) {
        String token = splitter.next() + " ";
        // TODO incorporate weight detection, formatting for token?
        currentStrWidth += fm.stringWidth(token);
        if (currentStrWidth >= width) {
          // if string length >= glyph width, build row
          textRows.add(currentBuilder.toString());
          currentBuilder = new StringBuilder();
          currentBuilder.append(token);
          currentStrWidth = fm.stringWidth(token);
        } else {
          // if not yet at end of row, append to builder
          currentBuilder.append(token);
        }
      }

      // if we've still space and still have things to write, add them here
      if (textRows.size() < maxRows) {
        textRows.add(currentBuilder.toString());
        currentBuilder = new StringBuilder();
        currentStrWidth = 0;
      }
    }

    // write each line to object
    for (int t = 0; t < textRows.size(); t++) {
      String line = textRows.get(t);
      if (fm.stringWidth(line) <= width) {
        // ensure that string doesn't overflow the box
        //                g.drawString(line, (float) (xPos-(width/2.)), (float) (yPos-(height/2.) +
        // h * (t+1)));
        g.drawString(line, (float) xPos, (float) (yPos + h * (t + 1)));
      }
    }
  }
Example #2
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);
    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }
    if (gameOver) return;
    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    for (int index = 0; index < missile.length; index++) {
      if (missile[index].active) {
        g.setColor(Color.red);
        drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5);
      }
    }
    if (rocketRight) {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0);
    } else {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0);
    }
    for (int index = 0; index < numStars; index++) {
      g.setColor(Color.yellow);
      if (starActive[index])
        drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5);
    }
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Score: " + score, 10, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("HighScore: " + highScore, 300, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Lives: " + rocketLife, 150, 45);
    if (rocketLife == 0) {
      g.setColor(Color.red);
      g.setFont(new Font("Impact", Font.BOLD, 60));
      g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2));
    }
    gOld.drawImage(image, 0, 0, null);
  }
Example #3
0
  /**
   * Draw method
   *
   * @param g2 Graphics element
   * @param select Selected node
   */
  public void draw(Graphics2D g2, boolean select) {
    Point pinit = new Point(centre.x - 25, centre.y - 25);
    Point pfin = new Point(centre.x + 25, centre.y + 25);
    figure =
        new RoundRectangle2D.Float(
            pinit.x, pinit.y, Math.abs(pfin.x - pinit.x), Math.abs(pfin.y - pinit.y), 20, 20);

    g2.setColor(Color.black);
    if (select) {
      Stroke s = g2.getStroke();
      g2.setStroke(
          new BasicStroke(
              5, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {1, 1}, 0));
      g2.draw(figure);
      g2.setStroke(s);
    } else {
      g2.draw(figure);
    }
    g2.drawImage(image, centre.x - 25, centre.y - 25, 50, 50, pd);

    g2.setFont(new Font("Courier", Font.BOLD + Font.ITALIC, 12));
    FontMetrics metrics = g2.getFontMetrics();
    int width = metrics.stringWidth(dsc.getName());
    int height = metrics.getHeight();
    g2.drawString(dsc.getName(), centre.x - width / 2, centre.y + 40);
  }
Example #4
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);
      }
    }
Example #5
0
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String message = "Hello, World!";

    Font f = new Font("Serif", Font.BOLD, 36);
    g2.setFont(f);

    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D bounds = f.getStringBounds(message, context);

    double x = (getWidth() - bounds.getWidth()) / 2;
    double y = (getHeight() - bounds.getHeight()) / 2;

    double ascent = -bounds.getY();
    double baseY = y + ascent;

    g2.drawString(message, (int) x, (int) baseY);

    g2.setPaint(Color.LIGHT_GRAY);

    g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY));
    Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());
    g2.draw(rect);
  }
Example #6
0
  public void paintComponent(Graphics g) {
    // необходиом чтобы текст коректно отрисовывался в окне
    super.paintComponent(g);
    // рисуем текст в окне
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform t = g2.getTransform();
    g.drawString("It is text", 5, 5);
    // создание шрифта
    Font f = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f);
    g2.drawString("It is new text", 5, 33);
    String[] fontNames =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 5; i < 20; i++) {
      g2.rotate(-0.05);
      g2.setColor(
          new Color(
              (int) (Math.random() * 255),
              (int) (Math.random() * 255),
              (int) (Math.random() * 255)));
      Font f1 = new Font(fontNames[i], Font.BOLD, 20);
      g2.setFont(f1);
      g2.drawString(fontNames[i], 5, 20 * i);
    }
    // текст в центре

    g2.setTransform(t); // возращение к кординатам, которые запонилив начале
    Font f2 = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f2);
    String s = "It is center!";
    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D r = f2.getStringBounds(s, context);
    double x1 = (getWidth() - r.getWidth()) / 2;
    double y1 = (getHeight() - r.getHeight()) / 2;
    double ascent = -r.getY(); // узнаем высоту текста
    double y2 = y1 + ascent;
    Rectangle2D rect = new Rectangle2D.Double(x1, y1, r.getWidth(), r.getHeight());
    g2.setColor(Color.YELLOW);
    g2.fill(rect);
    g2.setColor(Color.red);
    g2.drawString(s, (int) x1, (int) y2);
    g2.setColor(Color.blue);
    g2.draw(new Line2D.Double(x1, y2, x1 + r.getWidth(), y2));

    g2.draw(rect);
  }
Example #7
0
 public void draw(Graphics2D g2, boolean shouldFlip) {
   Font font = new Font("Sans_Serif", Font.PLAIN, 30);
   g2.setColor(Color.orange);
   g2.fillOval((int) x - 10, (int) (FieldConstants.FIELD_HEIGHT - y - 10), 20, 20);
   font = new Font("Sans_Serif", Font.PLAIN, 18);
   g2.setFont(font);
   g2.drawString(Double.toString(confidence), x, FieldConstants.FIELD_HEIGHT - y + 60);
 }
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();
 }
  /** Draw vertices on top of the edge structure */
  public void drawNodes(Graphics2D gg) {
    Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
    // Run through the traversal and draw each vertex
    // using an Ellipse2D
    // The draw point has been determined previously in
    // calcNodeCoords()
    while (nodeList.hasMoreElements()) {
      TreeVertex vertex = (TreeVertex) nodeList.nextElement();
      // Don't draw virtual nodes
      if (vertex.isVirtual()) continue;

      // If tree is incomplete and we're on the top layer, skip it
      if (argument.isMultiRoots() && vertex.getLayer() == 0) continue;

      Point corner = vertex.getDrawPoint();
      Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM);
      vertex.setShape(node, this);

      // Fill the interior of the node with vertex's fillPaint
      gg.setPaint(vertex.fillPaint);
      gg.fill(node);

      // Draw the outline with vertex's outlinePaint; bold if selected
      gg.setPaint(vertex.outlinePaint);
      if (vertex.isSelected()) {
        gg.setStroke(selectStroke);
      } else {
        gg.setStroke(solidStroke);
      }
      gg.draw(node);

      // Draw the short label on top of the vertex
      gg.setPaint(vertex.textPaint);
      String shortLabelString = new String(vertex.getShortLabel());
      if (shortLabelString.length() == 1) {
        gg.setFont(labelFont1);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4);
      } else if (shortLabelString.length() == 2) {
        gg.setFont(labelFont2);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4);
      }
    }
  }
 public void draw(Graphics2D g) {
   g.setColor(fillColor);
   g.fill(gp);
   g.setColor(Color.black);
   g.draw(gp);
   for (int i = 0; i < points.size(); i++) {
     GlyphPoint p = points.get(i);
     g.setColor(Color.red);
     g.draw(p.gp);
     g.setColor(Color.blue);
     g.setFont(gfont);
     g.drawString(String.valueOf(i), p.x + 3, p.y + 3);
   }
   g.setColor(Color.black);
   //	    System.out.println("Advance: "+advance);
   g.draw(advp);
   if (name != null) {
     g.setFont(gfont);
     g.drawString(name, 0, -40);
   }
 }
Example #11
0
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;

      // paint ball, paddle, and brick configuration
      g2.drawImage(background.getImage(), 0, 0, null);
      bconfig.paint(g2);
      paddle.paint(g2);
      ball.paint(g2);
      g2.setColor(Color.WHITE);
      g2.setFont(new Font("Serif", Font.PLAIN, 20));
      g2.drawString("Score: " + score, 15, 20);
      if (ball.getY() > 500) {
        g2.setColor(Color.WHITE);
        g2.setFont(new Font("Serif", Font.PLAIN, 30));
        g2.drawString("Game Over!", 200, 300);
        g2.drawString("Your final score was " + score, 150, 330);
        timer.stop();
      }
    }
Example #12
0
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(Color.WHITE);
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   if (isDead) {
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 30));
     g2.drawString("Game Over!", 300, 300);
     g2.drawString("Your final score was " + score, 250, 330);
     moverTimer.stop();
     scoreTimer.stop();
   } else {
     topWall.paint(g2);
     bottomWall.paint(g2);
     bird.paint(g2);
     g2.setColor(Color.BLACK);
     g2.setFont(new Font("Serif", Font.PLAIN, 20));
     g2.drawString("Score: " + score, 50, 50);
   }
 }
Example #13
0
  /**
   * Method to draw a message as a string on the buffered image
   *
   * @param message the message to draw on the buffered image
   * @param xPos the x coordinate of the leftmost point of the string
   * @param yPos the y coordinate of the bottom of the string
   */
  public void addMessage(String message, int xPos, int yPos) {
    // get a graphics context to use to draw on the buffered image
    Graphics2D graphics2d = bufferedImage.createGraphics();

    // set the color to white
    graphics2d.setPaint(Color.white);

    // set the font to Helvetica bold style and size 16
    graphics2d.setFont(new Font("Helvetica", Font.BOLD, 16));

    // draw the message
    graphics2d.drawString(message, xPos, yPos);
  }
Example #14
0
 /**
  * Overrides Step draw method.
  *
  * @param panel the drawing panel requesting the drawing
  * @param _g the graphics context on which to draw
  */
 public void draw(DrawingPanel panel, Graphics _g) {
   if (track.trackerPanel == panel) {
     AutoTracker autoTracker = track.trackerPanel.getAutoTracker();
     if (autoTracker.isInteracting(track)) return;
   }
   if (panel instanceof TrackerPanel) {
     TrackerPanel trackerPanel = (TrackerPanel) panel;
     super.draw(trackerPanel, _g);
     Graphics2D g = (Graphics2D) _g;
     if (isLabelVisible()) {
       TextLayout layout = textLayouts.get(trackerPanel);
       if (layout == null) return;
       Point p = getLayoutPosition(trackerPanel);
       Paint gpaint = g.getPaint();
       Font gfont = g.getFont();
       g.setPaint(footprint.getColor());
       g.setFont(textLayoutFont);
       layout.draw(g, p.x, p.y);
       g.setPaint(gpaint);
       g.setFont(gfont);
     }
   }
 }
Example #15
0
 private synchronized void doBuffer(Graphics2D g2, boolean opq, Rectangle rt) {
   origTransform = g2.getTransform();
   if (opq && rt != null) g2.clearRect(rt.x, rt.y, rt.width, rt.height);
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   if (inBuffer) { // System.out.println("upps");
     for (int i = 0; i < a1x.size(); i++) doPaint(g2, a1x.get(i), a2x.get(i));
     origTransform = null;
     return;
   }
   for (int i = 0; i < a1.size(); i++) doPaint(g2, a1.get(i), a2.get(i));
   origTransform = null;
 }
Example #16
0
 protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) {
   // Calculate the width of the string.
   FontRenderContext frc = g2.getFontRenderContext();
   TextLayout subLayout = new TextLayout(s, mFont, frc);
   float advance = subLayout.getAdvance();
   // Fill the background rectangle with a gradient.
   GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2);
   g2.setPaint(gradient);
   Rectangle2D bounds = mLayout.getBounds();
   Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight());
   g2.fill(back);
   // Draw the string over the gradient rectangle.
   g2.setPaint(Color.white);
   g2.setFont(mFont);
   g2.drawString(s, (float) x, (float) -bounds.getY());
   return advance;
 }
Example #17
0
    /** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */
    @Override
    public void render(Graphics2D g, VisualItem item) {
      Shape s = getShape(item);
      GraphicsLib.paint(g, item, m_line, getStroke(item), getRenderType(item));

      // check if we have a text label, if so, render it
      String str;
      if (item.canGetString(VisualItem.LABEL)) {
        str = (String) item.getString(VisualItem.LABEL);
        if (str != null && !str.equals("")) {
          float x = (float) m_box.getMinX();
          float y = (float) m_box.getMinY() + m_ascent;

          // draw label background
          GraphicsLib.paint(g, item, s, null, RENDER_TYPE_FILL);

          AffineTransform origTransform = g.getTransform();
          AffineTransform transform = this.getTransform(item);
          if (transform != null) {
            g.setTransform(transform);
          }

          g.setFont(item.getFont());
          g.setColor(ColorLib.getColor(item.getTextColor()));

          if (!(str.length() > 5
              && str.substring(str.length() - 5, str.length()).equals("_last"))) {

            g.setColor(Color.WHITE);
            // TODO properly hunt down source of null str! for now, triage
            if (str != null) {
              // bump y down by appropriate amount
              FontMetrics fm = g.getFontMetrics(item.getFont());
              int strHeight = fm.getAscent();
              //                        g.drawString(str, x, y);
              g.drawString(str, x, y + strHeight);
            }

            if (transform != null) {
              g.setTransform(origTransform);
            }
          }
        }
      }
    }
Example #18
0
 void renderUI(Graphics2D g2d) {
   g2d.setFont(new Font("Courier New", Font.PLAIN, 12));
   g2d.setColor(Color.white);
   if (removeMode) g2d.setColor(Color.black);
   if (player.health < 0) player.health = 0;
   g2d.drawString(String.format("Helath: %s", player.health), 10, 20);
   g2d.drawString(String.format("Kills: %s", player.score), 10, 40);
   int WLevel = (Integer) player.weapon[player.currentWeapon][10];
   if (WLevel == 5)
     g2d.drawString(String.format("Current Weapon: %s:Max", player.currentWeapon), 10, 60);
   else
     g2d.drawString(String.format("Current Weapon: %s:%s", player.currentWeapon, WLevel), 10, 60);
   g2d.setColor(Color.gray);
   g2d.drawString(String.format("Level: %s", difficulty), 10, 80);
   g2d.setColor(Color.black);
   if (showDebug) g2d.drawString(String.format("FPS: %s", fps), 10, 100);
   if (cheated) g2d.drawString("You cheated, no highscore will be saved", 200, height - 15);
 }
Example #19
0
  /**
   * A rendering method to draw this label to the given Graphics2D object, with the additional
   * option of allowing the "long" lines to be drawn. Due to the fact that the relative drawing
   * point of a state is its x and y co-ordinates and for a Transition there is a workOutMiddle()
   * method, the relative x and y values must be supplied to this method. Usually this method will
   * be called from inside a Transition render method or a State render method.
   *
   * @param g2 the Graphics2D component upon which to draw this label.
   * @param x the x position upon which to make relative co-ordinates exact.
   * @param y the y position upon which to make relative co-ordinates exact.
   * @param longLines flag to determine whether the long version of this label should be drawn.
   */
  public void render(Graphics2D g2, double x, double y, boolean longLines) {
    intersects(new Rectangle2D.Double(0, 0, 1, 1));
    StringTokenizer tokens = new StringTokenizer(getRenderString(), "\n");
    if (selected) {
      g2.setColor(Color.green);
    } else {
      g2.setColor(theColour);
    }
    g2.setFont(theFont);
    int i = 0;
    boolean doneLong = false;
    while (tokens.hasMoreTokens()) {
      if (doneLong)
        g2.drawString(
            tokens.nextToken(),
            (float) (x + offsetX),
            (float) (y + offsetY + ((i * (theFont.getSize() + 2)))));
      else {
        if (!longLines)
          g2.drawString(
              tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
        else
          g2.drawString(
              getName() + ": " + tokens.nextToken().trim(),
              (float) (x + offsetX),
              (float) (y + offsetY + ((i * (theFont.getSize()))) + 2));
      }
      i++;
      doneLong = true;
    }

    /*if(intersects != null)
    {
        g2.setColor(Color.magenta);
        for(int j = 0; j < intersects.size(); j++)
        {
            Rectangle2D rect = (Rectangle2D)intersects.get(j);
            g2.draw(rect);
        }
    }*/

  }
Example #20
0
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String message = "Hello, World!";

    Font f = new Font("Serif", Font.BOLD, 36);
    g2.setFont(f);

    // measure the size of the message

    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D bounds = f.getStringBounds(message, context);

    // set (x,y) = top left corner of text

    double x = (getWidth() - bounds.getWidth()) / 2;
    double y = (getHeight() - bounds.getHeight()) / 2;

    // add ascent to y to reach the baseline

    double ascent = -bounds.getY();
    double baseY = y + ascent;

    // draw the message

    g2.drawString(message, (int) x, (int) baseY);

    g2.setPaint(Color.LIGHT_GRAY);

    // draw the baseline

    g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY));

    // draw the enclosing rectangle

    Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());
    g2.draw(rect);
  }
Example #21
0
 private synchronized void toBuffer(int s, Object a) {
   a1.add(s);
   a2.add(a);
   if (s == clear) {
     clearBuffer();
   }
   if (s == opaque) theOpaque = (Boolean) a;
   if (s == setBackground) theBackground = (Color) a;
   if (inBuffer) return;
   if (isSetter(s)) return;
   Graphics g = getGraphics();
   if (g == null) return;
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   for (int i = 0; i < a1.size() - 1; i++) {
     int s1 = a1.get(i);
     Object s2 = a2.get(i);
     if (isSetter(s1)) doPaint(g2, s1, s2);
   }
   doPaint((Graphics2D) g, s, a);
 }
  /**
   * Same as parent, but override for native version of the font.
   *
   * <p>Also gets called by textFont, so the metrics will get recorded properly.
   */
  public void textSize(float size) {
    if (textFont == null) {
      defaultFontOrDeath("textAscent", size);
    }

    // if a native version available, derive this font
    //    if (textFontNative != null) {
    //      textFontNative = textFontNative.deriveFont(size);
    //      g2.setFont(textFontNative);
    //      textFontNativeMetrics = g2.getFontMetrics(textFontNative);
    //    }
    Font font = textFont.getFont();
    if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) {
      Font dfont = font.deriveFont(size);
      g2.setFont(dfont);
      textFont.setFont(dfont);
    }

    // take care of setting the textSize and textLeading vars
    // this has to happen second, because it calls textAscent()
    // (which requires the native font metrics to be set)
    super.textSize(size);
  }
 /** Draw a value. */
 protected void drawValue(Graphics2D g, Color sourceColor, String msg, double x, double y) {
   g.setFont(valueDrawerFont);
   valueDrawer.draw(g, getLegendColor(), getForeground(), getBackground(), msg, x, y);
 }
Example #24
0
  boolean eventHandeler(Graphics2D g2d) {

    if (keyboard.keyDownOnce(KeyEvent.VK_Q)) {
      window.setState(Frame.ICONIFIED);
      paused = true;
    }

    if (firstStartup) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));

      g2d.setFont(new Font("Courier New", Font.PLAIN, 20));
      g2d.setColor(Color.black);
      switch (startupPage) {
        case 1:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 2;

          g2d.drawString("The goal of this game is to kill as", 100, 170);
          g2d.drawString("many *zombies* as possible. You are", 100, 200);
          g2d.drawString("given weapons and power-ups to help", 100, 230);
          g2d.drawString("you succeed. Good luck.", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("Ø O O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Story", 265, 110);
          break;
        case 2:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 3;

          g2d.drawString("Use A,S,D,W to stear", 100, 170);
          g2d.drawString("Use 1,2,3,4 to change weapon", 100, 200);
          g2d.drawString("Use the MOUSE to aim", 100, 230);
          g2d.drawString("Use the LEFT MOUSE BUTTON to fire", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("O Ø O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Controlls", 230, 110);
          break;
        case 3:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) firstStartup = false;

          g2d.setColor(Color.black);
          g2d.draw(new Ellipse2D.Double(100, 170 - 15, 20, 20));
          g2d.setColor(Color.red);
          g2d.draw(new Ellipse2D.Double(100, 200 - 15, 20, 20));
          g2d.setColor(Color.blue);
          g2d.draw(new Ellipse2D.Double(100, 230 - 15, 20, 20));
          g2d.setColor(Color.green);
          g2d.draw(new Ellipse2D.Double(100, 260 - 15, 20, 20));

          g2d.setColor(Color.black);
          g2d.drawString("Is you", 130, 170);
          g2d.drawString("Heals you", 130, 200);
          g2d.drawString("Unlocks / upgrades a weapon", 130, 230);
          g2d.drawString("Causes an explosion around you", 130, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to start", 150, 330);
          g2d.drawString("O O Ø", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Power-ups", 230, 110);
          break;
      }
      return true;
    }

    if (player.isDead) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_R)) restart();

      if (newHighscore) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 320, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("New Highscore"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record was " + oldHighScore + " kills", 210, 260);
      } else if (cheated) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 270, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("You cheated"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Highscore not saved", 210, 260);
      } else {
        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record is " + oldHighScore + " kills", 210, 260);
      }

      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));

      if (player.score == 1) g2d.drawString(String.format(player.score + " kill"), 200, 230);
      else g2d.drawString(String.format(player.score + " kills"), 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press R to restart"), 150, 330);
      return true;
    }

    if (window.isFocused() == false) paused = true;

    if (paused) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = false;
      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));
      g2d.drawString("Paused", 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press ESC to resume"), 150, 330);
      return true;
    }

    return false;
  }
 /** Paints the text of the <tt>VisualEdge</tt>. */
 public void paintText(Graphics2D g2d, Font font, Color fontColor, String text, float x, float y) {
   g2d.setFont(font);
   g2d.setColor(fontColor);
   g2d.drawString(text, x, y);
 }
Example #26
0
  static void paintShadowTitle(
      Graphics g,
      String title,
      int x,
      int y,
      Color frente,
      Color shadow,
      int desp,
      int tipo,
      int orientation) {

    // Si hay que rotar la fuente, se rota
    Font f = g.getFont();
    if (orientation == SwingConstants.VERTICAL) {
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      f = f.deriveFont(rotate);
    }

    // Si hay que pintar sombra, se hacen un monton de cosas
    if (shadow != null) {
      int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT);

      Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g);

      int w, h;
      if (orientation == SwingConstants.HORIZONTAL) {
        w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      } else {
        h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      }

      // La sombra del titulo
      BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
      BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = iTitulo.createGraphics();
      g2.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      g2.setFont(f);
      g2.setColor(shadow);
      g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro

      ConvolveOp cop =
          new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null);
      cop.filter(iTitulo, iSombra); // A ditorsionar

      // Por fin, pintamos el jodio titulo
      g.drawImage(
          iSombra,
          x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1
          y - 3 * matrix + desp, // para que la sombra quede pelin desplazada
          null);
    }

    // Si hay que pintar el frente, se pinta
    if (frente != null) {
      g.setFont(f);
      g.setColor(frente);
      g.drawString(title, x, y);
    }
  }
Example #27
0
 public void paintComponent(Graphics g1) {
   animationCount = 1;
   if (!visible) return;
   Graphics2D g = (Graphics2D) g1;
   float width = getWidth();
   float height = getHeight();
   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (45.0 <= rotate && rotate < 135.0) {
     g.translate(width, 0.0);
     g.rotate(Math.PI * rotate / 180, 0.0, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else if (135.0 <= rotate && rotate < 225.0) {
     g.rotate(Math.PI * rotate / 180, width / 2, height / 2);
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   } else if (225.0 <= rotate && rotate < 315.0) {
     g.translate(-height, 0.0);
     g.rotate(Math.PI * rotate / 180, height, 0.0);
     g.transform(
         AffineTransform.getScaleInstance(height / original_width, width / original_height));
   } else
     g.transform(
         AffineTransform.getScaleInstance(width / original_width, height / original_height));
   if ((dd.dynType & GeDyn.mDynType_Rotate) != 0 && dd.rotate != 0) {
     g.rotate(
         Math.PI * dd.rotate / 180,
         (dd.x0 - getX()) * original_width / width,
         (dd.y0 - getY()) * original_height / height);
   }
   AffineTransform save = g.getTransform();
   AffineTransform save_tmp;
   int rounds = 1;
   if (fillLevel != 1F) rounds = 2;
   int oldColor = 0;
   for (int i = 0; i < rounds; i++) {
     if (rounds == 2) {
       switch (i) {
         case 0:
           if (levelColorTone != GeColor.COLOR_TONE_NO) {
             oldColor = colorTone;
             colorTone = levelColorTone;
           } else if (levelFillColor != GeColor.COLOR_NO) {
             oldColor = fillColor;
             fillColor = levelFillColor;
           }
           break;
         case 1:
           if (levelColorTone != GeColor.COLOR_TONE_NO) colorTone = oldColor;
           else if (levelFillColor != GeColor.COLOR_NO) fillColor = oldColor;
           break;
       }
       switch (levelDirection) {
         case Ge.DIRECTION_UP:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     fillLevel * original_height + Ge.cJBean_Offset,
                     original_width,
                     original_height));
           else
             g.setClip(
                 new Rectangle2D.Float(
                     0F, 0F, original_width, fillLevel * original_height + Ge.cJBean_Offset));
           break;
         case Ge.DIRECTION_DOWN:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     0F,
                     original_width,
                     (1 - fillLevel) * original_height + Ge.cJBean_Offset));
           else
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     (1 - fillLevel) * original_height + Ge.cJBean_Offset,
                     original_width,
                     original_height));
           break;
         case Ge.DIRECTION_RIGHT:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     fillLevel * original_width + Ge.cJBean_Offset,
                     0F,
                     original_width,
                     original_height));
           else
             g.setClip(
                 new Rectangle2D.Float(0F, 0F, fillLevel * width + Ge.cJBean_Offset, height));
           break;
         case Ge.DIRECTION_LEFT:
           if (i == 0)
             g.setClip(
                 new Rectangle2D.Float(
                     0F,
                     0F,
                     (1 - fillLevel) * original_width + Ge.cJBean_Offset,
                     original_height));
           else
             g.setClip(
                 new Rectangle2D.Float(
                     (1 - fillLevel) * original_width + Ge.cJBean_Offset,
                     0F,
                     original_width,
                     original_height));
           break;
       }
     }
     {
       int fcolor =
           GeColor.getDrawtype(
               41,
               colorTone,
               colorShift,
               colorIntensity,
               colorBrightness,
               colorInverse,
               fillColor,
               dimmed);
       if (gradient == GeGradient.eGradient_No) {
         g.setColor(GeColor.getColor(fcolor));
         g.fill(shapes[0]);
       } else {
         GeGradient.paint(
             g,
             gradient,
             2,
             -2,
             2F,
             2F,
             606.515F,
             15.9609F,
             false,
             41,
             colorTone,
             colorShift,
             colorIntensity,
             colorInverse,
             fillColor,
             dimmed);
         g.fill(shapes[0]);
       }
       if (shadow != 0) {
         g.setColor(GeColor.shiftColor(fcolor, -2, colorInverse));
         g.fill(shapes[1]);
         g.setColor(GeColor.shiftColor(fcolor, 2, colorInverse));
         g.fill(shapes[2]);
       }
       g.setStroke(new BasicStroke(1F));
       g.setColor(
           GeColor.getColor(
               0,
               colorTone,
               colorShift,
               colorIntensity,
               colorBrightness,
               colorInverse,
               borderColor,
               dimmed));
       g.draw(shapes[0]);
     }
     g.setColor(
         GeColor.getColor(
             annot1Color,
             colorTone,
             colorShift,
             colorIntensity,
             colorBrightness,
             colorInverse,
             textColor,
             dimmed));
     g.setFont(annot1Font);
     save_tmp = g.getTransform();
     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
     g.transform(
         AffineTransform.getScaleInstance(original_width / width * height / original_height, 1));
     if (annot1 != null)
       g.drawString(annot1, 8 * original_height / height * width / original_width, 15F);
     g.setTransform(save_tmp);
   }
   if (rounds == 2) g.setClip(null);
   g.setTransform(save);
 }
Example #28
0
 public void paintComponent(Graphics g1) {
   Graphics2D g = (Graphics2D) g1;
   float width = getWidth();
   float height = getHeight();
   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   double scaleWidth = (1.0 * width / original_width);
   double scaleHeight = (1.0 * height / original_height);
   AffineTransform save = g.getTransform();
   g.setColor(getBackground());
   g.fill(new Rectangle(0, 0, getWidth(), getHeight()));
   g.transform(AffineTransform.getScaleInstance(scaleWidth, scaleHeight)); // scaletest
   AffineTransform save_tmp;
   g.setColor(
       GeColor.getColor(
           0,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           textColor,
           dimmed));
   g.setFont(new Font("Helvetica", Font.BOLD, 12));
   g.drawString(JopLang.transl("Status"), 13, 91);
   g.setColor(
       GeColor.getColor(
           0,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           textColor,
           dimmed));
   g.setFont(new Font("Helvetica", Font.BOLD, 12));
   g.drawString(JopLang.transl("LogMessage"), 13, 114);
   g.setColor(
       GeColor.getColor(
           0,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           textColor,
           dimmed));
   g.setFont(new Font("Helvetica", Font.BOLD, 12));
   g.drawString(JopLang.transl("EventListSize"), 13, 23);
   g.setColor(
       GeColor.getColor(
           0,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           textColor,
           dimmed));
   g.setFont(new Font("Helvetica", Font.BOLD, 12));
   g.drawString(JopLang.transl("EventLogSize"), 13, 44);
   g.setColor(
       GeColor.getColor(
           0,
           colorTone,
           colorShift,
           colorIntensity,
           colorBrightness,
           colorInverse,
           textColor,
           dimmed));
   g.setFont(new Font("Helvetica", Font.BOLD, 12));
   g.drawString(JopLang.transl("MaxApplAlarms"), 13, 67);
   g.setTransform(save);
 }
Example #29
0
    public void paintComponent(final Graphics g) {
      final Graphics2D g2 = (Graphics2D) g;
      g2.setBackground(backgroundColor);
      g2.clearRect(0, 0, frameWidth, overViewHeight);

      if (this.points.size() > 0) {
        g2.setColor(Color.blue);
        // draw the lines
        g2.setStroke(stroke);
        if (points.size() > frameWidth) { // draw contour
          // g2.setStroke(thickerStroke);
          for (int i = 0; i < this.points.size() - 1; i += 4) {
            Point2D.Float pt1 = points.get(i).getDispPoint();
            // Point2D.Float pt2  = new Point2D.Float(pt1.x, pt1.y/2);
            Point2D.Float pt2 = points.get(i + 1).getDispPoint();
            Point2D.Float pt3 = points.get(i + 2).getDispPoint();
            Point2D.Float pt4 = points.get(i + 3).getDispPoint();

            //						//Point2D.Float pt4  = new Point2D.Float(pt2.x, pt2.y/2);
            g2.draw(new Line2D.Float(pt1, pt2));
            // g2.setColor(waveLiteColor);
            g.setColor(waveLiteColor);
            g2.draw(new Line2D.Float(pt2, pt3));
            g2.setColor(waveColor);
            g2.draw(new Line2D.Float(pt3, pt4));
            //						g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
            //								this.points.get(i+1).getDispPoint()));
            //						g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
            //								this.points.get(i+1).getDispPoint()));
            //						g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
            //								this.points.get(i+1).getDispPoint()));
          }

        } else {
          for (int i = 0; i < this.points.size() - 1; i++) {
            g2.draw(
                new Line2D.Float(
                    this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint()));
          }
        }
      }

      // draw the selection if it exists
      if (viewBeginX != 0 && viewEndX != 0) {
        g2.setColor(overViewSelectionColor);
        g2.fillRect(viewBeginX, 0, viewEndX - viewBeginX + 1, overViewHeight);
      }

      final double totalTimeInSec = data.size() / myHelper.getSamplingRate();
      final int mainTickDist = (int) Math.floor(frameWidth / totalTimeInSec);
      final int smallTickDist = (int) Math.floor(mainTickDist / (numOfSmallTicks + 1));

      // draw the base line;
      g2.setColor(Color.black);
      g2.setStroke(thickerStroke);
      final Point2D base = new Point2D.Double(0, this.baseLineLocY);
      Point2D pt = new Point2D.Double(frameWidth, this.baseLineLocY);
      g2.draw(new Line2D.Double(base, pt));

      // draw the ticks
      pt = new Point2D.Double(0, baseLineLocY - this.mainTickHeight);
      // show text for main ticks
      g2.setFont(textFont2);
      for (int i = 0; i <= totalTimeInSec; i++) {
        g2.setStroke(thickerStroke);
        g2.draw(new Line2D.Double(base, pt));

        g2.drawString(i + "", (float) base.getX(), (float) base.getY() + textHeightFromBase);

        for (int j = 0; j < numOfSmallTicks; j++) {
          g2.setStroke(stroke);
          base.setLocation(base.getX() + smallTickDist, baseLineLocY);
          pt.setLocation(pt.getX() + smallTickDist, baseLineLocY - this.smallTickHeight);

          if (smallTickDist > 100) {
            g2.drawString(
                (j + 1) * 0.2 + 1 + "",
                (float) base.getX(),
                (float) base.getY() + textHeightFromBase);
          }

          if (base.getX() > frameWidth) {
            break;
          }
          g2.draw(new Line2D.Double(base, pt));
        }
        base.setLocation(base.getX() + smallTickDist, baseLineLocY);
        pt.setLocation(pt.getX() + smallTickDist, baseLineLocY - mainTickHeight);
      }
    }
Example #30
0
    public void paintComponent(Graphics g) {
      Rectangle selection = g.getClipBounds();

      // clear out the image
      Graphics2D g2 = (Graphics2D) g;
      g2.setBackground(backgroundColor);
      g2.clearRect(
          (int) selection.getX(),
          (int) selection.getY(),
          (int) selection.getWidth(),
          (int) selection.getHeight());

      // draw the selection if it exists
      if (selBeginPixel != -1 && selEndPixel != -1) {
        g2.setBackground(selectionColor);
        g2.clearRect(selBeginPixel, 0, selEndPixel - selBeginPixel + 1, this.getHeight());
      }

      if (this.points.size() > 0) {
        g2.setColor(waveColor);
        // draw the lines
        if (this.points.size() > stemThresh) {
          if (points.size() > frameWidth) { // draw contour
            // g2.setStroke(thickerStroke);
            for (int i = 0; i < this.points.size() - 1; i += 4) {
              Point2D.Float pt1 = points.get(i).getDispPoint();
              // Point2D.Float pt2  = new Point2D.Float(pt1.x, pt1.y/2);
              Point2D.Float pt2 = points.get(i + 1).getDispPoint();
              Point2D.Float pt3 = points.get(i + 2).getDispPoint();
              Point2D.Float pt4 = points.get(i + 3).getDispPoint();

              //							//Point2D.Float pt4  = new Point2D.Float(pt2.x, pt2.y/2);
              g2.draw(new Line2D.Float(pt1, pt2));
              // g2.setColor(waveLiteColor);
              g.setColor(waveLiteColor);
              g2.draw(new Line2D.Float(pt2, pt3));
              g2.setColor(waveColor);
              g2.draw(new Line2D.Float(pt3, pt4));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
              //							g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(),
              //									this.points.get(i+1).getDispPoint()));
            }

          } else { // draw line
            g2.setStroke(stroke);
            for (int i = 0; i < this.points.size() - 1; i++) {
              g2.draw(
                  new Line2D.Float(
                      this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint()));
            }
          }
        } else { // stem plot
          for (int i = 0; i < this.points.size(); i++) {
            // draw the stem
            SoundSample sample = this.points.get(i);
            g2.setStroke(thickerStroke);
            Point2D.Double base =
                new Point2D.Double(
                    sample.getDispPoint().getX() + 10, Math.floor(this.getHeight()) / 2);
            Point2D.Double pt =
                new Point2D.Double(sample.getDispPoint().getX() + 10, sample.getDispPoint().getY());
            g2.draw(new Line2D.Float(base, pt));

            if (this.points.size() < zoomThresh) {
              // draw the sample value
              float sampleValue = (float) sample.getSampleValue();
              float y = (float) sample.getDispPoint().getY();
              g2.setFont(textFont);
              if (y < Math.floor(this.getHeight()) / 2) y = y - 10;
              else y = y + 10;
              // if (sample.getDispPoint().getX() > 0)
              g2.drawString(formatter.format(sampleValue), (float) sample.getDispPoint().getX(), y);
            }

            // draw the vertical bar in the array
            //						g2.setStroke(thickerStroke);
            //						base = new Point2D.Double(base.getX()-8, this.getHeight() - 10);
            //						pt = new Point2D.Double(base.getX(), this.getHeight() - 50);
            //						g2.draw(new Line2D.Double(base, pt));
            //						g2.drawString(formatter.format(points.get(i).getSampleIndex()),
            // (float)base.getX(), (float)base.getY() - 10 );
          }
          //
          //					g2.setStroke(wideStroke);
          //					//draw the array cells
          //					g2.draw(new Line2D.Double(selection.getX(),
          //							Math.floor(this.getHeight() - 30),
          //							selection.getX()+selection.getWidth()-1,
          //							Math.floor(this.getHeight() - 30)));
          //					//draw the array cells
          //					g2.draw(new Line2D.Double(selection.getX(),
          //							Math.floor(this.getHeight() - 10),
          //							selection.getX()+selection.getWidth()-1,
          //							Math.floor(this.getHeight() - 10)));
        }
      }

      // draw the center line
      g2.setColor(barColor);
      g2.setStroke(new BasicStroke(1));
      g2.draw(
          new Line2D.Double(
              selection.getX(),
              Math.floor(this.getHeight() / 2),
              selection.getX() + selection.getWidth() - 1,
              Math.floor(this.getHeight() / 2)));

      //			//draw the current position
      //			if (selection.getX()<currentPixelPosition &&
      //					currentPixelPosition<(selection.getX()+selection.getWidth()-1))
      //			{
      //				g2.setColor(barColor);
      //				g2.setStroke(new BasicStroke(1));
      //				g2.draw(new Line2D.Double(currentPixelPosition, 0,
      //						currentPixelPosition, frameHeight));
      //			}
    }