UndoSupport, now the editor will reload the gui only if file is changed and some property editors. Also xml auto completition and XmlNavigator
This commit is contained in:
parent
f1071fd05b
commit
ba848391dd
Binary file not shown.
@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
|
<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
|
||||||
<!-- +++++++++++++++++++++++++++++++++++++++ -->
|
<!-- +++++++++++++++++++++++++++++++++++++++ -->
|
||||||
<!-- start screen -->
|
<!-- start screen -->
|
||||||
<!-- +++++++++++++++++++++++++++++++++++++++ -->
|
<!-- +++++++++++++++++++++++++++++++++++++++ -->
|
||||||
<screen id="GScreen0" controller="mygame.Main">
|
<screen id="GScreen0" controller="mygame.Main">
|
||||||
<layer id="GLayer0" childLayout="absolute">
|
<layer id="GLayer0" childLayout="absolute">
|
||||||
</layer>
|
</layer>
|
||||||
</screen>
|
</screen>
|
||||||
</nifty>
|
</nifty>
|
@ -1,191 +1,202 @@
|
|||||||
/*
|
/*
|
||||||
* To change this template, choose Tools | Templates
|
* To change this template, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
package com.jme3.gde.gui;
|
package com.jme3.gde.gui;
|
||||||
|
|
||||||
import com.jme3.gde.gui.nodes.GElementNode;
|
import com.jme3.gde.gui.nodes.GElementNode;
|
||||||
import com.jme3.gde.gui.nodes.ScreenChildFactory;
|
import com.jme3.gde.gui.nodes.GUINode;
|
||||||
import jada.ngeditor.controller.GUIEditor;
|
import com.jme3.gde.gui.nodes.ScreenChildFactory;
|
||||||
import jada.ngeditor.model.elements.GElement;
|
import jada.ngeditor.controller.CommandProcessor;
|
||||||
import java.awt.BorderLayout;
|
import jada.ngeditor.controller.GUIEditor;
|
||||||
import java.beans.PropertyChangeEvent;
|
import jada.ngeditor.controller.commands.SelectCommand;
|
||||||
import java.beans.PropertyChangeListener;
|
import jada.ngeditor.listeners.events.ReloadGuiEvent;
|
||||||
import java.beans.PropertyVetoException;
|
import jada.ngeditor.listeners.events.SelectionChanged;
|
||||||
import java.util.ArrayList;
|
import jada.ngeditor.model.GUI;
|
||||||
import java.util.Observable;
|
import jada.ngeditor.model.GuiEditorModel;
|
||||||
import java.util.Observer;
|
import jada.ngeditor.model.elements.GElement;
|
||||||
import javax.swing.JComponent;
|
import java.awt.BorderLayout;
|
||||||
import org.netbeans.spi.navigator.NavigatorPanel;
|
import java.beans.PropertyChangeEvent;
|
||||||
import org.openide.explorer.ExplorerManager;
|
import java.beans.PropertyChangeListener;
|
||||||
import org.openide.explorer.ExplorerUtils;
|
import java.beans.PropertyVetoException;
|
||||||
import org.openide.explorer.view.BeanTreeView;
|
import java.util.ArrayList;
|
||||||
import org.openide.nodes.AbstractNode;
|
import java.util.Observable;
|
||||||
import org.openide.nodes.Children;
|
import java.util.Observer;
|
||||||
import org.openide.nodes.Node;
|
import javax.swing.JComponent;
|
||||||
import org.openide.util.Exceptions;
|
import org.netbeans.spi.navigator.NavigatorPanel;
|
||||||
import org.openide.util.Lookup;
|
import org.openide.explorer.ExplorerManager;
|
||||||
import org.openide.util.LookupEvent;
|
import org.openide.explorer.ExplorerUtils;
|
||||||
import org.openide.util.LookupListener;
|
import org.openide.explorer.view.BeanTreeView;
|
||||||
import org.openide.util.Utilities;
|
import org.openide.nodes.AbstractNode;
|
||||||
import org.openide.util.lookup.ProxyLookup;
|
import org.openide.nodes.Children;
|
||||||
import org.openide.windows.TopComponent;
|
import org.openide.nodes.Node;
|
||||||
|
import org.openide.util.Exceptions;
|
||||||
/**
|
import org.openide.util.Lookup;
|
||||||
*
|
import org.openide.util.LookupEvent;
|
||||||
* @author cris
|
import org.openide.util.LookupListener;
|
||||||
*/
|
import org.openide.util.Utilities;
|
||||||
@NavigatorPanel.Registration(mimeType = "text/x-niftygui+xml", displayName="Gui View")
|
import org.openide.util.lookup.ProxyLookup;
|
||||||
public class Navigator extends javax.swing.JPanel implements NavigatorPanel,ExplorerManager.Provider , Observer, PropertyChangeListener, LookupListener{
|
import org.openide.windows.TopComponent;
|
||||||
private Lookup lookup;
|
|
||||||
private ExplorerManager mgr = new ExplorerManager();
|
/**
|
||||||
private final BeanTreeView beanTreeView;
|
*
|
||||||
private GUIEditor editor;
|
* @author cris
|
||||||
private Lookup context;
|
*/
|
||||||
private boolean lock;
|
@NavigatorPanel.Registration(mimeType = "text/x-niftygui+xml", displayName="Gui View")
|
||||||
/**
|
public class Navigator extends javax.swing.JPanel implements NavigatorPanel,ExplorerManager.Provider , Observer, PropertyChangeListener{
|
||||||
* Creates new form Navigator
|
private Lookup lookup;
|
||||||
*/
|
private ExplorerManager mgr = new ExplorerManager();
|
||||||
public Navigator() {
|
private final BeanTreeView beanTreeView;
|
||||||
initComponents();
|
private GUIEditor editor;
|
||||||
setLayout(new BorderLayout());
|
private Lookup context;
|
||||||
beanTreeView = new BeanTreeView();
|
private boolean lock;
|
||||||
add(beanTreeView, BorderLayout.CENTER);
|
/**
|
||||||
|
* Creates new form Navigator
|
||||||
}
|
*/
|
||||||
|
public Navigator() {
|
||||||
/**
|
initComponents();
|
||||||
* This method is called from within the constructor to initialize the form.
|
setLayout(new BorderLayout());
|
||||||
* WARNING: Do NOT modify this code. The content of this method is always
|
beanTreeView = new BeanTreeView();
|
||||||
* regenerated by the Form Editor.
|
add(beanTreeView, BorderLayout.CENTER);
|
||||||
*/
|
CommandProcessor.getInstance().getObservable().addObserver(this);
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
}
|
||||||
private void initComponents() {
|
|
||||||
|
/**
|
||||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
* This method is called from within the constructor to initialize the form.
|
||||||
this.setLayout(layout);
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
layout.setHorizontalGroup(
|
* regenerated by the Form Editor.
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
*/
|
||||||
.addGap(0, 244, Short.MAX_VALUE)
|
@SuppressWarnings("unchecked")
|
||||||
);
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
layout.setVerticalGroup(
|
private void initComponents() {
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
||||||
.addGap(0, 274, Short.MAX_VALUE)
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||||
);
|
this.setLayout(layout);
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
layout.setHorizontalGroup(
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
// End of variables declaration//GEN-END:variables
|
.addGap(0, 244, Short.MAX_VALUE)
|
||||||
|
);
|
||||||
@Override
|
layout.setVerticalGroup(
|
||||||
public String getDisplayName() {
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
return "GuiView";
|
.addGap(0, 274, Short.MAX_VALUE)
|
||||||
}
|
);
|
||||||
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
@Override
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
public String getDisplayHint() {
|
// End of variables declaration//GEN-END:variables
|
||||||
return "Easy view for your gui";
|
|
||||||
}
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
@Override
|
return "GuiView";
|
||||||
public JComponent getComponent() {
|
}
|
||||||
return this;
|
|
||||||
}
|
@Override
|
||||||
|
public String getDisplayHint() {
|
||||||
@Override
|
return "Easy view for your gui";
|
||||||
public void panelActivated(Lookup context) {
|
}
|
||||||
try {
|
|
||||||
this.context = context;
|
@Override
|
||||||
context.lookupResult(NiftyGuiDataObject.class).addLookupListener(this);
|
public JComponent getComponent() {
|
||||||
intNavigator(context);
|
return this;
|
||||||
} catch (PropertyVetoException ex) {
|
}
|
||||||
Exceptions.printStackTrace(ex);
|
|
||||||
}
|
@Override
|
||||||
}
|
public void panelActivated(Lookup context) {
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void panelDeactivated() {
|
|
||||||
ExplorerUtils.activateActions(mgr, false);
|
@Override
|
||||||
}
|
public void panelDeactivated() {
|
||||||
|
ExplorerUtils.activateActions(mgr, false);
|
||||||
@Override
|
}
|
||||||
public Lookup getLookup() {
|
|
||||||
return lookup;
|
@Override
|
||||||
}
|
public Lookup getLookup() {
|
||||||
|
return lookup;
|
||||||
@Override
|
}
|
||||||
public ExplorerManager getExplorerManager() {
|
|
||||||
return mgr;
|
@Override
|
||||||
}
|
public ExplorerManager getExplorerManager() {
|
||||||
|
return mgr;
|
||||||
@Override
|
}
|
||||||
public void update(Observable o, Object arg) {
|
|
||||||
|
@Override
|
||||||
jada.ngeditor.listeners.actions.Action act = ( jada.ngeditor.listeners.actions.Action) arg;
|
public void update(Observable o, Object arg) {
|
||||||
if(act.getType() == jada.ngeditor.listeners.actions.Action.SEL){
|
if(o instanceof GuiEditorModel){
|
||||||
ArrayList<String> path = new ArrayList<String>();
|
try {
|
||||||
GElement parent = act.getGUIElement();
|
GuiEditorModel model = (GuiEditorModel) o;
|
||||||
while(parent!=null){
|
model.getCurrent().addObserver(this);
|
||||||
path.add(parent.getID());
|
model.getCurrent().getSelection().addObserver(this);
|
||||||
parent = parent.getParent();
|
this.intNavigator(model.getCurrent());
|
||||||
}
|
} catch (PropertyVetoException ex) {
|
||||||
Node result = mgr.getRootContext();
|
Exceptions.printStackTrace(ex);
|
||||||
for(int i=path.size()-1;i>=0;i--){
|
}
|
||||||
result = result.getChildren().findChild(path.get(i));
|
}
|
||||||
}
|
|
||||||
try {
|
if(arg instanceof SelectionChanged){
|
||||||
mgr.setSelectedNodes(new Node[]{result});
|
SelectionChanged event = (SelectionChanged) arg;
|
||||||
} catch (PropertyVetoException ex) {
|
if(event.getNewSelection().isEmpty()){
|
||||||
Exceptions.printStackTrace(ex);
|
return;
|
||||||
}
|
}
|
||||||
}else if(act.getType() == jada.ngeditor.listeners.actions.Action.NEW){
|
ArrayList<String> path = new ArrayList<String>();
|
||||||
try {
|
GElement parent = ((SelectionChanged)arg).getElement();
|
||||||
this.intNavigator(context);
|
while(parent!=null){
|
||||||
} catch (PropertyVetoException ex) {
|
path.add(parent.getID());
|
||||||
Exceptions.printStackTrace(ex);
|
parent = parent.getParent();
|
||||||
}
|
}
|
||||||
}
|
Node result = mgr.getRootContext();
|
||||||
beanTreeView.updateUI();
|
for(int i=path.size()-1;i>=0;i--){
|
||||||
}
|
result = result.getChildren().findChild(path.get(i));
|
||||||
|
}
|
||||||
@Override
|
try {
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
mgr.setSelectedNodes(new Node[]{result});
|
||||||
if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
|
} catch (PropertyVetoException ex) {
|
||||||
Node[] newValue = (Node[]) evt.getNewValue();
|
Exceptions.printStackTrace(ex);
|
||||||
if (newValue.length > 0) {
|
}
|
||||||
AbstractNode firstSelected = (AbstractNode) newValue[0];
|
}
|
||||||
if (firstSelected instanceof GElementNode) {
|
beanTreeView.updateUI();
|
||||||
GElement element = ((GElementNode) firstSelected).getGelement();
|
}
|
||||||
|
|
||||||
editor.selectElement(element);
|
@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) {
|
||||||
@Override
|
GElement element = ((GElementNode) firstSelected).getGelement();
|
||||||
public void resultChanged(LookupEvent ev) {
|
GUI gui = ((GUINode)mgr.getRootContext()).getGui();
|
||||||
try {
|
gui.getSelection().deleteObserver(this); // I don't wont to get notified about this selection change
|
||||||
intNavigator(context);
|
SelectCommand command = CommandProcessor.getInstance().getCommand(SelectCommand.class);
|
||||||
} catch (PropertyVetoException ex) {
|
command.setElement(element);
|
||||||
Exceptions.printStackTrace(ex);
|
try {
|
||||||
}
|
lock = true;
|
||||||
}
|
CommandProcessor.getInstance().excuteCommand(command);
|
||||||
|
} catch (Exception ex) {
|
||||||
private void intNavigator(Lookup context) throws PropertyVetoException {
|
Exceptions.printStackTrace(ex);
|
||||||
|
}
|
||||||
NiftyGuiDataObject man = context.lookup(NiftyGuiDataObject.class);
|
gui.getSelection().addObserver(this);
|
||||||
ExplorerUtils.activateActions(mgr, true);
|
|
||||||
editor = man.getLookup().lookup(GUIEditor.class);
|
}
|
||||||
AbstractNode guiRoot = new AbstractNode(Children.create(new ScreenChildFactory(editor.getGui()), true));
|
}
|
||||||
guiRoot.setName("Gui");
|
}
|
||||||
this.mgr.setRootContext(guiRoot);
|
}
|
||||||
this.beanTreeView.updateUI();
|
|
||||||
mgr.addPropertyChangeListener(this);
|
|
||||||
this.mgr.setSelectedNodes(new Node[]{guiRoot});
|
private void intNavigator(GUI gui) throws PropertyVetoException {
|
||||||
Lookup lookup1 = ExplorerUtils.createLookup(mgr, getActionMap());
|
|
||||||
lookup = new ProxyLookup(lookup1);
|
|
||||||
editor.addObserver(this);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,148 +1,149 @@
|
|||||||
/*
|
/*
|
||||||
* To change this template, choose Tools | Templates
|
* To change this template, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
package com.jme3.gde.gui;
|
package com.jme3.gde.gui;
|
||||||
|
|
||||||
import com.jme3.gde.core.assets.ProjectAssetManager;
|
import com.jme3.gde.core.assets.ProjectAssetManager;
|
||||||
import jada.ngeditor.controller.GUIEditor;
|
import jada.ngeditor.controller.CommandProcessor;
|
||||||
import java.io.IOException;
|
import jada.ngeditor.controller.GUIEditor;
|
||||||
import org.netbeans.api.project.Project;
|
import java.io.IOException;
|
||||||
import org.netbeans.api.project.ProjectManager;
|
import org.netbeans.api.project.Project;
|
||||||
import org.netbeans.core.spi.multiview.MultiViewElement;
|
import org.netbeans.api.project.ProjectManager;
|
||||||
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
|
import org.netbeans.core.spi.multiview.MultiViewElement;
|
||||||
import org.openide.awt.ActionID;
|
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
|
||||||
import org.openide.awt.ActionReference;
|
import org.openide.awt.ActionID;
|
||||||
import org.openide.awt.ActionReferences;
|
import org.openide.awt.ActionReference;
|
||||||
import org.openide.filesystems.FileObject;
|
import org.openide.awt.ActionReferences;
|
||||||
import org.openide.filesystems.MIMEResolver;
|
import org.openide.filesystems.FileObject;
|
||||||
import org.openide.loaders.DataNode;
|
import org.openide.filesystems.MIMEResolver;
|
||||||
import org.openide.loaders.DataObject;
|
import org.openide.loaders.DataNode;
|
||||||
import org.openide.loaders.DataObjectExistsException;
|
import org.openide.loaders.DataObject;
|
||||||
import org.openide.loaders.MultiDataObject;
|
import org.openide.loaders.DataObjectExistsException;
|
||||||
import org.openide.loaders.MultiFileLoader;
|
import org.openide.loaders.MultiDataObject;
|
||||||
import org.openide.nodes.Children;
|
import org.openide.loaders.MultiFileLoader;
|
||||||
import org.openide.nodes.Node;
|
import org.openide.nodes.Children;
|
||||||
import org.openide.util.Lookup;
|
import org.openide.nodes.Node;
|
||||||
import org.openide.util.NbBundle.Messages;
|
import org.openide.util.Lookup;
|
||||||
import org.openide.windows.TopComponent;
|
import org.openide.util.NbBundle.Messages;
|
||||||
|
import org.openide.windows.TopComponent;
|
||||||
@Messages({
|
|
||||||
"LBL_NiftyGui_LOADER=Files of NiftyGui"
|
@Messages({
|
||||||
})
|
"LBL_NiftyGui_LOADER=Files of NiftyGui"
|
||||||
@MIMEResolver.Registration(
|
})
|
||||||
displayName = "#LBL_NiftyGui_LOADER",
|
@MIMEResolver.Registration(
|
||||||
resource = "NiftyGuiResolver.xml")
|
displayName = "#LBL_NiftyGui_LOADER",
|
||||||
@DataObject.Registration(
|
resource = "NiftyGuiResolver.xml")
|
||||||
mimeType = "text/x-niftygui+xml",
|
@DataObject.Registration(
|
||||||
iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
|
mimeType = "text/x-niftygui+xml",
|
||||||
displayName = "#LBL_NiftyGui_LOADER",
|
iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
|
||||||
position = 300)
|
displayName = "#LBL_NiftyGui_LOADER",
|
||||||
@ActionReferences({
|
position = 300)
|
||||||
@ActionReference(
|
@ActionReferences({
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "System", id = "org.openide.actions.OpenAction"),
|
id =
|
||||||
position = 100,
|
@ActionID(category = "System", id = "org.openide.actions.OpenAction"),
|
||||||
separatorAfter = 200),
|
position = 100,
|
||||||
@ActionReference(
|
separatorAfter = 200),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
|
id =
|
||||||
position = 300),
|
@ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
|
||||||
@ActionReference(
|
position = 300),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
|
id =
|
||||||
position = 400,
|
@ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
|
||||||
separatorAfter = 500),
|
position = 400,
|
||||||
@ActionReference(
|
separatorAfter = 500),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
|
id =
|
||||||
position = 600),
|
@ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
|
||||||
@ActionReference(
|
position = 600),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "System", id = "org.openide.actions.RenameAction"),
|
id =
|
||||||
position = 700,
|
@ActionID(category = "System", id = "org.openide.actions.RenameAction"),
|
||||||
separatorAfter = 800),
|
position = 700,
|
||||||
@ActionReference(
|
separatorAfter = 800),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
|
id =
|
||||||
position = 900,
|
@ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
|
||||||
separatorAfter = 1000),
|
position = 900,
|
||||||
@ActionReference(
|
separatorAfter = 1000),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
|
id =
|
||||||
position = 1100,
|
@ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
|
||||||
separatorAfter = 1200),
|
position = 1100,
|
||||||
@ActionReference(
|
separatorAfter = 1200),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
|
id =
|
||||||
position = 1300),
|
@ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
|
||||||
@ActionReference(
|
position = 1300),
|
||||||
path = "Loaders/text/x-niftygui+xml/Actions",
|
@ActionReference(
|
||||||
id =
|
path = "Loaders/text/x-niftygui+xml/Actions",
|
||||||
@ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
|
id =
|
||||||
position = 1400)
|
@ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
|
||||||
})
|
position = 1400)
|
||||||
public class NiftyGuiDataObject extends MultiDataObject {
|
})
|
||||||
|
public class NiftyGuiDataObject extends MultiDataObject {
|
||||||
public NiftyGuiDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
|
|
||||||
super(pf, loader);
|
public NiftyGuiDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
|
||||||
registerEditor("text/x-niftygui+xml", true);
|
super(pf, loader);
|
||||||
findAssetManager();
|
registerEditor("text/x-niftygui+xml", true);
|
||||||
this.getCookieSet().assign(GUIEditor.class,new GUIEditor());
|
findAssetManager();
|
||||||
}
|
this.getCookieSet().assign(GUIEditor.class, CommandProcessor.getInstance().getGuiEditor());
|
||||||
|
}
|
||||||
protected final void findAssetManager() {
|
|
||||||
FileObject file = getPrimaryFile();
|
protected final void findAssetManager() {
|
||||||
ProjectManager pm = ProjectManager.getDefault();
|
FileObject file = getPrimaryFile();
|
||||||
while (file != null) {
|
ProjectManager pm = ProjectManager.getDefault();
|
||||||
if (file.isFolder() && pm.isProject(file)) {
|
while (file != null) {
|
||||||
try {
|
if (file.isFolder() && pm.isProject(file)) {
|
||||||
Project project = ProjectManager.getDefault().findProject(file);
|
try {
|
||||||
if (project != null) {
|
Project project = ProjectManager.getDefault().findProject(file);
|
||||||
ProjectAssetManager mgr = project.getLookup().lookup(ProjectAssetManager.class);
|
if (project != null) {
|
||||||
if (mgr != null) {
|
ProjectAssetManager mgr = project.getLookup().lookup(ProjectAssetManager.class);
|
||||||
this.getCookieSet().assign(mgr.getClass(),mgr);
|
if (mgr != null) {
|
||||||
return;
|
this.getCookieSet().assign(mgr.getClass(),mgr);
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
}
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IOException ex) {
|
||||||
}
|
} catch (IllegalArgumentException ex) {
|
||||||
}
|
}
|
||||||
file = file.getParent();
|
}
|
||||||
}
|
file = file.getParent();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
protected Node createNodeDelegate() {
|
@Override
|
||||||
DataNode node = new DataNode(this, Children.LEAF, getLookup());
|
protected Node createNodeDelegate() {
|
||||||
node.setIconBaseWithExtension("com/jme3/gde/gui/Computer_File_043.gif");
|
DataNode node = new DataNode(this, Children.LEAF, getLookup());
|
||||||
return node;
|
node.setIconBaseWithExtension("com/jme3/gde/gui/Computer_File_043.gif");
|
||||||
}
|
return node;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
protected int associateLookup() {
|
@Override
|
||||||
return 1;
|
protected int associateLookup() {
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
@MultiViewElement.Registration(
|
|
||||||
displayName = "#LBL_NiftyGui_EDITOR",
|
@MultiViewElement.Registration(
|
||||||
iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
|
displayName = "#LBL_NiftyGui_EDITOR",
|
||||||
mimeType = "text/x-niftygui+xml",
|
iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
|
||||||
persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
|
mimeType = "text/x-niftygui+xml",
|
||||||
preferredID = "NiftyGui",
|
persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
|
||||||
position = 1000)
|
preferredID = "NiftyGui",
|
||||||
@Messages("LBL_NiftyGui_EDITOR=XML")
|
position = 1000)
|
||||||
public static MultiViewEditorElement createEditor(Lookup lkp) {
|
@Messages("LBL_NiftyGui_EDITOR=XML")
|
||||||
final MultiViewEditorElement multiViewEditorElement = new MultiViewEditorElement(lkp);
|
public static MultiViewEditorElement createEditor(Lookup lkp) {
|
||||||
return multiViewEditorElement;
|
final MultiViewEditorElement multiViewEditorElement = new MultiViewEditorElement(lkp);
|
||||||
}
|
return multiViewEditorElement;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -1,332 +1,335 @@
|
|||||||
/*
|
/*
|
||||||
* To change this template, choose Tools | Templates
|
* To change this template, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
package com.jme3.gde.gui;
|
package com.jme3.gde.gui;
|
||||||
|
|
||||||
import com.jme3.gde.core.assets.ProjectAssetManager;
|
import com.jme3.gde.core.assets.ProjectAssetManager;
|
||||||
import com.jme3.gde.core.scene.SceneApplication;
|
import com.jme3.gde.gui.nodes.GUINode;
|
||||||
import com.jme3.gde.gui.nodes.GUINode;
|
import de.lessvoid.nifty.Nifty;
|
||||||
import com.jme3.gde.gui.palette.NiftyGUIPaletteFactory;
|
import jada.ngeditor.controller.CommandProcessor;
|
||||||
import de.lessvoid.nifty.Nifty;
|
import jada.ngeditor.controller.GUIEditor;
|
||||||
import jada.ngeditor.controller.GUIEditor;
|
import jada.ngeditor.guiviews.DND.PaletteDropTarget;
|
||||||
import jada.ngeditor.guiviews.DND.PaletteDropTarget;
|
import jada.ngeditor.guiviews.DND.TrasferHandling;
|
||||||
import jada.ngeditor.guiviews.DND.TrasferHandling;
|
import jada.ngeditor.guiviews.J2DNiftyView;
|
||||||
import jada.ngeditor.guiviews.J2DNiftyView;
|
import jada.ngeditor.listeners.events.SelectionChanged;
|
||||||
import jada.ngeditor.model.elements.GElement;
|
import jada.ngeditor.model.GuiEditorModel;
|
||||||
import jada.ngeditor.model.elements.GLayer;
|
import jada.ngeditor.model.elements.GElement;
|
||||||
import jada.ngeditor.model.exception.NoProductException;
|
import jada.ngeditor.model.elements.GLayer;
|
||||||
import java.awt.Dimension;
|
import jada.ngeditor.model.exception.NoProductException;
|
||||||
import java.awt.dnd.DropTarget;
|
import java.awt.Dimension;
|
||||||
import java.awt.dnd.DropTargetDragEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.dnd.DropTargetDropEvent;
|
import java.awt.event.ItemListener;
|
||||||
import java.awt.dnd.DropTargetEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.awt.dnd.DropTargetListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.awt.event.ItemEvent;
|
import java.beans.PropertyVetoException;
|
||||||
import java.awt.event.ItemListener;
|
import java.io.File;
|
||||||
import java.beans.PropertyVetoException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.File;
|
import java.io.IOException;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.util.ArrayList;
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
import java.util.Collection;
|
import java.util.Observable;
|
||||||
import java.util.Observable;
|
import java.util.Observer;
|
||||||
import java.util.Observer;
|
import javax.swing.Action;
|
||||||
import java.util.concurrent.Callable;
|
import javax.swing.ActionMap;
|
||||||
import javax.swing.Action;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.ActionMap;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JToolBar;
|
||||||
import javax.swing.JToolBar;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.swing.text.AbstractDocument;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.bind.JAXBException;
|
import org.netbeans.api.progress.ProgressHandle;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import org.netbeans.api.progress.ProgressHandleFactory;
|
||||||
import org.netbeans.api.progress.ProgressHandle;
|
import org.netbeans.core.spi.multiview.CloseOperationState;
|
||||||
import org.netbeans.api.progress.ProgressHandleFactory;
|
import org.netbeans.core.spi.multiview.MultiViewElement;
|
||||||
import org.netbeans.core.spi.multiview.CloseOperationState;
|
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
|
||||||
import org.netbeans.core.spi.multiview.MultiViewElement;
|
import org.openide.awt.UndoRedo;
|
||||||
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
|
import org.openide.explorer.ExplorerManager;
|
||||||
import org.openide.DialogDisplayer;
|
import org.openide.explorer.ExplorerUtils;
|
||||||
import org.openide.NotifyDescriptor;
|
import org.openide.loaders.DataObject;
|
||||||
import org.openide.awt.UndoRedo;
|
import org.openide.nodes.Node;
|
||||||
import org.openide.explorer.ExplorerManager;
|
import org.openide.util.Exceptions;
|
||||||
import org.openide.explorer.ExplorerUtils;
|
import org.openide.util.Lookup;
|
||||||
import org.openide.nodes.Node;
|
import org.openide.util.NbBundle.Messages;
|
||||||
import org.openide.util.Exceptions;
|
import org.openide.windows.TopComponent;
|
||||||
import org.openide.util.Lookup;
|
import org.xml.sax.SAXException;
|
||||||
import org.openide.util.NbBundle.Messages;
|
import sun.rmi.runtime.Log;
|
||||||
import org.openide.util.lookup.AbstractLookup;
|
|
||||||
import org.openide.util.lookup.InstanceContent;
|
@MultiViewElement.Registration(
|
||||||
import org.openide.util.lookup.ProxyLookup;
|
displayName = "#LBL_NiftyGui_VISUAL",
|
||||||
import org.openide.windows.TopComponent;
|
iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
|
||||||
import org.xml.sax.SAXException;
|
mimeType = "text/x-niftygui+xml",
|
||||||
|
persistenceType = TopComponent.PERSISTENCE_NEVER,
|
||||||
@MultiViewElement.Registration(
|
preferredID = "NiftyGuiVisual",
|
||||||
displayName = "#LBL_NiftyGui_VISUAL",
|
position = 2000)
|
||||||
iconBase = "com/jme3/gde/gui/Computer_File_043.gif",
|
@Messages("LBL_NiftyGui_VISUAL=Visual")
|
||||||
mimeType = "text/x-niftygui+xml",
|
public final class NiftyGuiVisualElement extends JPanel implements MultiViewElement , ExplorerManager.Provider,Observer, PropertyChangeListener {
|
||||||
persistenceType = TopComponent.PERSISTENCE_NEVER,
|
|
||||||
preferredID = "NiftyGuiVisual",
|
private NiftyGuiDataObject obj;
|
||||||
position = 2000)
|
private JToolBar toolbar = new JToolBar();
|
||||||
@Messages("LBL_NiftyGui_VISUAL=Visual")
|
private transient MultiViewElementCallback callback;
|
||||||
public final class NiftyGuiVisualElement extends JPanel implements MultiViewElement , ExplorerManager.Provider,Observer {
|
private GUIEditor editor;
|
||||||
|
private final Nifty nifty;
|
||||||
private NiftyGuiDataObject obj;
|
private final J2DNiftyView view;
|
||||||
private JToolBar toolbar = new JToolBar();
|
private final JComboBox layers = new JComboBox();
|
||||||
private transient MultiViewElementCallback callback;
|
private final ExplorerManager nodesManager;
|
||||||
private GUIEditor editor;
|
private final UndoRedo.Manager undoSupport;
|
||||||
private final Nifty nifty;
|
private int guiID;
|
||||||
private final J2DNiftyView view;
|
|
||||||
private final JComboBox layers = new JComboBox();
|
|
||||||
private final ExplorerManager nodesManager;
|
public NiftyGuiVisualElement(Lookup lkp) {
|
||||||
|
obj = lkp.lookup(NiftyGuiDataObject.class);
|
||||||
|
assert obj != null;
|
||||||
public NiftyGuiVisualElement(Lookup lkp) {
|
initComponents();
|
||||||
obj = lkp.lookup(NiftyGuiDataObject.class);
|
view = new J2DNiftyView(800, 600);
|
||||||
assert obj != null;
|
view.init();
|
||||||
initComponents();
|
this.scrollArea.getViewport().addChangeListener(view);
|
||||||
view = new J2DNiftyView(800, 600);
|
this.scrollArea.setViewportView(view);
|
||||||
view.init();
|
TrasferHandling tranf = new TrasferHandling();
|
||||||
this.scrollArea.getViewport().addChangeListener(view);
|
PaletteDropTarget tmp = new PaletteDropTarget();
|
||||||
this.scrollArea.setViewportView(view);
|
editor = obj.getLookup().lookup(GUIEditor.class);
|
||||||
TrasferHandling tranf = new TrasferHandling();
|
nodesManager = new ExplorerManager();
|
||||||
PaletteDropTarget tmp = new PaletteDropTarget();
|
nifty = view.getNifty();
|
||||||
editor = obj.getLookup().lookup(GUIEditor.class);
|
view.setTransferHandler(tranf);
|
||||||
editor.addObserver(this);
|
view.setDropTarget(tmp);
|
||||||
nodesManager = new ExplorerManager();
|
// editor.addObserver(view);
|
||||||
nifty = view.getNifty();
|
// editor.addObserver(tranf);
|
||||||
view.setTransferHandler(tranf);
|
this.obj.addPropertyChangeListener(this);
|
||||||
view.setDropTarget(tmp);
|
this.createToolbar();
|
||||||
editor.addObserver(view);
|
this.undoSupport = new UndoRedo.Manager();
|
||||||
editor.addObserver(tranf);
|
CommandProcessor.getInstance().setUndoManager(undoSupport);
|
||||||
editor.addObserver(tmp);
|
}
|
||||||
this.createToolbar();
|
/**
|
||||||
}
|
* Old code
|
||||||
/**
|
* @author normenhansen
|
||||||
* Old code
|
*/
|
||||||
* @author normenhansen
|
private void createToolbar() {
|
||||||
*/
|
toolbar.setPreferredSize(new Dimension(10000, 24));
|
||||||
private void createToolbar() {
|
toolbar.setMaximumSize(new Dimension(10000, 24));
|
||||||
toolbar.setPreferredSize(new Dimension(10000, 24));
|
toolbar.setFloatable(false);
|
||||||
toolbar.setMaximumSize(new Dimension(10000, 24));
|
toolbar.add(new JLabel("Change Resolution"));
|
||||||
toolbar.setFloatable(false);
|
JComboBox comboBox = new JComboBox(new String[]{"640x480", "480x800", "800x480", "800x600", "1024x768", "1280x720"});
|
||||||
JComboBox comboBox = new JComboBox(new String[]{"640x480", "480x800", "800x480", "800x600", "1024x768", "1280x720"});
|
comboBox.addItemListener(new ItemListener() {
|
||||||
comboBox.addItemListener(new ItemListener() {
|
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
public void itemStateChanged(ItemEvent e) {
|
String string = (String) e.getItem();
|
||||||
String string = (String) e.getItem();
|
if ("640x480".equals(string)) {
|
||||||
if ("640x480".equals(string)) {
|
view.setResoltion(640, 480);
|
||||||
view.setResoltion(640, 480);
|
} else if ("1024x768".equals(string)) {
|
||||||
} else if ("1024x768".equals(string)) {
|
view.setResoltion(1024, 768);
|
||||||
view.setResoltion(1024, 768);
|
} else if ("1280x720".equals(string)) {
|
||||||
} else if ("1280x720".equals(string)) {
|
view.setResoltion(1280, 720);
|
||||||
view.setResoltion(1280, 720);
|
} else if ("800x600".equals(string)) {
|
||||||
} else if ("800x600".equals(string)) {
|
view.setResoltion(800, 600);
|
||||||
view.setResoltion(800, 600);
|
} else if ("800x480".equals(string)) {
|
||||||
} else if ("800x480".equals(string)) {
|
view.setResoltion(800, 480);
|
||||||
view.setResoltion(800, 480);
|
} else if ("480x800".equals(string)) {
|
||||||
} else if ("480x800".equals(string)) {
|
view.setResoltion(480, 800);
|
||||||
view.setResoltion(480, 800);
|
} else {
|
||||||
} else {
|
view.setResoltion(800, 600);
|
||||||
view.setResoltion(800, 600);
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
toolbar.add(comboBox);
|
||||||
toolbar.add(comboBox);
|
comboBox.setSelectedItem("800x600");
|
||||||
comboBox.setSelectedItem("800x600");
|
toolbar.add(new JLabel("Current Layer"));
|
||||||
layers.addItemListener(new ItemListener() {
|
layers.addItemListener(new ItemListener() {
|
||||||
|
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
GLayer item = (GLayer) e.getItem();
|
GLayer item = (GLayer) e.getItem();
|
||||||
editor.selectElement(item);
|
editor.selectElement(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toolbar.add(layers);
|
toolbar.add(layers);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "NiftyGuiVisualElement";
|
return "NiftyGuiVisualElement";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* 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
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
* regenerated by the Form Editor.
|
* regenerated by the Form Editor.
|
||||||
*/
|
*/
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents() {
|
private void initComponents() {
|
||||||
|
|
||||||
scrollArea = new javax.swing.JScrollPane();
|
scrollArea = new javax.swing.JScrollPane();
|
||||||
|
|
||||||
setLayout(new java.awt.BorderLayout());
|
setLayout(new java.awt.BorderLayout());
|
||||||
add(scrollArea, java.awt.BorderLayout.CENTER);
|
add(scrollArea, java.awt.BorderLayout.CENTER);
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JScrollPane scrollArea;
|
private javax.swing.JScrollPane scrollArea;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
@Override
|
@Override
|
||||||
public JComponent getVisualRepresentation() {
|
public JComponent getVisualRepresentation() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JComponent getToolbarRepresentation() {
|
public JComponent getToolbarRepresentation() {
|
||||||
return toolbar;
|
return toolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Action[] getActions() {
|
public Action[] getActions() {
|
||||||
return new Action[0];
|
return new Action[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Lookup getLookup() {
|
public Lookup getLookup() {
|
||||||
return ExplorerUtils.createLookup(nodesManager, new ActionMap());
|
return ExplorerUtils.createLookup(nodesManager, new ActionMap());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Raw implementation , just to prototype the editor
|
* Raw implementation , just to prototype the editor
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void componentOpened() {
|
public void componentOpened() {
|
||||||
try {
|
loadGui();
|
||||||
ProgressHandle handle = ProgressHandleFactory.createHandle("Loading the gui file");
|
}
|
||||||
String path = this.obj.getPrimaryFile().getPath();
|
|
||||||
ProjectAssetManager mgr = obj.getLookup().lookup(ProjectAssetManager.class);
|
@Override
|
||||||
String assetPath = mgr.getAssetFolder().getPath();
|
public void componentClosed() {
|
||||||
handle.progress(50);
|
|
||||||
this.editor.createNewGui(nifty,new File(path),new File(assetPath));
|
}
|
||||||
nodesManager.setRootContext(new GUINode(this.editor.getGui()));
|
/**
|
||||||
Collection<GLayer> layers1 = this.editor.getGui().getLayers();
|
* Raw implementation , just to prototype the editor
|
||||||
DefaultComboBoxModel<GLayer> model = new DefaultComboBoxModel<GLayer>(layers1.toArray(new GLayer[0]));
|
*/
|
||||||
layers.setModel(model);
|
@Override
|
||||||
layers.setSelectedItem(this.editor.getCurrentLayer());
|
public void componentShowing() {
|
||||||
|
if(!this.obj.isModified()){
|
||||||
handle.finish();
|
return;
|
||||||
|
}
|
||||||
} catch (ParserConfigurationException ex) {
|
loadGui();
|
||||||
Exceptions.printStackTrace(ex);
|
|
||||||
} catch (JAXBException ex) {
|
}
|
||||||
Exceptions.printStackTrace(ex);
|
/**
|
||||||
} catch (ClassNotFoundException ex) {
|
* Raw implementation , just to prototype the editor
|
||||||
Exceptions.printStackTrace(ex);
|
*/
|
||||||
} catch (IOException ex) {
|
@Override
|
||||||
Exceptions.printStackTrace(ex);
|
public void componentHidden() {
|
||||||
} catch (NoProductException ex) {
|
String path = this.obj.getPrimaryFile().getPath();
|
||||||
Exceptions.printStackTrace(ex);
|
try {
|
||||||
} catch (SAXException ex) {
|
this.editor.saveGui(path);
|
||||||
Exceptions.printStackTrace(ex);
|
} catch (FileNotFoundException ex) {
|
||||||
} catch (Exception ex) {
|
Exceptions.printStackTrace(ex);
|
||||||
Exceptions.printStackTrace(ex);
|
} catch (JAXBException ex) {
|
||||||
}
|
Exceptions.printStackTrace(ex);
|
||||||
}
|
} catch (NullPointerException ex){
|
||||||
|
Exceptions.printStackTrace(ex);
|
||||||
@Override
|
}
|
||||||
public void componentClosed() {
|
}
|
||||||
}
|
|
||||||
/**
|
@Override
|
||||||
* Raw implementation , just to prototype the editor
|
public void componentActivated() {
|
||||||
*/
|
GuiEditorModel model = (GuiEditorModel) CommandProcessor.getInstance().getObservable();
|
||||||
@Override
|
model.setCurrentGUI(guiID);
|
||||||
public void componentShowing() {
|
CommandProcessor.getInstance().setUndoManager(undoSupport);
|
||||||
try {
|
}
|
||||||
ProgressHandle handle = ProgressHandleFactory.createHandle("Loading the gui file");
|
|
||||||
String path = this.obj.getPrimaryFile().getPath();
|
@Override
|
||||||
ProjectAssetManager mgr = this.obj.getLookup().lookup(ProjectAssetManager.class);
|
public void componentDeactivated() {
|
||||||
String assetPath = mgr.getAssetFolder().getPath();
|
}
|
||||||
this.editor.createNewGui(nifty,new File(path),new File(assetPath));
|
|
||||||
nodesManager.setRootContext(new GUINode(this.editor.getGui()));
|
@Override
|
||||||
Collection<GLayer> layers1 = this.editor.getGui().getLayers();
|
public UndoRedo getUndoRedo() {
|
||||||
DefaultComboBoxModel<GLayer> model = new DefaultComboBoxModel<GLayer>(layers1.toArray(new GLayer[0]));
|
return this.undoSupport;
|
||||||
layers.setModel(model);
|
}
|
||||||
layers.setSelectedItem(this.editor.getCurrentLayer());
|
|
||||||
|
@Override
|
||||||
handle.finish();
|
public void setMultiViewCallback(MultiViewElementCallback callback) {
|
||||||
} catch (ParserConfigurationException ex) {
|
this.callback = callback;
|
||||||
Exceptions.printStackTrace(ex);
|
}
|
||||||
} catch (JAXBException ex) {
|
|
||||||
Exceptions.printStackTrace(ex);
|
@Override
|
||||||
} catch (ClassNotFoundException ex) {
|
public CloseOperationState canCloseElement() {
|
||||||
Exceptions.printStackTrace(ex);
|
return CloseOperationState.STATE_OK;
|
||||||
} catch (IOException ex) {
|
}
|
||||||
Exceptions.printStackTrace(ex);
|
|
||||||
} catch (NoProductException ex) {
|
@Override
|
||||||
Exceptions.printStackTrace(ex);
|
public ExplorerManager getExplorerManager() {
|
||||||
} catch (SAXException ex) {
|
return nodesManager;
|
||||||
Exceptions.printStackTrace(ex);
|
}
|
||||||
} catch (Exception ex) {
|
|
||||||
Exceptions.printStackTrace(ex);
|
@Override
|
||||||
}
|
public void update(Observable o, Object arg) {
|
||||||
|
if(arg instanceof SelectionChanged ){
|
||||||
}
|
SelectionChanged event = (SelectionChanged) arg;
|
||||||
/**
|
if(event.getNewSelection().isEmpty()){
|
||||||
* Raw implementation , just to prototype the editor
|
return;
|
||||||
*/
|
}
|
||||||
@Override
|
ArrayList<String> path = new ArrayList<String>();
|
||||||
public void componentHidden() {
|
GElement parent = event.getElement();
|
||||||
String path = this.obj.getPrimaryFile().getPath();
|
while(parent!=null){
|
||||||
try {
|
path.add(parent.getID());
|
||||||
this.editor.saveGui(path);
|
parent = parent.getParent();
|
||||||
} catch (FileNotFoundException ex) {
|
}
|
||||||
Exceptions.printStackTrace(ex);
|
|
||||||
} catch (JAXBException ex) {
|
Node result = nodesManager.getRootContext();
|
||||||
Exceptions.printStackTrace(ex);
|
|
||||||
}
|
for(int i=path.size()-1;i>=0 && result!=null;i--){
|
||||||
}
|
result = result.getChildren().findChild(path.get(i));
|
||||||
|
}
|
||||||
@Override
|
try {
|
||||||
public void componentActivated() {
|
if(result!=null){
|
||||||
}
|
nodesManager.setSelectedNodes(new Node[]{result});
|
||||||
|
}
|
||||||
@Override
|
} catch (PropertyVetoException ex) {
|
||||||
public void componentDeactivated() {
|
Exceptions.printStackTrace(ex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public UndoRedo getUndoRedo() {
|
|
||||||
return UndoRedo.NONE;
|
@Override
|
||||||
}
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
|
if(evt.getPropertyName().equals(DataObject.PROP_MODIFIED)){
|
||||||
@Override
|
boolean old = (Boolean)evt.getOldValue();
|
||||||
public void setMultiViewCallback(MultiViewElementCallback callback) {
|
boolean nev = (Boolean)evt.getNewValue();
|
||||||
this.callback = callback;
|
if(old && !nev){
|
||||||
}
|
this.loadGui();
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public CloseOperationState canCloseElement() {
|
|
||||||
return CloseOperationState.STATE_OK;
|
}
|
||||||
}
|
|
||||||
|
private void loadGui() {
|
||||||
@Override
|
try {
|
||||||
public ExplorerManager getExplorerManager() {
|
ProgressHandle handle = ProgressHandleFactory.createHandle("Loading the gui file");
|
||||||
return nodesManager;
|
InputStream is = this.obj.getPrimaryFile().getInputStream();
|
||||||
}
|
|
||||||
|
ProjectAssetManager mgr = this.obj.getLookup().lookup(ProjectAssetManager.class);
|
||||||
@Override
|
String assetPath = mgr.getAssetFolder().getPath();
|
||||||
public void update(Observable o, Object arg) {
|
this.editor.createNewGui(nifty,is,new File(assetPath));
|
||||||
jada.ngeditor.listeners.actions.Action act = ( jada.ngeditor.listeners.actions.Action) arg;
|
this.view.newGui(this.editor.getGui());
|
||||||
if(act.getType() == jada.ngeditor.listeners.actions.Action.SEL){
|
nodesManager.setRootContext(new GUINode(this.editor.getGui()));
|
||||||
ArrayList<String> path = new ArrayList<String>();
|
this.editor.getGui().getSelection().addObserver(this);
|
||||||
GElement parent = act.getGUIElement();
|
Collection<GLayer> layers1 = this.editor.getGui().getLayers();
|
||||||
while(parent!=null){
|
guiID = this.editor.getGui().getGUIid();
|
||||||
path.add(parent.getID());
|
DefaultComboBoxModel<GLayer> model = new DefaultComboBoxModel<GLayer>(layers1.toArray(new GLayer[0]));
|
||||||
parent = parent.getParent();
|
layers.setModel(model);
|
||||||
}
|
layers.setSelectedItem(this.editor.getCurrentLayer());
|
||||||
|
|
||||||
Node result = nodesManager.getRootContext();
|
handle.finish();
|
||||||
|
} catch (ParserConfigurationException ex) {
|
||||||
for(int i=path.size()-1;i>=0 && result!=null;i--){
|
Exceptions.printStackTrace(ex);
|
||||||
result = result.getChildren().findChild(path.get(i));
|
} catch (JAXBException ex) {
|
||||||
}
|
Exceptions.printStackTrace(ex);
|
||||||
try {
|
} catch (ClassNotFoundException ex) {
|
||||||
if(result!=null){
|
Exceptions.printStackTrace(ex);
|
||||||
nodesManager.setSelectedNodes(new Node[]{result});
|
} catch (IOException ex) {
|
||||||
}
|
Exceptions.printStackTrace(ex);
|
||||||
} catch (PropertyVetoException ex) {
|
} catch (NoProductException ex) {
|
||||||
Exceptions.printStackTrace(ex);
|
Exceptions.printStackTrace(ex);
|
||||||
}
|
} catch (SAXException ex) {
|
||||||
}
|
Exceptions.printStackTrace(ex);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
}
|
Exceptions.printStackTrace(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
|
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
|
||||||
<filesystem>
|
<filesystem>
|
||||||
<folder name="NiftyPalette">
|
<folder name="NiftyPalette">
|
||||||
<folder name="Items">
|
<folder name="Items">
|
||||||
<file name="Screen" url="com/jme3/gde/gui/palette/Screen.xml">
|
<file name="Screen" url="com/jme3/gde/gui/palette/Screen.xml">
|
||||||
</file>
|
</file>
|
||||||
</folder>
|
</folder>
|
||||||
</folder>
|
</folder>
|
||||||
</filesystem>
|
<folder name="Navigator">
|
||||||
|
<folder name="Panels">
|
||||||
|
<folder name="text">
|
||||||
|
<folder name="x-niftygui+xml">
|
||||||
|
<file name="org-netbeans-modules-xml-text-navigator-XMLNavigatorPanel.instance"/>
|
||||||
|
</folder>
|
||||||
|
</folder>
|
||||||
|
</folder>
|
||||||
|
</folder>
|
||||||
|
</filesystem>
|
||||||
|
@ -1,97 +1,117 @@
|
|||||||
/*
|
/*
|
||||||
* To change this template, choose Tools | Templates
|
* To change this template, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
package com.jme3.gde.gui.nodes;
|
package com.jme3.gde.gui.nodes;
|
||||||
|
|
||||||
import jada.ngeditor.model.elements.GElement;
|
import com.jme3.gde.gui.propertyeditors.ResourceEditor;
|
||||||
import java.beans.PropertyEditor;
|
import com.jme3.gde.gui.propertyeditors.SizeEditor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import jada.ngeditor.model.elements.GElement;
|
||||||
import java.util.Map.Entry;
|
import java.beans.PropertyEditor;
|
||||||
import org.openide.nodes.AbstractNode;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import org.openide.nodes.Children;
|
import java.util.Map.Entry;
|
||||||
import org.openide.nodes.Node;
|
import org.openide.nodes.AbstractNode;
|
||||||
import org.openide.nodes.Sheet;
|
import org.openide.nodes.Children;
|
||||||
|
import org.openide.nodes.Node;
|
||||||
/**
|
import org.openide.nodes.Sheet;
|
||||||
*
|
import sun.beans.editors.BoolEditor;
|
||||||
* @author cris
|
import sun.beans.editors.BooleanEditor;
|
||||||
*/
|
|
||||||
public class GElementNode extends AbstractNode{
|
/**
|
||||||
private final GElement element;
|
*
|
||||||
|
* @author cris
|
||||||
public GElementNode(GElement element) {
|
*/
|
||||||
super(Children.create(new GElementChildFactory(element), false));
|
public class GElementNode extends AbstractNode{
|
||||||
|
private final GElement element;
|
||||||
this.element = element;
|
|
||||||
this.setName(element.getID());
|
public GElementNode(GElement element) {
|
||||||
|
super(Children.create(new GElementChildFactory(element), false));
|
||||||
}
|
|
||||||
|
this.element = element;
|
||||||
public GElement getGelement(){
|
this.setName(element.getID());
|
||||||
return element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateChildren(){
|
public GElement getGelement(){
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
protected Sheet createSheet() {
|
public void updateChildren(){
|
||||||
Sheet s = super.createSheet();
|
|
||||||
Sheet.Set set = s.get(Sheet.PROPERTIES);
|
}
|
||||||
if (set == null) {
|
@Override
|
||||||
set = Sheet.createPropertiesSet();
|
protected Sheet createSheet() {
|
||||||
s.put(set);
|
Sheet s = super.createSheet();
|
||||||
}
|
Sheet.Set set = s.get(Sheet.PROPERTIES);
|
||||||
set.setName("Element Properties");
|
if (set == null) {
|
||||||
set.setShortDescription("You can set element properties");
|
set = Sheet.createPropertiesSet();
|
||||||
for(Entry<String,String> pair : this.element.listAttributes().entrySet()){
|
s.put(set);
|
||||||
set.put(new ElementAttributeProperty(element,pair.getKey()));
|
}
|
||||||
}
|
set.setName("Element Properties");
|
||||||
s.put(set);
|
set.setShortDescription("You can set element properties");
|
||||||
return s;
|
for(Entry<String,String> pair : this.element.listAttributes().entrySet()){
|
||||||
}
|
final ElementAttributeProperty elementAttributeProperty = new ElementAttributeProperty(element,pair.getKey());
|
||||||
|
pickEditor(pair, elementAttributeProperty);
|
||||||
public class ElementAttributeProperty extends Node.Property {
|
set.put(elementAttributeProperty);
|
||||||
|
}
|
||||||
private String attributeName;
|
s.put(set);
|
||||||
private GElement element;
|
return s;
|
||||||
|
}
|
||||||
public ElementAttributeProperty(GElement element, String attributeName) {
|
|
||||||
super(String.class);
|
private void pickEditor(Entry<String, String> pair, final ElementAttributeProperty elementAttributeProperty) {
|
||||||
this.element = element;
|
if(pair.getKey().equals("width")||pair.getKey().equals("height") || pair.getKey().equals("x") || pair.getKey().equals("y") ){
|
||||||
this.attributeName = attributeName;
|
elementAttributeProperty.setPropertyEditor(new SizeEditor());
|
||||||
this.setName(attributeName);
|
}else if(pair.getKey().equals("filename")){
|
||||||
this.setDisplayName(attributeName);
|
elementAttributeProperty.setPropertyEditor(new ResourceEditor());
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean canRead() {
|
public class ElementAttributeProperty extends Node.Property {
|
||||||
return true;
|
|
||||||
}
|
private String attributeName;
|
||||||
|
private GElement element;
|
||||||
@Override
|
private PropertyEditor editor;
|
||||||
public String getValue() throws IllegalAccessException, InvocationTargetException{
|
|
||||||
return element.getAttribute(attributeName);
|
public ElementAttributeProperty(GElement element, String attributeName) {
|
||||||
}
|
super(String.class);
|
||||||
|
this.element = element;
|
||||||
@Override
|
this.attributeName = attributeName;
|
||||||
public boolean canWrite() {
|
this.setName(attributeName);
|
||||||
return true;
|
this.setDisplayName(attributeName);
|
||||||
}
|
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public PropertyEditor getPropertyEditor() {
|
@Override
|
||||||
return super.getPropertyEditor(); //To change body of generated methods, choose Tools | Templates.
|
public boolean canRead() {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Override
|
public String getValue() throws IllegalAccessException, InvocationTargetException{
|
||||||
public void setValue(Object val) throws IllegalAccessException, IllegalArgumentException {
|
return element.getAttribute(attributeName);
|
||||||
element.addAttribute(attributeName, val.toString());
|
}
|
||||||
element.refresh();
|
|
||||||
}
|
@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 {
|
||||||
|
element.addAttribute(attributeName, val.toString());
|
||||||
|
element.refresh();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user