ropes.MainWindow.java Source code

Java tutorial

Introduction

Here is the source code for ropes.MainWindow.java

Source

/*
 * 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 ropes;

import com.sun.jmx.snmp.BerDecoder;
import de.tu_darmstadt.informatik.rbg.hatlak.iso9660.ISO9660Directory;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import org.apache.commons.codec.binary.Hex;
import ropes.SystemInfo.MediaInfo;

/**
 *
 * @author Urban
 */
public class MainWindow extends javax.swing.JFrame {

    /**
     * Creates new form MainWindow
     */

    private int privMediaSelection;
    private String workingDir = System.getProperty("user.dir") + "\\Ropes\\";
    private Boolean cdromSelected = false;
    private Map<String, MediaInfo> drives = null;
    String initIv = "";
    String salt = "";

    public MainWindow() {
        initComponents();
        //initilize media drives
        SystemInfo info = new SystemInfo();
        drives = info.getMediaDrives();

    }

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

        jFrame1 = new javax.swing.JFrame();
        buttonGroup_store_size_select = new javax.swing.ButtonGroup();
        buttonGroup_store_retrive = new javax.swing.ButtonGroup();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jComboBox_media = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jRadioButton_allSpace = new javax.swing.JRadioButton();
        jRadioButton_partSpace = new javax.swing.JRadioButton();
        jSlider_size_select = new javax.swing.JSlider();
        jRadioButton_store = new javax.swing.JRadioButton();
        jRadioButton_retrive = new javax.swing.JRadioButton();
        jButton_write = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel3 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton_changePath = new javax.swing.JButton();
        jButton_clear_fileList = new javax.swing.JButton();
        jPasswordField_master_password = new javax.swing.JPasswordField();
        jCheckBox_showPassword = new javax.swing.JCheckBox();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTree_fileList = new javax.swing.JTree();
        jButton4 = new javax.swing.JButton();
        jButton_about = new javax.swing.JButton();
        jLabel_path = new javax.swing.JLabel();
        jButton_test = new javax.swing.JButton();
        jTextField_sliderValue = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(jFrame1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE));
        jFrame1Layout.setVerticalGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE));

        jScrollPane2.setViewportView(jTree1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Ropes - Robust Offline Physical Encrypted Storage");
        setName("MainWindow"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jButton1.setText("Close");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Master Password");

        jComboBox_media.setName("select_media_cmb"); // NOI18N
        jComboBox_media.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_mediaActionPerformed(evt);
            }
        });

        jLabel1.setText("Choose Media");
        jLabel1.setName(""); // NOI18N

        buttonGroup_store_size_select.add(jRadioButton_allSpace);
        jRadioButton_allSpace.setSelected(true);
        jRadioButton_allSpace.setText("Fill all avalible space");
        jRadioButton_allSpace.setName("all_space_radio"); // NOI18N
        jRadioButton_allSpace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton_allSpaceActionPerformed(evt);
            }
        });

        buttonGroup_store_size_select.add(jRadioButton_partSpace);
        jRadioButton_partSpace.setText("Set storage space");
        jRadioButton_partSpace.setMaximumSize(new java.awt.Dimension(121, 23));
        jRadioButton_partSpace.setName("some_space_radio"); // NOI18N
        jRadioButton_partSpace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton_partSpaceActionPerformed(evt);
            }
        });

        jSlider_size_select.setMajorTickSpacing(100);
        jSlider_size_select.setMaximum(1000);
        jSlider_size_select.setMinorTickSpacing(1);
        jSlider_size_select.setPaintTicks(true);
        jSlider_size_select.setToolTipText("");
        jSlider_size_select.setValue(0);
        jSlider_size_select.setEnabled(false);
        jSlider_size_select.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSlider_size_selectStateChanged(evt);
            }
        });

        buttonGroup_store_retrive.add(jRadioButton_store);
        jRadioButton_store.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jRadioButton_store.setSelected(true);
        jRadioButton_store.setText("store");

        buttonGroup_store_retrive.add(jRadioButton_retrive);
        jRadioButton_retrive.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jRadioButton_retrive.setText("retrive");

        jButton_write.setText("write");
        jButton_write.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_writeActionPerformed(evt);
            }
        });

        jLabel3.setText("Files for storage");

        jButton3.setText("Add file");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton_changePath.setText("Change Path");
        jButton_changePath.setActionCommand("Setpath");
        jButton_changePath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_changePathActionPerformed(evt);
            }
        });

        jButton_clear_fileList.setText("Clear");
        jButton_clear_fileList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_clear_fileListActionPerformed(evt);
            }
        });

        jCheckBox_showPassword.setText("Show Password");
        jCheckBox_showPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_showPasswordActionPerformed(evt);
            }
        });

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("JTree");
        jTree_fileList.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane3.setViewportView(jTree_fileList);

        jButton4.setText("Delete item");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton_about.setText("About");
        jButton_about.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_aboutActionPerformed(evt);
            }
        });

        jLabel_path.setToolTipText("");
        jLabel_path.setMaximumSize(new java.awt.Dimension(231, 14));
        jLabel_path.setMinimumSize(new java.awt.Dimension(22, 22));

        jButton_test.setText("test");
        jButton_test.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_testActionPerformed(evt);
            }
        });

        jTextField_sliderValue.setEnabled(false);
        jTextField_sliderValue.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField_sliderValueKeyReleased(evt);
            }

            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField_sliderValueKeyTyped(evt);
            }
        });

        jLabel4.setText("MB");

        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(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup().addComponent(jButton3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton_clear_fileList))
                                .addComponent(jProgressBar1, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        layout.createSequentialGroup()
                                                .addComponent(jLabel_path, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        231, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, Short.MAX_VALUE).addComponent(jButton_changePath)
                                                .addGap(9, 9, 9))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton_about, javax.swing.GroupLayout.PREFERRED_SIZE, 89,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(
                                                jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 89,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addComponent(jLabel1)
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jComboBox_media,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGroup(layout.createSequentialGroup().addGap(17, 17, 17)
                                                                .addComponent(jRadioButton_store,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(10, 10, 10)
                                                                .addComponent(jRadioButton_retrive,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                                        .addGroup(layout.createSequentialGroup().addComponent(jRadioButton_allSpace)
                                                .addGap(18, 18, 18)
                                                .addComponent(jTextField_sliderValue,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 62,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel4))
                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel2).addComponent(jLabel3)).addGap(18, 18, 18)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jPasswordField_master_password,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 187,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jCheckBox_showPassword))))
                                        .addGap(0, 0, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jRadioButton_partSpace,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18).addComponent(jSlider_size_select,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap())
                .addGroup(
                        layout.createSequentialGroup().addGap(5, 5, 5).addComponent(jButton_test).addGap(18, 18, 18)
                                .addComponent(jButton_write, javax.swing.GroupLayout.PREFERRED_SIZE, 176,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(5, 5, 5)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jRadioButton_retrive, javax.swing.GroupLayout.DEFAULT_SIZE, 34,
                                        Short.MAX_VALUE)
                                .addComponent(jRadioButton_store, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jComboBox_media, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1)).addGap(2, 2, 2)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jButton_changePath).addComponent(jLabel_path,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel2).addComponent(jPasswordField_master_password,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup().addGap(19, 19, 19)
                                                        .addComponent(jLabel3))
                                                .addGroup(layout.createSequentialGroup()
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jCheckBox_showPassword)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 97,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jButton3).addComponent(jButton_clear_fileList)
                                                .addComponent(jButton4))
                                        .addGap(27, 27, 27)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jRadioButton_allSpace)
                                                .addComponent(jTextField_sliderValue,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel4))
                                        .addGap(6, 6, 6)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jSlider_size_select,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jRadioButton_partSpace,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18).addComponent(jButton_write,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 62,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jButton_test))
                        .addGap(52, 52, 52)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton_about, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)));

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

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        //TODO display loader animation while liberys are loading
        DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

        final JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.setMultiSelectionEnabled(true);

        int returnVal = fc.showOpenDialog(MainWindow.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File[] files = fc.getSelectedFiles();
            for (File file : files) {

                if (file.isFile()) {
                    addFileToList(file);
                } else if (file.isDirectory()) {
                    //adds the parent to tree
                    root.add(new DefaultMutableTreeNode(file));
                    //adds all the subfolders and files to the parent
                    addFileRecursive(file.toString());

                }

            }

        }

    }//GEN-LAST:event_jButton3ActionPerformed

    private void addFileToList(File path) {
        DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        //get perent directory to see if such node exist
        File perentDir = path.getParentFile();

        DefaultMutableTreeNode node = findNode(root, perentDir.toString());
        if (node != null)
            node.add(new DefaultMutableTreeNode(path));
        else {
            root.add(new DefaultMutableTreeNode(path));
        }
        //update jtree
        model.reload(root);

    }

    private DefaultMutableTreeNode findNode(DefaultMutableTreeNode root, String s) {
        //reutrn node if exist in jtree
        @SuppressWarnings("unchecked")
        Enumeration<DefaultMutableTreeNode> e = root.depthFirstEnumeration();
        while (e.hasMoreElements()) {
            DefaultMutableTreeNode node = e.nextElement();
            if (node.toString().equalsIgnoreCase(s)) {
                return node;
            }
        }
        return null;
    }

    private void addFileRecursive(String rootDir) {
        File[] faFiles = new File(rootDir).listFiles();
        for (File file : faFiles) {
            if (file.getName().matches("^(.*?)")) {
                addFileToList(file);//.getAbsolutePath().toString());
            }
            if (file.isDirectory()) {
                addFileRecursive(file.getAbsolutePath());
            }
        }
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

        for (Map.Entry<String, MediaInfo> drive : drives.entrySet()) {

            jComboBox_media.addItem(drive.getKey() + "  -  " + drive.getValue().description);
        }
        //set some controll values
        jTree_fileList.setRootVisible(false);
        jTree_fileList.setShowsRootHandles(true);

    }//GEN-LAST:event_formWindowOpened

    private void jComboBox_mediaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_mediaActionPerformed

        //reset controlls
        jSlider_size_select.setValue(0);
        jTextField_sliderValue.setText("0");

        //gets the string of the meda drivev selected
        String selected = getSelectedPathFromCMB();
        //turn flag on if CD Rom selected

        //get avalible space of selected drive
        MediaInfo mi = (MediaInfo) drives.get(selected);
        jSlider_size_select.setMaximum(mi.freeSpace);
        jLabel_path.setText(mi.path);

        if (mi.description.contains("CD Drive")) {
            cdromSelected = true;
            cdRomMode();
        } else {
            cdromSelected = false;
            normalMode();
        }

        if (!cdromSelected) {
            //Create the label table
            Hashtable labelTable = new Hashtable();
            labelTable.put(new Integer(0), new JLabel("0 Mb"));
            labelTable.put(new Integer(mi.freeSpace), new JLabel(String.valueOf(mi.freeSpace) + " Mb"));
            jSlider_size_select.setLabelTable(labelTable);
            jSlider_size_select.setPaintLabels(true);
        }

        //remember last select
        privMediaSelection = jComboBox_media.getSelectedIndex();
    }//GEN-LAST:event_jComboBox_mediaActionPerformed

    private void cdRomMode() {
        SystemInfo si = new SystemInfo();

        jButton_write.setText("Create ISO");
        jRadioButton_allSpace.setEnabled(false);
        jRadioButton_partSpace.setSelected(true);
        jTextField_sliderValue.setEnabled(true);
        jSlider_size_select.setEnabled(true);

        //Create the label table

        Integer dvdValMB = si.getFreeSpaceMB(new Long("4294967295")); //(2^32 -1) max dvd size

        //map logoritmic sacale to jslider so everything will fit

        jSlider_size_select.setMaximum(1400); //log10(4096) = 3.612

        Hashtable labelTable = new Hashtable();
        labelTable.put(new Integer(0), new JLabel("0 Mb"));
        labelTable.put(new Integer(730), new JLabel("CD 700Mb"));
        labelTable.put(new Integer(dvdValMB), new JLabel("DVD 4.2 GB"));
        jSlider_size_select.setLabelTable(labelTable);
        jSlider_size_select.setPaintLabels(true);
        jSlider_size_select.setSnapToTicks(true);

    }

    private void normalMode() {
        jButton_write.setText("Write");
        jRadioButton_allSpace.setEnabled(true);
        jRadioButton_allSpace.setSelected(true);
        jTextField_sliderValue.setEnabled(true);
        jTextField_sliderValue.setEnabled(false);
    }

    private String getSelectedPathFromCMB() {
        return jComboBox_media.getSelectedItem().toString().split(" - ")[0].trim();//replaceAll("\\s+","");
    }

    private void jRadioButton_partSpaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton_partSpaceActionPerformed
        jSlider_size_select.setEnabled(true);
        jTextField_sliderValue.setEnabled(true);
    }//GEN-LAST:event_jRadioButton_partSpaceActionPerformed

    private void jRadioButton_allSpaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton_allSpaceActionPerformed
        jSlider_size_select.setEnabled(false);
        jTextField_sliderValue.setEnabled(false);

    }//GEN-LAST:event_jRadioButton_allSpaceActionPerformed

    private void jSlider_size_selectStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider_size_selectStateChanged
        jTextField_sliderValue.setText(String.valueOf(jSlider_size_select.getValue()));
    }//GEN-LAST:event_jSlider_size_selectStateChanged

    private void jCheckBox_showPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_showPasswordActionPerformed
        if (jCheckBox_showPassword.isSelected()) {
            jPasswordField_master_password.setEchoChar((char) 0);
        } else {
            jPasswordField_master_password.setEchoChar('*');
        }
    }//GEN-LAST:event_jCheckBox_showPasswordActionPerformed

    private void jButton_aboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_aboutActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton_aboutActionPerformed

    private void jButton_changePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_changePathActionPerformed
        final JFileChooser fc = new JFileChooser(getSelectedPathFromCMB());
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(MainWindow.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            Path p = Paths.get(file.toString());
            //if root is changed via the change path botton, then also change to the right media in the combobox
            if (!p.getRoot().toString().equals(getSelectedPathFromCMB())) {
                for (int i = 0; i < jComboBox_media.getItemCount(); i++) {
                    if (jComboBox_media.getItemAt(i).toString().contains(p.getRoot().toString())) {
                        jComboBox_media.setSelectedIndex(i);
                        break;
                    }
                }
            }

            jLabel_path.setText(file.toString());
        }

    }//GEN-LAST:event_jButton_changePathActionPerformed

    private void jButton_clear_fileListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_clear_fileListActionPerformed
        DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        root.removeAllChildren(); //this removes all nodes
        model.reload(); //this notifies the listeners and changes the GUI
    }//GEN-LAST:event_jButton_clear_fileListActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        DefaultTreeModel model = (DefaultTreeModel) jTree_fileList.getModel();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree_fileList.getLastSelectedPathComponent();
        //DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        // TreePath parent_node = null; 
        if (node != null) {
            // parent_node = new TreePath(node.getParent());
            node.removeFromParent();

        } else {
            JOptionPane.showMessageDialog(this, "Please select an item first", "Error", JOptionPane.ERROR_MESSAGE);
        }
        model.reload();

        //TODO expand jtree after removing of a node

    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton_writeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_writeActionPerformed

        String storeSpace_option = null;
        File encrypted_file = null;
        List<File> files = new ArrayList<File>();

        if (!validateFileds()) {
            JOptionPane.showMessageDialog(this, "Some fileds are invalid", "Error", JOptionPane.WARNING_MESSAGE);
            return;
        }

        if (jRadioButton_allSpace.isSelected()) {
            storeSpace_option = "all avalible space";
        } else {
            storeSpace_option = String.valueOf(jSlider_size_select.getValue()) + " Mb of space";
        }

        int dialogResult = JOptionPane
                .showConfirmDialog(null,
                        "Are you sure you want to fill\n" + storeSpace_option + " at the media you selected:\n"
                                + jComboBox_media.getSelectedItem().toString(),
                        "Warning", JOptionPane.YES_NO_OPTION);
        if (dialogResult == JOptionPane.YES_OPTION) {
            //get all added files and perent directories 
            DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) jTree_fileList.getModel().getRoot();
            int chiledCount = rootNode.getChildCount();
            for (int i = 0; i < chiledCount; i++) {
                String path = jTree_fileList.getModel().getChild(rootNode, i).toString();
                files.add(new File(path));
                System.out.println(path);
            }
            if (validateFileds()) {
                encrypted_file = compressAndEncrypt(String.valueOf(jPasswordField_master_password.getPassword()),
                        files);
            } else {
                System.err.println("some fields are invalid");
                return;
            }

            Double size_select_bytes = jSlider_size_select.getValue() * Math.pow(1024, 2);
            Long size_select = size_select_bytes.longValue();
            if (encrypted_file.exists()) {
                Long fileSize = encrypted_file.length();
                if (jRadioButton_allSpace.isSelected()) {
                    size_select_bytes = jSlider_size_select.getMaximum() * Math.pow(1024, 2);
                    createIso(encrypted_file, size_select_bytes.longValue(), initIv, salt);
                } else if (size_select > 0 && size_select > fileSize)
                    createIso(encrypted_file, size_select, initIv, salt);
            }

        }

    }

    private Boolean validateFileds() {

        return true;
    }

    private File compressAndEncrypt(String password, List<File> inFiles) {
        File archivePath = new File(workingDir + "archive.zip");
        File encryptPath = new File(workingDir + archivePath.getName() + ".aes");
        //initilize compression class
        FileCompressor fCompress = new FileCompressor(archivePath);
        //preforming compression
        for (File file : inFiles) {
            fCompress.compressZipFile(file, "");
        }
        try {
            //close output stream
            fCompress.zos.close();
        } catch (IOException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("file compression, done: " + archivePath);
        //initilize cypto class
        Crypto crypt = new Crypto(password);
        crypt.setupEncrypt();
        //store IV and salt for decryption
        initIv = Hex.encodeHexString(crypt.getInitVec());
        salt = Hex.encodeHexString(crypt.getSalt());

        //encrypy out created archive
        crypt.WriteEncryptedFile(archivePath, encryptPath);
        System.out.println("file encryption, done: " + encryptPath);
        return encryptPath;

    }//GEN-LAST:event_jButton_writeActionPerformed

    private void createIso(File file, Long size, String initIV, String salt) {
        IsoCreator ic = new IsoCreator();
        String timeStamp = new SimpleDateFormat("dd/MM/yyyy_HH:mm:ss").format(Calendar.getInstance().getTime());
        //temp solution, untill iv and salt will be incorporated into the file itself
        PrintWriter writer = null;
        try {
            writer = new PrintWriter(new File(workingDir + "info.txt"), "UTF-8");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
        writer.println(initIV);
        writer.println(salt);
        writer.println("created on: " + timeStamp);
        writer.close();

        Long numOfFiles = size / file.length();
        System.out.println("creating ISO file...");
        System.out.println(numOfFiles.toString() + " number of copies will be created");

        jProgressBar1.setMaximum(numOfFiles.intValue());
        ic.addFiles(file, numOfFiles);

        ic.createISO(new File(workingDir + "Disc.iso"));
    }

    private void jButton_testActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_testActionPerformed

    }//GEN-LAST:event_jButton_testActionPerformed

    private void jTextField_sliderValueKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField_sliderValueKeyTyped
        char c = evt.getKeyChar();
        String txtVal = jTextField_sliderValue.getText();
        if (txtVal.equals("") && (c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)) {
            evt.consume();
            return;
        }
        if (!"".equals(txtVal)) {
            if (!(Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)
                    || jSlider_size_select.getMaximum() <= Integer.valueOf(txtVal)) {
                evt.consume();
            } else {

                if (Integer.valueOf(txtVal) == 0)
                    jTextField_sliderValue.setText("");
            }
        }

        //Integer textFieldVal = Integer.valueOf(jTextField_sliderValue.getText());
        // jSlider_size_select.setValue(WIDTH);
    }//GEN-LAST:event_jTextField_sliderValueKeyTyped

    private void jTextField_sliderValueKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField_sliderValueKeyReleased
        JTextField txt = (JTextField) evt.getSource();
        if (txt.getText().equals("")) {
            txt.setText("0");
            return;
        }
        jSlider_size_select.setValue(Integer.valueOf(txt.getText()));
    }//GEN-LAST:event_jTextField_sliderValueKeyReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup_store_retrive;
    private javax.swing.ButtonGroup buttonGroup_store_size_select;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton_about;
    private javax.swing.JButton jButton_changePath;
    private javax.swing.JButton jButton_clear_fileList;
    private javax.swing.JButton jButton_test;
    private javax.swing.JButton jButton_write;
    private javax.swing.JCheckBox jCheckBox_showPassword;
    private javax.swing.JComboBox jComboBox_media;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel_path;
    private javax.swing.JPasswordField jPasswordField_master_password;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JRadioButton jRadioButton_allSpace;
    private javax.swing.JRadioButton jRadioButton_partSpace;
    private javax.swing.JRadioButton jRadioButton_retrive;
    private javax.swing.JRadioButton jRadioButton_store;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSlider jSlider_size_select;
    private javax.swing.JTextField jTextField_sliderValue;
    private javax.swing.JTree jTree1;
    private javax.swing.JTree jTree_fileList;
    // End of variables declaration//GEN-END:variables
}