/*
 * VentanaConfigurarAsincronos.java
 *
 * Created on 21 de agosto de 2008, 20:03
 */

package sdsimulator.interfaz;
/**
 *
 * @author  Miguel Herreros
 */
public class VentanaConfigurarAsincronos extends javax.swing.JDialog {
    /** A return status code - returned if Cancel button has been pressed */
    public static final int RET_CANCEL = 0;
    /** A return status code - returned if OK button has been pressed */
    public static final int RET_OK = 1;
    
    public VentanaConfigurarAsincronos(java.awt.Frame parent, boolean modal){
        super(parent, modal);
        
        initComponents();
  
        jSliderAsynchronous.setValue(sdsimulator.Main.FRECUENCIA_LLEGADA_ASINCRONOS_DEFECTO);
        checkboxAsynchronous.setState(sdsimulator.Main.PRIORIDAD_ASINCRONOS_ANTIGUOS_DEFECTO);
    }
    
    /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
    public int getReturnStatus() {
        return returnStatus;
    }
    
    public int getFrecuenciaLlegada(){
        return jSliderAsynchronous.getValue();
    }
    
    public boolean getPrioridadAntiguos(){
        return checkboxAsynchronous.getState();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabelAsynchronous = new javax.swing.JLabel();
        jSliderAsynchronous = new javax.swing.JSlider();
        checkboxAsynchronous = new java.awt.Checkbox();
        jLabel1 = new javax.swing.JLabel();
        jLabelSliderInfo1 = new javax.swing.JLabel();
        jLabelSliderInfo2 = new javax.swing.JLabel();

        setTitle("Configuration of  asynchronous messages behaviour");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        jLabelAsynchronous.setText("Delay in asynchronous messages reception ");
        jLabelAsynchronous.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jSliderAsynchronous.setMaximum(10);
        jSliderAsynchronous.setMinimum(1);
        jSliderAsynchronous.setMinorTickSpacing(1);
        jSliderAsynchronous.setPaintTicks(true);
        jSliderAsynchronous.setSnapToTicks(true);
        jSliderAsynchronous.setToolTipText("about 5");
        jSliderAsynchronous.setValue(5);
        jSliderAsynchronous.setFocusable(false);
        jSliderAsynchronous.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSliderAsynchronousMouseReleased(evt);
            }
        });

        checkboxAsynchronous.setFont(new java.awt.Font("Tahoma", 0, 11));
        checkboxAsynchronous.setLabel("Give priority to older messages");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("blocked!");

        jLabelSliderInfo1.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabelSliderInfo1.setText("<- decrease delay");

        jLabelSliderInfo2.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabelSliderInfo2.setText("increase delay ->");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(checkboxAsynchronous, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabelAsynchronous)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE))
                            .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addComponent(cancelButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(315, Short.MAX_VALUE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabelSliderInfo1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 149, Short.MAX_VALUE)
                .addComponent(jLabelSliderInfo2)
                .addGap(31, 31, 31))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSliderAsynchronous, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabelAsynchronous)
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelSliderInfo1)
                    .addComponent(jLabelSliderInfo2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSliderAsynchronous, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(12, 12, 12)
                .addComponent(checkboxAsynchronous, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(71, 71, 71)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        doClose(RET_OK);
    }//GEN-LAST:event_okButtonActionPerformed
    
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        doClose(RET_CANCEL);
    }//GEN-LAST:event_cancelButtonActionPerformed

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        doClose(RET_CANCEL);
    }//GEN-LAST:event_closeDialog

private void jSliderAsynchronousMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSliderAsynchronousMouseReleased
    jSliderAsynchronous.setToolTipText("about " + jSliderAsynchronous.getValue());
}//GEN-LAST:event_jSliderAsynchronousMouseReleased

    private void doClose(int retStatus) {
        returnStatus = retStatus;
        setVisible(false);
        dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private java.awt.Checkbox checkboxAsynchronous;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelAsynchronous;
    private javax.swing.JLabel jLabelSliderInfo1;
    private javax.swing.JLabel jLabelSliderInfo2;
    private javax.swing.JSlider jSliderAsynchronous;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables

    private int returnStatus = RET_CANCEL;
}
