imageuploader.ImgWindow.java Source code

Java tutorial

Introduction

Here is the source code for imageuploader.ImgWindow.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 imageuploader;

import com.jscape.inet.ftp.FtpException;
import it.sauronsoftware.ftp4j.FTPException;
import it.sauronsoftware.ftp4j.FTPIllegalReplyException;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.nio.file.StandardCopyOption;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.event.ListDataListener;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPHTTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
import org.apache.commons.net.io.CopyStreamEvent;
import org.apache.commons.net.io.CopyStreamListener;
import org.apache.commons.net.util.TrustManagerUtils;

/**
 *
 * @author dturcios
 */
public class ImgWindow extends javax.swing.JFrame {

    /**
     * Creates new form ImgWindow
     */
    public ImgWindow() {
        initComponents();

        //list = new Vector();
        jCB_Colors.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
        setExplicitSelectionManager(jCB_Colors);
        eventCounter = 0;
    }

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

        jFC_Images = new javax.swing.JFileChooser();
        jD_Alert = new javax.swing.JDialog();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTF_StyleCode = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jCB_Colors = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jB_upload = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jL_Info = new javax.swing.JList();
        jB_Remove = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jCHBox_MY = new javax.swing.JCheckBox();
        jCHB_CA = new javax.swing.JCheckBox();
        jCHB_AZ = new javax.swing.JCheckBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMI_colorFile = new javax.swing.JMenuItem();
        jMenu6 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();

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

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        jScrollPane2.setViewportView(jList1);

        jMenu3.setText("File");
        jMenuBar2.add(jMenu3);

        jMenu4.setText("Edit");
        jMenuBar2.add(jMenu4);

        jMenu5.setText("jMenu5");

        jMenuItem2.setText("jMenuItem2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Myron Upload Images");
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Create Images");

        jLabel2.setText("Style Code");

        jLabel3.setText("Color");

        jCB_Colors.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Click in Edit-> Color File" }));
        jCB_Colors.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCB_ColorsActionPerformed(evt);
            }
        });

        jLabel4.setText("Upload Images");

        jB_upload.setText("Upload");
        jB_upload.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jB_uploadMouseClicked(evt);
            }
        });

        DefaultListModel listModel = new DefaultListModel();
        jL_Info.setModel(listModel);
        jScrollPane3.setViewportView(jL_Info);

        jB_Remove.setFont(new java.awt.Font("Tahoma", 1, 8)); // NOI18N
        jB_Remove.setText("-");
        jB_Remove.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jB_RemoveMouseClicked(evt);
            }
        });

        jLabel5.setText("Upload FTP");

        jCHBox_MY.setText("MY");

        jCHB_CA.setText("CA");

        jCHB_AZ.setText("AZ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(
                        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel1Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                                        .addComponent(jLabel1).addGap(69, 69, 69))
                                .addGroup(jPanel1Layout
                                        .createSequentialGroup().addGroup(jPanel1Layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(
                                                        jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 251,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jB_Remove,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 18,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(jPanel1Layout
                                                        .createSequentialGroup().addComponent(jLabel4).addGap(18,
                                                                18, 18)
                                                        .addComponent(jB_upload,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 145,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(jPanel1Layout.createSequentialGroup()
                                                        .addGroup(jPanel1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addGroup(jPanel1Layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                                        false)
                                                                        .addComponent(jLabel3,
                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                Short.MAX_VALUE)
                                                                        .addComponent(jLabel2,
                                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                Short.MAX_VALUE))
                                                                .addComponent(jLabel5))
                                                        .addGap(35, 35, 35)
                                                        .addGroup(jPanel1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                .addComponent(jCB_Colors,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 145,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jTF_StyleCode,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 145,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGroup(jPanel1Layout.createSequentialGroup()
                                                                        .addComponent(jCHBox_MY).addGap(18, 18, 18)
                                                                        .addComponent(jCHB_CA)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                Short.MAX_VALUE)
                                                                        .addComponent(jCHB_AZ)))))
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(jTF_StyleCode,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3).addComponent(jCB_Colors,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5).addComponent(jCHBox_MY).addComponent(jCHB_CA)
                                .addComponent(jCHB_AZ))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jB_upload, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jB_Remove, javax.swing.GroupLayout.PREFERRED_SIZE, 18,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)));

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMI_colorFile.setText("Color File");
        jMI_colorFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMI_colorFileMouseClicked(evt);
            }

            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jMI_colorFileMouseEntered(evt);
            }

            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMI_colorFileMousePressed(evt);
            }
        });
        jMenu2.add(jMI_colorFile);

        jMenuBar1.add(jMenu2);

        jMenu6.setText("FTP");

        jMenuItem3.setText("FTP Access");
        jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem3MouseClicked(evt);
            }

            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jMenuItem3MouseEntered(evt);
            }

            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem3MousePressed(evt);
            }
        });
        jMenu6.add(jMenuItem3);

        jMenuBar1.add(jMenu6);

        setJMenuBar(jMenuBar1);

        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().addComponent(jPanel1,
                        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().addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));

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

    private void jB_uploadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jB_uploadMouseClicked
        try {
            // TODO add your handling code here:
            DefaultListModel mod = (DefaultListModel) jL_Info.getModel();
            if (jTF_StyleCode.getText().length() <= 0 || jCB_Colors.getModel().getSize() <= 1
                    || mod.getSize() <= 0) {
                JOptionPane.showMessageDialog(rootPane, "Please insert the Stle Code and select the color");
            } else if (jCHB_CA.isSelected() || jCHBox_MY.isSelected()) {
                if (FtpCredentials.getInstancia().getUser() == null) {
                    JOptionPane.showMessageDialog(rootPane, "Please add the FTP Credentials");
                } else {
                    showDialog(0);
                    File[] files = jFC_Images.getSelectedFiles();
                    if (files.length == 0) {
                        JOptionPane.showMessageDialog(rootPane, "Please select one image");
                    } else {
                        generatedImages(jTF_StyleCode.getText(), files);
                    }
                }
            } else {
                showDialog(0);
                File[] files = jFC_Images.getSelectedFiles();
                if (files.length == 0) {
                    JOptionPane.showMessageDialog(rootPane, "Please select one image");
                } else {
                    generatedImages(jTF_StyleCode.getText(), files);
                }
            }

        } catch (IOException ex) {
            Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalStateException ex) {
            Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FTPIllegalReplyException ex) {
            Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FTPException ex) {
            Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FtpException ex) {
            Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jB_uploadMouseClicked

    private void jMI_colorFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMI_colorFileMouseClicked
        // TODO add your handling code here
    }//GEN-LAST:event_jMI_colorFileMouseClicked

    private void jMI_colorFileMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMI_colorFileMouseEntered
        // TODO add your handling code here:
        showDialog(1);
        File f = jFC_Images.getSelectedFile();
        try {
            fillCombo(f);
        } catch (IOException ex) {
            Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jMI_colorFileMouseEntered

    private void jMI_colorFileMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMI_colorFileMousePressed
        // TODO add your handling code here:
        showDialog(1);
        File f = jFC_Images.getSelectedFile();
        try {
            fillCombo(f);
        } catch (IOException ex) {
            Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jMI_colorFileMousePressed

    private void jCB_ColorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCB_ColorsActionPerformed
        // TODO add your handling code here:
        eventCounter++;

        if (evt.getActionCommand().equals("comboBoxChanged")) {

            if (jCB_Colors.getModel().getSize() > 0) {
                String a = jCB_Colors.getSelectedItem().toString();
                DefaultListModel listM = (DefaultListModel) jL_Info.getModel();

                if (eventCounter > 2) {

                    if (listM.contains(a) == false) {
                        listM.addElement(a);
                        // boolean add = list.add(jCB_Colors.getSelectedItem().toString());
                    }
                }

            }

        }

    }//GEN-LAST:event_jCB_ColorsActionPerformed

    private void jB_RemoveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jB_RemoveMouseClicked
        // TODO add your handling code here:
        if (jL_Info.getSelectedIndices().length == 0) {
            JOptionPane.showMessageDialog(rootPane, "Select a color to delete");
        } else {
            DefaultListModel mod = (DefaultListModel) jL_Info.getModel();
            if (jL_Info.getSelectedIndices().length == 1) {
                int[] a = jL_Info.getSelectedIndices();
                mod.removeElementAt(a[0]);
            } else {
                mod.removeAllElements();
            }
        }
    }//GEN-LAST:event_jB_RemoveMouseClicked

    private void jMenuItem3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MouseClicked
        // TODO add your handling code here:
        FtpAccess win = new FtpAccess();
        win.setVisible(true);
    }//GEN-LAST:event_jMenuItem3MouseClicked

    private void jMenuItem3MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem3MouseEntered

    private void jMenuItem3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MousePressed
        // TODO add your handling code here:
        FtpAccess win = new FtpAccess();
        win.setVisible(true);
    }//GEN-LAST:event_jMenuItem3MousePressed

    private void fillCombo(File f) throws FileNotFoundException, IOException {
        BufferedReader input = new BufferedReader(new FileReader(f));
        String line = null;
        Vector model = new Vector();
        Items it;
        jCB_Colors.removeAllItems();
        JList list = new JList();
        while ((line = input.readLine()) != null) {
            String[] result = line.split(",");
            jCB_Colors.addItem(new Items(result[0], result[1]));
        }
        //jtx_colorname.setText("");
        input.close();

    }

    private void showDialog(int display) {
        //display=0 for images || display=1 for txt files
        if (display == 0) {
            FileNameExtensionFilter imgFilter = new FileNameExtensionFilter("Image Files", "jpg", "jpeg");
            jFC_Images.setFileFilter(imgFilter);
            jFC_Images.setMultiSelectionEnabled(true);
            int showDialog = jFC_Images.showDialog(null, null);
        } else if (display == 1) {
            FileNameExtensionFilter imgFilter = new FileNameExtensionFilter("Text Files", "txt");
            jFC_Images.setFileFilter(imgFilter);
            int showDialog = jFC_Images.showDialog(null, null);
        }
    }

    private void generatedImages(String code, File[] files)
            throws IOException, IllegalStateException, FTPIllegalReplyException, FTPException, FtpException {

        int ubicacion;
        File directory = new File(code);
        ArrayList<File> imageList = new ArrayList();
        DefaultListModel mod = (DefaultListModel) jL_Info.getModel();
        if (!directory.exists()) {
            boolean result = directory.mkdir();
            if (!result) {
                JOptionPane.showMessageDialog(rootPane, "Directory -- Error");
            } else {
                File dir, img;
                boolean rst;
                FileChannel source = null;
                FileChannel dest = null;
                FtpCredentials.getInstancia().connect();
                for (int i = 0; i < files.length; i++) {

                    int val = 1 + i;
                    //Create the Angle directory
                    dir = new File(directory, "Angle" + val);
                    rst = dir.mkdir();

                    //Copy Images
                    //DefaultListModel mod = (DefaultListModel)jL_Info.getModel();

                    for (int j = 0; j < mod.getSize(); j++) {
                        img = new File(dir, code + "~" + mod.getElementAt(j).toString() + ".jpg");
                        rst = img.createNewFile();
                        imageList.add(img);
                        source = new RandomAccessFile(files[i], "rw").getChannel();
                        dest = new RandomAccessFile(img, "rw").getChannel();

                        long position = 0;
                        long count = source.size();
                        source.transferTo(position, count, dest);

                        if (source != null) {
                            source.close();
                        }
                        if (dest != null) {
                            dest.close();
                        }

                    }
                    ubicacion = i + 1;
                    /*Using the private library  */
                    if (jCHBox_MY.isSelected()) {
                        FtpCredentials.getInstancia().getClient().setDir("/Myron/angle" + ubicacion + "Flash");
                        FtpCredentials.getInstancia().copyImage(imageList);
                    }
                    if (jCHB_CA.isSelected()) {
                        FtpCredentials.getInstancia().getClient().setDir("/canada/angle" + ubicacion + "Flash");
                        FtpCredentials.getInstancia().copyImage(imageList);
                    }
                    if (jCHB_AZ.isSelected()) {
                        FtpCredentials.getInstancia().getClient().setDir("/australia/angle" + ubicacion + "Flash");
                        FtpCredentials.getInstancia().copyImage(imageList);
                    }
                    imageList.clear();

                }

                mod.removeAllElements();
                jTF_StyleCode.setText("");
                //jL_Info.removeAll();
                //list.removeAllElements();
                JOptionPane.showMessageDialog(rootPane, "Images uploaded");
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "There is a folder with the same name in the same location");
        }

    }

    private void setExplicitSelectionManager(JComboBox comboBox) {

        class ExplicitSelectionManager implements KeyListener, FocusListener {

            private JComboBox src;
            private KeyListener superKeyListener;

            ExplicitSelectionManager(JComboBox src) {
                this.src = src;

                //   we like what the default key listener does, but not the action command
                // it uses for ActionEvents it fires for plain text type-ahead characters
                this.superKeyListener = src.getKeyListeners()[0]; // we only have one
                src.removeKeyListener(superKeyListener); // will be replace right away, below
            }

            @Override
            public void keyTyped(KeyEvent e) {
                // basic combo box has no code in keyTyped
            }

            @Override
            public void keyPressed(KeyEvent e) {

                //   in the default JComboBox implementation, the KeySelectionManager is
                // called from keyPressed. I'm fine with the implementation of
                // the default, but I don't want it firing ActionEvents that will cause
                // model updates
                src.setActionCommand("comboBoxMovement");
                this.superKeyListener.keyPressed(e);
                src.setActionCommand("comboBoxChanged");

                if (e.getKeyCode() == 10) {
                    src.setSelectedIndex(src.getSelectedIndex());
                }
            }

            @Override
            public void keyReleased(KeyEvent e) {
                // basic combo box has no code in keyReleased
            }

            @Override
            public void focusGained(FocusEvent e) {
            }

            @Override
            //  this will also give us the event we want, if the user decides to Tab out of
            // the combo box, instead of hitting Enter
            public void focusLost(FocusEvent e) {
                src.setSelectedIndex(src.getSelectedIndex());
            }

        }

        ExplicitSelectionManager newSelectionManager = new ExplicitSelectionManager(comboBox);

        comboBox.addKeyListener(newSelectionManager);
        comboBox.addFocusListener(newSelectionManager);

    }

    /**
     * @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(ImgWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ImgWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ImgWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ImgWindow.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 ImgWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_Remove;
    private javax.swing.JButton jB_upload;
    private javax.swing.JComboBox jCB_Colors;
    private javax.swing.JCheckBox jCHB_AZ;
    private javax.swing.JCheckBox jCHB_CA;
    private javax.swing.JCheckBox jCHBox_MY;
    private javax.swing.JDialog jD_Alert;
    private javax.swing.JFileChooser jFC_Images;
    private javax.swing.JList jL_Info;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JList jList1;
    private javax.swing.JMenuItem jMI_colorFile;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField jTF_StyleCode;
    // End of variables declaration//GEN-END:variables
    //private Vector list;
    private int eventCounter;
}