diff --git a/modeling/SysMLSec/AliceAndBobHW.xml b/modeling/SysMLSec/AliceAndBobHW.xml index a4c6f68b3ced3b385218708c21f6929eff61b25e..e0771ad393f5135ea4f86c4e4d0527600c01f6b2 100644 --- a/modeling/SysMLSec/AliceAndBobHW.xml +++ b/modeling/SysMLSec/AliceAndBobHW.xml @@ -897,7 +897,7 @@ <sizeparam width="15" height="35" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> <enabled value="true" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="decrypt" value="null" /> <new d="false" /> <TGConnectingPoint num="0" id="330" /> @@ -908,11 +908,11 @@ </COMPONENT> <COMPONENT type="1036" id="335" index="1" uid="b3b5764e-e503-4dca-aa65-2189abbc888e" > -<cdparam x="669" y="406" /> +<cdparam x="494" y="409" /> <sizeparam width="15" height="35" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> <enabled value="true" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="decrypt" value="null" /> <new d="false" /> <TGConnectingPoint num="0" id="333" /> @@ -927,7 +927,7 @@ <sizeparam width="15" height="35" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> <enabled value="true" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="encrypt" value="null" /> <new d="false" /> <TGConnectingPoint num="0" id="336" /> @@ -942,7 +942,7 @@ <sizeparam width="108" height="20" minWidth="30" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> <enabled value="true" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="write channel" value="nonce_ch(1)" /> <new d="false" /> <TGConnectingPoint num="0" id="339" /> @@ -956,7 +956,7 @@ <cdparam x="491" y="489" /> <sizeparam width="20" height="20" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="stop state" value="null" /> <new d="false" /> <TGConnectingPoint num="0" id="342" /> @@ -967,7 +967,7 @@ <sizeparam width="89" height="20" minWidth="30" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> <enabled value="true" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="read channel" value="comm(1) " /> <new d="false" /> <TGConnectingPoint num="0" id="344" /> @@ -982,7 +982,7 @@ <sizeparam width="89" height="20" minWidth="30" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> <enabled value="true" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="read channel" value="comm(1) " /> <new d="false" /> <TGConnectingPoint num="0" id="347" /> @@ -996,7 +996,7 @@ <cdparam x="494" y="85" /> <sizeparam width="15" height="15" minWidth="1" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> -<cdrectangleparam minX="10" maxX="2500" minY="10" maxY="1500" /> +<cdrectangleparam minX="10" maxX="2000" minY="10" maxY="1500" /> <infoparam name="start state" value="null" /> <new d="false" /> <TGConnectingPoint num="0" id="350" /> @@ -1015,7 +1015,7 @@ <cdparam x="525" y="491" /> <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="null" /> -<P1 x="676" y="451" id="334" /> +<P1 x="501" y="454" id="334" /> <P2 x="501" y="484" id="342" /> <AutomaticDrawing data="true" /> <new d="false" /> @@ -1034,7 +1034,7 @@ <sizeparam width="0" height="0" minWidth="0" minHeight="0" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <infoparam name="connector" value="null" /> <P1 x="501" y="390" id="348" /> -<P2 x="676" y="401" id="333" /> +<P2 x="501" y="404" id="333" /> <AutomaticDrawing data="true" /> <new d="false" /> </CONNECTOR> @@ -2992,9 +2992,9 @@ <SUBCOMPONENT type="1103" id="1046" index="15" uid="82785cce-97cd-4347-8d5a-01ffdc771be5" > <father id="1071" num="0" /> <cdparam x="432" y="408" /> -<sizeparam width="106" height="40" minWidth="75" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> +<sizeparam width="104" height="40" minWidth="75" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> -<cdrectangleparam minX="0" maxX="81" minY="0" maxY="91" /> +<cdrectangleparam minX="0" maxX="83" minY="0" maxY="91" /> <infoparam name="TGComponent" value="MAC::comm" /> <new d="false" /> <TGConnectingPoint num="0" id="1038" /> @@ -3274,9 +3274,9 @@ <SUBCOMPONENT type="1101" id="1223" index="18" uid="f7bd214e-253e-4a5b-b1eb-8daa6faffbea" > <father id="1248" num="0" /> <cdparam x="530" y="99" /> -<sizeparam width="98" height="40" minWidth="75" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> +<sizeparam width="96" height="40" minWidth="75" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> -<cdrectangleparam minX="0" maxX="110" minY="0" maxY="61" /> +<cdrectangleparam minX="0" maxX="112" minY="0" maxY="61" /> <infoparam name="TGComponent" value="MAC::Alice" /> <new d="false" /> <TGConnectingPoint num="0" id="1215" /> @@ -3331,9 +3331,9 @@ <SUBCOMPONENT type="1101" id="1257" index="19" uid="467ba799-1d32-4cad-a893-74add4b8598f" > <father id="1282" num="0" /> <cdparam x="308" y="110" /> -<sizeparam width="93" height="40" minWidth="75" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> +<sizeparam width="91" height="40" minWidth="75" minHeight="1" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> -<cdrectangleparam minX="0" maxX="119" minY="0" maxY="62" /> +<cdrectangleparam minX="0" maxX="121" minY="0" maxY="62" /> <infoparam name="TGComponent" value="MAC::Bob" /> <new d="false" /> <TGConnectingPoint num="0" id="1249" /> diff --git a/src/main/java/myutil/Conversion.java b/src/main/java/myutil/Conversion.java index 416c2d72742641588906e61c4efbf355768f3605..cf04ab8ead1247bfe95751448f7c35b9b4f0502d 100644 --- a/src/main/java/myutil/Conversion.java +++ b/src/main/java/myutil/Conversion.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,7 +31,7 @@ * 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. */ @@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.Iterator; import java.util.List; +import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -664,9 +665,9 @@ public class Conversion { public static boolean isInteger(String s) { try { Integer.parseInt(s); - } catch(NumberFormatException e) { + } catch (NumberFormatException e) { return false; - } catch(NullPointerException e) { + } catch (NullPointerException e) { return false; } // only got here if we didn't return false @@ -857,6 +858,29 @@ public class Conversion { } + public static String breakIntoLines(String input, int maxLineLength) { + Scanner scanner = new Scanner(input); + StringBuilder output = new StringBuilder(input.length()); + String line = ""; + + while (scanner.hasNext()) { + String word = scanner.next(); + + if (line.length() + word.length() <= maxLineLength) { + line += word + " "; + } else { + output.append(line.trim()).append("\n"); + line = word + " "; + } + } + + if (!line.isEmpty()) { + output.append(line.trim()).append("\n"); + } + + scanner.close(); + return output.toString(); + } } // Class Conversion diff --git a/src/main/java/ui/GTURTLEModeling.java b/src/main/java/ui/GTURTLEModeling.java index 3dfb8111cc71beddf431d4530b7c82c0b399c03f..55786a00d62cf63abb85b48695315fd1459b2942 100644 --- a/src/main/java/ui/GTURTLEModeling.java +++ b/src/main/java/ui/GTURTLEModeling.java @@ -9856,11 +9856,13 @@ public class GTURTLEModeling { warnings.clear(); //TraceManager.addDev("Clearing warnings"); } - for(NameChecker.NamedElement ne: nes) { - checkName(ne, warnings, _tdp); - if (ne.getSubNamedElements() != null) { - for (NameChecker.NamedElement sub : ne.getSubNamedElements()) { - checkName(sub, warnings, _tdp); + if (nes != null) { + for (NameChecker.NamedElement ne : nes) { + checkName(ne, warnings, _tdp); + if (ne.getSubNamedElements() != null) { + for (NameChecker.NamedElement sub : ne.getSubNamedElements()) { + checkName(sub, warnings, _tdp); + } } } } diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index d1eaefa0b05e784323f890af941ed5740f9c3416..60f769a84a5d169e196a3270b20e7617a51a66ef 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -3826,7 +3826,9 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per boolean b = false; boolean ret = false; - gtm.getCheckingWarnings().clear(); + if (gtm.getCheckingWarnings() != null) { + gtm.getCheckingWarnings().clear(); + } if (file == null) { JOptionPane.showMessageDialog(frame, "The project must be saved before any simulation or formal verification can be performed", diff --git a/src/main/java/ui/TDiagramPanel.java b/src/main/java/ui/TDiagramPanel.java index 458ed5593b36d2929f52207bd1dbf0d517f1505b..91b4e64120aada66aeb4b7c9913b8ba69d2f3ba3 100644 --- a/src/main/java/ui/TDiagramPanel.java +++ b/src/main/java/ui/TDiagramPanel.java @@ -41,7 +41,6 @@ package ui; import avatartranslator.ElementWithNew; import myutil.GenericTree; import myutil.GraphicLib; -import myutil.NameChecker; import myutil.TraceManager; import myutilsvg.SVGGeneration; import myutilsvg.SVGGraphics; @@ -3552,7 +3551,7 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { for (TGComponent o : this.componentList) if (o instanceof AvatarRDRequirement) { AvatarRDRequirement areq = (AvatarRDRequirement) o; - int otherid = Integer.decode(areq.getID()).intValue(); + int otherid = Integer.decode(areq.getReqID()).intValue(); if (intid == otherid) { ok = false; break; @@ -4028,6 +4027,43 @@ public abstract class TDiagramPanel extends JPanel implements GenericTree { return res; } + public int numberOfComponentsIn(int _x, int _y, int _with, int _height) { + int nb = 0; + for(TGComponent tgc: getComponentList()) { + if (GraphicLib.isInRectangle(tgc.getX(), tgc.getY(), _x, _y, _with, _height)) { + nb ++; + } else if (GraphicLib.isInRectangle(tgc.getX() + tgc.getWidth(), tgc.getY(), _x, _y, _with, _height)) { + nb ++; + } else if(GraphicLib.isInRectangle(tgc.getX(), tgc.getY() + tgc.getHeight(), _x, _y, _with, _height)) { + nb ++; + } else if (GraphicLib.isInRectangle(tgc.getX()+ tgc.getWidth(), tgc.getY()+ tgc.getHeight(), _x, _y, _with, _height)) { + nb ++; + } + } + return nb; + } + + /** + * Analyze the density of drawn elements, and find the less populated one yet + * close to minX, minY + * @return + */ + public Point findLessPopulatedLocation(int _width, int _height) { + int x = getMinX(), y = getMinY(), maxNb = Integer.MAX_VALUE; + for(int xi= getMinX()+_width; xi < getMaxX() - 2*_width ; xi = xi + 20) { + for(int yi= getMinY()+_height; yi < getMaxY() - 2*_height ; yi = yi + 20) { + int nb = numberOfComponentsIn(xi-_width, yi-_height, _width*2, _height*2); + if (nb < maxNb) { + //TraceManager.addDev("xi=" + xi + " yi=" + yi + " nb=" + nb + " maxNb=" + maxNb); + maxNb = nb; + x = xi; y = yi; + } + } + } + return new Point(x, y); + } + + public boolean isSelectedTemp() { return selectedTemp; } diff --git a/src/main/java/ui/TGScalableComponent.java b/src/main/java/ui/TGScalableComponent.java index baa30b906ebe0e76a7e0de4154f4e1d2f98a9641..2357c3fc2297757fa0060add93bee465392efa07 100644 --- a/src/main/java/ui/TGScalableComponent.java +++ b/src/main/java/ui/TGScalableComponent.java @@ -96,6 +96,7 @@ public abstract class TGScalableComponent extends TGComponent implements Scalabl && (txtWidth + spaceTakenByIcon < width) // enough space in width ; } + /** * Draw a box of two rectangle: one for the title and one for the content of the box * lineHeight defines the height of the first box diff --git a/src/main/java/ui/avatarrd/AvatarRDPanel.java b/src/main/java/ui/avatarrd/AvatarRDPanel.java index 3abed031d8e83c50ecc8889b18d08633dabf3104..06e371fbb6fe79a1fe20b6baba8176d762597fd9 100755 --- a/src/main/java/ui/avatarrd/AvatarRDPanel.java +++ b/src/main/java/ui/avatarrd/AvatarRDPanel.java @@ -39,13 +39,14 @@ package ui.avatarrd; +import myutil.TraceManager; import org.json.JSONObject; import org.json.JSONArray; import myutil.NameChecker; -import myutil.TraceManager; import ui.*; +import java.awt.*; import java.util.*; /** @@ -186,6 +187,31 @@ public class AvatarRDPanel extends TDiagramPanel implements TDPWithAttributes, N } return null; } + + public AvatarRDRequirement getReqWithId(String id) { + for(TGComponent tgc: componentList) { + if (tgc instanceof AvatarRDRequirement) { + if ( ((AvatarRDRequirement)(tgc)).getReqID().compareTo(id) == 0) { + return (AvatarRDRequirement)tgc; + } + } + } + return null; + } + + public AvatarRDRequirement addRequirement(String _name, String _id) { + // Find a less populated location, closer to (minX, minY) + Point p = findLessPopulatedLocation(200, 120); + + AvatarRDRequirement rdReq = new AvatarRDRequirement(p.x, p.y, getMinX(), getMaxX(), getMinY(), getMaxY(), true, null, this); + rdReq.setValue(_name); + rdReq.setReqID(_id); + rdReq.adaptItsSizeAndWrapText(); + addBuiltComponent(rdReq); + + + return rdReq; + } /*public boolean isLinkedByVerifyTo(TGComponent tgc1, TGComponent tgc2) { ListIterator iterator = getComponentList().listIterator(); @@ -687,7 +713,7 @@ public class AvatarRDPanel extends TDiagramPanel implements TDPWithAttributes, N /** * - * @param text: the json specification + * @param _spec: the json specification * Elements of a requirement: name, id, doc, category, refine, derive, compose * { * "requirements": [ @@ -704,11 +730,71 @@ public class AvatarRDPanel extends TDiagramPanel implements TDPWithAttributes, N * }, * */ - public void loadAndUpdateFromText(JSONObject text) { - JSONArray reqArray = text.getJSONArray("requirements"); + public void loadAndUpdateFromText(String _spec) throws org.json.JSONException { + + // cut before and after what is not part of the json array + int indexStart = _spec.indexOf('['); + int indexStop = _spec.lastIndexOf(']'); + + if ((indexStart == -1) || (indexStop == -1) || (indexStart > indexStop)) { + throw new org.json.JSONException("Invalid JSON array"); + } + + _spec = _spec.substring(indexStart, indexStop+1); + + TraceManager.addDev("Cut spec: " + _spec); + + JSONArray reqArray = new JSONArray(_spec); for(int i=0; i<reqArray.length(); i++) { - JSONObject name = reqArray.getJSONObject(i).getJSONObject("message"); + String name = reqArray.getJSONObject(i).getString("name"); + String id = reqArray.getJSONObject(i).getString("id"); + TraceManager.addDev("Handling requirements " + name + " / " + id); + + // If no requirement has this name, nor id, we create a new one. + // If a requirement has the same id xor the same name, we update it + // If a requirement has both, we simply select it + + name = name.trim().replaceAll(" ", "_"); + + AvatarRDRequirement reqName = getReqWithName(name); + AvatarRDRequirement reqId = getReqWithId(id); + AvatarRDRequirement selectedReq = null; + + if (reqName != null) { + if (reqId != null) { + if (reqName == reqId) { + selectedReq = reqName; + } else { + // Incoherency situation. We assume the name goes first + selectedReq = reqName; + selectedReq.setReqID(id); + } + } else { + selectedReq = reqName; + selectedReq.setReqID(id); + } + } else if (reqId != null) { + // We know that the name is null + // We update the name of the requirement + selectedReq = reqId; + selectedReq.setValue(name); + + } else { + if (selectedReq == null) { + // We create a new Requirement + selectedReq = addRequirement(name, id); + } + } + + // We complete other values + String doc = reqArray.getJSONObject(i).getString("doc"); + selectedReq.setText(doc); + /*JSONObject derive = reqArray.getJSONObject(i).getJSONObject("derive"); + JSONObject refine = reqArray.getJSONObject(i).getJSONObject("refine");*/ } + + + } diff --git a/src/main/java/ui/avatarrd/AvatarRDRequirement.java b/src/main/java/ui/avatarrd/AvatarRDRequirement.java index 3e7f11a82e2f6ff040a42233a18be26b593a6215..4384d209ab407a6e363f2df95402608548e9c60c 100755 --- a/src/main/java/ui/avatarrd/AvatarRDRequirement.java +++ b/src/main/java/ui/avatarrd/AvatarRDRequirement.java @@ -138,6 +138,8 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem // References private ArrayList<AvatarRDRequirementReference> references; + private boolean adapt = false; + public AvatarRDRequirement(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); @@ -249,6 +251,19 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem @Override public void internalDrawing(Graphics g) { + if (adapt) { + // Must adapt its size according to its name + //TraceManager.addDev("Size of border: " + textX); + int sizeOfValue = g.getFontMetrics().stringWidth(getValue()); + width = Math.max(width, sizeOfValue + (textX * 10) + iconSize); + + // Wrapping the text + wrapText(40); + + adapt = false; + } + + // Rectangle and lines g.drawRect(x, y, width, height); g.drawLine(x, y + lineHeight, x + width, y + lineHeight); @@ -357,155 +372,16 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem } } -// public void internalDrawing(Graphics g) { -// Font f = g.getFont(); -// // Font fold = f; -// // int w, c; -// int size; -// -// if (texts == null) { -// makeValue(); -// } -// -// if (!tdp.isScaled()) { -// graphics = g; -// } -// -// if (((rescaled) && (!tdp.isScaled())) || myFont == null) { -// currentFontSize = tdp.getFontSize(); -// // -// myFont = f.deriveFont((float) currentFontSize); -// myFontB = myFont.deriveFont(Font.BOLD); -// -// if (rescaled) { -// rescaled = false; -// } -// } -// -// displayText = currentFontSize >= minFontSize; -// -// // int h = g.getFontMetrics().getHeight(); -// -// g.drawRect(x, y, width, height); -// -// g.drawLine(x, y + lineHeight, x + width, y + lineHeight); -// Color topColor = REQ_TYPE_COLOR.get(reqType); -// if (topColor == null) { -// //TraceManager.addDev("Swithing back to default Color for:" + REQ_TYPE_STR.get(reqType)); -// topColor = ColorManager.AVATAR_REQUIREMENT_TOP; -// } else { -// //TraceManager.addDev("Using color: " + topColor.getRGB() + "for " +REQ_TYPE_STR.get(reqType)); -// } -// g.setColor(topColor); -// g.fillRect(x + 1, y + 1, width - 1, lineHeight - 1); -// g.setColor(ColorManager.AVATAR_REQUIREMENT_ATTRIBUTES); -// g.fillRect(x + 1, y + 1 + lineHeight, width - 1, height - 1 - lineHeight); -// ColorManager.setColor(g, getState(), 0); -// if ((lineHeight > 23) && (width > 23)) { -// g.drawImage(IconManager.img5100, x + width - iconSize + 1, y + 3, Color.yellow, null); -// } -// -// if (displayText) { -// size = currentFontSize - 2; -// g.setFont(myFont.deriveFont((float) (myFont.getSize() - 2))); -// -// drawLimitedString(g, "<<" + REQ_TYPE_STR.get(reqType) + ">>", x, y + size, width, 1); -// -// size += currentFontSize; -// g.setFont(myFontB); -// // w = g.getFontMetrics().stringWidth(value); -// drawLimitedString(g, value, x, y + size, width, 1); -// -// } -// -// if (verified) { -// if (satisfied) { -// Color tmp = g.getColor(); -// GraphicLib.setMediumStroke(g); -// g.setColor(Color.green); -// g.drawLine(x + width - 2, y - 6 + lineHeight, x + width - 6, y - 2 + lineHeight); -// g.drawLine(x + width - 6, y - 3 + lineHeight, x + width - 8, y - 6 + lineHeight); -// g.setColor(tmp); -// GraphicLib.setNormalStroke(g); -// } else { -// //g.drawString("acc", x + width - 10, y+height-10); -// Color tmp = g.getColor(); -// GraphicLib.setMediumStroke(g); -// g.setColor(Color.red); -// g.drawLine(x + width - 2, y - 2 + lineHeight, x + width - 8, y - 8 + lineHeight); -// g.drawLine(x + width - 8, y - 2 + lineHeight, x + width - 2, y - 8 + lineHeight); -// g.setColor(tmp); -// GraphicLib.setNormalStroke(g); -// } -// } -// -// g.setFont(myFont); -// String texti = "Text"; -// String s; -// int i; -// size = lineHeight + currentFontSize; -// -// //ID -// if (size < (height - 2)) { -// drawLimitedString(g, "ID=" + id, x + textX, y + size, width, 0); -// } -// size += currentFontSize; -// -// //text -// for (i = 0; i < texts.length; i++) { -// if (size < (height - 2)) { -// s = texts[i]; -// if (i == 0) { -// s = texti + "=\"" + s; -// } -// if (i == (texts.length - 1)) { -// s = s + "\""; -// } -// drawLimitedString(g, s, x + textX, y + size, width, 0); -// } -// size += currentFontSize; -// -// } -// // Type and risk -// if (size < (height - 2)) { -// drawLimitedString(g, "Kind=\"" + kind + "\"", x + textX, y + size, width, 0); -// size += currentFontSize; -// if (size < (height - 2)) { -// drawLimitedString(g, "Risk=\"" + criticality + "\"", x + textX, y + size, width, 0); -// size += currentFontSize; -// if (size < (height - 2)) { -// -// drawLimitedString(g, "Reference elements=\"" + referenceElements + "\"", x + textX, y + size, width, 0); -// size += currentFontSize; -// -// if (size < (height - 2)) { -// -// if (reqType == SECURITY_REQ) { -// drawLimitedString(g, "Targeted attacks=\"" + attackTreeNode + "\"", x + textX, y + size, width, 0); -// size += currentFontSize; -// } -// -// if (reqType == SAFETY_REQ) { -// drawLimitedString(g, "State violating req.=\"" + violatedAction + "\"", x + textX, y + size, width, 0); -// size += currentFontSize; -// } -// } -// } -// } -// } -// -// // Extra attributes -// for (i = 0; i < extraParamIDs.size(); i++) { -// if (size < (height - 2)) { -// s = extraParamIDs.get(i) + ":" + extraParamValues.get(i); -// drawLimitedString(g, s, x + textX, y + size, width, 0); -// } -// size += currentFontSize; -// -// } -// -// g.setFont(f); -// } + public void adaptItsSizeAndWrapText() { + adapt = true; + } + + private void wrapText(int maxNbOfcharacters) { + text = Conversion.breakIntoLines(text, maxNbOfcharacters); + makeValue(); + } + + public boolean editOnDoubleClick(JFrame frame, int _x, int _y) { // On the name ? @@ -992,14 +868,23 @@ public class AvatarRDRequirement extends TGCScalableWithInternalComponent implem return text; } + public void setText(String _text) { + text = _text; + makeValue(); + } + public String[] getTexts() { return texts; } - public String getID() { + public String getReqID() { return id; } + public void setReqID(String _id) { + id = _id; + } + public String getKind() { return kind; } diff --git a/src/main/java/ui/avatarrd/AvatarRDRequirementReference.java b/src/main/java/ui/avatarrd/AvatarRDRequirementReference.java index 08ddc65a5a9f62b48fdeb98d9c5e2f675721c6d7..27a5ca91867b01a63f0f1dae71ec1fa42850aad0 100755 --- a/src/main/java/ui/avatarrd/AvatarRDRequirementReference.java +++ b/src/main/java/ui/avatarrd/AvatarRDRequirementReference.java @@ -282,7 +282,7 @@ public class AvatarRDRequirementReference extends TGCScalableWithInternalCompone //ID if (size < (height - 2)) { - drawLimitedString(g, "ID=" + reference.getID(), x + textX, y + size, width, 0); + drawLimitedString(g, "ID=" + reference.getReqID(), x + textX, y + size, width, 0); } size += currentFontSize; @@ -433,7 +433,7 @@ public class AvatarRDRequirementReference extends TGCScalableWithInternalCompone if (reference == null) { return ""; } - String attr = "ID=" + reference.getID() + "\n"; + String attr = "ID=" + reference.getReqID() + "\n"; attr += "Text= " + reference.getText() + "\n"; attr += "Kind= " + reference.getKind() + "\n"; attr += "Risk= " + reference.getCriticality() + "\n"; diff --git a/src/main/java/ui/tmlad/TMLADDecrypt.java b/src/main/java/ui/tmlad/TMLADDecrypt.java index ff1bb416f55b3807bd67b37036e97e6545339739..240a851bd8b864eee1b454dbc0f171418b9e65cd 100755 --- a/src/main/java/ui/tmlad/TMLADDecrypt.java +++ b/src/main/java/ui/tmlad/TMLADDecrypt.java @@ -164,8 +164,8 @@ public class TMLADDecrypt extends TADComponentWithoutSubcomponents/* Issue #69 T /*TraceManager.addDev("Custom getMyCurrentMaxX. x+width= " + (x+width) + " SecurityMaxX=" + securityMaxX + " securityContext=" + securityContext);*/ int max = Math.max(x + width, securityMaxX); - TraceManager.addDev("Custom getMyCurrentMaxX. x+width= " + (x+width) + " SecurityMaxX=" + securityMaxX + " securityContext=" + - securityContext + " max=" + max); + /*TraceManager.addDev("Custom getMyCurrentMaxX. x+width= " + (x+width) + " SecurityMaxX=" + securityMaxX + " securityContext=" + + securityContext + " max=" + max);*/ return max; } diff --git a/src/main/java/ui/tmlad/TMLADEncrypt.java b/src/main/java/ui/tmlad/TMLADEncrypt.java index a71e7ad6a99e6395a7d55be5a4123cef312df743..4057349b4b25e687cb96d27d9ad01ad7eebc6cb5 100755 --- a/src/main/java/ui/tmlad/TMLADEncrypt.java +++ b/src/main/java/ui/tmlad/TMLADEncrypt.java @@ -235,8 +235,8 @@ public class TMLADEncrypt extends TADComponentWithoutSubcomponents/* Issue #69 T int max = Math.max(x + width, securityMaxX); max = Math.max(max, nonceMaxX); max = Math.max(max, keyMaxX); - TraceManager.addDev("Custom getMyCurrentMaxX. x+width= " + (x+width) + " SecurityMaxX=" + securityMaxX + " securityContext=" + - securityContext + " max=" + max); + /*TraceManager.addDev("Custom getMyCurrentMaxX. x+width= " + (x+width) + " SecurityMaxX=" + securityMaxX + " securityContext=" + + securityContext + " max=" + max);*/ return max; } diff --git a/src/main/java/ui/window/JFrameAI.java b/src/main/java/ui/window/JFrameAI.java index e03b94f5ca5b30cd9dddf075fa1c44664fb10c0b..eca63324271b842730ea6ed3ef2291aed9496c4f 100644 --- a/src/main/java/ui/window/JFrameAI.java +++ b/src/main/java/ui/window/JFrameAI.java @@ -85,8 +85,11 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable { "following sub categories: privacy, confidentiality, non-repudiation, controlled access, availability," + "immunity, data origin authenticity, freshness. Use the following format for the answer:" + " - Requirement name: classification\n"; - private String QUESTION_IDENTIFY_REQ = "Identify the requirements of the following specification. List them as follows: " + - "- name of the requirement: text of the requirement ; link to other requirements (derive, refine, compose). The name " + + private String QUESTION_IDENTIFY_REQ = "Identify all the relevant requirements of the following specification. List them as a json array with " + + "the following elements for each requirements in the array:" + + " " + + "name: name of the requirement, id: id of the requirement (as a string), doc: text of the requirement " + + "compose: all req names, derive: all req names, refine: all req names. The name " + "should be an english " + "name and not a number or an identifier"; private String QUESTION_IDENTIFY_PROPERTIES = "List properties of the following SysML V2 specification."; @@ -269,10 +272,41 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable { } private void applyResponse() { - if (previousKind == 1) { + if (previousKind == KIND_CLASSIFY_REQUIREMENT) { applyRequirementClassification(); + } else if (previousKind == IDENTIFY_REQUIREMENT) { + applyRequirementIdentification(); } } + private void applyRequirementIdentification() { + if (previousTDP == null) { + error("No diagram has been selected\n"); + return; + } + + if (!(previousTDP instanceof AvatarRDPanel)) { + error("Wrong diagram has been selected\n"); + return; + } + + AvatarRDPanel rdpanel = (AvatarRDPanel) previousTDP; + + inform("Enhancing requirement diagram with ai answer, please wait\n"); + TraceManager.addDev("Considered JSON array: " + automatedAnswer); + try { + + rdpanel.loadAndUpdateFromText(automatedAnswer); + + } catch (org.json.JSONException e) { + TraceManager.addDev("JSON Exception: " + e.getMessage()); + inform("Answer provided by AI does not respect the JSON format necessary for TTool"); + rdpanel.repaint(); + return; + } + rdpanel.repaint(); + + inform("Enhancing requirement diagram with ai answer: done<\n"); + } private void applyRequirementClassification() { if (previousTDP == null) { @@ -410,7 +444,9 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable { TraceManager.addDev("Asking for requirements"); String questionT = "\nTTool:" + QUESTION_IDENTIFY_REQ + "\n" + question.getText().trim() + "\n"; - makeQuestion(questionT, IDENTIFY_REQUIREMENT, tdp); + String answer = makeQuestion(questionT, IDENTIFY_REQUIREMENT, tdp); + + } private void classifyRequirements() { @@ -451,7 +487,6 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable { AVATAR2SysMLV2 tosysmlv2 = new AVATAR2SysMLV2(avspec); StringBuffer sb = tosysmlv2.generateSysMLV2Spec(false, false); - TraceManager.addDev("Appending: " + sb.toString().trim() + " to answer"); String question = QUESTION_IDENTIFY_PROPERTIES + "\n" + sb.toString().trim(); @@ -463,7 +498,7 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable { makeQuestion(question, IDENTIFY_PROPERTIES, tdp); } - private void makeQuestion(String _question, int _kind, TDiagramPanel _tdp) { + private String makeQuestion(String _question, int _kind, TDiagramPanel _tdp) { GraphicLib.appendToPane(answer, _question, Color.blue); try { @@ -473,10 +508,13 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable { previousTDP = _tdp; } catch (AIInterfaceException aiie) { error(aiie.getMessage()); - return; + return null; } inform("Got answer from ai. All done.\n\n"); GraphicLib.appendToPane(answer, "\nAI:\n" + automatedAnswer + "\n", Color.red); + + return automatedAnswer; + } private boolean makeAIInterface() { diff --git a/src/main/java/ui/window/RequirementsTableModel.java b/src/main/java/ui/window/RequirementsTableModel.java index 6ee76175810ee1c55973792d490986b3eca5eb53..558b0dbe5ca926767e56e3aa21994c7f0133f9bb 100644 --- a/src/main/java/ui/window/RequirementsTableModel.java +++ b/src/main/java/ui/window/RequirementsTableModel.java @@ -39,7 +39,6 @@ package ui.window; -import myutil.TraceManager; import ui.TGComponent; import ui.avatarrd.AvatarRDRequirement; import ui.req.Requirement; @@ -164,7 +163,7 @@ public class RequirementsTableModel extends AbstractTableModel { switch (index) { case 0: - return rd.getID(); + return rd.getReqID(); case 1: return rd.getStereotype(); case 2: