Package javax.print.attribute.standard

Examples of javax.print.attribute.standard.MediaPrintableArea


    final Media media = MediaSize.findMedia((float) (paper.getWidth() / POINTS_PER_INCH),
        (float) (paper.getHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);
    attributes.add(media);

    final MediaPrintableArea printableArea = new MediaPrintableArea
        ((float) (paper.getImageableX() / POINTS_PER_INCH),
            (float) (paper.getImageableY() / POINTS_PER_INCH),
            (float) (paper.getImageableWidth() / POINTS_PER_INCH),
            (float) (paper.getImageableHeight() / POINTS_PER_INCH),
            Size2DSyntax.INCH);
View Full Code Here


  }

  public static PageFormat extractPageFormat(final PrintRequestAttributeSet attributeSet)
  {
    final Media media = (Media) attributeSet.get(Media.class);
    final MediaPrintableArea printableArea =
        (MediaPrintableArea) attributeSet.get(MediaPrintableArea.class);
    final OrientationRequested orientationRequested =
        (OrientationRequested) attributeSet.get(OrientationRequested.class);

    final MediaSize mediaSize = lookupMediaSize(media);
View Full Code Here

        if (service == null || attributes == null) {
            return pf;
        }

        Media media = (Media)attributes.get(Media.class);
        MediaPrintableArea mpa =
            (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
        OrientationRequested orientReq =
           (OrientationRequested)attributes.get(OrientationRequested.class);

        if (media == null && mpa == null && orientReq == null) {
           return pf;
        }
        Paper paper = pf.getPaper();

  /* If there's a media but no media printable area, we can try
   * to retrieve the default value for mpa and use that.
   */
  if (mpa == null && media != null &&
      service.isAttributeCategorySupported(MediaPrintableArea.class)) {
      Object mpaVals =
    service.getSupportedAttributeValues(MediaPrintableArea.class,
                null, attributes);
      if (mpaVals instanceof MediaPrintableArea[] &&
    ((MediaPrintableArea[])mpaVals).length > 0) {
    mpa = ((MediaPrintableArea[])mpaVals)[0];
      }
  }

        if (media != null &&
            service.isAttributeValueSupported(media, null, attributes)) {
            if (media instanceof MediaSizeName) {
                MediaSizeName msn = (MediaSizeName)media;
                MediaSize msz = MediaSize.getMediaSizeForName(msn);
                if (msz != null) {
        double inch = 72.0;
                    double paperWid = msz.getX(MediaSize.INCH) * inch;
                    double paperHgt = msz.getY(MediaSize.INCH) * inch;
                    paper.setSize(paperWid, paperHgt);
        if (mpa == null) {
      paper.setImageableArea(inch, inch,
                 paperWid-2*inch,
                 paperHgt-2*inch);
        }
    }
            }
        }

        if (mpa != null &&
      service.isAttributeValueSupported(mpa, null, attributes)) {
            float [] printableArea =
                mpa.getPrintableArea(MediaPrintableArea.INCH);
            for (int i=0; i < printableArea.length; i++) {
                printableArea[i] = printableArea[i]*72.0f;
            }
            paper.setImageableArea(printableArea[0], printableArea[1],
                                   printableArea[2], printableArea[3]);
View Full Code Here

          printableHeight = jPrint.getPageHeight();
          break;
      }
     
      printRequestAttributeSet.add(
        new MediaPrintableArea(
          0f,
          0f,
          printableWidth / 72f,
          printableHeight / 72f,
          MediaPrintableArea.INCH
View Full Code Here

    final Media media = MediaSize.findMedia((float) (paper.getWidth() / POINTS_PER_INCH),
        (float) (paper.getHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);
    attributes.add(media);

    final MediaPrintableArea printableArea = new MediaPrintableArea
        ((float) (paper.getImageableX() / POINTS_PER_INCH),
            (float) (paper.getImageableY() / POINTS_PER_INCH),
            (float) (paper.getImageableWidth() / POINTS_PER_INCH),
            (float) (paper.getImageableHeight() / POINTS_PER_INCH),
            Size2DSyntax.INCH);
View Full Code Here

  }

  public static PageFormat extractPageFormat(final PrintRequestAttributeSet attributeSet)
  {
    final Media media = (Media) attributeSet.get(Media.class);
    final MediaPrintableArea printableArea =
        (MediaPrintableArea) attributeSet.get(MediaPrintableArea.class);
    final OrientationRequested orientationRequested =
        (OrientationRequested) attributeSet.get(OrientationRequested.class);

    final MediaSize mediaSize = lookupMediaSize(media);
View Full Code Here

/*
* Calculate MediaPrintableArea attribute for tis margins and the given
* MediaSize object.
*/
public MediaPrintableArea getMediaPrintableArea(MediaSize size) {
    return new MediaPrintableArea(getX1(MM),
                                  getY1(MM),
                                  size.getX(MM) - getX1(MM) - getX2(MM),
                                  size.getY(MM) - getY1(MM) - getY2(MM),
                                  MM);
}
View Full Code Here

                    && attrs.containsKey(MediaPrintableArea.class)
                    && attrs.get(Media.class).equals(selectedMedia)
                    && isMediaSizeSelected) {      
                /* p.1 - see fillMarginsFields() comments above*/  
                try {
                    MediaPrintableArea attrsPA = (MediaPrintableArea)
                            attrs.get(MediaPrintableArea.class);
                    margins = new MediaMargins(selectedSize, attrsPA);
                } catch(IllegalArgumentException e) {
                    /*
                     * If we are unable to get correct margins values from the
                     * given MediaPrintableArea (attrsPA) and MediaSize
                     * (selectedSize), we just ignore this case
                     */
                }
            }

            if ((margins == null)
                    && (isMarginsSupported || (dialogType == PAGE_DIALOG))) {
                /* p.2 - see fillMarginsFields() comments above*/  
                margins = (MediaMargins) (attrs.containsKey(MediaMargins.class)
                     ? attrs.get(MediaMargins.class)
                     : myService.getDefaultAttributeValue(MediaMargins.class));
            }

            if ((margins == null
                    && isPaSupported 
                    && isMediaSupported
                    && isMediaSizeSelected) {
                /* p.3 - see fillMarginsFields() comments above*/  
                try {
                    MediaPrintableArea defaultPA = (MediaPrintableArea)
                            myService.getDefaultAttributeValue(
                                    MediaPrintableArea.class);
                    if ((defaultPA != null) && (selectedSize != null)) {
                        margins = new MediaMargins(selectedSize, defaultPA);
                    }
View Full Code Here

        float paperWidth = mediaSize.getX(Size2DSyntax.MM);
        float paperHeight = mediaSize.getY(Size2DSyntax.MM);
        if ((x1 + x2 >= paperWidth) || (y1 + y2 >= paperHeight)) {
            return false;
        }
        newAttrs.add(new MediaPrintableArea(x1,
                                            y1,
                                            paperWidth - x1 - x2,
                                            paperHeight - y1 - y2,
                                            MediaPrintableArea.MM));
    } else {
View Full Code Here

        if (service == null || attributes == null) {
            return pf;
        }

        Media media = (Media)attributes.get(Media.class);
        MediaPrintableArea mpa =
            (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
        OrientationRequested orientReq =
           (OrientationRequested)attributes.get(OrientationRequested.class);

        if (media == null && mpa == null && orientReq == null) {
           return pf;
        }
        Paper paper = pf.getPaper();

        /* If there's a media but no media printable area, we can try
         * to retrieve the default value for mpa and use that.
         */
        if (mpa == null && media != null &&
            service.isAttributeCategorySupported(MediaPrintableArea.class)) {
            Object mpaVals =
                service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                    null, attributes);
            if (mpaVals instanceof MediaPrintableArea[] &&
                ((MediaPrintableArea[])mpaVals).length > 0) {
                mpa = ((MediaPrintableArea[])mpaVals)[0];
            }
        }

        if (media != null &&
            service.isAttributeValueSupported(media, null, attributes)) {
            if (media instanceof MediaSizeName) {
                MediaSizeName msn = (MediaSizeName)media;
                MediaSize msz = MediaSize.getMediaSizeForName(msn);
                if (msz != null) {
                    double inch = 72.0;
                    double paperWid = msz.getX(MediaSize.INCH) * inch;
                    double paperHgt = msz.getY(MediaSize.INCH) * inch;
                    paper.setSize(paperWid, paperHgt);
                    if (mpa == null) {
                        paper.setImageableArea(inch, inch,
                                               paperWid-2*inch,
                                               paperHgt-2*inch);
                    }
                }
            }
        }

        if (mpa != null &&
            service.isAttributeValueSupported(mpa, null, attributes)) {
            float [] printableArea =
                mpa.getPrintableArea(MediaPrintableArea.INCH);
            for (int i=0; i < printableArea.length; i++) {
                printableArea[i] = printableArea[i]*72.0f;
            }
            paper.setImageableArea(printableArea[0], printableArea[1],
                                   printableArea[2], printableArea[3]);
View Full Code Here

TOP

Related Classes of javax.print.attribute.standard.MediaPrintableArea

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.