1
/* ParagraphView.java -- Renders a paragraph in HTML
2
Copyright (C) 2006 Free Software Foundation, Inc.
4
This file is part of GNU Classpath.
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING. If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library. Thus, the terms and
23
conditions of the GNU General Public License cover the whole
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module. An independent module is a module which is not derived from
33
or based on this library. If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so. If you do not wish to do so, delete this
36
exception statement from your version. */
39
package javax.swing.text.html;
41
import java.awt.Graphics;
42
import java.awt.Shape;
44
import javax.swing.SizeRequirements;
45
import javax.swing.text.AttributeSet;
46
import javax.swing.text.Document;
47
import javax.swing.text.Element;
48
import javax.swing.text.View;
51
* Renders a paragraph in HTML. This is a subclass of
52
* {@link javax.swing.text.ParagraphView} with some adjustments for
53
* understanding stylesheets.
55
* @author Roman Kennke (kennke@aicas.com)
57
public class ParagraphView
58
extends javax.swing.text.ParagraphView
62
* Creates a new ParagraphView for the specified element.
64
* @param element the element
66
public ParagraphView(Element element)
72
* Sets the parent of this view. This is implemented to call the parent
73
* functionality and then trigger {@link #setPropertiesFromAttributes} in
74
* order to load the stylesheet attributes.
76
* @param parent the parent view to set
78
public void setParent(View parent)
80
super.setParent(parent);
82
setPropertiesFromAttributes();
86
* Returns the attributes used by this view. This is implemented to multiplex
87
* the attributes of the model with the attributes of the stylesheet.
89
public AttributeSet getAttributes()
91
// FIXME: Implement this multiplexing thing.
92
return super.getAttributes();
96
* Loads the visual properties of the ParagraphView from the element's
97
* attributes and the stylesheet of the HTML document.
99
protected void setPropertiesFromAttributes()
101
// FIXME: Implement this.
105
* Returns the stylesheet used by this view.
107
* @return the stylesheet used by this view
109
protected StyleSheet getStyleSheet()
111
Document doc = getDocument();
112
StyleSheet styleSheet = null;
113
if (doc instanceof HTMLDocument)
114
styleSheet = ((HTMLDocument) doc).getStyleSheet();
119
* Calculates the minor axis requirements of this view. This is implemented
120
* to return the super class'es requirements and modifies the minimumSpan
121
* slightly so that it is not smaller than the length of the longest word.
123
* @param axis the axis
124
* @param r the SizeRequirements object to be used as return parameter;
125
* if <code>null</code> a new one will be created
127
* @return the requirements along the minor layout axis
129
protected SizeRequirements calculateMinorAxisRequirements(int axis,
132
// FIXME: Implement the above specified behaviour.
133
return super.calculateMinorAxisRequirements(axis, r);
137
* Determines if this view is visible or not. If none of the children is
138
* visible and the only visible child is the break that ends the paragraph,
139
* this paragraph is not considered to be visible.
141
* @return the visibility of this paragraph
143
public boolean isVisible()
145
// FIXME: Implement the above specified behaviour.
146
return super.isVisible();
150
* Paints this view. This delegates to the superclass after the coordinates
151
* have been updated for tab calculations.
153
* @param g the graphics object
154
* @param a the current allocation of this view
156
public void paint(Graphics g, Shape a)
158
// FIXME: Implement the above specified behaviour.
163
* Returns the preferred span of this view. If this view is not visible,
164
* we return <code>0</code>, otherwise the super class is called.
166
* @param axis the axis
168
* @return the preferred span of this view
170
public float getPreferredSpan(int axis)
174
span = super.getPreferredSpan(axis);
179
* Returns the minimum span of this view. If this view is not visible,
180
* we return <code>0</code>, otherwise the super class is called.
182
* @param axis the axis
184
* @return the minimum span of this view
186
public float getMinimumSpan(int axis)
190
span = super.getMinimumSpan(axis);
195
* Returns the maximum span of this view. If this view is not visible,
196
* we return <code>0</code>, otherwise the super class is called.
198
* @param axis the axis
200
* @return the maximum span of this view
202
public float getMaximumSpan(int axis)
206
span = super.getMaximumSpan(axis);