Source Code Cross Referenced for Paper.java in  » 6.0-JDK-Core » AWT » java » awt » print » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt.print 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1997-2006 Sun Microsystems, Inc.  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.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.awt.print;
027
028        import java.awt.geom.Rectangle2D;
029
030        /**
031         * The <code>Paper</code> class describes the physical characteristics of
032         * a piece of paper.
033         * <p>
034         * When creating a <code>Paper</code> object, it is the application's 
035         * responsibility to ensure that the paper size and the imageable area
036         * are compatible.  For example, if the paper size is changed from 
037         * 11 x 17 to 8.5 x 11, the application might need to reduce the 
038         * imageable area so that whatever is printed fits on the page.
039         * <p>
040         * @see #setSize(double, double)
041         * @see #setImageableArea(double, double, double, double)
042         */
043        public class Paper implements  Cloneable {
044
045            /* Private Class Variables */
046
047            private static final int INCH = 72;
048            private static final double LETTER_WIDTH = 8.5 * INCH;
049            private static final double LETTER_HEIGHT = 11 * INCH;
050
051            /* Instance Variables */
052
053            /**
054             * The height of the physical page in 1/72nds
055             * of an inch. The number is stored as a floating
056             * point value rather than as an integer
057             * to facilitate the conversion from metric
058             * units to 1/72nds of an inch and then back.
059             * (This may or may not be a good enough reason
060             * for a float).
061             */
062            private double mHeight;
063
064            /**
065             * The width of the physical page in 1/72nds
066             * of an inch.
067             */
068            private double mWidth;
069
070            /**
071             * The area of the page on which drawing will
072             * be visable. The area outside of this
073             * rectangle but on the Page generally
074             * reflects the printer's hardware margins.
075             * The origin of the physical page is
076             * at (0, 0) with this rectangle provided
077             * in that coordinate system.
078             */
079            private Rectangle2D mImageableArea;
080
081            /* Constructors */
082
083            /**
084             * Creates a letter sized piece of paper
085             * with one inch margins.
086             */
087            public Paper() {
088                mHeight = LETTER_HEIGHT;
089                mWidth = LETTER_WIDTH;
090                mImageableArea = new Rectangle2D.Double(INCH, INCH, mWidth - 2
091                        * INCH, mHeight - 2 * INCH);
092            }
093
094            /* Instance Methods */
095
096            /**
097             * Creates a copy of this <code>Paper</code> with the same contents
098             * as this <code>Paper</code>.
099             * @return a copy of this <code>Paper</code>.
100             */
101            public Object clone() {
102
103                Paper newPaper;
104
105                try {
106                    /* It's okay to copy the reference to the imageable
107                     * area into the clone since we always return a copy
108                     * of the imageable area when asked for it.
109                     */
110                    newPaper = (Paper) super .clone();
111
112                } catch (CloneNotSupportedException e) {
113                    e.printStackTrace();
114                    newPaper = null; // should never happen.
115                }
116
117                return newPaper;
118            }
119
120            /**
121             * Returns the height of the page in 1/72nds of an inch.
122             * @return the height of the page described by this
123             *		<code>Paper</code>.
124             */
125            public double getHeight() {
126                return mHeight;
127            }
128
129            /**
130             * Sets the width and height of this <code>Paper</code>
131             * object, which represents the properties of the page onto
132             * which printing occurs.
133             * The dimensions are supplied in 1/72nds of
134             * an inch.
135             * @param width the value to which to set this <code>Paper</code>
136             * object's width
137             * @param height the value to which to set this <code>Paper</code>
138             * object's height
139             */
140            public void setSize(double width, double height) {
141                mWidth = width;
142                mHeight = height;
143            }
144
145            /**
146             * Returns the width of the page in 1/72nds
147             * of an inch.
148             * @return the width of the page described by this
149             * <code>Paper</code>.
150             */
151            public double getWidth() {
152                return mWidth;
153            }
154
155            /**
156             * Sets the imageable area of this <code>Paper</code>.  The 
157             * imageable area is the area on the page in which printing
158             * occurs. 
159             * @param x the X coordinate to which to set the
160             * upper-left corner of the imageable area of this <code>Paper</code>
161             * @param y the Y coordinate to which to set the
162             * upper-left corner of the imageable area of this <code>Paper</code>
163             * @param width the value to which to set the width of the 
164             * imageable area of this <code>Paper</code>
165             * @param height the value to which to set the height of the
166             * imageable area of this <code>Paper</code>
167             */
168            public void setImageableArea(double x, double y, double width,
169                    double height) {
170                mImageableArea = new Rectangle2D.Double(x, y, width, height);
171            }
172
173            /**
174             * Returns the x coordinate of the upper-left corner of this
175             * <code>Paper</code> object's imageable area.
176             * @return the x coordinate of the imageable area.
177             */
178            public double getImageableX() {
179                return mImageableArea.getX();
180            }
181
182            /**
183             * Returns the y coordinate of the upper-left corner of this
184             * <code>Paper</code> object's imageable area.
185             * @return the y coordinate of the imageable area.
186             */
187            public double getImageableY() {
188                return mImageableArea.getY();
189            }
190
191            /**
192             * Returns the width of this <code>Paper</code> object's imageable
193             * area.
194             * @return the width of the imageable area.
195             */
196            public double getImageableWidth() {
197                return mImageableArea.getWidth();
198            }
199
200            /**
201             * Returns the height of this <code>Paper</code> object's imageable
202             * area.
203             * @return the height of the imageable area.   
204             */
205            public double getImageableHeight() {
206                return mImageableArea.getHeight();
207            }
208        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.