import java.awt.Component; //导入方法依赖的package包/类
/** Installs the component we will embed to display the property */
private void installDisplayerComponent() {
//Fetch or instantiate the component we will embed to display the
//property. Depending on the prefs, it may be a RendererPropertyDisplayer,
//an EditablePropertyDisplayer or a CustomPropertyDisplayer.
PropertyDisplayer displayer = getPropertyDisplayer();
//Find who has focus now, so if we have focus, focus won't end up set
//to null
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
boolean hadFocus = (focusOwner == this) || isAncestorOf(focusOwner);
if (hadFocus) {
//If we had focus, clear the global focus owner for now, so that
//when the existing component is removed, it does not cause
//focus to get briefly set to a random component
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
}
//Fetch the new inner component (the custom editor or Inplace editor)
Component newInner = displayer.getComponent();
//Set the enabled state appropriately. For implementations of
//PropertyDisplayer_Editable, this will already be handled; for render-
//only cases, it should be handled explicitly
if (!(displayer instanceof PropertyDisplayer_Editable)) {
//only for renderers
newInner.setEnabled(isEnabled() && getProperty().canWrite());
}
newInner.setForeground(getForeground());
newInner.setBackground(getBackground());
//Make sure the inner component has really changed
if (newInner != inner) {
synchronized (getTreeLock()) {
//remove the odl component
if (inner != null) {
remove(inner);
}
//and add the new one (if any)
if (newInner != null) {
add(newInner);
//invalidate its layout so it will be re-laid out
newInner.invalidate();
inner = newInner;
}
}
}
//Force a re-layout immediately if visible
if (isShowing() && !(getParent() instanceof javax.swing.CellRendererPane)) {
validate();
}
//Restore focus if necessary
if (hadFocus && isEnabled() && ((preferences & PREF_READ_ONLY) == 0)) {
requestFocus();
}
//Simply adding a component to a container can sometimes cause it to be
//given focus even though it's not focusable. If this has happened,
//find the next component in the focus cycle root and force focus to that.
//Mainly a problem with JFileChooser, but we also have a few property
//editors that force focus on addNotify which should be fixed
if (!isEnabled() || ((preferences & PREF_READ_ONLY) != 0)) {
Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if ((focus == inner) || ((inner instanceof Container) && ((Container) inner).isAncestorOf(focus))) {
this.transferFocusUpCycle();
}
}
}