~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to javax/swing/text/html/ParagraphView.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ParagraphView.java -- Renders a paragraph in HTML
 
2
   Copyright (C) 2006 Free Software Foundation, Inc.
 
3
 
 
4
This file is part of GNU Classpath.
 
5
 
 
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)
 
9
any later version.
 
10
 
 
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.
 
15
 
 
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
 
19
02110-1301 USA.
 
20
 
 
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
 
24
combination.
 
25
 
 
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. */
 
37
 
 
38
 
 
39
package javax.swing.text.html;
 
40
 
 
41
import java.awt.Graphics;
 
42
import java.awt.Shape;
 
43
 
 
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;
 
49
 
 
50
/**
 
51
 * Renders a paragraph in HTML. This is a subclass of
 
52
 * {@link javax.swing.text.ParagraphView} with some adjustments for
 
53
 * understanding stylesheets.
 
54
 *
 
55
 * @author Roman Kennke (kennke@aicas.com)
 
56
 */
 
57
public class ParagraphView
 
58
    extends javax.swing.text.ParagraphView
 
59
{
 
60
 
 
61
  /**
 
62
   * Creates a new ParagraphView for the specified element.
 
63
   *
 
64
   * @param element the element
 
65
   */
 
66
  public ParagraphView(Element element)
 
67
  {
 
68
    super(element);
 
69
  }
 
70
 
 
71
  /**
 
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.
 
75
   *
 
76
   * @param parent the parent view to set
 
77
   */
 
78
  public void setParent(View parent)
 
79
  {
 
80
    super.setParent(parent);
 
81
    if (parent != null)
 
82
      setPropertiesFromAttributes();
 
83
  }
 
84
 
 
85
  /**
 
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.
 
88
   */
 
89
  public AttributeSet getAttributes()
 
90
  {
 
91
    // FIXME: Implement this multiplexing thing.
 
92
    return super.getAttributes();
 
93
  }
 
94
 
 
95
  /**
 
96
   * Loads the visual properties of the ParagraphView from the element's
 
97
   * attributes and the stylesheet of the HTML document.
 
98
   */
 
99
  protected void setPropertiesFromAttributes()
 
100
  {
 
101
    // FIXME: Implement this.
 
102
  }
 
103
 
 
104
  /**
 
105
   * Returns the stylesheet used by this view.
 
106
   *
 
107
   * @return the stylesheet used by this view
 
108
   */
 
109
  protected StyleSheet getStyleSheet()
 
110
  {
 
111
    Document doc = getDocument();
 
112
    StyleSheet styleSheet = null;
 
113
    if (doc instanceof HTMLDocument)
 
114
      styleSheet = ((HTMLDocument) doc).getStyleSheet();
 
115
    return styleSheet;
 
116
  }
 
117
 
 
118
  /**
 
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.
 
122
   *
 
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
 
126
   *
 
127
   * @return the requirements along the minor layout axis
 
128
   */
 
129
  protected SizeRequirements calculateMinorAxisRequirements(int axis,
 
130
                                                            SizeRequirements r)
 
131
  {
 
132
    // FIXME: Implement the above specified behaviour.
 
133
    return super.calculateMinorAxisRequirements(axis, r);
 
134
  }
 
135
 
 
136
  /**
 
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.
 
140
   *
 
141
   * @return the visibility of this paragraph
 
142
   */
 
143
  public boolean isVisible()
 
144
  {
 
145
    // FIXME: Implement the above specified behaviour.
 
146
    return super.isVisible();
 
147
  }
 
148
 
 
149
  /**
 
150
   * Paints this view. This delegates to the superclass after the coordinates
 
151
   * have been updated for tab calculations.
 
152
   *
 
153
   * @param g the graphics object
 
154
   * @param a the current allocation of this view
 
155
   */
 
156
  public void paint(Graphics g, Shape a)
 
157
  {
 
158
    // FIXME: Implement the above specified behaviour.
 
159
    super.paint(g, a);
 
160
  }
 
161
 
 
162
  /**
 
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.
 
165
   *
 
166
   * @param axis the axis
 
167
   *
 
168
   * @return the preferred span of this view
 
169
   */
 
170
  public float getPreferredSpan(int axis)
 
171
  {
 
172
    float span = 0;
 
173
    if (isVisible())
 
174
      span = super.getPreferredSpan(axis);
 
175
    return span;
 
176
  }
 
177
 
 
178
  /**
 
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.
 
181
   *
 
182
   * @param axis the axis
 
183
   *
 
184
   * @return the minimum span of this view
 
185
   */
 
186
  public float getMinimumSpan(int axis)
 
187
  {
 
188
    float span = 0;
 
189
    if (isVisible())
 
190
      span = super.getMinimumSpan(axis);
 
191
    return span;
 
192
  }
 
193
 
 
194
  /**
 
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.
 
197
   *
 
198
   * @param axis the axis
 
199
   *
 
200
   * @return the maximum span of this view
 
201
   */
 
202
  public float getMaximumSpan(int axis)
 
203
  {
 
204
    float span = 0;
 
205
    if (isVisible())
 
206
      span = super.getMaximumSpan(axis);
 
207
    return span;
 
208
  }
 
209
}