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
195 throw new NullPointerException("null category");
196 }
197 if (!Attribute.class.isAssignableFrom(category)) {
198 throw new IllegalArgumentException(category +
199 " is not an Attribute");
200 }
201
202 if (!isAttributeCategorySupported(category)) {
203 return null;
204 }
205
206 if (category == Copies.class) {
207 return new Copies(1);
208 } else if (category == Chromaticity.class) {
209 return Chromaticity.COLOR;
210 } else if (category == Fidelity.class) {
211 return Fidelity.FIDELITY_FALSE;
212 } else if (category == Media.class) {
213 String defaultCountry = Locale.getDefault().getCountry();
214 if (defaultCountry != null &&
215 (defaultCountry.equals("") ||
216 defaultCountry.equals(Locale.US.getCountry()) ||
217 defaultCountry.equals(Locale.CANADA.getCountry()))) {
218 return MediaSizeName.NA_LETTER;
219 } else {
220 return MediaSizeName.ISO_A4;
221 }
222 } else if (category == MediaPrintableArea.class) {
223 String defaultCountry = Locale.getDefault().getCountry();
224 float iw, ih;
225 float margin = 0.5f; // both these papers > 5" in all dimensions
226 if (defaultCountry != null &&
227 (defaultCountry.equals("") ||
228 defaultCountry.equals(Locale.US.getCountry()) ||
229 defaultCountry.equals(Locale.CANADA.getCountry()))) {
230 iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 2*margin;
231 ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 2*margin;
232 } else {
233 iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 2*margin;
234 ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 2*margin;
235 }
236 return new MediaPrintableArea(margin, margin, iw, ih,
237 MediaPrintableArea.INCH);
238 } else if (category == OrientationRequested.class) {
239 return OrientationRequested.PORTRAIT;
240 } else if (category == PageRanges.class) {
241 return new PageRanges(1, Integer.MAX_VALUE);
242 } else if (category == SheetCollate.class) {
243 return SheetCollate.UNCOLLATED;
244 } else if (category == Sides.class) {
245 return Sides.ONE_SIDED;
246
247 } else
|
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
195 throw new NullPointerException("null category");
196 }
197 if (!Attribute.class.isAssignableFrom(category)) {
198 throw new IllegalArgumentException(category +
199 " is not an Attribute");
200 }
201
202 if (!isAttributeCategorySupported(category)) {
203 return null;
204 }
205
206 if (category == Copies.class) {
207 return new Copies(1);
208 } else if (category == Chromaticity.class) {
209 return Chromaticity.COLOR;
210 } else if (category == Fidelity.class) {
211 return Fidelity.FIDELITY_FALSE;
212 } else if (category == Media.class) {
213 String defaultCountry = Locale.getDefault().getCountry();
214 if (defaultCountry != null &&
215 (defaultCountry.isEmpty() ||
216 defaultCountry.equals(Locale.US.getCountry()) ||
217 defaultCountry.equals(Locale.CANADA.getCountry()))) {
218 return MediaSizeName.NA_LETTER;
219 } else {
220 return MediaSizeName.ISO_A4;
221 }
222 } else if (category == MediaPrintableArea.class) {
223 String defaultCountry = Locale.getDefault().getCountry();
224 float iw, ih;
225 float margin = 0.5f; // both these papers > 5" in all dimensions
226 if (defaultCountry != null &&
227 (defaultCountry.isEmpty() ||
228 defaultCountry.equals(Locale.US.getCountry()) ||
229 defaultCountry.equals(Locale.CANADA.getCountry()))) {
230 iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 2*margin;
231 ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 2*margin;
232 } else {
233 iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 2*margin;
234 ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 2*margin;
235 }
236 return new MediaPrintableArea(margin, margin, iw, ih,
237 MediaPrintableArea.INCH);
238 } else if (category == OrientationRequested.class) {
239 return OrientationRequested.PORTRAIT;
240 } else if (category == PageRanges.class) {
241 return new PageRanges(1, Integer.MAX_VALUE);
242 } else if (category == SheetCollate.class) {
243 return SheetCollate.UNCOLLATED;
244 } else if (category == Sides.class) {
245 return Sides.ONE_SIDED;
246
247 } else
|