1 7 package javax.swing.text.html; 8 9 import java.util.Enumeration ; 10 import java.awt.*; 11 import javax.swing.text.*; 12 13 19 public class ListView extends BlockView { 20 21 26 public ListView(Element elem) { 27 super(elem, View.Y_AXIS); 28 } 29 30 36 public float getAlignment(int axis) { 37 switch (axis) { 38 case View.X_AXIS: 39 return 0.5f; 40 case View.Y_AXIS: 41 return 0.5f; 42 default: 43 throw new IllegalArgumentException ("Invalid axis: " + axis); 44 } 45 } 46 47 55 public void paint(Graphics g, Shape allocation) { 56 super.paint(g, allocation); 57 Rectangle alloc = allocation.getBounds(); 58 Rectangle clip = g.getClipBounds(); 59 if ((clip.x + clip.width) < (alloc.x + getLeftInset())) { 64 Rectangle childRect = alloc; 65 alloc = getInsideAllocation(allocation); 66 int n = getViewCount(); 67 int endY = clip.y + clip.height; 68 for (int i = 0; i < n; i++) { 69 childRect.setBounds(alloc); 70 childAllocation(i, childRect); 71 if (childRect.y < endY) { 72 if ((childRect.y + childRect.height) >= clip.y) { 73 listPainter.paint(g, childRect.x, childRect.y, 74 childRect.width, childRect.height, 75 this, i); 76 } 77 } 78 else { 79 break; 80 } 81 } 82 } 83 } 84 85 94 protected void paintChild(Graphics g, Rectangle alloc, int index) { 95 listPainter.paint(g, alloc.x, alloc.y, alloc.width, alloc.height, this, index); 96 super.paintChild(g, alloc, index); 97 } 98 99 protected void setPropertiesFromAttributes() { 100 super.setPropertiesFromAttributes(); 101 listPainter = getStyleSheet().getListPainter(getAttributes()); 102 } 103 104 private StyleSheet.ListPainter listPainter; 105 } 106 | Popular Tags |