001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.print.attribute;
019:
020: import java.io.Serializable;
021:
022: public abstract class ResolutionSyntax implements Cloneable,
023: Serializable {
024: private static final long serialVersionUID = 2706743076526672017L;
025:
026: public static final int DPI = 100;
027:
028: public static final int DPCM = 254;
029:
030: private final int crossFeedRes;
031:
032: private final int feedRes;
033:
034: public ResolutionSyntax(int crossFeedResolution,
035: int feedResolution, int units) {
036: if (crossFeedResolution < 1) {
037: throw new IllegalArgumentException("CrossFeedResolution "
038: + "is less than 1");
039: }
040: if (feedResolution < 1) {
041: throw new IllegalArgumentException(
042: "FeedResolution is less than 1");
043: }
044: if (units < 1) {
045: throw new IllegalArgumentException("Units is less than 1");
046: }
047: crossFeedRes = crossFeedResolution * units;
048: feedRes = feedResolution * units;
049: }
050:
051: @Override
052: public boolean equals(Object object) {
053: if ((object instanceof ResolutionSyntax)
054: && crossFeedRes == ((ResolutionSyntax) object).crossFeedRes
055: && feedRes == ((ResolutionSyntax) object).feedRes) {
056: return true;
057: }
058: return false;
059: }
060:
061: public int getCrossFeedResolution(int units) {
062: if (units < 1) {
063: throw new IllegalArgumentException("units is less than 1");
064: }
065: return Math.round(((float) crossFeedRes) / units);
066: }
067:
068: protected int getCrossFeedResolutionDphi() {
069: return crossFeedRes;
070: }
071:
072: public int getFeedResolution(int units) {
073: if (units < 1) {
074: throw new IllegalArgumentException("units is less than 1");
075: }
076: return Math.round(((float) feedRes) / units);
077: }
078:
079: protected int getFeedResolutionDphi() {
080: return feedRes;
081: }
082:
083: public int[] getResolution(int units) {
084: return new int[] { getCrossFeedResolution(units),
085: getFeedResolution(units) };
086: }
087:
088: @Override
089: public int hashCode() {
090: return (crossFeedRes | (feedRes << 16));
091: }
092:
093: public boolean lessThanOrEquals(ResolutionSyntax resolutionSyntax) {
094: if (crossFeedRes <= resolutionSyntax.crossFeedRes
095: && feedRes <= resolutionSyntax.feedRes) {
096: return true;
097: }
098: return false;
099: }
100:
101: @Override
102: public String toString() {
103: return (crossFeedRes + "x" + feedRes + " dphi");
104: }
105:
106: public String toString(int units, String unitsName) {
107: if (unitsName == null) {
108: unitsName = "";
109: }
110: return (getCrossFeedResolution(units) + "x"
111: + getFeedResolution(units) + " " + unitsName);
112: }
113: }
|