KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > RegionViewport


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: RegionViewport.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.area;
21
22 import java.awt.geom.Rectangle2D JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.HashMap JavaDoc;
25
26 /**
27  * Region Viewport area.
28  * This object represents the region-viewport-area. It has a
29  * region-reference-area as its child. These areas are described
30  * in the fo:region-body description in the XSL Recommendation.
31  */

32 public class RegionViewport extends Area implements Cloneable JavaDoc {
33     // this rectangle is relative to the page
34
private RegionReference regionReference;
35     private Rectangle2D JavaDoc viewArea;
36     private boolean clip = false;
37
38     /**
39      * Create a new region-viewport-area
40      *
41      * @param viewArea the view area of this viewport
42      */

43     public RegionViewport(Rectangle2D JavaDoc viewArea) {
44         this.viewArea = viewArea;
45         addTrait(Trait.IS_VIEWPORT_AREA, Boolean.TRUE);
46     }
47
48     /**
49      * Set the region-reference-area for this region viewport.
50      *
51      * @param reg the child region-reference-area inside this viewport
52      */

53     public void setRegionReference(RegionReference reg) {
54         regionReference = reg;
55     }
56
57     /**
58      * Get the region-reference-area for this region viewport.
59      *
60      * @return the child region-reference-area inside this viewport
61      */

62     public RegionReference getRegionReference() {
63         return regionReference;
64     }
65
66     /**
67      * Set the clipping for this region viewport.
68      *
69      * @param c the clipping value
70      */

71     public void setClip(boolean c) {
72         clip = c;
73     }
74
75     /** @return true if the viewport should be clipped. */
76     public boolean isClip() {
77         return this.clip;
78     }
79     
80     /**
81      * Get the view area of this viewport.
82      *
83      * @return the viewport rectangle area
84      */

85     public Rectangle2D JavaDoc getViewArea() {
86         return viewArea;
87     }
88
89     private void writeObject(java.io.ObjectOutputStream JavaDoc out)
90     throws IOException JavaDoc {
91         out.writeFloat((float) viewArea.getX());
92         out.writeFloat((float) viewArea.getY());
93         out.writeFloat((float) viewArea.getWidth());
94         out.writeFloat((float) viewArea.getHeight());
95         out.writeBoolean(clip);
96         out.writeObject(props);
97         out.writeObject(regionReference);
98     }
99
100     private void readObject(java.io.ObjectInputStream JavaDoc in)
101             throws IOException JavaDoc, ClassNotFoundException JavaDoc {
102         viewArea = new Rectangle2D.Float JavaDoc(in.readFloat(), in.readFloat(),
103                                          in.readFloat(), in.readFloat());
104         clip = in.readBoolean();
105         props = (HashMap JavaDoc)in.readObject();
106         setRegionReference((RegionReference) in.readObject());
107     }
108
109     /**
110      * Clone this region viewport.
111      * Used when creating a copy from the page master.
112      *
113      * @return a new copy of this region viewport
114      */

115     public Object JavaDoc clone() {
116         RegionViewport rv = new RegionViewport((Rectangle2D JavaDoc)viewArea.clone());
117         rv.regionReference = (RegionReference)regionReference.clone();
118         if (props != null) {
119             rv.props = new HashMap JavaDoc(props);
120         }
121         if (foreignAttributes != null) {
122             rv.foreignAttributes = new HashMap JavaDoc(foreignAttributes);
123         }
124         return rv;
125     }
126 }
127
128
Popular Tags