package easysm.boundaries.components;
import java.awt.BorderLayout;
import java.awt.Event;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import easysm.boundaries.EasySM;
import easysm.boundaries.components.classdiagram.CD_Panel;
import easysm.boundaries.components.events.E_Panel;
import easysm.boundaries.components.stateobserver.SOPanel;
import easysm.boundaries.components.statetable.ST_panel;
import easysm.boundaries.components.utils.EasySMFileFilter;
import easysm.boundaries.components.utils.JCheckBoxTabRender;
import easysm.datatypes.Name;
/**
* @author Artur Tolstenco
*/
public class EasySMFrame extends javax.swing.JFrame
{
private static final long serialVersionUID = 1L;
private static String PROGRAM_NAME = "EasySM";
// MENU BAR
private JMenuBar jMenuBar;
private JMenu jMenu_file;
private JMenuItem file_close;
private JMenuItem file_save;
private JMenuItem file_exit;
private JMenuItem file_new;
private JMenuItem file_open;
private JMenu jMenu_updateParts;
private JMenuItem updateParts_eventsAndCondReact;
private JMenuItem updateParts_stateObserversAndInv;
private JMenuItem updateParts_inputclassDiagram;
private JMenuItem updateParts_stateTable;
private JMenu jMenu_stateMachine;
private JMenuItem stateMachine_generate;
private JMenuItem stateMachine_showOutputCD;
private JMenuItem stateMachine_showSM;
private JMenu jMenu_help;
private JMenuItem help_showSplash;
private JMenuItem help_about;
private JSeparator jSeparator3;
private JSeparator jSeparator2;
private JSeparator jSeparator1;
// TOOLBAR
private JToolBar jtoolbar;
private JButton button_save;
private JButton button_open;
private JButton button_new;
private JButton button_showOutputCD;
private JButton button_showSM;
private JButton button_generateStateMachine;
// TABS
private JTabbedPane jTabbedPane_contentPane;
private E_Panel events_panel;
private SOPanel stateObservers_panel;
private CD_Panel classDiagram_panel;
private ST_panel stats_panel;
// Checkboxes for tabs
private JCheckBoxTabRender checkbox_cd;
private JCheckBoxTabRender checkbox_so;
private JCheckBoxTabRender checkbox_ev;
private JCheckBoxTabRender checkbox_st;
// Viewers
private FullViewer fullViewerSM;
private FullViewer fullViewerOutputCD;
private ShowSplashWindow_Help splashReshow;
private SplashWindow splash;
// ordinary variables
private boolean error;
private int prevSelectionedTab = -1;
private EasySM easySm;
public EasySMFrame(EasySM easySm)
{
super();
this.easySm = easySm;
// splash window here showing
splash = new SplashWindow();
splash.toFront();
initGUI();
fullViewerSM = new FullViewer("State Machine");
fullViewerOutputCD = new FullViewer("Output Class Diagram");
splashReshow = new ShowSplashWindow_Help();
// finishing showing splash window
closedStateSetButtons();
splash.dispose();
}
private void initGUI()
{
try {
BorderLayout thisLayout = new BorderLayout();
getContentPane().setLayout(thisLayout);
{
jTabbedPane_contentPane = new JTabbedPane();
/**
* closing and opening the right part every time the tab is changed
*/
jTabbedPane_contentPane.addChangeListener(new ChangeListener()
{
@Override
public void stateChanged(ChangeEvent e)
{
JTabbedPane pane = (JTabbedPane) e.getSource();
int sel = pane.getSelectedIndex();
if (easySm.updateProject() == null)
return;
if (sel == 0) {
easySm.updateProject().openInputCD();
switch (prevSelectionedTab) {
case 1:
easySm.updateProject().updateSO().closePart();
stateObservers_panel.hideFullViewer();
break;
case 2:
easySm.updateProject().updateEvents().closePart();
events_panel.hideFullViewer();
break;
case 3:
easySm.updateProject().updateST().closePart();
stats_panel.hideFullViewer();
break;
default:
break;
}
} else if (sel == 1) {
easySm.updateProject().openSO();
switch (prevSelectionedTab) {
case 0:
easySm.updateProject().updateInputCD().closePart();
classDiagram_panel.hideFullViewer();
break;
case 2:
easySm.updateProject().updateEvents().closePart();
events_panel.hideFullViewer();
break;
case 3:
easySm.updateProject().updateST().closePart();
stats_panel.hideFullViewer();
break;
default:
break;
}
} else if (sel == 2) {
easySm.updateProject().openEvents();
switch (prevSelectionedTab) {
case 1:
easySm.updateProject().updateSO().closePart();
stateObservers_panel.hideFullViewer();
break;
case 0:
easySm.updateProject().updateInputCD().closePart();
classDiagram_panel.hideFullViewer();
break;
case 3:
easySm.updateProject().updateST().closePart();
stats_panel.hideFullViewer();
break;
default:
break;
}
} else if (sel == 3) {
easySm.updateProject().openST();
switch (prevSelectionedTab) {
case 1:
easySm.updateProject().updateSO().closePart();
stateObservers_panel.hideFullViewer();
break;
case 2:
easySm.updateProject().updateEvents().closePart();
events_panel.hideFullViewer();
break;
case 0:
easySm.updateProject().updateInputCD().closePart();
classDiagram_panel.hideFullViewer();
break;
default:
break;
}
}
prevSelectionedTab = sel;
}
});
jTabbedPane_contentPane.setEnabled(false);
getContentPane().add(jTabbedPane_contentPane, BorderLayout.CENTER);
{
// Input Class Diagram Panel
classDiagram_panel = new CD_Panel(easySm.updateProject().updateInputCD());
classDiagram_panel.setEnabledElements(false);
jTabbedPane_contentPane
.addTab("<html>Input <u>C</u>lass Diagram</html>",
new ImageIcon(getClass().getClassLoader().getResource("easysm/icons/x22/code-class.png")),
classDiagram_panel,
"<html>Edit/Add/Delete class diagram elements (Classes, Enumerations)<br/>"
+ "The selected checkbox means the <b>Input Class Diagram</b> Part is "
+ "<b>Valid</b> and <b>Not Valid</b> otherwise.<br/>"
+ "Check the checkbox to validate the entire <b>Input Class Diagram</b> Part.</html>");
jTabbedPane_contentPane.setMnemonicAt(jTabbedPane_contentPane.getTabCount() - 1, KeyEvent.VK_C);
checkbox_cd = new JCheckBoxTabRender(jTabbedPane_contentPane, jTabbedPane_contentPane.getTabCount() - 1);
/**
* Managing the validation the Input Class Diagram Part
*/
checkbox_cd.getCheckBox().addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent e)
{
JCheckBox source = (JCheckBox) e.getSource();
if (source.isSelected()) {
easySm.updateProject().updateInputCD().validateInputCD();
source.setEnabled(false);
}
}
});
}
{
// State Observers Part
stateObservers_panel = new SOPanel(easySm.updateProject().updateSO());
jTabbedPane_contentPane
.addTab("<html><u>S</u>tate Observers and Invariants</html>",
new ImageIcon(getClass().getClassLoader().getResource("easysm/icons/x22/soAndInv.png")),
stateObservers_panel,
"<html>Edit/Add/Delete state observers and their relative invariants<br/>"
+ "The selected checkbox means the <b>State Observers and Invariants</b> "
+ "Part is <b>Valid</b> and <b>Not Valid</b> otherwise.<br/>"
+ "Check the checkbox to validate the entire <b>State "
+ "Observers and Invariants</b> Part.</html>");
jTabbedPane_contentPane.setMnemonicAt(jTabbedPane_contentPane.getTabCount() - 1, KeyEvent.VK_S);
checkbox_so = new JCheckBoxTabRender(jTabbedPane_contentPane,
jTabbedPane_contentPane.getTabCount() - 1);
/**
* Managing the validation the State Observers Part
*/
checkbox_so.getCheckBox().addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent e)
{
JCheckBox source = (JCheckBox) e.getSource();
if (source.isSelected()) {
easySm.updateProject().updateSO().validateSO();
source.setEnabled(false);
}
}
});
}
{
// Events and Conditions/Reactions Part
events_panel = new E_Panel(easySm.updateProject().updateEvents());
jTabbedPane_contentPane
.addTab("<html>E<u>v</u>ents and Conditions/Reactions</html>",
new ImageIcon(getClass().getClassLoader().getResource("easysm/icons/x22/evtAndCondReact.png")),
events_panel,
"<html>Edit/Add/Delete events and their relative conditions/reactions<br/>"
+ "The selected checkbox means the <b>Events and Conditions/Reactions</b> "
+ "Part is <b>Valid</b> and <b>Not Valid</b> otherwise.<br/>"
+ "Check the checkbox to validate the entire <b>Events and "
+ "Conditions/Reactions</b> Part.</html>");
jTabbedPane_contentPane.setMnemonicAt(jTabbedPane_contentPane.getTabCount() - 1, KeyEvent.VK_V);
checkbox_ev = new JCheckBoxTabRender(jTabbedPane_contentPane,
jTabbedPane_contentPane.getTabCount() - 1);
/**
* Managing the validation the Events and Conditions/Reactions Part
*/
checkbox_ev.getCheckBox().addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent e)
{
JCheckBox source = (JCheckBox) e.getSource();
if (source.isSelected()) {
easySm.updateProject().updateEvents().validateEvents();
source.setEnabled(false);
}
}
});
}
{
// State Table Part
stats_panel = new ST_panel(easySm.updateProject().updateST(), easySm.updateProject().updateSO());
jTabbedPane_contentPane.addTab("<html>S<u>t</u>ate Table", new ImageIcon(getClass()
.getClassLoader().getResource("easysm/icons/x22/stateTable.png")), stats_panel,
"<html>Edit/Define/Delete the states of the State Machine<br/>"
+ "The selected checkbox means the <b>State Table</b> "
+ "Part is <b>Valid</b> and <b>Not Valid</b> otherwise.<br/>"
+ "Check the checkbox to validate the entire <b>State Table</b> Part.</html>");
jTabbedPane_contentPane.setMnemonicAt(jTabbedPane_contentPane.getTabCount() - 1, KeyEvent.VK_T);
checkbox_st = new JCheckBoxTabRender(jTabbedPane_contentPane,
jTabbedPane_contentPane.getTabCount() - 1);
/**
* Managing the validation the State Table Part
*/
checkbox_st.getCheckBox().addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent e)
{
JCheckBox source = (JCheckBox) e.getSource();
if (source.isSelected()) {
easySm.updateProject().updateST().validateST();
source.setEnabled(false);
}
}
});
}
}
{
// Adding the buttons to TOOLBAR
jtoolbar = new JToolBar();
getContentPane().add(jtoolbar, BorderLayout.NORTH);
{
button_new = new JButton();
jtoolbar.add(button_new);
button_new.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x22/document-new.png")));
button_new.setToolTipText("<html>Create a new Project<br/>"
+ "Shortcut: <b>CTRL+N</b></html>");
button_new.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_newActionPerformed(evt);
}
});
}
{
button_open = new JButton();
jtoolbar.add(button_open);
button_open.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x22/document-open.png")));
button_open.setToolTipText("<html>Open an existing Project<br/>"
+ "Shortcut: <b>CTRL+O</b></html>");
button_open.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_openActionPerformed(evt);
}
});
}
{
button_save = new JButton();
jtoolbar.add(button_save);
button_save.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x22/document-save.png")));
button_save.setToolTipText("<html>Save the current Project into<br/>"
+ "the current working directory<br/>"
+ "Shortcut: <b>CTRL+S</b></html>");
button_save.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_saveActionPerformed(evt);
}
});
}
jtoolbar.addSeparator();
{
button_generateStateMachine = new JButton();
jtoolbar.add(button_generateStateMachine);
button_generateStateMachine.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x22/generate-state-machine.png")));
button_generateStateMachine.setToolTipText("<html>Generate the <b>State Machine</b><br/>"
+ "Shortcut: <b>CTRL+G</b></html>");
button_generateStateMachine.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_generateStateMachineActionPerformed(evt);
}
});
}
{
button_showSM = new JButton();
jtoolbar.add(button_showSM);
button_showSM.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x22/view-state-machine.png")));
button_showSM.setToolTipText("<html>Show the current <b>State Machine</b><br/>"
+ "Shortcut: <b>CTRL+SHIFT+M</b></html>");
button_showSM.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_showSMActionPerformed(evt);
}
});
}
{
button_showOutputCD = new JButton();
jtoolbar.add(button_showOutputCD);
button_showOutputCD.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x22/view-output-cd.png")));
button_showOutputCD.setToolTipText("<html>Show the current "
+ "<b>Output Class Diagram</b><br/>"
+ "Shortcut: <b>CTRL+SHIFT+C</b></html>");
button_showOutputCD.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_showOutputCDActionPerformed(evt);
}
});
}
}
{
jMenuBar = new JMenuBar();
setJMenuBar(jMenuBar);
{
jMenu_file = new JMenu();
jMenuBar.add(jMenu_file);
jMenu_file.setText("File");
jMenu_file.setMnemonic(java.awt.event.KeyEvent.VK_F);
{
file_new = new JMenuItem();
jMenu_file.add(file_new);
file_new.setText("New");
file_new.setMnemonic(java.awt.event.KeyEvent.VK_N);
file_new.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
file_new.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/document-new.png")));
file_new.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_newActionPerformed(evt);
}
});
}
{
file_open = new JMenuItem();
jMenu_file.add(file_open);
file_open.setText("Open");
file_open.setMnemonic(java.awt.event.KeyEvent.VK_O);
file_open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
file_open.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/document-open.png")));
file_open.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_openActionPerformed(evt);
}
});
}
{
jSeparator1 = new JSeparator();
jMenu_file.add(jSeparator1);
jSeparator1.setBounds(35, 36, 70, 8);
}
{
file_save = new JMenuItem();
jMenu_file.add(file_save);
file_save.setText("Save");
file_save.setMnemonic(java.awt.event.KeyEvent.VK_S);
file_save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
file_save.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/document-save.png")));
file_save.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_saveActionPerformed(evt);
}
});
}
{
jSeparator2 = new JSeparator();
jMenu_file.add(jSeparator2);
}
{
file_close = new JMenuItem();
jMenu_file.add(file_close);
file_close.setText("Close");
file_close.setMnemonic(java.awt.event.KeyEvent.VK_S);
file_close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
file_close.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/document-close.png")));
file_close.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
file_closeActionPerformed(evt);
}
});
}
{
file_exit = new JMenuItem();
jMenu_file.add(file_exit);
file_exit.setText("Exit");
file_exit.setMnemonic(java.awt.event.KeyEvent.VK_E);
file_exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK));
file_exit.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/application-exit.png")));
file_exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
file_exitActionPerformed(evt);
}
});
}
}
{
jMenu_updateParts = new JMenu();
jMenuBar.add(jMenu_updateParts);
jMenu_updateParts.setText("Update Parts");
jMenu_updateParts.setMnemonic(java.awt.event.KeyEvent.VK_U);
{
updateParts_inputclassDiagram = new JMenuItem();
jMenu_updateParts.add(updateParts_inputclassDiagram);
updateParts_inputclassDiagram.setText("Input Class Diagram");
updateParts_inputclassDiagram.setMnemonic(java.awt.event.KeyEvent.VK_C);
updateParts_inputclassDiagram.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
Event.CTRL_MASK + Event.SHIFT_MASK));
updateParts_inputclassDiagram.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/code-class.png")));
updateParts_inputclassDiagram.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
jTabbedPane_contentPane.setSelectedIndex(0);
}
});
}
{
updateParts_stateObserversAndInv = new JMenuItem();
jMenu_updateParts.add(updateParts_stateObserversAndInv);
updateParts_stateObserversAndInv.setText("State Observers and Invariants");
updateParts_stateObserversAndInv.setMnemonic(java.awt.event.KeyEvent.VK_S);
updateParts_stateObserversAndInv.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Event.CTRL_MASK + Event.SHIFT_MASK));
updateParts_stateObserversAndInv.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/soAndInv.png")));
updateParts_stateObserversAndInv.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
jTabbedPane_contentPane.setSelectedIndex(1);
}
});
}
{
updateParts_eventsAndCondReact = new JMenuItem();
jMenu_updateParts.add(updateParts_eventsAndCondReact);
updateParts_eventsAndCondReact.setText("Events and Conditions/Reactions");
updateParts_eventsAndCondReact.setMnemonic(java.awt.event.KeyEvent.VK_V);
updateParts_eventsAndCondReact.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
Event.CTRL_MASK + Event.SHIFT_MASK));
updateParts_eventsAndCondReact.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/evtAndCondReact.png")));
updateParts_eventsAndCondReact.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
jTabbedPane_contentPane.setSelectedIndex(2);
}
});
}
{
updateParts_stateTable = new JMenuItem();
jMenu_updateParts.add(updateParts_stateTable);
updateParts_stateTable.setText("State Table");
updateParts_stateTable.setMnemonic(java.awt.event.KeyEvent.VK_T);
updateParts_stateTable.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, Event.CTRL_MASK
+ Event.SHIFT_MASK));
updateParts_stateTable.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/stateTable.png")));
updateParts_stateTable.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
jTabbedPane_contentPane.setSelectedIndex(3);
}
});
}
}
{
jMenu_stateMachine = new JMenu();
jMenuBar.add(jMenu_stateMachine);
jMenu_stateMachine.setText("State Machine");
jMenu_stateMachine.setMnemonic(java.awt.event.KeyEvent.VK_M);
{
stateMachine_generate = new JMenuItem();
jMenu_stateMachine.add(stateMachine_generate);
stateMachine_generate.setText("Generate State Machine");
stateMachine_generate.setMnemonic(java.awt.event.KeyEvent.VK_G);
stateMachine_generate.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, Event.CTRL_MASK));
stateMachine_generate.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/generate-state-machine.png")));
stateMachine_generate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_generateStateMachineActionPerformed(evt);
}
});
}
{
jSeparator3 = new JSeparator();
jMenu_stateMachine.add(jSeparator3);
}
{
stateMachine_showSM = new JMenuItem();
jMenu_stateMachine.add(stateMachine_showSM);
stateMachine_showSM.setText("Show the State Machine");
stateMachine_showSM.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/view-state-machine.png")));
stateMachine_showSM.setMnemonic(java.awt.event.KeyEvent.VK_M);
stateMachine_showSM.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK
+ Event.SHIFT_MASK));
stateMachine_showSM.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_showSMActionPerformed(evt);
}
});
}
{
stateMachine_showOutputCD = new JMenuItem();
jMenu_stateMachine.add(stateMachine_showOutputCD);
stateMachine_showOutputCD.setText("Show the Output Class Diagram");
stateMachine_showOutputCD.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/view-output-cd.png")));
stateMachine_showOutputCD.setMnemonic(java.awt.event.KeyEvent.VK_C);
stateMachine_showOutputCD.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK
+ Event.SHIFT_MASK));
stateMachine_showOutputCD.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
button_showOutputCDActionPerformed(evt);
}
});
}
}
{
jMenu_help = new JMenu();
jMenuBar.add(jMenu_help);
jMenu_help.setText("Help");
jMenu_help.setMnemonic(java.awt.event.KeyEvent.VK_H);
{
help_showSplash = new JMenuItem();
jMenu_help.add(help_showSplash);
help_showSplash.setText("Re-show Splash Window");
help_showSplash.setBounds(37, 18, 112, 18);
help_showSplash.setMnemonic(java.awt.event.KeyEvent.VK_W);
help_showSplash.setIcon(new ImageIcon(getClass().getClassLoader()
.getResource("easysm/icons/x16/help-show-splash.png")));
help_showSplash.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
help_showSplashActionPerformed(evt);
}
});
}
{
help_about = new JMenuItem();
jMenu_help.add(help_about);
help_about.setText("About");
help_about.setMnemonic(java.awt.event.KeyEvent.VK_A);
help_about.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
"easysm/icons/x16/help-about.png")));
help_about.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
help_aboutActionPerformed(evt);
}
});
}
}
}
pack();
setSize(980, 500);
setLocationRelativeTo(null);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
file_exitActionPerformed(null);
}
});
} catch (Exception e) {
// add your error handling code here
e.printStackTrace();
}
}
private void updateTitle()
{
String firstPart = "";
if (easySm.updateProject().currentProject() != null) {
String prjName = easySm.updateProject().currentProject().project().name().toString();
String prjAuthor = easySm.updateProject().currentProject().project().authorName();
String prjVersion = easySm.updateProject().currentProject().project().version();
if (prjAuthor.equals("")) {
if (prjVersion.equals(""))
firstPart = prjName + " - ";
else
firstPart = prjName + " (v.:" + prjVersion + ") - ";
} else {
if (prjVersion.equals(""))
firstPart = prjName + " (" + prjAuthor + ") - ";
else
firstPart = prjName + " (" + prjAuthor + ", v.:" + prjVersion + ") - ";
}
}
this.setTitle(firstPart + PROGRAM_NAME);
}
private void disableCheckboxes() {
checkbox_cd.getCheckBox().setEnabled(false);
checkbox_cd.getCheckBox().setSelected(false);
checkbox_ev.getCheckBox().setEnabled(false);
checkbox_ev.getCheckBox().setSelected(false);
checkbox_so.getCheckBox().setEnabled(false);
checkbox_so.getCheckBox().setSelected(false);
checkbox_st.getCheckBox().setEnabled(false);
checkbox_st.getCheckBox().setSelected(false);
}
private void closedStateSetButtons() {
jMenu_updateParts.setEnabled(false);
jMenu_stateMachine.setEnabled(false);
file_close.setEnabled(false);
file_save.setEnabled(false);
file_new.setEnabled(true);
file_open.setEnabled(true);
button_open.setEnabled(true);
button_new.setEnabled(true);
button_save.setEnabled(false);
// button_showOutputCD.setEnabled(false);
// button_showSM.setEnabled(false);
button_generateStateMachine.setEnabled(false);
disableCheckboxes();
jTabbedPane_contentPane.setSelectedComponent(classDiagram_panel);
jTabbedPane_contentPane.setEnabled(false);
classDiagram_panel.setEnabledElements(false);
classDiagram_panel.hideFullViewer();
if (fullViewerSM.isVisible())
fullViewerSM.setVisible(false);
if (fullViewerOutputCD.isVisible())
fullViewerOutputCD.setVisible(false);
enableShowButtons();
updateTitle();
}
private void openStateSetButtons() {
jMenu_updateParts.setEnabled(true);
jMenu_stateMachine.setEnabled(true);
file_close.setEnabled(true);
file_save.setEnabled(true);
file_new.setEnabled(false);
file_open.setEnabled(false);
button_open.setEnabled(false);
button_new.setEnabled(false);
button_save.setEnabled(true);
//vedere se si puo vedere la output e la sm allora abilito i bottoni
// button_showOutputCD.setEnabled(false);
// button_showSM.setEnabled(false);
button_generateStateMachine.setEnabled(true);
jTabbedPane_contentPane.setSelectedComponent(classDiagram_panel);
jTabbedPane_contentPane.setEnabled(true);
classDiagram_panel.setEnabledElements(true);
updateTitle();
}
public boolean getError()
{
boolean tmp = error;
if (error == true)
error = false;
return tmp;
}
/*
* Events Handler
*/
private void button_newActionPerformed(ActionEvent evt)
{
new NewProjectFrame(this).setVisible(true);
requestFocus();
if (easySm.updateProject().currentProject()!=null)
openStateSetButtons();
}
private void button_openActionPerformed(ActionEvent evt)
{
JFileChooser fc = new JFileChooser();
fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]);
fc.addChoosableFileFilter(new EasySMFileFilter());
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
easySm.openProject(file.getAbsolutePath());
easySm.updateProject().openInputCD();
if (!getError())
openStateSetButtons();
} else {
// DO NOTHING
}
}
private void button_saveActionPerformed(ActionEvent evt)
{
easySm.saveProject();
}
private void file_exitActionPerformed(ActionEvent evt)
{
easySm.closeProject();
System.exit(0);
}
private void file_closeActionPerformed(ActionEvent evt)
{
easySm.closeProject();
closedStateSetButtons();
classDiagram_panel.updateTable();
}
private void button_generateStateMachineActionPerformed(ActionEvent evt)
{
easySm.updateProject().generateSM();
}
private void button_showSMActionPerformed(ActionEvent evt)
{
fullViewerSM.setText(easySm.updateProject().currentSM().toString(),
easySm.updateProject().currentSM().isInvalid());
fullViewerSM.setVisible(true);
}
private void button_showOutputCDActionPerformed(ActionEvent evt)
{
fullViewerOutputCD.setText(easySm.updateProject().currentOutputCD().toString(),
easySm.updateProject().currentOutputCD().isInvalid());
fullViewerOutputCD.setVisible(true);
}
private void help_aboutActionPerformed(ActionEvent evt)
{
new AboutDialog(this).setVisible(true);
}
private void help_showSplashActionPerformed(ActionEvent evt) {
splashReshow.setVisible(true);
}
/*
* public methods
*/
public void setError()
{
if (error == false)
error = true;
}
/**
* Enabling/disabling show output CD and SM buttons
*/
public void enableShowButtons() {
if (easySm.updateProject().currentSM()==null) {
if (button_showSM.isEnabled()) {
button_showSM.setEnabled(false);
stateMachine_showSM.setEnabled(false);
}
} else {
if (!button_showSM.isEnabled()) {
button_showSM.setEnabled(true);
stateMachine_showSM.setEnabled(true);
}
}
if (easySm.updateProject().currentOutputCD()==null){
if (button_showOutputCD.isEnabled()) {
button_showOutputCD.setEnabled(false);
stateMachine_showOutputCD.setEnabled(false);
}
} else
if (!button_showOutputCD.isEnabled()){
button_showOutputCD.setEnabled(true);
stateMachine_showOutputCD.setEnabled(true);
}
}
/**
* Updating checkboxes whenever a part is valid or not
*/
public void updateCheckboxTabsIfValid() {
if (easySm.updateProject().updateInputCD().currentInputCD().classDiagram().isInvalid()) {
checkbox_cd.getCheckBox().setEnabled(true);
checkbox_cd.getCheckBox().setSelected(false);
} else {
checkbox_cd.getCheckBox().setEnabled(false);
checkbox_cd.getCheckBox().setSelected(true);
}
if (easySm.updateProject().updateSO().currentSO().isInvalid()) {
checkbox_so.getCheckBox().setEnabled(true);
checkbox_so.getCheckBox().setSelected(false);
} else {
checkbox_so.getCheckBox().setEnabled(false);
checkbox_so.getCheckBox().setSelected(true);
}
if (easySm.updateProject().updateEvents().currentEvents().events().isInvalid()) {
checkbox_ev.getCheckBox().setEnabled(true);
checkbox_ev.getCheckBox().setSelected(false);
} else {
checkbox_ev.getCheckBox().setEnabled(false);
checkbox_ev.getCheckBox().setSelected(true);
}
if (easySm.updateProject().updateST().currentST().stateTable().isInvalid()) {
checkbox_st.getCheckBox().setEnabled(true);
checkbox_st.getCheckBox().setSelected(false);
} else {
checkbox_st.getCheckBox().setEnabled(false);
checkbox_st.getCheckBox().setSelected(true);
}
}
public void createNewProject(Name name,
String author,
String version)
{
easySm.newProject(name, author, version);
}
public SOPanel getStateObserversPanel()
{
return stateObservers_panel;
}
public CD_Panel getInputClassDiagramPanel()
{
return classDiagram_panel;
}
public E_Panel getEventsPanel()
{
return events_panel;
}
public ST_panel getStateTablePanel()
{
return stats_panel;
}
}