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 000000000..b870b37ae Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/error.png differ 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 000000000..b28b24d29 Binary files /dev/null and b/sdk/jme3-gui/src/com/jme3/gde/gui/multiview/icons/warning.png differ