From 6c5a34c25cd9744572091351cd066c3b1902c228 Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Wed, 3 Jul 2019 17:54:52 +0200 Subject: [PATCH] Adding attributes in blocks of context diag --- modeling/DIPLODOCUS/SmartCardProtocol.xml | 177 ------- src/main/java/ui/GeneralAttribute.java | 115 +++++ src/main/java/ui/avatarcd/AvatarCDBlock.java | 296 +++++++++++- .../ui/window/JDialogGeneralAttribute.java | 441 ++++++++++++++++++ 4 files changed, 843 insertions(+), 186 deletions(-) create mode 100644 src/main/java/ui/GeneralAttribute.java create mode 100644 src/main/java/ui/window/JDialogGeneralAttribute.java diff --git a/modeling/DIPLODOCUS/SmartCardProtocol.xml b/modeling/DIPLODOCUS/SmartCardProtocol.xml index 9ac4be0480..dcdc9717c4 100755 --- a/modeling/DIPLODOCUS/SmartCardProtocol.xml +++ b/modeling/DIPLODOCUS/SmartCardProtocol.xml @@ -7498,181 +7498,4 @@ the smart card and the terminal -<Modeling type="Avatar Analysis" nameTab="Analysis" > -<AvatarCDPanel name="Context Diagram 0" minX="10" maxX="2500" minY="10" maxY="1500" zoom="1.0" > -<CONNECTOR type="5404" id="1897" > -<cdparam x="893" y="430" /> -<sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<infoparam name="connector" value="null" /> -<TGConnectingPoint num="0" id="1896" /> -<P1 x="1325" y="210" id="1941" /> -<P2 x="1184" y="500" id="1911" /> -<AutomaticDrawing data="true" /> -</CONNECTOR> -<CONNECTOR type="5404" id="1899" > -<cdparam x="504" y="403" /> -<sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<infoparam name="connector" value="null" /> -<TGConnectingPoint num="0" id="1898" /> -<P1 x="449" y="569" id="1965" /> -<P2 x="1059" y="500" id="1910" /> -<AutomaticDrawing data="true" /> -</CONNECTOR> -<CONNECTOR type="5404" id="1901" > -<cdparam x="504" y="353" /> -<sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<infoparam name="connector" value="null" /> -<TGConnectingPoint num="0" id="1900" /> -<P1 x="449" y="519" id="1956" /> -<P2 x="1263" y="160" id="1939" /> -<AutomaticDrawing data="true" /> -</CONNECTOR> -<COMPONENT type="5400" id="1926" > -<cdparam x="997" y="500" /> -<sizeparam width="250" height="200" minWidth="5" minHeight="2" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> -<infoparam name="Block1" value="Block1" /> -<TGConnectingPoint num="0" id="1902" /> -<TGConnectingPoint num="1" id="1903" /> -<TGConnectingPoint num="2" id="1904" /> -<TGConnectingPoint num="3" id="1905" /> -<TGConnectingPoint num="4" id="1906" /> -<TGConnectingPoint num="5" id="1907" /> -<TGConnectingPoint num="6" id="1908" /> -<TGConnectingPoint num="7" id="1909" /> -<TGConnectingPoint num="8" id="1910" /> -<TGConnectingPoint num="9" id="1911" /> -<TGConnectingPoint num="10" id="1912" /> -<TGConnectingPoint num="11" id="1913" /> -<TGConnectingPoint num="12" id="1914" /> -<TGConnectingPoint num="13" id="1915" /> -<TGConnectingPoint num="14" id="1916" /> -<TGConnectingPoint num="15" id="1917" /> -<TGConnectingPoint num="16" id="1918" /> -<TGConnectingPoint num="17" id="1919" /> -<TGConnectingPoint num="18" id="1920" /> -<TGConnectingPoint num="19" id="1921" /> -<TGConnectingPoint num="20" id="1922" /> -<TGConnectingPoint num="21" id="1923" /> -<TGConnectingPoint num="22" id="1924" /> -<TGConnectingPoint num="23" id="1925" /> -<extraparam> -<stereotype value="block" /> -</extraparam> -</COMPONENT> - -<COMPONENT type="5400" id="1951" > -<cdparam x="1263" y="10" /> -<sizeparam width="250" height="200" minWidth="5" minHeight="2" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> -<infoparam name="Block0" value="Block0" /> -<TGConnectingPoint num="0" id="1927" /> -<TGConnectingPoint num="1" id="1928" /> -<TGConnectingPoint num="2" id="1929" /> -<TGConnectingPoint num="3" id="1930" /> -<TGConnectingPoint num="4" id="1931" /> -<TGConnectingPoint num="5" id="1932" /> -<TGConnectingPoint num="6" id="1933" /> -<TGConnectingPoint num="7" id="1934" /> -<TGConnectingPoint num="8" id="1935" /> -<TGConnectingPoint num="9" id="1936" /> -<TGConnectingPoint num="10" id="1937" /> -<TGConnectingPoint num="11" id="1938" /> -<TGConnectingPoint num="12" id="1939" /> -<TGConnectingPoint num="13" id="1940" /> -<TGConnectingPoint num="14" id="1941" /> -<TGConnectingPoint num="15" id="1942" /> -<TGConnectingPoint num="16" id="1943" /> -<TGConnectingPoint num="17" id="1944" /> -<TGConnectingPoint num="18" id="1945" /> -<TGConnectingPoint num="19" id="1946" /> -<TGConnectingPoint num="20" id="1947" /> -<TGConnectingPoint num="21" id="1948" /> -<TGConnectingPoint num="22" id="1949" /> -<TGConnectingPoint num="23" id="1950" /> -<extraparam> -<stereotype value="block" /> -</extraparam> -</COMPONENT> - -<COMPONENT type="5400" id="2001" > -<cdparam x="128" y="329" /> -<sizeparam width="635" height="455" minWidth="5" minHeight="2" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> -<infoparam name="Block2" value="Eq1" /> -<TGConnectingPoint num="0" id="1977" /> -<TGConnectingPoint num="1" id="1978" /> -<TGConnectingPoint num="2" id="1979" /> -<TGConnectingPoint num="3" id="1980" /> -<TGConnectingPoint num="4" id="1981" /> -<TGConnectingPoint num="5" id="1982" /> -<TGConnectingPoint num="6" id="1983" /> -<TGConnectingPoint num="7" id="1984" /> -<TGConnectingPoint num="8" id="1985" /> -<TGConnectingPoint num="9" id="1986" /> -<TGConnectingPoint num="10" id="1987" /> -<TGConnectingPoint num="11" id="1988" /> -<TGConnectingPoint num="12" id="1989" /> -<TGConnectingPoint num="13" id="1990" /> -<TGConnectingPoint num="14" id="1991" /> -<TGConnectingPoint num="15" id="1992" /> -<TGConnectingPoint num="16" id="1993" /> -<TGConnectingPoint num="17" id="1994" /> -<TGConnectingPoint num="18" id="1995" /> -<TGConnectingPoint num="19" id="1996" /> -<TGConnectingPoint num="20" id="1997" /> -<TGConnectingPoint num="21" id="1998" /> -<TGConnectingPoint num="22" id="1999" /> -<TGConnectingPoint num="23" id="2000" /> -<extraparam> -<stereotype value="Eq" /> -</extraparam> -</COMPONENT> -<SUBCOMPONENT type="5400" id="1976" > -<father id="2001" num="0" /> -<cdparam x="199" y="419" /> -<sizeparam width="250" height="200" minWidth="5" minHeight="2" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> -<hidden value="false" /> -<cdrectangleparam minX="0" maxX="385" minY="0" maxY="255" /> -<infoparam name="Block0" value="flow1" /> -<TGConnectingPoint num="0" id="1952" /> -<TGConnectingPoint num="1" id="1953" /> -<TGConnectingPoint num="2" id="1954" /> -<TGConnectingPoint num="3" id="1955" /> -<TGConnectingPoint num="4" id="1956" /> -<TGConnectingPoint num="5" id="1957" /> -<TGConnectingPoint num="6" id="1958" /> -<TGConnectingPoint num="7" id="1959" /> -<TGConnectingPoint num="8" id="1960" /> -<TGConnectingPoint num="9" id="1961" /> -<TGConnectingPoint num="10" id="1962" /> -<TGConnectingPoint num="11" id="1963" /> -<TGConnectingPoint num="12" id="1964" /> -<TGConnectingPoint num="13" id="1965" /> -<TGConnectingPoint num="14" id="1966" /> -<TGConnectingPoint num="15" id="1967" /> -<TGConnectingPoint num="16" id="1968" /> -<TGConnectingPoint num="17" id="1969" /> -<TGConnectingPoint num="18" id="1970" /> -<TGConnectingPoint num="19" id="1971" /> -<TGConnectingPoint num="20" id="1972" /> -<TGConnectingPoint num="21" id="1973" /> -<TGConnectingPoint num="22" id="1974" /> -<TGConnectingPoint num="23" id="1975" /> -<extraparam> -<stereotype value="Flow" /> -</extraparam> -</SUBCOMPONENT> - - -</AvatarCDPanel> - -</Modeling> - - - - </TURTLEGMODELING> \ No newline at end of file diff --git a/src/main/java/ui/GeneralAttribute.java b/src/main/java/ui/GeneralAttribute.java new file mode 100644 index 0000000000..fad29836c0 --- /dev/null +++ b/src/main/java/ui/GeneralAttribute.java @@ -0,0 +1,115 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package ui; + +import tmltranslator.TMLTextSpecification; +import translator.JKeyword; +import translator.RTLOTOSKeyword; +import translator.UPPAALKeyword; + +import java.util.List; + +/** + * Class GeneralAttribute + * Definition of a general attribute + * Creation: 03/07/2019 + * + * @author Ludovic APVRILLE + * @version 1.0 03/07/2019 + */ +public class GeneralAttribute { + + private String id; + private String initialValue; + private String type; + + + public GeneralAttribute(String _id, String _initialValue, String _type) { + id = new String(_id); + initialValue = new String(_initialValue); + type = new String(_type); + } + + + + public String getId() { + return id; + } + + public String getInitialValue() { + return initialValue; + } + + public String getType() { + return type; + } + + public void setId(String _id) { + id = _id; + } + + public void setInitialValue(String _initialValue) { + initialValue = _initialValue; + } + + public void setType(String _type) { + type = _type; + } + + + public String toString() { + String ret = ""; + if (id != null) ret += id; + if ((initialValue != null) && (initialValue.length() > 0)) { + ret += " = " + initialValue; + } + if ((type != null) && (type.length() > 0)) { + ret += " : " + type; + } + + return ret; + } + + public GeneralAttribute makeClone() { + return new GeneralAttribute(id, initialValue, type); + } + + +} diff --git a/src/main/java/ui/avatarcd/AvatarCDBlock.java b/src/main/java/ui/avatarcd/AvatarCDBlock.java index b9eec5991e..e44ffc190b 100644 --- a/src/main/java/ui/avatarcd/AvatarCDBlock.java +++ b/src/main/java/ui/avatarcd/AvatarCDBlock.java @@ -45,10 +45,15 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import ui.*; import ui.util.IconManager; +import ui.window.JDialogAttribute; +import ui.window.JDialogGeneralAttribute; import javax.swing.*; import java.awt.*; +import java.util.HashMap; import java.util.LinkedList; +import java.util.List; +import java.util.Map; /** @@ -57,7 +62,7 @@ import java.util.LinkedList; * Creation: 31/08/2011 * * @author Ludovic APVRILLE - * @version 1.1 31/08/2011 + * @version 1.2 03/07/2019 */ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent { private int textY1 = 3; @@ -73,6 +78,10 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S private int limitAttr = -1; private int limitMethod = -1; + protected List<GeneralAttribute> myAttributes; + + protected Map<GeneralAttribute, Integer> attrLocMap = new HashMap<GeneralAttribute, Integer>(); + // Icon //private int iconSize = 15; //private boolean iconIsDrawn = false; @@ -128,10 +137,207 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S myImageIcon = IconManager.imgic700; + this.myAttributes = new LinkedList<GeneralAttribute>(); + actionOnAdd(); } - public void internalDrawing(Graphics g) { + @Override + public void internalDrawing(Graphics graph) { + Font font = graph.getFont(); + this.internalDrawingAux(graph); + graph.setFont(font); + } + + private 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); + + // Draw inner rectangle + //graph.setColor(ColorManager.AVATAR_BLOCK); + + //TraceManager.addDev("type stereotype=" + typeStereotype); + + //graph.setColor(BLOCK_TYPE_COLOR.get(typeStereotype)); + 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; + + // 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()); + + // Draw icon + /*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); +*/ + + Font font = graph.getFont(); + + + //String ster = BLOCK_TYPE_STR.get(typeStereotype); + String ster = stereotype; + + //TraceManager.addDev("My ster=" + ster); + + 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); + + // Try to decrease font size until we get below the minimum + while (maxCurrentFontSize > (this.minFontSize * this.tdp.getZoom() - 1)) { + // Compute width of name of the function + int w0 = graph.getFontMetrics(font).stringWidth(this.value); + // Compute width of string stereotype + int w1 = graph.getFontMetrics(font).stringWidth(ster); + + // if one of the two width is small enough use this font size + if (Math.min(w0, w1) < this.width - (2 * this.textX)) + break; + + // Decrease font size + maxCurrentFontSize--; + // Scale the font + font = font.deriveFont((float) maxCurrentFontSize); + } + + // Box is too damn small + if (this.currentFontSize < this.minFontSize * this.tdp.getZoom()) { + maxCurrentFontSize++; + // Scale the font + font = font.deriveFont((float) maxCurrentFontSize); + } + + // Use this font + graph.setFont(font); + this.currentFontSize = maxCurrentFontSize; + } else + font = font.deriveFont(this.currentFontSize); + + graph.setFont(font.deriveFont(Font.BOLD)); + h = graph.getFontMetrics().getAscent() + graph.getFontMetrics().getLeading() + textY1; + + 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); + else { + // try to draw with "..." instead + + + 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) + 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); + 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); + break; + } + } + } + + h += graph.getFontMetrics().getDescent() + textY1; + + // Update lower bound of text + this.limitName = this.y + h; + + if (h + textY1 >= this.height) + return; + + // Draw separator + graph.drawLine(this.x, this.y + h, this.x + this.width, this.y + h); + + 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(); + + h += textY1; + + // Attributes + limitAttr = limitName; + for (GeneralAttribute attr : this.myAttributes) { + h += step; + if (h >= this.height - textX) { + this.limitAttr = this.y + this.height; + return; + } + + // Get the string for this parameter + String attrString = attr.toString(); + + // Try to draw it + w = graph.getFontMetrics().stringWidth(attrString); + + attrLocMap.put(attr, this.y + h); + 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); + break; + } + } + + if (stringLength < 0) + // skip attribute + h -= step; + } + } + } + + /*public void internalDrawing(Graphics g) { String ster = "<<" + stereotype + ">>"; Font f = g.getFont(); Font fold = f; @@ -234,13 +440,13 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S iconIsDrawn = false; }*/ - g.setFont(fold); + //g.setFont(fold); // Icon //g.drawImage(IconManager.imgic1100.getImage(), x + 4, y + 4, null); //g.drawImage(IconManager.img9, x + width - 20, y + 4, null); - } + //} public TGComponent isOnOnlyMe(int x1, int y1) { @@ -262,13 +468,23 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S public boolean editOndoubleClick(JFrame frame) { - oldValue = getStereotype() + "/" + getValue(); + JDialogGeneralAttribute jda = new JDialogGeneralAttribute(myAttributes, null, frame, + "Setting attributes of " + value, "Attribute", stereotype + "/" + value); + //setJDialogOptions(jda); + // jda.setSize(650, 375); + GraphicLib.centerOnParent(jda, 750, 375); + jda.setVisible(true); // blocked until dialog has been closed + + rescaled = true; + + String oldValue = getStereotype() + "/" + getValue(); //String text = getName() + ": "; - String s = (String) JOptionPane.showInputDialog(frame, "Stereotype / identifier", - "Setting value", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, - null, - getStereotype() + "/" + getValue()); + String s = jda.getValue(); + + if (s == null) { + return false; + } if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { //boolean b; @@ -507,6 +723,15 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<stereotype value=\"" + GTURTLEModeling.transformString(getStereotype())); sb.append("\" />\n"); + for (GeneralAttribute a : this.myAttributes) { + sb.append("<Attribute id=\""); + sb.append(a.getId()); + sb.append("\" value=\""); + sb.append(a.getInitialValue()); + sb.append("\" type=\""); + sb.append(a.getType()); + sb.append("\" />\n"); + } sb.append("</extraparam>\n"); return new String(sb); } @@ -523,6 +748,7 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S // String sdescription = null; // String prio; // String isRoot = null; + String type, id, valueAtt; for (int i = 0; i < nl.getLength(); i++) { n1 = nl.item(i); @@ -537,6 +763,21 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S if (elt.getTagName().equals("stereotype")) { stereotype = elt.getAttribute("value"); } + + if (elt.getTagName().equals("Attribute")) { + // + type = elt.getAttribute("type"); + id = elt.getAttribute("id"); + valueAtt = elt.getAttribute("value"); + + if (valueAtt.equals("null")) { + valueAtt = ""; + } + + GeneralAttribute ga = new GeneralAttribute(id, valueAtt, type); + this.myAttributes.add(ga); + + } } } } @@ -547,4 +788,41 @@ public class AvatarCDBlock extends TGCScalableWithInternalComponent implements S } } + + // Main Tree + public int getChildCount() { + //TraceManager.addDev("Counting childs!"); + return this.myAttributes.size() + nbInternalTGComponent; + } + + public Object getChild(int index) { + + int sa = nbInternalTGComponent; + + if (sa > index) { + return tgcomponent[index]; + } + + index = index - nbInternalTGComponent; + + return this.myAttributes.get(index); + } + + public int getIndexOfChild(Object child) { + if (child instanceof AvatarCDBlock) { + for (int i = 0; i < nbInternalTGComponent; i++) { + if (tgcomponent[i] == child) { + return i; + } + } + } + + if (child instanceof TAttribute) { + return this.myAttributes.indexOf(child) + nbInternalTGComponent; + } + + + return -1; + } + } diff --git a/src/main/java/ui/window/JDialogGeneralAttribute.java b/src/main/java/ui/window/JDialogGeneralAttribute.java new file mode 100644 index 0000000000..1bc1783651 --- /dev/null +++ b/src/main/java/ui/window/JDialogGeneralAttribute.java @@ -0,0 +1,441 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package ui.window; + +import ui.GeneralAttribute; +import ui.util.IconManager; +import ui.TAttribute; + +import javax.swing.*; +import javax.swing.border.TitledBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.LinkedList; + + +/** + * Class JDialogGeneralAttribute + * Dialog for managing general attributes and names + * Creation: 03/07/2019 + * + * @author Ludovic APVRILLE + * @version 2.0 03/07/2019 + */ +public class JDialogGeneralAttribute extends JDialogBase implements ActionListener, ListSelectionListener { + protected java.util.List<GeneralAttribute> attributes, attributesPar, forbidden; + protected java.util.List<Boolean> initValues; + + protected JPanel panel1, panel2; + + protected Frame frame; + + protected String attrib; // "Attributes", "Gates", etc. + + // Daemon task? + protected boolean isDaemon; + protected JCheckBox daemonBox; + + // Operation type + protected String value; + protected JPanel panelValue; + protected JTextField valueField; + + // Panel1 + protected JTextField identifierText; + protected JTextField initialValue; + protected JTextField type; + protected JButton addButton; + + //Panel2 + protected JList<GeneralAttribute> listAttribute; + protected JButton upButton; + protected JButton downButton; + protected JButton removeButton; + + protected String finalValue; + + + /* Creates new form */ + public JDialogGeneralAttribute(java.util.List<GeneralAttribute> _attributes, java.util.List<GeneralAttribute> _forbidden, Frame f, + String title, String attrib, String _value) { + super(f, title, true); + frame = f; + attributesPar = _attributes; + forbidden = _forbidden; + initValues = new LinkedList<Boolean>(); + this.attrib = attrib; + this.value = _value; + + attributes = new LinkedList<GeneralAttribute>(); + + for (GeneralAttribute attr : attributesPar) + attributes.add(attr.makeClone()); + + initComponents(); + myInitComponents(); + pack(); + } + + protected void myInitComponents() { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + } + + protected void initComponents() { + Container c = getContentPane(); + GridBagLayout gridbag0 = new GridBagLayout(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagLayout gridbag2 = new GridBagLayout(); + GridBagConstraints c0 = new GridBagConstraints(); + GridBagConstraints c1 = new GridBagConstraints(); + GridBagConstraints c2 = new GridBagConstraints(); + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + c.setLayout(gridbag0); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + panel1 = new JPanel(); + panel1.setLayout(gridbag1); + panel1.setBorder(new TitledBorder("Adding " + attrib + "s")); + panel1.setPreferredSize(new Dimension(300, 250)); + + panel2 = new JPanel(); + panel2.setLayout(gridbag2); + panel2.setBorder(new TitledBorder("Managing " + attrib + "s")); + panel2.setPreferredSize(new Dimension(300, 250)); + + // first line panel1 + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 3; + panel1.add(new JLabel(" "), c1); + + c1.gridwidth = 1; + c1.gridheight = 1; + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.anchor = GridBagConstraints.CENTER; + panel1.add(new JLabel("identifier"), c1); + + panel1.add(new JLabel(" "), c1); + panel1.add(new JLabel("initial value"), c1); + + panel1.add(new JLabel(" "), c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + panel1.add(new JLabel("type"), c1); + + // second line panel1 + c1.gridwidth = 1; + c1.fill = GridBagConstraints.HORIZONTAL; + c1.anchor = GridBagConstraints.CENTER; + identifierText = new JTextField(); + identifierText.setColumns(15); + identifierText.setEditable(true); + panel1.add(identifierText, c1); + + initialValue = new JTextField(); + initialValue.setColumns(5); + initialValue.setEditable(true); + + panel1.add(new JLabel(" = "), c1); + panel1.add(initialValue, c1); + + + panel1.add(new JLabel(" : "), c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + type = new JTextField(); + type.setColumns(15); + type.setEditable(true); + panel1.add(type, c1); + + // third line panel1 + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.BOTH; + c1.gridheight = 3; + panel1.add(new JLabel(" "), c1); + + // fourth line panel2 + c1.gridheight = 1; + c1.fill = GridBagConstraints.HORIZONTAL; + addButton = new JButton("Add / Modify " + attrib); + addButton.addActionListener(this); + panel1.add(addButton, c1); + + // 1st line panel2 + listAttribute = new JList<GeneralAttribute>(attributes.toArray(new GeneralAttribute[0])); + //listAttribute.setFixedCellWidth(150); + //listAttribute.setFixedCellHeight(20); + listAttribute.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listAttribute.addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(listAttribute); + scrollPane.setSize(300, 250); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + c2.fill = GridBagConstraints.BOTH; + c2.gridheight = 5; + c2.weighty = 10.0; + c2.weightx = 10.0; + panel2.add(scrollPane, c2); + + // 2nd line panel2 + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.fill = GridBagConstraints.BOTH; + c2.gridheight = 1; + panel2.add(new JLabel(""), c2); + + // third line panel2 + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + c2.fill = GridBagConstraints.HORIZONTAL; + upButton = new JButton("Up"); + upButton.addActionListener(this); + panel2.add(upButton, c2); + + downButton = new JButton("Down"); + downButton.addActionListener(this); + panel2.add(downButton, c2); + + removeButton = new JButton("Remove " + attrib); + removeButton.addActionListener(this); + panel2.add(removeButton, c2); + + // Operation panel + if (value == null) { + value = ""; + } + + GridBagLayout gbOp = new GridBagLayout(); + GridBagConstraints cOp = new GridBagConstraints(); + panelValue = new JPanel(); + panelValue.setLayout(gbOp); + panelValue.setBorder(new TitledBorder("Value: stereotype/blockname")); + //panelOperation.setPreferredSize(new Dimension(500, 70)); + + cOp.weighty = 1.0; + cOp.weightx = 2.0; + cOp.gridwidth = 4; + cOp.fill = GridBagConstraints.BOTH; + cOp.gridheight = 3; + valueField = new JTextField(value); + panelValue.add(valueField, cOp); + + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.fill = GridBagConstraints.BOTH; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + c.add(panelValue, c0); + + + // main panel; + c0.gridwidth = 1; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.fill = GridBagConstraints.BOTH; + + + c.add(panel1, c0); + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + c.add(panel2, c0); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + + initButtons(c0, c, this); + } + + public void actionPerformed(ActionEvent evt) { + + + String command = evt.getActionCommand(); + + // Compare the action command to the known actions. + if (command.equals("Save and Close")) { + closeDialog(); + } else if (command.equals("Add / Modify " + attrib)) { + addAttribute(); + } else if (command.equals("Cancel")) { + cancelDialog(); + } else if (command.equals("Remove " + attrib)) { + removeAttribute(); + } else if (command.equals("Down")) { + downAttribute(); + } else if (command.equals("Up")) { + upAttribute(); + } + } + + + public void addAttribute() { + + String id = identifierText.getText(); + String value = initialValue.getText(); + String typeS = type.getText(); + GeneralAttribute a = new GeneralAttribute(id, value, typeS); + + //checks whether the same attribute already belongs to the list + int index = attributes.size(); + + int indexIn = -1; + int cpt = 0; + for(GeneralAttribute ga: attributes) { + if (ga.getId().equals(id)) { + indexIn = cpt; + break; + } + cpt ++; + } + + + if (indexIn > -1) { + a = attributes.get(indexIn); + a.setType(type.getText()); + a.setInitialValue(initialValue.getText()); + a.setId(identifierText.getText()); + } else { + attributes.add(index, a); + } + listAttribute.setListData(attributes.toArray(new GeneralAttribute[0])); + identifierText.setText(""); + } + + public void removeAttribute() { + int i = listAttribute.getSelectedIndex(); + if (i != -1) { + GeneralAttribute a = attributes.get(i); + attributes.remove(i); + listAttribute.setListData(attributes.toArray(new GeneralAttribute[0])); + } + } + + public void downAttribute() { + int i = listAttribute.getSelectedIndex(); + if ((i != -1) && (i != attributes.size() - 1)) { + GeneralAttribute o = attributes.get(i); + attributes.remove(i); + attributes.add(i + 1, o); + listAttribute.setListData(attributes.toArray(new GeneralAttribute[0])); + listAttribute.setSelectedIndex(i + 1); + } + } + + public void upAttribute() { + int i = listAttribute.getSelectedIndex(); + if (i > 0) { + GeneralAttribute o = attributes.get(i); + attributes.remove(i); + attributes.add(i - 1, o); + listAttribute.setListData(attributes.toArray(new GeneralAttribute[0])); + listAttribute.setSelectedIndex(i - 1); + } + } + + + public void closeDialog() { + attributesPar.clear(); + for (GeneralAttribute attr : this.attributes) + attributesPar.add(attr); + finalValue = valueField.getText(); + dispose(); + } + + public void cancelDialog() { + dispose(); + } + + public void valueChanged(ListSelectionEvent e) { + int i = listAttribute.getSelectedIndex(); + if (i == -1) { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + identifierText.setText(""); + //initialValue.setText(""); + } else { + GeneralAttribute a = attributes.get(i); + identifierText.setText(a.getId()); + initialValue.setText(a.getInitialValue()); + type.setText(a.getType()); + removeButton.setEnabled(true); + if (i > 0) { + upButton.setEnabled(true); + } else { + upButton.setEnabled(false); + } + if (i != attributes.size() - 1) { + downButton.setEnabled(true); + } else { + downButton.setEnabled(false); + } + } + } + + public void select(JComboBox<String> jcb, String text) { + String s; + for (int i = 0; i < jcb.getItemCount(); i++) { + s = jcb.getItemAt(i); + // + if (s.equals(text)) { + jcb.setSelectedIndex(i); + return; + } + } + } + + public boolean isDaemon() { + return daemonBox.isSelected(); + } + + public String getValue() { + return finalValue; + } + + + +} -- GitLab