below I've a sub class of JideSplitButton with the following changes:
1) Use Action.LARGE_ICON_KEY when available since (I think) the split button is more a button than a menu (which uses small icon always)
2) Added support for a SPLIT_BUTTON_ENABLED action property
I think the first is OK to be committed to common JideSplitButton, as I don't think someone would use it in a menu (preferring a small icon)?
The second is a bit incomplete as there is also a setButtonSelected() but that is more a view property (whether the button or the menu part is selected) I think?
- Code: Select all
public class CustomJideSplitButton extends JideSplitButton {
public static final String SPLIT_BUTTON_ENABLED = "JideSplitButtonEnabled";
public CustomJideSplitButton(Action action) {
super(action);
}
@Override
protected void configurePropertiesFromAction(Action action) {
super.configurePropertiesFromAction(action);
setButtonEnabled(isSplitButtonEnabled(action));
doSetIconFromAction(action);
}
protected void doSetIconFromAction(Action action) {
// setIconFromAction is package private in AbstractButton
Icon icon = null;
if (action != null) {
icon = (Icon) action.getValue(Action.LARGE_ICON_KEY);
if (icon == null) {
icon = (Icon) action.getValue(Action.SMALL_ICON);
}
}
setIcon(icon);
}
@Override
protected void actionPropertyChanged(Action action, String propertyName) {
super.actionPropertyChanged(action, propertyName);
if(SPLIT_BUTTON_ENABLED.equals(propertyName)) {
setButtonEnabled(isSplitButtonEnabled(action));
}
else if (propertyName == Action.SMALL_ICON) {
// smallIconChanged is package private in AbstractButton
if(action.getValue(Action.LARGE_ICON_KEY) == null) {
doSetIconFromAction(action);
}
}
else if (propertyName == Action.LARGE_ICON_KEY) {
// largeIconChanged is package private in AbstractButton
doSetIconFromAction(action);
}
}
public static boolean isSplitButtonEnabled(Action action) {
if(action == null) {
return false;
}
else {
Object value = action.getValue(SPLIT_BUTTON_ENABLED);
if(value instanceof Boolean) {
return ((Boolean) value).booleanValue();
}
else {
return action.isEnabled();
}
}
}
}