Пример #1
0
 /**
  * For any given paper, this retrieves the hardware margins, or a reasonable and safe guess if
  * they aren't available.
  */
 public Rectangle2D printableArea(Paper paper) {
   int INCH = MediaSize.INCH;
   Rectangle2D area = null;
   MediaSizeName msn =
       MediaSize.findMedia(
           (float) paper.getWidth(), (float) paper.getHeight(), (int) (INCH / 72.0));
   if (msn != null) {
     PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
     pras.add(msn);
     MediaPrintableArea[] mpa =
         (MediaPrintableArea[])
             service.getSupportedAttributeValues(MediaPrintableArea.class, null, pras);
     if (mpa != null && mpa.length > 0) {
       int MPA_INCH = MediaPrintableArea.INCH;
       area =
           new Rectangle2D(
               mpa[0].getX(MPA_INCH),
               mpa[0].getY(MPA_INCH),
               mpa[0].getWidth(MPA_INCH),
               mpa[0].getHeight(MPA_INCH));
     }
   }
   // If we could not get the area for whatever reason,
   // then go with 0.75" margins unless they are too large
   // ie its a really small paper.
   if (area == null) {
     double pw = (paper.getWidth() / 72.0);
     ;
     double ph = (paper.getHeight() / 72.0);
     double iw, ih;
     if (pw < 3.0) {
       iw = 0.75 * pw;
     } else {
       iw = pw - 1.5;
     }
     if (ph < 3.0) {
       ih = 0.75 * ph;
     } else {
       ih = ph - 1.5;
     }
     double lm = (pw - iw) / 2.0;
     double tm = (ph - ih) / 2.0;
     area = new Rectangle2D(lm, tm, iw, ih);
   }
   return area;
 }
Пример #2
0
 /** This sorts papers lexically based on name, not size. */
 public int compare(Paper p1, Paper p2) {
   return p1.getName().compareTo(p2.getName());
 }