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: * @author Igor A. Pyankov
019: * @version $Revision$
020: */package java.awt.print;
021:
022: import org.apache.harmony.awt.internal.nls.Messages;
023:
024: public class PageFormat implements Cloneable {
025: public static final int LANDSCAPE = 0;
026: public static final int PORTRAIT = 1;
027: public static final int REVERSE_LANDSCAPE = 2;
028:
029: private Paper pagePaper;
030: private int pageOrientation;
031:
032: public PageFormat() {
033: super ();
034: pageOrientation = PORTRAIT;
035: pagePaper = new Paper();
036: }
037:
038: @Override
039: public Object clone() {
040: PageFormat clonedPage;
041: try {
042: clonedPage = (PageFormat) super .clone();
043: clonedPage.pagePaper = (Paper) pagePaper.clone();
044: } catch (CloneNotSupportedException cnse) {
045: cnse.printStackTrace();
046: clonedPage = null;
047: }
048: return clonedPage;
049: }
050:
051: public double getHeight() {
052: if (pageOrientation == PORTRAIT) {
053: return pagePaper.getHeight();
054: }
055: return pagePaper.getWidth();
056: }
057:
058: public double getImageableHeight() {
059: if (pageOrientation == PORTRAIT) {
060: return pagePaper.getImageableHeight();
061: }
062: return pagePaper.getImageableWidth();
063: }
064:
065: public double getImageableWidth() {
066: if (pageOrientation == PORTRAIT) {
067: return pagePaper.getImageableWidth();
068: }
069: return pagePaper.getImageableHeight();
070: }
071:
072: public double getImageableX() {
073: double x = 0;
074: switch (getOrientation()) {
075: case PORTRAIT:
076: x = pagePaper.getImageableX();
077: break;
078:
079: case LANDSCAPE:
080: x = pagePaper.getHeight()
081: - (pagePaper.getImageableY() + pagePaper
082: .getImageableHeight());
083: break;
084:
085: case REVERSE_LANDSCAPE:
086: x = pagePaper.getImageableY();
087: break;
088: }
089: return x;
090: }
091:
092: public double getImageableY() {
093: double y = 0;
094: switch (getOrientation()) {
095: case PORTRAIT:
096: y = pagePaper.getImageableY();
097: break;
098:
099: case LANDSCAPE:
100: y = pagePaper.getImageableX();
101: break;
102:
103: case REVERSE_LANDSCAPE:
104: y = pagePaper.getWidth()
105: - (pagePaper.getImageableX() + pagePaper
106: .getImageableWidth());
107: break;
108: }
109: return y;
110: }
111:
112: public double[] getMatrix() {
113: double matrix[] = { 0d, 0d, 0d, 0d, 0d, 0d };
114:
115: switch (pageOrientation) {
116:
117: case PORTRAIT:
118: matrix[0] = 1.0d;
119: matrix[3] = 1.0d;
120: break;
121:
122: case LANDSCAPE:
123: matrix[1] = -1.0d;
124: matrix[2] = 1.0d;
125: matrix[5] = pagePaper.getHeight();
126: break;
127:
128: case REVERSE_LANDSCAPE:
129: matrix[1] = 1.0d;
130: matrix[2] = -1.0d;
131: matrix[4] = pagePaper.getWidth();
132: break;
133: }
134: return matrix;
135: }
136:
137: public int getOrientation() {
138: return pageOrientation;
139: }
140:
141: public Paper getPaper() {
142: return pagePaper;
143: }
144:
145: public double getWidth() {
146: if (pageOrientation == PORTRAIT) {
147: return pagePaper.getWidth();
148: }
149: return pagePaper.getHeight();
150: }
151:
152: public void setOrientation(int orientation)
153: throws IllegalArgumentException {
154: if (orientation == PORTRAIT || orientation == LANDSCAPE
155: || orientation == REVERSE_LANDSCAPE) {
156: this .pageOrientation = orientation;
157: } else {
158: // awt.5F=wrong orientation
159: throw new IllegalArgumentException(Messages
160: .getString("awt.5F")); //$NON-NLS-1$
161: }
162: }
163:
164: public void setPaper(Paper paper) {
165: this.pagePaper = paper;
166: }
167: }
|