private void shadeExt(Graphics2D g2, int r, int g, int b, int a) {
   g2.setPaint(new Color(r, g, b, a));
   g2.fillRect(0, 0, iw, rect.y); /* _N_ */
   g2.fillRect(
       rect.x + rect.width + 1, rect.y, iw - rect.x - rect.width - 1, rect.height + 1); /* E */
   g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */
   g2.fillRect(0, rect.y + rect.height + 1, iw, ih - rect.y - rect.height - 1); /* _S_ */
 }
示例#2
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();
  }
示例#3
0
  @Override
  public BufferedImage makeIcon(
      final int width, final int height, final Path2D iconShape, final boolean allowAlpha) {
    final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = result.createGraphics();

    g.setStroke(new BasicStroke(0.05f));

    final Color c;
    if (allowAlpha) {
      c =
          new Color(
              this.color.getRed(),
              this.color.getGreen(),
              this.color.getBlue(),
              this.color.getAlpha());
    } else {
      c = new Color(this.color.getRGB());
    }

    if (iconShape != null) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(
          RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
      g.setColor(c);
      final Shape path = makeTransformedPathForSize(width, height, iconShape);
      g.fill(path);
    } else {
      g.setColor(c);
      g.fillRect(0, 0, width, height);
    }
    g.dispose();
    return result;
  }
示例#4
0
 /** [Internal] */
 private void paintBackground(Graphics2D g2, Color theBackground) {
   Color color1 = g2.getColor();
   if (theBackground == null) theBackground = Color.white;
   g2.setColor(theBackground);
   g2.fillRect(0, 0, 30000, 30000);
   g2.setColor(color1);
 }
示例#5
0
  public VolatileImage renderBackgroundLayer(int LayerNumber) {
    // create hardware accellerated background layer (Volatile Image)
    backgroundLayer[LayerNumber] =
        this.getGraphicsConfiguration()
            .createCompatibleVolatileImage(
                loadedLevel.getWidth() * 16,
                loadedLevel.getHeight() * 16,
                Transparency.TRANSLUCENT);
    Graphics2D g2d = backgroundLayer[LayerNumber].createGraphics();
    g2d.setComposite(AlphaComposite.Src);

    // Clear the image.
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(
        0, 0, backgroundLayer[LayerNumber].getWidth(), backgroundLayer[LayerNumber].getHeight());
    g2d.setBackground(new Color(0, 0, 0, 0));

    g2d.setColor(new Color(1f, 1f, 1f, 1f));
    for (int i = 0;
        i
            < backgroundLayer[LayerNumber].getWidth(this)
                / backgroundImage[LayerNumber].getWidth(this);
        i++) {
      g2d.drawImage(
          backgroundImage[LayerNumber], i * backgroundImage[LayerNumber].getWidth(this), 0, this);
    }
    return backgroundLayer[LayerNumber];
  }
示例#6
0
 private void fillRectangle(int x, int y, int width, int height, int symbolType) {
   if (!Preferences.monochrome) {
     setFillColor(symbolType);
     gRef.fillRect(x, y, width, height);
     restoreColor();
   }
 }
示例#7
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);
  }
示例#8
0
 // initialize default image
 private BufferedImage getDefaultImage(int w, int h) {
   BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics2D = defaultImage.createGraphics();
   graphics2D.setColor(new Color(200, 200, 200));
   graphics2D.fillRect(0, 0, w, h);
   graphics2D.setColor(new Color(130, 130, 130));
   graphics2D.drawRect(0, 0, w - 1, h - 1);
   return defaultImage;
 }
示例#9
0
 private void drawSnake(Graphics2D g) {
   g.setColor(panel.getColor());
   for (BodyPart bodyPart : snake.getBody()) {
     g.fillRect(
         bodyPart.getX() * CELL_SIZE - CELL_SIZE,
         game.getScreenSize().height - (bodyPart.getY() * CELL_SIZE),
         CELL_SIZE,
         CELL_SIZE);
   }
 }
示例#10
0
 public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w, h);
   g2.drawImage(bi, -x, -y, null); // this);
   g2.dispose();
   return image;
 }
示例#11
0
 private void drawApple(Graphics2D g) {
   Color c = new Color(13, 111, 28);
   g.setColor(c);
   Image img1 = Toolkit.getDefaultToolkit().getImage("/apple.png");
   g.drawImage(img1, apple.getX(), apple.getY(), CELL_SIZE, CELL_SIZE, null);
   g.fillRect(
       apple.getX() * CELL_SIZE - CELL_SIZE,
       game.getScreenSize().height - (apple.getY() * CELL_SIZE),
       CELL_SIZE,
       CELL_SIZE);
 }
示例#12
0
  public void drawMissile(int xpos, int ypos, double rot, double xscale, double yscale) {
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.fillRect(-10, -10, 20, 20);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
示例#13
0
 public static BufferedImage tileImage(BufferedImage im, int width, int height) {
   GraphicsConfiguration gc =
       GraphicsEnvironment.getLocalGraphicsEnvironment()
           .getDefaultScreenDevice()
           .getDefaultConfiguration();
   int transparency = Transparency.OPAQUE; // Transparency.BITMASK;
   BufferedImage compatible = gc.createCompatibleImage(width, height, transparency);
   Graphics2D g = (Graphics2D) compatible.getGraphics();
   g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight())));
   g.fillRect(0, 0, width, height);
   return compatible;
 }
示例#14
0
        public int print(Graphics g,PageFormat pf,int pageIndex) {

                if (pageIndex == 0) {
                        Graphics2D g2d= (Graphics2D)g;
                        g2d.translate(pf.getImageableX(), pf.getImageableY()); 
                        g2d.setColor(Color.black);
                        g2d.drawString("example string", 250, 250);
                        g2d.fillRect(0, 0, 200, 200);
                        return Printable.PAGE_EXISTS;                                   
                } else {
                        return Printable.NO_SUCH_PAGE;
                }
        }
示例#15
0
 public static BufferedImage scaleImage(BufferedImage bi, double scale) {
   int w1 = (int) (Math.round(scale * bi.getWidth()));
   int h1 = (int) (Math.round(scale * bi.getHeight()));
   BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w1, h1);
   g2.drawImage(bi, 0, 0, w1, h1, null); // this);
   g2.dispose();
   return image;
 }
示例#16
0
 public static BufferedImage rotateImage(BufferedImage bi) {
   int w = bi.getWidth();
   int h = bi.getHeight();
   BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white); // getBackground());
   g2.fillRect(0, 0, h, w);
   g2.rotate(90 * Math.PI / 180);
   g2.drawImage(bi, 0, -h, w, h, null); // this);
   g2.dispose();
   return image;
 }
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setColor(Color.white);
   g2.fillRect(0, 0, getWidth(), getHeight());
   AffineTransform at = new AffineTransform(0.5, 0, 0, -0.5, 30, getHeight() * 3 / 4);
   g2.transform(at);
   g2.setColor(Color.black);
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setRenderingHint(
       RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   //	System.out.println("Showing="+showing);
   if (showing != null) {
     showing.draw(g2);
   }
 }
 private BufferedImage createCustomImage() {
   BufferedImage image = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = image.createGraphics();
   int dx = image.getWidth() / SQUARES;
   int dy = image.getHeight() / SQUARES;
   for (int i = 0; i < SQUARES; ++i) {
     for (int j = 0; j < SQUARES; ++j) {
       g2d.setColor(new Color(rand.nextInt()));
       g2d.fillRect(i * dx, j * dy, dx, dy);
     }
   }
   g2d.setColor(Color.GREEN);
   g2d.drawRect(0, 0, image.getWidth() - 1, image.getHeight() - 1);
   g2d.dispose();
   return image;
 }
示例#19
0
  @Override
  public void paintComponent(Graphics window) {
    super.paintComponent(window);

    Image bufferedImage = createImage(getWidth(), getHeight());
    Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();

    g2d.setPaint(gradient1);
    g2d.fillRect(0, 0, 300, 1000);

    if (showInstructions == true) {
      g2d.setColor(Color.YELLOW);
      g2d.setFont(font1);
      g2d.drawString("Instructions:", 10, 150);
      g2d.setFont(font3);
      g2d.drawString("To Play, Click New Game", 10, 200);
      g2d.drawString("Each game costs $1", 10, 230);
      g2d.drawString("Hit adds a card to your hand", 10, 260);
      g2d.drawString("Stand stops the game and", 10, 290);
      g2d.drawString("calculates each persons score", 10, 320);
      g2d.drawString("To play dealer, click Play Dealer", 10, 350);
      g2d.drawString("Enter your desired wager", 10, 380);
      g2d.drawString("Every time you score 20 or 21", 10, 470);
      g2d.drawString("you get one arcade token", 10, 500);
      g2d.drawString("Arcade Tokens can be redeemed", 10, 530);
      g2d.drawString("By closing instructions and clicking", 10, 560);
      g2d.drawString("Play Arcade Game", 10, 590);
    } else {
      g2d.setColor(Color.YELLOW);
      g2d.setFont(font1);
      g2d.drawString("Arcade Game:", 10, 250);
      g2d.setFont(font3);
      g2d.drawString("Select the game you would like", 10, 320);
      g2d.drawString("Click Play to Play.", 10, 350);
      g2d.drawString("Hold and Drag the Mouse", 10, 380);
      g2d.drawString("to move in Cube Runner", 10, 410);
      g2d.drawString("Press the mouse to sprint", 10, 440);
      g2d.drawString("in Spiral Game, and click", 10, 500);
      g2d.drawString("to Jump", 10, 530);
      g2d.drawString("Each game costs one token", 10, 560);
      g2d.drawString("", 10, 590);
    }
    g2d.setColor(Color.YELLOW);
    g2d.setFont(font1);
    g2d.drawString("Tokens: " + tempObject.tokens, 10, 700);
    window.drawImage(bufferedImage, 0, 0, this);
  }
示例#20
0
  public void initialize() {

    // openLevelFile images:
    try {
      boxSpriteSheet = ImageIO.read(new File("ItemContainer.png"));
      coinSpriteSheet = ImageIO.read(new File("Coin.png"));
    } catch (Exception e) {
    }

    if (openLevelFile == false) {
      try {
        loadLevel(initLevel);
      } catch (Exception e) {
        System.out.println(e);
      }
    } else {
      loadLevel(FileOpenDialog("Open ..."));
    }

    // create tile layer:
    renderTileLayer();

    // create bg layer:
    backgroundLayer = new VolatileImage[backgroundImage.length];

    // render layer:
    for (int i = 0; i < backgroundImage.length; i++) {
      renderBackgroundLayer(0);
      renderBackgroundLayer(1);
    }

    // create hardware accellerated rendering layer:
    renderImage =
        this.getGraphicsConfiguration()
            .createCompatibleVolatileImage(
                loadedLevel.getWidth() * 16,
                loadedLevel.getHeight() * 16,
                Transparency.TRANSLUCENT);
    Graphics2D g2d = renderImage.createGraphics();
    g2d.setComposite(AlphaComposite.Src);

    // Clear the image.
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(0, 0, renderImage.getWidth(), renderImage.getHeight());
    g2d.setBackground(new Color(0, 0, 0, 0));
  }
      public void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;

        if (!text.equals("")) {
          g2.translate(0, getSize().getHeight());
          g2.rotate(-Math.PI / 2);
          g2.setColor(Color.red);
          g2.fillRect(0, 0, sizeText_y, sizeText_x);
          g2.setColor(Color.white);
          g2.drawString(text, 20, 14);

          g2.translate(0, -getSize().getHeight());
          g2.transform(AffineTransform.getQuadrantRotateInstance(1));
        }
      }
示例#22
0
  /**
   * Draw rectangle.
   *
   * @param xModifier int -
   * @param yModifier int -
   * @param Xsize float - zoom factor.
   * @param Ysize float - zoom factor.
   * @param g2 Graphics - class graphics.
   */
  @Override
  public void draw(int xModifier, int yModifier, float Xsize, float Ysize, Graphics2D g2) {

    // Set the box color: light-gray, with a transparency defined by "alpha" value.
    g2.setColor(getColor());

    int a = xModifier + (int) (Xsize * getX());
    int b = yModifier + (int) (Ysize * getY());
    int c = (int) (Xsize * getWidth());
    int d = (int) (Ysize * getHeight());

    // draw the bounding box rectangle.
    g2.fillRect(a, b, c, d);

    // Draw selection markers if object selected.
    if (isSelected()) {
      drawSelection(g2);
    }
  } // draw
示例#23
0
  public void write() {
    System.out.println("Writing image");
    BufferedImage img = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();

    g.setColor(Color.white);
    g.fillRect(0, 0, 1600, 1200);
    g.setColor(Color.black);
    counts = new double[depth];
    for (int i = 0; i < depth; i++) {
      counts[i] = 0;
    }
    draw(root, g, 800, 10);

    try {
      File f = new File(jpeg);
      ImageIO.write((RenderedImage) img, "jpeg", f);
    } catch (Exception e) {
      System.out.println("Error writing image data");
    }
  }
示例#24
0
  // init
  private static void init() {
    if (frame != null) frame.setVisible(false);
    frame = new JFrame();
    offscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    onscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    offscreen = offscreenImage.createGraphics();
    onscreen = onscreenImage.createGraphics();
    setXscale();
    setYscale();
    offscreen.setColor(DEFAULT_CLEAR_COLOR);
    offscreen.fillRect(0, 0, width, height);
    setPenColor();
    setPenRadius();
    setFont();
    clear();

    // add antialiasing
    RenderingHints hints =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    offscreen.addRenderingHints(hints);

    // frame stuff
    ImageIcon icon = new ImageIcon(onscreenImage);
    JLabel draw = new JLabel(icon);

    draw.addMouseListener(std);
    draw.addMouseMotionListener(std);

    frame.setContentPane(draw);
    frame.addKeyListener(std); // JLabel cannot get keyboard focus
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes all windows
    // frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);      // closes only current window
    frame.setTitle("Standard Draw");
    frame.setJMenuBar(createMenuBar());
    frame.pack();
    frame.requestFocusInWindow();
    frame.setVisible(true);
  }
示例#25
0
  @Override
  public void draw(Graphics2D g) {
    g.setColor(Color.lightGray);
    g.fillRect(0, 0, game.getScreenSize().width, game.getScreenSize().height);
    drawSnake(g);
    drawApple(g);
    g.setFont(new Font("Default", Font.BOLD, 12));

    String message = "Press <F5> to save, <F6> to load.";
    Rectangle2D messageBounds =
        g.getFontMetrics()
            .getStringBounds(
                message,
                g); // g.getFontMetrics().getStringBounds - ��������� �������� ������ ��������
                    // ������ � ��������
    int messageWidth = (int) (messageBounds.getWidth());
    int messageHeight = (int) (messageBounds.getHeight());

    g.drawString(message, 15, 10);

    if (paused) {
      g.setFont(new Font("Default", Font.BOLD, 60));
      g.setColor(Color.white);
      message = "Pause";
      messageBounds =
          g.getFontMetrics()
              .getStringBounds(
                  message,
                  g); // g.getFontMetrics().getStringBounds - ��������� �������� ������ ��������
                      // ������ � ��������
      messageWidth = (int) (messageBounds.getWidth());
      messageHeight = (int) (messageBounds.getHeight());
      g.drawString(
          message,
          game.getScreenSize().width / 2 - messageWidth / 2,
          game.getScreenSize().height / 2 - messageHeight / 2);
    }
  }
示例#26
0
  public VolatileImage renderTileLayer() {
    // create hardware accellerated tile layer (Volatile Image)
    tileLayer =
        this.getGraphicsConfiguration()
            .createCompatibleVolatileImage(
                loadedLevel.getWidth() * 16,
                loadedLevel.getHeight() * 16,
                Transparency.TRANSLUCENT);
    Graphics2D g2d = tileLayer.createGraphics();
    g2d.setComposite(AlphaComposite.Src);

    // Clear the image.
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(0, 0, tileLayer.getWidth(), tileLayer.getHeight());
    g2d.setBackground(new Color(0, 0, 0, 0));

    g2d.setColor(new Color(1f, 1f, 1f, 1f));

    for (int i = 0; i < numberOfTiles; i++) {
      tile[i].draw(g2d, this);
    }

    return tileLayer;
  }
示例#27
0
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    int h = getHeight();
    int w = getWidth();
    double factor = (h - (MARGIN_BOTTOM * 1.0)) / RSSI_MAX_VALUE;
    double sSpacing = (w - MARGIN_RIGHT) / (TOTAL * 1.0);
    int sWidth = (int) (sSpacing - 1);
    if (sWidth == 0) sWidth = 1;

    // Set white background in the plot
    g.setColor(Color.white);
    g.fillRect(0, 0, w, h);

    // Gradient example (ytics background)
    GradientPaint greytowhite =
        new GradientPaint(w - MARGIN_RIGHT, 0, Color.WHITE, w, 0, Color.lightGray, false);
    g2.setPaint(greytowhite);
    g2.fillRect(w - MARGIN_RIGHT, 0, w, h);

    // Draw the light grey channels from 11 to 26
    double xpos = 10;
    for (int i = 4; i < TOTAL - 4; i++) {
      if (i == 4 + 5 * (INTERFERED_CHANNEL - 11)) g.setColor(Color.cyan);
      else g.setColor(Color.lightGray);
      g.fillRect((int) (xpos + i * sSpacing), 0, (int) (sSpacing * 3), h - MARGIN_BOTTOM);
      i = i + 4;
      g.setColor(Color.blue);
      g.drawString(
          String.valueOf(((i - 8) / 5) + 11), (int) (xpos + (i - 4) * sSpacing), MARGIN_TOP);
    }
    g.drawString(String.valueOf("Channel"), (int) (w - MARGIN_RIGHT + 20), MARGIN_TOP);

    // Write the y-axis with dBm
    int base_dBm = -100; // The bottom corresponds to -100 dBm
    int ytics = 10; // How many tics on the y-axis
    for (int i = -ytics; i <= 0; i++) {
      g.setColor(Color.red);
      g.drawString(
          String.valueOf(((ytics + i) * (base_dBm / ytics)) + "dBm"),
          (int) (w - MARGIN_RIGHT + 20),
          (int) (h + i * (h / ytics)) - MARGIN_BOTTOM);
      // Dashed line for the ytics
      final float dash1[] = {10.0f};
      final BasicStroke dashed =
          new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
      g2.setStroke(dashed);
      g2.drawLine(
          0,
          (int) (h + i * (h / ytics)) - MARGIN_BOTTOM,
          (int) (w - MARGIN_RIGHT + 7),
          (int) (h + i * (h / ytics)) - MARGIN_BOTTOM);
    }

    // Write the x-axis with MHz
    g.setColor(Color.blue);
    int start_x_axis = 4;
    g.drawString(String.valueOf(2400 + "MHz"), (int) xpos, (int) h - start_x_axis);
    g.drawString(String.valueOf(2442.5 + "MHz"), (w - 119) / 2, (int) h - start_x_axis);
    g.drawString(String.valueOf(2485 + "MHz"), w - 119, (int) h - start_x_axis);

    // Draw the old RSSI in each MHz channel (grey)
    g.setColor(Color.gray);
    double xposition = xpos;
    for (int i = 0, n = rssi.length; i < n; i++) {
      int rssi = (int) (rssiMax[i] * factor);
      g.fillRect((int) xposition, h - MARGIN_BOTTOM - rssi, sWidth, rssi + 1);
      xposition += sSpacing;
    }

    // Draw the current RSSI in each MHz channel (black)
    g.setColor(Color.black);
    xposition = xpos;
    for (int i = 0, n = rssi.length; i < n; i++) {
      int rssiVal = (int) (rssi[i] * factor);
      g.fillRect((int) xposition, h - MARGIN_BOTTOM - rssiVal, sWidth, rssiVal + 1);
      xposition += sSpacing;
    }
  }
示例#28
0
 /**
  * Draw one pixel at (x, y).
  *
  * @param x the x-coordinate of the pixel
  * @param y the y-coordinate of the pixel
  */
 private static void pixel(double x, double y) {
   offscreen.fillRect((int) Math.round(scaleX(x)), (int) Math.round(scaleY(y)), 1, 1);
 }
示例#29
0
 /**
  * Clear the screen to the given color.
  *
  * @param color the Color to make the background
  */
 public static void clear(Color color) {
   offscreen.setColor(color);
   offscreen.fillRect(0, 0, width, height);
   offscreen.setColor(penColor);
   draw();
 }
示例#30
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public boolean animate(int sAt, boolean forward) {

    int x;
    LinkedList lt = null;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in aborted attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }

    // First capture the new image in a buffer called image2
    SnapAt = sAt;
    BufferedImage image2 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) image2.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Next capture the image we are coming from in a buffer called image1
    SnapAt = (forward ? sAt - 1 : sAt + 1);
    BufferedImage image1 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g1 = (Graphics2D) image1.getGraphics(); // need a separate object each time?
    g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g1.setColor(Color.WHITE);
    g1.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g1 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Now slide from image1 to image2

    // From the gaff Visualizer by Chris Gaffney
    //        double step = 4;	// Adjust this for more/less granularity between images
    double step = 40; // Adjust this for more/less granularity between images

    Image buffer = getGraphicsConfiguration().createCompatibleVolatileImage(my_width, my_height);
    Graphics2D g2d = (Graphics2D) buffer.getGraphics();

    AffineTransform trans = AffineTransform.getTranslateInstance(step * (forward ? -1 : 1), 0);
    //        AffineTransform orig = g2d.getTransform();

    Shape mask = createMask(my_width, my_height);

    for (double i = 0; i < my_width; i += step) {
      if (i + step > my_width) // last time through loop, so adjust transform
      trans =
            AffineTransform.getTranslateInstance(((double) (my_width - i)) * (forward ? -1 : 1), 0);
      g2d.transform(trans);
      g2d.drawImage(image1, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      AffineTransform last = g2d.getTransform();
      g2d.transform(AffineTransform.getTranslateInstance(my_width * (-1 * (forward ? -1 : 1)), 0));
      g2d.drawImage(image2, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      g2d.setTransform(last);

      this.my_image = buffer;
      repaint();

      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {

      }
    }
    Image b = getGraphicsConfiguration().createCompatibleImage(my_width, my_height);
    b.getGraphics().drawImage(buffer, 0, 0, null);
    this.my_image = b;

    return animation_done;
  }