From 6d96ca13d52183b83c480cc6e65f0fbd4093f743 Mon Sep 17 00:00:00 2001
From: Ludovic Apvrille <ludovic.apvrille@telecom-paris.fr>
Date: Tue, 13 Jul 2021 17:23:34 +0200
Subject: [PATCH] Adding basic dialog for SysML V2 text

---
 src/main/java/ui/ActionPerformer.java         |   2 +
 src/main/java/ui/TGCSysMLV2.java              | 252 ++++++++++++++++++
 src/main/java/ui/TGComponentManager.java      |   8 +
 src/main/java/ui/TGUIAction.java              |  14 +-
 .../java/ui/avatarrd/AvatarRDToolBar.java     |   6 +
 .../java/ui/window/JFrameSysMLV2Text.java     | 136 ++++++++++
 6 files changed, 415 insertions(+), 3 deletions(-)
 create mode 100644 src/main/java/ui/TGCSysMLV2.java
 create mode 100644 src/main/java/ui/window/JFrameSysMLV2Text.java

diff --git a/src/main/java/ui/ActionPerformer.java b/src/main/java/ui/ActionPerformer.java
index 2bcf267fc9..19ea3ecdee 100644
--- a/src/main/java/ui/ActionPerformer.java
+++ b/src/main/java/ui/ActionPerformer.java
@@ -333,6 +333,8 @@ public class ActionPerformer {
             mgui.actionOnButton(TGComponentManager.EDIT, -1);
         } else if (command.equals(mgui.actions[TGUIAction.UML_NOTE].getActionCommand())) {
             mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.UML_NOTE);
+        } else if (command.equals(mgui.actions[TGUIAction.SysMLV2_TEXT].getActionCommand())) {
+            mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.SYSMLV2_TEXT);
         } else if (command.equals(mgui.actions[TGUIAction.DEPENDENCY_MATRIX].getActionCommand())) {
             mgui.actionOnButton(TGComponentManager.COMPONENT, TGComponentManager.DEPENDENCY_MATRIX);
         } else if (command.equals(mgui.actions[TGUIAction.PRAGMA].getActionCommand())) {
diff --git a/src/main/java/ui/TGCSysMLV2.java b/src/main/java/ui/TGCSysMLV2.java
new file mode 100644
index 0000000000..a08066b56d
--- /dev/null
+++ b/src/main/java/ui/TGCSysMLV2.java
@@ -0,0 +1,252 @@
+/* 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 myutil.Conversion;
+import myutil.GraphicLib;
+import myutil.TraceManager;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import ui.util.IconManager;
+import ui.window.JDialogDependencyMatrix;
+import ui.window.JDialogNote;
+import ui.window.JFrameSysMLV2Text;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * Class TGCSysMLV2
+ * Generic text box for displaying notes
+ * Creation: 13/07/2021
+ *
+ * @author Ludovic APVRILLE
+ * @version 1.0 13/07/2021
+ */
+public class TGCSysMLV2 extends TGCScalableWithoutInternalComponent implements ColorCustomizable {
+
+    protected String[] lines;
+
+    private static final int MARGIN_X = 5;
+    private static final int MARGIN_Y = 5;
+
+    protected Graphics myg;
+
+
+    private int currentFontSize = -1;
+
+    protected Graphics graphics;
+
+
+    public TGCSysMLV2(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) {
+        super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp);
+
+        // Issue #31
+//        this.width = 150;
+//        this.height = 30;
+
+        width = 150;
+        height = 150;
+        minWidth = 20;
+        minHeight = 20;
+
+        initScaling( 150, 150 );
+
+        //oldScaleFactor = tdp.getZoom();
+
+        this.nbConnectingPoint = 0;
+        int len = this.makeTGConnectingPointsComment(16);
+        int decw = 0;
+        int dech = 0;
+        for (int i = 0; i < 2; i++) {
+            connectingPoint[len] = new TGConnectingPointComment(this, 0, 0, true, true, 0.0 + decw, 0.0 + dech);
+            connectingPoint[len + 1] = new TGConnectingPointComment(this, 0, 0, true, true, 0.5 + decw, 0.0 + dech);
+            connectingPoint[len + 2] = new TGConnectingPointComment(this, 0, 0, true, true, 1.0 + decw, 0.0 + dech);
+            connectingPoint[len + 3] = new TGConnectingPointComment(this, 0, 0, true, true, 0.0 + decw, 0.5 + dech);
+            connectingPoint[len + 4] = new TGConnectingPointComment(this, 0, 0, true, true, 1.0 + decw, 0.5 + dech);
+            connectingPoint[len + 5] = new TGConnectingPointComment(this, 0, 0, true, true, 0.0 + decw, 1.0 + dech);
+            connectingPoint[len + 6] = new TGConnectingPointComment(this, 0, 0, true, true, 0.5 + decw, 1.0 + dech);
+            connectingPoint[len + 7] = new TGConnectingPointComment(this, 0, 0, true, true, 0.9 + decw, 1.0 + dech);
+            len += 8;
+        }
+
+        this.moveable = true;
+        this.editable = true;
+        this.removable = true;
+        this.userResizable = true;
+
+        this.currentFontSize = tdp.getFontSize();
+
+        this.name = "SysMLV2 Text";
+        this.value = "";
+
+        rescaled = true;
+
+        this.myImageIcon = IconManager.imgic320;
+    }
+
+
+    @Override
+    protected void internalDrawing(Graphics g) {
+        Font f = g.getFont();
+
+
+        if (((rescaled) && (!tdp.isScaled()))) {
+            currentFontSize = tdp.getFontSize();
+
+            if (rescaled) {
+                rescaled = false;
+            }
+        }
+
+        Color c = g.getColor();
+
+        g.setColor(getCurrentColor());
+        g.fillRect(x, y, width, height);
+        g.setColor(c);
+        g.drawRect(x, y, width, height);
+
+        int xStr = x, yStr = y;
+        Font f0 = g.getFont();
+        g.setFont(f.deriveFont(Font.BOLD));
+        int w = g.getFontMetrics().stringWidth(name);
+
+        // Issue #31
+        final int marginX = scale( MARGIN_X );
+        final int marginY = scale( MARGIN_Y );
+
+        xStr += width/2 - w/2;
+        yStr += marginY + currentFontSize;
+
+        g.drawString(name, xStr, yStr);
+        g.setFont(f0);
+        g.setColor(c);
+    }
+
+    public TGComponent isOnMe(int x1, int y1) {
+
+        if (GraphicLib.isInRectangle(x1, y1, x, y, width, height)) {
+            return this;
+        }
+        return null;
+    }
+
+    @Override
+    public boolean editOnDoubleClick(JFrame frame) {
+        String oldValue = value;
+
+        JFrameSysMLV2Text jfsmlv2t = new JFrameSysMLV2Text("Edit " + name,  this, lines, IconManager.imgic8);
+        jfsmlv2t.setIconImage(IconManager.img8);
+        GraphicLib.centerOnParent(jfsmlv2t, 740, 800);
+        jfsmlv2t.setVisible(true);
+        return true;
+    }
+
+
+    @Override
+    public int getType() {
+        return TGComponentManager.SYSMLV2_TEXT;
+    }
+
+    @Override
+    protected String translateExtraParam() {
+        if (lines == null) {
+            return "";
+        }
+
+        StringBuffer sb = new StringBuffer("<extraparam>\n");
+        for (int i = 0; i < lines.length; i++) {
+            sb.append("<Line value=\"");
+            sb.append(GTURTLEModeling.transformString(lines[i]));
+            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 {
+        lines = null;
+        String line = "";
+        try {
+            NodeList nli;
+            Node n1, n2;
+            Element elt;
+            String s;
+
+            for (int i = 0; i < nl.getLength(); i++) {
+                n1 = nl.item(i);
+                //
+                if (n1.getNodeType() == Node.ELEMENT_NODE) {
+                    nli = n1.getChildNodes();
+                    for (int j = 0; j < nli.getLength(); j++) {
+                        n2 = nli.item(j);
+                        //
+                        if (n2.getNodeType() == Node.ELEMENT_NODE) {
+                            elt = (Element) n2;
+                            if (elt.getTagName().equals("Line")) {
+                                //
+                                s = elt.getAttribute("value");
+                                if (s.equals("null")) {
+                                    s = "";
+                                }
+                                //TraceManager.addDev("Adding " + s + " in decoded format:" + GTURTLEModeling.decodeString(s));
+                                line += GTURTLEModeling.decodeString(s) + "\n";
+                            }
+                        }
+                    }
+                }
+            }
+            setLines(line);
+
+        } catch (Exception e) {
+            throw new MalformedModelingException( e );
+        }
+    }
+
+    public void setLines(String line) {
+        lines = line.split(("\n"));
+    }
+
+    // Color management
+    public Color getMainColor() {
+        return Color.LIGHT_GRAY;
+    }
+}
diff --git a/src/main/java/ui/TGComponentManager.java b/src/main/java/ui/TGComponentManager.java
index 709f7cd34a..42744feda6 100644
--- a/src/main/java/ui/TGComponentManager.java
+++ b/src/main/java/ui/TGComponentManager.java
@@ -576,6 +576,9 @@ public class TGComponentManager {
     public static final int COMPONENT = 0;
     public static final int CONNECTOR = 1;
 
+    // SysML V2
+    public static final int SYSMLV2_TEXT = 11000;
+
 
     public static LinkedList<ADDConnector> addconnectors = new LinkedList<ADDConnector>();
 
@@ -957,6 +960,9 @@ public class TGComponentManager {
             case UML_NOTE:
                 tgc = new TGCNote(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
                 break;
+            case SYSMLV2_TEXT:
+                tgc = new TGCSysMLV2(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
+                break;
             case DEPENDENCY_MATRIX:
                 tgc = new TGCDependencyMatrix(x, y, tdp.getMinX(), tdp.getMaxX(), tdp.getMinY(), tdp.getMaxY(), false, null, tdp);
                 break;
@@ -1978,6 +1984,8 @@ public class TGComponentManager {
             return CONNECTOR_INTERACTION;
         } else if (tgc instanceof TGCNote) {
             return UML_NOTE;
+        } else if (tgc instanceof TGCSysMLV2) {
+            return SYSMLV2_TEXT;
         } else if (tgc instanceof TGCDependencyMatrix) {
             return DEPENDENCY_MATRIX;
         } else if (tgc instanceof TGCPanelInfo) {
diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java
index 2b45ff27b2..66b2987c0e 100644
--- a/src/main/java/ui/TGUIAction.java
+++ b/src/main/java/ui/TGUIAction.java
@@ -713,8 +713,11 @@ public class TGUIAction extends AbstractAction {
     public static final int M_REF_MAPPING = 552;
     public static final int M_PANEL_INFO = 553;
 
+    // SysMLV2
+    public static final int SysMLV2_TEXT = 557;
 
-    public static final int NB_ACTION = 557; // Last + 1
+
+    public static final int NB_ACTION = 558; // Last + 1
 
     private static final TAction [] actions = new TAction[NB_ACTION];
 
@@ -1052,11 +1055,16 @@ public class TGUIAction extends AbstractAction {
         actions[TCD_SYNCHRO_OPERATOR] = new TAction("add-synchro-operator", "Add Synchro composition operator", IconManager.imgic110, IconManager.imgic110, "Synchro composition operator", "Adds a Synchro composition operator to the currently opened class diagram", 0);
         actions[TCD_INVOCATION_OPERATOR] = new TAction("add-invocation-operator", "Add Invocation composition operator", IconManager.imgic126, IconManager.imgic126, "Invocation composition operator", "Adds an invocation composition operator to the currently opened class diagram", 0);
         actions[TCD_ASSOCIATION_NAVIGATION] = new TAction("add-association-navigation", "Add association with navigation", IconManager.imgic106, IconManager.imgic108, "Association with navigation", "Adds an association with a navigation indication between two tclasses of the currently opened class diagram", 0);
-        actions[UML_NOTE] = new TAction("edit-note", "Add a note to a diagram", IconManager.imgic320, IconManager.imgic321, "Add a comment", "Add a comment to the currently opened TTool diagram", 0);
+        actions[UML_NOTE] = new TAction("edit-note", "Add a note to a diagram", IconManager.imgic320, IconManager.imgic321,
+                "Add a comment", "Add a comment to the currently opened TTool diagram", 0);
+        actions[SysMLV2_TEXT] = new TAction("edit-sysmlv2-text", "Add a SysMLV2 text", IconManager.imgic320,
+                IconManager.imgic321, "Add a SysML V2 text", "Add a SysML V2 text to the currently opened TTool diagram",
+                0);
         actions[DEPENDENCY_MATRIX] = new TAction("dep-matrix", "Add a dependency matrix", IconManager.imgic320,
                 IconManager.imgic321, "Dependency matrix",
                 "Add a dependency matrix to the currently opened TTool diagram", 0);
-        actions[PRAGMA] = new TAction("pragma", "Security pragmas", IconManager.imgic6000, IconManager.imgic6001, "Security pragmas", "Add security pragmas to the currently opened TTool diagram", 0);
+        actions[PRAGMA] = new TAction("pragma", "Security pragmas", IconManager.imgic6000, IconManager.imgic6001,
+                "Security pragmas", "Add security pragmas to the currently opened TTool diagram", 0);
         actions[SAFETY_PRAGMA] = new TAction("safety_pragma", "Add a safety (UPPAAL) property to a diagram", IconManager.imgic6002, IconManager.imgic6003, "Safety property (UPPAAL)", "Add a safety (UPPAAL) property to the currently opened TTool diagram", 0);
         actions[TML_PRAGMA] = new TAction("tml_pragma", "Add a TML pragma", IconManager.imgic6006, IconManager.imgic6007,"TML pragma", "Add a TML pragma to the currently opened TTool diagram", 0);
         actions[PERFORMANCE_PRAGMA] = new TAction("performance_pragma", "Add a performance property to a diagram", IconManager.imgic6004, IconManager.imgic6005, "Performance property", "Add a performance property to the currently opened TTool diagram", 0);
diff --git a/src/main/java/ui/avatarrd/AvatarRDToolBar.java b/src/main/java/ui/avatarrd/AvatarRDToolBar.java
index dfd7071d2b..d5f06223b7 100755
--- a/src/main/java/ui/avatarrd/AvatarRDToolBar.java
+++ b/src/main/java/ui/avatarrd/AvatarRDToolBar.java
@@ -72,6 +72,7 @@ public class AvatarRDToolBar extends TToolBar {
 
         mgui.actions[TGUIAction.ARD_EDIT].setEnabled(b);
         mgui.actions[TGUIAction.UML_NOTE].setEnabled(b);
+        mgui.actions[TGUIAction.SysMLV2_TEXT].setEnabled(b);
         mgui.actions[TGUIAction.DEPENDENCY_MATRIX].setEnabled(b);
         mgui.actions[TGUIAction.CONNECTOR_COMMENT].setEnabled(b);
         mgui.actions[TGUIAction.ARD_REQUIREMENT].setEnabled(b);
@@ -114,6 +115,11 @@ public class AvatarRDToolBar extends TToolBar {
 
         this.addSeparator();
 
+        button = this.add(mgui.actions[TGUIAction.SysMLV2_TEXT]);
+        button.addMouseListener(mgui.mouseHandler);
+
+        this.addSeparator();
+
         button = this.add(mgui.actions[TGUIAction.ARD_REQUIREMENT]);
         button.addMouseListener(mgui.mouseHandler);
 
diff --git a/src/main/java/ui/window/JFrameSysMLV2Text.java b/src/main/java/ui/window/JFrameSysMLV2Text.java
new file mode 100644
index 0000000000..dc7bf49bc6
--- /dev/null
+++ b/src/main/java/ui/window/JFrameSysMLV2Text.java
@@ -0,0 +1,136 @@
+/* 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.TGCSysMLV2;
+import ui.util.IconManager;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+
+/**
+ * Class JFrameSysMLV2Text
+ * Creation: 13/07/2021
+ * version 1.0 13/07/2021
+ * @author Ludovic APVRILLE
+ */
+public class JFrameSysMLV2Text extends JFrame implements ActionListener {
+
+
+	private TGCSysMLV2 comp;
+
+	private JButton buttonCancel, buttonClose;
+	private JTextArea jta;
+
+
+	public JFrameSysMLV2Text(String title, TGCSysMLV2 _comp, String[] _lines, ImageIcon imgic) {
+		super(title);
+		comp = _comp;
+		
+		setDefaultCloseOperation( DISPOSE_ON_CLOSE );
+		Container framePanel = getContentPane();
+		framePanel.setLayout(new BorderLayout());
+
+		String line = "";
+		if (_lines != null) {
+			for (int i=0; i < _lines.length; i++) {
+				line += _lines[i] + "\n";
+			}
+		}
+
+		jta = new JTextArea(line);
+		// Issue #35: This should not be editable because changes will not be 
+		// taken into account
+		jta.setEditable( true );
+//		jta.setEditable(true);
+		jta.setMargin(new Insets(10, 10, 10, 10));
+		jta.setTabSize(3);
+		Font f = new Font("Courrier", Font.BOLD, 12); 
+		jta.setFont(f);
+		JScrollPane jsp = new JScrollPane(jta);
+		
+		framePanel.add(jsp, BorderLayout.CENTER);
+		
+		buttonCancel = new JButton("Cancel", IconManager.imgic27);
+		buttonCancel.addActionListener(this);
+		buttonClose = new JButton("Save and close", IconManager.imgic25);
+		buttonClose.addActionListener(this);
+		
+		JPanel jp = new JPanel();
+		jp.add(buttonCancel);
+		jp.add(buttonClose);
+		
+		framePanel.add(jp, BorderLayout.SOUTH);
+
+		
+		pack();
+	}
+	
+ 	public void actionPerformed(ActionEvent evt)  {
+		
+		if (evt.getSource() == buttonCancel) {
+			cancel();
+		} else if (evt.getSource() == buttonClose) {
+			close();
+		}
+	}
+
+	private void cancel() {
+    	dispose();
+	}
+
+	private void close() {
+    	if (comp != null) {
+    		comp.setLines(jta.getText());
+    		comp.getTDiagramPanel().repaint();
+		}
+    	dispose();
+	}
+
+	
+    
+} // Class 
+
+	
\ No newline at end of file
-- 
GitLab