Browse Source

JDK : Nifty Editor
- added validation of the XML with build in Nifty validaiton tool
- added an error list reporting the errors on the file
- redisigned the UI a bit

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9112 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

rem..om 13 years ago
parent
commit
67a02ebfe3

+ 2 - 0
jme3-gui/src/com/jme3/gde/gui/multiview/Bundle.properties

@@ -1,2 +1,4 @@
 
 
 PreviewPanel.jLabel1.text=jLabel1
 PreviewPanel.jLabel1.text=jLabel1
+ErrorPanel.jLabel1.text=jLabel1
+ErrorPanel.jLabel2.text=\ Errors

+ 62 - 0
jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.form

@@ -0,0 +1,62 @@
+<?xml version="1.1" encoding="UTF-8" ?>
+
+<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.PanelFormInfo">
+  <NonVisualComponents>
+    <Component class="javax.swing.JLabel" name="jLabel1">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/gui/multiview/Bundle.properties" key="ErrorPanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+  </NonVisualComponents>
+  <AuxValues>
+    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,93,0,0,3,24"/>
+  </AuxValues>
+
+  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+  <SubComponents>
+    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
+      <Constraints>
+        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+          <BorderConstraints direction="Center"/>
+        </Constraint>
+      </Constraints>
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+      <SubComponents>
+        <Component class="javax.swing.JList" name="jList1">
+          <Properties>
+            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
+              <Connection code="errors" type="code"/>
+            </Property>
+          </Properties>
+        </Component>
+      </SubComponents>
+    </Container>
+    <Component class="javax.swing.JLabel" name="jLabel2">
+      <Properties>
+        <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
+          <Color blue="c8" green="c8" red="c8" type="rgb"/>
+        </Property>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/gui/multiview/Bundle.properties" key="ErrorPanel.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+      <Constraints>
+        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+          <BorderConstraints direction="North"/>
+        </Constraint>
+      </Constraints>
+    </Component>
+  </SubComponents>
+</Form>

+ 114 - 0
jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.java

@@ -0,0 +1,114 @@
+/*
+ * 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.
+     */
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//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);
+    }// </editor-fold>//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
+}

+ 60 - 18
jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewPanel.java

@@ -33,20 +33,22 @@ import javax.swing.JToolBar;
 import org.netbeans.modules.xml.multiview.Error;
 import org.netbeans.modules.xml.multiview.Error;
 import org.netbeans.modules.xml.multiview.ui.PanelView;
 import org.netbeans.modules.xml.multiview.ui.PanelView;
 import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor;
 import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor;
-import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
 import org.openide.NotifyDescriptor;
 import org.openide.NotifyDescriptor.Message;
 import org.openide.NotifyDescriptor.Message;
 import org.openide.nodes.Node;
 import org.openide.nodes.Node;
 import org.openide.util.Exceptions;
 import org.openide.util.Exceptions;
 import org.openide.xml.XMLUtil;
 import org.openide.xml.XMLUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Document;
+import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 
 /**
 /**
  *
  *
  * @author normenhansen
  * @author normenhansen
  */
  */
-public class NiftyPreviewPanel extends PanelView {
+public class NiftyPreviewPanel extends PanelView implements ErrorHandler {
 
 
     private NiftyGuiDataObject niftyObject;
     private NiftyGuiDataObject niftyObject;
     private OffScenePanel offPanel;
     private OffScenePanel offPanel;
@@ -58,6 +60,7 @@ public class NiftyPreviewPanel extends PanelView {
     private NiftyJmeDisplay niftyDisplay;
     private NiftyJmeDisplay niftyDisplay;
     private JScrollPane scrollPanel;
     private JScrollPane scrollPanel;
     private int width = 640, height = 480;
     private int width = 640, height = 480;
+    private ErrorPanel errors;
 
 
     public NiftyPreviewPanel(NiftyGuiDataObject niftyObject, ToolBarDesignEditor comp) {
     public NiftyPreviewPanel(NiftyGuiDataObject niftyObject, ToolBarDesignEditor comp) {
         super();
         super();
@@ -102,6 +105,7 @@ public class NiftyPreviewPanel extends PanelView {
                     height = 480;
                     height = 480;
                 }
                 }
                 offPanel.resizeGLView(width, height);
                 offPanel.resizeGLView(width, height);
+
                 SceneApplication.getApplication().enqueue(new Callable<Object>() {
                 SceneApplication.getApplication().enqueue(new Callable<Object>() {
 
 
                     public Object call() throws Exception {
                     public Object call() throws Exception {
@@ -109,12 +113,20 @@ public class NiftyPreviewPanel extends PanelView {
                         return null;
                         return null;
                     }
                     }
                 });
                 });
+
 //                updatePreView();
 //                updatePreView();
             }
             }
         });
         });
         toolBar.add(comboBox);
         toolBar.add(comboBox);
         toolBar.add(new JPanel());
         toolBar.add(new JPanel());
-        add(toolBar);
+        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() {
     public void updatePreView() {
@@ -122,36 +134,53 @@ public class NiftyPreviewPanel extends PanelView {
     }
     }
 
 
     public void updatePreView(final String screen) {
     public void updatePreView(final String screen) {
+        errors.clear();
         final ProjectAssetManager pm = niftyObject.getLookup().lookup(ProjectAssetManager.class);
         final ProjectAssetManager pm = niftyObject.getLookup().lookup(ProjectAssetManager.class);
         if (pm == null) {
         if (pm == null) {
             Logger.getLogger(NiftyPreviewPanel.class.getName()).log(Level.WARNING, "No Project AssetManager found!");
             Logger.getLogger(NiftyPreviewPanel.class.getName()).log(Level.WARNING, "No Project AssetManager found!");
         }
         }
-        InputStream in = null;
+        InputStream stream = null;
         try {
         try {
-            in = niftyObject.getPrimaryFile().getInputStream();
-            doc = XMLUtil.parse(new InputSource(in), false, false, null, null);
+            stream = niftyObject.getPrimaryFile().getInputStream();
+            doc = XMLUtil.parse(new InputSource(stream), false, false, this, null);
             NiftyFileNode rootContext = new NiftyFileNode(doc.getDocumentElement());
             NiftyFileNode rootContext = new NiftyFileNode(doc.getDocumentElement());
             setRoot(rootContext);
             setRoot(rootContext);
             comp.setRootContext(rootContext);
             comp.setRootContext(rootContext);
         } catch (Exception ex) {
         } catch (Exception ex) {
-            Message msg = new NotifyDescriptor.Message(
-                    "Error parsing File:" + ex,
-                    NotifyDescriptor.ERROR_MESSAGE);
-            DialogDisplayer.getDefault().notifyLater(msg);
-            Exceptions.printStackTrace(ex);
-            return;
+//            Message msg = new NotifyDescriptor.Message(
+//                    "Error parsing File:" + ex,
+//                    NotifyDescriptor.ERROR_MESSAGE);
+            //  DialogDisplayer.getDefault().notifyLater(msg);
+            Exceptions.printStackTrace(ex);            
+            // return;
         } finally {
         } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException ex) {
-                    Exceptions.printStackTrace(ex);
+            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<Object>() {
         SceneApplication.getApplication().enqueue(new Callable<Object>() {
 
 
             public Object call() throws Exception {
             public Object call() throws Exception {
+
                 try {
                 try {
                     nifty.fromXml(pm.getRelativeAssetPath(niftyObject.getPrimaryFile().getPath()), screen);
                     nifty.fromXml(pm.getRelativeAssetPath(niftyObject.getPrimaryFile().getPath()), screen);
                     if (screen == null || screen.length() == 0) {
                     if (screen == null || screen.length() == 0) {
@@ -166,8 +195,9 @@ public class NiftyPreviewPanel extends PanelView {
                     Message msg = new NotifyDescriptor.Message(
                     Message msg = new NotifyDescriptor.Message(
                             "Error opening File:" + ex,
                             "Error opening File:" + ex,
                             NotifyDescriptor.ERROR_MESSAGE);
                             NotifyDescriptor.ERROR_MESSAGE);
-                    DialogDisplayer.getDefault().notifyLater(msg);
+                    //  DialogDisplayer.getDefault().notifyLater(msg);                   
                     Exceptions.printStackTrace(ex);
                     Exceptions.printStackTrace(ex);
+                    errors.addError(ex.getMessage());
                 }
                 }
                 return null;
                 return null;
             }
             }
@@ -290,4 +320,16 @@ public class NiftyPreviewPanel extends PanelView {
             }
             }
         });
         });
     }
     }
+
+    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());
+    }
 }
 }

BIN
jme3-gui/src/com/jme3/gde/gui/multiview/icons/error.png


BIN
jme3-gui/src/com/jme3/gde/gui/multiview/icons/warning.png