Package periman

Source Code of periman.ScreenerConfigurationDialog

package periman;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;

@SuppressWarnings("serial")
public class ScreenerConfigurationDialog extends JDialog implements ActionListener{
 
  private ScreenerConf conf;
 
  private SpinnerNumberModel timeLimitSpinnerModel;
 
  private JTextField timeoutMsgField;
 
  private SpinnerNumberModel threatImagesSpinnerModel;
 
  private SpinnerNumberModel threatAlertSpinnerModel;
 
  private SpinnerNumberModel noThreatImagesSpinnerModel;
 
  private SpinnerNumberModel noThreatAlertSpinnerModel;
 
  private JCheckBox acknowledgeResultCBox;
 
  private JTextField passCaptionTField;
  private JTextField failCaptionTField;
 
  private SpinnerNumberModel confidenceLevelModel;
 
  private JTextField confiCaptionField;
  private JTextField confiLeftCaptionTField;
  private JTextField confiRightCaptionTField;
 
  private SpinnerNumberModel alarmDurationSpinnerModel;
  private SpinnerNumberModel alarmDelaySpinnerModel;
  private SpinnerNumberModel imgDelaySpinnerModel;
 
  private JTextField alarmCaptionTField;
 
  private JCheckBox feedBackCBox;
 
  private SpinnerNumberModel delayOkSpinnerModel;
 
  private JTextField imageHadThreatSuccMsgField;
  private JTextField imageHadThreatFailMsgField;
 
  private JTextField imageNoThreatSuccMsgField;
  private JTextField imageNoThreatFailMsgField;
 
  private JTextField generalMsgTField;
 
  private Dimension maxRightSide = new Dimension(1000,20);
  private Dimension fieldPrefSize = new Dimension(200, 20);

 
  ScreenerConf getConf()
  {
    return conf;
  }
 
  public ScreenerConfigurationDialog(JFrame owner) {
    super(owner);
    setLocation(400,300);
    setTitle("Screener Configuration");
    setModalityType( JDialog.DEFAULT_MODALITY_TYPE);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
   
    conf = new ScreenerConf();
       
    createGui();   
       
    pack();
    setVisible(true);
       
  }
 
  private void createGui() {
    setLayout( new BoxLayout( getContentPane(), BoxLayout.Y_AXIS ));
   
    JTabbedPane tabbedPane = new JTabbedPane();
    add(tabbedPane);
    tabbedPane.addTab("General", createGeneralTab() );
    tabbedPane.addTab("FeedBack", createFeedBackTab());   
   
    /*************************************************/
   
    Box rowLast = new Box( BoxLayout.X_AXIS);
    JButton okBtn = new JButton("Ok");
    rowLast.add(okBtn);
    add(rowLast);
   
    okBtn.addActionListener(this);
  }
 
  private JPanel createGeneralTab() {
   
    JPanel pan = new JPanel();
    pan.setLayout( new BoxLayout( pan, BoxLayout.Y_AXIS) );
    add(pan);

    JPanel timeLimitPanel = new JPanel();
    timeLimitPanel.setLayout( new BoxLayout(timeLimitPanel, BoxLayout.Y_AXIS));
    timeLimitPanel.setBorder( BorderFactory.createTitledBorder("Screening time limit") );
    pan.add(timeLimitPanel);
    pan.add( Box.createVerticalStrut( 8 ));
   
    Box timeLimitLayout = new Box(BoxLayout.X_AXIS);
    timeLimitPanel.add(timeLimitLayout);
   
    JLabel timeLimitLbl = new JLabel("Time limit for each screening page:");
    timeLimitLayout.add(timeLimitLbl);
   
    timeLimitLayout.add(Box.createHorizontalGlue());
   
    timeLimitSpinnerModel = new SpinnerNumberModel(0// inital value
                            0// min
                            300// max
                            1)// step
    JSpinner timeLimitSpinner = new JSpinner(timeLimitSpinnerModel);
    timeLimitSpinner.setMaximumSize(maxRightSide);
    timeLimitLayout.add(timeLimitSpinner);
   
    Box timeLimitMsgBox = new Box(BoxLayout.X_AXIS);
    timeLimitPanel.add(timeLimitMsgBox);
   
    JLabel timeLimitMsgLbl = new JLabel("Time out message:");
    timeLimitMsgBox.add(timeLimitMsgLbl);
   
    //timeLimitMsgBox.add( Box.createHorizontalGlue() );
   
    timeoutMsgField = new JTextField();
    timeoutMsgField.setPreferredSize( fieldPrefSize );
    timeoutMsgField.setMaximumSize(maxRightSide);
    timeLimitMsgBox.add(timeoutMsgField);
    /*************************************************/
   
    JPanel threatImagesPanel = new JPanel();
    threatImagesPanel.setBorder( BorderFactory.createTitledBorder("Images with a threat")  );
    threatImagesPanel.setLayout( new BoxLayout(threatImagesPanel, BoxLayout.Y_AXIS) );
    pan.add(threatImagesPanel);
    pan.add( Box.createVerticalStrut( 8 ));
   
    Box threatImgCnLayout = new Box( BoxLayout.X_AXIS );
    threatImagesPanel.add(threatImgCnLayout);
   
    JLabel threatImagesNum = new JLabel("Number of images:");
    threatImgCnLayout.add(threatImagesNum);
   
    threatImgCnLayout.add(Box.createHorizontalGlue());
   
    threatImagesSpinnerModel = new SpinnerNumberModel(1, //initial value
                        1, //min
                        99, // max
                        1); // step
    JSpinner threatImagesSpinner = new JSpinnerthreatImagesSpinnerModel );
    threatImagesSpinner.setMaximumSize(maxRightSide);
    threatImgCnLayout.add(threatImagesSpinner);
   
    Box threatAlertLayout = new Box(BoxLayout.X_AXIS);
    threatImagesPanel.add(threatAlertLayout);
   
    JLabel threatAlertLbl = new JLabel("Number of images to show alert for:");
    threatAlertLayout.add(threatAlertLbl);
   
    threatAlertLayout.add(Box.createHorizontalGlue());
   
    threatAlertSpinnerModel = new SpinnerNumberModel(1, //initial value
                             1, // min
                             99, // max
                             1);// step
    JSpinner threatAlertSpinner = new JSpinner(threatAlertSpinnerModel);
    threatAlertSpinner.setMaximumSize(maxRightSide);
    threatAlertLayout.add(threatAlertSpinner);   
   
    /*************************************************/
    JPanel noThreatImagesPanel = new JPanel();
    noThreatImagesPanel.setBorder( BorderFactory.createTitledBorder("Images without a threat")  );
    noThreatImagesPanel.setLayout( new BoxLayout(noThreatImagesPanel, BoxLayout.Y_AXIS) );
    pan.add(noThreatImagesPanel);
    pan.add( Box.createVerticalStrut( 8 ));
   
    Box noThreatImgCnlayout = new Box( BoxLayout.X_AXIS );
    noThreatImagesPanel.add(noThreatImgCnlayout);
   
    JLabel noThreatImagesNum = new JLabel("Number Of Images:");
    noThreatImgCnlayout.add(noThreatImagesNum);
   
    noThreatImgCnlayout.add(Box.createHorizontalGlue());
   
    noThreatImagesSpinnerModel = new SpinnerNumberModel(1, // initial value
                              1, // min
                              99, // max
                              1); // step
    JSpinner noThreatImagesSpinner  = new JSpinner( noThreatImagesSpinnerModel );
    noThreatImagesSpinner.setMaximumSize(maxRightSide);
    noThreatImgCnlayout.add(noThreatImagesSpinner);
   
    Box noThreatAlertLayout = new Box( BoxLayout.X_AXIS );
    noThreatImagesPanel.add(noThreatAlertLayout);
   
    JLabel noThreatAlertLbl = new JLabel("Number of images to show alert for:");
    noThreatAlertLayout.add(noThreatAlertLbl);
   
    noThreatAlertLayout.add(Box.createHorizontalGlue());
   
    noThreatAlertSpinnerModel = new SpinnerNumberModel(1, // initial value
                              1, // min
                              99, // max
                              1); // step
    JSpinner noThreatAlertSpinner = new JSpinner(noThreatAlertSpinnerModel);
    noThreatAlertSpinner.setMaximumSize(maxRightSide);
    noThreatAlertLayout.add(noThreatAlertSpinner);
   
    /*************************************************/
   
    JPanel passFailPanel = new JPanel();
    passFailPanel.setLayout( new BoxLayout(passFailPanel, BoxLayout.Y_AXIS));
    passFailPanel.setBorder( BorderFactory.createTitledBorder("Button Caption"));
    pan.add(passFailPanel);
    pan.add( Box.createVerticalStrut( 8 ));
   
    Box passBox = new Box(BoxLayout.X_AXIS);
    passFailPanel.add(passBox);
   
    JLabel passLbl = new JLabel("Pass Caption");
    passBox.add(passLbl);
   
    passBox.add(Box.createHorizontalGlue());
   
    passCaptionTField = new JTextField(conf.defaultPassBtnCaption);
    passCaptionTField.setMaximumSize(new Dimension(200, 20) );
    passBox.add(passCaptionTField);
   
    Box failBox = new Box(BoxLayout.X_AXIS);
    passFailPanel.add(failBox);
   
    JLabel failLbl = new JLabel("Pass Caption");
    failBox.add(failLbl);
   
    failBox.add(Box.createHorizontalGlue());
   
    failCaptionTField = new JTextField(conf.defaultFailBtnCaption);
    failCaptionTField.setMaximumSize(new Dimension(200, 20) );
    failBox.add(failCaptionTField);
   
   
    /*************** Confidence *************************/
    JPanel confidencePanel = new JPanel();
    confidencePanel.setLayout( new BoxLayout(confidencePanel, BoxLayout.Y_AXIS));
    confidencePanel.setBorder( BorderFactory.createTitledBorder("Confidence Level"));
    pan.add(confidencePanel);
    pan.add( Box.createVerticalStrut( 8 ));
   
    Box confidenceLevelLayout = new Box( BoxLayout.X_AXIS );
    confidencePanel.add(confidenceLevelLayout);
   
    JLabel confidenceLbl = new JLabel("Scale");
    confidenceLevelLayout.add(confidenceLbl);
   
    confidenceLevelLayout.add(Box.createHorizontalGlue());
   
    confidenceLevelModel = new SpinnerNumberModel(0, // initial value
                            0, // min
                            10// max
                            1); // step
    JSpinner confidenceLevelSpinner = new JSpinner(confidenceLevelModel);
    confidenceLevelSpinner.setMaximumSize(maxRightSide);
    confidenceLevelLayout.add(confidenceLevelSpinner);
   
    // ***** msg title
    Box confiMsgLayout = new Box( BoxLayout.X_AXIS );
    confidencePanel.add( confiMsgLayout );
   
    JLabel confiMsgCaptionLbl = new JLabel("Caption");
    confiMsgLayout.add(confiMsgCaptionLbl);
   
    confiMsgLayout.add( Box.createHorizontalGlue() );
    confiCaptionField = new JTextField( conf.defaultConfidenceTitle );
    confiCaptionField.setMaximumSize( maxRightSide );
    confiCaptionField.setPreferredSize( fieldPrefSize );
    confiMsgLayout.add(confiCaptionField);
   
    // ***** left caption row
    Box confiLeftCaptionLayout = new Box( BoxLayout.X_AXIS);
    confidencePanel.add(confiLeftCaptionLayout);
   
    JLabel confiLeftCaptionLbl = new JLabel("Left caption");
    confiLeftCaptionLayout.add(confiLeftCaptionLbl);
   
    confiLeftCaptionLayout.add(Box.createHorizontalGlue());
   
    confiLeftCaptionTField= new JTextField(conf.defaultConfidenceLeft);
    confiLeftCaptionTField.setMaximumSize(maxRightSide);
    confiLeftCaptionLayout.add(confiLeftCaptionTField);
   
    // ***** right caption row
    Box confiRightCaptionLayout = new Box( BoxLayout.X_AXIS);
    confidencePanel.add(confiRightCaptionLayout);
   
    JLabel confiRightCaptionLbl = new JLabel("Right caption");
    confiRightCaptionLayout.add(confiRightCaptionLbl);
   
    confiRightCaptionLayout.add(Box.createHorizontalGlue());
   
    confiRightCaptionTField= new JTextField(conf.defaultConfidenceRight);
    confiRightCaptionTField.setMaximumSize(maxRightSide);
    confiRightCaptionLayout.add(confiRightCaptionTField);
   
    /*************************************************/
    JPanel alarmPanel = new JPanel();
    alarmPanel.setLayout( new BoxLayout(alarmPanel, BoxLayout.Y_AXIS));
    alarmPanel.setBorder(BorderFactory.createTitledBorder("Alarm and Image Apearance"));
    pan.add(alarmPanel);
    pan.add( Box.createVerticalStrut( 8 ));
   
    // alarm duration spinner
    Box alarmDurationLayout = new Box( BoxLayout.X_AXIS);
    alarmPanel.add(alarmDurationLayout);
   
    JLabel alarmDurationLbl = new JLabel("Alarm duration");
    alarmDurationLayout.add(alarmDurationLbl);
   
    alarmDurationLayout.add(Box.createHorizontalGlue());
   
    alarmDurationSpinnerModel = new SpinnerNumberModel(0, // initial value
                                        0, // min
                                        59, // max
                                        1);
    JSpinner alarmDurationSpinner = new JSpinner(alarmDurationSpinnerModel);
    alarmDurationSpinner.setMaximumSize(maxRightSide);
    alarmDurationLayout.add(alarmDurationSpinner);
   
    // alarm delay spinner
    Box alarmDelayLayout = new Box( BoxLayout.X_AXIS);
    alarmPanel.add(alarmDelayLayout);
   
    JLabel alarmDelayLbl = new JLabel("Alarm delay");
    alarmDelayLayout.add(alarmDelayLbl);
   
    alarmDelayLayout.add(Box.createHorizontalGlue());
   
    alarmDelaySpinnerModel = new SpinnerNumberModel(0, // initial value
                                        0, // min
                                        59, // max
                                        1);
    JSpinner alarmDelaySpinner = new JSpinner(alarmDelaySpinnerModel);
    alarmDelaySpinner.setMaximumSize(maxRightSide);
    alarmDelayLayout.add(alarmDelaySpinner);
   
    // image delay spinner
    Box imgDelayLayout = new Box( BoxLayout.X_AXIS);
    alarmPanel.add(imgDelayLayout);
   
    JLabel imgDelayLbl = new JLabel("Image delay");
    imgDelayLayout.add(imgDelayLbl);
   
    imgDelayLayout.add(Box.createHorizontalGlue());
   
    imgDelaySpinnerModel = new SpinnerNumberModel(0, // initial value
                                        0, // min
                                        59, // max
                                        1);
    JSpinner imgDelaySpinner = new JSpinner(imgDelaySpinnerModel);
    imgDelaySpinner.setMaximumSize(maxRightSide);
    imgDelayLayout.add(imgDelaySpinner);
   
    // alarm Caption
    Box alarmCaptionLayout = new Box( BoxLayout.X_AXIS);
    alarmPanel.add(alarmCaptionLayout);
   
    JLabel alarmCaptionLbl = new JLabel("Alarm label");
    alarmCaptionLayout.add(alarmCaptionLbl);

    alarmCaptionLayout.add(Box.createHorizontalGlue());
   
    alarmCaptionTField = new JTextField(conf.defaultAlertCaption);
    alarmCaptionTField.setMaximumSize(new Dimension(200, 20) );
    alarmCaptionLayout.add(alarmCaptionTField);

    return pan;
  }

 
 
  private JPanel createFeedBackTab() {
   
    JPanel pan = new JPanel();
    pan.setLayout( new BoxLayout( pan, BoxLayout.Y_AXIS) );
    add(pan);
   
    Box fbBox = new Box(BoxLayout.X_AXIS);
    pan.add(fbBox);
    pan.add( Box.createVerticalStrut( 8 ));
   
    feedBackCBox = new JCheckBox("Show Feedback Dialog.");
    fbBox.add(feedBackCBox);
    fbBox.add(Box.createHorizontalGlue());
    /*************************************************/
   
    Box delayOkBox  = new Box( BoxLayout.X_AXIS);
    pan.add(delayOkBox);
    pan.add( Box.createVerticalStrut( 8 ));
   
    JLabel delayOkLbl = new JLabel("Delay button Ok (sec)");
    delayOkBox.add(delayOkLbl);
   
    delayOkBox.add(Box.createHorizontalGlue());
   
    delayOkSpinnerModel = new SpinnerNumberModel(0//initial value
                          0,   // min
                          30, // max
                          1); // step
    JSpinner delayOkSpinner = new JSpinner(delayOkSpinnerModel);
    delayOkSpinner.setMaximumSize(maxRightSide);
    delayOkBox.add(delayOkSpinner);
       
    /*************************************************/
    JPanel ackPanel = new JPanel();
    ackPanel.setLayout( new BoxLayout(ackPanel, BoxLayout.Y_AXIS));
    ackPanel.setBorder( BorderFactory.createTitledBorder("Acknowledge User"));
    pan.add(ackPanel);
    pan.add( Box.createVerticalStrut( 8 ));
   
    // Acknowledge check box
    Box ackBox = new Box(BoxLayout.X_AXIS);
    ackPanel.add(ackBox);
   
    acknowledgeResultCBox = new JCheckBox("Show Correctness of user choice.");
    ackBox.add(acknowledgeResultCBox);
   
    ackBox.add(Box.createHorizontalGlue());

    // instruction label for 
    Box ackInstBox = new Box(BoxLayout.X_AXIS);
    ackPanel.add(ackInstBox);   
    JLabel ackInstLbl = new JLabel("<html>Embed the text <i>TIMETOK</i> in and it will be</html>");
    ackInstBox.add(ackInstLbl);
   
    Box ackInst2Box = new Box(BoxLayout.X_AXIS);
    ackPanel.add(ackInst2Box);
    JLabel ackInst2Lbl = new JLabel("replaced for the user with the answer time.");
    ackInst2Box.add(ackInst2Lbl);
   
   
    // success msg
    imageHadThreatSuccMsgField = new JTextField();
    imageHadThreatFailMsgField = new JTextField();
    createFeedBackMsgPanel(ackPanel,
        imageHadThreatSuccMsgField,
        imageHadThreatFailMsgField,
        "Image had a threat");
   
    imageNoThreatSuccMsgField = new JTextField();
    imageNoThreatFailMsgField = new JTextField();
    createFeedBackMsgPanel(ackPanel,
        imageNoThreatSuccMsgField,
        imageNoThreatFailMsgField,
        "Image had no threat");
   
   
    /*************************************************/
    Box generalMsgBox = new Box(BoxLayout.X_AXIS);
    pan.add(generalMsgBox);
    pan.add( Box.createVerticalStrut( 8 ));
   
    JLabel generalMsgLbl = new JLabel("General message.");
    generalMsgBox.add(generalMsgLbl);
   
    generalMsgBox.add(Box.createHorizontalGlue());
   
    generalMsgTField = new JTextField("Screening page complete");
    generalMsgTField.setMaximumSize(maxRightSide);
    generalMsgBox.add(generalMsgTField);   
   
    return pan;
  }
 
  public void createFeedBackMsgPanel(JPanel fp_parentPanel,
                  JTextField fp_succMsgField,
                  JTextField fp_failMsgField,
                  final String fp_title)
  {
    JPanel container = new JPanel();
    container.setBorder( BorderFactory.createTitledBorder(fp_title));
    container.setLayout( new BoxLayout(container, BoxLayout.Y_AXIS));
    fp_parentPanel.add(container);
   
    Box succMsgBox = new Box(BoxLayout.X_AXIS);
    container.add(succMsgBox);
   
    JLabel succMsgLbl = new JLabel("Succefull message:");
    succMsgBox.add(succMsgLbl);
   
    succMsgBox.add(Box.createHorizontalGlue());
   
    fp_succMsgField.setText(conf.defaultSuccMsg);
    fp_succMsgField.setMaximumSize(maxRightSide);
    fp_succMsgField.setPreferredSize( fieldPrefSize );
    succMsgBox.add(fp_succMsgField);
   
    // fail msg
    Box failMsgBox = new Box(BoxLayout.X_AXIS);
    container.add(failMsgBox);
   
    JLabel failMsgLbl = new JLabel("Failure message:");
    failMsgBox.add(failMsgLbl);
   
    failMsgBox.add(Box.createHorizontalGlue());
   
    fp_failMsgField.setText(conf.defaultFailureMsg);
    fp_failMsgField.setMaximumSize(maxRightSide);
    fp_failMsgField.setPreferredSize( fieldPrefSize );
    failMsgBox.add(fp_failMsgField);
   
  }
 
  public void actionPerformed(ActionEvent e)
  {
    conf.timeLimit = timeLimitSpinnerModel.getNumber().intValue() * 1000;
    conf.timeoutMsg = timeoutMsgField.getText();
    conf.numOfPicturesWThreat =  threatImagesSpinnerModel.getNumber().intValue();
    conf.numOfPicturesWThreatToAlertFor = threatImagesSpinnerModel.getNumber().intValue();
    conf.numOfPicturesWOThreat = noThreatImagesSpinnerModel.getNumber().intValue();
    conf.numOfPicturesWOThreatToAlertFor = noThreatAlertSpinnerModel.getNumber().intValue();
    conf.passBtnCaption = passCaptionTField.getText();
    conf.failBtnCaption = failCaptionTField.getText();
    conf.confidenceScale = confidenceLevelModel.getNumber().intValue();
    conf.confidenceTitle = confiCaptionField.getText();
    conf.confidenceLeftCaption = confiLeftCaptionTField.getText();
    conf.confidenceRightCaption = confiRightCaptionTField.getText();
    conf.alertDuration = alarmDurationSpinnerModel.getNumber().intValue() * 1000;
    conf.alertDelay = alarmDelaySpinnerModel.getNumber().intValue() * 1000 ;
    conf.imageDelay = imgDelaySpinnerModel.getNumber().intValue() * 1000;
    conf.alertCaption = alarmCaptionTField.getText();
   
    // tab feedback
    conf.feedback = (feedBackCBox.isSelected())?true:false;
    conf.delayOk = delayOkSpinnerModel.getNumber().intValue()* 1000;
    conf.acknowledgeResult = (acknowledgeResultCBox.isSelected()==true) ? true : false;
    conf.imageHadThreatSuccessMsg = imageHadThreatSuccMsgField.getText();
    conf.imageHadThreatFailureMsg = imageHadThreatFailMsgField.getText();
    conf.imageNoThreatSuccessMsg = imageNoThreatSuccMsgField.getText();
    conf.imageNoThreatFailureMsg = imageNoThreatFailMsgField.getText();
    conf.genralMsg = generalMsgTField.getText();
   
    setVisible(false);
  }
 
 
 
};
TOP

Related Classes of periman.ScreenerConfigurationDialog

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.