fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / java / awt / JobAttributes.java
blobb64234dda5fc4a86ddc499e4a897c27314b90160
1 /* JobAttributes.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt;
41 /**
42 * Needs documentation...
44 * @author Eric Blake <ebb9@email.byu.edu>
45 * @since 1.3
46 * @status updated to 1.4, lacks documentation
48 public final class JobAttributes implements Cloneable
50 public static final class DefaultSelectionType extends AttributeValue
52 private static final String[] NAMES = { "all", "range", "selection" };
53 public static final DefaultSelectionType ALL
54 = new DefaultSelectionType(0);
55 public static final DefaultSelectionType RANGE
56 = new DefaultSelectionType(1);
57 public static final DefaultSelectionType SELECTION
58 = new DefaultSelectionType(2);
59 private DefaultSelectionType(int value)
61 super(value, NAMES);
63 } // class DefaultSelectionType
65 public static final class DestinationType extends AttributeValue
67 private static final String[] NAMES = { "file", "printer" };
68 public static final DestinationType FILE = new DestinationType(0);
69 public static final DestinationType PRINTER = new DestinationType(1);
70 private DestinationType(int value)
72 super(value, NAMES);
74 } // class DestinationType
76 public static final class DialogType extends AttributeValue
78 private static final String[] NAMES = { "common", "native", "none" };
79 public static final DialogType COMMON = new DialogType(0);
80 public static final DialogType NATIVE = new DialogType(1);
81 public static final DialogType NONE = new DialogType(2);
82 private DialogType(int value)
84 super(value, NAMES);
86 } // class DialogType
88 public static final class MultipleDocumentHandlingType
89 extends AttributeValue
91 private static final String[] NAMES = {
92 "separate-documents-collated-copies",
93 "separate-documents-uncollated-copies"
95 public static final MultipleDocumentHandlingType
96 SEPARATE_DOCUMENTS_COLLATED_COPIES
97 = new MultipleDocumentHandlingType(0);
98 public static final MultipleDocumentHandlingType
99 SEPARATE_DOCUMENTS_UNCOLLATED_COPIES
100 = new MultipleDocumentHandlingType(1);
101 private MultipleDocumentHandlingType(int value)
103 super(value, NAMES);
105 } // class MultipleDocumentHandlingType
107 public static final class SidesType extends AttributeValue
109 private static final String[] NAMES
110 = { "one-sided", "two-sided-long-edge", "two-sided-short-edge" };
111 public static final SidesType ONE_SIDED = new SidesType(0);
112 public static final SidesType TWO_SIDED_LONG_EDGE = new SidesType(1);
113 public static final SidesType TWO_SIDED_SHORT_EDGE = new SidesType(2);
114 private SidesType(int value)
116 super(value, NAMES);
118 } // class SidesType
120 private int copies;
121 private DefaultSelectionType selection;
122 private DestinationType destination;
123 private DialogType dialog;
124 private String filename;
125 private int maxPage;
126 private int minPage;
127 private MultipleDocumentHandlingType multiple;
128 private int[][] pageRanges; // null for default value
129 private int fromPage; // 0 for default value
130 private int toPage; // 0 for default value
131 private String printer;
132 private SidesType sides;
134 public JobAttributes()
136 copies = 1;
137 selection = DefaultSelectionType.ALL;
138 destination = DestinationType.PRINTER;
139 dialog = DialogType.NATIVE;
140 maxPage = Integer.MAX_VALUE;
141 minPage = 1;
142 multiple
143 = MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES;
144 sides = SidesType.ONE_SIDED;
147 public JobAttributes(JobAttributes attr)
149 set(attr);
152 public JobAttributes(int copies, DefaultSelectionType selection,
153 DestinationType destination, DialogType dialog,
154 String filename, int max, int min,
155 MultipleDocumentHandlingType multiple,
156 int[][] pageRanges, String printer, SidesType sides)
158 if (copies <= 0 || selection == null || destination == null
159 || dialog == null || max < min || min <= 0 || multiple == null
160 || sides == null)
161 throw new IllegalArgumentException();
162 this.copies = copies;
163 this.selection = selection;
164 this.destination = destination;
165 this.dialog = dialog;
166 this.filename = filename;
167 maxPage = max;
168 minPage = min;
169 this.multiple = multiple;
170 setPageRanges(pageRanges);
171 this.printer = printer;
172 this.sides = sides;
175 public Object clone()
177 return new JobAttributes(this);
180 public void set(JobAttributes attr)
182 copies = attr.copies;
183 selection = attr.selection;
184 destination = attr.destination;
185 dialog = attr.dialog;
186 filename = attr.filename;
187 maxPage = attr.maxPage;
188 minPage = attr.minPage;
189 multiple = attr.multiple;
190 pageRanges = (int[][]) attr.pageRanges.clone();
191 printer = attr.printer;
192 sides = attr.sides;
193 fromPage = attr.fromPage;
194 toPage = attr.toPage;
197 public int getCopies()
199 return copies;
202 public void setCopies(int copies)
204 if (copies <= 0)
205 throw new IllegalArgumentException();
206 this.copies = copies;
209 public void setCopiesToDefault()
211 copies = 1;
214 public DefaultSelectionType getDefaultSelection()
216 return selection;
219 public void setDefaultSelection(DefaultSelectionType selection)
221 if (selection == null)
222 throw new IllegalArgumentException();
223 this.selection = selection;
226 public DestinationType getDestination()
228 return destination;
231 public void setDestination(DestinationType destination)
233 if (destination == null)
234 throw new IllegalArgumentException();
235 this.destination = destination;
238 public DialogType getDialog()
240 return dialog;
243 public void setDialog(DialogType dialog)
245 if (dialog == null)
246 throw new IllegalArgumentException();
247 this.dialog = dialog;
250 public String getFileName()
252 return filename;
255 public void setFileName(String filename)
257 this.filename = filename;
260 public int getFromPage()
262 return fromPage != 0 ? fromPage
263 : pageRanges != null ? pageRanges[0][0]
264 : toPage != 0 ? toPage : minPage;
267 public void setFromPage(int fromPage)
269 if (fromPage < minPage || (fromPage > toPage && toPage != 0)
270 || fromPage > maxPage)
271 throw new IllegalArgumentException();
272 if (pageRanges == null)
273 this.fromPage = fromPage;
276 public int getMaxPage()
278 return maxPage;
281 public void setMaxPage(int maxPage)
283 if (maxPage < minPage)
284 throw new IllegalArgumentException();
285 this.maxPage = maxPage;
286 if (maxPage < fromPage)
287 fromPage = maxPage;
288 if (maxPage < toPage)
289 toPage = maxPage;
290 if (pageRanges != null)
292 int i = pageRanges.length - 1;
293 while (i >= 0 && maxPage < pageRanges[i][1])
294 i--;
295 if (maxPage >= pageRanges[++i][0])
296 pageRanges[i++][1] = maxPage;
297 if (i == 0)
298 pageRanges = null;
299 else if (i < pageRanges.length)
301 int[][] tmp = new int[i][];
302 System.arraycopy(pageRanges, 0, tmp, 0, i);
303 pageRanges = tmp;
308 public int getMinPage()
310 return minPage;
313 public void setMinPage(int minPage)
315 if (minPage <= 0 || minPage > maxPage)
316 throw new IllegalArgumentException();
317 this.minPage = minPage;
318 if (minPage > toPage)
319 toPage = minPage;
320 if (minPage > fromPage)
321 fromPage = minPage;
322 if (pageRanges != null)
324 int size = pageRanges.length;
325 int i = 0;
326 while (i < size && minPage > pageRanges[i][0])
327 i++;
328 if (minPage <= pageRanges[i - 1][1])
329 pageRanges[--i][0] = minPage;
330 if (i == size)
331 pageRanges = null;
332 else if (i > 0)
334 int[][] tmp = new int[size - i][];
335 System.arraycopy(pageRanges, i, tmp, 0, size - i);
336 pageRanges = tmp;
341 public MultipleDocumentHandlingType getMultipleDocumentHandling()
343 return multiple;
346 public void setMultipleDocumentHandling
347 (MultipleDocumentHandlingType multiple)
349 if (multiple == null)
350 throw new IllegalArgumentException();
351 this.multiple = multiple;
354 public void setMultipleDocumentHandlingToDefault()
356 multiple
357 = MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES;
360 public int[][] getPageRanges()
362 if (pageRanges == null)
363 return new int[][] { { getFromPage(), getToPage() } };
364 // Perform a deep clone, so user code cannot affect original arrays.
365 int i = pageRanges.length;
366 int[][] result = new int[i][];
367 while (--i >= 0)
368 result[i] = (int[]) pageRanges[i].clone();
369 return result;
372 public void setPageRanges(int[][] pageRanges)
374 int size = pageRanges == null ? 0 : pageRanges.length;
375 if (size == 0)
376 throw new IllegalArgumentException();
377 while (--size >= 0)
379 int[] range = pageRanges[size];
380 if (range == null || range.length != 2
381 || range[0] < minPage || range[1] < range[0] || range[1] > maxPage
382 || (size != 0 && range[0] <= pageRanges[size - 1][1]))
383 throw new IllegalArgumentException();
385 size = pageRanges.length;
386 if (fromPage > 0 && pageRanges[0][0] > fromPage)
387 fromPage = pageRanges[0][0];
388 if (toPage > 0 && pageRanges[size - 1][1] < toPage)
389 toPage = pageRanges[size - 1][1];
390 this.pageRanges = new int[size][];
391 while (--size >= 0)
392 this.pageRanges[size] = (int[]) pageRanges[size].clone();
395 public String getPrinter()
397 return printer;
400 public void setPrinter(String printer)
402 this.printer = printer;
405 public SidesType getSides()
407 return sides;
410 public void setSides(SidesType sides)
412 if (sides == null)
413 throw new IllegalArgumentException();
414 this.sides = sides;
417 public void setSidesToDefault()
419 sides = SidesType.ONE_SIDED;
422 public int getToPage()
424 return toPage != 0 ? toPage
425 : pageRanges != null ? pageRanges[pageRanges.length - 1][1]
426 : fromPage != 0 ? fromPage : maxPage;
429 public void setToPage(int toPage)
431 if (toPage < minPage || (fromPage > toPage && fromPage != 0)
432 || toPage > maxPage)
433 throw new IllegalArgumentException();
434 if (pageRanges == null)
435 this.toPage = toPage;
438 public boolean equals(Object o)
440 if (this == o)
441 return true;
442 if (! (o instanceof JobAttributes))
443 return false;
444 JobAttributes ja = (JobAttributes) o;
445 if (copies != ja.copies || selection != ja.selection
446 || destination != ja.destination || dialog != ja.dialog
447 || ! filename.equals(ja.filename) || maxPage != ja.maxPage
448 || minPage != ja.minPage || multiple != ja.multiple
449 || fromPage != ja.fromPage || toPage != ja.toPage
450 || ! printer.equals(ja.printer) || sides != ja.sides
451 || (pageRanges == null) != (ja.pageRanges == null))
452 return false;
453 if (pageRanges != ja.pageRanges)
454 for (int i = pageRanges.length; --i >= 0; )
455 if (pageRanges[i][0] != ja.pageRanges[i][0]
456 || pageRanges[i][1] != ja.pageRanges[i][1])
457 return false;
458 return true;
461 public int hashCode()
463 int hash = (selection.value << 6) ^ (destination.value << 5)
464 ^ (dialog.value << 3) ^ (multiple.value << 2) ^ sides.value
465 ^ (filename == null ? 0 : filename.hashCode())
466 ^ (printer == null ? 0 : printer.hashCode());
467 // The effect of the above fields on the hashcode match the JDK. However,
468 // I am unable to reverse engineer the effect of the fields listed below,
469 // so I am using my own implementation. Note that this still satisfies
470 // the general contract of hashcode, it just doesn't match the JDK.
471 hash ^= (copies << 27) ^ (maxPage << 22) ^ (minPage << 17);
472 if (pageRanges == null)
473 hash ^= (getFromPage() << 13) ^ (getToPage() << 8);
474 else
475 for (int i = pageRanges.length; --i >= 0; )
476 hash ^= (pageRanges[i][0] << 13) ^ (pageRanges[i][1] << 8);
477 return hash;
480 public String toString()
482 StringBuffer s = new StringBuffer("copies=").append(copies)
483 .append(",defaultSelection=").append(selection).append(",destination=")
484 .append(destination).append(",dialog=").append(dialog)
485 .append(",fileName=").append(filename).append(",fromPage=")
486 .append(getFromPage()).append(",maxPage=").append(maxPage)
487 .append(",minPage=").append(minPage)
488 .append(",multiple-document-handling=").append(multiple)
489 .append(",page-ranges=[");
490 if (pageRanges == null)
491 s.append(minPage).append(':').append(minPage).append(']');
492 else
493 for (int i = 0; i < pageRanges.length; i++)
494 s.append(pageRanges[i][0]).append(':').append(pageRanges[i][1])
495 .append(',');
496 s.setLength(s.length() - 1);
497 return s.append("],printer=").append(printer).append(",sides=")
498 .append(sides).append(",toPage=").append(getToPage()).toString();
500 } // class JobAttributes