svn commit: r15009 - branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels: panel xml

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: penyaskito
Date: 2008-06-19 16:14:24-0700
New Revision: 15009

Added:
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java   (contents, props changed)
Modified:
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/UmlClass.xml

Log:
Creating simple GUI from an XML String.

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java?view=diff&rev=15009&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java&r1=15008&r2=15009
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java	2008-06-19 16:14:24-0700
@@ -24,20 +24,20 @@
 
 package org.argouml.core.propertypanels.panel;
 
-import java.awt.Panel;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
+import java.io.DataInputStream;
 
-import javax.swing.JLabel;
 import javax.swing.JPanel;
 
 import org.apache.log4j.Logger;
+import org.argouml.core.propertypanels.xml.XMLPropertyPanelsHandler;
 import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
+// this import is weird, but it will be removed (just a workaround
+// until the problem with loading XMLs from jars is solved.
+import com.sun.org.apache.bcel.internal.util.ByteSequence;
+
 // TODO: This class will be an interface or abstract class
 // and will be implemented by SwingUIFactory and SwtUIFactory.
 public class UIFactory {
@@ -60,12 +60,10 @@
     // TODO: This will be a template method, where there will be two
     // implementations, for Swing and for SWT.
     public JPanel createGUI (Object target) throws Exception {
-        JPanel p = new JPanel();
-        p.add(new JLabel("Test label from code"));
         String filename = getXMLFileName(target);
         LOG.info("[XMLPP] filename is:" + filename);
-        // parseXML(filename);
-        return p;       
+        JPanel panel = parseXML(filename);
+        return panel;       
     }
     
     private String getXMLFileName(Object target) {
@@ -74,8 +72,10 @@
         return classname.replace("$Impl", "");
     }
 
-    public void parseXML(String filename) 
+    public JPanel parseXML(String filename) 
         throws Exception {
+        JPanel panel = new JPanel();
+        
         // TODO: I have to investigate how to read the XML.
         // There are some different APIs available, but
         // I'll choose SAX because it's the one API used in
@@ -83,10 +83,33 @@
         XMLReader parser = XMLReaderFactory.createXMLReader(
                 "org.apache.xerces.parsers.SAXParser"
               );
+        parser.setContentHandler(new XMLPropertyPanelsHandler(panel));
+
         String file = "/org/argouml/core/propertypanels/xml/"
-            + filename;
-        FileInputStream stream = new FileInputStream(file);
+            + filename + ".xml";
+        LOG.info("File = "+ file);
+        // URL url = ClassLoader.getSystemResource(file);
+        // ClassLoader loader = UIFactory.class.getClassLoader();
+        // URL url = loader.getResource(file);
+        // LOG.info("URL = "+ url.toString());
+//        Enumeration<URL> urls = loader.getResources(file);        
+//        while (urls.hasMoreElements()) {
+//            URL u = (URL) urls.nextElement();
+//            LOG.info("URL = "+ u.toString());
+//        }
+//        URL url = loader.getResource(file);
+//        LOG.info("URL = "+ url.toString());
+        DataInputStream stream = getStream();
+//        FileInputStream stream = new FileInputStream(file);
+        
         InputSource source = new InputSource(stream);
-        parser.parse(source);
+        parser.parse(source);        
+        
+        return panel; 
+    }
+
+    private DataInputStream getStream() {
+        String x = "<?xml version='1.0' encoding='UTF-8'?><panel title='Prueba de titutlo'>     <label text='This is a test from XML' />        <property name='name' value='hey'       /></panel>";
+        return new ByteSequence(x.getBytes());
     }
 }

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java?view=diff&rev=15009&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java&r1=15008&r2=15009
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java	2008-06-19 16:14:24-0700
@@ -26,13 +26,13 @@
 
 import javax.swing.ImageIcon;
 import javax.swing.JPanel;
-import javax.swing.JScrollPane;
 
 import org.apache.log4j.Logger;
 import org.argouml.ui.TabFigTarget;
 import org.argouml.uml.ui.PropPanel;
 
-public class XmlPropertyPanel extends PropPanel implements TabFigTarget {
+public class XmlPropertyPanel extends PropPanel 
+    implements TabFigTarget {
     
     /**
      * Logger.
@@ -57,11 +57,6 @@
     }
     
     @Override
-    public String getTitle() {
-        return "XML Property Panel";
-    }
-    
-    @Override
     public void setTarget(Object t) {
         super.setTarget(t);
         // TODO: Here will have to do something based on the 
@@ -74,6 +69,7 @@
         
         JPanel panel;
         try {
+            this.removeAll();
             panel = UIFactory.getInstance().createGUI(t);
             this.add(panel);
         } catch (Exception e) {

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/UmlClass.xml
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/UmlClass.xml?view=diff&rev=15009&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/UmlClass.xml&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/UmlClass.xml&r1=15008&r2=15009
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/UmlClass.xml	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/UmlClass.xml	2008-06-19 16:14:24-0700
@@ -1,4 +1,5 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<panel>
-	<label text="This is a test from XML" />	
+<?xml version='1.0' encoding='UTF-8'?>
+<panel title='Prueba de titutlo'>
+	<label text='This is a test from XML' />
+	<property name='name' value='hey'	/>
 </panel>

Added: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java?view=auto&rev=15009
==============================================================================
--- (empty file)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java	2008-06-19 16:14:24-0700
@@ -0,0 +1,72 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.core.propertypanels.xml;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JTextField;
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * This handles the XML events by SAX Api for building 
+ * the property panels.
+ * @author penyaskito
+ */
+public class XMLPropertyPanelsHandler extends DefaultHandler {
+
+    /**
+     * The panel that will host the controls. 
+     */
+    private final JPanel panel;    
+    
+    
+    /**
+     * 
+     */
+    public XMLPropertyPanelsHandler(JPanel panel) {
+        this.panel = panel;
+    }
+
+    public void startElement(String namespaceURI, String localName, 
+            String qName, Attributes attr) throws SAXException { 
+        if (localName.equals("panel")){
+            String title = attr.getValue("title");
+            panel.add(new JLabel(title));
+            panel.add(new JSeparator() );
+        }
+        if (localName.equals("property")){
+            String name = attr.getValue("name");
+            String value = attr.getValue("value");
+            panel.add(new JLabel(name));
+            panel.add(new JTextField(value, 60));
+            panel.add(new JSeparator() );
+        }
+    }
+
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.