package easysm.boundaries.components.statetable;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.Vector;
import javax.swing.*;
import easysm.boundaries.UpdateStateObservers;
import easysm.boundaries.UpdateStateTable;
import easysm.boundaries.components.FullViewer;
import easysm.datatypes.information.SplitInfo;
import easysm.factories.ListFactory;
import easysm.stores.CondReact;
import easysm.stores.Event;
/**
* @author Artur Tolstenco
*/
public class SplitCondReact extends javax.swing.JDialog
{
private static final long serialVersionUID = 1L;
private JPanel jpanel_buttons;
private JButton jbutton_ok;
private JScrollPane jScrollPane1;
private JButton jbutton_showSO;
private JPanel jPanel4;
private JPanel jPanel3;
private JPanel jPanel2;
private JPanel jpanel_content;
private JPanel jPanel1;
private JButton jbutton_cancel;
private UpdateStateTable updateStateTable;
private Vector<CondReact_row> rows;
private FullViewer fullViewer;
public SplitCondReact(UpdateStateTable updateStateTable,
UpdateStateObservers updateStateObservers)
{
super();
setModal(true);
this.updateStateTable = updateStateTable;
initGUI();
fullViewer = new FullViewer("State Observers", this);
fullViewer.setText(updateStateTable.allSOToString(),
updateStateObservers.currentSO().isInvalid());
rows = new Vector<CondReact_row>();
for (Event event : updateStateTable.currentEvents().events().eventList()) {
for (CondReact cr : event.condsReacts()) {
CondReact_row tmp = new CondReact_row(cr);
rows.add(tmp);
jpanel_content.add(tmp);
if (event.equals(Event.CREATED))
tmp.disableConditionFields();
}
}
pack();
setSize(getWidth()+10, 400);
setLocationRelativeTo(null);
}
private void initGUI()
{
try {
setTitle("Split Conditions/Reactions");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jpanel_buttons = new JPanel();
BorderLayout jpanel_buttonsLayout = new BorderLayout();
jpanel_buttons.setLayout(jpanel_buttonsLayout);
getContentPane().add(jpanel_buttons, BorderLayout.SOUTH);
{
jPanel2 = new JPanel();
FlowLayout jPanel2Layout1 = new FlowLayout();
jPanel2.setLayout(jPanel2Layout1);
jpanel_buttons.add(jPanel2, BorderLayout.CENTER);
{
jbutton_ok = new JButton();
jPanel2.add(jbutton_ok);
jbutton_ok.setText("Ok");
jbutton_ok.setPreferredSize(new java.awt.Dimension(101, 25));
jbutton_ok.setMnemonic(KeyEvent.VK_O);
jbutton_ok.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
"easysm/icons/x16/dialog-ok-apply.png")));
jbutton_ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton_okActionPerformed(evt);
}
});
}
{
jbutton_cancel = new JButton();
jPanel2.add(jbutton_cancel);
jbutton_cancel.setPreferredSize(new java.awt.Dimension(101, 25));
jbutton_cancel.setMnemonic(java.awt.event.KeyEvent.VK_C);
jbutton_cancel.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
"easysm/icons/x16/edit-delete.png")));
jbutton_cancel.setText("Cancel");
jbutton_cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton_cancelActionPerformed(evt);
}
});
}
}
{
jPanel3 = new JPanel();
BorderLayout jPanel3Layout = new BorderLayout();
jPanel3.setLayout(jPanel3Layout);
jpanel_buttons.add(jPanel3, BorderLayout.WEST);
{
jPanel4 = new JPanel();
jPanel3.add(jPanel4, BorderLayout.CENTER);
{
jbutton_showSO = new JButton();
jPanel4.add(jbutton_showSO);
jbutton_showSO.setText("Show State Observers");
jbutton_showSO.setIcon(new ImageIcon(getClass().getClassLoader().getResource(
"easysm/icons/x16/soAndInv.png")));
jbutton_showSO.setMnemonic(java.awt.event.KeyEvent.VK_H);
jbutton_showSO.setToolTipText("<html>Show the current State Observers<br/>"
+ "Mnemonic <b>ALT+H</b></html>");
jbutton_showSO.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jbutton_showSOActionPerformed(evt);
}
});
}
}
}
}
{
jScrollPane1 = new JScrollPane();
getContentPane().add(jScrollPane1, BorderLayout.CENTER);
{
jPanel1 = new JPanel();
BorderLayout jPanel1Layout = new BorderLayout();
jScrollPane1.setViewportView(jPanel1);
jPanel1.setLayout(jPanel1Layout);
{
jpanel_content = new JPanel();
BoxLayout jPanel2Layout = new BoxLayout(jpanel_content, javax.swing.BoxLayout.Y_AXIS);
jPanel1.add(jpanel_content, BorderLayout.NORTH);
jpanel_content.setLayout(jPanel2Layout);
}
}
}
getRootPane().setDefaultButton(jbutton_ok);
} catch (Exception e) {
e.printStackTrace();
}
}
/*
* Events Handler
*/
private void jbutton_okActionPerformed(ActionEvent evt) {
List<SplitInfo> toReturn = ListFactory.createList(SplitInfo.class);
for (CondReact_row row : rows) {
toReturn.add(row.getSplitInfo());
}
updateStateTable.splitCR(toReturn);
fullViewer.dispose();
dispose();
}
private void jbutton_cancelActionPerformed(ActionEvent evt) {
fullViewer.dispose();
dispose();
}
private void jbutton_showSOActionPerformed(ActionEvent evt) {
fullViewer.setVisible(true);
fullViewer.toFront();
fullViewer.requestFocus();
}
}