Package it.unina.seclab.jafimon

Source Code of it.unina.seclab.jafimon.UserInterface

package it.unina.seclab.jafimon;

import it.unina.seclab.jafimon.exceptions.CannotIstantiatePhysicalActivatorException;
import it.unina.seclab.jafimon.interfaces.IUserInterface;
import it.unina.seclab.jafimon.ui.CfgEditor;
import it.unina.seclab.jafimon.ui.ShowResultsDialog;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.KeyStroke;

import org.apache.log4j.Logger;

/**
* Questo componente � il punto di ingresso per l'utente verso il tool di iniezione
* guasti e monitoraggio JaFiMon. L'interfaccia grafica � costituita da una finestra
* principale sulla quale sono situati i pulsanti che avviano le principali operazioni
* disponibili.<br>
*
<ul>
<li>I due pulsanti "Monitor Black-Box" e "Monitor White-Box" danno il via ad
*  altrettante procedure guidate che assistono l'utente rispettivamente durante
*  la selezione di una configurazione predefinita gi� esistente seguita dall'avvio
*  del sistema target, oppure attraverso l'interfaccia di definizione di una propria
*  configurazione custom seguita dall'avvio del sistema target con la configurazione
*  appena definita.
<li>Queste stesse operazioni altres� disponibili singolarmente e raggiungibili
*  attraverso i pulsanti di comando "Select predefined configuration" e "Define
*  Custom Configuration".
<li>Sul sistema target sono naturalmente disponibili le operazioni di avvio test
*  e di arresto.
<li>Infine � possibile effettuare la lettura dei dati rilevati durante la fase
*  di test del sistema target.
</ul>
*
*  Essendo questo componente puramente grafico non � ulteriormente documentato.
* @author   Mauro Iorio
* @see Monitor
* @see CfgEditor
*
*/
public class UserInterface extends JFrame implements IUserInterface {

  private static final long serialVersionUID = 1L;

  private static final String SELCFGPANEL = "selectConfig";

  private static final String SELCOLLPANEL = "selectCollections";

  private static final String WELCOMEPANEL = "welcome";

  private static Logger logger = Logger.getRootLogger()//  @jve:decl-index=0:

  private Coordinator theCoordinator;
 
  private static final int INITIAL_STATUS   = 0;
 
  private static final int CFG_SELECTED_STATUS= 1;
 
  private static final int CFG_DEFINED_STATUS = 2;
 
  private static final int SUT_STARTED_STATUS = 3;
 
  private int currentStatus = INITIAL_STATUS;
 
  private boolean wizardMode = false;
 
  // BEGIN - Swing Components
  // BEGIN - Swing Components
  // BEGIN - Swing Components

  private CancelAction cancelAction;  //  @jve:decl-index=0:

  private ExitAction exitAction;  //  @jve:decl-index=0:

  private SelectCfgAction selectCfgAction;  //  @jve:decl-index=0:
 
  private SelectCollectionAction selectCollectionAction;  //  @jve:decl-index=0:
 
  private JButton jButtonCancel = null;

  private JButton jButtonDefineCustomCfg = null;

  private JButton jButtonMonitorBB = null;

  private JButton jButtonMonitorWB = null;

  private JButton jButtonOk = null;

  private JButton jButtonReadResults = null;

  private JButton jButtonSelectPredefinedCfg = null;

  private JButton jButtonStartSUT = null;

  private JButton jButtonStopSUT = null;

  private JPanel jContentPane = null;

  private JLabel jLabelWelcome = null;

  private JLabel jLabelSelectConfig = null;

  private JMenuBar jJMenuBar = null;

  private JMenu jMenuFile = null;

  private JMenuItem jMenuItemEsci = null;

  private JPanel jPanelCoicheButton = null;

  private JPanel jPanelSelectConfig = null//  @jve:decl-index=0:visual-constraint="225,650"

  private JPanel jPanelSelectionButtons = null;

  private JPanel jPanelWelcome = null//  @jve:decl-index=0:visual-constraint="104,647"

  private JPanel jPanelWorking = null;

  private JPanel jPanelWorkingContainer = null;

  private JPanel jPanelSelectCollections = null;

  private JLabel jLabelSelectConfig1 = null;

  // END - Swing Components
  // END - Swing Components
  // END - Swing Components

  // BEGIN - IUserInterface methods
  // BEGIN - IUserInterface methods
  // BEGIN - IUserInterface methods

  public void defineConfig() {
    CfgEditor ed = new CfgEditor(this);
    ed.setModal(true);
    ed.show();
    logger.trace("La CfgEditor.show() � ritornata");
    if (ed.hasUserConfirmed()) {
      logger.trace(ed.getXmlConfiguration());
     
      // Chiedo il nome all'utente
      String s;
      do {
      s = (String)JOptionPane.showInputDialog(
                          this,
                          "Inserire un nome per questa configurazione\n" +
                          "NOTA: Il nome della configrazione DEVE coincidere\n" +
                          "con il nome del sistema (ad. es.: \"Tomcat5\")",
                          "Nome configurazione",
                          JOptionPane.QUESTION_MESSAGE);

      //If a string was returned, say so.
      } while ((s == null) || (s.length() <= 0));
     
      try {
        String fullName = "custom" + File.separator + s + File.separator + s + ".xml";
        String cfgBody = ed.getXmlConfiguration();
       
        // Prima di istanziare la cfg devo aggiungere i tag:
        // <name>, <type>, <filename>
        cfgBody = aggiungiTag(cfgBody, s, fullName);
       
        Configuration cfg = Configuration.configurationFromString(cfgBody,fullName);
        theCoordinator.newConfig(cfg);
        theCoordinator.selectConfig(fullName);
        currentStatus = CFG_DEFINED_STATUS;
      } catch (Exception e) {
        logger.debug("UI ha rilevato una eccezione in defineConfig");
        JOptionPane.showMessageDialog(this, "Impossibile creare la configurazione. Il messaggio di errore e':\n\"" + e.getLocalizedMessage() + "\"","Eccezione", JOptionPane.ERROR_MESSAGE);
        ed.dispose();
        return;
      }
      ed.dispose();
     
      if (wizardMode) {
        startMonitor();
      }
     
    } else {
      logger.trace("L'utente ha cancellato l'operazione");
      ed.dispose();
    }
  }

  private String aggiungiTag(String cfgBody, String name, String fullName) {
    StringBuffer sb = new StringBuffer();
    int inizio = cfgBody.indexOf("author=");
    inizio = cfgBody.indexOf(">\n", inizio);
   
    sb.append(cfgBody.substring(0, inizio + ">\n".length()));
    sb.append("<name>" + name + "</name>\n");
    sb.append("<type>custom</type>\n");
    sb.append("<filename>"+ fullName + "</filename>\n");
    sb.append(cfgBody.substring(inizio + ">\n".length(), cfgBody.length()));
   
    return sb.toString();
  }

  public void readData() {
    logger.debug("readData()");
    String[] cfgs = theCoordinator.getDataCollectionList();
    logger.debug("Got " + cfgs.length + " collections");

    /**
     * Preparo la composizione del pannello di lavoro
     */
    JPanel working = flushPanel(getJPanelSelectCollections());
    working.add(new JLabel("Selezionare una delle seguenti e premere \"Seleziona:\""));
    working.add(Box.createRigidArea(new Dimension(0,10)));
   
    /**
     * In questo caso mi serve un radiobutton per ogni configuration
     * trovata
     */
    JRadioButton cb[] = new JRadioButton[cfgs.length];
    ButtonGroup bg = new ButtonGroup();
    for (int i = 0; i < cfgs.length; i++) {
      cb[i] = new JRadioButton(cfgs[i]);
      cb[i].setName("jrb" + cfgs[i]);
      bg.add(cb[i]);
      working.add(cb[i]);
    }
   
    /**
     * Imposto l'action per i bottoni ok e cancel
     */
    getJButtonOk().setAction(getSelectCollectionAction());
    getJButtonCancel().setAction(getCancelAction());

        CardLayout cl = (CardLayout)(getJPanelWorking().getLayout());
        cl.show(getJPanelWorking(), SELCOLLPANEL);

    logger.debug("Finito");
  }

  public void selectConfig() {
    logger.debug("selectConfig()");
    String[] cfgs = theCoordinator.listConfigs();
    logger.debug("Got " + cfgs.length + " configurations");
   
    /**
     * Preparo la composizione del pannello di lavoro
     */
    JPanel working = flushPanel(getJPanelSelectConfig());
    working.add(new JLabel("Selezionare una delle seguenti e premere \"Seleziona:\""));
    working.add(Box.createRigidArea(new Dimension(0,10)));
   
    /**
     * In questo caso mi serve un radiobutton per ogni configuration
     * trovata
     */
    JRadioButton cb[] = new JRadioButton[cfgs.length];
    ButtonGroup bg = new ButtonGroup();
    for (int i = 0; i < cfgs.length; i++) {
      cb[i] = new JRadioButton(cfgs[i]);
      cb[i].setName("jrb" + cfgs[i]);
      bg.add(cb[i]);
      working.add(cb[i]);
    }
   
    /**
     * Imposto l'action per i bottoni ok e cancel
     */
    getJButtonOk().setAction(getSelectCfgAction());
    getJButtonCancel().setAction(getCancelAction());

        CardLayout cl = (CardLayout)(getJPanelWorking().getLayout());
        cl.show(getJPanelWorking(), SELCFGPANEL);

    logger.debug("Finito");
  }

  public void startMonitor() {
    if (currentStatus < CFG_SELECTED_STATUS) {
      JOptionPane.showMessageDialog(this, "Nessun configurazione selezionata","Errore", JOptionPane.ERROR_MESSAGE);
      return;
    }
    try {
      theCoordinator.startSystem();
      currentStatus = SUT_STARTED_STATUS;
    } catch (CannotIstantiatePhysicalActivatorException e) {
      logger.debug("UI ha rilevato una eccezione in startSystem");
      JOptionPane.showMessageDialog(this, "Impossibile avviare il Sistema. Il messaggio di errore e':\n\"" + e.getLocalizedMessage() + "\"","Eccezione", JOptionPane.ERROR_MESSAGE);
    }
    wizardMode = false;
  }

  public void stopMonitor() {
    if (currentStatus < SUT_STARTED_STATUS) {
      JOptionPane.showMessageDialog(this, "Nessun sistema in esecuzione","Errore", JOptionPane.ERROR_MESSAGE);
      return;
    }
    theCoordinator.stopSystem();
    currentStatus = INITIAL_STATUS;
  }

  // END - IUserInterface methods
  // END - IUserInterface methods
  // END - IUserInterface methods

  public void wizardBB() {
    wizardMode = true;
    selectConfig();
  }
 
  public void wizardWB() {
    wizardMode = true;
    defineConfig();
  }
 
  /**
   * This is the default constructor
   */
  public UserInterface(Coordinator coord) {
    super();
    theCoordinator = coord;
    initialize();
  }

  private JPanel flushPanel(JPanel p) {
    p.removeAll();
    return p;
  }
 
  /**
   * This method initializes this
   *
   * @return void
   */
  private void initialize() {
    this.setSize(600, 600);
    this.setContentPane(getJContentPane());
    this.setJMenuBar(getJJMenuBar());
    this.setLocation(200, 100);
    this.setTitle("JaFiMon");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  private Action getCancelAction() {
    if (cancelAction == null) {
      cancelAction = new CancelAction("Annulla", "",
                    KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_F24, ActionEvent.ALT_MASK),
                    "cmdCancel");
    }
    return cancelAction;
  }

  private Action getExitAction() {
    if (exitAction == null) {
      exitAction = new ExitAction("Chiudi JaFiMon", "Esce dal programma",
                    KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK),
                    "cmdExit");
    }
    return exitAction;
  }

  private Action getSelectCfgAction() {
    if (selectCfgAction == null) {
      selectCfgAction = new SelectCfgAction("Seleziona", "",
                    KeyEvent.VK_S, KeyStroke.getKeyStroke(KeyEvent.VK_F24, ActionEvent.ALT_MASK),
                    "cmdSelectCfg");
    }
    return selectCfgAction;
  }

  private Action getSelectCollectionAction() {
    if (selectCollectionAction == null) {
      selectCollectionAction = new SelectCollectionAction("Seleziona", "",
                    KeyEvent.VK_S, KeyStroke.getKeyStroke(KeyEvent.VK_F24, ActionEvent.ALT_MASK),
                    "cmdSelectColl");
    }
    return selectCollectionAction;
  }

  private void setDefaultOkAction() {
    JButton b = getJButtonOk();
    b.setAction(null);
    b.setText("OK");
    b.setMnemonic(KeyEvent.VK_O);
  }
  /**
   * This method initializes jButtonCancel 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonCancel() {
    if (jButtonCancel == null) {
      jButtonCancel = new JButton();
      jButtonCancel.setText("Annulla");
      jButtonCancel.setMnemonic(KeyEvent.VK_A);
    }
    return jButtonCancel;
  }

  /**
   * This method initializes jButtonDefineCustomCfg 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonDefineCustomCfg() {
    if (jButtonDefineCustomCfg == null) {
      jButtonDefineCustomCfg = new JButton();
      jButtonDefineCustomCfg.setText("Define Custom Configuration");
      jButtonDefineCustomCfg.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          defineConfig();
        }
      });
    }
    return jButtonDefineCustomCfg;
  }

  /**
   * This method initializes jButtonMonitorBB 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonMonitorBB() {
    if (jButtonMonitorBB == null) {
      jButtonMonitorBB = new JButton();
      jButtonMonitorBB.setText("Monitor Black-Box System");
      jButtonMonitorBB.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          wizardBB();
        }
      });
    }
    return jButtonMonitorBB;
  }

  /**
   * This method initializes jButtonMonitorWB 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonMonitorWB() {
    if (jButtonMonitorWB == null) {
      jButtonMonitorWB = new JButton();
      jButtonMonitorWB.setText("Monitor White-Box System");
      jButtonMonitorWB.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          wizardWB();
        }
      });
    }
    return jButtonMonitorWB;
  }

  /**
   * This method initializes jButtonOk 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonOk() {
    if (jButtonOk == null) {
      jButtonOk = new JButton();
      jButtonOk.setText("OK");
      jButtonOk.setMnemonic(KeyEvent.VK_O);
    }
    return jButtonOk;
  }

  /**
   * This method initializes jButtonReadResults 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonReadResults() {
    if (jButtonReadResults == null) {
      jButtonReadResults = new JButton();
      jButtonReadResults.setText("Read Results");
      jButtonReadResults.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          readData();
        }
      });
    }
    return jButtonReadResults;
  }

  /**
   * This method initializes jButtonSelectPredefinedCfg 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonSelectPredefinedCfg() {
    if (jButtonSelectPredefinedCfg == null) {
      jButtonSelectPredefinedCfg = new JButton();
      jButtonSelectPredefinedCfg.setText("Select Predefined Configuration");
      jButtonSelectPredefinedCfg.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          selectConfig();
        }
      });
    }
    return jButtonSelectPredefinedCfg;
  }

  /**
   * This method initializes jButtonStartSUT 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonStartSUT() {
    if (jButtonStartSUT == null) {
      jButtonStartSUT = new JButton();
      jButtonStartSUT.setText("Start \"System Under Test\"");
      jButtonStartSUT.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          startMonitor();
        }
      });
    }
    return jButtonStartSUT;
  }

  /**
   * This method initializes jButtonStopSUT 
   *  
   * @return javax.swing.JButton 
   */
  private JButton getJButtonStopSUT() {
    if (jButtonStopSUT == null) {
      jButtonStopSUT = new JButton();
      jButtonStopSUT.setText("Stop \"System Under Test\"");
      jButtonStopSUT.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
          stopMonitor();
        }
      });
    }
    return jButtonStopSUT;
  }

  /**
   * This method initializes jContentPane 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJContentPane() {
    if (jContentPane == null) {
      jContentPane = new JPanel();
      jContentPane.setLayout(new BorderLayout());
      jContentPane.add(getJPanelSelectionButtons(), BorderLayout.WEST);
      jContentPane.add(getJPanelWorkingContainer(), BorderLayout.CENTER);
    }
    return jContentPane;
  }

  /**
   * This method initializes jJMenuBar 
   *  
   * @return javax.swing.JMenuBar 
   */
  private JMenuBar getJJMenuBar() {
    if (jJMenuBar == null) {
      jJMenuBar = new JMenuBar();
      jJMenuBar.add(getJMenuFile());
    }
    return jJMenuBar;
  }

  /**
   * This method initializes jMenuFile 
   *  
   * @return javax.swing.JMenu 
   */
  private JMenu getJMenuFile() {
    if (jMenuFile == null) {
      jMenuFile = new JMenu();
      jMenuFile.setText("File");
      jMenuFile.setMnemonic(KeyEvent.VK_F);
      jMenuFile.add(getJMenuItemEsci());
    }
    return jMenuFile;
  }

  /**
   * This method initializes jMenuItemEsci 
   *  
   * @return javax.swing.JMenuItem 
   */
  private JMenuItem getJMenuItemEsci() {
    if (jMenuItemEsci == null) {
      jMenuItemEsci = new JMenuItem(getExitAction());
    }
    return jMenuItemEsci;
  }
 
  /**
   * This method initializes jPanelCoicheButton 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelCoicheButton() {
    if (jPanelCoicheButton == null) {
      jPanelCoicheButton = new JPanel();
      jPanelCoicheButton.setLayout(new FlowLayout(FlowLayout.CENTER,100,10));
      jPanelCoicheButton.add(getJButtonOk(), null);
      jPanelCoicheButton.add(getJButtonCancel(), null);
    }
    return jPanelCoicheButton;
  }

  /**
   * This method initializes jPanelSelectConfig 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelSelectConfig() {
    if (jPanelSelectConfig == null) {
      jLabelSelectConfig = new JLabel();
      jLabelSelectConfig.setText("SelectConfig Panel");
      jPanelSelectConfig = new JPanel();
      jPanelSelectConfig.setLayout(new BoxLayout(jPanelSelectConfig,BoxLayout.Y_AXIS));
      jPanelSelectConfig.add(jLabelSelectConfig);
    }
    return jPanelSelectConfig;
  }

  /**
   * This method initializes jPanelSelectionButtons 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelSelectionButtons() {
    if (jPanelSelectionButtons == null) {
      GridLayout gridLayout = new GridLayout();
      gridLayout.setRows(7);
      gridLayout.setVgap(30);
      gridLayout.setHgap(0);
      gridLayout.setColumns(1);
      jPanelSelectionButtons = new JPanel();
      jPanelSelectionButtons.setLayout(gridLayout);
      jPanelSelectionButtons.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
      jPanelSelectionButtons.add(getJButtonMonitorBB(), null);
      jPanelSelectionButtons.add(getJButtonSelectPredefinedCfg(), null);
      jPanelSelectionButtons.add(getJButtonMonitorWB(), null);
      jPanelSelectionButtons.add(getJButtonDefineCustomCfg(), null);
      jPanelSelectionButtons.add(getJButtonStartSUT(), null);
      jPanelSelectionButtons.add(getJButtonStopSUT(), null);
      jPanelSelectionButtons.add(getJButtonReadResults(), null);
    }
    return jPanelSelectionButtons;
  }

  /**
   * This method initializes jPanelWelcome 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelWelcome() {
    if (jPanelWelcome == null) {
      //java.net.URL imgUrl = UserInterface.class.getResource("images/lente.jpg");
      //ImageIcon img = new ImageIcon(imgUrl);
      jLabelWelcome = new JLabel();
      jLabelWelcome.setText("Welcome Panel");
      //jLabelWelcome.setIcon(img);
      jLabelWelcome.hide();
      jPanelWelcome = new JPanel();
      jPanelWelcome.setLayout(new BorderLayout());
      jPanelWelcome.setBackground(new Color(100,150,255));
      jPanelWelcome.add(jLabelWelcome, BorderLayout.CENTER);
    }
    return jPanelWelcome;
  }

  /**
   * This method initializes jPanelWorking 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelWorking() {
    if (jPanelWorking == null) {
      jPanelWorking = new JPanel();
      jPanelWorking.setLayout(new CardLayout());
     
      /**
       * Aggiungo il pannello vuoto di benvenuto
       */
      jPanelWorking.add(getJPanelWelcome(), WELCOMEPANEL);
     
      /**
       * Aggiungo il primo pannello:
       * Le CheckBox per la selectConfig() sono costruite a
       * runtime
       */
      jPanelWorking.add(getJPanelSelectConfig(), SELCFGPANEL);

     
      /**
       * Aggiungo il secondo pannello:
       * Le CheckBox per la readData() sono costruite a
       * runtime
       */
      jPanelWorking.add(getJPanelSelectCollections(), SELCOLLPANEL);   
    }
    return jPanelWorking;
  }

  /**
   * This method initializes jPanelWorkingContainer 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelWorkingContainer() {
    if (jPanelWorkingContainer == null) {
      jPanelWorkingContainer = new JPanel();
      jPanelWorkingContainer.setLayout(new BorderLayout());
      jPanelWorkingContainer.add(getJPanelCoicheButton(), BorderLayout.SOUTH);
      jPanelWorkingContainer.add(getJPanelWorking(), BorderLayout.NORTH);
    }
    return jPanelWorkingContainer;
  }

  private class CancelAction extends AbstractAction {
 
    private static final long serialVersionUID = -8818405018420624194L;

    public CancelAction(String text, String desc, int mnemonic, KeyStroke accelerator, String actionCmd) {
      super(text);
      putValue(SHORT_DESCRIPTION, desc);
          putValue(MNEMONIC_KEY, new Integer(mnemonic));
          putValue(ACCELERATOR_KEY, accelerator);
          putValue(ACTION_COMMAND_KEY, actionCmd);
    }

    public void actionPerformed(ActionEvent e) {
      logger.debug("L'utente ha cliccato Cancel");

      currentStatus = INITIAL_STATUS ;
     
      /**
       * Imposto l'action per i bottoni ok e cancel
       */
      setDefaultOkAction();

          CardLayout cl = (CardLayout)(getJPanelWorking().getLayout());
          cl.show(getJPanelWorking(), WELCOMEPANEL);
         
          wizardMode = false;
    }
  }
 
  /**
   * ExitAction per jMenuItemEsci
   *
   */
  private class ExitAction extends AbstractAction {

    private static final long serialVersionUID = -8497688739126346574L;

    public ExitAction(String text, String desc, int mnemonic, KeyStroke accelerator, String actionCmd) {
      super(text);
      putValue(SHORT_DESCRIPTION, desc);
          putValue(MNEMONIC_KEY, new Integer(mnemonic));
          putValue(ACCELERATOR_KEY, accelerator);
          putValue(ACTION_COMMAND_KEY, actionCmd);
    }
   
    public void actionPerformed(ActionEvent e) {
      logger.info("ExitAction was called. Exiting JaFiMon...");
      logger.info("JaFiMon exited");
      System.exit(0);
    }
   
  }

  private class SelectCfgAction extends AbstractAction {

    private static final long serialVersionUID = 3584348963742735075L;

    public SelectCfgAction(String text, String desc, int mnemonic, KeyStroke accelerator, String actionCmd) {
      super(text);
      putValue(SHORT_DESCRIPTION, desc);
          putValue(MNEMONIC_KEY, new Integer(mnemonic));
          putValue(ACCELERATOR_KEY, accelerator);
          putValue(ACTION_COMMAND_KEY, actionCmd);
    }
   
    public void actionPerformed(ActionEvent e) {
      logger.debug("L'utente ha cliccato Seleziona");
      JPanel p = getJPanelSelectConfig();
      int i = 0;
      boolean found = false;
      JRadioButton rb = null;
      do {
        Component c = p.getComponent(i);
        if (c.getName() != null)
          if (c.getName().startsWith("jrb")) {
            rb = (JRadioButton)c;
            if (rb.isSelected())
            {
              found = true;
              break;
            }
          }
        i++;
      } while (i < p.getComponentCount() && !found);
     
      if (found) {
        logger.debug("Trovato rb selezionato: " + rb.getText());
        theCoordinator.selectConfig(rb.getText());
        JOptionPane.showMessageDialog(UserInterface.this, "Configurazione attiva:\n" + rb.getText(),"Configurazione attiva", JOptionPane.INFORMATION_MESSAGE);
        currentStatus = CFG_SELECTED_STATUS;
        setDefaultOkAction();
            ((CardLayout)(getJPanelWorking().getLayout())).show(getJPanelWorking(), WELCOMEPANEL);
            if (wizardMode)
              startMonitor();
      } else {
        logger.debug("Nessun rb selezionato");
        JOptionPane.showMessageDialog(getJContentPane().getParent(), "Selezionare una configurazione oppure premere Annulla","Errore", JOptionPane.ERROR_MESSAGE);
      }
    }
   
  }

  private class SelectCollectionAction extends AbstractAction {

    private static final long serialVersionUID = -7763741926068310791L;

    public SelectCollectionAction(String text, String desc, int mnemonic, KeyStroke accelerator, String actionCmd) {
      super(text);
      putValue(SHORT_DESCRIPTION, desc);
          putValue(MNEMONIC_KEY, new Integer(mnemonic));
          putValue(ACCELERATOR_KEY, accelerator);
          putValue(ACTION_COMMAND_KEY, actionCmd);
    }
   
    public void actionPerformed(ActionEvent e) {
      logger.debug("L'utente ha cliccato Seleziona Cfg");
      JPanel p = getJPanelSelectCollections();
      int i = 0;
      boolean found = false;
      JRadioButton rb = null;
      do {
        Component c = p.getComponent(i);
        if (c.getName() != null)
          if (c.getName().startsWith("jrb")) {
            rb = (JRadioButton)c;
            if (rb.isSelected())
            {
              found = true;
              break;
            }
          }
        i++;
      } while (i < p.getComponentCount() && !found);
     
      if (found) {
        logger.debug("Trovato rb selezionato: " + rb.getText());
        new ShowResultsDialog(UserInterface.this, theCoordinator.getDataCollection(rb.getText())).show();
        currentStatus = INITIAL_STATUS;
        setDefaultOkAction();
            ((CardLayout)(getJPanelWorking().getLayout())).show(getJPanelWorking(), WELCOMEPANEL);
      } else {
        logger.debug("Nessun rb selezionato");
        JOptionPane.showMessageDialog(getJContentPane().getParent(), "Selezionare una collezione oppure premere Annulla","Errore", JOptionPane.ERROR_MESSAGE);
      }
    }
   
  }

  /**
   * This method initializes jPanelSelectCollections 
   *  
   * @return javax.swing.JPanel 
   */
  private JPanel getJPanelSelectCollections() {
    if (jPanelSelectCollections == null) {
      jLabelSelectConfig1 = new JLabel();
      jLabelSelectConfig1.setText("SelectCollections Panel");
      jPanelSelectCollections = new JPanel();
      jPanelSelectCollections.setLayout(new BoxLayout(getJPanelSelectCollections(), BoxLayout.Y_AXIS));
      jPanelSelectCollections.setName("jPanelSelectCollections");
      jPanelSelectCollections.add(jLabelSelectConfig1, jLabelSelectConfig1.getName());
    }
    return jPanelSelectCollections;
  }

}
TOP

Related Classes of it.unina.seclab.jafimon.UserInterface

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.