37 |
|
|
38 |
package javax.swing.text; |
package javax.swing.text; |
39 |
|
|
40 |
|
import java.awt.Container; |
41 |
import java.awt.Graphics; |
import java.awt.Graphics; |
42 |
import java.awt.Shape; |
import java.awt.Shape; |
43 |
import java.util.Vector; |
import java.util.Vector; |
45 |
|
|
46 |
public abstract class View implements SwingConstants |
public abstract class View implements SwingConstants |
47 |
{ |
{ |
48 |
static int BadBreakWeight; |
public static final int BadBreakWeight = 0; |
49 |
static int ExcellentBreakWeight; |
public static final int ExcellentBreakWeight = 2000; |
50 |
static int ForcedBreakWeight; |
public static final int ForcedBreakWeight = 3000; |
51 |
static int GoodBreakWeight; |
public static final int GoodBreakWeight = 1000; |
52 |
|
|
53 |
public final static int X_AXIS = 0; |
public static final int X_AXIS = 0; |
54 |
public final static int Y_AXIS = 1; |
public static final int Y_AXIS = 1; |
55 |
|
|
56 |
float width, height; |
private float width, height; |
57 |
Element elt; |
private Element elt; |
58 |
View parent; |
private View parent; |
59 |
|
|
60 |
/** |
/** |
61 |
* this vector contains the views ordered at offsets... |
* Creates a new <code>View</code> instance. |
62 |
|
* |
63 |
|
* @param elem an <code>Element</code> value |
64 |
*/ |
*/ |
|
Vector v = new Vector(); |
|
|
|
|
|
|
|
65 |
public View(Element elem) |
public View(Element elem) |
66 |
{ |
{ |
67 |
elt = elem; |
elt = elem; |
68 |
} |
} |
69 |
|
|
70 |
public int getViewCount() |
public abstract void paint(Graphics g, Shape s); |
71 |
|
|
72 |
|
public void setParent(View a) |
73 |
{ |
{ |
74 |
return v.size(); |
parent = a; |
75 |
} |
} |
76 |
|
|
77 |
public View getView(int a) |
public View getParent() |
78 |
{ |
{ |
79 |
return (View) v.get(a); |
return parent; |
80 |
} |
} |
81 |
|
|
82 |
public void remove(int i) |
public void setSize(int w, int h) |
83 |
{ |
{ |
84 |
v.removeElementAt(i); |
width = w; |
85 |
|
height = h; |
86 |
} |
} |
87 |
|
|
88 |
public void insert(int off, View view) |
public Container getContainer() |
89 |
{ |
{ |
90 |
v.insertElementAt(view, off); |
return parent != null ? parent.getContainer() : null; |
91 |
} |
} |
92 |
|
|
93 |
public void append(View view) |
public Document getDocument() |
94 |
{ |
{ |
95 |
v.addElement(view); |
return getElement().getDocument(); |
96 |
} |
} |
97 |
|
|
98 |
public void paint(Graphics g, Shape allocation) |
public Element getElement() |
99 |
{ |
{ |
100 |
System.out.println("view.paint() !!!!"); |
return elt; |
101 |
} |
} |
102 |
|
|
103 |
public void setParent(View a) |
public abstract float getPreferredSpan(int axis); |
104 |
|
|
105 |
|
public float getAlignment(int axis) |
106 |
{ |
{ |
107 |
parent = a; |
return 0.5f; |
108 |
} |
} |
109 |
|
|
110 |
public View getParent() |
public AttributeSet getAttributes() |
111 |
{ |
{ |
112 |
return parent; |
return elt.getAttributes(); |
113 |
} |
} |
114 |
|
|
115 |
public void setSize(int w, int h) |
public boolean isVisible() |
116 |
{ |
{ |
117 |
width = w; |
return true; |
|
height = h; |
|
118 |
} |
} |
119 |
|
|
120 |
public Document getDocument() |
public int getViewCount() |
121 |
{ |
{ |
122 |
return getElement().getDocument(); |
return 0; |
123 |
} |
} |
124 |
|
|
125 |
public Element getElement() |
public View getView(int index) |
126 |
{ |
{ |
127 |
return elt; |
return null; |
128 |
} |
} |
129 |
|
|
130 |
public float getPreferredSpan(int a) |
public ViewFactory getViewFactory() |
131 |
{ |
{ |
132 |
switch (a) |
return parent != null ? parent.getViewFactory() : null; |
133 |
|
} |
134 |
|
|
135 |
|
public void replace(int offset, int length, View[] views) |
136 |
{ |
{ |
137 |
case X_AXIS: return width; |
// Default implementation does nothing. |
138 |
case Y_AXIS: return height; |
} |
139 |
default: |
|
140 |
|
public void insert(int offset, View view) |
141 |
{ |
{ |
142 |
System.err.println("I sure wish Java had enums !!! "); |
View[] array = { view }; |
143 |
return 0; |
replace(offset, 1, array); |
144 |
} |
} |
145 |
|
|
146 |
|
public void append(View view) |
147 |
|
{ |
148 |
|
View[] array = { view }; |
149 |
|
replace(getViewCount(), 1, array); |
150 |
|
} |
151 |
|
|
152 |
|
public void removeAll() |
153 |
|
{ |
154 |
|
replace(0, getViewCount(), null); |
155 |
} |
} |
156 |
|
|
157 |
|
public void remove(int index) |
158 |
|
{ |
159 |
|
replace(index, 1, null); |
160 |
|
} |
161 |
|
|
162 |
|
public View createFragment(int p0, int p1) |
163 |
|
{ |
164 |
|
// The default implementation doesnt support fragmentation. |
165 |
|
return this; |
166 |
} |
} |
167 |
} |
} |
168 |
|
|