package lmnd.controller;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import lmnd.view.FileListPanel;
import lmnd.model.command.CommandData;
import lmnd.model.command.Keys;
import lmnd.model.command.View;
/**
*
*/
public class ViewController implements ActionListener {
private FileListPanel[] panels;
public ViewController() {
}
public void setPanels(FileListPanel[] panels) {
this.panels = panels;
}
@Override
public void actionPerformed(ActionEvent event) {
// Get directory name.
File file = getSelectedFile();
CommandData data = new CommandData();
data.addItem(Keys.FILE, file);
// Create command.
View view = new View();
try {
view.perform(data);
} catch (Exception exception) {
exception.printStackTrace();
}
}
private File getSelectedFile() {
for (FileListPanel panel : panels) {
if (panel.isSelected()) {
File result = panel.getSelectedFile();
return result;
}
}
return null;
}
}