# HG changeset patch
# Parent 36d9fb69458c63a2b56190598f75ee170e15a287
diff --git a/openide.awt/apichanges.xml b/openide.awt/apichanges.xml
--- a/openide.awt/apichanges.xml
+++ b/openide.awt/apichanges.xml
@@ -50,6 +50,23 @@
AWT API
+
+
+ Support "selected" icons in Actions and Actions.checkbox
+
+
+
+
+
+
+ Handle _selected, _rolloverSelected and _disabledSelected
+ icon resources in Actions.connect.
+ Actions.checkbox on a Toolbar uses them if they are available.
+
+
+
+
+ New @ActionReference annotations
diff --git a/openide.awt/manifest.mf b/openide.awt/manifest.mf
--- a/openide.awt/manifest.mf
+++ b/openide.awt/manifest.mf
@@ -2,5 +2,5 @@
OpenIDE-Module: org.openide.awt
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
AutoUpdate-Essential-Module: true
-OpenIDE-Module-Specification-Version: 7.30
+OpenIDE-Module-Specification-Version: 7.31
diff --git a/openide.awt/src/org/openide/awt/Actions.java b/openide.awt/src/org/openide/awt/Actions.java
--- a/openide.awt/src/org/openide/awt/Actions.java
+++ b/openide.awt/src/org/openide/awt/Actions.java
@@ -219,15 +219,21 @@
}
/** Connects buttons to action. If the action supplies value for "iconBase"
- * key from getValue(String) with a path to icons the methods setIcon,
- * setPressedIcon, setDisabledIcon and setRolloverIcon will be called on the
+ * key from getValue(String) with a path to icons, the methods set*Icon
+ * will be called on the
* button with loaded icons using the iconBase. E.g. if the value for "iconBase"
- * will be "com/mycompany/myIcon.gif" following images will be tried "com/mycompany/myIcon.gif"
- * for setIcon, "com/mycompany/myIcon_pressed.gif" for setPressedIcon,
- * "com/mycompany/myIcon_disabled.gif" for setDisabledIcon and
- * "com/mycompany/myIcon_rollover.gif" for setRolloverIcon. SystemAction has
- * special support for iconBase - please check {@link SystemAction#iconResource}
- * for more details.
+ * is "com/mycompany/myIcon.gif" then the following images are tried
+ *
+ *
setIcon with "com/mycompany/myIcon.gif"
+ *
setPressedIcon with "com/mycompany/myIcon_pressed.gif"
+ *
setDisabledIcon with "com/mycompany/myIcon_disabled.gif"
+ *
setRolloverIcon with "com/mycompany/myIcon_rollover.gif"
+ *
setSelectedIcon with "com/mycompany/myIcon_selected.gif"
+ *
setRolloverSelectedIcon with "com/mycompany/myIcon_rolloverSelected.gif"
+ *
setDisabledSelectedIcon with "com/mycompany/myIcon_disabledSelected.gif"
+ *
+ * SystemAction has special support for iconBase - please check
+ * {@link SystemAction#iconResource} for more details.
* You can supply an alternative implementation
* for this method by implementing method
* {@link ButtonActionConnector#connect(AbstractButton, Action)} and
@@ -236,6 +242,7 @@
* @param button the button
* @param action the action
* @since 3.29
+ * @since 7.31 for set*SelectedIcon
*/
public static void connect(AbstractButton button, Action action) {
for (ButtonActionConnector bac : buttonActionConnectors()) {
@@ -1025,6 +1032,21 @@
} else if (imgIcon != null) {
button.setDisabledIcon(ImageUtilities.createDisabledIcon(imgIcon));
}
+
+ ImageIcon sImgIcon = ImageUtilities.loadImageIcon(insertBeforeSuffix(b, "_selected"), true); // NOI18N
+ if (sImgIcon != null) {
+ button.setSelectedIcon(sImgIcon);
+ }
+
+ sImgIcon = ImageUtilities.loadImageIcon(insertBeforeSuffix(b, "_rolloverSelected"), true); // NOI18N
+ if (sImgIcon != null) {
+ button.setRolloverSelectedIcon(sImgIcon);
+ }
+
+ sImgIcon = ImageUtilities.loadImageIcon(insertBeforeSuffix(b, "_disabledSelected"), true); // NOI18N
+ if (sImgIcon != null) {
+ button.setDisabledSelectedIcon(sImgIcon);
+ }
}
}
diff --git a/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java b/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java
--- a/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java
+++ b/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java
@@ -17,16 +17,19 @@
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuItem;
+import javax.swing.JToggleButton;
import org.openide.util.ContextAwareAction;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.NbPreferences;
+import org.openide.util.WeakSet;
import org.openide.util.actions.Presenter;
import org.openide.util.actions.ActionInvoker;
@@ -256,7 +259,7 @@
}
static final class CheckBox extends AlwaysEnabledAction
- implements Presenter.Menu, Presenter.Popup, PreferenceChangeListener, LookupListener
+ implements Presenter.Menu, Presenter.Popup, Presenter.Toolbar, PreferenceChangeListener, LookupListener
{
private static final long serialVersionUID = 1L;
@@ -271,6 +274,8 @@
private JCheckBoxMenuItem popupItem;
+ private WeakSet toolbarItems;
+
private Preferences preferencesNode;
private Lookup.Result preferencesNodeResult;
@@ -311,6 +316,17 @@
return popupItem;
}
+ public AbstractButton getToolbarPresenter() {
+ if(toolbarItems == null) {
+ toolbarItems = new WeakSet(4);
+ }
+ AbstractButton b = new DefaultIconToggleButton();
+ toolbarItems.add(b);
+ b.setSelected(isPreferencesSelected());
+ Actions.connect(b, this);
+ return b;
+ }
+
public void preferenceChange(PreferenceChangeEvent pce) {
updateItemsSelected();
}
@@ -351,6 +367,11 @@
if (popupItem != null) {
popupItem.setSelected(selected);
}
+ if (toolbarItems != null) {
+ for(AbstractButton b : toolbarItems) {
+ b.setSelected(selected);
+ }
+ }
}
private synchronized Preferences prefs() {
@@ -423,4 +444,24 @@
}
+ /**
+ * A button that provides a default icon when no text and no custom icon have been set.
+ * Copied from Toolbar.java and made a toggle button.
+ */
+ private static class DefaultIconToggleButton extends JToggleButton {
+ private Icon unknownIcon;
+
+ @Override
+ public Icon getIcon() {
+ Icon retValue = super.getIcon();
+ if( null == retValue && (null == getText() || getText().isEmpty()) ) {
+ if (unknownIcon == null) {
+ unknownIcon = ImageUtilities.loadImageIcon("org/openide/loaders/unknown.gif", false); //NOI18N
+ }
+ retValue = unknownIcon;
+ }
+ return retValue;
+ }
+ }
+
}