1 7 package javax.swing.text.html; 8 9 import java.util.Enumeration ; 10 import java.awt.*; 11 import javax.swing.*; 12 import javax.swing.border.*; 13 import javax.swing.event.*; 14 import javax.swing.text.*; 15 16 25 class LineView extends ParagraphView { 26 27 int tabBase; 28 29 34 public LineView(Element elem) { 35 super(elem); 36 } 37 38 42 public boolean isVisible() { 43 return true; 44 } 45 46 56 public float getMinimumSpan(int axis) { 57 return getPreferredSpan(axis); 58 } 59 60 66 public int getResizeWeight(int axis) { 67 switch (axis) { 68 case View.X_AXIS: 69 return 1; 70 case View.Y_AXIS: 71 return 0; 72 default: 73 throw new IllegalArgumentException ("Invalid axis: " + axis); 74 } 75 } 76 77 83 public float getAlignment(int axis) { 84 if (axis == View.X_AXIS) { 85 return 0; 86 } 87 return super.getAlignment(axis); 88 } 89 90 105 protected void layout(int width, int height) { 106 super.layout(Integer.MAX_VALUE - 1, height); 107 } 108 109 134 public float nextTabStop(float x, int tabOffset) { 135 if (getTabSet() == null && 137 StyleConstants.getAlignment(getAttributes()) == 138 StyleConstants.ALIGN_LEFT) { 139 return getPreTab(x, tabOffset); 140 } 141 return super.nextTabStop(x, tabOffset); 142 } 143 144 147 protected float getPreTab(float x, int tabOffset) { 148 Document d = getDocument(); 149 View v = getViewAtPosition(tabOffset, null); 150 if ((d instanceof StyledDocument) && v != null) { 151 Font f = ((StyledDocument)d).getFont(v.getAttributes()); 153 Container c = getContainer(); 154 FontMetrics fm = (c != null) ? c.getFontMetrics(f) : 155 Toolkit.getDefaultToolkit().getFontMetrics(f); 156 int width = getCharactersPerTab() * fm.charWidth('W'); 157 int tb = (int)getTabBase(); 158 return (float)((((int)x - tb) / width + 1) * width + tb); 159 } 160 return 10.0f + x; 161 } 162 163 166 protected int getCharactersPerTab() { 167 return 8; 168 } 169 } 170 | Popular Tags |