< prev index next >

src/java.desktop/share/classes/sun/print/PrintJob2D.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 666                     }
 667                 }
 668             } catch (PrinterException pe) {
 669             }
 670         }
 671 
 672         DestinationType dest = jobAttributes.getDestination();
 673         if (dest == DestinationType.FILE && pServ != null &&
 674             pServ.isAttributeCategorySupported(Destination.class)) {
 675 
 676             String fileName = jobAttributes.getFileName();
 677 
 678             Destination defaultDest;
 679             if (fileName == null && (defaultDest = (Destination)pServ.
 680                     getDefaultAttributeValue(Destination.class)) != null) {
 681                 attributes.add(defaultDest);
 682             } else {
 683                 URI uri = null;
 684                 try {
 685                     if (fileName != null) {
 686                         if (fileName.equals("")) {
 687                             fileName = ".";
 688                         }
 689                     } else {
 690                         // defaultDest should not be null.  The following code
 691                         // is only added to safeguard against a possible
 692                         // buggy implementation of a PrintService having a
 693                         // null default Destination.
 694                         fileName = "out.prn";
 695                     }
 696                     uri = (new File(fileName)).toURI();
 697                 } catch (SecurityException se) {
 698                     try {
 699                         // '\\' file separator is illegal character in opaque
 700                         // part and causes URISyntaxException, so we replace
 701                         // it with '/'
 702                         fileName = fileName.replace('\\', '/');
 703                         uri = new URI("file:"+fileName);
 704                     } catch (URISyntaxException e) {
 705                     }
 706                 }


1216                 pageAttributes.setMedia(SIZES[MediaType.LEGAL.hashCode()]);
1217             } else if (str.equals(EXECUTIVE)) {
1218                 pageAttributes.setMedia(SIZES[MediaType.EXECUTIVE.hashCode()]);
1219             } else if (str.equals(A4)) {
1220                 pageAttributes.setMedia(SIZES[MediaType.A4.hashCode()]);
1221             }
1222         }
1223     }
1224 
1225     private void translateOutputProps() {
1226         if (props == null) {
1227             return;
1228         }
1229 
1230         String str;
1231 
1232         props.setProperty(DEST_PROP,
1233             (jobAttributes.getDestination() == DestinationType.PRINTER) ?
1234                           PRINTER : FILE);
1235         str = jobAttributes.getPrinter();
1236         if (str != null && !str.equals("")) {
1237             props.setProperty(PRINTER_PROP, str);
1238         }
1239         str = jobAttributes.getFileName();
1240         if (str != null && !str.equals("")) {
1241             props.setProperty(FILENAME_PROP, str);
1242         }
1243         int copies = jobAttributes.getCopies();
1244         if (copies > 0) {
1245             props.setProperty(NUMCOPIES_PROP, "" + copies);
1246         }
1247         str = this.options;
1248         if (str != null && !str.equals("")) {
1249             props.setProperty(OPTIONS_PROP, str);
1250         }
1251         props.setProperty(ORIENT_PROP,
1252             (pageAttributes.getOrientationRequested() ==
1253              OrientationRequestedType.PORTRAIT)
1254                           ? PORTRAIT : LANDSCAPE);
1255         MediaType media = SIZES[pageAttributes.getMedia().hashCode()];
1256         if (media == MediaType.LETTER) {
1257             str = LETTER;
1258         } else if (media == MediaType.LEGAL) {
1259             str = LEGAL;
1260         } else if (media == MediaType.EXECUTIVE) {
1261             str = EXECUTIVE;
1262         } else if (media == MediaType.A4) {
1263             str = A4;
1264         } else {
1265             str = media.toString();
1266         }
1267         props.setProperty(PAPERSIZE_PROP, str);
1268     }
   1 /*
   2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 666                     }
 667                 }
 668             } catch (PrinterException pe) {
 669             }
 670         }
 671 
 672         DestinationType dest = jobAttributes.getDestination();
 673         if (dest == DestinationType.FILE && pServ != null &&
 674             pServ.isAttributeCategorySupported(Destination.class)) {
 675 
 676             String fileName = jobAttributes.getFileName();
 677 
 678             Destination defaultDest;
 679             if (fileName == null && (defaultDest = (Destination)pServ.
 680                     getDefaultAttributeValue(Destination.class)) != null) {
 681                 attributes.add(defaultDest);
 682             } else {
 683                 URI uri = null;
 684                 try {
 685                     if (fileName != null) {
 686                         if (fileName.isEmpty()) {
 687                             fileName = ".";
 688                         }
 689                     } else {
 690                         // defaultDest should not be null.  The following code
 691                         // is only added to safeguard against a possible
 692                         // buggy implementation of a PrintService having a
 693                         // null default Destination.
 694                         fileName = "out.prn";
 695                     }
 696                     uri = (new File(fileName)).toURI();
 697                 } catch (SecurityException se) {
 698                     try {
 699                         // '\\' file separator is illegal character in opaque
 700                         // part and causes URISyntaxException, so we replace
 701                         // it with '/'
 702                         fileName = fileName.replace('\\', '/');
 703                         uri = new URI("file:"+fileName);
 704                     } catch (URISyntaxException e) {
 705                     }
 706                 }


1216                 pageAttributes.setMedia(SIZES[MediaType.LEGAL.hashCode()]);
1217             } else if (str.equals(EXECUTIVE)) {
1218                 pageAttributes.setMedia(SIZES[MediaType.EXECUTIVE.hashCode()]);
1219             } else if (str.equals(A4)) {
1220                 pageAttributes.setMedia(SIZES[MediaType.A4.hashCode()]);
1221             }
1222         }
1223     }
1224 
1225     private void translateOutputProps() {
1226         if (props == null) {
1227             return;
1228         }
1229 
1230         String str;
1231 
1232         props.setProperty(DEST_PROP,
1233             (jobAttributes.getDestination() == DestinationType.PRINTER) ?
1234                           PRINTER : FILE);
1235         str = jobAttributes.getPrinter();
1236         if (str != null && !str.isEmpty()) {
1237             props.setProperty(PRINTER_PROP, str);
1238         }
1239         str = jobAttributes.getFileName();
1240         if (str != null && !str.isEmpty()) {
1241             props.setProperty(FILENAME_PROP, str);
1242         }
1243         int copies = jobAttributes.getCopies();
1244         if (copies > 0) {
1245             props.setProperty(NUMCOPIES_PROP, "" + copies);
1246         }
1247         str = this.options;
1248         if (str != null && !str.isEmpty()) {
1249             props.setProperty(OPTIONS_PROP, str);
1250         }
1251         props.setProperty(ORIENT_PROP,
1252             (pageAttributes.getOrientationRequested() ==
1253              OrientationRequestedType.PORTRAIT)
1254                           ? PORTRAIT : LANDSCAPE);
1255         MediaType media = SIZES[pageAttributes.getMedia().hashCode()];
1256         if (media == MediaType.LETTER) {
1257             str = LETTER;
1258         } else if (media == MediaType.LEGAL) {
1259             str = LEGAL;
1260         } else if (media == MediaType.EXECUTIVE) {
1261             str = EXECUTIVE;
1262         } else if (media == MediaType.A4) {
1263             str = A4;
1264         } else {
1265             str = media.toString();
1266         }
1267         props.setProperty(PAPERSIZE_PROP, str);
1268     }
< prev index next >