23 * questions.
24 */
25 package javax.swing.text;
26
27 import java.awt.*;
28 import java.beans.PropertyChangeEvent;
29 import java.beans.PropertyChangeListener;
30 import java.util.Set;
31 import javax.swing.SwingUtilities;
32 import javax.swing.event.*;
33
34 /**
35 * Component decorator that implements the view interface. The
36 * entire element is used to represent the component. This acts
37 * as a gateway from the display-only View implementations to
38 * interactive lightweight components (ie it allows components
39 * to be embedded into the View hierarchy).
40 * <p>
41 * The component is placed relative to the text baseline
42 * according to the value returned by
43 * <code>Component.getAlignmentY</code>. For Swing components
44 * this value can be conveniently set using the method
45 * <code>JComponent.setAlignmentY</code>. For example, setting
46 * a value of <code>0.75</code> will cause 75 percent of the
47 * component to be above the baseline, and 25 percent of the
48 * component to be below the baseline.
49 * <p>
50 * This class is implemented to do the extra work necessary to
51 * work properly in the presence of multiple threads (i.e. from
52 * asynchronous notification of model changes for example) by
53 * ensuring that all component access is done on the event thread.
54 * <p>
55 * The component used is determined by the return value of the
56 * createComponent method. The default implementation of this
57 * method is to return the component held as an attribute of
58 * the element (by calling StyleConstants.getComponent). A
59 * limitation of this behavior is that the component cannot
60 * be used by more than one text component (i.e. with a shared
61 * model). Subclasses can remove this constraint by implementing
62 * the createComponent to actually create a component based upon
63 * some kind of specification contained in the attributes. The
64 * ObjectView class in the html package is an example of a
65 * ComponentView implementation that supports multiple component
66 * views of a shared model.
220 public float getAlignment(int axis) {
221 if (c != null) {
222 switch (axis) {
223 case View.X_AXIS:
224 return c.getAlignmentX();
225 case View.Y_AXIS:
226 return c.getAlignmentY();
227 }
228 }
229 return super.getAlignment(axis);
230 }
231
232 /**
233 * Sets the parent for a child view.
234 * The parent calls this on the child to tell it who its
235 * parent is, giving the view access to things like
236 * the hosting Container. The superclass behavior is
237 * executed, followed by a call to createComponent if
238 * the parent view parameter is non-null and a component
239 * has not yet been created. The embedded components parent
240 * is then set to the value returned by <code>getContainer</code>.
241 * If the parent view parameter is null, this view is being
242 * cleaned up, thus the component is removed from its parent.
243 * <p>
244 * The changing of the component hierarchy will
245 * touch the component lock, which is the one thing
246 * that is not safe from the View hierarchy. Therefore,
247 * this functionality is executed immediately if on the
248 * event thread, or is queued on the event queue if
249 * called from another thread (notification of change
250 * from an asynchronous update).
251 *
252 * @param p the parent
253 */
254 public void setParent(View p) {
255 super.setParent(p);
256 if (SwingUtilities.isEventDispatchThread()) {
257 setComponentParent();
258 } else {
259 Runnable callSetComponentParent = new Runnable() {
260 public void run() {
421 if (!isValid()) {
422 validate();
423 }
424 }
425
426 private void cacheChildSizes() {
427 if (getComponentCount() > 0) {
428 Component child = getComponent(0);
429 min = child.getMinimumSize();
430 pref = child.getPreferredSize();
431 max = child.getMaximumSize();
432 yalign = child.getAlignmentY();
433 xalign = child.getAlignmentX();
434 } else {
435 min = pref = max = new Dimension(0, 0);
436 }
437 }
438
439 /**
440 * Shows or hides this component depending on the value of parameter
441 * <code>b</code>.
442 * @param b If <code>true</code>, shows this component;
443 * otherwise, hides this component.
444 * @see #isVisible
445 * @since 1.1
446 */
447 public void setVisible(boolean b) {
448 super.setVisible(b);
449 if (getComponentCount() > 0) {
450 getComponent(0).setVisible(b);
451 }
452 }
453
454 /**
455 * Overridden to fix 4759054. Must return true so that content
456 * is painted when inside a CellRendererPane which is normally
457 * invisible.
458 */
459 public boolean isShowing() {
460 return true;
461 }
462
|
23 * questions.
24 */
25 package javax.swing.text;
26
27 import java.awt.*;
28 import java.beans.PropertyChangeEvent;
29 import java.beans.PropertyChangeListener;
30 import java.util.Set;
31 import javax.swing.SwingUtilities;
32 import javax.swing.event.*;
33
34 /**
35 * Component decorator that implements the view interface. The
36 * entire element is used to represent the component. This acts
37 * as a gateway from the display-only View implementations to
38 * interactive lightweight components (ie it allows components
39 * to be embedded into the View hierarchy).
40 * <p>
41 * The component is placed relative to the text baseline
42 * according to the value returned by
43 * {@code Component.getAlignmentY}. For Swing components
44 * this value can be conveniently set using the method
45 * {@code JComponent.setAlignmentY}. For example, setting
46 * a value of {@code 0.75} will cause 75 percent of the
47 * component to be above the baseline, and 25 percent of the
48 * component to be below the baseline.
49 * <p>
50 * This class is implemented to do the extra work necessary to
51 * work properly in the presence of multiple threads (i.e. from
52 * asynchronous notification of model changes for example) by
53 * ensuring that all component access is done on the event thread.
54 * <p>
55 * The component used is determined by the return value of the
56 * createComponent method. The default implementation of this
57 * method is to return the component held as an attribute of
58 * the element (by calling StyleConstants.getComponent). A
59 * limitation of this behavior is that the component cannot
60 * be used by more than one text component (i.e. with a shared
61 * model). Subclasses can remove this constraint by implementing
62 * the createComponent to actually create a component based upon
63 * some kind of specification contained in the attributes. The
64 * ObjectView class in the html package is an example of a
65 * ComponentView implementation that supports multiple component
66 * views of a shared model.
220 public float getAlignment(int axis) {
221 if (c != null) {
222 switch (axis) {
223 case View.X_AXIS:
224 return c.getAlignmentX();
225 case View.Y_AXIS:
226 return c.getAlignmentY();
227 }
228 }
229 return super.getAlignment(axis);
230 }
231
232 /**
233 * Sets the parent for a child view.
234 * The parent calls this on the child to tell it who its
235 * parent is, giving the view access to things like
236 * the hosting Container. The superclass behavior is
237 * executed, followed by a call to createComponent if
238 * the parent view parameter is non-null and a component
239 * has not yet been created. The embedded components parent
240 * is then set to the value returned by {@code getContainer}.
241 * If the parent view parameter is null, this view is being
242 * cleaned up, thus the component is removed from its parent.
243 * <p>
244 * The changing of the component hierarchy will
245 * touch the component lock, which is the one thing
246 * that is not safe from the View hierarchy. Therefore,
247 * this functionality is executed immediately if on the
248 * event thread, or is queued on the event queue if
249 * called from another thread (notification of change
250 * from an asynchronous update).
251 *
252 * @param p the parent
253 */
254 public void setParent(View p) {
255 super.setParent(p);
256 if (SwingUtilities.isEventDispatchThread()) {
257 setComponentParent();
258 } else {
259 Runnable callSetComponentParent = new Runnable() {
260 public void run() {
421 if (!isValid()) {
422 validate();
423 }
424 }
425
426 private void cacheChildSizes() {
427 if (getComponentCount() > 0) {
428 Component child = getComponent(0);
429 min = child.getMinimumSize();
430 pref = child.getPreferredSize();
431 max = child.getMaximumSize();
432 yalign = child.getAlignmentY();
433 xalign = child.getAlignmentX();
434 } else {
435 min = pref = max = new Dimension(0, 0);
436 }
437 }
438
439 /**
440 * Shows or hides this component depending on the value of parameter
441 * {@code b}.
442 * @param b If {@code true}, shows this component;
443 * otherwise, hides this component.
444 * @see #isVisible
445 * @since 1.1
446 */
447 public void setVisible(boolean b) {
448 super.setVisible(b);
449 if (getComponentCount() > 0) {
450 getComponent(0).setVisible(b);
451 }
452 }
453
454 /**
455 * Overridden to fix 4759054. Must return true so that content
456 * is painted when inside a CellRendererPane which is normally
457 * invisible.
458 */
459 public boolean isShowing() {
460 return true;
461 }
462
|