diff --git a/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java b/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java index 068e9aca3ec450866cf59e63403656dd2e9d93df..0142072bee32d148f619f48c31247ba835a58bc2 100755 --- a/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java +++ b/src/main/java/ui/avatarinteractivesimulation/AvatarInteractiveSimulationActions.java @@ -49,7 +49,7 @@ import java.awt.event.ActionListener; /** * Class AvatarInteractiveSimulationActions - * <p> + * * Creation: 21/01/2011 * * @author Ludovic APVRILLE diff --git a/src/main/java/ui/sysmlv2/ActionBar.java b/src/main/java/ui/sysmlv2/ActionBar.java index e41e964c9060b3dc5f75c01e2e232ccdedf32b97..1525ef29b0fcbe2a8875055bb876a00b1c98114f 100644 --- a/src/main/java/ui/sysmlv2/ActionBar.java +++ b/src/main/java/ui/sysmlv2/ActionBar.java @@ -38,8 +38,6 @@ package ui.sysmlv2; -import ui.*; - import javax.swing.*; @@ -47,141 +45,39 @@ import javax.swing.*; * Class ActionBar * Sysmlv2 edition * Creation: 15/07/2021 - * @version 1.0 15/07/2021 + * * @author Ludovic APVRILLE + * @version 1.0 15/07/2021 */ public class ActionBar extends JToolBar { - + protected JFrameSysMLV2Text frame; - + public ActionBar(JFrameSysMLV2Text _frame) { super(); frame = _frame; setOrientation(SwingConstants.HORIZONTAL); - setFloatable(true) ; - setEnableActions(false); + setFloatable(true); + setEnableActions(false); setButtons(); } - - public void setEnableActions(boolean b) { - /*mgui.actions[LEGUIAction.COMMENT_REGION].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_SECTION].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_SUBSECTION].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_REFERENCE].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_LABEL].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_CITE].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_ITEMIZE].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_ITEM].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_ENUMERATE].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_FIGURE].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_BLOCK].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_ALERTBLOCK].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_EXAMPLEBLOCK].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_COLUMNS].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_COLUMN].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_TABULAR].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_ROWCOLOR].setEnabled(b); - mgui.actions[LEGUIAction.INSERT_HLINE].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_LISTING].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_FRAME].setEnabled(b); - - mgui.actions[LEGUIAction.INSERT_NOTE].setEnabled(b);*/ - - - } - - protected void setButtons() { + + public void setEnableActions(boolean b) { + frame.actions[SysMLV2Actions.ACT_SAVE].setEnabled(b); + + + } + + protected void setButtons() { JButton button; - - /*button = this.add(mgui.actions[LEGUIAction.COMMENT_REGION]);*/ - - this.addSeparator(); - - /*button = this.add(mgui.actions[LEGUIAction.INSERT_FRAME]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_SECTION]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_SUBSECTION]); - button.addMouseListener(mgui.mouseHandler); - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_LABEL]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_REFERENCE]); - button.addMouseListener(mgui.mouseHandler); - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_CITE]); - button.addMouseListener(mgui.mouseHandler); - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_ITEMIZE]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_ENUMERATE]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_ITEM]); - button.addMouseListener(mgui.mouseHandler); - + button = this.add(frame.actions[SysMLV2Actions.ACT_SAVE]); + button.addMouseListener(frame.mouseHandler); + this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_FIGURE]); - button.addMouseListener(mgui.mouseHandler); - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_BLOCK]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_ALERTBLOCK]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_EXAMPLEBLOCK]); - button.addMouseListener(mgui.mouseHandler); - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_COLUMNS]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_COLUMN]); - button.addMouseListener(mgui.mouseHandler); - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_TABULAR]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_HLINE]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.INSERT_ROWCOLOR]); - button.addMouseListener(mgui.mouseHandler); - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.INSERT_NOTE]); - button.addMouseListener(mgui.mouseHandler); */ - - } - + + + } + } // Class diff --git a/src/main/java/ui/sysmlv2/JFrameSysMLV2Text.java b/src/main/java/ui/sysmlv2/JFrameSysMLV2Text.java index 0d9603ee8525a50093dad2eb37e24d7e3d82c55c..332e319fd5464d4b48bef5587a20d46f2cbbf021 100644 --- a/src/main/java/ui/sysmlv2/JFrameSysMLV2Text.java +++ b/src/main/java/ui/sysmlv2/JFrameSysMLV2Text.java @@ -39,13 +39,18 @@ package ui.sysmlv2; +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; /** @@ -57,15 +62,23 @@ import java.awt.event.ActionListener; */ public class JFrameSysMLV2Text extends JFrame implements ActionListener { - public static final int SAVED = 1; + public final String REQUIREMENT_TEXT = "requirement def id '1.1' name {\n" + + "\tdoc /* documentation */\n\n" + + "\tsubject x : y\n\n" + + "\tattribute x : y ;\n\n" + + "\trequire constraint { x < y }\n\n" + + "}\n"; + public static final int SAVED = 1; + public SysMLV2Actions[] actions; private TGCSysMLV2 comp; - + private JLabel statuss; private JButton buttonCancel, buttonClose; private JTextArea jta; private JPanelForEdition jpfe; + public MouseHandler mouseHandler; public JFrameSysMLV2Text(String title, TGCSysMLV2 _comp, String[] _lines, ImageIcon imgic) { @@ -76,6 +89,13 @@ public class JFrameSysMLV2Text extends JFrame implements ActionListener { Container framePanel = getContentPane(); framePanel.setLayout(new BorderLayout()); + initActions(); + + statuss = createStatusBar(); + + // Mouse handler + mouseHandler = new MouseHandler(statuss); + String line = ""; if (_lines != null) { for (int i = 0; i < _lines.length; i++) { @@ -84,7 +104,6 @@ public class JFrameSysMLV2Text extends JFrame implements ActionListener { } - jta = new JTextArea(line); /*jta.setEditable(true); @@ -93,8 +112,8 @@ public class JFrameSysMLV2Text extends JFrame implements ActionListener { Font f = new Font("Courrier", Font.BOLD, 12); jta.setFont(f);*/ - jpfe = new JPanelForEdition(this); - jpfe.setText(line); + jpfe = new JPanelForEdition(this); + jpfe.setText(line); JScrollPane jsp = new JScrollPane(jpfe); @@ -109,6 +128,7 @@ public class JFrameSysMLV2Text extends JFrame implements ActionListener { JPanel jp = new JPanel(); jp.add(buttonCancel); jp.add(buttonClose); + jp.add(statuss); framePanel.add(jp, BorderLayout.SOUTH); @@ -116,24 +136,54 @@ public class JFrameSysMLV2Text extends JFrame implements ActionListener { pack(); } + private void initActions() { + actions = new SysMLV2Actions[SysMLV2Actions.NB_ACTION]; + for (int i = 0; i < SysMLV2Actions.NB_ACTION; i++) { + actions[i] = new SysMLV2Actions(i); + actions[i].addActionListener(this); + } + + } + + private JLabel createStatusBar() { + statuss = new JLabel("Ready..."); + statuss.setForeground(ColorManager.InteractiveSimulationText); + statuss.setBorder(BorderFactory.createEtchedBorder()); + return statuss; + } + public void actionPerformed(ActionEvent evt) { + TraceManager.addDev("Action performed"); + if (evt.getSource() == buttonCancel) { cancel(); } else if (evt.getSource() == buttonClose) { close(); + } else if (evt.getActionCommand().equals(actions[SysMLV2Actions.ACT_SAVE].getActionCommand())) { + TraceManager.addDev("save"); + saveText(); + } else if ( evt.getActionCommand().equals(actions[SysMLV2Actions.INSERT_REQUIREMENT].getActionCommand())) { + TraceManager.addDev("insert req"); + insertText(REQUIREMENT_TEXT); } + + } private void cancel() { dispose(); } - private void close() { + private void saveText() { if (comp != null) { comp.setLines(jpfe.getText()); comp.getTDiagramPanel().repaint(); } + } + + private void close() { + saveText(); dispose(); } @@ -146,6 +196,45 @@ public class JFrameSysMLV2Text extends JFrame implements ActionListener { } + private void insertText(String toBeInserted) { + if (jpfe != null) { + jpfe.insertText(toBeInserted, ""); + } + } + + /** + * This adapter is constructed to handle mouse over component events. + */ + private class MouseHandler extends MouseAdapter { + + private JLabel label; + + /** + * ctor for the adapter. + * + * @param label the JLabel which will recieve value of the + * Action.LONG_DESCRIPTION key. + */ + public MouseHandler(JLabel label) { + setLabel(label); + } + + public void setLabel(JLabel label) { + this.label = label; + } + + public void mouseEntered(MouseEvent evt) { + if (evt.getSource() instanceof AbstractButton) { + AbstractButton button = (AbstractButton) evt.getSource(); + Action action = button.getAction(); + if (action != null) { + String message = (String) action.getValue(Action.LONG_DESCRIPTION); + label.setText(message); + } + } + } + } + } // Class diff --git a/src/main/java/ui/sysmlv2/SyntaxDocument.java b/src/main/java/ui/sysmlv2/SyntaxDocument.java index d00aec046ddc1378f410492d5223e7eb234a220b..6382fb4ecf2a1cc88872b245925ff10a8b53cbba 100644 --- a/src/main/java/ui/sysmlv2/SyntaxDocument.java +++ b/src/main/java/ui/sysmlv2/SyntaxDocument.java @@ -66,10 +66,11 @@ class SyntaxDocument extends DefaultStyledDocument { private static Color Green = new Color(43, 125, 15); private static Color ColorComment = new Color(156, 0, 255); private static Color ColorText = Color.black; - private static Color Color0 = Color.blue; + private static Color Color0 = ENSTRed; private static Color Color1 = Green; private static Color Color2 = Color.orange; - private static Color Color3 = ENSTRed; + private static Color Color3 = Color.blue; + private static Color Color4 = Color.GRAY; private static Color ColorFind = Color.magenta; @@ -133,6 +134,7 @@ class SyntaxDocument extends DefaultStyledDocument { StyleConstants.setForeground(keyword[1], Color1); StyleConstants.setForeground(keyword[2], Color2); StyleConstants.setForeground(keyword[3], Color3); + StyleConstants.setForeground(keyword[4], Color4); // main keywords keywords[0].add( "package"); diff --git a/src/main/java/ui/sysmlv2/SysMLV2Actions.java b/src/main/java/ui/sysmlv2/SysMLV2Actions.java new file mode 100755 index 0000000000000000000000000000000000000000..a011b52f370e45bd387b65b7363740d9309f60fe --- /dev/null +++ b/src/main/java/ui/sysmlv2/SysMLV2Actions.java @@ -0,0 +1,157 @@ +/* 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.sysmlv2; + +import ui.TAction; +import ui.util.IconManager; + +import javax.swing.*; +import javax.swing.event.EventListenerList; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Class © + * <p> + * Creation: 15/07/2021 + * + * @author Ludovic APVRILLE + * @version 1.0 15/07/2021 + * @see ui.sysmlv2.JFrameSysMLV2Text + */ +public class SysMLV2Actions extends AbstractAction { + // Actions + public static final int INSERT_REQUIREMENT = 0; + public static final int ACT_SAVE = 1; + public static final int INSERT_STATE_MACHINE = 2; + public static final int INSERT_CONSTRAINT = 3; + + public static final int NB_ACTION = 4; + + + public static final TAction[] actions = new TAction[NB_ACTION]; + public static final String LARGE_ICON = "LargeIcon"; + private EventListenerList listeners; + + + public SysMLV2Actions(int id) { + if (actions[0] == null) { + init(); + } + if (actions[id] == null) { + return; + } + + putValue(Action.NAME, actions[id].NAME); + putValue(Action.SMALL_ICON, actions[id].SMALL_ICON); + putValue(LARGE_ICON, actions[id].LARGE_ICON); + putValue(Action.SHORT_DESCRIPTION, actions[id].SHORT_DESCRIPTION); + putValue(Action.LONG_DESCRIPTION, actions[id].LONG_DESCRIPTION); + //putValue(Action.MNEMONIC_KEY, new Integer(actions[id].MNEMONIC_KEY)); + if (actions[id].MNEMONIC_KEY != 0) { + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(actions[id].MNEMONIC_KEY, java.awt.event.InputEvent.CTRL_MASK)); + } + putValue(Action.ACTION_COMMAND_KEY, actions[id].ACTION_COMMAND_KEY); + + } + + public void setName(int index, String name) { + actions[index].NAME = name; + putValue(Action.NAME, actions[index].NAME); + } + + public void init() { + actions[ACT_SAVE] = new TAction("sysmlv2-save", "Save text", IconManager.imgic24, IconManager.imgic25, + "Save", "Save text under edition", 'S'); + + actions[INSERT_REQUIREMENT] = new TAction("sysmlv2-insert-req", "Insert requirement", IconManager.imgic5006, + IconManager.imgic5006, + "Requirement", "Insert requirement", 'R'); + + actions[INSERT_CONSTRAINT] = new TAction("sysmlv2-insert-constraint", "Insert constraint", IconManager.imgic1302, + IconManager.imgic1302, + "Constraint", "Insert constraint", 'C'); + + actions[INSERT_STATE_MACHINE] = new TAction("sysmlv2-insert-sm", "Insert state machine", IconManager.imgic1302, + IconManager.imgic1302, + "State machine", "Insert state machine", 'M'); + + } + + public String getActionCommand() { + return (String) getValue(Action.ACTION_COMMAND_KEY); + } + + public String getShortDescription() { + return (String) getValue(Action.SHORT_DESCRIPTION); + } + + public String getLongDescription() { + return (String) getValue(Action.LONG_DESCRIPTION); + } + + public void actionPerformed(ActionEvent evt) { + // + if (listeners != null) { + Object[] listenerList = listeners.getListenerList(); + + // Recreate the ActionEvent and stuff the value of the ACTION_COMMAND_KEY + ActionEvent e = new ActionEvent(evt.getSource(), evt.getID(), + (String) getValue(Action.ACTION_COMMAND_KEY)); + for (int i = 0; i <= listenerList.length - 2; i += 2) { + ((ActionListener) listenerList[i + 1]).actionPerformed(e); + } + } + } + + public void addActionListener(ActionListener l) { + if (listeners == null) { + listeners = new EventListenerList(); + } + listeners.add(ActionListener.class, l); + } + + public void removeActionListener(ActionListener l) { + if (listeners == null) { + return; + } + listeners.remove(ActionListener.class, l); + } +} diff --git a/src/main/java/ui/sysmlv2/TextBar.java b/src/main/java/ui/sysmlv2/TextBar.java index 9e93e1d3cf1f6866c80176805a4e58b108568fc5..e0e159e4b2a982c370b4bfd2130b587a5a111d22 100644 --- a/src/main/java/ui/sysmlv2/TextBar.java +++ b/src/main/java/ui/sysmlv2/TextBar.java @@ -46,75 +46,37 @@ import javax.swing.*; * Class TextBar * Sysmlv2 edition * Creation: 15/07/2021 - * @version 1.0 15/07/2021 + * * @author Ludovic APVRILLE + * @version 1.0 15/07/2021 */ public class TextBar extends JToolBar { - + protected JFrameSysMLV2Text frame; - + public TextBar(JFrameSysMLV2Text _frame) { super(); frame = _frame; setOrientation(SwingConstants.HORIZONTAL); - setFloatable(true) ; - setEnableActions(false); + setFloatable(true); + setEnableActions(false); setButtons(); } - - public void setEnableActions(boolean b) { - /*mgui.actions[LEGUIAction.TEXT_BOLD].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_ITALICS].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_UNDERLINE].setEnabled(b); - - mgui.actions[LEGUIAction.ALIGN_LEFT].setEnabled(b); - mgui.actions[LEGUIAction.ALIGN_RIGHT].setEnabled(b); - mgui.actions[LEGUIAction.ALIGN_CENTER].setEnabled(b); - mgui.actions[LEGUIAction.ALIGN_JUSTIFY].setEnabled(b); - - mgui.actions[LEGUIAction.TEXT_SIZE_0].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_1].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_2].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_3].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_4].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_5].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_6].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_7].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_8].setEnabled(b); - mgui.actions[LEGUIAction.TEXT_SIZE_9].setEnabled(b);*/ - - - } - - protected void setButtons() { + + public void setEnableActions(boolean b) { + frame.actions[SysMLV2Actions.INSERT_REQUIREMENT].setEnabled(true); + + } + + protected void setButtons() { JButton button; - - /*button = this.add(mgui.actions[LEGUIAction.TEXT_BOLD]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.TEXT_ITALICS]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.TEXT_UNDERLINE]); - button.addMouseListener(mgui.mouseHandler); - - - this.addSeparator(); - - button = this.add(mgui.actions[LEGUIAction.ALIGN_LEFT]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.ALIGN_CENTER]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.ALIGN_JUSTIFY]); - button.addMouseListener(mgui.mouseHandler); - - button = this.add(mgui.actions[LEGUIAction.ALIGN_RIGHT]); - button.addMouseListener(mgui.mouseHandler);*/ - - - this.addSeparator(); + + button = this.add(frame.actions[SysMLV2Actions.INSERT_REQUIREMENT]); + button.addMouseListener(frame.mouseHandler); + + + + this.addSeparator(); /*button = this.add(mgui.actions[LEGUIAction.TEXT_SIZE_0]); button.addMouseListener(mgui.mouseHandler); @@ -136,10 +98,10 @@ public class TextBar extends JToolBar { button.addMouseListener(mgui.mouseHandler); button = this.add(mgui.actions[LEGUIAction.TEXT_SIZE_9]); button.addMouseListener(mgui.mouseHandler);*/ - - - } - + + + } + } // Class