java.awt.JobAttributes Java Examples

The following examples show how to use java.awt.JobAttributes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobAttributes.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this {@code JobAttributes} to
 * the same values as the attributes of obj.
 *
 * @param   obj the {@code JobAttributes} to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #2
Source File: JobAttributes.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #3
Source File: JobAttributes.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #4
Source File: JobAttributes.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #5
Source File: JobAttributes.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #6
Source File: JobAttributes.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #7
Source File: JobAttributes.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #8
Source File: JobAttributes.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #9
Source File: JobAttributes.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #10
Source File: JobAttributes.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #11
Source File: JobAttributes.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this <code>JobAttributes</code> to
 * the same values as the attributes of obj.
 *
 * @param   obj the <code>JobAttributes</code> to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #12
Source File: JobAttributes.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Sets all of the attributes of this {@code JobAttributes} to
 * the same values as the attributes of obj.
 *
 * @param   obj the {@code JobAttributes} to copy
 */
public void set(JobAttributes obj) {
    copies = obj.copies;
    defaultSelection = obj.defaultSelection;
    destination = obj.destination;
    dialog = obj.dialog;
    fileName = obj.fileName;
    fromPage = obj.fromPage;
    maxPage = obj.maxPage;
    minPage = obj.minPage;
    multipleDocumentHandling = obj.multipleDocumentHandling;
    // okay because we never modify the contents of pageRanges
    pageRanges = obj.pageRanges;
    prFirst = obj.prFirst;
    prLast = obj.prLast;
    printer = obj.printer;
    sides = obj.sides;
    toPage = obj.toPage;
}
 
Example #13
Source File: PrinterException.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    Thread t = new Thread (() -> {
        robot.waitForIdle();
        robot.delay(2000);
        robot.keyPress(KeyEvent.VK_ESCAPE);
        robot.keyRelease(KeyEvent.VK_ESCAPE);
       });
    Toolkit tk = Toolkit.getDefaultToolkit();
    PrintJob pj = null;

    int[][] pageRange = new int[][]{new int[]{1,1}};
    JobAttributes ja = new JobAttributes(1,
            java.awt.JobAttributes.DefaultSelectionType.ALL,
            JobAttributes.DestinationType.FILE, JobAttributes.DialogType.NATIVE,
            "filename.ps", Integer.MAX_VALUE, 1,
            JobAttributes.MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES,
             pageRange, "", JobAttributes.SidesType.ONE_SIDED);

    Frame testFrame = new Frame("print");
    try {
        if (tk != null) {
            t.start();
            pj = tk.getPrintJob(testFrame, null, ja, null);
        }
    } finally {
        testFrame.dispose();
    }
}
 
Example #14
Source File: NullFrameTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JobAttributes ja = new JobAttributes();
    ja.setDialog(JobAttributes.DialogType.COMMON);
    boolean npeThrown = false;
    try {
        Toolkit.getDefaultToolkit().getPrintJob(null,
                                           "test Printing", ja, null);
    } catch (NullPointerException ex) {
        npeThrown = true;
    }
    if (!npeThrown) {
        throw
        new RuntimeException("getPrintJob didn't throw NPE for null Frame");
    }
}
 
Example #15
Source File: PrintJob2D.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public PrintJob2D(Frame frame,  String doctitle,
                  final Properties props) {
    this.props = props;
    this.jobAttributes = new JobAttributes();
    this.pageAttributes = new PageAttributes();
    translateInputProps();
    initPrintJob2D(frame, doctitle,
                   this.jobAttributes, this.pageAttributes);
}
 
Example #16
Source File: PrintJob2D.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public PrintJob2D(Frame frame,  String doctitle,
                  final Properties props) {
    this.props = props;
    this.jobAttributes = new JobAttributes();
    this.pageAttributes = new PageAttributes();
    translateInputProps();
    initPrintJob2D(frame, doctitle,
                   this.jobAttributes, this.pageAttributes);
}
 
Example #17
Source File: PrintJob2D.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public PrintJob2D(Frame frame,  String doctitle,
                  final Properties props) {
    this.props = props;
    this.jobAttributes = new JobAttributes();
    this.pageAttributes = new PageAttributes();
    translateInputProps();
    initPrintJob2D(frame, doctitle,
                   this.jobAttributes, this.pageAttributes);
}
 
Example #18
Source File: PrintJob2D.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public PrintJob2D(Frame frame,  String doctitle,
                  final Properties props) {
    this.props = props;
    this.jobAttributes = new JobAttributes();
    this.pageAttributes = new PageAttributes();
    translateInputProps();
    initPrintJob2D(frame, doctitle,
                   this.jobAttributes, this.pageAttributes);
}
 
Example #19
Source File: PrintJob2D.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public PrintJob2D(Frame frame,  String doctitle,
                  final Properties props) {
    this.props = props;
    this.jobAttributes = new JobAttributes();
    this.pageAttributes = new PageAttributes();
    translateInputProps();
    initPrintJob2D(frame, doctitle,
                   this.jobAttributes, this.pageAttributes);
}
 
Example #20
Source File: JobAttributes.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a <code>JobAttributes</code> instance with the
 * specified values for every attribute.
 *
 * @param   copies an integer greater than 0
 * @param   defaultSelection <code>DefaultSelectionType.ALL</code>,
 *          <code>DefaultSelectionType.RANGE</code>, or
 *          <code>DefaultSelectionType.SELECTION</code>
 * @param   destination <code>DesintationType.FILE</code> or
 *          <code>DesintationType.PRINTER</code>
 * @param   dialog <code>DialogType.COMMON</code>,
 *          <code>DialogType.NATIVE</code>, or
 *          <code>DialogType.NONE</code>
 * @param   fileName the possibly <code>null</code> file name
 * @param   maxPage an integer greater than zero and greater than or equal
 *          to <i>minPage</i>
 * @param   minPage an integer greater than zero and less than or equal
 *          to <i>maxPage</i>
 * @param   multipleDocumentHandling
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES</code> or
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES</code>
 * @param   pageRanges an array of integer arrays of two elements; an array
 *          is interpreted as a range spanning all pages including and
 *          between the specified pages; ranges must be in ascending
 *          order and must not overlap; specified page numbers cannot be
 *          less than <i>minPage</i> nor greater than <i>maxPage</i>;
 *          for example:
 *          <pre>
 *          (new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
 *                         new int[] { 15, 19 } }),
 *          </pre>
 *          specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
 *          (<code>new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }</code>),
 *          is an invalid set of page ranges because the two ranges
 *          overlap
 * @param   printer the possibly <code>null</code> printer name
 * @param   sides <code>SidesType.ONE_SIDED</code>,
 *          <code>SidesType.TWO_SIDED_LONG_EDGE</code>, or
 *          <code>SidesType.TWO_SIDED_SHORT_EDGE</code>
 * @throws  IllegalArgumentException if one or more of the above
 *          conditions is violated
 */
public JobAttributes(int copies, DefaultSelectionType defaultSelection,
                     DestinationType destination, DialogType dialog,
                     String fileName, int maxPage, int minPage,
                     MultipleDocumentHandlingType multipleDocumentHandling,
                     int[][] pageRanges, String printer, SidesType sides) {
    setCopies(copies);
    setDefaultSelection(defaultSelection);
    setDestination(destination);
    setDialog(dialog);
    setFileName(fileName);
    setMaxPage(maxPage);
    setMinPage(minPage);
    setMultipleDocumentHandling(multipleDocumentHandling);
    setPageRanges(pageRanges);
    setPrinter(printer);
    setSides(sides);
}
 
Example #21
Source File: PrintJob2D.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public PrintJob2D(Frame frame,  String doctitle,
                  JobAttributes jobAttributes,
                  PageAttributes pageAttributes) {
    initPrintJob2D(frame, doctitle, jobAttributes, pageAttributes);
}
 
Example #22
Source File: JobAttributes.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a {@code JobAttributes} instance with the
 * specified values for every attribute.
 *
 * @param   copies an integer greater than 0
 * @param   defaultSelection {@code DefaultSelectionType.ALL},
 *          {@code DefaultSelectionType.RANGE}, or
 *          {@code DefaultSelectionType.SELECTION}
 * @param   destination {@code DestinationType.FILE} or
 *          {@code DestinationType.PRINTER}
 * @param   dialog {@code DialogType.COMMON},
 *          {@code DialogType.NATIVE}, or
 *          {@code DialogType.NONE}
 * @param   fileName the possibly {@code null} file name
 * @param   maxPage an integer greater than zero and greater than or equal
 *          to <i>minPage</i>
 * @param   minPage an integer greater than zero and less than or equal
 *          to <i>maxPage</i>
 * @param   multipleDocumentHandling
 *     {@code MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES} or
 *     {@code MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES}
 * @param   pageRanges an array of integer arrays of two elements; an array
 *          is interpreted as a range spanning all pages including and
 *          between the specified pages; ranges must be in ascending
 *          order and must not overlap; specified page numbers cannot be
 *          less than <i>minPage</i> nor greater than <i>maxPage</i>;
 *          for example:
 *          <pre>
 *          (new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
 *                         new int[] { 15, 19 } }),
 *          </pre>
 *          specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
 *          ({@code new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }}),
 *          is an invalid set of page ranges because the two ranges
 *          overlap
 * @param   printer the possibly {@code null} printer name
 * @param   sides {@code SidesType.ONE_SIDED},
 *          {@code SidesType.TWO_SIDED_LONG_EDGE}, or
 *          {@code SidesType.TWO_SIDED_SHORT_EDGE}
 * @throws  IllegalArgumentException if one or more of the above
 *          conditions is violated
 */
public JobAttributes(int copies, DefaultSelectionType defaultSelection,
                     DestinationType destination, DialogType dialog,
                     String fileName, int maxPage, int minPage,
                     MultipleDocumentHandlingType multipleDocumentHandling,
                     int[][] pageRanges, String printer, SidesType sides) {
    setCopies(copies);
    setDefaultSelection(defaultSelection);
    setDestination(destination);
    setDialog(dialog);
    setFileName(fileName);
    setMaxPage(maxPage);
    setMinPage(minPage);
    setMultipleDocumentHandling(multipleDocumentHandling);
    setPageRanges(pageRanges);
    setPrinter(printer);
    setSides(sides);
}
 
Example #23
Source File: JobAttributes.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Determines whether two JobAttributes are equal to each other.
 * <p>
 * Two JobAttributes are equal if and only if each of their attributes are
 * equal. Attributes of enumeration type are equal if and only if the
 * fields refer to the same unique enumeration object. A set of page
 * ranges is equal if and only if the sets are of equal length, each range
 * enumerates the same pages, and the ranges are in the same order.
 *
 * @param   obj the object whose equality will be checked.
 * @return  whether obj is equal to this JobAttribute according to the
 *          above criteria.
 */
public boolean equals(Object obj) {
    if (!(obj instanceof JobAttributes)) {
        return false;
    }
    JobAttributes rhs = (JobAttributes)obj;

    if (fileName == null) {
        if (rhs.fileName != null) {
            return false;
        }
    } else {
        if (!fileName.equals(rhs.fileName)) {
            return false;
        }
    }

    if (pageRanges == null) {
        if (rhs.pageRanges != null) {
            return false;
        }
    } else {
        if (rhs.pageRanges == null ||
                pageRanges.length != rhs.pageRanges.length) {
            return false;
        }
        for (int i = 0; i < pageRanges.length; i++) {
            if (pageRanges[i][0] != rhs.pageRanges[i][0] ||
                pageRanges[i][1] != rhs.pageRanges[i][1]) {
                return false;
            }
        }
    }

    if (printer == null) {
        if (rhs.printer != null) {
            return false;
        }
    } else {
        if (!printer.equals(rhs.printer)) {
            return false;
        }
    }

    return (copies == rhs.copies &&
            defaultSelection == rhs.defaultSelection &&
            destination == rhs.destination &&
            dialog == rhs.dialog &&
            fromPage == rhs.fromPage &&
            maxPage == rhs.maxPage &&
            minPage == rhs.minPage &&
            multipleDocumentHandling == rhs.multipleDocumentHandling &&
            prFirst == rhs.prFirst &&
            prLast == rhs.prLast &&
            sides == rhs.sides &&
            toPage == rhs.toPage);
}
 
Example #24
Source File: JobAttributes.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines whether two JobAttributes are equal to each other.
 * <p>
 * Two JobAttributes are equal if and only if each of their attributes are
 * equal. Attributes of enumeration type are equal if and only if the
 * fields refer to the same unique enumeration object. A set of page
 * ranges is equal if and only if the sets are of equal length, each range
 * enumerates the same pages, and the ranges are in the same order.
 *
 * @param   obj the object whose equality will be checked.
 * @return  whether obj is equal to this JobAttribute according to the
 *          above criteria.
 */
public boolean equals(Object obj) {
    if (!(obj instanceof JobAttributes)) {
        return false;
    }
    JobAttributes rhs = (JobAttributes)obj;

    if (fileName == null) {
        if (rhs.fileName != null) {
            return false;
        }
    } else {
        if (!fileName.equals(rhs.fileName)) {
            return false;
        }
    }

    if (pageRanges == null) {
        if (rhs.pageRanges != null) {
            return false;
        }
    } else {
        if (rhs.pageRanges == null ||
                pageRanges.length != rhs.pageRanges.length) {
            return false;
        }
        for (int i = 0; i < pageRanges.length; i++) {
            if (pageRanges[i][0] != rhs.pageRanges[i][0] ||
                pageRanges[i][1] != rhs.pageRanges[i][1]) {
                return false;
            }
        }
    }

    if (printer == null) {
        if (rhs.printer != null) {
            return false;
        }
    } else {
        if (!printer.equals(rhs.printer)) {
            return false;
        }
    }

    return (copies == rhs.copies &&
            defaultSelection == rhs.defaultSelection &&
            destination == rhs.destination &&
            dialog == rhs.dialog &&
            fromPage == rhs.fromPage &&
            maxPage == rhs.maxPage &&
            minPage == rhs.minPage &&
            multipleDocumentHandling == rhs.multipleDocumentHandling &&
            prFirst == rhs.prFirst &&
            prLast == rhs.prLast &&
            sides == rhs.sides &&
            toPage == rhs.toPage);
}
 
Example #25
Source File: JobAttributes.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a <code>JobAttributes</code> instance with the
 * specified values for every attribute.
 *
 * @param   copies an integer greater than 0
 * @param   defaultSelection <code>DefaultSelectionType.ALL</code>,
 *          <code>DefaultSelectionType.RANGE</code>, or
 *          <code>DefaultSelectionType.SELECTION</code>
 * @param   destination <code>DesintationType.FILE</code> or
 *          <code>DesintationType.PRINTER</code>
 * @param   dialog <code>DialogType.COMMON</code>,
 *          <code>DialogType.NATIVE</code>, or
 *          <code>DialogType.NONE</code>
 * @param   fileName the possibly <code>null</code> file name
 * @param   maxPage an integer greater than zero and greater than or equal
 *          to <i>minPage</i>
 * @param   minPage an integer greater than zero and less than or equal
 *          to <i>maxPage</i>
 * @param   multipleDocumentHandling
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES</code> or
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES</code>
 * @param   pageRanges an array of integer arrays of two elements; an array
 *          is interpreted as a range spanning all pages including and
 *          between the specified pages; ranges must be in ascending
 *          order and must not overlap; specified page numbers cannot be
 *          less than <i>minPage</i> nor greater than <i>maxPage</i>;
 *          for example:
 *          <pre>
 *          (new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
 *                         new int[] { 15, 19 } }),
 *          </pre>
 *          specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
 *          (<code>new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }</code>),
 *          is an invalid set of page ranges because the two ranges
 *          overlap
 * @param   printer the possibly <code>null</code> printer name
 * @param   sides <code>SidesType.ONE_SIDED</code>,
 *          <code>SidesType.TWO_SIDED_LONG_EDGE</code>, or
 *          <code>SidesType.TWO_SIDED_SHORT_EDGE</code>
 * @throws  IllegalArgumentException if one or more of the above
 *          conditions is violated
 */
public JobAttributes(int copies, DefaultSelectionType defaultSelection,
                     DestinationType destination, DialogType dialog,
                     String fileName, int maxPage, int minPage,
                     MultipleDocumentHandlingType multipleDocumentHandling,
                     int[][] pageRanges, String printer, SidesType sides) {
    setCopies(copies);
    setDefaultSelection(defaultSelection);
    setDestination(destination);
    setDialog(dialog);
    setFileName(fileName);
    setMaxPage(maxPage);
    setMinPage(minPage);
    setMultipleDocumentHandling(multipleDocumentHandling);
    setPageRanges(pageRanges);
    setPrinter(printer);
    setSides(sides);
}
 
Example #26
Source File: JobAttributes.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines whether two JobAttributes are equal to each other.
 * <p>
 * Two JobAttributes are equal if and only if each of their attributes are
 * equal. Attributes of enumeration type are equal if and only if the
 * fields refer to the same unique enumeration object. A set of page
 * ranges is equal if and only if the sets are of equal length, each range
 * enumerates the same pages, and the ranges are in the same order.
 *
 * @param   obj the object whose equality will be checked.
 * @return  whether obj is equal to this JobAttribute according to the
 *          above criteria.
 */
public boolean equals(Object obj) {
    if (!(obj instanceof JobAttributes)) {
        return false;
    }
    JobAttributes rhs = (JobAttributes)obj;

    if (fileName == null) {
        if (rhs.fileName != null) {
            return false;
        }
    } else {
        if (!fileName.equals(rhs.fileName)) {
            return false;
        }
    }

    if (pageRanges == null) {
        if (rhs.pageRanges != null) {
            return false;
        }
    } else {
        if (rhs.pageRanges == null ||
                pageRanges.length != rhs.pageRanges.length) {
            return false;
        }
        for (int i = 0; i < pageRanges.length; i++) {
            if (pageRanges[i][0] != rhs.pageRanges[i][0] ||
                pageRanges[i][1] != rhs.pageRanges[i][1]) {
                return false;
            }
        }
    }

    if (printer == null) {
        if (rhs.printer != null) {
            return false;
        }
    } else {
        if (!printer.equals(rhs.printer)) {
            return false;
        }
    }

    return (copies == rhs.copies &&
            defaultSelection == rhs.defaultSelection &&
            destination == rhs.destination &&
            dialog == rhs.dialog &&
            fromPage == rhs.fromPage &&
            maxPage == rhs.maxPage &&
            minPage == rhs.minPage &&
            multipleDocumentHandling == rhs.multipleDocumentHandling &&
            prFirst == rhs.prFirst &&
            prLast == rhs.prLast &&
            sides == rhs.sides &&
            toPage == rhs.toPage);
}
 
Example #27
Source File: PrintJob2D.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void initPrintJob2D(Frame frame,  String doctitle,
                            JobAttributes jobAttributes,
                            PageAttributes pageAttributes) {

    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }

    if (frame == null &&
        (jobAttributes == null ||
         jobAttributes.getDialog() == DialogType.NATIVE)) {
        throw new NullPointerException("Frame must not be null");
    }
    this.frame = frame;

    this.docTitle = (doctitle == null) ? "" : doctitle;
    this.jobAttributes = (jobAttributes != null)
        ? jobAttributes : new JobAttributes();
    this.pageAttributes = (pageAttributes != null)
        ? pageAttributes : new PageAttributes();

    // Currently, we always reduce page ranges to xxx or xxx-xxx
    int[][] pageRanges = this.jobAttributes.getPageRanges();
    int first = pageRanges[0][0];
    int last = pageRanges[pageRanges.length - 1][1];
    this.jobAttributes.setPageRanges(new int[][] {
        new int[] { first, last }
    });
    this.jobAttributes.setToPage(last);
    this.jobAttributes.setFromPage(first);


    // Verify that the cross feed and feed resolutions are the same
    int[] res = this.pageAttributes.getPrinterResolution();
    if (res[0] != res[1]) {
        throw new IllegalArgumentException("Differing cross feed and feed"+
                                           " resolutions not supported.");
    }

    // Verify that the app has access to the file system
    DestinationType dest= this.jobAttributes.getDestination();
    if (dest == DestinationType.FILE) {
        throwPrintToFile();

        // check if given filename is valid
        String destStr = jobAttributes.getFileName();
        if ((destStr != null) &&
            (jobAttributes.getDialog() == JobAttributes.DialogType.NONE)) {

            File f = new File(destStr);
            try {
                // check if this is a new file and if filename chars are valid
                // createNewFile returns false if file exists
                if (f.createNewFile()) {
                    f.delete();
                }
            } catch (IOException ioe) {
                throw new IllegalArgumentException("Cannot write to file:"+
                                                   destStr);
            } catch (SecurityException se) {
                //There is already file read/write access so at this point
                // only delete access is denied.  Just ignore it because in
                // most cases the file created in createNewFile gets overwritten
                // anyway.
            }

             File pFile = f.getParentFile();
             if ((f.exists() &&
                  (!f.isFile() || !f.canWrite())) ||
                 ((pFile != null) &&
                  (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                 throw new IllegalArgumentException("Cannot write to file:"+
                                                    destStr);
             }
        }
    }
}
 
Example #28
Source File: JobAttributes.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a <code>JobAttributes</code> instance with the
 * specified values for every attribute.
 *
 * @param   copies an integer greater than 0
 * @param   defaultSelection <code>DefaultSelectionType.ALL</code>,
 *          <code>DefaultSelectionType.RANGE</code>, or
 *          <code>DefaultSelectionType.SELECTION</code>
 * @param   destination <code>DesintationType.FILE</code> or
 *          <code>DesintationType.PRINTER</code>
 * @param   dialog <code>DialogType.COMMON</code>,
 *          <code>DialogType.NATIVE</code>, or
 *          <code>DialogType.NONE</code>
 * @param   fileName the possibly <code>null</code> file name
 * @param   maxPage an integer greater than zero and greater than or equal
 *          to <i>minPage</i>
 * @param   minPage an integer greater than zero and less than or equal
 *          to <i>maxPage</i>
 * @param   multipleDocumentHandling
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES</code> or
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES</code>
 * @param   pageRanges an array of integer arrays of two elements; an array
 *          is interpreted as a range spanning all pages including and
 *          between the specified pages; ranges must be in ascending
 *          order and must not overlap; specified page numbers cannot be
 *          less than <i>minPage</i> nor greater than <i>maxPage</i>;
 *          for example:
 *          <pre>
 *          (new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
 *                         new int[] { 15, 19 } }),
 *          </pre>
 *          specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
 *          (<code>new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }</code>),
 *          is an invalid set of page ranges because the two ranges
 *          overlap
 * @param   printer the possibly <code>null</code> printer name
 * @param   sides <code>SidesType.ONE_SIDED</code>,
 *          <code>SidesType.TWO_SIDED_LONG_EDGE</code>, or
 *          <code>SidesType.TWO_SIDED_SHORT_EDGE</code>
 * @throws  IllegalArgumentException if one or more of the above
 *          conditions is violated
 */
public JobAttributes(int copies, DefaultSelectionType defaultSelection,
                     DestinationType destination, DialogType dialog,
                     String fileName, int maxPage, int minPage,
                     MultipleDocumentHandlingType multipleDocumentHandling,
                     int[][] pageRanges, String printer, SidesType sides) {
    setCopies(copies);
    setDefaultSelection(defaultSelection);
    setDestination(destination);
    setDialog(dialog);
    setFileName(fileName);
    setMaxPage(maxPage);
    setMinPage(minPage);
    setMultipleDocumentHandling(multipleDocumentHandling);
    setPageRanges(pageRanges);
    setPrinter(printer);
    setSides(sides);
}
 
Example #29
Source File: JobAttributes.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a {@code JobAttributes} instance with the
 * specified values for every attribute.
 *
 * @param   copies an integer greater than 0
 * @param   defaultSelection {@code DefaultSelectionType.ALL},
 *          {@code DefaultSelectionType.RANGE}, or
 *          {@code DefaultSelectionType.SELECTION}
 * @param   destination {@code DestinationType.FILE} or
 *          {@code DestinationType.PRINTER}
 * @param   dialog {@code DialogType.COMMON},
 *          {@code DialogType.NATIVE}, or
 *          {@code DialogType.NONE}
 * @param   fileName the possibly {@code null} file name
 * @param   maxPage an integer greater than zero and greater than or equal
 *          to <i>minPage</i>
 * @param   minPage an integer greater than zero and less than or equal
 *          to <i>maxPage</i>
 * @param   multipleDocumentHandling
 *     {@code MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES} or
 *     {@code MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES}
 * @param   pageRanges an array of integer arrays of two elements; an array
 *          is interpreted as a range spanning all pages including and
 *          between the specified pages; ranges must be in ascending
 *          order and must not overlap; specified page numbers cannot be
 *          less than <i>minPage</i> nor greater than <i>maxPage</i>;
 *          for example:
 *          <pre>
 *          (new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
 *                         new int[] { 15, 19 } }),
 *          </pre>
 *          specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
 *          ({@code new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }}),
 *          is an invalid set of page ranges because the two ranges
 *          overlap
 * @param   printer the possibly {@code null} printer name
 * @param   sides {@code SidesType.ONE_SIDED},
 *          {@code SidesType.TWO_SIDED_LONG_EDGE}, or
 *          {@code SidesType.TWO_SIDED_SHORT_EDGE}
 * @throws  IllegalArgumentException if one or more of the above
 *          conditions is violated
 */
public JobAttributes(int copies, DefaultSelectionType defaultSelection,
                     DestinationType destination, DialogType dialog,
                     String fileName, int maxPage, int minPage,
                     MultipleDocumentHandlingType multipleDocumentHandling,
                     int[][] pageRanges, String printer, SidesType sides) {
    setCopies(copies);
    setDefaultSelection(defaultSelection);
    setDestination(destination);
    setDialog(dialog);
    setFileName(fileName);
    setMaxPage(maxPage);
    setMinPage(minPage);
    setMultipleDocumentHandling(multipleDocumentHandling);
    setPageRanges(pageRanges);
    setPrinter(printer);
    setSides(sides);
}
 
Example #30
Source File: JobAttributes.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a <code>JobAttributes</code> instance with the
 * specified values for every attribute.
 *
 * @param   copies an integer greater than 0
 * @param   defaultSelection <code>DefaultSelectionType.ALL</code>,
 *          <code>DefaultSelectionType.RANGE</code>, or
 *          <code>DefaultSelectionType.SELECTION</code>
 * @param   destination <code>DesintationType.FILE</code> or
 *          <code>DesintationType.PRINTER</code>
 * @param   dialog <code>DialogType.COMMON</code>,
 *          <code>DialogType.NATIVE</code>, or
 *          <code>DialogType.NONE</code>
 * @param   fileName the possibly <code>null</code> file name
 * @param   maxPage an integer greater than zero and greater than or equal
 *          to <i>minPage</i>
 * @param   minPage an integer greater than zero and less than or equal
 *          to <i>maxPage</i>
 * @param   multipleDocumentHandling
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES</code> or
 *     <code>MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES</code>
 * @param   pageRanges an array of integer arrays of two elements; an array
 *          is interpreted as a range spanning all pages including and
 *          between the specified pages; ranges must be in ascending
 *          order and must not overlap; specified page numbers cannot be
 *          less than <i>minPage</i> nor greater than <i>maxPage</i>;
 *          for example:
 *          <pre>
 *          (new int[][] { new int[] { 1, 3 }, new int[] { 5, 5 },
 *                         new int[] { 15, 19 } }),
 *          </pre>
 *          specifies pages 1, 2, 3, 5, 15, 16, 17, 18, and 19. Note that
 *          (<code>new int[][] { new int[] { 1, 1 }, new int[] { 1, 2 } }</code>),
 *          is an invalid set of page ranges because the two ranges
 *          overlap
 * @param   printer the possibly <code>null</code> printer name
 * @param   sides <code>SidesType.ONE_SIDED</code>,
 *          <code>SidesType.TWO_SIDED_LONG_EDGE</code>, or
 *          <code>SidesType.TWO_SIDED_SHORT_EDGE</code>
 * @throws  IllegalArgumentException if one or more of the above
 *          conditions is violated
 */
public JobAttributes(int copies, DefaultSelectionType defaultSelection,
                     DestinationType destination, DialogType dialog,
                     String fileName, int maxPage, int minPage,
                     MultipleDocumentHandlingType multipleDocumentHandling,
                     int[][] pageRanges, String printer, SidesType sides) {
    setCopies(copies);
    setDefaultSelection(defaultSelection);
    setDestination(destination);
    setDialog(dialog);
    setFileName(fileName);
    setMaxPage(maxPage);
    setMinPage(minPage);
    setMultipleDocumentHandling(multipleDocumentHandling);
    setPageRanges(pageRanges);
    setPrinter(printer);
    setSides(sides);
}