diff --git a/src/main/java/avatartranslator/AvatarAMSInterface.java b/src/main/java/avatartranslator/AvatarAMSInterface.java new file mode 100644 index 0000000000000000000000000000000000000000..28e0eb5dd9db836be68104579193c975d988c4eb --- /dev/null +++ b/src/main/java/avatartranslator/AvatarAMSInterface.java @@ -0,0 +1,595 @@ +/* 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. + */ + +package avatartranslator; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + + +/** + * Class AvatarBlock + * Creation: 20/05/2010 + * @version 1.1 01/07/2014 + * @author Ludovic APVRILLE, Raja GATGOUT + */ +public class AvatarAMSInterface extends AvatarElement implements AvatarStateMachineOwner { + + private AvatarAMSInterface father; + private List<AvatarAttribute> attributes; + private List<AvatarMethod> methods; + private List<AvatarSignal> signals; + private AvatarStateMachine asm; + private AvatarSpecification avspec; + + private String globalCode; + + + public AvatarAMSInterface(String _name, AvatarSpecification _avspec, Object _referenceObject) { + super(_name, _referenceObject); + this.avspec = _avspec; + + attributes = new LinkedList<AvatarAttribute>(); + methods = new LinkedList<AvatarMethod>(); + signals = new LinkedList<AvatarSignal>(); + asm = new AvatarStateMachine(this, "statemachineofblock__" + _name, _referenceObject); + } + + + // For code generation + public void addGlobalCode(String _code) { + if (_code == null) { + return; + } + if (globalCode == null) { + globalCode = _code; + return; + } + globalCode += _code + "\n"; + } + + public String getGlobalCode() { + if (globalCode == null) { + return ""; + } + return globalCode; + } + + + // Relation with parent block + public void setFather(AvatarAMSInterface _father) { + father = _father; + } + + public AvatarAMSInterface getFather() { + return father; + } + + public AvatarStateMachine getStateMachine() { + return asm; + } + + /*public void addAttribute(AvatarAttribute _attribute) { + attributes.add(_attribute); + }*/ + + public void addMethod(AvatarMethod _method) { + methods.add(_method); + } + + public void addSignal(AvatarSignal _signal) { + signals.add(_signal); + } + + public List<AvatarAttribute> getAttributes() { + return attributes; + } + + public List<AvatarMethod> getMethods() { + return methods; + } + + + public List<AvatarSignal> getSignals() { + return signals ; + } + + public AvatarSignal getSignalByName(String _name) { + for(AvatarSignal sig: signals) { + if (sig.getName().compareTo(_name) == 0) { + return sig; + } + } + + if (father != null) { + return father.getSignalByName(_name); + } + + return null; + } + + public int getNbOfASMGraphicalElements() { + if (asm == null) { + return 0; + } + + return asm.getNbOfASMGraphicalElements(); + } + + public AvatarSpecification getAvatarSpecification () { + return this.avspec; + } + + public void addAttribute(AvatarAttribute _aa) { + if (getAvatarAttributeWithName(_aa.getName()) == null) { + attributes.add(_aa); + } + } + + public void addIntAttributeIfApplicable(String _name) { + if (getAvatarAttributeWithName(_name) == null) { + AvatarAttribute aa = new AvatarAttribute(_name, AvatarType.INTEGER, this, null); + attributes.add(aa); + } + } + + public String toString() { + //Thread.currentThread().dumpStack(); + StringBuffer sb = new StringBuffer("block:" + getName() + " ID=" + getID() + " \n"); + if (getFather() != null) { + sb.append(" subblock of: " + getFather().getName() + " ID=" + getFather().getID()+ "\n"); + } else { + sb.append(" top level block\n"); + } + for(AvatarAttribute attribute: attributes) { + sb.append(" attribute: " + attribute.toString() + " ID=" + attribute.getID() + "\n"); + } + for(AvatarMethod method: methods) { + sb.append(" method: " + method.toString() + " ID=" + method.getID() + "\n"); + } + for(AvatarSignal signal: signals) { + sb.append(" signal: " + signal.toString() + " ID=" + signal.getID() + "\n"); + } + if (asm != null) { + sb.append(asm.toString()); + } else { + sb.append("No state machine"); + } + + return sb.toString(); + } + + public String toShortString() { + //Thread.currentThread().dumpStack(); + StringBuffer sb = new StringBuffer("block:" + getName() + " ID=" + getID() + " \n"); + if (getFather() != null) { + sb.append(" subblock of: " + getFather().getName() + " ID=" + getFather().getID()+ "\n"); + } else { + sb.append(" top level block\n"); + } + for(AvatarAttribute attribute: attributes) { + sb.append(" attribute: " + attribute.toString() + " ID=" + attribute.getID() + "\n"); + } + for(AvatarMethod method: methods) { + sb.append(" method: " + method.toString() + " ID=" + method.getID() + "\n"); + } + for(AvatarSignal signal: signals) { + sb.append(" signal: " + signal.toString() + " ID=" + signal.getID() + "\n"); + } + + + return sb.toString(); + } + + public int attributeNb() { + return attributes.size(); + } + + public int stateNb() { + return asm.stateNb(); + } + + public AvatarState getState(int index) { + return asm.getState(index); + } + + public AvatarAttribute getAttribute(int _index) { + return attributes.get(_index); + } + + public boolean setAttributeValue(int _index, String _value) { + AvatarAttribute aa = attributes.get(_index); + if (aa == null) { + return false; + } + aa.setInitialValue(_value); + return true; + } + + public int getIndexOfAvatarAttributeWithName(String _name) { + int cpt = 0; + for(AvatarAttribute attribute: attributes) { + if (attribute.getName().compareTo(_name)== 0) { + return cpt; + } + cpt ++; + } + return -1; + } + + /** + * Look for an attribute with the provided name. + * + * @param _name + * The name of the attribute to look for. + * + * @return The attribute if found, or null otherwise + */ + public AvatarAttribute getAvatarAttributeWithName(String _name) { + for(AvatarAttribute attribute: attributes) { + if (attribute.getName().compareTo(_name)== 0) { + return attribute; + } + } + return null; + } + + public AvatarMethod getAvatarMethodWithName(String _name) { + for(AvatarMethod method: methods) { + if (method.getName().compareTo(_name)== 0) { + return method; + } + } + + if (getFather() != null) { + return getFather().getAvatarMethodWithName(_name); + } + + return null; + } + + public AvatarAttribute getNTypeOfMethod(String methodName, int indexOfAttribute) { + AvatarMethod am = getAvatarMethodWithName(methodName); + if (am == null) { + return null; + } + + return am.getListOfAttributes().get(indexOfAttribute); + } + + public AvatarAMSInterface getAMSInterfaceOfMethodWithName(String _name) { + for(AvatarMethod method: methods) { + if (method.getName().compareTo(_name)== 0) { + return this; + } + } + + if (getFather() != null) { + return getFather().getAMSInterfaceOfMethodWithName(_name); + } + + return null; + } + + public AvatarSignal getAvatarSignalWithName(String _name) { + for(AvatarSignal signal: signals) { + if (signal.getName().compareTo(_name)== 0) { + return signal; + } + } + + if (getFather() != null) { + return getFather().getAvatarSignalWithName(_name); + } + + return null; + } + + public static boolean isAValidMethodCall (AvatarStateMachineOwner owner, String _s) { + int i; + + //TraceManager.addDev("****** method=" + _s); + String all = _s; + + int indexeq = _s.indexOf('='); + + if (indexeq != -1) { + _s = _s.substring(indexeq + 1, _s.length()).trim(); + //TraceManager.addDev("****** cut method: " + _s); + } + + int index0 = _s.indexOf("("); + int index1 = _s.indexOf(")"); + if ((index0 == -1) || (index1 == -1) || (index1 < index0)) { + //TraceManager.addDev("No parenthesis"); + return false; + } + + String method = _s.substring(0, index0); + + AvatarMethod am = owner.getAvatarMethodWithName(method); + if (am == null) { + //TraceManager.addDev("Method not found"); + return false; + } + + String params = _s.substring(index0+1, index1).trim(); + //TraceManager.addDev("params=" + params); + if (params.length() == 0) { + return am.getListOfAttributes().size() == 0; + } + //TraceManager.addDev("params=" + params); + String [] actions = params.split(","); + if (am.getListOfAttributes().size() != actions.length) { + return false; + } + + AvatarAttribute aa; + for(i=0; i<actions.length; i++) { + //TraceManager.addDev("params=" + params + " actions=" + actions[i]); + // Must check tha validity of this action + + if (am.getListOfAttributes().get(i).isInt()) { + if (AvatarSyntaxChecker.isAValidIntExpr(null, owner, actions[i].trim()) < 0) { + return false; + } + } else { + // Assume it is a bool attribute + if (AvatarSyntaxChecker.isAValidBoolExpr(null, owner, actions[i].trim()) < 0) { + return false; + } + } + + /*aa = getAvatarAttributeWithName(actions[i].trim()); + if (aa == null) { + //TraceManager.addDev("Failed for attribute " + actions[i]); + return false; + }*/ + } + + // Checking for return attributes + if (indexeq != -1) { + //TraceManager.addDev("Checking for return params"); + String retparams = all.substring(0, indexeq).trim(); + //TraceManager.addDev("Retparam=" + retparams); + + // multiple params + if (retparams.length()>0) { + if (retparams.charAt(0) == '(') { + if (retparams.charAt(retparams.length()-1) != ')') { + //TraceManager.addDev("Bad format for return params: " + retparams); + return false; + } + + retparams = retparams.substring(1, retparams.length()-1).trim(); + actions = retparams.split(","); + if (am.getListOfReturnAttributes().size() != actions.length) { + return false; + } + + for(i=0; i<actions.length; i++) { + //TraceManager.addDev("params=" + retparams + " actions=" + actions[i]); + aa = owner.getAvatarAttributeWithName(actions[i].trim()); + if (aa == null) { + //TraceManager.addDev("Failed for attribute " + actions[i]); + return false; + } + } + + } else { + // Only one param. + aa = owner.getAvatarAttributeWithName(retparams); + if (aa == null) { + //TraceManager.addDev("Failed for return attribute " + retparams); + return false; + } + + if (am.getListOfReturnAttributes().size() != 1) { + //TraceManager.addDev("Wrong number of return parameters in :" + retparams); + return false; + } + } + + } + } + //TraceManager.addDev("Ok for method " + _s); + + return true; + } + + public AvatarStateMachineElement getStateMachineElementFromReferenceObject(Object _o) { + return asm.getStateMachineElementFromReferenceObject(_o); + } + + public boolean containsStateMachineElementWithReferenceObject(Object _o) { + AvatarStateMachineElement asme = asm.getStateMachineElementFromReferenceObject(_o); + return (asme != null); + } + + public AvatarAttribute addIntegerAttribute(String _name) { + AvatarAttribute aa; + int cpt; + + for(cpt=0; cpt<50000; cpt++) { + aa = getAvatarAttributeWithName(_name + cpt); + if (aa == null) { + break; + } + } + + aa = new AvatarAttribute(_name+cpt, AvatarType.INTEGER, this, getReferenceObject()); + addAttribute(aa); + + return aa; + } + + public boolean hasARealBehaviour() { + if (asm == null) { + return false; + } + + AvatarStartState ass = asm.getStartState(); + if (ass == null) { + return false; + } + + AvatarStateMachineElement asme = ass.getNext(0); + + if (asme == null) { + return false; + } + + if (asme instanceof AvatarTransition) { + AvatarTransition at = (AvatarTransition)asme; + if (at.hasDelay() || at.hasCompute() || at.hasActions()) { + return true; + } + + if (at.getNext(0) instanceof AvatarStopState) { + return false; + } + } + + return true; + } + + public int getMaxNbOfParams() { + if (asm == null) { + return 0; + } + + int cpt = 0; + + for(AvatarStateMachineElement asme :asm.getListOfElements()) { + if (asme instanceof AvatarActionOnSignal) { + cpt = Math.max(cpt, ((AvatarActionOnSignal)asme).getNbOfValues()); + } + } + return cpt; + } + + public int getMaxNbOfMultipleBranches() { + if (asm == null) { + return 0; + } + + int cpt = 1; + + for(AvatarStateMachineElement asme :asm.getListOfElements()) { + if (asme instanceof AvatarState) { + cpt = Math.max(cpt, asme.nbOfNexts()); + } + } + return cpt; + } + + + public int getIndexOfStartState() { + if (asm == null) { + return -1; + } + + return asm.getIndexOfStartState(); + + } + + public int getIndexOfRealStartState() { + if (asm == null) { + return -1; + } + + int cpt = 0; + AvatarStateElement ase = asm.getStartState(); + + while((ase != null) && (cpt<50)) { + if (ase.getNexts().size() != 1) { + break; + } + + AvatarTransition at = (AvatarTransition)(ase.getNext(0)); + if (!(at.isEmpty())) { + break; + } + + if (ase.getNexts().size() != 1) { + break; + } + + AvatarStateMachineElement next = at.getNext(0); + if (!(next instanceof AvatarStateElement)) { + break; + } + + ase = (AvatarStateElement) next; + + cpt ++; + } + + if (ase != null) { + return asm.getIndexOfState(ase); + } + + return -1; + + } + + @Override + public AvatarAMSInterface advancedClone(AvatarSpecification avspec) { + AvatarAMSInterface av = new AvatarAMSInterface(this.getName(), this.getAvatarSpecification(), this.getReferenceObject()); + + cloneLinkToReferenceObjects(av); + + + //Attributes, methods and signals + for(AvatarAttribute aa: attributes) { + av.addAttribute(aa.advancedClone(av)); + } + for(AvatarMethod am: methods) { + av.addMethod(am.advancedClone(av)); + } + for(AvatarSignal as: signals) { + av.addSignal(as.advancedClone(av)); + } + + // global code + av.addGlobalCode(getGlobalCode()); + + return av; + } +} diff --git a/src/main/java/avatartranslator/AvatarInterfaceRelation.java b/src/main/java/avatartranslator/AvatarInterfaceRelation.java new file mode 100644 index 0000000000000000000000000000000000000000..6647c637f6bcec016b6d17b6752bb6c5afde0094 --- /dev/null +++ b/src/main/java/avatartranslator/AvatarInterfaceRelation.java @@ -0,0 +1,308 @@ +/* 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. + */ + + + + + +package avatartranslator; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Class AvatarInterfaceRelation + * synchronizatio in Avatar ... + * Creation: 20/05/2010 + * @version 1.0 20/05/2010 + * @author Ludovic APVRILLE + */ +public class AvatarInterfaceRelation extends AvatarElement { + + + public AvatarBlock block1; + public AvatarAMSInterface block2; + private List<AvatarSignal> signals1, signals2; + private boolean blocking, asynchronous, ams, isPrivate, isBroadcast, isLossy; + private int sizeOfFIFO; // -1 means infinite + public int id;//DG + + public AvatarInterfaceRelation(String _name, AvatarBlock _block1, AvatarAMSInterface _block2, Object _referenceObject) { + super(_name, _referenceObject); + signals1 = new LinkedList<AvatarSignal>(); + signals2 = new LinkedList<AvatarSignal>(); + block1 = _block1; + block2 = _block2; + blocking = false; + sizeOfFIFO = 1024; + asynchronous = false; + isBroadcast = false; + ams = false; + id = 0;//DG + } + + public void setId(int newid) {//DG + id=newid; + } + + public int getId() {//DG + return id; + } + + + public boolean containsSignal(AvatarSignal _as) { + return (signals1.contains(_as) || signals2.contains(_as)); + } + + public void setAsynchronous(boolean _b) { + asynchronous = _b; + } + + public void setAMS(boolean _b) { + ams = _b; + } + + public void setBlocking(boolean _b) { + blocking = _b; + } + + public void setPrivate(boolean _b) { + isPrivate = _b; + } + + public void setBroadcast(boolean _b) { + isBroadcast = _b; + } + + public void setLossy(boolean _b) { + isLossy = _b; + } + + public void setSizeOfFIFO(int _sizeOfFIFO) { + sizeOfFIFO = _sizeOfFIFO; + } + + public boolean isAsynchronous() { + return asynchronous; + } + + public boolean isAMS() { + return ams; + } + + public boolean isPrivate() { + return isPrivate; + } + + public boolean isBroadcast() { + return isBroadcast; + } + + public boolean isLossy() { + return isLossy; + } + + public int getSizeOfFIFO() { + return sizeOfFIFO; + } + + public boolean isBlocking() { + return blocking; + } + + + + public void addSignals(AvatarSignal _sig1, AvatarSignal _sig2) { + signals1.add(_sig1); + signals2.add(_sig2); + } + + public int nbOfSignals() { + return signals1.size(); + } + + public AvatarSignal getSignal1(int _index) { + return signals1.get(_index); + } + + public AvatarSignal getSignal2(int _index) { + return signals2.get(_index); + } + + public AvatarBlock getBlock1() { + return this.block1; + } + + public AvatarAMSInterface getBlock2() { + return this.block2; + } + + public AvatarSignal getInSignal(int _index) { + AvatarSignal sig1 = signals1.get(_index); + if (sig1.isIn()) { + return sig1; + } + + return getSignal2(_index); + } + + public AvatarAMSInterface getInBlock(int _index) { + AvatarSignal sig1 = signals1.get(_index); + if (sig1.isIn()) { + //return block1; + } + + return block2; + } + + public AvatarSignal getOutSignal(int _index) { + AvatarSignal sig1 = signals1.get(_index); + if (sig1.isOut()) { + return sig1; + } + + return getSignal2(_index); + } + + public AvatarAMSInterface getOutBlock(int _index) { + AvatarSignal sig1 = signals1.get(_index); + if (sig1.isOut()) { + //return block1; + } + + return block2; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + for(int i=0; i<signals1.size(); i++) { + if (i>0) { + sb.append(" ; "); + } + if ((signals1.get(i) == null) || (signals2.get(i) == null)) { + sb.append(block1.getName() + "." + "NULL" + "=" + block2.getName() + "." + "NULL"); + } else { + sb.append(block1.getName() + "." + signals1.get(i).getName() + "=" + block2.getName() + "." + signals2.get(i).getName()); + } + } + return sb.toString(); + } + + public String toStringIndex(int index) { + return block1.getName() + "." + signals1.get(index).getName() + " -> " + block2.getName() + "." + signals2.get(index).getName(); + } + + // Return index of signal. If not found, return -1 + public int hasSignal(AvatarSignal sig) { + int index1 = signals1.indexOf(sig); + int index2 = signals2.indexOf(sig); + return Math.max(index1, index2); + } + + public int getIndexOfSignal(AvatarSignal sig) { + int index1 = signals1.indexOf(sig); + if (index1 > -1) { + return index1; + } + return signals2.indexOf(sig); + } + + /*public void makeRobustness() { + LinkedList<AvatarSignal> signals1_tmp = new LinkedList<AvatarSignal>(); + LinkedList<AvatarSignal> signals2_tmp = new LinkedList<AvatarSignal>(); + AvatarSignal as1, as2, astmp; + for(int i=0; i<signals1.size(); i++) { + as1 = signals1.get(i); + as2 = signals2.get(i); + + if (as1.isOut()) { + astmp = as2; + as2 = as1; + as1 = astmp; + } + + signals1_tmp.add(as1); + astmp = new AvatarSignal(as1.getName() + "__in", AvatarSignal.IN, as1.getReferenceObject()); + astmp.setInOut(AvatarSignal.IN); + signals2_tmp.add(astmp); + + + astmp = new AvatarSignal(as2.getName() + "__out", AvatarSignal.OUT, as2.getReferenceObject()); + astmp.setInOut(AvatarSignal.OUT); + signals1_tmp.add(astmp); + signals2_tmp.add(as2); + } + + signals1 = signals1_tmp; + signals2 = signals2_tmp; + }*/ + + /* public AvatarInterfaceRelation advancedClone( Map<AvatarBlock, AvatarBlock> correspondenceBlocks) { + AvatarBlock b1, b2; + b1 = correspondenceBlocks.get(block1); + b2 = correspondenceBlocks.get(block2); + if ((b1 == null) || (b2 == null)) { + return null; + } + AvatarInterfaceRelation ar = new AvatarInterfaceRelation(getName(), b1, b2, getReferenceObject()); + ar.setAsynchronous(isAsynchronous()); + ar.setBlocking(isBlocking()); + ar.setPrivate(isPrivate()); + ar.setBroadcast(isBroadcast()); + ar.setLossy(isLossy()); + ar.setSizeOfFIFO(getSizeOfFIFO()); + + // Signals + for(int i=0; i<signals1.size(); i++) { + AvatarSignal s1 = getSignal1(i); + AvatarSignal s2 = getSignal2(i); + + AvatarSignal ns1 = b1.getSignalByName(s1.getName()); + AvatarSignal ns2 = b2.getSignalByName(s2.getName()); + if ((ns1 == null) || (ns2 == null)) { + continue; + } + ar.addSignals(ns1, ns2); + } + + cloneLinkToReferenceObjects(ar); + + return ar; + }*/ +} diff --git a/src/main/java/avatartranslator/AvatarSpecification.java b/src/main/java/avatartranslator/AvatarSpecification.java index 2c60c5ced5001c250912f64a2dc63425ec944fd7..3489db37c27fa2a9c127469bbbfcc11488d8b40c 100644 --- a/src/main/java/avatartranslator/AvatarSpecification.java +++ b/src/main/java/avatartranslator/AvatarSpecification.java @@ -59,6 +59,8 @@ public class AvatarSpecification extends AvatarElement { private List<AvatarBlock> blocks; private List<AvatarRelation> relations; + private List<AvatarInterfaceRelation> irelations; + private List<AvatarAMSInterface> interfaces; /** * The list of all library functions that can be called. @@ -82,6 +84,7 @@ public class AvatarSpecification extends AvatarElement { public AvatarSpecification(String _name, Object _referenceObject) { super(_name, _referenceObject); blocks = new LinkedList<AvatarBlock>(); + interfaces = new LinkedList<AvatarAMSInterface>(); relations = new LinkedList<AvatarRelation>(); //broadcast = new AvatarBroadcast("Broadcast", _referenceObject); pragmas = new LinkedList<AvatarPragma>(); @@ -141,6 +144,10 @@ public class AvatarSpecification extends AvatarElement { return blocks; } + public List<AvatarAMSInterface> getListOfInterfaces() { + return interfaces; + } + public List<AvatarRelation> getRelations() { return relations; } @@ -195,10 +202,18 @@ public class AvatarSpecification extends AvatarElement { blocks.add(_block); } + public void addInterface(AvatarAMSInterface _interface) { + interfaces.add(_interface); + } + public void addRelation(AvatarRelation _relation) { relations.add(_relation); } + public void addInterfaceRelation(AvatarInterfaceRelation _irelation) { + irelations.add(_irelation); + } + /*public void addBroadcastSignal(AvatarSignal _as) { if (!broadcast.containsSignal(_as)) { broadcast.addSignal(_as); @@ -279,6 +294,16 @@ public class AvatarSpecification extends AvatarElement { return null; } + public AvatarAMSInterface getAMSInterfaceWithName(String _name) { + for(AvatarAMSInterface interf: interfaces) { + if (interf.getName().compareTo(_name)== 0) { + return interf; + } + } + + return null; + } + public AvatarConstant getAvatarConstantWithName(String _name) { for(AvatarConstant constant: constants) { if (constant.getName().compareTo(_name)== 0) { diff --git a/src/main/java/ui/ActionPerformer.java b/src/main/java/ui/ActionPerformer.java index f993d18878a6375ba7d869c53efb182be00d9e31..fd19ff8c94725d86ee5156f92cb3626c96a184db 100644 --- a/src/main/java/ui/ActionPerformer.java +++ b/src/main/java/ui/ActionPerformer.java @@ -346,6 +346,7 @@ public class ActionPerformer { // AVATAR BD } else if (command.equals(mgui.actions[TGUIAction.ABD_BLOCK].getActionCommand())) { + } else if (command.equals(mgui.actions[TGUIAction.AMS_INTERFACE].getActionCommand())) { mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.AVATARBD_BLOCK); } else if (command.equals(mgui.actions[TGUIAction.ABD_CRYPTOBLOCK].getActionCommand())) { mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.AVATARBD_CRYPTOBLOCK); diff --git a/src/main/java/ui/AvatarDesignPanelTranslator.java b/src/main/java/ui/AvatarDesignPanelTranslator.java index 3b9429948d3836417b05d4c7cdc1997754eaa62d..e83083d0b399f762724bfa8cbefce79d8dfb9172 100644 --- a/src/main/java/ui/AvatarDesignPanelTranslator.java +++ b/src/main/java/ui/AvatarDesignPanelTranslator.java @@ -89,11 +89,14 @@ public class AvatarDesignPanelTranslator { public AvatarSpecification generateAvatarSpecification(List<AvatarBDStateMachineOwner> _blocks) { List<AvatarBDBlock> blocks = new LinkedList<AvatarBDBlock>(); + List<AvatarBDInterface> interfaces = new LinkedList<AvatarBDInterface>(); List<AvatarBDLibraryFunction> libraryFunctions = new LinkedList<AvatarBDLibraryFunction>(); for (AvatarBDStateMachineOwner owner : _blocks) if (owner instanceof AvatarBDBlock) blocks.add((AvatarBDBlock) owner); + else if (owner instanceof AvatarBDInterface) + interfaces.add((AvatarBDInterface) owner); else libraryFunctions.add((AvatarBDLibraryFunction) owner); @@ -109,7 +112,9 @@ public class AvatarDesignPanelTranslator { nameTypeMap = new HashMap<String, String>(); createLibraryFunctions(as, libraryFunctions); createBlocks(as, blocks); + createInterfaces(as, interfaces); createRelationsBetweenBlocks(as, blocks); + createRelationsBetweenBlocksAndInterfaces(as, blocks, interfaces); makeBlockStateMachines(as); createPragmas(as, blocks); @@ -670,6 +675,10 @@ public class AvatarDesignPanelTranslator { _ab.addAttribute(this.createRegularAttribute(_ab, _a, _preName)); } + private void addRegularAttributeInterface(AvatarAMSInterface _ai, TAttribute _a, String _preName) { + _ai.addAttribute(this.createRegularAttribute(_ai, _a, _preName)); + } + private void createLibraryFunctions(AvatarSpecification _as, List<AvatarBDLibraryFunction> _libraryFunctions) { for (AvatarBDLibraryFunction libraryFunction : _libraryFunctions) { AvatarLibraryFunction alf = new AvatarLibraryFunction(libraryFunction.getFunctionName(), _as, libraryFunction); @@ -869,6 +878,92 @@ public class AvatarDesignPanelTranslator { } } + //ajoute DG 28.02. + + private void createInterfaces(AvatarSpecification _as, List<AvatarBDInterface> _interfaces) { + for (AvatarBDInterface interf : _interfaces) { + //for (AvatarBDInterface interf : _as.getListOfInterfaces()) { + AvatarAMSInterface ai = new AvatarAMSInterface(interf.getInterfaceName(), _as, interf); + _as.addInterface(ai); + listE.addCor(ai, interf); + interf.setAVATARID(ai.getID()); + + // Create attributes + for (TAttribute a : interf.getAttributeList()) { + if (a.getType() == TAttribute.INTEGER) { + addRegularAttributeInterface(ai, a, ""); + } else if (a.getType() == TAttribute.NATURAL) { + addRegularAttributeInterface(ai, a, ""); + } else if (a.getType() == TAttribute.BOOLEAN) { + addRegularAttributeInterface(ai, a, ""); + } else if (a.getType() == TAttribute.TIMER) { + addRegularAttributeInterface(ai, a, ""); + } else { + // other + // TraceManager.addDev(" -> Other type found: " + a.getTypeOther()); + List<TAttribute> types = adp.getAvatarBDPanel().getAttributesOfDataType(a.getTypeOther()); + if (types == null) { + UICheckingError ce = new UICheckingError(CheckingError.STRUCTURE_ERROR, "Unknown data type: " + a.getTypeOther() + " used in " + ai.getName()); + ce.setTDiagramPanel(adp.getAvatarBDPanel()); + addCheckingError(ce); + return; + } else { + if (types.size() == 0) { + UICheckingError ce = new UICheckingError(CheckingError.STRUCTURE_ERROR, "Data type definition must contain at least one attribute: " + ai.getName()); + ce.setTDiagramPanel(adp.getAvatarBDPanel()); + addCheckingError(ce); + } else { + nameTypeMap.put(interf.getInterfaceName() + "." + a.getId(), a.getTypeOther()); + typeAttributesMap.put(a.getTypeOther(), types); + for (TAttribute type : types) + addRegularAttributeInterface(ai, type, a.getId() + "__"); + } + } + + } + } + + // Create methods + for (ui.AvatarMethod uiam : interf.getMethodList()) { + avatartranslator.AvatarMethod atam = new avatartranslator.AvatarMethod(uiam.getId(), uiam); + atam.setImplementationProvided(uiam.isImplementationProvided()); + ai.addMethod(atam); + makeParameters(ai, atam, uiam); + makeReturnParameters(ai, interf, atam, uiam); + } + + // Create signals + for (ui.AvatarSignal uias : interf.getSignalList()) { + avatartranslator.AvatarSignal atas; + if (uias.getInOut() == AvatarSignal.IN) { + atas = new avatartranslator.AvatarSignal(uias.getId(), avatartranslator.AvatarSignal.IN, uias); + } else { + atas = new avatartranslator.AvatarSignal(uias.getId(), avatartranslator.AvatarSignal.OUT, uias); + } + ai.addSignal(atas); + makeParameters(ai, atas, uias); + } + + // Put global code + ai.addGlobalCode(interf.getGlobalCode()); + + } + + // Make interface hierarchy + for (AvatarAMSInterface interf : _as.getListOfInterfaces()) { + TGComponent tgc1 = listE.getTG(interf); + if ((tgc1 != null) && (tgc1.getFather() != null)) { + TGComponent tgc2 = tgc1.getFather(); + AvatarAMSInterface ai = listE.getAvatarAMSInterface(tgc2); + if (ai != null) { + interf.setFather(ai); + } + } + } + } + + //fin ajoute DG + private void makeBlockStateMachines(AvatarSpecification _as) { // Make state machine of blocks for (AvatarBlock block : _as.getListOfBlocks()) @@ -2102,6 +2197,89 @@ public class AvatarDesignPanelTranslator { return null; } + // ajoute DG + + private void createRelationsBetweenBlocksAndInterfaces(AvatarSpecification _as, List<AvatarBDBlock> _blocks, List<AvatarBDInterface> _interfaces) { + adp.getAvatarBDPanel().updateAllSignalsOnConnectors(); + Iterator<TGComponent> iterator = adp.getAvatarBDPanel().getComponentList().listIterator(); + + TGComponent tgc; + AvatarBDPortConnector port; + AvatarBDBlock block; + AvatarBDInterface interf; + List<String> l1, l2; + int i; + String name1, name2; + AvatarInterfaceRelation r; + AvatarBlock b; + AvatarAMSInterface interf2; + avatartranslator.AvatarSignal atas1, atas2; + + while (iterator.hasNext()) { + tgc = iterator.next(); + + if (tgc instanceof AvatarBDPortConnector) { + port = (AvatarBDPortConnector) tgc; + + block = port.getAvatarBDBlock1(); + interf = port.getAvatarBDInterface2(); + + //TraceManager.addDev("Searching block #1 with name " + block1.getBlockName() + " and block #2 with name " + block2.getBlockName()); + b = _as.getBlockWithName(block.getBlockName()); + interf2 = _as.getAMSInterfaceWithName(interf.getInterfaceName()); + + if ((b != null) && (interf2 != null)) { + //TraceManager.addDev("B1 and B2 are not null"); + r = new AvatarInterfaceRelation("relation", b, interf2, tgc); + // Signals of l1 + l1 = port.getListOfSignalsOrigin(); + l2 = port.getListOfSignalsDestination(); + + for (i = 0; i < l1.size(); i++) { + name1 = AvatarSignal.getSignalNameFromFullSignalString(l1.get(i)); + name2 = AvatarSignal.getSignalNameFromFullSignalString(l2.get(i)); + //TraceManager.addDev("Searching signal with name " + name1 + " in block " + b1.getName()); + atas1 = b.getAvatarSignalWithName(name1); + atas2 = interf2.getAvatarSignalWithName(name2); + + if ((atas1 != null) && (atas2 != null)) { + if (atas1.isCompatibleWith(atas2)) { + //TraceManager.addDev("Signals " + atas1 + " and " + atas2 + " are compatible"); + r.addSignals(atas1, atas2); + } else { + //TraceManager.addDev("Signals " + atas1 + " and " + atas2 + " are NOT compatible"); + UICheckingError ce = new UICheckingError(CheckingError.STRUCTURE_ERROR, "Wrong signal association betwen " + atas1 + " and " + atas2); + // TODO: adapt + // ce.setAvatarBlock(_ab); + ce.setTDiagramPanel(tgc.getTDiagramPanel()); + ce.setTGComponent(tgc); + addCheckingError(ce); + } + } else { + TraceManager.addDev("Null signals in AVATAR relation: " + name1 + " " + name2); + } + } + + // Attribute of the relation + r.setBlocking(port.isBlocking()); + r.setAsynchronous(port.isAsynchronous()); + r.setAMS(port.isAMS()); + r.setSizeOfFIFO(port.getSizeOfFIFO()); + r.setPrivate(port.isPrivate()); + r.setBroadcast(port.isBroadcast()); + r.setLossy(port.isLossy()); + + _as.addInterfaceRelation(r); + } else { + TraceManager.addDev("Null block b=" + b + " interface =" + interf2); + } + } + } + } + + + //fin ajoute DG + private void createRelationsBetweenBlocks(AvatarSpecification _as, List<AvatarBDBlock> _blocks) { adp.getAvatarBDPanel().updateAllSignalsOnConnectors(); Iterator<TGComponent> iterator = adp.getAvatarBDPanel().getComponentList().listIterator(); diff --git a/src/main/java/ui/ColorManager.java b/src/main/java/ui/ColorManager.java index 18f0b3e3e225f07a285b95023d531af1c1b21d79..64498851ed0b670367f59a892aeace60cd03aa1a 100644 --- a/src/main/java/ui/ColorManager.java +++ b/src/main/java/ui/ColorManager.java @@ -173,6 +173,7 @@ public class ColorManager { //public static final Color AVATAR_BLOCK = new Color(158, 218, 227); //public static final Color AVATAR_BLOCK = new Color(149, 193, 210); public static Color AVATAR_BLOCK = new Color(193, 218, 241); + public static Color AVATAR_INTERFACE = new Color(144, 201, 211); public static Color AVATAR_LIBRARYFUNCTION = new Color(237, 208, 14); //public static final Color AVATAR_DATATYPE = new Color(109, 193, 210); public static Color AVATAR_DATATYPE = new Color(156, 220, 162); diff --git a/src/main/java/ui/CorrespondanceTGElement.java b/src/main/java/ui/CorrespondanceTGElement.java index 04ad5d08d1180130e7f162c5d27786499f0a1855..f51454a2f46abc2ca1f00dfdb051801a27225542 100644 --- a/src/main/java/ui/CorrespondanceTGElement.java +++ b/src/main/java/ui/CorrespondanceTGElement.java @@ -43,6 +43,7 @@ package ui; import avatartranslator.AvatarBlock; +import avatartranslator.AvatarAMSInterface; import avatartranslator.AvatarLibraryFunction; import req.ebrdd.EBRDDComponent; import req.ebrdd.EBRDDGeneralComponent; @@ -217,6 +218,18 @@ public class CorrespondanceTGElement implements CorrespondanceElement<TGComponen return null; } + public AvatarAMSInterface getAvatarAMSInterface(TGComponent _tgc) { + int index = tg.indexOf(_tgc); + if ((index != -1) && (tg.size() > index)) { + Object o = data.elementAt(index); + if (o instanceof AvatarAMSInterface) { + return (AvatarAMSInterface)o; + } + return null; + } + return null; + } + public AvatarLibraryFunction getAvatarLibraryFunction (TGComponent _tgc) { int index = tg.indexOf (_tgc); if (index == -1) diff --git a/src/main/java/ui/TDiagramPanel.java b/src/main/java/ui/TDiagramPanel.java index 9dee959253df6a9e460c8762a252f192690b94b6..52417ab1b5a336b838b8ce4bceb440d4159cdebb 100644 --- a/src/main/java/ui/TDiagramPanel.java +++ b/src/main/java/ui/TDiagramPanel.java @@ -44,6 +44,7 @@ import ui.atd.ATDAttack; import ui.atd.ATDBlock; import ui.avatarad.AvatarADActivity; import ui.avatarbd.AvatarBDBlock; +import ui.avatarbd.AvatarBDInterface; import ui.avatarbd.AvatarBDPragma; import ui.avatarbd.AvatarBDDataType; import ui.avatarbd.AvatarBDLibraryFunction; @@ -2784,6 +2785,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { || (o instanceof ATDAttack && this.checkATDAttack((ATDAttack) o, name)) || (o instanceof FTDFault && this.checkFTDFault((FTDFault) o, name)) || (o instanceof AvatarBDBlock && this.checkAvatarBDBlock((AvatarBDBlock) o, name)) + || (o instanceof AvatarBDInterface && this.checkAvatarBDInterface((AvatarBDInterface) o, name)) || (o instanceof AvatarCDBlock && this.checkAvatarCDBlock((AvatarCDBlock) o, name)) || (o instanceof AvatarSMDState && this.checkAvatarSMDState((AvatarSMDState) o, name)) || (o instanceof AvatarADActivity && this.checkAvatarADActivity((AvatarADActivity) o, name)) @@ -2945,6 +2947,10 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { return false; } + public boolean checkAvatarBDInterface(AvatarBDInterface o, String name) { + return false; + } + public boolean checkAvatarCDBlock(AvatarCDBlock o, String name) { return false; } @@ -3246,6 +3252,28 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { }); } + //ajoute DG + + public String findAvatarBDInterfaceName(String name) { + return this.findGoodName(name, new NameChecker() { + public boolean checkAvatarBDInterface(AvatarBDInterface o, String name) { + if (o.getValue().equals(name)) + return true; + return o.hasInternalInterfaceWithName(name); + } + + public boolean checkAvatarBDLibraryFunction(AvatarBDLibraryFunction o, String name) { + return o.getFunctionName().equals(name); + } + + public boolean checkAvatarBDDataType(AvatarBDDataType o, String name) { + return o.getDataTypeName().equals(name); + } + }); + } + + // fin ajoute + public String findAvatarBDBlockName(String name) { return this.findGoodName(name, new NameChecker() { public boolean checkAvatarBDBlock(AvatarBDBlock o, String name) { diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java index 7fa46c0416fb1d046e64692d75a98143cf03b822..5d3fbccb61c3f76b440a82ce8ae3929cb4430fec 100644 --- a/src/main/java/ui/TGUIAction.java +++ b/src/main/java/ui/TGUIAction.java @@ -417,6 +417,7 @@ public class TGUIAction extends AbstractAction { // AVATAR Block Diagram public static final int ABD_BLOCK = 289; public static final int ABD_CRYPTOBLOCK = 332; + public static final int AMS_INTERFACE = 527; public static final int ABD_DATATYPE = 324; public static final int ABD_COMPOSITION_CONNECTOR = 290; public static final int ABD_PORT_CONNECTOR = 295; @@ -430,6 +431,8 @@ public class TGUIAction extends AbstractAction { 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 ASMD_SEND_AMSSIGNAL = 525; + public static final int ASMD_RECEIVE_AMSSIGNAL = 526; public static final int ASMD_LIBRARY_FUNCTION_CALL = 432; //public static final int ASMD_PARALLEL = 298; Issue #69 public static final int ASMD_STATE = 299; @@ -526,6 +529,8 @@ public class TGUIAction extends AbstractAction { public static final int AAD_ACTIVITY = 357; public static final int AAD_ACTION = 358; public static final int AAD_STOP_FLOW = 359; + public static final int AAD_ACCEPT_EVENTAMS_ACTION = 360; + public static final int AAD_SEND_SIGNALAMS_ACTION = 361; public static final int AAD_ACCEPT_EVENT_ACTION = 360; public static final int AAD_SEND_SIGNAL_ACTION = 361; public static final int AAD_PARTITION = 362; @@ -678,7 +683,7 @@ public class TGUIAction extends AbstractAction { public static final int MOVE_ENABLED = 463; public static final int FIRST_DIAGRAM = 464; public static final int ACT_GEN_LATENCY_GRAPH = 519; - public static final int NB_ACTION = 525; + public static final int NB_ACTION = 528; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -1308,6 +1313,7 @@ public class TGUIAction extends AbstractAction { // AVATAR Block Diagrams 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_CRYPTOBLOCK] = new TAction("abd-cryptoblock", "Add a crypto block", IconManager.imgic5000, IconManager.imgic5000, "Crypto block", "Add a SysML Crypto Block to the currently opened AVATAR Block Diagram", 0); + actions[AMS_INTERFACE] = new TAction("interface", "Add an AMS interface", IconManager.imgic5000, IconManager.imgic5000, "interface", "Add an AMS interface to the currently opened AVATAR Block Diagram", 0); actions[ABD_DATATYPE] = new TAction("abd-datatype", "Add a data type", IconManager.imgic5034, IconManager.imgic5034, "Data type", "Add a SysML Block representing a Data Type 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); @@ -1321,6 +1327,8 @@ public class TGUIAction extends AbstractAction { 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.imgic2014, IconManager.imgic2014, "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.imgic2016, IconManager.imgic2016, "Receive signal", "Add a receive signal operator to the currently opened AVATAR state machine diagram", 0); + actions[ASMD_SEND_AMSSIGNAL] = new TAction("add-ams-sendsignal", "Send signal", IconManager.imgic2015, IconManager.imgic2015, "Send signal", "Add an AMS send signal operator to the currently opened AVATAR state machine diagram", 0); + actions[ASMD_RECEIVE_AMSSIGNAL] = new TAction("add-asmd-receivesignal", "Receive signal", IconManager.imgic2017, IconManager.imgic2017, "Receive signal", "Add an AMS receive signal operator to the currently opened AVATAR state machine diagram", 0); // TODO: change icon actions[ASMD_LIBRARY_FUNCTION_CALL] = new TAction("add-asmd-libraryfunctioncall", "Library function call", IconManager.imgic2018, IconManager.imgic2018, "Library function call", "Add a library function call to the currently opened AVATAR state machine diagram", 0); //actions[ASMD_PARALLEL] = new TAction("add-asmd-parallel", "Parallel", IconManager.imgic206, IconManager.imgic206, "Parallel", "Add a parallel operator to the currently opened AVATAR state machine diagram", 0); diff --git a/src/main/java/ui/avatarad/AvatarADToolBar.java b/src/main/java/ui/avatarad/AvatarADToolBar.java index b75b010ef1f8a3899a603f155a41348e1f496379..266365bf1402e98cc60dc5e3750341987458e800 100644 --- a/src/main/java/ui/avatarad/AvatarADToolBar.java +++ b/src/main/java/ui/avatarad/AvatarADToolBar.java @@ -133,8 +133,15 @@ public class AvatarADToolBar extends TToolBar { button.addMouseListener(mgui.mouseHandler); this.addSeparator(); + + button = this.add(mgui.actions[TGUIAction.AAD_SEND_SIGNALAMS_ACTION]); + button.addMouseListener(mgui.mouseHandler); + button = this.add(mgui.actions[TGUIAction.AAD_ACCEPT_EVENTAMS_ACTION]); + button.addMouseListener(mgui.mouseHandler); + this.addSeparator(); + button = this.add(mgui.actions[TGUIAction.AAD_ACTION]); button.addMouseListener(mgui.mouseHandler); diff --git a/src/main/java/ui/avatarbd/AvatarBDInterface.java b/src/main/java/ui/avatarbd/AvatarBDInterface.java new file mode 100644 index 0000000000000000000000000000000000000000..c1fdd35199a8cfafae4bcbbbdbba64f2a162e976 --- /dev/null +++ b/src/main/java/ui/avatarbd/AvatarBDInterface.java @@ -0,0 +1,1756 @@ +/* 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. + */ + +package ui.avatarbd; + +import myutil.Conversion; +import myutil.GenericTree; +import myutil.GraphicLib; +import myutil.TraceManager; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import proverifspec.ProVerifResultTrace; +import proverifspec.ProVerifResultTraceStep; +import ui.*; +import ui.avatarsmd.AvatarSMDPanel; +import ui.interactivesimulation.JFrameSimulationSDPanel; +import ui.util.IconManager; +//import ui.window.JDialogAvatarBlock; +import ui.window.JDialogAvatarInterface; +import ui.window.JDialogIDAndStereotype; + +import javax.swing.*; +import java.awt.*; +import java.io.*; +import java.util.*; +import java.util.List; + +/** + * Class AvatarBDInterface + * Node. To be used in AVATAR Block Diagrams + * Creation: 06/04/2010 + * + * @author Ludovic APVRILLE + * @version 1.1 06/04/2010 + */ +public class AvatarBDInterface extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent, GenericTree, AvatarBDStateMachineOwner, WithAttributes { + + private static String GLOBAL_CODE_INFO = "(block code)"; + +// private int textY1 = 3; +// private int textX = 7; + + private static String stereotype = "block"; +// private static String stereotypeCrypto = "cryptoblock"; + + protected static List<String> BLOCK_TYPE_STR = new ArrayList<String>(Arrays.asList("block", "cryptoblock")); + protected static List<Color> BLOCK_TYPE_COLOR = new ArrayList<Color>(Arrays.asList(ColorManager.AVATAR_BLOCK, ColorManager.AVATAR_BLOCK)); + private int typeStereotype = 0; // <<block>> by default + + private int maxFontSize = 12; + // private int minFontSize = 4; + private int currentFontSize = -1; + + private int limitName = -1; + private int limitAttr = -1; + private int limitMethod = -1; + private int limitSignal = -1; + + // Icon + private int iconSize = 15; + + + // TAttribute, AvatarMethod, AvatarSignal + protected List<TAttribute> myAttributes; + protected List<AvatarMethod> myMethods; + protected List<AvatarSignal> mySignals; + protected String[] globalCode; + + protected Map<TAttribute, ProVerifResultTrace> attrTraceMap = new HashMap<TAttribute, ProVerifResultTrace>(); + protected Map<TAttribute, Integer> attrLocMap = new HashMap<TAttribute, Integer>(); + + public String oldValue; + + public AvatarBDInterface(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 = 250; + height = 200; + minWidth = 5; + minHeight = 2; + textY = 3; + textX = 7; + initScaling(250, 200); + + + nbConnectingPoint = 16; + connectingPoint = new TGConnectingPoint[16]; + + connectingPoint[0] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.0); + connectingPoint[1] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.5, 0.0); + connectingPoint[2] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.0); + connectingPoint[3] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.5); + connectingPoint[4] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.5); + connectingPoint[5] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 1.0); + connectingPoint[6] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.5, 1.0); + connectingPoint[7] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 1.0); + + connectingPoint[8] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.25, 0.0); + connectingPoint[9] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.75, 0.0); + connectingPoint[10] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.25); + connectingPoint[11] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.25); + connectingPoint[12] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.0, 0.75); + connectingPoint[13] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 1.0, 0.75); + connectingPoint[14] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.25, 1.0); + connectingPoint[15] = new AvatarBDConnectingPoint(this, 0, 0, true, true, 0.75, 1.0); + + addTGConnectingPointsComment(); + + nbInternalTGComponent = 0; + + moveable = true; + editable = true; + multieditable = true; + removable = true; + userResizable = true; + + name = tdp.findAvatarBDInterfaceName("Interface"); + setValue(name); + oldValue = value; + + oldScaleFactor = tdp.getZoom(); + currentFontSize = (int) (maxFontSize * oldScaleFactor); + + //myImageIcon = IconManager.imgic700; + myImageIcon = IconManager.imgic700; + + this.myAttributes = new LinkedList<TAttribute>(); + this.myMethods = new LinkedList<AvatarMethod>(); + this.mySignals = new LinkedList<AvatarSignal>(); + + actionOnAdd(); + } + + @Override + public void internalDrawing(Graphics graph) { + Font font = graph.getFont(); + this.internalDrawingAux(graph); + graph.setFont(font); + } + + public void addProVerifTrace(TAttribute attr, ProVerifResultTrace trace) { + attrTraceMap.put(attr, trace); + } + + public void setSignalsAsNonAttached() { + for (AvatarSignal mySig : mySignals) mySig.attachedToARelation = false; + } + + public void addSignal(AvatarSignal sig) { + this.mySignals.add(sig); + } + + /** + * Issue #31: text disappearance + * + * @param graph + */ + private void internalDrawingAux(Graphics graph) { + //Rectangle + Color c = graph.getColor(); + graph.drawRect(this.x, this.y, this.width, this.height); + graph.setColor(BLOCK_TYPE_COLOR.get(typeStereotype)); + graph.fillRect(this.x + 1, this.y + 1, this.width - 1, this.height - 1); + graph.setColor(c); + + //string + int h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY; + + if (h + graph.getFontMetrics().getDescent() + textY >= this.height) + return; + Font f = graph.getFont(); + + // limits +// this.limitName = -1; +// this.limitAttr = -1; +// this.limitMethod = -1; +// this.limitSignal = y + height; +// +// // h retains the coordinate along X where an element was last drawn +// int h = 0; +// +// int textY1 = (int) (this.textY1 * this.tdp.getZoom()); +// int textX = (int) (this.textX * this.tdp.getZoom()); +// +// // Draw icon +// this.iconIsDrawn = this.width > IconManager.iconSize + 2 * textX && height > IconManager.iconSize + 2 * textX; +// if (this.iconIsDrawn) { +// graph.drawImage(IconManager.img5100, this.x + this.width - IconManager.iconSize - textX, this.y + textX, null); +// } +// +// +// Font font = graph.getFont(); + + + String ster = BLOCK_TYPE_STR.get(typeStereotype); + int w = graph.getFontMetrics().stringWidth(ster); + h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY; + graph.setFont(f.deriveFont(Font.BOLD)); + if (w + 2 * textX < this.width) + drawSingleString(graph, ster, getCenter(graph, ster), this.y + h); + h += graph.getFontMetrics().getHeight() + textY; + w = graph.getFontMetrics().stringWidth(value); + graph.setFont(f.deriveFont(Font.PLAIN)); + if (w + 2 * textX < this.width) + drawSingleString(graph, this.value, getCenter(graph, value), this.y + h); + + //draw separator + this.limitName = this.y + h; + //TraceManager.addDev("limitName=" + limitName); + + if (h + textY >= this.height) + return; + h += graph.getFontMetrics().getDescent() + textY; + //if (canTextGoInTheBox(graph, h, "line", 0)); + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); + h += textY; + + //Attributes + if (!this.tdp.areAttributesVisible()) + return; + int attributeFontSize = f.getSize() * 5 / 6; + graph.setFont(f.deriveFont((float) attributeFontSize)); + int step = graph.getFontMetrics().getHeight(); + h += textY; + limitAttr = limitName; + for (TAttribute attr : this.myAttributes) { + h += step; + if (h >= this.height - textX) { + this.limitAttr = this.y + this.height; + return; + } + + // Get the string for this parameter + String attrString = attr.toAvatarString(); + w = graph.getFontMetrics().stringWidth(attrString); + attrLocMap.put(attr, this.y + h); + if (w + 2 * textX < this.width) { + //graph.drawString(attrString, this.x + textX, this.y + h); + drawSingleString(graph, attrString, this.x + textX, this.y + h); + this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h); + } + } + + //ICON + drawImageWithCheck(graph, IconManager.img5100, this.x + this.width - scale(IconManager.iconSize) - textX, this.y + textX); + + + // Remember the end of attributes + this.limitAttr = this.y + h; + if (h + textY >= this.height) + return; + + h += graph.getFontMetrics().getDescent(); + + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); + h += textY; + + // Methods + limitMethod = limitAttr; + limitSignal = limitAttr; + + for (AvatarMethod method : this.myMethods) { + h += step; + if (h >= this.height - textX) { + this.limitMethod = this.y + this.height; + this.limitSignal = limitMethod; + return; + } + + // Get the string for this method + String methodString = "- " + method.toString(); + + w = graph.getFontMetrics().stringWidth(methodString); + if (w + 2 * textX < this.width) + drawSingleString(graph, methodString, this.x + textX, this.y + h); + else { + // If we can't, try to draw with "..." instead + int stringLength; + for (stringLength = methodString.length() - 1; stringLength >= 0; stringLength--) { + String abbrev = methodString.substring(0, stringLength) + "..."; + w = graph.getFontMetrics().stringWidth(abbrev); + if (w + 2 * textX < this.width) { + drawSingleString(graph, abbrev, this.x + textX, this.y + h); + break; + } + } + + if (stringLength < 0) + // skip method + h -= step; + } + } + + h += graph.getFontMetrics().getDescent() + textY; + + if (h + textY >= this.height) { + limitMethod = this.y + this.height; + limitSignal = this.y + this.height; + return; + } + + // Remember limit of methods + this.limitMethod = this.y + h; + this.limitSignal = this.y + h; + + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); + h += textY; + + // Signals + for (AvatarSignal signal : this.mySignals) { + h += step; + if (h >= this.height - textX) { + limitSignal = this.height + this.y; + return; + } + + String signalString = "~ " + signal.toString(); + w = graph.getFontMetrics().stringWidth(signalString); + if (w + 2 * textX < this.width) { +// graph.drawString(signalString, this.x + textX, this.y + h); + drawSingleString(graph, signalString, this.x + textX, this.y + h); + drawInfoAttachement(signal, graph, x, y + h); + + } else { + // If we can't, try to draw with "..." instead + int stringLength; + for (stringLength = signalString.length() - 1; stringLength >= 0; stringLength--) { + String abbrev = signalString.substring(0, stringLength) + "..."; + w = graph.getFontMetrics().stringWidth(abbrev); + if (w + 2 * textX < this.width) { + //graph.drawString(abbrev, this.x + textX, this.y + h); + drawSingleString(graph, abbrev, this.x + textX, this.y + h); + drawInfoAttachement(signal, graph, x, y + h); + break; + } + } + + if (stringLength < 0) + // skip signal + h -= step; + } + } + + h += graph.getFontMetrics().getDescent() + textY; + + if (h + textY >= this.height) { + limitSignal = this.height + this.y; + return; + } + + // Global code + limitSignal = this.y + h; + if (hasGlobalCode()) { + if (h + textY + step >= this.height - textX) + return; + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); + h += textY + step; + + w = graph.getFontMetrics().stringWidth(GLOBAL_CODE_INFO); + if (w + 2 * textX < this.width) + drawSingleString(graph, GLOBAL_CODE_INFO, this.x + (this.width - w) / 2, this.y + h); +// graph.drawString(GLOBAL_CODE_INFO, this.x + (this.width - w) / 2, this.y + h); + } else { + limitSignal = height; + } + + } + +// private void internalDrawingAu(Graphics graph) { +// +// //TraceManager.addDev("Interface drawing aux = " + this); +// +// // Draw outer rectangle (for border) +// Color c = graph.getColor(); +// graph.drawRect(this.x, this.y, this.width, this.height); +// +// // Draw inner rectangle +// //graph.setColor(ColorManager.AVATAR_BLOCK); +// +// //TraceManager.addDev("type stereotype=" + typeStereotype); +// +// graph.setColor(BLOCK_TYPE_COLOR.get(typeStereotype)); +// graph.fillRect(this.x + 1, this.y + 1, this.width - 1, this.height - 1); +// graph.setColor(c); +// +// // limits +// this.limitName = -1; +// this.limitAttr = -1; +// this.limitMethod = -1; +// this.limitSignal = y + height; +// +// // h retains the coordinate along X where an element was last drawn +// int h = 0; +// +//// int textY1 = (int) (this.textY1 * this.tdp.getZoom()); +//// int textX = (int) (this.textX * this.tdp.getZoom()); +// +// // Draw icon +// this.iconIsDrawn = this.width > IconManager.iconSize + 2 * textX && height > IconManager.iconSize + 2 * textX; +// if (this.iconIsDrawn) +// graph.drawImage(scale(IconManager.img5100), this.x + this.width - scale(IconManager.iconSize) - textX, this.y + textX, null); +// +// +// Font font = graph.getFont(); +// +// +// String ster = BLOCK_TYPE_STR.get(typeStereotype); +// +// //TraceManager.addDev("My ster=" + ster); +// +// if (this.rescaled && !this.tdp.isScaled()) { +// this.rescaled = false; +// // Must set the font size... +// // Incrementally find the biggest font not greater than max_font size +// // If font is less than min_font, no text is displayed +// +// // This is the maximum font size possible +// int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom()))); +// font = font.deriveFont((float) maxCurrentFontSize); +// +// // Try to decrease font size until we get below the minimum +// while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) { +// // Compute width of name of the function +// int w0 = graph.getFontMetrics(font).stringWidth(this.value); +// // Compute width of string stereotype +// int w1 = graph.getFontMetrics(font).stringWidth(ster); +// +// // if one of the two width is small enough use this font size +// if (Math.min(w0, w1) < this.width - (2 * this.textX)) +// break; +// +// // Decrease font size +// maxCurrentFontSize--; +// // Scale the font +// font = font.deriveFont((float) maxCurrentFontSize); +// } +// +// // Box is too damn small +// if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) { +// maxCurrentFontSize++; +// // Scale the font +// font = font.deriveFont((float) maxCurrentFontSize); +// } +// +// // Use this font +// graph.setFont(font); +// this.currentFontSize = maxCurrentFontSize; +// } else +// font = font.deriveFont(this.currentFontSize); +// +// graph.setFont(font.deriveFont(Font.BOLD)); +// h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY; +// +// if (h + graph.getFontMetrics().getDescent() + textY >= this.height) +// return; +// +// // Write stereotype if small enough +// int w = graph.getFontMetrics().stringWidth(ster); +// if (w + 2 * textX < this.width) +//// graph.drawString(ster, this.x + (this.width - w) / 2, this.y + h); +// drawSingleString(graph, ster, this.x + (this.width - w) / 2, this.y + h); +// else { +// // try to draw with "..." instead +// if (!this.isCryptoBlock()) +// ster = stereotype; +// else +// ster = stereotypeCrypto; +// +// for (int stringLength = ster.length() - 1; stringLength >= 0; stringLength--) { +// String abbrev = "<<" + ster.substring(0, stringLength) + "...>>"; +// w = graph.getFontMetrics().stringWidth(abbrev); +// if (w + 2 * textX < this.width) { +//// graph.drawString(abbrev, this.x + (this.width - w) / 2, this.y + h); +// drawSingleString(graph, abbrev, this.x + (this.width - w) / 2, this.y + h); +// break; +// } +// } +// } +// +// // Write value if small enough +// graph.setFont(font); +// h += graph.getFontMetrics().getHeight() + textY; +// if (h + graph.getFontMetrics().getDescent() + textY >= this.height) +// return; +// +// w = graph.getFontMetrics().stringWidth(this.value); +// if (w + 2 * textX < this.width) +// graph.drawString(this.value, this.x + (this.width - w) / 2, this.y + h); +// else { +// // try to draw with "..." instead +// for (int stringLength = this.value.length() - 1; stringLength >= 0; stringLength--) { +// String abbrev = this.value.substring(0, stringLength) + "..."; +// w = graph.getFontMetrics().stringWidth(abbrev); +// if (w + 2 * textX < this.width) { +// graph.drawString(abbrev, this.x + (this.width - w) / 2, this.y + h); +// break; +// } +// } +// } +// +// h += graph.getFontMetrics().getDescent() + textY; +// +// // Update lower bound of text +// this.limitName = this.y + h; +// +// if (h + textY >= this.height) +// return; +// +// // Draw separator +// graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); +// +// if (!this.tdp.areAttributesVisible()) +// return; +// +// // Set font size +// // int attributeFontSize = Math.min (12, this.currentFontSize - 2); +// int attributeFontSize = this.currentFontSize * 5 / 6; +// graph.setFont(font.deriveFont((float) attributeFontSize)); +// int step = graph.getFontMetrics().getHeight(); +// +// h += textY; +// +// // Attributes +// limitAttr = limitName; +// for (TAttribute attr : this.myAttributes) { +// h += step; +// if (h >= this.height - textX) { +// this.limitAttr = this.y + this.height; +// return; +// } +// +// // Get the string for this parameter +// String attrString = attr.toAvatarString(); +// +// // Try to draw it +// w = graph.getFontMetrics().stringWidth(attrString); +// +// attrLocMap.put(attr,this.y+h); +// if (w + 2 * textX < this.width) { +// graph.drawString(attrString, this.x + textX, this.y + h); +// this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h); +// } else { +// // If we can't, try to draw with "..." instead +// int stringLength; +// for (stringLength = attrString.length() - 1; stringLength >= 0; stringLength--) { +// String abbrev = attrString.substring(0, stringLength) + "..."; +// w = graph.getFontMetrics().stringWidth(abbrev); +// if (w + 2 * textX < this.width) { +// graph.drawString(abbrev, this.x + textX, this.y + h); +// this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h); +// break; +// } +// } +// +// if (stringLength < 0) +// // skip attribute +// h -= step; +// } +// } +// +// h += graph.getFontMetrics().getDescent() + textY; +// +// // Remember the end of attributes +// this.limitAttr = this.y + h; +// +// if (h + textY >= this.height) +// return; +// +// graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); +// h += textY; +// +// // Methods +// limitMethod = limitAttr; +// limitSignal = limitAttr; +// for (AvatarMethod method : this.myMethods) { +// h += step; +// if (h >= this.height - textX) { +// this.limitMethod = this.y + this.height; +// this.limitSignal = limitMethod; +// return; +// } +// +// // Get the string for this method +// String methodString = "- " + method.toString(); +// +// w = graph.getFontMetrics().stringWidth(methodString); +// if (w + 2 * textX < this.width) +// graph.drawString(methodString, this.x + textX, this.y + h); +// else { +// // If we can't, try to draw with "..." instead +// int stringLength; +// for (stringLength = methodString.length() - 1; stringLength >= 0; stringLength--) { +// String abbrev = methodString.substring(0, stringLength) + "..."; +// w = graph.getFontMetrics().stringWidth(abbrev); +// if (w + 2 * textX < this.width) { +// graph.drawString(abbrev, this.x + textX, this.y + h); +// break; +// } +// } +// +// if (stringLength < 0) +// // skip method +// h -= step; +// } +// } +// +// h += graph.getFontMetrics().getDescent() + textY; +// +// if (h + textY >= this.height) { +// limitMethod = this.y + this.height; +// limitSignal = this.y + this.height; +// return; +// } +// +// // Remember limit of methods +// this.limitMethod = this.y + h; +// this.limitSignal = this.y + h; +// +// graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); +// h += textY; +// +// // Signals +// for (AvatarSignal signal : this.mySignals) { +// h += step; +// if (h >= this.height - textX) { +// limitSignal = this.height + this.y; +// return; +// } +// +// String signalString = "~ " + signal.toString(); +// w = graph.getFontMetrics().stringWidth(signalString); +// if (w + 2 * textX < this.width) { +// graph.drawString(signalString, this.x + textX, this.y + h); +// drawInfoAttachement(signal, graph, x, y + h); +// +// } else { +// // If we can't, try to draw with "..." instead +// int stringLength; +// for (stringLength = signalString.length() - 1; stringLength >= 0; stringLength--) { +// String abbrev = signalString.substring(0, stringLength) + "..."; +// w = graph.getFontMetrics().stringWidth(abbrev); +// if (w + 2 * textX < this.width) { +// graph.drawString(abbrev, this.x + textX, this.y + h); +// drawInfoAttachement(signal, graph, x, y + h); +// +// +// break; +// } +// } +// +// if (stringLength < 0) +// // skip signal +// h -= step; +// } +// } +// +// h += graph.getFontMetrics().getDescent() + textY; +// +// if (h + textY >= this.height) { +// limitSignal = this.height + this.y; +// return; +// } +// +// // Global code +// limitSignal = this.y + h; +// if (hasGlobalCode()) { +// if (h + textY + step >= this.height - textX) +// return; +// graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); +// h += textY + step; +// +// w = graph.getFontMetrics().stringWidth(GLOBAL_CODE_INFO); +// if (w + 2 * textX < this.width) +// graph.drawString(GLOBAL_CODE_INFO, this.x + (this.width - w) / 2, this.y + h); +// } else { +// limitSignal = height; +// } +// } + + private void drawInfoAttachement(AvatarSignal _as, Graphics g, int _x, int _y) { + if (_as.attachedToARelation) { + return; + } + Color c = g.getColor(); + g.setColor(Color.RED); + int[] xA = new int[3]; + int[] yA = new int[3]; + //top of triangle + xA[0] = _x + 5; + yA[0] = _y - 7; + + // Right bottom point + xA[1] = _x + 2; + yA[1] = _y; + + // Left bottom point + xA[2] = _x + 8; + yA[2] = _y; + + g.fillPolygon(xA, yA, 3); + + g.setColor(c); + } + + public void showTrace(int y) { + + if (y < limitAttr) { + for (TAttribute attr : attrLocMap.keySet()) { + if (attrLocMap.get(attr) < y && y < attrLocMap.get(attr) + currentFontSize && attrTraceMap.get(attr) != null) { + PipedOutputStream pos = new PipedOutputStream(); + try { + PipedInputStream pis = new PipedInputStream(pos, 4096); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(pos)); + + JFrameSimulationSDPanel jfssdp = new JFrameSimulationSDPanel(null, tdp.getMGUI(), "Confidentiality " + attr.toString()); + jfssdp.setIconImage(IconManager.img8); + GraphicLib.centerOnParent(jfssdp, 600, 600); + jfssdp.setFileReference(new BufferedReader(new InputStreamReader(pis))); + jfssdp.setVisible(true); + //jfssdp.setModalExclusionType(ModalExclusionType + // .APPLICATION_EXCLUDE); + jfssdp.toFront(); + + // TraceManager.addDev("\n--- Trace ---"); + int i = 0; + for (ProVerifResultTraceStep step : attrTraceMap.get(attr).getTrace()) { + step.describeAsTMLSDTransaction(bw, i); + i++; + } + bw.close(); + } catch (IOException e) { + TraceManager.addDev("Error when writing trace step SD transaction"); + } finally { + try { + pos.close(); + } catch (IOException ignored) { + } + } + + } + } + } + } + + private void drawConfidentialityVerification(int confidentialityVerification, Graphics g, int _x, int _y) { + Color c = g.getColor(); + Color c1; + int xc = (int) (6 * tdp.getZoom()); + int yc = (int) (10 * tdp.getZoom()); + int lockwidth = (int) (9 * tdp.getZoom()); + int lockheight = (int) (7 * tdp.getZoom()); + int ovalwidth = (int) (6 * tdp.getZoom()); + int ovalheight = (int) (9 * tdp.getZoom()); + switch (confidentialityVerification) { + case TAttribute.CONFIDENTIALITY_OK: + c1 = Color.green; + break; + case TAttribute.CONFIDENTIALITY_KO: + c1 = Color.red; + break; + case TAttribute.COULD_NOT_VERIFY_CONFIDENTIALITY: + c1 = Color.orange; + break; + default: + return; + } + + g.drawOval(_x + xc, _y - yc, ovalwidth, ovalheight); + g.setColor(c1); + g.fillRect(_x + xc * 2 / 3, _y - yc * 2 / 3, lockwidth, lockheight); + g.setColor(c); + g.drawRect(_x + xc * 2 / 3, _y - yc * 2 / 3, lockwidth, lockheight); + + } + + @Override + public TGComponent isOnOnlyMe(int x1, int y1) { + if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) { + return this; + } + return null; + } + + public String getStereotype() { + return stereotype; + } + + public String getNodeName() { + return name; + } + + public String getFullyQualifiedName() { + String result = ""; + if (this.father != null && (this.father instanceof AvatarBDInterface)) { + result = ((AvatarBDInterface) this.father).getFullyQualifiedName() + "."; + } + result += this.value; + + return result; + } + + @Override + public boolean editOndoubleClick(JFrame frame, int _x, int _y) { + int textX = (int) (this.textX * this.tdp.getZoom()); + + if (GraphicLib.isInRectangle(_x, _y, x + width - iconSize - textX, y + textX, iconSize, iconSize)) { + tdp.getMouseManager().setSelection(-1, -1); + tdp.selectTab(getValue()); + return true; + } + + // On the name ? + //TraceManager.addDev("_y=" + _y + " limitName=" + limitName); + if ((limitName == -1) || _y < limitName) { + JDialogIDAndStereotype dialog = new JDialogIDAndStereotype(frame, "Setting Interface ID", + BLOCK_TYPE_STR.toArray(new String[0]), getValue + (), typeStereotype, BLOCK_TYPE_COLOR.toArray(new Color[0]), ColorManager.AVATAR_INTERFACE); + //dialog.setSize(400, 300); + GraphicLib.centerOnParent(dialog, 400, 300); + // dialog.show(); // blocked until dialog has been closed + oldValue = value; + dialog.setVisible(true); + + if (dialog.hasBeenCancelled()) { + return false; + } + + String s = dialog.getName(); + + if ((s != null) && (s.length() > 0)) { + //boolean b; + if (!s.equals(oldValue)) { + if (!TAttribute.isAValidId(s, false, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Interface: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + /* if (!tdp.isAvatarInterfaceNameUnique(s)) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Interface: the new name is already in use", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + }*/ + + setValue(s); + recalculateSize(); + + if (!(tdp.actionOnDoubleClick(this))) { + JOptionPane.showMessageDialog(frame, + "Could not change the name of the Interface: this name is already in use", + "Error", + JOptionPane.INFORMATION_MESSAGE); + setValue(oldValue); + return false; + } + + + } + + + // Setting stereotype + s = dialog.getStereotype().trim(); + + if (!TAttribute.isAValidId(s, false, false, false)) { + JOptionPane.showMessageDialog(frame, + "Could not use the new stereotype: the new stereotype name is not valid", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + int rgb = dialog.getColor(); + + //TraceManager.addDev("RGBColor:" + rgb + " vs default color:" + ColorManager.AVATAR_BLOCK.getRGB()); + + addStereotype(s, rgb); + + //TraceManager.addDev("My stereotype=" + BLOCK_TYPE_STR.get(typeStereotype) + " color=" + BLOCK_TYPE_COLOR.get(typeStereotype).getRGB()); + + + if (isCryptoBlock()) { + addCryptoElements(); + } else { + int tmpSter = typeStereotype; + removeCryptoElements(); + typeStereotype = tmpSter; + } + + + return true; + + } + + + return false; + } + + // And so -> attributes! + + int tab = 0; + + //TraceManager.addDev("limitAttr=" + limitAttr + " method=" + limitMethod + " limitSignal=" + limitSignal + " y=" + _y + " height=" + height); + + if (limitMethod == -1) { + limitMethod = limitAttr; + } + + if (limitSignal == -1) { + limitSignal = limitMethod; + } + + if (limitAttr == -1) { + tab = 0; + } else { + if (_y < limitAttr) { + tab = 0; + } else if (_y < limitMethod) { + tab = 1; + } else if (_y < limitSignal) { + tab = 2; + } else if (_y > limitSignal && hasGlobalCode()) { + tab = 3; + } else if (_y > limitSignal && !hasGlobalCode()) { + tab = 2; + } + } + + /*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 (this.mySignals.size() > 1) { + tab = 2; + } + }*/ + + String mainCode = null; + TDiagramPanel ttdp = getTDiagramPanel(); + if (ttdp instanceof AvatarBDPanel) { + mainCode = ((AvatarBDPanel) (ttdp)).getMainCode(); + } + JDialogAvatarInterface jdab = new JDialogAvatarInterface(this.myAttributes, this.myMethods, this.mySignals, null, frame, "Setting attributes of " + value, "Attribute", tab, globalCode, true, mainCode); + setJDialogOptions(jdab); +// jdab.setSize(650, 575); + GraphicLib.centerOnParent(jdab, 780, 700); + jdab.setVisible(true); // blocked until dialog has been closed + //makeValue(); + //if (oldValue.equals(value)) { + //return false; + //} + + if (!jdab.hasBeenCancelled()) { + globalCode = jdab.getGlobalCode(); + String tmp = jdab.getMainCode(); + if (tmp != null) { + ((AvatarBDPanel) (ttdp)).setMainCode(tmp); + } + } + + ((AvatarBDPanel) tdp).updateAllSignalsOnConnectors(); + rescaled = true; + return true; + } + + protected void setJDialogOptions(JDialogAvatarInterface _jdab) { + //jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC)); + _jdab.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE)); + //_jdab.addType(TAttribute.getStringType(TAttribute.NATURAL), true); + _jdab.addType(TAttribute.getStringAvatarType(TAttribute.BOOLEAN), true); + _jdab.addType(TAttribute.getStringAvatarType(TAttribute.INTEGER), true); + _jdab.addType(TAttribute.getStringType(TAttribute.TIMER), false); + + for (String s : tdp.getAllDataTypes()) { + _jdab.addType(s, false); + } + + _jdab.enableInitialValue(true); + _jdab.enableRTLOTOSKeyword(false); + _jdab.enableJavaKeyword(false); + _jdab.enableUPPAALKeyword(false); + } + + @Override + public int getType() { + return TGComponentManager.AVATARBD_BLOCK; + } + + @Override + public boolean acceptSwallowedTGComponent(TGComponent tgc) { + return tgc instanceof AvatarBDInterface || tgc instanceof AvatarBDLibraryFunction; + + } + + @Override + public boolean addSwallowedTGComponent(TGComponent tgc, int x, int y) { + boolean swallowed = false; + + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof SwallowTGComponent) { + if (tgcomponent[i].isOnMe(x, y) != null) { + swallowed = true; + ((SwallowTGComponent) tgcomponent[i]).addSwallowedTGComponent(tgc, x, y); + break; + } + } + } + + if (swallowed) { + return true; + } + + if (!acceptSwallowedTGComponent(tgc)) { + return false; + } + + // + // Choose its position + + // Make it an internal component + // It's one of my son + tgc.setFather(this); + tgc.setDrawingZone(true); + + //Set its coordinates + if (tgc instanceof AvatarBDInterface) { + //tgc.setCdRectangle((width/2) - tgc.getWidth(), (width/2), spacePt, height-spacePt); + // + tgc.resizeWithFather(); + //tgc.setCdRectangle(0, width - tgc.getWidth(), 0, height - tgc.getHeight()); + //tgc.setCd(x, y); + } else if (tgc instanceof AvatarBDLibraryFunction) + tgc.resizeWithFather(); + + // else unknown*/ + + //add it + addInternalComponent(tgc, 0); + + return true; + } + + @Override + public void removeSwallowedTGComponent(TGComponent 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 (((AvatarBDInterface) tgcomponent[i]).removeMyInternalComponent(tgc, false)) { + return true; + } + } + } + return false; + } + + @Override + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<blockType data=\""); + sb.append(BLOCK_TYPE_STR.get(typeStereotype)); + sb.append("\" color=\""); + sb.append(BLOCK_TYPE_COLOR.get(typeStereotype).getRGB()); + sb.append("\" />\n"); + sb.append("<CryptoBlock value=\"" + isCryptoBlock() + "\" />\n"); + for (TAttribute a : this.myAttributes) { + 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 (AvatarMethod am : this.myMethods) { + sb.append("<Method value=\""); + sb.append(am.toSaveString()); + sb.append("\" />\n"); + } + for (AvatarSignal as : this.mySignals) { + sb.append("<Signal value=\""); + sb.append(as.toString()); + sb.append("\" attached=\""); + sb.append(as.attachedToARelation); + sb.append("\" />\n"); + } + if (hasGlobalCode()) { + for (int i = 0; i < globalCode.length; i++) { + sb.append("<globalCode value=\""); + sb.append(GTURTLEModeling.transformString(globalCode[i])); + sb.append("\" />\n"); + } + } + sb.append("</extraparam>\n"); + return new String(sb); + } + + @Override + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { + + String s; + String tmpGlobalCode = ""; + + try { + NodeList nli; + Node n1, n2; + Element elt; + int access, type; + String typeOther; + String id, valueAtt; + String method; + String signal; + AvatarMethod am; + AvatarSignal as; + boolean implementation = false; + String crypt; + String attached; + //boolean mustAddCryptoFunctions = false; + + + // + // + + //TraceManager.addDev("LEP Begin Interface = " + this + " trace="); + //Thread.currentThread().dumpStack(); + + for (int i = 0; i < nl.getLength(); i++) { + n1 = nl.item(i); + // + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for (int j = 0; j < nli.getLength(); j++) { + n2 = nli.item(j); + // + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("CryptoBlock")) { + crypt = elt.getAttribute("value"); + if (crypt.compareTo("true") == 0) { + + } + } + if (elt.getTagName().equals("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, false)) && (TAttribute.isAValidInitialValue(type, valueAtt))) { + //TraceManager.addDev("Adding attribute " + id + " typeOther=" + typeOther); + if (type == TAttribute.NATURAL) { + type = TAttribute.INTEGER; + } + TAttribute ta = new TAttribute(access, id, valueAtt, type, typeOther); + ta.isAvatar = true; + this.myAttributes.add(ta); + } + } + if (elt.getTagName().equals("blockType")) { + // + s = elt.getAttribute("data"); + String tmp3 = elt.getAttribute("color"); + //TraceManager.addDev("stereotype=" + s + " color=" + tmp3); + int rgb = ColorManager.AVATAR_REQUIREMENT_TOP.getRGB(); + try { + rgb = Integer.decode(tmp3).intValue(); + } catch (Exception e) { + } + if (s.equals("null")) { + typeStereotype = 0; + } else { + try { + typeStereotype = Integer.decode(s).intValue(); // default stereo: old way + } catch (Exception e) { + addStereotype(s, rgb); + } + } + if (typeStereotype > (BLOCK_TYPE_STR.size() - 1)) { + typeStereotype = 0; + } + + } + if (elt.getTagName().equals("Method")) { + // + method = elt.getAttribute("value"); + + if (method.equals("null")) { + method = ""; + } + if (method.startsWith("$")) { + implementation = true; + method = method.substring(1, method.length()); + } else { + implementation = false; + } + + //TraceManager.addDev("Method = " + method + ". Starting with aencrypt?"); + if (method.startsWith("bool verifyMAC(")) { + typeStereotype = 1; + + //TraceManager.addDev("Add crypto methods"); + //addCryptoElements(); + } + + am = AvatarMethod.isAValidMethod(method); + if (am != null) { + //TraceManager.addDev("Setting to " + implementation + " the implementation of " + am); + am.setImplementationProvided(implementation); + //addMethodIfApplicable(am); + this.myMethods.add(am); + } + } + if (elt.getTagName().equals("Signal")) { + // + signal = elt.getAttribute("value"); + attached = elt.getAttribute("attached"); + + if (signal.equals("null")) { + signal = ""; + } + as = AvatarSignal.isAValidSignal(signal); + if (as != null) { + this.mySignals.add(as); + if (attached != null) { + as.attachedToARelation = (attached.compareTo("true") == 0); + } + } else { + TraceManager.addDev("Invalid signal:" + signal); + } + } + if (elt.getTagName().equals("globalCode")) { + // + s = elt.getAttribute("value"); + if (s.equals("null")) { + s = ""; + } + tmpGlobalCode += GTURTLEModeling.decodeString(s) + "\n"; + } + } + } + } + } + + } catch (Exception e) { + throw new MalformedModelingException(); + } + + + if (isCryptoBlock()) { + addCryptoElements(); + } + + if (tmpGlobalCode.trim().length() == 0) { + globalCode = null; + } else { + globalCode = Conversion.wrapText(tmpGlobalCode); + } + + //TraceManager.addDev("LEP End Block = " + this); + } + + public boolean addStereotype(String s, int rgb) { + //TraceManager.addDev("Adding stereotype for " + s + " with color " + rgb); + int index = -1; + String sLower = s.toLowerCase(); + for (int i = 0; i < BLOCK_TYPE_STR.size(); i++) { + if (BLOCK_TYPE_STR.get(i).toLowerCase().compareTo(sLower) == 0) { + index = i; + break; + } + } + + // Found stereotype + if (index != -1) { + //TraceManager.addDev("Found stereotype"); + typeStereotype = index; + if (index > 0) { + //TraceManager.addDev("Setting new color"); + BLOCK_TYPE_COLOR.set(index, new Color(rgb)); + } + return false; + + // Must add a new stereotype + } else { + //TraceManager.addDev("No stereotype found: adding" + s + " with color " + rgb); + BLOCK_TYPE_STR.add(s); + BLOCK_TYPE_COLOR.add(new Color(rgb)); + typeStereotype = BLOCK_TYPE_STR.size() - 1; + //TraceManager.addDev("Stereotype =" + BLOCK_TYPE_STR.get(typeStereotype) + " typestereotype=" + typeStereotype); + return true; + } + } + + public String getInterfaceName() { + return value; + } + + + + public boolean hasGlobalCode() { + if (globalCode == null) { + return false; + } + + if (globalCode.length == 0) { + return false; + } + + String tmp; + for (int i = 0; i < globalCode.length; i++) { + tmp = globalCode[i].trim(); + if (tmp.length() > 0) { + if (!(tmp.equals("\n"))) { + return true; + } + } + } + + return false; + } + + public String getGlobalCode() { + if (globalCode == null) { + return null; + } + String ret = ""; + for (int i = 0; i < globalCode.length; i++) { + ret += globalCode[i] + "\n"; + } + return ret; + } + + @Override + public void hasBeenResized() { + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof AvatarBDInterface) { + tgcomponent[i].resizeWithFather(); + } else if (tgcomponent[i] instanceof AvatarBDLibraryFunction) { + tgcomponent[i].resizeWithFather(); + } + } + + if (getFather() != null) { + resizeWithFather(); + } + + } + + @Override + public void resizeWithFather() { + if ((father != null) && (father instanceof AvatarBDInterface)) { + // Too large to fit in the father? -> resize it! + resizeToFatherSize(); + + setCdRectangle(0, father.getWidth() - getWidth(), 0, father.getHeight() - getHeight()); + setMoveCd(x, y); + } + } + + public List<AvatarBDInterface> getInterfaceList() { + List<AvatarBDInterface> list = new LinkedList<AvatarBDInterface>(); + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof AvatarBDInterface) { + list.add((AvatarBDInterface) (tgcomponent[i])); + } + } + return list; + } + + public List<AvatarBDInterface> getFullInterfaceList() { + List<AvatarBDInterface> list = new LinkedList<AvatarBDInterface>(); + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] instanceof AvatarBDInterface) { + list.add((AvatarBDInterface) (tgcomponent[i])); + list.addAll(((AvatarBDInterface) tgcomponent[i]).getFullInterfaceList()); + } + } + return list; + } + + public List<AvatarBDLibraryFunction> getFullLibraryFunctionList() { + List<AvatarBDLibraryFunction> list = new LinkedList<AvatarBDLibraryFunction>(); + for (int i = 0; i < nbInternalTGComponent; i++) { + if (this.tgcomponent[i] instanceof AvatarBDLibraryFunction) + list.add((AvatarBDLibraryFunction) this.tgcomponent[i]); + else if (this.tgcomponent[i] instanceof AvatarBDInterface) + list.addAll(((AvatarBDInterface) this.tgcomponent[i]).getFullLibraryFunctionList()); + } + + return list; + } + + public boolean hasInternalInterfaceWithName(String name) { + List<AvatarBDInterface> list = getFullInterfaceList(); + for (AvatarBDInterface b : list) { + if (b.getValue().compareTo(name) == 0) { + return true; + } + } + /* List<AvatarBDLibraryFunction> llist = getFullLibraryFunctionList(); + for (AvatarBDLibraryFunction b : llist) { + if (b.getFunctionName().compareTo(name) == 0) { + return true; + } + }*/ + + return false; + } + + @Override + public int getDefaultConnector() { + return TGComponentManager.AVATARBD_PORT_CONNECTOR; + } + + public List<TAttribute> getAttributeList() { + return this.myAttributes; + } + + public TAttribute getAttributeByName(String _name) { + for (TAttribute a : this.myAttributes) + if (a.getId().compareTo(_name) == 0) + return a; + return null; + } + + public void addAttribute(TAttribute ta) { + this.myAttributes.add(ta); + } + + public List<AvatarMethod> getMethodList() { + return this.myMethods; + } + + public List<AvatarSignal> getSignalList() { + return this.mySignals; + } + + public List<AvatarSignal> getOutSignalList() { + List<AvatarSignal> v = new LinkedList<AvatarSignal>(); + for (AvatarSignal s : this.mySignals) + if (s.getInOut() == AvatarSignal.OUT) + v.add(s); + return v; + } + + public List<AvatarSignal> getInSignalList() { + List<AvatarSignal> v = new LinkedList<AvatarSignal>(); + for (AvatarSignal s : this.mySignals) + if (s.getInOut() == AvatarSignal.IN) + v.add(s); + return v; + } + + public List<AvatarMethod> getAllMethodList() { + if (getFather() == null) { + return this.myMethods; + } + + List<AvatarMethod> v = new LinkedList<AvatarMethod>(); + v.addAll(this.myMethods); + v.addAll(((AvatarBDInterface) getFather()).getAllMethodList()); + return v; + } + + public List<AvatarSignal> getAllSignalList() { + if (getFather() == null) { + return this.mySignals; + } + + List<AvatarSignal> v = new LinkedList<AvatarSignal>(); + v.addAll(this.mySignals); + v.addAll(((AvatarBDInterface) getFather()).getAllSignalList()); + return v; + } + + public List<String> getAllTimerList() { + List<String> v = new LinkedList<String>(); + + for (TAttribute a : this.myAttributes) + if (a.getType() == TAttribute.TIMER) + v.add(a.getId()); + return v; + } + + public AvatarSignal getAvatarSignalFromName(String _name) { + for (AvatarSignal as : this.mySignals) + if (as.getId().compareTo(_name) == 0) + return as; + return null; + } + + public List<AvatarSignal> getListOfAvailableSignals() { + return ((AvatarBDPanel) (tdp)).getListOfAvailableSignals(this); + } + + public List<AvatarSignal> getListOfAvailableOutSignals() { + return ((AvatarBDPanel) (tdp)).getListOfAvailableOutSignals(this); + } + + public List<AvatarSignal> getListOfAvailableInSignals() { + return ((AvatarBDPanel) (tdp)).getListOfAvailableInSignals(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); + for (AvatarSignal as : this.mySignals) { + // + if (as.getId().compareTo(_id) == 0) + 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; + } + + public AvatarSMDPanel getAvatarSMDPanel() { + return ((AvatarDesignPanel) (tdp.tp)).getAvatarSMDPanel(getInterfaceName()); + } + + public boolean isCryptoBlock() { + return typeStereotype == 1; + } + + public void removeCryptoElements() { + typeStereotype = 0; + + for (String method : AvatarMethod.cryptoMethods) + this.removeMethodIfApplicable(method); + } + + public void addCryptoElements() { + typeStereotype = 1; + + for (String method : AvatarMethod.cryptoMethods) + this.addMethodIfApplicable(method); + } + + private void removeMethodIfApplicable(String methodString) { + Iterator<AvatarMethod> iterator = this.myMethods.iterator(); + while (iterator.hasNext()) { + AvatarMethod am = iterator.next(); + // TODO: replace by a more OO way... + if (am.toString().equals(methodString)) { + iterator.remove(); + break; + } + } + } + + public void addMethodIfApplicable(String methodString) { + for (AvatarMethod am : this.myMethods) + // TODO: replace by a more OO way... + if (am.toString().equals(methodString)) + return; + + AvatarMethod am = AvatarMethod.isAValidMethod(methodString); + if (am != null) + this.myMethods.add(am); + } + + public boolean hasDefinitions() { + return ((this.myAttributes.size() + this.myMethods.size() + this.mySignals.size() + nbInternalTGComponent) > 0); + } + + // Main Tree + + public int getChildCount() { + //TraceManager.addDev("Counting childs!"); + return this.myAttributes.size() + this.myMethods.size() + this.mySignals.size() + nbInternalTGComponent; + } + + public Object getChild(int index) { + + int sa = nbInternalTGComponent; + + if (sa > index) { + return tgcomponent[index]; + } + + index = index - nbInternalTGComponent; + sa = this.myAttributes.size(); + // TraceManager.addDev("index = " + index + " sa=" + sa); + if (sa <= index) { + index = index - sa; + sa = this.myMethods.size(); + if (sa <= index) { + return this.mySignals.get(index - sa); + } else { + return this.myMethods.get(index); + } + } + + return this.myAttributes.get(index); + } + + public int getIndexOfChild(Object child) { + if (child instanceof AvatarBDInterface) { + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] == child) { + return i; + } + } + } + + if (child instanceof TAttribute) { + return this.myAttributes.indexOf(child) + nbInternalTGComponent; + } + + if (child instanceof AvatarMethod) { + return this.myMethods.indexOf(child) + this.myAttributes.size() + nbInternalTGComponent; + } + + if (child instanceof AvatarSignal) { + return this.mySignals.indexOf(child) + this.myAttributes.size() + this.myMethods.size() + nbInternalTGComponent; + } + + return -1; + } + + @Override + public ImageIcon getImageIcon() { + return myImageIcon; + } + + public void resetConfidentialityOfAttributes() { + for (TAttribute a : this.myAttributes) + a.setConfidentialityVerification(TAttribute.NOT_VERIFIED); + } + + public String getOwnerName() { + return this.getInterfaceName(); + } + + @Override + public String toString() { + return "Interface: " + getValue(); + } + + public String getAttributes() { + String attr = ""; + for (TAttribute a : myAttributes) { + attr += a.toAvatarString() + "\n"; + } + for (AvatarMethod m : myMethods) { + attr += m.toString() + "\n"; + } + for (AvatarSignal s : mySignals) { + attr += s.toString() + "\n"; + } + return attr; + } +} diff --git a/src/main/java/ui/avatarbd/AvatarBDPanel.java b/src/main/java/ui/avatarbd/AvatarBDPanel.java index b5541b1b4f00c5ea497535ee6aae28e7a523978c..8e287e05b664b29ac59230e7b55c903fcf55e00f 100644 --- a/src/main/java/ui/avatarbd/AvatarBDPanel.java +++ b/src/main/java/ui/avatarbd/AvatarBDPanel.java @@ -178,6 +178,16 @@ public class AvatarBDPanel extends TDiagramPanel { return false; } + /* @Override + public boolean actionOnValueChanged(TGComponent tgc) { + if (tgc instanceof AvatarAMSInterface) { + //updateAllSignalsOnConnectors(); + return actionOnDoubleClick(tgc); + } + return false; + }*/ + + @Override public boolean areAttributesVisible() { return attributesVisible; @@ -452,7 +462,87 @@ public class AvatarBDPanel extends TDiagramPanel { return v; } + //ajoute DG 27.02.: Interfcae signals treated as block signals to avoid too many case distinctions - is this possible ? + + public List<AvatarSignal> getListOfAvailableSignals(AvatarBDInterface _block) { + List<AvatarSignal> v = new LinkedList<AvatarSignal> (); + + List<AvatarSignal> listOfBlock = _block.getSignalList(); + if (listOfBlock.size() == 0) + return v; + + v.addAll(listOfBlock); + + for (TGComponent tgc: this.componentList) + if (tgc instanceof AvatarBDPortConnector) { + AvatarBDPortConnector port = (AvatarBDPortConnector) tgc; + if (port.getAvatarBDInterface1() == _block) { + List<String> ll = port.getListOfSignalsOrigin(); + removeSignals(v, ll); + } + if (port.getAvatarBDInterface2() == _block) { + List<String> ll = port.getListOfSignalsDestination(); + removeSignals(v, ll); + } + } + + return v; + } + + public List<AvatarSignal> getListOfAvailableOutSignals (AvatarBDInterface _block) { + List<AvatarSignal> v = new LinkedList<AvatarSignal> (); + + List<AvatarSignal> listOfBlock = _block.getOutSignalList(); + if (listOfBlock.size() == 0) + return v; + + v.addAll(listOfBlock); + + for (TGComponent tgc: this.componentList) + if (tgc instanceof AvatarBDPortConnector) { + AvatarBDPortConnector port = (AvatarBDPortConnector)tgc; + if (port.getAvatarBDInterface1() == _block) { + List<String> ll = port.getListOfSignalsOrigin(); + removeSignals(v, ll); + } + if (port.getAvatarBDInterface2() == _block) { + List<String> ll = port.getListOfSignalsDestination(); + removeSignals(v, ll); + } + } + + return v; + } + + public List<AvatarSignal> getListOfAvailableInSignals(AvatarBDInterface _block) { + List<AvatarSignal> v = new LinkedList<AvatarSignal> (); + + List<AvatarSignal> listOfBlock = _block.getInSignalList(); + if (listOfBlock.size() == 0) + return v; + + v.addAll(listOfBlock); + + for (TGComponent tgc: this.componentList) + if (tgc instanceof AvatarBDPortConnector) { + AvatarBDPortConnector port = (AvatarBDPortConnector)tgc; + if (port.getAvatarBDInterface1() == _block) { + List<String> ll = port.getListOfSignalsOrigin(); + removeSignals(v, ll); + } + if (port.getAvatarBDInterface2() == _block) { + List<String> ll = port.getListOfSignalsDestination(); + removeSignals(v, ll); + } + } + + return v; + } + + + //fin ajoute DG + // Remove AvatarSignals of v which name is provided in list private static void removeSignals(List<AvatarSignal> v, List<String> list) { for(String s: list) { diff --git a/src/main/java/ui/avatarbd/AvatarBDPortConnector.java b/src/main/java/ui/avatarbd/AvatarBDPortConnector.java index 96f4ca5d59003d31c5af5416352b2a21abd7d420..439161578825ffa4ac4c80b7947367261eb6cfd2 100644 --- a/src/main/java/ui/avatarbd/AvatarBDPortConnector.java +++ b/src/main/java/ui/avatarbd/AvatarBDPortConnector.java @@ -82,11 +82,13 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint protected List<String> outSignalsAtOrigin; protected boolean asynchronous; + protected boolean AMS; protected int sizeOfFIFO; protected boolean blockingFIFO; protected boolean isPrivate = true; // isprivate = cannot be listened by an attacker protected boolean isBroadcast = false; protected boolean isLossy = false; + protected boolean isAMS = false; 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<Point> _listPoint) { super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint); @@ -126,6 +128,9 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint int cz = (int) (tdp.getZoom() * c); if (isAsynchronous()) { g.setColor(Color.WHITE); + } + if (isAMS()) { + g.setColor(Color.GRAY); } g.fillRect(x2 - (cz / 2), y2 - (cz / 2), cz, cz); g.fillRect(p1.getX() - (cz / 2), p1.getY() - (cz / 2), cz, cz); @@ -305,6 +310,18 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint return (AvatarBDBlock) (tdp.getComponentToWhichBelongs(p2)); } + + public AvatarBDInterface getAvatarBDInterface1() { + return (AvatarBDInterface) (tdp.getComponentToWhichBelongs(p1)); + } + + + public AvatarBDInterface getAvatarBDInterface2() { + return (AvatarBDInterface) (tdp.getComponentToWhichBelongs(p2)); + } + + + @Override public boolean editOndoubleClick(JFrame frame) { // Gets the two concerned blocks @@ -357,6 +374,7 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint isPrivate = jdas.isPrivate(); isBroadcast = jdas.isBroadcast(); isLossy = jdas.isLossy(); + isAMS = jdas.isAMS(); try { sizeOfFIFO = Integer.decode(jdas.getSizeOfFIFO()).intValue(); @@ -402,6 +420,7 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint sb.append("\" private=\"" + isPrivate); sb.append("\" broadcast=\"" + isBroadcast); sb.append("\" lossy=\"" + isLossy); + sb.append("\" ams=\"" + isAMS); sb.append("\" />\n"); sb.append("</extraparam>\n"); @@ -414,7 +433,7 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint NodeList nli; Node n1, n2; Element elt; - String val, val1, val2, val3, val4, val5; + String val, val1, val2, val3, val4, val5, val6; sizeOfFIFO = 4; blockingFIFO = false; asynchronous = false; @@ -467,6 +486,7 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint val3 = elt.getAttribute("private"); val4 = elt.getAttribute("broadcast"); val5 = elt.getAttribute("lossy"); + val6 = elt.getAttribute("ams"); if ((val != null) && (!(val.equals("null")))) { asynchronous = val.trim().toLowerCase().compareTo("true") == 0; @@ -507,6 +527,12 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint } else { isLossy = false; } + if ((val6 != null) && (!(val6.equals("null")))) { + isAMS = val6.trim().toLowerCase().compareTo("true") == 0; + + } else { + isAMS = false; + } } } } @@ -714,10 +740,18 @@ public class AvatarBDPortConnector extends TGConnectorWithCommentConnectionPoint return asynchronous; } + public boolean isAMS() { + return AMS; + } + public void setAsynchronous(boolean asy) { asynchronous = asy; } + public void setAMS(boolean ams) { + AMS = ams; + } + public int getSizeOfFIFO() { return sizeOfFIFO; } diff --git a/src/main/java/ui/avatarbd/AvatarBDToolBar.java b/src/main/java/ui/avatarbd/AvatarBDToolBar.java index 86481a41d9b89374a29c12db0a20b4cb76f08bf2..7228b20e21548c379e80fa7b8e68297c08a04780 100644 --- a/src/main/java/ui/avatarbd/AvatarBDToolBar.java +++ b/src/main/java/ui/avatarbd/AvatarBDToolBar.java @@ -79,6 +79,7 @@ public class AvatarBDToolBar extends TToolBar { mgui.actions[TGUIAction.CONNECTOR_COMMENT].setEnabled(b); mgui.actions[TGUIAction.ABD_BLOCK].setEnabled(b); + mgui.actions[TGUIAction.AMS_INTERFACE].setEnabled(b); mgui.actions[TGUIAction.ABD_CRYPTOBLOCK].setEnabled(b); mgui.actions[TGUIAction.ABD_DATATYPE].setEnabled(b); mgui.actions[TGUIAction.ABD_COMPOSITION_CONNECTOR].setEnabled(b); @@ -130,6 +131,12 @@ public class AvatarBDToolBar extends TToolBar { button = this.add(mgui.actions[TGUIAction.ABD_BLOCK]); button.addMouseListener(mgui.mouseHandler); + + this.addSeparator(); + + button = this.add(mgui.actions[TGUIAction.AMS_INTERFACE]); + button.addMouseListener(mgui.mouseHandler); + this.addSeparator(); button = this.add(mgui.actions[TGUIAction.ABD_CRYPTOBLOCK]); diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index ff4bf4796ffbccb582b52eaeef63caae9051fdc1..a92a97adc592cc818caf2efcce9ae2ea84a415a1 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -105,7 +105,7 @@ public class IconManager { public static ImageIcon imgic600, imgic602, imgic604, imgic606, imgic608, imgic610, imgic612, imgic614; - public static ImageIcon imgic700, imgic702; + public static ImageIcon imgic700, imgic701, imgic702; public static ImageIcon imgic800, imgic802, imgic804, imgic806, imgic808, imgic810, imgic812; public static ImageIcon imgic900, imgic902, imgic904, imgic905, imgic906, imgic907, imgic908, imgic910, imgic912, imgic914, imgic916, imgic918; @@ -141,7 +141,7 @@ public class IconManager { // SMD diagram public static ImageIcon imgic2000, imgic2002, imgic2004, imgic2006, imgic2008, imgic2010, imgic2012, imgic2014, - imgic2016, imgic2018; + imgic2016, imgic2018, imgic2015, imgic2017; // CSD diagram public static ImageIcon imgic2100, imgic2104, imgic2106, imgic2108, imgic2110; @@ -151,7 +151,7 @@ public class IconManager { public static ImageIcon imgic3000; // AVATAR - public static ImageIcon imgic5000, imgic5002, imgic5004, imgic5006, imgic5008; + public static ImageIcon imgic5000, imgic5001, imgic5002, imgic5004, imgic5006, imgic5008; public static ImageIcon imgic5010, imgic5012, imgic5014, imgic5016, imgic5018; public static ImageIcon imgic5020, imgic5022, imgic5024, imgic5026, imgic5028; public static ImageIcon imgic5030, imgic5032, imgic5034, imgic5036, imgic5038; @@ -453,6 +453,7 @@ public class IconManager { // Deployment diagrams private static String icon700 = "ddnode.gif"; + private static String icon701 = "ddnode.gif"; private static String icon702 = "ddartifact.gif"; @@ -581,6 +582,8 @@ public class IconManager { private static String icon2012 = "prosmdstate.gif"; private static String icon2014 = "sendsignal.gif"; private static String icon2016 = "receivesignal.gif"; + private static String icon2015 = "sendsignalams.gif"; + private static String icon2017 = "receivesignalams.gif"; private static String icon2018 = "functioncall.gif"; //CSD diagrams @@ -599,6 +602,7 @@ public class IconManager { public static final int iconSize = 15; private static String icon5000 = "avatarblock.gif"; + private static String icon5001 = "avatarinterface.gif"; private static String icon5002 = "avatarbdcomp.gif"; private static String icon5004 = "avatarbdlink.gif"; private static String icon5006 = "avatarrdreq.gif"; @@ -970,6 +974,7 @@ public class IconManager { imgic614 = getIcon(icon614); imgic700 = getIcon(icon700); + imgic701 = getIcon(icon701); imgic702 = getIcon(icon702); imgic800 = getIcon(icon800); @@ -1110,7 +1115,9 @@ public class IconManager { imgic2014 = getIcon(icon2014); imgic2016 = getIcon(icon2016); imgic2018 = getIcon(icon2018); - + imgic2015 = getIcon(icon2015); + imgic2017 = getIcon(icon2017); + imgic2100 = getIcon(icon2100); //Delegate Ports removed, by Solange //imgic2102 = getIcon(icon2102); @@ -1126,6 +1133,7 @@ public class IconManager { // AVATAR //imgic3000 = getIcon(icon3000); imgic5000 = getIcon(icon5000); + imgic5001 = getIcon(icon5001); imgic5002 = getIcon(icon5002); imgic5004 = getIcon(icon5004); imgic5006 = getIcon(icon5006); diff --git a/src/main/java/ui/window/JDialogAvatarInterface.java b/src/main/java/ui/window/JDialogAvatarInterface.java new file mode 100644 index 0000000000000000000000000000000000000000..8798281488fbeddb0a0963b397f37ae0947cc5fb --- /dev/null +++ b/src/main/java/ui/window/JDialogAvatarInterface.java @@ -0,0 +1,1118 @@ +/* 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. + */ + + +package ui.window; + +import myutil.Conversion; +import myutil.GraphicLib; +import ui.AvatarMethod; +import ui.AvatarSignal; +import ui.TAttribute; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.LinkedList; +import java.util.List; + + +/** + * Class JDialogAvatarInterface + * Dialog for managing attributes, methods and signals of Avatar Interfaces + * Creation: 08/04/2010 + * + * @author Ludovic APVRILLE + * @version 1.0 08/04/2010 + */ +public class JDialogAvatarInterface extends JDialogBase implements ActionListener, ListSelectionListener { + + private List<TAttribute> attributes, attributesPar, forbidden; + private List<Boolean> initValues; + private List<AvatarMethod> methods, methodsPar; + private List<AvatarSignal> signals, signalsPar; + private boolean checkKeyword, checkJavaKeyword, checkUPPAALKeyword; + + private boolean cancelled = true; + + protected String[] globalCode; + protected JTextArea jtaGlobalCode; + protected boolean hasGlobalCode; + protected String mainCode; + protected JTextArea jtaMainCode; + + private JPanel panel1, panel2; + + private Frame frame; + private int tab; + + private String attrib; // "Attributes", "Gates", etc. + + // Panel1 + private JComboBox<String> accessBox, typeBox; + private JTextField identifierText; + private JTextField initialValue; + private JButton addButton; + + //Panel2 + private JList<TAttribute> listAttribute; + private JButton upButton; + private JButton downButton; + private JButton removeButton; + + // Method + private boolean hasMethods = true; + private JPanel panel3, panel4; + private JTextField methodText; + private JButton addMethodButton; + private JList<AvatarMethod> listMethod; + private JButton upMethodButton; + private JButton downMethodButton; + private JButton removeMethodButton; + private JCheckBox implementationProvided; + + // Signals + private boolean hasSignals = true; + private JPanel panel5, panel6; + private JComboBox<String> signalInOutBox; + private JTextField signalText; + private JButton addSignalButton; + private JList<AvatarSignal> listSignal; + private JButton upSignalButton; + private JButton downSignalButton; + private JButton removeSignalButton; + + /* + * Creates new form + */ + public JDialogAvatarInterface( List<TAttribute> _attributes, List<AvatarMethod> _methods, List<AvatarSignal> _signals, List<TAttribute> _forbidden, Frame f, String title, String attrib, int _tab, String[] _globalCode, boolean _hasGlobalCode, String _mainCode) { + super(f, title, true); + frame = f; + attributesPar = _attributes; + methodsPar = _methods; + signalsPar = _signals; + globalCode = _globalCode; + mainCode = _mainCode; + + + if (methodsPar == null) { + methodsPar = new LinkedList<AvatarMethod>(); + hasMethods = false; + } + + if (signalsPar == null) { + signalsPar = new LinkedList<AvatarSignal>(); + hasSignals = false; + } + + hasGlobalCode = _hasGlobalCode; + if (globalCode == null) { + globalCode = new String[1]; + globalCode[0] = ""; + } + + + forbidden = _forbidden; + initValues = new LinkedList<Boolean>(); + this.attrib = attrib; + tab = _tab; + + attributes = new LinkedList<TAttribute>(); + methods = new LinkedList<AvatarMethod>(); + signals = new LinkedList<AvatarSignal>(); + + for (TAttribute attr : this.attributesPar) + this.attributes.add(attr.makeClone()); + + for (AvatarMethod meth : this.methodsPar) + this.methods.add(meth.makeClone()); + + for (AvatarSignal sig : this.signalsPar) + this.signals.add(sig.makeClone()); + + initComponents(); + myInitComponents(); + pack(); + } + + private void myInitComponents() { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + } + + private void initComponents() { + + // Issue #41 Ordering of tabbed panes + JTabbedPane tabbedPane = GraphicLib.createTabbedPane();//new JTabbedPane(); + Container c = getContentPane(); + + //JPanel panelAttr = new JPanel(new FlowLayout()); + //JPanel panelMethod = new JPanel(new BorderLayout()); + //JPanel panelSignal = new JPanel(new BorderLayout()); + JPanel panelCode; + 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(); + GridBagLayout gridbag7 = new GridBagLayout(); + GridBagLayout gridbag8 = new GridBagLayout(); + GridBagLayout gridbag9 = new GridBagLayout(); + GridBagLayout gridbag10 = 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(); + GridBagConstraints c7 = new GridBagConstraints(); + GridBagConstraints c8 = new GridBagConstraints(); + GridBagConstraints c9 = new GridBagConstraints(); + GridBagConstraints c10 = new GridBagConstraints(); + + JPanel panelAttr = new JPanel(gridbag8); + JPanel panelMethod = new JPanel(gridbag9); + JPanel panelSignal = new JPanel(gridbag10); + + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + //c.setLayout(gridbag0); + c.setLayout(new BorderLayout()); + + + 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, 550)); + panel1.setMinimumSize(new Dimension(300, 200)); + + panel2 = new JPanel(); + panel2.setLayout(gridbag2); + panel2.setBorder(new javax.swing.border.TitledBorder("Managing " + attrib + "s")); + panel2.setPreferredSize(new Dimension(300, 550)); + panel2.setMinimumSize(new Dimension(300, 200)); + + // 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<String>(); + 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<String>(); + 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<TAttribute>(this.attributes.toArray(new TAttribute[0])); + //listAttribute.setFixedCellWidth(150); + //listAttribute.setFixedCellHeight(20); + listAttribute.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listAttribute.addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(listAttribute); + scrollPane.setSize(300, 450); + 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, 550)); + + panel4 = new JPanel(); + panel4.setLayout(gridbag2); + panel4.setBorder(new javax.swing.border.TitledBorder("Managing methods")); + panel4.setPreferredSize(new Dimension(300, 550)); + + // 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 + c3.fill = GridBagConstraints.HORIZONTAL; + 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.gridwidth = GridBagConstraints.REMAINDER; //end row + c3.fill = GridBagConstraints.BOTH; + c3.gridheight = 3; + implementationProvided = new JCheckBox("Implementation provided by user"); + implementationProvided.setSelected(false); + panel3.add(implementationProvided, c3); + + + // fifth 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<AvatarMethod>(this.methods.toArray(new AvatarMethod[0])); + listMethod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listMethod.addListSelectionListener(this); + scrollPane = new JScrollPane(listMethod); + scrollPane.setSize(300, 550); + 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, 550)); + + panel6 = new JPanel(); + panel6.setLayout(gridbag6); + panel6.setBorder(new javax.swing.border.TitledBorder("Managing signals")); + panel6.setPreferredSize(new Dimension(300, 550)); + + // 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; + c5.fill = GridBagConstraints.HORIZONTAL; + String[] v = new String[2]; + v[0] = "in"; + v[1] = "out"; + signalInOutBox = new JComboBox<String>(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<AvatarSignal>(this.signals.toArray(new AvatarSignal[0])); + listSignal.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listSignal.addListSelectionListener(this); + scrollPane = new JScrollPane(listSignal); + scrollPane.setSize(300, 450); + 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); + + // Prototyping + panelCode = new JPanel(); + panelCode.setLayout(gridbag7); + + panelCode.setBorder(new javax.swing.border.TitledBorder("Global code")); + // guard + c7.weighty = 1.0; + c7.weightx = 1.0; + c7.gridwidth = 1; + c7.gridheight = 1; + c7.fill = GridBagConstraints.BOTH; + c7.gridwidth = GridBagConstraints.REMAINDER; + c7.gridheight = 1; + + panelCode.add(new JLabel("Global code of application:"), c7); + jtaMainCode = new JTextArea(); + jtaMainCode.setEditable(true); + jtaMainCode.setMargin(new Insets(10, 10, 10, 10)); + jtaMainCode.setTabSize(3); + String tmp = ""; + if (mainCode != null) { + tmp = mainCode; + } + + jtaMainCode.append(tmp); + if (mainCode == null) { + jtaMainCode.setEnabled(false); + } + jtaMainCode.setFont(new Font("times", Font.PLAIN, 12)); + JScrollPane jsp = new JScrollPane(jtaMainCode, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + jsp.setPreferredSize(new Dimension(300, 200)); + panelCode.add(jsp, c2); + + panelCode.add(new JLabel("Global code of block:"), c7); + panelCode.add(new JLabel("To implement a method m of block B: \"__userImplemented__B__m(...){...}\""), c7); + jtaGlobalCode = new JTextArea(); + jtaGlobalCode.setEditable(true); + jtaGlobalCode.setMargin(new Insets(10, 10, 10, 10)); + jtaGlobalCode.setTabSize(3); + String files = ""; + if (globalCode != null) { + for (int i = 0; i < globalCode.length; i++) { + files += globalCode[i] + "\n"; + } + } + jtaGlobalCode.append(files); + jtaGlobalCode.setFont(new Font("times", Font.PLAIN, 12)); + jsp = new JScrollPane(jtaGlobalCode, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + jsp.setPreferredSize(new Dimension(300, 200)); + panelCode.add(jsp, c2); + + + // main panel; + //panelAttr.add(panel1, BorderLayout.WEST); + //panelAttr.add(panel2, BorderLayout.EAST); + c8.gridwidth = 1; + c8.gridheight = 10; + c8.weighty = 1.0; + c8.weightx = 1.0; + c8.fill = GridBagConstraints.BOTH; + panelAttr.add(panel1, c8); + c8.gridwidth = GridBagConstraints.REMAINDER; //end row + //c.add(tabbedPane, c0); + + c8.gridwidth = 1; + c8.gridheight = 10; + panelAttr.add(panel2, c8); + + tabbedPane.addTab("Attributes", panelAttr); + + if (hasMethods) { + //panelMethod.add(panel3, BorderLayout.WEST); + //panelMethod.add(panel4, BorderLayout.EAST); + c9.gridwidth = 1; + c9.gridheight = 10; + c9.weighty = 1.0; + c9.weightx = 1.0; + c9.fill = GridBagConstraints.BOTH; + panelMethod.add(panel3, c9); + c9.gridwidth = GridBagConstraints.REMAINDER; //end row + //c.add(tabbedPane, c0); + + c9.gridwidth = 1; + c9.gridheight = 10; + panelMethod.add(panel4, c9); + tabbedPane.addTab("Methods", panelMethod); + } + + if (hasSignals) { + //panelSignal.add(panel5, BorderLayout.WEST); + //panelSignal.add(panel6, BorderLayout.EAST); + c10.gridwidth = 1; + c10.gridheight = 10; + c10.weighty = 1.0; + c10.weightx = 1.0; + c10.fill = GridBagConstraints.BOTH; + panelSignal.add(panel5, c10); + c10.gridwidth = GridBagConstraints.REMAINDER; //end row + //c.add(tabbedPane, c0); + + c10.gridwidth = 1; + c10.gridheight = 10; + panelSignal.add(panel6, c10); + + tabbedPane.addTab("Signals", panelSignal); + } + + if (hasGlobalCode) { + tabbedPane.addTab("Prototyping", panelCode); + } + + 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; + + JPanel panel4Buttons = new JPanel(); + panel4Buttons.setLayout(gridbag0); + initButtons(c0, panel4Buttons, this); + + c.add(tabbedPane, BorderLayout.CENTER); + c.add(panel4Buttons, BorderLayout.SOUTH); + } + + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == typeBox) { + boolean b = initValues.get(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) { + 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() == upSignalButton) { + upSignal(); + } 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 enableUPPAALKeyword(boolean b) { + checkUPPAALKeyword = !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, checkUPPAALKeyword, checkJavaKeyword)) && (TAttribute.notIn(s, forbidden))) { + int i = TAttribute.getAccess(o1.toString()); + int j = TAttribute.getAvatarType(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()); + a.isAvatar = true; + // + } else { + a = new TAttribute(i, s, value, j); + a.isAvatar = true; + } + //checks whether the same attribute already belongs to the list + int index = attributes.size(); + if (attributes.contains(a)) { + index = attributes.indexOf(a); + a = attributes.get(index); + a.setAccess(i); + if (j == TAttribute.OTHER) { + a.setTypeOther(o2.toString()); + } + a.setType(j); + a.setInitialValue(value); + } else { + attributes.add(index, a); + } + listAttribute.setListData(attributes.toArray(new TAttribute[0])); + 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) { + am.setImplementationProvided(implementationProvided.isSelected()); + + // Checks whether the same method already belongs to the list + int index = -1; + for (int i = 0; i < methods.size(); i++) { + amtmp = methods.get(i); + // Same id? + if (amtmp.equals(am)) { + index = i; + break; + } + } + if (index == -1) { + methods.add(am); + } else { + methods.remove(index); + methods.add(index, am); + } + listMethod.setListData(methods.toArray(new AvatarMethod[0])); + 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 = signals.get(i); + // Same id? + if (astmp.equals(as)) { + index = i; + break; + } + } + if (index == -1) { + signals.add(as); + } else { + signals.remove(index); + signals.add(index, as); + } + listSignal.setListData(signals.toArray(new AvatarSignal[0])); + 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 = attributes.get(i); + a.setAccess(-1); + attributes.remove(i); + listAttribute.setListData(attributes.toArray(new TAttribute[0])); + } + } + + public void downAttribute() { + int i = listAttribute.getSelectedIndex(); + if ((i != -1) && (i != attributes.size() - 1)) { + TAttribute o = attributes.get(i); + attributes.remove(i); + attributes.add(i + 1, o); + listAttribute.setListData(attributes.toArray(new TAttribute[0])); + listAttribute.setSelectedIndex(i + 1); + } + } + + public void upAttribute() { + int i = listAttribute.getSelectedIndex(); + //TraceManager.addDev("Selected index = " + i); + if (i > 0) { + //TraceManager.addDev("Modifying ..."); + TAttribute o = attributes.get(i); + attributes.remove(i); + attributes.add(i - 1, o); + listAttribute.setListData(attributes.toArray(new TAttribute[0])); + listAttribute.setSelectedIndex(i - 1); + } + } + + public void removeMethod() { + int i = listMethod.getSelectedIndex(); + if (i != -1) { + methods.remove(i); + listMethod.setListData(methods.toArray(new AvatarMethod[0])); + } + } + + public void upMethod() { + int i = listMethod.getSelectedIndex(); + //TraceManager.addDev("Selected index method = " + i); + if (i > 0) { + AvatarMethod o = methods.get(i); + methods.remove(i); + methods.add(i - 1, o); + listMethod.setListData(methods.toArray(new AvatarMethod[0])); + listMethod.setSelectedIndex(i - 1); + } + } + + public void downMethod() { + int i = listMethod.getSelectedIndex(); + if ((i != -1) && (i != methods.size() - 1)) { + AvatarMethod o = methods.get(i); + methods.remove(i); + methods.add(i + 1, o); + listMethod.setListData(methods.toArray(new AvatarMethod[0])); + listMethod.setSelectedIndex(i + 1); + } + } + + public void removeSignal() { + int i = listSignal.getSelectedIndex(); + if (i != -1) { + signals.remove(i); + listSignal.setListData(signals.toArray(new AvatarSignal[0])); + } + } + + public void upSignal() { + int i = listSignal.getSelectedIndex(); + if (i > 0) { + AvatarSignal o = signals.get(i); + signals.remove(i); + signals.add(i - 1, o); + listSignal.setListData(signals.toArray(new AvatarSignal[0])); + listSignal.setSelectedIndex(i - 1); + } + } + + public void downSignal() { + int i = listSignal.getSelectedIndex(); + if ((i != -1) && (i != signals.size() - 1)) { + AvatarSignal o = signals.get(i); + signals.remove(i); + signals.add(i + 1, o); + listSignal.setListData(signals.toArray(new AvatarSignal[0])); + listSignal.setSelectedIndex(i + 1); + } + } + + + public void closeDialog() { + cancelled = false; + attributesPar.clear(); + for (TAttribute attr : this.attributes) + attributesPar.add(attr); + + methodsPar.clear(); + for (AvatarMethod meth : this.methods) + methodsPar.add(meth); + + signalsPar.clear(); + for (AvatarSignal sig : this.signals) + signalsPar.add(sig); + + globalCode = Conversion.wrapText(jtaGlobalCode.getText()); + mainCode = jtaMainCode.getText(); + cancelled = false; + dispose(); + } + + public boolean hasBeenCancelled() { + return cancelled; + } + + + 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 = attributes.get(i); + identifierText.setText(a.getId()); + initialValue.setText(a.getInitialValue()); + select(accessBox, TAttribute.getStringAccess(a.getAccess())); + if (a.getType() == TAttribute.OTHER) { + select(typeBox, a.getTypeOther()); + } else { + select(typeBox, TAttribute.getStringAvatarType(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 = methods.get(i); + methodText.setText(am.toString()); + //TraceManager.addDev("Implementation of " + am + " is: " + am.isImplementationProvided()); + implementationProvided.setSelected(am.isImplementationProvided()); + 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 = signals.get(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<String> jcb, String text) { + String s; + for (int i = 0; i < jcb.getItemCount(); i++) { + s = jcb.getItemAt(i); + // + if (s.equals(text)) { + jcb.setSelectedIndex(i); + return; + } + } + } + + public String[] getGlobalCode() { + return globalCode; + } + + public String getMainCode() { + return mainCode; + } + +} diff --git a/src/main/java/ui/window/JDialogSignalAssociation.java b/src/main/java/ui/window/JDialogSignalAssociation.java index 8a091b0cb7006436d9dbfbb1842c66e78fb48ccd..30c3784ebb2563729506bf4db1e099ec682826da 100644 --- a/src/main/java/ui/window/JDialogSignalAssociation.java +++ b/src/main/java/ui/window/JDialogSignalAssociation.java @@ -82,10 +82,11 @@ public class JDialogSignalAssociation extends JDialogBase implements ActionListe private List<AvatarSignal> available1, available2; private AvatarBDPortConnector connector; - private JRadioButton synchronous, asynchronous; + private JRadioButton synchronous, asynchronous, AMS; + private JLabel labelFIFO; private JTextField sizeOfFIFO; - private JCheckBox blocking, isPrivate, isBroadcast, isLossy; + private JCheckBox blocking, isPrivate, isBroadcast, isLossy, isAMS; private JPanel panel1, panel2, panel3, panel4; private boolean cancelled = true; @@ -274,6 +275,10 @@ public class JDialogSignalAssociation extends JDialogBase implements ActionListe isLossy.setToolTipText("A lossy channel randomly losses messages"); isLossy.setSelected(connector.isLossy()); panel3.add(isLossy, c3); + isAMS = new JCheckBox("AMS channel"); + isAMS.setToolTipText("An AMS channel communicates with an analog module"); + isAMS.setSelected(connector.isAMS()); + panel3.add(isAMS, c3); c3.gridwidth = 3; labelFIFO = new JLabel("Size of FIFO:"); @@ -508,6 +513,10 @@ public class JDialogSignalAssociation extends JDialogBase implements ActionListe return asynchronous.isSelected(); } + public boolean isAMS() { + return AMS.isSelected(); + } + public String getSizeOfFIFO() { return sizeOfFIFO.getText(); } diff --git a/src/main/resources/ui/util/avatarinterface.gif b/src/main/resources/ui/util/avatarinterface.gif new file mode 100644 index 0000000000000000000000000000000000000000..330963443bdeb448d412d44d06f770aa7b18ddf4 Binary files /dev/null and b/src/main/resources/ui/util/avatarinterface.gif differ diff --git a/src/main/resources/ui/util/receivesignalams.gif b/src/main/resources/ui/util/receivesignalams.gif new file mode 100755 index 0000000000000000000000000000000000000000..5e9fb439fa2fe544fb7a3b6a3cec8ee99be23d95 Binary files /dev/null and b/src/main/resources/ui/util/receivesignalams.gif differ diff --git a/src/main/resources/ui/util/sendsignalams.gif b/src/main/resources/ui/util/sendsignalams.gif new file mode 100755 index 0000000000000000000000000000000000000000..1f61428d8cb67ba4333c6427eea6b95af1699598 Binary files /dev/null and b/src/main/resources/ui/util/sendsignalams.gif differ