diff --git a/src/avatartranslator/AvatarLibraryFunction.java b/src/avatartranslator/AvatarLibraryFunction.java
index d14a89eb69276c668752c522c184077fe58bee24..ea7bcb180e055925dac5eabf990b699cc49f41c8 100644
--- a/src/avatartranslator/AvatarLibraryFunction.java
+++ b/src/avatartranslator/AvatarLibraryFunction.java
@@ -89,6 +89,12 @@ public class AvatarLibraryFunction extends AvatarElement implements AvatarTransl
      */
     private LinkedList<AvatarAttribute> returnAttributes;
 
+    /**
+     * The list of methods that can be used by the function.
+     *
+     */
+    private LinkedList<AvatarMethod> methods;
+
     /**
      * The state machine describing the behaviour of the function.
      */
diff --git a/src/avatartranslator/AvatarMethod.java b/src/avatartranslator/AvatarMethod.java
index 3e6f1dd388a12b1dd1285d533a00fc76b4aaedc1..297e12bb0eea185215691eddd5e3a8804d190aff 100644
--- a/src/avatartranslator/AvatarMethod.java
+++ b/src/avatartranslator/AvatarMethod.java
@@ -51,7 +51,7 @@ import java.util.*;
 
 import myutil.*;
 
-public class AvatarMethod extends AvatarElement{
+public class AvatarMethod extends AvatarElement {
 
     protected boolean implementationProvided;
 
diff --git a/src/ui/AvatarDesignPanelTranslator.java b/src/ui/AvatarDesignPanelTranslator.java
index 971be016f18fcb6478baef99378fee673abc9273..34dc0dfc372c2369431cd5a8148f6826e7b508bd 100644
--- a/src/ui/AvatarDesignPanelTranslator.java
+++ b/src/ui/AvatarDesignPanelTranslator.java
@@ -90,10 +90,16 @@ public class AvatarDesignPanelTranslator {
         return listE;
     }
 
-    public AvatarSpecification generateAvatarSpecification(Vector _blocks) {
+    public AvatarSpecification generateAvatarSpecification(Vector<AvatarBDStateMachineOwner> _blocks) {
         LinkedList<AvatarBDBlock> blocks = new LinkedList<AvatarBDBlock>();
+        LinkedList<AvatarBDLibraryFunction> libraryFunctions = new LinkedList<AvatarBDLibraryFunction>();
+
+        for (AvatarBDStateMachineOwner owner: _blocks)
+            if (owner instanceof AvatarBDBlock)
+                blocks.add ((AvatarBDBlock) owner);
+            else
+                libraryFunctions.add ((AvatarBDLibraryFunction) owner);
 
-        blocks.addAll(_blocks);
         AvatarSpecification as = new AvatarSpecification("avatarspecification", adp);
 
         if (adp != null) {
@@ -104,6 +110,7 @@ public class AvatarDesignPanelTranslator {
         }
 	typeAttributesMap = new HashMap<String, Vector>();
 	nameTypeMap = new HashMap<String,String>();
+        createLibraryFunctions (as, libraryFunctions);
         createBlocks(as, blocks);
         createRelationsBetweenBlocks(as, blocks);
         makeBlockStateMachines(as);
@@ -466,6 +473,10 @@ public class AvatarDesignPanelTranslator {
         _ab.addAttribute(aa);
     }
 
+    public void createLibraryFunctions (AvatarSpecification _as, LinkedList<AvatarBDLibraryFunction> _libraryFunctions) {
+        // TODO: translate this as a block
+    }
+
     public void createBlocks(AvatarSpecification _as, LinkedList<AvatarBDBlock> _blocks) {
         AvatarBlock ab;
         Vector v;
diff --git a/src/ui/AvatarMethod.java b/src/ui/AvatarMethod.java
index 9e210a0f7a815bbccee52de18b915b6069c893b6..b5bbb0e1c32ed6c0e3b75ba865eb55cd765f9343 100644
--- a/src/ui/AvatarMethod.java
+++ b/src/ui/AvatarMethod.java
@@ -55,6 +55,27 @@ import myutil.*;
 
 public class AvatarMethod {
 
+    public static final String[] cryptoMethods = {
+        "Message aencrypt(Message msg, Key k)",
+        "Message adecrypt(Message msg, Key k)",
+        "Key pk(Key k)",
+        "Message sign(Message msg, Key k)",
+        "bool verifySign(Message msg1, Message sig, Key k)",
+        "Message cert(Key k, Message msg)",
+        "bool verifyCert(Message cert, Key k)",
+        "Key getpk(Message cert)",
+        "Message sencrypt(Message msg, Key k)",
+        "Message sdecrypt(Message msg, Key k)",
+        "Message hash(Message msg)",
+        "Message MAC(Message msg, Key k)",
+        "bool verifyMAC(Message msg, Key k, Message macmsg)",
+        "Message concat2(Message msg1, Message msg2)",
+        "Message concat3(Message msg1, Message msg2, Message msg3)",
+        "Message concat4(Message msg1, Message msg2, Message msg3, Message msg4)",
+        "get2(Message msg, Message msg1, Message msg2)",
+        "get3(Message msg, Message msg1, Message msg2, Message msg3)",
+        "get4(Message msg, Message msg1, Message msg2, Message msg3, Message msg4)"};
+        
     // Types of parameters
     public final static int NATURAL = 0;
     public final static int BOOLEAN = 1;
diff --git a/src/ui/ColorManager.java b/src/ui/ColorManager.java
index 48a3835eb1934cf24b36369b38462ec6ff3628e9..a6cc20c25262676b3d6d7f1eba117e8c9476d8cf 100755
--- a/src/ui/ColorManager.java
+++ b/src/ui/ColorManager.java
@@ -152,6 +152,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_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);
     public static  Color AVATAR_SEND_SIGNAL = new Color(128, 180, 205);
diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java
index d7b9456dabee5e587e904f37e239d7b9b17d688a..8d3f7e3149debe4191535a0d750475c83fc2a712 100755
--- a/src/ui/GTURTLEModeling.java
+++ b/src/ui/GTURTLEModeling.java
@@ -1920,7 +1920,7 @@ public class GTURTLEModeling {
     }
 
     // BUILDING An AVATAR Design AND CHECKING IT
-    public boolean checkAvatarDesign(Vector blocks, AvatarDesignPanel adp, boolean _optimize) {
+    public boolean checkAvatarDesign(Vector<AvatarBDStateMachineOwner> blocks, AvatarDesignPanel adp, boolean _optimize) {
         // Builds a TURTLE modeling from diagrams
         //warnings = new Vector();
         //checkingErrors = null;
diff --git a/src/ui/IconManager.java b/src/ui/IconManager.java
index 95301cac9e8e88d1df8dc7171080699f558e0ce9..c5ebc8da3df4a27c872c82c3846226456ed65559 100755
--- a/src/ui/IconManager.java
+++ b/src/ui/IconManager.java
@@ -148,6 +148,7 @@ public class IconManager {
     public static ImageIcon imgic5040, imgic5042, imgic5044, imgic5046, imgic5048;
     public static ImageIcon imgic5050, imgic5052, imgic5054, imgic5056, imgic5058;
     public static ImageIcon imgic5060, imgic5062, imgic5064, imgic5066, imgic5068;
+    public static ImageIcon imgic5070;
 
     public static ImageIcon imgic5100, imgic5102, imgic5104, imgic5106, imgic5108;
     public static ImageIcon imgic5110, imgic5112, imgic5113,imgic5114;
@@ -524,6 +525,8 @@ public class IconManager {
 
 
     // AVATAR
+    public static final int iconSize = 15;
+
     private static String icon5000 = "images/avatarblock.gif";
     private static String icon5002 = "images/avatarbdcomp.gif";
     private static String icon5004 = "images/avatarbdlink.gif";
@@ -559,6 +562,7 @@ public class IconManager {
     private static String icon5064 = "images/avatarmadversioning.gif";
     private static String icon5066 = "images/avatarmadimpact.gif";
     private static String icon5068 = "images/avatarrdref.gif";
+    private static String icon5070 = "images/avatarlibfunction.gif";
 
     private static String icon5100 = "images/avatarhead16.gif";
     private static String icon5102 = "images/avatarhead32.gif";
@@ -954,6 +958,7 @@ public class IconManager {
         imgic5064 = getIcon(icon5064);
         imgic5066 = getIcon(icon5066);
 	imgic5068 = getIcon(icon5068);
+	imgic5070 = getIcon(icon5070);
 
         imgic5100 = getIcon(icon5100);
         imgic5102 = getIcon(icon5102);
diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java
index 4b86a4e9a2fc56f0a42fd45533fa103d2b3c20d6..be21a47f40f96d35c0a788a0fdd5354b036ac2d3 100755
--- a/src/ui/MainGUI.java
+++ b/src/ui/MainGUI.java
@@ -151,7 +151,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
     public  KeyListener keyHandler;
 
     // Validation
-    public Vector tclassesToValidate = new Vector();
+    public Vector<AvatarBDStateMachineOwner> tclassesToValidate = new Vector<AvatarBDStateMachineOwner> ();
 
     // Status bar
     private     JLabel status;
@@ -1848,7 +1848,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
             activetdp = null;
 
             gtm = null;
-            tclassesToValidate = new Vector();
+            tclassesToValidate = new Vector<AvatarBDStateMachineOwner> ();
             MasterGateManager.reinitNameRestriction();
 
             typeButtonSelected = - 1;
@@ -3208,7 +3208,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
             DesignPanel dp = (DesignPanel)tp;
             JDialogModelChecking.validated = dp.validated;
             JDialogModelChecking.ignored = dp.ignored;
-            tclassesToValidate = new Vector();
+            tclassesToValidate = new Vector<AvatarBDStateMachineOwner> ();
             JDialogModelChecking jdmc = new JDialogModelChecking(frame, tclassesToValidate,dp.tcdp.getComponentList(), "Choosing Tclasses to validate");
             if (!automatic) {
                 GraphicLib.centerOnParent(jdmc);
@@ -3292,7 +3292,7 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
             //JDialogModelChecking.validated = adp.validated;
             //JDialogModelChecking.ignored = adp.ignored;
             tclassesToValidate = new Vector();
-            JDialogSelectAvatarBlock jdmc = new JDialogSelectAvatarBlock(frame, tclassesToValidate, adp.getAvatarBDPanel().getFullBlockList(), "Choosing blocks to validate", adp.getValidated(), adp.getIgnored(), adp.getOptimized());
+            JDialogSelectAvatarBlock jdmc = new JDialogSelectAvatarBlock(frame, tclassesToValidate, adp.getAvatarBDPanel().getFullStateMachineOwnerList(), "Choosing blocks to validate", adp.getValidated(), adp.getIgnored(), adp.getOptimized());
             if (!automatic) {
                 GraphicLib.centerOnParent(jdmc);
                 jdmc.setVisible(true); // blocked until dialog has been closed
@@ -3321,18 +3321,20 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
                     setMode(MainGUI.AVATAR_SYNTAXCHECKING_OK);
                     //setMode(MainGUI.MODEL_PROVERIF_OK);
                     //setMode(MainGUI.GEN_DESIGN_OK);
+                    /*
                     if (!automatic) {
                         JOptionPane.showMessageDialog(frame,
                                                       "0 error, " + getCheckingWarnings().size() + " warning(s). You can now perform simulations or formal proofs (UPPAAL)",
                                                       "Syntax analysis successful on avatar design diagrams",
                                                       JOptionPane.INFORMATION_MESSAGE);
                     }
+                    */
                 } else {
                     if (!automatic) {
                         JOptionPane.showMessageDialog(frame,
                                                       "The Avatar modeling contains several errors",
                                                       "Syntax analysis failed",
-                                                      JOptionPane.INFORMATION_MESSAGE);
+                                                      JOptionPane.ERROR_MESSAGE);
                     }
                 }
             }
@@ -5247,16 +5249,6 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
         return idButtonSelected;
     }
 
-    public void addAvatarBlock(TURTLEPanel tp, String s)        {
-        //TraceManager.addDev("ADD TML Task=" + s);
-        if (!(tp instanceof AvatarDesignPanel)) {
-            return;
-        }
-
-        ((AvatarDesignPanel)tp).addAvatarStateMachineDiagramPanel(s);
-        setPanelMode();
-    }
-
     public void addTClass(TURTLEPanel tp, String s)     {
         if (!(tp instanceof DesignPanel)) {
             return;
@@ -7017,43 +7009,6 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
         return false;
     }
 
-    public boolean newAvatarBDBlockName(TURTLEPanel tp, String old, String niou) {
-        //TraceManager.addDev("Panel=" + tp + " Old  task name = " + old + " New task name=" + niou);
-        JTabbedPane jtp = tp.tabbedPane;
-        int i;
-        for(i = 0; i<jtp.getTabCount(); i++) {
-            //TraceManager.addDev("jtp  = " + jtp.getTitleAt(i));
-            if (jtp.getTitleAt(i).equals(niou)) {
-                return false;
-            }
-        }
-        //TraceManager.addDev("old " + old + " niou " + niou);
-        //TraceManager.addDev("nb Of panels:"+ jtp.getTabCount());
-        for(i = 0; i<jtp.getTabCount(); i++) {
-            //TraceManager.addDev("Tab " + i + " = " + mainTabbedPane.getTitleAt(i));
-            //TraceManager.addDev("jtp  = >" + jtp.getTitleAt(i) + "<");
-            //TraceManager.addDev("old  = >" + old + "<");
-            if (jtp.getTitleAt(i).compareTo(old) == 0) {
-                jtp.setTitleAt(i, niou);
-                jtp.setToolTipTextAt(i, "Opens the state machine of " + niou);
-                TDiagramPanel tdp;
-                //change panel name
-                for(int j=0; j<tp.panels.size(); j++) {
-                    tdp = (TDiagramPanel)(tp.panels.elementAt(j));
-                    if (tdp.getName().equals(old)) {
-                        tdp.setName(niou);
-                        //TraceManager.addDev("Renamed to " + niou);
-                    }
-                }
-
-                return true;
-            }
-        }
-        // internal error
-        ErrorGUI.exit(ErrorGUI.ERROR_TAB);
-        return false;
-    }
-
     public boolean nameComponentInUse(TURTLEPanel tp, String old, String niou) {
         JTabbedPane jtp = tp.tabbedPane;
         for(int i = 0; i<jtp.getTabCount(); i++) {
@@ -8131,6 +8086,10 @@ public  class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
             actionOnButton(TGComponentManager.CONNECTOR, TGComponentManager.AVATARBD_COMPOSITION_CONNECTOR);
         } else if (command.equals(actions[TGUIAction.ABD_PORT_CONNECTOR].getActionCommand())) {
             actionOnButton(TGComponentManager.CONNECTOR, TGComponentManager.AVATARBD_PORT_CONNECTOR);
+        } else if (command.equals(actions[TGUIAction.ABD_LIBRARYFUNCTION].getActionCommand())) {
+            actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.AVATARBD_LIBRARYFUNCTION);
+        } else if (command.equals(actions[TGUIAction.ABD_CRYPTOLIBRARYFUNCTION].getActionCommand())) {
+            actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.AVATARBD_CRYPTOLIBRARYFUNCTION);
 
             // AVATAR SMD
         } else if (command.equals(actions[TGUIAction.ASMD_EDIT].getActionCommand())) {
diff --git a/src/ui/TDiagramPanel.java b/src/ui/TDiagramPanel.java
index eb2520483acdbfb83beab169f619619a8da5a9f1..7b823d703aedbf5e1ccf39e87dabeca04564cd8d 100755
--- a/src/ui/TDiagramPanel.java
+++ b/src/ui/TDiagramPanel.java
@@ -110,7 +110,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     protected String name;
 
-    protected LinkedList componentList;
+    protected LinkedList<TGComponent> componentList;
     protected TGConnectingPoint selectedConnectingPoint;
     protected TGComponent componentPointed;
     protected TGComponent componentPopup;
@@ -240,7 +240,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
         //setMinimumSize(new Dimension(1000, 1000));
         //setMaximumSize(new Dimension(1000, 1000));
         setPreferredSize(new Dimension(maxX + limit, maxY + limit));
-        componentList = new LinkedList();
+        componentList = new LinkedList<TGComponent> ();
         mgui = _mgui;
         ttb = _ttb;
         mode = NORMAL;
@@ -299,17 +299,13 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     public void updateComponentsAfterZoom() {
         //TraceManager.addDev("Zoom factor=" + zoom);
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
         boolean change = false;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof ScalableTGComponent) {
                 ((ScalableTGComponent)tgc).rescale(zoom);
                 change = true;
             }
-        }
 
         if (change) {
             mgui.changeMade(this, MOVE_COMPONENT);
@@ -327,7 +323,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void removeAll() {
-        componentList = new LinkedList();
+        this.componentList = new LinkedList<TGComponent> ();
     }
 
 
@@ -341,13 +337,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void structureChanged() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             tgc.TDPStructureChanged();
-        }
     }
 
     public void setAttributes(int _attr) {
@@ -359,23 +350,13 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void valueChanged() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             tgc.TDPvalueChanged();
-        }
     }
 
     public int makeLovelyIds(int id) {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             id = tgc.makeLovelyIds(id);
-        }
 
         return id;
     }
@@ -396,7 +377,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     public void basicPaintMyComponents(Graphics g) {
         TGComponent tgc;
         for(int i=componentList.size()-1; i>=0; i--) {
-            tgc = (TGComponent)(componentList.get(i));
+            tgc = this.componentList.get(i);
             if (!tgc.isHidden()) {
                 TraceManager.addDev("Painting " + tgc.getName() + " x=" + tgc.getX() + " y=" + tgc.getY());
                 tgc.draw(g);
@@ -452,8 +433,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
         //TraceManager.addDev("Draw 3");
 
         TGComponent tgc;
-        for(int i=componentList.size()-1; i>=0; i--) {
-            tgc = (TGComponent)(componentList.get(i));
+        for(int i=this.componentList.size()-1; i>=0; i--) {
+            tgc = this.componentList.get(i);
             if (!tgc.isHidden()) {
                 //TraceManager.addDev("Painting " + tgc.getName() + " x=" + tgc.getX() + " y=" + tgc.getY());
                 tgc.draw(g);
@@ -538,8 +519,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
         if ((this instanceof TDPWithAttributes) && (getAttributeState() != 0))  {
             //TraceManager.addDev("Tdp with attributes");
-            for(int i=componentList.size()-1; i>=0; i--) {
-                tgc = (TGComponent)(componentList.get(i));
+            for(int i=this.componentList.size()-1; i>=0; i--) {
+                tgc = this.componentList.get(i);
                 if (!tgc.isHidden()) {
                     tgc.drawWithAttributes(g);
                 }
@@ -591,7 +572,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
       }*/
 
     public void loadFromXML(String s) {
-        componentList = new LinkedList();
+        this.componentList = new LinkedList();
 
         mode = NORMAL;
     }
@@ -639,15 +620,12 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     private StringBuffer componentsInXML(boolean selected) {
         StringBuffer sb = new StringBuffer("");
         StringBuffer s;
-        TGComponent tgc;
 
         //Added by Solange to see the components in the list
-        LinkedList ruteoList=componentList;
+        LinkedList<TGComponent> ruteoList=this.componentList;
         //
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if ((selected == false) || (tgc.isSelected())) {
                 s = tgc.saveInXML();
                 if (s == null) {
@@ -657,8 +635,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
                 sb.append("\n");
             }
 
-        }
-        //TraceManager.addDev("making copy sb=\n" + sb);
         return sb;
     }
 
@@ -670,12 +646,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     // Selecting components
     public int selectComponentInRectangle(int x, int y, int width, int height) {
         //TraceManager.addDev("x=" + x + " y=" + y + " width=" +width + " height=" + height);
-        TGComponent tgc;
         int cpt = 0;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc.areAllInRectangle(x, y, width, height)) {
                 tgc.select(true);
                 tgc.setState(TGState.SELECTED);
@@ -684,7 +657,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
                 tgc.select(false);
                 tgc.setState(TGState.NORMAL);
             }
-        }
 
         return cpt;
     }
@@ -695,7 +667,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     //author: huytruong
     public byte hoveredComponent(int x, int y) {
-        TGComponent tgc, tgcTmp;
+        TGComponent tgcTmp;
         //int state;
         //boolean b = false;
         boolean hoveredElementFound = false;
@@ -704,10 +676,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
         TGComponent tmp = componentHovered;
         componentHovered = null;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList) {
             //state = tgc.getState();
             tgcTmp = tgc.isOnMeHL(x, y);
             if (tgcTmp != null) {
@@ -744,7 +714,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     // -> 2 One component highlighted, no change
     // -> 3 One component highlighted, change
     public byte highlightComponent(int x, int y) {
-        TGComponent tgc, tgcTmp;
+        TGComponent tgcTmp;
         //int state;
         //boolean b = false;
         boolean pointedElementFound = false;
@@ -753,10 +723,8 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
         TGComponent tmp = componentPointed;
         componentPointed = null;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList) {
             //state = tgc.getState();
             tgcTmp = tgc.isOnMeHL(x, y);
             if (tgcTmp != null) {
@@ -786,7 +754,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void highlightTGComponent(TGComponent tgc) {
-        if (!componentList.contains(tgc.getTopFather())) {
+        if (!this.componentList.contains(tgc.getTopFather())) {
             return;
         }
 
@@ -816,12 +784,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public TGConnectingPoint findConnectingPoint(int id) {
-        TGComponent tgc;
         TGConnectingPoint p;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList) {
             p = tgc.findConnectingPoint(id);
             if (p != null) {
                 return p;
@@ -832,84 +797,58 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public TGComponent findComponentWithId(int id) {
-        TGComponent tgc1, tgc2;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc1 = (TGComponent)(iterator.next());
-            tgc2 = tgc1.containsLoadedId(id);
-            if (tgc2 != null) {
+        for (TGComponent tgc1: this.componentList) {
+            TGComponent tgc2 = tgc1.containsLoadedId(id);
+            if (tgc2 != null)
                 return tgc2;
-            }
         }
+
         return null;
     }
 
     public TGConnector findTGConnectorStartingAt(CDElement c) {
-        TGComponent tgc;
-        TGConnector tgco;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof TGConnector) {
-                tgco = (TGConnector) tgc;
-                if (tgco.isP1(c)) {
+                TGConnector tgco = (TGConnector) tgc;
+                if (tgco.isP1(c))
                     return tgco;
-                }
-
             }
-        }
+
         return null;
     }
 
     public TGConnector findTGConnectorUsing(CDElement c) {
-        TGComponent tgc;
-        TGConnector tgco;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof TGConnector) {
-                tgco = (TGConnector) tgc;
-                if (tgco.isP1(c)) {
+                TGConnector tgco = (TGConnector) tgc;
+                if (tgco.isP1(c))
                     return tgco;
-                }
-                if (tgco.isP2(c)) {
+                if (tgco.isP2(c))
                     return tgco;
-                }
-
             }
-        }
+
         return null;
     }
 
 
     public boolean highlightOutAndFreeConnectingPoint(int x, int y, int type) {
-        TGComponent tgc;
-        TGConnectingPoint cp;
-        int state;
         boolean b = false;
         boolean pointedElementFound = false;
         selectedConnectingPoint = null;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (pointedElementFound == true) {
+        for (TGComponent tgc: this.componentList)
+            if (pointedElementFound)
                 b =  tgc.setStateTGConnectingPoint(TGConnectingPoint.NORMAL) || b;
-            }
-            if (pointedElementFound == false) {
-                cp = tgc.getFreeTGConnectingPointAtAndCompatible(x, y, type);
+            else {
+                TGConnectingPoint cp = tgc.getFreeTGConnectingPointAtAndCompatible(x, y, type);
                 if ((cp != null) && (cp.isOut()) && (cp.isFree()) && (cp.isCompatibleWith(type))) {
                     selectedConnectingPoint = cp;
                     pointedElementFound = true;
                     b = cp.setState(TGConnectingPoint.SELECTED) || b;
-                } else {
+                } else
                     b =  tgc.setStateTGConnectingPoint(TGConnectingPoint.NORMAL) || b;
-                }
             }
-        }
+
         return b;
     }
 
@@ -942,16 +881,13 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
       }*/
 
     public boolean highlightInAndFreeConnectingPoint(int x, int y, int type) {
-        TGComponent tgc;
         TGConnectingPoint cp;
         int state;
         boolean b = false;
         boolean pointedElementFound = false;
         selectedConnectingPoint = null;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList) {
             if (pointedElementFound == true) {
                 b =  tgc.setStateTGConnectingPoint(TGConnectingPoint.NORMAL) || b;
             }
@@ -1026,54 +962,41 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public SwallowTGComponent findSwallowTGComponent(int x, int y, TGComponent tgcdiff) {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if ((tgc instanceof SwallowTGComponent) && (tgc.isOnMeHL(x, y) != null) && (tgc != tgcdiff)) {
+        for (TGComponent tgc: this.componentList)
+            if ((tgc instanceof SwallowTGComponent) && (tgc.isOnMeHL(x, y) != null) && (tgc != tgcdiff))
                 return ((SwallowTGComponent)tgc);
-                /*if (((SwallowTGComponent)tgc).acceptSwallowedTGComponent(tgcdiff)) {
 
-                  }*/
-            }
-        }
         return null;
     }
 
     public void addBuiltComponent(TGComponent tgc) {
         if (tgc != null) {
-            componentList.add(tgc);
+            this.componentList.add(tgc);
         }
     }
 
     public void addBuiltConnector(TGConnector tgc) {
         if (tgc != null) {
-            componentList.add(tgc);
+            this.componentList.add(tgc);
         }
     }
 
-    public LinkedList getComponentList() {
-        return componentList;
+    public LinkedList<TGComponent> getComponentList() {
+        return this.componentList;
     }
 
-    public LinkedList getAllComponentList() {
-        TGComponent tgc;
+    public LinkedList<TGComponent> getAllComponentList() {
 
-        LinkedList ll = new LinkedList();
-        ll.addAll(componentList);
+        LinkedList<TGComponent> ll = new LinkedList<TGComponent> ();
+        ll.addAll(this.componentList);
 
-        ListIterator iterator = componentList.listIterator();
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             ll.addAll(tgc.getRecursiveAllInternalComponent());
-        }
 
         return ll;
     }
 
     // Adding connector
-
     public void addingTGConnector() {
         listPoint = new Vector();
         p1 = getSelectedTGConnectingPoint();
@@ -1096,7 +1019,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
         if (tgco != null) {
             TraceManager.addDev("Adding connector");
             p2.setFree(false);
-            componentList.add(0, tgco);
+            this.componentList.add(0, tgco);
             if (tgco instanceof SpecificActionAfterAdd) {
                 ((SpecificActionAfterAdd)tgco).specificActionAfterAdd();
             }
@@ -1175,11 +1098,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void unselectSelectedComponents() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList) {
             tgc.select(false);
             tgc.setState(TGState.NORMAL);
         }
@@ -1206,27 +1125,15 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void setMovingSelectedComponents() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.isSelected()) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc.isSelected())
                 tgc.setState(TGState.MOVING);
-            }
-        }
     }
 
     public void setStopMovingSelectedComponents() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.isSelected()) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc.isSelected())
                 tgc.setState(TGState.SELECTED);
-            }
-        }
     }
 
     public int getXSelected() {
@@ -1249,127 +1156,91 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
         int oldY = ySel;
         xSel = x;
         ySel = y;
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.isSelected()) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc.isSelected())
                 tgc.forceMove(xSel - oldX, ySel - oldY);
-            }
-        }
     }
 
     public TGComponent nextSelectedComponent() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.isSelected()) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc.isSelected())
                 return tgc;
-            }
-        }
+
         return null;
     }
 
-    public Vector selectedTclasses() {
-        TGComponent tgc;
-        TCDTClass t;
-        Vector v = null;
-        Iterator iterator = componentList.listIterator();
+    public Vector<TCDTClass> selectedTclasses() {
+        Vector<TCDTClass> v = null;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if ((tgc.isSelected()) && (tgc instanceof TCDTClass)) {
-                if (v == null) {
-                    v = new Vector();
-                }
-                v.addElement(tgc);
+                if (v == null)
+                    v = new Vector<TCDTClass> ();
+
+                v.addElement((TCDTClass) tgc);
             }
-        }
+
         return v;
     }
 
-    public Vector selectedTURTLEOSClasses() {
-        TGComponent tgc;
-        Vector v = null;
-        Iterator iterator = componentList.listIterator();
+    public Vector<TOSClass> selectedTURTLEOSClasses() {
+        Vector<TOSClass> v = null;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if ((tgc.isSelected()) && (tgc instanceof TOSClass)) {
-                if (v == null) {
-                    v = new Vector();
-                }
-                v.addElement(tgc);
+                if (v == null)
+                    v = new Vector<TOSClass> ();
+                v.addElement((TOSClass) tgc);
             }
-        }
+
         return v;
     }
 
-    public Vector selectedTMLTasks() {
-        TGComponent tgc;
-        TMLTaskOperator t;
-        Vector v = null;
-        Iterator iterator = componentList.listIterator();
+    public Vector<TMLTaskOperator> selectedTMLTasks() {
+        Vector<TMLTaskOperator> v = null;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if ((tgc.isSelected()) && (tgc instanceof TMLTaskOperator)) {
-                if (v == null) {
-                    v = new Vector();
-                }
-                v.addElement(tgc);
+                if (v == null)
+                    v = new Vector<TMLTaskOperator> ();
+                v.addElement((TMLTaskOperator) tgc);
             }
-        }
+
         return v;
     }
 
-    public Vector selectedAvatarBDBlocks() {
-        TGComponent tgc;
-        //AvatarBDBlock b;
-        Vector v = null;
-        Iterator iterator = componentList.listIterator();
+    public Vector<AvatarBDBlock> selectedAvatarBDBlocks() {
+        Vector<AvatarBDBlock> v = null;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if ((tgc.isSelected()) && (tgc instanceof AvatarBDBlock)) {
-                if (v == null) {
-                    v = new Vector();
-                }
-                v.addElement(tgc);
-                LinkedList<AvatarBDBlock> list = ((AvatarBDBlock)tgc).getFullBlockList();
-                v.addAll(list);
+                if (v == null)
+                    v = new Vector<AvatarBDBlock> ();
+                v.addElement((AvatarBDBlock) tgc);
+                v.addAll(((AvatarBDBlock) tgc).getFullBlockList());
             }
-        }
+
         return v;
     }
 
-    public Vector selectedCPrimitiveComponent() {
-        TGComponent tgc;
-        TMLCPrimitiveComponent tcomp;
-        Vector v = null;
-        Iterator iterator = componentList.listIterator();
+    public Vector<TMLCPrimitiveComponent> selectedCPrimitiveComponent() {
+        Vector<TMLCPrimitiveComponent> v = null;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc.isSelected()) {
                 if (tgc instanceof TMLCPrimitiveComponent) {
-                    if (v == null) {
-                        v = new Vector();
-                    }
-                    v.addElement(tgc);
+                    if (v == null)
+                        v = new Vector<TMLCPrimitiveComponent> ();
+                    v.addElement((TMLCPrimitiveComponent) tgc);
                 }
 
                 if (tgc instanceof TMLCCompositeComponent) {
-                    if (v == null) {
-                        v = new Vector();
-                    }
-                    v.addAll(((TMLCCompositeComponent)(tgc)).getAllPrimitiveComponents());
+                    if (v == null)
+                        v = new Vector<TMLCPrimitiveComponent> ();
+                    v.addAll(((TMLCCompositeComponent) (tgc)).getAllPrimitiveComponents());
                 }
             }
-        }
+
         return v;
     }
 
@@ -2150,13 +2021,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     // operations
     public void removeComponent(TGComponent tgc) {
-        TGComponent t;
-        Iterator iterator = componentList.listIterator();
-
         fatherOfRemoved = tgc.getFather();
 
-        while(iterator.hasNext()) {
-            t = (TGComponent)(iterator.next());
+        for (TGComponent t: this.componentList)
             if (t == tgc) {
                 removeConnectors(tgc);
                 if (tgc instanceof TGConnector) {
@@ -2176,60 +2043,46 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
                     return;
                 }
             }
-        }
     }
 
     public void removeConnectors(TGComponent tgc) {
-        TGConnector tgcon;
-        TGComponent t;
-        TGConnectingPoint cp;
-        int i, j, k;
-
-        for (i = 0; i<tgc.getNbConnectingPoint(); i++) {
-            cp = tgc.tgconnectingPointAtIndex(i);
-            for(j=0; j<componentList.size(); j++) {
-                t = (TGComponent)(componentList.get(j));
+        for (int i = 0; i<tgc.getNbConnectingPoint(); i++) {
+            TGConnectingPoint cp = tgc.tgconnectingPointAtIndex(i);
+            Iterator<TGComponent> iterator = this.componentList.iterator ();
+            while (iterator.hasNext ()) {
+                TGComponent t = iterator.next ();
                 if (t instanceof TGConnector) {
-                    tgcon = (TGConnector)t;
+                    TGConnector tgcon = (TGConnector)t;
                     if ((cp == tgcon.getTGConnectingPointP1()) || (cp == tgcon.getTGConnectingPointP2())) {
-                        componentList.remove(j);
+                        iterator.remove ();
                         actionOnRemove(t);
-                        j --;
                         tgcon.getTGConnectingPointP1().setFree(true);
                         tgcon.getTGConnectingPointP2().setFree(true);
-                        for(k=0; k<tgcon.getNbConnectingPoint(); k++) {
+                        for(int k=0; k<tgcon.getNbConnectingPoint(); k++)
                             removeOneConnector(tgcon.tgconnectingPointAtIndex(k));
-                        }
                     }
                 }
             }
         }
 
-        for(i=0; i<tgc.getNbInternalTGComponent(); i++) {
+        for(int i=0; i<tgc.getNbInternalTGComponent(); i++)
             removeConnectors(tgc.getInternalTGComponent(i));
-        }
     }
 
     public void removeOneConnector(TGConnectingPoint cp) {
-        //TraceManager.addDev("Remove one connector");
-        TGConnector tgcon;
-        TGComponent t;
-        int j, k;
-
-        for(j=0; j<componentList.size(); j++) {
-            t = (TGComponent)(componentList.get(j));
+        Iterator<TGComponent> iterator = this.componentList.iterator ();
+        while (iterator.hasNext ()) {
+            TGComponent t = iterator.next ();
             if (t instanceof TGConnector) {
-                tgcon = (TGConnector)t;
+                TGConnector tgcon = (TGConnector)t;
                 if ((cp == tgcon.getTGConnectingPointP1()) || (cp == tgcon.getTGConnectingPointP2())) {
-                    componentList.remove(j);
+                    iterator.remove ();
                     actionOnRemove(t);
-                    j --;
                     tgcon.getTGConnectingPointP1().setFree(true);
                     tgcon.getTGConnectingPointP2().setFree(true);
                     TraceManager.addDev("Removed one connector!");
-                    for(k=0; k<tgcon.getNbConnectingPoint(); k++) {
+                    for(int k=0; k<tgcon.getNbConnectingPoint(); k++)
                         removeOneConnector(tgcon.tgconnectingPointAtIndex(k));
-                    }
                 }
             }
         }
@@ -2298,19 +2151,16 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void attach(TGComponent tgc) {
-        if (tgc instanceof SwallowedTGComponent) {
-            if (tgc.tdp.addComponent(tgc, tgc.getX(), tgc.getY(), true, false)) {
-                // Component was attached -> must be removed from the list
-                componentList.remove(tgc);
-            }
-        }
+        if (tgc instanceof SwallowedTGComponent && tgc.tdp.addComponent (tgc, tgc.getX(), tgc.getY(), true, false))
+            // Component was attached -> must be removed from the list
+            this.componentList.remove(tgc);
     }
 
     public void detach(TGComponent tgc) {
         if ((tgc instanceof SwallowedTGComponent) && (tgc.getFather() != null)) {
             ((SwallowTGComponent)tgc.getFather()).removeSwallowedTGComponent(tgc);
             tgc.setFather(null);
-            componentList.add(tgc);
+            this.componentList.add(tgc);
             tgc.wasUnswallowed();
             bringToFront(tgc);
         }
@@ -2337,28 +2187,19 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     //returns the highest id amongst its components
     public int getMaxId() {
-        TGComponent tgc;
         int ret = 0;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             ret = Math.max(ret, tgc.getMaxId());
-        }
+
         return ret;
     }
 
     public int getMaxIdSelected() {
-        TGComponent tgc;
         int ret = 0;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.isSelected()) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc.isSelected())
                 ret = Math.max(ret, tgc.getMaxId());
-            }
-        }
+
         return ret;
     }
 
@@ -2376,19 +2217,13 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     // tell the other component connected to this connecting point
     public TGConnector getConnectorConnectedTo(TGConnectingPoint p) {
-        TGComponent tgc;
-        TGConnector tgco;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof TGConnector) {
-                tgco = (TGConnector)tgc;
-                if ((tgco.getTGConnectingPointP1() == p) || (tgco.getTGConnectingPointP2() == p)) {
+                TGConnector tgco = (TGConnector) tgc;
+                if ((tgco.getTGConnectingPointP1() == p) || (tgco.getTGConnectingPointP2() == p))
                     return tgco;
-                }
             }
-        }
+
         return null;
     }
 
@@ -2432,957 +2267,469 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public TGComponent getComponentToWhichBelongs(TGConnectingPoint p) {
-        TGComponent tgc1, tgc2;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc1 = (TGComponent)(iterator.next());
-            tgc2 = tgc1.belongsToMeOrSon(p);
-            if (tgc2 != null) {
+        for (TGComponent tgc1: this.componentList) {
+            TGComponent tgc2 = tgc1.belongsToMeOrSon(p);
+            if (tgc2 != null)
                 return tgc2;
-            }
         }
+
         return null;
     }
 
-    public TGComponent getComponentToWhichBelongs(LinkedList components, TGConnectingPoint p) {
-        TGComponent tgc1, tgc2;
-        Iterator iterator = components.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc1 = (TGComponent)(iterator.next());
-            tgc2 = tgc1.belongsToMeOrSon(p);
-            if (tgc2 != null) {
+    public static TGComponent getComponentToWhichBelongs (LinkedList<TGComponent> components, TGConnectingPoint p) {
+        for (TGComponent tgc1: components) {
+            TGComponent tgc2 = tgc1.belongsToMeOrSon(p);
+            if (tgc2 != null)
                 return tgc2;
-            }
         }
+
         return null;
     }
 
     public void getAllCheckableTGComponent(ArrayList<TGComponent> _list) {
-        //TraceManager.addDev("Checking for components on=" + this);
-        Iterator iterator = componentList.listIterator();
-        TGComponent tgc;
-        LinkedList list;
-
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.hasCheckableAccessibility()) {
-                list = tgc.getAllCheckableAccessibility();
-                _list.addAll(list);
-            }
-        }
-
+        for (TGComponent tgc: this.componentList)
+            if (tgc.hasCheckableAccessibility())
+                _list.addAll(tgc.getAllCheckableAccessibility ());
     }
 
     public void getAllCheckableInvariantTGComponent(ArrayList<TGComponent> _list) {
-        //TraceManager.addDev("Checking for components on=" + this);
-        Iterator iterator = componentList.listIterator();
-        TGComponent tgc;
-        LinkedList list;
-
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.hasCheckableInvariant()) {
-                list = tgc.getAllCheckableInvariant();
-                _list.addAll(list);
-            }
-        }
+        for (TGComponent tgc: this.componentList)
+            if (tgc.hasCheckableInvariant())
+                _list.addAll(tgc.getAllCheckableInvariant());
     }
 
     // Main Tree
-
     public int getChildCount() {
-        return componentList.size();
+        return this.componentList.size();
     }
 
     public Object getChild(int index) {
-        return componentList.get(index);
+        return this.componentList.get(index);
     }
 
     public int getIndexOfChild(Object child) {
-        return componentList.indexOf(child);
+        return this.componentList.indexOf(child);
     }
 
     //Tclass
+    private class NameChecker {
+        public boolean isNameAlreadyTaken (TGComponent o, String name) {
+            // Must deal with the case where mutliple the tested component
+            // inherit from multiple classes / interfaces.
+            // In such case we execute all check*** functions until one
+            // returns true, in which case we can return true;
+            return (o instanceof TClassInterface        && this.checkTClassInterface ((TClassInterface) o, name))
+                || (o instanceof TCDTData               && this.checkTCDTData ((TCDTData) o, name))
+                || (o instanceof TCDTObject             && this.checkTCDTObject ((TCDTObject) o, name))
+                || (o instanceof TOSClass               && this.checkTOSClass ((TOSClass) o, name))
+                || (o instanceof Requirement            && this.checkRequirement ((Requirement) o, name))
+                || (o instanceof TMLCPrimitiveComponent && this.checkTMLCPrimitiveComponent ((TMLCPrimitiveComponent) o, name))
+                || (o instanceof TMLCRecordComponent    && this.checkTMLCRecordComponent ((TMLCRecordComponent) o, name))
+                || (o instanceof TMLCCompositeComponent && this.checkTMLCCompositeComponent ((TMLCCompositeComponent) o, name))
+                || (o instanceof TMLTaskInterface       && this.checkTMLTaskInterface ((TMLTaskInterface) o, name))
+                || (o instanceof ATDBlock               && this.checkATDBlock ((ATDBlock) o, name))
+                || (o instanceof AvatarBDBlock          && this.checkAvatarBDBlock ((AvatarBDBlock) 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))
+                || (o instanceof AvatarMADAssumption    && this.checkAvatarMADAssumption ((AvatarMADAssumption) o, name))
+                || (o instanceof AvatarRDRequirement    && this.checkAvatarRDRequirement ((AvatarRDRequirement) o, name))
+                || (o instanceof NCEqNode               && this.checkNCEqNode ((NCEqNode) o, name))
+                || (o instanceof NCSwitchNode           && this.checkNCSwitchNode ((NCSwitchNode) o, name))
+                || (o instanceof AvatarBDDataType       && this.checkAvatarBDDataType ((AvatarBDDataType) o, name))
+                || (o instanceof AvatarBDLibraryFunction && this.checkAvatarBDLibraryFunction ((AvatarBDLibraryFunction) o, name));
+        }
+
+        public boolean checkTClassInterface (TClassInterface o, String name) { return false; }
+        public boolean checkTCDTData (TCDTData o, String name) { return false; }
+        public boolean checkTCDTObject (TCDTObject o, String name) { return false; }
+        public boolean checkTOSClass (TOSClass o, String name) { return false; }
+        public boolean checkRequirement (Requirement o, String name) { return false; }
+        public boolean checkTMLCPrimitiveComponent (TMLCPrimitiveComponent o, String name) { return false; }
+        public boolean checkTMLCRecordComponent (TMLCRecordComponent o, String name) { return false; }
+        public boolean checkTMLCCompositeComponent (TMLCCompositeComponent o, String name) { return false; }
+        public boolean checkTMLTaskInterface (TMLTaskInterface o, String name) { return false; }
+        public boolean checkATDBlock (ATDBlock o, String name) { return false; }
+        public boolean checkAvatarBDBlock (AvatarBDBlock o, String name) { return false; }
+        public boolean checkAvatarCDBlock (AvatarCDBlock o, String name) { return false; }
+        public boolean checkAvatarSMDState (AvatarSMDState o, String name) { return false; }
+        public boolean checkAvatarADActivity (AvatarADActivity o, String name) { return false; }
+        public boolean checkAvatarMADAssumption (AvatarMADAssumption o, String name) { return false; }
+        public boolean checkAvatarRDRequirement (AvatarRDRequirement o, String name) { return false; }
+        public boolean checkNCEqNode (NCEqNode o, String name) { return false; }
+        public boolean checkNCSwitchNode (NCSwitchNode o, String name) { return false; }
+        public boolean checkAvatarBDDataType (AvatarBDDataType o, String name) { return false; }
+        public boolean checkAvatarBDLibraryFunction (AvatarBDLibraryFunction o, String name) { return false; }
+    }
+
+    private boolean isNameUnique (String name, NameChecker checker) {
+        for (TGComponent o: this.componentList)
+            if (checker.isNameAlreadyTaken (o, name))
+                return false;
+        return true;
+    }
 
-    public boolean isAlreadyATClassName(String name) {
-        TClassInterface t;
-        Object o;
-        int i;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TClassInterface) {
-                t = (TClassInterface)o;
-                if (t.getClassName().equals(name)) {
-                    return true;
-                }
-            }
+    private String findGoodName (String name, NameChecker checker) {
+        // index >= 0 catch overflows
+        for (int index=0; index>=0; index++) {
+            String tryName = name + index;
+            if (this.isNameUnique (tryName, checker))
+                return tryName;
         }
-        return false;
+
+        throw new RuntimeException("Integer Overflow");
     }
 
-    public boolean isAlreadyATMLTaskName(String name) {
-        TMLTaskInterface t;
-        Object o;
-        int i;
-        Iterator iterator = componentList.listIterator();
+    public String findTClassName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkTClassInterface (TClassInterface o, String name) {
+                return o.getClassName ().equals (name);
+            }
+            public boolean checkTCDTData (TCDTData o, String name) {
+                return o.getValue ().equals (name);
+            }
+        });
+    }
 
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TMLTaskInterface) {
-                t = (TMLTaskInterface)o;
-                if (t.getTaskName().equals(name)) {
-                    return true;
-                }
+    public String findTOSClassName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkTOSClass (TOSClass o, String name) {
+                return o.getClassName ().equals (name);
             }
-        }
-        return false;
+        });
     }
 
-    public boolean isAlreadyAnAvatarBDBlockName(String name) {
-        AvatarBDBlock b;
-        Object o;
-        int i;
-        Iterator iterator = componentList.listIterator();
+    public String findRequirementName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkRequirement (Requirement o, String name) {
+                return o.getRequirementName ().equals (name);
+            }
+        });
+    }
 
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof AvatarBDBlock) {
-                b = (AvatarBDBlock)o;
-                if (b.getBlockName().equals(name)) {
-                    return true;
-                }
-                LinkedList<AvatarBDBlock> list = b.getFullBlockList();
-                for(AvatarBDBlock ab: list) {
-                    if (ab.getBlockName().equals(name)) {
+    public String findTMLPrimitiveComponentName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkTMLCPrimitiveComponent (TMLCPrimitiveComponent o, String name) {
+                return o.getValue ().equals (name);
+            }
+            public boolean checkTMLCRecordComponent (TMLCRecordComponent o, String name) {
+                return o.getValue ().equals (name);
+            }
+            public boolean checkTMLCCompositeComponent (TMLCCompositeComponent o, String name) {
+                for (int i=0; i<o.getNbInternalTGComponent (); i++)
+                    if (this.isNameAlreadyTaken (o.getInternalTGComponent (i), name))
                         return true;
-                    }
-                }
+                return false;
+            }
+        });
+    }
+
+    public String findTMLRecordComponentName(String name) {
+        return this.findTMLPrimitiveComponentName (name);
+    }
 
+    public String findTMLTaskName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkTMLTaskInterface (TMLTaskInterface o, String name) {
+                return o.getTaskName ().equals (name);
             }
-        }
-        return false;
+        });
     }
 
-    public boolean isAlreadyATMLPrimitiveComponentName(String name) {
-        TMLCPrimitiveComponent pc;
-        Object o;
-        int i;
-        Iterator iterator = componentList.listIterator();
-        ArrayList<TMLCPrimitiveComponent> list;
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TMLCPrimitiveComponent) {
-                pc = (TMLCPrimitiveComponent)o;
-                if (pc.getValue().equals(name)) {
+    public String findBlockName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkATDBlock (ATDBlock o, String name) {
+                return o.getName ().equals (name);
+            }
+        });
+    }
+
+    public String findAvatarBDBlockName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkAvatarBDBlock (AvatarBDBlock o, String name) {
+                if (o.getValue ().equals (name))
                     return true;
-                }
+                return o.hasInternalBlockWithName (name);
             }
-            if (o instanceof TMLCCompositeComponent) {
-                list = ((TMLCCompositeComponent)o).getAllPrimitiveComponents();
-                for(TMLCPrimitiveComponent cpc: list) {
-                    if (cpc.getValue().equals(name)) {
-                        return true;
-                    }
-                }
+            public boolean checkAvatarBDLibraryFunction (AvatarBDLibraryFunction o, String name) {
+                return o.getFunctionName ().equals (name);
             }
-        }
-        return false;
+            public boolean checkAvatarBDDataType (AvatarBDDataType o, String name) {
+                return o.getDataTypeName ().equals (name);
+            }
+        });
     }
 
-    public boolean isAlreadyATOSClassName(String name) {
-        TOSClass t;
-        Object o;
-        int i;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TOSClass) {
-                t = (TOSClass)o;
-                if (t.getClassName().equals(name)) {
+    public String findAvatarCDBlockName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkAvatarCDBlock (AvatarCDBlock o, String name) {
+                if (o.getValue ().equals (name))
                     return true;
-                }
+                return o.hasInternalBlockWithName (name);
             }
-        }
-        return false;
+        });
     }
 
-    public String findTClassName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        TClassInterface t;
-        Object o;
-        TCDTData td;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof TClassInterface) {
-                    t = (TClassInterface)o;
-                    if (t.getClassName().equals(name + index)) {
-                        ok = false;
-                    }
-                }
-                if (o instanceof TCDTData) {
-                    td = (TCDTData)o;
-                    if (td.getValue().equals(name + index)) {
-                        ok = false;
-                    }
-                }
+    public String findAvatarSMDStateName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkAvatarSMDState (AvatarSMDState o, String name) {
+                if (o.getValue ().equals (name))
+                    return true;
+                return o.hasInternalStateWithName (name);
             }
-            if (ok) {
-                return name + index;
+        });
+    }
+
+    public String findAvatarADActivityName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkAvatarADActivity (AvatarADActivity o, String name) {
+                if (o.getValue ().equals (name))
+                    return true;
+                return o.hasInternalActivityWithName (name);
             }
-            index ++;
-        }
-        return name;
+        });
     }
 
-    public String findTOSClassName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        TOSClass t;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof TOSClass) {
-                    t = (TOSClass)o;
-                    if (t.getClassName().equals(name + index)) {
-                        ok = false;
-                    }
-                }
+    public String findAvatarAssumptionName(String name, int start) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkAvatarMADAssumption (AvatarMADAssumption o, String name) {
+                return o.getValue ().equals (name);
             }
-            if (ok) {
-                return name + index;
+        });
+    }
+
+    public String findAvatarRequirementName(String name, int start) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkAvatarRDRequirement (AvatarRDRequirement o, String name) {
+                return o.getValue ().equals (name);
             }
-            index ++;
-        }
-        return name;
+        });
     }
 
-    public String findRequirementName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        Requirement req;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof Requirement) {
-                    req = (Requirement)o;
-                    if (req.getRequirementName().equals(name + index)) {
-                        ok = false;
+    public String findAvatarRequirementID(String id) {
+        try {
+            // intid >= 0 catch overflows
+            for (int intid = Integer.decode(id).intValue(); intid >=0; intid++) {
+                boolean ok = true;
+                for (TGComponent o: this.componentList)
+                    if (o instanceof AvatarRDRequirement) {
+                        AvatarRDRequirement areq = (AvatarRDRequirement) o;
+                        int otherid = Integer.decode(areq.getID()).intValue();
+                        if (intid == otherid) {
+                            ok = false;
+                            break;
+                        }
                     }
-                }
-            }
-            if (ok) {
-                return name + index;
+
+                if (ok)
+                    return Integer.toString(intid);
             }
-            index ++;
+        } catch (NumberFormatException e) {
+            return id;
         }
-        return name;
+
+        throw new RuntimeException("Integer Overflow");
     }
 
-    public String findTMLPrimitiveComponentName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        TGComponent o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (findTMLPrimitiveComponentNameTgc(name, o, index)) {
-                    ok = false;
-                    break;
-                }
+    public String findTObjectName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkTCDTObject (TCDTObject o, String name) {
+                return o.getObjectName ().equals (name);
             }
-            if (ok) {
-                return name + index;
+            public boolean checkTCDTClass (TCDTClass o, String name) {
+                return o.getClassName ().startsWith (name);
             }
-            index ++;
-        }
-        return name;
+        });
     }
 
-    public String findTMLRecordComponentName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        TGComponent o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (findTMLRecordComponentNameTgc(name, o, index)) {
+    public String findTObjectName(String name1, String name2) {
+        // index >= 0 catch overflows
+        for (int index=0; index>=0; index++) {
+            boolean ok = true;
+            String tryName = name1 + index;
+
+            for (TGComponent o: this.componentList)
+                if (o instanceof TCDTObject && ((TCDTObject) o).getObjectName().equals(tryName))
                     ok = false;
-                    break;
-                }
-            }
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
-    }
 
-    public boolean findTMLPrimitiveComponentNameTgc(String name, TGComponent tgc, int index) {
-        if (tgc instanceof TMLCPrimitiveComponent) {
-            if (tgc.getValue().equals(name+index)) {
-                return true;
-            }
+            if (ok && this.isTObjectNameUnique(tryName+name2))
+                return tryName;
         }
 
-        if (tgc instanceof TMLCRecordComponent) {
-            if (tgc.getValue().equals(name+index)) {
-                return true;
-            }
-        }
-
-        for(int i=0; i<tgc.getNbInternalTGComponent(); i++) {
-            if (findTMLPrimitiveComponentNameTgc(name, tgc.getInternalTGComponent(i), index)) {
-                return true;
-            }
-        }
 
-        return false;
+        throw new RuntimeException("Integer Overflow");
     }
 
-    public boolean findTMLRecordComponentNameTgc(String name, TGComponent tgc, int index) {
-        if (tgc instanceof TMLCPrimitiveComponent) {
-            if (tgc.getValue().equals(name+index)) {
-                return true;
+    public String findNodeName(String name) {
+        return this.findGoodName (name, new NameChecker () {
+            public boolean checkNCEqNode (NCEqNode o, String name) {
+                if (o.getName ().equals (name))
+                    return true;
+                for (NCTrafficArtifact arti: o.getArtifactList ())
+                    if (arti.getValue ().equals (name))
+                        return true;
+                return false;
             }
-        }
-
-        if (tgc instanceof TMLCRecordComponent) {
-            if (tgc.getValue().equals(name+index)) {
-                return true;
+            public boolean checkNCSwitchNode (NCSwitchNode o, String name) {
+                if (o.getName ().equals (name))
+                    return true;
+                for (NCRouteArtifact arti: o.getArtifactList ())
+                    if (arti.getValue ().equals (name))
+                        return true;
+                return false;
             }
-        }
-
-        for(int i=0; i<tgc.getNbInternalTGComponent(); i++) {
-            if (findTMLRecordComponentNameTgc(name, tgc.getInternalTGComponent(i), index)) {
-                return true;
+            public boolean checkNCConnectorNode (NCConnectorNode o, String name) {
+                return o.getInterfaceName ().equals (name);
             }
-        }
-
-        return false;
+        });
     }
 
-    public String findTMLTaskName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        TMLTaskInterface t;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof TMLTaskInterface) {
-                    t = (TMLTaskInterface)o;
-                    if (t.getTaskName().equals(name + index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
+    public String findInterfaceName(String name) {
+        return this.findNodeName (name);
     }
 
-    public String findBlockName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        ATDBlock t;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof ATDBlock) {
-                    t = (ATDBlock)o;
-                    if (t.getName().equals(name + index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
+    public boolean isAlreadyATClassName (String name) {
+        return !this.isTClassNameUnique (name);
     }
 
-    public String findAvatarBDBlockName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        AvatarBDBlock t;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof AvatarBDBlock) {
-                    t = (AvatarBDBlock)o;
-                    if (t.getValue().equals(name + index)) {
-                        ok = false;
-                    }
-                    if (t.hasInternalBlockWithName(name+index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
+    public boolean isAlreadyATMLTaskName(String name) {
+        return !this.isTMLTaskNameUnique (name);
     }
 
-    public String findAvatarCDBlockName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        AvatarCDBlock t;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof AvatarCDBlock) {
-                    t = (AvatarCDBlock)o;
-                    if (t.getValue().equals(name + index)) {
-                        ok = false;
-                    }
-                    if (t.hasInternalBlockWithName(name+index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
+    public boolean isAlreadyAnAvatarBDBlockName(String name) {
+        return !this.isAvatarBlockNameUnique (name);
     }
 
-    public String findAvatarSMDStateName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        AvatarSMDState s;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof AvatarSMDState) {
-                    s = (AvatarSMDState)o;
-                    if (s.getValue().equals(name + index)) {
-                        ok = false;
-                    }
-                    if (s.hasInternalStateWithName(name+index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                return name + index;
+    public boolean isAlreadyATMLPrimitiveComponentName(String name) {
+        return !this.isNameUnique (name, new NameChecker () {
+            public boolean checkTMLCPrimitiveComponent (TMLCPrimitiveComponent o, String name) {
+                return o.getValue ().equals (name);
             }
-            index ++;
-        }
-        return name;
-    }
-
-    public String findAvatarADActivityName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        AvatarADActivity s;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof AvatarADActivity) {
-                    s = (AvatarADActivity)o;
-                    if (s.getValue().equals(name + index)) {
-                        ok = false;
-                    }
-                    if (s.hasInternalActivityWithName(name+index)) {
-                        ok = false;
-                    }
-                }
+            public boolean checkTMLCRecordComponent (TMLCRecordComponent o, String name) {
+                return o.getValue ().equals (name);
             }
-            if (ok) {
-                return name + index;
+            public boolean checkTMLCCompositeComponent (TMLCCompositeComponent o, String name) {
+                for (int i=0; i<o.getNbInternalTGComponent (); i++)
+                    if (this.isNameAlreadyTaken (o.getInternalTGComponent (i), name))
+                        return true;
+                return false;
             }
-            index ++;
-        }
-        return name;
+        });
     }
 
-
-
-    public String findAvatarAssumptionName(String name, int start) {
-        boolean ok;
-        int i;
-        int index = start;
-        AvatarMADAssumption assump;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof AvatarMADAssumption) {
-                    assump = (AvatarMADAssumption)o;
-                    if (assump.getValue().equals(name + index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
+    public boolean isAlreadyATOSClassName(String name) {
+        return !this.isTOSClassNameUnique (name);
     }
 
-    public String findAvatarRequirementName(String name, int start) {
-        boolean ok;
-        int i;
-        int index = start;
-        AvatarRDRequirement areq;
-        Object o;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                o = (TGComponent)(iterator.next());
-                if (o instanceof AvatarRDRequirement) {
-                    areq = (AvatarRDRequirement)o;
-                    if (areq.getValue().equals(name + index)) {
-                        ok = false;
-                    }
-                }
+    public boolean isTClassNameUnique(String name) {
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkTClassInterface (TClassInterface o, String name) {
+                return o.getClassName ().equals (name);
             }
-            if (ok) {
-                return name + index;
+            public boolean checkTCDTData (TCDTData o, String name) {
+                return o.getValue ().equals (name);
             }
-            index ++;
-        }
-        return name;
+        });
     }
 
-    public String findAvatarRequirementID(String id) {
-        boolean ok;
-        int i;
-        int index = 0;
-        AvatarRDRequirement areq;
-        Object o;
-        Iterator iterator;
-        try {
-            int intid = Integer.decode(id).intValue();
-            int otherid;
-
-            while(index >= 0) {
-                ok = true;
-                iterator = componentList.listIterator();
-                while(iterator.hasNext()) {
-                    o = (TGComponent)(iterator.next());
-                    if (o instanceof AvatarRDRequirement) {
-                        areq = (AvatarRDRequirement)o;
-                        otherid = Integer.decode(areq.getID()).intValue();
-                        if (intid == otherid) {
-                            ok = false;
-                        }
-                    }
-                }
-                if (ok) {
-                    return "" + intid;
-                }
-                intid ++;
+    public boolean isTOSClassNameUnique(String name) {
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkTOSClass (TOSClass o, String name) {
+                return o.getClassName ().equals (name);
             }
-        } catch (Exception e) {
-        }
-        return id;
+        });
     }
 
-
-
-    public String findTObjectName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        Iterator iterator;
-
-        while(index >= 0) {
-            TGComponent tgc;
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                tgc = (TGComponent)(iterator.next());
-                if (tgc instanceof TCDTObject) {
-                    if (((TCDTObject)tgc).getObjectName().equals(name + index)) {
-                        ok = false;
-                    }
-                }
-                if (tgc instanceof TCDTClass) {
-                    if (((TCDTClass)tgc).getClassName().startsWith(name + index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                return name + index;
+    public boolean isTMLTaskNameUnique(String name) {
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkTMLTaskInterface (TMLTaskInterface o, String name) {
+                return o.getTaskName ().equals (name);
             }
-            index ++;
-        }
-        return name;
-    }
-
-    public String findTObjectName(String name1, String name2) {
-        boolean ok;
-        int i;
-        int index = 0;
-        Iterator iterator;
-
-        while(index >= 0) {
-            TGComponent tgc;
-            ok = true;
-            iterator = componentList.listIterator();
-            while(iterator.hasNext()) {
-                tgc = (TGComponent)(iterator.next());
-                if (tgc instanceof TCDTObject) {
-                    if (((TCDTObject)tgc).getObjectName().equals(name + index)) {
-                        ok = false;
-                    }
-                }
-            }
-            if (ok) {
-                if (isTObjectNameUnique(name1+index+name2)) {
-                    return name1 + index;
-                }
-            }
-            index ++;
-        }
-        return name;
-    }
-
-    public String findNodeName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        TGComponent tgc;
-        Iterator iterator;
-
-        while(index >= 0) {
-            //ok = true;
-            ok = isNCNameUnique(name + index);
-            /*iterator = componentList.listIterator();
-              while(iterator.hasNext()) {
-              tgc = (TGComponent)(iterator.next());
-              if (tgc.getName().equals(name + index)) {
-              ok = false;
-              }
-              }*/
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
-    }
-
-    public String findInterfaceName(String name) {
-        boolean ok;
-        int i;
-        int index = 0;
-        TGComponent tgc;
-        Iterator iterator;
-
-        while(index >= 0) {
-            ok = isNCNameUnique(name + index);
-            /*iterator = componentList.listIterator();
-              while(iterator.hasNext()) {
-              tgc = (TGComponent)(iterator.next());
-              if (tgc instanceof NCConnectorNode) {
-              if (((NCConnectorNode)tgc).getInterfaceName().equals(name + index)) {
-              ok = false;
-              }
-              } else {
-              if (tgc.getName().equals(name + index)) {
-              ok = false;
-              }
-              }
-              }*/
-            if (ok) {
-                return name + index;
-            }
-            index ++;
-        }
-        return name;
+        });
     }
 
-    public boolean isTClassNameUnique(String s) {
-        Object o;
-        TClassInterface t;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TClassInterface) {
-                t = (TClassInterface)o;
-                if (t.getClassName().equals(s)) {
-                    return false;
-                }
+    public boolean isBlockNameUnique(String name) {
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkATDBlock (ATDBlock o, String name) {
+                return o.getName ().equals (name);
             }
-            if (o instanceof TCDTData) {
-                if (((TCDTData)o).getValue().equals(s)) {
-                    return false;
-                }
-            }
-        }
-        return true;
+        });
     }
 
-    public boolean isTOSClassNameUnique(String s) {
-        Object o;
-        TOSClass t;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TOSClass) {
-                t = (TOSClass)o;
-                if (t.getClassName().equals(s)) {
-                    return false;
-                }
+    /**
+     * Check if any other <b>block, library function or data type</b>
+     * (contrary to what the name suggests) has this name.
+     *
+     * @param name
+     *      The name to check.
+     *
+     * @return true if the name is unique, false otherwise.
+     */
+    public boolean isAvatarBlockNameUnique (String name) {
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkAvatarBDBlock (AvatarBDBlock o, String name) {
+                if (o.getValue ().equals (name))
+                    return true;
+                return o.hasInternalBlockWithName (name);
             }
-        }
-        return true;
-    }
-
-    public boolean isTMLTaskNameUnique(String s) {
-        Object o;
-        TMLTaskInterface t;
-        Iterator iterator = componentList.listIterator();
-
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TMLTaskInterface) {
-                t = (TMLTaskInterface)o;
-                if (t.getTaskName().equals(s)) {
-                    return false;
-                }
+            public boolean checkAvatarBDLibraryFunction (AvatarBDLibraryFunction o, String name) {
+                return o.getFunctionName ().equals (name);
             }
-        }
-        return true;
-    }
-
-    public boolean isBlockNameUnique(String s) {
-        Object o;
-        ATDBlock t;
-        Iterator iterator = componentList.listIterator();
-
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof ATDBlock) {
-                t = (ATDBlock)o;
-                if (t.getName().equals(s)) {
-                    return false;
-                }
+            public boolean checkAvatarBDDataType (AvatarBDDataType o, String name) {
+                return o.getDataTypeName ().equals (name);
             }
-        }
-        return true;
+        });
     }
 
-    public boolean isAvatarBlockNameUnique(String s) {
-        Object o;
-        AvatarBDBlock block;
-        AvatarBDDataType type;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof AvatarBDBlock) {
-                block = (AvatarBDBlock)o;
-                if (block.getBlockName().equals(s)) {
-                    return false;
-                }
-            }
-            if (o instanceof AvatarBDDataType) {
-                type = (AvatarBDDataType)o;
-                if (type.getDataTypeName().equals(s)) {
-                    return false;
-                }
+    public boolean isNCNameUnique(String name) {
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkNCEqNode (NCEqNode o, String name) {
+                if (o.getName ().equals (name))
+                    return true;
+                for (NCTrafficArtifact arti: o.getArtifactList ())
+                    if (arti.getValue ().equals (name))
+                        return true;
+                return false;
             }
-        }
-        return true;
-    }
-
-    public boolean isNCNameUnique(String s) {
-        Object o;
-        TGComponent tgc;
-        Vector v;
-        NCTrafficArtifact arti;
-        NCRouteArtifact artiroute;
-        int i;
-        NCConnectorNode link;
-
-        Iterator iterator = componentList.listIterator();
-
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if ((tgc instanceof NCEqNode) || (tgc instanceof NCSwitchNode)){
-                if (tgc.getName().equals(s)) {
-                    return false;
-                }
-
-                if (tgc instanceof NCEqNode) {
-                    v = ((NCEqNode)tgc).getArtifactList();
-                    for (i=0; i<v.size(); i++) {
-                        arti = (NCTrafficArtifact)(v.get(i));
-                        if (arti.getValue().equals(s)) {
-                            return false;
-                        }
-                    }
-                }
-
-                if (tgc instanceof NCSwitchNode) {
-                    v = ((NCSwitchNode)tgc).getArtifactList();
-                    for (i=0; i<v.size(); i++) {
-                        artiroute = (NCRouteArtifact)(v.get(i));
-                        if (artiroute.getValue().equals(s)) {
-                            return false;
-                        }
-                    }
-                }
+            public boolean checkNCSwitchNode (NCSwitchNode o, String name) {
+                if (o.getName ().equals (name))
+                    return true;
+                for (NCRouteArtifact arti: o.getArtifactList ())
+                    if (arti.getValue ().equals (name))
+                        return true;
+                return false;
             }
-
-            if (tgc instanceof NCConnectorNode) {
-                link = (NCConnectorNode)tgc;
-                if (link.getInterfaceName().equals(s)) {
-                    return false;
-                }
+            public boolean checkNCConnectorNode (NCConnectorNode o, String name) {
+                return o.getInterfaceName ().equals (name);
             }
-        }
-        return true;
+        });
     }
 
-    public boolean isRequirementNameUnique(String s) {
-        Object o;
-        Requirement req;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof Requirement) {
-                req = (Requirement)o;
-                //TraceManager.addDev("analysing s = " + s + " vs " + req.getRequirementName());
-                if (req.getRequirementName().compareTo(s) == 0) {
-                    return false;
-                }
+    public boolean isRequirementNameUnique(String name) {
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkRequirement (Requirement o, String name) {
+                return o.getRequirementName ().equals (name);
             }
-        }
-        return true;
+        });
     }
 
-    public boolean isTObjectNameUnique(String s) {
-        Object o;
-        TClassInterface t;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = (TGComponent)(iterator.next());
-            if (o instanceof TClassInterface) {
-                t = (TClassInterface)o;
-                if (t.getClassName().equals(s)) {
-                    return false;
-                }
+    public boolean isTObjectNameUnique(String name) {
+        // FIXME: this is not coherent with findTObjectName !!!
+        return this.isNameUnique (name, new NameChecker () {
+            public boolean checkTClassInterface (TClassInterface o, String name) {
+                return o.getClassName ().equals (name);
             }
-        }
-        return true;
+        });
     }
 
     // For compatibility with ttool v0.41
     // Assumes no internal duplicate id
     public void checkForDuplicateId() {
-        TGComponent tgc1, tgc2;
-        int id;
-        int i, j;
-
-        for(i=0; i<componentList.size(); i++) {
-            tgc1 = (TGComponent)(componentList.get(i));
-            for(j=0; j<componentList.size(); j++) {
+        for(int i=0; i<componentList.size(); i++) {
+            TGComponent tgc1 = (TGComponent)(componentList.get(i));
+            for(int j=0; j<componentList.size(); j++)
                 if (j != i) {
-                    tgc2 = (TGComponent)(componentList.get(j));
+                    TGComponent tgc2 = (TGComponent)(componentList.get(j));
                     tgc2 = tgc2.getIfId(tgc1.getId());
                     if (tgc2 != null) {
                         TraceManager.addDev("*** Same ID ***");
@@ -3390,7 +2737,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
                         TraceManager.addDev("tgc2" + tgc2.getClass());
                     }
                 }
-            }
         }
     }
 
@@ -3402,164 +2748,101 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
       }
       }*/
 
-    public Vector getTClasses() {
-        Vector v = new Vector();
-        Object o;
-        Iterator iterator = componentList.iterator();
+    public Vector<TCDTClass> getTClasses() {
+        Vector<TCDTClass> v = new Vector<TCDTClass> ();
 
-        while(iterator.hasNext()) {
-            o = iterator.next();
-            if (o instanceof TCDTClass) {
-                v.add(o);
-            }
-        }
+        for (TGComponent o: this.componentList)
+            if (o instanceof TCDTClass)
+                v.add((TCDTClass) o);
 
         return v;
     }
 
     public Vector<String> getAllDataTypes() {
         Vector<String> v = new Vector<String>();
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
 
-            if (tgc instanceof AvatarBDDataType) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc instanceof AvatarBDDataType)
                 v.add(((AvatarBDDataType)(tgc)).getDataTypeName());
-            }
-        }
 
         return v;
     }
 
     public void removeSynchronizedGates(Vector v, TClassInterface t, TCDSynchroGateList tcdsgl ) {
-        TGComponent tgc;
-        TCDCompositionOperatorWithSynchro tgso;
-        Vector ttwoattrib;
         int j = 0;
-        TTwoAttributes tt;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
 
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof TCDCompositionOperatorWithSynchro) {
-                tgso = (TCDCompositionOperatorWithSynchro)tgc;
-
-                if ((tgso.getT1() == t) ||(tgso.getT2() == t)) {
-                    if (tgso.getSynchroGateList() != tcdsgl) {
-                        ttwoattrib = tgso.getSynchroGateList().getGates();
-                        for(j=0; j<ttwoattrib.size(); j++) {
-                            tt = (TTwoAttributes)(ttwoattrib.elementAt(j));
-                            if (tt.t1 == t) {
-                                v.removeElement(tt.ta1);
-                            } else {
-                                v.removeElement(tt.ta2);
-                            }
-                        }
+                TCDCompositionOperatorWithSynchro tgso = (TCDCompositionOperatorWithSynchro)tgc;
+
+                if (((tgso.getT1() == t) || (tgso.getT2() == t)) && tgso.getSynchroGateList() != tcdsgl) {
+                    Vector ttwoattrib = tgso.getSynchroGateList().getGates();
+                    for(j=0; j<ttwoattrib.size(); j++) {
+                        TTwoAttributes tt = (TTwoAttributes)(ttwoattrib.elementAt(j));
+                        if (tt.t1 == t)
+                            v.removeElement(tt.ta1);
+                        else
+                            v.removeElement(tt.ta2);
                     }
                 }
             }
-        }
     }
 
     public boolean isASynchronizedGate(TAttribute ta) {
-        TGComponent tgc;
-        TCDCompositionOperatorWithSynchro tgso;
-        Vector ttwoattrib;
-        TTwoAttributes tt;
-        Iterator iterator = componentList.listIterator();
-        int j;
-
-        //TraceManager.addDev("Checking " + ta);
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof TCDCompositionOperatorWithSynchro) {
-                tgso = (TCDCompositionOperatorWithSynchro)tgc;
-                ttwoattrib = tgso.getSynchroGateList().getGates();
-                for(j=0; j<ttwoattrib.size(); j++) {
-                    tt = (TTwoAttributes)(ttwoattrib.elementAt(j));
-                    //TraceManager.addDev("tt= " + tt);
-                    if ((tt.ta1 == ta) || (tt.ta2 == ta)) {
-                        //TraceManager.addDev("true");
+                TCDCompositionOperatorWithSynchro tgso = (TCDCompositionOperatorWithSynchro)tgc;
+                Vector ttwoattrib = tgso.getSynchroGateList().getGates();
+                for(int j=0; j<ttwoattrib.size(); j++) {
+                    TTwoAttributes tt = (TTwoAttributes)(ttwoattrib.elementAt(j));
+                    if ((tt.ta1 == ta) || (tt.ta2 == ta))
                         return true;
-                    }
-                    //TraceManager.addDev("false!");
                 }
             }
-        }
+
         return false;
     }
 
     public boolean hasAlreadyAnInstance(TCDTObject to) {
-        Object o;
-        TClassInterface t;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = iterator.next();
+        for (TGComponent o: this.componentList)
             if ((o instanceof TClassInterface)  && (!o.equals(to))){
-                t = (TClassInterface)o;
-                if (t.getClassName().compareTo(to.getClassName()) == 0) {
+                TClassInterface t = (TClassInterface)o;
+                if (t.getClassName().compareTo(to.getClassName()) == 0)
                     return true;
-                }
             }
-        }
 
         return false;
     }
 
     // updates attributes and gates
     public void updateInstances(TCDTClass tc) {
-        Object o;
-        TCDTObject to;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = iterator.next();
-            if (o instanceof TCDTObject){
-                to = (TCDTObject)o;
+        for (TGComponent o: this.componentList)
+            if (o instanceof TCDTObject) {
+                TCDTObject to = (TCDTObject)o;
                 if (to.getMasterTClass() == tc) {
                     to.updateAttributes(tc.getAttributes());
                     to.updateGates(tc.getGates());
                 }
             }
-        }
     }
 
     public void resetAllInstancesOf(TCDTClass tc) {
-        Object o;
-        TCDTObject to;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = iterator.next();
+        for (TGComponent o: this.componentList)
             if (o instanceof TCDTObject){
-                to = (TCDTObject)o;
-                if (to.getMasterTClass() == tc) {
+                TCDTObject to = (TCDTObject)o;
+                if (to.getMasterTClass() == tc)
                     to.reset();
-                }
             }
-        }
     }
 
     public TCDTClass findTClassByName(String name) {
-        TCDTClass tc;
-        Object o;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            o = iterator.next();
+        for (TGComponent o: this.componentList)
             if (o instanceof TCDTClass){
-                tc = (TCDTClass)o;
-                if (tc.getClassName().compareTo(name) == 0) {
+                TCDTClass tc = (TCDTClass)o;
+                if (tc.getClassName().compareTo(name) == 0)
                     return tc;
-                }
             }
-        }
+
         return null;
     }
 
@@ -3626,13 +2909,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     public int getRealMinX() {
         int res = maxX;
-        int cur;
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            cur = tgc.getCurrentMinX();
+        for (TGComponent tgc: this.componentList) {
+            int cur = tgc.getCurrentMinX();
             //TraceManager.addDev("cur=" + cur + " res=" + res + " tgc=" + tgc.getName());
             if (cur < res)
                 res = cur;
@@ -3649,13 +2928,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     public int getRealMinY() {
         int res = maxY;
-        int cur;
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            cur = tgc.getCurrentMinY();
+        for (TGComponent tgc: this.componentList) {
+            int cur = tgc.getCurrentMinY();
             if (cur < res)
                 res = cur;
         }
@@ -3671,13 +2946,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     public int getRealMaxX() {
         int res = limit;
-        int cur;
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            cur = tgc.getCurrentMaxX();
+        for (TGComponent tgc: this.componentList) {
+            int cur = tgc.getCurrentMaxX();
             if (cur > res)
                 res = cur;
         }
@@ -3686,13 +2957,9 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     public int getRealMaxY() {
         int res = limit;
-        int cur;
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            cur = tgc.getCurrentMaxY();
+        for (TGComponent tgc: this.componentList) {
+            int cur = tgc.getCurrentMaxY();
             if (cur > res)
                 res = cur;
         }
@@ -3705,15 +2972,11 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
     public TGComponent getSecondTGComponent(TGConnector tgco) {
         TGConnectingPoint p = tgco.getTGConnectingPointP2();
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc.belongsToMe(p)) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc.belongsToMe(p))
                 return tgc;
-            }
-        }
+
         return null;
     }
 
@@ -3735,29 +2998,18 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void checkAllMySize() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             tgc.checkAllMySize();
-        }
     }
 
     public void enhance() {
-
     }
 
     public void autoAdjust() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (tgc instanceof TGAutoAdjust) {
+        for (TGComponent tgc: this.componentList)
+            if (tgc instanceof TGAutoAdjust)
                 ((TGAutoAdjust)tgc).autoAdjust(adjustMode);
-            }
-        }
+
         adjustMode = (adjustMode + 1)% 2;
 
         repaint();
@@ -3794,9 +3046,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
 
         TGConnector tgco;
 
-        TGComponent tgc;
-        Iterator iterator;
-
         for(i=0; i<added.getNbConnectingPoint(); i++) {
 
             tgcp = added.getTGConnectingPointAtIndex(i);
@@ -3806,9 +3055,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
                 found = null;
                 distance = 100;
 
-                iterator = componentList.listIterator();
-                while(iterator.hasNext()) {
-                    tgc = (TGComponent)(iterator.next());
+                for (TGComponent tgc: this.componentList)
                     if (tgc != added) {
                         for(j=0; j<tgc.getNbConnectingPoint(); j++) {
                             tgcp1 = tgc.getTGConnectingPointAtIndex(j);
@@ -3828,7 +3075,6 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
                         }
 
                     }
-                }
                 if (found != null) {
                     //TraceManager.addDev("Adding connector");
                     if (found.isIn()) {
@@ -3838,7 +3084,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
                     }
                     found.setFree(false);
                     tgcp.setFree(false);
-                    componentList.add(tgco);
+                    this.componentList.add(tgco);
                     //TraceManager.addDev("Connector added");
                 }
             }
@@ -3847,39 +3093,25 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
     }
 
     public void resetAllDIPLOIDs() {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             tgc.setDIPLOID(-1);
-        }
     }
 
     public void getListOfBreakPoints(ArrayList<Point> points, int taskID) {
-        Point p;
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-        int i;
-        boolean found;
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc.getBreakpoint() && (tgc.getDIPLOID() != -1)) {
-                found = false;
-                for(i=0; i<points.size(); i++) {
+                boolean found = false;
+                for(int i=0; i<points.size(); i++)
                     if (points.get(i).y == tgc.getDIPLOID()) {
                         found = true;
                         break;
                     }
-                }
+
                 if (!found) {
-                    p = new Point(taskID, tgc.getDIPLOID());
+                    Point p = new Point(taskID, tgc.getDIPLOID());
                     points.add(p);
                 }
             }
-        }
-
     }
 
     public String svgCapture() {
@@ -3933,30 +3165,36 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree {
         }
     }
 
-    public void searchForText(String text, Vector<Object> elements) {
-        TraceManager.addDev("Searching for " + text + " in " + this);
-
-        Iterator iterator = componentList.listIterator();
-        TGComponent tgc;
-        String save;
+    public boolean changeStateMachineTabName (String oldValue, String newValue) {
+        int stateMachineTab = -1;
+        for(int i = 0; i<this.tp.tabbedPane.getTabCount(); i++) {
+            if (this.tp.tabbedPane.getTitleAt (i).equals (newValue))
+                return false;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            tgc.searchForText(text, elements);
-            /*save = tgc.saveInXML().toString().toLowerCase();
-              if (save.indexOf(text) >= 0) {
-              TraceManager.addDev("Found " + tgc);
-              elements.add(tgc);
-              CheckingError ce = new CheckingError(CheckingError.INFO, tgc.toString());
-              ce.setTDiagramPanel(this);
-              ce.setTGComponent(tgc);
-              elements.add(ce);
-              }*/
+            if (this.tp.tabbedPane.getTitleAt (i).equals (oldValue))
+                stateMachineTab = i;
         }
 
-    }
+        if (stateMachineTab < 0)
+            return false;
 
+        this.tp.tabbedPane.setTitleAt (stateMachineTab, newValue);
+        this.tp.tabbedPane.setToolTipTextAt (stateMachineTab, "Opens the state machine of " + newValue);
 
+        //change panel name
+        for (int j=0; j<this.tp.panels.size(); j++) {
+            TDiagramPanel tdp = (TDiagramPanel) (this.tp.panels.elementAt(j));
+            if (tdp.getName().equals(oldValue))
+                tdp.setName(newValue);
+        }
 
+        return true;
+    }
 
+    public void searchForText(String text, Vector<Object> elements) {
+        TraceManager.addDev("Searching for " + text + " in " + this);
+
+        for (TGComponent tgc: this.componentList)
+            tgc.searchForText(text, elements);
+    }
 }
diff --git a/src/ui/TGComponentManager.java b/src/ui/TGComponentManager.java
index 7107a14e3507c6f67f3eaa41de8ffb66b7090172..e8f57cd0899214c21d2df288c7b6642577c66a9f 100755
--- a/src/ui/TGComponentManager.java
+++ b/src/ui/TGComponentManager.java
@@ -342,10 +342,12 @@ public class TGComponentManager {
 
     // AVATAR BD -> starts at 5000
     public static final int AVATARBD_BLOCK = 5000;
-    public static final int AVATARBD_CRYPTOBLOCK = 5004;
     public static final int AVATARBD_COMPOSITION_CONNECTOR = 5001;
     public static final int AVATARBD_PORT_CONNECTOR = 5002;
     public static final int AVATARBD_DATATYPE = 5003;
+    public static final int AVATARBD_CRYPTOBLOCK = 5004;
+    public static final int AVATARBD_LIBRARYFUNCTION = 5005;
+    public static final int AVATARBD_CRYPTOLIBRARYFUNCTION = 5006;
 
     // AVATAR SMD -> starts at 5100
     public static final int AVATARSMD_START_STATE = 5100;
@@ -497,6 +499,13 @@ public class TGComponentManager {
         case AVATARBD_DATATYPE:
             tgc = new AvatarBDDataType(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
             break;
+        case AVATARBD_LIBRARYFUNCTION:
+            tgc = new AvatarBDLibraryFunction (x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
+            break;
+        case AVATARBD_CRYPTOLIBRARYFUNCTION:
+            tgc = new AvatarBDLibraryFunction (x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
+            ((AvatarBDLibraryFunction)tgc).addCryptoElements();
+            break;
         case AVATARSMD_START_STATE:
             tgc = new AvatarSMDStartState(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
             break;
diff --git a/src/ui/TGUIAction.java b/src/ui/TGUIAction.java
index f16ad5e81e2d2125780a11fcabaf5e65ba0fd275..a4691fae081482c84e4f1f4aa049b8c81270665d 100755
--- a/src/ui/TGUIAction.java
+++ b/src/ui/TGUIAction.java
@@ -334,6 +334,8 @@ public class TGUIAction extends AbstractAction {
     public static final int ABD_DATATYPE = 324;
     public static final int ABD_COMPOSITION_CONNECTOR = 290;
     public static final int ABD_PORT_CONNECTOR = 295;
+    public static final int ABD_LIBRARYFUNCTION = 428;
+    public static final int ABD_CRYPTOLIBRARYFUNCTION = 429;
 
     // AVATAR State Machine
     public static final int ASMD_EDIT = 291;
@@ -1049,6 +1051,8 @@ public class TGUIAction extends AbstractAction {
         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);
+        actions[ABD_LIBRARYFUNCTION] = new TAction("abd-libraryfunction", "Add a library function", IconManager.imgic5070, IconManager.imgic5000, "Library Function", "Add a Library Function to the currently opened AVATAR Block Diagram", 0);
+        actions[ABD_CRYPTOLIBRARYFUNCTION] = new TAction("abd-cryptolibraryfunction", "Add a crypto library function", IconManager.imgic5070, IconManager.imgic5000, "Crypto library function", "Add a Crypto Library Function to the currently opened AVATAR Block Diagram", 0);
 
         // AVATAR State Machine Diagrams
         actions[ASMD_EDIT] = new TAction("edit-asmd-diagram", "Edit AVATAR state machine diagram", IconManager.imgic100, IconManager.imgic101, "Edit AVATAR state machine diagram", "Make it possible to edit the currently opened AVATAR state machine diagram", 0);
diff --git a/src/ui/avatarbd/AvatarBDBlock.java b/src/ui/avatarbd/AvatarBDBlock.java
index f5cd407a7b53a5ee986bcd402c63cba422995179..5bff4a48da2790eccf2f47a0c0e659df7a6e6e71 100644
--- a/src/ui/avatarbd/AvatarBDBlock.java
+++ b/src/ui/avatarbd/AvatarBDBlock.java
@@ -58,7 +58,7 @@ import ui.window.*;
 import ui.avatarsmd.*;
 
 
-public class AvatarBDBlock extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent, GenericTree {
+public class AvatarBDBlock extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent, GenericTree, AvatarBDStateMachineOwner {
 
     private static String GLOBAL_CODE_INFO = "(global code)";
 
@@ -84,7 +84,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
 
 
     // TAttribute, AvatarMethod, AvatarSignal
-    protected Vector myAttributes, myMethods, mySignals;
+    protected Vector<TAttribute> myAttributes;
+    protected Vector<AvatarMethod> myMethods;
+    protected Vector<AvatarSignal> mySignals;
     protected String [] globalCode;
 
 
@@ -138,9 +140,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
 
         myImageIcon = IconManager.imgic700;
 
-        myAttributes = new Vector();
-        myMethods = new Vector();
-        mySignals = new Vector();
+        this.myAttributes = new Vector<TAttribute> ();
+        this.myMethods = new Vector<AvatarMethod> ();
+        this.mySignals = new Vector<AvatarSignal> ();
 
         actionOnAdd();
     }
@@ -263,12 +265,12 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
             g.setFont(f);
             int step = si + 2;
 
-            while(index < myAttributes.size()) {
+            while(index < this.myAttributes.size()) {
                 cpt += step ;
                 if (cpt >= (height - textX)) {
                     break;
                 }
-                a = (TAttribute)(myAttributes.get(index));
+                a = this.myAttributes.get(index);
                 attr = a.toAvatarString();
                 w = g.getFontMetrics().stringWidth(attr);
                 if ((w + (2 * textX) + 1) < width) {
@@ -299,7 +301,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         // Methods
         if (((AvatarBDPanel)tdp).areAttributesVisible()) {
             limitMethod = -1;
-            if (myMethods.size() > 0) {
+            if (this.myMethods.size() > 0) {
                 if (cpt < height) {
                     cpt += textY1;
                     g.drawLine(x, y+cpt, x+width, y+cpt);
@@ -318,12 +320,12 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
             g.setFont(f);
             int step = si + 2;
 
-            while(index < myMethods.size()) {
+            while(index < this.myMethods.size()) {
                 cpt += step ;
                 if (cpt >= (height - textX)) {
                     break;
                 }
-                am = (AvatarMethod)(myMethods.get(index));
+                am = this.myMethods.get (index);
                 method = "~ " + am.toString();
                 w = g.getFontMetrics().stringWidth(method);
                 if ((w + (2 * textX) + 1) < width) {
@@ -349,7 +351,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         // Signals
         if (((AvatarBDPanel)tdp).areAttributesVisible()) {
 
-            if (mySignals.size() > 0) {
+            if (this.mySignals.size() > 0) {
                 if (cpt < height) {
                     cpt += textY1;
                     g.drawLine(x, y+cpt, x+width, y+cpt);
@@ -368,12 +370,12 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
             g.setFont(f);
             int step = si + 2;
 
-            while(index < mySignals.size()) {
+            while(index < this.mySignals.size()) {
                 cpt += step ;
                 if (cpt >= (height - textX)) {
                     break;
                 }
-                as = (AvatarSignal)(mySignals.get(index));
+                as = this.mySignals.get (index);
                 signal = "~ " + as.toString();
                 w = g.getFontMetrics().stringWidth(signal);
                 if ((w + (2 * textX) + 1) < width) {
@@ -531,7 +533,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         }
 
         if ((limitMethod == -1) && (limitAttr == -1)) {
-            if (mySignals.size() > 1) {
+            if (this.mySignals.size() > 1) {
                 tab = 2;
             }
         }
@@ -541,7 +543,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         if (ttdp instanceof AvatarBDPanel) {
             mainCode = ((AvatarBDPanel)(ttdp)).getMainCode();
         }
-        JDialogAvatarBlock jdab = new JDialogAvatarBlock(myAttributes, myMethods, mySignals, null, frame, "Setting attributes of " + value, "Attribute", tab, globalCode, true, mainCode);
+        JDialogAvatarBlock jdab = new JDialogAvatarBlock(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);
@@ -679,19 +681,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
     }
 
     protected String translateExtraParam() {
-        TAttribute a;
-        AvatarMethod am;
-        AvatarSignal as;
-
-        //System.out.println("Loading extra params of " + value);
-        //value = "";
         StringBuffer sb = new StringBuffer("<extraparam>\n");
         sb.append("<CryptoBlock value=\"" + isCryptoBlock + "\" />\n");
-        for(int i=0; i<myAttributes.size(); i++) {
-            //System.out.println("Attribute:" + i);
-            a = (TAttribute)(myAttributes.elementAt(i));
-            //System.out.println("Attribute:" + i + " = " + a.getId());
-            //value = value + a + "\n";
+        for (TAttribute a: this.myAttributes) {
             sb.append("<Attribute access=\"");
             sb.append(a.getAccess());
             sb.append("\" id=\"");
@@ -704,20 +696,12 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
             sb.append(a.getTypeOther());
             sb.append("\" />\n");
         }
-        for(int i=0; i<myMethods.size(); i++) {
-            //System.out.println("Attribute:" + i);
-            am = (AvatarMethod)(myMethods.elementAt(i));
-            //System.out.println("Attribute:" + i + " = " + a.getId());
-            //value = value + a + "\n";
+        for (AvatarMethod am: this.myMethods) {
             sb.append("<Method value=\"");
             sb.append(am.toSaveString());
             sb.append("\" />\n");
         }
-        for(int i=0; i<mySignals.size(); i++) {
-            //System.out.println("Attribute:" + i);
-            as = (AvatarSignal)(mySignals.elementAt(i));
-            //System.out.println("Attribute:" + i + " = " + a.getId());
-            //value = value + a + "\n";
+        for (AvatarSignal as: this.mySignals) {
             sb.append("<Signal value=\"");
             sb.append(as.toString());
             sb.append("\" />\n");
@@ -794,7 +778,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
                                     }
                                     TAttribute ta = new TAttribute(access, id, valueAtt, type, typeOther);
                                     ta.isAvatar = true;
-                                    myAttributes.addElement(ta);
+                                    this.myAttributes.addElement(ta);
                                 }
                             }
                             if (elt.getTagName().equals("Method")) {
@@ -819,7 +803,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
                                 if (am != null) {
                                     //TraceManager.addDev("Setting to " + implementation + " the implementation of " + am);
                                     am.setImplementationProvided(implementation);
-                                    myMethods.add(am);
+                                    this.myMethods.add(am);
                                 }
                             }
                             if (elt.getTagName().equals("Signal")) {
@@ -831,7 +815,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
                                 }
                                 as = AvatarSignal.isAValidSignal(signal);
                                 if (as != null) {
-                                    mySignals.add(as);
+                                    this.mySignals.add(as);
                                 } else {
                                     TraceManager.addDev("Invalid signal:" + signal);
                                 }
@@ -959,96 +943,76 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         return TGComponentManager.AVATARBD_PORT_CONNECTOR;
     }
 
-    public Vector getAttributeList() {
-        return myAttributes;
+    public Vector<TAttribute> getAttributeList() {
+        return this.myAttributes;
     }
 
     public TAttribute getAttributeByName(String _name) {
-        TAttribute a;
-        for(int i=0; i<myAttributes.size(); i++) {
-            a = (TAttribute)(myAttributes.elementAt(i));
-            if (a.getId().compareTo(_name) == 0) {
+        for (TAttribute a: this.myAttributes)
+            if (a.getId().compareTo(_name) == 0)
                 return a;
-            }
-        }
         return null;
     }
 
-    public Vector getMethodList() {
-        return myMethods;
+    public Vector<AvatarMethod> getMethodList() {
+        return this.myMethods;
     }
 
-    public Vector getSignalList() {
-        return mySignals;
+    public Vector<AvatarSignal> getSignalList() {
+        return this.mySignals;
     }
 
-    public Vector getOutSignalList() {
-        Vector v = new Vector();
-        AvatarSignal s;
-	for(int i=0; i<mySignals.size(); i++) {
-            s = (AvatarSignal)(mySignals.get(i));
-            if (s.getInOut() == AvatarSignal.OUT) {
+    public Vector<AvatarSignal> getOutSignalList() {
+        Vector<AvatarSignal> v = new Vector<AvatarSignal> ();
+	for(AvatarSignal s: this.mySignals)
+            if (s.getInOut() == AvatarSignal.OUT)
                 v.add(s);
-            }
-        }
         return v;
     }
 
-    public Vector getInSignalList() {
-        Vector v = new Vector();
-        AvatarSignal s;
-	for(int i=0; i<mySignals.size(); i++) {
-            s = (AvatarSignal)(mySignals.get(i));
-            if (s.getInOut() == AvatarSignal.IN) {
+    public Vector<AvatarSignal> getInSignalList() {
+        Vector<AvatarSignal> v = new Vector<AvatarSignal> ();
+	for(AvatarSignal s: this.mySignals)
+            if (s.getInOut() == AvatarSignal.IN)
                 v.add(s);
-            }
-        }
         return v;
     }
 
-    public Vector getAllMethodList() {
+    public Vector<AvatarMethod> getAllMethodList() {
         if (getFather() == null) {
-            return myMethods;
+            return this.myMethods;
         }
 
-        Vector v = new Vector();
-        v.addAll(myMethods);
-        v.addAll(((AvatarBDBlock)getFather()).getAllMethodList());
+        Vector<AvatarMethod> v = new Vector<AvatarMethod> ();
+        v.addAll(this.myMethods);
+        v.addAll(((AvatarBDBlock) getFather()).getAllMethodList());
         return v;
     }
 
-    public Vector getAllSignalList() {
+    public Vector<AvatarSignal> getAllSignalList() {
         if (getFather() == null) {
-            return mySignals;
+            return this.mySignals;
         }
 
-        Vector v = new Vector();
-        v.addAll(mySignals);
+        Vector<AvatarSignal> v = new Vector<AvatarSignal> ();
+        v.addAll(this.mySignals);
         v.addAll(((AvatarBDBlock)getFather()).getAllSignalList());
         return v;
     }
 
-    public Vector getAllTimerList() {
-        Vector v = new Vector();
-        TAttribute a;
+    public Vector<String> getAllTimerList() {
+        Vector<String> v = new Vector<String> ();
 
-        for(int i=0; i<myAttributes.size(); i++) {
-            a = (TAttribute)(myAttributes.elementAt(i));
-            if (a.getType() == TAttribute.TIMER) {
+        for (TAttribute a: this.myAttributes)
+            if (a.getType() == TAttribute.TIMER)
                 v.add(a.getId());
-            }
-        }
         return v;
     }
 
     public AvatarSignal getAvatarSignalFromName(String _name) {
-        AvatarSignal as;
-        for(int i=0; i<mySignals.size(); i++) {
-            as = (AvatarSignal)(mySignals.get(i));
-            if (as.getId().compareTo(_name) == 0) {
+        for (AvatarSignal as: this.mySignals)
+            if (as.getId().compareTo(_name) == 0)
                 return as;
-            }
-        }
         return null;
     }
 
@@ -1073,14 +1037,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         }
         _id = _id.trim();
         //TraceManager.addDev("Searching for signal with id=" + _id);
-        AvatarSignal as;
-        for(int i=0; i<mySignals.size(); i++) {
-            as = (AvatarSignal)(mySignals.get(i));
-            if (as.getId().compareTo(_id) == 0) {
-                //TraceManager.addDev("found");
+        for (AvatarSignal as: this.mySignals)
+            if (as.getId().compareTo(_id) == 0)
                 return as;
-            }
-        }
         //TraceManager.addDev("Not found");
         return null;
     }
@@ -1107,190 +1066,49 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
     public void removeCryptoElements() {
         isCryptoBlock = false;
 
-        // Adding function
-        String method = "Message aencrypt(Message msg, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "Message adecrypt(Message msg, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "Key pk(Key k)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "Message sign(Message msg, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "bool verifySign(Message msg1, Message sig, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-
-        /* Certifying */
-        method = "Message cert(Key k, Message msg)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "bool verifyCert(Message cert, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "Key getpk(Message cert)";
-        removeMethodIfApplicable(myMethods, method);
-
-
-        method = "Message sencrypt(Message msg, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "Message sdecrypt(Message msg, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-
-        method = "Message hash(Message msg)";
-        removeMethodIfApplicable(myMethods, method);
-
-        method = "Message MAC(Message msg, Key k)";
-        removeMethodIfApplicable(myMethods, method);
-        method = "bool verifyMAC(Message msg, Key k, Message macmsg)";
-        removeMethodIfApplicable(myMethods, method);
-
-        method = "Message concat2(Message msg1, Message msg2)";
-        removeMethodIfApplicable(myMethods, method);
-
-        method = "Message concat3(Message msg1, Message msg2, Message msg3)";
-        removeMethodIfApplicable(myMethods, method);
-
-        method = "Message concat4(Message msg1, Message msg2, Message msg3, Message msg4)";
-        removeMethodIfApplicable(myMethods, method);
-
-
-        method = "get2(Message msg, Message msg1, Message msg2)";
-        removeMethodIfApplicable(myMethods, method);
-
-        method = "get3(Message msg, Message msg1, Message msg2, Message msg3)";
-        removeMethodIfApplicable(myMethods, method);
-
-        method = "get4(Message msg, Message msg1, Message msg2, Message msg3, Message msg4)";
-        removeMethodIfApplicable(myMethods, method);
-
-        // Adding channels chin chout
-        /*String signal = "in chin(Message msg)";
-          addSignalIfApplicable(mySignals, signal);
-          signal = "out chout(Message msg)";
-          addSignalIfApplicable(mySignals, signal);*/
-
+        for (String method: AvatarMethod.cryptoMethods)
+            this.removeMethodIfApplicable (method);
     }
 
     public void addCryptoElements() {
         isCryptoBlock = true;
 
-        // Adding function
-        String method = "Message aencrypt(Message msg, Key k)";
-        addMethodIfApplicable(myMethods, method);
-        method = "Message adecrypt(Message msg, Key k)";
-        addMethodIfApplicable(myMethods, method);
-        method = "Key pk(Key k)";
-        addMethodIfApplicable(myMethods, method);
-        method = "Message sign(Message msg, Key k)";
-        addMethodIfApplicable(myMethods, method);
-        method = "bool verifySign(Message msg1, Message sig, Key k)";
-        addMethodIfApplicable(myMethods, method);
-
-        /* Certifying */
-        method = "Message cert(Key k, Message msg)";
-        addMethodIfApplicable(myMethods, method);
-        method = "bool verifyCert(Message cert, Key k)";
-        addMethodIfApplicable(myMethods, method);
-        method = "Key getpk(Message cert)";
-        addMethodIfApplicable(myMethods, method);
-
-
-        method = "Message sencrypt(Message msg, Key k)";
-        addMethodIfApplicable(myMethods, method);
-        method = "Message sdecrypt(Message msg, Key k)";
-        addMethodIfApplicable(myMethods, method);
-
-        method = "Message hash(Message msg)";
-        addMethodIfApplicable(myMethods, method);
-
-        method = "Message MAC(Message msg, Key k)";
-        addMethodIfApplicable(myMethods, method);
-        method = "bool verifyMAC(Message msg, Key k, Message macmsg)";
-        addMethodIfApplicable(myMethods, method);
-
-        method = "Message concat2(Message msg1, Message msg2)";
-        addMethodIfApplicable(myMethods, method);
-
-        method = "Message concat3(Message msg1, Message msg2, Message msg3)";
-        addMethodIfApplicable(myMethods, method);
-
-        method = "Message concat4(Message msg1, Message msg2, Message msg3, Message msg4)";
-        addMethodIfApplicable(myMethods, method);
-
-
-        method = "get2(Message msg, Message msg1, Message msg2)";
-        addMethodIfApplicable(myMethods, method);
-
-        method = "get3(Message msg, Message msg1, Message msg2, Message msg3)";
-        addMethodIfApplicable(myMethods, method);
-
-        method = "get4(Message msg, Message msg1, Message msg2, Message msg3, Message msg4)";
-        addMethodIfApplicable(myMethods, method);
-
-        // Adding channels chin chout
-        /*String signal = "in chin(Message msg)";
-          addSignalIfApplicable(mySignals, signal);
-          signal = "out chout(Message msg)";
-          addSignalIfApplicable(mySignals, signal);*/
-
+        for (String method: AvatarMethod.cryptoMethods)
+            this.addMethodIfApplicable (method);
     }
 
-    private void removeMethodIfApplicable(Vector _v, String _s) {
-        AvatarMethod am = null;
-        for(Object o: _v) {
-            if (o instanceof AvatarMethod) {
-                am = (AvatarMethod)o;
-                if (am.toString().compareTo(_s) == 0) {
-                    break;
-                }
+    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;
             }
         }
-
-        if (am != null) {
-            _v.remove(am);
-        }
     }
 
-    private void addMethodIfApplicable(Vector _v, String _s) {
-        AvatarMethod am;
-        for(Object o: _v) {
-            if (o instanceof AvatarMethod) {
-                am = (AvatarMethod)o;
-                if (am.toString().compareTo(_s) == 0) {
+    private void addMethodIfApplicable (String methodString) {
+        for (AvatarMethod am: this.myMethods)
+            // TODO: replace by a more OO way...
+            if (am.toString ().equals (methodString))
                     return;
-                }
-            }
-        }
 
-        am = AvatarMethod.isAValidMethod(_s);
-        if (am != null) {
-            _v.add(am);
-        }
-    }
-
-    private void addSignalIfApplicable(Vector _v, String _s) {
-        AvatarSignal as;
-        for(Object o: _v) {
-            if (o instanceof AvatarSignal) {
-                as = (AvatarSignal)o;
-                if (as.toString().compareTo(_s) == 0) {
-                    return;
-                }
-            }
-        }
-
-        as = AvatarSignal.isAValidSignal(_s);
-        if (as != null) {
-            _v.add(as);
-        }
+        AvatarMethod am = AvatarMethod.isAValidMethod (methodString);
+        if (am != null)
+            this.myMethods.add (am);
     }
 
     public boolean hasDefinitions() {
-        return ((myAttributes.size() + myMethods.size() + mySignals.size() + nbInternalTGComponent)>0);
+        return ((this.myAttributes.size() + this.myMethods.size() + this.mySignals.size() + nbInternalTGComponent)>0);
     }
 
     // Main Tree
 
     public int getChildCount() {
         //TraceManager.addDev("Counting childs!");
-        return myAttributes.size() + myMethods.size() + mySignals.size() + nbInternalTGComponent;
+        return this.myAttributes.size() + this.myMethods.size() + this.mySignals.size() + nbInternalTGComponent;
     }
 
     public Object getChild(int index) {
@@ -1302,19 +1120,19 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         }
 
         index = index - nbInternalTGComponent;
-        sa = myAttributes.size();
+        sa = this.myAttributes.size();
         //      TraceManager.addDev("index = " + index + " sa=" + sa);
         if (sa <= index) {
             index = index - sa;
-            sa = myMethods.size();
+            sa = this.myMethods.size();
             if (sa <= index) {
-                return mySignals.get(index - sa);
+                return this.mySignals.get(index - sa);
             } else {
-                return myMethods.get(index);
+                return this.myMethods.get(index);
             }
         }
 
-        return myAttributes.get(index);
+        return this.myAttributes.get(index);
     }
 
     public int getIndexOfChild(Object child) {
@@ -1327,15 +1145,15 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
         }
 
         if (child instanceof TAttribute) {
-            return myAttributes.indexOf(child) + nbInternalTGComponent;
+            return this.myAttributes.indexOf(child) + nbInternalTGComponent;
         }
 
         if (child instanceof AvatarMethod) {
-            return myMethods.indexOf(child) + myAttributes.size() + nbInternalTGComponent;
+            return this.myMethods.indexOf(child) + this.myAttributes.size() + nbInternalTGComponent;
         }
 
         if (child instanceof AvatarSignal) {
-            return mySignals.indexOf(child) + myAttributes.size() + myMethods.size() + nbInternalTGComponent;
+            return this.mySignals.indexOf(child) + this.myAttributes.size() + this.myMethods.size() + nbInternalTGComponent;
         }
 
         return -1;
@@ -1346,14 +1164,12 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S
     }
 
     public void resetConfidentialityOfAttributes() {
-        TAttribute a;
-
-        for(int i=0; i<myAttributes.size(); i++) {
-            a = (TAttribute)(myAttributes.elementAt(i));
+        for (TAttribute a: this.myAttributes)
             a.setConfidentialityVerification(TAttribute.NOT_VERIFIED);
-        }
     }
 
-
-
+    @Override
+    public String getOwnerName () {
+        return this.getBlockName ();
+    }
 }
diff --git a/src/ui/avatarbd/AvatarBDLibraryFunction.java b/src/ui/avatarbd/AvatarBDLibraryFunction.java
new file mode 100644
index 0000000000000000000000000000000000000000..9c84bde989c955040506f3fba6ff8715925d2770
--- /dev/null
+++ b/src/ui/avatarbd/AvatarBDLibraryFunction.java
@@ -0,0 +1,1008 @@
+/* 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 java.util.LinkedList;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+
+import java.awt.Graphics;
+import java.awt.Font;
+import java.awt.Color;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+
+import myutil.GraphicLib;
+import myutil.TraceManager;
+
+import ui.TGCScalableWithInternalComponent;
+import ui.TAttribute;
+import ui.TGComponent;
+import ui.TDiagramPanel;
+import ui.MalformedModelingException;
+import ui.TGConnectingPoint;
+import ui.IconManager;
+import ui.ColorManager;
+import ui.TGComponentManager;
+import ui.AvatarSignal;
+import ui.AvatarMethod;
+import ui.AvatarDesignPanel;
+import ui.avatarsmd.AvatarSMDPanel;
+import ui.window.JDialogAvatarLibraryFunction;
+
+/**
+ * This class represent a Library Function block on an avatar block diagram.
+ *
+ * @version 1.0 04.08.2016
+ * @author Florian LUGOU
+ */
+public class AvatarBDLibraryFunction extends TGCScalableWithInternalComponent implements AvatarBDStateMachineOwner {
+
+    /**
+     * Stereotype for standard library function.
+     */
+    private static final String stereotype = "library";
+
+    /**
+     * Stereotype for cryptographic library function.
+     */
+    private static final String stereotypeCrypto = "cryptolibrary";
+
+    /**
+     * Maximum font size for this compontent.
+     */
+    private static final int maxFontSize = 12;
+
+    /**
+     * Minimum font size for this compontent.
+     */
+    private static final int minFontSize = 4;
+
+    /**
+     * The horizontal spacing between text and left and right borders.
+     */
+    private static final int paddingHorizontal = 7;
+
+    /**
+     * The vertical spacing before and after text.
+     */
+    private static final int paddingVertical   = 3;
+
+    /**
+     * Used to know where the user double clicked
+     */
+    private int limitName;
+
+    /**
+     * Used to know where the user double clicked
+     */
+    private int limitParameters;
+
+    /**
+     * Used to know where the user double clicked
+     */
+    private int limitSignals;
+    
+    /**
+     * Current font size.
+     */
+    private int currentFontSize = -1;
+
+    /**
+     * Equals True when the box is large enough for the text to be displayed.
+     */
+    private boolean displayText = true;
+
+    /**
+     * Equals True when the box is large enough for the icon to be drawn.
+     */
+    private boolean iconIsDrawn = false;
+
+    /**
+     * For function that use cryptographic primitives.
+     */
+    private boolean isCrypto = false;
+
+    /**
+     * The list of parameters of the function.
+     */
+    private LinkedList<TAttribute> parameters;
+
+    /**
+     * The list of variables local to the function.
+     */
+    private LinkedList<TAttribute> attributes;
+
+    /**
+     * The list of signals used by the function.
+     */
+    private LinkedList<AvatarSignal> signals;
+
+    /**
+     * The list of attribute that will hold the return values of the function.
+     */
+    private LinkedList<TAttribute> returnAttributes;
+
+    /**
+     * The list of methods that can be used by the function.
+     */
+    private LinkedList<AvatarMethod> methods;
+
+    /**
+     * Standard constructor for a library function block.
+     *
+     * @param x
+     *      The absolute coordinate of the block along X.
+     * @param y
+     *      The absolute coordinate of the block along Y.
+     * @param minX
+     *      The minimum authorized coordinate along X.
+     * @param maxX
+     *      The maximum authorized coordinate along X.
+     * @param minY
+     *      The minimum authorized coordinate along Y.
+     * @param maxY
+     *      The maximum authorized coordinate along Y.
+     * @param pos
+     *      Indicates whether the position is considered as relative to this father's component.
+     * @param father
+     *      The father component in the diagram.
+     * @param tdb
+     *      The diagram panel.
+     */
+    public AvatarBDLibraryFunction (
+            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);
+
+        this.width = 160;
+        this.height = 100;
+        this.minWidth = 5;
+        this.minHeight = 2;
+
+        this.nbConnectingPoint = 0;
+        this.connectingPoint = new TGConnectingPoint[0];
+        this.addTGConnectingPointsComment();
+
+        this.nbInternalTGComponent = 0;
+
+        this.moveable = true;
+        this.editable = true;
+        this.multieditable = true;
+        this.removable = true;
+        this.userResizable = true;
+
+        // Find a new unused name
+        int i;
+        for (i=0; i<100; i++) {
+            String tmpName = "LibraryFunction" + i;
+            if (this.tdp.isAvatarBlockNameUnique (tmpName) &&
+                true) { // TODO: check if no other tab has same name
+                this.name = tmpName;
+                this.setValue(tmpName);
+                break;
+            }
+        }
+        if  (i == 100) {
+            // TODO: throw exception
+        }
+
+        this.currentFontSize = this.maxFontSize;
+        this.oldScaleFactor = this.tdp.getZoom();
+
+        // TODO: change that
+        this.myImageIcon = IconManager.imgic700;
+
+        this.parameters = new LinkedList<TAttribute> ();
+        this.attributes = new LinkedList<TAttribute> ();
+        this.signals    = new LinkedList<AvatarSignal> ();
+        this.returnAttributes = new LinkedList<TAttribute> ();
+        this.methods = new LinkedList<AvatarMethod> ();
+
+        // Ask the panel to add a tab for the state machine diagram.
+        this.actionOnAdd();
+    }
+
+    public TDiagramPanel getDiagramPanel () {
+        return this.tdp;
+    }
+
+    public String getFunctionName () {
+        return this.name;
+    }
+
+    public LinkedList<TAttribute> getParameters () {
+        return this.parameters;
+    }
+
+    public void resetParameters () {
+        this.parameters = new LinkedList<TAttribute> ();
+    }
+
+    public void addParameter (TAttribute parameter) {
+        this.parameters.add (parameter);
+    }
+
+    public LinkedList<AvatarSignal> getSignals () {
+        return this.signals;
+    }
+
+    public void resetSignals () {
+        this.signals = new LinkedList<AvatarSignal> ();
+    }
+
+    public void addSignal (AvatarSignal signal) {
+        this.signals.add (signal);
+    }
+
+    public LinkedList<TAttribute> getAttributes () {
+        return this.attributes;
+    }
+
+    public void resetAttributes () {
+        this.attributes = new LinkedList<TAttribute> ();
+    }
+
+    public void addAttribute (TAttribute attribute) {
+        this.attributes.add (attribute);
+    }
+
+    public LinkedList<TAttribute> getReturnAttributes () {
+        return this.returnAttributes;
+    }
+
+    public void resetReturnAttributes () {
+        this.returnAttributes = new LinkedList<TAttribute> ();
+    }
+
+    public void addReturnAttribute (TAttribute returnAttribute) {
+        this.returnAttributes.add (returnAttribute);
+    }
+
+    public LinkedList<AvatarMethod> getMethods () {
+        return this.methods;
+    }
+
+    public void resetMethods () {
+        this.methods = new LinkedList<AvatarMethod> ();
+    }
+
+    public void addMethod (AvatarMethod method) {
+        this.methods.add (method);
+    }
+
+    @Override
+    public void internalDrawing (Graphics graph) {
+        Font font = graph.getFont ();
+        this.internalDrawingAux (graph);
+        graph.setFont (font);
+    }
+
+    /**
+     * Draws the Library Function object.
+     *
+     * @param graph
+     *      The {@link Graphics} object used to draw this component.
+     */
+    private void internalDrawingAux (Graphics graph) {
+        String ster;
+        if (!this.isCrypto)
+            ster = "<<" + stereotype + ">>";
+        else
+            ster = "<<" + stereotypeCrypto + ">>";
+
+        Font font = graph.getFont ();
+
+        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, this.maxFontSize));
+            font = font.deriveFont ((float) maxCurrentFontSize);
+
+            // Try to decrease font size until we get below the minimum
+            while (maxCurrentFontSize > (this.minFontSize - 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.paddingHorizontal))
+                    break;
+
+                // Decrease font size
+                maxCurrentFontSize --;
+                // Scale the font
+                font = font.deriveFont ((float) maxCurrentFontSize);
+            }
+
+            // Use this font
+            graph.setFont (font);
+            this.currentFontSize = maxCurrentFontSize;
+
+            // if font is two small don't display the text
+            this.displayText = this.currentFontSize >= this.minFontSize;
+        }
+
+        // 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_LIBRARYFUNCTION);
+        graph.fillRect (this.x+1, this.y+1, this.width-1, this.height-1);
+        graph.setColor (c);
+
+        // limits
+        this.limitName = -1;
+        this.limitParameters = -1;
+        this.limitSignals = -1;
+
+        // h retains the coordinate along X where an element was last drawn
+        int h = 0;
+
+        // Draw icon
+        this.iconIsDrawn = this.width > IconManager.iconSize + 2*this.paddingHorizontal && height > IconManager.iconSize + 2*paddingHorizontal;
+        if (this.iconIsDrawn)
+            graph.drawImage (IconManager.img5100, this.x + this.width - IconManager.iconSize - this.paddingHorizontal, this.y + paddingHorizontal, null);
+
+        if (!this.displayText)
+            return;
+
+        int paddingVertical = (int) (this.paddingVertical * this.tdp.getZoom ());
+
+        // Write stereotype if small enough
+        graph.setFont (font.deriveFont (Font.BOLD));
+        int w = graph.getFontMetrics ().stringWidth (ster);
+        h = graph.getFontMetrics ().getAscent () + graph.getFontMetrics ().getLeading () + paddingVertical;
+        if (w + 2*this.paddingHorizontal < this.width && h + graph.getFontMetrics ().getDescent () + paddingVertical < this.height)
+            graph.drawString (ster, this.x + (this.width - w)/2, this.y + h);
+
+        // Write value if small enough
+        graph.setFont (font);
+        w = graph.getFontMetrics ().stringWidth (this.value);
+        h += graph.getFontMetrics ().getHeight () + paddingVertical;
+        if (w + 2*this.paddingHorizontal < this.width && h + graph.getFontMetrics ().getDescent () + paddingVertical < this.height)
+            graph.drawString (this.value, this.x + (this.width - w)/2, this.y + h);
+
+        // Update lower bound of text
+        this.limitName = this.y + h;
+
+        h += paddingVertical;
+        if (h + paddingVertical >= this.height)
+            return;
+
+        // Draw separator
+        graph.drawLine (this.x, this.y+h, this.x+this.width, this.y+h);
+
+        if (! ((AvatarBDPanel) this.tdp).areAttributesVisible ())
+            return;
+
+        // Set font size
+        int attributeFontSize = Math.min (12, this.currentFontSize - 2);
+        graph.setFont (font.deriveFont ((float) attributeFontSize));
+        int step = graph.getFontMetrics ().getHeight ();
+
+        h += paddingVertical;
+
+        // Parameters
+        for (TAttribute attr: this.parameters) {
+            h += step;
+            if (h >= this.height - this.paddingHorizontal) {
+                this.limitParameters = this.y + this.height;
+                return;
+            }
+
+            // Get the string for this parameter
+            String attrString = attr.toAvatarString ();
+
+            // Try to draw it
+            w = graph.getFontMetrics ().stringWidth (attrString);
+            if (w + 2*this.paddingHorizontal < this.width)
+                graph.drawString (attrString, this.x + this.paddingHorizontal, 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*this.paddingHorizontal < this.width) {
+                        graph.drawString (abbrev, this.x + this.paddingHorizontal, this.y + h);
+                        break;
+                    }
+                }
+
+                if (stringLength < 0)
+                    // skip attribute
+                    h -= step;
+            }
+        }
+
+        // Remember the end of parameters
+        this.limitParameters = this.y + h;
+
+        // Signals
+        if (this.signals.size() > 0) {
+            h += paddingVertical;
+
+            if (h + paddingVertical >= this.height)
+                return;
+
+            graph.drawLine(this.x, this.y+h, this.x+this.width, this.y+h);
+            h += paddingVertical;
+
+            for (AvatarSignal signal: this.signals) {
+                h += step ;
+                if (h >= this.height - this.paddingHorizontal) {
+                    this.limitSignals = this.y + this.height;
+                    return;
+                }
+
+                String signalString = "~ " + signal.toString ();
+                w = graph.getFontMetrics ().stringWidth (signalString);
+                if (w + 2*this.paddingHorizontal < this.width)
+                    graph.drawString (signalString, this.x + this.paddingHorizontal, this.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*this.paddingHorizontal < this.width) {
+                            graph.drawString (abbrev, this.x + this.paddingHorizontal, this.y + h);
+                            break;
+                        }
+                    }
+
+                    if (stringLength < 0)
+                        // skip signal
+                        h -= step;
+                }
+            }
+
+            // Remember limit of signals
+            this.limitSignals = this.y + h;
+        }
+
+        // Return Attributes
+        if (this.returnAttributes.size() > 0) {
+            h += paddingVertical;
+
+            if (h + paddingVertical >= this.height)
+                return;
+
+            graph.drawLine(this.x, this.y+h, this.x+this.width, this.y+h);
+            h += paddingVertical;
+
+            for (TAttribute attr: this.returnAttributes) {
+                h += step;
+                if (h >= this.height - this.paddingHorizontal)
+                    return;
+
+                // Get the string for this return attribute
+                String attrString = attr.toAvatarString ();
+
+                w = graph.getFontMetrics ().stringWidth (attrString);
+                if (w + 2*this.paddingHorizontal < this.width)
+                    graph.drawString (attrString, this.x + this.paddingHorizontal, 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*this.paddingHorizontal < this.width) {
+                            graph.drawString (abbrev, this.x + this.paddingHorizontal, this.y + h);
+                            break;
+                        }
+                    }
+
+                    if (stringLength < 0)
+                        // skip signal
+                        h -= step;
+                }
+            }
+        }
+    }
+
+    @Override
+    public TGComponent isOnOnlyMe (int x1, int y1) {
+
+        if (GraphicLib.isInRectangle(x1, y1, this.x, this.y, this.width, this.height))
+            return this;
+
+        return null;
+    }
+
+    @Override
+    public boolean editOndoubleClick(JFrame frame, int _x, int _y) {
+        if (this.iconIsDrawn && GraphicLib.isInRectangle(
+                    _x,
+                    _y,
+                    this.x + this.width - IconManager.iconSize - this.paddingHorizontal,
+                    this.y + this.paddingHorizontal,
+                    IconManager.iconSize,
+                    IconManager.iconSize)) {
+            this.tdp.selectTab (this.getValue ());
+            return true;
+        }
+
+        // Click on the name
+        if (_y < limitName) {
+            String s = (String) JOptionPane.showInputDialog (frame, "Library Function Name",
+                    "setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101,
+                    null,
+                    this.getValue());
+
+            if (s == null || s.isEmpty () || s.equals(this.value))
+                return false;
+
+            if (!TAttribute.isAValidId(s, false, false)) {
+                JOptionPane.showMessageDialog(frame,
+                        "Could not change the name of the Library Function: the new name is not a valid name",
+                        "Error",
+                        JOptionPane.INFORMATION_MESSAGE);
+                return false;
+            }
+
+            if (!this.tdp.isAvatarBlockNameUnique (s)) {
+                JOptionPane.showMessageDialog(frame,
+                        "Could not change the name of the Library Function: the new name is already used by another element.",
+                        "Error",
+                        JOptionPane.INFORMATION_MESSAGE);
+                return false;
+            }
+
+            // Update the name of the tab corresponding to the state machine of the library function
+            if (!this.tdp.changeStateMachineTabName (this.value, s)) {
+                JOptionPane.showMessageDialog(frame,
+                        "Could not change the name of the Library Function: this name is already used by another tab.",
+                        "Error",
+                        JOptionPane.INFORMATION_MESSAGE);
+                return false;
+            }
+
+            this.name = s;
+            this.setValue (s);
+            this.recalculateSize ();
+
+            return true;
+        }
+
+        // Click on parameters
+
+        // Create a new dialog to change parameters, signals, return values, etc.
+        JDialogAvatarLibraryFunction dialog = new JDialogAvatarLibraryFunction (
+                this,
+                frame,
+                "Settings of library function " + value,
+                "Library Function");
+        this.setJDialogOptions (dialog);
+        dialog.setSize (650, 575);
+        GraphicLib.centerOnParent (dialog);
+
+        // Focus on the right input depending on the part that was clicked.
+        // FIXME: if nothing is displayed, focus will go on tab 2 instead of tab 0
+        if (_y < this.limitParameters)
+            dialog.selectTabIndex (0);
+        else if (_y < this.limitSignals)
+            dialog.selectTabIndex (1);
+        else
+            dialog.selectTabIndex (2);
+
+        // Set visible and block until dialog is closed
+        dialog.setVisible (true);
+
+        ((AvatarBDPanel) tdp).updateAllSignalsOnConnectors ();
+
+        // Tag so that it is rescaled
+        this.rescaled = true;
+
+        return true;
+    }
+
+    protected void setJDialogOptions (JDialogAvatarLibraryFunction jdab) {
+        /*
+        jdab.addAccess (TAttribute.getStringAccess (TAttribute.PRIVATE));
+        jdab.addType (TAttribute.getStringAvatarType (TAttribute.BOOLEAN), true);
+        jdab.addType (TAttribute.getStringAvatarType (TAttribute.INTEGER), true);
+        jdab.addType (TAttribute.getStringType (TAttribute.TIMER), false);
+
+        for (String s: this.tdp.getAllDataTypes ())
+            jdab.addType(s, false);
+
+
+        jdab.enableInitialValue(true);
+        jdab.enableRTLOTOSKeyword(false);
+        jdab.enableJavaKeyword(false);
+        */
+    }
+
+    @Override
+    public int getType() {
+        return TGComponentManager.AVATARBD_LIBRARYFUNCTION;
+    }
+
+    /**
+     * Translate this Library Function into a XML element.
+     *
+     * @return The string for the corresponding XML element.
+     */
+    protected String translateExtraParam () {
+        StringBuffer sb = new StringBuffer ("<extraparam>\n");
+        sb.append("<CryptoLibraryFunction value=\"" + isCrypto + "\" />\n");
+        for (TAttribute attr: this.parameters) {
+            sb.append("<Parameter access=\"");
+            sb.append(attr.getAccess());
+            sb.append("\" id=\"");
+            sb.append(attr.getId());
+            sb.append("\" value=\"");
+            sb.append(attr.getInitialValue());
+            sb.append("\" type=\"");
+            sb.append(attr.getType());
+            sb.append("\" typeOther=\"");
+            sb.append(attr.getTypeOther());
+            sb.append("\" />\n");
+        }
+
+        for(AvatarSignal signal: this.signals) {
+            sb.append("<Signal value=\"");
+            sb.append(signal.toString());
+            sb.append("\" />\n");
+        }
+
+        for (TAttribute attr: this.returnAttributes) {
+            sb.append("<ReturnAttribute access=\"");
+            sb.append(attr.getAccess());
+            sb.append("\" id=\"");
+            sb.append(attr.getId());
+            sb.append("\" value=\"");
+            sb.append(attr.getInitialValue());
+            sb.append("\" type=\"");
+            sb.append(attr.getType());
+            sb.append("\" typeOther=\"");
+            sb.append(attr.getTypeOther());
+            sb.append("\" />\n");
+        }
+
+        for(AvatarMethod method: this.methods) {
+            sb.append("<Method value=\"");
+            sb.append(method.toSaveString());
+            sb.append("\" />\n");
+        }
+
+        sb.append("</extraparam>\n");
+
+        return new String(sb);
+    }
+
+    /**
+     * Load a Library Function element from a XML description.
+     *
+     * TODO
+     * @param nl
+     *      The {@link NodeList} representing the XML extraparam node
+     * @param decX
+     *      Unused.
+     * @param decY
+     *      Unused.
+     * @param decID
+     *      Unused.
+     *
+     * @throws MalformedModelingExpresion When the provided XML is corrupted.
+     */
+    public void loadExtraParam (NodeList nl, int decX, int decY, int decId) throws MalformedModelingException {
+        try {
+            for(int i=0; i<nl.getLength(); i++) {
+                Node n1 = nl.item(i);
+
+                // Ignore if it's not an element
+                if (n1.getNodeType() != Node.ELEMENT_NODE)
+                    continue;
+
+                // Fetch the children nodes
+                NodeList nli = n1.getChildNodes();
+                for(int j=0; j<nli.getLength(); j++) {
+                    Node n2 = nli.item(j);
+
+                    // Ignore if it's not an element
+                    if (n2.getNodeType() != Node.ELEMENT_NODE)
+                        continue;
+                    Element elt = (Element) n2;
+
+                    switch (elt.getTagName ()) {
+                        case "CryptoLibraryFunction":
+                            if (elt.getAttribute("value").equals ("true"))
+                                this.isCrypto = true;
+                            break;
+
+                        case "Parameter":
+                            {
+                                Integer access = Integer.decode (elt.getAttribute ("access")).intValue ();
+                                Integer type = Integer.decode (elt.getAttribute ("type")).intValue ();
+                                String typeOther = elt.getAttribute ("typeOther");
+                                String id = elt.getAttribute("id");
+                                String valueAtt = elt.getAttribute("value");
+                                if (valueAtt.equals("null"))
+                                    valueAtt = "";
+
+                                if (TAttribute.isAValidId (id, false, false) && TAttribute.isAValidInitialValue (type, valueAtt)) {
+                                    if (type == TAttribute.NATURAL)
+                                        type = TAttribute.INTEGER;
+
+                                    TAttribute ta = new TAttribute(access, id, valueAtt, type, typeOther);
+                                    ta.isAvatar = true;
+                                    this.parameters.add (ta);
+                                }
+                            }
+
+                            break;
+
+                        case "Signal":
+                            String signal = elt.getAttribute("value");
+
+                            if (signal.equals ("null"))
+                                break;
+
+                            AvatarSignal as = AvatarSignal.isAValidSignal (signal);
+                            if (as != null)
+                                this.signals.add (as);
+                            else
+                                TraceManager.addDev("Invalid signal ignored:" + signal);
+
+                            break;
+
+                        case "ReturnAttribute":
+                            {
+                                Integer access = Integer.decode (elt.getAttribute ("access")).intValue ();
+                                Integer type = Integer.decode (elt.getAttribute ("type")).intValue ();
+                                String typeOther = elt.getAttribute ("typeOther");
+                                String id = elt.getAttribute("id");
+                                String valueAtt = elt.getAttribute("value");
+                                if (valueAtt.equals("null"))
+                                    valueAtt = "";
+
+                                if (TAttribute.isAValidId (id, false, false) && TAttribute.isAValidInitialValue (type, valueAtt)) {
+                                    if (type == TAttribute.NATURAL)
+                                        type = TAttribute.INTEGER;
+
+                                    TAttribute ta = new TAttribute(access, id, valueAtt, type, typeOther);
+                                    ta.isAvatar = true;
+                                    this.returnAttributes.add (ta);
+                                }
+                            }
+
+                            break;
+
+                        case "Method":
+                            String method = elt.getAttribute("value");
+
+                            if (method.equals ("null"))
+                                break;
+
+                            boolean implementation = false;
+                            if (method.startsWith("$")) {
+                                implementation = true;
+                                method = method.substring(1);
+                            }
+
+                            if (method.startsWith("aencrypt("))
+                                this.isCrypto = true;
+
+                            AvatarMethod am = AvatarMethod.isAValidMethod(method);
+                            if (am != null) {
+                                am.setImplementationProvided(implementation);
+                                this.methods.add (am);
+                            }
+
+                            break;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            throw new MalformedModelingException();
+        }
+    }
+
+    /*
+    public int getDefaultConnector() {
+        return TGComponentManager.AVATARBD_PORT_CONNECTOR;
+    }
+    */
+
+    /**
+     * Returns the panel corresponding to the state machine diagram that describes the behaviour of this function.
+     *
+     * @return The panel of the corresponding state machine diagram.
+     */
+    public AvatarSMDPanel getAvatarSMDPanel () {
+        return ((AvatarDesignPanel) (this.tdp.tp)).getAvatarSMDPanel (this.value);
+    }
+
+    /**
+     * Removes the cryptographic primitives from the list of methods.
+     */
+    public void removeCryptoElements() {
+        this.isCrypto = false;
+
+        for (String method: AvatarMethod.cryptoMethods)
+            this.removeMethodIfApplicable (method);
+    }
+
+    /**
+     * Adds the cryptographic primitives to the list of methods.
+     */
+    public void addCryptoElements() {
+        this.isCrypto = true;
+
+        for (String method: AvatarMethod.cryptoMethods)
+            this.addMethodIfApplicable (method);
+    }
+
+    /**
+     * Removes a method from the list of methods if it exists.
+     *
+     * @param methodString
+     *      The String corresponding to the method to remove.
+     */
+    private void removeMethodIfApplicable(String methodString) {
+        Iterator<AvatarMethod> iterator = this.methods.iterator ();
+        while (iterator.hasNext ()) {
+            AvatarMethod am = iterator.next ();
+            // TODO: replace by a more OO way...
+            if (am.toString ().equals (methodString)) {
+                iterator.remove ();
+                break;
+            }
+        }
+    }
+
+    /**
+     * Adds a method to the list of methods if it doesn't already exist.
+     *
+     * @param methodString
+     *      The String corresponding to the method to add.
+     */
+    private void addMethodIfApplicable (String methodString) {
+        for (AvatarMethod am: this.methods)
+            // TODO: replace by a more OO way...
+            if (am.toString ().equals (methodString))
+                    return;
+
+        AvatarMethod am = AvatarMethod.isAValidMethod (methodString);
+        if (am != null)
+            this.methods.add (am);
+    }
+
+    @Override
+    public String getOwnerName () {
+        return this.getFunctionName ();
+    }
+
+    @Override
+    public Vector<TAttribute> getAttributeList () {
+        Vector<TAttribute> list = new Vector<TAttribute> ();
+        list.addAll (this.parameters);
+        list.addAll (this.returnAttributes);
+        list.addAll (this.attributes);
+
+        return list;
+    }
+
+    @Override
+    public Vector<String> getAllTimerList () {
+        Vector<String> v = new Vector<String> ();
+
+        for (TAttribute a: this.parameters)
+            if (a.getType() == TAttribute.TIMER)
+                v.add(a.getId());
+        for (TAttribute a: this.returnAttributes)
+            if (a.getType() == TAttribute.TIMER)
+                v.add(a.getId());
+        for (TAttribute a: this.attributes)
+            if (a.getType() == TAttribute.TIMER)
+                v.add(a.getId());
+
+        return v;
+    }
+
+    @Override
+    public TAttribute getAttributeByName (String _name) {
+        for (TAttribute a: this.parameters)
+            if (a.getId().compareTo(_name) == 0)
+                return a;
+        for (TAttribute a: this.returnAttributes)
+            if (a.getId().compareTo(_name) == 0)
+                return a;
+        for (TAttribute a: this.attributes)
+            if (a.getId().compareTo(_name) == 0)
+                return a;
+        return null;
+    }
+
+    @Override
+    public Vector<AvatarSignal> getSignalList () {
+        return new Vector<AvatarSignal> (this.signals);
+    }
+
+    @Override
+    public Vector<AvatarSignal> getAllSignalList () {
+        return this.getSignalList ();
+    }
+
+    @Override
+    public AvatarSignal getSignalNameBySignalDef (String _id) {
+        int index0 = _id.indexOf('(');
+        if (index0 > -1)
+            _id = _id.substring(0, index0);
+
+        _id = _id.trim();
+        for (AvatarSignal as: this.signals)
+            if (as.getId().equals (_id))
+                return as;
+
+        return null;
+    }
+
+    @Override
+    public Vector<AvatarMethod> getMethodList () {
+        return new Vector<AvatarMethod> (this.methods);
+    }
+
+    @Override
+    public Vector<AvatarMethod> getAllMethodList () {
+        return this.getMethodList ();
+    }
+}
diff --git a/src/ui/avatarbd/AvatarBDPanel.java b/src/ui/avatarbd/AvatarBDPanel.java
index 1adda024be472c8d825547fb1642630b0300d8a7..5ac42b43b837dce91e377dd72652ba6236cf47cb 100644
--- a/src/ui/avatarbd/AvatarBDPanel.java
+++ b/src/ui/avatarbd/AvatarBDPanel.java
@@ -56,7 +56,7 @@ import java.util.*;
 import myutil.*;
 
 public class AvatarBDPanel extends TDiagramPanel {
-    private Vector validated, ignored;
+    private Vector<AvatarBDStateMachineOwner> validated, ignored;
     private String val = null, ign = null;
     private boolean optimized = true;
 
@@ -73,13 +73,14 @@ public class AvatarBDPanel extends TDiagramPanel {
           addMouseMotionListener(tdmm);*/
     }
 
-
     public boolean actionOnDoubleClick(TGComponent tgc) {
         //System.out.println("Action");
         if (tgc instanceof AvatarBDBlock) {
             AvatarBDBlock b = (AvatarBDBlock)tgc;
             //System.out.println("oldValue:" + b.oldValue);
-            return mgui.newAvatarBDBlockName(tp, b.oldValue, b.getValue());
+            return this.changeStateMachineTabName (b.oldValue, b.getValue());
+        } else if (tgc instanceof AvatarBDLibraryFunction) {
+            return true;
         } else if (tgc instanceof AvatarBDDataType) {
             return true;
         }
@@ -93,7 +94,12 @@ public class AvatarBDPanel extends TDiagramPanel {
         if (tgc instanceof AvatarBDBlock) {
             AvatarBDBlock abdb = (AvatarBDBlock)(tgc);
             //TraceManager.addDev(" *** add Avatar block *** name=" + abdb.getBlockName());
-            mgui.addAvatarBlock(tp, abdb.getBlockName());
+            ((AvatarDesignPanel) this.tp).addAvatarStateMachineDiagramPanel(abdb.getBlockName());
+            this.mgui.setPanelMode ();
+            return true;
+        } else if (tgc instanceof AvatarBDLibraryFunction) {
+            ((AvatarDesignPanel) this.tp).addAvatarStateMachineDiagramPanel(((AvatarBDLibraryFunction) tgc).getFunctionName ());
+            this.mgui.setPanelMode ();
             return true;
         }
         return false;
@@ -151,20 +157,11 @@ public class AvatarBDPanel extends TDiagramPanel {
     }
 
     public void setConnectorsToFront() {
-        TGComponent tgc;
-
-        //System.out.println("list size=" + componentList.size());
-
-        Iterator iterator = componentList.listIterator();
-
         ArrayList<TGComponent> list = new ArrayList<TGComponent>();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
-            if (!(tgc instanceof TGConnector)) {
+        for (TGComponent tgc: this.componentList)
+            if (!(tgc instanceof TGConnector))
                 list.add(tgc);
-            }
-        }
 
         //System.out.println("Putting to back ...");
         for(TGComponent tgc1: list) {
@@ -174,8 +171,6 @@ public class AvatarBDPanel extends TDiagramPanel {
         }
     }
 
-
-
     /*public boolean areAttributesVisible() {
       return attributesVisible;
       }
@@ -215,7 +210,7 @@ public class AvatarBDPanel extends TDiagramPanel {
         } else {
             s+= "<Validated value=\"";
             for(i=0; i<validated.size();i++) {
-                s += ((AvatarBDBlock)(validated.elementAt(i))).getBlockName() + ";";
+                s += ((AvatarBDStateMachineOwner)(validated.elementAt(i))).getOwnerName() + ";";
             }
             s += "\" />\n";
         }
@@ -225,7 +220,7 @@ public class AvatarBDPanel extends TDiagramPanel {
         } else {
             s+= "<Ignored value=\"";
             for(i=0; i<ignored.size();i++) {
-                s += ((AvatarBDBlock)(ignored.elementAt(i))).getBlockName() + ";";
+                s += ((AvatarBDStateMachineOwner)(ignored.elementAt(i))).getOwnerName() + ";";
             }
             s += "\" />\n";
         }
@@ -324,243 +319,186 @@ public class AvatarBDPanel extends TDiagramPanel {
         } catch (Exception e) {
             // Model was saved in an older version of TTool
             TraceManager.addDev("Exception when loading parameter of block diagram:" + e.getMessage());
-
         }
-
-
     }
 
-
     public void updateAllSignalsOnConnectors() {
-        TGComponent tgc;
-        AvatarBDPortConnector port;
-        Iterator iterator = componentList.listIterator();
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof AvatarBDPortConnector) {
-                port = (AvatarBDPortConnector)tgc;
+                AvatarBDPortConnector port = (AvatarBDPortConnector)tgc;
                 port.updateAllSignals();
             }
-        }
     }
 
-    public Vector getListOfAvailableSignals(AvatarBDBlock _block) {
-        int i;
-        TGComponent tgc;
-        LinkedList<String> ll;
-        AvatarBDPortConnector port;
-        Iterator iterator = componentList.listIterator();
-        ArrayList<String> list = new ArrayList<String>();
-        Vector v = new Vector();
-        Vector listOfBlock = _block.getSignalList();
+    public Vector<AvatarSignal> getListOfAvailableSignals(AvatarBDBlock _block) {
+        Vector<AvatarSignal> v = new Vector<AvatarSignal> ();
 
-        if (listOfBlock.size() == 0) {
+        Vector<AvatarSignal> listOfBlock = _block.getSignalList();
+        if (listOfBlock.size() == 0)
             return v;
-        }
 
         v.addAll(listOfBlock);
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof AvatarBDPortConnector) {
-                port = (AvatarBDPortConnector)tgc;
+                AvatarBDPortConnector port = (AvatarBDPortConnector) tgc;
                 if (port.getAvatarBDBlock1() == _block) {
-                    ll = port.getListOfSignalsOrigin();
+                    LinkedList<String> ll = port.getListOfSignalsOrigin();
                     removeSignals(v, ll);
                 }
                 if (port.getAvatarBDBlock2() == _block) {
-                    ll = port.getListOfSignalsDestination();
+                    LinkedList<String> ll = port.getListOfSignalsDestination();
                     removeSignals(v, ll);
                 }
             }
-        }
 
         return v;
     }
 
-    public Vector getListOfAvailableOutSignals(AvatarBDBlock _block) {
-        int i;
-        TGComponent tgc;
-        LinkedList<String> ll;
-        AvatarBDPortConnector port;
-        Iterator iterator = componentList.listIterator();
-        ArrayList<String> list = new ArrayList<String>();
-        Vector v = new Vector();
-        Vector listOfBlock = _block.getOutSignalList();
+    public Vector<AvatarSignal> getListOfAvailableOutSignals (AvatarBDBlock _block) {
+        Vector<AvatarSignal> v = new Vector<AvatarSignal> ();
 
-        if (listOfBlock.size() == 0) {
+        Vector<AvatarSignal> listOfBlock = _block.getOutSignalList();
+        if (listOfBlock.size() == 0)
             return v;
-        }
 
         v.addAll(listOfBlock);
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof AvatarBDPortConnector) {
-                port = (AvatarBDPortConnector)tgc;
+                AvatarBDPortConnector port = (AvatarBDPortConnector)tgc;
                 if (port.getAvatarBDBlock1() == _block) {
-                    ll = port.getListOfSignalsOrigin();
+                    LinkedList<String> ll = port.getListOfSignalsOrigin();
                     removeSignals(v, ll);
                 }
                 if (port.getAvatarBDBlock2() == _block) {
-                    ll = port.getListOfSignalsDestination();
+                    LinkedList<String> ll = port.getListOfSignalsDestination();
                     removeSignals(v, ll);
                 }
             }
-        }
 
         return v;
     }
 
-    public Vector getListOfAvailableInSignals(AvatarBDBlock _block) {
-        int i;
-        TGComponent tgc;
-        LinkedList<String> ll;
-        AvatarBDPortConnector port;
-        Iterator iterator = componentList.listIterator();
-        ArrayList<String> list = new ArrayList<String>();
-        Vector v = new Vector();
-        Vector listOfBlock = _block.getInSignalList();
+    public Vector<AvatarSignal> getListOfAvailableInSignals(AvatarBDBlock _block) {
+        Vector<AvatarSignal> v = new Vector<AvatarSignal> ();
 
-        if (listOfBlock.size() == 0) {
+        Vector<AvatarSignal> listOfBlock = _block.getInSignalList();
+        if (listOfBlock.size() == 0)
             return v;
-        }
 
         v.addAll(listOfBlock);
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof AvatarBDPortConnector) {
-                port = (AvatarBDPortConnector)tgc;
+                AvatarBDPortConnector port = (AvatarBDPortConnector)tgc;
                 if (port.getAvatarBDBlock1() == _block) {
-                    ll = port.getListOfSignalsOrigin();
+                    LinkedList<String> ll = port.getListOfSignalsOrigin();
                     removeSignals(v, ll);
                 }
                 if (port.getAvatarBDBlock2() == _block) {
-                    ll = port.getListOfSignalsDestination();
+                    LinkedList<String> ll = port.getListOfSignalsDestination();
                     removeSignals(v, ll);
                 }
             }
-        }
 
         return v;
     }
 
     // Remove AvatarSignals of v which name is provided in list
-    private void removeSignals(Vector v, LinkedList<String> list) {
-        int i;
-        AvatarSignal as;
+    private static void removeSignals(Vector<AvatarSignal> v, LinkedList<String> list) {
         for(String s: list) {
-            for(i=0; i<v.size(); i++) {
-                as = (AvatarSignal)(v.get(i));
-                if (as.toString().compareTo(s) == 0) {
-                    v.removeElementAt(i);
+            Iterator<AvatarSignal> iterator = v.iterator ();
+            while (iterator.hasNext ()) {
+                AvatarSignal as = iterator.next ();
+                if (as.toString().equals (s)) {
+                    iterator.remove ();
                     break;
                 }
             }
         }
     }
 
-    public LinkedList<AvatarBDBlock> getFullBlockList() {
-        TGComponent tgc;
-        AvatarBDBlock block;
-        LinkedList<AvatarBDBlock> list = new LinkedList<AvatarBDBlock>();
-        Iterator iterator = componentList.listIterator();
+    public LinkedList<AvatarBDStateMachineOwner> getFullStateMachineOwnerList() {
+        LinkedList<AvatarBDStateMachineOwner> list = new LinkedList<AvatarBDStateMachineOwner>();
+
+        for (TGComponent tgc: this.componentList)
+            if (tgc instanceof AvatarBDStateMachineOwner) {
+                list.add ((AvatarBDStateMachineOwner) tgc);
+                if (tgc instanceof AvatarBDBlock)
+                    list.addAll (((AvatarBDBlock) tgc).getFullBlockList());
+            }
+
+        return list;
+    }
+
+    public LinkedList<AvatarBDBlock> getFullBlockList () {
+        LinkedList<AvatarBDBlock> list = new LinkedList<AvatarBDBlock> ();
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof AvatarBDBlock) {
-                block = (AvatarBDBlock)tgc;
-                list.add(block);
-                list.addAll(block.getFullBlockList());
+                list.add ((AvatarBDBlock) tgc);
+                list.addAll (((AvatarBDBlock) tgc).getFullBlockList());
             }
-        }
+
         return list;
     }
 
     public TAttribute getAttributeByBlockName(String _blockName, String attributeName) {
         TAttribute a;
-        for(AvatarBDBlock block: getFullBlockList()) {
-            if (block.getBlockName().compareTo(_blockName) == 0) {
+        for(AvatarBDStateMachineOwner block: getFullStateMachineOwnerList())
+            if (block.getOwnerName().equals (_blockName))
                 return block.getAttributeByName(attributeName);
-            }
-        }
+
         return null;
     }
 
-    public Vector getAllAttributesOfBlock(String _name) {
-        LinkedList<AvatarBDBlock> list = getFullBlockList();
-        for(AvatarBDBlock block: list) {
-            if (block.getBlockName().compareTo(_name) ==0) {
-                return block.getAttributeList();
-            }
-        }
-        return null;
+    public Vector<TAttribute> getAllAttributesOfBlock (String _name) {
+        LinkedList<AvatarBDStateMachineOwner> list = getFullStateMachineOwnerList ();
+        for(AvatarBDStateMachineOwner block: list)
+            if (block.getOwnerName ().equals (_name))
+                return block.getAttributeList ();
+
+        return new Vector<TAttribute> ();
     }
 
-    public Vector getAllMethodsOfBlock(String _name) {
-        LinkedList<AvatarBDBlock> list = getFullBlockList();
-        for(AvatarBDBlock block: list) {
-            if (block.getBlockName().compareTo(_name) ==0) {
+    public Vector<AvatarMethod> getAllMethodsOfBlock(String _name) {
+        for(AvatarBDStateMachineOwner block: getFullStateMachineOwnerList())
+            if (block.getOwnerName().equals (_name))
                 return block.getAllMethodList();
-            }
-        }
+
         return null;
     }
 
-    public Vector getAllSignalsOfBlock(String _name) {
-        LinkedList<AvatarBDBlock> list = getFullBlockList();
-        for(AvatarBDBlock block: list) {
-            if (block.getBlockName().compareTo(_name) ==0) {
+    public Vector<AvatarSignal> getAllSignalsOfBlock(String _name) {
+        for(AvatarBDStateMachineOwner block: getFullStateMachineOwnerList())
+            if (block.getOwnerName().equals (_name))
                 return block.getAllSignalList();
-            }
-        }
+
         return null;
     }
 
-    public Vector getAllTimersOfBlock(String _name) {
-        LinkedList<AvatarBDBlock> list = getFullBlockList();
-        for(AvatarBDBlock block: list) {
-            if (block.getBlockName().compareTo(_name) ==0) {
+    public Vector<String> getAllTimersOfBlock(String _name) {
+        for(AvatarBDStateMachineOwner block: getFullStateMachineOwnerList())
+            if (block.getOwnerName().equals (_name))
                 return block.getAllTimerList();
-            }
-        }
+
         return null;
     }
 
     public Vector getAttributesOfDataType(String _name) {
-        TGComponent tgc;
-        Iterator iterator = componentList.listIterator();
-        AvatarBDDataType adt;
-
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof AvatarBDDataType) {
-                adt = (AvatarBDDataType)tgc;
-                if (adt.getDataTypeName().compareTo(_name) == 0) {
+                AvatarBDDataType adt = (AvatarBDDataType)tgc;
+                if (adt.getDataTypeName().compareTo(_name) == 0)
                     return adt.getAttributeList();
-                }
             }
-        }
 
         return null;
     }
 
     public TAttribute getAttribute(String _name, String _nameOfBlock) {
-
-        //TraceManager.addDev("Searching for attribute: " + _name  + " of block " + _nameOfBlock);
-
-        TAttribute ta;
-        Vector v = getAllAttributesOfBlock(_nameOfBlock);
-
-        for(int i=0; i<v.size(); i++) {
-            ta = (TAttribute)(v.get(i));
-            if (ta.getId().compareTo(_name) ==0) {
-                return ta;
-            }
-        }
-
-        return null;
+        return this.getAttributeByBlockName(_nameOfBlock, _name);
     }
 
     public void setMainCode(String s) {
@@ -574,14 +512,14 @@ public class AvatarBDPanel extends TDiagramPanel {
         return mainCode;
     }
 
-    public Vector getValidated() {
+    public Vector<AvatarBDStateMachineOwner> getValidated() {
         if ((val != null) && (validated == null)) {
             makeValidated();
         }
         return validated;
     }
 
-    public Vector getIgnored() {
+    public Vector<AvatarBDStateMachineOwner> getIgnored() {
         if ((ign != null) && (ignored == null)) {
             makeIgnored();
         }
@@ -593,11 +531,11 @@ public class AvatarBDPanel extends TDiagramPanel {
     }
 
 
-    public void setValidated(Vector _validated) {
+    public void setValidated(Vector<AvatarBDStateMachineOwner> _validated) {
         validated = _validated;
     }
 
-    public void setIgnored(Vector _ignored) {
+    public void setIgnored(Vector<AvatarBDStateMachineOwner> _ignored) {
         ignored = _ignored;
     }
 
@@ -607,16 +545,16 @@ public class AvatarBDPanel extends TDiagramPanel {
 
     public void makeValidated() {
         TraceManager.addDev("Making validated with val=" + val);
-        validated = new Vector();
-        LinkedList<AvatarBDBlock> list = getFullBlockList();
+        validated = new Vector<AvatarBDStateMachineOwner> ();
+        LinkedList<AvatarBDStateMachineOwner> list = getFullStateMachineOwnerList();
         String tmp;
 
         String split[] = val.split(";");
         for(int i=0; i<split.length; i++) {
             tmp = split[i].trim();
             if (tmp.length() > 0) {
-                for (AvatarBDBlock block: list) {
-                    if (block.getBlockName().compareTo(tmp) == 0) {
+                for (AvatarBDStateMachineOwner block: list) {
+                    if (block.getOwnerName().equals (tmp)) {
                         validated.add(block);
                         break;
                     }
@@ -628,17 +566,17 @@ public class AvatarBDPanel extends TDiagramPanel {
 
     public void makeIgnored() {
         TraceManager.addDev("Making ignored with ign=" + val);
-        ignored = new Vector();
-        LinkedList<AvatarBDBlock> list = getFullBlockList();
+        ignored = new Vector<AvatarBDStateMachineOwner> ();
+        LinkedList<AvatarBDStateMachineOwner> list = getFullStateMachineOwnerList();
         String tmp;
 
         String split[] = ign.split(";");
         for(int i=0; i<split.length; i++) {
             tmp = split[i].trim();
             if (tmp.length() > 0) {
-                for (AvatarBDBlock block: list) {
-                    if (block.getBlockName().compareTo(tmp) == 0) {
-                        validated.add(block);
+                for (AvatarBDStateMachineOwner block: list) {
+                    if (block.getOwnerName().equals (tmp)) {
+                        ignored.add(block);
                         break;
                     }
                 }
@@ -672,26 +610,18 @@ public class AvatarBDPanel extends TDiagramPanel {
 
     
     public ArrayList<String> getAllNonMappedAvatarChannelNames(String _topName, ADDDiagramPanel _tadp) {
-        Iterator iterator = componentList.listIterator();
         ArrayList<String> list = new ArrayList<String>();
-        String name;
-        TGComponent tgc;
 
-        while(iterator.hasNext()) {
-            tgc = (TGComponent)(iterator.next());
+        for (TGComponent tgc: this.componentList)
             if (tgc instanceof AvatarBDPortConnector) {
                 AvatarBDPortConnector port = (AvatarBDPortConnector)tgc;
 		if (port.getListOfSignalsOrigin().size() > 0) {
-		    name = port.getChannelName();
-		    if (!_tadp.isChannelMapped(_topName,  name)) {
+                    String name = port.getChannelName();
+		    if (!_tadp.isChannelMapped(_topName,  name))
 			list.add(_topName + "::" + name);
-		    }
 		}
             }
-        }
+
         return list;
     }
-
-
-
 }
diff --git a/src/ui/avatarbd/AvatarBDStateMachineOwner.java b/src/ui/avatarbd/AvatarBDStateMachineOwner.java
new file mode 100755
index 0000000000000000000000000000000000000000..0eeaf4839e559d5eb83412afc40a99e91ff68a96
--- /dev/null
+++ b/src/ui/avatarbd/AvatarBDStateMachineOwner.java
@@ -0,0 +1,67 @@
+/* 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 java.util.Vector;
+
+import ui.AvatarSignal;
+import ui.AvatarMethod;
+import ui.TAttribute;
+
+/**
+ * This interface represent block diagram elements that are associated to a state machine.
+ * It defines the functions so that a state machine can deal transparently no matter if
+ * its owner block is a LibraryFunction or a Block for instance.
+ *
+ * @version 1.0 04.14.2016
+ * @author Florian LUGOU
+ */
+public interface AvatarBDStateMachineOwner {
+
+    public Vector<TAttribute> getAttributeList ();
+    public Vector<String> getAllTimerList ();
+    public TAttribute getAttributeByName (String _name);
+    public Vector<AvatarSignal> getSignalList ();
+    public Vector<AvatarSignal> getAllSignalList ();
+    public AvatarSignal getSignalNameBySignalDef (String _id);
+    public Vector<AvatarMethod> getMethodList ();
+    public Vector<AvatarMethod> getAllMethodList ();
+
+    public String getOwnerName ();
+}
diff --git a/src/ui/avatarbd/AvatarBDToolBar.java b/src/ui/avatarbd/AvatarBDToolBar.java
index 3f9307ad1b4bc357ef1e4244ccdefe7207fd5830..7f072810e5dce9a067976bca262a0fd2c78a36ee 100644
--- a/src/ui/avatarbd/AvatarBDToolBar.java
+++ b/src/ui/avatarbd/AvatarBDToolBar.java
@@ -77,6 +77,8 @@ public class AvatarBDToolBar extends TToolBar {
 		mgui.actions[TGUIAction.ABD_DATATYPE].setEnabled(b);
 		mgui.actions[TGUIAction.ABD_COMPOSITION_CONNECTOR].setEnabled(b);
 		mgui.actions[TGUIAction.ABD_PORT_CONNECTOR].setEnabled(b);
+		mgui.actions[TGUIAction.ABD_LIBRARYFUNCTION].setEnabled(b);
+		mgui.actions[TGUIAction.ABD_CRYPTOLIBRARYFUNCTION].setEnabled(b);
 		
         //mgui.actions[TGUIAction.ATD_ATTACK].setEnabled(b);
 		
@@ -126,6 +128,16 @@ public class AvatarBDToolBar extends TToolBar {
         button.addMouseListener(mgui.mouseHandler);
 		
 		this.addSeparator();
+        
+        button = this.add(mgui.actions[TGUIAction.ABD_LIBRARYFUNCTION]);
+        button.addMouseListener(mgui.mouseHandler);
+		
+		this.addSeparator();
+		
+		button = this.add(mgui.actions[TGUIAction.ABD_CRYPTOLIBRARYFUNCTION]);
+        button.addMouseListener(mgui.mouseHandler);
+		
+		this.addSeparator();
 		
 		button = this.add(mgui.actions[TGUIAction.ABD_COMPOSITION_CONNECTOR]);
         button.addMouseListener(mgui.mouseHandler);
diff --git a/src/ui/avatarmad/AvatarMADAssumption.java b/src/ui/avatarmad/AvatarMADAssumption.java
index 8d470582711b6d598ae326b9044bd651b8fe7519..3993b0cef1e5fca07ab3271b98e448a0a3cead0b 100644
--- a/src/ui/avatarmad/AvatarMADAssumption.java
+++ b/src/ui/avatarmad/AvatarMADAssumption.java
@@ -418,8 +418,6 @@ public class AvatarMADAssumption extends TGCScalableWithInternalComponent implem
         return TGComponentManager.AVATARMAD_ASSUMPTION;
     }
 
-
-
     public String toString() {
         String ret =  getValue();
 
diff --git a/src/ui/avatarsmd/AvatarSMDSendSignal.java b/src/ui/avatarsmd/AvatarSMDSendSignal.java
index 0cf078873fe16ad73b278f68db4ebca43397853f..05bb457cf90e0ef0440f3250f54628d784c29591 100644
--- a/src/ui/avatarsmd/AvatarSMDSendSignal.java
+++ b/src/ui/avatarsmd/AvatarSMDSendSignal.java
@@ -219,7 +219,6 @@ public class AvatarSMDSendSignal extends AvatarSMDBasicComponent implements Chec
         return AvatarSignal.getValue(value, _index);
     }
 
-
     public boolean editOndoubleClick(JFrame frame) {
         Vector signals = tdp.getMGUI().getAllSignals();
         //TraceManager.addDev("Nb of signals:" + signals.size());
diff --git a/src/ui/cd/TCDTData.java b/src/ui/cd/TCDTData.java
index d8936df319e16fa3c8df03aadef49c8268bacd0b..ff6985baa98d400ca1bfa22b31e74c3a69a175e5 100755
--- a/src/ui/cd/TCDTData.java
+++ b/src/ui/cd/TCDTData.java
@@ -359,8 +359,8 @@ public class TCDTData extends TGCWithInternalComponent {
     public String toString() {    
        return getValue(); 
     }
-    
+
  	public int getDefaultConnector() {
         return TGComponentManager.CONNECTOR_ASSOCIATION;
       }
-}
\ No newline at end of file
+}
diff --git a/src/ui/cd/TCDTObject.java b/src/ui/cd/TCDTObject.java
index 5e904b76703a8a37f770b444da4e404db50a616e..ff6828e7efab7d4a3c7996d98cddeb556de78f11 100755
--- a/src/ui/cd/TCDTObject.java
+++ b/src/ui/cd/TCDTObject.java
@@ -710,4 +710,4 @@ public class TCDTObject extends TGCWithInternalComponent implements TClassInterf
         return TGComponentManager.CONNECTOR_ASSOCIATION;
       }
     
-}
\ No newline at end of file
+}
diff --git a/src/ui/images/avatarlibfunction.gif b/src/ui/images/avatarlibfunction.gif
new file mode 100644
index 0000000000000000000000000000000000000000..c3fba3d3d2ce0598ac1452e2f65836728d9ff1df
Binary files /dev/null and b/src/ui/images/avatarlibfunction.gif differ
diff --git a/src/ui/ncdd/NCEqNode.java b/src/ui/ncdd/NCEqNode.java
index 6cc6b792ab89b62d79b1ca9c4a14ac6d15b4fda0..cc3bf63399bc39aa292ca476c3b00e1142369c8c 100755
--- a/src/ui/ncdd/NCEqNode.java
+++ b/src/ui/ncdd/NCEqNode.java
@@ -257,11 +257,11 @@ public class NCEqNode extends TGCWithInternalComponent implements SwallowTGCompo
     }
     
     
-    public Vector getArtifactList() {
-        Vector v = new Vector();
+    public Vector<NCTrafficArtifact> getArtifactList() {
+        Vector<NCTrafficArtifact> v = new Vector<NCTrafficArtifact> ();
         for(int i=0; i<nbInternalTGComponent; i++) {
             if (tgcomponent[i] instanceof NCTrafficArtifact) {
-                v.add(tgcomponent[i]);
+                v.add((NCTrafficArtifact) tgcomponent[i]);
             }
         }
         return v;
diff --git a/src/ui/ncdd/NCSwitchNode.java b/src/ui/ncdd/NCSwitchNode.java
index 7cdf22f9310d069731f537b8751cf4f60fc24777..3dded2def9437dc4f473c96e4feb7e97b728d199 100755
--- a/src/ui/ncdd/NCSwitchNode.java
+++ b/src/ui/ncdd/NCSwitchNode.java
@@ -301,8 +301,8 @@ public class NCSwitchNode extends TGCWithInternalComponent implements SwallowTGC
         return list;
     }
 	
-	public Vector getArtifactList() {
-       Vector v = new Vector();
+	public Vector<NCRouteArtifact> getArtifactList() {
+       Vector<NCRouteArtifact> v = new Vector<NCRouteArtifact> ();
 	   NCRouteArtifact r;
 	   
         for(int i=0; i<nbInternalTGComponent; i++) {
diff --git a/src/ui/req/Requirement.java b/src/ui/req/Requirement.java
index 836c71d1c2918daccf148a95c1643e002b210917..55056519aa5370c85f13d155c4f50004aa05094b 100755
--- a/src/ui/req/Requirement.java
+++ b/src/ui/req/Requirement.java
@@ -425,7 +425,7 @@ public class Requirement extends TGCScalableWithInternalComponent implements Wit
     public String getRequirementName() {
         return value;
     }
-    
+
     public boolean isFormal() {
         return (reqType == 1);
     }
diff --git a/src/ui/tmlcd/TMLTaskOperator.java b/src/ui/tmlcd/TMLTaskOperator.java
index 9ed91696a0a78335e76c1582ba0f4a284dd7d7be..836244fa29525b94b802c3d63395b7718769e5f3 100755
--- a/src/ui/tmlcd/TMLTaskOperator.java
+++ b/src/ui/tmlcd/TMLTaskOperator.java
@@ -270,7 +270,7 @@ public class TMLTaskOperator extends TGCWithInternalComponent implements TMLTask
     public String getTaskName() {
         return value;
     }
-    
+
     public  int getType() {
         return TGComponentManager.TMLTD_TASK;
     }
diff --git a/src/ui/window/JDialogAvatarLibraryFunction.java b/src/ui/window/JDialogAvatarLibraryFunction.java
new file mode 100755
index 0000000000000000000000000000000000000000..67d8c548986279d041d6fdfcad17a39697fd8e3a
--- /dev/null
+++ b/src/ui/window/JDialogAvatarLibraryFunction.java
@@ -0,0 +1,1064 @@
+/* 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 java.util.LinkedList;
+import java.util.Collections;
+
+import javax.swing.JFrame;
+import javax.swing.JComboBox;
+import javax.swing.JTextField;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JButton;
+import javax.swing.JList;
+import javax.swing.ListSelectionModel;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JOptionPane;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+
+import java.awt.BorderLayout;
+import java.awt.GridBagLayout;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.Container;
+import java.awt.Font;
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import ui.TAttribute;
+import ui.IconManager;
+import ui.AvatarMethod;
+import ui.AvatarSignal;
+import ui.avatarbd.AvatarBDLibraryFunction;
+
+/**
+ * Dialog for managing parameters, return values, attributes, methods and signals of Avatar Library Functions
+ * @version 1.0 04.11.2016
+ * @author Florian Lugou
+ */
+public class JDialogAvatarLibraryFunction extends javax.swing.JDialog implements ActionListener, ListSelectionListener {
+    private AvatarBDLibraryFunction bdElement;
+
+    private boolean checkKeyword;
+    private boolean checkJavaKeyword;
+
+    // General
+    private JTabbedPane tabbedPane;
+    private JButton closeButton;
+    private JButton cancelButton;
+
+    private JButton removeButtons[];
+    private JButton modifyButtons[];
+    private JButton upButtons[];
+    private JButton downButtons[];
+    private JList<Object> listAttribute[];
+    private LinkedList<Object> attributes[];
+
+    // Parameters Tab
+    private JComboBox<String> parametersAccessBox;
+    private JTextField parametersIdentifierText;
+    private JTextField parametersInitialValue;
+    private JComboBox<String> parametersTypeBox;
+
+    // Signals Tab
+    private JComboBox<String> signalInOutBox;
+    private JTextField signalText;
+
+    // Return Attributes Tab
+    private JComboBox<String> returnAttributesAccessBox;
+    private JTextField returnAttributesIdentifierText;
+    private JTextField returnAttributesInitialValue;
+    private JComboBox<String> returnAttributesTypeBox;
+
+    // Attributes Tab
+    private JComboBox<String> attributesAccessBox;
+    private JTextField attributesIdentifierText;
+    private JTextField attributesInitialValue;
+    private JComboBox<String> attributesTypeBox;
+
+    // Methods Tab
+    private JTextField methodText;
+
+
+    public JDialogAvatarLibraryFunction (AvatarBDLibraryFunction bdElement, JFrame frame, String title, String attrib) {
+        super (frame, title, true);
+
+        this.bdElement = bdElement;
+        this.checkKeyword = true;
+        this.checkJavaKeyword = true;
+
+        this.removeButtons = new JButton [5];
+        this.modifyButtons = new JButton [5];
+        this.upButtons = new JButton [5];
+        this.downButtons = new JButton [5];
+        this.listAttribute = new JList [5];
+        this.attributes = new LinkedList [5];
+
+        this.attributes[0] = new LinkedList ();
+        for (TAttribute attr: this.bdElement.getParameters ())
+            this.attributes[0].add (attr.makeClone ());
+
+        this.attributes[1] = new LinkedList ();
+        for (AvatarSignal signal: this.bdElement.getSignals ())
+            this.attributes[1].add (signal.makeClone ());
+
+        this.attributes[2] = new LinkedList ();
+        for (TAttribute attr: this.bdElement.getReturnAttributes ())
+            this.attributes[2].add (attr.makeClone ());
+
+        this.attributes[3] = new LinkedList ();
+        for (TAttribute attr: this.bdElement.getAttributes ())
+            this.attributes[3].add (attr.makeClone ());
+
+        this.attributes[4] = new LinkedList ();
+        for (AvatarMethod meth: this.bdElement.getMethods ())
+            this.attributes[4].add (meth.makeClone ());
+
+        this.initComponents ();
+
+        this.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE));
+        this.addType(TAttribute.getStringAvatarType(TAttribute.BOOLEAN));
+        this.addType(TAttribute.getStringAvatarType(TAttribute.INTEGER));
+        this.addType(TAttribute.getStringType(TAttribute.TIMER));
+        for(String s: this.bdElement.getDiagramPanel ().getAllDataTypes())
+            this.addType(s);
+        /*
+        pack();
+        */
+    }
+
+    private void fillGenericAttributesTab (JPanel tab, int tabIndex, String tabTitle, JComboBox<String> accessBox, JTextField identifierText, JTextField initialValue, JComboBox<String> typeBox) {
+        // West Panel
+        JPanel panelWest = new JPanel ();
+        tab.add(panelWest, BorderLayout.WEST);
+        panelWest.setLayout (new GridBagLayout ());
+        panelWest.setBorder (new javax.swing.border.TitledBorder ("Adding " + tabTitle + "s"));
+        panelWest.setPreferredSize(new Dimension(300, 450));
+
+        //      first line of west panel (field titles)
+        GridBagConstraints gridConstraints = new GridBagConstraints();
+        gridConstraints.gridheight = 1;
+        gridConstraints.weighty = 1.0;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 3;
+
+        panelWest.add(new JLabel(" "), gridConstraints);
+
+        gridConstraints.gridwidth = 1;
+        gridConstraints.anchor = GridBagConstraints.CENTER;
+        panelWest.add(new JLabel("access"), gridConstraints);
+        panelWest.add(new JLabel("identifier"), gridConstraints);
+        panelWest.add(new JLabel(" "), gridConstraints);
+        panelWest.add(new JLabel("initial value"), gridConstraints);
+        panelWest.add(new JLabel(" "), gridConstraints);
+
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        panelWest.add(new JLabel("type"), gridConstraints);
+
+        //      second line west panel (input fields)
+        gridConstraints.gridwidth = 1;
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        gridConstraints.anchor = GridBagConstraints.CENTER;
+        panelWest.add(accessBox, gridConstraints);
+
+        identifierText.setColumns(15);
+        identifierText.setEditable(true);
+        panelWest.add(identifierText, gridConstraints);
+
+        panelWest.add(new JLabel(" = "), gridConstraints);
+
+        initialValue.setColumns(5);
+        initialValue.setEditable(true);
+        panelWest.add(initialValue, gridConstraints);
+
+        panelWest.add(new JLabel(" : "), gridConstraints);
+
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        typeBox.addActionListener(this);
+        panelWest.add(typeBox, gridConstraints);
+
+        //      third line west panel (empty line)
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 3;
+        panelWest.add(new JLabel(" "), gridConstraints);
+
+        //      fourth line west panel (Add and modify buttons)
+        gridConstraints.gridheight = 1;
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.gridwidth = 3;
+        this.modifyButtons[tabIndex] = new JButton ("Modify " + tabTitle);
+        this.modifyButtons[tabIndex].addActionListener(this);
+        this.modifyButtons[tabIndex].setEnabled (false);
+        panelWest.add(this.modifyButtons[tabIndex], gridConstraints);
+
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        JButton addButton = new JButton ("Add " + tabTitle);
+        addButton.addActionListener(this);
+        panelWest.add(addButton, gridConstraints);
+
+
+        // East Panel
+        JPanel panelEast = new JPanel ();
+        tab.add(panelEast, BorderLayout.EAST);
+        panelEast.setLayout (new GridBagLayout ());
+        panelEast.setBorder (new javax.swing.border.TitledBorder("Managing " + tabTitle + "s"));
+        panelEast.setPreferredSize (new Dimension (300, 450));
+
+        //      first line east panel
+        this.listAttribute[tabIndex] = new JList <Object> (this.attributes[tabIndex].toArray ());
+        this.listAttribute[tabIndex].setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        this.listAttribute[tabIndex].addListSelectionListener(this);
+        JScrollPane scrollPane = new JScrollPane(this.listAttribute[tabIndex]);
+        scrollPane.setSize(300, 250);
+        gridConstraints = new GridBagConstraints();
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 5;
+        gridConstraints.weighty = 10.0;
+        gridConstraints.weightx = 10.0;
+        panelEast.add(scrollPane, gridConstraints);
+
+        //      second line east panel
+        gridConstraints.weighty = 1.0;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 1;
+        panelEast.add(new JLabel(""), gridConstraints);
+
+        //      third line east panel
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        this.upButtons[tabIndex] = new JButton("Up");
+        this.upButtons[tabIndex].setEnabled(false);
+        this.upButtons[tabIndex].addActionListener(this);
+        panelEast.add(this.upButtons[tabIndex], gridConstraints);
+
+        this.downButtons[tabIndex] = new JButton("Down");
+        this.downButtons[tabIndex].setEnabled(false);
+        this.downButtons[tabIndex].addActionListener(this);
+        panelEast.add(this.downButtons[tabIndex], gridConstraints);
+
+        this.removeButtons[tabIndex] = new JButton("Remove " + tabTitle);
+        this.removeButtons[tabIndex].setEnabled(false);
+        this.removeButtons[tabIndex].addActionListener(this);
+        panelEast.add(this.removeButtons[tabIndex], gridConstraints);
+    }
+
+    private JPanel initParametersTab () {
+        JPanel panelParameters = new JPanel(new BorderLayout());
+        this.parametersAccessBox = new JComboBox<String> ();
+        this.parametersIdentifierText = new JTextField ();
+        this.parametersInitialValue = new JTextField ();
+        this.parametersTypeBox = new JComboBox<String> ();
+
+        this.fillGenericAttributesTab (
+                panelParameters,
+                0,
+                "Parameter",
+                this.parametersAccessBox,
+                this.parametersIdentifierText,
+                this.parametersInitialValue,
+                this.parametersTypeBox);
+
+        return panelParameters;
+    }
+
+    private JPanel initSignalsTab () {
+        JPanel panelSignals = new JPanel(new BorderLayout());
+
+        // West Panel
+        JPanel panelWest = new JPanel();
+        panelSignals.add (panelWest, BorderLayout.WEST);
+        panelWest.setLayout(new GridBagLayout ());
+        panelWest.setBorder(new javax.swing.border.TitledBorder("Adding Signals"));
+        panelWest.setPreferredSize(new Dimension(300, 250));
+
+        //      first line west panel
+        GridBagConstraints gridConstraints = new GridBagConstraints();
+        gridConstraints.weighty = 1.0;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 3;
+        panelWest.add(new JLabel(" "), gridConstraints);
+
+        gridConstraints.gridheight = 1;
+        gridConstraints.anchor = GridBagConstraints.CENTER;
+        panelWest.add(new JLabel("signal:"), gridConstraints);
+
+        //      second line west panel
+        gridConstraints.gridwidth = 1;
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        this.signalInOutBox = new JComboBox<String> (new String[] {"in", "out"});
+        panelWest.add (this.signalInOutBox, gridConstraints);
+
+        this.signalText = new JTextField();
+        this.signalText.setColumns(50);
+        this.signalText.setEditable(true);
+        panelWest.add(this.signalText, gridConstraints);
+
+        //      third line west panel
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 3;
+        panelWest.add(new JLabel(" "), gridConstraints);
+
+        //      fourth line west panel
+        gridConstraints.gridheight = 1;
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        gridConstraints.gridwidth = 1;
+        this.modifyButtons[1] = new JButton ("Modify Signal");
+        this.modifyButtons[1].addActionListener(this);
+        this.modifyButtons[1].setEnabled (false);
+        panelWest.add(this.modifyButtons[1], gridConstraints);
+
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        JButton addSignalButton = new JButton("Add Signal");
+        addSignalButton.addActionListener(this);
+        panelWest.add(addSignalButton, gridConstraints);
+
+        // East Panel
+        JPanel panelEast = new JPanel();
+        panelSignals.add(panelEast, BorderLayout.EAST);
+        panelEast.setLayout(new GridBagLayout ());
+        panelEast.setBorder(new javax.swing.border.TitledBorder("Managing Signals"));
+        panelEast.setPreferredSize(new Dimension(300, 250));
+
+        //      first line east panel
+        this.listAttribute[1] = new JList<Object> (this.attributes[1].toArray ());
+        this.listAttribute[1].setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        this.listAttribute[1].addListSelectionListener(this);
+        JScrollPane scrollPane = new JScrollPane(listAttribute[1]);
+        scrollPane.setSize(300, 250);
+        gridConstraints = new GridBagConstraints();
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 5;
+        gridConstraints.weighty = 10.0;
+        gridConstraints.weightx = 10.0;
+        panelEast.add(scrollPane, gridConstraints);
+
+        //      second line east panel
+        gridConstraints.weighty = 1.0;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.gridheight = 1;
+        panelEast.add(new JLabel(""), gridConstraints);
+
+        //      third line east panel
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        this.upButtons[1] = new JButton("Up");
+        this.upButtons[1].setEnabled (false);
+        this.upButtons[1].addActionListener(this);
+        panelEast.add(this.upButtons[1], gridConstraints);
+
+        this.downButtons[1] = new JButton("Down");
+        this.downButtons[1].setEnabled (false);
+        this.downButtons[1].addActionListener(this);
+        panelEast.add(this.downButtons[1], gridConstraints);
+
+        this.removeButtons[1] = new JButton("Remove Signal");
+        this.removeButtons[1].setEnabled (false);
+        this.removeButtons[1].addActionListener(this);
+        panelEast.add(this.removeButtons[1], gridConstraints);
+
+        return panelSignals;
+    }
+
+    private JPanel initReturnAttributesTab () {
+        JPanel panelReturnAttributes = new JPanel(new BorderLayout());
+        this.returnAttributesAccessBox = new JComboBox<String> ();
+        this.returnAttributesIdentifierText = new JTextField ();
+        this.returnAttributesInitialValue = new JTextField ();
+        this.returnAttributesTypeBox = new JComboBox<String> ();
+
+        this.fillGenericAttributesTab (
+                panelReturnAttributes,
+                2,
+                "Return Value",
+                this.returnAttributesAccessBox,
+                this.returnAttributesIdentifierText,
+                this.returnAttributesInitialValue,
+                this.returnAttributesTypeBox);
+
+        return panelReturnAttributes;
+    }
+
+    private JPanel initAttributesTab () {
+        JPanel panelAttributes = new JPanel(new BorderLayout());
+        this.attributesAccessBox = new JComboBox<String> ();
+        this.attributesIdentifierText = new JTextField ();
+        this.attributesInitialValue = new JTextField ();
+        this.attributesTypeBox = new JComboBox<String> ();
+
+        this.fillGenericAttributesTab (
+                panelAttributes,
+                3,
+                "Local Attribute",
+                this.attributesAccessBox,
+                this.attributesIdentifierText,
+                this.attributesInitialValue,
+                this.attributesTypeBox);
+
+        return panelAttributes;
+    }
+
+    private JPanel initMethodsTab () {
+        JPanel panelMethods = new JPanel(new BorderLayout());
+
+        // Panel West
+        JPanel panelWest = new JPanel();
+        panelMethods.add(panelWest, BorderLayout.WEST);
+        panelWest.setLayout(new GridBagLayout ());
+        panelWest.setBorder(new javax.swing.border.TitledBorder("Adding Methods"));
+        panelWest.setPreferredSize(new Dimension(300, 250));
+
+        //      first line west panel
+        GridBagConstraints gridConstraints = new GridBagConstraints();
+        gridConstraints.weighty = 1.0;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 3;
+        panelWest.add(new JLabel(" "), gridConstraints);
+
+        gridConstraints.gridheight = 1;
+        gridConstraints.anchor = GridBagConstraints.CENTER;
+        panelWest.add(new JLabel("method:"), gridConstraints);
+
+        //      second line west panel
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        this.methodText = new JTextField();
+        this.methodText.setColumns(50);
+        this.methodText.setEditable(true);
+        panelWest.add(this.methodText, gridConstraints);
+
+        //      third line west panel
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 3;
+        panelWest.add(new JLabel(" "), gridConstraints);
+
+        //      fourth line west panel
+        gridConstraints.gridheight = 1;
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        gridConstraints.gridwidth = 1;
+        this.modifyButtons[4] = new JButton ("Modify Method");
+        this.modifyButtons[4].addActionListener(this);
+        this.modifyButtons[4].setEnabled (false);
+        panelWest.add(this.modifyButtons[4], gridConstraints);
+
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        JButton addMethodButton = new JButton("Add Method");
+        addMethodButton.addActionListener(this);
+        panelWest.add(addMethodButton, gridConstraints);
+
+
+        // Panel East
+        JPanel panelEast = new JPanel();
+        panelMethods.add(panelEast, BorderLayout.EAST);
+        panelEast.setLayout(new GridBagLayout ());
+        panelEast.setBorder(new javax.swing.border.TitledBorder("Managing Methods"));
+        panelEast.setPreferredSize(new Dimension(300, 250));
+
+        //      first line east panel
+        this.listAttribute[4] = new JList<Object> (this.attributes[4].toArray ());
+        this.listAttribute[4].setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        this.listAttribute[4].addListSelectionListener(this);
+        JScrollPane scrollPane = new JScrollPane(listAttribute[4]);
+        scrollPane.setSize(300, 250);
+        gridConstraints = new GridBagConstraints();
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 5;
+        gridConstraints.weighty = 10.0;
+        gridConstraints.weightx = 10.0;
+        panelEast.add(scrollPane, gridConstraints);
+
+        //      second line east panel
+        gridConstraints.weighty = 1.0;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.fill = GridBagConstraints.BOTH;
+        gridConstraints.gridheight = 1;
+        panelEast.add(new JLabel(""), gridConstraints);
+
+        //      third line east panel
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        this.upButtons[4] = new JButton("Up");
+        this.upButtons[4].setEnabled (false);
+        this.upButtons[4].addActionListener(this);
+        panelEast.add(this.upButtons[4], gridConstraints);
+
+        this.downButtons[4] = new JButton("Down");
+        this.downButtons[4].setEnabled (false);
+        this.downButtons[4].addActionListener(this);
+        panelEast.add(this.downButtons[4], gridConstraints);
+
+        this.removeButtons[4] = new JButton("Remove Method");
+        this.removeButtons[4].setEnabled (false);
+        this.removeButtons[4].addActionListener(this);
+        panelEast.add(this.removeButtons[4], gridConstraints);
+
+        return panelMethods;
+    }
+
+    private void initComponents() {
+        // Get container
+        Container c = this.getContentPane ();
+        c.setLayout (new GridBagLayout ());
+
+        this.setFont (new Font("Helvetica", Font.PLAIN, 14));
+        this.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
+
+        // Add the tabs panel
+        this.tabbedPane = new JTabbedPane();
+
+        tabbedPane.addTab ("Parameters", this.initParametersTab ());            // Parameters Tab
+        tabbedPane.addTab ("Signals", this.initSignalsTab ());                  // Signals Tab
+        tabbedPane.addTab ("Return Values", this.initReturnAttributesTab ());   // Return Attributes Tab
+        tabbedPane.addTab ("Attributes", this.initAttributesTab ());            // Attributes Tab
+        tabbedPane.addTab ("Methods", this.initMethodsTab ());                  // Methods Tab
+
+        GridBagConstraints gridConstraints = new GridBagConstraints();
+        gridConstraints.gridwidth = 1;
+        gridConstraints.gridheight = 10;
+        gridConstraints.weighty = 1.0;
+        gridConstraints.weightx = 1.0;
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        c.add(tabbedPane, gridConstraints);
+
+        // Add Save & Close button
+        gridConstraints.gridwidth = 1;
+        gridConstraints.gridheight = 1;
+        gridConstraints.fill = GridBagConstraints.HORIZONTAL;
+        this.closeButton = new JButton("Save and Close", IconManager.imgic25);
+        this.closeButton.addActionListener(this);
+        c.add(this.closeButton, gridConstraints);
+
+        // Add Cancel button
+        gridConstraints.gridwidth = GridBagConstraints.REMAINDER; //end row
+        this.cancelButton = new JButton("Cancel", IconManager.imgic27);
+        this.cancelButton.addActionListener(this);
+        c.add(this.cancelButton, gridConstraints);
+    }
+
+    public void selectTabIndex (int tab) {
+        this.tabbedPane.setSelectedIndex(tab);
+    }
+
+    private void highlightField (final JTextField textField) {
+        /*
+        (new Thread () {
+            public void run () {
+                Color color = textField.getBackground ();
+                try {
+                    for (int i=0; i<5; i++) {
+                        textField.setBackground (Color.RED);
+                        Thread.sleep (50);
+
+                        textField.setBackground (color);
+                        Thread.sleep (100);
+                    }
+                } catch (InterruptedException e) {
+                    textField.setBackground (color);
+                }
+            }
+        }).start ();
+        */
+    }
+
+    public void actionPerformed (ActionEvent evt) {
+        Object source = evt.getSource ();
+        if (source == this.closeButton) {
+            this.save ();
+            this.dispose ();
+        } else if (source == this.cancelButton)
+            this.dispose ();
+        else if (source instanceof JButton) {
+            String label = ((JButton) source).getText ().split (" ", 2)[0];
+            switch (label) {
+                case "Add":
+                    this.handleAdd ();
+                    break;
+                case "Modify":
+                    this.handleModify ();
+                    break;
+                case "Up":
+                    this.handleUp ();
+                    break;
+                case "Down":
+                    this.handleDown ();
+                    break;
+                case "Remove":
+                    this.handleRemove ();
+                    break;
+                default:
+                    // Should not arrive here
+            }
+        }
+        /*
+        if (evt.getSource() == typeBox) {
+            boolean b = ((Boolean)(initValues.elementAt(typeBox.getSelectedIndex()))).booleanValue();
+            initialValue.setEnabled(b);
+            return;
+        }
+        */
+    }
+    
+    private void save () {
+        this.bdElement.resetParameters ();
+        for (Object o: this.attributes[0])
+            this.bdElement.addParameter ((TAttribute) o);
+        this.bdElement.resetSignals ();
+        for (Object o: this.attributes[1])
+            this.bdElement.addSignal ((AvatarSignal) o);
+        this.bdElement.resetReturnAttributes ();
+        for (Object o: this.attributes[2])
+            this.bdElement.addReturnAttribute ((TAttribute) o);
+        this.bdElement.resetAttributes ();
+        for (Object o: this.attributes[3])
+            this.bdElement.addAttribute ((TAttribute) o);
+        this.bdElement.resetMethods ();
+        for (Object o: this.attributes[4])
+            this.bdElement.addMethod ((AvatarMethod) o);
+    }
+
+    private void handleAdd () {
+        int selectedTab = this.tabbedPane.getSelectedIndex ();
+        switch (selectedTab) {
+            case 0:
+                this.addAttribute (0, this.parametersAccessBox, this.parametersIdentifierText, this.parametersInitialValue, this.parametersTypeBox, false);
+                break;
+            case 1:
+                this.addSignal (false);
+                break;
+            case 2:
+                this.addAttribute (2, this.returnAttributesAccessBox, this.returnAttributesIdentifierText, this.returnAttributesInitialValue, this.returnAttributesTypeBox, false);
+                break;
+            case 3:
+                this.addAttribute (3, this.attributesAccessBox, this.attributesIdentifierText, this.attributesInitialValue, this.attributesTypeBox, false);
+                break;
+            case 4:
+                this.addMethod (false);
+                break;
+            default:
+                // Should not arrive here
+        }
+    }
+
+    private void addAttribute (int tabIndex, JComboBox<String> accessBox, JTextField identifierText, JTextField initialValue, JComboBox<String> typeBox, boolean modify) {
+        String identifier = identifierText.getText ();
+        if (identifier.isEmpty ()) {
+            // Identifier is empty
+            this.highlightField (identifierText);
+            identifierText.requestFocus ();
+            return;
+        }
+
+        if (!TAttribute.isAValidId (identifier, this.checkKeyword, this.checkJavaKeyword)) {
+            // Identifier should not be used
+            JOptionPane.showMessageDialog (this,
+                                          "Bad identifier '" + identifier + "': invalid identifier",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            identifierText.requestFocus ();
+            return;
+        }
+
+        int accessIndex = TAttribute.getAccess ((String) accessBox.getSelectedItem ());
+        if (accessIndex < 0) {
+            // Unknown access modifier
+            JOptionPane.showMessageDialog (this,
+                                          "Bad access modifier",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            accessBox.requestFocus ();
+            return;
+        }
+
+        int typeIndex = TAttribute.getAvatarType ((String) typeBox.getSelectedItem ());
+        if (typeIndex < 0) {
+            // Unknown type
+            JOptionPane.showMessageDialog (this,
+                                          "Bad type",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            typeBox.requestFocus ();
+            return;
+        }
+
+        String value = initialValue.getText().trim ();
+        if (typeIndex == TAttribute.ARRAY_NAT && value.isEmpty ())
+            value = "2";
+        if (!initialValue.isEnabled ())
+            value = "";
+
+        if (!TAttribute.isAValidInitialValue(typeIndex, value)) {
+            // Bad initial value
+            JOptionPane.showMessageDialog (this,
+                                          "The initial value is not valid",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            initialValue.requestFocus ();
+            return;
+        }
+
+        TAttribute a;
+        if (typeIndex == TAttribute.OTHER)
+            a = new TAttribute(accessIndex, identifier, value, (String) typeBox.getSelectedItem ());
+        else
+            a = new TAttribute(accessIndex, identifier, value, typeIndex);
+        a.isAvatar = true;
+
+        //checks whether an attribute with this identifier already belongs to the list
+        if (this.attributes[0].contains (a) || this.attributes[2].contains (a) || this.attributes[3].contains (a)) {
+            JOptionPane.showMessageDialog (this,
+                                          "Bad Identifier: another attribute or parameter already has the same name.",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            identifierText.requestFocus ();
+            return;
+        }
+
+        if (modify) {
+            int index = this.listAttribute[tabIndex].getSelectedIndex ();
+            this.attributes[tabIndex].remove (index);
+            this.attributes[tabIndex].add (index, a);
+            this.listAttribute[tabIndex].setListData (this.attributes[tabIndex].toArray ());
+            this.listAttribute[tabIndex].setSelectedIndex(index);
+        } else {
+            this.attributes[tabIndex].add (a);
+            this.listAttribute[tabIndex].setListData (this.attributes[tabIndex].toArray ());
+            this.listAttribute[tabIndex].setSelectedIndex(this.attributes[tabIndex].size () - 1);
+        }
+
+        this.listAttribute[tabIndex].requestFocus ();
+
+        /*
+        if (attributes.contains(a)) {
+            index = attributes.indexOf(a);
+            a = (TAttribute)(attributes.elementAt(index));
+            a.setAccess(i);
+            if (j == TAttribute.OTHER) {
+                a.setTypeOther(o2.toString());
+            }
+            a.setType(j);
+            a.setInitialValue(value);
+            //attributes.removeElementAt(index);
+        }
+        */
+    }
+
+    private void addMethod (boolean modify) {
+        String s = this.methodText.getText().trim ();
+        if (s.isEmpty ()) {
+            this.methodText.requestFocus ();
+            return;
+        }
+
+        AvatarMethod am = AvatarMethod.isAValidMethod(s);
+
+        if (am == null) {
+            JOptionPane.showMessageDialog (this,
+                                          "Badly formatted method declaration",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            this.methodText.requestFocus ();
+            return;
+        }
+
+        am.setImplementationProvided(false);
+        
+        AvatarMethod amtmp;
+
+        // Checks whether the same method already belongs to the list
+        if (this.attributes[4].contains (am)) {
+            JOptionPane.showMessageDialog (this,
+                                          "This method already exists",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            this.methodText.requestFocus ();
+            return;
+        }
+
+        if (modify) {
+            int index = this.listAttribute[4].getSelectedIndex ();
+            this.attributes[4].remove (index);
+            this.attributes[4].add (index, am);
+            this.listAttribute[4].setListData (this.attributes[4].toArray ());
+            this.listAttribute[4].setSelectedIndex(index);
+        } else {
+            this.attributes[4].add (am);
+            this.listAttribute[4].setListData (this.attributes[4].toArray ());
+            this.listAttribute[4].setSelectedIndex(this.attributes[4].size () - 1);
+        }
+        this.listAttribute[4].requestFocus ();
+
+            /*
+        {
+        }
+        */
+    }
+
+    private void addSignal (boolean modify) {
+        String s = this.signalText.getText().trim ();
+        if (s.isEmpty ()) {
+            this.signalText.requestFocus ();
+            return;
+        }
+
+        AvatarSignal as = AvatarSignal.isAValidSignal (this.signalInOutBox.getSelectedIndex(), s);
+
+        if (as == null) {
+            JOptionPane.showMessageDialog (this,
+                                          "Badly formatted signal declaration",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            this.signalText.requestFocus ();
+            return;
+        }
+
+        // Checks whether the same signal already belongs to the list
+        if (this.attributes[1].contains (as)) {
+            JOptionPane.showMessageDialog (this,
+                                          "This signal already exists",
+                                          "Error",
+                                          JOptionPane.ERROR_MESSAGE);
+            this.signalText.requestFocus ();
+            return;
+        }
+
+        if (modify) {
+            int index = this.listAttribute[1].getSelectedIndex ();
+            this.attributes[1].remove (index);
+            this.attributes[1].add (index, as);
+            this.listAttribute[1].setListData (this.attributes[1].toArray ());
+            this.listAttribute[1].setSelectedIndex(index);
+        } else {
+            this.attributes[1].add(as);
+            this.listAttribute[1].setListData(this.attributes[1].toArray ());
+            this.listAttribute[1].setSelectedIndex(this.attributes[1].size () - 1);
+        }
+
+        this.listAttribute[1].requestFocus ();
+
+                /*
+            {
+                signals.removeElementAt(index);
+                signals.add(index, as);
+            }
+            */
+    }
+
+    private void handleModify () {
+        int selectedTab = this.tabbedPane.getSelectedIndex ();
+        switch (selectedTab) {
+            case 0:
+                this.addAttribute (0, this.parametersAccessBox, this.parametersIdentifierText, this.parametersInitialValue, this.parametersTypeBox, true);
+                break;
+            case 1:
+                this.addSignal (true);
+                break;
+            case 2:
+                this.addAttribute (2, this.returnAttributesAccessBox, this.returnAttributesIdentifierText, this.returnAttributesInitialValue, this.returnAttributesTypeBox, true);
+                break;
+            case 3:
+                this.addAttribute (3, this.attributesAccessBox, this.attributesIdentifierText, this.attributesInitialValue, this.attributesTypeBox, true);
+                break;
+            case 4:
+                this.addMethod (true);
+                break;
+            default:
+                // Should not arrive here
+        }
+    }
+
+    private void handleUp () {
+        int selectedTab = this.tabbedPane.getSelectedIndex ();
+        int i = this.listAttribute[selectedTab].getSelectedIndex();
+        if (i != -1 && i != 0) {
+            Collections.swap (this.attributes[selectedTab], i, i-1);
+            this.listAttribute[selectedTab].setListData(this.attributes[selectedTab].toArray ());
+            this.listAttribute[selectedTab].setSelectedIndex(i-1);
+        }
+    }
+
+    private void handleDown () {
+        int selectedTab = this.tabbedPane.getSelectedIndex ();
+        int i = this.listAttribute[selectedTab].getSelectedIndex();
+        if (i != -1 && i != this.attributes[selectedTab].size() - 1) {
+            Collections.swap (this.attributes[selectedTab], i, i+1);
+            this.listAttribute[selectedTab].setListData(this.attributes[selectedTab].toArray ());
+            this.listAttribute[selectedTab].setSelectedIndex(i+1);
+        }
+    }
+
+    private void handleRemove () {
+        int selectedTab = this.tabbedPane.getSelectedIndex ();
+        switch (selectedTab) {
+            case 0:
+                this.removeAttribute (0);
+                break;
+            case 1:
+                this.removeSignal ();
+                break;
+            case 2:
+                this.removeAttribute (2);
+                break;
+            case 3:
+                this.removeAttribute (3);
+                break;
+            case 4:
+                this.removeMethod ();
+                break;
+            default:
+                // Should not arrive here
+        }
+    }
+
+    private void removeAttribute (int tabIndex) {
+        int i = this.listAttribute[tabIndex].getSelectedIndex ();
+        if (i != -1) {
+            ((TAttribute) this.attributes[tabIndex].get (i)).setAccess (-1);
+            this.attributes[tabIndex].remove (i);
+            this.listAttribute[tabIndex].setListData (this.attributes[tabIndex].toArray ());
+        }
+    }
+
+    private void removeSignal () {
+        int i = this.listAttribute[1].getSelectedIndex ();
+        if (i != -1) {
+            this.attributes[1].remove (i);
+            this.listAttribute[1].setListData(this.attributes[1].toArray ());
+        }
+    }
+
+    private void removeMethod () {
+        int i = this.listAttribute[4].getSelectedIndex();
+        if (i!= -1) {
+            this.attributes[4].remove (i);
+            this.listAttribute[4].setListData (this.attributes[4].toArray ());
+        }
+    }
+
+    public void valueChanged (ListSelectionEvent e) {
+        int selectedTab = this.tabbedPane.getSelectedIndex ();
+        int i = this.listAttribute[selectedTab].getSelectedIndex() ;
+
+        this.removeButtons[selectedTab].setEnabled(i != -1);
+        this.modifyButtons[selectedTab].setEnabled(i != -1);
+        this.upButtons[selectedTab].setEnabled(i > 0);
+        this.downButtons[selectedTab].setEnabled(i != -1 && i < this.attributes[selectedTab].size ()-1);
+
+        if (selectedTab == 1) { // Signals
+            if (i == -1)
+                this.signalText.setText ("");
+            else {
+                AvatarSignal as = (AvatarSignal) (this.attributes[1].get (i));
+                this.signalText.setText (as.toBasicString());
+                this.signalInOutBox.setSelectedIndex (as.getInOut());
+            }
+        } else if (selectedTab == 4) { // Methods
+            if (i == -1)
+                this.methodText.setText ("");
+            else {
+                AvatarMethod am = (AvatarMethod) (this.attributes[4].get (i));
+                this.methodText.setText (am.toString());
+            }
+        } else { // Attributes
+            TAttribute a = (TAttribute) (this.attributes[selectedTab].get (i));
+            JTextField textField, initialValue;
+            JComboBox<String> accessBox, typeBox;
+
+            if (selectedTab == 0) {
+                textField = this.parametersIdentifierText;
+                initialValue = this.parametersInitialValue;
+                accessBox = this.parametersAccessBox;
+                typeBox = this.parametersTypeBox;
+            } else if (selectedTab == 2) {
+                textField = this.returnAttributesIdentifierText;
+                initialValue = this.returnAttributesInitialValue;
+                accessBox = this.returnAttributesAccessBox;
+                typeBox = this.returnAttributesTypeBox;
+            } else {
+                textField = this.attributesIdentifierText;
+                initialValue = this.attributesInitialValue;
+                accessBox = this.attributesAccessBox;
+                typeBox = this.attributesTypeBox;
+            }
+
+            textField.setText (a.getId ());
+            initialValue.setText(a.getInitialValue());
+            this.select (accessBox, a.getStringAccess(a.getAccess()));
+            if (a.getType() == TAttribute.OTHER)
+                this.select (typeBox, a.getTypeOther());
+            else
+                this.select(typeBox, a.getStringAvatarType(a.getType()));
+        }
+    }
+
+    public void addAccess(String s) {
+        this.parametersAccessBox.addItem (s);
+        this.attributesAccessBox.addItem (s);
+        this.returnAttributesAccessBox.addItem (s);
+    }
+
+    public void addType(String s) {
+        this.parametersTypeBox.addItem (s);
+        this.attributesTypeBox.addItem (s);
+        this.returnAttributesTypeBox.addItem (s);
+    }
+
+    public void select (JComboBox<String> jcb, String text) {
+        for (int i=0; i < jcb.getItemCount(); i++) {
+            String s = jcb.getItemAt(i);
+            if (s.equals (text)) {
+                jcb.setSelectedIndex(i);
+                return;
+            }
+        }
+    }
+}
diff --git a/src/ui/window/JDialogSelectAvatarBlock.java b/src/ui/window/JDialogSelectAvatarBlock.java
index f78377df404c6ab12570673291439d3a6d2188a6..90972757311f421bd6ee4571f3f54ecf56a80c82 100755
--- a/src/ui/window/JDialogSelectAvatarBlock.java
+++ b/src/ui/window/JDialogSelectAvatarBlock.java
@@ -57,15 +57,15 @@ import ui.avatarbd.*;
 
 
 public class JDialogSelectAvatarBlock extends javax.swing.JDialog implements ActionListener, ListSelectionListener  {
-    public Vector validated, ignored;
+    public Vector<AvatarBDStateMachineOwner> validated, ignored;
     private boolean optimized = true;
 
-    private Vector val, ign, back;
+    private Vector<AvatarBDStateMachineOwner> val, ign, back;
 
     //subpanels
     private JPanel panel1, panel2, panel3, panel4, panel5, panel6;
-    private JList listIgnored;
-    private JList listValidated;
+    private JList<AvatarBDStateMachineOwner> listIgnored;
+    private JList<AvatarBDStateMachineOwner> listValidated;
     private JButton allValidated;
     private JButton addOneValidated;
     private JButton addOneIgnored;
@@ -79,7 +79,7 @@ public class JDialogSelectAvatarBlock extends javax.swing.JDialog implements Act
     private boolean hasBeenCancelled = false;
 
     /** Creates new form  */
-    public JDialogSelectAvatarBlock(Frame f, Vector _back, LinkedList componentList, String title, Vector _validated, Vector _ignored, boolean _optimized) {
+    public JDialogSelectAvatarBlock(Frame f, Vector<AvatarBDStateMachineOwner> _back, LinkedList<AvatarBDStateMachineOwner> componentList, String title, Vector<AvatarBDStateMachineOwner> _validated, Vector<AvatarBDStateMachineOwner> _ignored, boolean _optimized) {
         super(f, title, true);
 
         back = _back;
@@ -103,42 +103,24 @@ public class JDialogSelectAvatarBlock extends javax.swing.JDialog implements Act
         pack();
     }
 
-    private Vector makeNewVal(LinkedList list) {
-        Vector v = new Vector();
-        TGComponent tgc;
-
-        for(int i=0; i<list.size(); i++) {
-            tgc = (TGComponent)(list.get(i));
-            //System.out.println(tgc);
-            if (tgc instanceof AvatarBDBlock) {
-                v.addElement(tgc);
-            }
-        }
-        return v;
+    private Vector<AvatarBDStateMachineOwner> makeNewVal(LinkedList<AvatarBDStateMachineOwner> list) {
+        return new Vector<AvatarBDStateMachineOwner> (list);
     }
 
-    private void checkTask(Vector tobeChecked, LinkedList source) {
-        AvatarBDBlock t;
-
-        for(int i=0; i<tobeChecked.size(); i++) {
-            t = (AvatarBDBlock)(tobeChecked.elementAt(i));
-            if (!source.contains(t)) {
-                tobeChecked.removeElementAt(i);
-                i--;
-            }
+    private void checkTask(Vector<AvatarBDStateMachineOwner> tobeChecked, LinkedList<AvatarBDStateMachineOwner> source) {
+        Iterator<AvatarBDStateMachineOwner> iterator = tobeChecked.iterator ();
+        
+        while (iterator.hasNext ()) {
+            AvatarBDStateMachineOwner t = iterator.next ();
+            if (!source.contains(t))
+                iterator.remove ();
         }
     }
 
-    public void addNewTask(Vector added, LinkedList source, Vector notSource) {
-        TGComponent tgc;
-
-        for(int i=0; i<source.size(); i++) {
-            tgc = (TGComponent)(source.get(i));
-            if ((tgc instanceof AvatarBDBlock) && (!added.contains(tgc)) && (!notSource.contains(tgc))){
+    public void addNewTask(Vector<AvatarBDStateMachineOwner> added, LinkedList<AvatarBDStateMachineOwner> source, Vector<AvatarBDStateMachineOwner> notSource) {
+        for (AvatarBDStateMachineOwner tgc: source)
+            if (!added.contains(tgc) && !notSource.contains(tgc))
                 added.addElement(tgc);
-                //System.out.println("New element");
-            }
-        }
     }
 
     private void myInitComponents() {
@@ -284,10 +266,9 @@ public class JDialogSelectAvatarBlock extends javax.swing.JDialog implements Act
 
     private void addOneIgnored() {
         int [] list = listValidated.getSelectedIndices();
-        Vector v = new Vector();
-        Object o;
+        Vector<AvatarBDStateMachineOwner> v = new Vector<AvatarBDStateMachineOwner> ();
         for (int i=0; i<list.length; i++){
-            o = val.elementAt(list[i]);
+            AvatarBDStateMachineOwner o = val.elementAt(list[i]);
             ign.addElement(o);
             v.addElement(o);
         }
@@ -301,9 +282,8 @@ public class JDialogSelectAvatarBlock extends javax.swing.JDialog implements Act
     private void addOneValidated() {
         int [] list = listIgnored.getSelectedIndices();
         Vector v = new Vector();
-        Object o;
         for (int i=0; i<list.length; i++){
-            o = ign.elementAt(list[i]);
+            AvatarBDStateMachineOwner o = ign.elementAt(list[i]);
             val.addElement(o);
             v.addElement(o);
         }
@@ -393,11 +373,11 @@ public class JDialogSelectAvatarBlock extends javax.swing.JDialog implements Act
         return hasBeenCancelled;
     }
 
-    public Vector getValidated() {
+    public Vector<AvatarBDStateMachineOwner> getValidated() {
         return validated;
     }
 
-    public Vector getIgnored() {
+    public Vector<AvatarBDStateMachineOwner> getIgnored() {
         return ignored;
     }
 }