diff --git a/src/ui/tmlsd/TMLSDControllerInstance.java b/src/ui/tmlsd/TMLSDControllerInstance.java index a8a490be6a05ad53603fef720bea34fb8cffbece..eea800e08dd15c6fd7714b1bfcbc30ae56a884b3 100755 --- a/src/ui/tmlsd/TMLSDControllerInstance.java +++ b/src/ui/tmlsd/TMLSDControllerInstance.java @@ -52,6 +52,8 @@ import javax.swing.*; import org.w3c.dom.*; import java.awt.event.*; +import java.util.*; +import ui.tmldd.*; import myutil.*; import ui.*; import ui.window.*; @@ -93,51 +95,41 @@ public class TMLSDControllerInstance extends TMLSDInstance implements SwallowTGC public boolean editOndoubleClick(JFrame frame) { - String oldValue = name; - - JDialogAttribute jda = new JDialogAttribute( myAttributes, null, frame, "Setting attributes of " + this.name, "Attribute" ); - setJDialogOptions( jda ); - jda.setSize( 650, 375 ); - GraphicLib.centerOnParent( jda ); - jda.setVisible( true ); // blocked until dialog has been closed + //Get the list of ArchiPanels, then ArchiDiagramPanels then CPU nodes + TDiagramPanel ttdp = getTDiagramPanel(); + Vector<TMLArchiNode> availableCPUs = new Vector<TMLArchiNode>(); + Vector<TMLArchiPanel> archiPanels = getTDiagramPanel().getMGUI().getTMLArchiDiagramPanels(); + + for( TMLArchiPanel panel: archiPanels ) { + TraceManager.addDev( "FOUND TML ARCHI PANEL named: " + panel ); + } + TDiagramPanel archiDiagramPanel = archiPanels.get(0).getPanels().get(0); // one ArchiPanel = one ArchiDiagramPanel + LinkedList archiComponentsList = archiDiagramPanel.getComponentList(); + for( int k = 0; k < archiComponentsList.size(); k++ ) { + if( archiComponentsList.get(k) instanceof TMLArchiCPUNode ) { + availableCPUs.addElement( (TMLArchiNode) archiComponentsList.get(k) ); + TraceManager.addDev( "Found cpu node: " + archiComponentsList.get(k) ); + } + } + + JDialogTMLCPControllerInstance jdab = new JDialogTMLCPControllerInstance( myAttributes, availableCPUs, null, frame, + "Setting properties of " + name, "Attribute", this.name ); + setJDialogOptions(jdab); + jdab.setSize(650, 575); + GraphicLib.centerOnParent(jdab); + jdab.setVisible(true); // blocked until dialog has been closed + this.name = jdab.getName(); + this.mappedUnit = jdab.getMappedUnit(); //makeValue(); //if (oldValue.equals(value)) { - //return false; + //return false; //} - /*rescaled = true; + + //rescaled = true; return true; - }*/ - - /*String s = this.name; - if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { - if (!TAttribute.isAValidId(s, false, false)) { - JOptionPane.showMessageDialog( frame, - "Could not change the name of the instance: the new name is not a valid name", - "Error", JOptionPane.INFORMATION_MESSAGE ); - return false; - } - setName(s); - TraceManager.addDev( Integer.toString( connectingPoint.length ) ); - for( int i = 0; i < connectingPoint.length; i++ ) { - //for each connecting point connected to something - if( connectingPoint[i].getReferenceToConnector() != null ) { - TGConnectorMessageAsyncTMLSD connector = (TGConnectorMessageAsyncTMLSD) connectingPoint[i].getReferenceToConnector(); - if( connectingPoint[i].isSource() ) { - connector.setStartName(s); - TraceManager.addDev( connector.getConnectorName() ); - } - else { - connector.setEndName(s); - TraceManager.addDev( connector.getConnectorName() ); - } - } - } - return true; - }*/ - return true; //true means that the component has been modified } - protected void setJDialogOptions( JDialogAttribute jda ) { + protected void setJDialogOptions( JDialogTMLCPControllerInstance jda ) { jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC)); jda.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE)); @@ -152,7 +144,7 @@ public class TMLSDControllerInstance extends TMLSDInstance implements SwallowTGC jda.enableInitialValue(true); jda.enableRTLOTOSKeyword(true); jda.enableJavaKeyword(false); - jda.enableTMLKeyword(false); + //jda.enableTMLKeyword(false); } @Override public int getType() { diff --git a/src/ui/tmlsd/TMLSDStorageInstance.java b/src/ui/tmlsd/TMLSDStorageInstance.java index 779988cc9f6aa9d1b0d2958dbfe444da3d99d21a..443a7d342f646cb0baca22be6947a13a7972192e 100755 --- a/src/ui/tmlsd/TMLSDStorageInstance.java +++ b/src/ui/tmlsd/TMLSDStorageInstance.java @@ -93,79 +93,29 @@ public class TMLSDStorageInstance extends TMLSDInstance implements SwallowTGComp myImageIcon = IconManager.imgic500; } - /*public boolean editOndoubleClick(JFrame frame) { - - String oldValue = name; - - JDialogAttribute jda = new JDialogAttribute( myAttributes, null, frame, "Setting attributes of " + this.name, "Attribute" ); - setJDialogOptions( jda ); - jda.setSize( 650, 375 ); - GraphicLib.centerOnParent( jda ); - jda.setVisible( true ); // blocked until dialog has been closed - //makeValue(); - //if (oldValue.equals(value)) { - //return false; - //} - /*rescaled = true; - return true; - }*/ - - /*String s = this.name; - if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { - if (!TAttribute.isAValidId(s, false, false)) { - JOptionPane.showMessageDialog( frame, - "Could not change the name of the instance: the new name is not a valid name", - "Error", JOptionPane.INFORMATION_MESSAGE ); - return false; - } - setName(s); - TraceManager.addDev( Integer.toString( connectingPoint.length ) ); - for( int i = 0; i < connectingPoint.length; i++ ) { - //for each connecting point connected to something - if( connectingPoint[i].getReferenceToConnector() != null ) { - TGConnectorMessageAsyncTMLSD connector = (TGConnectorMessageAsyncTMLSD) connectingPoint[i].getReferenceToConnector(); - if( connectingPoint[i].isSource() ) { - connector.setStartName(s); - TraceManager.addDev( connector.getConnectorName() ); - } - else { - connector.setEndName(s); - TraceManager.addDev( connector.getConnectorName() ); - } - } - } - return true; - }*/ -// return true; //true means that the component has been modified - //} - public boolean editOndoubleClick(JFrame frame) { //Get the list of ArchiPanels, then ArchiDiagramPanels then Memory nodes TDiagramPanel ttdp = getTDiagramPanel(); - Vector<TMLArchiMemoryNode> memories = new Vector<TMLArchiMemoryNode>(); + Vector<TMLArchiNode> availableMemories = new Vector<TMLArchiNode>(); Vector<TMLArchiPanel> archiPanels = getTDiagramPanel().getMGUI().getTMLArchiDiagramPanels(); - for( TMLArchiPanel panel: archiPanels ) { - TraceManager.addDev( "FOUND TML ARCHI PANEL named: " + panel ); - } TDiagramPanel archiDiagramPanel = archiPanels.get(0).getPanels().get(0); // one ArchiPanel = one ArchiDiagramPanel LinkedList archiComponentsList = archiDiagramPanel.getComponentList(); for( int k = 0; k < archiComponentsList.size(); k++ ) { if( archiComponentsList.get(k) instanceof TMLArchiMemoryNode ) { - memories.addElement( (TMLArchiMemoryNode) archiComponentsList.get(k) ); - TraceManager.addDev( "Found memory node: " + archiComponentsList.get(k) ); + availableMemories.addElement( (TMLArchiNode) archiComponentsList.get(k) ); } } - //System.exit(0); - JDialogTMLCPSDInstance jdab = new JDialogTMLCPSDInstance( myAttributes, memories, null, frame, + JDialogTMLCPStorageInstance jdab = new JDialogTMLCPStorageInstance( myAttributes, availableMemories, null, frame, "Setting properties of " + name, "Attribute", this.name ); setJDialogOptions(jdab); jdab.setSize(650, 575); GraphicLib.centerOnParent(jdab); jdab.setVisible(true); // blocked until dialog has been closed this.name = jdab.getName(); + this.mappedUnit = jdab.getMappedUnit(); //makeValue(); //if (oldValue.equals(value)) { //return false; @@ -175,7 +125,7 @@ public class TMLSDStorageInstance extends TMLSDInstance implements SwallowTGComp return true; } - protected void setJDialogOptions( JDialogTMLCPSDInstance jda ) { + protected void setJDialogOptions( JDialogTMLCPStorageInstance jda ) { jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC)); jda.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE)); diff --git a/src/ui/tmlsd/TMLSDTransferInstance.java b/src/ui/tmlsd/TMLSDTransferInstance.java index 1be46397a2863487c59a2e9423d679841f75ab45..01694b9ac8072a1e06eaf02f69ab677e97ba8bc6 100755 --- a/src/ui/tmlsd/TMLSDTransferInstance.java +++ b/src/ui/tmlsd/TMLSDTransferInstance.java @@ -52,6 +52,8 @@ import javax.swing.*; import org.w3c.dom.*; import java.awt.event.*; +import java.util.*; +import ui.tmldd.*; import myutil.*; import ui.*; import ui.window.*; @@ -93,50 +95,51 @@ public class TMLSDTransferInstance extends TMLSDInstance implements SwallowTGCom public boolean editOndoubleClick(JFrame frame) { - String oldValue = name; - - JDialogAttribute jda = new JDialogAttribute( myAttributes, null, frame, "Setting attributes of " + this.name, "Attribute" ); - setJDialogOptions( jda ); - jda.setSize( 650, 375 ); - GraphicLib.centerOnParent( jda ); - jda.setVisible( true ); // blocked until dialog has been closed + //Get the list of ArchiPanels, then ArchiDiagramPanels then Memory nodes + TDiagramPanel ttdp = getTDiagramPanel(); + Vector<TMLArchiNode> availableTransferUnits = new Vector<TMLArchiNode>(); +// Vector<TMLArchiBridgeNode> availableBridges = new Vector<TMLArchiBridgeNode>(); + // Vector<TMLArchiDMANode> availableDMAs = new Vector<TMLArchiDMANode>(); + Vector<TMLArchiPanel> archiPanels = getTDiagramPanel().getMGUI().getTMLArchiDiagramPanels(); + + for( TMLArchiPanel panel: archiPanels ) { + TraceManager.addDev( "FOUND TML ARCHI PANEL named: " + panel ); + } + TDiagramPanel archiDiagramPanel = archiPanels.get(0).getPanels().get(0); // one ArchiPanel = one ArchiDiagramPanel + LinkedList archiComponentsList = archiDiagramPanel.getComponentList(); + for( int k = 0; k < archiComponentsList.size(); k++ ) { + if( archiComponentsList.get(k) instanceof TMLArchiBUSNode ) { + availableTransferUnits.addElement( (TMLArchiNode) archiComponentsList.get(k) ); + TraceManager.addDev( "Found bus node: " + archiComponentsList.get(k) ); + } + if( archiComponentsList.get(k) instanceof TMLArchiBridgeNode ) { + availableTransferUnits.addElement( (TMLArchiNode) archiComponentsList.get(k) ); + TraceManager.addDev( "Found bridge node: " + archiComponentsList.get(k) ); + } + if( archiComponentsList.get(k) instanceof TMLArchiDMANode ) { + availableTransferUnits.addElement( (TMLArchiNode) archiComponentsList.get(k) ); + TraceManager.addDev( "Found dma node: " + archiComponentsList.get(k) ); + } + } + + JDialogTMLCPTransferInstance jdab = new JDialogTMLCPTransferInstance( myAttributes, availableTransferUnits, null, frame, + "Setting properties of " + name, "Attribute", this.name ); + setJDialogOptions(jdab); + jdab.setSize(650, 575); + GraphicLib.centerOnParent(jdab); + jdab.setVisible(true); // blocked until dialog has been closed + this.name = jdab.getName(); + this.mappedUnit = jdab.getMappedUnit(); //makeValue(); //if (oldValue.equals(value)) { - //return false; + //return false; //} - /*rescaled = true; + + //rescaled = true; return true; - }*/ - - /*String s = this.name; - if ((s != null) && (s.length() > 0) && (!s.equals(oldValue))) { - if (!TAttribute.isAValidId(s, false, false)) { - JOptionPane.showMessageDialog( frame, - "Could not change the name of the instance: the new name is not a valid name", - "Error", JOptionPane.INFORMATION_MESSAGE ); - return false; - } - setName(s); - TraceManager.addDev( Integer.toString( connectingPoint.length ) ); - for( int i = 0; i < connectingPoint.length; i++ ) { - //for each connecting point connected to something - if( connectingPoint[i].getReferenceToConnector() != null ) { - TGConnectorMessageAsyncTMLSD connector = (TGConnectorMessageAsyncTMLSD) connectingPoint[i].getReferenceToConnector(); - if( connectingPoint[i].isSource() ) { - connector.setStartName(s); - TraceManager.addDev( connector.getConnectorName() ); - } - else { - connector.setEndName(s); - TraceManager.addDev( connector.getConnectorName() ); - } - } - } - return true; - }*/ - return true; //true means that the component has been modified } - protected void setJDialogOptions( JDialogAttribute jda ) { + + protected void setJDialogOptions( JDialogTMLCPTransferInstance jda ) { jda.addAccess(TAttribute.getStringAccess(TAttribute.PUBLIC)); jda.addAccess(TAttribute.getStringAccess(TAttribute.PRIVATE)); @@ -151,7 +154,7 @@ public class TMLSDTransferInstance extends TMLSDInstance implements SwallowTGCom jda.enableInitialValue(true); jda.enableRTLOTOSKeyword(true); jda.enableJavaKeyword(false); - jda.enableTMLKeyword(false); + //jda.enableTMLKeyword(false); } @Override public int getType() { diff --git a/src/ui/window/JDialogTMLCPControllerInstance.java b/src/ui/window/JDialogTMLCPControllerInstance.java new file mode 100755 index 0000000000000000000000000000000000000000..dcbb69cd8e997e6d4f0a5127f90e7cf47b4e9bfe --- /dev/null +++ b/src/ui/window/JDialogTMLCPControllerInstance.java @@ -0,0 +1,356 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici +* +* ludovic.apvrille AT telecom-paristech.fr +* andrea.enrici AT telecom-paristech.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. +* +* /** +* Class JDialogTMLCPControllerInstance +* Dialog for managing attributes, mapping and name of a SD instance +* Creation: 25/07/2014 +* @version 1.0 25/07/2014 +* @author Ludovic APVRILLE, Andrea ENRICI +* @see +*/ + +package ui.window; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import ui.*; +import ui.tmldd.*; +import myutil.*; + + +public class JDialogTMLCPControllerInstance extends JDialogTMLSDInstance implements ActionListener, ListSelectionListener { + + /** Creates new form */ + public JDialogTMLCPControllerInstance( Vector _attributes, Vector<TMLArchiNode> _availableUnits, Vector _forbidden, Frame f, String title, + String attrib, String _name ) { + super(_attributes, _availableUnits, _forbidden, f, title, attrib, _name ); + } + + @Override protected void initComponents() { + JTabbedPane tabbedPane = new JTabbedPane(); + Container c = getContentPane(); + + JPanel namePanel = new JPanel(); + JPanel panelAttr = new JPanel(new BorderLayout()); + JPanel panelMethod = new JPanel(new BorderLayout()); + GridBagLayout gridbag0 = new GridBagLayout(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagLayout gridbag2 = new GridBagLayout(); + GridBagLayout gridbag3 = new GridBagLayout(); + GridBagLayout gridbag4 = new GridBagLayout(); + GridBagLayout gridbag5 = new GridBagLayout(); + GridBagLayout gridbag6 = new GridBagLayout(); + GridBagLayout gridbag7 = new GridBagLayout(); + GridBagConstraints c0 = new GridBagConstraints(); + GridBagConstraints c1 = new GridBagConstraints(); + GridBagConstraints c2 = new GridBagConstraints(); + GridBagConstraints c3 = new GridBagConstraints(); + GridBagConstraints c4 = new GridBagConstraints(); + GridBagConstraints c5 = new GridBagConstraints(); + GridBagConstraints c6 = new GridBagConstraints(); + GridBagConstraints c7 = new GridBagConstraints(); + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + c.setLayout(gridbag0); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + + //Name panel + namePanel.add( new JLabel( "Name of storage instance:" ) ); + nameOfInstance = new JTextField( this.name, 30 ); + namePanel.add( nameOfInstance ); + + //Panel1 + + panel1 = new JPanel(); + panel1.setLayout(gridbag1); + panel1.setBorder(new javax.swing.border.TitledBorder("Adding " + attrib + "s")); + panel1.setPreferredSize(new Dimension(300, 250)); + + panel2 = new JPanel(); + panel2.setLayout(gridbag2); + panel2.setBorder(new javax.swing.border.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("access"), c1); + panel1.add(new JLabel("identifier"), c1); + if (attrib.equals("Attribute") || attrib.equals("Variable")) { + 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; + accessBox = new JComboBox(); + panel1.add(accessBox, c1); + identifierText = new JTextField(); + identifierText.setColumns(15); + identifierText.setEditable(true); + panel1.add(identifierText, c1); + + initialValue = new JTextField(); + initialValue.setColumns(5); + initialValue.setEditable(true); + + if (attrib.equals("Attribute") || attrib.equals("Variable")) { + panel1.add(new JLabel(" = "), c1); + panel1.add(initialValue, c1); + } + + panel1.add(new JLabel(" : "), c1); + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + typeBox = new JComboBox(); + typeBox.addActionListener(this); + panel1.add(typeBox, 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(attributes); + //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); + + // Mapping + panel3 = new JPanel(); + panel3.setLayout(gridbag3); + panel3.setBorder(new javax.swing.border.TitledBorder("Available storage units")); + panel3.setPreferredSize(new Dimension(300, 250)); + + panel4 = new JPanel(); + panel4.setLayout(gridbag2); + panel4.setBorder(new javax.swing.border.TitledBorder("Mapped storage unit")); + panel4.setPreferredSize(new Dimension(300, 250)); + + // first line panel3 + c3.gridwidth = 1; + c3.gridheight = 1; + c3.weighty = 1.0; + c3.weightx = 1.0; + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + c3.fill = GridBagConstraints.BOTH; + c3.gridheight = 3; + panel3.add(new JLabel(" "), c3); + + c3.gridwidth = 1; + c3.gridheight = 1; + c3.weighty = 1.0; + c3.weightx = 1.0; + c3.anchor = GridBagConstraints.CENTER; + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + panel3.add(new JLabel("Controller unit:"), c3); + + // second line panel3 + c3.fill = GridBagConstraints.HORIZONTAL; + + for( int j = 0; j < unitsPar.size(); j++ ) { + //TMLArchiMemoryNode mem = (TMLArchiMemoryNode) memoriesPar.get(j); + availableUnits.add( ( (TMLArchiNode) unitsPar.get(j)).getName() ); + } + referenceMemoriesName = new JComboBox( availableUnits ); + panel3.add( referenceMemoriesName, c3); + + // third line panel3 + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + c3.fill = GridBagConstraints.BOTH; + c3.gridheight = 3; + panel3.add( new JLabel(" "), c3 ); + + // fourth line panel3 + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + c3.fill = GridBagConstraints.BOTH; + c3.gridheight = 3; + + // fifth line panel3 + c3.gridheight = 1; + c3.fill = GridBagConstraints.HORIZONTAL; + addMappingButton = new JButton("Map storage unit"); + addMappingButton.addActionListener(this); + panel3.add( addMappingButton, c3 ); + + // 1st line panel4 + + listMappedUnits = new JList( mappedUnits ); + listMappedUnits.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + listMappedUnits.addListSelectionListener( this ); + scrollPane = new JScrollPane( listMappedUnits ); + scrollPane.setSize( 300, 250 ); + c4.gridwidth = GridBagConstraints.REMAINDER; //end row + c4.fill = GridBagConstraints.BOTH; + c4.gridheight = 5; + c4.weighty = 10.0; + c4.weightx = 10.0; + panel4.add(scrollPane, c4); + + // 2nd line panel4 + c4.weighty = 1.0; + c4.weightx = 1.0; + c4.fill = GridBagConstraints.BOTH; + c4.gridheight = 1; + panel4.add(new JLabel(""), c4); + + // third line panel4 + c4.gridwidth = GridBagConstraints.REMAINDER; //end row + c4.fill = GridBagConstraints.HORIZONTAL; + removeMappingButton = new JButton( "Remove storage unit" ); + removeMappingButton.addActionListener( this ); + panel4.add( removeMappingButton, c4 ); + + // main panel; + panelAttr.add(panel1, BorderLayout.WEST); + panelAttr.add(panel2, BorderLayout.EAST); + tabbedPane.addTab("Attributes", panelAttr); + + //if (hasMethods) { + panelMethod.add(panel3, BorderLayout.WEST); + panelMethod.add(panel4, BorderLayout.EAST); + tabbedPane.addTab("Mapping", panelMethod); + //} + + tabbedPane.setSelectedIndex(tab); + + //c.add(panel1, c0); + //c.add(panel2, c0); + + c0.gridwidth = 1; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + + c.add(namePanel, c0); + + c.add(tabbedPane, c0); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + closeButton = new JButton("Save and Close", IconManager.imgic25); + //closeButton.setPreferredSize(new Dimension(600, 50)); + closeButton.addActionListener(this); + c.add(closeButton, c0); + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + cancelButton = new JButton("Cancel", IconManager.imgic27); + cancelButton.addActionListener(this); + c.add(cancelButton, c0); + } + + @Override public void closeDialog() { + cancelled = false; + attributesPar.removeAllElements(); + for(int i=0; i<attributes.size(); i++) { + attributesPar.addElement(attributes.elementAt(i)); + } + this.name = nameOfInstance.getText(); + if( mappedUnits.size() > 1 ) { + JOptionPane.showMessageDialog( frame, "Only one CPU unit can be mapped per each Controller instance", + "Error", JOptionPane.INFORMATION_MESSAGE ); + return; + } + dispose(); + } + +} //End of class diff --git a/src/ui/window/JDialogTMLCPStorageInstance.java b/src/ui/window/JDialogTMLCPStorageInstance.java index 9ec6d28f4833f4097e91a172e1aa2e00e8e97c43..2aff3262b5d9e72cfe56f1cf5a92506a260cf9a0 100755 --- a/src/ui/window/JDialogTMLCPStorageInstance.java +++ b/src/ui/window/JDialogTMLCPStorageInstance.java @@ -58,85 +58,15 @@ import ui.tmldd.*; import myutil.*; -public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements ActionListener, ListSelectionListener { +public class JDialogTMLCPStorageInstance extends JDialogTMLSDInstance implements ActionListener, ListSelectionListener { - private Vector attributes, attributesPar, forbidden, initValues; - private Vector memoriesPar; - private Vector<String> mappedMemories = new Vector<String>(); - private Vector<String> availableMemories = new Vector<String>(); - private boolean checkKeyword, checkJavaKeyword; - - private boolean cancelled = false; - - private JPanel panel1, panel2; - - private Frame frame; - private int tab; - - private String attrib; // "Attributes", "Gates", etc. - - //Name panel - private JTextField nameOfInstance; - - // Panel1 - private JComboBox accessBox, typeBox; - private JTextField identifierText; - private JTextField initialValue; - private JButton addButton; - - //Panel2 - private JList listAttribute; - private JButton upButton; - private JButton downButton; - private JButton removeButton; - - //Panel 3 - private JButton removeMappingButton; - private JComboBox referenceMemoriesName; - - - // Mapping of storage units - private JPanel panel3, panel4; - private JButton addMappingButton; - private JList listStorageUnits; - - // Main Panel - private JButton closeButton; - private JButton cancelButton; - - private String name = ""; - /** Creates new form */ - public JDialogTMLCPStorageInstance( Vector _attributes, Vector<TMLArchiMemoryNode> _memories, Vector _forbidden, Frame f, String title, + public JDialogTMLCPStorageInstance( Vector _attributes, Vector<TMLArchiNode> _availableUnits, Vector _forbidden, Frame f, String title, String attrib, String _name ) { - super(f, title, true); - frame = f; - attributesPar = _attributes; - memoriesPar = _memories; - this.name = _name; - forbidden = _forbidden; - initValues = new Vector(); - this.attrib = attrib; - - attributes = new Vector(); - - for( int i = 0; i < attributesPar.size(); i++ ) { - attributes.addElement( ( (TAttribute)( attributesPar.elementAt(i) ) ).makeClone() ); - } - - initComponents(); - myInitComponents(); - pack(); + super( _attributes, _availableUnits, _forbidden, f, title, attrib, _name ); } - private void myInitComponents() { - removeButton.setEnabled(false); - upButton.setEnabled(false); - downButton.setEnabled(false); - removeMappingButton.setEnabled(false); - } - - private void initComponents() { + @Override protected void initComponents() { JTabbedPane tabbedPane = new JTabbedPane(); Container c = getContentPane(); @@ -316,11 +246,10 @@ public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements // second line panel3 c3.fill = GridBagConstraints.HORIZONTAL; - for( int j = 0; j < memoriesPar.size(); j++ ) { - TMLArchiMemoryNode mem = (TMLArchiMemoryNode) memoriesPar.get(j); - availableMemories.add( mem.getName() ); + for( int j = 0; j < unitsPar.size(); j++ ) { + availableUnits.add( ( (TMLArchiNode) unitsPar.get(j)).getName() ); } - referenceMemoriesName = new JComboBox( availableMemories ); + referenceMemoriesName = new JComboBox( availableUnits ); panel3.add( referenceMemoriesName, c3); // third line panel3 @@ -343,10 +272,10 @@ public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements // 1st line panel4 - listStorageUnits = new JList( mappedMemories ); - listStorageUnits.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); - listStorageUnits.addListSelectionListener( this ); - scrollPane = new JScrollPane( listStorageUnits ); + listMappedUnits = new JList( mappedUnits ); + listMappedUnits.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + listMappedUnits.addListSelectionListener( this ); + scrollPane = new JScrollPane( listMappedUnits ); scrollPane.setSize( 300, 250 ); c4.gridwidth = GridBagConstraints.REMAINDER; //end row c4.fill = GridBagConstraints.BOTH; @@ -408,258 +337,19 @@ public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements c.add(cancelButton, c0); } - public void actionPerformed(ActionEvent evt) { - if (evt.getSource() == typeBox) { - boolean b = ((Boolean)(initValues.elementAt(typeBox.getSelectedIndex()))).booleanValue(); - initialValue.setEnabled(b); - return; - } - - - //String command = evt.getActionCommand(); - - // Compare the action command to the known actions. - if (evt.getSource() == closeButton) { - closeDialog(); - } else if (evt.getSource() == addButton) { - addAttribute(); - } else if (evt.getSource() == cancelButton) { - cancelDialog(); - } else if (evt.getSource() == removeButton) { - removeAttribute(); - } else if (evt.getSource() == downButton) { - downAttribute(); - } else if (evt.getSource() == upButton) { - upAttribute(); - } else if (evt.getSource() == addMappingButton) { - addMappedUnit(); - } else if (evt.getSource() == removeMappingButton) { - removeMappedUnit(); - } - } - - public void addAccess(String s) { - accessBox.addItem(s); - } - - public void addType(String s) { - initValues.add(new Boolean(true)); - typeBox.addItem(s); - } - - public void addType(String s, boolean b) { - initValues.add(new Boolean(b)); - typeBox.addItem(s); - } - - public void enableInitialValue(boolean b) { - initialValue.setEnabled(b); - } - - public void enableRTLOTOSKeyword(boolean b) { - checkKeyword = !b; - } - - public void enableJavaKeyword(boolean b) { - checkJavaKeyword = !b; - } - - public void addAttribute() { - Object o1 = accessBox.getSelectedItem(); - Object o2 = typeBox.getSelectedItem(); - String s = identifierText.getText(); - String value = initialValue.getText(); - TAttribute a; - - if( s.length() > 0 ) { - if( ( TAttribute.isAValidId( s, checkKeyword, checkJavaKeyword ) ) && ( TAttribute.notIn(s, forbidden ) ) ) { - int i = TAttribute.getAccess(o1.toString()); - int j = TAttribute.getAvatarType(o2.toString()); - if( ( j == TAttribute.ARRAY_NAT ) && ( value.length() < 1 ) ) { - value = "2"; - } - if ((i != -1) && (j!= -1)) { - if ((value.length() < 1) || (initialValue.isEnabled() == false)) { - value = ""; - } - else { - if( !TAttribute.isAValidInitialValue(j, value) ) { - JOptionPane.showMessageDialog( frame, "The initial value is not valid", "Error", JOptionPane.INFORMATION_MESSAGE ); - return; - } - } - if( j == TAttribute.OTHER ) { - a = new TAttribute(i, s, value, o2.toString()); - a.isAvatar = true; - //System.out.println("New attribute: " + o2.toString()); - } - else { - a = new TAttribute(i, s, value, j); - a.isAvatar = true; - } - //checks whether the same attribute already belongs to the list - int index = attributes.size(); - if( attributes.contains(a) ) { - index = attributes.indexOf(a); - a = (TAttribute)(attributes.elementAt(index)); - a.setAccess(i); - if( j == TAttribute.OTHER ) { - a.setTypeOther(o2.toString()); - } - a.setType(j); - a.setInitialValue(value); - //attributes.removeElementAt(index); - } - else { - attributes.add(index, a); - } - listAttribute.setListData(attributes); - identifierText.setText(""); - } - else { - JOptionPane.showMessageDialog( frame, "Bad access / type", "Error", JOptionPane.INFORMATION_MESSAGE); - return; - } - } - else { - JOptionPane.showMessageDialog( frame, "Bad identifier: identifier already in use, or invalid identifier", - "Error", JOptionPane.INFORMATION_MESSAGE); - return; - } - } - else { - JOptionPane.showMessageDialog( frame, "Bad identifier", "Error", JOptionPane.INFORMATION_MESSAGE ); - return; - } - } //End of method - - public void addMappedUnit() { - - //TraceManager.addDev( "**************************" ); - //TraceManager.addDev( referenceMemoriesName.getSelectedItem().toString() ); - //TraceManager.addDev( "**************************" ); - removeMappingButton.setEnabled( true ); - String s = referenceMemoriesName.getSelectedItem().toString(); - mappedMemories.add(s); - listStorageUnits.setListData( mappedMemories ); - } - - public void removeMappedUnit() { - mappedMemories.removeElementAt( 0 ); - listStorageUnits.setListData( mappedMemories ); - removeMappingButton.setEnabled( false ); - } - - public void removeAttribute() { - int i = listAttribute.getSelectedIndex() ; - if (i!= -1) { - TAttribute a = (TAttribute)(attributes.elementAt(i)); - a.setAccess(-1); - attributes.removeElementAt(i); - listAttribute.setListData(attributes); - } - } - - public void downAttribute() { - int i = listAttribute.getSelectedIndex(); - if ((i!= -1) && (i != attributes.size() - 1)) { - Object o = attributes.elementAt(i); - attributes.removeElementAt(i); - attributes.insertElementAt(o, i+1); - listAttribute.setListData(attributes); - listAttribute.setSelectedIndex(i+1); - } - } - - public void upAttribute() { - int i = listAttribute.getSelectedIndex(); - //TraceManager.addDev("Selected index = " + i); - if (i > 0) { - //TraceManager.addDev("Modifying ..."); - Object o = attributes.elementAt(i); - attributes.removeElementAt(i); - attributes.insertElementAt(o, i-1); - listAttribute.setListData(attributes); - listAttribute.setSelectedIndex(i-1); - } - } - - public void closeDialog() { + @Override public void closeDialog() { cancelled = false; attributesPar.removeAllElements(); for(int i=0; i<attributes.size(); i++) { attributesPar.addElement(attributes.elementAt(i)); } this.name = nameOfInstance.getText(); - if( mappedMemories.size() > 1 ) { - JOptionPane.showMessageDialog( frame, "Only one memory can be mapped per storage unit", "Error", JOptionPane.INFORMATION_MESSAGE ); + if( mappedUnits.size() > 1 ) { + JOptionPane.showMessageDialog( frame, "Only one Memory unit can be mapped per each Storage instance", + "Error", JOptionPane.INFORMATION_MESSAGE ); return; } dispose(); } - public boolean hasBeenCancelled() { - return cancelled; - } - - public void cancelDialog() { - cancelled = true; - 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 { - TAttribute a = (TAttribute)(attributes.elementAt(i)); - identifierText.setText(a.getId()); - initialValue.setText(a.getInitialValue()); - select(accessBox, a.getStringAccess(a.getAccess())); - if (a.getType() == TAttribute.OTHER) { - select(typeBox, a.getTypeOther()); - } else { - select(typeBox, a.getStringAvatarType(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); - } - } - - } //End of method - - public void select(JComboBox jcb, String text) { - String s; - for(int i=0; i<jcb.getItemCount(); i++) { - s = (String)(jcb.getItemAt(i)); - //System.out.println("String found: *" + s + "* *" + text + "*"); - if (s.equals(text)) { - jcb.setSelectedIndex(i); - return; - } - } - } - - public String getName() { - return this.name; - } - - public String getMappedMemory() { - if( mappedMemories.size() == 1 ) { - return mappedMemories.get(0); - } - return ""; - } } //End of class diff --git a/src/ui/window/JDialogTMLCPTransferInstance.java b/src/ui/window/JDialogTMLCPTransferInstance.java index 9ec6d28f4833f4097e91a172e1aa2e00e8e97c43..515d6b9848458b378a88fb2c15fe9772adcd9cde 100755 --- a/src/ui/window/JDialogTMLCPTransferInstance.java +++ b/src/ui/window/JDialogTMLCPTransferInstance.java @@ -37,7 +37,7 @@ * knowledge of the CeCILL license and that you accept its terms. * * /** -* Class JDialogTMLCPStorageInstance +* Class JDialogTMLCPTransferInstance * Dialog for managing attributes, mapping and name of a SD instance * Creation: 25/07/2014 * @version 1.0 25/07/2014 @@ -58,85 +58,15 @@ import ui.tmldd.*; import myutil.*; -public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements ActionListener, ListSelectionListener { +public class JDialogTMLCPTransferInstance extends JDialogTMLSDInstance implements ActionListener, ListSelectionListener { - private Vector attributes, attributesPar, forbidden, initValues; - private Vector memoriesPar; - private Vector<String> mappedMemories = new Vector<String>(); - private Vector<String> availableMemories = new Vector<String>(); - private boolean checkKeyword, checkJavaKeyword; - - private boolean cancelled = false; - - private JPanel panel1, panel2; - - private Frame frame; - private int tab; - - private String attrib; // "Attributes", "Gates", etc. - - //Name panel - private JTextField nameOfInstance; - - // Panel1 - private JComboBox accessBox, typeBox; - private JTextField identifierText; - private JTextField initialValue; - private JButton addButton; - - //Panel2 - private JList listAttribute; - private JButton upButton; - private JButton downButton; - private JButton removeButton; - - //Panel 3 - private JButton removeMappingButton; - private JComboBox referenceMemoriesName; - - - // Mapping of storage units - private JPanel panel3, panel4; - private JButton addMappingButton; - private JList listStorageUnits; - - // Main Panel - private JButton closeButton; - private JButton cancelButton; - - private String name = ""; - /** Creates new form */ - public JDialogTMLCPStorageInstance( Vector _attributes, Vector<TMLArchiMemoryNode> _memories, Vector _forbidden, Frame f, String title, + public JDialogTMLCPTransferInstance( Vector _attributes, Vector<TMLArchiNode> _availableUnits, Vector _forbidden, Frame f, String title, String attrib, String _name ) { - super(f, title, true); - frame = f; - attributesPar = _attributes; - memoriesPar = _memories; - this.name = _name; - forbidden = _forbidden; - initValues = new Vector(); - this.attrib = attrib; - - attributes = new Vector(); - - for( int i = 0; i < attributesPar.size(); i++ ) { - attributes.addElement( ( (TAttribute)( attributesPar.elementAt(i) ) ).makeClone() ); - } - - initComponents(); - myInitComponents(); - pack(); + super( _attributes, _availableUnits, _forbidden, f, title, attrib, _name ); } - private void myInitComponents() { - removeButton.setEnabled(false); - upButton.setEnabled(false); - downButton.setEnabled(false); - removeMappingButton.setEnabled(false); - } - - private void initComponents() { + @Override protected void initComponents() { JTabbedPane tabbedPane = new JTabbedPane(); Container c = getContentPane(); @@ -311,16 +241,16 @@ public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements c3.weightx = 1.0; c3.anchor = GridBagConstraints.CENTER; c3.gridwidth = GridBagConstraints.REMAINDER; //end row - panel3.add(new JLabel("Storage unit:"), c3); + panel3.add(new JLabel("Transfer unit:"), c3); // second line panel3 c3.fill = GridBagConstraints.HORIZONTAL; - for( int j = 0; j < memoriesPar.size(); j++ ) { - TMLArchiMemoryNode mem = (TMLArchiMemoryNode) memoriesPar.get(j); - availableMemories.add( mem.getName() ); + for( int j = 0; j < unitsPar.size(); j++ ) { + //TMLArchiMemoryNode mem = (TMLArchiMemoryNode) unitsPar.get(j); + availableUnits.add( ((TMLArchiNode) unitsPar.get(j)).getName() ); } - referenceMemoriesName = new JComboBox( availableMemories ); + referenceMemoriesName = new JComboBox( availableUnits ); panel3.add( referenceMemoriesName, c3); // third line panel3 @@ -337,16 +267,16 @@ public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements // fifth line panel3 c3.gridheight = 1; c3.fill = GridBagConstraints.HORIZONTAL; - addMappingButton = new JButton("Map storage unit"); + addMappingButton = new JButton("Map transfer unit"); addMappingButton.addActionListener(this); panel3.add( addMappingButton, c3 ); // 1st line panel4 - listStorageUnits = new JList( mappedMemories ); - listStorageUnits.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); - listStorageUnits.addListSelectionListener( this ); - scrollPane = new JScrollPane( listStorageUnits ); + listMappedUnits = new JList( mappedUnits ); + listMappedUnits.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + listMappedUnits.addListSelectionListener( this ); + scrollPane = new JScrollPane( listMappedUnits ); scrollPane.setSize( 300, 250 ); c4.gridwidth = GridBagConstraints.REMAINDER; //end row c4.fill = GridBagConstraints.BOTH; @@ -408,258 +338,19 @@ public class JDialogTMLCPStorageInstance extends javax.swing.JDialog implements c.add(cancelButton, c0); } - public void actionPerformed(ActionEvent evt) { - if (evt.getSource() == typeBox) { - boolean b = ((Boolean)(initValues.elementAt(typeBox.getSelectedIndex()))).booleanValue(); - initialValue.setEnabled(b); - return; - } - - - //String command = evt.getActionCommand(); - - // Compare the action command to the known actions. - if (evt.getSource() == closeButton) { - closeDialog(); - } else if (evt.getSource() == addButton) { - addAttribute(); - } else if (evt.getSource() == cancelButton) { - cancelDialog(); - } else if (evt.getSource() == removeButton) { - removeAttribute(); - } else if (evt.getSource() == downButton) { - downAttribute(); - } else if (evt.getSource() == upButton) { - upAttribute(); - } else if (evt.getSource() == addMappingButton) { - addMappedUnit(); - } else if (evt.getSource() == removeMappingButton) { - removeMappedUnit(); - } - } - - public void addAccess(String s) { - accessBox.addItem(s); - } - - public void addType(String s) { - initValues.add(new Boolean(true)); - typeBox.addItem(s); - } - - public void addType(String s, boolean b) { - initValues.add(new Boolean(b)); - typeBox.addItem(s); - } - - public void enableInitialValue(boolean b) { - initialValue.setEnabled(b); - } - - public void enableRTLOTOSKeyword(boolean b) { - checkKeyword = !b; - } - - public void enableJavaKeyword(boolean b) { - checkJavaKeyword = !b; - } - - public void addAttribute() { - Object o1 = accessBox.getSelectedItem(); - Object o2 = typeBox.getSelectedItem(); - String s = identifierText.getText(); - String value = initialValue.getText(); - TAttribute a; - - if( s.length() > 0 ) { - if( ( TAttribute.isAValidId( s, checkKeyword, checkJavaKeyword ) ) && ( TAttribute.notIn(s, forbidden ) ) ) { - int i = TAttribute.getAccess(o1.toString()); - int j = TAttribute.getAvatarType(o2.toString()); - if( ( j == TAttribute.ARRAY_NAT ) && ( value.length() < 1 ) ) { - value = "2"; - } - if ((i != -1) && (j!= -1)) { - if ((value.length() < 1) || (initialValue.isEnabled() == false)) { - value = ""; - } - else { - if( !TAttribute.isAValidInitialValue(j, value) ) { - JOptionPane.showMessageDialog( frame, "The initial value is not valid", "Error", JOptionPane.INFORMATION_MESSAGE ); - return; - } - } - if( j == TAttribute.OTHER ) { - a = new TAttribute(i, s, value, o2.toString()); - a.isAvatar = true; - //System.out.println("New attribute: " + o2.toString()); - } - else { - a = new TAttribute(i, s, value, j); - a.isAvatar = true; - } - //checks whether the same attribute already belongs to the list - int index = attributes.size(); - if( attributes.contains(a) ) { - index = attributes.indexOf(a); - a = (TAttribute)(attributes.elementAt(index)); - a.setAccess(i); - if( j == TAttribute.OTHER ) { - a.setTypeOther(o2.toString()); - } - a.setType(j); - a.setInitialValue(value); - //attributes.removeElementAt(index); - } - else { - attributes.add(index, a); - } - listAttribute.setListData(attributes); - identifierText.setText(""); - } - else { - JOptionPane.showMessageDialog( frame, "Bad access / type", "Error", JOptionPane.INFORMATION_MESSAGE); - return; - } - } - else { - JOptionPane.showMessageDialog( frame, "Bad identifier: identifier already in use, or invalid identifier", - "Error", JOptionPane.INFORMATION_MESSAGE); - return; - } - } - else { - JOptionPane.showMessageDialog( frame, "Bad identifier", "Error", JOptionPane.INFORMATION_MESSAGE ); - return; - } - } //End of method - - public void addMappedUnit() { - - //TraceManager.addDev( "**************************" ); - //TraceManager.addDev( referenceMemoriesName.getSelectedItem().toString() ); - //TraceManager.addDev( "**************************" ); - removeMappingButton.setEnabled( true ); - String s = referenceMemoriesName.getSelectedItem().toString(); - mappedMemories.add(s); - listStorageUnits.setListData( mappedMemories ); - } - - public void removeMappedUnit() { - mappedMemories.removeElementAt( 0 ); - listStorageUnits.setListData( mappedMemories ); - removeMappingButton.setEnabled( false ); - } - - public void removeAttribute() { - int i = listAttribute.getSelectedIndex() ; - if (i!= -1) { - TAttribute a = (TAttribute)(attributes.elementAt(i)); - a.setAccess(-1); - attributes.removeElementAt(i); - listAttribute.setListData(attributes); - } - } - - public void downAttribute() { - int i = listAttribute.getSelectedIndex(); - if ((i!= -1) && (i != attributes.size() - 1)) { - Object o = attributes.elementAt(i); - attributes.removeElementAt(i); - attributes.insertElementAt(o, i+1); - listAttribute.setListData(attributes); - listAttribute.setSelectedIndex(i+1); - } - } - - public void upAttribute() { - int i = listAttribute.getSelectedIndex(); - //TraceManager.addDev("Selected index = " + i); - if (i > 0) { - //TraceManager.addDev("Modifying ..."); - Object o = attributes.elementAt(i); - attributes.removeElementAt(i); - attributes.insertElementAt(o, i-1); - listAttribute.setListData(attributes); - listAttribute.setSelectedIndex(i-1); - } - } - - public void closeDialog() { + @Override public void closeDialog() { cancelled = false; attributesPar.removeAllElements(); for(int i=0; i<attributes.size(); i++) { attributesPar.addElement(attributes.elementAt(i)); } this.name = nameOfInstance.getText(); - if( mappedMemories.size() > 1 ) { - JOptionPane.showMessageDialog( frame, "Only one memory can be mapped per storage unit", "Error", JOptionPane.INFORMATION_MESSAGE ); + if( mappedUnits.size() > 1 ) { + JOptionPane.showMessageDialog( frame, "Only one Bus/Bridge unit can be mapped per Transfer instance", + "Error", JOptionPane.INFORMATION_MESSAGE ); return; } dispose(); } - public boolean hasBeenCancelled() { - return cancelled; - } - - public void cancelDialog() { - cancelled = true; - 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 { - TAttribute a = (TAttribute)(attributes.elementAt(i)); - identifierText.setText(a.getId()); - initialValue.setText(a.getInitialValue()); - select(accessBox, a.getStringAccess(a.getAccess())); - if (a.getType() == TAttribute.OTHER) { - select(typeBox, a.getTypeOther()); - } else { - select(typeBox, a.getStringAvatarType(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); - } - } - - } //End of method - - public void select(JComboBox jcb, String text) { - String s; - for(int i=0; i<jcb.getItemCount(); i++) { - s = (String)(jcb.getItemAt(i)); - //System.out.println("String found: *" + s + "* *" + text + "*"); - if (s.equals(text)) { - jcb.setSelectedIndex(i); - return; - } - } - } - - public String getName() { - return this.name; - } - - public String getMappedMemory() { - if( mappedMemories.size() == 1 ) { - return mappedMemories.get(0); - } - return ""; - } } //End of class diff --git a/src/ui/window/JDialogTMLSDInstance.java b/src/ui/window/JDialogTMLSDInstance.java new file mode 100755 index 0000000000000000000000000000000000000000..3f3f5d87fc9ac72e7dfe605ea331394f03e2672e --- /dev/null +++ b/src/ui/window/JDialogTMLSDInstance.java @@ -0,0 +1,383 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, Andrea Enrici +* +* ludovic.apvrille AT telecom-paristech.fr +* andrea.enrici AT telecom-paristech.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. +* +* /** +* Class JDialogTMLSDInstance +* Dialog for managing attributes, mapping and name of a SD instance +* Creation: 25/07/2014 +* @version 1.0 25/07/2014 +* @author Ludovic APVRILLE, Andrea ENRICI +* @see +*/ + +package ui.window; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.event.*; +import java.util.*; + +import ui.*; +import ui.tmldd.*; +import myutil.*; + + +public abstract class JDialogTMLSDInstance extends javax.swing.JDialog implements ActionListener, ListSelectionListener { + + protected Vector attributes, attributesPar, forbidden, initValues; + protected Vector unitsPar; + protected Vector<String> mappedUnits = new Vector<String>(); + protected Vector<String> availableUnits = new Vector<String>(); + protected boolean checkKeyword, checkJavaKeyword; + + protected boolean cancelled = false; + + protected JPanel panel1, panel2; + + protected Frame frame; + protected int tab; + + protected String attrib; // "Attributes", "Gates", etc. + + //Name panel + protected JTextField nameOfInstance; + + // Panel1 + protected JComboBox accessBox, typeBox; + protected JTextField identifierText; + protected JTextField initialValue; + protected JButton addButton; + + //Panel2 + protected JList listAttribute; + protected JButton upButton; + protected JButton downButton; + protected JButton removeButton; + + //Panel 3 + protected JButton removeMappingButton; + protected JComboBox referenceMemoriesName; + + + // Mapping of storage units + protected JPanel panel3, panel4; + protected JButton addMappingButton; + protected JList listMappedUnits; + + // Main Panel + protected JButton closeButton; + protected JButton cancelButton; + + protected String name = ""; + + /** Creates new form */ + public JDialogTMLSDInstance( Vector _attributes, Vector<TMLArchiNode> _availableUnits, Vector _forbidden, Frame f, String title, + String attrib, String _name ) { + super(f, title, true); + frame = f; + attributesPar = _attributes; + unitsPar = _availableUnits; + this.name = _name; + forbidden = _forbidden; + initValues = new Vector(); + this.attrib = attrib; + + attributes = new Vector(); + + for( int i = 0; i < attributesPar.size(); i++ ) { + attributes.addElement( ( (TAttribute)( attributesPar.elementAt(i) ) ).makeClone() ); + } + + initComponents(); + myInitComponents(); + pack(); + } + + protected void myInitComponents() { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + removeMappingButton.setEnabled(false); + } + + protected abstract void initComponents(); + + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == typeBox) { + boolean b = ((Boolean)(initValues.elementAt(typeBox.getSelectedIndex()))).booleanValue(); + initialValue.setEnabled(b); + return; + } + + + //String command = evt.getActionCommand(); + + // Compare the action command to the known actions. + if (evt.getSource() == closeButton) { + closeDialog(); + } else if (evt.getSource() == addButton) { + addAttribute(); + } else if (evt.getSource() == cancelButton) { + cancelDialog(); + } else if (evt.getSource() == removeButton) { + removeAttribute(); + } else if (evt.getSource() == downButton) { + downAttribute(); + } else if (evt.getSource() == upButton) { + upAttribute(); + } else if (evt.getSource() == addMappingButton) { + addMappedUnit(); + } else if (evt.getSource() == removeMappingButton) { + removeMappedUnit(); + } + } + + public void addAccess(String s) { + accessBox.addItem(s); + } + + public void addType(String s) { + initValues.add(new Boolean(true)); + typeBox.addItem(s); + } + + public void addType(String s, boolean b) { + initValues.add(new Boolean(b)); + typeBox.addItem(s); + } + + public void enableInitialValue(boolean b) { + initialValue.setEnabled(b); + } + + public void enableRTLOTOSKeyword(boolean b) { + checkKeyword = !b; + } + + public void enableJavaKeyword(boolean b) { + checkJavaKeyword = !b; + } + + public void addAttribute() { + Object o1 = accessBox.getSelectedItem(); + Object o2 = typeBox.getSelectedItem(); + String s = identifierText.getText(); + String value = initialValue.getText(); + TAttribute a; + + if( s.length() > 0 ) { + if( ( TAttribute.isAValidId( s, checkKeyword, checkJavaKeyword ) ) && ( TAttribute.notIn(s, forbidden ) ) ) { + int i = TAttribute.getAccess(o1.toString()); + int j = TAttribute.getAvatarType(o2.toString()); + if( ( j == TAttribute.ARRAY_NAT ) && ( value.length() < 1 ) ) { + value = "2"; + } + if ((i != -1) && (j!= -1)) { + if ((value.length() < 1) || (initialValue.isEnabled() == false)) { + value = ""; + } + else { + if( !TAttribute.isAValidInitialValue(j, value) ) { + JOptionPane.showMessageDialog( frame, "The initial value is not valid", "Error", JOptionPane.INFORMATION_MESSAGE ); + return; + } + } + if( j == TAttribute.OTHER ) { + a = new TAttribute(i, s, value, o2.toString()); + a.isAvatar = true; + //System.out.println("New attribute: " + o2.toString()); + } + else { + a = new TAttribute(i, s, value, j); + a.isAvatar = true; + } + //checks whether the same attribute already belongs to the list + int index = attributes.size(); + if( attributes.contains(a) ) { + index = attributes.indexOf(a); + a = (TAttribute)(attributes.elementAt(index)); + a.setAccess(i); + if( j == TAttribute.OTHER ) { + a.setTypeOther(o2.toString()); + } + a.setType(j); + a.setInitialValue(value); + //attributes.removeElementAt(index); + } + else { + attributes.add(index, a); + } + listAttribute.setListData(attributes); + identifierText.setText(""); + } + else { + JOptionPane.showMessageDialog( frame, "Bad access / type", "Error", JOptionPane.INFORMATION_MESSAGE); + return; + } + } + else { + JOptionPane.showMessageDialog( frame, "Bad identifier: identifier already in use, or invalid identifier", + "Error", JOptionPane.INFORMATION_MESSAGE); + return; + } + } + else { + JOptionPane.showMessageDialog( frame, "Bad identifier", "Error", JOptionPane.INFORMATION_MESSAGE ); + return; + } + } //End of method + + public void addMappedUnit() { + + //TraceManager.addDev( "**************************" ); + //TraceManager.addDev( referenceMemoriesName.getSelectedItem().toString() ); + //TraceManager.addDev( "**************************" ); + removeMappingButton.setEnabled( true ); + String s = referenceMemoriesName.getSelectedItem().toString(); + mappedUnits.add(s); + listMappedUnits.setListData( mappedUnits ); + } + + public void removeMappedUnit() { + mappedUnits.removeElementAt( 0 ); + listMappedUnits.setListData( mappedUnits ); + removeMappingButton.setEnabled( false ); + } + + public void removeAttribute() { + int i = listAttribute.getSelectedIndex() ; + if (i!= -1) { + TAttribute a = (TAttribute)(attributes.elementAt(i)); + a.setAccess(-1); + attributes.removeElementAt(i); + listAttribute.setListData(attributes); + } + } + + public void downAttribute() { + int i = listAttribute.getSelectedIndex(); + if ((i!= -1) && (i != attributes.size() - 1)) { + Object o = attributes.elementAt(i); + attributes.removeElementAt(i); + attributes.insertElementAt(o, i+1); + listAttribute.setListData(attributes); + listAttribute.setSelectedIndex(i+1); + } + } + + public void upAttribute() { + int i = listAttribute.getSelectedIndex(); + //TraceManager.addDev("Selected index = " + i); + if (i > 0) { + //TraceManager.addDev("Modifying ..."); + Object o = attributes.elementAt(i); + attributes.removeElementAt(i); + attributes.insertElementAt(o, i-1); + listAttribute.setListData(attributes); + listAttribute.setSelectedIndex(i-1); + } + } + + public abstract void closeDialog(); + + public boolean hasBeenCancelled() { + return cancelled; + } + + public void cancelDialog() { + cancelled = true; + 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 { + TAttribute a = (TAttribute)(attributes.elementAt(i)); + identifierText.setText(a.getId()); + initialValue.setText(a.getInitialValue()); + select(accessBox, a.getStringAccess(a.getAccess())); + if (a.getType() == TAttribute.OTHER) { + select(typeBox, a.getTypeOther()); + } else { + select(typeBox, a.getStringAvatarType(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); + } + } + + } //End of method + + public void select(JComboBox jcb, String text) { + String s; + for(int i=0; i<jcb.getItemCount(); i++) { + s = (String)(jcb.getItemAt(i)); + //System.out.println("String found: *" + s + "* *" + text + "*"); + if (s.equals(text)) { + jcb.setSelectedIndex(i); + return; + } + } + } + + public String getName() { + return this.name; + } + + public String getMappedUnit() { + if( mappedUnits.size() == 1 ) { + return mappedUnits.get(0); + } + return ""; + } +} //End of class