diff -r 428419c1ab32 -r af0aefefe222 apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/resources/layer.xml Tue Jul 08 17:28:31 2008 +0200 @@ -185,6 +185,7 @@ made subject to such option by the copyr + diff -r 428419c1ab32 -r af0aefefe222 apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/DataModel.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/DataModel.java Tue Jun 17 13:36:09 2008 -0700 +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/DataModel.java Tue Jul 08 17:28:31 2008 +0200 @@ -41,6 +41,9 @@ package org.netbeans.modules.apisupport.project.ui.wizard.action; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -48,10 +51,14 @@ import java.util.Map; import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.logging.Level; +import java.util.logging.Logger; import org.netbeans.modules.apisupport.project.CreatedModifiedFiles; import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator; import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; +import org.openide.modules.SpecificationVersion; +import org.openide.util.Exceptions; /** * Data model used across the New Action Wizard. @@ -145,10 +152,27 @@ final class DataModel extends BasicWizar String shadow = dashedFqClassName + ".shadow"; // NOI18N cmf = new CreatedModifiedFiles(getProject()); + + boolean actionProxy; + try { + SpecificationVersion current = getModuleInfo().getDependencyVersion("org.openide.awt"); + actionProxy = current.compareTo(new SpecificationVersion("7.3")) >= 0; // NOI18N + } catch (IOException ex) { + Logger.getLogger(DataModel.class.getName()).log(Level.INFO, null, ex); + actionProxy = false; + } String actionPath = getDefaultPackagePath(className + ".java", false); // NOI18N // XXX use nbresloc URL protocol rather than DataModel.class.getResource(...): - FileObject template = CreatedModifiedFiles.getTemplate(alwaysEnabled ? "callableSystemAction.java" : "cookieAction.java"); // NOI18N + FileObject template = CreatedModifiedFiles.getTemplate( + alwaysEnabled ? ( + actionProxy ? + "actionListener.java" + : + "callableSystemAction.java" + ): + "cookieAction.java" + ); // NOI18N assert template != null; String actionNameKey = "CTL_" + className; // NOI18N Map replaceTokens = new HashMap(); @@ -196,8 +220,9 @@ final class DataModel extends BasicWizar cmf.add(cmf.bundleKey(getDefaultPackagePath("Bundle.properties", true), actionNameKey, displayName)); // NOI18N // Copy action icon + String relativeIconPath = null; if (origIconPath != null) { - String relativeIconPath = addCreateIconOperation(cmf, origIconPath); + relativeIconPath = addCreateIconOperation(cmf, origIconPath); replaceTokens.put("ICON_RESOURCE_METHOD", DataModel.generateIconResourceMethod(relativeIconPath)); // NOI18N replaceTokens.put("INITIALIZE_METHOD", ""); // NOI18N } else { @@ -212,7 +237,30 @@ final class DataModel extends BasicWizar // add layer entry about the action String instanceFullPath = category + "/" // NOI18N + dashedFqClassName + ".instance"; // NOI18N - cmf.add(cmf.createLayerEntry(instanceFullPath, null, null, null, null)); + if (!alwaysEnabled || !actionProxy) { + cmf.add(cmf.createLayerEntry(instanceFullPath, null, null, null, null)); + } else { + Map attrs = new HashMap(); + attrs.put("instanceCreate", "methodvalue:org.openide.awt.Actions.alwaysEnabled"); // NOI18N + attrs.put("delegate", "newvalue:" + getPackageName() + '.' + className); // NOI18N + attrs.put("noIconInMenu", "false"); // NOI18N + if (relativeIconPath != null) { + try { + attrs.put("SystemFileSystem.icon", new URL("nbresloc://" + relativeIconPath)); // NOI18N + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } + } + cmf.add( + cmf.createLayerEntry( + instanceFullPath, + null, + null, + displayName, + attrs + ) + ); + } // add dependency on util to project.xml cmf.add(cmf.addModuleDependency("org.openide.util")); // NOI18N diff -r 428419c1ab32 -r af0aefefe222 apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/actionListener.javx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/action/actionListener.javx Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,15 @@ +<#assign licenseFirst = "/*"> +<#assign licensePrefix = " * "> +<#assign licenseLast = " */"> +<#include "../Licenses/license-${project.license}.txt"> + +package ${PACKAGE_NAME}; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public final class ${CLASS_NAME} implements ActionListener { + public void actionPerformed(ActionEvent e) { + // TODO implement action body + } +} diff -r 428419c1ab32 -r af0aefefe222 apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java --- a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java Tue Jun 17 13:36:09 2008 -0700 +++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/NewTCIterator.java Tue Jul 08 17:28:31 2008 +0200 @@ -43,10 +43,14 @@ package org.netbeans.modules.apisupport. import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import org.netbeans.api.project.Project; import org.netbeans.modules.apisupport.project.CreatedModifiedFiles; import org.netbeans.modules.apisupport.project.Util; @@ -56,6 +60,8 @@ import org.openide.filesystems.FileObjec import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; +import org.openide.modules.SpecificationVersion; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; /** @@ -170,6 +176,16 @@ final class NewTCIterator extends BasicW final String name = model.getName(); final String packageName = model.getPackageName(); final String mode = model.getMode(); + + boolean actionLessTC; + try { + SpecificationVersion current = model.getModuleInfo().getDependencyVersion("org.openide.windows"); + actionLessTC = current.compareTo(new SpecificationVersion("6.24")) >= 0; // NOI18N + } catch (IOException ex) { + Logger.getLogger(NewTCIterator.class.getName()).log(Level.INFO, null, ex); + actionLessTC = false; + } + Map replaceTokens = new HashMap(); replaceTokens.put("TEMPLATENAME", name);//NOI18N @@ -189,9 +205,9 @@ final class NewTCIterator extends BasicW fil = null; } } + String relativeIconPath = null; if (fil != null) { FileObject fo = FileUtil.toFileObject(fil); - String relativeIconPath = null; if (!FileUtil.isParentOf(Util.getResourceDirectory(project), fo)) { String iconPath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, "", fo.getNameExt()); //NOI18N @@ -228,11 +244,13 @@ final class NewTCIterator extends BasicW name, "TopComponent.form"); //NOI18N template = CreatedModifiedFiles.getTemplate("templateTopComponent.form");//NOI18N fileChanges.add(fileChanges.createFileWithSubstitutions(tcFormName, template, replaceTokens)); - - final String actionName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, - name, "Action.java"); //NOI18N - template = CreatedModifiedFiles.getTemplate("templateAction.java");//NOI18N - fileChanges.add(fileChanges.createFileWithSubstitutions(actionName, template, replaceTokens)); + + if (!actionLessTC) { + final String actionName = getRelativePath(moduleInfo.getSourceDirectoryPath(), packageName, + name, "Action.java"); //NOI18N + template = CreatedModifiedFiles.getTemplate("templateAction.java");//NOI18N + fileChanges.add(fileChanges.createFileWithSubstitutions(actionName, template, replaceTokens)); + } final String settingsName = name + "TopComponent.settings"; //NOI18N template = CreatedModifiedFiles.getTemplate("templateSettings.xml");//NOI18N @@ -242,10 +260,49 @@ final class NewTCIterator extends BasicW template = CreatedModifiedFiles.getTemplate("templateWstcref.xml");//NOI18N fileChanges.add(fileChanges.createLayerEntry("Windows2/Modes/" + mode + "/" + wstcrefName, // NOI18N template, replaceTokens, null, null)); - - fileChanges.add(fileChanges.layerModifications(new CreateActionEntryOperation(name + "Action", packageName), // NOI18N + + String bundlePath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, "", "Bundle.properties"); //NOI18N + if (actionLessTC) { + String path = "Actions/Window/" + packageName.replace('.','-') + "-" + name + "Action.instance"; // NOI18N + { + Map attrs = new HashMap(); + attrs.put("instanceCreate", "methodvalue:org.openide.windows.TopComponent.openAction"); // NOI18N + attrs.put("component", "methodvalue:" + packageName + '.' + name + "TopComponent.findInstance"); // NOI18N + if (relativeIconPath != null) { + try { + attrs.put("SystemFileSystem.icon", new URL("nbresloc://" + relativeIconPath)); // NOI18N + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } + } + fileChanges.add( + fileChanges.createLayerEntry( + path, + null, + null, + NbBundle.getMessage(NewTCIterator.class, "LBL_TemplateActionName", name), // NOI18N + attrs + ) + ); + } + + { + Map attrs = new HashMap(); + attrs.put("originalFile", path); // NOI18N + fileChanges.add( + fileChanges.createLayerEntry( + "Menu/Window/" + name + "Action.shadow", // NOI18N + null, + null, + null, + attrs + ) + ); + } + } else { + fileChanges.add(fileChanges.layerModifications(new CreateActionEntryOperation(name + "Action", packageName), // NOI18N Collections.emptySet())); - String bundlePath = getRelativePath(moduleInfo.getResourceDirectoryPath(false), packageName, "", "Bundle.properties"); //NOI18N + } fileChanges.add(fileChanges.bundleKey(bundlePath, "CTL_" + name + "Action", // NOI18N NbBundle.getMessage(NewTCIterator.class, "LBL_TemplateActionName", name))); //NOI18N diff -r 428419c1ab32 -r af0aefefe222 core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java --- a/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java Tue Jun 17 13:36:09 2008 -0700 +++ b/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java Tue Jul 08 17:28:31 2008 +0200 @@ -41,6 +41,7 @@ package org.netbeans.core.startup.layers; +import java.beans.BeanInfo; import java.beans.PropertyVetoException; import java.io.ByteArrayInputStream; import java.io.File; @@ -75,6 +76,7 @@ import org.openide.filesystems.FileChang import org.openide.filesystems.FileChangeListener; import org.openide.filesystems.FileLock; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileSystem; import org.openide.util.Enumerations; import org.openide.util.Exceptions; @@ -878,7 +880,19 @@ public class BinaryFS extends FileSystem } public Object get(String key) { - return fo.getAttribute(key); + Object ret = fo.getAttribute(key); + if (ret != null) { + return ret; + } + if ("displayName".equals(key)) { // NOI18N + try { + // NOI18N + return fo.getFileSystem().getStatus().annotateName(fo.getNameExt(), Collections.singleton(fo)); + } catch (FileStateInvalidException ex) { + Exceptions.printStackTrace(ex); + } + } + return null; } public Object remove(Object key) { @@ -899,13 +913,17 @@ public class BinaryFS extends FileSystem public Iterator> iterator() { class Iter implements Iterator> { + int fixed; Enumeration attrs = fo.getAttributes(); public boolean hasNext() { - return attrs.hasMoreElements(); + return fixed < 2 || attrs.hasMoreElements(); } public Map.Entry next() { + if (fixed < 2) { + return new LocEntry(fo, fixed++); + } String s = attrs.nextElement(); return new FOEntry(fo, s); } @@ -953,4 +971,30 @@ public class BinaryFS extends FileSystem throw new UnsupportedOperationException(); } } // end of FOEntry + private static final class LocEntry implements Map.Entry { + private FileObject fo; + private int type; + + private LocEntry(FileObject fo, int cnt) { + this.fo = fo; + this.type = cnt; + } + + public String getKey() { + return type == 0 ? "displayName" : "image"; // NOI18N + } + + public Object getValue() { + switch (type) { + case 0: return SystemFileSystem.annotateName(fo); + case 1: return SystemFileSystem.annotateIcon(fo, BeanInfo.ICON_COLOR_16x16); + default: return null; + } + } + + + public Object setValue(Object value) { + throw new UnsupportedOperationException(); + } + } // end of FOEntry } diff -r 428419c1ab32 -r af0aefefe222 core.startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java --- a/core.startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java Tue Jun 17 13:36:09 2008 -0700 +++ b/core.startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java Tue Jul 08 17:28:31 2008 +0200 @@ -185,6 +185,28 @@ implements FileSystem.Status { public FileSystem.Status getStatus () { return this; } + + static final String annotateName(FileObject fo) { + + String bundleName = (String) fo.getAttribute(ATTR_BUNDLE); // NOI18N + if (bundleName != null) { + try { + bundleName = org.openide.util.Utilities.translate(bundleName); + ResourceBundle b = NbBundle.getBundle(bundleName); + try { + return b.getString(fo.getPath()); + } catch (MissingResourceException ex) { + // ignore--normal + } + } catch (MissingResourceException ex) { + ModuleLayeredFileSystem.err.log( + Level.WARNING, + "Computing display name for " + fo, ex); // NOI18N + // ignore + } + } + return null; + } /** Annotate name */ @@ -197,35 +219,18 @@ implements FileSystem.Status { while (it.hasNext ()) { // annotate a name FileObject fo = (FileObject) it.next (); - - String bundleName = (String)fo.getAttribute (ATTR_BUNDLE); // NOI18N - if (bundleName != null) { - try { - bundleName = org.openide.util.Utilities.translate(bundleName); - ResourceBundle b = NbBundle.getBundle(bundleName); - try { - return b.getString (fo.getPath()); - } catch (MissingResourceException ex) { - // ignore--normal - } - } catch (MissingResourceException ex) { - ModuleLayeredFileSystem.err.log( - Level.WARNING, - "Computing display name for " + fo, ex); // NOI18N - // ignore - } + String displayName = annotateName(fo); + if (displayName != null) { + return displayName; } - String fixedName = FixedFileSystem.deflt.annotateName(fo.getPath()); if (fixedName != null) return fixedName; } return s; } - - /** Annotate icon - */ - public Image annotateIcon (Image im, int type, Set s) { + + static Image annotateIcon(FileObject fo, int type) { String attr; if (type == BeanInfo.ICON_COLOR_16x16) { attr = ATTR_ICON_16; @@ -233,21 +238,31 @@ implements FileSystem.Status { attr = ATTR_ICON_32; } else { // mono icons not supported - return im; + return null; } + Object value = fo.getAttribute(attr); + if (value != null) { + if (value instanceof URL) { + return Toolkit.getDefaultToolkit().getImage((URL) value); + } else if (value instanceof Image) { + // #18832 + return (Image) value; + } else { + ModuleLayeredFileSystem.err.warning("Attribute " + attr + " on " + fo + " expected to be a URL or Image; was: " + value); + } + } + return null; + } + + /** Annotate icon + */ + public Image annotateIcon (Image im, int type, Set s) { Iterator it = s.iterator (); while (it.hasNext ()) { FileObject fo = (FileObject) it.next (); - Object value = fo.getAttribute (attr); - if (value != null) { - if (value instanceof URL) { - return Toolkit.getDefaultToolkit ().getImage ((URL) value); - } else if (value instanceof Image) { - // #18832 - return (Image)value; - } else { - ModuleLayeredFileSystem.err.warning("Attribute " + attr + " on " + fo + " expected to be a URL or Image; was: " + value); - } + Image img = annotateIcon(fo, type); + if (img != null) { + return img; } Image anntIm = FixedFileSystem.deflt.annotateIcon(fo.getPath()); if (anntIm != null) { diff -r 428419c1ab32 -r af0aefefe222 core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java --- a/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java Tue Jun 17 13:36:09 2008 -0700 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java Tue Jul 08 17:28:31 2008 +0200 @@ -41,6 +41,8 @@ package org.netbeans.core.startup.layers; +import java.awt.Image; +import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -51,11 +53,13 @@ import org.openide.filesystems.FileObjec import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.MultiFileSystem; +import org.openide.util.ImageUtilities; /** Test layer cache managers generally. * @author Jesse Glick */ public abstract class CacheManagerTestBaseHid extends NbTestCase { private long initTime = System.currentTimeMillis (); + private static Image icon; /** * Called from layer, do not rename! @@ -65,11 +69,23 @@ public abstract class CacheManagerTestBa return String.valueOf(fo.getAttribute("x")) + "/" + attr; } + public static Image icon() { + assertNull("Called just once", icon); + icon = new BufferedImage(133, 133, BufferedImage.TYPE_INT_ARGB); + return icon; + } + public static Object map1(Map map) { return String.valueOf(map.get("x")); } public static Object map2(Map map, String attr) { return String.valueOf(map.get("x")) + "/" + attr; + } + public static Object mapImage(Map map) { + return map.get("image"); + } + public static Object mapDisplayName(Map map) { + return map.get("displayName"); } protected CacheManagerTestBaseHid(String name) { @@ -143,6 +159,10 @@ public abstract class CacheManagerTestBa assertEquals("val/a", attr(mfs, "foo/29356", "a")); assertEquals("val", attr(mfs, "foo/29356", "map1")); assertEquals("val/map2", attr(mfs, "foo/29356", "map2")); + assertEquals("Ahoj", attr(mfs, "foo/29356", "mapDisplayName")); + Image read = (Image) attr(mfs, "foo/29356", "mapImage"); + assertNotNull("Image loaded", icon); + assertEquals("Same image", icon, read); } private static String slurp(FileSystem f, String path) throws IOException { diff -r 428419c1ab32 -r af0aefefe222 core.startup/test/unit/src/org/netbeans/core/startup/layers/TestBundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/TestBundle.properties Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,38 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# +# 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. Sun designates this +# particular file as subject to the "Classpath" exception as provided +# by Sun 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 2008 Sun Microsystems, Inc. + +foo/29356=Ahoj diff -r 428419c1ab32 -r af0aefefe222 core.startup/test/unit/src/org/netbeans/core/startup/layers/data/layer1.xml --- a/core.startup/test/unit/src/org/netbeans/core/startup/layers/data/layer1.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/data/layer1.xml Tue Jul 08 17:28:31 2008 +0200 @@ -12,6 +12,10 @@ + + + + diff -r 428419c1ab32 -r af0aefefe222 core.ui/nbproject/project.xml --- a/core.ui/nbproject/project.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/core.ui/nbproject/project.xml Tue Jul 08 17:28:31 2008 +0200 @@ -86,7 +86,7 @@ made subject to such option by the copyr - 6.8 + 7.3 diff -r 428419c1ab32 -r af0aefefe222 core.ui/src/org/netbeans/core/ui/resources/layer.xml --- a/core.ui/src/org/netbeans/core/ui/resources/layer.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/core.ui/src/org/netbeans/core/ui/resources/layer.xml Tue Jul 08 17:28:31 2008 +0200 @@ -102,7 +102,12 @@ made subject to such option by the copyr - + + + + + + diff -r 428419c1ab32 -r af0aefefe222 java.hints.analyzer/nbproject/project.xml --- a/java.hints.analyzer/nbproject/project.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/java.hints.analyzer/nbproject/project.xml Tue Jul 08 17:28:31 2008 +0200 @@ -160,7 +160,7 @@ - 6.16 + 6.23 diff -r 428419c1ab32 -r af0aefefe222 java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/layer.xml --- a/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/layer.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/layer.xml Tue Jul 08 17:28:31 2008 +0200 @@ -47,7 +47,11 @@ made subject to such option by the copyr - + + + + + diff -r 428419c1ab32 -r af0aefefe222 java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/ui/AnalyzerAction.java --- a/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/ui/AnalyzerAction.java Tue Jun 17 13:36:09 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. - * - * 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. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun 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 2008 Sun Microsystems, Inc. - */ -package org.netbeans.modules.java.hints.analyzer.ui; - -import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; -import org.openide.util.NbBundle; -import org.openide.windows.TopComponent; - -/** - * Action which shows Analyzer component. - */ -public class AnalyzerAction extends AbstractAction { - public AnalyzerAction() { - super(NbBundle.getMessage(AnalyzerAction.class, "CTL_AnalyzerAction")); -// putValue(SMALL_ICON, new ImageIcon(Utilities.loadImage(AnalyzerTopComponent.ICON_PATH, true))); - } - - public void actionPerformed(ActionEvent evt) { - TopComponent win = AnalyzerTopComponent.findInstance(); - win.open(); - win.requestActive(); - } -} diff -r 428419c1ab32 -r af0aefefe222 java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/ui/Bundle.properties --- a/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/ui/Bundle.properties Tue Jun 17 13:36:09 2008 -0700 +++ b/java.hints.analyzer/src/org/netbeans/modules/java/hints/analyzer/ui/Bundle.properties Tue Jul 08 17:28:31 2008 +0200 @@ -38,6 +38,8 @@ # made subject to such option by the copyright holder. CTL_AnalyzerAction=&Analyzer +Actions/Window/org-netbeans-modules-java-hints-analyzer-ui-AnalyzerAction.instance=&Analyzer + CTL_AnalyzerTopComponent=Analyzer Window CTL_TaskListAction=Task List CTL_TaskListTopComponent=Task List diff -r 428419c1ab32 -r af0aefefe222 o.n.core/src/org/netbeans/core/actions/Bundle.properties --- a/o.n.core/src/org/netbeans/core/actions/Bundle.properties Tue Jun 17 13:36:09 2008 -0700 +++ b/o.n.core/src/org/netbeans/core/actions/Bundle.properties Tue Jul 08 17:28:31 2008 +0200 @@ -82,4 +82,5 @@ JumpPrevAction=&Previous Error #LogAction MSG_LogTab_name=IDE &Log File +Actions/View/org-netbeans-core-actions-LogAction.instance=IDE &Log File MSG_ShortLogTab_name=IDE Log File diff -r 428419c1ab32 -r af0aefefe222 openide.awt/nbproject/project.properties --- a/openide.awt/nbproject/project.properties Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.awt/nbproject/project.properties Tue Jul 08 17:28:31 2008 +0200 @@ -46,4 +46,4 @@ javadoc.arch=${basedir}/arch.xml #javadoc.apichanges=${basedir}/api/apichanges.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=7.2.0 +spec.version.base=7.3.0 diff -r 428419c1ab32 -r af0aefefe222 openide.awt/nbproject/project.xml --- a/openide.awt/nbproject/project.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.awt/nbproject/project.xml Tue Jul 08 17:28:31 2008 +0200 @@ -55,6 +55,15 @@ made subject to such option by the copyr + + + unit + + org.openide.filesystems + + + + org.openide.awt diff -r 428419c1ab32 -r af0aefefe222 openide.awt/src/org/openide/awt/Actions.java --- a/openide.awt/src/org/openide/awt/Actions.java Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.awt/src/org/openide/awt/Actions.java Tue Jul 08 17:28:31 2008 +0200 @@ -66,6 +66,7 @@ import org.openide.util.Utilities; import org.openide.util.Utilities; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; @@ -379,7 +380,49 @@ public class Actions extends Object { return result; } + + // + // Factories + // + + /** Creates new action which is always enabled. + * This method can also be used from + * XML Layer + * directly by following XML definition: + *
+     * <file name="your-pkg-action-id.instance">
+     *   <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
+     *   <attr name="delegate" methodvalue="your.pkg.YourAction.factoryMethod"/>
+     *   <attr name="SystemFileSystem.icon" stringvalue="your/pkg/YourComponent.png"/>
+     *   <attr name="SystemFileSystem.localizingBundle" stringvalue="your.pkg.Bundle"/>
+     *   <attr name="noIconInMenu" boolvalue="false"/>
+     * </file>
+     * 
+ * + * + * @param delegate the task to perform when action is invoked + * @param displayName the name of the action + * @param iconBase the location to the actions icon + * @param noIconInMenu true if this icon shall not have an item in menu + * @since 7.3 + */ + public static Action alwaysEnabled( + ActionListener delegate, String displayName, String iconBase, boolean noIconInMenu + ) { + HashMap map = new HashMap(); + map.put("delegate", delegate); // NOI18N + map.put("displayName", displayName); // NOI18N + map.put("iconBase", iconBase); // NOI18N + map.put("noIconInMenu", noIconInMenu); // NOI18N + return alwaysEnabled(map); + } + // for use from layers + static Action alwaysEnabled(Map map) { + return new AlwaysEnabledAction(map); + } + + /** Extracts help from action. */ private static HelpCtx findHelp(Action a) { diff -r 428419c1ab32 -r af0aefefe222 openide.awt/src/org/openide/awt/AlwaysEnabledAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.awt/src/org/openide/awt/AlwaysEnabledAction.java Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,100 @@ +package org.openide.awt; + +import java.awt.EventQueue; +import java.awt.Image; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.URL; +import java.util.Map; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.KeyStroke; +import javax.swing.text.Keymap; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; + +/** Lazily initialized always enabled action + * + * @author Jaroslav Tulach + */ +final class AlwaysEnabledAction extends AbstractAction { + + private Map map; + + public AlwaysEnabledAction(Map m) { + super(); + this.map = m; + } + + @Override + public boolean isEnabled() { + assert EventQueue.isDispatchThread(); + return true; + } + + public void actionPerformed(ActionEvent e) { + assert EventQueue.isDispatchThread(); + Object listener = map.get("delegate"); + if (!(listener instanceof ActionListener)) { + throw new NullPointerException(); + } + ((ActionListener) listener).actionPerformed(e); + } + + @Override + public Object getValue(String name) { + return extractCommonAttribute(map, this, name); + } + + static final Object extractCommonAttribute(Map fo, Action action, String name) { + if (Action.NAME.equals(name)) { + String actionName = (String) fo.get("displayName"); // NOI18N + // NOI18N + //return Actions.cutAmpersand(actionName); + return actionName; + } + if (Action.MNEMONIC_KEY.equals(name)) { + String actionName = (String) fo.get("displayName"); // NOI18N + // NOI18N + int position = Mnemonics.findMnemonicAmpersand(actionName); + + return position == -1 ? null : Character.valueOf(actionName.charAt(position + 1)); + } + if (Action.SMALL_ICON.equals(name)) { + Object icon = fo == null ? null : fo.get("iconBase"); // NOI18N + if (icon instanceof Icon) { + return (Icon) icon; + } + if (icon instanceof Image) { + return ImageUtilities.image2Icon((Image)icon); + } + if (icon instanceof String) { + return ImageUtilities.loadImage((String)icon); + } + if (icon instanceof URL) { + return Toolkit.getDefaultToolkit().getImage((URL) icon); + } + Object image = fo.get("image"); // NOI18N + if (image instanceof Image) { + return ImageUtilities.image2Icon((Image)image); + } + } + if ("iconBase".equals(name)) { // NOI18N + return fo == null ? null : fo.get("iconBase"); // NOI18N + } + if ("noIconInMenu".equals(name)) { // NOI18N + return fo == null ? null : fo.get("noIconInMenu"); // NOI18N + } + if (Action.ACCELERATOR_KEY.equals(name)) { + Keymap map = Lookup.getDefault().lookup(Keymap.class); + if (map != null) { + KeyStroke[] arr = map.getKeyStrokesForAction(action); + return arr.length > 0 ? arr[0] : null; + } + } + + return null; + } +} diff -r 428419c1ab32 -r af0aefefe222 openide.awt/test/unit/src/META-INF/MANIFEST.MF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.awt/test/unit/src/META-INF/MANIFEST.MF Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,3 @@ +OpenIDE-Module: org.openide.awt.test +OpenIDE-Module-Layer: org/openide/awt/test-layer.xml +OpenIDE-Public-Packages: - diff -r 428419c1ab32 -r af0aefefe222 openide.awt/test/unit/src/org/openide/awt/AlwaysEnabledActionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.awt/test/unit/src/org/openide/awt/AlwaysEnabledActionTest.java Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,136 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.openide.awt; + +import java.awt.event.ActionListener; +import javax.swing.Action; +import org.netbeans.junit.NbTestCase; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.Repository; +import org.openide.util.ContextAwareAction; + +/** + * + * @author Jaroslav Tulach + */ +public class AlwaysEnabledActionTest extends NbTestCase { + private FileObject folder; + + public AlwaysEnabledActionTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + FileSystem fs = Repository.getDefault().getDefaultFileSystem(); + folder = fs.findResource("actions/support/test"); + assertNotNull("testing layer is loaded: ", folder); + } + + @Override + protected boolean runInEQ() { + return true; + } + + public void testIconIsCorrect() throws Exception { + myListenerCounter = 0; + myIconResourceCounter = 0; + Action a = readAction("testIconIsCorrect.instance"); + + assertNotNull("Action created", a); + assertEquals("No myListener called", 0, myListenerCounter); + assertEquals("No myIconURL called", 0, myIconResourceCounter); + + Object name = a.getValue(a.NAME); + Object mnem = a.getValue(a.MNEMONIC_KEY); + Object smallIcon = a.getValue(a.SMALL_ICON); + //Object icon = a.getValue(a.ICON) + + assertEquals("Right localized name", "Icon &Name Action", name); + assertEquals("Mnemonic is N", Character.valueOf('N'), mnem); + assertNotNull("small icon present", smallIcon); + + assertEquals("once icon called", 1, myIconResourceCounter); + + + Object base = a.getValue("iconBase"); + assertEquals("iconBase attribute is delegated", 2, myIconResourceCounter); + + assertTrue("Always enabled", a.isEnabled()); + a.setEnabled(false); + assertTrue("Still Always enabled", a.isEnabled()); + + + assertEquals("No icon in menu", Boolean.TRUE, a.getValue("noIconInMenu")); + + if (a instanceof ContextAwareAction) { + fail("Should not be context sensitive, otherwise it would have to implement equal correctly: " + a); + } + } + + private static int myListenerCounter; + private static ActionListener myListener() { + myListenerCounter++; + return null; + } + private static int myIconResourceCounter; + private static String myIconResource() { + myIconResourceCounter++; + return "/org/openide/awt/TestIcon.png"; + } + + + private Action readAction(String fileName) throws Exception { + FileObject fo = this.folder.getFileObject(fileName); + assertNotNull("file " + fileName, fo); + + Object obj = fo.getAttribute("instanceCreate"); + assertNotNull("File object has not null instanceCreate attribute", obj); + + if (!(obj instanceof Action)) { + fail("Object needs to be action: " + obj); + } + + return (Action)obj; + } +} diff -r 428419c1ab32 -r af0aefefe222 openide.awt/test/unit/src/org/openide/awt/TestBundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.awt/test/unit/src/org/openide/awt/TestBundle.properties Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,43 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. +# +# 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. Sun designates this +# particular file as subject to the "Classpath" exception as provided +# by Sun 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]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun +# Microsystems, Inc. All Rights Reserved. +# +# 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. + + +actions/support/test/testIconIsCorrect.instance=Icon &Name Action +actions/support/test/testContext.instance=Open + diff -r 428419c1ab32 -r af0aefefe222 openide.awt/test/unit/src/org/openide/awt/TestIcon.png Binary file openide.awt/test/unit/src/org/openide/awt/TestIcon.png has changed diff -r 428419c1ab32 -r af0aefefe222 openide.awt/test/unit/src/org/openide/awt/test-layer.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.awt/test/unit/src/org/openide/awt/test-layer.xml Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + diff -r 428419c1ab32 -r af0aefefe222 openide.filesystems/apichanges.xml --- a/openide.filesystems/apichanges.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.filesystems/apichanges.xml Tue Jul 08 17:28:31 2008 +0200 @@ -46,6 +46,23 @@ made subject to such option by the copyr Filesystems API + + + Attributes 'displayName' and 'image' + + + + + +

+ When using methodvalue in XML filesystem, one can add there + expect new values 'displayName' and 'image' available to methods + that accept java.util.Map. +

+
+ + +
Added methods to interconvert URLs and traditional path entries diff -r 428419c1ab32 -r af0aefefe222 openide.filesystems/manifest.mf --- a/openide.filesystems/manifest.mf Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.filesystems/manifest.mf Tue Jul 08 17:28:31 2008 +0200 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Manifest-Version: 1.0 OpenIDE-Module: org.openide.filesystems -OpenIDE-Module-Specification-Version: 7.9 +OpenIDE-Module-Specification-Version: 7.10 OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties diff -r 428419c1ab32 -r af0aefefe222 openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java --- a/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.filesystems/src/org/openide/filesystems/XMLFileSystem.java Tue Jul 08 17:28:31 2008 +0200 @@ -146,7 +146,10 @@ import org.xml.sax.helpers.DefaultHandle * static Value methodName(Map attrs); // since 7.0 * static Value methodName(Map attrs, String attrName); // since 7.0 * - * where Value can be any java type. + * where Value can be any java type. Since version 7.9 the Map + * attribute may also contain special values for keys displayName and + * image representing display name of the {@link FileObject} and its image + * respectively. * * * @author Radek Matous diff -r 428419c1ab32 -r af0aefefe222 openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java --- a/openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java Tue Jul 08 17:28:31 2008 +0200 @@ -40,6 +40,7 @@ */ package org.openide.filesystems; +import java.awt.Toolkit; import org.openide.util.SharedClassObject; import org.openide.util.Utilities; import org.openide.util.io.NbMarshalledObject; @@ -53,6 +54,7 @@ import java.net.URL; import java.util.*; import org.openide.util.Exceptions; +import org.openide.util.NbBundle; /** @@ -338,6 +340,7 @@ final class XMLMapAttr implements Map { return map.containsValue(p1); } + @Override public synchronized int hashCode() { return map.hashCode(); } @@ -367,6 +370,7 @@ final class XMLMapAttr implements Map { return map.isEmpty(); } + @Override public synchronized boolean equals(Object p1) { return map.equals(p1); } @@ -982,6 +986,7 @@ final class XMLMapAttr implements Map { return index; } + @Override public boolean equals(Object obj) { if (obj instanceof Attr) { Attr other = (Attr)obj; @@ -995,6 +1000,7 @@ final class XMLMapAttr implements Map { return false; } + @Override public int hashCode() { return 743 + keyIndex << 8 + value.hashCode(); } @@ -1140,10 +1146,12 @@ final class XMLMapAttr implements Map { return fo.getAttribute(key); } + @Override public Object remove(Object key) { throw new UnsupportedOperationException(); } + @Override public Object put(String key, Object value) { throw new UnsupportedOperationException(); } @@ -1158,13 +1166,17 @@ final class XMLMapAttr implements Map { public Iterator> iterator() { class Iter implements Iterator> { + int fixed; Enumeration attrs = fo.getAttributes(); - + public boolean hasNext() { - return attrs.hasMoreElements(); + return fixed < 2 || attrs.hasMoreElements(); } - + public Map.Entry next() { + if (fixed < 2) { + return new LocEntry(fo, fixed++); + } String s = attrs.nextElement(); return new FOEntry(fo, s); } @@ -1186,6 +1198,7 @@ final class XMLMapAttr implements Map { return cnt; } + @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); } @@ -1212,4 +1225,38 @@ final class XMLMapAttr implements Map { throw new UnsupportedOperationException(); } } // end of FOEntry + private static final class LocEntry implements Map.Entry { + private FileObject fo; + private int type; + + private LocEntry(FileObject fo, int cnt) { + this.fo = fo; + this.type = cnt; + } + + public String getKey() { + return type == 0 ? "displayName" : "image"; // NOI18N + } + + public Object getValue() { + if (type == 0) { + String rb = (String) fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N + if (rb == null) { + return fo.getNameExt(); + } + return NbBundle.getBundle(rb).getString(fo.getPath()); + } else if (type == 1) { + URL u = (URL) fo.getAttribute("SystemFileSystem.icon"); // NOI18N + if (u != null) { + return Toolkit.getDefaultToolkit().getImage(u); + } + } + return null; + } + + + public Object setValue(Object value) { + throw new UnsupportedOperationException(); + } + } // end of LocEntry } diff -r 428419c1ab32 -r af0aefefe222 openide.windows/apichanges.xml --- a/openide.windows/apichanges.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.windows/apichanges.xml Tue Jul 08 17:28:31 2008 +0200 @@ -48,6 +48,18 @@ made subject to such option by the copyr + + + TopComponent.openAction + + + + + + Adding new factory method that creates an action to open a TopComponent. + + + Added a group of resource bundle properties for customization diff -r 428419c1ab32 -r af0aefefe222 openide.windows/manifest.mf --- a/openide.windows/manifest.mf Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.windows/manifest.mf Tue Jul 08 17:28:31 2008 +0200 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Manifest-Version: 1.0 OpenIDE-Module: org.openide.windows -OpenIDE-Module-Specification-Version: 6.23 +OpenIDE-Module-Specification-Version: 6.24 OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties AutoUpdate-Essential-Module: true diff -r 428419c1ab32 -r af0aefefe222 openide.windows/nbproject/project.xml --- a/openide.windows/nbproject/project.xml Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.windows/nbproject/project.xml Tue Jul 08 17:28:31 2008 +0200 @@ -47,7 +47,7 @@ made subject to such option by the copyr org.openide.windows - org.openide.util + org.openide.awt @@ -63,26 +63,26 @@ made subject to such option by the copyr - org.openide.awt + org.openide.util - 6.2 + 7.15 - - - unit - - org.openide.windows - - - - - - qa-functional - + + + unit + + org.openide.windows + + + + + + qa-functional + org.openide.windows diff -r 428419c1ab32 -r af0aefefe222 openide.windows/src/org/openide/windows/OpenComponentAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.windows/src/org/openide/windows/OpenComponentAction.java Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,87 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 2008 Sun Microsystems, Inc. + */ + +package org.openide.windows; + +import java.awt.EventQueue; +import java.awt.Image; +import java.awt.event.ActionEvent; +import java.util.Map; +import javax.swing.AbstractAction; + +import org.openide.util.ImageUtilities; + +/** Opens a top component. + * + * @author Jaroslav Tulach + */ +final class OpenComponentAction extends AbstractAction { + private TopComponent component; + private final Map map; + + OpenComponentAction(TopComponent component, String displayName, Image image) { + super(displayName); + this.component = component; + putValue(SMALL_ICON, ImageUtilities.image2Icon(image)); + map = null; + } + + OpenComponentAction(Map map) { + super((String)map.get("displayName")); // NOI18N + this.map = map; + Image image = (Image)map.get("image"); // NOI18N + if (image != null) { + putValue(SMALL_ICON, ImageUtilities.image2Icon(image)); + } + } + + private TopComponent getTopComponent() { + assert EventQueue.isDispatchThread(); + if (component != null) { + return component; + } + return component = (TopComponent)map.get("component"); // NOI18N + } + + public void actionPerformed(ActionEvent e) { + TopComponent win = getTopComponent(); + win.open(); + win.requestActive(); + } +} diff -r 428419c1ab32 -r af0aefefe222 openide.windows/src/org/openide/windows/TopComponent.java --- a/openide.windows/src/org/openide/windows/TopComponent.java Tue Jun 17 13:36:09 2008 -0700 +++ b/openide.windows/src/org/openide/windows/TopComponent.java Tue Jul 08 17:28:31 2008 +0200 @@ -65,6 +65,7 @@ import java.util.Arrays; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -535,6 +536,32 @@ public class TopComponent extends JCompo } else { return actions; } + } + + /** Creates an action that opens and activates given TopComponent, + * when invoked. This method can also be used from + * XML Layer + * directly by following XML definition: + *
+     * <file name="your-pkg-action-id.instance">
+     *   <attr name="instanceCreate" methodvalue="org.openide.windows.TopComponent.openAction"/>
+     *   <attr name="component" methodvalue="your.pkg.YourComponent.factoryMethod"/>
+     *   <attr name="SystemFileSystem.icon" stringvalue="your/pkg/YourComponent.png"/>
+     *   <attr name="SystemFileSystem.localizingBundle" stringvalue="your/pkg/Bundle"/>
+     * </file>
+     * 
+ * + * @param component the component to open + * @param displayName the display name of the action + * @param image the image to associated with the action + * + * @since 6.24 + */ + public static Action openAction(TopComponent component, String displayName, Image image) { + return new OpenComponentAction(component, displayName, image); + } + static Action openAction(Map map) { + return new OpenComponentAction(map); } /** Set the close mode for the component. diff -r 428419c1ab32 -r af0aefefe222 openide.windows/test/unit/src/org/openide/windows/OpenComponentActionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.windows/test/unit/src/org/openide/windows/OpenComponentActionTest.java Tue Jul 08 17:28:31 2008 +0200 @@ -0,0 +1,160 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 2008 Sun Microsystems, Inc. + */ + +package org.openide.windows; + +import java.awt.Image; +import java.awt.event.ActionEvent; +import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.Map; +import javax.swing.Action; +import javax.swing.Icon; +import org.netbeans.junit.NbTestCase; + +/** + * + * @author Jaroslav Tulach + */ +public class OpenComponentActionTest extends NbTestCase { + + public OpenComponentActionTest(String testName) { + super(testName); + } + + @Override + protected boolean runInEQ() { + return true; + } + + + + @Override + protected void setUp() throws Exception { + super.setUp(); + + TC.instance = null; + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testMethodCallDirectly() { + ActionEvent e = new ActionEvent(this, 0, ""); + TC tc = new TC(); + Image img = new BufferedImage(133, 133, BufferedImage.TYPE_INT_ARGB); + Action instance = TopComponent.openAction(tc, "Ahoj", img); + instance.actionPerformed(e); + + tc.close(); + + assertEquals("Opened once", 1, tc.cntOpen); + assertEquals("Activated once", 1, tc.cntRequest); + + Icon icon = (Icon) instance.getValue(Action.SMALL_ICON); + assertEquals("Width", 133, icon.getIconWidth()); + assertEquals("Height", 133, icon.getIconHeight()); + assertEquals("Name", "Ahoj", instance.getValue(Action.NAME)); + } + + public void testMapInstantiation() { + final Image img = new BufferedImage(133, 133, BufferedImage.TYPE_INT_ARGB); + + Map m = new HashMap() { + @Override + public Object get(Object key) { + if ("component".equals(key)) { + return new TC(); + } + if ("displayName".equals(key)) { + return "Ahoj"; + } + if ("image".equals(key)) { + return img; + } + return null; + } + }; + + ActionEvent e = new ActionEvent(this, 0, ""); + Action instance = TopComponent.openAction(m); + + assertNull("No instance yet", TC.instance); + instance.actionPerformed(e); + + assertNotNull("Instance created", TC.instance); + TC tc = TC.instance; + tc.close(); + + assertEquals("Opened once", 1, tc.cntOpen); + assertEquals("Activated once", 1, tc.cntRequest); + + Icon icon = (Icon) instance.getValue(Action.SMALL_ICON); + assertEquals("Width", 133, icon.getIconWidth()); + assertEquals("Height", 133, icon.getIconHeight()); + assertEquals("Name", "Ahoj", instance.getValue(Action.NAME)); + } + + + public static final class TC extends TopComponent { + static TC instance; + + int cntOpen; + int cntRequest; + + public TC() { + assertNull("No previous one", instance); + instance = this; + } + + @Override + public void open() { + super.open(); + cntOpen++; + } + + @Override + public void requestActive() { + super.requestActive(); + cntRequest++; + } + } +}