Esempio n. 1
0
  /** Overrides <code>Graphics.fillArc</code>. */
  public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling arc: "
                  + new Rectangle(x, y, width, height)
                  + " startAngle: "
                  + startAngle
                  + " arcAngle: "
                  + arcAngle);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
        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.fillArc(x, y, width, height, startAngle, arcAngle);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  }
 public Image getScreenshot() {
   BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   Graphics g = image.getGraphics();
   paint(g);
   g.dispose();
   return image;
 }
Esempio n. 3
0
  /** Overrides <code>Graphics.drawChars</code>. */
  public void drawChars(char data[], int offset, int length, int x, int y) {
    DebugGraphicsInfo info = info();

    Font font = graphics.getFont();

    if (debugLog()) {
      info().log(toShortString() + " Drawing chars at " + new Point(x, y));
    }

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

        debugGraphics.drawChars(data, offset, length, x, y);
        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.drawChars(data, offset, length, x, y);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawChars(data, offset, length, x, y);
  }
Esempio n. 4
0
  /** Overrides <code>Graphics.drawString</code>. */
  public void drawString(AttributedCharacterIterator iterator, int x, int y) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Drawing text: \"" + iterator + "\" at: " + new Point(x, y));
    }

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

        debugGraphics.drawString(iterator, x, y);
        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.drawString(iterator, x, y);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawString(iterator, x, y);
  }
Esempio n. 5
0
  /** Overrides <code>Graphics.drawLine</code>. */
  public void drawLine(int x1, int y1, int x2, int y2) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Drawing line: from "
                  + pointToString(x1, y1)
                  + " to "
                  + pointToString(x2, y2));
    }

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

        debugGraphics.drawLine(x1, y1, x2, y2);
        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.drawLine(x1, y1, x2, y2);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawLine(x1, y1, x2, y2);
  }
 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();
 }
Esempio n. 7
0
  /** Overrides <code>Graphics.fill3DRect</code>. */
  public void fill3DRect(int x, int y, int width, int height, boolean raised) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling 3D rect: "
                  + new Rectangle(x, y, width, height)
                  + " Raised bezel: "
                  + raised);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fill3DRect(x, y, width, height, raised);
        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.fill3DRect(x, y, width, height, raised);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fill3DRect(x, y, width, height, raised);
  }
Esempio n. 8
0
  /** Overrides <code>Graphics.drawImage</code>. */
  public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y));
    }

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

        debugGraphics.drawImage(img, x, y, observer);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      int i, count = (info.flashCount * 2) - 1;
      ImageProducer oldProducer = img.getSource();
      ImageProducer newProducer =
          new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
      Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
      DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();

      Image imageToDraw;
      for (i = 0; i < count; i++) {
        imageToDraw = (i % 2) == 0 ? newImage : img;
        loadImage(imageToDraw);
        graphics.drawImage(imageToDraw, x, y, imageObserver);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
    }
    return graphics.drawImage(img, x, y, observer);
  }
Esempio n. 9
0
  /** Overrides <code>Graphics.drawOval</code>. */
  public void drawOval(int x, int y, int width, int height) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Drawing oval: " + new Rectangle(x, y, width, height));
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawOval(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.drawOval(x, y, width, height);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawOval(x, y, width, height);
  }
 protected void computeGeometry() {
   pictHalfWidth = Width.getInt() / 2;
   pictWidth = pictHalfWidth + pictHalfWidth - 1;
   pictHeight = Height.getInt();
   xLoc = -pictHalfWidth;
   yLoc = -pictHeight / 2;
   setFramesPerCycle(pictWidth - 1);
   setFrameIncrement(FrameIncrement.getInt());
   // System.out.println("width = " + pictWidth);
   // System.out.println("    x = " + xLoc);
   // System.out.println("    y = " + yLoc);
   PxlColor[] ramp = AColor.getPxlColor().sinusoidalRampTo(BColor.getPxlColor(), pictHalfWidth);
   // System.out.println("w=" + (4*pictHalfWidth-1) + ", h=" + pictHeight);
   int ibWidth = 4 * pictHalfWidth - 1;
   if ((imageBuffer == null)
       || (imageBuffer.getWidth() != ibWidth)
       || (imageBuffer.getHeight() != pictHeight)) {
     imageBuffer = new BufferedImage(ibWidth, pictHeight, BufferedImage.TYPE_INT_RGB);
   }
   Graphics g = imageBuffer.getGraphics();
   for (int x = 0; x < pictHalfWidth; x++) {
     g.setColor(ramp[x].dev());
     g.drawLine(x, 0, x, pictHeight - 1);
     if (x < (pictHalfWidth - 1))
       g.drawLine(pictWidth - x - 1, 0, pictWidth - x - 1, pictHeight - 1);
     if (x > 0) g.drawLine(pictWidth + x - 1, 0, pictWidth + x - 1, pictHeight - 1);
     if ((x > 0) && (x < (pictHalfWidth - 1)))
       g.drawLine(4 * pictHalfWidth - 4 - x, 0, 4 * pictHalfWidth - 4 - x, pictHeight - 1);
   }
   g.dispose();
   BitMapElement p = (BitMapElement) getDisplayElement(pictElement);
   p.setImage(imageBuffer);
   p.setLocation(xLoc, yLoc);
   p.setClipRect(xLoc, yLoc, pictWidth, pictHeight);
 }
Esempio n. 11
0
 public static BufferedImage copyImage(BufferedImage source) {
   BufferedImage b =
       new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = b.getGraphics();
   g.drawImage(source, 0, 0, null);
   g.dispose();
   return b;
 }
 private void scaleImage() {
   Image img =
       back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH);
   back =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = back.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
 }
 @Override
 protected void paintTabBackground(
     Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
   g = g.create();
   try {
     internalPaintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
   } finally {
     g.dispose();
   }
 }
Esempio n. 14
0
 /**
  * Prepare a buffer for the image, return if the canvas is ready Only need to call this when the
  * size of the canvas is changed, Since we automatically detect the size change in paint() only
  * call this on start
  */
 public boolean newImgBuf() {
   Dimension sz = getSize();
   if (sz.width == 0 || sz.height == 0) return false;
   // quit if the current image already has the right size
   if (img != null && imgG != null && sz.equals(imgSize)) return true;
   img = createImage(sz.width, sz.height);
   if (imgG != null) imgG.dispose();
   imgG = img.getGraphics();
   imgSize = sz;
   return true;
 }
Esempio n. 15
0
 private static ImageIcon makeGrayImageIcon1(Image img) {
   BufferedImage source =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = source.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   ColorConvertOp colorConvert =
       new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
   BufferedImage destination = colorConvert.filter(source, null);
   return new ImageIcon(destination);
 }
Esempio n. 16
0
  /** Overrides <code>Graphics.drawImage</code>. */
  public boolean drawImage(
      Image img,
      int dx1,
      int dy1,
      int dx2,
      int dy2,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      Color bgcolor,
      ImageObserver observer) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info.log(
          toShortString()
              + " Drawing image: "
              + img
              + " destination: "
              + new Rectangle(dx1, dy1, dx2, dy2)
              + " source: "
              + new Rectangle(sx1, sy1, sx2, sy2)
              + ", bgcolor: "
              + bgcolor);
    }

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

        debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      int i, count = (info.flashCount * 2) - 1;
      ImageProducer oldProducer = img.getSource();
      ImageProducer newProducer =
          new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
      Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
      DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();

      Image imageToDraw;
      for (i = 0; i < count; i++) {
        imageToDraw = (i % 2) == 0 ? newImage : img;
        loadImage(imageToDraw);
        graphics.drawImage(
            imageToDraw, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, imageObserver);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
    }
    return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
  }
Esempio n. 17
0
 private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) {
   RescaleOp op =
       new RescaleOp(new float[] {1.2f, 1.2f, 1.2f, 1f}, new float[] {0f, 0f, 0f, 0f}, null);
   BufferedImage img =
       new BufferedImage(
           srcIcon.getIconWidth(), srcIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics g = img.getGraphics();
   // g.drawImage(srcIcon.getImage(), 0, 0, null);
   srcIcon.paintIcon(null, g, 0, 0);
   g.dispose();
   return new ImageIcon(op.filter(img, null));
 }
Esempio n. 18
0
 public void loadImage() throws IOException {
   nonMax = ImageIO.read(new File(path));
   width = nonMax.getWidth();
   height = nonMax.getHeight();
   rmax = width > height ? height / 2 : width / 2;
   accRMax = (rmax + offset - 1) / offset;
   whichRadius.setMaximum(accRMax);
   img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   Graphics g = img.getGraphics();
   g.drawImage(nonMax, 0, 0, null);
   g.dispose();
   res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   g = res.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   greyScale = copyImage(nonMax);
   ImageIcon icon = new ImageIcon(img);
   ImageIcon icon2 = new ImageIcon(greyScale);
   lbl1.setIcon(icon);
   lbl2.setIcon(icon2);
 }
Esempio n. 19
0
 private static ImageIcon makeGrayImageIcon2(Image img) {
   int w = img.getWidth(null);
   int h = img.getHeight(null);
   BufferedImage destination = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = destination.createGraphics();
   //// g.setColor(Color.WHITE);
   // https://community.oracle.com/thread/1373262 Color to Grayscale to Binary
   // g.fillRect(0, 0, w, h); // need to pre-fill(alpha?)
   g.drawImage(img, 0, 0, null);
   g.dispose();
   return new ImageIcon(destination);
 }
Esempio n. 20
0
 /** Scales an image. To be used for tiles. Probably not the most efficient scaling method. */
 public static Image scaleImage(Image orig, int scale) {
   Image result;
   if (scale != 1) {
     int width = orig.getWidth(null);
     int height = orig.getHeight(null);
     // Scale cropped image to proper size
     result = new BufferedImage(width * scale, height * scale, BufferedImage.TYPE_INT_ARGB);
     Graphics g = ((BufferedImage) result).createGraphics();
     g.drawImage(orig, 0, 0, width * scale, height * scale, 0, 0, width - 1, height - 1, null);
     g.dispose();
   } else {
     return orig;
   }
   return result;
 }
Esempio n. 21
0
 private void paintScreen()
       // use active rendering to put the buffered image on-screen
     {
   Graphics g;
   try {
     g = this.getGraphics();
     if ((g != null) && (dbImage != null)) g.drawImage(dbImage, 0, 0, null);
     // Sync the display on some systems.
     // (on Linux, this fixes event queue problems)
     Toolkit.getDefaultToolkit().sync();
     g.dispose();
   } catch (Exception e) {
     System.out.println("Graphics context error: " + e);
   }
 } // end of paintScreen()
Esempio n. 22
0
 //     private BufferedImage makeBI(String str) {
 //         BufferedImage image;
 //         try {
 //             image = ImageIO.read(getClass().getResource(str));
 //         } catch (IOException ioe) {
 //             ioe.printStackTrace();
 //             return null;
 //         }
 //         return image;
 //     }
 private static int[] getData(ImageIcon imageIcon, int w, int h) {
   Image img = imageIcon.getImage();
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics g = image.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   return ((DataBufferInt) (image.getRaster().getDataBuffer())).getData();
   //         int[] pixels = new int[w * h];
   //         try {
   //             new PixelGrabber(image, 0, 0, width, height, pixels, 0, width).grabPixels();
   //         } catch (InterruptedException ex) {
   //             ex.printStackTrace();
   //         }
   //         return pixels;
 }
  // This method returns a buffered image with the contents of an image
  // Source: http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html
  public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
      return (BufferedImage) image;
    }

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels; for this method's
    // implementation, see Determining If an Image Has Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
      // Determine the type of transparency of the new buffered image
      int transparency = Transparency.OPAQUE;
      if (hasAlpha) {
        transparency = Transparency.BITMASK;
      }

      // Create the buffered image
      GraphicsDevice gs = ge.getDefaultScreenDevice();
      GraphicsConfiguration gc = gs.getDefaultConfiguration();
      bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
      // The system does not have a screen
    }

    if (bimage == null) {
      // Create a buffered image using the default color model
      int type = BufferedImage.TYPE_INT_RGB;
      if (hasAlpha) {
        type = BufferedImage.TYPE_INT_ARGB;
      }
      bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
  }
Esempio n. 24
0
  static Icon reescala(Icon ic, int maxW, int maxH) {
    if (ic == null) {
      return null;
    }
    if (ic.getIconHeight() == maxH && ic.getIconWidth() == maxW) {
      return ic;
    }

    BufferedImage bi =
        new BufferedImage(ic.getIconHeight(), ic.getIconWidth(), BufferedImage.TYPE_INT_ARGB);

    Graphics g = bi.createGraphics();
    ic.paintIcon(null, g, 0, 0);
    g.dispose();

    Image bf = bi.getScaledInstance(maxW, maxH, Image.SCALE_SMOOTH);

    return new ImageIcon(bf);
  }
Esempio n. 25
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();
  }
Esempio n. 26
0
  public static java.awt.image.BufferedImage loadBufferedImageFromResources(
      Component c, String filename) {

    try {
      Misc m = new Misc();
      java.awt.Image img = loadImageFromResources(filename);
      MediaTracker mt = new MediaTracker(c);
      mt.addImage(img, 0);
      mt.waitForID(0);
      int width = img.getWidth(null);
      int height = img.getHeight(null);
      BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics gg = bi.getGraphics();
      gg.drawImage(img, 0, 0, null);
      gg.dispose();
      return bi;
    } catch (Exception ex) {
      System.out.println(ex.toString());
    }
    return null;
  }
Esempio n. 27
0
  private JLabel makeLabelIcon() {
    ImageIcon i = new ImageIcon(getClass().getResource("duke.gif"));
    Dimension d = new Dimension(i.getIconWidth(), i.getIconHeight());
    final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.createGraphics();
    i.paintIcon(null, g, 0, 0);
    g.dispose();
    final JLabel icon =
        new JLabel(i) {
          @Override
          public boolean contains(int x, int y) {
            return super.contains(x, y) && ((image.getRGB(x, y) >> 24) & 0xff) != 0;
          }
        };
    icon.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    MouseAdapter l =
        new MouseAdapter() {
          private final transient Point start = new Point();
          private Point loc;

          @Override
          public void mousePressed(MouseEvent me) {
            start.setLocation(me.getPoint());
          }

          @Override
          public void mouseDragged(MouseEvent me) {
            loc = icon.getLocation(loc);
            int x = loc.x - start.x + me.getX();
            int y = loc.y - start.y + me.getY();
            icon.setLocation(x, y);
          }
        };
    icon.addMouseListener(l);
    icon.addMouseMotionListener(l);
    icon.setBounds(new Rectangle(22, 22, d.width, d.height));
    return icon;
  }
Esempio n. 28
0
  /**
   * Overrides the <code>paintComponent</code> method in <tt>JComponent</tt> to paint the screen
   * capture image as a background of this component.
   */
  @Override
  protected void paintComponent(Graphics g) {
    g = g.create();
    try {
      AntialiasingManager.activateAntialiasing(g);

      Graphics2D g2 = (Graphics2D) g;
      int width = getWidth();
      int height = getHeight();

      g2.drawImage(this.background, 0, 0, null);

      g2.setColor(new Color(255, 255, 255, 180));

      g2.fillRoundRect(0, 0, width, height, 10, 10);

      g2.setColor(Constants.BORDER_COLOR);

      g2.drawRoundRect(0, 0, width - 1, height - 1, 10, 10);
    } finally {
      g.dispose();
    }
  }
Esempio n. 29
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;
  }
Esempio n. 30
0
  /** Overrides <code>Graphics.fillPolygon</code>. */
  public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling polygon: "
                  + " nPoints: "
                  + nPoints
                  + " X's: "
                  + xPoints
                  + " Y's: "
                  + yPoints);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fillPolygon(xPoints, yPoints, nPoints);
        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.fillPolygon(xPoints, yPoints, nPoints);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillPolygon(xPoints, yPoints, nPoints);
  }