diff --git a/.idea/misc.xml b/.idea/misc.xml index b755d8ca46c060cb7a2b6b29b7ec83e02b8b71e2..51e5191ed4bd4e6ffe2a1823753c5d6f92894ab9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -38,7 +38,7 @@ <property name="caretWidth" class="java.lang.Integer" /> </properties> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.7" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build" /> </component> </project> \ No newline at end of file diff --git a/src/main/java/ui/avatarbd/AvatarBDBlock.java b/src/main/java/ui/avatarbd/AvatarBDBlock.java index f2bbe5300219718ddd4f0ccf806d64595a94b255..cad86936ecfda873ef6a2ad764d8ce056b6a91cf 100644 --- a/src/main/java/ui/avatarbd/AvatarBDBlock.java +++ b/src/main/java/ui/avatarbd/AvatarBDBlock.java @@ -1,26 +1,26 @@ /* 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, @@ -31,14 +31,12 @@ * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. - * + * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. */ - - package ui.avatarbd; import myutil.Conversion; @@ -60,11 +58,12 @@ import java.util.LinkedList; /** - * Class AvatarBDBlock - * Node. To be used in AVATAR Block Diagrams - * Creation: 06/04/2010 - * @version 1.1 06/04/2010 - * @author Ludovic APVRILLE + * Class AvatarBDBlock + * Node. To be used in AVATAR Block Diagrams + * Creation: 06/04/2010 + * + * @author Ludovic APVRILLE + * @version 1.1 06/04/2010 */ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent, GenericTree, AvatarBDStateMachineOwner { @@ -95,12 +94,12 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S protected LinkedList<TAttribute> myAttributes; protected LinkedList<AvatarMethod> myMethods; protected LinkedList<AvatarSignal> mySignals; - protected String [] globalCode; + protected String[] globalCode; public String oldValue; - public AvatarBDBlock(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + public AvatarBDBlock(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); width = 250; @@ -144,64 +143,64 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S oldValue = value; oldScaleFactor = tdp.getZoom(); - currentFontSize = (int) (maxFontSize*oldScaleFactor); + currentFontSize = (int) (maxFontSize * oldScaleFactor); myImageIcon = IconManager.imgic700; - this.myAttributes = new LinkedList<TAttribute> (); - this.myMethods = new LinkedList<AvatarMethod> (); - this.mySignals = new LinkedList<AvatarSignal> (); + this.myAttributes = new LinkedList<TAttribute>(); + this.myMethods = new LinkedList<AvatarMethod>(); + this.mySignals = new LinkedList<AvatarSignal>(); actionOnAdd(); } @Override - public void internalDrawing (Graphics graph) { - Font font = graph.getFont (); - this.internalDrawingAux (graph); - graph.setFont (font); + public void internalDrawing(Graphics graph) { + Font font = graph.getFont(); + this.internalDrawingAux(graph); + graph.setFont(font); } public void setSignalsAsNonAttached() { - for (AvatarSignal mySig: mySignals) mySig.attachedToARelation = false; + for (AvatarSignal mySig : mySignals) mySig.attachedToARelation = false; } - - public void addSignal(AvatarSignal sig){ - this.mySignals.add(sig); + + public void addSignal(AvatarSignal sig) { + this.mySignals.add(sig); } - - public void internalDrawingAux (Graphics graph) { - //TraceManager.addDev("Block drawing aux = " + this); - + public void internalDrawingAux(Graphics graph) { + + //TraceManager.addDev("Block drawing aux = " + this); + // Draw outer rectangle (for border) - Color c = graph.getColor (); - graph.drawRect (this.x, this.y, this.width, this.height); + Color c = graph.getColor(); + graph.drawRect(this.x, this.y, this.width, this.height); // Draw inner rectangle - graph.setColor (ColorManager.AVATAR_BLOCK); - graph.fillRect (this.x+1, this.y+1, this.width-1, this.height-1); - graph.setColor (c); + graph.setColor(ColorManager.AVATAR_BLOCK); + graph.fillRect(this.x + 1, this.y + 1, this.width - 1, this.height - 1); + graph.setColor(c); // limits this.limitName = -1; this.limitAttr = -1; this.limitMethod = -1; - this.limitSignal = y + height; + this.limitSignal = y + height; // h retains the coordinate along X where an element was last drawn int h = 0; - int textY1 = (int) (this.textY1 * this.tdp.getZoom ()); - int textX = (int) (this.textX * this.tdp.getZoom ()); + int textY1 = (int) (this.textY1 * this.tdp.getZoom()); + int textX = (int) (this.textX * this.tdp.getZoom()); // Draw icon - this.iconIsDrawn = this.width > IconManager.iconSize + 2*textX && height > IconManager.iconSize + 2*textX; + this.iconIsDrawn = this.width > IconManager.iconSize + 2 * textX && height > IconManager.iconSize + 2 * textX; if (this.iconIsDrawn) - graph.drawImage (IconManager.img5100, this.x + this.width - IconManager.iconSize - textX, this.y + textX, null); + graph.drawImage(IconManager.img5100, this.x + this.width - IconManager.iconSize - textX, this.y + textX, null); - Font font = graph.getFont (); + Font font = graph.getFont(); String ster; if (!this.isCryptoBlock) @@ -209,56 +208,56 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S else ster = "<<" + stereotypeCrypto + ">>"; - if (this.rescaled && !this.tdp.isScaled ()) { + if (this.rescaled && !this.tdp.isScaled()) { this.rescaled = false; // Must set the font size... // Incrementally find the biggest font not greater than max_font size // If font is less than min_font, no text is displayed // This is the maximum font size possible - int maxCurrentFontSize = Math.max (0, Math.min (this.height, (int) (this.maxFontSize*this.tdp.getZoom ()))); - font = font.deriveFont ((float) maxCurrentFontSize); + int maxCurrentFontSize = Math.max(0, Math.min(this.height, (int) (this.maxFontSize * this.tdp.getZoom()))); + font = font.deriveFont((float) maxCurrentFontSize); // Try to decrease font size until we get below the minimum - while (maxCurrentFontSize > (this.minFontSize*this.tdp.getZoom () - 1)) { + while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) { // Compute width of name of the function - int w0 = graph.getFontMetrics (font).stringWidth (this.value); + int w0 = graph.getFontMetrics(font).stringWidth(this.value); // Compute width of string stereotype - int w1 = graph.getFontMetrics (font).stringWidth (ster); + int w1 = graph.getFontMetrics(font).stringWidth(ster); // if one of the two width is small enough use this font size - if (Math.min (w0, w1) < this.width - (2*this.textX)) + if (Math.min(w0, w1) < this.width - (2 * this.textX)) break; // Decrease font size - maxCurrentFontSize --; + maxCurrentFontSize--; // Scale the font - font = font.deriveFont ((float) maxCurrentFontSize); + font = font.deriveFont((float) maxCurrentFontSize); } // Box is too damn small - if (this.currentFontSize < this.minFontSize*this.tdp.getZoom ()) { - maxCurrentFontSize ++; + if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) { + maxCurrentFontSize++; // Scale the font - font = font.deriveFont ((float) maxCurrentFontSize); + font = font.deriveFont((float) maxCurrentFontSize); } // Use this font - graph.setFont (font); + graph.setFont(font); this.currentFontSize = maxCurrentFontSize; } else - font = font.deriveFont (this.currentFontSize); + font = font.deriveFont(this.currentFontSize); - graph.setFont (font.deriveFont (Font.BOLD)); - h = graph.getFontMetrics ().getAscent () + graph.getFontMetrics ().getLeading () + textY1; + graph.setFont(font.deriveFont(Font.BOLD)); + h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY1; - if (h + graph.getFontMetrics ().getDescent () + textY1 >= this.height) + if (h + graph.getFontMetrics().getDescent() + textY1 >= this.height) return; // Write stereotype if small enough - int w = graph.getFontMetrics ().stringWidth (ster); - if (w + 2*textX < this.width) - graph.drawString (ster, this.x + (this.width - w)/2, this.y + h); + int w = graph.getFontMetrics().stringWidth(ster); + if (w + 2 * textX < this.width) + graph.drawString(ster, this.x + (this.width - w) / 2, this.y + h); else { // try to draw with "..." instead if (!this.isCryptoBlock) @@ -266,38 +265,38 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S else ster = stereotypeCrypto; - for (int stringLength = ster.length ()-1; stringLength >= 0; stringLength--) { - String abbrev = "<<" + ster.substring (0, stringLength) + "...>>"; - w = graph.getFontMetrics ().stringWidth (abbrev); - if (w + 2*textX < this.width) { - graph.drawString (abbrev, this.x + (this.width - w)/2, this.y + h); + for (int stringLength = ster.length() - 1; stringLength >= 0; stringLength--) { + String abbrev = "<<" + ster.substring(0, stringLength) + "...>>"; + w = graph.getFontMetrics().stringWidth(abbrev); + if (w + 2 * textX < this.width) { + graph.drawString(abbrev, this.x + (this.width - w) / 2, this.y + h); break; } } } // Write value if small enough - graph.setFont (font); - h += graph.getFontMetrics ().getHeight () + textY1; - if (h + graph.getFontMetrics ().getDescent () + textY1 >= this.height) + graph.setFont(font); + h += graph.getFontMetrics().getHeight() + textY1; + if (h + graph.getFontMetrics().getDescent() + textY1 >= this.height) return; - w = graph.getFontMetrics ().stringWidth (this.value); - if (w + 2*textX < this.width) - graph.drawString (this.value, this.x + (this.width - w)/2, this.y + h); + w = graph.getFontMetrics().stringWidth(this.value); + if (w + 2 * textX < this.width) + graph.drawString(this.value, this.x + (this.width - w) / 2, this.y + h); else { // try to draw with "..." instead - for (int stringLength = this.value.length ()-1; stringLength >= 0; stringLength--) { - String abbrev = this.value.substring (0, stringLength) + "..."; - w = graph.getFontMetrics ().stringWidth (abbrev); - if (w + 2*textX < this.width) { - graph.drawString (abbrev, this.x + (this.width - w)/2, this.y + h); + for (int stringLength = this.value.length() - 1; stringLength >= 0; stringLength--) { + String abbrev = this.value.substring(0, stringLength) + "..."; + w = graph.getFontMetrics().stringWidth(abbrev); + if (w + 2 * textX < this.width) { + graph.drawString(abbrev, this.x + (this.width - w) / 2, this.y + h); break; } } } - h += graph.getFontMetrics ().getDescent () + textY1; + h += graph.getFontMetrics().getDescent() + textY1; // Update lower bound of text this.limitName = this.y + h; @@ -306,22 +305,22 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S return; // Draw separator - graph.drawLine (this.x, this.y+h, this.x+this.width, this.y+h); + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); - if (! this.tdp.areAttributesVisible ()) + if (!this.tdp.areAttributesVisible()) return; // Set font size // int attributeFontSize = Math.min (12, this.currentFontSize - 2); - int attributeFontSize = this.currentFontSize*5/6; - graph.setFont (font.deriveFont ((float) attributeFontSize)); - int step = graph.getFontMetrics ().getHeight (); + int attributeFontSize = this.currentFontSize * 5 / 6; + graph.setFont(font.deriveFont((float) attributeFontSize)); + int step = graph.getFontMetrics().getHeight(); h += textY1; // Attributes - limitAttr = limitName; - for (TAttribute attr: this.myAttributes) { + limitAttr = limitName; + for (TAttribute attr : this.myAttributes) { h += step; if (h >= this.height - textX) { this.limitAttr = this.y + this.height; @@ -329,22 +328,22 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } // Get the string for this parameter - String attrString = attr.toAvatarString (); + String attrString = attr.toAvatarString(); // Try to draw it - w = graph.getFontMetrics ().stringWidth (attrString); - if (w + 2*textX < this.width) { - graph.drawString (attrString, this.x + textX, this.y + h); - this.drawConfidentialityVerification (attr.getConfidentialityVerification (), graph, this.x, this.y + h); + w = graph.getFontMetrics().stringWidth(attrString); + if (w + 2 * textX < this.width) { + graph.drawString(attrString, this.x + textX, this.y + h); + this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h); } else { // If we can't, try to draw with "..." instead int stringLength; - for (stringLength = attrString.length ()-1; stringLength >= 0; stringLength--) { - String abbrev = attrString.substring (0, stringLength) + "..."; - w = graph.getFontMetrics ().stringWidth (abbrev); - if (w + 2*textX < this.width) { - graph.drawString (abbrev, this.x + textX, this.y + h); - this.drawConfidentialityVerification (attr.getConfidentialityVerification (), graph, this.x, this.y + h); + for (stringLength = attrString.length() - 1; stringLength >= 0; stringLength--) { + String abbrev = attrString.substring(0, stringLength) + "..."; + w = graph.getFontMetrics().stringWidth(abbrev); + if (w + 2 * textX < this.width) { + graph.drawString(abbrev, this.x + textX, this.y + h); + this.drawConfidentialityVerification(attr.getConfidentialityVerification(), graph, this.x, this.y + h); break; } } @@ -355,7 +354,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } } - h += graph.getFontMetrics ().getDescent () + textY1; + h += graph.getFontMetrics().getDescent() + textY1; // Remember the end of attributes this.limitAttr = this.y + h; @@ -363,34 +362,34 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S if (h + textY1 >= this.height) return; - graph.drawLine (this.x, this.y+h, this.x+this.width, this.y+h); + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); h += textY1; // Methods - limitMethod = limitAttr; - limitSignal = limitAttr; - for (AvatarMethod method: this.myMethods) { + limitMethod = limitAttr; + limitSignal = limitAttr; + for (AvatarMethod method : this.myMethods) { h += step; if (h >= this.height - textX) { this.limitMethod = this.y + this.height; - this.limitSignal = limitMethod; + this.limitSignal = limitMethod; return; } // Get the string for this method - String methodString = "- " + method.toString (); + String methodString = "- " + method.toString(); - w = graph.getFontMetrics ().stringWidth (methodString); - if (w + 2*textX < this.width) - graph.drawString (methodString, this.x + textX, this.y + h); + w = graph.getFontMetrics().stringWidth(methodString); + if (w + 2 * textX < this.width) + graph.drawString(methodString, this.x + textX, this.y + h); else { // If we can't, try to draw with "..." instead int stringLength; - for (stringLength = methodString.length ()-1; stringLength >= 0; stringLength--) { - String abbrev = methodString.substring (0, stringLength) + "..."; - w = graph.getFontMetrics ().stringWidth (abbrev); - if (w + 2*textX < this.width) { - graph.drawString (abbrev, this.x + textX, this.y + h); + for (stringLength = methodString.length() - 1; stringLength >= 0; stringLength--) { + String abbrev = methodString.substring(0, stringLength) + "..."; + w = graph.getFontMetrics().stringWidth(abbrev); + if (w + 2 * textX < this.width) { + graph.drawString(abbrev, this.x + textX, this.y + h); break; } } @@ -401,47 +400,46 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } } - h += graph.getFontMetrics ().getDescent () + textY1; + h += graph.getFontMetrics().getDescent() + textY1; if (h + textY1 >= this.height) { - limitMethod = this.y + this.height; - limitSignal = this.y + this.height; + limitMethod = this.y + this.height; + limitSignal = this.y + this.height; return; - } + } - // Remember limit of methods + // Remember limit of methods this.limitMethod = this.y + h; - this.limitSignal = this.y + h; + this.limitSignal = this.y + h; - graph.drawLine (this.x, this.y+h, this.x+this.width, this.y+h); + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); h += textY1; // Signals - for (AvatarSignal signal: this.mySignals) { + for (AvatarSignal signal : this.mySignals) { h += step; if (h >= this.height - textX) { - limitSignal = this.height + this.y; + limitSignal = this.height + this.y; return; - } - - String signalString = "~ " + signal.toString (); - w = graph.getFontMetrics ().stringWidth (signalString); - if (w + 2*textX < this.width) { - graph.drawString (signalString, this.x + textX, this.y + h); - drawInfoAttachement(signal, graph, x, y+h); - - } - else { + } + + String signalString = "~ " + signal.toString(); + w = graph.getFontMetrics().stringWidth(signalString); + if (w + 2 * textX < this.width) { + graph.drawString(signalString, this.x + textX, this.y + h); + drawInfoAttachement(signal, graph, x, y + h); + + } else { // If we can't, try to draw with "..." instead int stringLength; - for (stringLength = signalString.length ()-1; stringLength >= 0; stringLength--) { - String abbrev = signalString.substring (0, stringLength) + "..."; - w = graph.getFontMetrics ().stringWidth (abbrev); - if (w + 2*textX < this.width) { - graph.drawString (abbrev, this.x + textX, this.y + h); - drawInfoAttachement(signal, graph, x, y+h); - - + for (stringLength = signalString.length() - 1; stringLength >= 0; stringLength--) { + String abbrev = signalString.substring(0, stringLength) + "..."; + w = graph.getFontMetrics().stringWidth(abbrev); + if (w + 2 * textX < this.width) { + graph.drawString(abbrev, this.x + textX, this.y + h); + drawInfoAttachement(signal, graph, x, y + h); + + break; } } @@ -452,83 +450,83 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } } - h += graph.getFontMetrics ().getDescent () + textY1; + h += graph.getFontMetrics().getDescent() + textY1; if (h + textY1 >= this.height) { - limitSignal = this.height + this.y; + limitSignal = this.height + this.y; return; - } + } // Global code - limitSignal = this.y+h; + limitSignal = this.y + h; if (hasGlobalCode()) { - if (h+textY1+step >= this.height - textX) + if (h + textY1 + step >= this.height - textX) return; - graph.drawLine (this.x, this.y+h, this.x+this.width, this.y+h); - h += textY1+step; - - w = graph.getFontMetrics ().stringWidth (GLOBAL_CODE_INFO); - if (w + 2*textX < this.width) - graph.drawString (GLOBAL_CODE_INFO, this.x + (this.width - w)/2, this.y + h); + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); + h += textY1 + step; + + w = graph.getFontMetrics().stringWidth(GLOBAL_CODE_INFO); + if (w + 2 * textX < this.width) + graph.drawString(GLOBAL_CODE_INFO, this.x + (this.width - w) / 2, this.y + h); } else { - limitSignal = height; - } + limitSignal = height; + } } - private void drawInfoAttachement(AvatarSignal _as, Graphics g, int _x, int _y) { - if (_as.attachedToARelation) { - return; - } - Color c = g.getColor(); - g.setColor(Color.RED); - int []xA = new int[3]; - int []yA = new int[3]; - //top of triangle - xA[0] = _x + 5; - yA[0] = _y - 7; - - // Right bottom point - xA[1] = _x + 2; - yA[1] = _y; + private void drawInfoAttachement(AvatarSignal _as, Graphics g, int _x, int _y) { + if (_as.attachedToARelation) { + return; + } + Color c = g.getColor(); + g.setColor(Color.RED); + int[] xA = new int[3]; + int[] yA = new int[3]; + //top of triangle + xA[0] = _x + 5; + yA[0] = _y - 7; + + // Right bottom point + xA[1] = _x + 2; + yA[1] = _y; - // Left bottom point - xA[2] = _x + 8; - yA[2] = _y; + // Left bottom point + xA[2] = _x + 8; + yA[2] = _y; - g.fillPolygon(xA, yA, 3); + g.fillPolygon(xA, yA, 3); - g.setColor(c); + g.setColor(c); } private void drawConfidentialityVerification(int confidentialityVerification, Graphics g, int _x, int _y) { Color c = g.getColor(); Color c1; - int xc=(int)(6*tdp.getZoom()); - int yc=(int)(10*tdp.getZoom()); - int lockwidth=(int) (9*tdp.getZoom()); - int lockheight=(int) (7*tdp.getZoom()); - int ovalwidth=(int) (6*tdp.getZoom()); - int ovalheight=(int) (9*tdp.getZoom()); - switch(confidentialityVerification) { - case TAttribute.CONFIDENTIALITY_OK: - c1 = Color.green; - break; - case TAttribute.CONFIDENTIALITY_KO: - c1 = Color.red; - break; - case TAttribute.COULD_NOT_VERIFY_CONFIDENTIALITY: - c1 = Color.orange; - break; - default: - return; + int xc = (int) (6 * tdp.getZoom()); + int yc = (int) (10 * tdp.getZoom()); + int lockwidth = (int) (9 * tdp.getZoom()); + int lockheight = (int) (7 * tdp.getZoom()); + int ovalwidth = (int) (6 * tdp.getZoom()); + int ovalheight = (int) (9 * tdp.getZoom()); + switch (confidentialityVerification) { + case TAttribute.CONFIDENTIALITY_OK: + c1 = Color.green; + break; + case TAttribute.CONFIDENTIALITY_KO: + c1 = Color.red; + break; + case TAttribute.COULD_NOT_VERIFY_CONFIDENTIALITY: + c1 = Color.orange; + break; + default: + return; } - g.drawOval(_x+xc, _y-yc, ovalwidth, ovalheight); + g.drawOval(_x + xc, _y - yc, ovalwidth, ovalheight); g.setColor(c1); - g.fillRect(_x+xc*2/3, _y-yc*2/3, lockwidth, lockheight); + g.fillRect(_x + xc * 2 / 3, _y - yc * 2 / 3, lockwidth, lockheight); g.setColor(c); - g.drawRect(_x+xc*2/3, _y-yc*2/3, lockwidth, lockheight); + g.drawRect(_x + xc * 2 / 3, _y - yc * 2 / 3, lockwidth, lockheight); } @@ -550,11 +548,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S return name; } - public String getFullyQualifiedName() - { + public String getFullyQualifiedName() { String result = ""; - if (this.father != null && (this.father instanceof AvatarBDBlock)) - { + if (this.father != null && (this.father instanceof AvatarBDBlock)) { result = ((AvatarBDBlock) this.father).getFullyQualifiedName() + "."; } result += this.value; @@ -563,39 +559,39 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } public boolean editOndoubleClick(JFrame frame, int _x, int _y) { - int textX = (int) (this.textX * this.tdp.getZoom ()); + int textX = (int) (this.textX * this.tdp.getZoom()); if (iconIsDrawn) { if (GraphicLib.isInRectangle(_x, _y, x + width - iconSize - textX, y + textX, iconSize, iconSize)) { - tdp.getMouseManager().setSelection(-1, -1); + tdp.getMouseManager().setSelection(-1, -1); tdp.selectTab(getValue()); return true; } } // On the name ? - if ((limitName == -1 && _y <= y + 2*currentFontSize) || _y < limitName) { + if ((limitName == -1 && _y <= y + 2 * currentFontSize) || _y < limitName) { oldValue = value; //String text = getName() + ": "; - String s = (String)JOptionPane.showInputDialog(frame, "Block name", - "setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, - null, - getValue()); + String s = (String) JOptionPane.showInputDialog(frame, "Block name", + "setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, + null, + getValue()); if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { //boolean b; if (!TAttribute.isAValidId(s, false, false)) { JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: the new name is not a valid name", - "Error", - JOptionPane.INFORMATION_MESSAGE); + "Could not change the name of the Block: the new name is not a valid name", + "Error", + JOptionPane.INFORMATION_MESSAGE); return false; } if (!tdp.isAvatarBlockNameUnique(s)) { JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: the new name is already in use", - "Error", - JOptionPane.INFORMATION_MESSAGE); + "Could not change the name of the Block: the new name is already in use", + "Error", + JOptionPane.INFORMATION_MESSAGE); return false; } @@ -606,9 +602,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S return true; } else { JOptionPane.showMessageDialog(frame, - "Could not change the name of the Block: frame error", - "Error", - JOptionPane.INFORMATION_MESSAGE); + "Could not change the name of the Block: frame error", + "Error", + JOptionPane.INFORMATION_MESSAGE); setValue(oldValue); } } @@ -616,34 +612,34 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } // And so -> attributes! - + int tab = 0; - //TraceManager.addDev("limitAttr=" + limitAttr + " method=" + limitMethod + " limitSignal=" + limitSignal + " y=" + _y + " height=" + height); + //TraceManager.addDev("limitAttr=" + limitAttr + " method=" + limitMethod + " limitSignal=" + limitSignal + " y=" + _y + " height=" + height); - if (limitMethod == -1) { - limitMethod = limitAttr; - } + if (limitMethod == -1) { + limitMethod = limitAttr; + } - if (limitSignal == -1) { - limitSignal = limitMethod; - } - - if (limitAttr == -1) { - tab = 0; - } else { - if (_y < limitAttr) { - tab = 0; - } else if (_y < limitMethod){ - tab = 1; - } else if (_y < limitSignal) { - tab = 2; - } else if (_y > limitSignal && hasGlobalCode()) { - tab = 3; - } else if (_y > limitSignal && !hasGlobalCode()) { - tab = 2; - } - } + if (limitSignal == -1) { + limitSignal = limitMethod; + } + + if (limitAttr == -1) { + tab = 0; + } else { + if (_y < limitAttr) { + tab = 0; + } else if (_y < limitMethod) { + tab = 1; + } else if (_y < limitSignal) { + tab = 2; + } else if (_y > limitSignal && hasGlobalCode()) { + tab = 3; + } else if (_y > limitSignal && !hasGlobalCode()) { + tab = 2; + } + } /*if (limitAttr != -1) { if (_y > limitAttr) { @@ -669,7 +665,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S String mainCode = null; TDiagramPanel ttdp = getTDiagramPanel(); if (ttdp instanceof AvatarBDPanel) { - mainCode = ((AvatarBDPanel)(ttdp)).getMainCode(); + mainCode = ((AvatarBDPanel) (ttdp)).getMainCode(); } JDialogAvatarBlock jdab = new JDialogAvatarBlock(this.myAttributes, this.myMethods, this.mySignals, null, frame, "Setting attributes of " + value, "Attribute", tab, globalCode, true, mainCode); setJDialogOptions(jdab); @@ -685,11 +681,11 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S globalCode = jdab.getGlobalCode(); String tmp = jdab.getMainCode(); if (tmp != null) { - ((AvatarBDPanel)(ttdp)).setMainCode(tmp); + ((AvatarBDPanel) (ttdp)).setMainCode(tmp); } } - ((AvatarBDPanel)tdp).updateAllSignalsOnConnectors(); + ((AvatarBDPanel) tdp).updateAllSignalsOnConnectors(); rescaled = true; return true; } @@ -702,7 +698,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S _jdab.addType(TAttribute.getStringAvatarType(TAttribute.INTEGER), true); _jdab.addType(TAttribute.getStringType(TAttribute.TIMER), false); - for(String s: tdp.getAllDataTypes()) { + for (String s : tdp.getAllDataTypes()) { _jdab.addType(s, false); } @@ -725,11 +721,11 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S public boolean addSwallowedTGComponent(TGComponent tgc, int x, int y) { boolean swallowed = false; - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof SwallowTGComponent) { if (tgcomponent[i].isOnMe(x, y) != null) { swallowed = true; - ((SwallowTGComponent)tgcomponent[i]).addSwallowedTGComponent(tgc, x, y); + ((SwallowTGComponent) tgcomponent[i]).addSwallowedTGComponent(tgc, x, y); break; } } @@ -758,10 +754,8 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S tgc.resizeWithFather(); //tgc.setCdRectangle(0, width - tgc.getWidth(), 0, height - tgc.getHeight()); //tgc.setCd(x, y); - } - - else if (tgc instanceof AvatarBDLibraryFunction) - tgc.resizeWithFather (); + } else if (tgc instanceof AvatarBDLibraryFunction) + tgc.resizeWithFather(); // else unknown*/ @@ -777,19 +771,19 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S public boolean removeMyInternalComponent(TGComponent tgc, boolean actionOnRemove) { //TGComponent tgc; - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] == tgc) { nbInternalTGComponent = nbInternalTGComponent - 1; if (nbInternalTGComponent == 0) { tgcomponent = null; } else { - TGComponent [] tgcomponentbis = new TGComponent[nbInternalTGComponent]; - for(int j=0; j<nbInternalTGComponent; j++) { - if (j<i) { + TGComponent[] tgcomponentbis = new TGComponent[nbInternalTGComponent]; + for (int j = 0; j < nbInternalTGComponent; j++) { + if (j < i) { tgcomponentbis[j] = tgcomponent[j]; } - if (j>=i) { - tgcomponentbis[j] = tgcomponent[j+1]; + if (j >= i) { + tgcomponentbis[j] = tgcomponent[j + 1]; } } tgcomponent = tgcomponentbis; @@ -800,7 +794,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } return true; } else { - if (((AvatarBDBlock)tgcomponent[i]).removeMyInternalComponent(tgc, false)) { + if (((AvatarBDBlock) tgcomponent[i]).removeMyInternalComponent(tgc, false)) { return true; } } @@ -811,7 +805,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S protected String translateExtraParam() { StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<CryptoBlock value=\"" + isCryptoBlock + "\" />\n"); - for (TAttribute a: this.myAttributes) { + for (TAttribute a : this.myAttributes) { sb.append("<Attribute access=\""); sb.append(a.getAccess()); sb.append("\" id=\""); @@ -824,20 +818,20 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S sb.append(a.getTypeOther()); sb.append("\" />\n"); } - for (AvatarMethod am: this.myMethods) { + for (AvatarMethod am : this.myMethods) { sb.append("<Method value=\""); sb.append(am.toSaveString()); sb.append("\" />\n"); } - for (AvatarSignal as: this.mySignals) { + for (AvatarSignal as : this.mySignals) { sb.append("<Signal value=\""); sb.append(as.toString()); - sb.append("\" attached=\""); - sb.append(as.attachedToARelation); + sb.append("\" attached=\""); + sb.append(as.attachedToARelation); sb.append("\" />\n"); } if (hasGlobalCode()) { - for(int i=0; i<globalCode.length; i++) { + for (int i = 0; i < globalCode.length; i++) { sb.append("<globalCode value=\""); sb.append(GTURTLEModeling.transformString(globalCode[i])); sb.append("\" />\n"); @@ -848,7 +842,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } @Override - public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { String s; String tmpGlobalCode = ""; @@ -867,21 +861,21 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S boolean implementation = false; String crypt; String attached; - //boolean mustAddCryptoFunctions = false; + //boolean mustAddCryptoFunctions = false; //System.out.println("Loading attributes"); //System.out.println(nl.toString()); - //TraceManager.addDev("LEP Begin Block = " + this + " trace="); - //Thread.currentThread().dumpStack(); + //TraceManager.addDev("LEP Begin Block = " + this + " trace="); + //Thread.currentThread().dumpStack(); - for(int i=0; i<nl.getLength(); i++) { + for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); //System.out.println(n1); if (n1.getNodeType() == Node.ELEMENT_NODE) { nli = n1.getChildNodes(); - for(int j=0; j<nli.getLength(); j++) { + for (int j = 0; j < nli.getLength(); j++) { n2 = nli.item(j); //System.out.println(n2); if (n2.getNodeType() == Node.ELEMENT_NODE) { @@ -914,7 +908,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } TAttribute ta = new TAttribute(access, id, valueAtt, type, typeOther); ta.isAvatar = true; - this.myAttributes.add (ta); + this.myAttributes.add(ta); } } if (elt.getTagName().equals("Method")) { @@ -931,25 +925,25 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S implementation = false; } - //TraceManager.addDev("Method = " + method + ". Starting with aencrypt?"); + //TraceManager.addDev("Method = " + method + ". Starting with aencrypt?"); if (method.startsWith("bool verifyMAC(")) { isCryptoBlock = true; - //TraceManager.addDev("Add crypto methods"); - //addCryptoElements(); + //TraceManager.addDev("Add crypto methods"); + //addCryptoElements(); } am = AvatarMethod.isAValidMethod(method); if (am != null) { //TraceManager.addDev("Setting to " + implementation + " the implementation of " + am); am.setImplementationProvided(implementation); - //addMethodIfApplicable(am); + //addMethodIfApplicable(am); this.myMethods.add(am); } } if (elt.getTagName().equals("Signal")) { //System.out.println("Analyzing attribute"); signal = elt.getAttribute("value"); - attached = elt.getAttribute("attached"); + attached = elt.getAttribute("attached"); if (signal.equals("null")) { signal = ""; @@ -957,9 +951,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S as = AvatarSignal.isAValidSignal(signal); if (as != null) { this.mySignals.add(as); - if (attached != null) { - as.attachedToARelation = (attached.compareTo("true") == 0); - } + if (attached != null) { + as.attachedToARelation = (attached.compareTo("true") == 0); + } } else { TraceManager.addDev("Invalid signal:" + signal); } @@ -980,20 +974,20 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } catch (Exception e) { throw new MalformedModelingException(); } - - if (isCryptoBlock()) { - addCryptoElements(); - } + + if (isCryptoBlock()) { + addCryptoElements(); + } if (tmpGlobalCode.trim().length() == 0) { globalCode = null; } else { globalCode = Conversion.wrapText(tmpGlobalCode); } - - //TraceManager.addDev("LEP End Block = " + this); - + + //TraceManager.addDev("LEP End Block = " + this); + } public String getBlockName() { @@ -1010,9 +1004,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } String tmp; - for(int i=0; i<globalCode.length; i++) { + for (int i = 0; i < globalCode.length; i++) { tmp = globalCode[i].trim(); - if (tmp.length()>0) { + if (tmp.length() > 0) { if (!(tmp.equals("\n"))) { return true; } @@ -1027,20 +1021,18 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S return null; } String ret = ""; - for(int i=0; i<globalCode.length; i++) { + for (int i = 0; i < globalCode.length; i++) { ret += globalCode[i] + "\n"; } return ret; } - public void hasBeenResized() { - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof AvatarBDBlock) { tgcomponent[i].resizeWithFather(); - } - else if (tgcomponent[i] instanceof AvatarBDLibraryFunction) { + } else if (tgcomponent[i] instanceof AvatarBDLibraryFunction) { tgcomponent[i].resizeWithFather(); } } @@ -1063,9 +1055,9 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S public LinkedList<AvatarBDBlock> getBlockList() { LinkedList<AvatarBDBlock> list = new LinkedList<AvatarBDBlock>(); - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof AvatarBDBlock) { - list.add((AvatarBDBlock)(tgcomponent[i])); + list.add((AvatarBDBlock) (tgcomponent[i])); } } return list; @@ -1073,21 +1065,20 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S public LinkedList<AvatarBDBlock> getFullBlockList() { LinkedList<AvatarBDBlock> list = new LinkedList<AvatarBDBlock>(); - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] instanceof AvatarBDBlock) { - list.add((AvatarBDBlock)(tgcomponent[i])); - list.addAll(((AvatarBDBlock)tgcomponent[i]).getFullBlockList()); + list.add((AvatarBDBlock) (tgcomponent[i])); + list.addAll(((AvatarBDBlock) tgcomponent[i]).getFullBlockList()); } } return list; } - public LinkedList<AvatarBDLibraryFunction> getFullLibraryFunctionList () { - LinkedList<AvatarBDLibraryFunction> list = new LinkedList<AvatarBDLibraryFunction> (); - for (int i=0; i<nbInternalTGComponent; i++) - { + public LinkedList<AvatarBDLibraryFunction> getFullLibraryFunctionList() { + LinkedList<AvatarBDLibraryFunction> list = new LinkedList<AvatarBDLibraryFunction>(); + for (int i = 0; i < nbInternalTGComponent; i++) { if (this.tgcomponent[i] instanceof AvatarBDLibraryFunction) - list.add ((AvatarBDLibraryFunction) this.tgcomponent[i]); + list.add((AvatarBDLibraryFunction) this.tgcomponent[i]); else if (this.tgcomponent[i] instanceof AvatarBDBlock) list.addAll(((AvatarBDBlock) this.tgcomponent[i]).getFullLibraryFunctionList()); } @@ -1096,15 +1087,15 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } public boolean hasInternalBlockWithName(String name) { - LinkedList<AvatarBDBlock> list = getFullBlockList(); - for(AvatarBDBlock b: list) { - if (b.getValue().compareTo(name) ==0) { + LinkedList<AvatarBDBlock> list = getFullBlockList(); + for (AvatarBDBlock b : list) { + if (b.getValue().compareTo(name) == 0) { return true; } } - LinkedList<AvatarBDLibraryFunction> llist = getFullLibraryFunctionList (); - for(AvatarBDLibraryFunction b: llist) { - if (b.getFunctionName().compareTo(name) ==0) { + LinkedList<AvatarBDLibraryFunction> llist = getFullLibraryFunctionList(); + for (AvatarBDLibraryFunction b : llist) { + if (b.getFunctionName().compareTo(name) == 0) { return true; } } @@ -1113,7 +1104,6 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } - public int getDefaultConnector() { return TGComponentManager.AVATARBD_PORT_CONNECTOR; } @@ -1123,13 +1113,14 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } public TAttribute getAttributeByName(String _name) { - for (TAttribute a: this.myAttributes) + for (TAttribute a : this.myAttributes) if (a.getId().compareTo(_name) == 0) return a; return null; } - public void addAttribute(TAttribute ta){ - this.myAttributes.add(ta); + + public void addAttribute(TAttribute ta) { + this.myAttributes.add(ta); } public LinkedList<AvatarMethod> getMethodList() { @@ -1141,16 +1132,16 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } public LinkedList<AvatarSignal> getOutSignalList() { - LinkedList<AvatarSignal> v = new LinkedList<AvatarSignal> (); - for(AvatarSignal s: this.mySignals) + LinkedList<AvatarSignal> v = new LinkedList<AvatarSignal>(); + for (AvatarSignal s : this.mySignals) if (s.getInOut() == AvatarSignal.OUT) v.add(s); return v; } public LinkedList<AvatarSignal> getInSignalList() { - LinkedList<AvatarSignal> v = new LinkedList<AvatarSignal> (); - for(AvatarSignal s: this.mySignals) + LinkedList<AvatarSignal> v = new LinkedList<AvatarSignal>(); + for (AvatarSignal s : this.mySignals) if (s.getInOut() == AvatarSignal.IN) v.add(s); return v; @@ -1161,7 +1152,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S return this.myMethods; } - LinkedList<AvatarMethod> v = new LinkedList<AvatarMethod> (); + LinkedList<AvatarMethod> v = new LinkedList<AvatarMethod>(); v.addAll(this.myMethods); v.addAll(((AvatarBDBlock) getFather()).getAllMethodList()); return v; @@ -1172,38 +1163,38 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S return this.mySignals; } - LinkedList<AvatarSignal> v = new LinkedList<AvatarSignal> (); + LinkedList<AvatarSignal> v = new LinkedList<AvatarSignal>(); v.addAll(this.mySignals); - v.addAll(((AvatarBDBlock)getFather()).getAllSignalList()); + v.addAll(((AvatarBDBlock) getFather()).getAllSignalList()); return v; } public LinkedList<String> getAllTimerList() { - LinkedList<String> v = new LinkedList<String> (); + LinkedList<String> v = new LinkedList<String>(); - for (TAttribute a: this.myAttributes) + for (TAttribute a : this.myAttributes) if (a.getType() == TAttribute.TIMER) v.add(a.getId()); return v; } public AvatarSignal getAvatarSignalFromName(String _name) { - for (AvatarSignal as: this.mySignals) + for (AvatarSignal as : this.mySignals) if (as.getId().compareTo(_name) == 0) return as; return null; } public LinkedList<AvatarSignal> getListOfAvailableSignals() { - return ((AvatarBDPanel)(tdp)).getListOfAvailableSignals(this); + return ((AvatarBDPanel) (tdp)).getListOfAvailableSignals(this); } public LinkedList<AvatarSignal> getListOfAvailableOutSignals() { - return ((AvatarBDPanel)(tdp)).getListOfAvailableOutSignals(this); + return ((AvatarBDPanel) (tdp)).getListOfAvailableOutSignals(this); } public LinkedList<AvatarSignal> getListOfAvailableInSignals() { - return ((AvatarBDPanel)(tdp)).getListOfAvailableInSignals(this); + return ((AvatarBDPanel) (tdp)).getListOfAvailableInSignals(this); } @@ -1215,28 +1206,28 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } _id = _id.trim(); //TraceManager.addDev("Searching for signal with id=" + _id); - for (AvatarSignal as: this.mySignals){ - // System.out.println(as.getId() + " " + for (AvatarSignal as : this.mySignals) { + // System.out.println(as.getId() + " " if (as.getId().compareTo(_id) == 0) return as; - } + } //TraceManager.addDev("Not found"); return null; } public AvatarSignal getAvatarSignalFromFullName(String _id) { - if(_id.startsWith("in ")) { + if (_id.startsWith("in ")) { return getSignalNameBySignalDef(_id.substring(3, _id.length()).trim()); } - if(_id.startsWith("out ")) { + if (_id.startsWith("out ")) { return getSignalNameBySignalDef(_id.substring(4, _id.length()).trim()); } return null; } public AvatarSMDPanel getAvatarSMDPanel() { - return ((AvatarDesignPanel)(tdp.tp)).getAvatarSMDPanel(getBlockName()); + return ((AvatarDesignPanel) (tdp.tp)).getAvatarSMDPanel(getBlockName()); } public boolean isCryptoBlock() { @@ -1246,42 +1237,42 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S public void removeCryptoElements() { isCryptoBlock = false; - for (String method: AvatarMethod.cryptoMethods) - this.removeMethodIfApplicable (method); + for (String method : AvatarMethod.cryptoMethods) + this.removeMethodIfApplicable(method); } public void addCryptoElements() { isCryptoBlock = true; - for (String method: AvatarMethod.cryptoMethods) - this.addMethodIfApplicable (method); + for (String method : AvatarMethod.cryptoMethods) + this.addMethodIfApplicable(method); } private void removeMethodIfApplicable(String methodString) { - Iterator<AvatarMethod> iterator = this.myMethods.iterator (); - while (iterator.hasNext ()) { - AvatarMethod am = iterator.next (); + 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 (); + if (am.toString().equals(methodString)) { + iterator.remove(); break; } } } - public void addMethodIfApplicable (String methodString) { - for (AvatarMethod am: this.myMethods) + public void addMethodIfApplicable(String methodString) { + for (AvatarMethod am : this.myMethods) // TODO: replace by a more OO way... - if (am.toString ().equals (methodString)) - return; + if (am.toString().equals(methodString)) + return; - AvatarMethod am = AvatarMethod.isAValidMethod (methodString); + AvatarMethod am = AvatarMethod.isAValidMethod(methodString); if (am != null) - this.myMethods.add (am); + this.myMethods.add(am); } public boolean hasDefinitions() { - return ((this.myAttributes.size() + this.myMethods.size() + this.mySignals.size() + nbInternalTGComponent)>0); + return ((this.myAttributes.size() + this.myMethods.size() + this.mySignals.size() + nbInternalTGComponent) > 0); } // Main Tree @@ -1317,7 +1308,7 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S public int getIndexOfChild(Object child) { if (child instanceof AvatarBDBlock) { - for(int i=0; i<nbInternalTGComponent; i++) { + for (int i = 0; i < nbInternalTGComponent; i++) { if (tgcomponent[i] == child) { return i; } @@ -1344,17 +1335,17 @@ public class AvatarBDBlock extends TGCScalableWithInternalComponent implements S } public void resetConfidentialityOfAttributes() { - for (TAttribute a: this.myAttributes) + for (TAttribute a : this.myAttributes) a.setConfidentialityVerification(TAttribute.NOT_VERIFIED); } @Override - public String getOwnerName () { - return this.getBlockName (); + public String getOwnerName() { + return this.getBlockName(); } - + public String toString() { - return "Block: " + getValue(); + return "Block: " + getValue(); } - + } diff --git a/src/main/java/ui/ftd/FTDConstraint.java b/src/main/java/ui/ftd/FTDConstraint.java index a66f86098012594be43174b08ebc13510f9fa4a7..adaf5d2510f6e06b551b6e836e48f7a1bbd38904 100644 --- a/src/main/java/ui/ftd/FTDConstraint.java +++ b/src/main/java/ui/ftd/FTDConstraint.java @@ -1,26 +1,26 @@ /* 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, @@ -31,14 +31,12 @@ * 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.ftd; import myutil.GraphicLib; @@ -51,19 +49,25 @@ import ui.window.JDialogConstraintText; import javax.swing.*; import java.awt.*; +import myutil.*;; /** - * Class FTDConstraint - * Constraint of SysML Parametric diagrams, adapted to fault trees - * Creation: 14/12/2017 - * @version 1.0 14/12/2017 - * @author Ludovic APVRILLE + * Class FTDConstraint + * Constraint of SysML Parametric diagrams, adapted to fault trees + * Creation: 14/12/2017 + * + * @author Ludovic APVRILLE + * @version 1.0 14/12/2017 */ -public class FTDConstraint extends TGCScalableWithInternalComponent implements SwallowedTGComponent, ConstraintListInterface { +public class FTDConstraint extends TGCScalableWithInternalComponent implements SwallowedTGComponent, ConstraintListInterface { private int textY1 = 5; //private int textY2 = 30; - public static final String[] STEREOTYPES = {"<<OR>>", "<<XOR>>", "<<AND>>", "<<NOT>>", "<<SEQUENCE>>", "<<AFTER>>", "<<BEFORE>>", "<<VOTE>>"}; + public static final String[] STEREOTYPES = {"<<OR>>", "<<XOR>>", "<<AND>>", "<<NOT>>", "<<SEQUENCE>>", "<<AFTER>>", + "<<BEFORE>>", "<<VOTE>>"}; + public static final Image[] ICONS = {IconManager.img1400, IconManager.img1400, IconManager.img1400, + IconManager.img1408, IconManager.img1402, IconManager.img1404 + , IconManager.img1406, IconManager.img1400}; protected String oldValue = ""; @@ -71,17 +75,19 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements private static int minFontSize = 4; private int currentFontSize = -1; private boolean displayText = true; - // private int textX = 1; + // private int textX = 1; private static int arc = 7; + private int index; + private String equation; - public FTDConstraint(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + public FTDConstraint(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); - width = (int)(150* tdp.getZoom()); - height = (int)(50 * tdp.getZoom()); + width = (int) (150 * tdp.getZoom()); + height = (int) (50 * tdp.getZoom()); minWidth = 100; nbConnectingPoint = 12; @@ -106,6 +112,7 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements removable = true; value = "<<OR>>"; + index = 0; equation = ""; currentFontSize = -1; @@ -117,7 +124,7 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements public void internalDrawing(Graphics g) { Font f = g.getFont(); - // Font fold = f; + // Font fold = f; if (currentFontSize == -1) { currentFontSize = f.getSize(); @@ -127,9 +134,9 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements rescaled = false; - float scale = (float)(f.getSize()*tdp.getZoom()); + float scale = (float) (f.getSize() * tdp.getZoom()); scale = Math.min(maxFontSize, scale); - currentFontSize = (int)scale; + currentFontSize = (int) scale; displayText = !(scale < minFontSize); } @@ -145,25 +152,33 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements g.setColor(c); + if (height > (IconManager.iconSize * 2 + 10)) { + g.drawImage(ICONS[index], this.x + this.width - IconManager.iconSize * 2 - 6, this.y + 10, null); + } + Font f0 = g.getFont(); if (displayText) { f = f.deriveFont(currentFontSize); g.setFont(f.deriveFont(Font.BOLD)); - int w = g.getFontMetrics().stringWidth(value); - g.drawString(value, x + (width - w)/2, y + currentFontSize + (int)(textY1*tdp.getZoom())); - g.setFont(f0.deriveFont(f0.getSize()-2).deriveFont(Font.ITALIC)); - w = g.getFontMetrics().stringWidth(equation); + int w = g.getFontMetrics().stringWidth(value); + g.drawString(value, x + (width - w) / 2, y + currentFontSize + (int) (textY1 * tdp.getZoom())); + + + g.setFont(f0.deriveFont(f0.getSize() - 2).deriveFont(Font.ITALIC)); + w = g.getFontMetrics().stringWidth(equation); if (w >= width) { - w = g.getFontMetrics().stringWidth("..."); - g.drawString("...", x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); + w = g.getFontMetrics().stringWidth("..."); + g.drawString("...", x + (width - w) / 2, y + (2 * currentFontSize) + (int) (textY1 * tdp.getZoom())); } else { - g.drawString(equation, x + (width - w)/2, y + (2*currentFontSize) + (int)(textY1*tdp.getZoom())); + g.drawString(equation, x + (width - w) / 2, y + (2 * currentFontSize) + (int) (textY1 * tdp.getZoom())); } g.setFont(f0); } } + + /* public void setValue(String val, Graphics g) { oldValue = value; int w = g.getFontMetrics().stringWidth(value); @@ -178,16 +193,14 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements }*/ - - public boolean editOndoubleClick(JFrame frame) { // String tmp; // boolean error = false; JDialogConstraintText dialog = new JDialogConstraintText(frame, "Setting constraint attributes", this, equation, "Equation"); - // dialog.setSize(450, 350); + // dialog.setSize(450, 350); GraphicLib.centerOnParent(dialog, 450, 350); - dialog.setVisible( true ); // blocked until dialog has been closed + dialog.setVisible(true); // blocked until dialog has been closed if (!dialog.isRegularClose()) { return false; @@ -199,6 +212,7 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements if (dialog.getStereotype().length() > 0) { value = dialog.getStereotype(); + index = dialog.getSelectedIndex(); } equation = dialog.getText(); @@ -233,62 +247,67 @@ public class FTDConstraint extends TGCScalableWithInternalComponent implements } public boolean isOR() { - return (value.compareTo(STEREOTYPES[0]) == 0); + return (value.compareTo(STEREOTYPES[0]) == 0); } public boolean isXOR() { - return (value.compareTo(STEREOTYPES[1]) == 0); + return (value.compareTo(STEREOTYPES[1]) == 0); } public boolean isAND() { - return (value.compareTo(STEREOTYPES[2]) == 0); + return (value.compareTo(STEREOTYPES[2]) == 0); } public boolean isSequence() { - return (value.compareTo(STEREOTYPES[3]) == 0); + return (value.compareTo(STEREOTYPES[3]) == 0); } public boolean isBefore() { - return (value.compareTo(STEREOTYPES[4]) == 0); + return (value.compareTo(STEREOTYPES[4]) == 0); } public boolean isAfter() { - return (value.compareTo(STEREOTYPES[5]) == 0); + return (value.compareTo(STEREOTYPES[5]) == 0); } protected String translateExtraParam() { StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<info equation=\"" + GTURTLEModeling.transformString(getEquation())); + sb.append("\" index=\"" + GTURTLEModeling.transformString("" + index)); sb.append("\" />\n"); sb.append("</extraparam>\n"); return new String(sb); } @Override - public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException { //System.out.println("*** load extra synchro ***"); try { NodeList nli; Node n1, n2; Element elt; + String tmp; // int t1id; // String sdescription = null; // String prio; // String isRoot = null; - for(int i=0; i<nl.getLength(); i++) { + for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); //System.out.println(n1); if (n1.getNodeType() == Node.ELEMENT_NODE) { nli = n1.getChildNodes(); - for(int j=0; j<nli.getLength(); j++) { + for (int j = 0; j < nli.getLength(); j++) { n2 = nli.item(j); //System.out.println(n2); if (n2.getNodeType() == Node.ELEMENT_NODE) { elt = (Element) n2; if (elt.getTagName().equals("info")) { equation = elt.getAttribute("equation"); + tmp = elt.getAttribute("index"); + //TraceManager.addDev("index=" + tmp); + index = Integer.decode(tmp).intValue(); } } } diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index 04048501f66240b959970e592f38c4e701bcfdf3..20e7c6cd44140a73fce2b75f93a4774efc1c623b 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -119,6 +119,10 @@ public class IconManager { public static ImageIcon imgic1070, imgic1072, imgic1074, imgic1076, imgic1078; public static ImageIcon imgic1080, imgic1082, imgic1084; + // Fault Tree Diagrams + public static ImageIcon imgic1400, imgic1402, imgic1404, imgic1406, imgic1408; + public static Image img1400, img1402, img1404, img1406, img1408; + // TMLDD public static ImageIcon imgic1100, imgic1102, imgic1104, imgic1106, imgic1108; public static ImageIcon imgic1110, imgic1112, imgic1114, imgic1116, imgic1118; @@ -487,6 +491,13 @@ public class IconManager { private static String icon1082 = "atdcountermeasure.gif"; private static String icon1084 = "atdcountermeasureconnector.gif"; + // Fault trees + private static String icon1400 = "AndFT.png"; + private static String icon1402 = "SequenceFT.png"; + private static String icon1404 = "AfterFT.png"; + private static String icon1406 = "BeforeFT.png"; + private static String icon1408 = "NotFT.png"; + // DIPLODOCUS architecture private static String icon1100 = "tmlcpunode.gif"; private static String icon1102 = "tmlbusnode.gif"; @@ -624,9 +635,12 @@ public class IconManager { //Attacker Scenarios private static String icon7008 = "attacker.gif"; - private static String icon7009 = "uppaal.gif"; + // + + + public IconManager() { @@ -921,6 +935,26 @@ public class IconManager { imgic1082 = getIcon(icon1082); imgic1084 = getIcon(icon1084); + imgic1400 = getIcon(icon1400); + if (imgic1400 != null) { + img1400 = imgic1400.getImage(); + } + imgic1402 = getIcon(icon1402); + if (imgic1402 != null) { + img1402 = imgic1402.getImage(); + } + imgic1404 = getIcon(icon1404); + if (imgic1404 != null) { + img1404 = imgic1404.getImage(); + } + imgic1408 = getIcon(icon1408); + if (imgic1408 != null) { + img1408 = imgic1408.getImage(); + } + imgic1406 = getIcon(icon1406); + if (imgic1406 != null) { + img1406 = imgic1406.getImage(); + } imgic1100 = getIcon(icon1100); imgic1102 = getIcon(icon1102); imgic1104 = getIcon(icon1104); diff --git a/src/main/java/ui/window/JDialogConstraintText.java b/src/main/java/ui/window/JDialogConstraintText.java index d35d73e2d61f55a66e4c5340c622eda22f211178..52def0b2f771bc6aa84e8ea17ca90a07b9c03e7c 100755 --- a/src/main/java/ui/window/JDialogConstraintText.java +++ b/src/main/java/ui/window/JDialogConstraintText.java @@ -171,6 +171,10 @@ public class JDialogConstraintText extends JDialogBase implements ActionListener return (String)(stereotype.getSelectedItem()); } + public int getSelectedIndex() { + return stereotype.getSelectedIndex(); + } + public String getText() { return textEdition.getText(); diff --git a/src/main/resources/ui/util/AfterFT.png b/src/main/resources/ui/util/AfterFT.png new file mode 100644 index 0000000000000000000000000000000000000000..3f0d3d554143a170c3507679ee21bcbc559343ed Binary files /dev/null and b/src/main/resources/ui/util/AfterFT.png differ diff --git a/src/main/resources/ui/util/AndFT.png b/src/main/resources/ui/util/AndFT.png new file mode 100644 index 0000000000000000000000000000000000000000..7788cb863fca328ffebd3f69551893a2037b3d0f Binary files /dev/null and b/src/main/resources/ui/util/AndFT.png differ diff --git a/src/main/resources/ui/util/BeforeFT.png b/src/main/resources/ui/util/BeforeFT.png new file mode 100644 index 0000000000000000000000000000000000000000..5cec1eaac6dbf90e551169d96b148030e201aa53 Binary files /dev/null and b/src/main/resources/ui/util/BeforeFT.png differ diff --git a/src/main/resources/ui/util/NotFT.png b/src/main/resources/ui/util/NotFT.png new file mode 100644 index 0000000000000000000000000000000000000000..32468a26f41e805f964d21ab84e6ba5e42c2f94f Binary files /dev/null and b/src/main/resources/ui/util/NotFT.png differ diff --git a/src/main/resources/ui/util/SequenceFT.png b/src/main/resources/ui/util/SequenceFT.png new file mode 100644 index 0000000000000000000000000000000000000000..45f9d4beed5d4d7275870ff47b109debf9fd590f Binary files /dev/null and b/src/main/resources/ui/util/SequenceFT.png differ