/*
 * SimResult.java
 *
 * Created on September 14, 2008, 9:51 PM
 */
package gui;

import java.awt.Component;
import java.text.NumberFormat;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import qsim.distributions.PseudoHyperExpDist;
import qsim.distributions.PseudoHypoExpDist;
import qsim.resultProcessors.*;
import qsim.simulators.*;
import umontreal.iro.lecuyer.probdist.ContinuousDistribution;
import umontreal.iro.lecuyer.probdist.ErlangDist;
import umontreal.iro.lecuyer.probdist.ExponentialDist;

/**
 *
 * @author  joe
 */
public class SimResultInTable extends javax.swing.JFrame {

    /** Creates new form SimResult */
    public SimResultInTable() {
        initComponents();
    }

    public SimResultInTable(ContinuousDistribution arrDist, ContinuousDistribution servDist, int n, int k, String policy, double timeHorizon) {
    
        this.arrDist = arrDist;
        this.servDist = servDist;

        this.n = n;
        this.k = k;
        this.policy = policy;
        this.timeHorizon = timeHorizon;

        initComponents();
        this.setLocation(170, 170);
        
        
        //ikon beszúrása
        java.net.URL imgURL = MainMenu.class.getResource("/gui/images/icon.png");
        ImageIcon icon = new ImageIcon(imgURL);
        this.setIconImage(icon.getImage());

        this.resjTable.getColumnModel().getColumn(1).setCellRenderer(new PrecisionCellRenderer(5));

        //sorbanállási rendszer szöveges megjelenítése:

        //beérkező időközök
        String arrString = new String();
        String servString = new String();

        if (arrDist instanceof ExponentialDist) {
            arrString = "M";
        } else if (arrDist instanceof ErlangDist) {
            arrString = "Er";
        } else if (arrDist instanceof PseudoHyperExpDist) {
            arrString = "HrE";
        } else if (arrDist instanceof PseudoHypoExpDist) {
            arrString = "HoE";
        }

        //kiszolgálási idők
        if (servDist instanceof ExponentialDist) {
            servString = "M";
        } else if (servDist instanceof ErlangDist) {
            servString = "Er";
        } else if (servDist instanceof PseudoHyperExpDist) {
            servString = "HrE";
        } else if (servDist instanceof PseudoHypoExpDist) {
            servString = "HoE";
        }
        
        //kapacitás
        String capacityString = "";
        if (k !=-1 ){
            capacityString+="/" + k;
        }
        this.queuingSystemTypejLabel.setText(arrString + "/" + servString + "/" + n + capacityString);
        this.policyValuejLabel.setText(policy);

        this.setTable();

    }

    public void setTable() {
        qSim = new QueueEv(arrDist, servDist, n, k, policy, timeHorizon);
        resString = qSim.getSimResult();
        //System.out.println(resString);
        ResultProcessor rp = new QueueEvResultProcessor(resString, n);
        
        //ResultProcessor rp = new QueueProcResultProcessor(resString);
        rp.getStatistic();
        if (k != -1){
            Double lossRatio = 1.0 - (new Double(rp.report[5][4]))/(new Double(rp.getLossRatio()));
            this.lossRatioValuejLabel.setText(lossRatio.toString());
        }
        
        /*
        //kapacitás beállítása
        this.resjTable.setValueAt(new Double(rp.report[0][0]), 0, 1);
        this.resjTable.setValueAt(new Double(rp.report[0][1]), 0, 2);
        //this.resjTable.setValueAt(new Double(rp.report[0][2]), 0, 3);
        */
        
        //kihasználtság
        this.resjTable.setValueAt(new Double(rp.report[1][0]), 0, 1);
        this.resjTable.setValueAt(new Double(rp.report[1][1]), 0, 2);
        this.resjTable.setValueAt(new Double(rp.report[1][2]), 0, 3);

        //sorhossz
        this.resjTable.setValueAt(new Double(rp.report[2][0]), 1, 1);
        this.resjTable.setValueAt(new Double(rp.report[2][1]), 1, 2);
        this.resjTable.setValueAt(new Double(rp.report[2][2]), 1, 3);
        this.resjTable.setValueAt(new Double(rp.report[2][3]), 1, 4);

        //várakozási idő
        this.resjTable.setValueAt(new Double(rp.report[3][0]), 2, 1);
        this.resjTable.setValueAt(new Double(rp.report[3][1]), 2, 2);
        this.resjTable.setValueAt(new Double(rp.report[3][2]), 2, 3);
        this.resjTable.setValueAt(new Double(rp.report[3][3]), 2, 4);
        //this.resjTable.setValueAt(new Double(rp.report[3][4]), 3, 5);

        //kiszolgálási idő
        this.resjTable.setValueAt(new Double(rp.report[4][0]), 3, 1);
        this.resjTable.setValueAt(new Double(rp.report[4][1]), 3, 2);
        this.resjTable.setValueAt(new Double(rp.report[4][2]), 3, 3);
        this.resjTable.setValueAt(new Double(rp.report[4][3]), 3, 4);
        //this.resjTable.setValueAt(new Double(rp.report[4][4]), 4, 5);

        //válaszidő
        this.resjTable.setValueAt(new Double(rp.report[5][0]), 4, 1);
        this.resjTable.setValueAt(new Double(rp.report[5][1]), 4, 2);
        this.resjTable.setValueAt(new Double(rp.report[5][2]), 4, 3);
        this.resjTable.setValueAt(new Double(rp.report[5][3]), 4, 4);
        this.resjTable.setValueAt(new Double(rp.report[5][4]), 4, 5);
        
    }

    /** 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() {

        jTextField1 = new javax.swing.JTextField();
        grafikonButtonGroup = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        titlejLabel = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        reSimjButton = new javax.swing.JButton();
        queuingSystemjLabel = new javax.swing.JLabel();
        policyjLabel = new javax.swing.JLabel();
        policyValuejLabel = new javax.swing.JLabel();
        queuingSystemTypejLabel = new javax.swing.JLabel();
        resjScrollPane = new javax.swing.JScrollPane();
        resjTable = new javax.swing.JTable();
        lossRatiojLabel = new javax.swing.JLabel();
        lossRatioValuejLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        drawChartjButton = new javax.swing.JButton();
        sojournjRadioButton = new javax.swing.JRadioButton();
        queueSizeRadioButton = new javax.swing.JRadioButton();
        bmmTitlejLabel = new javax.swing.JLabel();
        batchmeansjLabel = new javax.swing.JLabel();
        batchSizejTextField = new javax.swing.JTextField();
        utilizationjRadioButton = new javax.swing.JRadioButton();
        waitjRadioButton = new javax.swing.JRadioButton();
        servjRadioButton = new javax.swing.JRadioButton();
        batchSizejLabel = new javax.swing.JLabel();
        confidenceLeveljLabel = new javax.swing.JLabel();
        confidenceLeveljTextField = new javax.swing.JTextField();

        jTextField1.setText("jTextField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Szimuláció eredménye");
        setResizable(false);

        titlejLabel.setFont(new java.awt.Font("Albany AMT", 0, 18));
        titlejLabel.setText("Szimuláció eredménye");

        reSimjButton.setText("Szimuláció megismétlése");
        reSimjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reSimjButtonActionPerformed(evt);
            }
        });

        queuingSystemjLabel.setText("Sorbanállási rendszer típusa: ");

        policyjLabel.setText("Kiszolgálási elv:");

        policyValuejLabel.setText("FIFO");

        queuingSystemTypejLabel.setText("M/M/1");

        resjTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Kihasználtság", null, null, null, null, null},
                {"Sorhossz", null, null, null, null, null},
                {"Várakozási idő", null, null, null, null, null},
                {"Kiszolgálási idő", null, null, null, null, null},
                {"Válaszidő", null, null, null, null, null}
            },
            new String [] {
                "", "min", "max", "átlag", "szórás", "igények száma"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        resjTable.setColumnSelectionAllowed(true);
        resjScrollPane.setViewportView(resjTable);
        resjTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        resjTable.getColumnModel().getColumn(0).setResizable(false);
        resjTable.getColumnModel().getColumn(1).setResizable(false);
        resjTable.getColumnModel().getColumn(2).setResizable(false);
        resjTable.getColumnModel().getColumn(3).setResizable(false);
        resjTable.getColumnModel().getColumn(4).setResizable(false);
        resjTable.getColumnModel().getColumn(5).setResizable(false);

        lossRatiojLabel.setText("Igényvesztés aránya:");

        lossRatioValuejLabel.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(resjScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 656, Short.MAX_VALUE)
                    .addComponent(reSimjButton)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(queuingSystemjLabel)
                            .addComponent(policyjLabel))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(policyValuejLabel)
                            .addComponent(queuingSystemTypejLabel)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lossRatiojLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lossRatioValuejLabel)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(reSimjButton)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(queuingSystemjLabel)
                    .addComponent(queuingSystemTypejLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(policyjLabel)
                    .addComponent(policyValuejLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(resjScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lossRatiojLabel)
                    .addComponent(lossRatioValuejLabel))
                .addContainerGap(55, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Szimulációs adatok", jPanel1);

        drawChartjButton.setText("Grafikon rajzolása");
        drawChartjButton.setEnabled(false);
        drawChartjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                drawChartjButtonActionPerformed(evt);
            }
        });

        grafikonButtonGroup.add(sojournjRadioButton);
        sojournjRadioButton.setText("Válaszidő");
        sojournjRadioButton.setActionCommand("sojourn");
        sojournjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sojournjRadioButtonActionPerformed(evt);
            }
        });

        grafikonButtonGroup.add(queueSizeRadioButton);
        queueSizeRadioButton.setText("Sorhossz");
        queueSizeRadioButton.setActionCommand("queueSize");
        queueSizeRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                queueSizeRadioButtonActionPerformed(evt);
            }
        });

        bmmTitlejLabel.setText("A szimulció során mért adatok grafikonon való megjelenítése");

        batchmeansjLabel.setText("Konfidencia interrvalum meghatározása a mintaátlaghoz a batch-means method-ot alkalmazva");

        batchSizejTextField.setText("20");
        batchSizejTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                batchSizejTextFieldKeyReleased(evt);
            }
        });

        grafikonButtonGroup.add(utilizationjRadioButton);
        utilizationjRadioButton.setText("Kihasználtság (a foglalt szerverek átlagos száma)");
        utilizationjRadioButton.setActionCommand("utilization");
        utilizationjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                utilizationjRadioButtonActionPerformed(evt);
            }
        });

        grafikonButtonGroup.add(waitjRadioButton);
        waitjRadioButton.setText("Várakozási idő");
        waitjRadioButton.setActionCommand("waitTime");
        waitjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                waitjRadioButtonActionPerformed(evt);
            }
        });

        grafikonButtonGroup.add(servjRadioButton);
        servjRadioButton.setText("Kiszolgálási idő");
        servjRadioButton.setActionCommand("servTime");
        servjRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                servjRadioButtonActionPerformed(evt);
            }
        });

        batchSizejLabel.setText("Kötegek mérete:");

        confidenceLeveljLabel.setText("Konfidencia szint (%):");

        confidenceLeveljTextField.setText("95");
        confidenceLeveljTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                confidenceLeveljTextFieldKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(queueSizeRadioButton)
                            .addComponent(utilizationjRadioButton)
                            .addComponent(waitjRadioButton)
                            .addComponent(servjRadioButton)
                            .addComponent(sojournjRadioButton)))
                    .addComponent(bmmTitlejLabel)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(batchmeansjLabel)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(batchSizejLabel)
                                    .addComponent(confidenceLeveljLabel))
                                .addGap(56, 56, 56)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(confidenceLeveljTextField, 0, 0, Short.MAX_VALUE)
                                    .addComponent(batchSizejTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)))))
                    .addComponent(drawChartjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(204, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(bmmTitlejLabel)
                .addGap(18, 18, 18)
                .addComponent(utilizationjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(queueSizeRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(waitjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(servjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sojournjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(batchmeansjLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(batchSizejLabel)
                    .addComponent(batchSizejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(confidenceLeveljTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(confidenceLeveljLabel))
                .addGap(18, 18, 18)
                .addComponent(drawChartjButton)
                .addGap(37, 37, 37))
        );

        jTabbedPane1.addTab("Grafikonok", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 681, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(titlejLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titlejLabel)
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

private void reSimjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reSimjButtonActionPerformed
    // TODO add your handling code here:

    //this.reSimjButton.setEnabled(false);
    this.setTable();
}
//GEN-LAST:event_reSimjButtonActionPerformed

private void drawChartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_drawChartjButtonActionPerformed
// TODO add your handling code here:
    String chartTitle = "";
    if (this.grafikonButtonGroup.getSelection().getActionCommand().equals("utilization")){
        chartTitle = "Kihasználtság";
    }
    else if (this.grafikonButtonGroup.getSelection().getActionCommand().equals("queueSize")){
        chartTitle = "Sorhossz";
    }
    else if (this.grafikonButtonGroup.getSelection().getActionCommand().equals("waitTime")){
        chartTitle = "Várakozási idő";
    }
    else if (this.grafikonButtonGroup.getSelection().getActionCommand().equals("servTime")){
        chartTitle = "Kiszolgálási idő";
    }
    else if (this.grafikonButtonGroup.getSelection().getActionCommand().equals("sojourn")){
        chartTitle = "Válaszidők a beérkezett igények sorszámának függvényében";
    }
    
    try{
        qSim.generateChart(this.grafikonButtonGroup.getSelection().getActionCommand(), new Integer(this.batchSizejTextField.getText()), 
                new Double(this.confidenceLeveljTextField.getText()), chartTitle);
    }
    catch(Exception e){
        new ErrorDialog(this, true, e.getMessage()).setVisible(true);
    }
}//GEN-LAST:event_drawChartjButtonActionPerformed

private void sojournjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sojournjRadioButtonActionPerformed
// TODO add your handling code here:
    this.drawChartjButton.setEnabled(true);
}//GEN-LAST:event_sojournjRadioButtonActionPerformed

private void queueSizeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_queueSizeRadioButtonActionPerformed
// TODO add your handling code here:
    this.drawChartjButton.setEnabled(true);
}//GEN-LAST:event_queueSizeRadioButtonActionPerformed

private void batchSizejTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_batchSizejTextFieldKeyReleased
// TODO add your handling code here:
    try {
        if (this.batchSizejTextField.getText().equals("")){
            return;
        }
        new Integer(this.batchSizejTextField.getText());
    } catch (Exception e) {
        this.batchSizejTextField.setText("20");
    }
}//GEN-LAST:event_batchSizejTextFieldKeyReleased

private void utilizationjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_utilizationjRadioButtonActionPerformed
// TODO add your handling code here:
    this.drawChartjButton.setEnabled(true);
}//GEN-LAST:event_utilizationjRadioButtonActionPerformed

private void waitjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_waitjRadioButtonActionPerformed
// TODO add your handling code here:
    this.drawChartjButton.setEnabled(true);
}//GEN-LAST:event_waitjRadioButtonActionPerformed

private void servjRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_servjRadioButtonActionPerformed
// TODO add your handling code here:
    this.drawChartjButton.setEnabled(true);
}//GEN-LAST:event_servjRadioButtonActionPerformed

private void confidenceLeveljTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_confidenceLeveljTextFieldKeyReleased
// TODO add your handling code here:
    try {
        if (this.confidenceLeveljTextField.getText().trim().equals("")) return;
        Double cL = new Double(this.confidenceLeveljTextField.getText());
        if (cL < 1 || 99.9 < cL){
            this.confidenceLeveljTextField.setText("95");
        }
    } catch (Exception e) {
        this.confidenceLeveljTextField.setText("95");
    }
}//GEN-LAST:event_confidenceLeveljTextFieldKeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel batchSizejLabel;
    private javax.swing.JTextField batchSizejTextField;
    private javax.swing.JLabel batchmeansjLabel;
    private javax.swing.JLabel bmmTitlejLabel;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.JLabel confidenceLeveljLabel;
    private javax.swing.JTextField confidenceLeveljTextField;
    private javax.swing.JButton drawChartjButton;
    private javax.swing.ButtonGroup grafikonButtonGroup;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JLabel lossRatioValuejLabel;
    private javax.swing.JLabel lossRatiojLabel;
    private javax.swing.JLabel policyValuejLabel;
    private javax.swing.JLabel policyjLabel;
    private javax.swing.JRadioButton queueSizeRadioButton;
    private javax.swing.JLabel queuingSystemTypejLabel;
    private javax.swing.JLabel queuingSystemjLabel;
    protected javax.swing.JButton reSimjButton;
    private javax.swing.JScrollPane resjScrollPane;
    private javax.swing.JTable resjTable;
    private javax.swing.JRadioButton servjRadioButton;
    private javax.swing.JRadioButton sojournjRadioButton;
    private javax.swing.JLabel titlejLabel;
    private javax.swing.JRadioButton utilizationjRadioButton;
    private javax.swing.JRadioButton waitjRadioButton;
    // End of variables declaration//GEN-END:variables
    private ContinuousDistribution arrDist;
    private ContinuousDistribution servDist;
    private int n;
    private int k;
    private String policy;
    private double timeHorizon;
    private QueueMotor qSim;
    private String resString;

    private static class PrecisionCellRenderer extends DefaultTableCellRenderer {

        private NumberFormat format;

        PrecisionCellRenderer(int precision) {
            format = NumberFormat.getNumberInstance();
            format.setMaximumFractionDigits(precision);
            format.setMinimumFractionDigits(precision);

        }

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            setText(format.format(value));
            setHorizontalAlignment(JLabel.RIGHT);
            return this;
        }
    }
}
