/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package SchedulesWindows;

import SchedulesRecovery.BankRecoveredSchedules;
import java.util.*;

/**
 *
 * @author frabe
 */
public class ShowSolutionResultsFrame extends javax.swing.JFrame {

    private List< BankRecoveredSchedules > bankRecoveredSchedulesOrderedByMeanCost;
    /**
     * Creates new form ShowSchedulesFrame
     */
    public ShowSolutionResultsFrame(List< BankRecoveredSchedules > bankRecoveredSchedulesOrderedByMeanCost) {
        this.bankRecoveredSchedulesOrderedByMeanCost = bankRecoveredSchedulesOrderedByMeanCost;
        initComponents();
        init();
    }
    
    private void init() {
        setTitle("Simulation Results");
        setVisible(true);
        changeScheduleNumberScrollBar.setMinimum(1);
        int numberOfSchedules = this.bankRecoveredSchedulesOrderedByMeanCost.size();
        changeScheduleNumberScrollBar.setMaximum(numberOfSchedules);
        changeScheduleNumberScrollBar.setBlockIncrement(numberOfSchedules/10);
        changeScheduleNumberScrollBar.setVisibleAmount(numberOfSchedules/10);
        changeScheduleNumberScrollBar.setUnitIncrement(1);
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        changeScheduleNumberScrollBar = new javax.swing.JScrollBar();
        jScrollPane1 = new javax.swing.JScrollPane();
        scheduleViewerArea = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        textSolutionNumber = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        mainPanel.setPreferredSize(new java.awt.Dimension(1400, 1000));

        changeScheduleNumberScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener() {
            public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {
                changeScheduleNumberScrollBarAdjustmentValueChanged(evt);
            }
        });

        scheduleViewerArea.setEditable(false);
        scheduleViewerArea.setColumns(20);
        scheduleViewerArea.setRows(5);
        jScrollPane1.setViewportView(scheduleViewerArea);

        jLabel1.setText("Solution number");

        textSolutionNumber.setText("0");

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(changeScheduleNumberScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(textSolutionNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 1166, Short.MAX_VALUE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(textSolutionNumber))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(changeScheduleNumberScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, 900, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 900, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE))
        );

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

    private void changeScheduleNumberScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_changeScheduleNumberScrollBarAdjustmentValueChanged
        // TODO add your handling code here:
        int scrollBarValue = evt.getValue();
        textSolutionNumber.setText(String.valueOf(scrollBarValue));
        refreshScheduleText(scrollBarValue);
    }//GEN-LAST:event_changeScheduleNumberScrollBarAdjustmentValueChanged

    private void refreshScheduleText(int scrollBarValue) {
        StringBuilder sbuf = new StringBuilder();

        String formattedInitialScedulesArray = ScheduleUtil.PrintSchedules.getFormattedSchedule(bankRecoveredSchedulesOrderedByMeanCost.get(scrollBarValue-1).initialSchedulesArray);
        sbuf.append(formattedInitialScedulesArray);
        sbuf.append(String.format("%s" + "%.2f","Mean Cost of Recovered Schedules : $", bankRecoveredSchedulesOrderedByMeanCost.get(scrollBarValue-1).meanCostRecoveredSimulations));
        scheduleViewerArea.setText(sbuf.toString());
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollBar changeScheduleNumberScrollBar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTextArea scheduleViewerArea;
    private javax.swing.JLabel textSolutionNumber;
    // End of variables declaration//GEN-END:variables
}
