diff --git a/src/ui/tmldd/TMLArchiFirewallNode.java b/src/ui/tmldd/TMLArchiFirewallNode.java new file mode 100644 index 0000000000000000000000000000000000000000..cd534ab2dfef43b5edf60c0ada7b69372d0a3988 --- /dev/null +++ b/src/ui/tmldd/TMLArchiFirewallNode.java @@ -0,0 +1,287 @@ +/**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. + +/** + * Class TMLArchiFirewallNode + * Node. To be used in TML architecture diagrams. + * Creation: 17/10/2016 + * @version 1.0 17/10/2016 + * @author Letitia LI + * @see + */ + +package ui.tmldd; + +import java.awt.*; +import java.util.*; +import javax.swing.*; + +import org.w3c.dom.*; + +import myutil.*; +import ui.*; +import ui.window.*; + +import tmltranslator.*; + +public class TMLArchiFirewallNode extends TMLArchiCommunicationNode implements SwallowTGComponent, WithAttributes { + private int textY1 = 15; + private int textY2 = 30; + private int derivationx = 2; + private int derivationy = 3; + private String stereotype = "FIREWALL"; + + private int latency = 0; + + public TMLArchiFirewallNode(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { + super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); + + width = 250; + height = 100; + minWidth = 100; + minHeight = 35; + + nbConnectingPoint = 16; + connectingPoint = new TGConnectingPoint[16]; + + connectingPoint[0] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.0, 0.0); + connectingPoint[1] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.5, 0.0); + connectingPoint[2] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 1.0, 0.0); + connectingPoint[3] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.0, 0.5); + connectingPoint[4] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 1.0, 0.5); + connectingPoint[5] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.0, 1.0); + connectingPoint[6] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.5, 1.0); + connectingPoint[7] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 1.0, 1.0); + + connectingPoint[8] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.25, 0.0); + connectingPoint[9] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.75, 0.0); + connectingPoint[10] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.0, 0.25); + connectingPoint[11] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 1.0, 0.25); + connectingPoint[12] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.0, 0.75); + connectingPoint[13] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 1.0, 0.75); + connectingPoint[14] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.25, 1.0); + connectingPoint[15] = new TMLArchiConnectingPoint(this, 0, 0, false, true, 0.75, 1.0); + + addTGConnectingPointsComment(); + + nbInternalTGComponent = 0; + + moveable = true; + editable = true; + removable = true; + userResizable = true; + + name = tdp.findNodeName("Firewall"); + value = "name"; + + myImageIcon = IconManager.imgic700; + } + + public void internalDrawing(Graphics g) { + Color c = g.getColor(); + g.draw3DRect(x, y, width, height, true); + + // Top lines + g.drawLine(x, y, x + derivationx, y - derivationy); + g.drawLine(x + width, y, x + width + derivationx, y - derivationy); + g.drawLine(x + derivationx, y - derivationy, x + width + derivationx, y - derivationy); + + // Right lines + g.drawLine(x + width, y + height, x + width + derivationx, y - derivationy + height); + g.drawLine(x + derivationx + width, y - derivationy, x + width + derivationx, y - derivationy + height); + + // Filling color + g.setColor(ColorManager.BRIDGE_BOX); + g.fill3DRect(x+1, y+1, width-1, height-1, true); + g.setColor(c); + + // Strings + String ster = "<<" + stereotype + ">>"; + int w = g.getFontMetrics().stringWidth(ster); + g.drawString(ster, x + (width - w)/2, y + textY1); + w = g.getFontMetrics().stringWidth(name); + g.drawString(name, x + (width - w)/2, y + textY2); + + // Icon + + g.drawImage(IconManager.imgic7001.getImage(), x + 4, y + 4, null); + g.drawImage(IconManager.img9, x + width - 20, y + 4, null); + } + + public TGComponent isOnOnlyMe(int x1, int y1) { + + Polygon pol = new Polygon(); + pol.addPoint(x, y); + pol.addPoint(x + derivationx, y - derivationy); + pol.addPoint(x + derivationx + width, y - derivationy); + pol.addPoint(x + derivationx + width, y + height - derivationy); + pol.addPoint(x + width, y + height); + pol.addPoint(x, y + height); + if (pol.contains(x1, y1)) { + return this; + } + + return null; + } + + public String getStereotype() { + return stereotype; + + } + + public String getNodeName() { + return name; + } + + public boolean editOndoubleClick(JFrame frame) { + boolean error = false; + String errors = ""; + int tmp; + String tmpName; + + JDialogFirewallNode dialog = new JDialogFirewallNode(frame, "Setting firewall attributes", this); + dialog.setSize(600, 600); + GraphicLib.centerOnParent(dialog); + dialog.show(); // blocked until dialog has been closed + + if (!dialog.isRegularClose()) { + return false; + } + + if (dialog.getNodeName().length() != 0) { + tmpName = dialog.getNodeName(); + tmpName = tmpName.trim(); + if (!TAttribute.isAValidId(tmpName, false, false)) { + error = true; + errors += "Name of the node "; + } else { + name = tmpName; + } + } + + + + if (error) { + JOptionPane.showMessageDialog(frame, + "Invalid value for the following attributes: " + errors, + "Error", + JOptionPane.INFORMATION_MESSAGE); + return false; + } + + return true; + } + + + public int getType() { + return TGComponentManager.TMLARCHI_FIREWALL; + } + + protected String translateExtraParam() { + StringBuffer sb = new StringBuffer("<extraparam>\n"); + sb.append("<info stereotype=\"" + stereotype + "\" nodeName=\"" + name); + sb.append("\" />\n"); + sb.append("<attributes latency=\"" + latency + "\" "); + sb.append("/>\n"); + sb.append("</extraparam>\n"); + return new String(sb); + } + + public void loadExtraParam(NodeList nl, int decX, int decY, int decId) throws MalformedModelingException{ + //System.out.println("*** load extra synchro ***"); + try { + + NodeList nli; + Node n1, n2; + Element elt; + int t1id; + String sstereotype = null, snodeName = null; + + for(int i=0; i<nl.getLength(); i++) { + n1 = nl.item(i); + //System.out.println(n1); + if (n1.getNodeType() == Node.ELEMENT_NODE) { + nli = n1.getChildNodes(); + for(int j=0; i<nli.getLength(); i++) { + n2 = nli.item(i); + //System.out.println(n2); + if (n2.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n2; + if (elt.getTagName().equals("info")) { + sstereotype = elt.getAttribute("stereotype"); + snodeName = elt.getAttribute("nodeName"); + } + if (sstereotype != null) { + stereotype = sstereotype; + } + if (snodeName != null){ + name = snodeName; + } + + if (elt.getTagName().equals("attributes")) { + latency = Integer.decode(elt.getAttribute("latency")).intValue(); + if ((elt.getAttribute("clockRatio") != null) && (elt.getAttribute("clockRatio").length() > 0)){ + clockRatio = Integer.decode(elt.getAttribute("clockRatio")).intValue(); + } + } + } + } + } + } + + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + + + public int getLatency(){ + return latency; + } + + public String getAttributes() { + String attr = ""; + attr += "Latency = " + latency + "\n"; + return attr; + } + + public int getComponentType() { + return TRANSFER; + } + + +} diff --git a/src/ui/window/JDialogFirewallNode.java b/src/ui/window/JDialogFirewallNode.java new file mode 100644 index 0000000000000000000000000000000000000000..7b19a6fb1355f0623b82c6badca1102106f6d107 --- /dev/null +++ b/src/ui/window/JDialogFirewallNode.java @@ -0,0 +1,262 @@ +/**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. + * + * /** + * Class JDialogFirewallNode + * Dialog for managing attributes of Firewall nodes + * Creation: 17/10/2007 + * @version 1.0 17/10/2007 + * @author Letitia Li + * @see + */ + +package ui.window; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; +import javax.swing.event.*; +//import javax.swing.event.*; +//import java.util.*; + +import ui.*; + +import ui.tmldd.*; + + +public class JDialogFirewallNode extends javax.swing.JDialog implements ActionListener,ListSelectionListener { + + private boolean regularClose; + + private JPanel panel2; + private Frame frame; + private TMLArchiFirewallNode node; + + + // Panel1 + protected JTextField nodeName; + private Vector rules= new Vector(); + // Panel2 + protected JTextField latency; + private JList listRules; + private JButton addButton,removeButton; + + // Main Panel + private JButton closeButton; + private JButton cancelButton; + private JComboBox task1; + private JComboBox task2; + /** Creates new form */ + public JDialogFirewallNode(Frame _frame, String _title, TMLArchiFirewallNode _node) { + super(_frame, _title, true); + frame = _frame; + node = _node; + + 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("Firewall attributes")); + panel2.setPreferredSize(new Dimension(500, 500)); + + c2.gridwidth = 2; + c2.gridheight = 1; + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.fill = GridBagConstraints.HORIZONTAL; + panel2.add(new JLabel("Firewall name:"), c2); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + nodeName = new JTextField(node.getNodeName(), 30); + nodeName.setEditable(true); + nodeName.setFont(new Font("times", Font.PLAIN, 12)); + panel2.add(nodeName, c2); + c2.gridwidth=2; + panel2.add(new JLabel("Latency (CC):"), c2); + c2.gridwidth = GridBagConstraints.REMAINDER; //end row + latency = new JTextField(""+node.getLatency(), 15); + panel2.add(latency, c2); + + c2.gridwidth = GridBagConstraints.REMAINDER; + c2.gridheight = 1; + c2.weighty = 1.0; + c2.weightx = 1.0; + c2.fill = GridBagConstraints.HORIZONTAL; + JLabel rulesLabel = new JLabel("Rules"); + panel2.add(rulesLabel, c2); + + listRules = new JList<String>(rules); + listRules.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + listRules.addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(listRules); + scrollPane.setSize(500, 250); + c2.gridwidth = 1; //end row + c2.fill = GridBagConstraints.BOTH; + c2.gridheight = 5; + c2.weighty = 10.0; + c2.weightx = 10.0; + panel2.add(scrollPane, c2); + task1 = new JComboBox(); + for (String task: node.getTDiagramPanel().getMGUI().getTMLTasks()){ + task1.addItem(task); + } + task1.addItem("*"); + + task2= new JComboBox(); + for (String task: node.getTDiagramPanel().getMGUI().getTMLTasks()){ + task2.addItem(task); + } + task2.addItem("*"); + + panel2.add(task1, c2); + panel2.add(new JLabel("--->"),c2); + c2.gridwidth=GridBagConstraints.REMAINDER; + panel2.add(task2, c2); + + addButton = new JButton("Add Rule"); + addButton.addActionListener(this); + panel2.add(addButton,c2); + removeButton= new JButton("Remove Rule"); + removeButton.addActionListener(this); + panel2.add(removeButton,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; + 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 = ((Boolean)(initValues.elementAt(typeBox.getSelectedIndex()))).booleanValue(); + initialValue.setEnabled(b); + return; + }*/ + + + 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(); + } else if (evt.getSource() == addButton) { + addRule(); + } else if (evt.getSource() == removeButton) { + removeRule(); + } + } + public void valueChanged(ListSelectionEvent e) { + int i = listRules.getSelectedIndex() ; + if (i == -1) { + removeButton.setEnabled(false); + } else { + removeButton.setEnabled(true); + } + } + + public void removeRule() { + int i = listRules.getSelectedIndex() ; + if (i!= -1) { + rules.removeElementAt(i); + listRules.setListData(rules); + } + } + public void addRule(){ + String s = task1.getSelectedItem().toString(); + s+= "->"; + s+= task2.getSelectedItem().toString(); + rules.add(s); + listRules.setListData(rules); + } + public void closeDialog() { + regularClose = true; + dispose(); + } + + public void cancelDialog() { + dispose(); + } + + public boolean isRegularClose() { + return regularClose; + } + + public String getNodeName() { + return nodeName.getText(); + } + + public String getLatency() { + return latency.getText(); + } + +}