/*
 * 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 java.util.List;

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

    private final List<ScheduleUtil.SchedulesArray> schedulesArrayList;
    private final String title;
    /**
     * Creates new form ShowSchedulesFrame 
    **/
    public ShowSchedulesFrame(List<ScheduleUtil.SchedulesArray> schedulesArrayList, String title) {
        this.schedulesArrayList = schedulesArrayList;
        this.title = title;
        initComponents();
        init();
    }
    
    private void init() {
        setTitle(title);
        setVisible(true);
        changeScheduleNumberScrollBar.setMinimum(1);
        int numberOfSchedules = this.schedulesArrayList.size();
        changeScheduleNumberScrollBar.setMaximum(numberOfSchedules);
        changeScheduleNumberScrollBar.setBlockIncrement(1);
        changeScheduleNumberScrollBar.setVisibleAmount(0);
        changeScheduleNumberScrollBar.setUnitIncrement(1);
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

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

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        changeScheduleNumberScrollBar.addAdjustmentListener(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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .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))
                    .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, javax.swing.GroupLayout.PREFERRED_SIZE, 1240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .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, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
                    .addComponent(changeScheduleNumberScrollBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .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.PREFERRED_SIZE, 1283, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 532, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        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) {
        scheduleViewerArea.setText(ScheduleUtil.PrintSchedules.getFormattedSchedule(schedulesArrayList.get(scrollBarValue-1)));
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollBar changeScheduleNumberScrollBar;
    private javax.swing.JTextArea scheduleViewerArea;
    private javax.swing.JLabel textSolutionNumber;
    // End of variables declaration//GEN-END:variables
}
