925 * @param obj the PageAttributes to copy.
926 */
927 public PageAttributes(PageAttributes obj) {
928 set(obj);
929 }
930
931 /**
932 * Constructs a PageAttributes instance with the specified values for
933 * every attribute.
934 *
935 * @param color ColorType.COLOR or ColorType.MONOCHROME.
936 * @param media one of the constant fields of the MediaType class.
937 * @param orientationRequested OrientationRequestedType.PORTRAIT or
938 * OrientationRequestedType.LANDSCAPE.
939 * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
940 * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
941 * or PrintQualityType.HIGH
942 * @param printerResolution an integer array of 3 elements. The first
943 * element must be greater than 0. The second element must be
944 * must be greater than 0. The third element must be either
945 * <code>3</code> or <code>4</code>.
946 * @throws IllegalArgumentException if one or more of the above
947 * conditions is violated.
948 */
949 public PageAttributes(ColorType color, MediaType media,
950 OrientationRequestedType orientationRequested,
951 OriginType origin, PrintQualityType printQuality,
952 int[] printerResolution) {
953 setColor(color);
954 setMedia(media);
955 setOrientationRequested(orientationRequested);
956 setOrigin(origin);
957 setPrintQuality(printQuality);
958 setPrinterResolution(printerResolution);
959 }
960
961 /**
962 * Creates and returns a copy of this PageAttributes.
963 *
964 * @return the newly created copy. It is safe to cast this Object into
965 * a PageAttributes.
1078 /**
1079 * Specifies the print orientation for pages using these attributes. Not
1080 * specifying the property is equivalent to specifying
1081 * OrientationRequestedType.PORTRAIT.
1082 *
1083 * @param orientationRequested OrientationRequestedType.PORTRAIT or
1084 * OrientationRequestedType.LANDSCAPE.
1085 * @throws IllegalArgumentException if orientationRequested is null.
1086 */
1087 public void setOrientationRequested(OrientationRequestedType
1088 orientationRequested) {
1089 if (orientationRequested == null) {
1090 throw new IllegalArgumentException("Invalid value for attribute "+
1091 "orientationRequested");
1092 }
1093 this.orientationRequested = orientationRequested;
1094 }
1095
1096 /**
1097 * Specifies the print orientation for pages using these attributes.
1098 * Specifying <code>3</code> denotes portrait. Specifying <code>4</code>
1099 * denotes landscape. Specifying any other value will generate an
1100 * IllegalArgumentException. Not specifying the property is equivalent
1101 * to calling setOrientationRequested(OrientationRequestedType.PORTRAIT).
1102 *
1103 * @param orientationRequested <code>3</code> or <code>4</code>
1104 * @throws IllegalArgumentException if orientationRequested is not
1105 * <code>3</code> or <code>4</code>
1106 */
1107 public void setOrientationRequested(int orientationRequested) {
1108 switch (orientationRequested) {
1109 case 3:
1110 setOrientationRequested(OrientationRequestedType.PORTRAIT);
1111 break;
1112 case 4:
1113 setOrientationRequested(OrientationRequestedType.LANDSCAPE);
1114 break;
1115 default:
1116 // This will throw an IllegalArgumentException
1117 setOrientationRequested(null);
1118 break;
1119 }
1120 }
1121
1122 /**
1123 * Sets the print orientation for pages using these attributes to the
1124 * default. The default orientation is portrait.
1125 */
1172
1173 /**
1174 * Specifies the print quality for pages using these attributes. Not
1175 * specifying the property is equivalent to specifying
1176 * PrintQualityType.NORMAL.
1177 *
1178 * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
1179 * or PrintQualityType.HIGH
1180 * @throws IllegalArgumentException if printQuality is null.
1181 */
1182 public void setPrintQuality(PrintQualityType printQuality) {
1183 if (printQuality == null) {
1184 throw new IllegalArgumentException("Invalid value for attribute "+
1185 "printQuality");
1186 }
1187 this.printQuality = printQuality;
1188 }
1189
1190 /**
1191 * Specifies the print quality for pages using these attributes.
1192 * Specifying <code>3</code> denotes draft. Specifying <code>4</code>
1193 * denotes normal. Specifying <code>5</code> denotes high. Specifying
1194 * any other value will generate an IllegalArgumentException. Not
1195 * specifying the property is equivalent to calling
1196 * setPrintQuality(PrintQualityType.NORMAL).
1197 *
1198 * @param printQuality <code>3</code>, <code>4</code>, or <code>5</code>
1199 * @throws IllegalArgumentException if printQuality is not <code>3
1200 * </code>, <code>4</code>, or <code>5</code>
1201 */
1202 public void setPrintQuality(int printQuality) {
1203 switch (printQuality) {
1204 case 3:
1205 setPrintQuality(PrintQualityType.DRAFT);
1206 break;
1207 case 4:
1208 setPrintQuality(PrintQualityType.NORMAL);
1209 break;
1210 case 5:
1211 setPrintQuality(PrintQualityType.HIGH);
1212 break;
1213 default:
1214 // This will throw an IllegalArgumentException
1215 setPrintQuality(null);
1216 break;
1217 }
1218 }
1219
1220 /**
1221 * Sets the print quality for pages using these attributes to the default.
1222 * The default print quality is normal.
1223 */
1224 public void setPrintQualityToDefault() {
1225 setPrintQuality(PrintQualityType.NORMAL);
1226 }
1227
1228 /**
1229 * Returns the print resolution for pages using these attributes.
1230 * Index 0 of the array specifies the cross feed direction resolution
1231 * (typically the horizontal resolution). Index 1 of the array specifies
1232 * the feed direction resolution (typically the vertical resolution).
1233 * Index 2 of the array specifies whether the resolutions are in dots per
1234 * inch or dots per centimeter. <code>3</code> denotes dots per inch.
1235 * <code>4</code> denotes dots per centimeter.
1236 *
1237 * @return an integer array of 3 elements. The first
1238 * element must be greater than 0. The second element must be
1239 * must be greater than 0. The third element must be either
1240 * <code>3</code> or <code>4</code>.
1241 */
1242 public int[] getPrinterResolution() {
1243 // Return a copy because otherwise client code could circumvent the
1244 // the checks made in setPrinterResolution by modifying the
1245 // returned array.
1246 int[] copy = new int[3];
1247 copy[0] = printerResolution[0];
1248 copy[1] = printerResolution[1];
1249 copy[2] = printerResolution[2];
1250 return copy;
1251 }
1252
1253 /**
1254 * Specifies the desired print resolution for pages using these attributes.
1255 * The actual resolution will be determined by the limitations of the
1256 * implementation and the target printer. Index 0 of the array specifies
1257 * the cross feed direction resolution (typically the horizontal
1258 * resolution). Index 1 of the array specifies the feed direction
1259 * resolution (typically the vertical resolution). Index 2 of the array
1260 * specifies whether the resolutions are in dots per inch or dots per
1261 * centimeter. <code>3</code> denotes dots per inch. <code>4</code>
1262 * denotes dots per centimeter. Note that the 1.1 printing implementation
1263 * (Toolkit.getPrintJob) requires that the feed and cross feed resolutions
1264 * be the same. Not specifying the property is equivalent to calling
1265 * setPrinterResolution(72).
1266 *
1267 * @param printerResolution an integer array of 3 elements. The first
1268 * element must be greater than 0. The second element must be
1269 * must be greater than 0. The third element must be either
1270 * <code>3</code> or <code>4</code>.
1271 * @throws IllegalArgumentException if one or more of the above
1272 * conditions is violated.
1273 */
1274 public void setPrinterResolution(int[] printerResolution) {
1275 if (printerResolution == null ||
1276 printerResolution.length != 3 ||
1277 printerResolution[0] <= 0 ||
1278 printerResolution[1] <= 0 ||
1279 (printerResolution[2] != 3 && printerResolution[2] != 4)) {
1280 throw new IllegalArgumentException("Invalid value for attribute "+
1281 "printerResolution");
1282 }
1283 // Store a copy because otherwise client code could circumvent the
1284 // the checks made above by holding a reference to the array and
1285 // modifying it after calling setPrinterResolution.
1286 int[] copy = new int[3];
1287 copy[0] = printerResolution[0];
1288 copy[1] = printerResolution[1];
1289 copy[2] = printerResolution[2];
1290 this.printerResolution = copy;
1291 }
1292
1293 /**
1294 * Specifies the desired cross feed and feed print resolutions in dots per
1295 * inch for pages using these attributes. The same value is used for both
1296 * resolutions. The actual resolutions will be determined by the
1297 * limitations of the implementation and the target printer. Not
1298 * specifying the property is equivalent to specifying <code>72</code>.
1299 *
1300 * @param printerResolution an integer greater than 0.
1301 * @throws IllegalArgumentException if printerResolution is less than or
1302 * equal to 0.
1303 */
1304 public void setPrinterResolution(int printerResolution) {
1305 setPrinterResolution(new int[] { printerResolution, printerResolution,
1306 3 } );
1307 }
1308
1309 /**
1310 * Sets the printer resolution for pages using these attributes to the
1311 * default. The default is 72 dpi for both the feed and cross feed
1312 * resolutions.
1313 */
1314 public void setPrinterResolutionToDefault() {
1315 setPrinterResolution(72);
1316 }
1317
1318 /**
|
925 * @param obj the PageAttributes to copy.
926 */
927 public PageAttributes(PageAttributes obj) {
928 set(obj);
929 }
930
931 /**
932 * Constructs a PageAttributes instance with the specified values for
933 * every attribute.
934 *
935 * @param color ColorType.COLOR or ColorType.MONOCHROME.
936 * @param media one of the constant fields of the MediaType class.
937 * @param orientationRequested OrientationRequestedType.PORTRAIT or
938 * OrientationRequestedType.LANDSCAPE.
939 * @param origin OriginType.PHYSICAL or OriginType.PRINTABLE
940 * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
941 * or PrintQualityType.HIGH
942 * @param printerResolution an integer array of 3 elements. The first
943 * element must be greater than 0. The second element must be
944 * must be greater than 0. The third element must be either
945 * {@code 3} or {@code 4}.
946 * @throws IllegalArgumentException if one or more of the above
947 * conditions is violated.
948 */
949 public PageAttributes(ColorType color, MediaType media,
950 OrientationRequestedType orientationRequested,
951 OriginType origin, PrintQualityType printQuality,
952 int[] printerResolution) {
953 setColor(color);
954 setMedia(media);
955 setOrientationRequested(orientationRequested);
956 setOrigin(origin);
957 setPrintQuality(printQuality);
958 setPrinterResolution(printerResolution);
959 }
960
961 /**
962 * Creates and returns a copy of this PageAttributes.
963 *
964 * @return the newly created copy. It is safe to cast this Object into
965 * a PageAttributes.
1078 /**
1079 * Specifies the print orientation for pages using these attributes. Not
1080 * specifying the property is equivalent to specifying
1081 * OrientationRequestedType.PORTRAIT.
1082 *
1083 * @param orientationRequested OrientationRequestedType.PORTRAIT or
1084 * OrientationRequestedType.LANDSCAPE.
1085 * @throws IllegalArgumentException if orientationRequested is null.
1086 */
1087 public void setOrientationRequested(OrientationRequestedType
1088 orientationRequested) {
1089 if (orientationRequested == null) {
1090 throw new IllegalArgumentException("Invalid value for attribute "+
1091 "orientationRequested");
1092 }
1093 this.orientationRequested = orientationRequested;
1094 }
1095
1096 /**
1097 * Specifies the print orientation for pages using these attributes.
1098 * Specifying {@code 3} denotes portrait. Specifying {@code 4}
1099 * denotes landscape. Specifying any other value will generate an
1100 * IllegalArgumentException. Not specifying the property is equivalent
1101 * to calling setOrientationRequested(OrientationRequestedType.PORTRAIT).
1102 *
1103 * @param orientationRequested {@code 3} or {@code 4}
1104 * @throws IllegalArgumentException if orientationRequested is not
1105 * {@code 3} or {@code 4}
1106 */
1107 public void setOrientationRequested(int orientationRequested) {
1108 switch (orientationRequested) {
1109 case 3:
1110 setOrientationRequested(OrientationRequestedType.PORTRAIT);
1111 break;
1112 case 4:
1113 setOrientationRequested(OrientationRequestedType.LANDSCAPE);
1114 break;
1115 default:
1116 // This will throw an IllegalArgumentException
1117 setOrientationRequested(null);
1118 break;
1119 }
1120 }
1121
1122 /**
1123 * Sets the print orientation for pages using these attributes to the
1124 * default. The default orientation is portrait.
1125 */
1172
1173 /**
1174 * Specifies the print quality for pages using these attributes. Not
1175 * specifying the property is equivalent to specifying
1176 * PrintQualityType.NORMAL.
1177 *
1178 * @param printQuality PrintQualityType.DRAFT, PrintQualityType.NORMAL,
1179 * or PrintQualityType.HIGH
1180 * @throws IllegalArgumentException if printQuality is null.
1181 */
1182 public void setPrintQuality(PrintQualityType printQuality) {
1183 if (printQuality == null) {
1184 throw new IllegalArgumentException("Invalid value for attribute "+
1185 "printQuality");
1186 }
1187 this.printQuality = printQuality;
1188 }
1189
1190 /**
1191 * Specifies the print quality for pages using these attributes.
1192 * Specifying {@code 3} denotes draft. Specifying {@code 4}
1193 * denotes normal. Specifying {@code 5} denotes high. Specifying
1194 * any other value will generate an IllegalArgumentException. Not
1195 * specifying the property is equivalent to calling
1196 * setPrintQuality(PrintQualityType.NORMAL).
1197 *
1198 * @param printQuality {@code 3}, {@code 4}, or {@code 5}
1199 * @throws IllegalArgumentException if printQuality is not
1200 * {@code 3}, {@code 4}, or {@code 5}
1201 */
1202 public void setPrintQuality(int printQuality) {
1203 switch (printQuality) {
1204 case 3:
1205 setPrintQuality(PrintQualityType.DRAFT);
1206 break;
1207 case 4:
1208 setPrintQuality(PrintQualityType.NORMAL);
1209 break;
1210 case 5:
1211 setPrintQuality(PrintQualityType.HIGH);
1212 break;
1213 default:
1214 // This will throw an IllegalArgumentException
1215 setPrintQuality(null);
1216 break;
1217 }
1218 }
1219
1220 /**
1221 * Sets the print quality for pages using these attributes to the default.
1222 * The default print quality is normal.
1223 */
1224 public void setPrintQualityToDefault() {
1225 setPrintQuality(PrintQualityType.NORMAL);
1226 }
1227
1228 /**
1229 * Returns the print resolution for pages using these attributes.
1230 * Index 0 of the array specifies the cross feed direction resolution
1231 * (typically the horizontal resolution). Index 1 of the array specifies
1232 * the feed direction resolution (typically the vertical resolution).
1233 * Index 2 of the array specifies whether the resolutions are in dots per
1234 * inch or dots per centimeter. {@code 3} denotes dots per inch.
1235 * {@code 4} denotes dots per centimeter.
1236 *
1237 * @return an integer array of 3 elements. The first
1238 * element must be greater than 0. The second element must be
1239 * must be greater than 0. The third element must be either
1240 * {@code 3} or {@code 4}.
1241 */
1242 public int[] getPrinterResolution() {
1243 // Return a copy because otherwise client code could circumvent the
1244 // the checks made in setPrinterResolution by modifying the
1245 // returned array.
1246 int[] copy = new int[3];
1247 copy[0] = printerResolution[0];
1248 copy[1] = printerResolution[1];
1249 copy[2] = printerResolution[2];
1250 return copy;
1251 }
1252
1253 /**
1254 * Specifies the desired print resolution for pages using these attributes.
1255 * The actual resolution will be determined by the limitations of the
1256 * implementation and the target printer. Index 0 of the array specifies
1257 * the cross feed direction resolution (typically the horizontal
1258 * resolution). Index 1 of the array specifies the feed direction
1259 * resolution (typically the vertical resolution). Index 2 of the array
1260 * specifies whether the resolutions are in dots per inch or dots per
1261 * centimeter. {@code 3} denotes dots per inch. {@code 4}
1262 * denotes dots per centimeter. Note that the 1.1 printing implementation
1263 * (Toolkit.getPrintJob) requires that the feed and cross feed resolutions
1264 * be the same. Not specifying the property is equivalent to calling
1265 * setPrinterResolution(72).
1266 *
1267 * @param printerResolution an integer array of 3 elements. The first
1268 * element must be greater than 0. The second element must be
1269 * must be greater than 0. The third element must be either
1270 * {@code 3} or {@code 4}.
1271 * @throws IllegalArgumentException if one or more of the above
1272 * conditions is violated.
1273 */
1274 public void setPrinterResolution(int[] printerResolution) {
1275 if (printerResolution == null ||
1276 printerResolution.length != 3 ||
1277 printerResolution[0] <= 0 ||
1278 printerResolution[1] <= 0 ||
1279 (printerResolution[2] != 3 && printerResolution[2] != 4)) {
1280 throw new IllegalArgumentException("Invalid value for attribute "+
1281 "printerResolution");
1282 }
1283 // Store a copy because otherwise client code could circumvent the
1284 // the checks made above by holding a reference to the array and
1285 // modifying it after calling setPrinterResolution.
1286 int[] copy = new int[3];
1287 copy[0] = printerResolution[0];
1288 copy[1] = printerResolution[1];
1289 copy[2] = printerResolution[2];
1290 this.printerResolution = copy;
1291 }
1292
1293 /**
1294 * Specifies the desired cross feed and feed print resolutions in dots per
1295 * inch for pages using these attributes. The same value is used for both
1296 * resolutions. The actual resolutions will be determined by the
1297 * limitations of the implementation and the target printer. Not
1298 * specifying the property is equivalent to specifying {@code 72}.
1299 *
1300 * @param printerResolution an integer greater than 0.
1301 * @throws IllegalArgumentException if printerResolution is less than or
1302 * equal to 0.
1303 */
1304 public void setPrinterResolution(int printerResolution) {
1305 setPrinterResolution(new int[] { printerResolution, printerResolution,
1306 3 } );
1307 }
1308
1309 /**
1310 * Sets the printer resolution for pages using these attributes to the
1311 * default. The default is 72 dpi for both the feed and cross feed
1312 * resolutions.
1313 */
1314 public void setPrinterResolutionToDefault() {
1315 setPrinterResolution(72);
1316 }
1317
1318 /**
|