From 79d4cb7a45731c613518304eb9d361245542c666 Mon Sep 17 00:00:00 2001
From: Moemoea Fierin <moemoea.fierin@epita.fr>
Date: Thu, 3 Oct 2019 16:07:16 +0200
Subject: [PATCH] [ZOOM] Issue #31: txt removes itself when too small on RD
 avatar

- removed useless elements causing warniong
- changed internalDrawing func with a new shorter one
- added missing overrides
---
 .../ui/avatarrd/AvatarRDElementReference.java | 190 ++++++-----
 .../java/ui/avatarrd/AvatarRDProperty.java    | 170 ++++++----
 .../java/ui/avatarrd/AvatarRDRequirement.java | 295 ++++++++++++------
 3 files changed, 422 insertions(+), 233 deletions(-)

diff --git a/src/main/java/ui/avatarrd/AvatarRDElementReference.java b/src/main/java/ui/avatarrd/AvatarRDElementReference.java
index 9f8d24b0a0..a5c9800f9f 100644
--- a/src/main/java/ui/avatarrd/AvatarRDElementReference.java
+++ b/src/main/java/ui/avatarrd/AvatarRDElementReference.java
@@ -58,8 +58,8 @@ import java.awt.*;
  */
 public class AvatarRDElementReference extends TGCScalableWithInternalComponent implements TGAutoAdjust {
     public String oldValue;
-    protected int textX = 5;
-    protected int textY = 22;
+//    protected int textX = 5;
+//    protected int textY = 22;
     protected int lineHeight = 30;
     private double dlineHeight = 0.0;
     //protected int startFontSize = 10;
@@ -67,8 +67,8 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
     //protected int iconSize = 30;
 
     private Font myFont, myFontB;
-    private int maxFontSize = 30;
-    private int minFontSize = 4;
+//    private int maxFontSize = 30;
+   // private int minFontSize = 4;
     private int currentFontSize = -1;
     private boolean displayText = true;
 
@@ -77,19 +77,24 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
     protected String diagramText;
 
     private int iconSize = 18;
-    private boolean iconIsDrawn = false;
+//    private boolean iconIsDrawn = false;
 
     public AvatarRDElementReference(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);
 
+        //Issue #31
+        minWidth = 10;
+        minHeight = lineHeight;
+        textX = 5;
+        textY = 22;
         initScaling(150, lineHeight);
+        
         oldScaleFactor = tdp.getZoom();
         dlineHeight = lineHeight * oldScaleFactor;
         lineHeight = (int)dlineHeight;
         dlineHeight = dlineHeight - lineHeight;
 
-        minWidth = 10;
-        minHeight = lineHeight;
+
 
         nbConnectingPoint = 12;
         connectingPoint = new TGConnectingPoint[nbConnectingPoint];
@@ -111,7 +116,7 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
         nbInternalTGComponent = 0;
         //tgcomponent = new TGComponent[nbInternalTGComponent];
 
-        int h = 1;
+        //int h = 1;
         //TAttributeRequirement tgc0;
         //tgc0 = new TAttributeRequirement(x, y+height+h, 0, 0, height + h, height+h, true, this, _tdp);
         //tgcomponent[0] = tgc0;
@@ -135,69 +140,100 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
         actionOnAdd();
     }
 
-
-    public void internalDrawing(Graphics g) {
-        Font f = g.getFont();
-        Font fold = f;
-        int w, c;
-        int size;
-
-        if (!tdp.isScaled()) {
-            graphics = g;
-        }
-
-        if (((rescaled) && (!tdp.isScaled())) || myFont == null) {
-            currentFontSize = tdp.getFontSize();
-            //
-            myFont = f.deriveFont((float)currentFontSize);
-            myFontB = myFont.deriveFont(Font.BOLD);
-
-            if (rescaled) {
-                rescaled = false;
-            }
-        }
-
-        displayText = currentFontSize >= minFontSize;
-
-        int h  = g.getFontMetrics().getHeight();
-
-        g.drawRect(x, y, width, height);
-
-        g.drawLine(x, y+lineHeight, x+width, y+lineHeight);
-        g.setColor(ColorManager.AVATAR_REQUIREMENT_TOP);
-        g.fillRect(x+1, y+1, width-1, lineHeight-1);
-        g.setColor(ColorManager.AVATAR_BLOCK);
-        g.fillRect(x+1, y+1+lineHeight, width-1, height-1-lineHeight);
-        ColorManager.setColor(g, getState(), 0);
-        if ((lineHeight > 23) && (width > 23)){
-            g.drawImage(scale(IconManager.img5100), x + width - scale(iconSize + 1), y + scale(3), Color.yellow, null);
-        }
-
-        if (displayText) {
-            size = currentFontSize - 2;
-            g.setFont(myFont.deriveFont((float)(myFont.getSize() - 2)));
-            drawLimitedString(g, ELEMENT_REFERENCE, x, y + size, width, 1);
-            size += currentFontSize;
-            g.setFont(myFontB);
-            w = g.getFontMetrics().stringWidth(value);
-            drawLimitedString(g, value, x, y + size, width, 1);
-
-        }
-
-        /*g.setFont(myFont);
-
-          size = lineHeight + currentFontSize;
-          if (size < (height - 2)) {
-          drawLimitedString(g, "Diagram=\"" + diagramText + "\"", x + textX, y + size, width, 0);
-          size += currentFontSize;
-          // Violated action
-          if (size < (height - 2)) {
-          drawLimitedString(g, "Violated_Action=\"" + violatedAction + "\"", x + textX, y + size, width, 0);
-          }
-          }*/
-        g.setFont(f);
+    @Override
+    public void internalDrawing(Graphics g)
+    {
+    	// Rectangle and Filling
+    	g.drawRect(x, y, width, height);
+
+    	g.drawLine(x, y+lineHeight, x+width, y+lineHeight);
+    	g.setColor(ColorManager.AVATAR_REQUIREMENT_TOP);
+    	g.fillRect(x+1, y+1, width-1, lineHeight-1);
+    	g.setColor(ColorManager.AVATAR_BLOCK);
+    	g.fillRect(x+1, y+1+lineHeight, width-1, height-1-lineHeight);
+    	ColorManager.setColor(g, getState(), 0);
+    	
+    	// Check Text readability
+    	if (!isTextReadable(g))
+    		return;
+    	
+    	// Icon
+    	g.drawImage(scale(IconManager.img5100), x + width - scale(iconSize) - scale(1), y + scale(3), Color.yellow, null);
+    	
+    	// Strings: <<Element ref>> and lossy or unlossy
+    	Font font = g.getFont();
+    	int fontSize = font.getSize();
+    	g.setFont(font.deriveFont(Font.BOLD));
+    	drawLimitedString(g, ELEMENT_REFERENCE, x, y + fontSize, width, 1);
+    	fontSize *=2;
+    	g.setFont(font.deriveFont(Font.PLAIN));
+    	drawLimitedString(g, value, x, y + fontSize, width, 1);
     }
-
+    
+    
+//    public void internalDrawing(Graphics g) {
+//        Font f = g.getFont();
+//        //Font fold = f;
+//        //int w, c;
+//        int fontSize;
+//
+//        if (!tdp.isScaled()) {
+//            graphics = g;
+//        }
+//
+//        if (((rescaled) && (!tdp.isScaled())) || myFont == null) {
+//            currentFontSize = tdp.getFontSize();
+//            //
+//            myFont = f.deriveFont((float)currentFontSize);
+//            myFontB = myFont.deriveFont(Font.BOLD);
+//
+//            if (rescaled) {
+//                rescaled = false;
+//            }
+//        }
+//
+//        displayText = currentFontSize >= minFontSize;
+//
+//        int h  = g.getFontMetrics().getHeight();
+//
+//        g.drawRect(x, y, width, height);
+//
+//        g.drawLine(x, y+lineHeight, x+width, y+lineHeight);
+//        g.setColor(ColorManager.AVATAR_REQUIREMENT_TOP);
+//        g.fillRect(x+1, y+1, width-1, lineHeight-1);
+//        g.setColor(ColorManager.AVATAR_BLOCK);
+//        g.fillRect(x+1, y+1+lineHeight, width-1, height-1-lineHeight);
+//        ColorManager.setColor(g, getState(), 0);
+//        if ((lineHeight > 23) && (width > 23)){
+//            g.drawImage(scale(IconManager.img5100), x + width - scale(iconSize + 1), y + scale(3), Color.yellow, null);
+//        }
+//
+//        if (displayText) {
+//            fontSize = currentFontSize - 2;
+//            g.setFont(myFont.deriveFont((float)(myFont.getSize() - 2)));
+//            drawLimitedString(g, ELEMENT_REFERENCE, x, y + fontSize, width, 1);
+//            fontSize += currentFontSize;
+//            g.setFont(myFontB);
+//            w = g.getFontMetrics().stringWidth(value);
+//            drawLimitedString(g, value, x, y + fontSize, width, 1);
+//
+//        }
+//
+//        /*g.setFont(myFont);
+//
+//          fontSize = lineHeight + currentFontSize;
+//          if (fontSize < (height - 2)) {
+//          drawLimitedString(g, "Diagram=\"" + diagramText + "\"", x + textX, y + fontSize, width, 0);
+//          fontSize += currentFontSize;
+//          // Violated action
+//          if (fontSize < (height - 2)) {
+//          drawLimitedString(g, "Violated_Action=\"" + violatedAction + "\"", x + textX, y + fontSize, width, 0);
+//          }
+//          }*/
+//        g.setFont(f);
+//    }
+    
+    @Override
     public boolean editOndoubleClick(JFrame frame, int _x, int _y) {
         oldValue = value;
 
@@ -222,8 +258,8 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
                 }
 
 
-                int size = graphics.getFontMetrics().stringWidth(s) + iconSize + 5;
-                minDesiredWidth = Math.max(size, minWidth);
+                int fontSize = graphics.getFontMetrics().stringWidth(s) + iconSize + 5;
+                minDesiredWidth = Math.max(fontSize, minWidth);
                 if (minDesiredWidth != width) {
                     newSizeForSon(null);
                 }
@@ -239,7 +275,7 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
     }
 
 
-
+    @Override
     public void rescale(double scaleFactor){
         dlineHeight = (lineHeight + dlineHeight) / oldScaleFactor * scaleFactor;
         lineHeight = (int)(dlineHeight);
@@ -248,7 +284,7 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
 
         super.rescale(scaleFactor);
     }
-
+    @Override
     public TGComponent isOnOnlyMe(int x1, int y1) {
         if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) {
             return this;
@@ -256,17 +292,17 @@ public class AvatarRDElementReference extends TGCScalableWithInternalComponent i
         return null;
     }
 
-
+    @Override
     public  int getType() {
         return TGComponentManager.AVATARRD_ELEMENT_REFERENCE;
     }
 
-
+    @Override
     public String toString() {
         String ret =  getValue() + ELEMENT_REFERENCE;
         return ret;
     }
-
+    @Override
     public void autoAdjust(int mode) {
         //
 
diff --git a/src/main/java/ui/avatarrd/AvatarRDProperty.java b/src/main/java/ui/avatarrd/AvatarRDProperty.java
index 1e38d8c89e..4ca3ca12fa 100755
--- a/src/main/java/ui/avatarrd/AvatarRDProperty.java
+++ b/src/main/java/ui/avatarrd/AvatarRDProperty.java
@@ -68,7 +68,7 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
     
 
     private Font myFont, myFontB;
-    private int maxFontSize = 30;
+    //private int maxFontSize = 30;
     private int minFontSize = 4;
     private int currentFontSize = -1;
     private boolean displayText = true;
@@ -79,12 +79,15 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
     protected String violatedAction = "noAction";
 
     private int iconSize = 18;
-    private boolean iconIsDrawn = false;
+    //private boolean iconIsDrawn = false;
 
     public AvatarRDProperty(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);
-
+        
+        textX = 5;
+        textY = 22;
         initScaling(150, lineHeight);
+        
         oldScaleFactor = tdp.getZoom();
         dlineHeight = lineHeight * oldScaleFactor;
         lineHeight = (int)dlineHeight;
@@ -113,7 +116,7 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
         nbInternalTGComponent = 0;
         //tgcomponent = new TGComponent[nbInternalTGComponent];
 
-        int h = 1;
+        //int h = 1;
         //TAttributeRequirement tgc0;
         //tgc0 = new TAttributeRequirement(x, y+height+h, 0, 0, height + h, height+h, true, this, _tdp);
         //tgcomponent[0] = tgc0;
@@ -138,66 +141,97 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
         actionOnAdd();
     }
     
-    public void internalDrawing(Graphics g) {
-        Font f = g.getFont();
-        
-        //Font fold = f; FIXME: unused 
-        //int w, c; FIXME: unused 
-        if (!tdp.isScaled()) {
-            graphics = g;
-        }
-
-        if (((rescaled) && (!tdp.isScaled())) || myFont == null) {
-            currentFontSize = tdp.getFontSize();
-            myFont = f.deriveFont((float)currentFontSize);
-            myFontB = myFont.deriveFont(Font.BOLD);
-
-            if (rescaled)
-                rescaled = false;
-        }
-
-        displayText = currentFontSize >= minFontSize;
-
-        //int h  = g.getFontMetrics().getHeight(); FIXME: unused ?
-
-        g.drawRect(x, y, width, height);
-
-        g.drawLine(x, y+lineHeight, x+width, y+lineHeight);
-        g.setColor(ColorManager.AVATAR_REQUIREMENT_TOP);
-        g.fillRect(x+1, y+1, width-1, lineHeight-1);
-        g.setColor(ColorManager.AVATAR_REQUIREMENT_ATTRIBUTES);
-        g.fillRect(x+1, y+1+lineHeight, width-1, height-1-lineHeight);
-        ColorManager.setColor(g, getState(), 0);
-        if ((lineHeight > 23) && (width > 23)){
-            g.drawImage(IconManager.img5100, x + width - iconSize + 1, y + 3, Color.yellow, null);
-        }
-
-        int size;
-        if (displayText) {
-            //size = currentFontSize - 2;
-        	size = 50;
-            g.setFont(myFont.deriveFont((float)(myFont.getSize() - 2)));
-            drawLimitedString(g, PROPERTY, x, y + size, width, 1);
-            size += currentFontSize;
-            g.setFont(myFontB);
-            //w = g.getFontMetrics().stringWidth(value); FIXME: unused 
-            drawLimitedString(g, value, x, y + size, width, 1);
-
-        }
-
-        /*g.setFont(myFont);
-
-          size = lineHeight + currentFontSize;
-          if (size < (height - 2)) {
-          drawLimitedString(g, "Diagram=\"" + diagramText + "\"", x + textX, y + size, width, 0);
-          size += currentFontSize;
-          // Violated action
-          if (size < (height - 2)) {
-          drawLimitedString(g, "Violated_Action=\"" + violatedAction + "\"", x + textX, y + size, width, 0);
-          }
-          }*/
-        g.setFont(f);
+    //Issue #31
+    @Override
+    public void internalDrawing(Graphics g)
+    {
+    	//Rectangle
+    	g.drawRect(x, y, width, height);
+    	g.drawLine(x, y + lineHeight, x + width, y + lineHeight);
+    	 
+    	//Filling
+    	g.setColor(ColorManager.AVATAR_REQUIREMENT_TOP);
+      g.fillRect(x+1, y+1, width-1, lineHeight-1);
+      g.setColor(ColorManager.AVATAR_REQUIREMENT_ATTRIBUTES);
+      g.fillRect(x+1, y+1+lineHeight, width-1, height-1-lineHeight);
+      ColorManager.setColor(g, getState(), 0);
+      
+      //Readability Check
+      if (!isTextReadable(g))
+    	  return;
+      //Icon
+      g.drawImage(scale(IconManager.img5100), x + width - scale(iconSize + 2), y + scale(3), Color.yellow, null);
+      
+      //Strings
+      Font font = g.getFont();
+      currentFontSize = font.getSize();
+      g.setFont(font.deriveFont(Font.BOLD));
+      drawLimitedString(g, PROPERTY, x, y + currentFontSize , width, 1);
+      g.setFont(font.deriveFont(Font.PLAIN));
+      drawLimitedString(g, value, x, y + currentFontSize * 2, width, 1);
     }
+    
+    
+//    public void internalDrawing(Graphics g) {
+//        Font f = g.getFont();
+//        
+//        //Font fold = f; FIXME: unused 
+//        //int w, c; FIXME: unused 
+//        if (!tdp.isScaled()) {
+//            graphics = g;
+//        }
+//
+//        if (((rescaled) && (!tdp.isScaled())) || myFont == null) {
+//            currentFontSize = tdp.getFontSize();
+//            myFont = f.deriveFont((float)currentFontSize);
+//            myFontB = myFont.deriveFont(Font.BOLD);
+//
+//            if (rescaled)
+//                rescaled = false;
+//        }
+//
+//        displayText = currentFontSize >= minFontSize;
+//
+//        //int h  = g.getFontMetrics().getHeight(); FIXME: unused ?
+//
+//        g.drawRect(x, y, width, height);
+//
+//        g.drawLine(x, y+lineHeight, x+width, y+lineHeight);
+//        g.setColor(ColorManager.AVATAR_REQUIREMENT_TOP);
+//        g.fillRect(x+1, y+1, width-1, lineHeight-1);
+//        g.setColor(ColorManager.AVATAR_REQUIREMENT_ATTRIBUTES);
+//        g.fillRect(x+1, y+1+lineHeight, width-1, height-1-lineHeight);
+//        ColorManager.setColor(g, getState(), 0);
+//        if ((lineHeight > 23) && (width > 23)){
+//            g.drawImage(IconManager.img5100, x + width - iconSize + 1, y + 3, Color.yellow, null);
+//        }
+//
+//        int size;
+//        if (displayText) {
+//            //size = currentFontSize - 2;
+//        	size = 50;
+//            g.setFont(myFont.deriveFont((float)(myFont.getSize() - 2)));
+//            drawLimitedString(g, PROPERTY, x, y + size, width, 1);
+//            size += currentFontSize;
+//            g.setFont(myFontB);
+//            //w = g.getFontMetrics().stringWidth(value); FIXME: unused 
+//            drawLimitedString(g, value, x, y + size, width, 1);
+//
+//        }
+//
+//        /*g.setFont(myFont);
+//
+//          size = lineHeight + currentFontSize;
+//          if (size < (height - 2)) {
+//          drawLimitedString(g, "Diagram=\"" + diagramText + "\"", x + textX, y + size, width, 0);
+//          size += currentFontSize;
+//          // Violated action
+//          if (size < (height - 2)) {
+//          drawLimitedString(g, "Violated_Action=\"" + violatedAction + "\"", x + textX, y + size, width, 0);
+//          }
+//          }*/
+//        g.setFont(f);
+//    }
     @Override
     public boolean editOndoubleClick(JFrame frame, int _x, int _y) {
         oldValue = value;
@@ -271,7 +305,7 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
 
       return true;
       }*/
-
+    @Override
     public void rescale(double scaleFactor){
         dlineHeight = (lineHeight + dlineHeight) / oldScaleFactor * scaleFactor;
         lineHeight = (int)(dlineHeight);
@@ -281,7 +315,7 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
         super.rescale(scaleFactor);
     }
 
-
+    @Override
     public TGComponent isOnOnlyMe(int x1, int y1) {
         if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) {
             return this;
@@ -293,7 +327,7 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
         return value;
     }
 
-
+    @Override
     public  int getType() {
         return TGComponentManager.AVATARRD_PROPERTY;
     }
@@ -321,12 +355,12 @@ public class AvatarRDProperty extends TGCScalableWithInternalComponent implement
        }
        return true;
        }*/
-
+    @Override
     public String toString() {
         String ret =  getValue() + PROPERTY;
         return ret;
     }
-
+    @Override
     public void autoAdjust(int mode) {
         //
 
diff --git a/src/main/java/ui/avatarrd/AvatarRDRequirement.java b/src/main/java/ui/avatarrd/AvatarRDRequirement.java
index 366ce63624..f90865a36f 100755
--- a/src/main/java/ui/avatarrd/AvatarRDRequirement.java
+++ b/src/main/java/ui/avatarrd/AvatarRDRequirement.java
@@ -71,8 +71,8 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem
     public static int SIZE_LIMIT = 35;
 
     public String oldValue;
-    protected int textX = 5;
-    protected int textY = 22;
+    //protected int textX = 5;
+    //protected int textY = 22;
     protected int lineHeight = 30;
     private double dlineHeight = 0.0;
     //protected int reqType = 0;
@@ -139,7 +139,13 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem
     public AvatarRDRequirement(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);
 
+        //Issue #31
+        textY = 22;
+        textX = 5;
+        minWidth = lineLength;
+        minHeight = 10;
         initScaling(200, 120);
+        
         oldScaleFactor = tdp.getZoom();
         dlineHeight = lineHeight * oldScaleFactor;
         lineHeight = (int) dlineHeight;
@@ -237,93 +243,59 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem
     public void makeValue() {
         texts = Conversion.wrapText(text);
     }
+    
 
-    public void internalDrawing(Graphics g) {
-        Font f = g.getFont();
-        //    Font fold = f;
-        //  int w, c;
-        int size;
-
-        if (texts == null) {
-            makeValue();
-        }
-
-        if (!tdp.isScaled()) {
-            graphics = g;
-        }
-
-        if (((rescaled) && (!tdp.isScaled())) || myFont == null) {
-            currentFontSize = tdp.getFontSize();
-            //
-            myFont = f.deriveFont((float) currentFontSize);
-            myFontB = myFont.deriveFont(Font.BOLD);
-
-            if (rescaled) {
-                rescaled = false;
-            }
-        }
-
-        displayText = currentFontSize >= minFontSize;
-
-        //   int h  = g.getFontMetrics().getHeight();
-
-        g.drawRect(x, y, width, height);
-
-        g.drawLine(x, y + lineHeight, x + width, y + lineHeight);
-        Color topColor = REQ_TYPE_COLOR.get(reqType);
-        if (topColor == null) {
-            //TraceManager.addDev("Swithing back to default Color for:" + REQ_TYPE_STR.get(reqType));
-            topColor = ColorManager.AVATAR_REQUIREMENT_TOP;
-        } else {
-            //TraceManager.addDev("Using color: " + topColor.getRGB() + "for  " +REQ_TYPE_STR.get(reqType));
-        }
-        g.setColor(topColor);
-        g.fillRect(x + 1, y + 1, width - 1, lineHeight - 1);
-        g.setColor(ColorManager.AVATAR_REQUIREMENT_ATTRIBUTES);
-        g.fillRect(x + 1, y + 1 + lineHeight, width - 1, height - 1 - lineHeight);
-        ColorManager.setColor(g, getState(), 0);
-        if ((lineHeight > 23) && (width > 23)) {
-            g.drawImage(IconManager.img5100, x + width - iconSize + 1, y + 3, Color.yellow, null);
-        }
-
-        if (displayText) {
-            size = currentFontSize - 2;
-            g.setFont(myFont.deriveFont((float) (myFont.getSize() - 2)));
-
-            drawLimitedString(g, "<<" + REQ_TYPE_STR.get(reqType) + ">>", x, y + size, width, 1);
-
-            size += currentFontSize;
-            g.setFont(myFontB);
-            //  w = g.getFontMetrics().stringWidth(value);
-            drawLimitedString(g, value, x, y + size, width, 1);
-
-        }
-
-        if (verified) {
-            if (satisfied) {
-                Color tmp = g.getColor();
-                GraphicLib.setMediumStroke(g);
-                g.setColor(Color.green);
-                g.drawLine(x + width - 2, y - 6 + lineHeight, x + width - 6, y - 2 + lineHeight);
-                g.drawLine(x + width - 6, y - 3 + lineHeight, x + width - 8, y - 6 + lineHeight);
-                g.setColor(tmp);
-                GraphicLib.setNormalStroke(g);
-            } else {
-                //g.drawString("acc", x + width - 10, y+height-10);
-                Color tmp = g.getColor();
-                GraphicLib.setMediumStroke(g);
-                g.setColor(Color.red);
-                g.drawLine(x + width - 2, y - 2 + lineHeight, x + width - 8, y - 8 + lineHeight);
-                g.drawLine(x + width - 8, y - 2 + lineHeight, x + width - 2, y - 8 + lineHeight);
-                g.setColor(tmp);
-                GraphicLib.setNormalStroke(g);
-            }
-        }
-
-        g.setFont(myFont);
+    @Override
+    public void internalDrawing(Graphics g)
+    {
+    	// Rectangle and lines
+    	g.drawRect(x, y, width, height);
+    	g.drawLine(x, y + lineHeight, x + width, y + lineHeight);
+    	
+    	// Rectangle Filling
+    	Color topColor = REQ_TYPE_COLOR.get(reqType);
+    	if (topColor == null)
+    		topColor = ColorManager.AVATAR_REQUIREMENT_TOP;
+    	g.setColor(topColor);
+    	g.fillRect(x + 1, y + 1, width - 1, lineHeight - 1);
+    	g.setColor(ColorManager.AVATAR_REQUIREMENT_ATTRIBUTES);
+    	g.fillRect(x + 1, y + 1 + lineHeight, width - 1, height - 1 - lineHeight);
+    	ColorManager.setColor(g, getState(), 0);
+	  
+    	// check readability
+    	if (!isTextReadable(g))
+    		return;
+    	Font f = g.getFont();
+    	int size = f.getSize();
+
+    	// TTool Icon
+    	int borders = scale(3);
+    	g.drawImage(scale(IconManager.img5100), x + width - scale(iconSize) - borders, y + borders, Color.yellow, null);
+    	
+    	//String
+    	String req = "<<" + REQ_TYPE_STR.get(reqType) + ">>";
+    	if (!canTextGoInTheBox(g, size, req, iconSize))
+    		return;
+    	g.setFont(f.deriveFont(Font.BOLD));
+    	drawLimitedString(g, req, x, y + size, width, 1);
+    	
+    	//g.setFont(myFontB);
+    	if (!canTextGoInTheBox(g, size, value, iconSize))
+    		return;
+    	Font iFont = f.deriveFont(Font.PLAIN);
+    	g.setFont(iFont);
+    	drawLimitedString(g, value, x, y + size * 2 + scale(2), width, 1);
+		
+    	internalDrawingAux(g, size);
+    }
+    
+    //FIXME: need to make this function easier
+    private void internalDrawingAux(Graphics g, int size)
+    {
         String texti = "Text";
         String s;
         int i;
+        currentFontSize = g.getFont().getSize();
         size = lineHeight + currentFontSize;
 
         //ID
@@ -382,12 +354,159 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem
                 drawLimitedString(g, s, x + textX, y + size, width, 0);
             }
             size += currentFontSize;
-
         }
-
-        g.setFont(f);
     }
 
+//    public void internalDrawing(Graphics g) {
+//        Font f = g.getFont();
+//        //    Font fold = f;
+//        //  int w, c;
+//        int size;
+//
+//        if (texts == null) {
+//            makeValue();
+//        }
+//
+//        if (!tdp.isScaled()) {
+//            graphics = g;
+//        }
+//
+//        if (((rescaled) && (!tdp.isScaled())) || myFont == null) {
+//            currentFontSize = tdp.getFontSize();
+//            //
+//            myFont = f.deriveFont((float) currentFontSize);
+//            myFontB = myFont.deriveFont(Font.BOLD);
+//
+//            if (rescaled) {
+//                rescaled = false;
+//            }
+//        }
+//
+//        displayText = currentFontSize >= minFontSize;
+//
+//        //   int h  = g.getFontMetrics().getHeight();
+//
+//        g.drawRect(x, y, width, height);
+//
+//        g.drawLine(x, y + lineHeight, x + width, y + lineHeight);
+//        Color topColor = REQ_TYPE_COLOR.get(reqType);
+//        if (topColor == null) {
+//            //TraceManager.addDev("Swithing back to default Color for:" + REQ_TYPE_STR.get(reqType));
+//            topColor = ColorManager.AVATAR_REQUIREMENT_TOP;
+//        } else {
+//            //TraceManager.addDev("Using color: " + topColor.getRGB() + "for  " +REQ_TYPE_STR.get(reqType));
+//        }
+//        g.setColor(topColor);
+//        g.fillRect(x + 1, y + 1, width - 1, lineHeight - 1);
+//        g.setColor(ColorManager.AVATAR_REQUIREMENT_ATTRIBUTES);
+//        g.fillRect(x + 1, y + 1 + lineHeight, width - 1, height - 1 - lineHeight);
+//        ColorManager.setColor(g, getState(), 0);
+//        if ((lineHeight > 23) && (width > 23)) {
+//            g.drawImage(IconManager.img5100, x + width - iconSize + 1, y + 3, Color.yellow, null);
+//        }
+//
+//        if (displayText) {
+//            size = currentFontSize - 2;
+//            g.setFont(myFont.deriveFont((float) (myFont.getSize() - 2)));
+//
+//            drawLimitedString(g, "<<" + REQ_TYPE_STR.get(reqType) + ">>", x, y + size, width, 1);
+//
+//            size += currentFontSize;
+//            g.setFont(myFontB);
+//            //  w = g.getFontMetrics().stringWidth(value);
+//            drawLimitedString(g, value, x, y + size, width, 1);
+//
+//        }
+//
+//        if (verified) {
+//            if (satisfied) {
+//                Color tmp = g.getColor();
+//                GraphicLib.setMediumStroke(g);
+//                g.setColor(Color.green);
+//                g.drawLine(x + width - 2, y - 6 + lineHeight, x + width - 6, y - 2 + lineHeight);
+//                g.drawLine(x + width - 6, y - 3 + lineHeight, x + width - 8, y - 6 + lineHeight);
+//                g.setColor(tmp);
+//                GraphicLib.setNormalStroke(g);
+//            } else {
+//                //g.drawString("acc", x + width - 10, y+height-10);
+//                Color tmp = g.getColor();
+//                GraphicLib.setMediumStroke(g);
+//                g.setColor(Color.red);
+//                g.drawLine(x + width - 2, y - 2 + lineHeight, x + width - 8, y - 8 + lineHeight);
+//                g.drawLine(x + width - 8, y - 2 + lineHeight, x + width - 2, y - 8 + lineHeight);
+//                g.setColor(tmp);
+//                GraphicLib.setNormalStroke(g);
+//            }
+//        }
+//
+//        g.setFont(myFont);
+//        String texti = "Text";
+//        String s;
+//        int i;
+//        size = lineHeight + currentFontSize;
+//
+//        //ID
+//        if (size < (height - 2)) {
+//            drawLimitedString(g, "ID=" + id, x + textX, y + size, width, 0);
+//        }
+//        size += currentFontSize;
+//
+//        //text
+//        for (i = 0; i < texts.length; i++) {
+//            if (size < (height - 2)) {
+//                s = texts[i];
+//                if (i == 0) {
+//                    s = texti + "=\"" + s;
+//                }
+//                if (i == (texts.length - 1)) {
+//                    s = s + "\"";
+//                }
+//                drawLimitedString(g, s, x + textX, y + size, width, 0);
+//            }
+//            size += currentFontSize;
+//
+//        }
+//        // Type and risk
+//        if (size < (height - 2)) {
+//            drawLimitedString(g, "Kind=\"" + kind + "\"", x + textX, y + size, width, 0);
+//            size += currentFontSize;
+//            if (size < (height - 2)) {
+//                drawLimitedString(g, "Risk=\"" + criticality + "\"", x + textX, y + size, width, 0);
+//                size += currentFontSize;
+//                if (size < (height - 2)) {
+//
+//                    drawLimitedString(g, "Reference elements=\"" + referenceElements + "\"", x + textX, y + size, width, 0);
+//                    size += currentFontSize;
+//
+//                    if (size < (height - 2)) {
+//
+//                        if (reqType == SECURITY_REQ) {
+//                            drawLimitedString(g, "Targeted attacks=\"" + attackTreeNode + "\"", x + textX, y + size, width, 0);
+//                            size += currentFontSize;
+//                        }
+//
+//                        if (reqType == SAFETY_REQ) {
+//                            drawLimitedString(g, "State violating req.=\"" + violatedAction + "\"", x + textX, y + size, width, 0);
+//                            size += currentFontSize;
+//                        }
+//                    }
+//                }
+//            }
+//        }
+//
+//        // Extra attributes
+//        for (i = 0; i < extraParamIDs.size(); i++) {
+//            if (size < (height - 2)) {
+//                s = extraParamIDs.get(i) + ":" + extraParamValues.get(i);
+//                drawLimitedString(g, s, x + textX, y + size, width, 0);
+//            }
+//            size += currentFontSize;
+//
+//        }
+//
+//        g.setFont(f);
+//    }
+
     public boolean editOndoubleClick(JFrame frame, int _x, int _y) {
         // On the name ?
         oldValue = value;
-- 
GitLab