/*! Copyright (C) 2009 Apertus, All Rights Reserved *! Author : Apertus Team -----------------------------------------------------------------------------** *! *! This program is free software: you can redistribute it and/or modify *! it under the terms of the GNU General Public License as published by *! the Free Software Foundation, either version 3 of the License, or *! (at your option) any later version. *! *! This program is distributed in the hope that it will be useful, *! but WITHOUT ANY WARRANTY; without even the implied warranty of *! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *! GNU General Public License for more details. *! *! You should have received a copy of the GNU General Public License *! along with this program. If not, see <http://www.gnu.org/licenses/>. *! -----------------------------------------------------------------------------**/ import java.awt.Color; import java.awt.Component; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractListModel; import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; public class PlaybackLayout extends javax.swing.JPanel { private class VideoFileListModel extends AbstractListModel { private ArrayList<VideoFile> VideoFilesList; VideoFileListModel() { VideoFilesList = new ArrayList<VideoFile>(); /*VideoFile test; test = new VideoFile(); test.setName("test1"); VideoFilesList.add(test);*/ } public int getSize() { return VideoFilesList.size(); } public Object getElementAt(int i) { return VideoFilesList.get(i).getName(); } public Object getVideoFileAt(int i) { return VideoFilesList.get(i); } private void clear() { VideoFilesList.clear(); } private void addElement(VideoFile file) { VideoFilesList.add(file); int index = VideoFilesList.indexOf(file); fireContentsChanged(this, index, index); } } class VideoListCellRenderer extends JLabel implements ListCellRenderer { protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer(); public VideoListCellRenderer() { // Don't paint behind the component setOpaque(true); } // Set the attributes of the //class and return a reference public Component getListCellRendererComponent(JList list, Object value, // value to display int index, // cell index boolean iss, // is selected boolean chf) // cell has focus? { //JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, iss, chf); // Set the text and //background color for rendering setText((String) value); setBackground(Color.WHITE); // Set a border if the //list item is selected if (iss) { setBackground(new Color(186, 206, 244, 100)); } else { setBackground(Color.WHITE); } return this; } } ElphelVision Parent; private VideoFileListModel videoFileListModel; private VideoListCellRenderer CellRenderer; public PlaybackLayout(ElphelVision parent) { Parent = parent; videoFileListModel = new VideoFileListModel(); CellRenderer = new VideoListCellRenderer(); try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); bg.setBackground(Parent.Settings.GetPanelBackgroundColor()); } }); } catch (InterruptedException ex) { Logger.getLogger(PlaybackLayout.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(PlaybackLayout.class.getName()).log(Level.SEVERE, null, ex); } } public void Load() { Parent.VLCPlayer.SetCanvas(vlcoverlay); } /** This method is called from within the init() method 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() { bg = new javax.swing.JPanel(); VideoFrame = new javax.swing.JPanel(); vlcoverlay = new java.awt.Canvas(); SettingsCancelButton = new EButton(Parent); eButton1 = new EButton(Parent); ListFiles = new EButton(Parent); jScrollPane1 = new javax.swing.JScrollPane(); FilesList = new javax.swing.JList(); bg.setBackground(new java.awt.Color(0, 0, 0)); bg.setPreferredSize(new java.awt.Dimension(1024, 600)); VideoFrame.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(100, 100, 100))); vlcoverlay.setBackground(java.awt.Color.darkGray); vlcoverlay.setForeground(new java.awt.Color(153, 65, 65)); javax.swing.GroupLayout VideoFrameLayout = new javax.swing.GroupLayout(VideoFrame); VideoFrame.setLayout(VideoFrameLayout); VideoFrameLayout.setHorizontalGroup( VideoFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(vlcoverlay, javax.swing.GroupLayout.DEFAULT_SIZE, 750, Short.MAX_VALUE) ); VideoFrameLayout.setVerticalGroup( VideoFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(vlcoverlay, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE) ); SettingsCancelButton.setText("Close"); SettingsCancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SettingsCancelButtonActionPerformed(evt); } }); eButton1.setText("Play"); eButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { eButton1ActionPerformed(evt); } }); ListFiles.setText("list"); ListFiles.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ListFilesActionPerformed(evt); } }); FilesList.setModel(videoFileListModel); FilesList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); FilesList.setCellRenderer(CellRenderer); jScrollPane1.setViewportView(FilesList); javax.swing.GroupLayout bgLayout = new javax.swing.GroupLayout(bg); bg.setLayout(bgLayout); bgLayout.setHorizontalGroup( bgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, bgLayout.createSequentialGroup() .addContainerGap() .addGroup(bgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(ListFiles, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(bgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(bgLayout.createSequentialGroup() .addComponent(eButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(SettingsCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(VideoFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); bgLayout.setVerticalGroup( bgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, bgLayout.createSequentialGroup() .addContainerGap() .addGroup(bgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE) .addComponent(VideoFrame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(bgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(SettingsCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(eButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ListFiles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(bg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(bg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); }// </editor-fold>//GEN-END:initComponents private void SettingsCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SettingsCancelButtonActionPerformed Parent.StopVideoPlayer(); Parent.LoadMainCard(); }//GEN-LAST:event_SettingsCancelButtonActionPerformed private void eButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eButton1ActionPerformed if (Parent.Settings.GetVideoPlayer() == streamVideoPlayer.VLC) { Parent.VLCPlayer.PlayVideoFile("/hdd/" + ((VideoFile) videoFileListModel.getVideoFileAt(FilesList.getSelectedIndex())).getPath()); } }//GEN-LAST:event_eButton1ActionPerformed private void UpdateFilesList() { videoFileListModel.clear(); for (int i = 0; i < Parent.Camera.GetVideoFilesList().size(); i++) { videoFileListModel.addElement(((VideoFile) (Parent.Camera.GetVideoFilesList().get(i)))); } } private void ListFilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ListFilesActionPerformed try { Parent.Camera.ReadCameraFileList(); } catch (Exception ex) { Logger.getLogger(PlaybackLayout.class.getName()).log(Level.SEVERE, null, ex); } UpdateFilesList(); }//GEN-LAST:event_ListFilesActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JList FilesList; private EButton ListFiles; private EButton SettingsCancelButton; private javax.swing.JPanel VideoFrame; private javax.swing.JPanel bg; private EButton eButton1; private javax.swing.JScrollPane jScrollPane1; private java.awt.Canvas vlcoverlay; // End of variables declaration//GEN-END:variables }