svn commit: r15543 - branches/gsoc2008/feature4_5142_bszanto/src/org/argouml: i18n ui uml/diagram/static_structure/ui uml/diagram/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bszanto
Date: 2008-08-11 08:39:45-0700
New Revision: 15543

Added:
   branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/ui/CmdCreateNodeWizard.java   (contents, props changed)
      - copied, changed from r15531, /branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/CmdCreateNodeWizard.java
Removed:
   branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/CmdCreateNodeWizard.java
Modified:
   branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/i18n/dialog.properties
   branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/static_structure/ui/ClassCreateWizard.java
   branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/UMLDiagram.java

Log:
Classes that have attributes and operations can now be created using the wizard.

Modified: branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/i18n/dialog.properties
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/i18n/dialog.properties?view=diff&rev=15543&p1=branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/i18n/dialog.properties&p2=branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/i18n/dialog.properties&r1=15542&r2=15543
==============================================================================
--- branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/i18n/dialog.properties	(original)
+++ branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/i18n/dialog.properties	2008-08-11 08:39:45-0700
@@ -179,6 +179,7 @@
 dialog.title.reverse-engineer-sequence-diagram = Reverse engineer sequence diagram for
 dialog.title.source-path-del = Confirm delete source path settings
 dialog.title.system-information = System Information
+dialog.title.wizard-class = New class Wizard
 dialog.import.classpath.title = Configure the import classpath
 dialog.import.classpath.text = Add entries to match the classpath that would \
  be used to compile these source modules.  For example, you probably want to \

Copied: branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/ui/CmdCreateNodeWizard.java (from r15531, /branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/CmdCreateNodeWizard.java)
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/ui/CmdCreateNodeWizard.java?view=diff&rev=15543&p1=/branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/CmdCreateNodeWizard.java&p2=branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/ui/CmdCreateNodeWizard.java&r1=15531&r2=15543
==============================================================================
--- /branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/CmdCreateNodeWizard.java	(original)
+++ branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/ui/CmdCreateNodeWizard.java	2008-08-11 08:39:45-0700
@@ -22,7 +22,7 @@
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,

 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

 

-package org.argouml.uml.diagram.ui;

+package org.argouml.ui;

 

 import java.awt.event.ActionEvent;

 

@@ -30,6 +30,7 @@
 

 import org.argouml.application.helpers.ResourceLoaderWrapper;

 import org.argouml.i18n.Translator;

+import org.argouml.uml.diagram.ui.CreateWizard;

 import org.tigris.gef.base.CreateNodeAction;

 

 /**

@@ -39,14 +40,10 @@
  */

 public class CmdCreateNodeWizard extends CreateNodeAction {

     

-    /**

-     * Wizard to use

-     */

+    /** Wizard to use */

     private CreateWizard wizard = null;

     

-    /**

-     * Object to be created.

-     */

+    /** Object to be created. */

     private Object node;

 

     /**

@@ -67,10 +64,15 @@
     

     @Override

     public void actionPerformed(ActionEvent e) {

-        super.actionPerformed(e);

-        

         // displays the wizard that returns the node to be created

         node = wizard.display();

+        

+        // if the node is null, the acion was canceled

+        if (node != null) {

+            super.actionPerformed(e);

+        } else {

+            return;

+        }

     }

     

     @Override


Modified: branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/static_structure/ui/ClassCreateWizard.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/static_structure/ui/ClassCreateWizard.java?view=diff&rev=15543&p1=branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/static_structure/ui/ClassCreateWizard.java&p2=branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/static_structure/ui/ClassCreateWizard.java&r1=15542&r2=15543
==============================================================================
--- branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/static_structure/ui/ClassCreateWizard.java	(original)
+++ branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/static_structure/ui/ClassCreateWizard.java	2008-08-11 08:39:45-0700
@@ -24,24 +24,341 @@
 

 package org.argouml.uml.diagram.static_structure.ui;

 

-import javax.swing.JOptionPane;

+import java.awt.BorderLayout;

+import java.awt.Dimension;

+import java.awt.Toolkit;

+import java.awt.event.ActionEvent;

+import java.awt.event.ActionListener;

+import java.util.Vector;

 

+import javax.swing.BorderFactory;

+import javax.swing.BoxLayout;

+import javax.swing.JButton;

+import javax.swing.JComboBox;

+import javax.swing.JDialog;

+import javax.swing.JLabel;

+import javax.swing.JPanel;

+import javax.swing.JTextField;

+

+import org.argouml.i18n.Translator;

+import org.argouml.model.CoreHelper;

 import org.argouml.model.Model;

+import org.argouml.model.VisibilityKind;

 import org.argouml.uml.diagram.ui.CreateWizard;

+import org.argouml.uml.ui.UMLComboBox2;

+import org.argouml.uml.ui.UMLComboBoxModel2;

+import org.argouml.uml.ui.foundation.core.ActionSetStructuralFeatureType;

+import org.argouml.uml.ui.foundation.core.UMLStructuralFeatureTypeComboBoxModel;

 

 /**

  * Wizard for creating a new Class.

- *

+ * 

  * @author bszanto

  */

 public class ClassCreateWizard implements CreateWizard {

 

-    

+    /** WIDTH of the dialog */

+    public final static int WIDTH = 600;

+    /** HEIGHT of the dialog */

+    public final static int HEIGHT = 450;

+

+    /** The wizard dialog */

+    private JDialog dialog = null;

+

+    private JTextField txtName = null;

+

+    /** The new class */

+    private Object classNode = null;

+

+    /** Attributes */

+    private Vector<Attribute> attributes = new Vector<Attribute>();

+

+    /** Operations */

+    private Vector<Operation> operations = new Vector<Operation>();

+

+    /**

+     * Constructor

+     */

+    public ClassCreateWizard() {

+        dialog = new JDialog();

+        dialog.setTitle(Translator.localize("dialog.title.wizard-class"));

+        dialog.setSize(WIDTH, HEIGHT);

+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

+        dialog.setLocation((screenSize.width - WIDTH) / 2,

+                (screenSize.height - HEIGHT) / 2);

+        dialog.setResizable(false);

+        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

+        

+        

+        dialog.getContentPane().setLayout(new BorderLayout());

+

+        JPanel pnlName = new JPanel();

+        pnlName.add(new JLabel(Translator.localize("label.name")));

+        txtName = new JTextField();

+        txtName.setPreferredSize(new Dimension(120, 25));

+        pnlName.add(txtName);

+        dialog.getContentPane().add(pnlName, BorderLayout.NORTH);

+

+        JPanel pnlContent = new JPanel();

+

+        JPanel pnlAtt = new JPanel();

+        pnlAtt.setBorder(BorderFactory.createTitledBorder(Translator

+                .localize("label.attributes")));

+        pnlAtt.setLayout(new BoxLayout(pnlAtt, BoxLayout.PAGE_AXIS));

+        JPanel pnlOp = new JPanel();

+        pnlOp.setBorder(BorderFactory.createTitledBorder(Translator

+                .localize("label.operations")));

+        pnlOp.setLayout(new BoxLayout(pnlOp, BoxLayout.PAGE_AXIS));

+        for (int i = 0; i < 4; i++) {

+            attributes.add(new Attribute());

+            pnlAtt.add(attributes.get(i));

+

+            operations.add(new Operation());

+            pnlOp.add(operations.get(i));

+        }

+        pnlContent.add(pnlAtt);

+        pnlContent.add(pnlOp);

+

+        dialog.getContentPane().add(pnlContent, BorderLayout.CENTER);

+

+        JPanel pnlButtons = new JPanel();

+        JButton btnOk = new JButton(Translator.localize("button.ok"));

+        btnOk.addActionListener(new ActionListener() {

+            public void actionPerformed(ActionEvent e) {

+                okPressed();

+            }

+        });

+        JButton btnCancel = new JButton(Translator.localize("button.cancel"));

+        btnCancel.addActionListener(new ActionListener() {

+            public void actionPerformed(ActionEvent e) {

+                dialog.setVisible(false);

+            }

+        });

+        pnlButtons.add(btnOk);

+        pnlButtons.add(btnCancel);

+        dialog.getContentPane().add(pnlButtons, BorderLayout.SOUTH);

+

+        dialog.setModal(true);

+    }

+

     public Object display() {

-        JOptionPane.showMessageDialog(null, "This will be a wizard!", 

-                "Create new class wizard", JOptionPane.PLAIN_MESSAGE);

-        // only creates a new class now

-        return Model.getCoreFactory().createClass();

+        dialog.setVisible(true);

+        // the next line is executed only when the dialog is not visible anymore

+        return classNode;

+    }

+    

+    /**

+     * When the OK button is pressed the new class is created, and the 

+     * attribtutes and operations are added.

+     */

+    public void okPressed() {

+        classNode = Model.getCoreFactory().createClass();

+        

+        /* setting name */

+        Model.getCoreHelper().setName(classNode, txtName.getText());

+        

+        /* adding attributes */

+        Vector<Object> attList = new Vector<Object>();

+        Object temp;

+        for (int i = 0; i < attributes.size(); i++) {

+            temp = attributes.get(i).getAttribute();

+            if (temp != null) {

+                attList.add(temp);

+            }

+        }

+        Model.getCoreHelper().setAttributes(classNode, attList);

+        

+        /* adding operations */

+        Vector<Object> opList = new Vector<Object>();

+        for (int i = 0; i < operations.size(); i++) {

+            temp = operations.get(i).getOperation();

+            if (temp != null) {

+                opList.add(temp);

+            }

+        }

+        Model.getCoreHelper().setOperations(classNode, opList);

+        

+        dialog.setVisible(false);

     }

 

 }

+

+class Attribute extends JPanel {

+

+    /** Name field */

+    private JTextField name;

+    /** Visibility field */

+    private JComboBox visibility;

+    /** Type field */

+    private UMLComboBox2 type;

+    

+    /** The newly created attribue */

+    private Object attribute = null;

+

+    /**

+     * Constructor.

+     */

+    public Attribute() {

+        super();

+        attribute = Model.getCoreFactory().createAttribute();         

+        

+        String[] vis = new String[] { "public(+)", "package(~)",

+                "protected(#)", "private(-)" };

+        visibility = new JComboBox(vis);

+        visibility.setPreferredSize(

+                new Dimension((int) (1.5 * ClassCreateWizard.WIDTH / 10), 25));

+        UMLComboBoxModel2 model = new UMLStructuralFeatureTypeComboBoxModel();

+        model.setTarget(attribute);

+        type = new UMLComboBox2(model,

+                ActionSetStructuralFeatureType.getInstance());

+        type.setSelectedIndex(0);

+        type.setPreferredSize(

+                new Dimension(3 * ClassCreateWizard.WIDTH / 10, 25));

+        name = new JTextField();

+        name.setPreferredSize(

+                new Dimension(3 * ClassCreateWizard.WIDTH / 10, 25));

+

+        this.add(visibility);

+        this.add(type);

+        this.add(name);

+    }

+

+    /**

+     * @return The newly created attribute, or null if a name was not specified.

+     */

+    public Object getAttribute() {    

+        if (name.getText().length() > 0) {

+            CoreHelper help = Model.getCoreHelper();

+            VisibilityKind vk = Model.getVisibilityKind();

+            

+            help.setName(attribute, name.getText());

+            

+            Object vis = null;

+            int index = visibility.getSelectedIndex();

+            switch (index) {

+            case 1:

+                vis = vk.getPublic();

+                break;

+            case 2:

+                vis = vk.getPackage();

+                break;

+            case 3:

+                vis = vk.getProtected();

+                break;

+            default:

+                vis = vk.getPrivate();

+            }

+            help.setVisibility(attribute, vis);

+            

+            help.setType(attribute, type.getSelectedItem());

+            

+            help.setReadOnly(attribute, false);

+        } else {

+            attribute = null;

+        }

+        return attribute;

+    }

+}

+

+class Operation extends JPanel {

+    /** Name field */

+    private JTextField name;

+    /** Visibility field */

+    private JComboBox visibility;

+    /** In type field */

+    private UMLComboBox2 inType;

+    /** Return type field */

+    private UMLComboBox2 outType;

+    /** In parameter */

+    private Object inParam = null;

+    /** Return parameter */

+    private Object returnParam = null;

+    

+    /** The newly created operation */

+    private Object operation = null;

+    

+    /**

+     * Constructor.

+     */

+    public Operation() {

+        super();

+        operation = Model.getCoreFactory().createOperation();

+        

+        String[] vis = new String[] { "public(+)", "package(~)",

+                "protected(#)", "private(-)" };

+        visibility = new JComboBox(vis);

+        visibility.setPreferredSize(

+                new Dimension((int) (1.5 * ClassCreateWizard.WIDTH / 10), 25));

+        

+        UMLComboBoxModel2 model = new UMLStructuralFeatureTypeComboBoxModel();

+        inParam = Model.getCoreFactory().createParameter();

+        model.setTarget(inParam);

+        inType = new UMLComboBox2(model,

+                ActionSetStructuralFeatureType.getInstance());

+        inType.setSelectedIndex(0);

+        inType.setPreferredSize(

+                new Dimension((int) (2.7 * ClassCreateWizard.WIDTH / 10), 25));

+        

+        name = new JTextField();

+        name.setPreferredSize(

+                new Dimension(2 * ClassCreateWizard.WIDTH / 10, 25));

+        

+        model = new UMLStructuralFeatureTypeComboBoxModel();

+        returnParam = Model.getCoreFactory().createParameter();

+        model.setTarget(returnParam);

+        outType = new UMLComboBox2(model,

+                ActionSetStructuralFeatureType.getInstance());

+        outType.setSelectedIndex(0);

+        outType.setPreferredSize(

+                new Dimension((int) (2.7 * ClassCreateWizard.WIDTH / 10), 25));

+

+        this.add(visibility);

+        this.add(inType);

+        this.add(name);

+        this.add(outType);

+    }

+    

+    /**

+     * @return The newly created operation, or null if a name was not specified.

+     */

+    public Object getOperation() {

+        

+        if (name.getText().length() > 0) {

+            CoreHelper help = Model.getCoreHelper();

+            VisibilityKind vk = Model.getVisibilityKind();

+

+            help.setName(operation, name.getText());

+            

+            Object vis = null;

+            int index = visibility.getSelectedIndex();

+            switch (index) {

+            case 1:

+                vis = vk.getPublic();

+                break;

+            case 2:

+                vis = vk.getPackage();

+                break;

+            case 3:

+                vis = vk.getProtected();

+                break;

+            default:

+                vis = vk.getPrivate();

+            }

+            help.setVisibility(operation, vis);

+            

+            // the return param

+            help.setType(returnParam, outType.getSelectedObjects()[0]);

+            help.setKind(returnParam, 

+                    Model.getDirectionKind().getReturnParameter());

+            help.addParameter(operation, returnParam);

+            

+            // the in param

+            help.setType(inParam, inType.getSelectedObjects()[0]);

+            help.setKind(inParam, Model.getDirectionKind().getInParameter());

+            help.addParameter(operation, inParam);       

+        } else {

+            operation = null;

+        }

+        return operation;

+    }

+}


Removed: branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/CmdCreateNodeWizard.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/CmdCreateNodeWizard.java?view=auto&rev=15542

Modified: branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/UMLDiagram.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/UMLDiagram.java?view=diff&rev=15543&p1=branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/UMLDiagram.java&p2=branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/UMLDiagram.java&r1=15542&r2=15543
==============================================================================
--- branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/UMLDiagram.java	(original)
+++ branches/gsoc2008/feature4_5142_bszanto/src/org/argouml/uml/diagram/ui/UMLDiagram.java	2008-08-11 08:39:45-0700
@@ -44,6 +44,7 @@
 import org.argouml.kernel.ProjectManager;
 import org.argouml.model.Model;
 import org.argouml.ui.CmdCreateNode;
+import org.argouml.ui.CmdCreateNodeWizard;
 import org.argouml.uml.UUIDHelper;
 import org.argouml.uml.diagram.ArgoDiagramImpl;
 import org.argouml.uml.diagram.Relocatable;
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.