diff --git a/sdk/jme3-gui/README.md b/sdk/jme3-gui/README.md new file mode 100644 index 000000000..4ae49b7f3 --- /dev/null +++ b/sdk/jme3-gui/README.md @@ -0,0 +1,6 @@ +# Nifty Editor + +This project is the result of 2014 summer of code. It's the integration of Nifty-Editor on JMonkeyEngine sdk. + +## Icons +Icons provided by [Yusuke Kamiyamane](http://p.yusukekamiyamane.com/). Licensed under a Creative Commons Attribution 3.0 License. diff --git a/sdk/jme3-gui/build.xml b/sdk/jme3-gui/build.xml index f7d03ec94..a5c92cb19 100644 --- a/sdk/jme3-gui/build.xml +++ b/sdk/jme3-gui/build.xml @@ -1,8 +1,8 @@ - - - - - - Builds, tests, and runs the project com.jme3.gde.gui. - - + + + + + + Builds, tests, and runs the project com.jme3.gde.gui. + + diff --git a/sdk/jme3-gui/manifest.mf b/sdk/jme3-gui/manifest.mf index 27ba6cf5c..38c508804 100644 --- a/sdk/jme3-gui/manifest.mf +++ b/sdk/jme3-gui/manifest.mf @@ -1,6 +1,6 @@ -Manifest-Version: 1.0 -OpenIDE-Module: com.jme3.gde.gui/1 -OpenIDE-Module-Implementation-Version: 0 -OpenIDE-Module-Layer: com/jme3/gde/gui/layer.xml -OpenIDE-Module-Localizing-Bundle: com/jme3/gde/gui/Bundle.properties - +Manifest-Version: 1.0 +OpenIDE-Module: com.jme3.gde.gui/3 +OpenIDE-Module-Implementation-Version: 0 +OpenIDE-Module-Layer: com/jme3/gde/gui/layer.xml +OpenIDE-Module-Localizing-Bundle: com/jme3/gde/gui/Bundle.properties + diff --git a/sdk/jme3-gui/nbproject/build-impl.xml b/sdk/jme3-gui/nbproject/build-impl.xml index 307e07b68..e5b9c7898 100644 --- a/sdk/jme3-gui/nbproject/build-impl.xml +++ b/sdk/jme3-gui/nbproject/build-impl.xml @@ -1,45 +1,45 @@ - - - - - - - - - - - - - You must set 'suite.dir' to point to your containing module suite - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + You must set 'suite.dir' to point to your containing module suite + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/jme3-gui/nbproject/genfiles.properties b/sdk/jme3-gui/nbproject/genfiles.properties index b2b0fab9d..99333ca57 100644 --- a/sdk/jme3-gui/nbproject/genfiles.properties +++ b/sdk/jme3-gui/nbproject/genfiles.properties @@ -1,3 +1,4 @@ +<<<<<<< HEAD build.xml.data.CRC32=971927a9 build.xml.script.CRC32=a0136781 build.xml.stylesheet.CRC32=a56c6a5b@2.66.1 @@ -6,3 +7,13 @@ build.xml.stylesheet.CRC32=a56c6a5b@2.66.1 nbproject/build-impl.xml.data.CRC32=971927a9 nbproject/build-impl.xml.script.CRC32=55a34aaf nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.66.1 +======= +build.xml.data.CRC32=d998e9a1 +build.xml.script.CRC32=a0136781 +build.xml.stylesheet.CRC32=a56c6a5b@2.56.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=d998e9a1 +nbproject/build-impl.xml.script.CRC32=55a34aaf +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.56.1 +>>>>>>> experimental diff --git a/sdk/jme3-gui/release/modules/ext/Nifty-Editor0.5.7.jar b/sdk/jme3-gui/release/modules/ext/Nifty-Editor0.5.7.jar new file mode 100644 index 000000000..c22e77625 Binary files /dev/null and b/sdk/jme3-gui/release/modules/ext/Nifty-Editor0.5.7.jar differ diff --git a/sdk/jme3-gui/release/modules/ext/Nifty-Editor0.5.9.jar b/sdk/jme3-gui/release/modules/ext/Nifty-Editor0.5.9.jar new file mode 100644 index 000000000..0747d52ea Binary files /dev/null and b/sdk/jme3-gui/release/modules/ext/Nifty-Editor0.5.9.jar differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/Bundle.properties b/sdk/jme3-gui/src/com/jme3/gde/gui/Bundle.properties index 91fe01a5b..be0d84773 100644 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/Bundle.properties +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/Bundle.properties @@ -1,7 +1,8 @@ LBL_NiftyGui_loader_name=NiftyGui Files OpenIDE-Module-Display-Category=jMonkeyEngine OpenIDE-Module-Long-Description=\ - This plugin adds NiftyGUI XML file support + This plugin adds NiftyGUI XML file support , with and easy visual desing interface . \ + Icon pack provided by http://p.yusukekamiyamane.com/ Licensed under a Creative Commons Attribution 3.0 License. OpenIDE-Module-Name=NiftyGUI Support OpenIDE-Module-Short-Description=Provides NiftyGUI Support Services/MIMEResolver/NiftyGuiResolver.xml=NiftyGui Files diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiDataObject.java b/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiDataObject.java index 98c57c631..32a62ff5e 100644 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiDataObject.java +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiDataObject.java @@ -1,89 +1,149 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.jme3.gde.gui; - -import com.jme3.gde.core.assets.ProjectAssetManager; -import com.jme3.gde.gui.multiview.PreviewView; -import java.io.IOException; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectManager; -import org.netbeans.modules.xml.multiview.DesignMultiViewDesc; -import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject; -import org.openide.filesystems.FileObject; -import org.openide.loaders.DataNode; -import org.openide.loaders.DataObjectExistsException; -import org.openide.loaders.MultiFileLoader; -import org.openide.nodes.Node; -import org.openide.nodes.Children; -import org.openide.util.Lookup; -import org.openide.util.lookup.AbstractLookup; -import org.openide.util.lookup.InstanceContent; -import org.openide.util.lookup.ProxyLookup; - -public class NiftyGuiDataObject extends XmlMultiViewDataObject { - - private static final int TYPE_TOOLBAR = 0; - protected final Lookup lookup; - protected final InstanceContent lookupContents = new InstanceContent(); - - public NiftyGuiDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { - super(pf, loader); - lookup = new ProxyLookup(getCookieSet().getLookup(), new AbstractLookup(getLookupContents())); - findAssetManager(); - } - - protected void findAssetManager() { - FileObject file = getPrimaryFile(); - ProjectManager pm = ProjectManager.getDefault(); - while (file != null) { - if (file.isFolder() && pm.isProject(file)) { - try { - Project project = ProjectManager.getDefault().findProject(file); - if (project != null) { - ProjectAssetManager mgr = project.getLookup().lookup(ProjectAssetManager.class); - if (mgr != null) { - getLookupContents().add(mgr); - return; - } - } - } catch (IOException ex) { - } catch (IllegalArgumentException ex) { - } - } - file = file.getParent(); - } - } - - @Override - public Lookup getLookup() { - return lookup; - } - - public InstanceContent getLookupContents() { - return lookupContents; - } - - @Override - protected Node createNodeDelegate() { - DataNode node = new DataNode(this, Children.LEAF, getLookup()); - node.setIconBaseWithExtension("com/jme3/gde/gui/Computer_File_043.gif"); - return node; - } - - @Override - protected DesignMultiViewDesc[] getMultiViewDesc() { - if (getLookup().lookup(ProjectAssetManager.class) == null) { - return new DesignMultiViewDesc[]{}; - } else { - - return new DesignMultiViewDesc[]{new PreviewView(this, TYPE_TOOLBAR)}; - } - } - - @Override - protected String getPrefixMark() { - return "Nifty"; - } -} +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui; + +import com.jme3.gde.core.assets.ProjectAssetManager; +import jada.ngeditor.controller.CommandProcessor; +import jada.ngeditor.controller.GUIEditor; +import java.io.IOException; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.netbeans.core.spi.multiview.text.MultiViewEditorElement; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.MIMEResolver; +import org.openide.loaders.DataNode; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectExistsException; +import org.openide.loaders.MultiDataObject; +import org.openide.loaders.MultiFileLoader; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.Lookup; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.TopComponent; + +@Messages({ + "LBL_NiftyGui_LOADER=Files of NiftyGui" +}) +@MIMEResolver.Registration( + displayName = "#LBL_NiftyGui_LOADER", + resource = "NiftyGuiResolver.xml") +@DataObject.Registration( + mimeType = "text/x-niftygui+xml", + iconBase = "com/jme3/gde/gui/multiview/icons/gui-icon.png", + displayName = "#LBL_NiftyGui_LOADER", + position = 300) +@ActionReferences({ + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.OpenAction"), + position = 100, + separatorAfter = 200), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.CutAction"), + position = 300), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"), + position = 400, + separatorAfter = 500), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"), + position = 600), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.RenameAction"), + position = 700, + separatorAfter = 800), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"), + position = 900, + separatorAfter = 1000), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"), + position = 1100, + separatorAfter = 1200), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.ToolsAction"), + position = 1300), + @ActionReference( + path = "Loaders/text/x-niftygui+xml/Actions", + id = + @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"), + position = 1400) +}) +public class NiftyGuiDataObject extends MultiDataObject { + + public NiftyGuiDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException { + super(pf, loader); + registerEditor("text/x-niftygui+xml", true); + findAssetManager(); + this.getCookieSet().assign(GUIEditor.class, CommandProcessor.getInstance().getGuiEditor()); + } + + protected final void findAssetManager() { + FileObject file = getPrimaryFile(); + ProjectManager pm = ProjectManager.getDefault(); + while (file != null) { + if (file.isFolder() && pm.isProject(file)) { + try { + Project project = ProjectManager.getDefault().findProject(file); + if (project != null) { + ProjectAssetManager mgr = project.getLookup().lookup(ProjectAssetManager.class); + if (mgr != null) { + this.getCookieSet().assign(mgr.getClass(),mgr); + return; + } + } + } catch (IOException ex) { + } catch (IllegalArgumentException ex) { + } + } + file = file.getParent(); + } + } + + @Override + protected Node createNodeDelegate() { + DataNode node = new DataNode(this, Children.LEAF, getLookup()); + node.setIconBaseWithExtension("com/jme3/gde/gui/multiview/icons/gui-icon.png"); + return node; + } + + @Override + protected int associateLookup() { + return 1; + } + + @MultiViewElement.Registration( + displayName = "#LBL_NiftyGui_EDITOR", + iconBase = "com/jme3/gde/gui/multiview/icons/gui-icon.png", + mimeType = "text/x-niftygui+xml", + persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED, + preferredID = "NiftyGui", + position = 1000) + @Messages("LBL_NiftyGui_EDITOR=XML") + public static MultiViewEditorElement createEditor(Lookup lkp) { + final MultiViewEditorElement multiViewEditorElement = new MultiViewEditorElement(lkp); + return multiViewEditorElement; + } +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiResolver.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiResolver.xml index cab60462a..4076cc28c 100644 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiResolver.xml +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGuiResolver.xml @@ -1,8 +1,4 @@ - diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/examples/01-button.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/examples/01-button.xml deleted file mode 100644 index e961a97d7..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/examples/01-button.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/examples/buttonstyle.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/examples/buttonstyle.xml new file mode 100644 index 000000000..788171282 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/examples/buttonstyle.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/layer.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/layer.xml index d83cea77c..9bba55c07 100644 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/layer.xml +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/layer.xml @@ -1,154 +1,19 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/Bundle.properties b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/Bundle.properties deleted file mode 100644 index 7a6ba8e9c..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/Bundle.properties +++ /dev/null @@ -1,4 +0,0 @@ - -PreviewPanel.jLabel1.text=jLabel1 -ErrorPanel.jLabel1.text=jLabel1 -ErrorPanel.jLabel2.text=\ Errors diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.form b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.form deleted file mode 100644 index ae4ae89ae..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.form +++ /dev/null @@ -1,62 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.java deleted file mode 100644 index 94a62d5a4..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * ErrorPanel.java - * - * Created on 23 janv. 2012, 22:19:24 - */ -package com.jme3.gde.gui.multiview; - -import java.awt.Component; -import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; -import javax.swing.ImageIcon; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.SwingConstants; - -/** - * - * @author Nehon - */ -public class ErrorPanel extends java.awt.Panel { - - private DefaultListModel errors = new DefaultListModel(); - private static ImageIcon fatalImage = null, nonFatalImage = null; - - /** Creates new form ErrorPanel */ - public ErrorPanel() { - initComponents(); - jList1.setCellRenderer(new DefaultListCellRenderer() { - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof JLabel) { - setIcon(((JLabel) value).getIcon()); - setText(((JLabel) value).getText()); - } - return this; - } - }); - } - - private static ImageIcon getFatalErrorIcon() { - if (fatalImage == null) { - fatalImage = new ImageIcon(ErrorPanel.class.getResource("/com/jme3/gde/gui/multiview/icons/error.png")); //NOI18N - } - return fatalImage; - } - - private static ImageIcon getNonfatalErrorIcon() { - if (nonFatalImage == null) { - nonFatalImage = new ImageIcon(ErrorPanel.class.getResource("/com/jme3/gde/gui/multiview/icons/warning.png")); //NOI18N - } - return nonFatalImage; - } - - public void addError(String error) { - errors.addElement(new JLabel( - error, - getFatalErrorIcon(), - SwingConstants.LEFT)); - - } - - public void addWarning(String error) { - errors.addElement(new JLabel( - error, - getNonfatalErrorIcon(), - SwingConstants.LEFT)); - - } - - public void clear(){ - errors.clear(); - } - - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - jScrollPane1 = new javax.swing.JScrollPane(); - jList1 = new javax.swing.JList(); - jLabel2 = new javax.swing.JLabel(); - - jLabel1.setText(org.openide.util.NbBundle.getMessage(ErrorPanel.class, "ErrorPanel.jLabel1.text")); // NOI18N - - setLayout(new java.awt.BorderLayout()); - - jList1.setModel(errors); - jScrollPane1.setViewportView(jList1); - - add(jScrollPane1, java.awt.BorderLayout.CENTER); - - jLabel2.setBackground(new java.awt.Color(200, 200, 200)); - jLabel2.setText(org.openide.util.NbBundle.getMessage(ErrorPanel.class, "ErrorPanel.jLabel2.text")); // NOI18N - add(jLabel2, java.awt.BorderLayout.NORTH); - }// //GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JList jList1; - private javax.swing.JScrollPane jScrollPane1; - // End of variables declaration//GEN-END:variables -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/MouseInputEvent.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/MouseInputEvent.java deleted file mode 100644 index 71a37d433..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/MouseInputEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.jme3.gde.gui.multiview; - -/** - * - * @author normenhansen - */ -public class MouseInputEvent { - int x; - int y; - int button; - int huh; - boolean pressed; - - public MouseInputEvent(int x, int y, int button, int huh, boolean pressed) { - this.x = x; - this.y = y; - this.button = button; - this.huh = huh; - this.pressed = pressed; - } - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyFileChildren.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyFileChildren.java deleted file mode 100644 index ee70aa1d8..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyFileChildren.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.jme3.gde.gui.multiview; - -import java.util.LinkedList; -import java.util.List; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.w3c.dom.Element; - -/** - * - * @author normenhansen - */ -public class NiftyFileChildren extends Children.Keys { - - Element xmlNode; - - public NiftyFileChildren(Element xmlNode) { - this.xmlNode = xmlNode; - } - - @Override - protected void addNotify() { - super.addNotify(); - setKeys(createKeys()); - } - - protected List createKeys() { - LinkedList ret = new LinkedList(); - Element curElement = XmlHelper.findFirstChildElement(xmlNode); - while (curElement != null) { - if (checkElement(curElement)) { - ret.add(curElement); - } - curElement = XmlHelper.findNextSiblingElement(curElement); - } - - return ret; - } - - private boolean checkElement(Element curElement) { - if (!"screen".equals(curElement.getTagName())) { - return false; - } - return true; - } - - @Override - protected Node[] createNodes(Element key) { - return new Node[]{new NiftyScreenNode(key.getAttribute("id"))}; - } -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyFileNode.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyFileNode.java deleted file mode 100644 index a3d15f188..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyFileNode.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.jme3.gde.gui.multiview; - -import org.openide.nodes.AbstractNode; -import org.w3c.dom.Element; - -/** - * - * @author normenhansen - */ -public class NiftyFileNode extends AbstractNode{ - - public NiftyFileNode(Element xmlNode) { - super(new NiftyFileChildren(xmlNode)); - } - - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyJmeDisplay.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyJmeDisplay.java deleted file mode 100644 index a76eec721..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyJmeDisplay.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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.gui.multiview; - -import com.jme3.asset.AssetInfo; -import com.jme3.asset.AssetKey; -import com.jme3.asset.AssetManager; -import com.jme3.asset.AssetNotFoundException; -import com.jme3.asset.DesktopAssetManager; -import com.jme3.audio.AudioRenderer; -import com.jme3.niftygui.RenderDeviceJme; -import com.jme3.niftygui.SoundDeviceJme; -import com.jme3.post.SceneProcessor; -import com.jme3.renderer.RenderManager; -import com.jme3.renderer.Renderer; -import com.jme3.renderer.ViewPort; -import com.jme3.renderer.queue.RenderQueue; -import com.jme3.texture.FrameBuffer; -import de.lessvoid.nifty.Nifty; -import de.lessvoid.nifty.spi.input.InputSystem; -import de.lessvoid.nifty.tools.TimeProvider; -import de.lessvoid.nifty.tools.resourceloader.ResourceLocation; -import java.io.InputStream; -import java.net.URL; - -public class NiftyJmeDisplay extends com.jme3.niftygui.NiftyJmeDisplay implements SceneProcessor { - - protected class ResourceLocationJmp implements ResourceLocation { - - public InputStream getResourceAsStream(String path) { - AssetKey key = new AssetKey(path); - AssetInfo info = assetManager.locateAsset(key); - if (info != null){ - return info.openStream(); - }else{ - throw new AssetNotFoundException(path); - } - } - - public URL getResource(String path) { - throw new UnsupportedOperationException(); - } - } - - private ResourceLocation resourceLocation = new ResourceLocationJmp(); - - public NiftyJmeDisplay(AssetManager assetManager, - InputSystem inputManager, - AudioRenderer audioRenderer, - ViewPort vp){ - this.assetManager = assetManager; - //TODO: move - ((DesktopAssetManager)assetManager).clearCache(); - w = vp.getCamera().getWidth(); - h = vp.getCamera().getHeight(); - - soundDev = new SoundDeviceJme(assetManager, audioRenderer); - renderDev = new RenderDeviceJme(this); - nifty = new Nifty(renderDev, soundDev, inputManager, new TimeProvider()); - nifty.getResourceLoader().addResourceLocation(resourceLocation); - } - - @Override - public void initialize(RenderManager rm, ViewPort vp) { - this.renderManager = rm; - renderDev.setRenderManager(rm); - inited = true; - this.vp = vp; - this.renderer = rm.getRenderer(); - - } - - @Override - public Nifty getNifty() { - return nifty; - } - - RenderDeviceJme getRenderDevice() { - return renderDev; - } - - AssetManager getAssetManager() { - return assetManager; - } - - RenderManager getRenderManager() { - return renderManager; - } - - int getHeight() { - return h; - } - - int getWidth() { - return w; - } - - Renderer getRenderer(){ - return renderer; - } - - @Override - public void reshape(ViewPort vp, int w, int h) { - this.w = w; - this.h = h; - nifty.resolutionChanged(); - } - - @Override - public boolean isInitialized() { - return inited; - } - - @Override - public void preFrame(float tpf) { - } - - @Override - public void postQueue(RenderQueue rq) { - // render nifty before anything else - renderManager.setCamera(vp.getCamera(), true); - nifty.render(false); - renderManager.setCamera(vp.getCamera(), false); - } - - @Override - public void postFrame(FrameBuffer out) { - } - - @Override - public void cleanup() { - nifty.getResourceLoader().removeResourceLocation(resourceLocation); - inited = false; -// nifty.exit(); - } - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewInputHandler.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewInputHandler.java deleted file mode 100644 index a0174a23f..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewInputHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.jme3.gde.gui.multiview; - -import de.lessvoid.nifty.NiftyInputConsumer; -import de.lessvoid.nifty.input.keyboard.KeyboardInputEvent; -import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -/** - * - * @author normenhansen - */ -public class NiftyPreviewInputHandler implements de.lessvoid.nifty.spi.input.InputSystem { - - private List mouseEvents = new LinkedList(); - private List keyEvents = new LinkedList(); - - public synchronized void forwardEvents(NiftyInputConsumer nic) { - for (Iterator it = mouseEvents.iterator(); it.hasNext();) { - MouseInputEvent mouseInputEvent = it.next(); - nic.processMouseEvent(mouseInputEvent.x, mouseInputEvent.y, mouseInputEvent.button, mouseInputEvent.huh, mouseInputEvent.pressed); - it.remove(); - } - for (Iterator it = keyEvents.iterator(); it.hasNext();) { - KeyboardInputEvent keyInputEvent = it.next(); - nic.processKeyboardEvent(keyInputEvent); - it.remove(); - } - } - - public synchronized void addMouseEvent(int newMouseX, int newMouseY, boolean mouseDown) { - MouseInputEvent event = new MouseInputEvent(newMouseX, newMouseY, 0, 0, mouseDown); - mouseEvents.add(event); - } - - public synchronized void addKeyEvent(int newKey, char newCharacter, boolean newKeyDown, boolean newShiftDown, boolean newControlDown) { - KeyboardInputEvent event = new KeyboardInputEvent(newKey, newCharacter, newKeyDown, newShiftDown, newControlDown); - keyEvents.add(event); - } - - public void setMousePosition(int i, int i1) { -// throw new UnsupportedOperationException("Not supported yet."); - } - - public void setResourceLoader(NiftyResourceLoader nrl) { - } - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewPanel.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewPanel.java deleted file mode 100644 index 36c721976..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewPanel.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.jme3.gde.gui.multiview; - -import com.jme3.audio.AudioRenderer; -import com.jme3.gde.core.assets.ProjectAssetManager; -import com.jme3.gde.core.scene.OffScenePanel; -import com.jme3.gde.core.scene.SceneApplication; -import com.jme3.gde.gui.NiftyGuiDataObject; -import com.jme3.renderer.ViewPort; -import de.lessvoid.nifty.Nifty; -import java.awt.Dimension; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; -import java.util.Iterator; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JComboBox; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JToolBar; -import org.netbeans.modules.xml.multiview.Error; -import org.netbeans.modules.xml.multiview.ui.PanelView; -import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor; -import org.openide.NotifyDescriptor; -import org.openide.NotifyDescriptor.Message; -import org.openide.nodes.Node; -import org.openide.util.Exceptions; -import org.openide.xml.XMLUtil; -import org.w3c.dom.Document; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -/** - * - * @author normenhansen - */ -public class NiftyPreviewPanel extends PanelView implements ErrorHandler { - - private NiftyGuiDataObject niftyObject; - private OffScenePanel offPanel; - private Nifty nifty; - private Document doc; - private ToolBarDesignEditor comp; - private String screen = ""; - private NiftyPreviewInputHandler inputHandler; - private NiftyJmeDisplay niftyDisplay; - private JScrollPane scrollPanel; - private int width = 640, height = 480; - private ErrorPanel errors; - - public NiftyPreviewPanel(NiftyGuiDataObject niftyObject, ToolBarDesignEditor comp) { - super(); - setRoot(Node.EMPTY); - this.niftyObject = niftyObject; - this.comp = comp; - comp.setContentView(this); - preparePreview(); - updatePreView(); - } - - private void createToolbar() { - JToolBar toolBar = new JToolBar(); - toolBar.setPreferredSize(new Dimension(10000, 24)); - toolBar.setMaximumSize(new Dimension(10000, 24)); - toolBar.setFloatable(false); - JComboBox comboBox = new JComboBox(new String[]{"640x480", "480x800", "800x480", "800x600", "1024x768", "1280x720"}); - comboBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - String string = (String) e.getItem(); - if ("640x480".equals(string)) { - width = 640; - height = 480; - } else if ("1024x768".equals(string)) { - width = 1024; - height = 768; - } else if ("1280x720".equals(string)) { - width = 1280; - height = 720; - } else if ("800x600".equals(string)) { - width = 800; - height = 600; - } else if ("800x480".equals(string)) { - width = 800; - height = 480; - } else if ("480x800".equals(string)) { - width = 480; - height = 800; - } else { - width = 640; - height = 480; - } - offPanel.resizeGLView(width, height); - - SceneApplication.getApplication().enqueue(new Callable() { - - public Object call() throws Exception { - niftyDisplay.reshape(offPanel.getViewPort(), width, height); - return null; - } - }); - -// updatePreView(); - } - }); - toolBar.add(comboBox); - toolBar.add(new JPanel()); - setLayout(new java.awt.BorderLayout()); - add(toolBar, java.awt.BorderLayout.NORTH); - errors = new ErrorPanel(); - errors.setPreferredSize(new Dimension(0, 80)); - - - add(errors, java.awt.BorderLayout.SOUTH); - - } - - public void updatePreView() { - updatePreView(screen); - } - - public void updatePreView(final String screen) { - errors.clear(); - final ProjectAssetManager pm = niftyObject.getLookup().lookup(ProjectAssetManager.class); - if (pm == null) { - Logger.getLogger(NiftyPreviewPanel.class.getName()).log(Level.WARNING, "No Project AssetManager found!"); - } - InputStream stream = null; - try { - stream = niftyObject.getPrimaryFile().getInputStream(); - doc = XMLUtil.parse(new InputSource(stream), false, false, this, null); - NiftyFileNode rootContext = new NiftyFileNode(doc.getDocumentElement()); - setRoot(rootContext); - comp.setRootContext(rootContext); - } catch (Exception ex) { -// Message msg = new NotifyDescriptor.Message( -// "Error parsing File:" + ex, -// NotifyDescriptor.ERROR_MESSAGE); - // DialogDisplayer.getDefault().notifyLater(msg); - Exceptions.printStackTrace(ex); - // return; - } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } - try { - - if (nifty != null) { - nifty.validateXml(niftyObject.getPrimaryFile().getPath()); - - } - } catch (Exception e) { - if (e instanceof SAXParseException) { - SAXParseException spe = (SAXParseException) e; - errors.addError("Line " + spe.getLineNumber() + " col :" + spe.getColumnNumber() + " : " + spe.getMessage()); - } else { - errors.addError(e.getMessage()); - } - Exceptions.printStackTrace(e); - } - SceneApplication.getApplication().enqueue(new Callable() { - - public Object call() throws Exception { - - try { - nifty.fromXml(pm.getRelativeAssetPath(niftyObject.getPrimaryFile().getPath()), screen); - if (screen == null || screen.length() == 0) { - Collection screens = nifty.getAllScreensName(); - for (Iterator it = screens.iterator(); it.hasNext();) { - String string = it.next(); - nifty.gotoScreen(string); - return null; - } - } - } catch (Exception ex) { - Message msg = new NotifyDescriptor.Message( - "Error opening File:" + ex, - NotifyDescriptor.ERROR_MESSAGE); - // DialogDisplayer.getDefault().notifyLater(msg); - Exceptions.printStackTrace(ex); - errors.addError(ex.getMessage()); - } - return null; - } - }); -// java.awt.EventQueue.invokeLater(new Runnable() { -// -// public void run() { -// validateTree(); -// } -// }); - } - - @Override - public void initComponents() { - super.initComponents(); - setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS)); - createToolbar(); - scrollPanel = new JScrollPane(); - offPanel = new OffScenePanel(640, 480); - scrollPanel.getViewport().add(offPanel); - add(scrollPanel); - offPanel.startPreview(); - prepareInputHandler(); - } - - private void prepareInputHandler() { - inputHandler = new NiftyPreviewInputHandler(); - offPanel.addMouseMotionListener(new MouseMotionListener() { - - public void mouseDragged(MouseEvent e) { - inputHandler.addMouseEvent(e.getX(), e.getY(), e.getButton() == MouseEvent.NOBUTTON ? false : true); - } - - public void mouseMoved(MouseEvent e) { - inputHandler.addMouseEvent(e.getX(), e.getY(), e.getButton() == MouseEvent.NOBUTTON ? false : true); - } - }); - offPanel.addMouseListener(new MouseListener() { - - public void mouseClicked(MouseEvent e) { - } - - public void mousePressed(MouseEvent e) { - inputHandler.addMouseEvent(e.getX(), e.getY(), e.getButton() == MouseEvent.NOBUTTON ? false : true); - } - - public void mouseReleased(MouseEvent e) { - } - - public void mouseEntered(MouseEvent e) { - } - - public void mouseExited(MouseEvent e) { - } - }); - offPanel.addKeyListener(new KeyListener() { - - public void keyTyped(KeyEvent e) { - } - - public void keyPressed(KeyEvent e) { - inputHandler.addKeyEvent(e.getKeyCode(), e.getKeyChar(), true, e.isShiftDown(), e.isControlDown()); - } - - public void keyReleased(KeyEvent e) { - } - }); - } - - private void preparePreview() { - SceneApplication.getApplication().enqueue(new Callable() { - - public Object call() throws Exception { - ViewPort guiViewPort = offPanel.getViewPort(); - ProjectAssetManager pm = niftyObject.getLookup().lookup(ProjectAssetManager.class); - if (pm == null) { - Logger.getLogger(NiftyPreviewPanel.class.getName()).log(Level.WARNING, "No Project AssetManager found!"); - return null; - } - AudioRenderer audioRenderer = SceneApplication.getApplication().getAudioRenderer(); - niftyDisplay = new NiftyJmeDisplay(pm, - inputHandler, - audioRenderer, - guiViewPort); - nifty = niftyDisplay.getNifty(); - - // attach the nifty display to the gui view port as a processor - guiViewPort.addProcessor(niftyDisplay); - return null; - } - }); - } - - @Override - protected Error validateView() { - return null; - } - - @Override - public void showSelection(Node[] nodes) { - this.screen = nodes[0].getName(); - final String screen = this.screen; - SceneApplication.getApplication().enqueue(new Callable() { - - public Object call() throws Exception { - nifty.gotoScreen(screen); - return null; - } - }); - } - - public void cleanup() { - offPanel.stopPreview(); - SceneApplication.getApplication().enqueue(new Callable() { - - public Object call() throws Exception { - ViewPort guiViewPort = offPanel.getViewPort(); - guiViewPort.removeProcessor(niftyDisplay); - return null; - } - }); - } - - public void warning(SAXParseException exception) throws SAXException { - //errors.addWarning("Line " + exception.getLineNumber() + " : " + exception.getMessage()); - } - - public void error(SAXParseException exception) throws SAXException { - //errors.addError("Line " + exception.getLineNumber() + " : " + exception.getMessage()); - } - - public void fatalError(SAXParseException exception) throws SAXException { - //errors.addError("Line " + exception.getLineNumber() + " : " + exception.getMessage()); - } -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyScreenNode.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyScreenNode.java deleted file mode 100644 index f6a9fa08f..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyScreenNode.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.jme3.gde.gui.multiview; - -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; - -/** - * - * @author normenhansen - */ -public class NiftyScreenNode extends AbstractNode{ - - public NiftyScreenNode(String name) { - super(Children.LEAF); - setName(name); - } - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/PreviewToolbarElement.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/PreviewToolbarElement.java deleted file mode 100644 index 80e9416e7..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/PreviewToolbarElement.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.jme3.gde.gui.multiview; - -import com.jme3.gde.gui.NiftyGuiDataObject; -import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement; -import org.netbeans.modules.xml.multiview.ui.SectionView; -import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor; -import org.openide.nodes.Node; - -/** - * - * @author normenhansen - */ -public class PreviewToolbarElement extends ToolBarMultiViewElement { -// private NiftyGuiDataObject dObj; - private ToolBarDesignEditor comp; - private NiftyPreviewPanel viewPanel; - - public PreviewToolbarElement(NiftyGuiDataObject dObj) { - super(dObj); -// this.dObj = dObj; - comp = new ToolBarDesignEditor(); - setVisualEditor(comp); - viewPanel=new NiftyPreviewPanel(dObj, comp); - } - - @Override - public SectionView getSectionView() { - return null; - } - - @Override - public void componentShowing() { - super.componentShowing(); - viewPanel.updatePreView(); - } - - @Override - public void componentClosed() { - super.componentClosed(); - viewPanel.cleanup(); - } - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/PreviewView.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/PreviewView.java deleted file mode 100644 index 989f14e42..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/PreviewView.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.jme3.gde.gui.multiview; - -import com.jme3.gde.gui.NiftyGuiDataObject; -import org.netbeans.modules.xml.multiview.DesignMultiViewDesc; - -/** - * - * @author normenhansen - */ -public class PreviewView extends DesignMultiViewDesc { - - private int type; - - public PreviewView(NiftyGuiDataObject dObj, int type) { - super(dObj, "Design"); - this.type = type; - } - - public org.netbeans.core.spi.multiview.MultiViewElement createElement() { - NiftyGuiDataObject dObj = (NiftyGuiDataObject) getDataObject(); - return new PreviewToolbarElement(dObj); - } - - public java.awt.Image getIcon() { - return org.openide.util.Utilities.loadImage("com/jme3/gde/gui/Computer_File_043.gif"); //NOI18N - } - - public String preferredID() { - return "Toc_multiview_design" + String.valueOf(type); - } -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/XmlHelper.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/XmlHelper.java deleted file mode 100644 index b58865d7c..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/XmlHelper.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.jme3.gde.gui.multiview; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * - * @author normenhansen - */ -public class XmlHelper { - public static Element findFirstChildElement(Element parent) { - org.w3c.dom.Node ret = parent.getFirstChild(); - while (ret != null && (!(ret instanceof Element))) { - ret = ret.getNextSibling(); - } - return (Element) ret; - } - - public static Element findChildElement(Element parent, String name) { - if (parent == null) { - return null; - } - org.w3c.dom.Node ret = parent.getFirstChild(); - while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name))) { - ret = ret.getNextSibling(); - } - return (Element) ret; - } - - public static Element findNextElement(Node ret, String name) { - ret = ret.getNextSibling(); - while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name))) { - ret = ret.getNextSibling(); - } - return (Element) ret; - } - - public static Element findChildElementWithAttribute(Element parent, String name, String attribute, String value) { - if (parent == null) { - return null; - } - org.w3c.dom.Node ret = parent.getFirstChild(); - while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name) || ((Element)ret).getAttribute(attribute)==null || !((Element)ret).getAttribute(attribute).equals(value))) { - ret = ret.getNextSibling(); - } - return (Element) ret; - } - - public static Element findNextElementWithAttribute(Node ret, String name, String attribute, String value) { - ret = ret.getNextSibling(); - while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name) || ((Element)ret).getAttribute(attribute)==null || !((Element)ret).getAttribute(attribute).equals(value))) { - ret = ret.getNextSibling(); - } - return (Element) ret; - } - - public static Element findNextSiblingElement(Element current) { - org.w3c.dom.Node ret = current.getNextSibling(); - while (ret != null) { - if (ret instanceof Element) { - return (Element) ret; - } - ret = ret.getNextSibling(); - } - return null; - } - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/Computer_File_043.gif b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/Computer_File_043.gif similarity index 100% rename from sdk/jme3-gui/src/com/jme3/gde/gui/Computer_File_043.gif rename to sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/Computer_File_043.gif diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GButton.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GButton.png new file mode 100644 index 000000000..32a4eeb71 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GButton.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GChat.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GChat.png new file mode 100644 index 000000000..1af30643f Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GChat.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GCheckbox.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GCheckbox.png new file mode 100644 index 000000000..07f3522a9 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GCheckbox.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GConsole.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GConsole.png new file mode 100644 index 000000000..c18df24f9 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GConsole.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDraggable.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDraggable.png new file mode 100644 index 000000000..172881f9e Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDraggable.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDropDown.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDropDown.png new file mode 100644 index 000000000..53d306e74 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDropDown.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDroppable.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDroppable.png new file mode 100644 index 000000000..fd7eb0a93 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GDroppable.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GHSlider.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GHSlider.png new file mode 100644 index 000000000..b012f5ce8 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GHSlider.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GImage.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GImage.png new file mode 100644 index 000000000..8f0717244 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GImage.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GImageSelect.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GImageSelect.png new file mode 100644 index 000000000..ef098a88a Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GImageSelect.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GLable.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GLable.png new file mode 100644 index 000000000..2fc5ccc4f Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GLable.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GLayer.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GLayer.png new file mode 100644 index 000000000..bc86e400b Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GLayer.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GListBox.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GListBox.png new file mode 100644 index 000000000..60a8db537 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GListBox.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GPanel.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GPanel.png new file mode 100644 index 000000000..92ea52a6b Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GPanel.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GRadioButton.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GRadioButton.png new file mode 100644 index 000000000..f83a25496 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GRadioButton.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GRadioGroup.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GRadioGroup.png new file mode 100644 index 000000000..1d27c7cc7 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GRadioGroup.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GScreen.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GScreen.png new file mode 100644 index 000000000..6f28049b7 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GScreen.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GScrollPanel.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GScrollPanel.png new file mode 100644 index 000000000..e1e6951b7 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GScrollPanel.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GTextfield.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GTextfield.png new file mode 100644 index 000000000..7fc1c7f7e Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GTextfield.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GTree.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GTree.png new file mode 100644 index 000000000..351866942 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GTree.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GVSlider.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GVSlider.png new file mode 100644 index 000000000..1b0dbc588 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GVSlider.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GWindow.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GWindow.png new file mode 100644 index 000000000..ea60171bd Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/GWindow.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/control.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/control.png new file mode 100644 index 000000000..efc599dcc Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/control.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/game-monitor.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/game-monitor.png new file mode 100644 index 000000000..fdb0219be Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/game-monitor.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/gui-icon.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/gui-icon.png new file mode 100644 index 000000000..b69761479 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/gui-icon.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/style.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/style.png new file mode 100644 index 000000000..df7ccc11e Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/style.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/ui-scroll-bar-horizontal.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/ui-scroll-bar-horizontal.png new file mode 100644 index 000000000..f93ed8f80 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/ui-scroll-bar-horizontal.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/ui-scroll-bar.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/ui-scroll-bar.png new file mode 100644 index 000000000..709605a0b Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/ui-scroll-bar.png differ diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GElementChildFactory.java b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GElementChildFactory.java new file mode 100644 index 000000000..608d7e15d --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GElementChildFactory.java @@ -0,0 +1,34 @@ +package com.jme3.gde.gui.nodes; + + +import jada.ngeditor.model.elements.GElement; +import java.util.List; +import java.util.Observable; +import java.util.Observer; +import org.openide.nodes.ChildFactory; +import org.openide.nodes.Node; + +public class GElementChildFactory extends ChildFactory implements Observer{ + private final GElement parent; + + public GElementChildFactory(GElement parent) { + this.parent = parent; + this.parent.addObserver(this); + + } + @Override + protected boolean createKeys(List list) { + list.addAll(parent.getElements()); + return true; + } + + @Override + protected Node createNodeForKey(GElement element) { + return new GElementNode(element); + } + + @Override + public void update(Observable o, Object arg) { + this.refresh(true); + } +} \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GElementNode.java b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GElementNode.java new file mode 100644 index 000000000..1fee94ffd --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GElementNode.java @@ -0,0 +1,158 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.nodes; + +import com.jme3.gde.gui.propertyeditors.ResourceEditor; +import com.jme3.gde.gui.propertyeditors.SizeEditor; +import jada.ngeditor.controller.CommandProcessor; +import jada.ngeditor.controller.commands.EditAttributeCommand; +import jada.ngeditor.controller.commands.VisibilityCommand; +import jada.ngeditor.model.elements.GElement; +import java.awt.event.ActionEvent; +import java.beans.PropertyEditor; +import java.lang.reflect.InvocationTargetException; +import java.util.Map.Entry; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JOptionPane; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.nodes.Sheet; +import org.openide.util.Exceptions; +import sun.beans.editors.BoolEditor; +import sun.beans.editors.BooleanEditor; + +/** + * + * @author cris + */ +public class GElementNode extends AbstractNode{ + private final GElement element; + private static final String basePath="com/jme3/gde/gui/multiview/icons"; + public GElementNode(GElement element) { + super(Children.create(new GElementChildFactory(element), false)); + + this.element = element; + this.setName(element.getID()); + String name = this.element.getClass().getSimpleName(); + this.setName(name); + this.setIconBaseWithExtension(basePath+"/"+name+".png"); + + } + + public GElement getGelement(){ + return element; + } + + @Override + public Action[] getActions(boolean context) { + if(!context){ + return new Action[]{new Visibility("Show", true),new Visibility("Hide", false)}; + }else + return super.getActions(context); + } + + public void updateChildren(){ + + } + @Override + protected Sheet createSheet() { + Sheet s = super.createSheet(); + Sheet.Set set = s.get(Sheet.PROPERTIES); + if (set == null) { + set = Sheet.createPropertiesSet(); + s.put(set); + } + set.setName("Element Properties"); + set.setShortDescription("You can set element properties"); + for(Entry pair : this.element.listAttributes().entrySet()){ + final ElementAttributeProperty elementAttributeProperty = new ElementAttributeProperty(element,pair.getKey()); + pickEditor(pair, elementAttributeProperty); + set.put(elementAttributeProperty); + } + s.put(set); + return s; + } + + private void pickEditor(Entry pair, final ElementAttributeProperty elementAttributeProperty) { + if(pair.getKey().equals("width")||pair.getKey().equals("height") || pair.getKey().equals("x") || pair.getKey().equals("y") ){ + elementAttributeProperty.setPropertyEditor(new SizeEditor()); + }else if(pair.getKey().equals("filename") || pair.getKey().equals("backgroundImage")){ + elementAttributeProperty.setPropertyEditor(new ResourceEditor()); + } + + } + + public class ElementAttributeProperty extends Node.Property { + + private String attributeName; + private GElement element; + private PropertyEditor editor; + + public ElementAttributeProperty(GElement element, String attributeName) { + super(String.class); + this.element = element; + this.attributeName = attributeName; + this.setName(attributeName); + this.setDisplayName(attributeName); + + } + + @Override + public boolean canRead() { + return true; + } + + @Override + public String getValue() throws IllegalAccessException, InvocationTargetException{ + return element.getAttribute(attributeName); + } + + @Override + public boolean canWrite() { + return true; + } + + public void setPropertyEditor(PropertyEditor editor){ + this.editor = editor; + } + @Override + public PropertyEditor getPropertyEditor() { + + return this.editor; //To change body of generated methods, choose Tools | Templates. + } + + + + @Override + public void setValue(Object val) throws IllegalAccessException, IllegalArgumentException { + try { + EditAttributeCommand command = CommandProcessor.getInstance().getCommand(EditAttributeCommand.class); + command.setAttribute(attributeName); + command.setValue(val.toString()); + CommandProcessor.getInstance().excuteCommand(command); + } catch (Exception ex) { + JOptionPane.showMessageDialog(null, ex); + } + + } + }; + + private class Visibility extends AbstractAction { + private final boolean param; + + public Visibility(String name ,boolean param) { + super(name); + this.param = param; + } + + @Override + public void actionPerformed(ActionEvent e) { + VisibilityCommand command = CommandProcessor.getInstance().getCommand(VisibilityCommand.class); + command.setVisibility(param); + } + } +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUINode.java b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUINode.java new file mode 100644 index 000000000..35e33bae0 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUINode.java @@ -0,0 +1,125 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.nodes; + +import jada.ngeditor.model.GUI; +import jada.ngeditor.model.elements.specials.GUseControls; +import jada.ngeditor.model.elements.specials.GUseStyle; +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.IOException; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; + +/** + * + * @author cris + */ +public class GUINode extends AbstractNode{ + private final GUI gui; + private static final String basePath="com/jme3/gde/gui/multiview/icons"; + public GUINode(GUI gui) { + super(Children.create(new ScreenChildFactory(gui),false)); + this.gui = gui; + this.setIconBaseWithExtension(basePath+"/"+"game-monitor"+".png"); + + } + + /** + * @return the gui + */ + public GUI getGui() { + return gui; + } + + @Override + public Action[] getActions(boolean context) { + if(true){ + return new Action[]{new AddStyleAction(),new AddControlAction()}; //To change body of generated methods, choose Tools | Templates. + }else + return super.getActions(); + } + + + + @Override + public String getName() { + return super.getName()+" "+this.gui; //To change body of generated methods, choose Tools | Templates. + } + + private class AddStyleAction extends AbstractAction { + + public AddStyleAction() { + super("Add style"); + } + + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser chooser = new JFileChooser(gui.getAssetFolder()); + int result = chooser.showSaveDialog(null); + if(result == JFileChooser.APPROVE_OPTION){ + GUseStyle style = new GUseStyle(); + + + style.setFilename(createReletive(chooser.getSelectedFile())); + gui.addLoadUseStyle(style); + + + } + } + + } + private class AddControlAction extends AbstractAction { + + public AddControlAction() { + super("Add Control"); + } + + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser chooser = new JFileChooser(gui.getAssetFolder()); + int result = chooser.showSaveDialog(null); + if(result == JFileChooser.APPROVE_OPTION){ + GUseControls controls = new GUseControls(); + + + controls.setFilename(createReletive(chooser.getSelectedFile())); + gui.addLoadUseControls(controls); + + + } + } + + + + } + + private String createReletive(File selected) { + File assets = gui.getAssetFolder(); + String res = ""; + String parentPath = selected.getParent(); + String absAssets = assets.getAbsolutePath(); + if (!parentPath.contains(absAssets)) { + try { + absAssets = assets.getCanonicalPath(); + if (!parentPath.contains(absAssets)) { + JOptionPane.showMessageDialog(null, "Sorry you can't relativize this file. Tip : the file must be inside the assets folder"); + } else { + res = assets.toURI().relativize(selected.toURI()).getPath(); + } + } catch (IOException ex) { + JOptionPane.showMessageDialog(null, "Sorry you can't relativize this file"); + } + } else { + res = assets.toURI().relativize(selected.toURI()).getPath(); + } + return res; + } + +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUseControlsNode.java b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUseControlsNode.java new file mode 100644 index 000000000..5efe64f8f --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUseControlsNode.java @@ -0,0 +1,20 @@ +package com.jme3.gde.gui.nodes; + +import jada.ngeditor.model.GUI; +import jada.ngeditor.model.elements.specials.GUseControls; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; + +public class GUseControlsNode extends AbstractNode { + private static final String basePath="com/jme3/gde/gui/multiview/icons"; + private final GUseControls controls; + + public GUseControlsNode(GUI gui,GUseControls controls) { + super(Children.LEAF); + this.setIconBaseWithExtension(basePath+"/"+"control"+".png"); + this.controls = controls; + this.setName(controls.getFilename()); + } + + +} \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUseStyleNode.java b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUseStyleNode.java new file mode 100644 index 000000000..9e0b7314f --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/GUseStyleNode.java @@ -0,0 +1,55 @@ +package com.jme3.gde.gui.nodes; + +import jada.ngeditor.model.GUI; +import jada.ngeditor.model.elements.specials.GUseStyle; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import javax.swing.Action; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; + +public class GUseStyleNode extends AbstractNode { + private static final String basePath="com/jme3/gde/gui/multiview/icons"; + private final GUI gui; + private final GUseStyle style; + + public GUseStyleNode(GUI gui,GUseStyle style) { + super(Children.LEAF); + this.setIconBaseWithExtension(basePath+"/"+"style"+".png"); + this.gui = gui; + this.style = style; + this.setName(style.getFilename()); + } + + @Override + public Action[] getActions(boolean context) { + return new Action[]{new Refresh(),new Delete()}; + } + + private class Refresh extends AbstractAction { + + public Refresh() { + super("Refresh"); + } + + @Override + public void actionPerformed(ActionEvent e) { + gui.reoloadStyles(style.getFilename()); + } + } + + private class Delete extends AbstractAction { + + public Delete() { + super("Delete"); + } + + @Override + public void actionPerformed(ActionEvent e) { + gui.removeStyle(style); + } + } + + + +} \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/ScreenChildFactory.java b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/ScreenChildFactory.java new file mode 100644 index 000000000..9d43f2f63 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/nodes/ScreenChildFactory.java @@ -0,0 +1,55 @@ +package com.jme3.gde.gui.nodes; + + +import jada.ngeditor.listeners.events.ElementEvent; +import jada.ngeditor.model.GUI; +import jada.ngeditor.model.elements.GElement; +import jada.ngeditor.model.elements.GScreen; +import jada.ngeditor.model.elements.specials.GUseControls; +import jada.ngeditor.model.elements.specials.GUseStyle; +import java.util.List; +import java.util.Observable; +import java.util.Observer; +import org.openide.nodes.ChildFactory; +import org.openide.nodes.Node; + +public class ScreenChildFactory extends ChildFactory implements Observer{ + private final GUI gui; + + public ScreenChildFactory(GUI gui){ + this.gui = gui; + this.gui.addObserver(ScreenChildFactory.this); + + } + @Override + protected boolean createKeys(List list) { + list.addAll(gui.getUseStyles()); + list.addAll(gui.getUseControls()); + list.addAll(gui.getScreens()); + + + return true; + } + + @Override + protected Node createNodeForKey(Object node) { + if(node instanceof GElement){ + return new GElementNode((GElement)node); + }else if (node instanceof GUseStyle){ + return new GUseStyleNode(gui, (GUseStyle)node); + }else + return new GUseControlsNode(gui,(GUseControls)node); + } + + @Override + public void update(Observable o, Object arg) { + if(arg == null){ + this.refresh(true); + }else{ + ElementEvent e = (ElementEvent) arg; + if(e.getElement() instanceof GScreen){ + this.refresh(true); + } + } + } +} \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/package-info.java b/sdk/jme3-gui/src/com/jme3/gde/gui/package-info.java new file mode 100644 index 000000000..a95406a1f --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/package-info.java @@ -0,0 +1,13 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +@TemplateRegistrations(value = {@TemplateRegistration(folder = "GUI", displayName = "Empty Gui",content = "templates/EmptyNiftyGui.xml",iconBase = "com/jme3/gde/gui/multiview/icons/gui-icon.png"), +@TemplateRegistration(folder = "GUI", displayName = "HelloJme",content = "templates/NiftyGui.xml",iconBase = "com/jme3/gde/gui/multiview/icons/game-monitor.png"), +@TemplateRegistration(folder = "GUI", displayName = "Empty Style",content = "templates/EmptyStyle.xml",iconBase = "com/jme3/gde/gui/multiview/icons/style.png"), +@TemplateRegistration(folder = "GUI", displayName = "Empty Control",content = "templates/EmptyControl.xml",iconBase = "com/jme3/gde/gui/multiview/icons/control.png"), +@TemplateRegistration(folder = "GUI/Control Styles", displayName = "Button Style",content = "examples/buttonstyle.xml",iconBase = "com/jme3/gde/gui/multiview/icons/style.png")}) +package com.jme3.gde.gui; + +import org.netbeans.api.templates.TemplateRegistration; +import org.netbeans.api.templates.TemplateRegistrations; diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/CategoryChildFactory.java b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/CategoryChildFactory.java new file mode 100644 index 000000000..61dda2d50 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/CategoryChildFactory.java @@ -0,0 +1,48 @@ +package com.jme3.gde.gui.palette; + + +import com.google.common.base.Predicate; +import jada.ngeditor.model.elements.GControl; +import jada.ngeditor.model.elements.GElement; +import java.util.List; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.ChildFactory; +import org.openide.nodes.Children; +import org.openide.nodes.Node; + +public class CategoryChildFactory extends ChildFactory { + + @Override + protected boolean createKeys(List list) { + ElementFilter elements = new ElementFilter("Elements") { + @Override + public boolean apply(Class t) { + return t.getGenericSuperclass().equals(GElement.class); + } + }; + list.add(elements); + ElementFilter controls = new ElementFilter("Controls") { + @Override + public boolean apply(Class t) { + return t.getGenericSuperclass().equals(GControl.class); + //To change body of generated methods, choose Tools | Templates. + } + }; + list.add(controls); + return true; + } + + @Override + protected Node createNodeForKey(ElementFilter category) { + return new CategoryNode(category); + } + + public class CategoryNode extends AbstractNode { + public CategoryNode(ElementFilter category) { + super(Children.create(new WidgetChildFactory(category), true)); + setDisplayName(category.getName()); + } + } + + +} \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/ElementFilter.java b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/ElementFilter.java new file mode 100644 index 000000000..dfb06b790 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/ElementFilter.java @@ -0,0 +1,28 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.palette; + +import com.google.common.base.Predicate; + +/** + * + * @author cris + */ +abstract class ElementFilter implements Predicate{ + private final String name; + + public ElementFilter(String name) { + this.name = name; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/JmePaletteUtilities.java b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/JmePaletteUtilities.java deleted file mode 100644 index 9f508b349..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/JmePaletteUtilities.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.gui.palette; - -import javax.swing.text.BadLocationException; -import javax.swing.text.Caret; -import javax.swing.text.Document; -import javax.swing.text.JTextComponent; -import javax.swing.text.StyledDocument; -import org.openide.text.NbDocument; - -public class JmePaletteUtilities { - - public static void insert(final String s,final JTextComponent target) throws BadLocationException { - - final StyledDocument doc = (StyledDocument)target.getDocument(); - - class AtomicChange implements Runnable { - - public void run() { - Document value = target.getDocument(); - if (value == null) - return; - try { - insert(s, target, doc); - } catch (BadLocationException e) {} - } - } - - try { - NbDocument.runAtomicAsUser(doc, new AtomicChange()); - } catch (BadLocationException ex) {} - - } - - private static int insert(String s, JTextComponent target, Document doc) throws BadLocationException { - - int start = -1; - - try { - - //firstly, find selected text range: - Caret caret = target.getCaret(); - int p0 = Math.min(caret.getDot(), caret.getMark()); - int p1 = Math.max(caret.getDot(), caret.getMark()); - doc.remove(p0, p1 - p0); - - //then, replace selected text range with the inserted one: - start = caret.getDot(); - doc.insertString(start, s, null); - - } catch (BadLocationException ble) {} - - return start; - - } - -} \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/NiftyGUIPaletteFactory.java b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/NiftyGUIPaletteFactory.java index 9a8d5f170..340fbf0ce 100644 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/NiftyGUIPaletteFactory.java +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/NiftyGUIPaletteFactory.java @@ -9,13 +9,19 @@ package com.jme3.gde.gui.palette; +import jada.ngeditor.guiviews.DND.WidgetData; import java.io.IOException; import javax.swing.Action; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.spi.palette.DragAndDropHandler; import org.netbeans.spi.palette.PaletteActions; import org.netbeans.spi.palette.PaletteController; import org.netbeans.spi.palette.PaletteFactory; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; import org.openide.util.Exceptions; import org.openide.util.Lookup; +import org.openide.util.datatransfer.ExTransferable; /** * @@ -26,21 +32,21 @@ public class NiftyGUIPaletteFactory { //http://blogs.sun.com/geertjan/entry/convert_your_topcomponent_to_a //http://www.javanb.com/netbeans/1/19785.html - public static final String PALETTE_FOLDER = "NiftyGUIPalette"; + public static final String PALETTE_FOLDER = "NiftyPalette"; private static PaletteController palette = null; public NiftyGUIPaletteFactory() { } - + @MimeRegistration(mimeType = "text/x-niftygui+xml", service = PaletteController.class) public static PaletteController createPalette() { - try { - if (null == palette) - palette = PaletteFactory.createPalette(PALETTE_FOLDER, new MyActions()); + + if (null == palette){ + AbstractNode paletteRoot = new AbstractNode(Children.create(new CategoryChildFactory(), true)); + paletteRoot.setName("Palette Root"); + palette = PaletteFactory.createPalette( paletteRoot,new MyActions(),null,new MyHandler()); + } + return palette; - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - return null; } private static class MyActions extends PaletteActions { @@ -71,5 +77,16 @@ public class NiftyGUIPaletteFactory { } } + + private static class MyHandler extends DragAndDropHandler { + + public MyHandler() { + } + + @Override + public void customize(ExTransferable t, Lookup item) { + t.remove(WidgetData.POINTFLAVOR); + } + } } diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/Screen.java b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/Screen.java deleted file mode 100644 index 5a442cf62..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/Screen.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.gui.palette; -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; -import org.openide.text.ActiveEditorDrop; - -/** - * - * @author normenhansen, zathras - */ -public class Screen implements ActiveEditorDrop { - - public Screen() { - } - - private String createBody() { - - String body = ""; - return body; - } - - public boolean handleTransfer(JTextComponent targetComponent) { - String body = createBody(); - try { - JmePaletteUtilities.insert(body, targetComponent); - } catch (BadLocationException ble) { - return false; - } - return true; - } - -} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/Screen.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/Screen.xml deleted file mode 100644 index 842a60646..000000000 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/Screen.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - Screen - light source (ambient) - - - \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/WidgetChildFactory.java b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/WidgetChildFactory.java new file mode 100644 index 000000000..2da997500 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/WidgetChildFactory.java @@ -0,0 +1,55 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.palette; + +import jada.ngeditor.guiviews.palettecomponents.NWidget; +import jada.ngeditor.model.elements.GControl; +import jada.ngeditor.model.elements.GElement; +import jada.ngeditor.model.utils.ClassUtils; +import java.lang.reflect.Modifier; +import java.util.List; +import java.util.Set; +import org.openide.nodes.ChildFactory; +import org.openide.nodes.Node; + +/** + * + * @author cris + */ +public class WidgetChildFactory extends ChildFactory{ + private final ElementFilter category; + + WidgetChildFactory(ElementFilter category) { + this.category = category; + + } + + @Override + protected boolean createKeys(List toPopulate) { + Set> classes = ClassUtils.findAllGElements(); + for(Class c : classes){ + if(this.isConcreteClass(c) && category.apply(c)){ + toPopulate.add(c); + + } + } + return true; + } + + private boolean isConcreteClass(Class object){ + boolean abs = Modifier.isAbstract( object.getModifiers() ); + return !abs && !object.isAnonymousClass() && GElement.class.isAssignableFrom(object); + } + + @Override + protected Node createNodeForKey(Class key) { + return new WidgetNode(key); + } + + + + + +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/palette/WidgetNode.java b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/WidgetNode.java new file mode 100644 index 000000000..4f6faad23 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/palette/WidgetNode.java @@ -0,0 +1,61 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.palette; + +import jada.ngeditor.guiviews.DND.DragHandler; +import jada.ngeditor.guiviews.DND.TrasferHandling; +import jada.ngeditor.guiviews.DND.WidgetData; +import jada.ngeditor.guiviews.palettecomponents.NWidget; +import jada.ngeditor.model.GUIFactory; +import jada.ngeditor.model.elements.GElement; +import jada.ngeditor.model.exception.NoProductException; +import java.awt.Image; +import java.awt.datatransfer.Transferable; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.util.Exceptions; + +/** + * + * @author cris + */ +public class WidgetNode extends AbstractNode{ + private final Class clazz; + private static final String basePath="com/jme3/gde/gui/multiview/icons"; + + public WidgetNode(Class wrappedClass) { + super(Children.LEAF); + this.clazz = wrappedClass; + String name = wrappedClass.getSimpleName(); + this.setName(name); + this.setIconBaseWithExtension(basePath+"/"+name+".png"); + } + + @Override + public Image getIcon(int type) { + return super.getIcon(type); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Transferable drag() throws IOException { + try { + final GElement gElement = GUIFactory.getInstance().newGElement(clazz); + return new WidgetData(gElement); + } catch (NoProductException ex) { + throw new IOException(ex); + } + } + + + + +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/ResourceEditor.java b/sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/ResourceEditor.java new file mode 100644 index 000000000..805d4da7a --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/ResourceEditor.java @@ -0,0 +1,71 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.propertyeditors; + +import jada.ngeditor.controller.CommandProcessor; +import jada.ngeditor.guiviews.editors.FileChooserEditor; +import jada.ngeditor.model.GuiEditorModel; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditorSupport; +import java.io.File; +import java.util.Observable; +import java.util.Observer; +import javax.swing.JFileChooser; + +/** + * + * @author cris + */ +public class ResourceEditor extends PropertyEditorSupport implements Observer, ActionListener{ + private final FileChooserEditor fileChooserEditor; + private File assetFolder; + + + public ResourceEditor() { + CommandProcessor.getInstance().getObservable().addObserver(this); + + GuiEditorModel model = (GuiEditorModel) CommandProcessor.getInstance().getObservable(); + this.assetFolder = model.getCurrent().getAssetFolder(); + fileChooserEditor = new FileChooserEditor(this.assetFolder); + fileChooserEditor.getFileChooser().addActionListener(this); + } + + + @Override + public Component getCustomEditor() { + + return fileChooserEditor.getFileChooser(); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean supportsCustomEditor() { + return true; //To change body of generated methods, choose Tools | Templates. + } + + + + @Override + public void update(Observable o, Object arg) { + if(o instanceof GuiEditorModel){ + GuiEditorModel model = (GuiEditorModel) o; + this.assetFolder = model.getCurrent().getAssetFolder(); + } + } + + @Override + public void actionPerformed(ActionEvent e) { + if (JFileChooser.APPROVE_SELECTION.equals(e.getActionCommand())) { + this.setValue(fileChooserEditor.traslateFile()); + } + } + + + + +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/SizeEditor.java b/sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/SizeEditor.java new file mode 100644 index 000000000..2abcc6f7b --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/propertyeditors/SizeEditor.java @@ -0,0 +1,59 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.propertyeditors; + +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditorSupport; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; +import javax.swing.JLabel; +import org.openide.explorer.propertysheet.ExPropertyEditor; +import org.openide.explorer.propertysheet.PropertyEnv; + +/** + * + * @author cris + */ +public class SizeEditor extends PropertyEditorSupport implements ExPropertyEditor, PropertyChangeListener{ + private PropertyEnv env; + + @Override + public void setAsText(String text) throws IllegalArgumentException { + super.setAsText(text); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getAsText() { + return super.getAsText(); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Component getCustomEditor() { + jada.ngeditor.guiviews.editors.SizeEditor editor = new jada.ngeditor.guiviews.editors.SizeEditor(); + editor.setValue(this.getValue()); + editor.addPropertyChangeListener(this); + return editor.getComponent(); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean supportsCustomEditor() { + return true; //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void attachEnv(PropertyEnv env) { + this.env = env; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + this.setValue(evt.getNewValue()); + } + + + +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyControl.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyControl.xml new file mode 100644 index 000000000..6f5f044a6 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyControl.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyNiftyGui.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyNiftyGui.xml new file mode 100644 index 000000000..2e51c89de --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyNiftyGui.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyStyle.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyStyle.xml new file mode 100644 index 000000000..3e7f3cab5 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/templates/EmptyStyle.xml @@ -0,0 +1,7 @@ + + + + diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGui.xml b/sdk/jme3-gui/src/com/jme3/gde/gui/templates/NiftyGui.xml similarity index 100% rename from sdk/jme3-gui/src/com/jme3/gde/gui/NiftyGui.xml rename to sdk/jme3-gui/src/com/jme3/gde/gui/templates/NiftyGui.xml diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/view/Navigator.java b/sdk/jme3-gui/src/com/jme3/gde/gui/view/Navigator.java new file mode 100644 index 000000000..7041eacb6 --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/view/Navigator.java @@ -0,0 +1,205 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.view; + +import com.jme3.gde.gui.nodes.GElementNode; +import com.jme3.gde.gui.nodes.GUINode; +import jada.ngeditor.controller.CommandProcessor; +import jada.ngeditor.controller.GUIEditor; +import jada.ngeditor.controller.commands.SelectCommand; +import jada.ngeditor.listeners.events.SelectionChanged; +import jada.ngeditor.model.GUI; +import jada.ngeditor.model.GuiEditorModel; +import jada.ngeditor.model.elements.GElement; +import java.awt.BorderLayout; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.util.ArrayList; +import java.util.Observable; +import java.util.Observer; +import javax.swing.JComponent; +import org.netbeans.spi.navigator.NavigatorPanel; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.ExplorerUtils; +import org.openide.explorer.view.BeanTreeView; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.util.lookup.ProxyLookup; + +/** + * + * @author cris + */ +@NavigatorPanel.Registration(mimeType = "text/x-niftygui+xml", displayName="Gui View") +public class Navigator extends javax.swing.JPanel implements NavigatorPanel,ExplorerManager.Provider , Observer, PropertyChangeListener{ + private Lookup lookup; + private ExplorerManager mgr = new ExplorerManager(); + private final BeanTreeView beanTreeView; + /** + * Creates new form Navigator + */ + public Navigator() { + initComponents(); + setLayout(new BorderLayout()); + beanTreeView = new BeanTreeView(); + add(beanTreeView, BorderLayout.CENTER); + final GuiEditorModel model = (GuiEditorModel) CommandProcessor.getInstance().getObservable(); + model.addObserver(this); + if(model.getCurrent() != null){ + try { + this.intNavigator(model.getCurrent()); + } catch (PropertyVetoException ex) { + Exceptions.printStackTrace(ex); + } + } + + + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 244, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 274, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables + + @Override + public String getDisplayName() { + return "GuiView"; + } + + @Override + public String getDisplayHint() { + return "Easy view for your gui"; + } + + @Override + public JComponent getComponent() { + return this; + } + + @Override + public void panelActivated(Lookup context) { + + } + + @Override + public void panelDeactivated() { + ExplorerUtils.activateActions(mgr, false); + } + + @Override + public Lookup getLookup() { + return lookup; + } + + @Override + public ExplorerManager getExplorerManager() { + return mgr; + } + + @Override + public void update(Observable o, Object arg) { + if(o instanceof GuiEditorModel){ + try { + GuiEditorModel model = (GuiEditorModel) o; + model.getCurrent().addObserver(this); + model.getCurrent().getSelection().addObserver(this); + this.intNavigator(model.getCurrent()); + } catch (PropertyVetoException ex) { + Exceptions.printStackTrace(ex); + } + } + + if(arg instanceof SelectionChanged){ + SelectionChanged event = (SelectionChanged) arg; + if(event.getNewSelection().isEmpty()){ + return; + } + ArrayList path = new ArrayList(); + GElement parent = ((SelectionChanged)arg).getElement(); + while(parent!=null){ + path.add(parent.getID()); + parent = parent.getParent(); + } + Node result = mgr.getRootContext(); + for(int i=path.size()-1;i>=0;i--){ + if(result!=null){ + result = result.getChildren().findChild(path.get(i)); + } + } + try { + if(result!=null){ + mgr.setSelectedNodes(new Node[]{result}); + } + + } catch (PropertyVetoException ex) { + Exceptions.printStackTrace(ex); + } + } + beanTreeView.updateUI(); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) { + Node[] newValue = (Node[]) evt.getNewValue(); + if (newValue.length > 0) { + AbstractNode firstSelected = (AbstractNode) newValue[0]; + if (firstSelected instanceof GElementNode) { + GElement element = ((GElementNode) firstSelected).getGelement(); + GUI gui = ((GUINode)mgr.getRootContext()).getGui(); + gui.getSelection().deleteObserver(this); // I don't wont to get notified about this selection change + SelectCommand command = CommandProcessor.getInstance().getCommand(SelectCommand.class); + command.setElement(element); + try { + CommandProcessor.getInstance().excuteCommand(command); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + } + gui.getSelection().addObserver(this); + + } + } + } + } + + + private void intNavigator(GUI gui) throws PropertyVetoException { + + + ExplorerUtils.activateActions(mgr, true); + + + AbstractNode guiRoot = new GUINode(gui); + guiRoot.setName("Gui"); + this.mgr.setRootContext(guiRoot); + this.beanTreeView.updateUI(); + mgr.addPropertyChangeListener(this); + this.mgr.setSelectedNodes(new Node[]{guiRoot}); + Lookup lookup1 = ExplorerUtils.createLookup(mgr, getActionMap()); + lookup = new ProxyLookup(lookup1); + + } +} diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/view/NiftyGuiVisualElement.java b/sdk/jme3-gui/src/com/jme3/gde/gui/view/NiftyGuiVisualElement.java new file mode 100644 index 000000000..d63f7543e --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/view/NiftyGuiVisualElement.java @@ -0,0 +1,407 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.gui.view; + +import com.jme3.app.Application; +import com.jme3.gde.core.assets.ProjectAssetManager; +import com.jme3.gde.gui.NiftyGuiDataObject; +import com.jme3.gde.gui.nodes.GElementNode; +import com.jme3.gde.gui.nodes.GUINode; +import de.lessvoid.nifty.Nifty; +import jada.ngeditor.controller.CommandProcessor; +import jada.ngeditor.controller.GUIEditor; +import jada.ngeditor.guiviews.DND.PaletteDropTarget; +import jada.ngeditor.guiviews.DND.TrasferHandling; +import jada.ngeditor.guiviews.J2DNiftyView; +import jada.ngeditor.listeners.events.SelectionChanged; +import jada.ngeditor.model.GUI; +import jada.ngeditor.model.GuiEditorModel; +import jada.ngeditor.model.elements.GElement; +import jada.ngeditor.model.elements.GLayer; +import jada.ngeditor.model.exception.NoProductException; +import jada.ngeditor.persistence.GUIWriter; +import java.awt.Dimension; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Observable; +import java.util.Observer; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JToolBar; +import javax.xml.bind.JAXBException; +import javax.xml.parsers.ParserConfigurationException; +import org.netbeans.api.progress.ProgressHandle; +import org.netbeans.api.progress.ProgressHandleFactory; +import org.netbeans.core.spi.multiview.CloseOperationState; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.netbeans.core.spi.multiview.MultiViewElementCallback; +import org.netbeans.spi.actions.AbstractSavable; +import org.openide.awt.UndoRedo; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.ExplorerUtils; +import org.openide.loaders.DataObject; +import org.openide.nodes.Node; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.util.NbBundle.Messages; +import org.openide.util.lookup.AbstractLookup; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.ProxyLookup; +import org.openide.windows.TopComponent; +import org.xml.sax.SAXException; +import sun.rmi.runtime.Log; + +@MultiViewElement.Registration( + displayName = "#LBL_NiftyGui_VISUAL", + iconBase = "com/jme3/gde/gui/multiview/icons/game-monitor.png", + mimeType = "text/x-niftygui+xml", + persistenceType = TopComponent.PERSISTENCE_NEVER, + preferredID = "NiftyGuiVisual", + position = 2000) +@Messages("LBL_NiftyGui_VISUAL=Visual") +public final class NiftyGuiVisualElement extends JPanel implements MultiViewElement , ExplorerManager.Provider,Observer, PropertyChangeListener { + private static final Logger logger = Logger.getLogger(NiftyGuiVisualElement.class.getName()); + private NiftyGuiDataObject obj; + private JToolBar toolbar = new JToolBar(); + private transient MultiViewElementCallback callback; + private GUIEditor editor; + private final Nifty nifty; + private final J2DNiftyView view; + private final JComboBox layers = new JComboBox(); + private final ExplorerManager nodesManager; + private final UndoRedo.Manager undoSupport; + private int guiID; + private final InstanceContent content = new InstanceContent(); + private Lookup lookup; + + public NiftyGuiVisualElement(Lookup lkp) { + obj = lkp.lookup(NiftyGuiDataObject.class); + assert obj != null; + initComponents(); + view = new J2DNiftyView(800, 600); + view.init(); + this.scrollArea.getViewport().addChangeListener(view); + this.scrollArea.setViewportView(view); + TrasferHandling tranf = new TrasferHandling(); + PaletteDropTarget tmp = new PaletteDropTarget(); + editor = obj.getLookup().lookup(GUIEditor.class); + nodesManager = new ExplorerManager(); + nifty = view.getNifty(); + view.setTransferHandler(tranf); + view.setDropTarget(tmp); + // editor.addObserver(view); + // editor.addObserver(tranf); + this.obj.addPropertyChangeListener(this); + this.createToolbar(); + this.undoSupport = new UndoRedo.Manager(); + CommandProcessor.getInstance().setUndoManager(undoSupport); + this.content.set(Collections.singleton(obj.getNodeDelegate()), null); + lookup = new AbstractLookup(content); + } + /** + * Old code + * @author normenhansen + */ + private void createToolbar() { + toolbar.setPreferredSize(new Dimension(10000, 24)); + toolbar.setMaximumSize(new Dimension(10000, 24)); + toolbar.setFloatable(false); + toolbar.add(new JLabel("Change Resolution")); + JComboBox comboBox = new JComboBox(new String[]{"640x480", "480x800", "800x480", "800x600", "1024x768", "1280x720"}); + comboBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + String string = (String) e.getItem(); + if ("640x480".equals(string)) { + view.setResoltion(640, 480); + } else if ("1024x768".equals(string)) { + view.setResoltion(1024, 768); + } else if ("1280x720".equals(string)) { + view.setResoltion(1280, 720); + } else if ("800x600".equals(string)) { + view.setResoltion(800, 600); + } else if ("800x480".equals(string)) { + view.setResoltion(800, 480); + } else if ("480x800".equals(string)) { + view.setResoltion(480, 800); + } else { + view.setResoltion(800, 600); + } + } + }); + toolbar.add(comboBox); + comboBox.setSelectedItem("800x600"); + toolbar.add(new JLabel("Current Layer")); + layers.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + GLayer item = (GLayer) e.getItem(); + editor.selectElement(item); + } + }); + toolbar.add(layers); + } + @Override + public String getName() { + return "NiftyGuiVisualElement"; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + scrollArea = new javax.swing.JScrollPane(); + + setLayout(new java.awt.BorderLayout()); + add(scrollArea, java.awt.BorderLayout.CENTER); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane scrollArea; + // End of variables declaration//GEN-END:variables + @Override + public JComponent getVisualRepresentation() { + return this; + } + + @Override + public JComponent getToolbarRepresentation() { + return toolbar; + } + + @Override + public Action[] getActions() { + return new Action[0]; + } + + @Override + public Lookup getLookup() { + return this.lookup ; + } + /** + * Raw implementation , just to prototype the editor + */ + @Override + public void componentOpened() { + loadGui(); + } + + @Override + public void componentClosed() { + + } + /** + * Raw implementation , just to prototype the editor + */ + @Override + public void componentShowing() { + if(!this.obj.isModified()){ + return; + } + loadGui(); + + } + /** + * Raw implementation , just to prototype the editor + */ + @Override + public void componentHidden() { + String path = this.obj.getPrimaryFile().getPath(); + try { + this.editor.saveGui(path); + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } catch (JAXBException ex) { + Exceptions.printStackTrace(ex); + } catch (NullPointerException ex){ + Exceptions.printStackTrace(ex); + } + } + + @Override + public void componentActivated() { + try{ + GuiEditorModel model = (GuiEditorModel) CommandProcessor.getInstance().getObservable(); + model.setCurrentGUI(guiID); + model.getCurrent().addObserver(this); + CommandProcessor.getInstance().setUndoManager(undoSupport); + }catch(java.lang.IllegalArgumentException ex){ + logger.log(Level.SEVERE,"Can't load your gui", ex); + } + } + + @Override + public void componentDeactivated() { + } + + @Override + public UndoRedo getUndoRedo() { + return this.undoSupport; + } + + @Override + public void setMultiViewCallback(MultiViewElementCallback callback) { + this.callback = callback; + } + + @Override + public CloseOperationState canCloseElement() { + return CloseOperationState.STATE_OK; + } + + @Override + public ExplorerManager getExplorerManager() { + return nodesManager; + } + + @Override + public void update(Observable o, Object arg) { + if(arg instanceof SelectionChanged ){ + SelectionChanged event = (SelectionChanged) arg; + if(event.getNewSelection().isEmpty()){ + return; + } + GElement parent = event.getElement(); + GElementNode node = new GElementNode(parent); + this.content.set(Collections.singleton(node), null); + + }else if(o instanceof GUI){ + //Add a save. We don't add multible savable because they cointains the same + //information about editing. + GuiSavable savable = this.lookup.lookup(GuiSavable.class); + if(savable == null){ + String path = this.obj.getPrimaryFile().getPath(); + final GuiSavable guiSavable = new NiftyGuiVisualElement.GuiSavable(((GUI)o),path); + this.content.add(guiSavable); + } + } + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if(evt.getPropertyName().equals(DataObject.PROP_MODIFIED)){ + boolean old = (Boolean)evt.getOldValue(); + boolean nev = (Boolean)evt.getNewValue(); + if(old && !nev){ + this.loadGui(); + } + } + + } + + private void loadGui() { + ProgressHandle handle = ProgressHandleFactory.createHandle("Loading the gui file"); + try { + + InputStream is = this.obj.getPrimaryFile().getInputStream(); + handle.start(); + ProjectAssetManager mgr = this.obj.getLookup().lookup(ProjectAssetManager.class); + String assetPath = mgr.getAssetFolder().getPath(); + this.editor.createNewGui(nifty,is,new File(assetPath)); + this.view.newGui(this.editor.getGui()); + nodesManager.setRootContext(new GUINode(this.editor.getGui())); + this.editor.getGui().getSelection().addObserver(this); + Collection layers1 = this.editor.getGui().getLayers(); + guiID = this.editor.getGui().getGUIid(); + this.editor.getGui().addObserver(this); + DefaultComboBoxModel model = new DefaultComboBoxModel(layers1.toArray(new GLayer[0])); + layers.setModel(model); + layers.setSelectedItem(this.editor.getCurrentLayer()); + + handle.finish(); + } catch (ParserConfigurationException ex) { + Exceptions.printStackTrace(ex); + } catch (JAXBException ex) { + Exceptions.printStackTrace(ex); + } catch (ClassNotFoundException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } catch (NoProductException ex) { + Exceptions.printStackTrace(ex); + } catch (SAXException ex) { + Exceptions.printStackTrace(ex); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); + }finally{ + handle.finish(); + } + + + + } + + private class GuiSavable extends AbstractSavable { + private final GUI gui; + + private final String filename; + + public GuiSavable(GUI gui,String filename){ + + this.gui = gui; + this.filename = filename; + this.register(); + + + } + @Override + protected String findDisplayName() { + return "Save "+ this.gui + " changes"; + } + + @Override + protected void handleSave() throws IOException { + try { + GUIWriter writer = new GUIWriter(this.gui); + writer.writeGUI(filename); + NiftyGuiVisualElement.this.content.remove(this); + + + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } catch (JAXBException ex) { + Exceptions.printStackTrace(ex); + } catch (ClassNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + } + + @Override + public boolean equals(Object obj) { + if(obj instanceof com.jme3.gde.gui.view.NiftyGuiVisualElement.GuiSavable){ + return this.gui.equals(((com.jme3.gde.gui.view.NiftyGuiVisualElement.GuiSavable)obj).gui); + } + return false; + } + + @Override + public int hashCode() { + return this.gui.hashCode(); + } + +} +}