From e51a0d82537293a5bcc88a32327449d0af4ba0db Mon Sep 17 00:00:00 2001
From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr>
Date: Mon, 2 Feb 2009 17:48:01 +0000
Subject: [PATCH] Modifications on requirements

-This line, and those below, will be ignored--

M    src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java
M    src/ui/window/JDialogRequirement.java
M    src/ui/req/Requirement.java
M    src/ui/req/TAttributeRequirement.java
M    src/ui/tmldd/TMLArchiMemoryNode.java
M    bin/config.xml
---
 bin/config.xml                                |   4 +-
 src/ui/req/Requirement.java                   | 121 +++++++++++++-----
 src/ui/req/TAttributeRequirement.java         |   4 +-
 .../TMLComponentTaskDiagramPanel.java         |  10 +-
 src/ui/tmldd/TMLArchiMemoryNode.java          |   2 +-
 src/ui/window/JDialogRequirement.java         |  41 ++++--
 6 files changed, 129 insertions(+), 53 deletions(-)

diff --git a/bin/config.xml b/bin/config.xml
index 638e1bc75b..66f31c1858 100755
--- a/bin/config.xml
+++ b/bin/config.xml
@@ -50,11 +50,11 @@
 <ExternalCommand2Host data="loupiac.eurecom.fr"/>
 <ExternalCommand2 data="/packages/uppaal/uppaal /homes/apvrille/TechTTool/UPPAAL/spec.xml"/>
 
-<LastOpenFile data="U:\TechTTool\TURTLEModeling\Chafic\CSmartCardProtocol_ludo_V01.xml"/>
+<LastOpenFile data="U:\TechTTool\TURTLEModeling\EVITA\evita_t2300_02.xml"/>
 
 
 
-<LastWindowAttributes x="112" y="60" width="1326" height="984" max="false" />
+<LastWindowAttributes x="28" y="29" width="1470" height="1087" max="false" />
 
 </TURTLECONFIGURATION>
 
diff --git a/src/ui/req/Requirement.java b/src/ui/req/Requirement.java
index 9d3396aed1..24cd7168c7 100755
--- a/src/ui/req/Requirement.java
+++ b/src/ui/req/Requirement.java
@@ -63,7 +63,8 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     protected int textY = 22;
 	protected int lineHeight = 30;
 	private double dlineHeight = 0.0;
-    protected boolean formal = false;
+    protected int type = 0;
+	// 0: normal, 1: formal, 2: security
     //protected int startFontSize = 10;
     protected Graphics graphics;
     //protected int iconSize = 30;
@@ -76,6 +77,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     
     protected final static String REGULAR_REQ = "<<Requirement>>";
     protected final static String FORMAL_REQ = "<<Formal Requirement>>";
+	protected final static String SECURITY_REQ = "<<Security Requirement>>";
     
     public final static int HIGH = 0;
     public final static int MEDIUM = 1;
@@ -86,6 +88,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     protected String kind = "";
     protected String criticality = "";
     protected String violatedAction = "";
+	protected String attackTreeNode = "";
 	
 	
 	
@@ -148,8 +151,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
         userResizable = true;
 		multieditable = true;
 		
-		
-        formal = false;
+        type = 0;
         
         // Name of the requirement
         name = "Requirement";
@@ -215,10 +217,14 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
 		if (displayText) {
 			size = currentFontSize - 2;
 			g.setFont(myFont.deriveFont((float)(myFont.getSize() - 2)));
-			if (formal) {
+			if (type == 1) {
 				drawLimitedString(g, FORMAL_REQ, x, y + size, width, 1);
 			} else {
-				drawLimitedString(g, REGULAR_REQ, x, y + size, width, 1);
+				if (type == 0) {
+					drawLimitedString(g, REGULAR_REQ, x, y + size, width, 1);
+				} else {
+					drawLimitedString(g, SECURITY_REQ, x, y + size, width, 1);
+				}
 			}			
 			size += currentFontSize;
 			g.setFont(myFontB);
@@ -229,7 +235,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
 		
 		g.setFont(myFont);
 		String texti;
-		if (formal) {
+		if (type == 1) {
 			texti = "TRDD";
 		} else {
 			texti = "Text";
@@ -254,10 +260,14 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
         }
         // Type and risk
 		if (size < (height - 2)) {
-			drawLimitedString(g, "Type=\"" + kind + "\"", x + textX, y + size, width, 0);
+			drawLimitedString(g, "Kind=\"" + kind + "\"", x + textX, y + size, width, 0);
 			size += currentFontSize;
 			if (size < (height - 2)) {
 				drawLimitedString(g, "Risk=\"" + criticality + "\"", x + textX, y + size, width, 0);
+				size += currentFontSize;
+				if ((size < (height - 2)) && (type == 2)) {
+					drawLimitedString(g, "Attack Tree Node=\"" + attackTreeNode + "\"", x + textX, y + size, width, 0);
+				}
 			}
 		}
 		
@@ -324,7 +334,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
 	
 	public boolean editAttributes() {
 		//String oldValue = value;
-        JDialogRequirement jdr = new JDialogRequirement(tdp.getGUI().getFrame(), "Setting attributes of Requirement " + getRequirementName(), text, kind, criticality, violatedAction, isFormal());
+        JDialogRequirement jdr = new JDialogRequirement(tdp.getGUI().getFrame(), "Setting attributes of Requirement " + getRequirementName(), text, kind, criticality, violatedAction, type, attackTreeNode);
         jdr.setSize(750, 400);
         GraphicLib.centerOnParent(jdr);
         jdr.show();
@@ -337,6 +347,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
         kind = jdr.getKind();
         criticality = jdr.getCriticality();
         violatedAction = jdr.getViolatedAction();
+		attackTreeNode = jdr.getAttackTreeNode();
         
         makeValue();
         return true;
@@ -365,11 +376,11 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     }
     
     public boolean isFormal() {
-        return formal;
+        return (type == 1);
     }
     
-    public void setFormal(boolean b) {
-        formal = b;
+    public void setType(int _type) {
+        type = _type;
     }
     
     public  int getType() {
@@ -382,18 +393,24 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     
     public void addActionToPopupMenu(JPopupMenu componentMenu, ActionListener menuAL, int x, int y) {
         componentMenu.addSeparator();
+		JMenuItem isRegular = null;
         JMenuItem isFormal = null;
-        if (formal) {
-            isFormal = new JMenuItem("Set a regular requirement");
-        } else {
-            isFormal = new JMenuItem("Set as formal requirement");
-        }
+		JMenuItem isSecurity = null;
+		
+		isRegular = new JMenuItem("Set as regular requirement");
+        isFormal = new JMenuItem("Set as formal requirement");
+		isSecurity = new JMenuItem("Set as security requirement");
+		
+		isRegular.addActionListener(menuAL);
 		isFormal.addActionListener(menuAL);
+		isSecurity.addActionListener(menuAL);
 		
 		JMenuItem editAttributes = new JMenuItem("Edit attributes");
 		editAttributes.addActionListener(menuAL);
         
-        componentMenu.add(isFormal);
+        componentMenu.add(isRegular);
+		componentMenu.add(isFormal);
+		componentMenu.add(isSecurity);
 		componentMenu.add(editAttributes);
     }
     
@@ -401,13 +418,18 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
         String s = e.getActionCommand();
         if (s.indexOf("regular") > -1) {
             //System.out.println("Set to regular");
-            formal = false;
+            type = 0;
         } else {
 			if (s.indexOf("formal") > 1) {
 				//System.out.println("Set to formal");
-				formal = true;
+				type = 1;
 			} else {
-				return editAttributes();
+				if (s.indexOf("security") > 1) {
+				//System.out.println("Set to formal");
+				type = 2;
+				} else {
+					return editAttributes();
+				}
 			}
         }
         return true;
@@ -415,30 +437,41 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     
     public String toString() {
         String ret =  getValue();
-        if (formal) {
+        if (type == 1) {
             ret = ret + " " + FORMAL_REQ;
         }  else {
-            ret = ret + " " + REGULAR_REQ;
+			if (type == 0) {
+				ret = ret + " " + REGULAR_REQ;
+			} else {
+				ret = ret + " " + SECURITY_REQ;
+			}
         }
 		
 		ret += " " + text;
 		ret += " criticality=" + criticality;
 		
-		if (formal) {
+		if (type == 1) {
 			ret += " violatedAction=" + violatedAction;
 		}
 		
+		if (type == 2) {
+			ret += " attackTreeNode =" + attackTreeNode;
+		}
+		
         return ret;
     }
     
     protected String translateExtraParam() {
         StringBuffer sb = new StringBuffer("<extraparam>\n");
-        sb.append("<Formal isFormal=\"");
+        /*sb.append("<Formal isFormal=\"");
         if (isFormal()) {
             sb.append("true\" />\n");
         } else {
             sb.append("false\" />\n");
-        }
+        }*/
+		sb.append("<type data=\"");
+		sb.append("" + type + "\" />\n");
+		
 		if (texts != null) {
             for(int i=0; i<texts.length; i++) {
                 //value = value + texts[i] + "\n";
@@ -455,6 +488,9 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
         sb.append("\" />\n");
         sb.append("<violated data=\"");
         sb.append(violatedAction);
+		sb.append("\" />\n");
+		sb.append("<attackTreeNode data=\"");
+        sb.append(attackTreeNode);
         sb.append("\" />\n");
         sb.append("</extraparam>\n");
         return new String(sb);
@@ -484,10 +520,17 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
                             if (elt.getTagName().equals("Formal")) {
                                 s = elt.getAttribute("isFormal");
                                 if (s.equals("true")) {
-                                    formal = true;
+                                    type = 1;
                                 } else {
-                                    formal = false;
+                                    type = 0;
                                 }
+                            } else if (elt.getTagName().equals("type")) {
+                                //System.out.println("Analyzing line0");
+                                s = elt.getAttribute("data");
+                                if (s.equals("null")) {
+                                    type = 0;
+                                }
+								type = Integer.decode(s).intValue();
                             } else if (elt.getTagName().equals("textline")) {
                                 //System.out.println("Analyzing line0");
                                 s = elt.getAttribute("data");
@@ -533,6 +576,10 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     public String getViolatedAction() {
         return violatedAction;
     }
+	
+	public String getAttackTreeNode() {
+        return attackTreeNode;
+    }
     
     public String getText() {
         return text;
@@ -551,13 +598,16 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
 	
 	public String getAttributes() {
 		String attr = "";
-		if (formal) {
+		if (type == 1) {
 			attr += "TRDD= " + text + "\n";
 		} else {
 			attr += "Text= " + text + "\n";
 		}
-		attr += "Type= " + kind + "\n";
+		attr += "Kind= " + kind + "\n";
 		attr += "Risk= " + criticality + "\n";
+		if (type == 2) {
+			attr += "AttackTreeNode=" + attackTreeNode + "\n";
+		}
 		return attr;
 	}
 	
@@ -575,12 +625,17 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
 		
 		// Must find for both modes which width is desirable
 		String s0, s1;
-		if (formal) {
+		if (type == 1) {
 			s0 = FORMAL_REQ;
 			s1 = "TRDD=";
 		} else {
-			s0 = REGULAR_REQ;
-			s1 = "Text=";
+			if (type == 0) {
+				s0 = REGULAR_REQ;
+				s1 = "Text=";
+			} else {
+				s0 = SECURITY_REQ;
+				s1 = "Text=";
+			}
 		}
 		
 		graphics.setFont(f2);
@@ -609,7 +664,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
 				w4 = Math.max(w4, w3+2);
 			}
 		}
-		w3 = graphics.getFontMetrics().stringWidth("Type=\"" + kind + "\"") + 2;
+		w3 = graphics.getFontMetrics().stringWidth("Kind=\"" + kind + "\"") + 2;
 		w4 = Math.max(w4, w3);
 		w3 = graphics.getFontMetrics().stringWidth("Risk=\"" + criticality + "\"") + 2;
 		w4 = Math.max(w4, w3);
diff --git a/src/ui/req/TAttributeRequirement.java b/src/ui/req/TAttributeRequirement.java
index 6406f72511..d2edeb399f 100755
--- a/src/ui/req/TAttributeRequirement.java
+++ b/src/ui/req/TAttributeRequirement.java
@@ -226,7 +226,7 @@ public class TAttributeRequirement extends TGCWithoutInternalComponent {
     
     public boolean editOndoubleClick(JFrame frame) {
         //String oldValue = value;
-        JDialogRequirement jdr = new JDialogRequirement(frame, "Setting attributes of Requirement " + ((Requirement)(getTopFather())).getRequirementName(), text, kind, criticality, violatedAction, ((Requirement)(getTopFather())).isFormal());
+        /*JDialogRequirement jdr = new JDialogRequirement(frame, "Setting attributes of Requirement " + ((Requirement)(getTopFather())).getRequirementName(), text, kind, criticality, violatedAction, ((Requirement)(getTopFather())).isFormal());
         jdr.setSize(750, 400);
         GraphicLib.centerOnParent(jdr);
         jdr.show();
@@ -241,7 +241,7 @@ public class TAttributeRequirement extends TGCWithoutInternalComponent {
         violatedAction = jdr.getViolatedAction();
         
         makeValue();
-        checkMySize();
+        checkMySize();*/
         return true;
     }
     
diff --git a/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java b/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java
index d0b2ff5d63..1f7d5cb8ea 100755
--- a/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java
+++ b/src/ui/tmlcompd/TMLComponentTaskDiagramPanel.java
@@ -370,12 +370,12 @@ public class TMLComponentTaskDiagramPanel extends TDiagramPanel implements TDPWi
 	}
 	
 	public void addNonMappedTMLPritimiveComponentsNames(TMLCPrimitiveComponent tgc, ArrayList<String> list, String _topName, TMLArchiDiagramPanel _tadp, boolean ref, String _name) {
-		name = tgc.getValue();
-		if (ref && name.equals(_name)) {
-			list.add(_topName + "::" + name);
+		String name1 = tgc.getValue();
+		if (ref && name1.equals(_name)) {
+			list.add(_topName + "::" + name1);
 		} else {
-			if (!_tadp.isMapped(_topName,  name)) {
-				list.add(_topName + "::" + name);
+			if (!_tadp.isMapped(_topName,  name1)) {
+				list.add(_topName + "::" + name1);
 			}
 		}
 	}
diff --git a/src/ui/tmldd/TMLArchiMemoryNode.java b/src/ui/tmldd/TMLArchiMemoryNode.java
index f916bfadda..63c087b418 100755
--- a/src/ui/tmldd/TMLArchiMemoryNode.java
+++ b/src/ui/tmldd/TMLArchiMemoryNode.java
@@ -172,7 +172,7 @@ public class TMLArchiMemoryNode extends TMLArchiCommunicationNode implements Swa
 		String tmpName;
         
 		JDialogMemoryNode dialog = new JDialogMemoryNode(frame, "Setting Memory attributes", this);
-		dialog.setSize(250, 350);
+		dialog.setSize(400, 350);
         GraphicLib.centerOnParent(dialog);
         dialog.show(); // blocked until dialog has been closed
         
diff --git a/src/ui/window/JDialogRequirement.java b/src/ui/window/JDialogRequirement.java
index c5b64e5964..4b48df3f9a 100755
--- a/src/ui/window/JDialogRequirement.java
+++ b/src/ui/window/JDialogRequirement.java
@@ -61,11 +61,11 @@ public class JDialogRequirement extends javax.swing.JDialog implements ActionLis
     
     private JPanel panel1, panel2;
     private Frame frame;
-    private String kind, criticality, violatedAction;
+    private String kind, criticality, violatedAction, attackTreeNode;
     //private String actionbegin1, actionend1, actionbegin2, actionend2;
     //private String time1, time2;
     private String text;
-    private boolean formal;
+    private int type;
     
     // Panel1
     protected JTextArea jta;
@@ -74,21 +74,22 @@ public class JDialogRequirement extends javax.swing.JDialog implements ActionLis
     
     //Panel2
     private JComboBox kindBox, criticalityBox;
-    private JTextField violatedActionBox;
+    private JTextField violatedActionBox, attackTreeNodeBox;
     
     // Main Panel
     private JButton closeButton;
     private JButton cancelButton;
     
     /** Creates new form  */
-    public JDialogRequirement(Frame _frame, String _title, String _text, String _kind, String _criticality, String _violatedAction, boolean _formal) {
+    public JDialogRequirement(Frame _frame, String _title, String _text, String _kind, String _criticality, String _violatedAction, int _type, String _attackTreeNode) {
         super(_frame, _title, true);
         frame = _frame;
         text = _text;
         kind = _kind;
         criticality = _criticality;
         violatedAction = _violatedAction;
-        formal = _formal;
+        type = _type;
+		attackTreeNode = _attackTreeNode;
         
         initComponents();
         myInitComponents();
@@ -114,11 +115,13 @@ public class JDialogRequirement extends javax.swing.JDialog implements ActionLis
         
         panel1 = new JPanel();
         panel1.setLayout(gridbag1);
-        if (formal) {
+        if (type == 1) {
             panel1.setBorder(new javax.swing.border.TitledBorder("Setting formal information on requirement "));
-        } else {
+        } else if (type == 0) {
             panel1.setBorder(new javax.swing.border.TitledBorder("Setting unformal text information on requirement "));
-        }
+        } else {
+			panel1.setBorder(new javax.swing.border.TitledBorder("Setting text information on security requirement "));
+		}
         panel1.setPreferredSize(new Dimension(350, 250));
         
         panel2 = new JPanel();
@@ -209,10 +212,24 @@ public class JDialogRequirement extends javax.swing.JDialog implements ActionLis
         
         c2.gridwidth = GridBagConstraints.REMAINDER; //end row
         violatedActionBox = new JTextField(violatedAction, 15);
-        if (!formal) {
+        if (type != 1) {
             violatedActionBox.setEnabled(false);
-        }
+        } else {
+			violatedActionBox.setEnabled(true);
+		}
         panel2.add(violatedActionBox, c2);
+		
+		c2.gridwidth = 1;
+        panel2.add(new JLabel("AttackTreeNode:"), c2);
+		
+		c2.gridwidth = GridBagConstraints.REMAINDER; //end row
+        attackTreeNodeBox = new JTextField(attackTreeNode, 50);
+        if (type != 2) {
+            attackTreeNodeBox.setEnabled(false);
+        } else {
+			attackTreeNodeBox.setEnabled(true);
+		}
+        panel2.add(attackTreeNodeBox, c2);
         
         // main panel;
         c0.gridwidth = 1;
@@ -285,5 +302,9 @@ public class JDialogRequirement extends javax.swing.JDialog implements ActionLis
     public String getViolatedAction() {
         return violatedActionBox.getText();
     }
+	
+	public String getAttackTreeNode() {
+        return attackTreeNodeBox.getText();
+    }
     
 }
-- 
GitLab