diff --git a/src/main/java/ui/window/JDialogCAMSBlocks.java b/src/main/java/ui/window/JDialogCAMSBlocks.java new file mode 100755 index 0000000000000000000000000000000000000000..d5f72aa864d0efb715221d1e76700c53337cfbd4 --- /dev/null +++ b/src/main/java/ui/window/JDialogCAMSBlocks.java @@ -0,0 +1,846 @@ +/* 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 myutil.Conversion; +import myutil.GraphicLib; +import ui.util.IconManager; +import ui.TGComponent; +import ui.het.CAMSBlock; +import heterogeneoustranslator.systemCAMStranslator.CAMSSignal; +import ui.TAttribute; +import ui.TDiagramPanel; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Vector; +import java.util.LinkedList; + + +/** + * Class JDialogCAMSBlocks + * Dialog for managing nodes to be validated + * Creation: 23/06/2017 + * @version 0.1 23/06/2017 + * @author Côme DEMARIGNY + */ + +public class JDialogCAMSBlocks extends JDialog implements ActionListener, ListSelectionListener { + + private LinkedList<TAttribute> attributes, attributesPar, forbidden; + private LinkedList<Boolean> initValues; + private LinkedList<CAMSSignal> signals, signalsPar; + private boolean checkKeyword, checkJavaKeyword; + + private boolean cancelled = true; + private boolean regularClose; + + protected String [] processCode; + protected JTextArea jtaProcessCode; + protected boolean hasProcessCode; + + private JPanel panel1, panel2; + + private TDiagramPanel tdp; + private Frame frame; + private int tab; + private String defaultName; + private String previousName; + + private String attrib; // "Attributes", "Gates", etc. + + // Panel1 + private JComboBox<String> accessBox, typeBox; + private JTextField identifierText; + private JTextField initialValue; + private JTextField blockName; + private JButton addButton; + + //Panel2 + private JList<TAttribute> listAttribute; + private JTextField nbOfIn, nbOfOut; + private CAMSBlock block; + private JButton upButton; + private JButton downButton; + private JButton removeButton; + + + // Signals + private boolean hasSignals = true; + private JPanel panel5, panel6; + private JComboBox<String> signalInOutBox; + private JTextField signalText; + private JButton addSignalButton; + private JList<CAMSSignal> listSignal; + private JButton upSignalButton; + private JButton downSignalButton; + private JButton removeSignalButton; + + // Main Panel + private JButton closeButton; + private JButton cancelButton; + + /** Creates new form */ + public JDialogCAMSBlocks(LinkedList<TAttribute> _attributes, LinkedList<CAMSSignal> _signals, LinkedList<TAttribute> _forbidden, Frame _frame, String _title, String _attrib, CAMSBlock _block, String []_processCode, boolean _hasProcessCode) { + super(_frame, _title, true); + frame = _frame; + block = _block; + attributesPar = _attributes; + signalsPar = _signals; + processCode = _processCode; + attrib = _attrib; + + if (signalsPar == null) { + signalsPar = new LinkedList<CAMSSignal> (); + hasSignals = false; + } + + hasProcessCode = _hasProcessCode; + if (processCode == null) { + processCode = new String[1]; + processCode[0] = ""; + } + + + forbidden = _forbidden; + initValues = new LinkedList<Boolean> (); + this.attrib = attrib; + + attributes = new LinkedList<TAttribute> (); + signals = new LinkedList<CAMSSignal> (); + + for(TAttribute attr: this.attributesPar) + this.attributes.add (attr.makeClone()); + + // for(CAMSSignal sig: this.signalsPar) + // this.signals.add (sig.makeClone()); + pack(); + initComponents(); + myInitComponents(); + pack(); + } + + + private void myInitComponents() { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + } + + private void initComponents() { + + // Issue #41 Ordering of tabbed panes + JTabbedPane tabbedPane = GraphicLib.createTabbedPane();//new JTabbedPane(); + Container c = getContentPane(); + + JPanel panelAttr = new JPanel(new BorderLayout()); + JPanel panelSignal = new JPanel(new BorderLayout()); + JPanel panelCode; + 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); + + panel1 = new JPanel(); + panel1.setLayout(gridbag1); + panel1.setBorder(new javax.swing.border.TitledBorder("Adding " + attrib)); + panel1.setPreferredSize(new Dimension(500, 500)); + panel1.setMinimumSize(new Dimension(500, 500)); + + panel2 = new JPanel(); + panel2.setLayout(gridbag2); + panel2.setBorder(new javax.swing.border.TitledBorder("Managing " + attrib)); + panel2.setPreferredSize(new Dimension(500, 500)); + panel2.setMinimumSize(new Dimension(500, 500)); + + // 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("Block Name: "), c1); + blockName = new JTextField(); + blockName.setColumns(5); + blockName.setEditable(true); + panel1.add(blockName, 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 = 2; + c1.fill = GridBagConstraints.HORIZONTAL; + c1.anchor = GridBagConstraints.CENTER; + accessBox = new JComboBox<String>(); + 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<String>(); + 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 panel1 + 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<TAttribute> (this.attributes.toArray (new TAttribute[0])); + listAttribute.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listAttribute.addListSelectionListener(this); //fixme + JScrollPane scrollPane = new JScrollPane(listAttribute); + scrollPane.setSize(500, 500); + c2.gridwidth = 2; //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); + + // Signals + panel5 = new JPanel(); + panel5.setLayout(gridbag5); + panel5.setBorder(new javax.swing.border.TitledBorder("Adding signals")); + panel5.setPreferredSize(new Dimension(500, 500)); + + panel6 = new JPanel(); + panel6.setLayout(gridbag6); + panel6.setBorder(new javax.swing.border.TitledBorder("Managing signals")); + panel6.setPreferredSize(new Dimension(500, 500)); + + // first line panel5 + c5.gridwidth = 1; + c5.gridheight = 1; + c5.weighty = 1.0; + c5.weightx = 1.0; + c5.gridwidth = GridBagConstraints.REMAINDER; //end row + c5.fill = GridBagConstraints.BOTH; + c5.gridheight = 3; + panel5.add(new JLabel(" "), c5); + + c5.gridwidth = 1; + c5.gridheight = 1; + c5.weighty = 1.0; + c5.weightx = 1.0; + c5.anchor = GridBagConstraints.CENTER; + c5.gridwidth = GridBagConstraints.REMAINDER; //end row + panel5.add(new JLabel("signal:"), c5); + + // second line panel5 + c5.gridwidth = 1; + c5.fill = GridBagConstraints.HORIZONTAL; + String[] v = new String[4]; + v[0] = "in"; + v[1] = "out"; + v[2] = "hybrid in"; + v[3] = "hybrid out"; + signalInOutBox = new JComboBox<String>(v); + panel5.add(signalInOutBox, c5); + signalText = new JTextField(); + signalText.setColumns(50); + signalText.setEditable(true); + panel5.add(signalText, c5); + + // third line panel5 + c5.gridwidth = GridBagConstraints.REMAINDER; //end row + c5.fill = GridBagConstraints.BOTH; + c5.gridheight = 3; + panel5.add(new JLabel(" "), c5); + + // fourth line panel5 + c5.gridheight = 1; + c5.fill = GridBagConstraints.HORIZONTAL; + addSignalButton = new JButton("Add signal"); + addSignalButton.addActionListener(this); + panel5.add(addSignalButton, c5); + + // 1st line panel6 + listSignal = new JList<CAMSSignal> (this.signals.toArray (new CAMSSignal[0])); + listSignal.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listSignal.addListSelectionListener(this); + scrollPane = new JScrollPane(listSignal); + scrollPane.setSize(500, 500); + c6.gridwidth = GridBagConstraints.REMAINDER; //end row + c6.fill = GridBagConstraints.BOTH; + c6.gridheight = 5; + c6.weighty = 10.0; + c6.weightx = 10.0; + panel6.add(scrollPane, c6); + + // 2nd line panel4 + c6.weighty = 1.0; + c6.weightx = 1.0; + c6.fill = GridBagConstraints.BOTH; + c6.gridheight = 1; + panel6.add(new JLabel(""), c6); + + // third line panel4 + c6.gridwidth = GridBagConstraints.REMAINDER; //end row + c6.fill = GridBagConstraints.HORIZONTAL; + upSignalButton = new JButton("Up"); + upSignalButton.addActionListener(this); + panel6.add(upSignalButton, c6); + + downSignalButton = new JButton("Down"); + downSignalButton.addActionListener(this); + panel6.add(downSignalButton, c6); + + removeSignalButton = new JButton("Remove signal"); + removeSignalButton.addActionListener(this); + panel6.add(removeSignalButton, c6); + + // Prototyping + panelCode = new JPanel(); + panelCode.setLayout(gridbag7); + + panelCode.setBorder(new javax.swing.border.TitledBorder("Process code")); + // guard + c7.weighty = 1.0; + c7.weightx = 1.0; + c7.gridwidth = 1; + c7.gridheight = 1; + c7.fill = GridBagConstraints.BOTH; + c7.gridwidth = GridBagConstraints.REMAINDER; + c7.gridheight = 1; + + + panelCode.add(new JLabel("Process code of block:"), c7); + //panelCode.add(new JLabel("To implement a method m of block B: \"userImplemented_B_m(...){...}\""), c7); + jtaProcessCode = new JTextArea(); + jtaProcessCode.setEditable(true); + jtaProcessCode.setMargin(new Insets(10, 10, 10, 10)); + jtaProcessCode.setTabSize(3); + String files = ""; + if (processCode != null) { + for(int i=0; i<processCode.length; i++) { + files += processCode[i] + "\n"; + } + } + jtaProcessCode.append(files); + jtaProcessCode.setFont(new Font("times", Font.PLAIN, 12)); + JScrollPane jsp = new JScrollPane(jtaProcessCode, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + jsp.setPreferredSize(new Dimension(500, 500)); + panelCode.add(jsp, c7); + + + // main panel; + panelAttr.add(panel1, BorderLayout.WEST); + panelAttr.add(panel2, BorderLayout.EAST); + tabbedPane.addTab("Attributes", panelAttr); + + if (hasSignals) { + panelSignal.add(panel5, BorderLayout.WEST); + panelSignal.add(panel6, BorderLayout.EAST); + tabbedPane.addTab("Signals", panelSignal); + } + + if (hasProcessCode) { + tabbedPane.addTab("Process", panelCode); + } + + 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 + c0.fill = GridBagConstraints.HORIZONTAL; + 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); + } + + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == typeBox) { + boolean b = initValues.get (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() == downSignalButton) { + downSignal(); + } else if (evt.getSource() == upSignalButton) { + upSignal(); + } else if (evt.getSource() == removeSignalButton) { + removeSignal(); + } else if (evt.getSource() == addSignalButton) { + addSignal(); + } + } + + 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.getCAMSType(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.isCAMS = true; + //System.out.println("New attribute: " + o2.toString()); + } else { + a = new TAttribute(i, s, value, j); + a.isCAMS = true; + } + //checks whether the same attribute already belongs to the list + int index = attributes.size(); + if (attributes.contains(a)) { + index = attributes.indexOf(a); + a = attributes.get (index); + a.setAccess(i); + if (j == TAttribute.OTHER) { + a.setTypeOther(o2.toString()); + } + a.setType(j); + a.setInitialValue(value); + } else { + attributes.add(index, a); + } + listAttribute.setListData(attributes.toArray (new TAttribute[0])); + 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; + } + } + + + public void addSignal() { + String s = signalText.getText(); + CAMSSignal cs = CAMSSignal.isAValidSignal(s, signalInOutBox.getSelectedIndex()); + CAMSSignal cstmp; + int inout; + + if (cs != null) { + // Checks whether the same signal already belongs to the list + int index = -1; + for(int i=0; i<signals.size(); i++) { + cstmp = signals.get(i); + // Same id? + if (cstmp.equals(cs)) { + index = i; + break; + } + } + if(signalInOutBox.getSelectedIndex()==0){ + inout=0; + }else if(signalInOutBox.getSelectedIndex()==1){ + inout=1; + }else if(signalInOutBox.getSelectedIndex()==2){ + inout=2; + }else if(signalInOutBox.getSelectedIndex()==3){ + inout=3; + }else{ + inout=-1; + } + cs = new CAMSSignal(s,inout); + if (index == -1) { + signals.add(cs); + } else { + signals.remove (index); + signals.add (index, cs); + } + listSignal.setListData(signals.toArray (new CAMSSignal[0])); + signalText.setText(""); + + } else { + JOptionPane.showMessageDialog(frame, + "Badly formatted signal declaration", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + } + + public void removeAttribute() { + int i = listAttribute.getSelectedIndex() ; + if (i!= -1) { + TAttribute a = attributes.get (i); + a.setAccess(-1); + attributes.remove (i); + listAttribute.setListData(attributes.toArray (new TAttribute[0])); + } + } + + public void downAttribute() { + int i = listAttribute.getSelectedIndex(); + if ((i!= -1) && (i != attributes.size() - 1)) { + TAttribute o = attributes.get (i); + attributes.remove (i); + attributes.add (i+1, o); + listAttribute.setListData(attributes.toArray (new TAttribute[0])); + listAttribute.setSelectedIndex(i+1); + } + } + + public void upAttribute() { + int i = listAttribute.getSelectedIndex(); + if (i > 0) { + TAttribute o = attributes.get (i); + attributes.remove (i); + attributes.add (i-1, o); + listAttribute.setListData(attributes.toArray (new TAttribute[0])); + listAttribute.setSelectedIndex(i-1); + } + } + + public void removeSignal() { + int i = listSignal.getSelectedIndex() ; + if (i!= -1) { + signals.remove (i); + listSignal.setListData(signals.toArray (new CAMSSignal [0])); + } + } + + public void upSignal() { + int i = listSignal.getSelectedIndex(); + if (i > 0) { + CAMSSignal o = signals.get (i); + signals.remove (i); + signals.add (i-1, o); + listSignal.setListData(signals.toArray (new CAMSSignal [0])); + listSignal.setSelectedIndex(i-1); + } + } + + public void downSignal() { + int i = listSignal.getSelectedIndex(); + if ((i!= -1) && (i != signals.size() - 1)) { + CAMSSignal o = signals.get (i); + signals.remove(i); + signals.add (i+1, o); + listSignal.setListData(signals.toArray (new CAMSSignal [0])); + listSignal.setSelectedIndex(i+1); + } + } + + + public void closeDialog() { + cancelled = false; + attributesPar.clear (); + for(TAttribute attr: this.attributes) + attributesPar.add (attr); + + signalsPar.clear (); + for(CAMSSignal sig: this.signals) + signalsPar.add (sig); + + processCode = Conversion.wrapText(jtaProcessCode.getText()); + dispose(); + } + + public boolean hasBeenCancelled() { + return cancelled; + } + + public boolean isRegularClose() { + return regularClose; + } + + public void cancelDialog() { + dispose(); + } + + public void valueChanged(ListSelectionEvent e) { + int i = listAttribute.getSelectedIndex() ; + if (i == -1) { + removeButton.setEnabled(false); + upButton.setEnabled(false); + downButton.setEnabled(false); + identifierText.setText(""); + //initialValue.setText(""); + } else { + TAttribute a = attributes.get (i); + identifierText.setText(a.getId()); + initialValue.setText(a.getInitialValue()); + select(accessBox, TAttribute.getStringAccess(a.getAccess())); + if (a.getType() == TAttribute.OTHER) { + select(typeBox, a.getTypeOther()); + } else { + //select(typeBox, TAttribute.getStringCAMSType(a.getType())); //fixme + } + 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); + } + } + + i = listSignal.getSelectedIndex() ; + if (i == -1) { + removeSignalButton.setEnabled(false); + upSignalButton.setEnabled(false); + downSignalButton.setEnabled(false); + signalText.setText(""); + //initialValue.setText(""); + } else { + CAMSSignal as = signals.get (i); + //signalText.setText(as.toBasicString()); //fixme + // signalInOutBox.setSelectedIndex(as.getInOut()); + removeSignalButton.setEnabled(true); + if (i > 0) { + upSignalButton.setEnabled(true); + } else { + upSignalButton.setEnabled(false); + } + if (i != signals.size() - 1) { + downSignalButton.setEnabled(true); + } else { + downSignalButton.setEnabled(false); + } + } + } + + public void select(JComboBox<String> jcb, String text) { + String s; + for(int i=0; i<jcb.getItemCount(); i++) { + s = jcb.getItemAt(i); + if (s.equals(text)) { + jcb.setSelectedIndex(i); + return; + } + } + } + + + public String getBlockName() { + if(blockName.getText() == null || blockName.getText() == "" || blockName.getText() == " ") { + return "Block0"; + } else { + return blockName.getText(); + } + } + + public LinkedList<CAMSSignal> getSignals(){ + return signals; + } + + public String[] getProcessCode() { + return processCode; + } + +} diff --git a/src/main/java/ui/window/JDialogCAMSConnectingPoint.java b/src/main/java/ui/window/JDialogCAMSConnectingPoint.java new file mode 100755 index 0000000000000000000000000000000000000000..ec5a9c91cf53fc03f3215e5c9da42d149a4ef8e2 --- /dev/null +++ b/src/main/java/ui/window/JDialogCAMSConnectingPoint.java @@ -0,0 +1,201 @@ +/* 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.util.IconManager; +import ui.het.*; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +//import javax.swing.event.*; +//import java.util.*; + + +/** +* Class JDialogADDCPUNode +* Dialog for managing attributes of cpu nodes in ADD +* Creation: 02/07/2014 +* @version 1.0 02/07/2014 +* @author Ludovic APVRILLE + */ +public class JDialogCAMSConnectingPoint extends JDialogBase implements ActionListener { + + private boolean regularClose; + + private JPanel panel2; + private Frame frame; + public CAMSConnectingPoint ccp; + + protected JComboBox<String> tracemode; + private static int selectedTracemode = 0; + + + // Panel1 + protected JTextField ccpName; + + // Panel2 + protected JTextField type, rate; + + /** Creates new form */ + public JDialogCAMSConnectingPoint(Frame _frame, String _title, CAMSConnectingPoint _ccp) { + super(_frame, _title, true); + frame = _frame; + ccp = _ccp; + + initComponents(); + myInitComponents(); + pack(); + } + + private void myInitComponents() { + } + + private void initComponents() { + Container c = getContentPane(); + GridBagLayout gridbag0 = new GridBagLayout(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagLayout gridbag2 = new GridBagLayout(); + GridBagConstraints c0 = new GridBagConstraints(); + //GridBagConstraints c1 = new GridBagConstraints(); + GridBagConstraints c2 = new GridBagConstraints(); + + setFont(new Font("Helvetica", Font.PLAIN, 14)); + c.setLayout(gridbag0); + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + + panel2 = new JPanel(); + panel2.setLayout(gridbag2); + panel2.setBorder(new javax.swing.border.TitledBorder("Connecting Point attributes")); + panel2.setPreferredSize(new Dimension(400, 300)); + + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.fill = GridBagConstraints.HORIZONTAL; + panel2.add(new JLabel("Connecting Point name:"), c2); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + ccpName = new JTextField(ccp.getccpName(), 30); + ccpName.setEditable(true); + ccpName.setFont(new Font("times", Font.PLAIN, 12)); + panel2.add(ccpName, c2); + + c2.gridwidth = 1; + c2.gridheight = 1; + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.fill = GridBagConstraints.HORIZONTAL; + + + c2.gridwidth = 1; + panel2.add(new JLabel("Type :"), c2); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + type = new JTextField(""+ccp.getPointType(), 15); + panel2.add(type, c2); + + c2.gridwidth = 1; + panel2.add(new JLabel("Rate:"), c2); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + rate = new JTextField(""+ccp.getRate(), 15); + panel2.add(rate, c2); + + // main panel; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + c.add(panel2, c0); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + + initButtons(c0, c, this); + } + + public void actionPerformed(ActionEvent evt) { + + if (evt.getSource() == tracemode) { + selectedTracemode = tracemode.getSelectedIndex(); + } + + String command = evt.getActionCommand(); + + // Compare the action command to the known actions. + if (command.equals("Save and Close")) { + closeDialog(); + } else if (command.equals("Cancel")) { + cancelDialog(); + } + } + + public void closeDialog() { + regularClose = true; + dispose(); + } + + public void cancelDialog() { + dispose(); + } + + public boolean isRegularClose() { + return regularClose; + } + + public String getccpName() { + return ccpName.getText(); + } + + public String getPointType() { + return type.getText(); + } + + public String getRate() { + return rate.getText(); + } + +}//class \ No newline at end of file diff --git a/src/main/java/ui/window/JDialogSelectSystemCAMSBlock.java b/src/main/java/ui/window/JDialogSelectSystemCAMSBlock.java new file mode 100755 index 0000000000000000000000000000000000000000..093e21dd964de36b208f18cef09aaa9a4fed2618 --- /dev/null +++ b/src/main/java/ui/window/JDialogSelectSystemCAMSBlock.java @@ -0,0 +1,420 @@ +/* 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. + */ + + + + +package ui.window; + +import myutil.TraceManager; +import ui.util.IconManager; +import ui.TGComponent; +import ui.het.*; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import java.util.List; +import java.util.Vector; + + +/** + * Class JDialogSelectSystemCAMSBlock + * Dialog for selecting systemC-AMS blocks + * Creation: 04/07/2017 + * @version 1.0 04/07/2017 + * @author Côme Demarigny + */ +public class JDialogSelectSystemCAMSBlock extends JDialogBase implements ActionListener, ListSelectionListener { + + public static Vector<TGComponent> validated, ignored; + private static boolean optimized = true; + + private Vector<TGComponent> val, ign, back; //val for validated, ign for ignored + + //subpanels + private JPanel panel1, panel2, panel3, panel4, panel5, panel6; + private JList<TGComponent> listIgnored; + private JList<TGComponent> listValidated; + private JButton allValidated; + private JButton addOneValidated; + private JButton addOneIgnored; + private JButton allIgnored; + protected JCheckBox optimize; + // protected JTextField clockField; + + /* Creates new form */ + public JDialogSelectSystemCAMSBlock( Frame f, Vector<TGComponent> _back, List<TGComponent> componentList, String title ) { + super(f, title, true); + + TraceManager.addDev( "Printing list of components: " + Arrays.toString( componentList.toArray()) ); + + back = _back; + if( ( validated == null ) || ( ignored == null ) ) { + val = makeNewVal( componentList ); //componentList must already contain something. + //originally contained in componentList + ign = new Vector<TGComponent>(); //empty + //val and ign are the lists that are printed in the Syntax Analysis window + } + else { + val = validated; //validated and ignored, the public vectors come from the instance of SystemCAMSPanel + ign = ignored; + checkBlock( val, componentList ); + checkBlock( ign, componentList ); + addNewBlock( val, componentList, ign ); + } + + initComponents(); + myInitComponents(); + pack(); + } + + //From componentList, filter out all the elements which are not TMLArchiNode + private Vector<TGComponent> makeNewVal( List<TGComponent> list ) { + + Vector<TGComponent> v = new Vector<TGComponent>(); + TGComponent tgc; + + for( int i = 0; i < list.size(); i++ ) { + tgc = list.get(i); + // System.out.println(tgc); + if (tgc instanceof CAMSBlock) { + v.addElement( tgc ); + } + } + return v; + } + + private void checkBlock( Vector<TGComponent> tobeChecked, List<TGComponent> source ) { + + CAMSBlock block; + + for(int i = 0; i < tobeChecked.size(); i++ ) { + if( tobeChecked.elementAt(i) instanceof CAMSBlock ){ + block = (CAMSBlock) tobeChecked.elementAt(i); + if( !source.contains(block) ) { + tobeChecked.removeElementAt(i); + i--; + } + } + } + } + + public void addNewBlock( Vector<TGComponent> added, List<TGComponent> source, Vector<TGComponent> notSource ) { + + TGComponent tgc; + + for( int i = 0; i < source.size(); i++ ) { + tgc = source.get(i); + if( ( tgc instanceof CAMSBlock ) && ( !added.contains(tgc) ) && ( !notSource.contains(tgc) ) ) { + added.addElement( tgc ); + System.out.println("New element"); + } + } + } + + private void myInitComponents() { + setButtons(); + } + + private void initComponents() { + + Container c = getContentPane(); + GridBagLayout gridbag1 = new GridBagLayout(); + GridBagConstraints c1 = new GridBagConstraints(); + GridBagLayout gridbag2 = new GridBagLayout(); + GridBagConstraints c2 = new GridBagConstraints(); + setFont( new Font( "Helvetica", Font.PLAIN, 14) ); + c.setLayout( new BorderLayout() ); + setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); + + c.setLayout(gridbag2); + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.gridwidth = 1; + c2.fill = GridBagConstraints.HORIZONTAL; + c2.gridheight = 1; + + // ignored list + panel1 = new JPanel(); + panel1.setLayout( new BorderLayout() ); + panel1.setBorder( new javax.swing.border.TitledBorder( "Diagrams ignored" ) ); + listIgnored = new JList<TGComponent>( ign ); + //listIgnored.setPreferredSize(new Dimension(200, 250)); + listIgnored.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); + listIgnored.addListSelectionListener( this ); + JScrollPane scrollPane1 = new JScrollPane( listIgnored ); + panel1.add( scrollPane1, BorderLayout.CENTER ); + panel1.setPreferredSize( new Dimension( 200, 250) ); + c.add( panel1, c2); + + + + // central buttons + panel3 = new JPanel(); + panel3.setLayout(gridbag1); + + c1.weighty = 1.0; + c1.weightx = 1.0; + c1.gridwidth = GridBagConstraints.REMAINDER; //end row + c1.fill = GridBagConstraints.HORIZONTAL; + c1.gridheight = 1; + + allValidated = new JButton(IconManager.imgic50); + allValidated.setPreferredSize(new Dimension(50, 25)); + allValidated.addActionListener(this); + allValidated.setActionCommand("allValidated"); + panel3.add(allValidated, c1); + + addOneValidated = new JButton(IconManager.imgic48); + addOneValidated.setPreferredSize(new Dimension(50, 25)); + addOneValidated.addActionListener(this); + addOneValidated.setActionCommand("addOneValidated"); + panel3.add(addOneValidated, c1); + + panel3.add(new JLabel(" "), c1); + + addOneIgnored = new JButton(IconManager.imgic46); + addOneIgnored.addActionListener(this); + addOneIgnored.setPreferredSize(new Dimension(50, 25)); + addOneIgnored.setActionCommand("addOneIgnored"); + panel3.add(addOneIgnored, c1); + + allIgnored = new JButton(IconManager.imgic44); + allIgnored.addActionListener(this); + allIgnored.setPreferredSize(new Dimension(50, 25)); + allIgnored.setActionCommand("allIgnored"); + panel3.add(allIgnored, c1); + + c.add(panel3, c2); + + // validated list + panel2 = new JPanel(); + panel2.setLayout( new BorderLayout() ); + panel2.setBorder( new javax.swing.border.TitledBorder( "Diagrams taken into account" ) ); + listValidated = new JList<TGComponent>( val ); + //listValidated.setPreferredSize(new Dimension(200, 250)); + listValidated.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); + listValidated.addListSelectionListener( this ); + JScrollPane scrollPane2 = new JScrollPane( listValidated ); + panel2.add( scrollPane2, BorderLayout.CENTER ); + panel2.setPreferredSize( new Dimension(200, 250) ); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + c.add( panel2, c2 ); + + // main panel; + panel6 = new JPanel(); + panel6.setLayout(new BorderLayout()); + + panel5 = new JPanel(); + /*GridBagLayout gridbag3 = new GridBagLayout(); + GridBagConstraints c3 = new GridBagConstraints(); + panel5.setLayout(gridbag3); + + c3.weighty = 1.0; + c3.weightx = 1.0; + c3.fill = GridBagConstraints.HORIZONTAL; + c3.gridheight = 1; + + c3.gridwidth = GridBagConstraints.REMAINDER; //end row + // optimize = new JCheckBox("Optimize TML specification"); + // optimize.setSelected(optimized); + // panel5.add(optimize, c2); + + c3.gridwidth = 1; //end row + // panel5.add(new JLabel("Master clock (in MHz)"), c2); + // c2.gridwidth = GridBagConstraints.REMAINDER; //end row + // clockField = new JTextField("" + clock); + // panel5.add(clockField, c2);*/ + + panel4 = new JPanel(); + panel4.setLayout(new FlowLayout()); + + closeButton = new JButton("Start Syntax Analysis", IconManager.imgic37); + //closeButton.setPreferredSize(new Dimension(600, 50)); + closeButton.addActionListener(this); + closeButton.setPreferredSize(new Dimension(200, 30)); + + cancelButton = new JButton("Cancel", IconManager.imgic27); + cancelButton.addActionListener(this); + cancelButton.setPreferredSize(new Dimension(200, 30)); + panel4.add(cancelButton); + panel4.add(closeButton); + + panel6.add(panel5, BorderLayout.NORTH); + panel6.add(panel4, BorderLayout.SOUTH); + + c.add(panel6, c2); + + } + + public void actionPerformed( ActionEvent evt ) { + String command = evt.getActionCommand(); + + if (evt.getSource() == closeButton) { + closeDialog(); + return; + } else if (evt.getSource() == cancelButton) { + cancelDialog(); + return; + } + // Compare the action command to the known actions. + if (command.equals("addOneIgnored")) { + addOneIgnored(); + } else if (command.equals("addOneValidated")) { + addOneValidated(); + } else if (command.equals("allValidated")) { + allValidated(); + } else if (command.equals("allIgnored")) { + allIgnored(); + } + } + + + private void addOneIgnored() { + int [] list = listValidated.getSelectedIndices(); + Vector<TGComponent> v = new Vector<TGComponent>(); + TGComponent o; + for (int i=0; i<list.length; i++){ + o = val.elementAt(list[i]); + ign.addElement(o); + v.addElement(o); + } + + val.removeAll(v); + listIgnored.setListData(ign); + listValidated.setListData(val); + setButtons(); + } + + private void addOneValidated() { + int [] list = listIgnored.getSelectedIndices(); + Vector<TGComponent> v = new Vector<TGComponent>(); + TGComponent o; + + for (int i=0; i<list.length; i++){ + o = ign.elementAt(list[i]); + val.addElement(o); + v.addElement(o); + } + + ign.removeAll(v); + listIgnored.setListData(ign); + listValidated.setListData(val); + setButtons(); + } + + private void allValidated() { + val.addAll(ign); + ign.removeAllElements(); + listIgnored.setListData(ign); + listValidated.setListData(val); + setButtons(); + } + + private void allIgnored() { + ign.addAll(val); + val.removeAllElements(); + listIgnored.setListData(ign); + listValidated.setListData(val); + setButtons(); + } + + + public void closeDialog() { + + back.removeAllElements(); + + for( int i = 0; i < val.size(); i++ ) { + back.addElement( val.elementAt(i) ); + } + validated = val; + ignored = ign; + dispose(); + } + + public void cancelDialog() { + dispose(); + } + + private void setButtons() { + int i1 = listIgnored.getSelectedIndex(); + int i2 = listValidated.getSelectedIndex(); + + if (i1 == -1) { + addOneValidated.setEnabled(false); + } else { + addOneValidated.setEnabled(true); + //listValidated.clearSelection(); + } + + if (i2 == -1) { + addOneIgnored.setEnabled(false); + } else { + addOneIgnored.setEnabled(true); + //listIgnored.clearSelection(); + } + + if (ign.size() ==0) { + allValidated.setEnabled(false); + } else { + allValidated.setEnabled(true); + } + + if (val.size() ==0) { + allIgnored.setEnabled(false); + closeButton.setEnabled(false); + } else { + allIgnored.setEnabled(true); + closeButton.setEnabled(true); + } + } + + public void valueChanged(ListSelectionEvent e) { + setButtons(); + } + + public boolean getOptimize() { + return optimized; + } +}