KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > inline > Viewport


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: Viewport.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.area.inline;
21
22 import org.apache.fop.area.Area;
23
24 import java.io.IOException JavaDoc;
25 import java.awt.geom.Rectangle2D JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 /**
29  * Inline viewport area.
30  * This is an inline-level viewport area for inline container,
31  * external graphic and instream foreign object. This viewport
32  * holds the area and positions it.
33  */

34 public class Viewport extends InlineArea {
35     // contents could be container, foreign object or image
36
private Area content;
37     // clipping for the viewport
38
private boolean clip = false;
39     // position of the child area relative to this area
40
private Rectangle2D JavaDoc contentPosition;
41
42     /**
43      * Create a new viewport area with the content area.
44      *
45      * @param child the child content area of this viewport
46      */

47     public Viewport(Area child) {
48         content = child;
49     }
50
51     /**
52      * Set the clip of this viewport.
53      *
54      * @param c true if this viewport should clip
55      */

56     public void setClip(boolean c) {
57         clip = c;
58     }
59
60     /**
61      * Get the clip of this viewport.
62      *
63      * @return true if this viewport should clip
64      */

65     public boolean getClip() {
66         return clip;
67     }
68
69     /**
70      * Set the position and size of the content of this viewport.
71      *
72      * @param cp the position and size to place the content
73      */

74     public void setContentPosition(Rectangle2D JavaDoc cp) {
75         contentPosition = cp;
76     }
77
78     /**
79      * Get the position and size of the content of this viewport.
80      *
81      * @return the position and size to place the content
82      */

83     public Rectangle2D JavaDoc getContentPosition() {
84         return contentPosition;
85     }
86
87     /**
88      * Sets the content area.
89      * @param content the content area
90      */

91     public void setContent(Area content) {
92         this.content = content;
93     }
94     
95     /**
96      * Get the content area for this viewport.
97      *
98      * @return the content area
99      */

100     public Area getContent() {
101         return content;
102     }
103
104     private void writeObject(java.io.ObjectOutputStream JavaDoc out)
105     throws IOException JavaDoc {
106         out.writeBoolean(contentPosition != null);
107         if (contentPosition != null) {
108             out.writeFloat((float) contentPosition.getX());
109             out.writeFloat((float) contentPosition.getY());
110             out.writeFloat((float) contentPosition.getWidth());
111             out.writeFloat((float) contentPosition.getHeight());
112         }
113         out.writeBoolean(clip);
114         out.writeObject(props);
115         out.writeObject(content);
116     }
117
118     private void readObject(java.io.ObjectInputStream JavaDoc in)
119     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
120         if (in.readBoolean()) {
121             contentPosition = new Rectangle2D.Float JavaDoc(in.readFloat(),
122                                                     in.readFloat(),
123                                                     in.readFloat(),
124                                                     in.readFloat());
125         }
126         clip = in.readBoolean();
127         props = (HashMap JavaDoc) in.readObject();
128         content = (Area) in.readObject();
129     }
130
131 }
132
Popular Tags