コード例 #1
0
  private void populateMedia() {
    initPrefinedMediaMaps();

    if (paperSet != null) {
      return; // already inited
    }
    Media[] media = (Media[]) service.getSupportedAttributeValues(Media.class, null, null);
    Set<Paper> pSet = new TreeSet<Paper>(PaperComparator.theComparator);
    Set<PaperSource> tSet = new TreeSet<PaperSource>(PaperSourceComparator.theComparator);
    /* We will get back a list of Media and want to look for
     * MediaSizeName and MediaTray instances and map to FX classes.
     * We will hard code here recognising the set we've chosen to
     * expose in FX API.
     * For the rest we'll need to create custom instances.
     */

    if (media != null) {
      for (int i = 0; i < media.length; i++) {
        Media m = media[i];
        if (m instanceof MediaSizeName) {
          pSet.add(addPaper(((MediaSizeName) m)));
        } else if (m instanceof MediaTray) {
          tSet.add(addPaperSource((MediaTray) m));
        }
      }
    }
    paperSet = Collections.unmodifiableSet(pSet);
    paperSourceSet = Collections.unmodifiableSet(tSet);
  }
コード例 #2
0
 public Set<PrintResolution> supportedPrintResolution() {
   if (resSet != null) {
     return resSet;
   }
   Set<PrintResolution> rSet =
       new TreeSet<PrintResolution>(PrintResolutionComparator.theComparator);
   PrinterResolution[] pr = null;
   try {
     pr =
         (PrinterResolution[])
             service.getSupportedAttributeValues(PrinterResolution.class, null, null);
   } catch (Exception e) {
   }
   if (pr == null || pr.length == 0) {
     rSet.add(defaultPrintResolution());
   } else {
     for (int i = 0; i < pr.length; i++) {
       int cfr = pr[i].getCrossFeedResolution(ResolutionSyntax.DPI);
       int fr = pr[i].getFeedResolution(ResolutionSyntax.DPI);
       rSet.add(PrintHelper.createPrintResolution(cfr, fr));
     }
   }
   resSet = Collections.unmodifiableSet(rSet);
   return resSet;
 }
コード例 #3
0
 public Set<PrintQuality> supportedPrintQuality() {
   if (qualitySet == null) {
     Set<PrintQuality> set = new TreeSet<PrintQuality>();
     javax.print.attribute.standard.PrintQuality[] arr = null;
     try {
       arr =
           (javax.print.attribute.standard.PrintQuality[])
               service.getSupportedAttributeValues(
                   javax.print.attribute.standard.PrintQuality.class, null, null);
     } catch (Exception e) {
     }
     if (arr == null || arr.length == 0) {
       set.add(PrintQuality.NORMAL);
     } else {
       for (int i = 0; i < arr.length; i++) {
         if (arr[i] == javax.print.attribute.standard.PrintQuality.NORMAL) {
           set.add(PrintQuality.NORMAL);
         }
         if (arr[i] == javax.print.attribute.standard.PrintQuality.DRAFT) {
           set.add(PrintQuality.DRAFT);
         }
         if (arr[i] == javax.print.attribute.standard.PrintQuality.HIGH) {
           set.add(PrintQuality.HIGH);
         }
       }
     }
     qualitySet = Collections.unmodifiableSet(set);
   }
   return qualitySet;
 }
コード例 #4
0
  public Set<PageOrientation> supportedOrientation() {
    if (orientSet != null) {
      return orientSet;
    }

    Set<PageOrientation> oset = new TreeSet<PageOrientation>();
    OrientationRequested[] or = null;
    try {
      or =
          (OrientationRequested[])
              service.getSupportedAttributeValues(OrientationRequested.class, null, null);
    } catch (Exception e) {
    }
    if (or == null || or.length == 0) {
      oset.add(defaultOrientation());
    } else {
      for (int i = 0; i < or.length; i++) {
        if (or[i] == OrientationRequested.PORTRAIT) {
          oset.add(PageOrientation.PORTRAIT);
        } else if (or[i] == OrientationRequested.REVERSE_PORTRAIT) {
          oset.add(PageOrientation.REVERSE_PORTRAIT);
        } else if (or[i] == OrientationRequested.LANDSCAPE) {
          oset.add(PageOrientation.LANDSCAPE);
        } else {
          oset.add(PageOrientation.REVERSE_LANDSCAPE);
        }
      }
    }
    orientSet = Collections.unmodifiableSet(oset);
    return orientSet;
  }
コード例 #5
0
 public Set<PrintSides> supportedSides() {
   if (sidesSet == null) {
     Set<PrintSides> sSet = new TreeSet<PrintSides>();
     Sides[] ss = null;
     try {
       ss = (Sides[]) service.getSupportedAttributeValues(Sides.class, null, null);
     } catch (Exception e) {
     }
     if (ss != null) {
       for (int i = 0; i < ss.length; i++) {
         if (ss[i] == Sides.ONE_SIDED) {
           sSet.add(PrintSides.ONE_SIDED);
         }
         if (ss[i] == Sides.DUPLEX) {
           sSet.add(PrintSides.DUPLEX);
         }
         if (ss[i] == Sides.TUMBLE) {
           sSet.add(PrintSides.TUMBLE);
         }
       }
     }
     sidesSet = Collections.unmodifiableSet(sSet);
   }
   return sidesSet;
 }
コード例 #6
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;
 }
コード例 #7
0
 public int maxCopies() {
   if (maxCopies > 0) {
     return maxCopies;
   }
   CopiesSupported copies = null;
   try {
     copies =
         (CopiesSupported) service.getSupportedAttributeValues(CopiesSupported.class, null, null);
   } catch (Exception e) {
   }
   if (copies != null) {
     int[][] members = copies.getMembers();
     if (members != null && members.length > 0 && members[0].length > 0) {
       maxCopies = members[0][1];
     }
   }
   if (maxCopies == 0) {
     maxCopies = 999;
   }
   return maxCopies;
 }
コード例 #8
0
 public Set<PrintColor> supportedPrintColor() {
   if (colorSet == null) {
     Set<PrintColor> cSet = new TreeSet<PrintColor>();
     Chromaticity[] sc = null;
     try {
       sc = (Chromaticity[]) service.getSupportedAttributeValues(Chromaticity.class, null, null);
     } catch (Exception e) {
     }
     if (sc != null) {
       for (int i = 0; i < sc.length; i++) {
         if (sc[i] == Chromaticity.COLOR) {
           cSet.add(PrintColor.COLOR);
         }
         if (sc[i] == Chromaticity.MONOCHROME) {
           cSet.add(PrintColor.MONOCHROME);
         }
       }
     }
     colorSet = Collections.unmodifiableSet(cSet);
   }
   return colorSet;
 }
コード例 #9
0
 public Set<Collation> supportedCollations() {
   if (collateSet == null) {
     Set<Collation> cSet = new TreeSet<Collation>();
     SheetCollate[] sc = null;
     try {
       sc = (SheetCollate[]) service.getSupportedAttributeValues(SheetCollate.class, null, null);
     } catch (Exception e) {
     }
     if (sc != null) {
       for (int i = 0; i < sc.length; i++) {
         if (sc[i] == SheetCollate.UNCOLLATED) {
           cSet.add(Collation.UNCOLLATED);
         }
         if (sc[i] == SheetCollate.COLLATED) {
           cSet.add(Collation.COLLATED);
         }
       }
     }
     collateSet = Collections.unmodifiableSet(cSet);
   }
   return collateSet;
 }