From ef9d2bc171a7c0e6bdf61bb2104d24bbf95b714a Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Sat, 19 Nov 2011 14:51:50 +0000 Subject: [PATCH] - create unified "Configuration Files" node in project where e.g. build.xml and android MainActivity can be put git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8727 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../gde/android/AndroidImportantFiles.java | 55 ++++++ .../jme3/gde/android/ImportantFilesNode.java | 160 ---------------- .../src/com/jme3/gde/android/layer.xml | 17 -- sdk/jme3-core/nbproject/project.xml | 2 + .../core/importantfiles/ImportantFiles.java | 43 +++++ .../importantfiles/ImportantFilesNode.java | 171 ++++++++++++++++++ .../gde/core/importantfiles/important.gif | Bin 0 -> 386 bytes .../core/j2seproject/J2seImportantFiles.java | 27 +++ sdk/jme3-core/src/com/jme3/gde/core/layer.xml | 3 + 9 files changed, 301 insertions(+), 177 deletions(-) create mode 100644 sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java delete mode 100644 sdk/jme3-android/src/com/jme3/gde/android/ImportantFilesNode.java create mode 100644 sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java create mode 100644 sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java create mode 100644 sdk/jme3-core/src/com/jme3/gde/core/importantfiles/important.gif create mode 100644 sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java diff --git a/sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java b/sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java new file mode 100644 index 000000000..6b3952eca --- /dev/null +++ b/sdk/jme3-android/src/com/jme3/gde/android/AndroidImportantFiles.java @@ -0,0 +1,55 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.android; + +import com.jme3.gde.core.importantfiles.ImportantFiles; +import java.io.InputStream; +import java.util.ArrayList; +import org.netbeans.api.project.Project; +import org.openide.filesystems.FileObject; +import org.openide.util.Exceptions; +import org.openide.xml.XMLUtil; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +/** + * + * @author normenhansen + */ +@org.openide.util.lookup.ServiceProvider(service = ImportantFiles.class) +public class AndroidImportantFiles implements ImportantFiles { + + @Override + public FileObject[] getFiles(Project project) { + FileObject manifest = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); + String mainActivity = "mobile/src"; + if (manifest != null) { + InputStream in = null; + try { + in = manifest.getInputStream(); + Document configuration = XMLUtil.parse(new InputSource(in), false, false, null, null); + mainActivity = "mobile/src/" + configuration.getDocumentElement().getAttribute("package").replaceAll("\\.", "/") + "/MainActivity.java"; + in.close(); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + } finally { + } + } + ArrayList list = new ArrayList(); + FileObject mainAct = project.getProjectDirectory().getFileObject(mainActivity); + if (mainAct != null) { + list.add(mainAct); + } + FileObject manif = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); + if (manif != null) { + list.add(manif); + } + FileObject buildProp = project.getProjectDirectory().getFileObject("mobile/ant.properties"); + if (buildProp != null) { + list.add(buildProp); + } + return list.toArray(new FileObject[list.size()]); + } +} diff --git a/sdk/jme3-android/src/com/jme3/gde/android/ImportantFilesNode.java b/sdk/jme3-android/src/com/jme3/gde/android/ImportantFilesNode.java deleted file mode 100644 index b82873d92..000000000 --- a/sdk/jme3-android/src/com/jme3/gde/android/ImportantFilesNode.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.jme3.gde.android; - -import java.awt.Image; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.LookupProvider; -import org.netbeans.spi.project.ui.support.NodeFactory; -import org.netbeans.spi.project.ui.support.NodeFactorySupport; -import org.netbeans.spi.project.ui.support.NodeList; -import org.openide.filesystems.FileObject; -import org.openide.loaders.DataObject; -import org.openide.loaders.DataObjectNotFoundException; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.Exceptions; -import org.openide.util.ImageUtilities; -import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; -import org.openide.xml.XMLUtil; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; - -/** - * - * @author normenhansen - */ -public class ImportantFilesNode extends AbstractNode { - - private static Image smallImage = - ImageUtilities.loadImage("com/jme3/gde/android/properties/Phone_16.gif"); - - public ImportantFilesNode(Project proj) throws DataObjectNotFoundException { - super(new ImportantFilesChildren(proj)); - } - - @Override - public String getDisplayName() { - return "Android Files"; - } - - @Override - public Image getIcon(int type) { - return smallImage; - } - - @Override - public Image getOpenedIcon(int type) { - return smallImage; - } - - public static class LookupProviderImpl implements LookupProvider { - - public Lookup createAdditionalLookup(Lookup lookup) { - - Project prj = lookup.lookup(Project.class); - - //create node if lookup has important files node - FileObject folder = prj.getProjectDirectory().getFileObject("mobile"); - if (folder != null && folder.isFolder()) { - return Lookups.fixed(new ImportantFilesLookupItem(prj)); - } - - return Lookups.fixed(); - - } - } - - public static class ImportantFilesNodeFactoryImpl implements NodeFactory { - - public NodeList createNodes(Project project) { - -// this.proj = project; - - //If our item is in the project's lookup, - //return a new node in the node list: - ImportantFilesLookupItem item = project.getLookup().lookup(ImportantFilesLookupItem.class); - if (item != null) { - try { - ImportantFilesNode nd = new ImportantFilesNode(project); - return NodeFactorySupport.fixedNodeList(nd); - } catch (DataObjectNotFoundException ex) { - Exceptions.printStackTrace(ex); - } - } - - //If our item isn't in the lookup, - //then return an empty list of nodes: - return NodeFactorySupport.fixedNodeList(); - - } - } - - public static class ImportantFilesLookupItem { - - public ImportantFilesLookupItem(Project prj) { - } - } - - public static class ImportantFilesChildren extends Children.Keys { - - private Project project; - - public ImportantFilesChildren(Project project) { - this.project = project; - } - - protected List createKeys() { -// package="com.mycompany.mygame" - FileObject manifest = project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"); - String mainActivity = "mobile/src"; - if (manifest != null) { - InputStream in = null; - try { - in = manifest.getInputStream(); - Document configuration = XMLUtil.parse(new InputSource(in), false, false, null, null); - mainActivity = "mobile/src/" + configuration.getDocumentElement().getAttribute("package").replaceAll("\\.", "/") + "/MainActivity.java"; - in.close(); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - } finally { - } - } - ArrayList list = new ArrayList(); - addFileObject(project.getProjectDirectory().getFileObject(mainActivity), list); - addFileObject(project.getProjectDirectory().getFileObject("mobile/AndroidManifest.xml"), list); - addFileObject(project.getProjectDirectory().getFileObject("mobile/build.properties"), list); - return list; - } - - private void addFileObject(FileObject file, List list) { - if (file != null) { - list.add(file); - } - } - - @Override - protected void addNotify() { - super.addNotify(); - setKeys(createKeys()); - } - - @Override - protected Node[] createNodes(FileObject key) { - try { - DataObject obj = DataObject.find(key); - return new Node[]{obj.getNodeDelegate()}; - } catch (DataObjectNotFoundException ex) { - Exceptions.printStackTrace(ex); - } - return new Node[]{}; - } - } -} \ No newline at end of file diff --git a/sdk/jme3-android/src/com/jme3/gde/android/layer.xml b/sdk/jme3-android/src/com/jme3/gde/android/layer.xml index 0dd4a223a..29a5650e0 100644 --- a/sdk/jme3-android/src/com/jme3/gde/android/layer.xml +++ b/sdk/jme3-android/src/com/jme3/gde/android/layer.xml @@ -1,23 +1,6 @@ - - - - - - - - - - - - - - - - - diff --git a/sdk/jme3-core/nbproject/project.xml b/sdk/jme3-core/nbproject/project.xml index 573ce8149..d532f4f31 100644 --- a/sdk/jme3-core/nbproject/project.xml +++ b/sdk/jme3-core/nbproject/project.xml @@ -285,7 +285,9 @@ com.jme3.gde.core.filters.actions com.jme3.gde.core.filters.impl com.jme3.gde.core.filters.impl.bloom + com.jme3.gde.core.importantfiles com.jme3.gde.core.j2seproject + com.jme3.gde.core.options com.jme3.gde.core.properties com.jme3.gde.core.properties.preview com.jme3.gde.core.scene diff --git a/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java new file mode 100644 index 000000000..ae0cc4abe --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFiles.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2009-2010 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.gde.core.importantfiles; + +import org.netbeans.api.project.Project; +import org.openide.filesystems.FileObject; + +/** + * + * @author normenhansen + */ +public interface ImportantFiles { + public FileObject[] getFiles(Project proj); +} diff --git a/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java new file mode 100644 index 000000000..deddc3aa8 --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/ImportantFilesNode.java @@ -0,0 +1,171 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.core.importantfiles; + +import java.awt.Image; +import java.util.ArrayList; +import java.util.List; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.ui.support.NodeFactory; +import org.netbeans.spi.project.ui.support.NodeFactorySupport; +import org.netbeans.spi.project.ui.support.NodeList; +import org.openide.filesystems.FileAttributeEvent; +import org.openide.filesystems.FileChangeListener; +import org.openide.filesystems.FileEvent; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileRenameEvent; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; + +/** + * + * @author normenhansen + */ +public class ImportantFilesNode extends AbstractNode implements FileChangeListener{ + + private static Image smallImage = + ImageUtilities.loadImage("com/jme3/gde/core/importantfiles/important.gif"); + + public ImportantFilesNode(Project proj) throws DataObjectNotFoundException { + super(new ImportantFilesChildren(proj)); + proj.getProjectDirectory().addRecursiveListener(this); + } + + @Override + public String getDisplayName() { + return "Configuration Files"; + } + + @Override + public Image getIcon(int type) { + return smallImage; + } + + @Override + public Image getOpenedIcon(int type) { + return smallImage; + } + + public void fileFolderCreated(FileEvent fe) { + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + ((ImportantFilesChildren)getChildren()).addNotify(); + } + }); + } + + public void fileDataCreated(FileEvent fe) { + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + ((ImportantFilesChildren)getChildren()).addNotify(); + } + }); + } + + public void fileChanged(FileEvent fe) { + } + + public void fileDeleted(FileEvent fe) { + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + ((ImportantFilesChildren)getChildren()).addNotify(); + } + }); + } + + public void fileRenamed(FileRenameEvent fre) { + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + ((ImportantFilesChildren)getChildren()).addNotify(); + } + }); + } + + public void fileAttributeChanged(FileAttributeEvent fae) { + } + +// public static class LookupProviderImpl implements LookupProvider { +// +// public Lookup createAdditionalLookup(Lookup lookup) { +// +// Project prj = lookup.lookup(Project.class); +// +// return Lookups.fixed(new ImportantFilesLookupItem(prj)); +// } +// } + + public static class ImportantFilesNodeFactoryImpl implements NodeFactory { + + public NodeList createNodes(Project project) { + +// ImportantFilesLookupItem item = project.getLookup().lookup(ImportantFilesLookupItem.class); +// if (item != null) { + try { + ImportantFilesNode nd = new ImportantFilesNode(project); + return NodeFactorySupport.fixedNodeList(nd); + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); + } +// } + + return NodeFactorySupport.fixedNodeList(); + } + } + +// public static class ImportantFilesLookupItem { +// +// public ImportantFilesLookupItem(Project prj) { +// } +// } + + public static class ImportantFilesChildren extends Children.Keys { + + private Project project; + + public ImportantFilesChildren(Project project) { + this.project = project; + } + + protected List createKeys() { + ArrayList list = new ArrayList(); + for (ImportantFiles di : Lookup.getDefault().lookupAll(ImportantFiles.class)) { + FileObject[] nodes = di.getFiles(project); + list.add(nodes); + } + return list; + } + + @Override + protected void addNotify() { + super.addNotify(); + setKeys(createKeys()); + } + + @Override + protected Node[] createNodes(FileObject[] key) { + Node[] nodes= new Node[key.length]; + for (int i = 0; i < key.length; i++) { + FileObject fileObject = key[i]; + try { + nodes[i] = DataObject.find(fileObject).getNodeDelegate(); + } catch (DataObjectNotFoundException ex) { + nodes[i] = Node.EMPTY; + Exceptions.printStackTrace(ex); + } + } + return nodes; + } + } +} \ No newline at end of file diff --git a/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/important.gif b/sdk/jme3-core/src/com/jme3/gde/core/importantfiles/important.gif new file mode 100644 index 0000000000000000000000000000000000000000..421d54335943f6eb085baa4fc48c26ff7758d7ce GIT binary patch literal 386 zcmZ?wbhEHb6krfwxXQrr|Nnn=W4p$_+5QoU;wlC^kDOn&aqsd?ds`;X`}XU9(}cMz zHt(CdXq|URTvPwt`1GQht{Hw|2{Gv<$+_iajeYe!Gt*1zW6}x>>w6me=0v9z{Q37k zFfzGg>cWJ~lI+sPik6Af7OmGXw%>p1O7ny{ITdZKljaxKcNf%jG*6sY**-P3pz7DZ z|4Dh3H62s(Dq1p%>dIRuNvIl0s2ZBu`*;P%dj`ju*n2bJ0E$0Zz%n`@667Zaw)qG6 zJRNkTI+ysd9>}qpD=NO=pk&1QFhAx8OpHp4n<{kVTp1L&7(Uf((o}EYn&7GVt}Dci z&tf5iAp=itbEAeng9HORH(MVYH+v_8zC42}gLLk!8S(}UVhnt097{RW_!cl2XfxVG!p(b&B6iiSfb1 LM-P-t9T}_vRGx&H literal 0 HcmV?d00001 diff --git a/sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java b/sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java new file mode 100644 index 000000000..02f308bde --- /dev/null +++ b/sdk/jme3-core/src/com/jme3/gde/core/j2seproject/J2seImportantFiles.java @@ -0,0 +1,27 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.core.j2seproject; + +import com.jme3.gde.core.importantfiles.ImportantFiles; +import java.util.ArrayList; +import org.netbeans.api.project.Project; +import org.openide.filesystems.FileObject; + +/** + * + * @author normenhansen + */ +@org.openide.util.lookup.ServiceProvider(service = ImportantFiles.class) +public class J2seImportantFiles implements ImportantFiles{ + + @Override + public FileObject[] getFiles(Project project) { + ArrayList list = new ArrayList(); +// list.add(project.getProjectDirectory().getFileObject("nbproject/project.properties")); + list.add(project.getProjectDirectory().getFileObject("build.xml")); + return list.toArray(new FileObject[list.size()]); + } + +} diff --git a/sdk/jme3-core/src/com/jme3/gde/core/layer.xml b/sdk/jme3-core/src/com/jme3/gde/core/layer.xml index af81cc3f9..347519d82 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/layer.xml +++ b/sdk/jme3-core/src/com/jme3/gde/core/layer.xml @@ -129,6 +129,9 @@ + + +