2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
package javax.swing.text.html;
|
|
26 |
|
|
27 |
import java.util.Enumeration;
|
|
28 |
import java.awt.*;
|
|
29 |
import javax.swing.text.*;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* A view implementation to display an html list
|
|
33 |
*
|
|
34 |
* @author Timothy Prinzing
|
|
35 |
*/
|
|
36 |
public class ListView extends BlockView {
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Creates a new view that represents a list element.
|
|
40 |
*
|
|
41 |
* @param elem the element to create a view for
|
|
42 |
*/
|
|
43 |
public ListView(Element elem) {
|
|
44 |
super(elem, View.Y_AXIS);
|
|
45 |
}
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Calculates the desired shape of the list.
|
|
49 |
*
|
|
50 |
* @return the desired span
|
|
51 |
* @see View#getPreferredSpan
|
|
52 |
*/
|
|
53 |
public float getAlignment(int axis) {
|
|
54 |
switch (axis) {
|
|
55 |
case View.X_AXIS:
|
|
56 |
return 0.5f;
|
|
57 |
case View.Y_AXIS:
|
|
58 |
return 0.5f;
|
|
59 |
default:
|
|
60 |
throw new IllegalArgumentException("Invalid axis: " + axis);
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
/**
|
|
65 |
* Renders using the given rendering surface and area on that
|
|
66 |
* surface.
|
|
67 |
*
|
|
68 |
* @param g the rendering surface to use
|
|
69 |
* @param allocation the allocated region to render into
|
|
70 |
* @see View#paint
|
|
71 |
*/
|
|
72 |
public void paint(Graphics g, Shape allocation) {
|
|
73 |
super.paint(g, allocation);
|
|
74 |
Rectangle alloc = allocation.getBounds();
|
|
75 |
Rectangle clip = g.getClipBounds();
|
|
76 |
// Since listPainter paints in the insets we have to check for the
|
|
77 |
// case where the child is not painted because the paint region is
|
|
78 |
// to the left of the child. This assumes the ListPainter paints in
|
|
79 |
// the left margin.
|
|
80 |
if ((clip.x + clip.width) < (alloc.x + getLeftInset())) {
|
|
81 |
Rectangle childRect = alloc;
|
|
82 |
alloc = getInsideAllocation(allocation);
|
|
83 |
int n = getViewCount();
|
|
84 |
int endY = clip.y + clip.height;
|
|
85 |
for (int i = 0; i < n; i++) {
|
|
86 |
childRect.setBounds(alloc);
|
|
87 |
childAllocation(i, childRect);
|
|
88 |
if (childRect.y < endY) {
|
|
89 |
if ((childRect.y + childRect.height) >= clip.y) {
|
|
90 |
listPainter.paint(g, childRect.x, childRect.y,
|
|
91 |
childRect.width, childRect.height,
|
|
92 |
this, i);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
else {
|
|
96 |
break;
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
/**
|
|
103 |
* Paints one of the children; called by paint(). By default
|
|
104 |
* that is all it does, but a subclass can use this to paint
|
|
105 |
* things relative to the child.
|
|
106 |
*
|
|
107 |
* @param g the graphics context
|
|
108 |
* @param alloc the allocated region to render the child into
|
|
109 |
* @param index the index of the child
|
|
110 |
*/
|
|
111 |
protected void paintChild(Graphics g, Rectangle alloc, int index) {
|
|
112 |
listPainter.paint(g, alloc.x, alloc.y, alloc.width, alloc.height, this, index);
|
|
113 |
super.paintChild(g, alloc, index);
|
|
114 |
}
|
|
115 |
|
|
116 |
protected void setPropertiesFromAttributes() {
|
|
117 |
super.setPropertiesFromAttributes();
|
|
118 |
listPainter = getStyleSheet().getListPainter(getAttributes());
|
|
119 |
}
|
|
120 |
|
|
121 |
private StyleSheet.ListPainter listPainter;
|
|
122 |
}
|