}
public void performAction() {
// TF:21/11/07: Refactored and commented this method for readability
JButton newDefaultButton = (JButton)this._component;
JRootPane rootPane = newDefaultButton.getRootPane();
if (rootPane == null) {
// If the button is not parented onto a Window, we cannot set the default button.
return;
}
// Get the button that used to be the default button
JButton oldDefaultButton = rootPane.getDefaultButton();
if (this.setAsDefault) {
if (oldDefaultButton == newDefaultButton) {
// We're just resetting the default button to the same thing, do nothing.
return;
}
// Make this button the default button
newDefaultButton.setDefaultCapable(true);
rootPane.setDefaultButton(newDefaultButton);
// Set the old button not as the default if applicable
if (oldDefaultButton != null) {
oldDefaultButton.setDefaultCapable(false);
}
}
else {
// See if we're the default button
if (oldDefaultButton == newDefaultButton) {
rootPane.setDefaultButton(null);
}
// DK:11/11/2008: reset the default button as far as we do not want the button to be default any more.
JButton initialDefault = (JButton)rootPane.getClientProperty("initialDefaultButton");
if (newDefaultButton == initialDefault) {
rootPane.putClientProperty("initialDefaultButton", null);
}
newDefaultButton.setDefaultCapable(false);
}
}