From 2c70d351bfe2df2d39a96e25502b6ff01efbd8e7 Mon Sep 17 00:00:00 2001 From: Moemoea Fierin <moemoea.fierin@epita.fr> Date: Mon, 23 Sep 2019 17:51:45 +0200 Subject: [PATCH] [CLEANING] Added basic documentation on functions - added FIXMEs for later checkups - basic doc for Javadoc --- .../AvatarMethodologyDiagramReference.java | 207 ++++++++---------- 1 file changed, 91 insertions(+), 116 deletions(-) diff --git a/src/main/java/ui/avatarmethodology/AvatarMethodologyDiagramReference.java b/src/main/java/ui/avatarmethodology/AvatarMethodologyDiagramReference.java index f2cac71f4f..48540c9d3a 100755 --- a/src/main/java/ui/avatarmethodology/AvatarMethodologyDiagramReference.java +++ b/src/main/java/ui/avatarmethodology/AvatarMethodologyDiagramReference.java @@ -63,9 +63,9 @@ import java.util.Vector; * @author Ludovic APVRILLE */ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithInternalComponent implements SwallowTGComponent { - public String oldValue; - protected int textX = 5; - protected int textY = 22; + public String oldValue; + protected int textX = 5; //FIXME already extended from TGScalableComponent, should be textX = 5 + protected int textY = 22; //FIXME already extended from TGScalableComponent, should be textY = 22 protected int lineHeight = 30; protected double dlineHeight = 0.0; //protected int reqType = 0; @@ -127,9 +127,7 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI removable = false; userResizable = true; multieditable = true; - - - + oldValue = value; myImageIcon = IconManager.imgic5006; @@ -138,7 +136,12 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI actionOnAdd(); } - + /*From abstract class ui.TGComponent: declaration of abstract method*/ + /* + * InternalDrawing + * @param g + * */ + @Override public void internalDrawing(Graphics g) { Font f = g.getFont(); // Font fold = f; @@ -164,8 +167,6 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI displayText = currentFontSize >= minFontSize; - // int h = g.getFontMetrics().getHeight(); - g.setColor(ColorManager.AVATAR_REQUIREMENT_TOP); g.fillRect(x, y, width, height); ColorManager.setColor(g, getState(), 0); @@ -188,98 +189,17 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI drawLimitedString(g, value, x, y + size + 3, width, 1); g.setFont(f); } - - /*if (displayText) { - size = currentFontSize - 2; - g.setFont(myFont.deriveFont((float)(myFont.getSize() - 2))); - - drawLimitedString(g, REQ_TYPE_STR[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); - } - - if (reqType == SAFETY_REQ) { - drawLimitedString(g, "Violated action=\"" + violatedAction + "\"", x + textX, y + size, width, 0); - } - } - } - } - } - - - g.setFont(f);*/ } - + + /* + * editOndoubleClick: permits edition of the element on double click + * by simply calling adddiagramReference + * @param frame + * @param _x + * @param _y + * @return boolean true + * */ + @Override public boolean editOndoubleClick(JFrame frame, int _x, int _y) { addDiagramReference(frame); return true; @@ -338,8 +258,13 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI return editAttributes();*/ } - - + /* + * Rescale: rescale the element with the help of a scaleFactor + * From abstract class TGScalableComponent + * @param scaleFactor + * + * */ + @Override public void rescale(double scaleFactor){ dlineHeight = (lineHeight + dlineHeight) / oldScaleFactor * scaleFactor; lineHeight = (int)(dlineHeight); @@ -349,17 +274,27 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI super.rescale(scaleFactor); } - - + + /* + * isOnOnlyMe, Coming from Abstract Method From TGCWithInternalComponent (Abstract Class) + * @param x1 + * @param y1 + * @return TGComponent or null + * */ + @Override public TGComponent isOnOnlyMe(int x1, int y1) { - if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) { + if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) return this; - } return null; } - - + /* + * addActionToPopupMenu + * @param componentMenu + * @param menuAL + * @param x + * @param y + * */ public void addActionToPopupMenu(JPopupMenu componentMenu, ActionListener menuAL, int x, int y) { componentMenu.addSeparator(); @@ -370,6 +305,11 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI componentMenu.add(diagramReference); } + /* + * eventOnPopup + * @param e + * @return boolean true + * */ public boolean eventOnPopup(ActionEvent e) { // String s = e.getActionCommand(); @@ -382,6 +322,10 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI return true; } + /* + * addDiagramReference: permits to pop a new window??? + * @param frame + * */ public void addDiagramReference(JFrame frame) { JDialogManageListOfString jdmlos; Vector<String> ignored; // Must be built from non selected TMLTaskDiagramPanel or TMLCompPanel @@ -457,16 +401,23 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI public abstract void makeValidationInfos(AvatarMethodologyDiagramName dn); + /* + * hasAvatarMethodologyDiagramName + * @param s + * @return boolean denoting if the string s is in the tgcomponent list + * */ public boolean hasAvatarMethodologyDiagramName(String s) { - for(int i=0; i<nbInternalTGComponent; i++) { - if (tgcomponent[i].getValue().compareTo(s) == 0) { + for (int i = 0; i < nbInternalTGComponent; i++) + if (tgcomponent[i].getValue().compareTo(s) == 0) return true; - } - } return false; } - + /* + * fillIgnoredSelectedFromInternalComponents + * @param ignored + * @param selected + * */ public void fillIgnoredSelectedFromInternalComponents(Vector<String> ignored, Vector<String>selected) { // Get from mgui the list of all diagrams with type depends from the subclass // If diagrams have the same name -> we do not see the difference @@ -513,11 +464,23 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI } public abstract boolean isAValidPanelType(TURTLEPanel panel); - + + /* + * Permits to know if tgc is an instance of AvatarMethodologyDiagramName + * @param tgc + * @return boolean + * */ public boolean acceptSwallowedTGComponent(TGComponent tgc) { return tgc instanceof AvatarMethodologyDiagramName; } + /* + * addSwallowedTGComponent + * @param tgc + * @param x + * @param y + * @return boolean + * */ public boolean addSwallowedTGComponent(TGComponent tgc, int x, int y) { tgc.setFather(this); addInternalComponent(tgc, 0); @@ -525,12 +488,21 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI return true; } + /* + * removeSwallowedTGComponent + * @param tgc + * */ public void removeSwallowedTGComponent(TGComponent tgc) { removeInternalComponent(tgc); } public abstract boolean makeCall(String diagramName, int index); + /* + * openDiagram + * @param tabName + * @return boolean + * */ protected boolean openDiagram(String tabName) { if (!tdp.getMGUI().selectMainTab(tabName)) { TraceManager.addDev("Diagram removed?"); @@ -539,12 +511,15 @@ public abstract class AvatarMethodologyDiagramReference extends TGCScalableWithI return true; } + /* + * giveInformation + * @param info + * + * */ protected void giveInformation(String info) { tdp.getMGUI().setStatusBarText(info); } - - /*public String getDiagramReferences() { return referenceElements; }*/ -- GitLab