# HG changeset patch # User ramis@netbeans.org # Date 1340238100 -7200 # Node ID bd7f8ebfd7e40a2de7bef1f43b2d8b6ca3d5d678 # Parent f1de2b55825dc5e83825a5f17311630ea8d3f386 [mq]: 208081.diff diff --git a/openide.awt/arch.xml b/openide.awt/arch.xml --- a/openide.awt/arch.xml +++ b/openide.awt/arch.xml @@ -478,6 +478,16 @@ of this key include default, never or always. +
  • + + There is a way to enable icons in popup menu items created via + Actions factory methods + in your own application build on top of NetBeans Platform. + Just provide branding for org/openide/awt/Bundle.properties + file and modify ICONS_IN_POPUP=always. Other possible values + of this key include default, never or always. + +
  • 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 @@ -1195,6 +1195,7 @@ private static class MenuBridge extends ButtonBridge { /** behave like menu or popup */ private boolean popup; + private final boolean showIconInPopup = showIconsInPopup(); /** Constructor. * @param popup pop-up menu @@ -1213,6 +1214,18 @@ } } + private boolean showIconsInPopup() { + String msg = NbBundle.getMessage(Actions.class, "ICONS_IN_POPUP"); // NOI18N + if ("always".equals(msg)) { // NOI18N + return true; + } else if ("never".equals(msg)) { // NOI18N + return false; + } else { + assert "default".equals(msg); // NOI18N + return false; + } + } + protected @Override void prepare() { if (popup) { // popups generally get no hierarchy events, yet we need to listen to other changes @@ -1238,7 +1251,7 @@ updateKey((JMenuItem) comp, action); } - if (!popup) { + if (!popup || showIconInPopup) { if ( (changedProperty == null) || changedProperty.equals(SystemAction.PROP_ICON) || changedProperty.equals(Action.SMALL_ICON) || changedProperty.equals("iconBase") diff --git a/openide.awt/src/org/openide/awt/Bundle.properties b/openide.awt/src/org/openide/awt/Bundle.properties --- a/openide.awt/src/org/openide/awt/Bundle.properties +++ b/openide.awt/src/org/openide/awt/Bundle.properties @@ -125,3 +125,4 @@ # either: default, never or always #NOI18N USE_MNEMONICS=default +ICONS_IN_POPUP=default diff --git a/openide.awt/test/unit/src/org/openide/awt/ActionsTest.java b/openide.awt/test/unit/src/org/openide/awt/ActionsTest.java --- a/openide.awt/test/unit/src/org/openide/awt/ActionsTest.java +++ b/openide.awt/test/unit/src/org/openide/awt/ActionsTest.java @@ -49,6 +49,7 @@ import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; +import java.util.Locale; import javax.swing.AbstractAction; import javax.swing.AbstractButton; import javax.swing.Action; @@ -306,6 +307,31 @@ } /** + * #208081 + */ + public void testIconInPopup() { + Locale.setDefault(new Locale("ic", "ON")); + Action action = new TestAction(); + JMenuItem menuItem = new JMenuItem(); + Actions.connect(menuItem, action, true); + Icon icon = menuItem.getIcon(); + assertNotNull(icon); + checkIfLoadedCorrectIcon(icon, menuItem, 0, "Enabled icon"); + } + + /** + * #208081 + */ + public void testNoIconInPopup() { + Locale.setDefault(new Locale("ic", "OF")); + Action action = new TestAction(); + JMenuItem menuItem = new JMenuItem(); + Actions.connect(menuItem, action, true); + Icon icon = menuItem.getIcon(); + assertNull(icon); + } + + /** * Test whether pressed, rollover and disabled 24x24 icons * work for SystemAction. */ diff --git a/openide.awt/test/unit/src/org/openide/awt/Bundle_ic_OF.properties b/openide.awt/test/unit/src/org/openide/awt/Bundle_ic_OF.properties new file mode 100644 --- /dev/null +++ b/openide.awt/test/unit/src/org/openide/awt/Bundle_ic_OF.properties @@ -0,0 +1,41 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2011 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +# +# Contributor(s): +# +# Portions Copyrighted 2011 Sun Microsystems, Inc. + +ICONS_IN_POPUP=never \ No newline at end of file diff --git a/openide.awt/test/unit/src/org/openide/awt/Bundle_ic_ON.properties b/openide.awt/test/unit/src/org/openide/awt/Bundle_ic_ON.properties new file mode 100644 --- /dev/null +++ b/openide.awt/test/unit/src/org/openide/awt/Bundle_ic_ON.properties @@ -0,0 +1,41 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2011 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +# +# Contributor(s): +# +# Portions Copyrighted 2011 Sun Microsystems, Inc. + +ICONS_IN_POPUP=always \ No newline at end of file