// draws the button, based on the type of button (ImageIcon, Image, or String)
  public void draw(Graphics g) {
    if (visible) {
      // if its image/imageicon, draw it
      g.setColor(new Color(50, 200, 50));
      g.fillRect(x - 1, y - 1, width + 2, height + 2);
      if (mode.equals("Image") || mode.equals("ImageIcon")) {
        if (enabled) {
          g.drawImage(image, x, y, null);
        } else {
          g.drawImage(BWimage, x, y, null);
        }
        // if its string, draw the string
      } else {

        g.setFont(new Font("Arial", Font.PLAIN, 20));
        if (enabled) {
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        } else {
          g.setColor(new Color(255, 255, 255));
          g.fillRect(x - 1, y - 1, width + 2, height + 2);
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        }
      }
    }
  }
  @Override
  public void paintDeterminate(Graphics g, JComponent c) {
    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - b.right - b.left;
    int barRectHeight = progressBar.getHeight() - b.top - b.bottom;
    if (barRectWidth <= 0 || barRectHeight <= 0) {
      return;
    }
    // int cellLength = getCellLength();
    // int cellSpacing = getCellSpacing();
    // amount of progress to draw
    int amountFull = getAmountFull(b, barRectWidth, barRectHeight);

    // draw the cells
    if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) {
      float x = amountFull / (float) barRectWidth;
      g.setColor(getColorFromPallet(pallet, x));
      g.fillRect(b.left, b.top, amountFull, barRectHeight);
    } else { // VERTICAL
      float y = amountFull / (float) barRectHeight;
      g.setColor(getColorFromPallet(pallet, y));
      g.fillRect(b.left, barRectHeight + b.bottom - amountFull, barRectWidth, amountFull);
    }
    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      paintString(g, b.left, b.top, barRectWidth, barRectHeight, amountFull, b);
    }
  }
  /** Overrides <code>Graphics.fillRect</code>. */
  public void fillRect(int x, int y, int width, int height) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Filling rect: " + new Rectangle(x, y, width, height));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fillRect(x, y, width, height);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.fillRect(x, y, width, height);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillRect(x, y, width, height);
  }
  public void draw(Graphics window, int x, int y) {
    window.setColor(Color.CYAN);
    window.fillOval(x + 8, y + 11, 45 - 16, 45 - 16);
    window.setColor(Color.BLACK);
    window.fillOval(x + 14, y + 15, 5, 5); // eyes
    window.fillOval(x + 25, y + 15, 5, 5); // eyes
    imgFound = false;

    // health bar
    window.setColor(Color.RED);
    window.fillRect(x, y, 45, 9);
    window.setColor(Color.GREEN);
    window.fillRect(x, y, (int) ((double) currentHealth / (double) (maxHealth) * 45), 9);
  }
Exemple #5
0
  public void paintFPS(int x, int y, Graphics g) {

    // Skip if not needed:
    if (usingMenu) {
      return;
    }

    if (showFPS) {

      // Update FPS count:
      if (--fpsCounter <= 0) {

        long ct = nes.getGui().getTimer().currentMicros();
        long frameT = (ct - prevFrameTime) / 45;
        if (frameT == 0) {
          fps = "FPS: -";
        } else {
          fps = "FPS: " + (1000000 / frameT);
        }
        fpsCounter = 45;
        prevFrameTime = ct;
      }

      // Draw FPS.
      gfx.setColor(Color.black);
      gfx.fillRect(
          x,
          y - gfx.getFontMetrics().getAscent(),
          gfx.getFontMetrics().stringWidth(fps) + 3,
          gfx.getFontMetrics().getHeight());
      gfx.setColor(Color.cyan);
      gfx.drawString(fps, x, y);
    }
  }
Exemple #6
0
  /** Affichage du logo */
  protected void drawLogo(Graphics g) {

    int x = 5;
    int y = 2;

    g.setColor(getBackground());
    g.fillRect(0, 0, W, H);

    // Remplissage
    fillBG(g, x, y, Color.white);

    // Dessin
    drawGrid(
        g,
        x,
        y,
        !isAvailable()
            ? Aladin.MYGRAY
            : isActive() ? Aladin.GREEN : isMouseIn() ? Color.blue : Color.black);

    // Label
    g.setColor(isAvailable() ? Color.black : Aladin.MYGRAY);
    g.setFont(Aladin.SPLAIN);
    g.drawString(LABEL, W / 2 - g.getFontMetrics().stringWidth(LABEL) / 2, H - 2);
  }
 // Show a message over frozen image in the display
 public void showMessage(String message) {
   Graphics g = getGraphics();
   g.setColor(Color.black);
   g.fillRect(30, (getHeight() / 2) - 16, message.length() * 10, 25);
   g.setColor(Color.white);
   g.drawString(message, 40, getHeight() / 2);
 }
 public SimpleWhiteboardPanel(int width, int height) {
   this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   Graphics g = this.image.getGraphics();
   g.setColor(Color.WHITE);
   g.fillRect(0, 0, image.getWidth(), image.getHeight());
   this.setFocusable(true);
 }
 public void clear() {
   Graphics g = this.image.getGraphics();
   g.setColor(Color.WHITE);
   g.fillRect(0, 0, this.image.getWidth(null), this.image.getHeight(null));
   g.dispose();
   repaint();
 }
Exemple #10
0
  private void gameRender() {
    if (dbImage == null) {
      dbImage = createImage(PWIDTH, PHEIGHT);
      if (dbImage == null) {
        System.out.println("dbImage is null");
        return;
      } else dbg = dbImage.getGraphics();
    }

    // draw a white background
    dbg.setColor(Color.white);
    dbg.fillRect(0, 0, PWIDTH, PHEIGHT);

    // draw the game elements: order is important
    ribsMan.display(dbg); // the background ribbons
    bricksMan.display(dbg); // the bricks
    jack.drawSprite(dbg); // the sprites
    fireball.drawSprite(dbg);

    if (showExplosion) // draw the explosion (in front of jack)
    dbg.drawImage(explosionPlayer.getCurrentImage(), xExpl, yExpl, null);

    reportStats(dbg);

    if (gameOver) gameOverMessage(dbg);

    if (showHelp) // draw the help at the very front (if switched on)
    dbg.drawImage(
          helpIm, (PWIDTH - helpIm.getWidth()) / 2, (PHEIGHT - helpIm.getHeight()) / 2, null);
  } // end of gameRender()
Exemple #11
0
    public void draw(Graphics g, ImageObserver ob) {
      if (!todraw) {
        g.setColor(bgcolor);
        g.drawRect(x, y, w + 2 * border, h + 2 * border);
        g.fillRect(x, y, w + 2 * border, h + 2 * border);
        return;
      }

      if (selected) g.setColor(selected_color);
      else g.setColor(unselected_color);

      g.drawRect(x, y, w + 2 * border, h + 2 * border);
      g.fillRect(x, y, w + 2 * border, h + 2 * border);
      g.drawImage(image[im], x + border, y + border, ob);

      // g.setColor(Color.black);
      // g.drawString("" + im,x+5,y+5);
    }
  public void draw(Graphics window, int scale, int x, int y) {
    window.setColor(Color.CYAN);
    window.fillOval(
        x + 8 * scale / 45, y + 11 * scale / 45, scale - 16 * scale / 45, scale - 16 * scale / 45);
    window.setColor(Color.BLACK);
    window.fillOval(
        x + 14 * scale / 45, y + 15 * scale / 45, 5 * scale / 45, 5 * scale / 45); // eyes
    window.fillOval(
        x + 25 * scale / 45, y + 15 * scale / 45, 5 * scale / 45, 5 * scale / 45); // eyes
    imgFound = false;

    // health bar
    window.setColor(Color.RED);
    window.fillRect(x, y, scale - 1, 9 * scale / 45);
    window.setColor(Color.GREEN);
    window.fillRect(
        x, y, (int) ((double) currentHealth / (double) (maxHealth) * (scale - 1)), 9 * scale / 45);
  }
Exemple #13
0
 /**
  * Paint method for applet.
  *
  * @param g the Graphics object for this applet
  */
 public void paint(Graphics g) {
   // simple text displayed on applet
   g.setColor(c);
   g.fillRect(0, 0, 200, 100);
   g.setColor(Color.black);
   g.drawString("Sample Applet", 20, 20);
   g.setColor(Color.blue);
   g.drawString("created by BlueJ", 20, 40);
 }
Exemple #14
0
 /**
  * Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using
  * the given alpha threshold and render-to-background colour, or display-compatible translucent
  * image. The alpha values in the image are set to either 0 (below threshold) or 255 (above
  * threshold). The render-to-background colour bg_col is used to determine how the pixels
  * overlapping transparent pixels should be rendered. The fast algorithm just sets the colour
  * behind the transparent pixels in the image (for bitmask source images); the slow algorithm
  * actually renders the image to a background of bg_col (for translucent sources).
  *
  * @param thresh alpha threshold between 0 and 255
  * @param fast use fast algorithm (only set bg_col behind transp. pixels)
  * @param bitmask true=use bitmask, false=use translucent
  */
 public JGImage toDisplayCompatible(int thresh, JGColor bg_col, boolean fast, boolean bitmask) {
   Color bgcol = new Color(bg_col.r, bg_col.g, bg_col.b);
   int bgcol_rgb = (bgcol.getRed() << 16) | (bgcol.getGreen() << 8) | bgcol.getBlue();
   JGPoint size = getSize();
   int[] buffer = getPixels();
   // render image to bg depending on bgcol
   BufferedImage img_bg;
   if (bitmask) {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.BITMASK);
   } else {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.TRANSLUCENT);
   }
   int[] bg_buf;
   if (!fast) {
     Graphics g = img_bg.getGraphics();
     g.setColor(bgcol);
     // the docs say I could use bgcol in the drawImage as an
     // equivalent to the following two lines, but this
     // doesn't handle translucency properly and is _slower_
     g.fillRect(0, 0, size.x, size.y);
     g.drawImage(img, 0, 0, null);
     bg_buf = new JREImage(img_bg).getPixels();
   } else {
     bg_buf = buffer;
   }
   // g.dispose();
   // ColorModel rgb_bitmask = ColorModel.getRGBdefault();
   // rgb_bitmask = new PackedColorModel(
   //		rgb_bitmask.getColorSpace(),25,0xff0000,0x00ff00,0x0000ff,
   //		0x1000000, false, Transparency.BITMASK, DataBuffer.TYPE_INT);
   //		ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean
   // isAlphaPremultiplied, int trans, int transferType)
   int[] thrsbuf = new int[size.x * size.y];
   for (int y = 0; y < size.y; y++) {
     for (int x = 0; x < size.x; x++) {
       if (((buffer[y * size.x + x] >> 24) & 0xff) >= thresh) {
         thrsbuf[y * size.x + x] = bg_buf[y * size.x + x] | (0xff << 24);
       } else {
         // explicitly set the colour of the transparent pixel.
         // This makes a difference when scaling!
         // thrsbuf[y*size.x+x]=bg_buf[y*size.x+x]&~(0xff<<24);
         thrsbuf[y * size.x + x] = bgcol_rgb;
       }
     }
   }
   return new JREImage(
       output_comp.createImage(
           new MemoryImageSource(
               size.x,
               size.y,
               // rgb_bitmask,
               img_bg.getColorModel(), // display compatible bitmask
               bitmask ? thrsbuf : bg_buf,
               0,
               size.x)));
 }
 public void drawObject(Graphics g, int x, int y, int w, int h, ImageObserver i) {
   if (style == O_IMG) {
     // paint image
     g.drawImage(objImage, x * w, y * h, w, h, i);
   } else {
     // paint square
     g.setColor(objColour);
     g.fillRect(x * w, y * h, w, h);
   }
 }
Exemple #16
0
  private void drawAWP(Graphics g, int x, int y) {
    if (System.currentTimeMillis() < shotTime + TAWP.SHOOT_TIME) {
      // System.out.println(true);
      double multi = 1.0 * (System.currentTimeMillis() - shotTime) / TAWP.SHOOT_TIME;
      g.setColor(new Color(255, 255, 255, 255 - (int) (multi * 256)));
      g.fillRect(0, 0, Wuigi.screenWidth, Wuigi.screenHeight);
    }
    if (numBullets <= 0) return;

    BufferedImage img = TAWP.IMAGE.getBuffer();
    AffineTransform xform = new AffineTransform();
    // g2d.setPaint(new TexturePaint(figureOutDrawImage(),
    //		new Rectangle2D.Float(0, 0, 32, 32)));
    // g2d.drawImage(figureOutDrawImage(),0,0,null);
    xform.setToIdentity();
    xform.translate(x - 5, y);

    double diffY = y + height / 2 - ScreenManager.mouse.y;
    double diffX = ScreenManager.mouse.x - x - width / 2;

    double angle;

    if (diffY > 0 && diffX > 0) {
      angle = Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX > 0) {
      angle = Math.PI / 2;
    } else if (diffY < 0 && diffX > 0) {
      angle = Math.PI / 2 + Math.atan(-diffY / diffX);
    } else if (diffY < 0 && diffX == 0) {
      angle = Math.PI;
    } else if (diffY < 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX < 0) {
      angle = 3 * Math.PI / 2;
    } else if (diffY > 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 + Math.atan(-diffY / diffX);
    } else {
      angle = 0;
    }
    angle -= Math.PI / 2;

    if (angle > Math.PI / 2 && angle < 3 * Math.PI / 2) {
      xform.scale(1, -1);
      xform.translate(0, -TAWP.IMAGE.getHeight());
      angle = -angle;
    }
    // xform.scale(/*width/img.getWidth(),height/img.getHeight()*/);
    xform.rotate(angle, 27, 13);

    ((Graphics2D) g).drawImage(img, xform, null);
    ammo.setPos(x + 10, y - 20);
    ammo.draw(g);
  }
 void showFrameRate(Graphics g) {
   frames++;
   if (System.currentTimeMillis() > firstFrame + 1000) {
     firstFrame = System.currentTimeMillis();
     fps = frames;
     frames = 0;
   }
   g.setColor(Color.white);
   g.fillRect(10, 12, 50, 15);
   g.setColor(Color.black);
   g.drawString((int) (fps + 0.5) + " fps", 10, 25);
 }
 public void paint(Graphics g) {
   if (histogram != null) {
     if (os == null) {
       os = createImage(WIDTH, HEIGHT);
       osg = os.getGraphics();
       osg.setColor(Color.white);
       osg.fillRect(0, 0, WIDTH, HEIGHT);
       osg.setColor(Color.gray);
       for (int i = 0; i < WIDTH; i++) {
         if (hColors != null) osg.setColor(hColors[i]);
         osg.drawLine(i, HEIGHT, i, HEIGHT - ((int) (HEIGHT * histogram[i]) / hmax) - 4);
       }
       osg.dispose();
     }
     g.drawImage(os, 0, 0, this);
   } else {
     g.setColor(Color.white);
     g.fillRect(0, 0, WIDTH, HEIGHT);
   }
   g.setColor(Color.black);
   g.drawLine(0, HEIGHT - 4, 256, HEIGHT - 4);
   g.drawRect(0, 0, WIDTH, HEIGHT);
   g.drawRect((int) minHue, 1, (int) (maxHue - minHue), HEIGHT - 5);
 }
Exemple #19
0
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (model != null) {
     newImgBuf(); // refresh the image buffer if necessary
     // compute the real-to-screen ratio, this variable differs
     // from model.real2Screen by zoomScale
     Dimension sz = getSize();
     double real2Screen0 = model.getScaleFromSpan(realSpan, sz.width, sz.height);
     model.setMatrix(viewMatrix, real2Screen0 * zoomScale, sz.width / 2, sz.height / 2);
     imgG.setColor(Color.BLACK);
     imgG.fillRect(0, 0, sz.width, sz.height);
     model.paint(imgG);
     g.drawImage(img, 0, 0, this);
   }
 }
Exemple #20
0
  public void paint(Graphics g) {
    Message("Copyright Feb, 2000 Weicon Conan Yuan.", "All Rights Reserved", 7);
    for (int i = 0; i < NUM_LOCATIONS; i++) {
      locs[i].draw(g, this);
      g.setColor(txtcolor);
      if (locs[i].ToDraw()) {
        g.drawString("" + i, locs[i].GetX(), locs[i].GetY() + 10);
      }
    }

    g.setColor(Color.red);
    g.drawRect(400, 200, 30, 30);
    g.fillRect(400, 200, 30, 30);
    Message("Cheat", 4);
  }
Exemple #21
0
  public void paint(Graphics g) {
    if (offg == null) {
      initScreen();
      // initObjects();
      return;
    }

    // offg.setColor(getBackground());
    offg.setColor(new Color(128, 0, 0));
    offg.fillRect(0, 0, getWidth(), getHeight());

    // IGCore.paint(offg);

    g.drawImage(offscreen, 0, 0, getWidth(), getHeight(), this);
  }
Exemple #22
0
 void drawPoint(Graphics g, DrawObject p) {
   if (p == null) {
     return;
   }
   if ((sequencingOn) && (p.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   int x = (int) ((p.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y = (int) ((p.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   if (p.diameter > 1) {
     int r = p.diameter / 2;
     g.fillOval(inset + x - r, D.height - y - inset - r, 2 * r, 2 * r);
   } else {
     g.fillRect(inset + x, D.height - y - inset, 1, 1);
   }
 }
Exemple #23
0
  public void Message(String s, int i) {
    Graphics g = getGraphics();

    if (s == null) {
      g.setColor(bgcolor);
      g.drawRect(400, 50 * i - 10, 200, 10);
      g.fillRect(400, 50 * i - 10, 200, 10);
      return;
    }
    /*
      g.setColor(Color.blue);
      g.drawRect(400,50 * i - 10,200,10);
      g.fillRect(400,50 * i - 10,200,10);
    */
    g.setColor(txtcolor);
    g.drawString(s, 400, 50 * i);
  }
  private synchronized void render(Graphics g) {
    if (level != null) {
      int xScroll = (int) (player.pos.x - screen.w / 2);
      int yScroll = (int) (player.pos.y - (screen.h - 24) / 2);
      soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y);
      level.render(screen, xScroll, yScroll);
    }
    if (!menuStack.isEmpty()) {
      menuStack.peek().render(screen);
    }

    Font.draw(screen, "FPS: " + fps, 10, 10);
    // for (int p = 0; p < players.length; p++) {
    // if (players[p] != null) {
    // String msg = "P" + (p + 1) + ": " + players[p].getScore();
    // Font.draw(screen, msg, 320, screen.h - 24 + p * 8);
    // }
    // }
    if (player != null && menuStack.size() == 0) {
      Font.draw(screen, player.health + " / 10", 340, screen.h - 19);
      Font.draw(screen, "" + player.score, 340, screen.h - 33);
    }

    g.setColor(Color.BLACK);

    g.fillRect(0, 0, getWidth(), getHeight());
    g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
    g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);

    if (!menuStack.isEmpty() || level != null) {

      // render mouse
      renderMouse(screen, mouseButtons);

      g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null);
    }

    // String msg = "FPS: " + fps;
    // g.setColor(Color.LIGHT_GRAY);
    // g.drawString(msg, 11, 11);
    // g.setColor(Color.WHITE);
    // g.drawString(msg, 10, 10);

  }
Exemple #25
0
 void drawImage(Graphics g, DrawObject I) {
   if ((sequencingOn) && (I.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   for (int i = 0; i < I.pixels.length; i++) {
     for (int j = 0; j < I.pixels[i].length; j++) {
       Color c = new Color(I.pixels[i][j][1], I.pixels[i][j][2], I.pixels[i][j][3]);
       g.setColor(c);
       // Note: i starts at the top row of the image.
       int x = j; // x along the x-axis is the column coord of pixels
       int y = I.pixels[i].length - i;
       int x1 = (int) ((x - minX) / (maxX - minX) * (D.width - 2 * inset));
       int y1 = (int) ((y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
       int x2 = (int) ((x + 1 - minX) / (maxX - minX) * (D.width - 2 * inset));
       int y2 = (int) ((y - 1 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
       g.fillRect(inset + x1, D.height - y1 - inset, x2 - x1, y1 - y2);
     }
   }
 }
Exemple #26
0
  private void createImage2() {
    java.awt.Image img2 = createImage(height, width);
    Graphics g = img2.getGraphics();

    g.setColor(Color.lightGray);
    g.fillRect(0, 0, height, width);

    g.setColor(Color.black);
    FontMetrics fm = g.getFontMetrics();
    String str = "Work Unit keyrate (kkeys/sec)";
    int length = fm.stringWidth(str);
    g.drawString(str, (height / 2) - length / 2, fm.getHeight());
    g.dispose();
    g.finalize();
    img2.flush();

    int[] pixels = new int[height * width];
    PixelGrabber pg = new PixelGrabber(img2, 0, 0, height, width, pixels, 0, height);
    try {
      pg.grabPixels();
    } catch (InterruptedException e) {
      System.err.println("interrupted waiting for pixels!");
      return;
    }

    /* Rotate the Image */
    int pixels2[] = new int[height * width];
    for (int x = 0; x < width; x++)
      for (int y = 0; y < height; y++) {
        int c = pixels[y + (x) * height];

        // Due a bug in the MS-JavaVM the Background for Images are not the same
        // as for Panel's  so. mark it as non-opaque ..
        if (c != 0xff000000) {
          c = 0;
        }
        pixels2[x + (height - y - 1) * width] = c;
      }

    img = createImage(new MemoryImageSource(width, height, pixels2, 0, width));
    repaint();
  }
Exemple #27
0
  /**
   * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla
   * en todas partes...
   */
  static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) {
    ButtonModel model = menuItem.getModel();
    Color oldColor = g.getColor();

    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();

    if (menuItem.isOpaque()) {
      g.setColor(menuItem.getBackground());
      g.fillRect(0, 0, menuWidth, menuHeight);
    }

    if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected())
        || model.isArmed()) {
      RoundRectangle2D.Float boton = new RoundRectangle2D.Float();
      boton.x = 1;
      boton.y = 0;
      boton.width = menuWidth - 3;
      boton.height = menuHeight - 1;
      boton.arcwidth = 8;
      boton.archeight = 8;

      GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu());

      Graphics2D g2D = (Graphics2D) g;
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(bgColor);
      g2D.fill(boton);

      g.setColor(bgColor.darker());
      g2D.draw(boton);

      g2D.setPaint(grad);
      g2D.fill(boton);

      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    }

    g.setColor(oldColor);
  }
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(getBackground());
   g.fillRect(0, 0, getWidth(), getHeight());
   int w = bufferedImage.getWidth(this);
   int h = bufferedImage.getHeight(this);
   if (mode == Flip.NONE) {
     g.drawImage(bufferedImage, 0, 0, w, h, this);
   } else if (mode == Flip.VERTICAL) {
     AffineTransform at = AffineTransform.getScaleInstance(1d, -1d);
     at.translate(0, -h);
     Graphics2D g2 = (Graphics2D) g.create();
     g2.drawImage(bufferedImage, at, this);
     g2.dispose();
   } else if (mode == Flip.HORIZONTAL) {
     AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d);
     at.translate(-w, 0);
     AffineTransformOp atOp = new AffineTransformOp(at, null);
     g.drawImage(atOp.filter(bufferedImage, null), 0, 0, w, h, this);
   }
 }
 void drawZoomIndicator(Graphics g) {
   int x1 = 10;
   int y1 = 10;
   double aspectRatio = (double) imageHeight / imageWidth;
   int w1 = 64;
   if (aspectRatio > 1.0) w1 = (int) (w1 / aspectRatio);
   int h1 = (int) (w1 * aspectRatio);
   if (w1 < 4) w1 = 4;
   if (h1 < 4) h1 = 4;
   int w2 = (int) (w1 * ((double) srcRect.width / imageWidth));
   int h2 = (int) (h1 * ((double) srcRect.height / imageHeight));
   if (w2 < 1) w2 = 1;
   if (h2 < 1) h2 = 1;
   int x2 = (int) (w1 * ((double) srcRect.x / imageWidth));
   int y2 = (int) (h1 * ((double) srcRect.y / imageHeight));
   if (zoomIndicatorColor == null) zoomIndicatorColor = new Color(128, 128, 255);
   g.setColor(zoomIndicatorColor);
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   g.drawRect(x1, y1, w1, h1);
   if (w2 * h2 <= 200 || w2 < 10 || h2 < 10) g.fillRect(x1 + x2, y1 + y2, w2, h2);
   else g.drawRect(x1 + x2, y1 + y2, w2, h2);
 }
Exemple #30
0
  /**
   * Parse the text then draw it without any rotation.
   *
   * @param g Graphics context
   * @param x pixel position of the text
   * @param y pixel position of the text
   */
  public void draw(Graphics g, int x, int y) {
    TextState ts;
    int xoffset = x;
    int yoffset = y;

    if (g == null || text == null) return;

    Graphics lg = g.create();

    parseText(g);

    if (justification == CENTER) {
      xoffset = x - width / 2;
    } else if (justification == RIGHT) {
      xoffset = x - width;
    }

    if (background != null) {
      lg.setColor(background);
      lg.fillRect(xoffset, yoffset - ascent, width, height);
      lg.setColor(g.getColor());
    }

    if (font != null) lg.setFont(font);
    if (color != null) lg.setColor(color);

    for (int i = 0; i < list.size(); i++) {
      ts = ((TextState) (list.elementAt(i)));
      if (ts.f != null) lg.setFont(ts.f);
      if (ts.s != null) lg.drawString(ts.toString(), ts.x + xoffset, ts.y + yoffset);
    }

    lg.dispose();

    lg = null;
  }