/*
 * Copyright 2015 Felipe Santos <live.proto at hotmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package proto.cederj.prownloader.mvp.view.swing;

import java.util.ArrayList;
import java.util.List;
import proto.cederj.prownloader.mvp.view.LessonView;
import proto.cederj.prownloader.mvp.view.MainView;

/**
 *
 * @author Felipe Santos <live.proto at hotmail.com>
 */
public class LessonPanelSwing extends javax.swing.JPanel implements LessonView {

    private long modelId;
    private MainView mainView;

    /**
     * Creates new form Course
     */
    public LessonPanelSwing(MainView view) {
        this.mainView = view;
        initComponents();
    }

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

        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        labelLessonTitle = new javax.swing.JLabel();
        labelDuration = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        labelProfessors = new javax.swing.JLabel();
        btnDownloadVideo = new javax.swing.JButton();
        btnPlayVideo = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        labelFilename = new javax.swing.JLabel();
        labelResolution = new javax.swing.JLabel();
        labelAspectRatio = new javax.swing.JLabel();
        labelBitrate = new javax.swing.JLabel();

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel6.setText("professor_list");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][]{
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                },
                new String[]{
                    "Title 1", "Title 2", "Title 3", "Title 4"
                }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
        );

        setPreferredSize(new java.awt.Dimension(500, 300));

        //labelLessonTitle.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        labelLessonTitle.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        labelLessonTitle.setText("Título da aula");

        //labelDuration.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelDuration.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        labelDuration.setText("tempo da aula");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("Professores");

        //labelProfessors.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelProfessors.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        labelProfessors.setText("Fulano, Ciclano, Beltrano");

        btnDownloadVideo.setText("Baixar vídeo");
        btnDownloadVideo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onDownloadVideo(evt);
            }
        });

        btnPlayVideo.setText("Assistir vídeo-aula");
        btnPlayVideo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onPlayVideo(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel5.setText("Informações sobre o vídeo");

        jLabel7.setText("arquivo:");

        jLabel8.setText("resolução:");

        jLabel9.setText("formato:");

        jLabel10.setText("bitrate:");

        labelFilename.setText("file.mp4");

        labelResolution.setText("320x240");

        labelAspectRatio.setText("4:3");

        labelBitrate.setText("100");

        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.TRAILING)
                                .addComponent(jLabel8)
                                .addComponent(jLabel7)
                                .addComponent(jLabel9)
                                .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(labelFilename)
                                .addComponent(labelResolution)
                                .addComponent(labelAspectRatio)
                                .addComponent(labelBitrate))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel7)
                                .addComponent(labelFilename))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8)
                                .addComponent(labelResolution))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel9)
                                .addComponent(labelAspectRatio))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10)
                                .addComponent(labelBitrate))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(labelLessonTitle)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE)
                                        .addComponent(labelDuration)
                                        .addGap(31, 31, 31))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addContainerGap())
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(24, 24, 24)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(labelProfessors)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                                .addComponent(btnPlayVideo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                .addComponent(btnDownloadVideo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addContainerGap())))))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(labelDuration)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(labelLessonTitle)
                                        .addGap(38, 38, 38)
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(labelProfessors)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(btnDownloadVideo)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(btnPlayVideo)
                                        .addGap(34, 34, 34))
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void onDownloadVideo(java.awt.event.ActionEvent evt) {
        mainView.onDownloadLessonVideoFile(modelId);
    }
    
    private void onPlayVideo(java.awt.event.ActionEvent evt) {
        mainView.onPlayVideo(modelId);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDownloadVideo;
    private javax.swing.JButton btnPlayVideo;
    private javax.swing.JLabel labelLessonTitle;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel labelFilename;
    private javax.swing.JLabel labelResolution;
    private javax.swing.JLabel labelAspectRatio;
    private javax.swing.JLabel labelBitrate;
    private javax.swing.JLabel labelDuration;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel labelProfessors;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setLessonId(long id) {
        modelId = id;
    }

    @Override
    public void setLessonTitle(String title) {
        labelLessonTitle.setText(title);
    }

    @Override
    public void setLessonDescription(String description) {
    }

    @Override
    public void setLessonProfessors(List<String> professors) {
        if (professors != null && !professors.isEmpty()) {
            StringBuilder builder = new StringBuilder();
            List<String> pro = new ArrayList<>(professors);
            builder.append(pro.remove(0));
            for (String s : pro) {
                builder.append(", ");
                builder.append(s);
            }
            labelProfessors.setText(builder.toString());
        }
    }

    @Override
    public void setLessonVideoFilename(String filename) {
        labelFilename.setText(filename);
    }

    @Override
    public void setLessonVideoResolution(String resolution) {
        labelResolution.setText(resolution);
    }

    @Override
    public void setLessonVideoAspectRatio(String aspectRatio) {
        labelAspectRatio.setText(aspectRatio);
    }

    @Override
    public void setLessonVideoBitrate(String bitrate) {
        labelBitrate.setText(bitrate);
    }

    @Override
    public void setLessonVideoDuration(String duration) {
        labelDuration.setText(duration);
    }
}
