01: /*
02: JSmooth: a VM wrapper toolkit for Windows
03: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
04:
05: This program is free software; you can redistribute it and/or modify
06: it under the terms of the GNU General Public License as published by
07: the Free Software Foundation; either version 2 of the License, or
08: (at your option) any later version.
09:
10: This program is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: GNU General Public License for more details.
14:
15: You should have received a copy of the GNU General Public License
16: along with this program; if not, write to the Free Software
17: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18:
19: */
20:
21: package net.charabia.jsmoothgen.application.gui.util;
22:
23: import java.io.*;
24: import javax.swing.*;
25:
26: public class EditableListFileEditor implements
27: SortedEditableList.Editor {
28: private File m_rootDir;
29: private JFileChooser m_fileChooser = new JFileChooser();
30:
31: /** Creates a new instance of EditableListFileEditor */
32: public EditableListFileEditor() {
33: }
34:
35: public void setFileChooser(JFileChooser chooser) {
36: m_fileChooser = chooser;
37: }
38:
39: public JFileChooser getFileChooser() {
40: return m_fileChooser;
41: }
42:
43: public void setRootDir(File dir) {
44: m_rootDir = dir;
45: m_fileChooser.setCurrentDirectory(dir);
46: }
47:
48: public File getRootDir() {
49: return m_rootDir;
50: }
51:
52: public Object createNewItem(SortedEditableList selist) {
53: if (m_fileChooser.showOpenDialog(selist) == JFileChooser.APPROVE_OPTION) {
54: File[] files = m_fileChooser.getSelectedFiles();
55: for (int i = 0; i < files.length; i++) {
56: File f = files[i];
57: if (m_rootDir != null) {
58: f = net.charabia.jsmoothgen.application.JSmoothModelPersistency
59: .makePathRelativeIfPossible(m_rootDir, f);
60: files[i] = f;
61: }
62: }
63: return files;
64: }
65: return null;
66: }
67:
68: public Object editItem(SortedEditableList selist, Object item) {
69: if (!(item instanceof File))
70: m_fileChooser.setSelectedFile(new File(item.toString()));
71: else
72: m_fileChooser.setSelectedFile((File) item);
73:
74: if (m_fileChooser.showOpenDialog(selist) == JFileChooser.APPROVE_OPTION) {
75: File f = m_fileChooser.getSelectedFile();
76: if (m_rootDir != null) {
77: f = net.charabia.jsmoothgen.application.JSmoothModelPersistency
78: .makePathRelativeIfPossible(m_rootDir, f);
79: }
80: return f;
81: }
82: return null;
83: }
84:
85: public boolean removeItem(SortedEditableList selist, Object item) {
86: return true;
87: }
88:
89: }
|