From 751b4e851d4a84831290fc22df92181a9649e0b2 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Tue, 24 Jan 2012 19:15:57 +0000 Subject: [PATCH] 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 --- .../jme3/gde/gui/multiview/Bundle.properties | 2 + .../jme3/gde/gui/multiview/ErrorPanel.form | 62 ++++++++++ .../jme3/gde/gui/multiview/ErrorPanel.java | 114 ++++++++++++++++++ .../gde/gui/multiview/NiftyPreviewPanel.java | 78 +++++++++--- .../jme3/gde/gui/multiview/icons/error.png | Bin 0 -> 794 bytes .../jme3/gde/gui/multiview/icons/warning.png | Bin 0 -> 1788 bytes 6 files changed, 238 insertions(+), 18 deletions(-) create mode 100644 sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.form create mode 100644 sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.java create mode 100644 sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/error.png create mode 100644 sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/warning.png 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 index bc07788de..7a6ba8e9c 100644 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/Bundle.properties +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/Bundle.properties @@ -1,2 +1,4 @@ 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 new file mode 100644 index 000000000..ae4ae89ae --- /dev/null +++ b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/ErrorPanel.form @@ -0,0 +1,62 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 000000000..94a62d5a4 --- /dev/null +++ b/sdk/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. + */ + // //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/NiftyPreviewPanel.java b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewPanel.java index 6f679798f..36c721976 100644 --- a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/NiftyPreviewPanel.java +++ b/sdk/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.ui.PanelView; import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor; -import org.openide.DialogDisplayer; 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 { +public class NiftyPreviewPanel extends PanelView implements ErrorHandler { private NiftyGuiDataObject niftyObject; private OffScenePanel offPanel; @@ -58,6 +60,7 @@ public class NiftyPreviewPanel extends PanelView { private NiftyJmeDisplay niftyDisplay; private JScrollPane scrollPanel; private int width = 640, height = 480; + private ErrorPanel errors; public NiftyPreviewPanel(NiftyGuiDataObject niftyObject, ToolBarDesignEditor comp) { super(); @@ -102,6 +105,7 @@ public class NiftyPreviewPanel extends PanelView { height = 480; } offPanel.resizeGLView(width, height); + SceneApplication.getApplication().enqueue(new Callable() { public Object call() throws Exception { @@ -109,12 +113,20 @@ public class NiftyPreviewPanel extends PanelView { return null; } }); + // updatePreView(); } }); toolBar.add(comboBox); 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() { @@ -122,36 +134,53 @@ public class NiftyPreviewPanel extends PanelView { } 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 in = null; + InputStream stream = null; 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()); 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; +// Message msg = new NotifyDescriptor.Message( +// "Error parsing File:" + ex, +// NotifyDescriptor.ERROR_MESSAGE); + // DialogDisplayer.getDefault().notifyLater(msg); + Exceptions.printStackTrace(ex); + // return; } 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() { public Object call() throws Exception { + try { nifty.fromXml(pm.getRelativeAssetPath(niftyObject.getPrimaryFile().getPath()), screen); if (screen == null || screen.length() == 0) { @@ -166,8 +195,9 @@ public class NiftyPreviewPanel extends PanelView { Message msg = new NotifyDescriptor.Message( "Error opening File:" + ex, NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(msg); + // DialogDisplayer.getDefault().notifyLater(msg); Exceptions.printStackTrace(ex); + errors.addError(ex.getMessage()); } 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()); + } } diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/error.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/error.png new file mode 100644 index 0000000000000000000000000000000000000000..b870b37ae05f8a377d26a732478945cebec0e93e GIT binary patch literal 794 zcmV+#1LgdQP)-ATX1NqW_?xzaZMW$bzI)qR5Rzi=c&BZX$v_Q)78Sp`39pjhz{1#;=88_f5Ua z_ww-GenM-_|Cs#M5fMTuMHf<@G^?wt0B_;br!j=+H}dAa>QpNBW4`#YgXv<~YE)Kq z7aeKwyS8mdSZXgAKGD0ItlXCjYqr)Q3dg|D^cT^u^3D7dFGxy zr|iN-tiAil*90u#_jgA^A+-X4qIMaqEz2fTtZr!Xqu=B8bghgqTfgb4tA5)7Ed+^ZoSGXqafd==$0Ow8305^Uka-(s^87hU zYpM~#AU_@%Ui);UdAS2&Y|ednPazhi#BDOsaf)o@9V%G6TpYHUIMa#OTY{dSr!YMQ zQu@B1QK>kF;nxcbka5rpS@MYl-)?}`8lBCuluRKEz%W3{((gM^Rt%*;StK)gHuT=1 zxM2^DJ%(f36xG!e=)FVoivyO0PzqtG@Cv|it3II=>BS`icl+_|*okA?OmucI+1c?8 zQb*v{ZPE)4SPJcS_pbob9$$~J)T~RId>$Rev27;1PP3-69IwBE$+KNJVVlpRFK}5F zLdxh;j(a~n(#Mv=t=cdLGRc(6X;@Y6LzpH)2(;Fu=jM^ppvYI66`Dhp1NVo2d*#{V zNB5h8hd}vXv@;9(LRJ5R!9QvNV5Y6D%;ln88{!0-EkIlgVrcr(DW|7)Xej$vG5w2u Y1(}Hs6VG)aApigX07*qoM6N<$g8E8uIRF3v literal 0 HcmV?d00001 diff --git a/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/warning.png b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/warning.png new file mode 100644 index 0000000000000000000000000000000000000000..b28b24d29e460f57e2f50d09092baa32a43053cd GIT binary patch literal 1788 zcmVd+fQ^ z9(!%zPvPzUM;D^Sq&_VZ^{Yer3vo6a#Z`g*4RfJvdDOxPt} z8?6<0@Q>ZTb9Zsj02`I5356v<_x3+IdC%VVbK_bdVyXTE#Hm!XsO~6AutwS1JO6KD?2m+pQn@G*ib9004WR zGXku-fW7C;(y$nia$EJ2sqY|Ul;m9YnF1fR6En3*EXSm0PNMN;T5@S=u0>mL;#YH1 z7s-qiW(rOJxY^?vE|+GSN80xYle|N$8!BMn-u5H}A~W zVqvA_$nffUHQAxw5>~YPhZR{%!IBPP{IaN`Wr7p4R%fA}Lz<=M+_>LQ@Ov~eWT86A z%hU}#70D|zW0gnX9I#nmcGXZmk%SL1|+VN(f2*UB<`a& zjhO%(`7HLXXh zZ2%Czm2zvo+L7gdq#}0Z-Jovk8NMg^^U@LF4F3WT<$}ye_y-H7gOBn69xZQiD*&)z z!swS&Kprw)QX>bUj$f4wfnn9;0Y1geHF;0gz*rb5&o0TQzE56Qdp*LMIlg`kCIjZU zDD)vG&ecQs8Bpw7kS}o*V1rt7&czt!EQ_mZxme0a zi-&zfzO0obgjnH(>EiRSi?e>%|M8$?2NBVgF=;B_O_AkoP!SQ;--jm=(e(%n5E0#~ zgCP-7$2?uew<2`d?g2+4qO0TJL_}4I7$+jP(sL}4x`~wY1!pQ5)K5LmJ|jvmpRI;R zP?%JmKPkt{hSu%X4Zd2RMlZ>p)-$*uzCiP33S_Z^)FX310r{X>Mp%VlC}kNCDV$2A z&5~*g$9e9A7KEW#y;hqV!ZB6?I2D? eNY%?PN(TTo*alb-Q_5Tb0000