@Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (drawOverlay) {
      g = g.create();
      AntialiasingManager.activateAntialiasing(g);

      try {
        // Paint a roll over fade out.
        FadeTracker fadeTracker = FadeTracker.getInstance();

        float visibility = 0.0f;
        if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) {
          visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER);
          visibility /= 4;
        } else visibility = 0.5f;

        // Draw black overlay
        g.setColor(new Color(0.0f, 0.0f, 0.0f, visibility));
        g.fillRoundRect(1, 1, width - 2, height - 2, 10, 10);

        // Draw arrow
        g.setColor(Color.WHITE);

        int[] arrowX = new int[] {width - 17, width - 7, width - 12};
        int[] arrowY = new int[] {height - 12, height - 12, height - 7};
        g.fillPolygon(arrowX, arrowY, arrowX.length);
      } finally {
        g.dispose();
      }
    }
  }
 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
 /** This internal method begins a new line */
 protected void newline() {
   charnum = 0; // Reset character number to 0
   linenum++; // Increment line number
   if (linenum >= lines_per_page) { // If we've reached the end of the page
     page.dispose(); //    send page to printer
     page = null; //    but don't start a new page yet.
   }
 }
 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();
 }
Esempio n. 6
0
 public void repaint() {
   text = tf.getText();
   Graphics g = getGraphics();
   if (g != null) {
     recalcPositions(g);
     g.dispose();
   }
   super.repaint();
 }
Esempio n. 7
0
 /** This method creates the off-screen canvas and fills it with the current fill color. */
 private void createOSC() {
   OSC = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
   Graphics osg = OSC.getGraphics();
   Color fillColor = new Color(0, 0, 0);
   fillColor = Color.WHITE;
   osg.setColor(fillColor);
   osg.fillRect(0, 0, getWidth(), getHeight());
   osg.dispose();
 }
Esempio n. 8
0
 private void drawLine(JComponent c, int x, int y) {
   _xedit = x;
   _yedit = y;
   Graphics g = c.getGraphics();
   g.setColor(Color.BLACK);
   g.setXORMode(c.getBackground());
   g.drawLine(_xdown, _ydown, _xedit, _yedit);
   g.dispose();
 }
Esempio n. 9
0
  private void replaceSurfaceData(
      int newBackBufferCount, BufferCapabilities newBackBufferCaps, boolean blit) {
    synchronized (surfaceDataLock) {
      final SurfaceData oldData = getSurfaceData();
      surfaceData = platformWindow.replaceSurfaceData();
      // TODO: volatile image
      //        VolatileImage oldBB = backBuffer;
      BufferedImage oldBB = backBuffer;
      backBufferCount = newBackBufferCount;
      backBufferCaps = newBackBufferCaps;
      final Rectangle size = getSize();
      if (getSurfaceData() != null && oldData != getSurfaceData()) {
        clearBackground(size.width, size.height);
      }

      if (blit) {
        blitSurfaceData(oldData, getSurfaceData());
      }

      if (oldData != null && oldData != getSurfaceData()) {
        // TODO: drop oldData for D3D/WGL pipelines
        // This can only happen when this peer is being created
        oldData.flush();
      }

      // TODO: volatile image
      //        backBuffer = (VolatileImage)delegate.createBackBuffer();
      backBuffer = (BufferedImage) platformWindow.createBackBuffer();
      if (backBuffer != null) {
        Graphics g = backBuffer.getGraphics();
        try {
          Rectangle r = getBounds();
          if (g instanceof Graphics2D) {
            ((Graphics2D) g).setComposite(AlphaComposite.Src);
          }
          g.setColor(nonOpaqueBackground);
          g.fillRect(0, 0, r.width, r.height);
          if (g instanceof SunGraphics2D) {
            ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion());
          }
          if (!isTextured()) {
            g.setColor(getBackground());
            g.fillRect(0, 0, r.width, r.height);
          }
          if (oldBB != null) {
            // Draw the old back buffer to the new one
            g.drawImage(oldBB, 0, 0, null);
            oldBB.flush();
          }
        } finally {
          g.dispose();
        }
      }
    }
    flushOnscreenGraphics();
  }
Esempio n. 10
0
 /**
  * Extracts the buffered image of some component
  *
  * @param myComponent the component for which the BufferedImage is required
  * @param region region to be captured
  * @return the BufferedImage which has the current condition of component
  * @throws IOException
  */
 public static BufferedImage Get_Component_Image(Component myComponent, Rectangle region)
     throws IOException {
   BufferedImage img =
       new BufferedImage(
           myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_RGB);
   Graphics g = img.getGraphics();
   myComponent.paint(g);
   g.dispose();
   return img;
 }
Esempio n. 11
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. 12
0
 /**
  * Finish a mouse drag operation. Nothing is done unless the current tool is a shape tool. For
  * shape tools, the user's shape is drawn to the off-screen canvas, making it a permanent part
  * of the picture, and then the repaint() method is called to show the modified picture on the
  * screen.
  */
 @Override
 public void mouseReleased(MouseEvent evt) {
   dragging = false;
   if (SHAPE_TOOLS.contains(currentTool)) {
     Graphics g = OSC.getGraphics();
     g.setColor(currentColor);
     putCurrentShape(g);
     g.dispose();
     repaint();
   }
 }
Esempio n. 13
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. 14
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);
 }
 public void dispose() {
   super.dispose();
   if (mViewport != null) {
     mViewport.terminate();
     mViewport = null;
   }
   setUniverse(null);
   if (mBackBufferGfx != null) {
     mBackBufferGfx.dispose();
   }
   Logger.log("FramedViewportContainer terminated");
 }
Esempio n. 16
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. 17
0
 /**
  * When the ERASE or SMUDGE tools are used and the mouse jumps from (x1,y1) to (x2,y2), the tool
  * has to be applied to a line of pixel positions between the two points in order to cover the
  * entire line that the mouse moves along. The change is made to the off-screen canvas, and
  * repaint() is called to copy the changes to the screen.
  */
 void applyToolAlongLine(int x1, int y1, int x2, int y2) {
   Graphics g = OSC.getGraphics();
   g.setColor(fillColor); // (for ERASE only)
   int w = OSC.getWidth(); // (for SMUDGE only)
   int h = OSC.getHeight(); // (for SMUDGE only)
   int dist = Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1));
   // dist is the number of points along the line from
   // (x1,y1) to (x2,y2) at which the tool will be applied.
   double dx = (double) (x2 - x1) / dist;
   double dy = (double) (y2 - y1) / dist;
   for (int d = 1; d <= dist; d++) {
     // Apply the tool at one of the points (x,y) along the
     // line from (x1,y1) to (x2,y2).
     int x = (int) Math.round(x1 + dx * d);
     int y = (int) Math.round(y1 + dy * d);
     if (currentTool == Tool.ERASE) {
       // Erase a 10-by-10 block of pixels around (x,y)
       g.fillRect(x - 5, y - 5, 10, 10);
       repaint(x - 5, y - 5, 10, 10);
     } else {
       // For the SMUDGE tool, blend some of the color from
       // the smudgeRed, smudgeGreen, and smudgeBlue arrays
       // into the pixels in a 7-by-7 block around (x,y), and
       // vice versa.  The effect is to smear out the color
       // of pixels that are visited by the tool.
       for (int i = 0; i < 7; i++) {
         for (int j = 0; j < 7; j++) {
           int r = y + j - 3;
           int c = x + i - 3;
           if (!(r < 0 || r >= h || c < 0 || c >= w || smudgeRed[i][j] == -1)) {
             int curCol = OSC.getRGB(c, r);
             int curRed = (curCol >> 16) & 0xFF;
             int curGreen = (curCol >> 8) & 0xFF;
             int curBlue = curCol & 0xFF;
             int newRed = (int) (curRed * 0.7 + smudgeRed[i][j] * 0.3);
             int newGreen = (int) (curGreen * 0.7 + smudgeGreen[i][j] * 0.3);
             int newBlue = (int) (curBlue * 0.7 + smudgeBlue[i][j] * 0.3);
             int newCol = newRed << 16 | newGreen << 8 | newBlue;
             OSC.setRGB(c, r, newCol);
             smudgeRed[i][j] = curRed * 0.3 + smudgeRed[i][j] * 0.7;
             smudgeGreen[i][j] = curGreen * 0.3 + smudgeGreen[i][j] * 0.7;
             smudgeBlue[i][j] = curBlue * 0.3 + smudgeBlue[i][j] * 0.7;
           }
         }
       }
       repaint(x - 3, y - 3, 7, 7);
     }
   }
   g.dispose();
 }
Esempio n. 18
0
    /** @{inheritDoc} */
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      g = g.create();

      try {
        AntialiasingManager.activateAntialiasing(g);

        g.setColor(Color.DARK_GRAY);
        g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10);
      } finally {
        g.dispose();
      }
    }
Esempio n. 19
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;
 }
Esempio n. 20
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. 21
0
  /** Prints the drawing. */
  public void print() {
    tool().deactivate();
    PrintJob printJob = getToolkit().getPrintJob(this, "Print Drawing", null);

    if (printJob != null) {
      Graphics pg = printJob.getGraphics();

      if (pg != null) {
        ((StandardDrawingView) view()).printAll(pg);
        pg.dispose(); // flush page
      }
      printJob.end();
    }
    tool().activate();
  }
Esempio n. 22
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. 23
0
  public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if (cmd.equals("print")) {
      PrintJob pjob = getToolkit().getPrintJob(this, "RoundedRectTest", null);
      if (pjob != null) {
        Graphics pg = pjob.getGraphics();

        if (pg != null) {
          canvas.printAll(pg);
          pg.dispose(); // flush page
        }

        pjob.end();
      }
    }
  }
 public void setViewportSize(Dimension _size) {
   mViewportSize = new Dimension(_size);
   int w = mViewportSize.width + 2 * INSET;
   int h = mViewportSize.height + 2 * INSET;
   // create an off screen buffer for drawing
   if (mBackBufferGfx != null) {
     mBackBufferGfx.dispose(); // free old one
   }
   mBackBufferImg = createImage(w, h);
   Logger.log("Create off-screen buffer of " + w + "x" + h + " (" + mBackBufferImg + ")");
   mBackBufferGfx = mBackBufferImg.getGraphics();
   // Determine the graphics context for the viewport
   mDrawGfx = mBackBufferGfx.create(INSET, INSET, mViewportSize.width, mViewportSize.height);
   mViewport.setActualSize(mViewportSize);
   Logger.log("Viewport resized");
 }
Esempio n. 25
0
 /** Start a drag operation. */
 @Override
 public void mousePressed(MouseEvent evt) {
   startX = prevX = currentX = evt.getX();
   startY = prevY = currentY = evt.getY();
   dragging = true;
   if (currentTool == Tool.ERASE) {
     // Erase a 10-by-10 block around the starting mouse position.
     Graphics g = OSC.getGraphics();
     g.setColor(fillColor);
     g.fillRect(startX - 5, startY - 5, 10, 10);
     g.dispose();
     repaint(startX - 5, startY - 5, 10, 10);
   } else if (currentTool == Tool.SMUDGE) {
     // Record the colors in a 7-by-7 block of pixels around the
     // starting mouse position into the arrays smudgeRed,
     // smudgeGreen, and smudgeBlue.  These arrays hold the
     // red, green, and blue components of the colors.
     if (smudgeRed == null) {
       // Create the arrays, if they have not already been created.
       smudgeRed = new double[7][7];
       smudgeGreen = new double[7][7];
       smudgeBlue = new double[7][7];
     }
     int w = OSC.getWidth();
     int h = OSC.getHeight();
     int x = evt.getX();
     int y = evt.getY();
     for (int i = 0; i < 7; i++) {
       for (int j = 0; j < 7; j++) {
         int r = y + j - 3;
         int c = x + i - 3;
         if (r < 0 || r >= h || c < 0 || c >= w) {
           // A -1 in the smudgeRed array indicates that the
           // corresponding pixel was outside the canvas.
           smudgeRed[i][j] = -1;
         } else {
           int color = OSC.getRGB(c, r);
           smudgeRed[i][j] = (color >> 16) & 0xFF;
           smudgeGreen[i][j] = (color >> 8) & 0xFF;
           smudgeBlue[i][j] = color & 0xFF;
         }
       }
     }
   }
 }
Esempio n. 26
0
  @Override
  public void paint(Graphics g) {
    super.paint(g);

    // menu on game over
    if (c.getLifes() < 1) {
      showMenu = true;
    }

    this.paintBackground((Graphics2D) g);
    this.paintItems((Graphics2D) g);
    this.paintLifes((Graphics2D) g);
    this.paintScore((Graphics2D) g);
    this.paintMenu((Graphics2D) g);

    Toolkit.getDefaultToolkit().sync();
    g.dispose();
  }
  /**
   * Paints a customized background.
   *
   * @param g the <tt>Graphics</tt> object through which we paint
   */
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    g = g.create();

    if (!(treeNode instanceof GroupNode) && !isSelected) return;

    AntialiasingManager.activateAntialiasing(g);

    Graphics2D g2 = (Graphics2D) g;

    try {
      internalPaintComponent(g2);
    } finally {
      g.dispose();
    }
  }
Esempio n. 28
0
  @Override
  public final synchronized void render() {
    final Graphics graphics = buffer.getDrawGraphics();
    if (smoothScale) {
      ((Graphics2D) graphics)
          .setRenderingHint(
              RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    }
    if (inFullScreen) {
      graphics.setColor(Color.BLACK);
      DisplayMode dm = gd.getDisplayMode();
      int scrnheight = dm.getHeight();
      int scrnwidth = dm.getWidth();
      // don't ask why this needs to be done every frame,
      // but it does b/c the canvas keeps resizing itself
      canvas.setSize(scrnwidth, scrnheight);
      graphics.fillRect(0, 0, scrnwidth, scrnheight);
      if (PrefsSingleton.get().getBoolean("maintainAspect", true)) {
        double scalefactor = getmaxscale(scrnwidth, scrnheight);
        int height = (int) (NES_HEIGHT * scalefactor);
        int width = (int) (256 * scalefactor * 1.1666667);
        graphics.drawImage(
            frame,
            ((scrnwidth / 2) - (width / 2)),
            ((scrnheight / 2) - (height / 2)),
            width,
            height,
            null);
      } else {
        graphics.drawImage(frame, 0, 0, scrnwidth, scrnheight, null);
      }
      graphics.setColor(Color.DARK_GRAY);
      graphics.drawString(this.getTitle(), 16, 16);

    } else {
      graphics.drawImage(
          frame, 0, 0, NES_WIDTH * screenScaleFactor, NES_HEIGHT * screenScaleFactor, null);
    }

    graphics.dispose();
    buffer.show();
  }
Esempio n. 29
0
  public void update(Graphics g) {
    Dimension size = getSize();
    if (offscreen == null)
      offscreen =
          createImage((size.width < 1) ? 1 : size.width, (size.height < 1) ? 1 : size.height);

    Graphics og = offscreen.getGraphics();
    if (og != null)
      try {
        og.setClip(g.getClip());

        og.setColor(getBackground());
        og.fillRect(0, 0, size.width, size.height);

        super.paint(og);
      } finally {
        og.dispose();
      }

    paint(g);
  }
Esempio n. 30
0
 /**
  * Continue a drag operation when the user drags the mouse. For the CURVE tool, a line is drawn
  * from the previous mouse position to the current mouse position in the off-screen canvas, and
  * the repaint() method is called for a rectangle that contains the line segment that was drawn.
  * For shape tools, the off-screen canvas is not changed, but the repaint() method is called so
  * that the paintComponent() method can redraw the picture with the user's shape in the new
  * position. For the SMUDGE and ERASE tools, the tool is applied along a line from the previous
  * mouse position to the current position;
  */
 @Override
 public void mouseDragged(MouseEvent evt) {
   currentX = evt.getX();
   currentY = evt.getY();
   if (currentTool == Tool.CURVE) {
     Graphics g = OSC.getGraphics();
     g.setColor(currentColor);
     g.drawLine(prevX, prevY, currentX, currentY);
     g.dispose();
     repaintRect(prevX, prevY, currentX, currentY);
   } else if (SHAPE_TOOLS.contains(currentTool)) {
     // Repaint the rectangles occupied by the previous position of
     // the shape and by its current position.
     repaintRect(startX, startY, prevX, prevY);
     repaintRect(startX, startY, currentX, currentY);
   } else {
     // Tool has to be ERASE or SMUDGE
     applyToolAlongLine(prevX, prevY, currentX, currentY);
   }
   prevX = currentX;
   prevY = currentY;
 }