svn commit: r17505 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels: panel ui

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-11-20 06:58:54-0800
New Revision: 17505

Removed:
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/UIFactory.java
Modified:
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java

Log:
Move the logic to build the panle outside of the panel itself

Removed: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/UIFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/UIFactory.java?view=markup&pathrev=17504

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java?view=diff&pathrev=17505&r1=17504&r2=17505
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java	2009-11-20 06:58:54-0800
@@ -28,10 +28,14 @@
 import java.util.Dictionary;
 import java.util.Hashtable;
 
+import javax.swing.JPanel;
+
+import org.apache.log4j.Logger;
+import org.argouml.core.propertypanels.ui.SwingUIFactory;
 import org.argouml.core.propertypanels.xml.XMLPropertyPanelsData;
 import org.argouml.core.propertypanels.xml.XmlSinglePanelHandler;
+import org.argouml.i18n.Translator;
 import org.argouml.model.Model;
-import org.argouml.uml.ui.PropPanel;
 import org.argouml.uml.ui.PropPanelFactory;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
@@ -43,6 +47,9 @@
  */
 public class XMLPropPanelFactory implements PropPanelFactory {
 
+    private static final Logger LOG =
+        Logger.getLogger(XMLPropPanelFactory.class);
+    
     private final Dictionary<String, XMLPropertyPanelsData> cache;
     
     private static XMLPropPanelFactory instance;
@@ -60,17 +67,41 @@
         parseXML();
     }
     
-    public PropPanel createPropPanel(Object target) {
+    /**
+     * Create the XML driven property panel for the given target
+     */
+    public JPanel createPropPanel(Object target) {
         if (Model.getFacade().isAModelElement(target)) {
-            XmlPropertyPanel panel =
+            JPanel panel =
                 new XmlPropertyPanel();
-            panel.build(target);
+            build(panel, target);
             return panel;
         } else {
             return null;
         }
     }
     
+    private void build(JPanel panel, Object target) {
+        // if we have anything or multiple elements selected,
+        // we don't do anything
+        // TODO: We need to support multiple selection.
+        // See issue 2552: http://argouml.tigris.org/issues/show_bug.cgi?id=2552        
+        panel.removeAll();
+        if (target == null){
+            return;
+        }
+        
+        try {
+            // TODO: This references the concrete factory
+            // We need a factories factory
+            SwingUIFactory builder = new SwingUIFactory();
+            builder.createGUI(target, panel);
+        } catch (Exception e) {
+            // TODO: Auto-generated catch block
+            LOG.error("Exception", e);
+        }        
+    }
+    
     private void parseXML() throws Exception {
         String file = "org/argouml/core/propertypanels/xml/panels.xml";        
         XMLReader parser = XMLReaderFactory.createXMLReader();
@@ -87,5 +118,58 @@
         return cache.get(forType);
     }
     
-    
+    /**
+     * @return the title of the panel, according to the target 
+     */
+    private String getPanelTitle(Object target) {
+        String title = null;
+        // if is a pseudostate, we have to look for the pseudostate kind.
+        if (Model.getFacade().isAPseudostate(target)) {
+            Object kind = Model.getFacade().getKind(target);
+            if (Model.getFacade().equalsPseudostateKind(kind,
+                    Model.getPseudostateKind().getFork())) {
+                title = Translator.localize("label.pseudostate.fork");
+            }
+            if (Model.getFacade().equalsPseudostateKind(kind,
+                    Model.getPseudostateKind().getJoin())) {
+                title = Translator.localize("label.pseudostate.join");
+            }
+            if (Model.getFacade().equalsPseudostateKind(kind,
+                    Model.getPseudostateKind().getChoice())) {
+                title = Translator.localize("label.pseudostate.choice");
+            }
+            if (Model.getFacade().equalsPseudostateKind(kind,
+                    Model.getPseudostateKind().getDeepHistory())) {
+                title = Translator.localize("label.pseudostate.deephistory");
+            }
+            if (Model.getFacade().equalsPseudostateKind(kind,
+                    Model.getPseudostateKind().getShallowHistory())) {
+                title = Translator.localize("label.pseudostate.shallowhistory");
+            }
+            if (Model.getFacade().equalsPseudostateKind(kind,
+                    Model.getPseudostateKind().getInitial())) {
+                title = Translator.localize("label.pseudostate.initial");
+            }
+            if (Model.getFacade().equalsPseudostateKind(kind,
+                    Model.getPseudostateKind().getJunction())) {
+                title = Translator.localize("label.pseudostate.junction");
+            }
+        }
+        // there are other cases that need special treatment, 
+        // like concurrent regions
+        if (Model.getFacade().isACompositeState(target)) {
+            if (Model.getFacade().isAConcurrentRegion(target)) {
+                title = Translator.localize("label.concurrent.region");
+            } else if (Model.getFacade().isConcurrent(target)) {
+                title = Translator.localize("label.concurrent.composite.state");
+            } else if (!Model.getFacade().isASubmachineState(target)) {
+                // PropPanelSubmachine is a subclass that handles its own title
+                title = Translator.localize("label.composite-state");
+            }
+        }
+        else {
+            title = Model.getMetaTypes().getName(target); 
+        }            
+        return title; 
+    }
 }

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java?view=diff&pathrev=17505&r1=17504&r2=17505
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java	2009-11-20 06:58:54-0800
@@ -24,23 +24,17 @@
 
 package org.argouml.core.propertypanels.panel;
 
-import javax.swing.ImageIcon;
 import javax.swing.JPanel;
 
 import org.apache.log4j.Logger;
-import org.argouml.core.propertypanels.ui.SwingUIFactory;
-import org.argouml.i18n.Translator;
-import org.argouml.model.Model;
-import org.argouml.ui.TabFigTarget;
-import org.argouml.uml.ui.PropPanel;
+import org.argouml.uml.ui.LabelledLayout;
 
 /**
  * This class is the main property panel, based on XML
  *
  * @author penyaskito
  */
-public class XmlPropertyPanel extends PropPanel 
-    implements TabFigTarget {
+public class XmlPropertyPanel extends JPanel {
     
     /**
      * Logger.
@@ -48,102 +42,6 @@
     private static final Logger LOG = Logger.getLogger(XmlPropertyPanel.class);
     
     public XmlPropertyPanel() {
-        super("XML Properties", null);
-        /* Since there are no buttons on this panel (YET), 
-         * we have to set the size of the buttonpanel, 
-         * otherwise the layout will give it a lot of space 
-         * */
+        super(new LabelledLayout());
     }
-
-    @Override
-    public void setTarget(Object target) {
-        super.setTarget(target);       
-        // TODO: Here will have to do something based on the 
-        // type of the target received. For
-        // commodity, we could use just the name:
-        // p.e.: org.omg.uml.foundation.core.UmlClass$Impl
-        // Our XML can be called Class.xml or if we split the
-        // UI and the model info, Class.ui.xml and Class.model.xml
-        build(target);
-    }
-    
-    public void build(Object target) {
-        // if we have anything or multiple elements selected,
-        // we don't do anything
-        // TODO: We need to support multiple selection.
-        // See issue 2552: http://argouml.tigris.org/issues/show_bug.cgi?id=2552        
-        removeAll();
-        if (target == null){
-            return;
-        }
-        
-        LOG.info("[XMLPP] t is type:" + target.getClass());
-        
-        try {
-            // TODO: This references the concrete factory
-            // We need a factories factory
-            UIFactory factory = SwingUIFactory.getInstance();
-            factory.createGUI(target, this);
-            this.getTitleLabel().setText(getPanelTitle(target));
-        } catch (Exception e) {
-            // TODO: Auto-generated catch block
-            LOG.error("Exception", e);
-        }        
-    }
-    
-    /**
-     * @return the title of the panel, according to the target 
-     */
-    private String getPanelTitle(Object target) {
-        String title = null;
-        // if is a pseudostate, we have to look for the pseudostate kind.
-        if (Model.getFacade().isAPseudostate(target)) {
-            Object kind = Model.getFacade().getKind(target);
-            if (Model.getFacade().equalsPseudostateKind(kind,
-                    Model.getPseudostateKind().getFork())) {
-                title = Translator.localize("label.pseudostate.fork");
-            }
-            if (Model.getFacade().equalsPseudostateKind(kind,
-                    Model.getPseudostateKind().getJoin())) {
-                title = Translator.localize("label.pseudostate.join");
-            }
-            if (Model.getFacade().equalsPseudostateKind(kind,
-                    Model.getPseudostateKind().getChoice())) {
-                title = Translator.localize("label.pseudostate.choice");
-            }
-            if (Model.getFacade().equalsPseudostateKind(kind,
-                    Model.getPseudostateKind().getDeepHistory())) {
-                title = Translator.localize("label.pseudostate.deephistory");
-            }
-            if (Model.getFacade().equalsPseudostateKind(kind,
-                    Model.getPseudostateKind().getShallowHistory())) {
-                title = Translator.localize("label.pseudostate.shallowhistory");
-            }
-            if (Model.getFacade().equalsPseudostateKind(kind,
-                    Model.getPseudostateKind().getInitial())) {
-                title = Translator.localize("label.pseudostate.initial");
-            }
-            if (Model.getFacade().equalsPseudostateKind(kind,
-                    Model.getPseudostateKind().getJunction())) {
-                title = Translator.localize("label.pseudostate.junction");
-            }
-        }
-        // there are other cases that need special treatment, 
-        // like concurrent regions
-        if (Model.getFacade().isACompositeState(target)) {
-            if (Model.getFacade().isAConcurrentRegion(target)) {
-                title = Translator.localize("label.concurrent.region");
-            } else if (Model.getFacade().isConcurrent(target)) {
-                title = Translator.localize("label.concurrent.composite.state");
-            } else if (!Model.getFacade().isASubmachineState(target)) {
-                // PropPanelSubmachine is a subclass that handles its own title
-                title = Translator.localize("label.composite-state");
-            }
-        }
-        else {
-            title = Model.getMetaTypes().getName(target); 
-        }            
-        return title; 
-    }
-   
 }

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java?view=diff&pathrev=17505&r1=17504&r2=17505
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java	2009-11-20 06:58:54-0800
@@ -39,7 +39,6 @@
 import javax.swing.ListModel;
 import javax.swing.border.TitledBorder;
 
-import org.argouml.core.propertypanels.panel.UIFactory;
 import org.argouml.core.propertypanels.panel.XMLPropPanelFactory;
 import org.argouml.core.propertypanels.xml.XMLPropertyPanelsData;
 import org.argouml.core.propertypanels.xml.XMLPropertyPanelsDataRecord;
@@ -97,24 +96,17 @@
 import org.argouml.uml.ui.foundation.extension_mechanisms.ActionSetTagDefinitionType;
 import org.argouml.uml.ui.foundation.extension_mechanisms.UMLMetaClassComboBoxModel;
 import org.tigris.swidgets.GridLayout2;
-import org.tigris.toolbar.ToolBar;
 import org.tigris.toolbar.ToolBarFactory;
 
 /**
  * Creates the XML Property panels
  */
-public class SwingUIFactory implements UIFactory {
-    
-    private static UIFactory instance = new SwingUIFactory();
+public class SwingUIFactory {
     
     public SwingUIFactory() {
         
     }
     
-    public static UIFactory getInstance() {        
-        return instance;
-    }
-    
     /**
      * @param target The model element selected
      * @return A Panel to be added to the main panel

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2420847

To unsubscribe from this discussion, e-mail: [[email protected]].
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.