Package lmnd.controller

Source Code of lmnd.controller.CopyController

package lmnd.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Collection;
import lmnd.model.command.CommandData;
import lmnd.model.command.Copy;
import lmnd.model.command.Keys;
import lmnd.model.command.Refresh;
import lmnd.view.FileListPanel;

/**
*
*/
public class CopyController implements ActionListener {
        private FileListPanel[] panels;
        public CopyController() {
        }
        public void setPanels(FileListPanel[] panels) {
                this.panels = panels;
        }
        public void actionPerformed(ActionEvent event) {
                // Get directory name.
                Collection<File> sources = getSourceFiles();
                File destanation = getDestanationPath();
                CommandData data = new CommandData();
                data.addItem(Keys.SOURCE_FILES, sources);
                data.addItem(Keys.DEST_DIR, destanation);
                // Create command.
                Copy copy = new Copy();
                try {
                        copy.perform(data);
                } catch (Exception exception) {
                        exception.printStackTrace();
                }
                // Refresh panels.
                CommandData refreshData = new CommandData();
                refreshData.addItem(Keys.PANELS, panels);
                Refresh refresh = new Refresh();
                try {
                        refresh.perform(refreshData);
                } catch (Exception exception) {
                        exception.printStackTrace();
                }
        }
        private Collection<File> getSourceFiles() {
                FileListPanel panel = getSourcePanel();
                Collection<File> sources = panel.getSelectedFiles();
                return sources;
        }
        private File getDestanationPath() {
                for (FileListPanel panel : panels) {
                        if (!panel.isSelected()) {
                                return panel.getCurrentPath();
                        }
                }
                return null;
        }
        private FileListPanel getSourcePanel() {
                for (FileListPanel panel : panels) {
                        if (panel.isSelected()) {
                                return panel;
                        }
                }
                return null;
        }
}
TOP

Related Classes of lmnd.controller.CopyController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.