52 public abstract class FlowView extends BoxView {
53
54 /**
55 * Constructs a FlowView for the given element.
56 *
57 * @param elem the element that this view is responsible for
58 * @param axis may be either View.X_AXIS or View.Y_AXIS
59 */
60 public FlowView(Element elem, int axis) {
61 super(elem, axis);
62 layoutSpan = Integer.MAX_VALUE;
63 strategy = new FlowStrategy();
64 }
65
66 /**
67 * Fetches the axis along which views should be
68 * flowed. By default, this will be the axis
69 * orthogonal to the axis along which the flow
70 * rows are tiled (the axis of the default flow
71 * rows themselves). This is typically used
72 * by the <code>FlowStrategy</code>.
73 * @return the axis along which views should be
74 * flowed
75 */
76 public int getFlowAxis() {
77 if (getAxis() == Y_AXIS) {
78 return X_AXIS;
79 }
80 return Y_AXIS;
81 }
82
83 /**
84 * Fetch the constraining span to flow against for
85 * the given child index. This is called by the
86 * FlowStrategy while it is updating the flow.
87 * A flow can be shaped by providing different values
88 * for the row constraints. By default, the entire
89 * span inside of the insets along the flow axis
90 * is returned.
91 *
92 * @param index the index of the row being updated.
114 */
115 public int getFlowStart(int index) {
116 return 0;
117 }
118
119 /**
120 * Create a View that should be used to hold a
121 * a rows worth of children in a flow. This is
122 * called by the FlowStrategy when new children
123 * are added or removed (i.e. rows are added or
124 * removed) in the process of updating the flow.
125 * @return a View that should be used to hold a
126 * a rows worth of children in a flow
127 */
128 protected abstract View createRow();
129
130 // ---- BoxView methods -------------------------------------
131
132 /**
133 * Loads all of the children to initialize the view.
134 * This is called by the <code>setParent</code> method.
135 * This is reimplemented to not load any children directly
136 * (as they are created in the process of formatting).
137 * If the layoutPool variable is null, an instance of
138 * LogicalView is created to represent the logical view
139 * that is used in the process of formatting.
140 *
141 * @param f the view factory
142 */
143 protected void loadChildren(ViewFactory f) {
144 if (layoutPool == null) {
145 layoutPool = new LogicalView(getElement());
146 }
147 layoutPool.setParent(this);
148
149 // This synthetic insertUpdate call gives the strategy a chance
150 // to initialize.
151 strategy.insertUpdate(this, null, null);
152 }
153
154 /**
398 * @param e the change information from the associated document
399 * @param alloc the current allocation of the view inside of the insets.
400 * @see View#removeUpdate
401 */
402 public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
403 addDamage(fv, e.getOffset());
404 if (alloc != null) {
405 Component host = fv.getContainer();
406 if (host != null) {
407 host.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
408 }
409 } else {
410 fv.preferenceChanged(null, true, true);
411 }
412 }
413
414 /**
415 * Gives notification from the document that attributes were changed
416 * in a location that this view is responsible for.
417 *
418 * @param fv the <code>FlowView</code> containing the changes
419 * @param e the <code>DocumentEvent</code> describing the changes
420 * done to the Document
421 * @param alloc Bounds of the View
422 * @see View#changedUpdate
423 */
424 public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
425 addDamage(fv, e.getOffset());
426 if (alloc != null) {
427 Component host = fv.getContainer();
428 if (host != null) {
429 host.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
430 }
431 } else {
432 fv.preferenceChanged(null, true, true);
433 }
434 }
435
436 /**
437 * This method gives flow strategies access to the logical
438 * view of the FlowView.
439 * @param fv the FlowView
|
52 public abstract class FlowView extends BoxView {
53
54 /**
55 * Constructs a FlowView for the given element.
56 *
57 * @param elem the element that this view is responsible for
58 * @param axis may be either View.X_AXIS or View.Y_AXIS
59 */
60 public FlowView(Element elem, int axis) {
61 super(elem, axis);
62 layoutSpan = Integer.MAX_VALUE;
63 strategy = new FlowStrategy();
64 }
65
66 /**
67 * Fetches the axis along which views should be
68 * flowed. By default, this will be the axis
69 * orthogonal to the axis along which the flow
70 * rows are tiled (the axis of the default flow
71 * rows themselves). This is typically used
72 * by the {@code FlowStrategy}.
73 * @return the axis along which views should be
74 * flowed
75 */
76 public int getFlowAxis() {
77 if (getAxis() == Y_AXIS) {
78 return X_AXIS;
79 }
80 return Y_AXIS;
81 }
82
83 /**
84 * Fetch the constraining span to flow against for
85 * the given child index. This is called by the
86 * FlowStrategy while it is updating the flow.
87 * A flow can be shaped by providing different values
88 * for the row constraints. By default, the entire
89 * span inside of the insets along the flow axis
90 * is returned.
91 *
92 * @param index the index of the row being updated.
114 */
115 public int getFlowStart(int index) {
116 return 0;
117 }
118
119 /**
120 * Create a View that should be used to hold a
121 * a rows worth of children in a flow. This is
122 * called by the FlowStrategy when new children
123 * are added or removed (i.e. rows are added or
124 * removed) in the process of updating the flow.
125 * @return a View that should be used to hold a
126 * a rows worth of children in a flow
127 */
128 protected abstract View createRow();
129
130 // ---- BoxView methods -------------------------------------
131
132 /**
133 * Loads all of the children to initialize the view.
134 * This is called by the {@code setParent} method.
135 * This is reimplemented to not load any children directly
136 * (as they are created in the process of formatting).
137 * If the layoutPool variable is null, an instance of
138 * LogicalView is created to represent the logical view
139 * that is used in the process of formatting.
140 *
141 * @param f the view factory
142 */
143 protected void loadChildren(ViewFactory f) {
144 if (layoutPool == null) {
145 layoutPool = new LogicalView(getElement());
146 }
147 layoutPool.setParent(this);
148
149 // This synthetic insertUpdate call gives the strategy a chance
150 // to initialize.
151 strategy.insertUpdate(this, null, null);
152 }
153
154 /**
398 * @param e the change information from the associated document
399 * @param alloc the current allocation of the view inside of the insets.
400 * @see View#removeUpdate
401 */
402 public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
403 addDamage(fv, e.getOffset());
404 if (alloc != null) {
405 Component host = fv.getContainer();
406 if (host != null) {
407 host.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
408 }
409 } else {
410 fv.preferenceChanged(null, true, true);
411 }
412 }
413
414 /**
415 * Gives notification from the document that attributes were changed
416 * in a location that this view is responsible for.
417 *
418 * @param fv the {@code FlowView} containing the changes
419 * @param e the {@code DocumentEvent} describing the changes
420 * done to the Document
421 * @param alloc Bounds of the View
422 * @see View#changedUpdate
423 */
424 public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
425 addDamage(fv, e.getOffset());
426 if (alloc != null) {
427 Component host = fv.getContainer();
428 if (host != null) {
429 host.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
430 }
431 } else {
432 fv.preferenceChanged(null, true, true);
433 }
434 }
435
436 /**
437 * This method gives flow strategies access to the logical
438 * view of the FlowView.
439 * @param fv the FlowView
|