示例#1
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 void collect() {
   for (int i = 0; i < variable_list.size(); i++) {
     ((NslVariable) variable_list.elementAt(i)).collect();
   }
   Graphics gr = getGraphics();
   paint_partial(gr);
   gr.dispose();
 }
 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();
 }
示例#4
0
文件: LJ3MDApp.java 项目: eskilj/mvp
 /**
  * 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;
 }
  /** 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();
  }
示例#6
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;
 }
  // 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;
  }
示例#8
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);
  }
示例#9
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;
  }
示例#10
0
 public void actionPerformed(ActionEvent e) {
   PrintJob pjob = getToolkit().getPrintJob(textViewerFrame, "Printing Nslm", null);
   if (pjob != null) {
     Graphics pg = pjob.getGraphics();
     if (pg != null) {
       // todo: this should print from
       // the file not from the screen.
       // if (editor1!=null) {
       //    editor1.print(pg); //print crashes, must use printAll
       // }
       // if (scroller1!=null) {
       //    scroller1.printAll(pg); //is clipping on left
       // }
       if (scroller1 != null) {
         JViewport jvp = scroller1.getViewport();
         jvp.printAll(pg);
       }
       pg.dispose();
     }
     pjob.end();
   }
 }
示例#11
0
 /**
  * This is the close() method that all Writer subclasses must implement. Print the pending page
  * (if any) and terminate the PrintJob.
  */
 public void close() {
   synchronized (this.lock) {
     if (page != null) page.dispose(); // Send page to the printer
     job.end(); // Terminate the job
   }
 }