diff --git a/src/main/java/syscamstranslator/SysCAMSTBlockDE.java b/src/main/java/syscamstranslator/SysCAMSTBlockDE.java index d687d1b74473408436952e999c5f3dff99357bba..dba0be54f7dcf9009ed094d8b102051933c58105 100644 --- a/src/main/java/syscamstranslator/SysCAMSTBlockDE.java +++ b/src/main/java/syscamstranslator/SysCAMSTBlockDE.java @@ -40,6 +40,8 @@ package syscamstranslator; import java.util.LinkedList; +import javax.swing.DefaultListModel; + /** * Class SysCAMSTBlockDE * Parameters of a SystemC-AMS block DE @@ -51,21 +53,38 @@ import java.util.LinkedList; public class SysCAMSTBlockDE extends SysCAMSTComponent { private String name; // private int period; +// private String time; private String nameFn; private String code; + private DefaultListModel<String> listStruct; + private String nameTemplate; + private String typeTemplate; + private DefaultListModel<String> listTypedef; + + private SysCAMSTCluster cluster; private LinkedList<SysCAMSTPortDE> portDE; - public SysCAMSTBlockDE(String _name, String _nameFn, String _code) { + public SysCAMSTBlockDE(String _name, String _nameFn, String _code, DefaultListModel<String> _listStruct, String _nameTemplate, String _typeTemplate, DefaultListModel<String> _listTypedef, SysCAMSTCluster _cluster) { name = _name; // period = _period; +// time = _time; nameFn = _nameFn; code = _code; + listStruct = _listStruct; + nameTemplate = _nameTemplate; + typeTemplate = _typeTemplate; + listTypedef = _listTypedef; + cluster = _cluster; portDE = new LinkedList<SysCAMSTPortDE>(); } // public int getPeriod() { // return period; +// } +// +// public String getTime() { +// return time; // } public String getName() { @@ -75,11 +94,31 @@ public class SysCAMSTBlockDE extends SysCAMSTComponent { public String getNameFn() { return nameFn; } - + public String getCode() { return code; } + + public DefaultListModel<String> getListStruct() { + return listStruct; + } + public String getNameTemplate() { + return nameTemplate; + } + + public String getTypeTemplate() { + return typeTemplate; + } + + public DefaultListModel<String> getListTypedef() { + return listTypedef; + } + + public SysCAMSTCluster getCluster() { + return cluster; + } + public LinkedList<SysCAMSTPortDE> getPortDE(){ return portDE; } diff --git a/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java b/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java index 02f0d8de1dc679a3d25e8a3472daf74d0ef0cb85..65cff7cbf0d9557cedd4c65fb1e722a97f346d4e 100644 --- a/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java +++ b/src/main/java/syscamstranslator/SysCAMSTBlockTDF.java @@ -51,9 +51,9 @@ import javax.swing.DefaultListModel; */ public class SysCAMSTBlockTDF extends SysCAMSTComponent { - private String name; private int period; + private String time; private String processCode; private DefaultListModel<String> listStruct; private String nameTemplate; @@ -65,9 +65,10 @@ public class SysCAMSTBlockTDF extends SysCAMSTComponent { private LinkedList<SysCAMSTPortTDF> portTDF; private LinkedList<SysCAMSTPortConverter> portConverter; - public SysCAMSTBlockTDF(String _name, int _period, String _processCode, DefaultListModel<String> _listStruct, String _nameTemplate, String _typeTemplate, DefaultListModel<String> _listTypedef, SysCAMSTCluster _cluster) { + public SysCAMSTBlockTDF(String _name, int _period, String _time, String _processCode, DefaultListModel<String> _listStruct, String _nameTemplate, String _typeTemplate, DefaultListModel<String> _listTypedef, SysCAMSTCluster _cluster) { name = _name; period = _period; + time = _time; processCode = _processCode; listStruct = _listStruct; nameTemplate = _nameTemplate; @@ -78,18 +79,22 @@ public class SysCAMSTBlockTDF extends SysCAMSTComponent { portConverter = new LinkedList<SysCAMSTPortConverter>(); } + public String getName() { + return name; + } + public int getPeriod() { return period; } + + public String getTime() { + return time; + } public String getProcessCode() { return processCode; } - public String getName() { - return name; - } - public DefaultListModel<String> getListStruct() { return listStruct; } diff --git a/src/main/java/ui/SysCAMSPanelTranslator.java b/src/main/java/ui/SysCAMSPanelTranslator.java index d31a74520724ee3074fbd4849c0a4f1595ee28dc..fc04b6d2111cc8d51316e75420b7033c6be7d924 100644 --- a/src/main/java/ui/SysCAMSPanelTranslator.java +++ b/src/main/java/ui/SysCAMSPanelTranslator.java @@ -97,10 +97,15 @@ public class SysCAMSPanelTranslator { String blockDEName = blockDE.getValue(); // int periodBlock = blockDE.getPeriod(); - String nameFn = blockDE.getNameFn(); - String code = blockDE.getCode(); +// String time = blockDE.getTime(); +// String nameFn = blockDE.getNameFn(); +// String code = blockDE.getCode(); +// DefaultListModel<String> listStruct = blockDE.getListStruct(); +// String nameTemplate = blockDE.getNameTemplate(); +// String typeTemplate = blockDE.getTypeTemplate(); +// DefaultListModel<String> listTypedef = blockDE.getListTypedef(); - SysCAMSTBlockDE syscamsBlockDE = new SysCAMSTBlockDE(blockDEName, nameFn, code); + SysCAMSTBlockDE syscamsBlockDE = new SysCAMSTBlockDE(blockDEName, "", "", null, "", "", null, null); List<SysCAMSPortDE> portsDE = blockDE.getAllInternalPortsDE(); for (int i = 0; i < portsDE.size(); i++) { @@ -138,13 +143,14 @@ public class SysCAMSPanelTranslator { String blockTDFName = blockTDF.getValue(); int periodBlock = blockTDF.getPeriod(); + String time = blockTDF.getTime(); String processCode = blockTDF.getProcessCode(); DefaultListModel<String> listStruct = blockTDF.getListStruct(); String nameTemplate = blockTDF.getNameTemplate(); String typeTemplate = blockTDF.getTypeTemplate(); DefaultListModel<String> listTypedef = blockTDF.getListTypedef(); - SysCAMSTBlockTDF syscamsBlockTDF = new SysCAMSTBlockTDF(blockTDFName, periodBlock, processCode, listStruct, nameTemplate, typeTemplate, listTypedef, syscamsCluster); + SysCAMSTBlockTDF syscamsBlockTDF = new SysCAMSTBlockTDF(blockTDFName, periodBlock, time, processCode, listStruct, nameTemplate, typeTemplate, listTypedef, syscamsCluster); List<SysCAMSPortTDF> portsTDF = blockTDF.getAllInternalPortsTDF(); for (int j = 0; j < portsTDF.size(); j++) { @@ -191,10 +197,15 @@ public class SysCAMSPanelTranslator { String blockDEName = blockDE.getValue(); // int periodBlock = blockDE.getPeriod(); +// String time = blockDE.getTime(); String nameFn = blockDE.getNameFn(); String code = blockDE.getCode(); + DefaultListModel<String> listStruct = blockDE.getListStruct(); + String nameTemplate = blockDE.getNameTemplate(); + String typeTemplate = blockDE.getTypeTemplate(); + DefaultListModel<String> listTypedef = blockDE.getListTypedef(); - SysCAMSTBlockDE syscamsBlockDE = new SysCAMSTBlockDE(blockDEName, nameFn, code); + SysCAMSTBlockDE syscamsBlockDE = new SysCAMSTBlockDE(blockDEName, nameFn, code, listStruct, nameTemplate, typeTemplate, listTypedef, syscamsCluster); List<SysCAMSPortDE> portsDE = blockDE.getAllInternalPortsDE(); for (int j = 0; j < portsDE.size(); j++) { diff --git a/src/main/java/ui/syscams/SysCAMSBlockDE.java b/src/main/java/ui/syscams/SysCAMSBlockDE.java index 55c8cdc8e3208b7ee84945132151572239c851d0..cabef17c3e73e14dfd3666282a58692b3b78068d 100644 --- a/src/main/java/ui/syscams/SysCAMSBlockDE.java +++ b/src/main/java/ui/syscams/SysCAMSBlockDE.java @@ -46,6 +46,7 @@ import ui.*; import ui.util.IconManager; import ui.window.JDialogSysCAMSBlockDE; import javax.swing.*; + import java.awt.*; import java.util.ArrayList; import java.util.LinkedList; @@ -63,6 +64,10 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements // private String time; private String nameFn; private String code; + private DefaultListModel<String> listStruct; + private String nameTemplate; + private String typeTemplate; + private DefaultListModel<String> listTypedef; private int maxFontSize = 14; private int minFontSize = 4; @@ -106,6 +111,10 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements // setTime(""); setNameFn(""); setCode(""); + setListStruct(new DefaultListModel<String>()); + setNameTemplate(""); + setTypeTemplate(""); + setListTypedef(new DefaultListModel<String>()); myImageIcon = IconManager.imgic1202; @@ -293,11 +302,28 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements // sb.append(getPeriod()); // sb.append("\" time=\"" + getTime()); sb.append("\" code=\"" + encode(getCode())); + sb.append("\" listStruct=\"" + splitParameters(getListStruct())); + sb.append("\" nameTemplate=\"" + getNameTemplate()); + sb.append("\" typeTemplate=\"" + getTypeTemplate()); + sb.append("\" listTypedef=\"" + splitParameters(getListTypedef())); sb.append("\" />\n"); sb.append("</extraparam>\n"); return new String(sb); } + public String splitParameters(DefaultListModel<String> listStruct) { + String s = ""; + + for (int i = 0; i < listStruct.getSize(); i++) { + if (i < listStruct.getSize()-1) { + s = s + listStruct.get(i) + "|"; + } else { + s = s + listStruct.get(i); + } + } + return s; + } + public StringBuffer encode(String data) { StringBuffer databuf = new StringBuffer(data); StringBuffer buffer = new StringBuffer(""); @@ -405,7 +431,7 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements Element elt; int period; - String time, code, nameFn; + String code, nameFn, listStruct, nameTemplate, typeTemplate, listTypedef; for(int i=0; i<nl.getLength(); i++) { n1 = nl.item(i); @@ -420,11 +446,33 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements // time = elt.getAttribute("time"); code = elt.getAttribute("code"); nameFn = elt.getAttribute("name_function"); + listStruct = elt.getAttribute("listStruct"); + nameTemplate = elt.getAttribute("nameTemplate"); + typeTemplate = elt.getAttribute("typeTemplate"); + listTypedef = elt.getAttribute("listTypedef"); // setPeriod(period); // setTime(time); setNameFn(nameFn); code = decode(code).toString(); setCode(code); + String[] splita = listStruct.split("\\|"); + DefaultListModel<String> lista = new DefaultListModel<String>(); + for (String s : splita) { + if (!s.equals("")) { + lista.addElement(s); + } + } + setListStruct(lista); + setNameTemplate(nameTemplate); + setTypeTemplate(typeTemplate); + String[] splitb = listTypedef.split("\\|"); + DefaultListModel<String> listb = new DefaultListModel<String>(); + for (String s : splitb) { + if (!s.equals("")) { + listb.addElement(s); + } + } + setListTypedef(listb); } } } @@ -503,4 +551,36 @@ public class SysCAMSBlockDE extends TGCScalableWithInternalComponent implements public String getNameFn() { return nameFn; } + + public DefaultListModel<String> getListStruct() { + return listStruct; + } + + public void setListStruct(DefaultListModel<String> _listStruct) { + listStruct = _listStruct; + } + + public String getNameTemplate() { + return nameTemplate; + } + + public void setNameTemplate(String _nameTemplate) { + nameTemplate = _nameTemplate; + } + + public String getTypeTemplate() { + return typeTemplate; + } + + public void setTypeTemplate(String _typeTemplate) { + typeTemplate = _typeTemplate; + } + + public DefaultListModel<String> getListTypedef() { + return listTypedef; + } + + public void setListTypedef(DefaultListModel<String> _listTypedef) { + listTypedef = _listTypedef; + } } \ No newline at end of file diff --git a/src/main/java/ui/syscams/SysCAMSBlockTDF.java b/src/main/java/ui/syscams/SysCAMSBlockTDF.java index b831b1ee56bc20770dd2a77a7af452b9081f4895..8692a950364d5c0d62a7bda710d644b1879a0e07 100644 --- a/src/main/java/ui/syscams/SysCAMSBlockTDF.java +++ b/src/main/java/ui/syscams/SysCAMSBlockTDF.java @@ -58,7 +58,7 @@ import java.util.LinkedList; * @author Irina Kit Yan LEE */ -public class SysCAMSBlockTDF extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent, WithAttributes { +public class SysCAMSBlockTDF extends TGCScalableWithInternalComponent implements SwallowTGComponent, SwallowedTGComponent { private int period; private String time; private String processCode; @@ -107,8 +107,8 @@ public class SysCAMSBlockTDF extends TGCScalableWithInternalComponent implements name = "Primitive component - Block TDF"; setPeriod(-1); - setProcessCode("void processing() {\n\n}"); setTime(""); + setProcessCode("void processing() {\n\n}"); setListStruct(new DefaultListModel<String>()); setNameTemplate(""); setTypeTemplate(""); @@ -565,14 +565,6 @@ public class SysCAMSBlockTDF extends TGCScalableWithInternalComponent implements return list; } - public String getProcessCode() { - return processCode; - } - - public void setProcessCode(String _processCode) { - processCode = _processCode; - } - public int getPeriod() { return period; } @@ -581,10 +573,6 @@ public class SysCAMSBlockTDF extends TGCScalableWithInternalComponent implements period = _period; } - public String getAttributes() { - return null; - } - public String getTime() { return time; } @@ -593,6 +581,14 @@ public class SysCAMSBlockTDF extends TGCScalableWithInternalComponent implements time = _time; } + public String getProcessCode() { + return processCode; + } + + public void setProcessCode(String _processCode) { + processCode = _processCode; + } + public DefaultListModel<String> getListStruct() { return listStruct; } diff --git a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java index d526407ad82b4c0a52a71603e5302772d68be0a8..7d8a3a84847da0f8676ba357bf2a6fba315a64c9 100644 --- a/src/main/java/ui/window/JDialogSysCAMSBlockDE.java +++ b/src/main/java/ui/window/JDialogSysCAMSBlockDE.java @@ -42,9 +42,10 @@ import ui.syscams.*; import ui.util.*; import java.awt.*; import java.awt.event.*; +import java.util.*; import javax.swing.*; import javax.swing.border.*; - +import javax.swing.event.*; /** * Class JDialogSystemCAMSBlockDE * Dialog for managing of SystemC-AMS DE Block @@ -55,16 +56,40 @@ import javax.swing.border.*; @SuppressWarnings("serial") -public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { +public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener, ListSelectionListener { private JTextField nameTextField; // private JTextField periodTextField; // private String listPeriodString[]; // private JComboBox<String> periodComboBoxString; - private JTextField nameFnTextField; - private JButton nameFnButton; + private JPanel parametersMainPanel; + private JTextField nameStructTextField; + private JTextField valueStructTextField; + private JRadioButton constantStructRadioButton; + private String listTypeStructString[]; + private JComboBox<String> typeStructComboBoxString; + private ArrayList<String> listTmpStruct; + private JList<String> structList; + private DefaultListModel<String> structListModel; + private boolean structBool = false; + private JTextField nameTemplateTextField; + private String listTypeTemplateString[]; + private JComboBox<String> typeTemplateComboBoxString; + private JTextField nameTypedefTextField; + private String listTypeTypedefString[]; + private JComboBox<String> typeTypedefComboBoxString; + private JButton addModifyTypedefButton; + private ArrayList<String> listTmpTypedef; + private JList<String> typedefList; + private DefaultListModel<String> typedefListModel; + private boolean typedefBool = false; + + private JButton upButton, downButton, removeButton; + private JPanel codeMainPanel; + private JTextField nameFnTextField; + private JButton nameFnButton; private JTextArea codeTextArea; private String finalString; @@ -167,8 +192,10 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { JPanel attributesMainPanel = new JPanel(); if (block.getFather() != null) { JTabbedPane tabbedPane = new JTabbedPane(); + parametersMainPanel = new JPanel(); codeMainPanel = new JPanel(); tabbedPane.add("Attributes", attributesMainPanel); + tabbedPane.add("Parameters", parametersMainPanel); tabbedPane.add("Method Code", codeMainPanel); mainPanel.add(tabbedPane, BorderLayout.NORTH); @@ -240,11 +267,324 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { // attributesBoxPanel.add(periodComboBoxString); attributesBox.add(attributesBoxPanel); - attributesMainPanel.add(attributesBox, BorderLayout.NORTH); - // --- ProcessCode ---// if (block.getFather() != null) { + // --- Parameters ---// + parametersMainPanel.setLayout(new BorderLayout()); + + Box parametersBox = Box.createVerticalBox(); + parametersBox.setBorder(BorderFactory.createTitledBorder("Setting TDF block parameters")); + + JPanel blockPanel = new JPanel(new GridLayout(3, 1)); + + // Struct + JPanel structPanel = new JPanel(); + structPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + GridBagLayout gridBagParameter = new GridBagLayout(); + GridBagConstraints constraintParameter = new GridBagConstraints(); + structPanel.setLayout(gridBagParameter); + TitledBorder border = new TitledBorder("Struct :"); + border.setTitleJustification(TitledBorder.CENTER); + border.setTitlePosition(TitledBorder.TOP); + structPanel.setBorder(border); + + JLabel nameParameterLabel = new JLabel("identifier"); + constraintParameter = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(nameParameterLabel, constraintParameter); + structPanel.add(nameParameterLabel); + + nameStructTextField = new JTextField(); + constraintParameter = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(nameStructTextField, constraintParameter); + structPanel.add(nameStructTextField); + + JLabel egalLabel = new JLabel("="); + constraintParameter = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(egalLabel, constraintParameter); + structPanel.add(egalLabel); + + JLabel valueParameterLabel = new JLabel("value"); + constraintParameter = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(valueParameterLabel, constraintParameter); + structPanel.add(valueParameterLabel); + + valueStructTextField = new JTextField(); + constraintParameter = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(valueStructTextField, constraintParameter); + structPanel.add(valueStructTextField); + + JLabel pointsLabel = new JLabel(":"); + constraintParameter = new GridBagConstraints(3, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(pointsLabel, constraintParameter); + structPanel.add(pointsLabel); + + JLabel constantLabel = new JLabel("const"); + constraintParameter = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(constantLabel, constraintParameter); + structPanel.add(constantLabel); + + constantStructRadioButton = new JRadioButton(); + constantStructRadioButton.setActionCommand("Const"); + constantStructRadioButton.setSelected(false); + constantStructRadioButton.addActionListener(this); + constraintParameter = new GridBagConstraints(4, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(constantStructRadioButton, constraintParameter); + structPanel.add(constantStructRadioButton); + + JLabel typeParameterLabel = new JLabel("type"); + constraintParameter = new GridBagConstraints(5, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(typeParameterLabel, constraintParameter); + structPanel.add(typeParameterLabel); + + listTypeStructString = new String[6]; + listTypeStructString[0] = "bool"; + listTypeStructString[1] = "double"; + listTypeStructString[2] = "float"; + listTypeStructString[3] = "int"; + listTypeStructString[4] = "long"; + listTypeStructString[5] = "short"; + typeStructComboBoxString = new JComboBox<String>(listTypeStructString); + typeStructComboBoxString.setSelectedIndex(0); + typeStructComboBoxString.addActionListener(this); + constraintParameter = new GridBagConstraints(5, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(typeStructComboBoxString, constraintParameter); + structPanel.add(typeStructComboBoxString); + + JButton addModifyButton = new JButton("Add / Modify parameter"); + addModifyButton.setActionCommand("Add_Modify_Struct"); + addModifyButton.addActionListener(this); + constraintParameter = new GridBagConstraints(0, 2, 6, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + gridBagParameter.setConstraints(addModifyButton, constraintParameter); + structPanel.add(addModifyButton); + + blockPanel.add(structPanel); + + // Template + JPanel templatePanel = new JPanel(); + templatePanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + GridBagLayout templateGridBag = new GridBagLayout(); + GridBagConstraints templateConstraint = new GridBagConstraints(); + templatePanel.setLayout(templateGridBag); + TitledBorder templateBorder = new TitledBorder("Template :"); + templateBorder.setTitleJustification(TitledBorder.CENTER); + templateBorder.setTitlePosition(TitledBorder.TOP); + templatePanel.setBorder(templateBorder); + + JLabel nameTemplateLabel = new JLabel("identifier"); + templateConstraint = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(nameTemplateLabel, templateConstraint); + templatePanel.add(nameTemplateLabel); + + nameTemplateTextField = new JTextField(block.getNameTemplate()); + templateConstraint = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(nameTemplateTextField, templateConstraint); + templatePanel.add(nameTemplateTextField); + + JLabel pointsTemplateLabel = new JLabel(":"); + templateConstraint = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(pointsTemplateLabel, templateConstraint); + templatePanel.add(pointsTemplateLabel); + + JLabel typeTemplateLabel = new JLabel("type"); + templateConstraint = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(typeTemplateLabel, templateConstraint); + templatePanel.add(typeTemplateLabel); + + listTypeTemplateString = new String[1]; + listTypeTemplateString[0] = "int"; + typeTemplateComboBoxString = new JComboBox<String>(listTypeTemplateString); + if (block.getTypeTemplate().equals("int") || block.getTypeTemplate().equals("")) { + typeTemplateComboBoxString.setSelectedIndex(0); + } + typeTemplateComboBoxString.addActionListener(this); + templateConstraint = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(typeTemplateComboBoxString, templateConstraint); + templatePanel.add(typeTemplateComboBoxString); + + JButton OKButton = new JButton("OK"); + OKButton.setActionCommand("OK"); + OKButton.addActionListener(this); + templateConstraint = new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + templateGridBag.setConstraints(OKButton, templateConstraint); + templatePanel.add(OKButton); + + blockPanel.add(templatePanel); + + // Typedef + JPanel typedefPanel = new JPanel(); + typedefPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + GridBagLayout typedefGridBag = new GridBagLayout(); + GridBagConstraints typedefConstraint = new GridBagConstraints(); + typedefPanel.setLayout(typedefGridBag); + TitledBorder typedefBorder = new TitledBorder("Typedef :"); + typedefBorder.setTitleJustification(TitledBorder.CENTER); + typedefBorder.setTitlePosition(TitledBorder.TOP); + typedefPanel.setBorder(typedefBorder); + + JLabel nameTypedefLabel = new JLabel("identifier"); + typedefConstraint = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(nameTypedefLabel, typedefConstraint); + typedefPanel.add(nameTypedefLabel); + + nameTypedefTextField = new JTextField(); + if (block.getListTypedef().isEmpty()) { + nameTypedefTextField.setEditable(false); + } else { + nameTypedefTextField.setEditable(true); + } + typedefConstraint = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(nameTypedefTextField, typedefConstraint); + typedefPanel.add(nameTypedefTextField); + + JLabel pointsTypedefLabel = new JLabel(":"); + typedefConstraint = new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(pointsTypedefLabel, typedefConstraint); + typedefPanel.add(pointsTypedefLabel); + + JLabel typeTypedefLabel = new JLabel("type"); + typedefConstraint = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(typeTypedefLabel, typedefConstraint); + typedefPanel.add(typeTypedefLabel); + + listTypeTypedefString = new String[1]; + listTypeTypedefString[0] = "sc_dt::sc_int"; + typeTypedefComboBoxString = new JComboBox<String>(listTypeTypedefString); + typeTypedefComboBoxString.setSelectedIndex(0); + if (block.getListTypedef().isEmpty()) { + typeTypedefComboBoxString.setEnabled(false); + } else { + typeTypedefComboBoxString.setEnabled(true); + } + typeTypedefComboBoxString.addActionListener(this); + typedefConstraint = new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(typeTypedefComboBoxString, typedefConstraint); + typedefPanel.add(typeTypedefComboBoxString); + + addModifyTypedefButton = new JButton("Add / Modify typedef"); + addModifyTypedefButton.setActionCommand("Add_Modify_Typedef"); + addModifyTypedefButton.addActionListener(this); + if (block.getListTypedef().isEmpty()) { + addModifyTypedefButton.setEnabled(false); + } else { + addModifyTypedefButton.setEnabled(true); + } + typedefConstraint = new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + typedefGridBag.setConstraints(addModifyTypedefButton, typedefConstraint); + typedefPanel.add(addModifyTypedefButton); + + blockPanel.add(typedefPanel); + + parametersBox.add(blockPanel); + parametersMainPanel.add(parametersBox, BorderLayout.WEST); + + Box managingParametersBox = Box.createVerticalBox(); + + JPanel managingParameterBoxPanel = new JPanel(new GridLayout(3, 1)); + managingParameterBoxPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + + JPanel listStructPanel = new JPanel(); + TitledBorder listStructBorder = new TitledBorder("Managing struct :"); + listStructBorder.setTitleJustification(TitledBorder.CENTER); + listStructBorder.setTitlePosition(TitledBorder.TOP); + listStructPanel.setBorder(listStructBorder); + + structListModel = block.getListStruct(); + structList = new JList<String>(structListModel); + structList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + structList.setLayoutOrientation(JList.VERTICAL); + structList.setSelectedIndex(-1); + structList.setVisibleRowCount(5); + structList.addListSelectionListener(this); + JScrollPane scrollPane = new JScrollPane(structList); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + scrollPane.setPreferredSize(new Dimension(300, 100)); + listStructPanel.add(scrollPane); + managingParameterBoxPanel.add(listStructPanel); + + JPanel listTypedefPanel = new JPanel(); + TitledBorder listTypedefBorder = new TitledBorder("Managing typedef :"); + listTypedefBorder.setTitleJustification(TitledBorder.CENTER); + listTypedefBorder.setTitlePosition(TitledBorder.TOP); + listTypedefPanel.setBorder(listTypedefBorder); + + typedefListModel = block.getListTypedef(); + typedefList = new JList<String>(typedefListModel); + typedefList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + typedefList.setLayoutOrientation(JList.VERTICAL); + typedefList.setSelectedIndex(-1); + typedefList.setVisibleRowCount(5); + typedefList.addListSelectionListener(this); + JScrollPane typedefScrollPane = new JScrollPane(typedefList); + typedefScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + typedefScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + typedefScrollPane.setPreferredSize(new Dimension(300, 100)); + listTypedefPanel.add(typedefScrollPane); + managingParameterBoxPanel.add(listTypedefPanel); + + GridBagLayout buttonGridBag = new GridBagLayout(); + GridBagConstraints buttonconstraints = new GridBagConstraints(); + JPanel buttonPanel = new JPanel(); + buttonPanel.setFont(new Font("Helvetica", Font.PLAIN, 14)); + buttonPanel.setLayout(buttonGridBag); + + upButton = new JButton("Up"); + upButton.setActionCommand("Up"); + upButton.setEnabled(false); + upButton.addActionListener(this); + buttonconstraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + buttonGridBag.setConstraints(upButton, buttonconstraints); + buttonPanel.add(upButton); + + downButton = new JButton("Down"); + downButton.setActionCommand("Down"); + downButton.setEnabled(false); + downButton.addActionListener(this); + buttonconstraints = new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 5, 10), 0, 0); + buttonGridBag.setConstraints(downButton, buttonconstraints); + buttonPanel.add(downButton); + + removeButton = new JButton("Remove parameter"); + removeButton.setActionCommand("Remove"); + removeButton.setEnabled(false); + removeButton.addActionListener(this); + buttonconstraints = new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(5, 10, 15, 10), 0, 0); + buttonGridBag.setConstraints(removeButton, buttonconstraints); + buttonPanel.add(removeButton); + + managingParameterBoxPanel.add(buttonPanel); + + managingParametersBox.add(managingParameterBoxPanel); + parametersMainPanel.add(managingParametersBox, BorderLayout.EAST); + + // --- ProcessCode ---// codeMainPanel.setLayout(new BorderLayout()); Box codeBox = Box.createVerticalBox(); @@ -271,7 +611,7 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { namePanel.add(nameFnTextField); nameFnButton = new JButton("OK"); - nameFnButton.setActionCommand("OK"); + nameFnButton.setActionCommand("Name_OK"); nameFnButton.addActionListener(this); nameConstraints = new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 10, 5, 10), 0, 0); @@ -295,7 +635,7 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { JScrollPane codeScrollPane = new JScrollPane(codeTextArea); codeScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); codeScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); - codeScrollPane.setPreferredSize(new Dimension(200, 200)); + codeScrollPane.setPreferredSize(new Dimension(200, 300)); codeScrollPane.setBorder(new EmptyBorder(15, 10, 15, 10)); codeBoxPanel.add(codeScrollPane, BorderLayout.SOUTH); @@ -327,7 +667,7 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { } public void actionPerformed(ActionEvent e) { - if ("OK".equals(e.getActionCommand())) { + if ("Name_OK".equals(e.getActionCommand())) { if (!nameFnTextField.getText().equals("")) { codeTextArea.setText("void " + nameFnTextField.getText() + "() {\n\n}"); } else { @@ -337,6 +677,305 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { JOptionPane.WARNING_MESSAGE); } } + if (block.getFather() != null) { + if ("OK".equals(e.getActionCommand())) { + nameTypedefTextField.setEditable(true); + typeTypedefComboBoxString.setEnabled(true); + addModifyTypedefButton.setEnabled(true); + } + + if ("Add_Modify_Struct".equals(e.getActionCommand())) { + listTmpStruct = new ArrayList<String>(); + Boolean alreadyExist = false; + int alreadyExistId = -1; + String type = (String) typeStructComboBoxString.getSelectedItem(); + String s = null; + + Boolean valueBoolean = false, valueInteger = false, valueDouble = false, valueLong = false, nameEmpty = false; + + if (nameStructTextField.getText().isEmpty()) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The name of struct is empty", "Warning !", + JOptionPane.WARNING_MESSAGE); + nameEmpty = true; + } + + for (int i = 0; i < structListModel.getSize(); i++) { + if (nameStructTextField.getText().equals(structListModel.elementAt(i).split("\\s")[0])) { + alreadyExist = true; + alreadyExistId = i; + } + } + + if (alreadyExist == false) { + try { + if (type.equals("bool")) { + Boolean.parseBoolean(valueStructTextField.getText()); + } else if (type.equals("double")) { + Double.parseDouble(valueStructTextField.getText()); + } else if (type.equals("float")) { + Float.parseFloat(valueStructTextField.getText()); + } else if (type.equals("int")) { + Integer.parseInt(valueStructTextField.getText()); + } else if (type.equals("long")) { + Long.parseLong(valueStructTextField.getText()); + } else if (type.equals("short")) { + Short.parseShort(valueStructTextField.getText()); + } + } catch (NumberFormatException e1) { + if (type.equals("bool")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Boolean", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueBoolean = true; + } else if (type.equals("double")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Double", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueInteger = true; + } else if (type.equals("float")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Float", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueInteger = true; + } else if (type.equals("int")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Integer", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueDouble = true; + } else if (type.equals("long")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Long", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueLong = true; + } else if (type.equals("short")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Short", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueLong = true; + } + } + + if ((valueBoolean == false) && (valueInteger == false) && (valueDouble == false) && (valueLong == false) && (nameEmpty == false)) { + s = nameStructTextField.getText() + " = "; + + if (type.equals("bool")) { + s = s + Boolean.parseBoolean(valueStructTextField.getText()) + " : "; + } else if (type.equals("double")) { + s = s + Double.parseDouble(valueStructTextField.getText()) + " : "; + } else if (type.equals("float")) { + s = s + Float.parseFloat(valueStructTextField.getText()) + " : "; + } else if (type.equals("int")) { + s = s + Integer.parseInt(valueStructTextField.getText()) + " : "; + } else if (type.equals("long")) { + s = s + Long.parseLong(valueStructTextField.getText()) + " : "; + } else if (type.equals("short")) { + s = s + Short.parseShort(valueStructTextField.getText()) + " : "; + } + + if (constantStructRadioButton.isSelected()) { + s = s + "const " + type; + } else { + s = s + type; + } + structListModel.addElement(s); + listTmpStruct.add(s); + } + } else { + try { + if (type.equals("bool")) { + Boolean.parseBoolean(valueStructTextField.getText()); + } else if (type.equals("double")) { + Double.parseDouble(valueStructTextField.getText()); + } else if (type.equals("float")) { + Float.parseFloat(valueStructTextField.getText()); + } else if (type.equals("int")) { + Integer.parseInt(valueStructTextField.getText()); + } else if (type.equals("long")) { + Long.parseLong(valueStructTextField.getText()); + } else if (type.equals("short")) { + Short.parseShort(valueStructTextField.getText()); + } + } catch (NumberFormatException e1) { + if (type.equals("bool")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Boolean", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueBoolean = true; + } else if (type.equals("double")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Double", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueInteger = true; + } else if (type.equals("float")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameteris not a Float", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueInteger = true; + } else if (type.equals("int")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Integer", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueDouble = true; + } else if (type.equals("long")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Long", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueLong = true; + } else if (type.equals("short")) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The value of the parameter is not a Short", "Warning !", + JOptionPane.WARNING_MESSAGE); + valueLong = true; + } + } + + if ((valueBoolean == false) && (valueInteger == false) && (valueDouble == false) && (valueLong == false) && (nameEmpty == false)) { + s = nameStructTextField.getText() + " = "; + + if (type.equals("bool")) { + s = s + Boolean.parseBoolean(valueStructTextField.getText()) + " : "; + } else if (type.equals("double")) { + s = s + Double.parseDouble(valueStructTextField.getText()) + " : "; + } else if (type.equals("float")) { + s = s + Float.parseFloat(valueStructTextField.getText()) + " : "; + } else if (type.equals("int")) { + s = s + Integer.parseInt(valueStructTextField.getText()) + " : "; + } else if (type.equals("long")) { + s = s + Long.parseLong(valueStructTextField.getText()) + " : "; + } else if (type.equals("short")) { + s = s + Short.parseShort(valueStructTextField.getText()) + " : "; + } + + if (constantStructRadioButton.isSelected()) { + s = s + "const " + type; + } else { + s = s + type; + } + structListModel.setElementAt(s, alreadyExistId); + listTmpStruct.add(s); + } + } + } + + if ("Add_Modify_Typedef".equals(e.getActionCommand())) { + listTmpTypedef = new ArrayList<String>(); + Boolean alreadyExist = false; + int alreadyExistId = -1; + String type = (String) typeTypedefComboBoxString.getSelectedItem(); + String s = null; + + Boolean nameEmpty = false; + + if (nameTypedefTextField.getText().isEmpty()) { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "The name of typedef is empty", "Warning !", + JOptionPane.WARNING_MESSAGE); + nameEmpty = true; + } + + if (nameEmpty == false) { + for (int i = 0; i < typedefListModel.getSize(); i++) { + if (nameTypedefTextField.getText().equals(typedefListModel.elementAt(i).split("\\s")[0])) { + alreadyExist = true; + alreadyExistId = i; + } + } + + if (alreadyExist == false) { + s = nameTypedefTextField.getText() + " : " + type; + typedefListModel.addElement(s); + listTmpTypedef.add(s); + } else { + s = nameTypedefTextField.getText() + " : " + type; + typedefListModel.setElementAt(s, alreadyExistId); + listTmpTypedef.add(s); + } + } + } + + + if ("Remove".equals(e.getActionCommand())) { + if (structBool == true) { + if (structListModel.getSize() >= 1) { + structListModel.remove(structList.getSelectedIndex()); + } + } + if (typedefBool == true) { + if (typedefListModel.getSize() >= 1) { + typedefListModel.remove(typedefList.getSelectedIndex()); + } + } + } + + if ("Up".equals(e.getActionCommand())) { + if (structBool == true) { + if (structList.getSelectedIndex() >= 1) { + String sprev = structListModel.get(structList.getSelectedIndex()-1); + structListModel.remove(structList.getSelectedIndex()-1); + structListModel.add(structList.getSelectedIndex()+1, sprev); + } else { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "Cannot move the parameter up", "Warning !", + JOptionPane.WARNING_MESSAGE); + } + } + if (typedefBool == true) { + if (typedefList.getSelectedIndex() >= 1) { + String sprev = typedefListModel.get(typedefList.getSelectedIndex()-1); + typedefListModel.remove(typedefList.getSelectedIndex()-1); + typedefListModel.add(typedefList.getSelectedIndex()+1, sprev); + } else { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "Cannot move the parameter up", "Warning !", + JOptionPane.WARNING_MESSAGE); + } + } + } + + if ("Down".equals(e.getActionCommand())) { + if (structBool == true) { + if (structList.getSelectedIndex() < structListModel.getSize()-1) { + String snext = structListModel.get(structList.getSelectedIndex()+1); + structListModel.remove(structList.getSelectedIndex()+1); + structListModel.add(structList.getSelectedIndex(), snext); + } else { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "Cannot move the parameter down", "Warning !", + JOptionPane.WARNING_MESSAGE); + } + } + if (typedefBool == true) { + if (typedefList.getSelectedIndex() < typedefListModel.getSize()-1) { + String snext = typedefListModel.get(typedefList.getSelectedIndex()+1); + typedefListModel.remove(typedefList.getSelectedIndex()+1); + typedefListModel.add(typedefList.getSelectedIndex(), snext); + } else { + JDialog msg = new JDialog(this); + msg.setLocationRelativeTo(null); + JOptionPane.showMessageDialog(msg, "Cannot move the parameter down", "Warning !", + JOptionPane.WARNING_MESSAGE); + } + } + } + } if ("Save_Close".equals(e.getActionCommand())) { block.setValue(new String(nameTextField.getText())); @@ -362,6 +1001,11 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { // } if (block.getFather() != null) { + block.setListStruct(structListModel); + block.setNameTemplate(nameTemplateTextField.getText()); + block.setTypeTemplate((String) typeTemplateComboBoxString.getSelectedItem()); + block.setListTypedef(typedefListModel); + block.setNameFn(nameFnTextField.getText()); block.setCode(codeTextArea.getText()); } @@ -370,7 +1014,100 @@ public class JDialogSysCAMSBlockDE extends JDialog implements ActionListener { } if ("Cancel".equals(e.getActionCommand())) { + if (block.getFather() != null) { + if (listTmpStruct != null) { + for (String s : listTmpStruct) { + structListModel.removeElement(s); + } + } + if (listTmpTypedef != null) { + for (String s : listTmpTypedef) { + typedefListModel.removeElement(s); + } + } + } this.dispose(); } } + + public void valueChanged(ListSelectionEvent e) { + JList listTmp = (JList) e.getSource(); + if (listTmp.equals(structList)) { + structBool = true; + typedefBool = false; + } + if (listTmp.equals(typedefList)) { + typedefBool = true; + structBool = false; + } + + if (e.getValueIsAdjusting() == false) { + if (structBool == true) { + if (structList.getSelectedIndex() != -1) { + String select = structListModel.get(structList.getSelectedIndex()); + String[] splita = select.split(" = "); + nameStructTextField.setText(splita[0]); + String[] splitb = splita[1].split(" : "); + valueStructTextField.setText(splitb[0]); + String[] splitc = splitb[1].split(" "); + + if (splitc[0].equals("const")) { + constantStructRadioButton.setSelected(true); + if (splitc[1].equals("bool")) { + typeStructComboBoxString.setSelectedIndex(0); + } else if (splitc[1].equals("double")) { + typeStructComboBoxString.setSelectedIndex(1); + } else if (splitc[1].equals("float")) { + typeStructComboBoxString.setSelectedIndex(2); + } else if (splitc[1].equals("int")) { + typeStructComboBoxString.setSelectedIndex(3); + } else if (splitc[1].equals("long")) { + typeStructComboBoxString.setSelectedIndex(4); + } else if (splitc[1].equals("short")) { + typeStructComboBoxString.setSelectedIndex(5); + } + } else { + constantStructRadioButton.setSelected(false); + if (splitc[0].equals("bool")) { + typeStructComboBoxString.setSelectedIndex(0); + } else if (splitc[0].equals("double")) { + typeStructComboBoxString.setSelectedIndex(1); + } else if (splitc[0].equals("float")) { + typeStructComboBoxString.setSelectedIndex(2); + } else if (splitc[0].equals("int")) { + typeStructComboBoxString.setSelectedIndex(3); + } else if (splitc[0].equals("long")) { + typeStructComboBoxString.setSelectedIndex(4); + } else if (splitc[0].equals("short")) { + typeStructComboBoxString.setSelectedIndex(5); + } + } + + if (structListModel.getSize() >= 2) { + upButton.setEnabled(true); + downButton.setEnabled(true); + } + removeButton.setEnabled(true); + } + } + + if (typedefBool == true) { + if (typedefList.getSelectedIndex() != -1) { + String select = typedefListModel.get(typedefList.getSelectedIndex()); + String[] split = select.split(" : "); + nameTypedefTextField.setText(split[0]); + + if (split[1].equals("sc_dt::sc_int")) { + typeTypedefComboBoxString.setSelectedIndex(0); + } + + if (typedefListModel.getSize() >= 2) { + upButton.setEnabled(true); + downButton.setEnabled(true); + } + removeButton.setEnabled(true); + } + } + } + } } \ No newline at end of file diff --git a/src/main/java/ui/window/JDialogSysCAMSBlockTDF.java b/src/main/java/ui/window/JDialogSysCAMSBlockTDF.java index beda5f0caca097b109d640baf71cfd889b363f69..37eee22cee0597b7e46f04788007554bdeada5d3 100644 --- a/src/main/java/ui/window/JDialogSysCAMSBlockTDF.java +++ b/src/main/java/ui/window/JDialogSysCAMSBlockTDF.java @@ -40,12 +40,12 @@ package ui.window; import ui.syscams.*; import ui.util.*; -import java.util.*; import java.awt.*; import java.awt.event.*; +import java.util.*; import javax.swing.*; -import javax.swing.event.*; import javax.swing.border.*; +import javax.swing.event.*; /** * Class JDialogSystemCAMSBlockTDF @@ -73,11 +73,9 @@ public class JDialogSysCAMSBlockTDF extends JDialog implements ActionListener, L private JList<String> structList; private DefaultListModel<String> structListModel; private boolean structBool = false; - private JTextField nameTemplateTextField; private String listTypeTemplateString[]; private JComboBox<String> typeTemplateComboBoxString; - private JTextField nameTypedefTextField; private String listTypeTypedefString[]; private JComboBox<String> typeTypedefComboBoxString; @@ -626,8 +624,8 @@ public class JDialogSysCAMSBlockTDF extends JDialog implements ActionListener, L downPanel.add(cancelButton); mainPanel.add(downPanel, BorderLayout.CENTER); - this.getRootPane().setDefaultButton(saveCloseButton); pack(); + this.getRootPane().setDefaultButton(saveCloseButton); } public void actionPerformed(ActionEvent e) {