diff --git a/modeling/AVATAR/CoffeeMachine_Avatar.xml b/modeling/AVATAR/CoffeeMachine_Avatar.xml index fa50f67982edd726b9115c025f20bf2f0e16cefa..8ef9d3594d66994af6e80adf823273f209233fb2 100644 --- a/modeling/AVATAR/CoffeeMachine_Avatar.xml +++ b/modeling/AVATAR/CoffeeMachine_Avatar.xml @@ -5,7 +5,7 @@ <Modeling type="Avatar Requirement" nameTab="AVATAR Requirements" > <AvatarRDPanel name="AVATAR RD" minX="10" maxX="1900" minY="10" maxY="1400" zoom="1.0" > <COMPONENT type="309" id="17" index="0" uid="4264f684-9e08-4164-a2f5-6c22db88858f" > -<cdparam x="1106" y="423" /> +<cdparam x="1106" y="424" /> <sizeparam width="150" height="150" minWidth="20" minHeight="20" maxWidth="2000" maxHeight="2000" minDesiredWidth="0" minDesiredHeight="0" /> <hidden value="false" /> <cdrectangleparam minX="10" maxX="1900" minY="10" maxY="1400" /> @@ -27,10 +27,13 @@ <TGConnectingPoint num="14" id="15" /> <TGConnectingPoint num="15" id="16" /> <extraparam> -<columnDiag v="" /> -<rowDiag v="" /> -<rows v="" /> -<columns v="" /> +<columnDiag v="AVATAR RD" /> +<rowDiag v="AVATAR RD" /> +<rows v="Requirement_0/21634324-f1ec-471d-b025-373bb090c963$req00/6a44a70b-341e-4094-9eb3-95ef05784845$Req_Availability/2db149ef-c53b-4707-8c0f-285eea3e4257$Req_CoffeeMachine/e73051aa-2858-45ad-9538-4bb540752766$req1/d6ff748e-4216-4bb2-b0ce-81e64e2dbd68$req0/3f856106-1533-4f29-bb50-d5da20b70742$req2/e1c3057e-2674-463d-8b8c-6d741b397711" /> +<columns v="Requirement_0/21634324-f1ec-471d-b025-373bb090c963$req00/6a44a70b-341e-4094-9eb3-95ef05784845$Req_Availability/2db149ef-c53b-4707-8c0f-285eea3e4257$Req_CoffeeMachine/e73051aa-2858-45ad-9538-4bb540752766$req1/d6ff748e-4216-4bb2-b0ce-81e64e2dbd68$req0/3f856106-1533-4f29-bb50-d5da20b70742$req2/e1c3057e-2674-463d-8b8c-6d741b397711" /> +<p x="0" y="0" v="2" /> +<p x="2" y="1" v="3" /> +<p x="6" y="6" v="1" /> </extraparam> </COMPONENT> diff --git a/src/main/java/myutil/BytePoint.java b/src/main/java/myutil/BytePoint.java new file mode 100644 index 0000000000000000000000000000000000000000..8cb5b0419f3169db963c2f4b9b05d49cb92522da --- /dev/null +++ b/src/main/java/myutil/BytePoint.java @@ -0,0 +1,75 @@ +/* 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 myutil; + + + + +/** + * Class BytePoint + * Point with a byte value + * Creation: 2005 + * @version 1.1 09/03/2005 + * @author Ludovic APVRILLE + */ +public class BytePoint { + public int x, y; + public byte value; + + public BytePoint(int _x, int _y, byte _value) { + x = _x; + y = _y; + value = _value; + } + + public BytePoint(int _x, int _y, int _value) { + x = _x; + y = _y; + value = (byte)_value; + } + + public String toString() { + return "(" + x + "," + y + "," + value + ")"; + } + + +} diff --git a/src/main/java/ui/TGCDependencyMatrix.java b/src/main/java/ui/TGCDependencyMatrix.java index d5d023f615765fc340a0cb245c78e27efa6bc461..a4f7cf4649dc21eef09d216a94aa739a17ef67db 100644 --- a/src/main/java/ui/TGCDependencyMatrix.java +++ b/src/main/java/ui/TGCDependencyMatrix.java @@ -41,7 +41,9 @@ package ui; import java.awt.*; import java.util.ArrayList; +import myutil.BytePoint; import myutil.Conversion; +import myutil.TraceManager; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -85,7 +87,7 @@ public class TGCDependencyMatrix extends TGCScalableWithInternalComponent implem protected String columns = ""; // separated by ";" protected String rows = ""; // separated by ; - protected ArrayList<Point> dependencies; + protected ArrayList<BytePoint> dependencies; @@ -124,7 +126,7 @@ public class TGCDependencyMatrix extends TGCScalableWithInternalComponent implem removable = true; userResizable = true; - dependencies = new ArrayList<Point>(); + dependencies = new ArrayList<BytePoint>(); name = "Matrix"; value = "Dependency Matrix"; @@ -189,7 +191,15 @@ public class TGCDependencyMatrix extends TGCScalableWithInternalComponent implem jddm.setVisible( true ); if (!jddm.hasBeenCancelled()) { - + TraceManager.addDev("Has been saved"); + if (jddm.hasMatrix()) { + TraceManager.addDev("Has matrix!"); + rowDiag = jddm.getRowDiag(); + columnDiag = jddm.getColumnDiag(); + rows = jddm.getRows(); + columns = jddm.getColumns(); + dependencies = jddm.getDependencies(); + } } return false; @@ -206,20 +216,15 @@ public class TGCDependencyMatrix extends TGCScalableWithInternalComponent implem protected String translateExtraParam() { - // TAttribute a; -// AvatarMethod am; -// AvatarSignal as; - - // - //value = ""; + // StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<columnDiag v=\"" + columnDiag + "\" />\n"); sb.append("<rowDiag v=\"" + rowDiag + "\" />\n"); StringBuffer sbT = new StringBuffer(); sb.append("<rows v=\"" + rows + "\" />\n"); sb.append("<columns v=\"" + columns + "\" />\n"); - for(Point pt: dependencies) { - sb.append("<p x=\"" + pt.x + "\" y=\"" + pt.y + "\" />\n"); + for(BytePoint pt: dependencies) { + sb.append("<p x=\"" + pt.x + "\" y=\"" + pt.y + "\" v=\"" + pt.value + "\" />\n"); } sb.append("</extraparam>\n"); @@ -228,7 +233,7 @@ public class TGCDependencyMatrix extends TGCScalableWithInternalComponent implem @Override public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ - String xP, yP; + String xP, yP, vP; try { NodeList nli; @@ -264,10 +269,12 @@ public class TGCDependencyMatrix extends TGCScalableWithInternalComponent implem if (elt.getTagName().equals("p")) { xP = elt.getAttribute("x"); yP = elt.getAttribute("y"); - if ((xP != null) && (yP != null) && (xP.length() > 0) && (yP.length() > 0)) { + vP = elt.getAttribute("v"); + if ((xP != null) && (yP != null) && (vP != null) && (xP.length() > 0) && (yP.length() > 0) && (vP.length() > 0)) { int xT = Integer.decode(xP); int yT = Integer.decode(yP); - dependencies.add(new Point(xT, yT)); + int vT = Integer.decode(vP); + dependencies.add(new BytePoint(xT, yT, vT)); } } diff --git a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java index 147ab51fc827b73a387ace0e6c212daeb553ad6b..67333c3b293e0c94b466001780f5d5f4105d6b7f 100755 --- a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java +++ b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java @@ -2476,6 +2476,9 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS "Variable modification", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101, null, variableValue); + if (s == null) { + return; + } s = s.trim(); boolean ret; diff --git a/src/main/java/ui/window/DependencyTableModel.java b/src/main/java/ui/window/DependencyTableModel.java index b8f0a2a33179b5a06c5a31f8619ce1c3918ff79f..940946715532e3ebc5cea90450cf123c701a68b4 100644 --- a/src/main/java/ui/window/DependencyTableModel.java +++ b/src/main/java/ui/window/DependencyTableModel.java @@ -39,6 +39,7 @@ package ui.window; +import myutil.BytePoint; import myutil.TraceManager; import ui.TGComponent; import ui.avatarrd.AvatarRDRequirement; @@ -58,14 +59,17 @@ import java.util.LinkedList; * @version 1.0 23/06/2021 */ public class DependencyTableModel extends AbstractTableModel { + public static final String[] VALUES = {"", "->", "<-", "<->"}; + private String[] cols, rows; - private ArrayList<Point> points; + private byte[][] values; - public DependencyTableModel(String[] _rows, String[] _cols, ArrayList<Point> _points) { + public DependencyTableModel(String[] _rows, String[] _cols, ArrayList<BytePoint> _points) { rows = _rows; cols = _cols; - points = _points; + values = new byte[rows.length][cols.length]; + fillValues(_points); } // From AbstractTableModel @@ -81,11 +85,12 @@ public class DependencyTableModel extends AbstractTableModel { if (column == 0) { return rows[row]; } - return "-"; - } - public String getRowName(int rowIndex) { - return rows[rowIndex]; + int val = values[row][column-1]; + if ((val >=0) && (val<VALUES.length)) { + return VALUES[val]; + } + return ""; } public String getColumnName(int columnIndex) { @@ -95,4 +100,32 @@ public class DependencyTableModel extends AbstractTableModel { return cols[columnIndex-1]; } + private void fillValues(ArrayList<BytePoint> _points) { + for(BytePoint p: _points) { + if ((p.x >= 0) && (p.y >= 0) && (p.x < rows.length) && (p.y<cols.length)) { + values[p.x][p.y] = p.value; + } + } + } + + public ArrayList<BytePoint> getNonNullPoints() { + ArrayList<BytePoint> points = new ArrayList<>(); + for(int i=0; i<rows.length; i++) { + for(int j=0; j< cols.length; j++) { + if (values[i][j] > 0) { + BytePoint pt = new BytePoint(i, j, values[i][j]); + TraceManager.addDev("Adding point: " + pt); + points.add(pt); + } + } + } + return points; + } + + public void mySetValueAt(int value, int selectedRow, int selectedCol) { + if ((selectedRow >= 0) && (selectedCol >= 0) && (selectedRow < rows.length) && (selectedCol<cols.length)) { + values[selectedRow][selectedCol] = (byte) value; + } + } + } \ No newline at end of file diff --git a/src/main/java/ui/window/JDialogDependencyMatrix.java b/src/main/java/ui/window/JDialogDependencyMatrix.java index d5930ab575a0d1c1210d3f31235d86270a13305e..261058c0827a9d4732f0384238095307e06bfb47 100644 --- a/src/main/java/ui/window/JDialogDependencyMatrix.java +++ b/src/main/java/ui/window/JDialogDependencyMatrix.java @@ -39,6 +39,7 @@ package ui.window; +import myutil.BytePoint; import myutil.TableSorter; import myutil.TraceManager; import ui.MainGUI; @@ -50,6 +51,8 @@ import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -69,6 +72,7 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen private boolean hasBeenCancelled = true; private MainGUI mgui; + private JTabbedPane mainPane; private JComboBox<String> rowPanelBox, rowDiagBox, colPanelBox, colDiagBox; private JList<String> rowClassList, colClassList; private DefaultListModel<String> rowClassListModel, colClassListModel; @@ -78,16 +82,19 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen private String columnDiag; private String rows; private String columns; - private ArrayList<Point> dependencies; + private ArrayList<BytePoint> dependencies; private JPanel panelMatrix; private JLabel labelMatrix; private JTable matrix; + protected JMenuItem edit0, edit1, edit2, edit3; + protected int selectedRow, selectedCol; + protected DependencyTableModel dtm; /* Creates new form */ public JDialogDependencyMatrix(JFrame f, MainGUI _mgui, String title, String _columnDiag, String _rowDiag, - String _columns, String _rows, ArrayList<Point> _dependencies) { + String _columns, String _rows, ArrayList<BytePoint> _dependencies) { super(f, title, true); mgui = _mgui; @@ -97,7 +104,7 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen rows = _rows; columns = _columns; dependencies = new ArrayList<>(); - dependencies.addAll(dependencies); + dependencies.addAll(_dependencies); myInitComponents(); initComponents(); @@ -114,7 +121,7 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen setFont(new Font("Helvetica", Font.PLAIN, 14)); Container c = getContentPane(); - JTabbedPane mainPane = new JTabbedPane(); + mainPane = new JTabbedPane(); c.add(BorderLayout.CENTER, mainPane); // Tab to generate Matrix @@ -226,7 +233,11 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen csp.gridheight = 1; panelConfiguration.add(generateMatrix, csp); - mainPane.add("Configuration", panelConfiguration); + if (dependencies.size() == 0) { + mainPane.add("Configuration", panelConfiguration); + } + + // Tab to edit Matrix // Empty if no matrix panelMatrix = new JPanel(new BorderLayout()); @@ -235,9 +246,6 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen mainPane.add("Matrix", panelMatrix); - // main panel; - - initButtons(c, this); } @@ -265,6 +273,14 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen } else if (evt.getSource() == generateMatrix) { prepareMatrixElements(); makeMatrix(); + } else if (evt.getSource() == edit0) { + setValueInMatrix(0); + } else if (evt.getSource() == edit1) { + setValueInMatrix(1); + } else if (evt.getSource() == edit2) { + setValueInMatrix(2); + } else if (evt.getSource() == edit3) { + setValueInMatrix(3); } } @@ -377,16 +393,40 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen labelMatrix.setText("Matrix between " + rowDiag + " and " + columnDiag); - DependencyTableModel dtm = new DependencyTableModel(rows.split("\\$"), columns.split("\\$"), + dtm = new DependencyTableModel(rows.split("\\$"), columns.split("\\$"), dependencies); TableSorter sorterRTM = new TableSorter(dtm); matrix = new JTable(sorterRTM); + matrix.setCellSelectionEnabled(true); + matrix.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + int r = matrix.rowAtPoint(e.getPoint()); + int c = matrix.columnAtPoint(e.getPoint()); + selectedRow = -1; + selectedRow = -1; + if (r >= 0 && r < matrix.getRowCount() && c >= 0 && c < matrix.getColumnCount()) { + selectedRow = r; + selectedCol = c; + + if (e.getComponent() instanceof JTable) { + TraceManager.addDev("Popup at x=" + e.getX() + " y=" + e.getY() + " row=" + selectedRow + " col=" + selectedCol); + JPopupMenu popup = createDependencyPopup(); + popup.show(e.getComponent(), e.getX(), e.getY()); + } + } + } + }); matrix.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JScrollPane jspRTM = new JScrollPane(matrix); jspRTM.setWheelScrollingEnabled(true); jspRTM.getVerticalScrollBar().setUnitIncrement(10); panelMatrix.add(BorderLayout.CENTER, jspRTM); + if (mainPane != null) { + mainPane.setSelectedIndex(mainPane.getTabCount()-1); + } + } private void makeMatrixIssue(String s) { @@ -454,4 +494,71 @@ public class JDialogDependencyMatrix extends JDialogBase implements ActionListen } + + private JPopupMenu createDependencyPopup() { + JPopupMenu menu = new JPopupMenu("Change dependency"); + + edit0 = new JMenuItem("Remove dependency"); + edit0.setActionCommand("edit0"); + edit0.addActionListener(this); + menu.add(edit0); + + edit1 = new JMenuItem("->"); + edit1.setActionCommand("edit1"); + edit1.addActionListener(this); + menu.add(edit1); + + edit2 = new JMenuItem("<-"); + edit2.setActionCommand("edit2"); + edit2.addActionListener(this); + menu.add(edit2); + + edit3 = new JMenuItem("<->"); + edit3.setActionCommand("edit3"); + edit3.addActionListener(this); + menu.add(edit3); + + return menu; + } + + public void setValueInMatrix(int value) { + if ((selectedCol >= 0) && (selectedRow >= 0) & dtm != null) { + dtm.mySetValueAt(value, selectedRow, selectedCol-1); + matrix.repaint(); + } + } + + // Getting information of matrix + public boolean hasMatrix() { + return matrix != null; + } + + public String getRowDiag() { + return rowDiag; + } + + public String getColumnDiag() { + return columnDiag; + } + + public String getRows() { + return rows; + } + + public String getColumns() { + return columns; + } + + public ArrayList<BytePoint> getDependencies() { + + if (dtm == null) { + return null; + } + + return dtm.getNonNullPoints(); + } + + + + } \ No newline at end of file diff --git a/src/main/java/ui/window/JDialogRequirementTable.java b/src/main/java/ui/window/JDialogRequirementTable.java index e1da2af8f3d5437c38c8850d6a8ccc8162607d4c..432ff08c3f0f55663fc518e291e48b5a9e6e3321 100644 --- a/src/main/java/ui/window/JDialogRequirementTable.java +++ b/src/main/java/ui/window/JDialogRequirementTable.java @@ -81,6 +81,8 @@ public class JDialogRequirementTable extends JDialogBase implements ActionListen private ArrayList<JComboBox<String>> itemBoxes, sizeBoxes; private boolean data = false; + + /* Creates new form */ public JDialogRequirementTable(JFrame f, String title) { @@ -224,5 +226,6 @@ public class JDialogRequirementTable extends JDialogBase implements ActionListen return pts; } + } \ No newline at end of file