1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.file.action;
14
15 import java.awt.Component;
16 import java.awt.event.ActionEvent;
17 import java.awt.event.KeyEvent;
18 import java.io.File;
19 import java.io.IOException;
20
21 import javax.swing.Action;
22 import javax.swing.JFileChooser;
23 import javax.swing.KeyStroke;
24
25 import org.abstracthorizon.aequo.file.FilesModel;
26
27
28
29
30
31
32 public class ReplaceSideAction extends FileBaseAction {
33
34 public ReplaceSideAction() {
35 setName("Open");
36 setMessage("Open");
37 setDescription("Open");
38 putValue(Action.MNEMONIC_KEY, KeyEvent.VK_O);
39 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
40 }
41
42 public boolean isEnabled() {
43 return true;
44 }
45
46
47
48
49
50
51 public void perform(ActionEvent e) {
52 FilesModel filesModel = getFilesModel();
53 File path = filesModel.getData(column);
54
55 JFileChooser fileChooser;
56 if (path != null) {
57 fileChooser = new JFileChooser(path);
58 } else {
59 fileChooser = new JFileChooser();
60 }
61 fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
62
63 int res = fileChooser.showOpenDialog((Component)e.getSource());
64 if (res == JFileChooser.APPROVE_OPTION) {
65 File file = fileChooser.getSelectedFile();
66 path = file.getParentFile();
67 context.getPreferences().setProperty("path", path.getAbsolutePath());
68 try {
69 context.getPreferences().save();
70 } catch (IOException ignore) {
71 }
72
73 filesModel.setData(column, file);
74 filesModel.refresh();
75 }
76 }
77 }