diff --git a/src/myutil/TraceManager.java b/src/myutil/TraceManager.java index c8bb517275b965cc20fe80f77775059dfbd5a868..af02502282814f849452937ca08ec0395efe311e 100644 --- a/src/myutil/TraceManager.java +++ b/src/myutil/TraceManager.java @@ -62,6 +62,7 @@ public class TraceManager { switch(devPolicy) { case TO_CONSOLE: System.out.println(_s); + break; default: System.out.println(_s); } @@ -71,6 +72,7 @@ public class TraceManager { switch(userPolicy) { case TO_CONSOLE: System.out.println(_s); + break; default: System.out.println(_s); } @@ -80,6 +82,7 @@ public class TraceManager { switch(errPolicy) { case TO_CONSOLE: System.err.println(_s); + break; default: System.err.println(_s); } diff --git a/src/ui/AvatarDesignPanel.java b/src/ui/AvatarDesignPanel.java index c56be8bebf2b1f2e5937c58961c14f7ac6032ff8..bf1ec6b9185feb6cd4bd19ed3002e5a3c86e53a2 100644 --- a/src/ui/AvatarDesignPanel.java +++ b/src/ui/AvatarDesignPanel.java @@ -129,6 +129,10 @@ public class AvatarDesignPanel extends TURTLEPanel { //jsp.setVisible(true); } + + public Vector getAllSignals(String _name) { + return abdp.getAllSignalsOfBlock(_name); + } public String saveHeaderInXml() { return "<Modeling type=\"AVATAR Design\" nameTab=\"" + mgui.getTabName(this) + "\" >\n"; diff --git a/src/ui/AvatarMethod.java b/src/ui/AvatarMethod.java new file mode 100644 index 0000000000000000000000000000000000000000..fb9b4ff3423fa92cef945b8bc74f5d8706e9d665 --- /dev/null +++ b/src/ui/AvatarMethod.java @@ -0,0 +1,332 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class AvatarMethod + * Method in Avatar ... + * Creation: 08/04/2010 + * @version 1.0 08/04/2010 + * @author Ludovic APVRILLE + * @see + */ + + +package ui; + +import translator.*; +import translator.tojava.*; +import java.util.*; + +import myutil.*; + +public class AvatarMethod { + + // Types of parameters + public final static int NATURAL = 0; + public final static int BOOLEAN = 1; + public final static int INTEGER = 2; + + protected String id; + protected String typeIds[]; + protected String types[]; + + + public AvatarMethod(String _id, String _types[], String _typeIds[]) { + id = _id; + types = _types; + typeIds = _typeIds; + } + + // An operation must be of the form: "id(type id0, type id1, ...) + // Returns null in case the method is not valid + public static AvatarMethod isAValidMethod(String _method) { + String method, tmp, id; + + if (_method == null) { + return null; + } + + method = _method.trim(); + + if (method.length() == 0) { + return null; + } + + int index0 = _method.indexOf('('); + int index1 = _method.indexOf(')'); + + // Only one of the two parenthesis + if ((index0 == -1) && (index1 > -1)) { + return null; + } + + if ((index1 == -1) && (index0 > -1)) { + return null; + } + + // No parenthesis at all + if ((index0 == -1) && (index1 == -1)) { + if (isAValidId(method, true, true, true)) { + return new AvatarMethod(method, new String [0], new String[0]); + } else { + return null; + } + } + + // Check parenthesis order + if (index0 > index1) { + return null; + } + + // Check that only one parenthesis of each type + tmp = method.substring(Math.min(index0+1, method.length()), method.length()); + if (tmp.indexOf('(') > -1) { + return null; + } + tmp = method.substring(Math.min(index1+1, method.length()), method.length()); + if (tmp.indexOf(')') > -1) { + return null; + } + + // And so: parenthesis are in the right order, and are used only one for each + + // Before parenthesis -> id + tmp = method.substring(0, index0).trim(); + if (!isAValidId(tmp, true, true, true)) { + return null; + } + id = tmp; + + // Between parenthesis: parameters of the form: String space String comma + // We replace double space by spaces and then spaces by commas + tmp = method.substring(index0+1, index1).trim(); + + // no parameter? + if (tmp.length() == 0) { + return new AvatarMethod(id, new String [0], new String[0]); + } + + // Has parameters... + tmp = Conversion.replaceAllString(tmp, " ", " "); + tmp = Conversion.replaceAllString(tmp, " ,", ","); + tmp = Conversion.replaceAllString(tmp, ", ", ","); + tmp = Conversion.replaceAllChar(tmp, ' ', ","); + + //TraceManager.addDev("tmp=" + tmp); + + String splitted[] = tmp.split(","); + int size = splitted.length/2; + //TraceManager.addDev("Nb of parameters=" + size); + String types[] = new String[size]; + String typeIds[] = new String[size]; + boolean b0, b1; + int i; + + /*for(i=0; i<splitted.length; i++) { + TraceManager.addDev("splitted[" + i + "]: " + splitted[i]); + }*/ + + try { + for(i=0; i<splitted.length; i = i + 2){ + if (splitted[i].length() == 0) { + return null; + } + if (splitted[i+1].length() == 0) { + return null; + } + if (!isAValidId(splitted[i], false, false, false)) { + //TraceManager.addDev("Unvalid type: " + splitted[i]); + return null; + } + if (!isAValidId(splitted[i+1], true, true, true)) { + //TraceManager.addDev("Unvalid id of parameter " + splitted[i+1]); + return null; + } + //TraceManager.addDev("Adding parameter: " + splitted[i] + " " + splitted[i+1]); + types[i/2] = splitted[i]; + typeIds[i/2] = splitted[i+1]; + } + } catch (Exception e) { + TraceManager.addDev("AvatarMethod Exception:" + e.getMessage()); + return null; + } + + return new AvatarMethod(id, types, typeIds); + } + + public String getId() { return id;} + public String[] getTypes(){ return types;} + public String[] getTypeIds(){ return typeIds;} + + public String getType(int _index) { + if ((_index <0) || (_index>=types.length)) { + return null; + } + return types[_index]; + } + + public String getTypeId(int _index) { + if ((_index <0) || (_index>=typeIds.length)) { + return null; + } + return typeIds[_index]; + } + + + public static boolean isAValidId(String id, boolean checkKeyword, boolean checkJavaKeyword, boolean checkTypes) { + // test whether _id is a word + + if ((id == null) || (id.length() < 1)) { + return false; + } + + String lowerid = id.toLowerCase(); + boolean b1, b2, b3, b4, b5; + b1 = (id.substring(0,1)).matches("[a-zA-Z]"); + b2 = id.matches("\\w*"); + if (checkKeyword) { + b3 = !RTLOTOSKeyword.isAKeyword(lowerid); + } else { + b3 = true; + } + if (checkJavaKeyword) { + b5 = !JKeyword.isAKeyword(lowerid); + } else { + b5 = true; + } + + if (checkTypes) { + if ((lowerid.equals(getStringType(0).toLowerCase())) || (lowerid.equals(getStringType(1).toLowerCase())) || (lowerid.equals(getStringType(2).toLowerCase())) || (lowerid.equals(getStringType(3).toLowerCase())) || (lowerid.equals(getStringType(4).toLowerCase()))) { + b4 = false; + } else { + b4 = true; + } + } else { + b4 = true; + } + + return (b1 && b2 && b3 && b4 && b5); + } + + public static boolean notIn(String s, Vector forbidden) { + if (forbidden == null) { + return true; + } + + AvatarMethod am; + + for(int i= 0; i<forbidden.size(); i++) { + am = (AvatarMethod)(forbidden.elementAt(i)); + if (s.compareTo(am.getId()) ==0) { + return false; + } + } + + return true; + } + + public static int getType(String s) { + if (s.equals("nat")) { + return NATURAL; + } else if (s.equals("bool")) { + return BOOLEAN; + } else if (s.equals("int")) { + return INTEGER; + } + return -1; + } + + public static String getStringType(int type) { + switch(type) { + case NATURAL: + return "nat"; + case BOOLEAN: + return "bool"; + case INTEGER: + return "int"; + } + return ""; + } + + public String toString() { + int cpt = 0; + + String method = id + "("; + for (int i=0; i<types.length; i++) { + method += types[i] + " " + typeIds[i]; + if (i<(types.length - 1)) { + method += ", "; + } + } + method += ")"; + return method; + } + + // Comparison on id only + public boolean equals(Object o) { + if (!(o instanceof AvatarMethod)) { + return false; + } + + AvatarMethod am = (AvatarMethod)o; + if (getId().equals(am.getId())) { + return true; + } + return false; + + } + + // Comparison on all fields + /*public int compareTo(Object o){ + if (!(o instanceof AvatarMethod)) { + return 1; + } + + AvatarMethod am = (AvatarMethod)o; + if (!(getId().equals(am.getId()))) { + return 1; + } + + + return 0; + + }*/ + + public AvatarMethod makeClone() { + return isAValidMethod(toString()); + } +} \ No newline at end of file diff --git a/src/ui/AvatarSignal.java b/src/ui/AvatarSignal.java new file mode 100644 index 0000000000000000000000000000000000000000..323a136d9500f5f900901b50464ad5303a47c8f0 --- /dev/null +++ b/src/ui/AvatarSignal.java @@ -0,0 +1,204 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class AvatarSignal + * Signals in Avatar ... + * Creation: 08/04/2010 + * @version 1.0 08/04/2010 + * @author Ludovic APVRILLE + * @see + */ + + +package ui; + +import translator.*; +import translator.tojava.*; +import java.util.*; + +import myutil.*; + +public class AvatarSignal extends AvatarMethod { + + // Signa type + public final static int IN = 0; + public final static int OUT = 1; + + private int inout; + + + public AvatarSignal(int _inout, String _id, String _types[], String _typeIds[]) { + super(_id, _types, _typeIds); + inout = _inout; + } + + public static AvatarSignal isAValidSignal(String _content) { + String tmp = _content.trim(); + if (!((_content.startsWith("in ")) || (_content.startsWith("out ")))) { + return null; + } + + int tmpinout; + if (_content.startsWith("in ")) { + tmpinout = IN; + } else { + tmpinout = OUT; + } + + return isAValidSignal(tmpinout, tmp.substring(3, tmp.length()).trim()); + } + + public static AvatarSignal isAValidSignal(int _inout, String _content) { + if (!((_inout == IN) || (_inout == OUT))) { + return null; + } + + AvatarMethod am = isAValidMethod(_content); + if (am == null) { + TraceManager.addDev("invalid signal: " + _content); + return null; + } + AvatarSignal as = new AvatarSignal(_inout, am.getId(), am.getTypes(), am.getTypeIds()); + + return as; + } + + public static boolean isAValidUseSignal(String _content) { + if (_content.indexOf("()") == -1) { + _content = Conversion.replaceAllString(_content, "(", "#int "); + _content = Conversion.replaceAllString(_content, "#", "("); + _content = Conversion.replaceAllString(_content, ",", "#int "); + _content = Conversion.replaceAllString(_content, "#", ","); + } + TraceManager.addDev("content:" + _content); + return (isAValidMethod(_content) != null); + } + + public int getInOut() { + return inout; + } + + public static String getStringInOut(int _inout) { + switch(_inout) { + case IN: + return "in"; + case OUT: + default: + return "out"; + } + } + + public String toBasicString() { + return super.toString(); + } + + public String toString() { + int cpt = 0; + + String signal = getStringInOut(inout) + " "; + signal += super.toString(); + return signal; + } + + + public String getUseDescription() { + String s = getId() + "("; + for(int i=0; i<typeIds.length; i++) { + s += typeIds[i]; + if (i < (typeIds.length - 1)) { + s += ", "; + } + } + s += ")"; + return s; + } + + // Comparison on id only + public boolean equals(Object o) { + if (!(o instanceof AvatarSignal)) { + return false; + } + + AvatarSignal as = (AvatarSignal)o; + if (getId().equals(as.getId())) { + return true; + } + return false; + + } + + // Comparison on all fields + /*public int compareTo(Object o){ + if (!(o instanceof AvatarMethod)) { + return 1; + } + + AvatarMethod am = (AvatarMethod)o; + if (!(getId().equals(am.getId()))) { + return 1; + } + + + return 0; + + }*/ + + public AvatarSignal makeClone() { + return isAValidSignal(inout, super.toString()); + } + + public boolean isCompatibleWith(AvatarSignal _as) { + if (_as.getInOut() == getInOut()) { + return false; + } + + String[] astypes = _as.getTypes(); + + if (astypes.length != types.length) { + return false; + } + + for(int i=0; i<types.length; i++) { + if (!(types[i].compareTo(astypes[i]) == 0)) { + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git a/src/ui/ColorManager.java b/src/ui/ColorManager.java index d1533b6c29a320bc5c688e2434df7fffd0741ba2..797970d4bbbd79fbd8e0711967901f853ae44953 100755 --- a/src/ui/ColorManager.java +++ b/src/ui/ColorManager.java @@ -126,7 +126,11 @@ public class ColorManager { public static final Color ATD_ROOT_ATTACK = new Color(243, 131, 10); public static final Color ATD_CONSTRAINT = new Color(191, 153, 161); - public static final Color AVATAR_BLOCK = new Color(128, 180, 205); + //public static final Color AVATAR_BLOCK = new Color(128, 180, 205); + //public static final Color AVATAR_BLOCK = new Color(158, 218, 227); + public static final Color AVATAR_BLOCK = new Color(149, 193, 200); + public static final Color AVATAR_SEND_SIGNAL = new Color(128, 180, 205); + public static final Color AVATAR_RECEIVE_SIGNAL = new Color(128, 180, 205); public static final Color DIAGRAM_BACKGROUND = Color.white; diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java index 3aae8b4c455120709106411e12f1ca102badc98d..8bad242f45be394417afb09fa289bb3b87eb568e 100755 --- a/src/ui/GTURTLEModeling.java +++ b/src/ui/GTURTLEModeling.java @@ -5,7 +5,7 @@ * This software is a computer program whose purpose is to allow the * edition of TURTLE analysis, design and deployment diagrams, to * allow the generation of RT-LOTOS or Java code from this diagram, - * and at last to almalow the analysis of formal validation traces + * and at last to allow the analysis of formal validation traces * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP * from INRIA Rhone-Alpes. * @@ -3375,9 +3375,9 @@ public class GTURTLEModeling { makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tdp); //System.out.println("Subcomponents"); makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tdp); - //System.out.println("RealPoints"); + TraceManager.addDev("RealPoints"); connectConnectorsToRealPoints(tdp); - //System.out.println("Structure changed"); + TraceManager.addDev("Structure changed"); tdp.structureChanged(); //System.out.println("Post loading"); makePostLoading(tdp, 0); @@ -3397,6 +3397,11 @@ public class GTURTLEModeling { //System.out.println("Connectors..."); ((AttackTreeDiagramPanel)tdp).setConnectorsToFront(); } + + if (tdp instanceof AvatarBDPanel) { + //System.out.println("Connectors..."); + ((AvatarBDPanel)tdp).setConnectorsToFront(); + } } // AVATAR @@ -4126,7 +4131,7 @@ public class GTURTLEModeling { throw new MalformedModelingException(); } - //System.out.println("Making TGComponent of type " + myType + " and of name " + myName); + TraceManager.addDev("Making TGComponent of type " + myType + " and of name " + myName); //TGComponent is ready to be built if(fatherId != -1) { fatherId += decId; @@ -4168,7 +4173,7 @@ public class GTURTLEModeling { } else { tgc = TGComponentManager.addComponent(myX, myY, myType, tdp); } - //System.out.println("TGComponent built " + myType); + TraceManager.addDev("TGComponent built " + myType); if (tgc == null) { throw new MalformedModelingException(); @@ -4233,7 +4238,7 @@ public class GTURTLEModeling { } if ((tgc instanceof AvatarBDBlock) && (decId >0)){ - //System.out.println("Going to load ad of task " + oldClassName + " myValue=" + myValue); + TraceManager.addDev("Going to load ad of task " + oldClassName + " myValue=" + myValue); loadAvatarSMD(tdp, oldClassName, myValue); } @@ -4312,7 +4317,7 @@ public class GTURTLEModeling { }*/ } catch (Exception e) { - System.out.println("Exception XML Component " + e.getMessage()); + System.out.println("Exception XML Component " + e.getMessage() + "trace=" + e.getStackTrace()); throw new MalformedModelingException(); } return tgc; diff --git a/src/ui/IconManager.java b/src/ui/IconManager.java index c558019efb993fb0c623ccaa11cad33c33dc6835..c470a257699d07748aef27c4c758c0013f306acb 100755 --- a/src/ui/IconManager.java +++ b/src/ui/IconManager.java @@ -56,8 +56,8 @@ import javax.swing.ImageIcon; * @see */ public class IconManager { - - public static ImageIcon imgic8, imgic9; + + public static ImageIcon imgic8, imgic9; //Added by Solange public static ImageIcon imgic0, imgic1; public static Image img8, img9; @@ -133,11 +133,16 @@ public class IconManager { // NC public static ImageIcon imgic3000; + // AVATAR + public static ImageIcon imgic5000, imgic5002, imgic5004, imgic5006, imgic5008; + + // Delegate ports image removed, by Solange //public static ImageIcon imgic2102; // Image of the help button for the ports (Solange) public static ImageIcon imgic2111; //New icon created by Solange + //private static String icon7 = "images/turtle_large.gif"; private static String icon8 = "images/turtle_16.gif"; @@ -467,6 +472,10 @@ public class IconManager { private static String icon3000= "images/nc.gif"; + private static String icon5000 = "images/avatarblock.gif"; + private static String icon5002 = "images/avatarbdcomp.gif"; + private static String icon5004 = "images/avatarbdlink.gif"; + public IconManager() { } @@ -775,6 +784,12 @@ public class IconManager { // NC imgic3000 = getIcon(icon3000); + + // AVATAR + //imgic3000 = getIcon(icon3000); + imgic5000 = getIcon(icon5000); + imgic5002 = getIcon(icon5002); + imgic5004 = getIcon(icon5004); } } // Class diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java index e2081f3b29fe95c3316a1a456162eb9762e209e7..62c8490cd2f6ae6b006346d16a3d49c0571196ba 100755 --- a/src/ui/MainGUI.java +++ b/src/ui/MainGUI.java @@ -1278,7 +1278,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { dtree.reinit(); dtree.forceUpdate(); - frame.setTitle("TURTLE Toolkit"); + frame.setTitle("TTool"); frame.repaint(); } } @@ -1403,7 +1403,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { newTurtleModeling(); //gtm.saveOperation(tcdp); file = null; - frame.setTitle("TURTLE Toolkit: unsaved project"); + frame.setTitle("TTool: unsaved project"); } else { // check if previous modeling is saved boolean b = actions[TGUIAction.ACT_SAVE].isEnabled(); @@ -1440,7 +1440,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { rgautprojfile = null; rgautprojdotfile = null; - frame.setTitle("TURTLE Toolkit: unsaved project"); + frame.setTitle("TTool: unsaved project"); } } @@ -1758,7 +1758,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { //System.out.println("Merging"); gtm.loadModelingFromXML(gtm.mergeTURTLEGModeling(oldmodeling, s)); //gtm.saveOperation(tcdp); - frame.setTitle("TURTLE Toolkit: " + file.getAbsolutePath()); + frame.setTitle("TTool: " + file.getAbsolutePath()); makeLotosFile(); } catch (MalformedModelingException mme) { @@ -1823,12 +1823,12 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { try { gtm.loadModelingFromXML(s); //gtm.saveOperation(tcdp); - frame.setTitle("TURTLE Toolkit: " + file.getAbsolutePath()); + frame.setTitle("TTool: " + file.getAbsolutePath()); makeLotosFile(); } catch (MalformedModelingException mme) { JOptionPane.showMessageDialog(frame, "Modeling could not be loaded (unsupported file) ", "Error when loading modeling", JOptionPane.INFORMATION_MESSAGE); - frame.setTitle("TURTLE Toolkit: unamed project"); + frame.setTitle("TToolt: unamed project"); } dtree.forceUpdate(); } @@ -1872,12 +1872,12 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { try { gtm.loadModelingFromXML(s); //gtm.saveOperation(tcdp); - frame.setTitle("TURTLE Toolkit: " + file.getAbsolutePath()); + frame.setTitle("TTool: " + file.getAbsolutePath()); makeLotosFile(); } catch (MalformedModelingException mme) { JOptionPane.showMessageDialog(frame, "Modeling could not be loaded (unsupported file) ", "Error when loading modeling", JOptionPane.INFORMATION_MESSAGE); - frame.setTitle("TURTLE Toolkit: unamed project"); + frame.setTitle("TTool: unamed project"); } dtree.forceUpdate(); @@ -2054,7 +2054,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { fos.close(); updateLastOpenFile(file); setMode(MODEL_SAVED); - String title = "TURTLE Toolkit: " + file.getAbsolutePath(); + String title = "TTool: " + file.getAbsolutePath(); if (!frame.getTitle().equals(title)) { frame.setTitle(title); } @@ -2739,6 +2739,22 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { dtree.forceUpdate(); return ret; } + + public Vector getAllSignals() { + TURTLEPanel tp = getCurrentTURTLEPanel(); + if (tp == null) { + return null; + } + + if (!(tp instanceof AvatarDesignPanel)) { + return null; + } + AvatarDesignPanel adp = (AvatarDesignPanel)tp; + + String name = getCurrentTDiagramPanel().getName(); + + return adp.getAllSignals(name); + } public Vector getCheckingErrors() { return gtm.getCheckingErrors(); @@ -4947,19 +4963,22 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { } public boolean newAvatarBDBlockName(TURTLEPanel tp, String old, String niou) { - //System.out.println("Panel=" + tp + " Old task name = " + old + " New task name=" + niou); + TraceManager.addDev("Panel=" + tp + " Old task name = " + old + " New task name=" + niou); JTabbedPane jtp = tp.tabbedPane; - for(int i = 0; i<jtp.getTabCount(); i++) { - //System.out.println("jtp = " + jtp.getTitleAt(i)); + int i; + for(i = 0; i<jtp.getTabCount(); i++) { + TraceManager.addDev("jtp = " + jtp.getTitleAt(i)); if (jtp.getTitleAt(i).equals(niou)) { return false; } } - //System.out.println("old " + old + " niou " + niou); - for(int i = 0; i<jtp.getTabCount(); i++) { - //System.out.println("Tab " + i + " = " + mainTabbedPane.getTitleAt(i)); - //System.out.println("jtp = " + jtp.getTitleAt(i)); - if (jtp.getTitleAt(i).equals(old)) { + TraceManager.addDev("old " + old + " niou " + niou); + TraceManager.addDev("nb Of panels:"+ jtp.getTabCount()); + for(i = 0; i<jtp.getTabCount(); i++) { + //TraceManager.addDev("Tab " + i + " = " + mainTabbedPane.getTitleAt(i)); + TraceManager.addDev("jtp = >" + jtp.getTitleAt(i) + "<"); + TraceManager.addDev("old = >" + old + "<"); + if (jtp.getTitleAt(i).compareTo(old) == 0) { jtp.setTitleAt(i, niou); jtp.setToolTipTextAt(i, "Opens the state machine of " + niou); TDiagramPanel tdp; @@ -4968,7 +4987,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { tdp = (TDiagramPanel)(tp.panels.elementAt(j)); if (tdp.getName().equals(old)) { tdp.setName(niou); - //System.out.println("Renamed to " + niou); + TraceManager.addDev("Renamed to " + niou); } } @@ -5027,7 +5046,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { changeMade(null, -1); } catch (MalformedModelingException mme) { JOptionPane.showMessageDialog(frame, "Modeling could not be loaded (unsupported file) ", "Error when loading modeling", JOptionPane.INFORMATION_MESSAGE); - frame.setTitle("TURTLE Toolkit: unamed project"); + frame.setTitle("TTool: unamed project"); } } @@ -5715,6 +5734,10 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.AVATARSMD_STOP_STATE); } else if (command.equals(actions[TGUIAction.ASMD_CONNECTOR].getActionCommand())) { actionOnButton(TGComponentManager.CONNECTOR, TGComponentManager.AVATARSMD_CONNECTOR); + } else if (command.equals(actions[TGUIAction.ASMD_SEND_SIGNAL].getActionCommand())) { + actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.AVATARSMD_SEND_SIGNAL); + } else if (command.equals(actions[TGUIAction.ASMD_RECEIVE_SIGNAL].getActionCommand())) { + actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.AVATARSMD_RECEIVE_SIGNAL); } else if (command.equals(actions[TGUIAction.TCD_ASSOCIATION].getActionCommand())) { actionOnButton(TGComponentManager.CONNECTOR, TGComponentManager.CONNECTOR_ASSOCIATION); diff --git a/src/ui/TAttribute.java b/src/ui/TAttribute.java index 31727f2fc34e895a7d7df8e4af2278bf43f365e0..e13eadc3bdbe4e4740391b3cbd3323e3729624cf 100755 --- a/src/ui/TAttribute.java +++ b/src/ui/TAttribute.java @@ -68,6 +68,7 @@ public class TAttribute { public final static int OTHER = 5; public final static int QUEUE_NAT = 6; public final static int ARRAY_NAT = 7; + public final static int INTEGER = 8; private int access; @@ -247,6 +248,8 @@ public class TAttribute { return QUEUE_NAT; } else if (s.equals("Array_nat")) { return ARRAY_NAT; + } else if (s.equals("int")) { + return ARRAY_NAT; } else if (!s.equals("")) { return OTHER; } @@ -287,6 +290,8 @@ public class TAttribute { return "Queue_nat"; case ARRAY_NAT: return "Array_nat"; + case INTEGER: + return "int"; default: return ""; } diff --git a/src/ui/TGComponentManager.java b/src/ui/TGComponentManager.java index 6feb6c7f4393aaca1ae2b238c30fe865a0f5bb9f..acb00606b26e07c2a81cb688bf6b3c2cd9c7970c 100755 --- a/src/ui/TGComponentManager.java +++ b/src/ui/TGComponentManager.java @@ -293,6 +293,8 @@ public class TGComponentManager { public static final int AVATARSMD_START_STATE = 5100; public static final int AVATARSMD_STOP_STATE = 5101; public static final int AVATARSMD_CONNECTOR = 5102; + public static final int AVATARSMD_SEND_SIGNAL = 5103; + public static final int AVATARSMD_RECEIVE_SIGNAL = 5104; public static final int EDIT = -1; @@ -312,6 +314,12 @@ public class TGComponentManager { break; case AVATARSMD_STOP_STATE: tgc = new AvatarSMDStopState(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); + break; + case AVATARSMD_SEND_SIGNAL: + tgc = new AvatarSMDSendSignal(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); + break; + case AVATARSMD_RECEIVE_SIGNAL: + tgc = new AvatarSMDReceiveSignal(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp); break; // Others @@ -739,6 +747,10 @@ public class TGComponentManager { return AVATARSMD_STOP_STATE; } else if (tgc instanceof AvatarSMDConnector) { return AVATARSMD_CONNECTOR; + } else if (tgc instanceof AvatarSMDSendSignal) { + return AVATARSMD_SEND_SIGNAL; + } else if (tgc instanceof AvatarSMDReceiveSignal) { + return AVATARSMD_RECEIVE_SIGNAL; // Others } else if (tgc instanceof TADDeterministicDelay) { diff --git a/src/ui/TGUIAction.java b/src/ui/TGUIAction.java index 3aad5dcad61b2d7139afdd4f77370f7050e99e8a..f1386181fa1047bcfc45882d2b31c86f69cdb827 100755 --- a/src/ui/TGUIAction.java +++ b/src/ui/TGUIAction.java @@ -303,6 +303,8 @@ public class TGUIAction extends AbstractAction { public static final int ASMD_CONNECTOR = 292; public static final int ASMD_START = 293; public static final int ASMD_STOP = 294; + public static final int ASMD_SEND_SIGNAL = 296; + public static final int ASMD_RECEIVE_SIGNAL = 297; public static final int ACT_MODEL_CHECKING = 25; public static final int ACT_GEN_RTLOTOS = 27; @@ -410,7 +412,7 @@ public class TGUIAction extends AbstractAction { //Action for the help button created by Solange public static final int PRUEBA_1 = 205; - public static final int NB_ACTION = 296; + public static final int NB_ACTION = 298; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -790,15 +792,17 @@ public class TGUIAction extends AbstractAction { actions[EXTERNAL_ACTION_2] = new TAction("user-command-2", "User command 2", IconManager.imgic338, IconManager.imgic338, "User command 2", "Execute the user command #2", '0'); // AVATAR Block Diagrams - actions[ABD_BLOCK] = new TAction("abd-block", "Add a block", IconManager.imgic1070, IconManager.imgic1070, "Block", "Add a SysML Block to the currently opened AVATAR Block Diagram", 0); - actions[ABD_COMPOSITION_CONNECTOR] = new TAction("abd-composition-connector", "Add a composition connector between blocks", IconManager.imgic1076, IconManager.imgic1076, "Composition connector", "Add a composition between blocks of the currently opened AVATAR Block Diagram", 0); - actions[ABD_PORT_CONNECTOR] = new TAction("abd-port-connector", "Add a composition connector between blocks", IconManager.imgic1076, IconManager.imgic1076, "Port connector", "Add a port link between blocks of the currently opened AVATAR Block Diagram", 0); + actions[ABD_BLOCK] = new TAction("abd-block", "Add a block", IconManager.imgic5000, IconManager.imgic5000, "Block", "Add a SysML Block to the currently opened AVATAR Block Diagram", 0); + actions[ABD_COMPOSITION_CONNECTOR] = new TAction("abd-composition-connector", "Add a composition connector between blocks", IconManager.imgic5002, IconManager.imgic5002, "Composition connector", "Add a composition between blocks of the currently opened AVATAR Block Diagram", 0); + actions[ABD_PORT_CONNECTOR] = new TAction("abd-port-connector", "Add a composition connector between blocks", IconManager.imgic5004, IconManager.imgic5004, "Port connector", "Add a port link between blocks of the currently opened AVATAR Block Diagram", 0); // AVATAR State Machine diagrams actions[ASMD_EDIT] = new TAction("edit-asmd-diagram", "Edit AVATAR state machine diagram", IconManager.imgic100, IconManager.imgic101, "Edit AVATAR state machine diagram", "Make it possible to edit the currently opened AVATAR state machine diagram", 0); actions[ASMD_CONNECTOR] = new TAction("add-asmd-connector", "Connect two operators together", IconManager.imgic202, IconManager.imgic202, "Connect two operators together", "Connect two operators of the currently opened AVATAR state machine diagram", 0); actions[ASMD_START] = new TAction("add-asmd-start", "Add Start state", IconManager.imgic222, IconManager.imgic222, "Start", "Add a start state to the currently opened AVATAR state machine diagram", 0); actions[ASMD_STOP] = new TAction("add-asmd-stop", "Add Stop", IconManager.imgic210, IconManager.imgic210, "Stop", "Add a termination state to the currently opened AVATAR state machine diagram", 0); + actions[ASMD_SEND_SIGNAL] = new TAction("add-asmd-sendsignal", "Send signal", IconManager.imgic904, IconManager.imgic904, "Send signal", "Add a send signal operator to the currently opened AVATAR state machine diagram", 0); + actions[ASMD_RECEIVE_SIGNAL] = new TAction("add-asmd-receivesignal", "Receive signal", IconManager.imgic908, IconManager.imgic908, "Receive signal", "Add a receive signal operator to the currently opened AVATAR state machine diagram", 0); } diff --git a/src/ui/avatarbd/AvatarBDBlock.java b/src/ui/avatarbd/AvatarBDBlock.java index 874ea291806935ee7cea9be8edda2e6d55200f44..41bbb8c0594cfb849a8048d02a4e15168e49c6df 100644 --- a/src/ui/avatarbd/AvatarBDBlock.java +++ b/src/ui/avatarbd/AvatarBDBlock.java @@ -36,13 +36,13 @@ The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms. /** - * Class AvatarBDBlock - * Node. To be used in AVATAR Block Diagrams - * Creation: 06/04/2010 - * @version 1.1 06/04/2010 - * @author Ludovic APVRILLE - * @see - */ +* Class AvatarBDBlock +* Node. To be used in AVATAR Block Diagrams +* Creation: 06/04/2010 +* @version 1.1 06/04/2010 +* @author Ludovic APVRILLE +* @see +*/ package ui.avatarbd; @@ -65,7 +65,19 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S private int minFontSize = 4; private int currentFontSize = -1; private boolean displayText = true; - private int textX = 1; + private int textX = 7; + + private int limitName = -1; + private int limitAttr = -1; + private int limitMethod = -1; + + // Icon + private int iconSize = 15; + private boolean iconIsDrawn = false; + + + // TAttribute, AvatarMethod, AvatarSignal + protected Vector myAttributes, myMethods, mySignals; public String oldValue; @@ -104,6 +116,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S moveable = true; editable = true; + multieditable = true; removable = true; userResizable = true; @@ -116,6 +129,10 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S myImageIcon = IconManager.imgic700; + myAttributes = new Vector(); + myMethods = new Vector(); + mySignals = new Vector(); + actionOnAdd(); } @@ -177,13 +194,14 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S // Strings int w; + int h = 0; if (displayText) { f = f.deriveFont((float)currentFontSize); Font f0 = g.getFont(); g.setFont(f.deriveFont(Font.BOLD)); w = g.getFontMetrics().stringWidth(ster); - int h = currentFontSize + (int)(textY1 * tdp.getZoom()); + h = currentFontSize + (int)(textY1 * tdp.getZoom()); if ((w < (2*textX + width)) && (h < height)) { g.drawString(ster, x + (width - w)/2, y +h); } @@ -193,9 +211,168 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S if ((w < (2*textX + width)) && (h < height)) { g.drawString(value, x + (width - w)/2, y + h); } + limitName = y + h; + } else { + limitName = -1; + } + + g.setFont(fold); + + h = h +2; + if (h < height) { + g.drawLine(x, y+h, x+width, y+h); + } + + // Icon + if ((width>30) && (height > (iconSize + 2*textX))) { + iconIsDrawn = true; + g.drawImage(IconManager.imgic1200.getImage(), x + width - iconSize - textX, y + textX, null); + } else { + iconIsDrawn = false; + } + + int cpt = h; + // Attributes + if (((AvatarBDPanel)tdp).areAttributesVisible()) { + limitAttr = -1; + int index = 0; + String attr; + + TAttribute a; + + int si = Math.min(12, (int)((float)currentFontSize - 2)); + + f = g.getFont(); + f = f.deriveFont((float)si); + g.setFont(f); + int step = si + 2; + + while(index < myAttributes.size()) { + cpt += step ; + if (cpt >= (height - textX)) { + break; + } + a = (TAttribute)(myAttributes.get(index)); + attr = a.toString(); + w = g.getFontMetrics().stringWidth(attr); + if ((w + (2 * textX) + 1) < width) { + g.drawString(attr, x + textX, y + cpt); + limitAttr = y + cpt; + } else { + attr = "..."; + w = g.getFontMetrics().stringWidth(attr); + if ((w + textX + 2) < width) { + g.drawString(attr, x + textX + 1, y + cpt); + limitAttr = y + cpt; + } else { + // skip attribute + cpt -= step; + } + } + index ++; + } + } else { + limitAttr = -1; + } + + // Methods + if (((AvatarBDPanel)tdp).areAttributesVisible()) { + limitMethod = -1; + if (myMethods.size() > 0) { + if (cpt < height) { + cpt += textY1; + g.drawLine(x, y+cpt, x+width, y+cpt); + cpt += textY1; + } + } + + int index = 0; + String method; + AvatarMethod am; + + int si = Math.min(12, (int)((float)currentFontSize - 2)); + + f = g.getFont(); + f = f.deriveFont((float)si); + g.setFont(f); + int step = si + 2; + + while(index < myMethods.size()) { + cpt += step ; + if (cpt >= (height - textX)) { + break; + } + am = (AvatarMethod)(myMethods.get(index)); + method = "- " + am.toString(); + w = g.getFontMetrics().stringWidth(method); + if ((w + (2 * textX) + 1) < width) { + g.drawString(method, x + textX, y + cpt); + limitMethod = y + cpt; + } else { + method = "..."; + w = g.getFontMetrics().stringWidth(method); + if ((w + textX + 2) < width) { + g.drawString(method, x + textX + 1, y + cpt); + limitMethod = y + cpt; + } else { + // skip attribute + cpt -= step; + } + } + index ++; + } + } else { + limitMethod = -1; + } + + // Signals + if (((AvatarBDPanel)tdp).areAttributesVisible()) { + + if (mySignals.size() > 0) { + if (cpt < height) { + cpt += textY1; + g.drawLine(x, y+cpt, x+width, y+cpt); + cpt += textY1; + } + } + + int index = 0; + String signal; + AvatarSignal as; + + int si = Math.min(12, (int)((float)currentFontSize - 2)); + + f = g.getFont(); + f = f.deriveFont((float)si); + g.setFont(f); + int step = si + 2; + + while(index < mySignals.size()) { + cpt += step ; + if (cpt >= (height - textX)) { + break; + } + as = (AvatarSignal)(mySignals.get(index)); + signal = as.toString(); + w = g.getFontMetrics().stringWidth(signal); + if ((w + (2 * textX) + 1) < width) { + g.drawString(signal, x + textX, y + cpt); + } else { + signal = "..."; + w = g.getFontMetrics().stringWidth(signal); + if ((w + textX + 2) < width) { + g.drawString(signal, x + textX + 1, y + cpt); + } else { + // skip attribute + cpt -= step; + } + } + index ++; + } } g.setFont(fold); + /*int w = g.getFontMetrics().stringWidth(ster); Font f = g.getFont(); g.setFont(f.deriveFont(Font.BOLD)); @@ -208,6 +385,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S //g.drawImage(IconManager.imgic1100.getImage(), x + 4, y + 4, null); //g.drawImage(IconManager.img9, x + width - 20, y + 4, null); } + public TGComponent isOnOnlyMe(int x1, int y1) { @@ -226,49 +404,103 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S return name; } - public boolean editOndoubleClick(JFrame frame) { - oldValue = value; - - //String text = getName() + ": "; - String s = (String)JOptionPane.showInputDialog(frame, "Block name", - "setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, - null, - getValue()); - - if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { - //boolean b; - if (!TAttribute.isAValidId(s, false, false)) { - JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: the new name is not a valid name", - "Error", - JOptionPane.INFORMATION_MESSAGE); - return false; - } - - if (!tdp.isBlockNameUnique(s)) { - JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: the new name is already in use", - "Error", - JOptionPane.INFORMATION_MESSAGE); - return false; - } - - setValue(s); - recalculateSize(); - - - - if (tdp.actionOnDoubleClick(this)) { - return true; - } else { - JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: this name is already in use", - "Error", - JOptionPane.INFORMATION_MESSAGE); - setValue(oldValue); - } - } - return false; + public boolean editOndoubleClick(JFrame frame, int _x, int _y) { + if (iconIsDrawn) { + if (GraphicLib.isInRectangle(_x, _y, x + width - iconSize - textX, y + textX, iconSize, iconSize)) { + tdp.selectTab(getValue()); + return true; + } + } + // On the name ? + if ((((limitName == -1) && (displayText) && (_y <= (y + 2*currentFontSize)))) || ((displayText) && (_y < limitName))) { + oldValue = value; + + //String text = getName() + ": "; + String s = (String)JOptionPane.showInputDialog(frame, "Block name", + "setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, + null, + getValue()); + + if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { + //boolean b; + if (!TAttribute.isAValidId(s, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Block: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + if (!tdp.isBlockNameUnique(s)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Block: the new name is already in use", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + setValue(s); + recalculateSize(); + + if (tdp.actionOnDoubleClick(this)) { + return true; + } else { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Block: this name is already in use", + "Error", + JOptionPane.INFORMATION_MESSAGE); + setValue(oldValue); + } + } + return false; + } + + // And so -> attributes! + int tab = 0; + if (limitAttr != -1) { + if (_y > limitAttr) { + if (limitMethod == -1) { + tab = 2; + } else { + tab = 1; + } + } + } + if (limitMethod != -1) { + if (_y > limitMethod) { + tab = 2; + } + } + + if ((limitMethod == -1) && (limitAttr == -1)) { + if (mySignals.size() > 1) { + tab = 2; + } + } + + JDialogAvatarBlock jdab = new JDialogAvatarBlock(myAttributes, myMethods, mySignals, null, frame, "Setting attributes of " + value, "Attribute", tab); + setJDialogOptions(jdab); + jdab.setSize(650, 375); + GraphicLib.centerOnParent(jdab); + jdab.setVisible(true); // blocked until dialog has been closed + //makeValue(); + //if (oldValue.equals(value)) { + //return false; + //} + ((AvatarBDPanel)tdp).updateAllSignalsOnConnectors(); + rescaled = true; + return true; + } + + protected void setJDialogOptions(JDialogAvatarBlock _jdab) { + //jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC)); + _jdab.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE)); + _jdab.addType(TAttribute.getStringType(TAttribute.NATURAL), true); + _jdab.addType(TAttribute.getStringType(TAttribute.BOOLEAN), true); + _jdab.addType(TAttribute.getStringType(TAttribute.INTEGER), true); + _jdab.enableInitialValue(true); + _jdab.enableRTLOTOSKeyword(false); + _jdab.enableJavaKeyword(false); } @@ -317,14 +549,177 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } public void removeSwallowedTGComponent(TGComponent tgc) { - removeInternalComponent(tgc); + removeMyInternalComponent(tgc, false); + } + + public boolean removeMyInternalComponent(TGComponent tgc, boolean actionOnRemove) { + //TGComponent tgc; + for(int i=0; i<nbInternalTGComponent; i++) { + if (tgcomponent[i] == tgc) { + nbInternalTGComponent = nbInternalTGComponent - 1; + if (nbInternalTGComponent == 0) { + tgcomponent = null; + } else { + TGComponent [] tgcomponentbis = new TGComponent[nbInternalTGComponent]; + for(int j=0; j<nbInternalTGComponent; j++) { + if (j<i) { + tgcomponentbis[j] = tgcomponent[j]; + } + if (j>=i) { + tgcomponentbis[j] = tgcomponent[j+1]; + } + } + tgcomponent = tgcomponentbis; + } + if (actionOnRemove) { + tgc.actionOnRemove(); + tdp.actionOnRemove(tgc); + } + return true; + } else { + if (((AvatarBDBlock)tgcomponent[i]).removeMyInternalComponent(tgc, false)) { + return true; + } + } + } + return false; + } + + protected String translateExtraParam() { + TAttribute a; + AvatarMethod am; + AvatarSignal as; + + //System.out.println("Loading extra params of " + value); + //value = ""; + StringBuffer sb = new StringBuffer("<extraparam>\n"); + for(int i=0; i<myAttributes.size(); i++) { + //System.out.println("Attribute:" + i); + a = (TAttribute)(myAttributes.elementAt(i)); + //System.out.println("Attribute:" + i + " = " + a.getId()); + //value = value + a + "\n"; + sb.append("<Attribute access=\""); + sb.append(a.getAccess()); + sb.append("\" id=\""); + sb.append(a.getId()); + sb.append("\" value=\""); + sb.append(a.getInitialValue()); + sb.append("\" type=\""); + sb.append(a.getType()); + sb.append("\" typeOther=\""); + sb.append(a.getTypeOther()); + sb.append("\" />\n"); + } + for(int i=0; i<myMethods.size(); i++) { + //System.out.println("Attribute:" + i); + am = (AvatarMethod)(myMethods.elementAt(i)); + //System.out.println("Attribute:" + i + " = " + a.getId()); + //value = value + a + "\n"; + sb.append("<Method value=\""); + sb.append(am.toString()); + sb.append("\" />\n"); + } + for(int i=0; i<mySignals.size(); i++) { + //System.out.println("Attribute:" + i); + as = (AvatarSignal)(mySignals.elementAt(i)); + //System.out.println("Attribute:" + i + " = " + a.getId()); + //value = value + a + "\n"; + sb.append("<Signal value=\""); + sb.append(as.toString()); + sb.append("\" />\n"); + } + sb.append("</extraparam>\n"); + return new String(sb); } - public String getBlockName() { - return value; + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + try { + NodeList nli; + Node n1, n2; + Element elt; + int access, type; + String typeOther; + String id, valueAtt; + String method; + String signal; + AvatarMethod am; + AvatarSignal as; + + //System.out.println("Loading attributes"); + //System.out.println(nl.toString()); + + for(int i=0; i<nl.getLength(); i++) { + n1 = nl.item(i); + //System.out.println(n1); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for(int j=0; j<nli.getLength(); j++) { + n2 = nli.item(j); + //System.out.println(n2); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("Attribute")) { + //System.out.println("Analyzing attribute"); + access = Integer.decode(elt.getAttribute("access")).intValue(); + type = Integer.decode(elt.getAttribute("type")).intValue(); + try { + typeOther = elt.getAttribute("typeOther"); + } catch (Exception e) { + typeOther = ""; + } + id = elt.getAttribute("id"); + valueAtt = elt.getAttribute("value"); + + if (valueAtt.equals("null")) { + valueAtt = ""; + } + if ((TAttribute.isAValidId(id, false, false)) && (TAttribute.isAValidInitialValue(type, valueAtt))) { + //System.out.println("Adding attribute " + id + " typeOther=" + typeOther); + TAttribute ta = new TAttribute(access, id, valueAtt, type, typeOther); + myAttributes.addElement(ta); + } + } + if (elt.getTagName().equals("Method")) { + //System.out.println("Analyzing attribute"); + method = elt.getAttribute("value"); + + if (method.equals("null")) { + method = ""; + } + am = AvatarMethod.isAValidMethod(method); + if (am != null) { + myMethods.add(am); + } + } + if (elt.getTagName().equals("Signal")) { + //System.out.println("Analyzing attribute"); + signal = elt.getAttribute("value"); + + if (signal.equals("null")) { + signal = ""; + } + as = AvatarSignal.isAValidSignal(signal); + if (as != null) { + mySignals.add(as); + } else { + TraceManager.addDev("Invalid signal:" + signal); + } + } + } + } + } + } + + } catch (Exception e) { + throw new MalformedModelingException(); + } } - + public String getBlockName() { + return value; + } + + public void hasBeenResized() { for(int i=0; i<nbInternalTGComponent; i++) { @@ -383,7 +778,59 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S public int getDefaultConnector() { - return TGComponentManager.AVATARBD_COMPOSITION_CONNECTOR; - } + return TGComponentManager.AVATARBD_PORT_CONNECTOR; + } + + public Vector getSignalList() { + return mySignals; + } + + public AvatarSignal getAvatarSignalFromName(String _name) { + AvatarSignal as; + for(int i=0; i<mySignals.size(); i++) { + as = (AvatarSignal)(mySignals.get(i)); + if (as.getId().compareTo(_name) == 0) { + return as; + } + } + return null; + } + + public Vector getListOfAvailableSignals() { + return ((AvatarBDPanel)(tdp)).getListOfAvailableSignals(this); + } + + // _id may contain the full signal + public AvatarSignal getSignalNameBySignalDef(String _id) { + int index0 = _id.indexOf('('); + if (index0 > -1) { + _id = _id.substring(0, index0); + } + _id = _id.trim(); + TraceManager.addDev("Searching for signal with id=" + _id); + AvatarSignal as; + for(int i=0; i<mySignals.size(); i++) { + as = (AvatarSignal)(mySignals.get(i)); + if (as.getId().compareTo(_id) == 0) { + TraceManager.addDev("found"); + return as; + } + } + TraceManager.addDev("Not found"); + return null; + } + + public AvatarSignal getAvatarSignalFromFullName(String _id) { + if(_id.startsWith("in ")) { + return getSignalNameBySignalDef(_id.substring(3, _id.length()).trim()); + } + + if(_id.startsWith("out ")) { + return getSignalNameBySignalDef(_id.substring(4, _id.length()).trim()); + } + return null; + } + + } diff --git a/src/ui/avatarbd/AvatarBDCompositionConnector.java b/src/ui/avatarbd/AvatarBDCompositionConnector.java index d0eda8c213f78d95006237bc3e0102f6ee2b1e0a..7f19c6a44baf9e0e443f20c72ed47d8d12b4362f 100644 --- a/src/ui/avatarbd/AvatarBDCompositionConnector.java +++ b/src/ui/avatarbd/AvatarBDCompositionConnector.java @@ -73,18 +73,15 @@ public class AvatarBDCompositionConnector extends TGConnector implements Scalab public AvatarBDCompositionConnector(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector _listPoint) { super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint); myImageIcon = IconManager.imgic202; + + value = "{info}"; editable = true; oldScaleFactor = tdp.getZoom(); rescaled = true; } - protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2){ - /*if (Point2D.distance(x1, y1, x2, y2) < GraphicLib.longueur * 1.5) { - g.drawLine(x1, y1, x2, y2); - } else { - GraphicLib.arrowWithLine(g, 1, 0, 10, x1, y1, x2, y2, true); - }*/ + protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2) { if ((p == null) || (rescaled) || (xp1 != x1) || (xp2 != x2) || (yp1 != y1) || (yp2 != y2)){ p = new Polygon(); xp1 = x1; diff --git a/src/ui/avatarbd/AvatarBDPanel.java b/src/ui/avatarbd/AvatarBDPanel.java index 5541a730b58749a9baf517e473f68057900f2158..35025b1712e494da7bf7154f02049cd1dffab838 100644 --- a/src/ui/avatarbd/AvatarBDPanel.java +++ b/src/ui/avatarbd/AvatarBDPanel.java @@ -99,16 +99,21 @@ public class AvatarBDPanel extends TDiagramPanel { mgui.removeAvatarBlock(tp, b.getBlockName()); } return true; - } + } return false; } public boolean actionOnValueChanged(TGComponent tgc) { if (tgc instanceof AvatarBDBlock) { + //updateAllSignalsOnConnectors(); return actionOnDoubleClick(tgc); } return false; } + + public boolean areAttributesVisible() { + return attributesVisible; + } public String getXMLHead() { return "<AVATARBlockDiagramPanel name=\"" + name + "\"" + sizeParam() + displayParam() +" >"; @@ -133,6 +138,30 @@ public class AvatarBDPanel extends TDiagramPanel { public String getXMLCloneTail() { return "</AVATARBlockDiagramPanelCopy>"; } + + public void setConnectorsToFront() { + TGComponent tgc; + + //System.out.println("list size=" + componentList.size()); + + Iterator iterator = componentList.listIterator(); + + ArrayList<TGComponent> list = new ArrayList<TGComponent>(); + + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + if (!(tgc instanceof TGConnector)) { + list.add(tgc); + } + } + + //System.out.println("Putting to back ..."); + for(TGComponent tgc1: list) { + //System.out.println("Putting to back: " + tgc1); + componentList.remove(tgc1); + componentList.add(tgc1); + } + } @@ -450,5 +479,94 @@ public class AvatarBDPanel extends TDiagramPanel { return null; }*/ + + public void updateAllSignalsOnConnectors() { + TGComponent tgc; + AvatarBDPortConnector port; + Iterator iterator = componentList.listIterator(); + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + if (tgc instanceof AvatarBDPortConnector) { + port = (AvatarBDPortConnector)tgc; + port.updateAllSignals(); + } + } + } + + public Vector getListOfAvailableSignals(AvatarBDBlock _block) { + int i; + TGComponent tgc; + LinkedList<String> ll; + AvatarBDPortConnector port; + Iterator iterator = componentList.listIterator(); + ArrayList<String> list = new ArrayList<String>(); + Vector v = new Vector(); + Vector listOfBlock = _block.getSignalList(); + + if (listOfBlock.size() == 0) { + return v; + } + + v.addAll(listOfBlock); + + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + if (tgc instanceof AvatarBDPortConnector) { + port = (AvatarBDPortConnector)tgc; + if (port.getAvatarBDBlock1() == _block) { + ll = port.getListOfSignalsOrigin(); + removeSignals(v, ll); + } + if (port.getAvatarBDBlock2() == _block) { + ll = port.getListOfSignalsDestination(); + removeSignals(v, ll); + } + } + } + + return v; + } + + // Remove AvatarSignals of v which name is provided in list + private void removeSignals(Vector v, LinkedList<String> list) { + int i; + AvatarSignal as; + for(String s: list) { + for(i=0; i<v.size(); i++) { + as = (AvatarSignal)(v.get(i)); + if (as.toString().compareTo(s) == 0) { + v.removeElementAt(i); + break; + } + } + } + } + + public LinkedList<AvatarBDBlock> getFullBlockList() { + TGComponent tgc; + AvatarBDBlock block; + LinkedList<AvatarBDBlock> list = new LinkedList<AvatarBDBlock>(); + Iterator iterator = componentList.listIterator(); + + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + if (tgc instanceof AvatarBDBlock) { + block = (AvatarBDBlock)tgc; + list.add(block); + list.addAll(block.getFullBlockList()); + } + } + return list; + } + + public Vector getAllSignalsOfBlock(String _name) { + LinkedList<AvatarBDBlock> list = getFullBlockList(); + for(AvatarBDBlock block: list) { + if (block.getBlockName().compareTo(_name) ==0) { + return block.getSignalList(); + } + } + return null; + } } diff --git a/src/ui/avatarbd/AvatarBDPortConnector.java b/src/ui/avatarbd/AvatarBDPortConnector.java index 7fe743dda982433d756ff31ecf66e23839509e13..d21f6a566f63043c45018b4d675c953da5a7c353 100644 --- a/src/ui/avatarbd/AvatarBDPortConnector.java +++ b/src/ui/avatarbd/AvatarBDPortConnector.java @@ -63,7 +63,16 @@ public class AvatarBDPortConnector extends TGConnector implements ScalableTGCom //protected int widthValue, heightValue, maxWidthValue, h; protected int c = 10; //square length protected double oldScaleFactor; - protected int fontSize = 12; + protected int fontSize = 10; + protected int decY = 20; + protected int decX = 6; + + protected LinkedList<String> inSignalsAtOrigin; + protected LinkedList<String> outSignalsAtDestination; + + protected LinkedList<String> inSignalsAtDestination; + protected LinkedList<String> outSignalsAtOrigin; + public AvatarBDPortConnector(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector _listPoint) { @@ -72,6 +81,10 @@ public class AvatarBDPortConnector extends TGConnector implements ScalableTGCom value = ""; editable = true; oldScaleFactor = tdp.getZoom(); + inSignalsAtOrigin = new LinkedList<String>(); + inSignalsAtDestination = new LinkedList<String>(); + outSignalsAtOrigin = new LinkedList<String>(); + outSignalsAtDestination = new LinkedList<String>(); } protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2){ @@ -90,18 +103,78 @@ public class AvatarBDPortConnector extends TGConnector implements ScalableTGCom if (p == null) { //System.out.println("null point"); } else { - if (Point2D.distance(x1, y1, p.x, p.y) < GraphicLib.longueur * 1.5) { - //System.out.println("p.x=" + p.x + " x1=" + x1 + "p.y=" + p.y + " y1=" + y1); - if ((p.x != x1) || (p.y != y1)) { - g.drawLine(x1, y1, p.x, p.y); - //System.out.println("drawn"); + g.drawLine(x1, y1, p.x, p.y); + } + + Font f = g.getFont(); + Font fold = f; + f = f.deriveFont((float)fontSize); + g.setFont(f); + int h = - decY; + int step = fontSize + 1; + int w; + String s; + + // Signals at origin + if (inSignalsAtOrigin.size() > 0) { + //g.drawString("in:", p1.getX() + decX, p1.getY() + h); + for(String iso: inSignalsAtOrigin) { + h += step; + s = getShortName(iso); + if (p1.getX() <= p2.getX()) { + g.drawString(s, p1.getX() + decX, p1.getY() + h); + } else { + w = g.getFontMetrics().stringWidth(s); + g.drawString(s, p1.getX() - decX - w, p1.getY() + h); + } + } + } + if (outSignalsAtOrigin.size() > 0) { + //h += step; + //g.drawString("out:", p1.getX() + decX, p1.getY() + h); + for(String oso: outSignalsAtOrigin) { + h += step; + s = getShortName(oso); + if (p1.getX() <= p2.getX()) { + g.drawString(s, p1.getX() + decX, p1.getY() + h); + } else { + w = g.getFontMetrics().stringWidth(s); + g.drawString(s, p1.getX() - decX - w, p1.getY() + h); + } + } + } + // Signals at destination + h = - decY; + if (inSignalsAtDestination.size() > 0) { + //g.drawString("in:", p2.getX() + decX, p2.getY() + h); + for(String isd: inSignalsAtDestination) { + h += step; + s = getShortName(isd); + if (p1.getX() > p2.getX()) { + g.drawString(s, p2.getX() + decX, p2.getY() + h); + } else { + w = g.getFontMetrics().stringWidth(s); + g.drawString(s, p2.getX() - decX - w, p2.getY() + h); + } + } + } + if (outSignalsAtDestination.size() > 0) { + //h += step; + //g.drawString("out:", p2.getX() + decX, p2.getY() + h); + for(String osd: outSignalsAtDestination) { + h += step; + s = getShortName(osd); + if (p1.getX() > p2.getX()) { + g.drawString(s, p2.getX() + decX, p2.getY() + h); + } else { + w = g.getFontMetrics().stringWidth(s); + g.drawString(s, p2.getX() - decX - w, p2.getY() + h); + } } - } else { - GraphicLib.arrowWithLine(g, 1, 0, 10, x1, y1, p.x, p.y, true); - } } + g.setFont(fold); - if (value.length() > 0) { + /*if (value.length() > 0) { Font f = g.getFont(); if (tdp.getZoom() < 1) { Font f0 = f.deriveFont((float)(fontSize*tdp.getZoom())); @@ -109,30 +182,146 @@ public class AvatarBDPortConnector extends TGConnector implements ScalableTGCom } g.drawString(value, x2-(cz/2), y2-(cz/2)-1); g.setFont(f); - } + }*/ + + } + public AvatarBDBlock getAvatarBDBlock1() { + return (AvatarBDBlock)(tdp.getComponentToWhichBelongs(p1)); + } + + public AvatarBDBlock getAvatarBDBlock2() { + return (AvatarBDBlock)(tdp.getComponentToWhichBelongs(p2)); + } + public boolean editOndoubleClick(JFrame frame) { - String oldValue = value; - String text = getName() + "Connector"; - String s = (String)JOptionPane.showInputDialog(frame, text, - "Setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, - null, - getValue()); - - if (s != null) { - s = Conversion.removeFirstSpaces(s); - } + // Gets the two concerned blocks + + AvatarBDBlock block1 = getAvatarBDBlock1(); + AvatarBDBlock block2 = getAvatarBDBlock2(); + Vector v = getAssociationSignals(); + + JDialogSignalAssociation jdas = new JDialogSignalAssociation(frame, block1, block2, v, this, "Setting signal association"); + jdas.setSize(750, 400); + GraphicLib.centerOnParent(jdas); + jdas.show(); // blocked until dialog has been closed + + if (jdas.hasBeenCancelled()) { + return false; + } + + inSignalsAtOrigin.clear(); + inSignalsAtDestination.clear(); + outSignalsAtOrigin.clear(); + outSignalsAtDestination.clear(); + + String assoc; + AvatarSignal as1, as2; + int index; + for(int i=0; i<v.size(); i++) { + assoc = (String)(v.get(i)); + as1 = block1.getSignalNameBySignalDef(getFirstSignalOfSignalAssociation(assoc)); + as2 = block2.getSignalNameBySignalDef(getSecondSignalOfSignalAssociation(assoc)); + + if ((as1 != null) && (as2 != null)) { + index = assoc.indexOf("->"); + if (index > -1) { + outSignalsAtOrigin.add(as1.toString()); + inSignalsAtDestination.add(as2.toString()); + } else { + inSignalsAtOrigin.add(as1.toString()); + outSignalsAtDestination.add(as2.toString()); + } + } + } + return true; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + for(String iso: inSignalsAtOrigin) { + sb.append("<iso value=\""); + sb.append(iso); + sb.append("\" />\n"); + } + for(String osd: outSignalsAtDestination) { + sb.append("<osd value=\""); + sb.append(osd); + sb.append("\" />\n"); + } + for(String isd: inSignalsAtDestination) { + sb.append("<isd value=\""); + sb.append(isd); + sb.append("\" />\n"); + } + for(String oso: outSignalsAtOrigin) { + sb.append("<oso value=\""); + sb.append(oso); + sb.append("\" />\n"); + } - //System.out.println("emptytext=" + emptyText); - - if ((s != null) && (!s.equals(oldValue))) { - setValue(s); - return true; + sb.append("</extraparam>\n"); + return new String(sb); + } + + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + try { + NodeList nli; + Node n1, n2; + Element elt; + String val; + + //System.out.println("Loading attributes"); + //System.out.println(nl.toString()); + + for(int i=0; i<nl.getLength(); i++) { + n1 = nl.item(i); + //System.out.println(n1); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for(int j=0; j<nli.getLength(); j++) { + n2 = nli.item(j); + //System.out.println(n2); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("iso")) { + val = elt.getAttribute("value"); + + if ((val != null) && (!(val.equals("null")))) { + inSignalsAtOrigin.add(val); + } + } + if (elt.getTagName().equals("osd")) { + val = elt.getAttribute("value"); + + if ((val != null) && (!(val.equals("null")))) { + outSignalsAtDestination.add(val); + } + } + if (elt.getTagName().equals("isd")) { + val = elt.getAttribute("value"); + + if ((val != null) && (!(val.equals("null")))) { + inSignalsAtDestination.add(val); + } + } + if (elt.getTagName().equals("oso")) { + val = elt.getAttribute("value"); + + if ((val != null) && (!(val.equals("null")))) { + outSignalsAtOrigin.add(val); + } + } + } + } + } + } + + } catch (Exception e) { + throw new MalformedModelingException(); } - - return false; } @@ -163,6 +352,151 @@ public class AvatarBDPortConnector extends TGConnector implements ScalableTGCom oldScaleFactor = scaleFactor; } - + public LinkedList getListOfSignalsOrigin() { + LinkedList<String> list = new LinkedList<String>(); + list.addAll(inSignalsAtOrigin); + list.addAll(outSignalsAtOrigin); + return list; + } + + public LinkedList getListOfSignalsDestination() { + LinkedList<String> list = new LinkedList<String>(); + list.addAll(inSignalsAtDestination); + list.addAll(outSignalsAtDestination); + return list; + } + + public Vector getAssociationSignals() { + AvatarBDBlock block1 = getAvatarBDBlock1(); + AvatarBDBlock block2 = getAvatarBDBlock2(); + + int i; + Vector v = new Vector(); + String s; + + for(i=0; i<outSignalsAtOrigin.size(); i++) { + try { + s = makeSignalAssociation(block1, block1.getAvatarSignalFromFullName(outSignalsAtOrigin.get(i)), block2, block2.getAvatarSignalFromFullName(inSignalsAtDestination.get(i))); + v.add(s); + } catch (Exception e) { + // Probably a signal has been removed + } + } + + for(i=0; i<inSignalsAtOrigin.size(); i++) { + try { + s = makeSignalAssociation(block1, block1.getAvatarSignalFromFullName(inSignalsAtOrigin.get(i)), block2, block2.getAvatarSignalFromFullName(outSignalsAtDestination.get(i))); + v.add(s); + } catch (Exception e) { + // Probably a signal has been removed + } + } + + return v; + } + + public static String makeSignalAssociation(AvatarBDBlock _block1, AvatarSignal _as1, AvatarBDBlock _block2, AvatarSignal _as2) { + String s = _block1.getBlockName() + "." + _as1.toBasicString(); + if (_as1.getInOut() == AvatarSignal.OUT) { + s += " -> "; + } else { + s += " <- "; + } + s += _block2.getBlockName() + "." + _as2.toBasicString(); + return s; + } + + public String getFirstSignalOfSignalAssociation(String _assoc) { + int index0 = _assoc.indexOf("."); + + + if (index0 == -1) { + return null; + } + + int index1 = _assoc.indexOf("->"); + int index2 = _assoc.indexOf("<-"); + + index1 = Math.max(index1, index2); + if (index1 == -1) { + return null; + } + + return _assoc.substring(index0+1, index1).trim(); + } + + public String getSecondSignalOfSignalAssociation(String _assoc) { + int index0 = _assoc.indexOf("->"); + int index1 = _assoc.indexOf("<-"); + + if ((index0 == -1) && (index1 == -1)) { + return null; + } + + index0 = Math.max(index0, index1); + _assoc = _assoc.substring(index0+2, _assoc.length()); + + index0 = _assoc.indexOf("."); + + if (index0 == -1) { + return null; + } + + return _assoc.substring(index0+1, _assoc.length()).trim(); + } + + public void updateAllSignals() { + try { + Vector v = getAssociationSignals(); + inSignalsAtOrigin.clear(); + inSignalsAtDestination.clear(); + outSignalsAtOrigin.clear(); + outSignalsAtDestination.clear(); + if (v.size() == 0) { + return; + } + + AvatarBDBlock block1 = getAvatarBDBlock1(); + AvatarBDBlock block2 = getAvatarBDBlock2(); + + String assoc; + AvatarSignal as1, as2; + int index; + for(int i=0; i<v.size(); i++) { + assoc = (String)(v.get(i)); + TraceManager.addDev("assoc=" + assoc); + as1 = block1.getSignalNameBySignalDef(getFirstSignalOfSignalAssociation(assoc)); + as2 = block2.getSignalNameBySignalDef(getSecondSignalOfSignalAssociation(assoc)); + + if ((as1 != null) && (as2 != null)) { + index = assoc.indexOf("->"); + if (index > -1) { + outSignalsAtOrigin.add(as1.toString()); + inSignalsAtDestination.add(as2.toString()); + } else { + inSignalsAtOrigin.add(as1.toString()); + outSignalsAtDestination.add(as2.toString()); + } + } else { + TraceManager.addDev("null signals: removing assoc"); + } + } + } catch (Exception e) { + TraceManager.addDev("Exception on connector"); + // Probably the model is not yet fully loaded... + } + } + + // remove the parameters in the name of a signal + public String getShortName(String _s) { + int index = _s.indexOf('('); + if (index == -1) { + return _s; + } + + return _s.substring(0, index).trim(); + } + + } diff --git a/src/ui/avatarsmd/AvatarSMDConnector.java b/src/ui/avatarsmd/AvatarSMDConnector.java index d547b398496538c8e69f396893fab07cffa56186..52642ea13af98b9b688a3f0fe156e4c518935e28 100644 --- a/src/ui/avatarsmd/AvatarSMDConnector.java +++ b/src/ui/avatarsmd/AvatarSMDConnector.java @@ -49,6 +49,7 @@ package ui.avatarsmd; import java.awt.*; import java.awt.geom.*; import java.util.*; +import javax.swing.*; import myutil.*; import ui.*; @@ -58,8 +59,51 @@ public class AvatarSMDConnector extends TGConnector { public AvatarSMDConnector(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector _listPoint) { super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint); + + nbInternalTGComponent = 1; + tgcomponent = new TGComponent[nbInternalTGComponent]; + AvatarSMDTransitionInfo tgc = new AvatarSMDTransitionInfo(x, y+40, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, this, _tdp); + tgc.setValue(""); + tgc.setName("List of all parameters of an Avatar SMD transition"); + tgc.setMoveWithFather(false); + tgcomponent[0] = tgc; + + editable = true; + myImageIcon = IconManager.imgic202; } + + public void internalDrawing(Graphics g) { + + TGComponent p3, p4; + int previousx = 0, previousy = 0; + + if (nbInternalTGComponent>0) { + p3 = tgcomponent[0]; + p4 = tgcomponent[0]; + //System.out.println("p3.x " + p3.getX() + " p3.y " + p3.getY()); + if (!(tgcomponent[0] instanceof AvatarSMDTransitionInfo)) { + drawMiddleSegment(g, p1.getX(), p1.getY(), p3.getX(), p3.getY()); + } else { + previousx = p1.getX(); + previousy = p1.getY(); + } + + for(int i=0; i<nbInternalTGComponent-1; i++) { + + if (p4 instanceof AvatarSMDTransitionInfo) { + } else { + p4 = tgcomponent[i+1]; + drawMiddleSegment(g, previousx, previousy, p4.getX(), p4.getY()); + previousx = p4.getX(); + previousy = p4.getY(); + } + } + drawLastSegment(g, p4.getX(), p4.getY(), p2.getX(), p2.getY()); + } else { + drawLastSegment(g, p1.getX(), p1.getY(), p2.getX(), p2.getY()); + } + } protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2){ if (Point2D.distance(x1, y1, x2, y2) < GraphicLib.longueur * 1.5) { @@ -68,6 +112,10 @@ public class AvatarSMDConnector extends TGConnector { GraphicLib.arrowWithLine(g, 1, 0, 10, x1, y1, x2, y2, true); } } + + public boolean editOndoubleClick(JFrame frame) { + return ((AvatarSMDTransitionInfo)(tgcomponent[0])).editOndoubleClick(frame); + } public int getType() { return TGComponentManager.AVATARSMD_CONNECTOR; diff --git a/src/ui/avatarsmd/AvatarSMDReceiveSignal.java b/src/ui/avatarsmd/AvatarSMDReceiveSignal.java new file mode 100644 index 0000000000000000000000000000000000000000..f860ddae44f33e22042f8ae1a8553c68bf4225f7 --- /dev/null +++ b/src/ui/avatarsmd/AvatarSMDReceiveSignal.java @@ -0,0 +1,257 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class AvatarSMDReceiveSignal + * Action of receiving a signal + * Creation: 12/04/2010 + * @version 1.0 12/04/2010 + * @author Ludovic APVRILLE + * @see + */ + +package ui.avatarsmd; + +import java.awt.*; +import java.awt.geom.*; +import javax.swing.*; +import java.util.*; + +import org.w3c.dom.*; + +import myutil.*; +import ui.*; +import ui.window.*; + +public class AvatarSMDReceiveSignal extends TGCWithoutInternalComponent implements CheckableAccessibility, BasicErrorHighlight { + protected int lineLength = 5; + protected int textX = 5; + protected int textY = 15; + protected int arc = 5; + protected int linebreak = 10; + protected int textX1 = 2; + + + protected int stateOfError = 0; // Not yet checked + + public AvatarSMDReceiveSignal(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); + + width = 30; + height = 20; + minWidth = 30; + + nbConnectingPoint = 2; + connectingPoint = new TGConnectingPoint[2]; + connectingPoint[0] = new AvatarSMDConnectingPoint(this, 0, -lineLength, true, false, 0.5, 0.0); + connectingPoint[1] = new AvatarSMDConnectingPoint(this, 0, lineLength, false, true, 0.5, 1.0); + + moveable = true; + editable = true; + removable = true; + + name = "Send signal"; + value = "sig()"; + //makeValue(); + + myImageIcon = IconManager.imgic904; + } + + public void internalDrawing(Graphics g) { + + int w = g.getFontMetrics().stringWidth(value + textX1); + int w1 = Math.max(minWidth, w + 2 * textX); + if ((w1 != width) & (!tdp.isScaled())) { + setCd(x + width/2 - w1/2, y); + width = w1; + //updateConnectingPoints(); + } + + + if (stateOfError > 0) { + Color c = g.getColor(); + switch(stateOfError) { + case ErrorHighlight.OK: + g.setColor(ColorManager.AVATAR_RECEIVE_SIGNAL); + break; + default: + g.setColor(ColorManager.UNKNOWN_BOX_ACTION); + } + // Making the polygon + int [] px1 = {x, x+width, x+width, x, x+linebreak}; + int [] py1 = {y, y, y+height, y+height, y+(height/2)}; + g.fillPolygon(px1, py1, 5); + g.setColor(c); + } + + //g.drawRoundRect(x, y, width, height, arc, arc); + Color c = g.getColor(); + //System.out.println("Color=" + c); + + g.drawLine(x+(width/2), y, x+(width/2), y - lineLength); + g.drawLine(x+(width/2), y+height, x+(width/2), y + lineLength + height); + + /*if (g.getColor().equals(ColorManager.NORMAL_0)) { + g.setColor(ColorManager.TML_PORT_EVENT); + }*/ + + int x1 = x + 1; + int y1 = y + 1; + int height1 = height; + int width1 = width; + g.setColor(ColorManager.AVATAR_RECEIVE_SIGNAL); + g.drawLine(x1, y1, x1+width1, y1); + g.drawLine(x1+width1, y1, x1+width1, y1+height1); + g.drawLine(x1, y1+height1, x1+width1, y1+height1); + g.drawLine(x1, y1, x1+linebreak, y1+height1/2); + g.drawLine(x1, y1+height1, x1+linebreak, y1+height1/2); + g.setColor(c); + + g.drawLine(x, y, x+width, y); + g.drawLine(x+width, y, x+width, y+height); + g.drawLine(x, y+height, x+width, y+height); + g.drawLine(x, y, x+linebreak, y+height/2); + g.drawLine(x, y+height, x+linebreak, y+height/2); + + + //g.drawString("sig()", x+(width-w) / 2, y); + g.drawString(value, x + linebreak + textX1, y + textY); + + + } + + public TGComponent isOnMe(int _x, int _y) { + if (GraphicLib.isInRectangle(_x, _y, x, y, width, height)) { + return this; + } + + if ((int)(Line2D.ptSegDistSq(x+(width/2), y-lineLength, x+(width/2), y + lineLength + height, _x, _y)) < distanceSelected) { + return this; + } + + return null; + } + + public void makeValue() { + /*boolean first = true; + value = eventName + "("; + for(int i=0; i<nParam; i++) { + if (params[i].length() > 0) { + if (!first) { + value += ", " + params[i]; + } else { + first = false; + value += params[i]; + } + + } + } + value += ")";*/ + + } + + public String getSignalName() { + if (value == null) { + return null; + } + + if (value.length() == 0) { + return ""; + } + + int index = value.indexOf('('); + if (index == -1) { + return value; + } + return value.substring(0, index).trim(); + } + + /*public String getParamValue(int i) { + return params[i]; + } + + public int nbOfParams() { + return nParam; + }*/ + + + public boolean editOndoubleClick(JFrame frame) { + Vector signals = tdp.getMGUI().getAllSignals(); + TraceManager.addDev("Nb of signals:" + signals.size()); + + JDialogAvatarSignal jdas = new JDialogAvatarSignal(frame, "Setting send signal", value, signals, false); + jdas.setSize(350, 300); + GraphicLib.centerOnParent(jdas); + jdas.show(); // blocked until dialog has been closed + + if (jdas.hasBeenCancelled()) { + return false; + } + + String val = jdas.getSignal(); + + if (val.indexOf('(') == -1) { + val += "()"; + } + + // valid signal? + if (AvatarSignal.isAValidUseSignal(val)) { + value = val; + return true; + } + + JOptionPane.showMessageDialog(frame, + "Could not change the setting of the signal: invalid declaration", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + + } + + + public int getType() { + return TGComponentManager.AVATARSMD_RECEIVE_SIGNAL; + } + + public int getDefaultConnector() { + return TGComponentManager.AVATARSMD_CONNECTOR; + } + + public void setStateAction(int _stateAction) { + stateOfError = _stateAction; + } +} diff --git a/src/ui/avatarsmd/AvatarSMDSendSignal.java b/src/ui/avatarsmd/AvatarSMDSendSignal.java new file mode 100644 index 0000000000000000000000000000000000000000..82d4791239f6ec94090112bcdccbe3233b93e2ad --- /dev/null +++ b/src/ui/avatarsmd/AvatarSMDSendSignal.java @@ -0,0 +1,319 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class AvatarSMDSendSignal + * Action of sending a signal + * Creation: 12/04/2010 + * @version 1.0 12/04/2010 + * @author Ludovic APVRILLE + * @see + */ + +package ui.avatarsmd; + +import java.awt.*; +import java.awt.geom.*; +import javax.swing.*; + +import java.util.*; + +import org.w3c.dom.*; + +import myutil.*; +import ui.*; +import ui.window.*; + +public class AvatarSMDSendSignal extends TGCWithoutInternalComponent implements CheckableAccessibility, BasicErrorHighlight { + protected int lineLength = 5; + protected int textX = 5; + protected int textY = 15; + protected int arc = 5; + protected int linebreak = 10; + + + protected int stateOfError = 0; // Not yet checked + + public AvatarSMDSendSignal(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); + + width = 30; + height = 20; + minWidth = 30; + + nbConnectingPoint = 2; + connectingPoint = new TGConnectingPoint[2]; + connectingPoint[0] = new AvatarSMDConnectingPoint(this, 0, -lineLength, true, false, 0.5, 0.0); + connectingPoint[1] = new AvatarSMDConnectingPoint(this, 0, lineLength, false, true, 0.5, 1.0); + + moveable = true; + editable = true; + removable = true; + + name = "Send signal"; + value = "sig()"; + //makeValue(); + + myImageIcon = IconManager.imgic904; + } + + public void internalDrawing(Graphics g) { + + int w = g.getFontMetrics().stringWidth(value); + int w1 = Math.max(minWidth, w + 2 * textX); + if ((w1 != width) & (!tdp.isScaled())) { + setCd(x + width/2 - w1/2, y); + width = w1; //updateConnectingPoints(); + } + + + if (stateOfError > 0) { + Color c = g.getColor(); + switch(stateOfError) { + case ErrorHighlight.OK: + g.setColor(ColorManager.AVATAR_SEND_SIGNAL); + break; + default: + g.setColor(ColorManager.UNKNOWN_BOX_ACTION); + } + // Making the polygon + int [] px1 = {x, x+width-linebreak, x+width, x+width-linebreak, x}; + int [] py1 = {y, y, y+(height/2), y+height, y+height}; + g.fillPolygon(px1, py1, 5); + g.setColor(c); + } + + //g.drawRoundRect(x, y, width, height, arc, arc); + Color c = g.getColor(); + //System.out.println("Color=" + c); + + g.drawLine(x+(width/2), y, x+(width/2), y - lineLength); + g.drawLine(x+(width/2), y+height, x+(width/2), y + lineLength + height); + + /*if (g.getColor().equals(ColorManager.NORMAL_0)) { + g.setColor(ColorManager.TML_PORT_EVENT); + }*/ + + int x1 = x + 1; + int y1 = y + 1; + int height1 = height; + int width1 = width; + g.setColor(ColorManager.AVATAR_SEND_SIGNAL); + g.drawLine(x1, y1, x1+width1-linebreak, y1); + g.drawLine(x1, y1+height1, x1+width1-linebreak, y1+height1); + g.drawLine(x1, y1, x1, y1+height1); + g.drawLine(x1+width1-linebreak, y1, x1+width1, y1+height1/2); + g.drawLine(x1+width1-linebreak, y1+height1, x1+width1, y1+height1/2); + g.setColor(c); + + g.drawLine(x, y, x+width-linebreak, y); + g.drawLine(x, y+height, x+width-linebreak, y+height); + g.drawLine(x, y, x, y+height); + g.drawLine(x+width-linebreak, y, x+width, y+height/2); + g.drawLine(x+width-linebreak, y+height, x+width, y+height/2); + + + //g.drawString("sig()", x+(width-w) / 2, y); + g.drawString(value, x + (width - w) / 2 , y + textY); + + + } + + public TGComponent isOnMe(int _x, int _y) { + if (GraphicLib.isInRectangle(_x, _y, x, y, width, height)) { + return this; + } + + if ((int)(Line2D.ptSegDistSq(x+(width/2), y-lineLength, x+(width/2), y + lineLength + height, _x, _y)) < distanceSelected) { + return this; + } + + return null; + } + + public void makeValue() { + /*boolean first = true; + value = eventName + "("; + for(int i=0; i<nParam; i++) { + if (params[i].length() > 0) { + if (!first) { + value += ", " + params[i]; + } else { + first = false; + value += params[i]; + } + + } + } + value += ")";*/ + + } + + public String getSignalName() { + if (value == null) { + return null; + } + + if (value.length() == 0) { + return ""; + } + + int index = value.indexOf('('); + if (index == -1) { + return value; + } + return value.substring(0, index).trim(); + } + + /*public String getParamValue(int i) { + return params[i]; + } + + public int nbOfParams() { + return nParam; + }*/ + + + public boolean editOndoubleClick(JFrame frame) { + Vector signals = tdp.getMGUI().getAllSignals(); + TraceManager.addDev("Nb of signals:" + signals.size()); + + JDialogAvatarSignal jdas = new JDialogAvatarSignal(frame, "Setting receiving signal", value, signals, true); + jdas.setSize(350, 300); + GraphicLib.centerOnParent(jdas); + jdas.show(); // blocked until dialog has been closed + + if (jdas.hasBeenCancelled()) { + return false; + } + + String val = jdas.getSignal(); + + if (val.indexOf('(') == -1) { + val += "()"; + } + + // valid signal? + if (AvatarSignal.isAValidUseSignal(val)) { + value = val; + return true; + } + + JOptionPane.showMessageDialog(frame, + "Could not change the setting of the signal: invalid declaration", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + + } + + /*protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<Data eventName=\""); + sb.append(getEventName()); + sb.append("\" nbOfParams=\""); + sb.append(nbOfParams()); + sb.append("\" />\n"); + for(int i=0; i<nParam; i++) { + if (params[i].length() > 0) { + sb.append("<Param index=\""); + sb.append(i); + sb.append("\" value=\""); + sb.append(params[i]); + sb.append("\" />\n"); + } + } + sb.append("</extraparam>\n"); + return new String(sb); + } + + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + //System.out.println("*** load extra synchro *** " + getId()); + try { + + NodeList nli; + Node n1, n2; + Element elt; + int k; + String s; + + //System.out.println("Loading Synchronization gates"); + //System.out.println(nl.toString()); + + for(int i=0; i<nl.getLength(); i++) { + n1 = nl.item(i); + //System.out.println(n1); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for(int j=0; i<nli.getLength(); i++) { + n2 = nli.item(i); + //System.out.println(n2); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("Data")) { + eventName = elt.getAttribute("eventName"); + nParam = Integer.decode(elt.getAttribute("nbOfParams")).intValue(); + } + if (elt.getTagName().equals("Param")) { + s = elt.getAttribute("value"); + k = Integer.decode(elt.getAttribute("index")).intValue(); + params[k] = s; + } + } + } + } + } + + } catch (Exception e) { + throw new MalformedModelingException(); + } + makeValue(); + }*/ + + + public int getType() { + return TGComponentManager.AVATARSMD_SEND_SIGNAL; + } + + public int getDefaultConnector() { + return TGComponentManager.AVATARSMD_CONNECTOR; + } + + public void setStateAction(int _stateAction) { + stateOfError = _stateAction; + } +} diff --git a/src/ui/avatarsmd/AvatarSMDToolBar.java b/src/ui/avatarsmd/AvatarSMDToolBar.java index 4ffd05f03ac794aac180d9a6fe60f9f844e13705..f0070847ced0da15ad1e6fbb7204a50f7bd92fb6 100755 --- a/src/ui/avatarsmd/AvatarSMDToolBar.java +++ b/src/ui/avatarsmd/AvatarSMDToolBar.java @@ -65,6 +65,8 @@ public class AvatarSMDToolBar extends TToolBar { mgui.actions[TGUIAction.ASMD_CONNECTOR].setEnabled(b); mgui.actions[TGUIAction.ASMD_START].setEnabled(b); mgui.actions[TGUIAction.ASMD_STOP].setEnabled(b); + mgui.actions[TGUIAction.ASMD_SEND_SIGNAL].setEnabled(b); + mgui.actions[TGUIAction.ASMD_RECEIVE_SIGNAL].setEnabled(b); mgui.actions[TGUIAction.ACT_ZOOM_MORE].setEnabled(false); mgui.actions[TGUIAction.ACT_ZOOM_LESS].setEnabled(false); @@ -95,6 +97,14 @@ public class AvatarSMDToolBar extends TToolBar { button = this.add(mgui.actions[TGUIAction.ASMD_STOP]); button.addMouseListener(mgui.mouseHandler); + + this.addSeparator(); + + button = this.add(mgui.actions[TGUIAction.ASMD_SEND_SIGNAL]); + button.addMouseListener(mgui.mouseHandler); + + button = this.add(mgui.actions[TGUIAction.ASMD_RECEIVE_SIGNAL]); + button.addMouseListener(mgui.mouseHandler); /*this.addSeparator(); diff --git a/src/ui/avatarsmd/AvatarSMDTransitionInfo.java b/src/ui/avatarsmd/AvatarSMDTransitionInfo.java new file mode 100755 index 0000000000000000000000000000000000000000..b15e213350884f5b898ed701c773f8c4099ff9bc --- /dev/null +++ b/src/ui/avatarsmd/AvatarSMDTransitionInfo.java @@ -0,0 +1,347 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** +* Class AvatarSMDTransitionInfo +* Internal component that represents a set of parameter for a transition +* e.g., guard, after, compute, set of actions +* Creation: 12/04/2010 +* @version 1.0 12/04/2010 +* @author Ludovic APVRILLE +* @see +*/ + +package ui.avatarsmd; + +import java.awt.*; +//import java.awt.geom.*; +import java.util.*; +import javax.swing.*; + +import org.w3c.dom.*; + +import myutil.*; +import ui.*; +import ui.window.*; + +public class AvatarSMDTransitionInfo extends TGCWithoutInternalComponent { + + protected String guard; + protected String afterMin; + protected String afterMax; + protected String computeMin; + protected String computeMax; + protected Vector<String> listOfActions; + + protected int minWidth = 10; + protected int minHeight = 15; + protected int h; + + protected String defaultValue; + + public AvatarSMDTransitionInfo(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); + + moveable = true; + editable = true; + removable = false; + + guard = "[ ]"; + afterMin = ""; + afterMax = ""; + computeMin = ""; + computeMax = ""; + + + listOfActions = new Vector<String>(); + + myImageIcon = IconManager.imgic302; + } + + public Vector<String> getListOfActions() { + return listOfActions; + } + + public void internalDrawing(Graphics g) { + int step = 0; + String s; + h = g.getFontMetrics().getHeight(); + ColorManager.setColor(g, getState(), 0); + int inc = h; + + if (guard.length() > 0) { + if (guard.compareTo("[ ]") != 0) { + g.drawString(guard, x, y + step); + if (!tdp.isScaled()) { + width = Math.max(g.getFontMetrics().stringWidth(guard), width); + width = Math.max(minWidth, width); + } + step += inc; + } + } + + if (afterMin.length() > 0) { + if (afterMax.length() > 0) { + s = "after (" + afterMin + "," + afterMax + ")"; + g.drawString(s, x, y + step); + if (!tdp.isScaled()) { + width = Math.max(g.getFontMetrics().stringWidth(s), width); + width = Math.max(minWidth, width); + } + step += inc; + } else { + s = "after (" + afterMin + ")"; + g.drawString(s, x, y + step); + if (!tdp.isScaled()) { + width = Math.max(g.getFontMetrics().stringWidth(s), width); + width = Math.max(minWidth, width); + } + step += inc; + } + } + + if (computeMin.length() > 0) { + if (computeMax.length() > 0) { + s = "computeFor (" + computeMin + "," + computeMax + ")"; + g.drawString(s, x, y + step); + if (!tdp.isScaled()) { + width = Math.max(g.getFontMetrics().stringWidth(s), width); + width = Math.max(minWidth, width); + } + step += inc; + } else { + s = "computeFor (" + computeMin + ")"; + g.drawString(s, x, y + step); + if (!tdp.isScaled()) { + width = Math.max(g.getFontMetrics().stringWidth(s), width); + width = Math.max(minWidth, width); + } + step += inc; + } + } + + for(int i=0; i<listOfActions.size(); i++) { + s = listOfActions.get(i); + if (s.length() > 0) { + g.drawString(s, x, y + step); + if (!tdp.isScaled()) { + width = Math.max(g.getFontMetrics().stringWidth(s), width); + width = Math.max(minWidth, width); + } + step += inc; + } + } + + if (!tdp.isScaled()) { + height = step; + } + } + + public TGComponent isOnMe(int _x, int _y) { + if (GraphicLib.isInRectangle(_x, _y, x, y - h + 2, width, height)) { + return this; + } + return null; + } + + public boolean isInRectangle(int x1, int y1, int width, int height) { + if ((getX() < x1) || (getY() < y1) || ((getX() + this.width) > (x1 + width)) || ((getY() + this.height) > (y1 + height))) { + //System.out.println("Not in my rectangle " + this); + return false; + } else { + return true; + } + } + + /*public int getMycurrentMinY() { + return Math.min(y, y - h + 2); + } + + public int getMycurrentMaxY() { + return Math.min(y, y - h + 2 + height); + }*/ + + /*public void valueChanged() { + + }*/ + + /*public void setTClass(TClassSynchroInterface _t1, TClassSynchroInterface _t2) { + t1 = _t1; + t2 = _t2; + if ((t1 != oldt1) || (t2 != oldt2)) { + gates = new Vector(); + //System.out.println("New gates"); + makeValue(); + } + oldt1 = t1; + oldt2 = t2; + } + + public void makeValue() { + value = ""; + for(int i=0; i<gates.size(); i++) { + if (i != 0) { + value += "\n"; + } + value += (gates.elementAt(i)).toString(); + } + }*/ + + public boolean editOndoubleClick(JFrame frame) { + + JDialogAvatarTransition jdat = new JDialogAvatarTransition(frame, "Setting transition parameters", guard, afterMin, afterMax, computeMin, computeMax, listOfActions); + jdat.setSize(750, 400); + GraphicLib.centerOnParent(jdat); + jdat.show(); // blocked until dialog has been closed + + + if (jdat.hasBeenCancelled()) { + return false; + } + + guard = jdat.getGuard().trim(); + + int index = guard.indexOf('['); + if (index == -1) { + guard = "[ " + guard + " ]"; + } + + afterMin = jdat.getAfterMin().trim(); + afterMax = jdat.getAfterMax().trim(); + computeMin = jdat.getComputeMin().trim(); + computeMax = jdat.getComputeMax().trim(); + + return false; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<guard value=\""); + sb.append(guard); + sb.append("\" />\n"); + + sb.append("<afterMin value=\""); + sb.append(afterMin); + sb.append("\" />\n"); + + sb.append("<afterMax value=\""); + sb.append(afterMax); + sb.append("\" />\n"); + + sb.append("<computeMin value=\""); + sb.append(computeMin); + sb.append("\" />\n"); + + sb.append("<computeMax value=\""); + sb.append(computeMax); + sb.append("\" />\n"); + + for(int i=0; i<listOfActions.size(); i++) { + sb.append("<actions value=\""); + sb.append(listOfActions.get(i)); + sb.append("\" />\n"); + } + sb.append("</extraparam>\n"); + return new String(sb); + } + + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + //System.out.println("*** load extra synchro *** " + getId()); + try { + listOfActions = new Vector(); + + NodeList nli; + Node n1, n2; + Element elt; + String s; + + for(int i=0; i<nl.getLength(); i++) { + n1 = nl.item(i); + //System.out.println(n1); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for(int j=0; i<nli.getLength(); i++) { + n2 = nli.item(i); + //System.out.println(n2); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)n2; + if (elt.getTagName().equals("guard")) { + s = elt.getAttribute("value"); + if (s != null) { + guard = s; + } + } + if (elt.getTagName().equals("afterMin")) { + s = elt.getAttribute("value"); + if (s != null) { + afterMin = s; + } + } + if (elt.getTagName().equals("afterMax")) { + s = elt.getAttribute("value"); + if (s != null) { + afterMax = s; + } + } + if (elt.getTagName().equals("computeMin")) { + s = elt.getAttribute("value"); + if (s != null) { + computeMin = s; + } + } + if (elt.getTagName().equals("computeMax")) { + s = elt.getAttribute("value"); + if (s != null) { + computeMax = s; + } + } + if (elt.getTagName().equals("action")) { + s = elt.getAttribute("value"); + if (s != null) { + listOfActions.add(s); + } + } + } + } + } + } + + } catch (Exception e) { + throw new MalformedModelingException(); + } + } +} \ No newline at end of file diff --git a/src/ui/images/avatarbdcomp.gif b/src/ui/images/avatarbdcomp.gif new file mode 100644 index 0000000000000000000000000000000000000000..2dd19f56edb722d7c045a5ac0a45dc5c62c67d55 Binary files /dev/null and b/src/ui/images/avatarbdcomp.gif differ diff --git a/src/ui/images/avatarbdlink.gif b/src/ui/images/avatarbdlink.gif new file mode 100644 index 0000000000000000000000000000000000000000..be9b21f4545d161e4f14bd39ac39f0ea72009fcd Binary files /dev/null and b/src/ui/images/avatarbdlink.gif differ diff --git a/src/ui/images/avatarblock.gif b/src/ui/images/avatarblock.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e96c5908fdf75f2ca64100fedd2e09fe22c59ae Binary files /dev/null and b/src/ui/images/avatarblock.gif differ diff --git a/src/ui/window/JDialogAvatarBlock.java b/src/ui/window/JDialogAvatarBlock.java new file mode 100755 index 0000000000000000000000000000000000000000..37d3c27a8513f4abd5ffae737ddeb748f9e93db2 --- /dev/null +++ b/src/ui/window/JDialogAvatarBlock.java @@ -0,0 +1,918 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + * + * /** + * Class JDialogAvatarBlock + * Dialog for managing attributes, methods and signals of Avatar Blocks + * Creation: 08/04/2010 + * @version 1.0 08/04/2010 + * @author Ludovic APVRILLE + * @see + */ + +package ui.window; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import ui.*; +import myutil.*; + + +public class JDialogAvatarBlock extends javax.swing.JDialog implements ActionListener, ListSelectionListener { + private Vector attributes, attributesPar, forbidden, initValues; + private Vector methods, methodsPar, signals, signalsPar; + private boolean checkKeyword, checkJavaKeyword; + + private JPanel panel1, panel2; + + private Frame frame; + private int tab; + + private String attrib; // "Attributes", "Gates", etc. + + // Panel1 + private JComboBox accessBox, typeBox; + private JTextField identifierText; + private JTextField initialValue; + private JButton addButton; + + //Panel2 + private JList listAttribute; + private JButton upButton; + private JButton downButton; + private JButton removeButton; + + // Method + private JPanel panel3, panel4; + private JTextField methodText; + private JButton addMethodButton; + private JList listMethod; + private JButton upMethodButton; + private JButton downMethodButton; + private JButton removeMethodButton; + + // Signals + private JPanel panel5, panel6; + private JComboBox signalInOutBox; + private JTextField signalText; + private JButton addSignalButton; + private JList listSignal; + private JButton upSignalButton; + private JButton downSignalButton; + private JButton removeSignalButton; + + // Main Panel + private JButton closeButton; + private JButton cancelButton; + + /** Creates new form */ + public JDialogAvatarBlock(Vector _attributes, Vector _methods, Vector _signals, Vector _forbidden, Frame f, String title, String attrib, int _tab) { + super(f, title, true); + frame = f; + attributesPar = _attributes; + methodsPar = _methods; + signalsPar = _signals; + forbidden = _forbidden; + initValues = new Vector(); + this.attrib = attrib; + tab = _tab; + + attributes = new Vector(); + methods = new Vector(); + signals = new Vector(); + + for(int i=0; i<attributesPar.size(); i++) { + attributes.addElement(((TAttribute)(attributesPar.elementAt(i))).makeClone()); + } + + for(int i=0; i<methodsPar.size(); i++) { + methods.addElement(((AvatarMethod)(methodsPar.elementAt(i))).makeClone()); + } + + for(int i=0; i<signalsPar.size(); i++) { + signals.addElement(((AvatarSignal)(signalsPar.elementAt(i))).makeClone()); + } + + initComponents(); + myInitComponents(); + pack(); + } + + private void myInitComponents() { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + } + + private void initComponents() { + JTabbedPane tabbedPane = new JTabbedPane(); + Container c = getContentPane(); + + JPanel panelAttr = new JPanel(new BorderLayout()); + JPanel panelMethod = new JPanel(new BorderLayout()); + JPanel panelSignal = new JPanel(new BorderLayout()); + GridBagLayout gridbag0 = new GridBagLayout(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagLayout gridbag2 = new GridBagLayout(); + GridBagLayout gridbag3 = new GridBagLayout(); + GridBagLayout gridbag4 = new GridBagLayout(); + GridBagLayout gridbag5 = new GridBagLayout(); + GridBagLayout gridbag6 = new GridBagLayout(); + GridBagConstraints c0 = new GridBagConstraints(); + GridBagConstraints c1 = new GridBagConstraints(); + GridBagConstraints c2 = new GridBagConstraints(); + GridBagConstraints c3 = new GridBagConstraints(); + GridBagConstraints c4 = new GridBagConstraints(); + GridBagConstraints c5 = new GridBagConstraints(); + GridBagConstraints c6 = new GridBagConstraints(); + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + c.setLayout(gridbag0); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + panel1 = new JPanel(); + panel1.setLayout(gridbag1); + panel1.setBorder(new javax.swing.border.TitledBorder("Adding " + attrib + "s")); + panel1.setPreferredSize(new Dimension(300, 250)); + + panel2 = new JPanel(); + panel2.setLayout(gridbag2); + panel2.setBorder(new javax.swing.border.TitledBorder("Managing " + attrib + "s")); + panel2.setPreferredSize(new Dimension(300, 250)); + + // first line panel1 + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 3; + panel1.add(new JLabel(" "), c1); + + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.anchor = GridBagConstraints.CENTER; + panel1.add(new JLabel("access"), c1); + panel1.add(new JLabel("identifier"), c1); + if (attrib.equals("Attribute") || attrib.equals("Variable")) { + panel1.add(new JLabel(" "), c1); + panel1.add(new JLabel("initial value"), c1); + } + panel1.add(new JLabel(" "), c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + panel1.add(new JLabel("type"), c1); + + // second line panel1 + c1.gridwidth = 1; + c1.fill = GridBagConstraints.HORIZONTAL; + c1.anchor = GridBagConstraints.CENTER; + accessBox = new JComboBox(); + panel1.add(accessBox, c1); + identifierText = new JTextField(); + identifierText.setColumns(15); + identifierText.setEditable(true); + panel1.add(identifierText, c1); + + initialValue = new JTextField(); + initialValue.setColumns(5); + initialValue.setEditable(true); + + if (attrib.equals("Attribute") || attrib.equals("Variable")) { + panel1.add(new JLabel(" = "), c1); + panel1.add(initialValue, c1); + } + + panel1.add(new JLabel(" : "), c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + typeBox = new JComboBox(); + typeBox.addActionListener(this); + panel1.add(typeBox, c1); + + // third line panel1 + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 3; + panel1.add(new JLabel(" "), c1); + + // fourth line panel2 + c1.gridheight = 1; + c1.fill = GridBagConstraints.HORIZONTAL; + addButton = new JButton("Add / Modify " + attrib); + addButton.addActionListener(this); + panel1.add(addButton, c1); + + // 1st line panel2 + listAttribute = new JList(attributes); + //listAttribute.setFixedCellWidth(150); + //listAttribute.setFixedCellHeight(20); + listAttribute.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listAttribute.addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(listAttribute); + scrollPane.setSize(300, 250); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + c2.fill = GridBagConstraints.BOTH; + c2.gridheight = 5; + c2.weighty = 10.0; + c2.weightx = 10.0; + panel2.add(scrollPane, c2); + + // 2nd line panel2 + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.fill = GridBagConstraints.BOTH; + c2.gridheight = 1; + panel2.add(new JLabel(""), c2); + + // third line panel2 + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + c2.fill = GridBagConstraints.HORIZONTAL; + upButton = new JButton("Up"); + upButton.addActionListener(this); + panel2.add(upButton, c2); + + downButton = new JButton("Down"); + downButton.addActionListener(this); + panel2.add(downButton, c2); + + removeButton = new JButton("Remove " + attrib); + removeButton.addActionListener(this); + panel2.add(removeButton, c2); + + // Methods + panel3 = new JPanel(); + panel3.setLayout(gridbag3); + panel3.setBorder(new javax.swing.border.TitledBorder("Adding methods")); + panel3.setPreferredSize(new Dimension(300, 250)); + + panel4 = new JPanel(); + panel4.setLayout(gridbag2); + panel4.setBorder(new javax.swing.border.TitledBorder("Managing methods")); + panel4.setPreferredSize(new Dimension(300, 250)); + + // first line panel3 + c3.gridwidth = 1; + c3.gridheight = 1; + c3.weighty = 1.0; + c3.weightx = 1.0; + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + c3.fill = GridBagConstraints.BOTH; + c3.gridheight = 3; + panel3.add(new JLabel(" "), c3); + + c3.gridwidth = 1; + c3.gridheight = 1; + c3.weighty = 1.0; + c3.weightx = 1.0; + c3.anchor = GridBagConstraints.CENTER; + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + panel3.add(new JLabel("method:"), c3); + + // second line panel3 + methodText = new JTextField(); + methodText.setColumns(50); + methodText.setEditable(true); + panel3.add(methodText, c3); + + // third line panel3 + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + c3.fill = GridBagConstraints.BOTH; + c3.gridheight = 3; + panel3.add(new JLabel(" "), c3); + + // fourth line panel3 + c3.gridheight = 1; + c3.fill = GridBagConstraints.HORIZONTAL; + addMethodButton = new JButton("Add method"); + addMethodButton.addActionListener(this); + panel3.add(addMethodButton, c3); + + // 1st line panel4 + listMethod = new JList(methods); + listMethod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listMethod.addListSelectionListener(this); + scrollPane = new JScrollPane(listMethod); + scrollPane.setSize(300, 250); + c4.gridwidth = GridBagConstraints.REMAINDER; //end row + c4.fill = GridBagConstraints.BOTH; + c4.gridheight = 5; + c4.weighty = 10.0; + c4.weightx = 10.0; + panel4.add(scrollPane, c4); + + // 2nd line panel4 + c4.weighty = 1.0; + c4.weightx = 1.0; + c4.fill = GridBagConstraints.BOTH; + c4.gridheight = 1; + panel4.add(new JLabel(""), c4); + + // third line panel4 + c4.gridwidth = GridBagConstraints.REMAINDER; //end row + c4.fill = GridBagConstraints.HORIZONTAL; + upMethodButton = new JButton("Up"); + upMethodButton.addActionListener(this); + panel4.add(upMethodButton, c4); + + downMethodButton = new JButton("Down"); + downMethodButton.addActionListener(this); + panel4.add(downMethodButton, c4); + + removeMethodButton = new JButton("Remove method"); + removeMethodButton.addActionListener(this); + panel4.add(removeMethodButton, c4); + + // Signals + panel5 = new JPanel(); + panel5.setLayout(gridbag5); + panel5.setBorder(new javax.swing.border.TitledBorder("Adding signals")); + panel5.setPreferredSize(new Dimension(300, 250)); + + panel6 = new JPanel(); + panel6.setLayout(gridbag6); + panel6.setBorder(new javax.swing.border.TitledBorder("Managing signals")); + panel6.setPreferredSize(new Dimension(300, 250)); + + // first line panel5 + c5.gridwidth = 1; + c5.gridheight = 1; + c5.weighty = 1.0; + c5.weightx = 1.0; + c5.gridwidth = GridBagConstraints.REMAINDER; //end row + c5.fill = GridBagConstraints.BOTH; + c5.gridheight = 3; + panel5.add(new JLabel(" "), c5); + + c5.gridwidth = 1; + c5.gridheight = 1; + c5.weighty = 1.0; + c5.weightx = 1.0; + c5.anchor = GridBagConstraints.CENTER; + c5.gridwidth = GridBagConstraints.REMAINDER; //end row + panel5.add(new JLabel("signal:"), c5); + + // second line panel5 + c5.gridwidth = 1; + Vector v = new Vector(); + v.add("in"); + v.add("out"); + signalInOutBox = new JComboBox(v); + panel5.add(signalInOutBox, c5); + signalText = new JTextField(); + signalText.setColumns(50); + signalText.setEditable(true); + panel5.add(signalText, c5); + + // third line panel5 + c5.gridwidth = GridBagConstraints.REMAINDER; //end row + c5.fill = GridBagConstraints.BOTH; + c5.gridheight = 3; + panel5.add(new JLabel(" "), c5); + + // fourth line panel5 + c5.gridheight = 1; + c5.fill = GridBagConstraints.HORIZONTAL; + addSignalButton = new JButton("Add signal"); + addSignalButton.addActionListener(this); + panel5.add(addSignalButton, c5); + + // 1st line panel6 + listSignal = new JList(signals); + listSignal.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listSignal.addListSelectionListener(this); + scrollPane = new JScrollPane(listSignal); + scrollPane.setSize(300, 250); + c6.gridwidth = GridBagConstraints.REMAINDER; //end row + c6.fill = GridBagConstraints.BOTH; + c6.gridheight = 5; + c6.weighty = 10.0; + c6.weightx = 10.0; + panel6.add(scrollPane, c6); + + // 2nd line panel4 + c6.weighty = 1.0; + c6.weightx = 1.0; + c6.fill = GridBagConstraints.BOTH; + c6.gridheight = 1; + panel6.add(new JLabel(""), c6); + + // third line panel4 + c6.gridwidth = GridBagConstraints.REMAINDER; //end row + c6.fill = GridBagConstraints.HORIZONTAL; + upSignalButton = new JButton("Up"); + upSignalButton.addActionListener(this); + panel6.add(upSignalButton, c6); + + downSignalButton = new JButton("Down"); + downSignalButton.addActionListener(this); + panel6.add(downSignalButton, c6); + + removeSignalButton = new JButton("Remove signal"); + removeSignalButton.addActionListener(this); + panel6.add(removeSignalButton, c6); + + // main panel; + panelAttr.add(panel1, BorderLayout.WEST); + panelAttr.add(panel2, BorderLayout.EAST); + tabbedPane.addTab("Attributes", panelAttr); + + panelMethod.add(panel3, BorderLayout.WEST); + panelMethod.add(panel4, BorderLayout.EAST); + tabbedPane.addTab("Methods", panelMethod); + + panelSignal.add(panel5, BorderLayout.WEST); + panelSignal.add(panel6, BorderLayout.EAST); + tabbedPane.addTab("Signals", panelSignal); + + tabbedPane.setSelectedIndex(tab); + + //c.add(panel1, c0); + //c.add(panel2, c0); + + c0.gridwidth = 1; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + c.add(tabbedPane, c0); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + closeButton = new JButton("Save and Close", IconManager.imgic25); + //closeButton.setPreferredSize(new Dimension(600, 50)); + closeButton.addActionListener(this); + c.add(closeButton, c0); + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + cancelButton = new JButton("Cancel", IconManager.imgic27); + cancelButton.addActionListener(this); + c.add(cancelButton, c0); + } + + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == typeBox) { + boolean b = ((Boolean)(initValues.elementAt(typeBox.getSelectedIndex()))).booleanValue(); + initialValue.setEnabled(b); + return; + } + + + //String command = evt.getActionCommand(); + + // Compare the action command to the known actions. + if (evt.getSource() == closeButton) { + closeDialog(); + } else if (evt.getSource() == addButton) { + addAttribute(); + } else if (evt.getSource() == cancelButton) { + cancelDialog(); + } else if (evt.getSource() == removeButton) { + removeAttribute(); + } else if (evt.getSource() == downButton) { + downAttribute(); + } else if (evt.getSource() == upButton) { + upAttribute(); + } else if (evt.getSource() == upMethodButton) { + //TraceManager.addDev("Up method"); + upMethod(); + } else if (evt.getSource() == downMethodButton) { + downMethod(); + } else if (evt.getSource() == removeMethodButton) { + removeMethod(); + } else if (evt.getSource() == addMethodButton) { + addMethod(); + } else if (evt.getSource() == downSignalButton) { + downSignal(); + } else if (evt.getSource() == removeSignalButton) { + removeSignal(); + } else if (evt.getSource() == addSignalButton) { + addSignal(); + } else if (evt.getSource() == addSignalButton) { + addSignal(); + } + } + + public void addAccess(String s) { + accessBox.addItem(s); + } + + public void addType(String s) { + initValues.add(new Boolean(true)); + typeBox.addItem(s); + } + + public void addType(String s, boolean b) { + initValues.add(new Boolean(b)); + typeBox.addItem(s); + } + + public void enableInitialValue(boolean b) { + initialValue.setEnabled(b); + } + + public void enableRTLOTOSKeyword(boolean b) { + checkKeyword = !b; + } + + public void enableJavaKeyword(boolean b) { + checkJavaKeyword = !b; + } + + + + public void addAttribute() { + Object o1 = accessBox.getSelectedItem(); + Object o2 = typeBox.getSelectedItem(); + String s = identifierText.getText(); + String value = initialValue.getText(); + TAttribute a; + + if (s.length()>0) { + if ((TAttribute.isAValidId(s, checkKeyword, checkJavaKeyword)) && (TAttribute.notIn(s, forbidden))){ + int i = TAttribute.getAccess(o1.toString()); + int j = TAttribute.getType(o2.toString()); + + if ((j == TAttribute.ARRAY_NAT) && (value.length() < 1)) { + value = "2"; + } + + if ((i != -1) && (j!= -1)) { + + if ((value.length() < 1) || (initialValue.isEnabled() == false)){ + + value = ""; + } else { + if (!TAttribute.isAValidInitialValue(j, value)) { + JOptionPane.showMessageDialog(frame, + "The initial value is not valid", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + } + if (j == TAttribute.OTHER) { + a = new TAttribute(i, s, value, o2.toString()); + //System.out.println("New attribute: " + o2.toString()); + } else { + a = new TAttribute(i, s, value, j); + } + //checks whether the same attribute already belongs to the list + int index = attributes.size(); + if (attributes.contains(a)) { + index = attributes.indexOf(a); + a = (TAttribute)(attributes.elementAt(index)); + a.setAccess(i); + if (j == TAttribute.OTHER) { + a.setTypeOther(o2.toString()); + } + a.setType(j); + a.setInitialValue(value); + //attributes.removeElementAt(index); + } else { + attributes.add(index, a); + } + listAttribute.setListData(attributes); + identifierText.setText(""); + } else { + JOptionPane.showMessageDialog(frame, + "Bad access / type", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + } else { + JOptionPane.showMessageDialog(frame, + "Bad identifier: identifier already in use, or invalid identifier", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + } else { + JOptionPane.showMessageDialog(frame, + "Bad identifier", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + } + + public void addMethod() { + TraceManager.addDev("addMethod"); + String s = methodText.getText(); + AvatarMethod am = AvatarMethod.isAValidMethod(s); + AvatarMethod amtmp; + + if (am != null) { + // Checks whether the same method already belongs to the list + int index = -1; + for(int i=0; i<methods.size(); i++) { + amtmp = (AvatarMethod)(methods.get(i)); + // Same id? + if (amtmp.equals(am)) { + index = i; + break; + } + } + if (index == -1) { + methods.add(am); + } else { + methods.removeElementAt(index); + methods.add(index, am); + } + listMethod.setListData(methods); + methodText.setText(""); + + } else { + JOptionPane.showMessageDialog(frame, + "Badly formatted method declaration", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + } + + public void addSignal() { + TraceManager.addDev("addSignal"); + String s = signalText.getText(); + AvatarSignal as = AvatarSignal.isAValidSignal(signalInOutBox.getSelectedIndex(), s); + AvatarSignal astmp; + + if (as != null) { + // Checks whether the same signal already belongs to the list + int index = -1; + for(int i=0; i<signals.size(); i++) { + astmp = (AvatarSignal)(signals.get(i)); + // Same id? + if (astmp.equals(as)) { + index = i; + break; + } + } + if (index == -1) { + signals.add(as); + } else { + signals.removeElementAt(index); + signals.add(index, as); + } + listSignal.setListData(signals); + signalText.setText(""); + + } else { + JOptionPane.showMessageDialog(frame, + "Badly formatted signal declaration", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + } + + public void removeAttribute() { + int i = listAttribute.getSelectedIndex() ; + if (i!= -1) { + TAttribute a = (TAttribute)(attributes.elementAt(i)); + a.setAccess(-1); + attributes.removeElementAt(i); + listAttribute.setListData(attributes); + } + } + + public void downAttribute() { + int i = listAttribute.getSelectedIndex(); + if ((i!= -1) && (i != attributes.size() - 1)) { + Object o = attributes.elementAt(i); + attributes.removeElementAt(i); + attributes.insertElementAt(o, i+1); + listAttribute.setListData(attributes); + listAttribute.setSelectedIndex(i+1); + } + } + + public void upAttribute() { + int i = listAttribute.getSelectedIndex(); + if (i > 0) { + Object o = attributes.elementAt(i); + attributes.removeElementAt(i); + attributes.insertElementAt(o, i-1); + listAttribute.setListData(attributes); + listAttribute.setSelectedIndex(i-1); + } + } + + public void removeMethod() { + int i = listMethod.getSelectedIndex() ; + if (i!= -1) { + //AvatarMethod am = (AvatarMethod)(methods.elementAt(i)); + //a.setAccess(-1); + methods.removeElementAt(i); + listMethod.setListData(methods); + } + } + + public void upMethod() { + int i = listMethod.getSelectedIndex(); + if (i > 0) { + Object o = methods.elementAt(i); + methods.removeElementAt(i); + methods.insertElementAt(o, i-1); + listMethod.setListData(methods); + listMethod.setSelectedIndex(i-1); + } + } + + public void downMethod() { + int i = listMethod.getSelectedIndex(); + if ((i!= -1) && (i != methods.size() - 1)) { + Object o = methods.elementAt(i); + methods.removeElementAt(i); + methods.insertElementAt(o, i+1); + listMethod.setListData(methods); + listMethod.setSelectedIndex(i+1); + } + } + + public void removeSignal() { + int i = listSignal.getSelectedIndex() ; + if (i!= -1) { + //AvatarMethod am = (AvatarMethod)(methods.elementAt(i)); + //a.setAccess(-1); + signals.removeElementAt(i); + listSignal.setListData(signals); + } + } + + public void upSignal() { + int i = listSignal.getSelectedIndex(); + if (i > 0) { + Object o = signals.elementAt(i); + signals.removeElementAt(i); + signals.insertElementAt(o, i-1); + listSignal.setListData(signals); + listSignal.setSelectedIndex(i-1); + } + } + + public void downSignal() { + int i = listSignal.getSelectedIndex(); + if ((i!= -1) && (i != signals.size() - 1)) { + Object o = signals.elementAt(i); + signals.removeElementAt(i); + signals.insertElementAt(o, i+1); + listSignal.setListData(signals); + listSignal.setSelectedIndex(i+1); + } + } + + + public void closeDialog() { + attributesPar.removeAllElements(); + for(int i=0; i<attributes.size(); i++) { + attributesPar.addElement(attributes.elementAt(i)); + } + methodsPar.removeAllElements(); + for(int i=0; i<methods.size(); i++) { + methodsPar.addElement(methods.elementAt(i)); + } + signalsPar.removeAllElements(); + for(int i=0; i<signals.size(); i++) { + signalsPar.addElement(signals.elementAt(i)); + } + dispose(); + } + + public void cancelDialog() { + dispose(); + } + + public void valueChanged(ListSelectionEvent e) { + int i = listAttribute.getSelectedIndex() ; + if (i == -1) { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + identifierText.setText(""); + //initialValue.setText(""); + } else { + TAttribute a = (TAttribute)(attributes.elementAt(i)); + identifierText.setText(a.getId()); + initialValue.setText(a.getInitialValue()); + select(accessBox, a.getStringAccess(a.getAccess())); + if (a.getType() == TAttribute.OTHER) { + select(typeBox, a.getTypeOther()); + } else { + select(typeBox, a.getStringType(a.getType())); + } + removeButton.setEnabled(true); + if (i > 0) { + upButton.setEnabled(true); + } else { + upButton.setEnabled(false); + } + if (i != attributes.size() - 1) { + downButton.setEnabled(true); + } else { + downButton.setEnabled(false); + } + } + + i = listMethod.getSelectedIndex() ; + if (i == -1) { + removeMethodButton.setEnabled(false); + upMethodButton.setEnabled(false); + downMethodButton.setEnabled(false); + methodText.setText(""); + //initialValue.setText(""); + } else { + AvatarMethod am = (AvatarMethod)(methods.elementAt(i)); + methodText.setText(am.toString()); + removeMethodButton.setEnabled(true); + if (i > 0) { + upMethodButton.setEnabled(true); + } else { + upMethodButton.setEnabled(false); + } + if (i != methods.size() - 1) { + downMethodButton.setEnabled(true); + } else { + downMethodButton.setEnabled(false); + } + } + + i = listSignal.getSelectedIndex() ; + if (i == -1) { + removeSignalButton.setEnabled(false); + upSignalButton.setEnabled(false); + downSignalButton.setEnabled(false); + signalText.setText(""); + //initialValue.setText(""); + } else { + AvatarSignal as = (AvatarSignal)(signals.elementAt(i)); + signalText.setText(as.toBasicString()); + signalInOutBox.setSelectedIndex(as.getInOut()); + removeSignalButton.setEnabled(true); + if (i > 0) { + upSignalButton.setEnabled(true); + } else { + upSignalButton.setEnabled(false); + } + if (i != signals.size() - 1) { + downSignalButton.setEnabled(true); + } else { + downSignalButton.setEnabled(false); + } + } + } + + public void select(JComboBox jcb, String text) { + String s; + for(int i=0; i<jcb.getItemCount(); i++) { + s = (String)(jcb.getItemAt(i)); + //System.out.println("String found: *" + s + "* *" + text + "*"); + if (s.equals(text)) { + jcb.setSelectedIndex(i); + return; + } + } + } + +} diff --git a/src/ui/window/JDialogAvatarSignal.java b/src/ui/window/JDialogAvatarSignal.java new file mode 100755 index 0000000000000000000000000000000000000000..fe1b30841d210ff04c3d0322f617d0303e209da4 --- /dev/null +++ b/src/ui/window/JDialogAvatarSignal.java @@ -0,0 +1,227 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class JDialogAvatarSignal + * Dialog for managing several string components + * Creation: 12/04/2010 + * @version 1.0 12/04/2010 + * @author Ludovic APVRILLE + * @see + */ + +package ui.window; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +import ui.*; + +public class JDialogAvatarSignal extends javax.swing.JDialog implements ActionListener { + + private Vector signals, realSignals; + private Vector<String> showSignals; + private String currentSignal; + private boolean isOut; + + private boolean cancelled = false; + + private JPanel panel1; + + // Panel1 + private JComboBox listSignals; + private JButton selectSignal; + private JTextField signal; + + // Main Panel + private JButton closeButton; + private JButton cancelButton; + + + /** Creates new form */ + // arrayDelay: [0] -> minDelay ; [1] -> maxDelay + public JDialogAvatarSignal(Frame _f, String _title, String _currentSignal, Vector _signals, boolean _isOut) { + + super(_f, _title, true); + + signals = _signals; + currentSignal = _currentSignal; + isOut = _isOut; + + makeSignals(); + + initComponents(); + myInitComponents(); + pack(); + } + + private void makeSignals() { + showSignals = new Vector(); + realSignals = new Vector(); + AvatarSignal as; + String s; + + for(int i=0; i<signals.size(); i++) { + as = (AvatarSignal)(signals.get(i)); + if (((as.getInOut() == AvatarSignal.OUT) && (isOut)) || ((as.getInOut() == AvatarSignal.IN) && (!isOut))){ + //s = as.getUseDescription(); + showSignals.add(as.toString()); + realSignals.add(as); + } + } + } + + + private void myInitComponents() { + } + + private void initComponents() { + Container c = getContentPane(); + GridBagLayout gridbag0 = new GridBagLayout(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagConstraints c0 = new GridBagConstraints(); + GridBagConstraints c1 = new GridBagConstraints(); + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + c.setLayout(gridbag0); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + panel1 = new JPanel(); + panel1.setLayout(gridbag1); + + panel1.setBorder(new javax.swing.border.TitledBorder("Signals")); + + panel1.setPreferredSize(new Dimension(300, 150)); + + // first line panel1 + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 1; + listSignals = new JComboBox(showSignals); + panel1.add(new JLabel(" "), c1); + + // Combo box + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.fill = GridBagConstraints.HORIZONTAL; + c1.anchor = GridBagConstraints.CENTER; + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + listSignals = new JComboBox(showSignals); + panel1.add(listSignals, c1); + + + // Signal + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + selectSignal = new JButton("Select signal"); + panel1.add(selectSignal, c1); + selectSignal.setEnabled(showSignals.size() > 0); + selectSignal.addActionListener(this); + + // Text + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + signal = new JTextField(currentSignal, 30); + panel1.add(signal, c1); + //panel1.setEditable(true); + + // main panel; + c0.gridwidth = 1; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + + c.add(panel1, c0); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + closeButton = new JButton("Save and Close", IconManager.imgic25); + //closeButton.setPreferredSize(new Dimension(600, 50)); + closeButton.addActionListener(this); + c.add(closeButton, c0); + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + cancelButton = new JButton("Cancel", IconManager.imgic27); + cancelButton.addActionListener(this); + c.add(cancelButton, c0); + } + + public void actionPerformed(ActionEvent evt) { + //String command = evt.getActionCommand(); + + // Compare the action command to the known actions. + if (evt.getSource() == closeButton) { + closeDialog(); + } else if (evt.getSource() == cancelButton) { + cancelDialog(); + } else if (evt.getSource() == selectSignal) { + selectSignal(); + } + } + + public void selectSignal() { + int index = listSignals.getSelectedIndex(); + signal.setText(((AvatarSignal)realSignals.get(index)).getUseDescription()); + } + + public void closeDialog() { + dispose(); + } + + public String getSignal() { + return signal.getText(); + } + + public boolean hasValidString() { + return signal.getText().length() > 0; + } + + public boolean hasBeenCancelled() { + return cancelled; + } + + public void cancelDialog() { + cancelled = true; + dispose(); + } +} diff --git a/src/ui/window/JDialogAvatarTransition.java b/src/ui/window/JDialogAvatarTransition.java new file mode 100755 index 0000000000000000000000000000000000000000..aaf32f54fcb1cdb9aaa497b63d9dcc5f11071148 --- /dev/null +++ b/src/ui/window/JDialogAvatarTransition.java @@ -0,0 +1,247 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class JDialogAvatarTransition + * Dialog for managing transitions between states + * Creation: 12/04/2010 + * @version 1.0 12/04/2010 + * @author Ludovic APVRILLE + * @see + */ + +package ui.window; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +import ui.*; + +public class JDialogAvatarTransition extends javax.swing.JDialog implements ActionListener { + + private Vector<String> actions; + private String guard, afterMin, afterMax, computeMin, computeMax; + + private boolean cancelled = false; + + private JPanel panel1; + + // Panel1 + private JTextField guardT, afterMinT, afterMaxT, computeMinT, computeMaxT; + private JTextArea actionsT; + + // Main Panel + private JButton closeButton; + private JButton cancelButton; + + + /** Creates new form */ + // arrayDelay: [0] -> minDelay ; [1] -> maxDelay + public JDialogAvatarTransition(Frame _f, String _title, String _guard, String _afterMin, String _afterMax, String _computeMin, String _computeMax, Vector<String> _actions) { + + super(_f, _title, true); + + guard = _guard; + afterMin = _afterMin; + afterMax = _afterMax; + computeMin = _computeMin; + computeMax = _computeMax; + actions = _actions; + + initComponents(); + myInitComponents(); + pack(); + } + + + private void myInitComponents() { + } + + private void initComponents() { + Container c = getContentPane(); + GridBagLayout gridbag0 = new GridBagLayout(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagConstraints c0 = new GridBagConstraints(); + GridBagConstraints c1 = new GridBagConstraints(); + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + c.setLayout(gridbag0); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + panel1 = new JPanel(); + panel1.setLayout(gridbag1); + + panel1.setBorder(new javax.swing.border.TitledBorder("Signals")); + + panel1.setPreferredSize(new Dimension(300, 150)); + + // guard + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.gridwidth = 1; + c1.gridheight = 1; + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 1; + panel1.add(new JLabel("guard = "), c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + guardT = new JTextField(guard); + panel1.add(guardT, c1); + + // After + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + panel1.add(new JLabel("after ("), c1); + afterMinT = new JTextField(afterMin); + panel1.add(afterMinT, c1); + panel1.add(new JLabel(","), c1); + afterMaxT = new JTextField(afterMax); + panel1.add(afterMaxT, c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + panel1.add(new JLabel(")"), c1); + + // Compute + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + panel1.add(new JLabel("compute for ("), c1); + computeMinT = new JTextField(computeMin); + panel1.add(computeMinT, c1); + panel1.add(new JLabel(","), c1); + computeMaxT = new JTextField(computeMax); + panel1.add(computeMaxT, c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + panel1.add(new JLabel(")"), c1); + + + // actions + c1.gridheight = 10; + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + actionsT = new JTextArea(); + actionsT.setEditable(true); + actionsT.setMargin(new Insets(10, 10, 10, 10)); + actionsT.setTabSize(3); + actionsT.setFont(new Font("times", Font.PLAIN, 12)); + actionsT.setPreferredSize(new Dimension(300, 300)); + JScrollPane jsp = new JScrollPane(actionsT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + for(int i=0; i<actions.size(); i++) { + actionsT.append(actions.get(i) + "\n"); + } + panel1.add(jsp, c1); + + // main panel; + c0.gridwidth = 1; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + + c.add(panel1, c0); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + closeButton = new JButton("Save and Close", IconManager.imgic25); + //closeButton.setPreferredSize(new Dimension(600, 50)); + closeButton.addActionListener(this); + c.add(closeButton, c0); + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + cancelButton = new JButton("Cancel", IconManager.imgic27); + cancelButton.addActionListener(this); + c.add(cancelButton, c0); + } + + public void actionPerformed(ActionEvent evt) { + //String command = evt.getActionCommand(); + + // Compare the action command to the known actions. + if (evt.getSource() == closeButton) { + closeDialog(); + } else if (evt.getSource() == cancelButton) { + cancelDialog(); + } + } + + public void closeDialog() { + actions.removeAllElements(); + String[] act = actionsT.getText().split("\n"); + for(int i=0; i<act.length; i++) { + if (act[0].length() > 0) { + actions.add(act[i]); + } + } + dispose(); + } + + /*public String getActions() { + return signal.getText(); + }*/ + + public String getGuard() { + return guardT.getText(); + } + + public String getAfterMin() { + return afterMinT.getText(); + } + + public String getAfterMax() { + return afterMaxT.getText(); + } + + public String getComputeMin() { + return computeMinT.getText(); + } + + public String getComputeMax() { + return computeMaxT.getText(); + } + + public boolean hasBeenCancelled() { + return cancelled; + } + + public void cancelDialog() { + cancelled = true; + dispose(); + } +} diff --git a/src/ui/window/JDialogSignalAssociation.java b/src/ui/window/JDialogSignalAssociation.java new file mode 100644 index 0000000000000000000000000000000000000000..d1a49e70e8129d3e2b383a44d8628d4317f01398 --- /dev/null +++ b/src/ui/window/JDialogSignalAssociation.java @@ -0,0 +1,386 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class JDialogSignalAssociation + * Dialog for managing associations between signals (AVATAR profile) + * Creation: 09/04/2010 + * @version 1.0 09/04/2010 + * @author Ludovic APVRILLE + * @see + */ + +package ui.window; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import ui.*; +import ui.avatarbd.*; +import myutil.*; + + +public class JDialogSignalAssociation extends javax.swing.JDialog implements ActionListener, ListSelectionListener { + private Vector signalAssociation, localSignalAssociations; + private AvatarBDBlock block1, block2; + private Vector available1, available2; + private AvatarBDPortConnector connector; + + private JPanel panel1, panel2; + + private boolean cancelled = false; + + // Panel1 + private JComboBox signalsBlock1, signalsBlock2; + private JButton addButton; + + //Panel2 + private JList listSignals; + private JButton upButton; + private JButton downButton; + private JButton removeButton; + + // Main Panel + private JButton closeButton; + private JButton cancelButton; + + /** Creates new form */ + public JDialogSignalAssociation(Frame _f, AvatarBDBlock _block1, AvatarBDBlock _block2, Vector _signalAssociation, AvatarBDPortConnector _connector, String _title) { + super(_f, _title, true); + block1 = _block1; + block2 = _block2; + connector = _connector; + signalAssociation = _signalAssociation; + localSignalAssociations = new Vector(); + localSignalAssociations.addAll(signalAssociation); + + // Available signals + available1 = block1.getListOfAvailableSignals(); + available2 = block2.getListOfAvailableSignals(); + + initComponents(); + myInitComponents(); + pack(); + } + + private void myInitComponents() { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + makeComboBoxes(); + } + + private void initComponents() { + Container c = getContentPane(); + GridBagLayout gridbag0 = new GridBagLayout(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagLayout gridbag2 = new GridBagLayout(); + GridBagConstraints c0 = new GridBagConstraints(); + GridBagConstraints c1 = new GridBagConstraints(); + GridBagConstraints c2 = new GridBagConstraints(); + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + c.setLayout(gridbag0); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + panel1 = new JPanel(); + panel1.setLayout(gridbag1); + panel1.setBorder(new javax.swing.border.TitledBorder("Adding signals")); + panel1.setPreferredSize(new Dimension(400, 250)); + + panel2 = new JPanel(); + panel2.setLayout(gridbag2); + panel2.setBorder(new javax.swing.border.TitledBorder("Managing Signals")); + panel2.setPreferredSize(new Dimension(300, 250)); + + // first line panel1 + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 3; + panel1.add(new JLabel(" "), c1); + + // second line panel1 + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.anchor = GridBagConstraints.CENTER; + c1.fill = GridBagConstraints.HORIZONTAL; + c1.anchor = GridBagConstraints.CENTER; + + signalsBlock1 = new JComboBox(); + signalsBlock1.addActionListener(this); + panel1.add(signalsBlock1, c1); + c1.gridwidth = 1; + panel1.add(new JLabel(" = "), c1); + + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + signalsBlock2 = new JComboBox(); + signalsBlock2.addActionListener(this); + panel1.add(signalsBlock2, c1); + + // third line panel1 + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 3; + panel1.add(new JLabel(" "), c1); + + // fourth line panel1 + c1.gridheight = 1; + c1.fill = GridBagConstraints.HORIZONTAL; + addButton = new JButton("Add Signals"); + addButton.addActionListener(this); + panel1.add(addButton, c1); + + // 1st line panel2 + listSignals = new JList(localSignalAssociations); + listSignals.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listSignals.addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(listSignals); + scrollPane.setSize(300, 250); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + c2.fill = GridBagConstraints.BOTH; + c2.gridheight = 5; + c2.weighty = 10.0; + c2.weightx = 10.0; + panel2.add(scrollPane, c2); + + // 2nd line panel2 + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.fill = GridBagConstraints.BOTH; + c2.gridheight = 1; + panel2.add(new JLabel(""), c2); + + // third line panel2 + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + c2.fill = GridBagConstraints.HORIZONTAL; + upButton = new JButton("Up"); + upButton.addActionListener(this); + panel2.add(upButton, c2); + + downButton = new JButton("Down"); + downButton.addActionListener(this); + panel2.add(downButton, c2); + + removeButton = new JButton("Remove signals"); + removeButton.addActionListener(this); + panel2.add(removeButton, c2); + + // main panel; + c0.gridwidth = 1; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + + c.add(panel1, c0); + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + c.add(panel2, c0); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + closeButton = new JButton("Save and Close", IconManager.imgic25); + //closeButton.setPreferredSize(new Dimension(600, 50)); + closeButton.addActionListener(this); + c.add(closeButton, c0); + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + cancelButton = new JButton("Cancel", IconManager.imgic27); + cancelButton.addActionListener(this); + c.add(cancelButton, c0); + } + + public void actionPerformed(ActionEvent evt) { + //String command = evt.getActionCommand(); + + // Compare the action command to the known actions. + if (evt.getSource() == closeButton) { + closeDialog(); + } else if (evt.getSource() == addButton) { + addSignals(); + } else if (evt.getSource() == cancelButton) { + cancelDialog(); + } else if (evt.getSource() == removeButton) { + removeSignals(); + } else if (evt.getSource() == downButton) { + downSignals(); + } else if (evt.getSource() == upButton) { + upSignals(); + } else if (evt.getSource() == signalsBlock1) { + updateAddButton(); + } else if (evt.getSource() == signalsBlock2) { + updateAddButton(); + } + } + + private void updateAddButton() { + TraceManager.addDev("updateAddButton"); + int i1 = signalsBlock1.getSelectedIndex(); + int i2 = signalsBlock2.getSelectedIndex(); + + + if ((i1 > -1) && (i2 > -1)) { + AvatarSignal as1 = (AvatarSignal)(available1.elementAt(i1)); + AvatarSignal as2 = (AvatarSignal)(available2.elementAt(i2)); + + addButton.setEnabled(as1.isCompatibleWith(as2)); + } + } + + private void makeComboBoxes() { + signalsBlock1.removeAllItems(); + signalsBlock2.removeAllItems(); + + int i; + AvatarSignal as; + + for(i=0; i<available1.size(); i++) { + as = (AvatarSignal)(available1.elementAt(i)); + signalsBlock1.addItem(as.toString()); + } + + for(i=0; i<available2.size(); i++) { + as = (AvatarSignal)(available2.elementAt(i)); + signalsBlock2.addItem(as.toString()); + } + } + + public void addSignals() { + int i1 = signalsBlock1.getSelectedIndex(); + int i2 = signalsBlock2.getSelectedIndex(); + + + if ((i1 > -1) && (i2 > -1)) { + AvatarSignal as1 = (AvatarSignal)(available1.elementAt(i1)); + AvatarSignal as2 = (AvatarSignal)(available2.elementAt(i2)); + + String s = connector.makeSignalAssociation(block1, as1, block2, as2); + localSignalAssociations.add(s); + available1.removeElementAt(i1); + available2.removeElementAt(i2); + makeComboBoxes(); + listSignals.setListData(localSignalAssociations); + } + } + + public void removeSignals() { + int i = listSignals.getSelectedIndex() ; + if (i!= -1) { + String s = (String)(localSignalAssociations.get(i)); + localSignalAssociations.removeElementAt(i); + listSignals.setListData(localSignalAssociations); + String sig1 = connector.getFirstSignalOfSignalAssociation(s); + String sig2 = connector.getSecondSignalOfSignalAssociation(s); + TraceManager.addDev("sig1"+ sig1); + TraceManager.addDev("sig2"+ sig2); + AvatarSignal as1 = block1.getSignalNameBySignalDef(sig1); + AvatarSignal as2 = block2.getSignalNameBySignalDef(sig2); + + if ((as1 != null) && (as2 != null)) { + available1.add(as1); + available2.add(as2); + makeComboBoxes(); + } + } + } + + public void downSignals() { + int i = listSignals.getSelectedIndex(); + if ((i!= -1) && (i != localSignalAssociations.size() - 1)) { + Object o = localSignalAssociations.elementAt(i); + localSignalAssociations.removeElementAt(i); + localSignalAssociations.insertElementAt(o, i+1); + listSignals.setListData(localSignalAssociations); + listSignals.setSelectedIndex(i+1); + } + } + + public void upSignals() { + int i = listSignals.getSelectedIndex(); + if (i > 0) { + Object o = localSignalAssociations.elementAt(i); + localSignalAssociations.removeElementAt(i); + localSignalAssociations.insertElementAt(o, i-1); + listSignals.setListData(localSignalAssociations); + listSignals.setSelectedIndex(i-1); + } + } + + + public void closeDialog() { + signalAssociation.removeAllElements(); + signalAssociation.addAll(localSignalAssociations); + dispose(); + } + + public void cancelDialog() { + cancelled = true; + dispose(); + } + + public boolean hasBeenCancelled() { + return cancelled; + } + + public void valueChanged(ListSelectionEvent e) { + int i = listSignals.getSelectedIndex() ; + if (i == -1) { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + } else { + removeButton.setEnabled(true); + if (i > 0) { + upButton.setEnabled(true); + } else { + upButton.setEnabled(false); + } + if (i != localSignalAssociations.size() - 1) { + downButton.setEnabled(true); + } else { + downButton.setEnabled(false); + } + } + } + +}