Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.print;
027
028/**
029 * Class to represent a supported device resolution of a printer in
030 * the feed and crossfeed directionsin dots-per-inch (DPI).
031 * When printing in a portrait orientation
032 * cross feed direction is usually x/horizontal resolution, and
033 * feed direction is usually y/horizontal resolution.
034 * On most printers these are the same value, but it is possuble
035 * for them to be different.
036 * @since JavaFX 8
037 */
038
039public final class PrintResolution {
040
041    private int cfRes;
042    private int fRes;
043
044    /**
045     * Represents the dots-per-inch (DPI) resolution of a printer device.
046     * When printing in a portrait orientation
047     * cross feed direction is usually x/horizontal resolution, and
048     * feed direction is usually y/horizontal resolution.
049     * On most printers these are the same value, but rarely they may be
050     * different.
051     * @param crossFeedResolution - resolution across the paper feed direction.
052     * @param feedResolution - resolution in the paper feed direction.
053     * @throws IllegalArgumentException if the values are not greater
054     * than zero.
055     */
056     PrintResolution(int crossFeedResolution, int feedResolution)
057        throws IllegalArgumentException
058    {
059        if (crossFeedResolution <= 0 || feedResolution <= 0) {
060            throw new IllegalArgumentException("Values must be positive");
061        }
062        cfRes = crossFeedResolution;
063        fRes  = feedResolution;
064    }
065
066    /**
067     * Returns the resolution in dpi. across the paper feed direction.
068     * @return cross feed resolution.
069     */
070    public int getCrossFeedResolution() {
071        return cfRes;
072    }
073
074    /**
075     * Returns the resolution in dpi. in the paper feed direction.
076     * @return feed resolution.
077     */
078    public int getFeedResolution() {
079        return fRes;
080    }
081
082    @Override
083    public boolean equals(Object o) {
084        try {
085            PrintResolution other = (PrintResolution)o;
086            return this.cfRes == other.cfRes && this.fRes == other.fRes;
087        } catch (Exception e) {
088            return false;
089        }
090    }
091
092    @Override
093    public int hashCode() {
094        return cfRes << 16 | fRes;
095    }
096
097    @Override
098    public String toString() {
099        return "Feed res=" + fRes + "dpi. Cross Feed res=" + cfRes + "dpi.";
100    }
101
102}