Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / text / ParagraphView.java
blobc4864503187b18b667e0f02b7308f161978a418f
1 /* ParagraphView.java -- A composite View
2 Copyright (C) 2005 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)
9 any later version.
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
19 02110-1301 USA.
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.
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;
41 import java.awt.Shape;
43 import javax.swing.event.DocumentEvent;
45 /**
46 * A {@link FlowView} that flows it's children horizontally and boxes the rows
47 * vertically.
49 * @author Roman Kennke (roman@kennke.org)
51 public class ParagraphView extends FlowView implements TabExpander
53 /**
54 * A specialized horizontal <code>BoxView</code> that represents exactly
55 * one row in a <code>ParagraphView</code>.
57 class Row extends BoxView
59 /**
60 * Creates a new instance of <code>Row</code>.
62 Row(Element el)
64 super(el, X_AXIS);
66 public float getAlignment(int axis)
68 // FIXME: This is very likely not 100% correct. Work this out.
69 return 0.0F;
73 /**
74 * The indentation of the first line of the paragraph.
76 protected int firstLineIndent;
78 /**
79 * The justification of the paragraph.
81 private int justification;
83 /**
84 * The line spacing of this paragraph.
86 private float lineSpacing;
88 /**
89 * The TabSet of this paragraph.
91 private TabSet tabSet;
93 /**
94 * Creates a new <code>ParagraphView</code> for the given
95 * <code>Element</code>.
97 * @param element the element that is rendered by this ParagraphView
99 public ParagraphView(Element element)
101 super(element, Y_AXIS);
104 public float nextTabStop(float x, int tabOffset)
106 throw new InternalError("Not implemented yet");
110 * Creates a new view that represents a row within a flow.
112 * @return a view for a new row
114 protected View createRow()
116 return new Row(getElement());
120 * Returns the alignment for this paragraph view for the specified axis.
121 * For the X_AXIS the paragraph view will be aligned at it's left edge
122 * (0.0F). For the Y_AXIS the paragraph view will be aligned at the
123 * center of it's first row.
125 * @param axis the axis which is examined
127 * @return the alignment for this paragraph view for the specified axis
129 public float getAlignment(int axis)
131 if (axis == X_AXIS)
132 return 0.0F;
133 else if (getViewCount() > 0)
136 float prefHeight = getPreferredSpan(Y_AXIS);
137 float firstRowHeight = getView(0).getPreferredSpan(Y_AXIS);
138 return (firstRowHeight / 2.F) / prefHeight;
140 else
141 return 0.0F;
145 * Receives notification when some attributes of the displayed element
146 * changes. This triggers a refresh of the cached attributes of this
147 * paragraph.
149 * @param ev the document event
150 * @param a the allocation of this view
151 * @param fv the view factory to use for creating new child views
153 public void changedUpdate(DocumentEvent ev, Shape a, ViewFactory fv)
155 setPropertiesFromAttributes();
159 * Fetches the cached properties from the element's attributes.
161 protected void setPropertiesFromAttributes()
163 Element el = getElement();
164 AttributeSet atts = el.getAttributes();
165 setFirstLineIndent(StyleConstants.getFirstLineIndent(atts));
166 setLineSpacing(StyleConstants.getLineSpacing(atts));
167 setJustification(StyleConstants.getAlignment(atts));
168 tabSet = StyleConstants.getTabSet(atts);
172 * Sets the indentation of the first line of the paragraph.
174 * @param i the indentation to set
176 protected void setFirstLineIndent(float i)
178 firstLineIndent = (int) i;
182 * Sets the justification of the paragraph.
184 * @param j the justification to set
186 protected void setJustification(int j)
188 justification = j;
192 * Sets the line spacing for this paragraph.
194 * @param s the line spacing to set
196 protected void setLineSpacing(float s)
198 lineSpacing = s;
202 * Returns the i-th view from the logical views, before breaking into rows.
204 * @param i the index of the logical view to return
206 * @return the i-th view from the logical views, before breaking into rows
208 protected View getLayoutView(int i)
210 return layoutPool.getView(i);
214 * Returns the number of logical child views.
216 * @return the number of logical child views
218 protected int getLayoutViewCount()
220 return layoutPool.getViewCount();
224 * Returns the TabSet used by this ParagraphView.
226 * @return the TabSet used by this ParagraphView
228 protected TabSet getTabSet()
230 return tabSet;