Package javax.print.attribute.standard

Examples of javax.print.attribute.standard.MediaPrintableArea


                        .get(OrientationRequested.class);
        final MediaSize size = attributes.containsKey(Media.class) ? MediaSize
                        .getMediaSizeForName((MediaSizeName) attributes
                                        .get(Media.class))
                        : (MediaSize) attributes.get(MediaSize.class);
        final MediaPrintableArea area = (MediaPrintableArea) attributes
                        .get(MediaPrintableArea.class);

        if (orient != null) {
            if (orient.equals(OrientationRequested.LANDSCAPE)) {
                format.setOrientation(PageFormat.LANDSCAPE);
            } else if (orient.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
                format.setOrientation(PageFormat.REVERSE_LANDSCAPE);
            }
        }

        if (size != null) {
            paper.setSize(size.getX(Size2DSyntax.INCH) * 72.0, size
                            .getY(Size2DSyntax.INCH) * 72.0);
        }

        if (area != null) {
            paper.setImageableArea(area.getX(Size2DSyntax.INCH) * 72.0, area
                            .getY(Size2DSyntax.INCH) * 72.0, area
                            .getWidth(Size2DSyntax.INCH) * 72.0, area
                            .getHeight(Size2DSyntax.INCH) * 72.0);
        }

        format.setPaper(paper);

View Full Code Here


        private PageFormat getPageFormat(final AttributeSet... attrSets) {
            final Paper paper = new Paper();
            final PageFormat format = new PageFormat();
            final DevmodeStructWrapper dm = service.getPrinterProps();
            final OrientationRequested o = dm.getOrientation();
            final MediaPrintableArea area = getAttribute(
                            MediaPrintableArea.class, attrSets);
            DevmodeStructWrapper.Paper p = dm.getPaper();

            if (p == null) {
                p = (DevmodeStructWrapper.Paper) service
                                .getDefaultAttributeValue(DevmodeStructWrapper.Paper.class);
                dm.setPaper(p);
            }

            paper.setSize(p.getSize().getX(Size2DSyntax.INCH) * 72.0, p
                            .getSize().getY(Size2DSyntax.INCH) * 72.0);
            format.setPaper(paper);

            if (OrientationRequested.LANDSCAPE.equals(o)
                            || OrientationRequested.REVERSE_LANDSCAPE.equals(o)) {
                format.setOrientation(PageFormat.LANDSCAPE);
            } else {
                format.setOrientation(PageFormat.PORTRAIT);
            }

            if (area != null) {
                paper.setImageableArea(area.getX(MediaPrintableArea.INCH) * 72,
                                area.getY(MediaPrintableArea.INCH) * 72,
                                area.getWidth(MediaPrintableArea.INCH) * 72,
                                area.getHeight(MediaPrintableArea.INCH) * 72);
            } else {
                final double x = paper.getWidth() / 10;
                final double y = paper.getHeight() / 10;

                paper.setImageableArea(x, y, (paper.getWidth() - 2 * x), (paper
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

      /* OpenBook is used internally only when app uses Printable.
         * This is the case when we use the values from the attribute set.
         */
        Media media = (Media)reqAttrSet.get(Media.class);
        OrientationRequested orientReq = (OrientationRequested)reqAttrSet.get(OrientationRequested.class);
        MediaPrintableArea mpa = (MediaPrintableArea)reqAttrSet.get(MediaPrintableArea.class);

        if ((orientReq != null || media != null || mpa != null) && pageable instanceof OpenBook) {

            /* We could almost(!) use PrinterJob.getPageFormat() except
             * here we need to start with the PageFormat from the OpenBook :
             */
            Printable printable = pageable.getPrintable(0);
            PageFormat pf = (PageFormat)pageable.getPageFormat(0).clone();
            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, reqAttrSet);
                if (mpaVals instanceof MediaPrintableArea[] && ((MediaPrintableArea[])mpaVals).length > 0) {
                    mpa = ((MediaPrintableArea[])mpaVals)[0];
                }
            }

            if (isSupportedValue(orientReq, reqAttrSet) || (!fidelity && orientReq != null)) {
                int orient;
                if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
                    orient = PageFormat.REVERSE_LANDSCAPE;
                } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
                    orient = PageFormat.LANDSCAPE;
                } else {
                    orient = PageFormat.PORTRAIT;
                }
                pf.setOrientation(orient);
            }

            if (isSupportedValue(media, reqAttrSet) || (!fidelity && media != null)) {
                if (media instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media;
                    MediaSize msz = MediaSize.getMediaSizeForName(msn);
                    if (msz != null) {
                        float paperWid =  msz.getX(MediaSize.INCH) * 72.0f;
                        float paperHgt =  msz.getY(MediaSize.INCH) * 72.0f;
                        paper.setSize(paperWid, paperHgt);
                        if (mpa == null) {
                            paper.setImageableArea(72.0, 72.0, paperWid-144.0, paperHgt-144.0);
                        }
                    }
                }
            }

            if (isSupportedValue(mpa, reqAttrSet) || (!fidelity && mpa != null)) {
                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

    if (top+bottom>=h){
      top=Math.floor(h/4);
      bottom=Math.floor(h/4);
      mchanged=true;
    }
    MediaPrintableArea area=new MediaPrintableArea((float)left, (float)top, (float)(w-left-right), (float)(h-top-bottom),MediaSize.MM);
    if (verify){
      MediaPrintableArea adaptedArea=ExtendedPageFormat.adaptMediaPrintableArea(area, document.getPrintService(), mediaSizeName);
      pageFormat.setPrintableArea(adaptedArea);
      if (area!=adaptedArea){
        //update margins
        mchanged=true;
      }
View Full Code Here

    while (top+bottom>=h){
      top=Math.floor(h/4);
      bottom=Math.floor(h/4);
      mchanged=true;
    }
    MediaPrintableArea area=new MediaPrintableArea((float)left, (float)top, (float)(w-left-right), (float)(h-top-bottom),MediaSize.MM);
    pageFormat.setPrintableArea(area);
    if (mchanged){
      double[] m=pageFormat.getMargins(true);
      marginLeft.setValue(m[0]);
      marginRight.setValue(m[1]);
View Full Code Here

        top=Math.floor(h/4);
        bottom=Math.floor(h/4);
        changed=true;
      }
    }
    MediaPrintableArea area=new MediaPrintableArea((float)left, (float)top, (float)(w-left-right), (float)(h-top-bottom),MediaSize.MM);
    //if (verify){
      MediaPrintableArea adaptedArea=ExtendedPageFormat.adaptMediaPrintableArea(area, document.getPrintService(), pageFormat.getSizeName());
      pageFormat.setPrintableArea(adaptedArea);
      if (area!=adaptedArea){
        //update margins
        changed=true;
      }
View Full Code Here

    }
    if (pageFormat==null){
      try{
        if (printSettings.isEmpty()||printSettings.getPageFormat()==null){
            MediaSizeName mediaSizeName=getDefaultMediaSizeName();
            MediaPrintableArea mediaPrintableArea=getDefaultMediaPrintableArea(mediaSizeName);
            pageFormat=new ExtendedPageFormat(mediaSizeName,mediaPrintableArea);
        }else{
          pageFormat=(ExtendedPageFormat)printSettings.getPageFormat().clone();
        }
        //pageFormatAlreadyExists=false;
View Full Code Here

  public static MediaSizeName getDefaultMediaSizeName(){
    return MediaSizeName.ISO_A4;
  }
  public static MediaPrintableArea getDefaultMediaPrintableArea(Size2DSyntax size){
    //MediaSize size=MediaSize.getMediaSizeForName(getDefaultMediaSizeName());
    return new MediaPrintableArea(DEFAULT_MARGINS,DEFAULT_MARGINS,size.getX(MediaSize.MM)-2*DEFAULT_MARGINS,size.getY(MediaSize.MM)-2*DEFAULT_MARGINS,MediaSize.MM);
  }
 
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.