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
23 * questions.
24 */
25
26 package sun.print;
27
28 import javax.print.attribute.*;
29 import javax.print.attribute.standard.*;
30 import javax.print.DocFlavor;
31 import javax.print.DocPrintJob;
32 import javax.print.PrintService;
33 import javax.print.ServiceUIFactory;
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.Locale;
37 import java.util.Date;
38 import java.util.Arrays;
39 import java.security.AccessController;
40 import java.security.PrivilegedActionException;
41 import java.security.PrivilegedExceptionAction;
42 import javax.print.event.PrintServiceAttributeListener;
43
44 import java.net.URI;
45 import java.net.URISyntaxException;
46 import java.net.URL;
47 import java.net.URLConnection;
1054 // of setting it, it is a safe assumption to just always
1055 // include SheetCollate as supported attribute.
1056
1057 catList.add(SheetCollate.class);
1058
1059 }
1060
1061 // With the assumption that Chromaticity is equivalent to
1062 // ColorSupported.
1063 if (getAttMap != null && getAttMap.containsKey("color-supported")) {
1064 catList.add(Chromaticity.class);
1065 }
1066
1067 // CUPS does not report printer resolution via IPP but it
1068 // may be gleaned from the PPD.
1069 PrinterResolution[] supportedRes = getPrintResolutions();
1070 if (supportedRes != null && (supportedRes.length > 0)) {
1071 catList.add(PrinterResolution.class);
1072 }
1073
1074 supportedCats = new Class<?>[catList.size()];
1075 catList.toArray(supportedCats);
1076 Class<?>[] copyCats = new Class<?>[supportedCats.length];
1077 System.arraycopy(supportedCats, 0, copyCats, 0, copyCats.length);
1078 return copyCats;
1079 }
1080
1081
1082 public boolean
1083 isAttributeCategorySupported(Class<? extends Attribute> category)
1084 {
1085 if (category == null) {
1086 throw new NullPointerException("null category");
1087 }
1088 if (!(Attribute.class.isAssignableFrom(category))) {
1089 throw new IllegalArgumentException(category +
1090 " is not an Attribute");
1091 }
1092
1093 if (supportedCats == null) {
1375 return true;
1376 }
1377 }
1378 }
1379 return false;
1380 } else if (attr.getCategory() == OrientationRequested.class) {
1381 OrientationRequested[] orientArray =
1382 (OrientationRequested[])getSupportedAttributeValues(
1383 OrientationRequested.class,
1384 flavor,
1385 attributes);
1386
1387 if (orientArray != null) {
1388 for (int i=0; i<orientArray.length; i++) {
1389 if (orientArray[i] == (OrientationRequested)attr) {
1390 return true;
1391 }
1392 }
1393 }
1394 return false;
1395 } if (attr.getCategory() == PrinterResolution.class) {
1396 if (attr instanceof PrinterResolution) {
1397 return isSupportedResolution((PrinterResolution)attr);
1398 }
1399 }
1400 return true;
1401 }
1402
1403
1404 public synchronized Object
1405 getDefaultAttributeValue(Class<? extends Attribute> category)
1406 {
1407 if (category == null) {
1408 throw new NullPointerException("null category");
1409 }
1410 if (!Attribute.class.isAssignableFrom(category)) {
1411 throw new IllegalArgumentException(category +
1412 " is not an Attribute");
1413 }
1414 if (!isAttributeCategorySupported(category)) {
1415 return null;
1416 }
1417
|
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
23 * questions.
24 */
25
26 package sun.print;
27
28 import java.awt.GraphicsEnvironment;
29 import java.awt.Toolkit;
30 import javax.print.attribute.*;
31 import javax.print.attribute.standard.*;
32 import javax.print.DocFlavor;
33 import javax.print.DocPrintJob;
34 import javax.print.PrintService;
35 import javax.print.ServiceUIFactory;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.Locale;
39 import java.util.Date;
40 import java.util.Arrays;
41 import java.security.AccessController;
42 import java.security.PrivilegedActionException;
43 import java.security.PrivilegedExceptionAction;
44 import javax.print.event.PrintServiceAttributeListener;
45
46 import java.net.URI;
47 import java.net.URISyntaxException;
48 import java.net.URL;
49 import java.net.URLConnection;
1056 // of setting it, it is a safe assumption to just always
1057 // include SheetCollate as supported attribute.
1058
1059 catList.add(SheetCollate.class);
1060
1061 }
1062
1063 // With the assumption that Chromaticity is equivalent to
1064 // ColorSupported.
1065 if (getAttMap != null && getAttMap.containsKey("color-supported")) {
1066 catList.add(Chromaticity.class);
1067 }
1068
1069 // CUPS does not report printer resolution via IPP but it
1070 // may be gleaned from the PPD.
1071 PrinterResolution[] supportedRes = getPrintResolutions();
1072 if (supportedRes != null && (supportedRes.length > 0)) {
1073 catList.add(PrinterResolution.class);
1074 }
1075
1076 if (GraphicsEnvironment.isHeadless() == false) {
1077 catList.add(DialogOwner.class);
1078 catList.add(DialogTypeSelection.class);
1079 }
1080
1081 supportedCats = new Class<?>[catList.size()];
1082 catList.toArray(supportedCats);
1083 Class<?>[] copyCats = new Class<?>[supportedCats.length];
1084 System.arraycopy(supportedCats, 0, copyCats, 0, copyCats.length);
1085 return copyCats;
1086 }
1087
1088
1089 public boolean
1090 isAttributeCategorySupported(Class<? extends Attribute> category)
1091 {
1092 if (category == null) {
1093 throw new NullPointerException("null category");
1094 }
1095 if (!(Attribute.class.isAssignableFrom(category))) {
1096 throw new IllegalArgumentException(category +
1097 " is not an Attribute");
1098 }
1099
1100 if (supportedCats == null) {
1382 return true;
1383 }
1384 }
1385 }
1386 return false;
1387 } else if (attr.getCategory() == OrientationRequested.class) {
1388 OrientationRequested[] orientArray =
1389 (OrientationRequested[])getSupportedAttributeValues(
1390 OrientationRequested.class,
1391 flavor,
1392 attributes);
1393
1394 if (orientArray != null) {
1395 for (int i=0; i<orientArray.length; i++) {
1396 if (orientArray[i] == (OrientationRequested)attr) {
1397 return true;
1398 }
1399 }
1400 }
1401 return false;
1402 } else if (attr.getCategory() == PrinterResolution.class) {
1403 if (attr instanceof PrinterResolution) {
1404 return isSupportedResolution((PrinterResolution)attr);
1405 }
1406 } else if (attr.getCategory() == DialogOwner.class) {
1407 DialogOwner owner = (DialogOwner)attr;
1408 // ID not supported on any dialog type on Unix platforms.
1409 if (DialogOwnerAccessor.getID(owner) != 0) {
1410 return false;
1411 }
1412 // On Mac we have no control over the native dialog.
1413 DialogTypeSelection dst = (attributes == null) ? null :
1414 (DialogTypeSelection)attributes.get(DialogTypeSelection.class);
1415 if (PrintServiceLookupProvider.isMac() &&
1416 dst == DialogTypeSelection.NATIVE) {
1417 return false;
1418 }
1419 // The other case is always a Swing dialog on all Unix platforms.
1420 // So we only need to check that the toolkit supports
1421 // always on top.
1422 if (owner.getOwner() != null) {
1423 return true;
1424 } else {
1425 return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
1426 }
1427 } else if (attr.getCategory() == DialogTypeSelection.class) {
1428 if (PrintServiceLookupProvider.isMac()) {
1429 return true;
1430 } else {
1431 DialogTypeSelection dst = (DialogTypeSelection)attr;
1432 return attr == DialogTypeSelection.COMMON;
1433 }
1434 }
1435 return true;
1436 }
1437
1438
1439 public synchronized Object
1440 getDefaultAttributeValue(Class<? extends Attribute> category)
1441 {
1442 if (category == null) {
1443 throw new NullPointerException("null category");
1444 }
1445 if (!Attribute.class.isAssignableFrom(category)) {
1446 throw new IllegalArgumentException(category +
1447 " is not an Attribute");
1448 }
1449 if (!isAttributeCategorySupported(category)) {
1450 return null;
1451 }
1452
|