diff --git a/src/main/java/common/ConfigurationTTool.java b/src/main/java/common/ConfigurationTTool.java index 855bf217a60b38f70bada29bbb04f1b5d5b207c7..e4ae215327c852f2ac6f83ba2d2591e5b92f40fc 100755 --- a/src/main/java/common/ConfigurationTTool.java +++ b/src/main/java/common/ConfigurationTTool.java @@ -148,6 +148,10 @@ public class ConfigurationTTool { // Z3 public static String Z3LIBS = ""; + // AI + public static String OPENAIKey = ""; + public static String OPENAIModel = ""; + // Ontology //public static String RequirementOntologyWebsite = ""; @@ -500,6 +504,10 @@ public class ConfigurationTTool { sb.append("Requirement ontology website: " + RequirementOntologyWebsite + "\n"); sb.append("Attack ontology website: " + AttackOntologyWebsite + "\n");*/ + sb.append("\nAI:\n"); + sb.append("Key: " + OPENAIKey + "\n"); + sb.append("Model: " + OPENAIModel + "\n"); + // Plugins sb.append("\nPlugins:\n"); //sb.append("Plugin path: " + PLUGIN_PKG + "\n"); @@ -793,6 +801,14 @@ public class ConfigurationTTool { if (nl.getLength() > 0) ProVerifVerifierHost(nl); + nl = doc.getElementsByTagName("OPENAIKey"); + if (nl.getLength() > 0) + openAIKey(nl); + + nl = doc.getElementsByTagName("OPENAIModel"); + if (nl.getLength() > 0) + openAIModel(nl); + // Ontologies /*nl = doc.getElementsByTagName("RequirementOntologyWebsite"); @@ -1577,6 +1593,24 @@ public class ConfigurationTTool { } } + private static void openAIKey(NodeList nl) throws MalformedConfigurationException { + try { + Element elt = (Element) (nl.item(0)); + OPENAIKey = elt.getAttribute("data"); + } catch (Exception e) { + throw new MalformedConfigurationException(e.getMessage()); + } + } + + private static void openAIModel(NodeList nl) throws MalformedConfigurationException { + try { + Element elt = (Element) (nl.item(0)); + OPENAIModel = elt.getAttribute("data"); + } catch (Exception e) { + throw new MalformedConfigurationException(e.getMessage()); + } + } + private static void Plugin(NodeList nl) throws MalformedConfigurationException { PLUGIN = new String[nl.getLength()]; PLUGIN_PKG = new String[nl.getLength()]; diff --git a/src/main/java/ui/ActionPerformer.java b/src/main/java/ui/ActionPerformer.java index bc3e128f9cc98c453eff10655c6b030277f8efae..33c663d9e1fe2537c2c8c0308020dc9dee6885c3 100644 --- a/src/main/java/ui/ActionPerformer.java +++ b/src/main/java/ui/ActionPerformer.java @@ -79,6 +79,8 @@ public class ActionPerformer { mgui.openLastProject(); } else if (command.equals(mgui.actions[TGUIAction.ACT_SAVE].getActionCommand())) { mgui.saveProject(); + } else if (command.equals(mgui.actions[TGUIAction.ACT_IA].getActionCommand())) { + mgui.ai(); } else if (command.equals(mgui.actions[TGUIAction.ACT_SAVE_AS_MODEL].getActionCommand())) { mgui.saveAsNewModel(); } else if (command.equals(mgui.actions[TGUIAction.ACT_SAVE_AS_PROJECT].getActionCommand())) { diff --git a/src/main/java/ui/JToolBarMainTurtle.java b/src/main/java/ui/JToolBarMainTurtle.java index 4b6668116f8aeb1038c65c55d170b7fca8700c24..92dcb2b9edfaaab874fa04e4a16a9e37a5c539e5 100644 --- a/src/main/java/ui/JToolBarMainTurtle.java +++ b/src/main/java/ui/JToolBarMainTurtle.java @@ -84,6 +84,9 @@ public class JToolBarMainTurtle extends JToolBar implements ActionListener private JButton oneClickrtlotos, onclicklotos, gensystemc, simusystemc, gentml, genC, genjava, nc,externalSearch, internalSearch; private JMenuItem oneClickrtlotosMI, onclicklotosMI, gensystemcMI, simusystemcMI, gentmlMI, genCMI, genjavaMI, ncMI; + // IA + private JButton ia; + // Main button private JButton menuButton; private JPopupMenu menu; @@ -353,6 +356,11 @@ public class JToolBarMainTurtle extends JToolBar implements ActionListener addSeparator(); + ia = add(mgui.actions[TGUIAction.ACT_IA]); + ia.addMouseListener(mgui.mouseHandler); + + addSeparator(); + showAvatarActions(false); search = new JTextField("", 10); search.setEnabled(false); @@ -660,6 +668,10 @@ public class JToolBarMainTurtle extends JToolBar implements ActionListener ncMI.setVisible(!b); } + if (ia != null) { + ia.setVisible(!b); + } + if (gendesign != null) { gendesign.setVisible(!b); gendesignMI.setVisible(!b); diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index 966df469938051a7a8507676a13497a5ba7208bd..f7ead006f5a95503c04357eadc2bd3a83be658f5 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -5069,6 +5069,13 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per } + public void ai() { + TraceManager.addDev("ai"); + JFrameAI frameAI = new JFrameAI("System engineering with AI"); + GraphicLib.centerOnParent(frameAI, 1000, 800); + frameAI.setVisible(true); + } + public void avatarSimulation() { TraceManager.addDev("Avatar simulation"); diff --git a/src/main/java/ui/ModeManager.java b/src/main/java/ui/ModeManager.java index 7dfdc08433eeefeca1a338af97fbaf722566f345..86c1c187b9a9bf092c486df5699be5d556848153 100644 --- a/src/main/java/ui/ModeManager.java +++ b/src/main/java/ui/ModeManager.java @@ -55,7 +55,7 @@ public class ModeManager { switch (mode) { case MainGUI.CREATE_NEW_PANEL: actions[TGUIAction.ACT_MODEL_CHECKING].setEnabled(false); - TraceManager.addDev("Deactivating syntax checking"); + //TraceManager.addDev("Deactivating syntax checking"); break; case MainGUI.NOT_OPENED: mgui.activeActions(false); @@ -98,6 +98,7 @@ public class ModeManager { if (mainBar != null) { mainBar.activateSearch(false); } + actions[TGUIAction.ACT_IA].setEnabled(false); break; case MainGUI.OPENED: actions[TGUIAction.ACT_MERGE].setEnabled(true); @@ -136,6 +137,9 @@ public class ModeManager { if (mainBar != null) { mainBar.activateSearch(true); } + + actions[TGUIAction.ACT_IA].setEnabled(true); + // @author: Huy TRUONG actions[TGUIAction.ACT_EXTERNAL_SEARCH].setEnabled(true); // disable when there is no text in search textfield diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java index 0de491cadf6d2755bb090b2dcd8fb4406a994545..91f879b9ac78df89ca3a5a5e7880fcc49f533c13 100644 --- a/src/main/java/ui/TGUIAction.java +++ b/src/main/java/ui/TGUIAction.java @@ -74,6 +74,8 @@ public class TGUIAction extends AbstractAction { public static final int ACT_MERGE = 228; public static final int ACT_SAVE = 2; + public static final int ACT_IA = 564; + public static final int ACT_SAVE_AS_PROJECT = 31; public static final int ACT_SAVE_AS_MODEL = 475; public static final int ACT_SAVE_TIF = 213; @@ -729,7 +731,7 @@ public class TGUIAction extends AbstractAction { - public static final int NB_ACTION = 564; // Last + 1 + public static final int NB_ACTION = 565; // Last + 1 private static final TAction [] actions = new TAction[NB_ACTION]; @@ -849,6 +851,8 @@ public class TGUIAction extends AbstractAction { actions[ACT_SAVE_AS_PROJECT] = new TAction("saveasproject-command", "Save as Project",IconManager.imgic24, IconManager.imgic25, "Save as Project", "Save an opened or a new TTool modeling under a new project", 0); actions[ACT_SAVE_AS_MODEL] = new TAction("saveasmodel-command", "Save as Model",IconManager.imgic24, IconManager.imgic25, "Save as Model", "Save an opened or a new TTool modeling under a new model", 0); actions[ACT_QUIT] = new TAction("quit-command", "Quit", IconManager.imgic26, IconManager.imgic27, "Quit", "Quit TTool", 'Q'); + actions[ACT_IA] = new TAction("ia-command", "IA", IconManager.imgic152, IconManager.imgic152, "IA", "Start IA for modeling", 'A'); + actions[ACT_SAVE_LOTOS] = new TAction("save-last-lotos", "Save last RT-LOTOS specification",IconManager.imgic24, IconManager.imgic25, "Save last RT-LOTOS specification", "Save the lastest automatically generated RT-LOTOS specification", 0); actions[ACT_SAVE_DTA] = new TAction("save-last-dta", "Save last DTA",IconManager.imgic24, IconManager.imgic25, "Save last DTA", "Save the lastest built DTA", 0); diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index 6c8f7c5f46caa81d0973b5feff25fa1b0bbc91d3..2d242069ff51765c4d91465763791172d96b59ab 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -76,7 +76,7 @@ public class IconManager { public static ImageIcon imgic90, imgic92, imgic94, imgic96, imgic98, imgic99; // Diverse actions - public static ImageIcon imgic150, imgic151; + public static ImageIcon imgic150, imgic151, imgic152; // Class diagram @@ -362,6 +362,7 @@ public class IconManager { private static String icon150 = "toolbarButtonGraphics/general/removeTrace16.gif"; private static String icon151 = "toolbarButtonGraphics/general/removeTrace24.gif"; + private static String icon152 = "ia.gif"; private static String icon200 = "toolbarButtonGraphics/general/Properties16.gif"; private static String icon201 = "toolbarButtonGraphics/general/Properties24.gif"; @@ -941,6 +942,7 @@ public class IconManager { imgic150 = getIcon(icon150); imgic151 = getIcon(icon151); + imgic152 = getIcon(icon152); imgic200 = getIcon(icon200); imgic201 = getIcon(icon201); diff --git a/src/main/java/ui/window/JFrameAI.java b/src/main/java/ui/window/JFrameAI.java new file mode 100644 index 0000000000000000000000000000000000000000..b9a24c0768b7a163ddab48de997a78e62db251eb --- /dev/null +++ b/src/main/java/ui/window/JFrameAI.java @@ -0,0 +1,219 @@ +/* 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.TraceManager; +import ui.ColorManager; +import ui.TGCSysMLV2; +import ui.util.IconManager; + +import javax.swing.*; +import javax.swing.plaf.basic.BasicTabbedPaneUI; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + + +/** + * Class JFrameSysMLV2Text + * Creation: 13/07/2021 + * version 1.0 13/07/2021 + * + * @author Ludovic APVRILLE + */ +public class JFrameAI extends JFrame implements ActionListener { + + private String [] POSSIBLE_ACTIONS = {"Chat", "Classify requirements"}; + + private JTextArea question, answer, console; + protected JComboBox<String> listOfPossibleActions; + + + private JButton buttonClose, buttonStart, buttonApplyResponse; + + public JFrameAI(String title) { + super(title); + makeComponents(); + } + + public void makeComponents() { + + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + Container framePanel = getContentPane(); + framePanel.setLayout(new BorderLayout()); + + setIconImage(IconManager.imgic152.getImage()); + + // Top panel : options + JPanel panelTop = new JPanel(); + panelTop.setLayout(new BorderLayout()); + panelTop.setBorder(new javax.swing.border.TitledBorder("Options")); + + listOfPossibleActions = new JComboBox<>(POSSIBLE_ACTIONS); + panelTop.add(listOfPossibleActions, BorderLayout.CENTER); + + framePanel.add(panelTop, BorderLayout.NORTH); + + + // Middle panel + + /*jta.setEditable(true); + jta.setMargin(new Insets(10, 10, 10, 10)); + jta.setTabSize(3); + Font f = new Font("Courrier", Font.BOLD, 12); + jta.setFont(f);*/ + + JPanel questionPanel = new JPanel(); + questionPanel.setBorder(new javax.swing.border.TitledBorder("Question")); + questionPanel.setPreferredSize(new Dimension(450, 550)); + question = new JTextArea(); + question.setPreferredSize(new Dimension(400, 500)); + JScrollPane scrollPane = new JScrollPane(question); + questionPanel.add(scrollPane, BorderLayout.CENTER); + + JPanel answerPanel = new JPanel(); + answerPanel.setBorder(new javax.swing.border.TitledBorder("Answer")); + answerPanel.setPreferredSize(new Dimension(450, 550)); + answer = new JTextArea(); + answer.setPreferredSize(new Dimension(400, 500)); + setOptionsJTextArea(answer, true); + scrollPane = new JScrollPane(answer); + answerPanel.add(scrollPane, BorderLayout.CENTER); + + JPanel consolePanel = new JPanel(); + consolePanel.setBorder(new javax.swing.border.TitledBorder("Console")); + console = new JTextArea(); + console.setPreferredSize(new Dimension(900, 150)); + addToConsole("Select options and click on \"start\""); + scrollPane = new JScrollPane(console); + consolePanel.add(scrollPane, BorderLayout.CENTER); + + JPanel middlePanel = new JPanel(new BorderLayout()); + JPanel intermediate = new JPanel(); + intermediate.add(questionPanel); + intermediate.add(answerPanel); + middlePanel.add(intermediate, BorderLayout.CENTER); + middlePanel.add(consolePanel, BorderLayout.SOUTH); + + framePanel.add(middlePanel, BorderLayout.CENTER); + + + + // Lower panel + + buttonClose = new JButton("Close", IconManager.imgic26); + buttonClose.addActionListener(this); + + buttonStart = new JButton("Start", IconManager.imgic53); + buttonStart.addActionListener(this); + + buttonApplyResponse = new JButton("Apply response", IconManager.imgic25); + buttonStart.addActionListener(this); + + JPanel lowPart = new JPanel(new BorderLayout()); + JPanel jp = new JPanel(); + jp.add(buttonClose); + jp.add(buttonStart); + jp.add(buttonApplyResponse); + lowPart.add(jp, BorderLayout.CENTER); + framePanel.add(lowPart, BorderLayout.SOUTH); + + enableDisableActions(); + + + pack(); + } + + + + public void actionPerformed(ActionEvent evt) { + + TraceManager.addDev("Action performed"); + + if (evt.getSource() == buttonClose) { + close(); + } else if (evt.getSource() == buttonStart) { + start(); + } else if (evt.getSource() == buttonApplyResponse) { + applyResponse(); + } + } + + + private void close() { + dispose(); + } + + private void start() { + + } + + private void applyResponse() { + + } + + private void enableDisableActions() { + + } + + private void setOptionsJTextArea(JTextArea jta, boolean _isEditable) { + jta.setEditable(_isEditable); + jta.setMargin(new Insets(10, 10, 10, 10)); + jta.setTabSize(3); + Font f = new Font("Courrier", Font.BOLD, 12); + jta.setFont(f); + } + + private void addToConsole() { + console.append("Select options and click on \"start\""); + } + + + + + + + + +} // Class + + \ No newline at end of file diff --git a/src/main/resources/ui/util/ia.gif b/src/main/resources/ui/util/ia.gif new file mode 100644 index 0000000000000000000000000000000000000000..d91486d77ef507a3bb45d151746199222b214c3a Binary files /dev/null and b/src/main/resources/ui/util/ia.gif differ