diff --git a/src/attacktrees/ANDNode.java b/src/attacktrees/ANDNode.java index dc5e15db3dcb596f9ecd82786e850127464be17e..b6aa05551ff26c8a0b62a519b4f7248a43fa5a47 100755 --- a/src/attacktrees/ANDNode.java +++ b/src/attacktrees/ANDNode.java @@ -50,8 +50,9 @@ import java.util.*; public class ANDNode extends BooleanNode { - public ANDNode(String _name) { - super(_name); + public ANDNode(String _name, Object _referenceObject) { + super(_name, _referenceObject); + type = "AND"; } diff --git a/src/attacktrees/AfterNode.java b/src/attacktrees/AfterNode.java index 2f0aa9984eba3fd5a10d5aee93f0a1129486f6a1..12b22652fe002b139c8a6392f05d10c9089359fe 100755 --- a/src/attacktrees/AfterNode.java +++ b/src/attacktrees/AfterNode.java @@ -50,8 +50,9 @@ import java.util.*; public class AfterNode extends TimeNode { - public AfterNode(String _name, int _time) { - super(_name, _time); + public AfterNode(String _name, Object _referenceObject, int _time) { + super(_name, _referenceObject, _time); + type = "AFTER"; } } diff --git a/src/attacktrees/Attack.java b/src/attacktrees/Attack.java index 7bd85c954cb308b35f6c3e88ec591451a67bf944..1aa21c0a49bd8457cd18c039e55ccbefd641c32a 100755 --- a/src/attacktrees/Attack.java +++ b/src/attacktrees/Attack.java @@ -52,11 +52,22 @@ public class Attack { private AttackNode originNode; // If no origin node -> leaf attack private ArrayList<AttackNode> destinationNodes; private String name; + private Object referenceObject; + private boolean isRoot; - public Attack(String _name) { + public Attack(String _name, Object _referenceObject) { name = _name; + referenceObject = _referenceObject; destinationNodes = new ArrayList<AttackNode>(); } + + public boolean isRoot() { + return isRoot; + } + + public void setRoot(boolean _root) { + isRoot = _root; + } public void setOriginNode(AttackNode _node) { originNode = _node; @@ -65,5 +76,9 @@ public class Attack { public void addDestinationNode(AttackNode _node) { destinationNodes.add(_node); } + + public String getName() { + return name; + } } diff --git a/src/attacktrees/AttackNode.java b/src/attacktrees/AttackNode.java index b8bba4c28a0eeb25e67836be1a5a7520973d3fc5..7d2862f7b8f01099004c81b027207b94afa5d13a 100755 --- a/src/attacktrees/AttackNode.java +++ b/src/attacktrees/AttackNode.java @@ -51,19 +51,46 @@ import java.util.*; public abstract class AttackNode { private Attack resultingAttack; // If no resulting attack -> error! private ArrayList<Attack> inputAttacks; + private ArrayList<Integer> inputValues; private String name; + protected String type = ""; + protected Object referenceObject; - public AttackNode(String _name) { + public AttackNode(String _name, Object _referenceObject) { name = _name; + referenceObject = _referenceObject; inputAttacks = new ArrayList<Attack>(); + inputValues = new ArrayList<Integer>(); } + + public String getName() { return name;} public void setResultingAttack(Attack _attack) { resultingAttack = _attack; } - public void addInputAttack(Attack _attack) { + public Attack getResultingAttack() { + return resultingAttack; + } + + public void addInputAttack(Attack _attack, Integer _val) { inputAttacks.add(_attack); + inputValues.add(_val); + } + + public String toString() { + String ret = name + "/" + type + " Incoming attacks: "; + for (Attack att: inputAttacks) { + ret += att.getName() + " "; + } + + if (resultingAttack == null) { + ret += " No resulting attack"; + } else { + ret += " Resulting attack:" + resultingAttack.getName(); + } + + return ret; } } diff --git a/src/attacktrees/AttackTree.java b/src/attacktrees/AttackTree.java index e14d8cb7a5b805fc1951ae84eb6b51bd15e33f67..60751ec39c8708e215b725a6141080dfb7db410b 100755 --- a/src/attacktrees/AttackTree.java +++ b/src/attacktrees/AttackTree.java @@ -70,5 +70,20 @@ public class AttackTree { attacks.add(_attack); } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("List of nodes:"); + for(AttackNode an: nodes) { + sb.append(" " + an.toString() + "\n"); + } + return sb.toString(); + } + + // Checks: + // Sequence nodes have attacks which are ordered + // Time value is positive in before and after + public boolean checkSyntax() { + } } diff --git a/src/attacktrees/BeforeNode.java b/src/attacktrees/BeforeNode.java index 608d9b83799927efbb828f0c8835b2b3b7d30017..afc3ec40414c3a06e76b162c07868d0944d35bf9 100755 --- a/src/attacktrees/BeforeNode.java +++ b/src/attacktrees/BeforeNode.java @@ -50,8 +50,9 @@ import java.util.*; public class BeforeNode extends TimeNode { - public BeforeNode(String _name, int _time) { - super(_name, _time); + public BeforeNode(String _name, Object _referenceObject, int _time) { + super(_name, _referenceObject, _time); + type = "BEFORE"; } } diff --git a/src/attacktrees/BooleanNode.java b/src/attacktrees/BooleanNode.java index 128d65b3a349b53a1dc1bc17f3d6128c33a8876e..f68908b787d18537d174e60be538bbb4ee7f5b14 100755 --- a/src/attacktrees/BooleanNode.java +++ b/src/attacktrees/BooleanNode.java @@ -50,8 +50,8 @@ import java.util.*; public abstract class BooleanNode extends AttackNode{ - public BooleanNode(String _name) { - super(_name); + public BooleanNode(String _name, Object _referenceObject) { + super(_name, _referenceObject); } diff --git a/src/attacktrees/ORNode.java b/src/attacktrees/ORNode.java index 5e1b64006880ae94396f240dff154e2e0d37017d..31b673e298eb16fe82cd73c598e5b46d0d29477f 100755 --- a/src/attacktrees/ORNode.java +++ b/src/attacktrees/ORNode.java @@ -50,8 +50,9 @@ import java.util.*; public class ORNode extends BooleanNode { - public ORNode(String _name) { - super(_name); + public ORNode(String _name, Object _referenceObject) { + super(_name, _referenceObject); + type = "OR"; } diff --git a/src/attacktrees/SequenceNode.java b/src/attacktrees/SequenceNode.java index 9fa77c9ec0847442d26598a0b8fb11ea47523ec5..eb52b701c9dce413276d8aeaeb2abe4a99c58f8c 100755 --- a/src/attacktrees/SequenceNode.java +++ b/src/attacktrees/SequenceNode.java @@ -48,10 +48,11 @@ package attacktrees; import java.util.*; -public class SequenceNode extends Node { +public class SequenceNode extends AttackNode { - public SequenceNode(String _name) { - super(_name); + public SequenceNode(String _name, Object _referenceObject) { + super(_name, _referenceObject); + type = "SEQUENCE"; } } diff --git a/src/attacktrees/TimeNode.java b/src/attacktrees/TimeNode.java index 4638092656365c7e8c925a0c0a671359c5ca1db0..c90ab30ff74104d5b770dda8926dc2dd761bb7ce 100755 --- a/src/attacktrees/TimeNode.java +++ b/src/attacktrees/TimeNode.java @@ -51,8 +51,8 @@ import java.util.*; public abstract class TimeNode extends AttackNode{ protected int time; - public TimeNode(String _name, int _time) { - super(_name); + public TimeNode(String _name, Object _objectReference, int _time) { + super(_name, _objectReference); time = _time; } diff --git a/src/avatartranslator/AvatarRelation.java b/src/avatartranslator/AvatarRelation.java index 806f73695be81d560c18d4620c4f43329d8e1ff7..3b4c8ffb7d1eaa4a1217ff227891195bf7deb903 100644 --- a/src/avatartranslator/AvatarRelation.java +++ b/src/avatartranslator/AvatarRelation.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class AvatarRelation - * synchronizatio in Avatar ... - * Creation: 20/05/2010 - * @version 1.0 20/05/2010 - * @author Ludovic APVRILLE - * @see - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class AvatarRelation + * synchronizatio in Avatar ... + * Creation: 20/05/2010 + * @version 1.0 20/05/2010 + * @author Ludovic APVRILLE + * @see + */ package avatartranslator; @@ -52,193 +52,193 @@ import java.util.*; import myutil.*; public class AvatarRelation extends AvatarElement { - - + + public AvatarBlock block1, block2; - private LinkedList<AvatarSignal> signals1, signals2; - private boolean blocking, asynchronous, isPrivate, isBroadcast, isLossy; - private int sizeOfFIFO; // -1 means infinite - - + private LinkedList<AvatarSignal> signals1, signals2; + private boolean blocking, asynchronous, isPrivate, isBroadcast, isLossy; + private int sizeOfFIFO; // -1 means infinite + + public AvatarRelation(String _name, AvatarBlock _block1, AvatarBlock _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; - - } - - public boolean containsSignal(AvatarSignal _as) { - return (signals1.contains(_as) || signals2.contains(_as)); - } - - public void setAsynchronous(boolean _b) { - asynchronous = _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 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 AvatarSignal getInSignal(int _index) { - AvatarSignal sig1 = signals1.get(_index); - if (sig1.isIn()) { - return sig1; - } - - return getSignal2(_index); - } - - public AvatarBlock 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 AvatarBlock 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(" ; "); - } - 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; - }*/ - - -} \ No newline at end of file + signals1 = new LinkedList<AvatarSignal>(); + signals2 = new LinkedList<AvatarSignal>(); + block1 = _block1; + block2 = _block2; + blocking = false; + sizeOfFIFO = 1024; + asynchronous = false; + isBroadcast = false; + + } + + public boolean containsSignal(AvatarSignal _as) { + return (signals1.contains(_as) || signals2.contains(_as)); + } + + public void setAsynchronous(boolean _b) { + asynchronous = _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 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 AvatarSignal getInSignal(int _index) { + AvatarSignal sig1 = signals1.get(_index); + if (sig1.isIn()) { + return sig1; + } + + return getSignal2(_index); + } + + public AvatarBlock 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 AvatarBlock 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(" ; "); + } + 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; + }*/ + + +} diff --git a/src/ui/AttackTreePanelTranslator.java b/src/ui/AttackTreePanelTranslator.java index 2f83dfdbe4ed97020e915a017b5618a1a99a14dd..ec17b83ee093f867ef7782f4e20735442d78688e 100644 --- a/src/ui/AttackTreePanelTranslator.java +++ b/src/ui/AttackTreePanelTranslator.java @@ -52,11 +52,12 @@ import ui.atd.*; import attacktrees.*; //import translator.*; import ui.window.*; +import avatartranslator.*; public class AttackTreePanelTranslator { - + protected AttackTree at; protected AttackTreePanel atp; protected Vector checkingErrors, warnings; protected CorrespondanceTGElement listE; // usual list @@ -89,152 +90,349 @@ public class AttackTreePanelTranslator { } public AttackTree translateToAttackTreeDataStructure() { - - AttackTree at = new AttackTree("AttackTree", atp); - - - for(TDiagramPanel panel: atp.panels) { - if (panel instanceof AttackTreeDiagramPanel) { - translate((AttackTreeDiagramPanel)panel); - } - } - - return at; - - } - public void translate(AttackTreeDiagramPanel atdp) { - } + at = new AttackTree("AttackTree", atp); - + for(TDiagramPanel panel: atp.panels) { + if (panel instanceof AttackTreeDiagramPanel) { + translate((AttackTreeDiagramPanel)panel); + } + } - - /*public void createBlocks(AvatarSpecification _as, LinkedList<AvatarBDBlock> _blocks) { - AvatarBlock ab; - Vector v; - TAttribute a; - int i; - AvatarAttribute aa; - ui.AvatarMethod uiam; - ui.AvatarSignal uias; - avatartranslator.AvatarMethod atam; - avatartranslator.AvatarSignal atas; - TGComponent tgc1, tgc2; - Vector types; - - for(AvatarBDBlock block: _blocks) { - ab = new AvatarBlock(block.getBlockName(), block); - _as.addBlock(ab); - listE.addCor(ab, block); - block.setAVATARID(ab.getID()); - - // Create attributes - v = block.getAttributeList(); - for(i=0; i<v.size(); i++) { - a = (TAttribute)(v.elementAt(i)); - if (a.getType() == TAttribute.INTEGER){ - addRegularAttribute(ab, a, ""); - } else if (a.getType() == TAttribute.NATURAL){ - addRegularAttribute(ab, a, ""); - } else if (a.getType() == TAttribute.BOOLEAN) { - addRegularAttribute(ab, a, ""); - } else if (a.getType() == TAttribute.TIMER) { - addRegularAttribute(ab, a, ""); - } else { - // other - //TraceManager.addDev(" -> Other type found: " + a.getTypeOther()); - types = adp.getAvatarBDPanel().getAttributesOfDataType(a.getTypeOther()); - if (types == null) { - CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Unknown data type: " + a.getTypeOther() + " used in " + ab.getName()); - ce.setAvatarBlock(ab); - ce.setTDiagramPanel(adp.getAvatarBDPanel()); + TraceManager.addDev("AT=" + at.toString()); + return at; + + } + + public void translate(AttackTreeDiagramPanel atdp) { + LinkedList<TGComponent> allComponents = (LinkedList<TGComponent>)(atdp.getAllComponentList()); + + int nodeID = 0; + + //Create attacks, nodes + for(TGComponent comp: allComponents) { + if (comp instanceof ATDAttack) { + ATDAttack atdatt = (ATDAttack)comp; + Attack att = new Attack(atdatt.getValue(), atdatt); + att.setRoot(atdatt.isRootAttack()); + at.addAttack(att); + listE.addCor(att, comp); + } + if (comp instanceof ATDConstraint) { + ATDConstraint cons = (ATDConstraint)comp; + nodeID ++; + + //OR + if (cons.isOR()) { + ORNode ornode = new ORNode("OR__" + nodeID, cons); + at.addNode(ornode); + listE.addCor(ornode, comp); + + //AND + } else if (cons.isAND()) { + ANDNode andnode = new ANDNode("AND__" + nodeID, cons); + at.addNode(andnode); + listE.addCor(andnode, comp); + + //SEQUENCE + } else if (cons.isSequence()) { + SequenceNode seqnode = new SequenceNode("SEQUENCE__" + nodeID, cons); + at.addNode(seqnode); + listE.addCor(seqnode, comp); + + //BEFORE + } else if (cons.isBefore()) { + String eq = cons.getEquation(); + int time; + try { + time = Integer.decode(eq).intValue(); + BeforeNode befnode = new BeforeNode("BEFORE__" + nodeID, cons, time); + at.addNode(befnode); + listE.addCor(befnode, comp); + } catch (Exception e) { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Invalid time in before node"); + ce.setTGComponent(comp); + ce.setTDiagramPanel(atdp); addCheckingError(ce); - return; - } else { - if (types.size() ==0) { - CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Data type definition must contain at least one attribute: " + ab.getName()); - ce.setAvatarBlock(ab); - ce.setTDiagramPanel(adp.getAvatarBDPanel()); - addCheckingError(ce); - } else { - for(int j=0; j<types.size(); j++) { - addRegularAttribute(ab, (TAttribute)(types.elementAt(j)), a.getId() + "__"); - } - } } - } - } + //AFTER + } else if (cons.isAfter()) { + String eq = cons.getEquation(); + int time; + try { + time = Integer.decode(eq).intValue(); + BeforeNode befnode = new BeforeNode("AFTER__" + nodeID, cons, time); + at.addNode(befnode); + listE.addCor(befnode, comp); + } catch (Exception e) { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Invalid time in after node"); + ce.setTGComponent(comp); + ce.setTDiagramPanel(atdp); + addCheckingError(ce); + } - // Create methods - v = block.getMethodList(); - for(i=0; i<v.size(); i++) { - uiam = (AvatarMethod)(v.get(i)); - atam = new avatartranslator.AvatarMethod(uiam.getId(), uiam); - atam.setImplementationProvided(uiam.isImplementationProvided()); - ab.addMethod(atam); - makeParameters(ab, atam, uiam); - makeReturnParameters(ab, block, atam, uiam); - } - // Create signals - v = block.getSignalList(); - for(i=0; i<v.size(); i++) { - uias = (AvatarSignal)(v.get(i)); - - if (uias.getInOut() == uias.IN) { - atas = new avatartranslator.AvatarSignal(uias.getId(), avatartranslator.AvatarSignal.IN, uias); - } else { - atas = new avatartranslator.AvatarSignal(uias.getId(), avatartranslator.AvatarSignal.OUT, uias); + } else { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Invalid attack node"); + ce.setTGComponent(comp); + ce.setTDiagramPanel(atdp); + addCheckingError(ce); } - ab.addSignal(atas); - makeParameters(ab, atas, uias); + + } - // Put global code - ab.addGlobalCode(block.getGlobalCode()); } - // Make block hierarchy - for(AvatarBlock block: _as.getListOfBlocks()) { - tgc1 = listE.getTG(block); - if ((tgc1 != null) && (tgc1.getFather() != null)) { - tgc2 = tgc1.getFather(); - ab = listE.getAvatarBlock(tgc2); - if (ab != null) { - block.setFather(ab); + // Making connections between nodes&attacks + TGComponent tgc1, tgc2; + for(TGComponent comp: allComponents) { + if (comp instanceof ATDAttackConnector) { + ATDAttackConnector con = (ATDAttackConnector)(comp); + tgc1 = atdp.getComponentToWhichBelongs(con.getTGConnectingPointP1()); + tgc2 = atdp.getComponentToWhichBelongs(con.getTGConnectingPointP2()); + if ( ((tgc1 instanceof ATDAttack) || (tgc1 instanceof ATDConstraint)) && + ((tgc2 instanceof ATDAttack) || (tgc2 instanceof ATDConstraint)) ) { + try { + // We must transpose this into attack -> node or node -> attack + + // Attack -> attack + if ((tgc1 instanceof ATDAttack) && (tgc2 instanceof ATDAttack)) { + // We link the two attacks with an "and" node + Attack at1 = (Attack)(listE.getObject(tgc1)); + Attack at2 = (Attack)(listE.getObject(tgc2)); + nodeID ++; + ANDNode andnode = new ANDNode("ANDBetweenAttacks__" + nodeID + "__" + at1.getName() + "__" + at2.getName(), tgc1); + at.addNode(andnode); + listE.addCor(andnode, comp); + at1.addDestinationNode(andnode); + at2.setOriginNode(andnode); + andnode.addInputAttack(at1, new Integer("0")); + andnode.setResultingAttack(at2); + + + // Attack -> node + } else if ((tgc1 instanceof ATDAttack) && (tgc2 instanceof ATDConstraint)) { + Attack at1 = (Attack)(listE.getObject(tgc1)); + AttackNode node1 = (AttackNode)(listE.getObject(tgc2)); + at1.addDestinationNode(node1); + String val = comp.getValue().trim(); + if (val.length() == 0) { + val = "0"; + } + node1.addInputAttack(at1, new Integer(val)); + + // Node -> attack + } else if ((tgc1 instanceof ATDConstraint) && (tgc2 instanceof ATDAttack)) { + Attack at1 = (Attack)(listE.getObject(tgc2)); + AttackNode node1 = (AttackNode)(listE.getObject(tgc1)); + at1.setOriginNode(node1); + if (node1.getResultingAttack() != null) { + // Already a resulting attack -> error + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Too many resulting attacks"); + ce.setTGComponent(tgc1); + ce.setTDiagramPanel(atdp); + addCheckingError(ce); + } else { + node1.setResultingAttack(at1); + } + + // Node -> Node + } else if ((tgc1 instanceof ATDConstraint) && (tgc2 instanceof ATDConstraint)) { + AttackNode node1 = (AttackNode)(listE.getObject(tgc1)); + AttackNode node2 = (AttackNode)(listE.getObject(tgc2)); + // Make fake attack + Attack att = new Attack("Attack__from_" + node1.getName() + "_to_" + node2.getName(), tgc1); + att.setRoot(false); + at.addAttack(att); + listE.addCor(att, comp); + + att.setOriginNode(node1); + att.addDestinationNode(node2); + + if (node1.getResultingAttack() != null) { + // Already a resulting attack -> error + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Too many resulting attacks"); + ce.setTGComponent(tgc1); + ce.setTDiagramPanel(atdp); + addCheckingError(ce); + } else { + node1.setResultingAttack(att); + } + + node2.addInputAttack(att, new Integer(0)); + } + + } catch (Exception e) { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Badly formed connector"); + ce.setTGComponent(comp); + ce.setTDiagramPanel(atdp); + addCheckingError(ce); + } } } } - }*/ - + } + + + public AvatarSpecification generateAvatarSpec() { + AvatarSpecification as = new AvatarSpecification("spec from attack trees", atp); + // One block per attacknode + // One block per attack -> syncho + // One mast block with all channels declared at that level + AvatarBlock mainBlock = new AvatarBlock("MainBlock", null); + as.addBlock(mainBlock); + + + + return as; + } + + + + + + + /*public void createBlocks(AvatarSpecification _as, LinkedList<AvatarBDBlock> _blocks) { + AvatarBlock ab; + Vector v; + TAttribute a; + int i; + AvatarAttribute aa; + ui.AvatarMethod uiam; + ui.AvatarSignal uias; + avatartranslator.AvatarMethod atam; + avatartranslator.AvatarSignal atas; + TGComponent tgc1, tgc2; + Vector types; + + for(AvatarBDBlock block: _blocks) { + ab = new AvatarBlock(block.getBlockName(), block); + _as.addBlock(ab); + listE.addCor(ab, block); + block.setAVATARID(ab.getID()); + + // Create attributes + v = block.getAttributeList(); + for(i=0; i<v.size(); i++) { + a = (TAttribute)(v.elementAt(i)); + if (a.getType() == TAttribute.INTEGER){ + addRegularAttribute(ab, a, ""); + } else if (a.getType() == TAttribute.NATURAL){ + addRegularAttribute(ab, a, ""); + } else if (a.getType() == TAttribute.BOOLEAN) { + addRegularAttribute(ab, a, ""); + } else if (a.getType() == TAttribute.TIMER) { + addRegularAttribute(ab, a, ""); + } else { + // other + //TraceManager.addDev(" -> Other type found: " + a.getTypeOther()); + types = adp.getAvatarBDPanel().getAttributesOfDataType(a.getTypeOther()); + if (types == null) { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Unknown data type: " + a.getTypeOther() + " used in " + ab.getName()); + ce.setAvatarBlock(ab); + ce.setTDiagramPanel(adp.getAvatarBDPanel()); + addCheckingError(ce); + return; + } else { + if (types.size() ==0) { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Data type definition must contain at least one attribute: " + ab.getName()); + ce.setAvatarBlock(ab); + ce.setTDiagramPanel(adp.getAvatarBDPanel()); + addCheckingError(ce); + } else { + for(int j=0; j<types.size(); j++) { + addRegularAttribute(ab, (TAttribute)(types.elementAt(j)), a.getId() + "__"); + } + } + } + + } + } + + // Create methods + v = block.getMethodList(); + for(i=0; i<v.size(); i++) { + uiam = (AvatarMethod)(v.get(i)); + atam = new avatartranslator.AvatarMethod(uiam.getId(), uiam); + atam.setImplementationProvided(uiam.isImplementationProvided()); + ab.addMethod(atam); + makeParameters(ab, atam, uiam); + makeReturnParameters(ab, block, atam, uiam); + } + // Create signals + v = block.getSignalList(); + for(i=0; i<v.size(); i++) { + uias = (AvatarSignal)(v.get(i)); + + if (uias.getInOut() == uias.IN) { + atas = new avatartranslator.AvatarSignal(uias.getId(), avatartranslator.AvatarSignal.IN, uias); + } else { + atas = new avatartranslator.AvatarSignal(uias.getId(), avatartranslator.AvatarSignal.OUT, uias); + } + ab.addSignal(atas); + makeParameters(ab, atas, uias); + } + + // Put global code + ab.addGlobalCode(block.getGlobalCode()); + + } + + // Make block hierarchy + for(AvatarBlock block: _as.getListOfBlocks()) { + tgc1 = listE.getTG(block); + if ((tgc1 != null) && (tgc1.getFather() != null)) { + tgc2 = tgc1.getFather(); + ab = listE.getAvatarBlock(tgc2); + if (ab != null) { + block.setFather(ab); + } + } + } + }*/ + + /*} - //TraceManager.addDev("Size of vector:" + v.size()); - for(i=0; i<v.size(); i++) { - aa = _ab.getAvatarAttributeWithName((String)(v.get(i))); - if (aa == null) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Badly formed parameter: " + _name + " in signal expression: " + _idOperator); - ce.setAvatarBlock(_ab); - ce.setTDiagramPanel(_tdp); - ce.setTGComponent(_tgc); - addCheckingError(ce); - return ; - } else { - //TraceManager.addDev("-> Adding attr in action on signal in block " + _ab.getName() + ":" + _name + "__" + tatmp.getId()); - _aaos.addValue((String)(v.get(i))); - } - } + //TraceManager.addDev("Size of vector:" + v.size()); + for(i=0; i<v.size(); i++) { + aa = _ab.getAvatarAttributeWithName((String)(v.get(i))); + if (aa == null) { + CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Badly formed parameter: " + _name + " in signal expression: " + _idOperator); + ce.setAvatarBlock(_ab); + ce.setTDiagramPanel(_tdp); + ce.setTGComponent(_tgc); + addCheckingError(ce); + return ; + } else { + //TraceManager.addDev("-> Adding attr in action on signal in block " + _ab.getName() + ":" + _name + "__" + tatmp.getId()); + _aaos.addValue((String)(v.get(i))); + } + } + + }*/ - }*/ - + private void addCheckingError(CheckingError ce) { + if (checkingErrors == null) { + checkingErrors = new Vector(); + } + checkingErrors.addElement(ce); + } + + private void addWarning(CheckingError ce) { + if (warnings == null) { + warnings = new Vector(); + } + warnings.addElement(ce); + } - } diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java index cda56def8262e501c8a0e8a9cc0d65ea861e510e..64f92097fd857abdbd85c6e61f8e5579525b9cb3 100755 --- a/src/ui/GTURTLEModeling.java +++ b/src/ui/GTURTLEModeling.java @@ -591,6 +591,10 @@ public class GTURTLEModeling { } public boolean generateUPPAALFromAVATAR(String _path) { + if (avatarspec == null) { + TraceManager.addDev("Null avatar spec"); + return false; + } avatar2uppaal = new AVATAR2UPPAAL(avatarspec); //tml2uppaal.setChoiceDeterministic(choices); //tml2uppaal.setSizeInfiniteFIFO(_size); @@ -6333,6 +6337,7 @@ public class GTURTLEModeling { if ((checkingErrors != null) && (checkingErrors.size() > 0)){ return false; } + avatarspec = att.generateAvatarSpec(); return true; } diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java index 61cdb55718d4c8e2343532ff1a5f984e06e8aeea..1f4d059fb5cce6337074c69b3548b49e40969160 100755 --- a/src/ui/MainGUI.java +++ b/src/ui/MainGUI.java @@ -3178,7 +3178,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe ret = true; if (!automatic) { JOptionPane.showMessageDialog(frame, - "0 error, " + getCheckingWarnings().size() + " warning(s). )", + "0 error, " + getCheckingWarnings().size() + " warning(s)", "Syntax analysis successful on attack tree", JOptionPane.INFORMATION_MESSAGE); } diff --git a/src/ui/atd/ATDAttack.java b/src/ui/atd/ATDAttack.java index b9a9241c38579cf96294c595796007a9ae38b191..0f3acaa9cdab3a4a55fa82701c8880224e9cb0c7 100755 --- a/src/ui/atd/ATDAttack.java +++ b/src/ui/atd/ATDAttack.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class ATDAttack - * Attack -> SysML value type - * Creation: 09/12/2009 - * @version 1.0 09/12/2009 - * @author Ludovic APVRILLE - * @see - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class ATDAttack + * Attack -> SysML value type + * Creation: 09/12/2009 + * @version 1.0 09/12/2009 + * @author Ludovic APVRILLE + * @see + */ package ui.atd; @@ -59,32 +59,32 @@ import ui.window.*; public class ATDAttack extends TGCScalableWithInternalComponent implements SwallowedTGComponent, WithAttributes { private int textY1 = 3; private int textY2 = 3; - + private static int arc = 7; - //private int textX = 10; - + //private int textX = 10; + protected String oldValue = ""; protected String description = ""; - private String stereotype = "attack"; - private String rootStereotype = "root attack"; - private boolean isRootAttack = false; - - private static int maxFontSize = 14; - private static int minFontSize = 4; - private int currentFontSize = -1; - private boolean displayText = true; - private int textX = 10; - + private String stereotype = "attack"; + private String rootStereotype = "root attack"; + private boolean isRootAttack = false; + + private static int maxFontSize = 14; + private static int minFontSize = 4; + private int currentFontSize = -1; + private boolean displayText = true; + private int textX = 10; + public ATDAttack(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 = 125; height = (int)(40 * tdp.getZoom()); minWidth = 100; - + nbConnectingPoint = 12; connectingPoint = new TGConnectingPoint[12]; - + connectingPoint[0] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.5, 0.0); connectingPoint[1] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.0, 0.5); connectingPoint[2] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 1.0, 0.5); @@ -98,183 +98,183 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall connectingPoint[10] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.25, 1.0); connectingPoint[11] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.75, 1.0); //addTGConnectingPointsComment(); - + moveable = true; editable = true; removable = true; - + value = "attack01"; - description = "blah blah blah"; - - currentFontSize = -1; - oldScaleFactor = tdp.getZoom(); - + description = "blah blah blah"; + + currentFontSize = -1; + oldScaleFactor = tdp.getZoom(); + myImageIcon = IconManager.imgic702; } - + public void internalDrawing(Graphics g) { - String ster; - if (isRootAttack) { - ster = "<<" + rootStereotype + ">>"; - } else { - ster = "<<" + stereotype + ">>"; - } - Font f = g.getFont(); - Font fold = f; - - if (value != oldValue) { - setValue(value, g); - } - - - if (currentFontSize == -1) { - currentFontSize = f.getSize(); - } - - if ((rescaled) && (!tdp.isScaled())) { - rescaled = false; - - - - // Must set the font size .. - // Find the biggest font not greater than max_font size - // By Increment of 1 - // Or decrement of 1 - // If font is less than 4, no text is displayed - - /*int maxCurrentFontSize = Math.max(0, Math.min(height, maxFontSize)); - int w0, w1, w2; - f = f.deriveFont((float)maxCurrentFontSize); - g.setFont(f); - //System.out.println("max current font size:" + maxCurrentFontSize); - while(maxCurrentFontSize > (minFontSize-1)) { - w0 = g.getFontMetrics().stringWidth(value); - w1 = g.getFontMetrics().stringWidth(ster); - w2 = Math.min(w0, w1); - if (w2 < (width - (2*textX))) { - break; - } - maxCurrentFontSize --; - f = f.deriveFont((float)maxCurrentFontSize); - g.setFont(f); - } - currentFontSize = maxCurrentFontSize; - - if(currentFontSize <minFontSize) { - displayText = false; - } else { - displayText = true; - f = f.deriveFont((float)currentFontSize); - g.setFont(f); - }*/ - - - float scale = (float)(f.getSize()*tdp.getZoom()); - scale = Math.min(maxFontSize, scale); - currentFontSize = (int)scale; - if (scale < minFontSize) { - displayText = false; - } else { - displayText = true; - setValue(value, g); - } - } - - // Core of the attack + String ster; + if (isRootAttack) { + ster = "<<" + rootStereotype + ">>"; + } else { + ster = "<<" + stereotype + ">>"; + } + Font f = g.getFont(); + Font fold = f; + + if (value != oldValue) { + setValue(value, g); + } + + + if (currentFontSize == -1) { + currentFontSize = f.getSize(); + } + + if ((rescaled) && (!tdp.isScaled())) { + rescaled = false; + + + + // Must set the font size .. + // Find the biggest font not greater than max_font size + // By Increment of 1 + // Or decrement of 1 + // If font is less than 4, no text is displayed + + /*int maxCurrentFontSize = Math.max(0, Math.min(height, maxFontSize)); + int w0, w1, w2; + f = f.deriveFont((float)maxCurrentFontSize); + g.setFont(f); + //System.out.println("max current font size:" + maxCurrentFontSize); + while(maxCurrentFontSize > (minFontSize-1)) { + w0 = g.getFontMetrics().stringWidth(value); + w1 = g.getFontMetrics().stringWidth(ster); + w2 = Math.min(w0, w1); + if (w2 < (width - (2*textX))) { + break; + } + maxCurrentFontSize --; + f = f.deriveFont((float)maxCurrentFontSize); + g.setFont(f); + } + currentFontSize = maxCurrentFontSize; + + if(currentFontSize <minFontSize) { + displayText = false; + } else { + displayText = true; + f = f.deriveFont((float)currentFontSize); + g.setFont(f); + }*/ + + + float scale = (float)(f.getSize()*tdp.getZoom()); + scale = Math.min(maxFontSize, scale); + currentFontSize = (int)scale; + if (scale < minFontSize) { + displayText = false; + } else { + displayText = true; + setValue(value, g); + } + } + + // Core of the attack Color c = g.getColor(); - g.draw3DRect(x, y, width, height, true); - if (isRootAttack) { - g.setColor(ColorManager.ATD_ROOT_ATTACK); - } else { - g.setColor(ColorManager.ATD_ATTACK); - } - g.fill3DRect(x+1, y+1, width-1, height-1, true); - g.setColor(c); - + g.draw3DRect(x, y, width, height, true); + if (isRootAttack) { + g.setColor(ColorManager.ATD_ROOT_ATTACK); + } else { + g.setColor(ColorManager.ATD_ATTACK); + } + g.fill3DRect(x+1, y+1, width-1, height-1, true); + g.setColor(c); + // Strings - int w; - - //TraceManager.addDev("display text of attack=" + displayText); - - if (displayText) { - f = f.deriveFont((float)currentFontSize); - g.setFont(f); - //Font f0 = g.getFont(); - - boolean cannotWriteAttack = (height < (2 * currentFontSize + (int)(textY1 * tdp.getZoom()))); - //TraceManager.addDev("Zoom=" + tdp.getZoom() + " Cannot write attack=" + cannotWriteAttack + "Font=" + f0); - - if (cannotWriteAttack) { - w = g.getFontMetrics().stringWidth(value); - int h = currentFontSize + (int)(textY1 * tdp.getZoom()); - if ((w < (2*textX + width)) && (h < height)) { - g.drawString(value, x + (width - w)/2, y + h); - } else { - w = g.getFontMetrics().stringWidth(ster); - if ((w < (2*textX + width)) && (h < height)) { - g.drawString(ster, x + (width - w)/2, y + h); - } - } - } else { - g.setFont(f.deriveFont(Font.BOLD)); - int h = currentFontSize + (int)(textY1 * tdp.getZoom()); - int cumulated = 0; - w = g.getFontMetrics().stringWidth(ster); - if ((w < (2*textX + width)) && (h < height)) { - g.drawString(ster, x + (width - w)/2, y + h); - cumulated = h; - } - g.setFont(f); - w = g.getFontMetrics().stringWidth(value); - h = cumulated + (int)currentFontSize + (int)(textY1 * tdp.getZoom()); - if ((w < (2*textX + width)) && (h < height)) { - //TraceManager.addDev("Drawing value=" + value); - g.drawString(value, x + (width - w)/2, y + h); - } else { - //TraceManager.addDev("--------------------------------------------------- Cannot draw value=" + value); - //TraceManager.addDev("w=" + w + " val=" + (2*textX + width) + "h=" + h + " height=" + height + " zoom=" + tdp.getZoom() + " Font=" + f0); - } - } - } else { - //TraceManager.addDev("-------------------------------------------------- Cannot display text of attack"); - } - - g.setFont(fold); - + int w; + + //TraceManager.addDev("display text of attack=" + displayText); + + if (displayText) { + f = f.deriveFont((float)currentFontSize); + g.setFont(f); + //Font f0 = g.getFont(); + + boolean cannotWriteAttack = (height < (2 * currentFontSize + (int)(textY1 * tdp.getZoom()))); + //TraceManager.addDev("Zoom=" + tdp.getZoom() + " Cannot write attack=" + cannotWriteAttack + "Font=" + f0); + + if (cannotWriteAttack) { + w = g.getFontMetrics().stringWidth(value); + int h = currentFontSize + (int)(textY1 * tdp.getZoom()); + if ((w < (2*textX + width)) && (h < height)) { + g.drawString(value, x + (width - w)/2, y + h); + } else { + w = g.getFontMetrics().stringWidth(ster); + if ((w < (2*textX + width)) && (h < height)) { + g.drawString(ster, x + (width - w)/2, y + h); + } + } + } else { + g.setFont(f.deriveFont(Font.BOLD)); + int h = currentFontSize + (int)(textY1 * tdp.getZoom()); + int cumulated = 0; + w = g.getFontMetrics().stringWidth(ster); + if ((w < (2*textX + width)) && (h < height)) { + g.drawString(ster, x + (width - w)/2, y + h); + cumulated = h; + } + g.setFont(f); + w = g.getFontMetrics().stringWidth(value); + h = cumulated + (int)currentFontSize + (int)(textY1 * tdp.getZoom()); + if ((w < (2*textX + width)) && (h < height)) { + //TraceManager.addDev("Drawing value=" + value); + g.drawString(value, x + (width - w)/2, y + h); + } else { + //TraceManager.addDev("--------------------------------------------------- Cannot draw value=" + value); + //TraceManager.addDev("w=" + w + " val=" + (2*textX + width) + "h=" + h + " height=" + height + " zoom=" + tdp.getZoom() + " Font=" + f0); + } + } + } else { + //TraceManager.addDev("-------------------------------------------------- Cannot display text of attack"); + } + + g.setFont(fold); + } - + public void setValue(String val, Graphics g) { oldValue = value; String ster; - if (isRootAttack) { - ster = "<<" + rootStereotype + ">>"; - } else { - ster = "<<" + stereotype + ">>"; - } - - Font f0 = g.getFont(); - - if (currentFontSize != -1) { - if (currentFontSize != f0.getSize()) { - g.setFont(f0.deriveFont((float)currentFontSize)); - } - } - + if (isRootAttack) { + ster = "<<" + rootStereotype + ">>"; + } else { + ster = "<<" + stereotype + ">>"; + } + + Font f0 = g.getFont(); + + if (currentFontSize != -1) { + if (currentFontSize != f0.getSize()) { + g.setFont(f0.deriveFont((float)currentFontSize)); + } + } + int w = Math.max(g.getFontMetrics().stringWidth(value), g.getFontMetrics().stringWidth(ster)); - int w1 = Math.max((int)(minWidth*tdp.getZoom()), w + 2 * textX); - + int w1 = Math.max((int)(minWidth*tdp.getZoom()), w + 2 * textX); + //System.out.println("width=" + width + " w1=" + w1 + " w2=" + w2 + " value=" + value); - if (w1 != width) { + if (w1 != width) { width = w1; resizeWithFather(); } - - + + g.setFont(f0); - + //System.out.println("width=" + width + " w1=" + w1 + " value=" + value); } - + public void resizeWithFather() { if ((father != null) && (father instanceof ATDBlock)) { //System.out.println("cdRect comp"); @@ -283,84 +283,84 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall setMoveCd(x, y); } } - - - public boolean editOndoubleClick(JFrame frame) { - String tmp; - boolean error = false; - - JDialogAttack dialog = new JDialogAttack(frame, "Setting attack attributes", this); - dialog.setSize(450, 350); + + + public boolean editOndoubleClick(JFrame frame) { + String tmp; + boolean error = false; + + JDialogAttack dialog = new JDialogAttack(frame, "Setting attack attributes", this); + dialog.setSize(450, 350); GraphicLib.centerOnParent(dialog); dialog.show(); // blocked until dialog has been closed - - if (!dialog.isRegularClose()) { - return false; - } - - if (dialog.getName() == null) { - return false; - } - - if (dialog.getName().length() > 0) { - tmp = dialog.getName(); - if (!TAttribute.isAValidId(tmp, false, false)) { - error = true; + + if (!dialog.isRegularClose()) { + return false; + } + + if (dialog.getName() == null) { + return false; + } + + if (dialog.getName().length() > 0) { + tmp = dialog.getName(); + if (!TAttribute.isAValidId(tmp, false, false)) { + error = true; } else { - value = tmp; - } - } - - - if (dialog.getDescription() != null) { - description = dialog.getDescription(); - } - - isRootAttack = dialog.isRootAttack(); - - if (error) { - JOptionPane.showMessageDialog(frame, - "Name is non-valid", - "Error", - JOptionPane.INFORMATION_MESSAGE); - } - - return !error; + value = tmp; + } + } + + + if (dialog.getDescription() != null) { + description = dialog.getDescription(); + } + + isRootAttack = dialog.isRootAttack(); + + if (error) { + JOptionPane.showMessageDialog(frame, + "Name is non-valid", + "Error", + JOptionPane.INFORMATION_MESSAGE); + } + + return !error; } - - public TGComponent isOnOnlyMe(int x1, int y1) { - + + public TGComponent isOnOnlyMe(int x1, int y1) { + if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) { return this; } return null; } - + public int getType() { return TGComponentManager.ATD_ATTACK; } - + protected String translateExtraParam() { StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<info description=\"" + description); - sb.append("\" root=\"" +isRootAttack); + sb.append("\" root=\"" +isRootAttack); sb.append("\" />\n"); sb.append("</extraparam>\n"); return new String(sb); } - + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ //System.out.println("*** load extra synchro ***"); try { - + NodeList nli; Node n1, n2; Element elt; int t1id; String sdescription = null; - String prio; - String isRoot = null; - + String prio; + String isRoot = null; + for(int i=0; i<nl.getLength(); i++) { n1 = nl.item(i); //System.out.println(n1); @@ -373,53 +373,53 @@ public class ATDAttack extends TGCScalableWithInternalComponent implements Swall elt = (Element) n2; if (elt.getTagName().equals("info")) { sdescription = elt.getAttribute("description"); - isRoot = elt.getAttribute("root"); + isRoot = elt.getAttribute("root"); } if (sdescription != null) { description = sdescription; - } - if (isRoot != null) { + } + if (isRoot != null) { if (isRoot.toUpperCase().compareTo("TRUE") == 0) { - isRootAttack = true; - } else { - isRootAttack = false; - } - } + isRootAttack = true; + } else { + isRootAttack = false; + } + } } } } } - + } catch (Exception e) { throw new MalformedModelingException(); } } - - - public String getDescription() { + + + public String getDescription() { return description; } - - public void setDescription(String _description) { + + public void setDescription(String _description) { description = _description; } - + public String getAttackName() { return value; } - - public String getAttributes() { - String s = "Description = " + description + "\n"; - s += "Id=" + getId(); - return s; - } - - - public boolean isRootAttack() { - return isRootAttack; - } - - - - + + public String getAttributes() { + String s = "Description = " + description + "\n"; + s += "Id=" + getId(); + return s; + } + + + public boolean isRootAttack() { + return isRootAttack; + } + + + + } diff --git a/src/ui/atd/ATDAttackConnector.java b/src/ui/atd/ATDAttackConnector.java index 710e12431cbb683522703414b7f1c79ab085dd7e..31891fd6c7fe75979716b38d34be12009e504723 100755 --- a/src/ui/atd/ATDAttackConnector.java +++ b/src/ui/atd/ATDAttackConnector.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class ATDAttackConnector - * Connector used in Attack Tree Diagrams - * Creation: 09/12/2009 - * @version 1.0 09/12/2009 - * @author Ludovic APVRILLE - * @see - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class ATDAttackConnector + * Connector used in Attack Tree Diagrams + * Creation: 09/12/2009 + * @version 1.0 09/12/2009 + * @author Ludovic APVRILLE + * @see + */ package ui.atd; @@ -63,159 +63,159 @@ import ui.window.*; public class ATDAttackConnector extends TGConnectorWithCommentConnectionPoints implements ScalableTGComponent { //protected int arrowLength = 10; //protected int widthValue, heightValue, maxWidthValue, h; - protected int c = 5; //square length - protected double oldScaleFactor; - protected int fontSize = 12; - - + protected int c = 5; //square length + protected double oldScaleFactor; + protected int fontSize = 12; + + public ATDAttackConnector(int _x, int _y, int _minX, int _minY, int _maxX, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp, TGConnectingPoint _p1, TGConnectingPoint _p2, Vector _listPoint) { super(_x, _y, _minX, _minY, _maxX, _maxY, _pos, _father, _tdp, _p1, _p2, _listPoint); myImageIcon = IconManager.imgic202; value = ""; editable = true; - oldScaleFactor = tdp.getZoom(); + oldScaleFactor = tdp.getZoom(); } - + protected void drawLastSegment(Graphics g, int x1, int y1, int x2, int y2){ /*if (Point2D.distance(x1, y1, x2, y2) < GraphicLib.longueur * 1.5) { - g.drawLine(x1, y1, x2, y2); - } else { - GraphicLib.arrowWithLine(g, 1, 0, 10, x1, y1, x2, y2, true); - }*/ - - //g.drawLine(x1, y1, x2, y2); - int cz = (int)(tdp.getZoom() * c); - - // white squares only if ATDConstraint - - TGConnectingPoint cp = p1; - CDElement comp = cp.getFather(); - int decX = 0; - int decY = 0; - // Origin = constraint? - if (comp instanceof ATDConstraint) { - if (comp.getX() == cp.getX()) { - decX = 0; - } else if (comp.getX() + comp.getWidth() == cp.getX()) { - decX = -cz; - } else { - decX = -cz/2; - } - - if (comp.getY() == cp.getY()) { - decY = 0; - } else if (comp.getY() + comp.getHeight() == cp.getY()) { - decY = -cz; - } else { - decY = -cz/2; - } - - g.drawRect(cp.getX() + decX, cp.getY() + decY, cz, cz); - } - cp = p2; - comp = cp.getFather(); - if (comp instanceof ATDConstraint) { - if (comp.getX() == cp.getX()) { - decX = 0; - } else if (comp.getX() + comp.getWidth() == cp.getX()) { - decX = -cz; - } else { - decX = -cz/2; - } - - if (comp.getY() == cp.getY()) { - decY = 0; - } else if (comp.getY() + comp.getHeight() == cp.getY()) { - decY = -cz; - } else { - decY = -cz/2; - } - g.drawRect(x2+decX, y2+decY, cz, cz); - } - - - /*g.fillRect(x2-(cz/2), y2-(cz/2), cz, cz); - g.fillRect(p1.getX()-(cz/2), p1.getY()-(cz/2), cz, cz);*/ - - Point p = new Point(x2, y2); - if (p == null) { - //System.out.println("null point"); - } else { - if (Point2D.distance(x1, y1, p.x, p.y) < GraphicLib.longueur * 1.5) { - //System.out.println("p.x=" + p.x + " x1=" + x1 + "p.y=" + p.y + " y1=" + y1); - if ((p.x != x1) || (p.y != y1)) { - g.drawLine(x1, y1, p.x, p.y); - //System.out.println("drawn"); - } + g.drawLine(x1, y1, x2, y2); + } else { + GraphicLib.arrowWithLine(g, 1, 0, 10, x1, y1, x2, y2, true); + }*/ + + //g.drawLine(x1, y1, x2, y2); + int cz = (int)(tdp.getZoom() * c); + + // white squares only if ATDConstraint + + TGConnectingPoint cp = p1; + CDElement comp = cp.getFather(); + int decX = 0; + int decY = 0; + // Origin = constraint? + if (comp instanceof ATDConstraint) { + if (comp.getX() == cp.getX()) { + decX = 0; + } else if (comp.getX() + comp.getWidth() == cp.getX()) { + decX = -cz; + } else { + decX = -cz/2; + } + + if (comp.getY() == cp.getY()) { + decY = 0; + } else if (comp.getY() + comp.getHeight() == cp.getY()) { + decY = -cz; + } else { + decY = -cz/2; + } + + g.drawRect(cp.getX() + decX, cp.getY() + decY, cz, cz); + } + cp = p2; + comp = cp.getFather(); + if (comp instanceof ATDConstraint) { + if (comp.getX() == cp.getX()) { + decX = 0; + } else if (comp.getX() + comp.getWidth() == cp.getX()) { + decX = -cz; + } else { + decX = -cz/2; + } + + if (comp.getY() == cp.getY()) { + decY = 0; + } else if (comp.getY() + comp.getHeight() == cp.getY()) { + decY = -cz; + } else { + decY = -cz/2; + } + g.drawRect(x2+decX, y2+decY, cz, cz); + } + + + /*g.fillRect(x2-(cz/2), y2-(cz/2), cz, cz); + g.fillRect(p1.getX()-(cz/2), p1.getY()-(cz/2), cz, cz);*/ + + Point p = new Point(x2, y2); + if (p == null) { + //System.out.println("null point"); } else { - GraphicLib.arrowWithLine(g, 1, 0, 10, x1, y1, p.x, p.y, true); + if (Point2D.distance(x1, y1, p.x, p.y) < GraphicLib.longueur * 1.5) { + //System.out.println("p.x=" + p.x + " x1=" + x1 + "p.y=" + p.y + " y1=" + y1); + if ((p.x != x1) || (p.y != y1)) { + g.drawLine(x1, y1, p.x, p.y); + //System.out.println("drawn"); + } + } else { + GraphicLib.arrowWithLine(g, 1, 0, 10, x1, y1, p.x, p.y, true); + } + } + + if (value.length() > 0) { + Font f = g.getFont(); + if (tdp.getZoom() < 1) { + Font f0 = f.deriveFont((float)(fontSize*tdp.getZoom())); + g.setFont(f0); + } + g.drawString(value, x2+(cz/2)+1, y2); + g.setFont(f); } - } - - if (value.length() > 0) { - Font f = g.getFont(); - if (tdp.getZoom() < 1) { - Font f0 = f.deriveFont((float)(fontSize*tdp.getZoom())); - g.setFont(f0); - } - g.drawString(value, x2+(cz/2)+1, y2); - g.setFont(f); - } - + } - - public boolean editOndoubleClick(JFrame frame) { + + public boolean editOndoubleClick(JFrame frame) { String oldValue = value; String text = getName() + "Connector"; String s = (String)JOptionPane.showInputDialog(frame, text, - "Setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, - null, - getValue()); - + "Setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, + null, + getValue()); + if (s != null) { s = Conversion.removeFirstSpaces(s); } - - //System.out.println("emptytext=" + emptyText); - + + //System.out.println("emptytext=" + emptyText); + if ((s != null) && (!s.equals(oldValue))) { setValue(s); return true; } - + return false; } - - + + public int getType() { return TGComponentManager.ATD_ATTACK_CONNECTOR; } - - public void rescale(double scaleFactor){ - //System.out.println("Rescale connector"); - int xx, yy; - - for(int i=0; i<nbInternalTGComponent; i++) { - xx = tgcomponent[i].getX(); - yy = tgcomponent[i].getY(); - //System.out.println("Internal comp xx= " + xx + " y==" + yy); - tgcomponent[i].dx = (tgcomponent[i].dx + xx) / oldScaleFactor * scaleFactor; - tgcomponent[i].dy = (tgcomponent[i].dy + yy) / oldScaleFactor * scaleFactor; - xx = (int)(tgcomponent[i].dx); - tgcomponent[i].dx = tgcomponent[i].dx - xx; - yy = (int)(tgcomponent[i].dy); - tgcomponent[i].dy = tgcomponent[i].dy - yy; - - tgcomponent[i].setCd(xx, yy); - - //System.out.println("Internal comp xx= " + xx + " y==" + yy); + + public void rescale(double scaleFactor){ + //System.out.println("Rescale connector"); + int xx, yy; + + for(int i=0; i<nbInternalTGComponent; i++) { + xx = tgcomponent[i].getX(); + yy = tgcomponent[i].getY(); + //System.out.println("Internal comp xx= " + xx + " y==" + yy); + tgcomponent[i].dx = (tgcomponent[i].dx + xx) / oldScaleFactor * scaleFactor; + tgcomponent[i].dy = (tgcomponent[i].dy + yy) / oldScaleFactor * scaleFactor; + xx = (int)(tgcomponent[i].dx); + tgcomponent[i].dx = tgcomponent[i].dx - xx; + yy = (int)(tgcomponent[i].dy); + tgcomponent[i].dy = tgcomponent[i].dy - yy; + + tgcomponent[i].setCd(xx, yy); + + //System.out.println("Internal comp xx= " + xx + " y==" + yy); } - - oldScaleFactor = scaleFactor; - } - - + oldScaleFactor = scaleFactor; + } + + + + - } diff --git a/src/ui/atd/ATDConstraint.java b/src/ui/atd/ATDConstraint.java index cb1f896959d22568dfca6515f9756620304420bd..42b8d0d896286f53e6632c7f1dbda59e69474030 100755 --- a/src/ui/atd/ATDConstraint.java +++ b/src/ui/atd/ATDConstraint.java @@ -1,48 +1,48 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class ATDConstraint - * Constraint of SysML Parametric diagrams, adapted to attack trees - * Creation: 11/12/2009 - * @version 1.0 11/12/2009 - * @author Ludovic APVRILLE - * @see - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class ATDConstraint + * Constraint of SysML Parametric diagrams, adapted to attack trees + * Creation: 11/12/2009 + * @version 1.0 11/12/2009 + * @author Ludovic APVRILLE + * @see + */ package ui.atd; @@ -59,31 +59,31 @@ import ui.window.*; public class ATDConstraint extends TGCScalableWithInternalComponent implements SwallowedTGComponent, ConstraintListInterface { private int textY1 = 5; //private int textY2 = 30; - - public static final String[] STEREOTYPES = {"<<OR>>", "<<AND>>", "<<SEQUENCE>>", "<<BEFORE>>", "<<AFTER>>"}; - + + public static final String[] STEREOTYPES = {"<<OR>>", "<<AND>>", "<<SEQUENCE>>", "<<BEFORE>>", "<<AFTER>>"}; + protected String oldValue = ""; - - private static int maxFontSize = 14; - private static int minFontSize = 4; - private int currentFontSize = -1; - private boolean displayText = true; - private int textX = 1; - - private static int arc = 7; - - private String equation; - + + private static int maxFontSize = 14; + private static int minFontSize = 4; + private int currentFontSize = -1; + private boolean displayText = true; + private int textX = 1; + + private static int arc = 7; + + private String equation; + public ATDConstraint(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 = (int)(150* tdp.getZoom()); height = (int)(50 * tdp.getZoom()); minWidth = 100; - + nbConnectingPoint = 12; connectingPoint = new TGConnectingPoint[12]; - + connectingPoint[0] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.5, 0.0); connectingPoint[1] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.0, 0.5); connectingPoint[2] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 1.0, 0.5); @@ -97,162 +97,182 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements connectingPoint[10] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.25, 1.0); connectingPoint[11] = new ATDAttackConnectingPoint(this, 0, 0, true, true, 0.75, 1.0); //addTGConnectingPointsComment(); - + moveable = true; editable = true; removable = true; - + value = "<<OR>>"; equation = ""; - - currentFontSize = -1; - oldScaleFactor = tdp.getZoom(); - + + currentFontSize = -1; + oldScaleFactor = tdp.getZoom(); + myImageIcon = IconManager.imgic1078; } - + public void internalDrawing(Graphics g) { - - Font f = g.getFont(); - Font fold = f; - - if (currentFontSize == -1) { - currentFontSize = f.getSize(); - } - - if ((rescaled) && (!tdp.isScaled())) { - - rescaled = false; - - float scale = (float)(f.getSize()*tdp.getZoom()); - scale = Math.min(maxFontSize, scale); - currentFontSize = (int)scale; - if (scale < minFontSize) { - displayText = false; - } else { - displayText = true; - } - } - + + Font f = g.getFont(); + Font fold = f; + + if (currentFontSize == -1) { + currentFontSize = f.getSize(); + } + + if ((rescaled) && (!tdp.isScaled())) { + + rescaled = false; + + float scale = (float)(f.getSize()*tdp.getZoom()); + scale = Math.min(maxFontSize, scale); + currentFontSize = (int)scale; + if (scale < minFontSize) { + displayText = false; + } else { + displayText = true; + } + } + Color c = g.getColor(); - //g.draw3DRect(x, y, width, height, true); - g.setColor(ColorManager.ATD_CONSTRAINT); - g.fillRoundRect(x, y, width, height, arc, arc); - g.setColor(c); - g.drawRoundRect(x, y, width, height, arc, arc); - - g.setColor(ColorManager.ATD_CONSTRAINT); - //g.fill3DRect(x+1, y+1, width-1, height-1, true); - - g.setColor(c); - - Font f0 = g.getFont(); - if (displayText) { - f = f.deriveFont(currentFontSize); - g.setFont(f.deriveFont(Font.BOLD)); - int w = g.getFontMetrics().stringWidth(value); - g.drawString(value, x + (width - w)/2, y + currentFontSize + (int)(textY1*tdp.getZoom())); - g.setFont(f0.deriveFont(f0.getSize()-2).deriveFont(Font.ITALIC)); - w = g.getFontMetrics().stringWidth(equation); - if (w >= width) { - w = g.getFontMetrics().stringWidth("..."); - g.drawString("...", x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); - } else { - g.drawString(equation, x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); - } - g.setFont(f0); - } - - } - - /* public void setValue(String val, Graphics g) { - oldValue = value; - int w = g.getFontMetrics().stringWidth(value); - int w1 = Math.max(minWidth, w + 2 * textX + fileX + space); - - //System.out.println("width=" + width + " w1=" + w1 + " w2=" + w2 + " value=" + value); - if (w1 != width) { - width = w1; - resizeWithFather(); + //g.draw3DRect(x, y, width, height, true); + g.setColor(ColorManager.ATD_CONSTRAINT); + g.fillRoundRect(x, y, width, height, arc, arc); + g.setColor(c); + g.drawRoundRect(x, y, width, height, arc, arc); + + g.setColor(ColorManager.ATD_CONSTRAINT); + //g.fill3DRect(x+1, y+1, width-1, height-1, true); + + g.setColor(c); + + Font f0 = g.getFont(); + if (displayText) { + f = f.deriveFont(currentFontSize); + g.setFont(f.deriveFont(Font.BOLD)); + int w = g.getFontMetrics().stringWidth(value); + g.drawString(value, x + (width - w)/2, y + currentFontSize + (int)(textY1*tdp.getZoom())); + g.setFont(f0.deriveFont(f0.getSize()-2).deriveFont(Font.ITALIC)); + w = g.getFontMetrics().stringWidth(equation); + if (w >= width) { + w = g.getFontMetrics().stringWidth("..."); + g.drawString("...", x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); + } else { + g.drawString(equation, x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); + } + g.setFont(f0); } - //System.out.println("width=" + width + " w1=" + w1 + " value=" + value); - }*/ - - - - - public boolean editOndoubleClick(JFrame frame) { - String tmp; - boolean error = false; - - JDialogConstraintText dialog = new JDialogConstraintText(frame, "Setting constraint attributes", (ConstraintListInterface)this, equation, "Equation"); - dialog.setSize(450, 350); + + } + + /* public void setValue(String val, Graphics g) { + oldValue = value; + int w = g.getFontMetrics().stringWidth(value); + int w1 = Math.max(minWidth, w + 2 * textX + fileX + space); + + //System.out.println("width=" + width + " w1=" + w1 + " w2=" + w2 + " value=" + value); + if (w1 != width) { + width = w1; + resizeWithFather(); + } + //System.out.println("width=" + width + " w1=" + w1 + " value=" + value); + }*/ + + + + + public boolean editOndoubleClick(JFrame frame) { + String tmp; + boolean error = false; + + JDialogConstraintText dialog = new JDialogConstraintText(frame, "Setting constraint attributes", (ConstraintListInterface)this, equation, "Equation"); + dialog.setSize(450, 350); GraphicLib.centerOnParent(dialog); dialog.show(); // blocked until dialog has been closed - - if (!dialog.isRegularClose()) { - return false; - } - - if (dialog.getStereotype() == null) { - return false; - } - - if (dialog.getStereotype().length() > 0) { - value = dialog.getStereotype(); - } - - equation = dialog.getText(); - - rescaled = true; - - return true; + + if (!dialog.isRegularClose()) { + return false; + } + + if (dialog.getStereotype() == null) { + return false; + } + + if (dialog.getStereotype().length() > 0) { + value = dialog.getStereotype(); + } + + equation = dialog.getText(); + + rescaled = true; + + return true; } - + public TGComponent isOnOnlyMe(int x1, int y1) { - + if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) { return this; } return null; } - + public int getType() { return TGComponentManager.ATD_CONSTRAINT; } - - public String[] getConstraintList() { - return STEREOTYPES; - } - - public String getCurrentConstraint() { - return value; - } - - public String getEquation() { - return equation; - } - - protected String translateExtraParam() { + + public String[] getConstraintList() { + return STEREOTYPES; + } + + public String getCurrentConstraint() { + return value; + } + + public String getEquation() { + return equation; + } + + public boolean isOR() { + return (value.compareTo(STEREOTYPES[0]) == 0); + } + + public boolean isAND() { + return (value.compareTo(STEREOTYPES[1]) == 0); + } + + public boolean isSequence() { + return (value.compareTo(STEREOTYPES[2]) == 0); + } + + public boolean isBefore() { + return (value.compareTo(STEREOTYPES[3]) == 0); + } + + public boolean isAfter() { + return (value.compareTo(STEREOTYPES[4]) == 0); + } + + protected String translateExtraParam() { StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<info equation=\"" + GTURTLEModeling.transformString(getEquation())); sb.append("\" />\n"); sb.append("</extraparam>\n"); return new String(sb); } - + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ //System.out.println("*** load extra synchro ***"); try { - + NodeList nli; Node n1, n2; Element elt; int t1id; String sdescription = null; - String prio; - String isRoot = null; - + String prio; + String isRoot = null; + for(int i=0; i<nl.getLength(); i++) { n1 = nl.item(i); //System.out.println(n1); @@ -270,12 +290,12 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements } } } - + } catch (Exception e) { throw new MalformedModelingException(); } } - + public void resizeWithFather() { if ((father != null) && (father instanceof ATDBlock)) { //System.out.println("cdRect comp"); @@ -284,6 +304,6 @@ public class ATDConstraint extends TGCScalableWithInternalComponent implements setMoveCd(x, y); } } - - + + }