Subversion Repositories public

Rev

Rev 85 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 85 Rev 86
1
/*
1
/*
2
 * ICFrame.java - jIncron application GUI frame
2
 * ICFrame.java - jIncron application GUI frame
3
 *
3
 *
4
 * Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
4
 * Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
5
 *
5
 *
6
 * ==========================================================================
6
 * ==========================================================================
7
 *
7
 *
8
 * This program is free software; you can redistribute it and/or modify
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License Version 2 as
9
 * it under the terms of the GNU General Public License Version 2 as
10
 * published by the Free Software Foundation.
10
 * published by the Free Software Foundation.
11
 *
11
 *
12
 * This program is distributed in the hope that it will be useful,
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
15
 * GNU General Public License for more details.
16
 *
16
 *
17
 * You should have received a copy of the GNU General Public License
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 *
20
 *
21
 * ==========================================================================
21
 * ==========================================================================
22
 */
22
 */
23
23
24
package cz.aiken.util.jincron;
24
package cz.aiken.util.jincron;
25
25
26
import java.awt.*;
26
import java.awt.*;
27
import java.awt.event.*;
27
import java.awt.event.*;
28
import java.io.*;
28
import java.io.*;
29
import javax.swing.*;
29
import javax.swing.*;
30
import javax.swing.event.*;
30
import javax.swing.event.*;
31
import javax.swing.table.*;
31
import javax.swing.table.*;
32
32
33
/**
33
/**
34
 *
34
 *
35
 * @author luk
35
 * @author luk
36
 */
36
 */
37
public class ICFrame extends JFrame implements ActionListener, ListSelectionListener {
37
public class ICFrame extends JFrame implements ActionListener, ListSelectionListener {
38
   
38
   
39
    private static final String pgmName = "jIncron";
39
    private static final String pgmName = "jIncron";
40
   
40
   
41
    private JMenuBar menubar = new JMenuBar();
41
    private JMenuBar menubar = new JMenuBar();
42
    private JMenuItem editRowItem = null;
42
    private JMenuItem editRowItem = null;
43
    private JMenuItem removeRowItem = null;
43
    private JMenuItem removeRowItem = null;
44
   
44
   
45
    private JButton addBut = new JButton("Add...");
45
    private JButton addBut = new JButton("Add...");
46
    private JButton editBut = new JButton("Edit...");
46
    private JButton editBut = new JButton("Edit...");
47
    private JButton removeBut = new JButton("Remove");
47
    private JButton removeBut = new JButton("Remove");
48
   
48
   
49
    private JPanel butPanel = new JPanel();
49
    private JPanel butPanel = new JPanel();
50
    private ICTableModel model = new ICTableModel();
50
    private ICTableModel model = new ICTableModel();
51
    private JTable table = null;
51
    private JTable table = null;
52
   
52
   
53
    private boolean changed = false;
53
    private boolean changed = false;
54
   
54
   
55
    /** Creates a new instance of ICFrame */
55
    /** Creates a new instance of ICFrame */
56
    public ICFrame() {
56
    public ICFrame() {
57
        super();
57
        super();
58
        init();
58
        init();
59
    }
59
    }
60
   
60
   
61
    protected void init() {
61
    protected void init() {
62
        setSize(ICConfig.getWindowSize());
62
        setSize(ICConfig.getWindowSize());
63
        setLocation(ICConfig.getWindowLocation());
63
        setLocation(ICConfig.getWindowLocation());
64
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
64
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
65
        updateTitle();
65
        updateTitle();
66
       
66
       
67
        initMenus();
67
        initMenus();
68
       
68
       
69
        initButtons();
69
        initButtons();
70
       
70
       
71
        table = new JTable(model);
71
        table = new JTable(model);
72
        table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
72
        table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
73
        table.getSelectionModel().addListSelectionListener(this);
73
        table.getSelectionModel().addListSelectionListener(this);
74
        JScrollPane jsp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
74
        JScrollPane jsp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
75
        JSplitPane spl = new JSplitPane(JSplitPane.VERTICAL_SPLIT, butPanel, jsp);
75
        JSplitPane spl = new JSplitPane(JSplitPane.VERTICAL_SPLIT, butPanel, jsp);
76
        setContentPane(spl);
76
        setContentPane(spl);
77
77
78
        load();
78
        load();
79
       
79
       
80
        updateMenus();
80
        updateMenus();
81
        updateButtons();
81
        updateButtons();
82
    }
82
    }
83
   
83
   
84
    protected void initButtons() {
84
    protected void initButtons() {
85
        butPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
85
        butPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
86
        initButton(addBut, "add", "Add a new rule");
86
        initButton(addBut, "add", "Add a new rule");
87
        initButton(editBut, "edit", "Edit the selected rule");
87
        initButton(editBut, "edit", "Edit the selected rule");
88
        initButton(removeBut, "remove", "Remove the selected rule(s)");
88
        initButton(removeBut, "remove", "Remove the selected rule(s)");
89
    }
89
    }
90
   
90
   
91
    protected void initButton(JButton but, String cmd, String tooltip) {
91
    protected void initButton(JButton but, String cmd, String tooltip) {
92
        but.setActionCommand(cmd);
92
        but.setActionCommand(cmd);
93
        but.addActionListener(this);
93
        but.addActionListener(this);
94
        but.setToolTipText(tooltip);
94
        but.setToolTipText(tooltip);
95
        butPanel.add(but);
95
        butPanel.add(but);
96
    }
96
    }
97
   
97
   
98
    protected void initMenus() {
98
    protected void initMenus() {
99
        JMenu menu = new JMenu("File");
99
        JMenu menu = new JMenu("File");
100
        initMenuItem("New", 'n', KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK), "new", this, menu);
100
        initMenuItem("New", 'n', KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK), "new", this, menu);
101
        initMenuItem("Load", 'l', KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK), "load", this, menu);
101
        initMenuItem("Load", 'l', KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK), "load", this, menu);
102
        initMenuItem("Save", 's', KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "save", this, menu);
102
        initMenuItem("Save", 's', KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "save", this, menu);
103
        menu.addSeparator();
103
        menu.addSeparator();
104
        initMenuItem("Import...", 'i', KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_MASK), "import", this, menu);
104
        initMenuItem("Import...", 'i', KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_MASK), "import", this, menu);
105
        initMenuItem("Export...", 'x', KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK), "export", this, menu);
105
        initMenuItem("Export...", 'x', KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK), "export", this, menu);
106
        menu.addSeparator();
106
        menu.addSeparator();
107
        initMenuItem("Quit", 'q', KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_MASK), "quit", this, menu);
107
        initMenuItem("Quit", 'q', KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_MASK), "quit", this, menu);
108
        menubar.add(menu);
108
        menubar.add(menu);
109
       
109
       
110
        menu = new JMenu("Action");
110
        menu = new JMenu("Action");
111
        initMenuItem("Add...", 'a', KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "add", this, menu);
111
        initMenuItem("Add...", 'a', KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "add", this, menu);
112
        editRowItem = initMenuItem("Edit...", 'e', KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK), "edit", this, menu);
112
        editRowItem = initMenuItem("Edit...", 'e', KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK), "edit", this, menu);
113
        removeRowItem = initMenuItem("Remove", 'v', KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "remove", this, menu);
113
        removeRowItem = initMenuItem("Remove", 'v', KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "remove", this, menu);
114
        menubar.add(menu);
114
        menubar.add(menu);
115
       
115
       
116
        menu = new JMenu("Help");
116
        menu = new JMenu("Help");
117
        initMenuItem("About", 'b', KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK), "about", this, menu);
117
        initMenuItem("About", 'b', KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK), "about", this, menu);
118
        menubar.add(menu);
118
        menubar.add(menu);
119
       
119
       
120
        setJMenuBar(menubar);
120
        setJMenuBar(menubar);
121
    }
121
    }
122
   
122
   
123
    protected JMenuItem initMenuItem(String text, int mnemo, KeyStroke accel, String cmd, ActionListener al, JMenu menu) {
123
    protected JMenuItem initMenuItem(String text, int mnemo, KeyStroke accel, String cmd, ActionListener al, JMenu menu) {
124
        JMenuItem it = new JMenuItem(text, mnemo);
124
        JMenuItem it = new JMenuItem(text, mnemo);
125
        it.setAccelerator(accel);
125
        it.setAccelerator(accel);
126
        it.setActionCommand(cmd);
126
        it.setActionCommand(cmd);
127
        it.addActionListener(al);
127
        it.addActionListener(al);
128
        menu.add(it);
128
        menu.add(it);
129
        return it;
129
        return it;
130
    }
130
    }
131
   
131
   
132
    protected void updateTitle() {
132
    protected void updateTitle() {
133
        if (changed) {
133
        if (changed) {
134
            setTitle(pgmName + " (modified)");
134
            setTitle(pgmName + " (modified)");
135
        }
135
        }
136
        else {
136
        else {
137
            setTitle(pgmName);
137
            setTitle(pgmName);
138
        }
138
        }
139
    }
139
    }
140
   
140
   
141
    protected void updateButtons() {
141
    protected void updateButtons() {
142
        int cnt = table.getSelectedRowCount();
142
        int cnt = table.getSelectedRowCount();
143
        editBut.setEnabled(cnt == 1);
143
        editBut.setEnabled(cnt == 1);
144
        removeBut.setEnabled(cnt > 0);
144
        removeBut.setEnabled(cnt > 0);
145
    }
145
    }
146
   
146
   
147
    protected void updateMenus() {
147
    protected void updateMenus() {
148
        int cnt = table.getSelectedRowCount();
148
        int cnt = table.getSelectedRowCount();
149
        editRowItem.setEnabled(cnt == 1);
149
        editRowItem.setEnabled(cnt == 1);
150
        removeRowItem.setEnabled(cnt > 0);
150
        removeRowItem.setEnabled(cnt > 0);
151
    }
151
    }
152
   
152
   
153
    protected void setModified(boolean b) {
153
    protected void setModified(boolean b) {
154
        changed = b;
154
        changed = b;
155
        updateTitle();
155
        updateTitle();
156
    }
156
    }
157
   
157
   
158
    protected void load() {
158
    protected void load() {
159
        ProcessBuilder pb = new ProcessBuilder("incrontab", "--list");
159
        ProcessBuilder pb = new ProcessBuilder("incrontab", "--list");
160
        try {
160
        try {
161
            Process p = pb.start();
161
            Process p = pb.start();
162
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
162
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
163
            model.importTable(br);
163
            model.importTable(br);
164
            br.close();
164
            br.close();
165
            boolean end = false;
165
            boolean end = false;
166
            while (!end) {
166
            while (!end) {
167
                try {
167
                try {
168
                    p.waitFor();
168
                    p.waitFor();
169
                    end = true;
169
                    end = true;
170
                } catch (InterruptedException ex) {}
170
                } catch (InterruptedException ex) {}
171
            }
171
            }
172
            setModified(false);
172
            setModified(false);
173
        } catch (IOException e) {
173
        } catch (IOException e) {
174
            JOptionPane.showMessageDialog(this, "Loading incron table failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
174
            JOptionPane.showMessageDialog(this, "Loading incron table failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
175
        }
175
        }
176
    }
176
    }
177
   
177
   
178
    protected void save() {
178
    protected void save() {
179
        ProcessBuilder pb = new ProcessBuilder("incrontab", "-");
179
        ProcessBuilder pb = new ProcessBuilder("incrontab", "-");
180
        try {
180
        try {
181
            Process p = pb.start();
181
            Process p = pb.start();
182
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
182
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
183
            model.exportTable(bw);
183
            model.exportTable(bw);
184
            bw.close();
184
            bw.close();
185
            boolean end = false;
185
            boolean end = false;
186
            while (!end) {
186
            while (!end) {
187
                try {
187
                try {
188
                    int ev = p.waitFor();
188
                    int ev = p.waitFor();
189
                    if (ev != 0)
189
                    if (ev != 0)
190
                        throw new IOException("incrontab return value: " + ev);
190
                        throw new IOException("incrontab return value: " + ev);
191
                    end = true;
191
                    end = true;
192
                } catch (InterruptedException ex) {}
192
                } catch (InterruptedException ex) {}
193
            }
193
            }
194
            JOptionPane.showMessageDialog(this, "Table successfully saved.", "Success", JOptionPane.INFORMATION_MESSAGE);
194
            JOptionPane.showMessageDialog(this, "Table successfully saved.", "Success", JOptionPane.INFORMATION_MESSAGE);
195
            setModified(false);
195
            setModified(false);
196
        } catch (IOException e) {
196
        } catch (IOException e) {
197
            JOptionPane.showMessageDialog(this, "Saving incron table failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
197
            JOptionPane.showMessageDialog(this, "Saving incron table failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
198
        }
198
        }
199
    }
199
    }
200
   
200
   
201
    protected void doExport() {
201
    protected void doExport() {
202
        try {
202
        try {
203
            JFileChooser fc = new JFileChooser();
203
            JFileChooser fc = new JFileChooser();
204
            fc.setDialogTitle("Export incron table");
204
            fc.setDialogTitle("Export incron table");
205
            fc.setDialogType(JFileChooser.SAVE_DIALOG);
205
            fc.setDialogType(JFileChooser.SAVE_DIALOG);
206
            fc.setMultiSelectionEnabled(false);
206
            fc.setMultiSelectionEnabled(false);
207
            int res = fc.showSaveDialog(this);
207
            int res = fc.showSaveDialog(this);
208
            if (res == JFileChooser.APPROVE_OPTION) {
208
            if (res == JFileChooser.APPROVE_OPTION) {
209
                File f = fc.getSelectedFile();
209
                File f = fc.getSelectedFile();
210
                if (f.exists()) {
210
                if (f.exists()) {
211
                    res = JOptionPane.showConfirmDialog(this, "Selected file already exists. Overwrite?", "File exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
211
                    res = JOptionPane.showConfirmDialog(this, "Selected file already exists. Overwrite?", "File exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
212
                    if (res != JOptionPane.YES_OPTION)
212
                    if (res != JOptionPane.YES_OPTION)
213
                        return;
213
                        return;
214
                }
214
                }
215
                model.exportToFile(f);
215
                model.exportToFile(f);
216
                JOptionPane.showMessageDialog(this, "Table successfully exported.", "Success", JOptionPane.INFORMATION_MESSAGE);
216
                JOptionPane.showMessageDialog(this, "Table successfully exported.", "Success", JOptionPane.INFORMATION_MESSAGE);
217
            }
217
            }
218
            else if (res == JFileChooser.ERROR_OPTION) {
218
            else if (res == JFileChooser.ERROR_OPTION) {
219
                JOptionPane.showMessageDialog(this, "Error occurred while selecting file for export.", "Error", JOptionPane.ERROR_MESSAGE);
219
                JOptionPane.showMessageDialog(this, "Error occurred while selecting file for export.", "Error", JOptionPane.ERROR_MESSAGE);
220
            }
220
            }
221
        } catch (IOException e) {
221
        } catch (IOException e) {
222
            JOptionPane.showMessageDialog(this, "Cannot export table to file: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
222
            JOptionPane.showMessageDialog(this, "Cannot export table to file: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
223
        }
223
        }
224
    }
224
    }
225
   
225
   
226
    protected void doImport() {
226
    protected void doImport() {
227
        try {
227
        try {
228
            JFileChooser fc = new JFileChooser();
228
            JFileChooser fc = new JFileChooser();
229
            fc.setDialogTitle("Import incron table");
229
            fc.setDialogTitle("Import incron table");
230
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
230
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
231
            fc.setMultiSelectionEnabled(false);
231
            fc.setMultiSelectionEnabled(false);
232
            int res = fc.showOpenDialog(this);
232
            int res = fc.showOpenDialog(this);
233
            if (res == JFileChooser.APPROVE_OPTION) {
233
            if (res == JFileChooser.APPROVE_OPTION) {
234
                File f = fc.getSelectedFile();
234
                File f = fc.getSelectedFile();
235
                model.importFromFile(f);
235
                model.importFromFile(f);
236
                JOptionPane.showMessageDialog(this, "Table successfully imported.", "Success", JOptionPane.INFORMATION_MESSAGE);
236
                JOptionPane.showMessageDialog(this, "Table successfully imported.", "Success", JOptionPane.INFORMATION_MESSAGE);
237
                setModified(true);
237
                setModified(true);
238
            }
238
            }
239
            else if (res == JFileChooser.ERROR_OPTION) {
239
            else if (res == JFileChooser.ERROR_OPTION) {
240
                JOptionPane.showMessageDialog(this, "Error occurred while selecting file for import.", "Error", JOptionPane.ERROR_MESSAGE);
240
                JOptionPane.showMessageDialog(this, "Error occurred while selecting file for import.", "Error", JOptionPane.ERROR_MESSAGE);
241
            }
241
            }
242
        } catch (IOException e) {
242
        } catch (IOException e) {
243
            JOptionPane.showMessageDialog(this, "Cannot import table from file: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
243
            JOptionPane.showMessageDialog(this, "Cannot import table from file: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
244
            setModified(true);
244
            setModified(true);
245
        }        
245
        }        
246
    }
246
    }
247
   
247
   
248
    protected void addRow() {
248
    protected void addRow() {
249
        ICPropDialog dg = new ICPropDialog(new ICRow("", new InotifyEvent(0, 0), ""));
249
        ICPropDialog dg = new ICPropDialog(new ICRow("", new InotifyEvent(0, 0), ""));
250
        dg.setVisible(true);
250
        dg.setVisible(true);
251
        dg.dispose();
251
        dg.dispose();
252
        if (dg.isCommitted() && dg.isModified()) {
252
        if (dg.isCommitted() && dg.isModified()) {
253
            model.addRow(dg.getData());
253
            model.addRow(dg.getData());
254
            setModified(true);
254
            setModified(true);
255
        }
255
        }
256
    }
256
    }
257
   
257
   
258
    protected void editRow() {
258
    protected void editRow() {
259
        int ia[] = table.getSelectedRows();
259
        int ia[] = table.getSelectedRows();
260
        if (ia.length == 1) {
260
        if (ia.length == 1) {
261
            ICPropDialog dg = new ICPropDialog(model.getRow(ia[0]));
261
            ICPropDialog dg = new ICPropDialog(model.getRow(ia[0]));
262
            dg.setVisible(true);
262
            dg.setVisible(true);
263
            dg.dispose();
263
            dg.dispose();
264
            if (dg.isCommitted() && dg.isModified()) {
264
            if (dg.isCommitted() && dg.isModified()) {
265
                model.updateRow(ia[0], dg.getData());
265
                model.updateRow(ia[0], dg.getData());
266
                setModified(true);
266
                setModified(true);
267
            }
267
            }
268
        }
268
        }
269
    }
269
    }
270
   
270
   
271
    protected void removeRow() {
271
    protected void removeRow() {
272
        int ia[] = table.getSelectedRows();
272
        int ia[] = table.getSelectedRows();
273
        if (ia.length > 0) {
273
        if (ia.length > 0) {
274
            model.removeRows(ia[0], ia[ia.length-1]);
274
            model.removeRows(ia[0], ia[ia.length-1]);
275
            setModified(true);
275
            setModified(true);
276
        }
276
        }
277
    }
277
    }
278
   
278
   
279
    protected void doDispose() {
279
    protected void doDispose() {
280
        ICConfig.setWindowSize(getSize());
280
        ICConfig.setWindowSize(getSize());
281
        ICConfig.setWindowLocation(getLocation());
281
        ICConfig.setWindowLocation(getLocation());
282
        ICConfig.save();
282
        ICConfig.save();
283
        super.dispose();
283
        super.dispose();
284
    }
284
    }
285
   
285
   
286
    public void dispose() {
286
    public void dispose() {
287
        if (changed) {
287
        if (changed) {
288
            int opt = JOptionPane.showConfirmDialog(this,
288
            int opt = JOptionPane.showConfirmDialog(this,
289
                    "Table data has been modified but not saved.\nDo you want to save it before closing?", "Unsaved data",
289
                    "Table data has been modified but not saved.\nDo you want to save it before closing?", "Unsaved data",
290
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
290
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
291
            switch (opt) {
291
            switch (opt) {
292
                case JOptionPane.YES_OPTION:
292
                case JOptionPane.YES_OPTION:
293
                    save();
293
                    save();
294
                case JOptionPane.NO_OPTION:
294
                case JOptionPane.NO_OPTION:
295
                    doDispose();
295
                    doDispose();
296
                default:;
296
                default:;
297
            }
297
            }
298
        }
298
        }
299
        else {
299
        else {
300
            doDispose();
300
            doDispose();
301
        }
301
        }
302
    }
302
    }
303
   
303
   
304
    public void actionPerformed(ActionEvent e) {
304
    public void actionPerformed(ActionEvent e) {
305
        String s = e.getActionCommand();
305
        String s = e.getActionCommand();
306
        if (s.equals("new")) {
306
        if (s.equals("new")) {
307
            model.clear();
307
            model.clear();
308
            setModified(true);
308
            setModified(true);
309
        }
309
        }
310
        else if (s.equals("load")) {
310
        else if (s.equals("load")) {
311
            load();
311
            load();
312
        }
312
        }
313
        else if (s.equals("save")) {
313
        else if (s.equals("save")) {
314
            save();
314
            save();
315
        }
315
        }
316
        else if (s.equals("import")) {
316
        else if (s.equals("import")) {
317
            doImport();
317
            doImport();
318
        }
318
        }
319
        else if (s.equals("export")) {
319
        else if (s.equals("export")) {
320
            doExport();
320
            doExport();
321
        }
321
        }
322
        else if (s.equals("quit")) {
322
        else if (s.equals("quit")) {
323
            dispose();
323
            dispose();
324
        }
324
        }
325
        else if (s.equals("add")) {
325
        else if (s.equals("add")) {
326
            addRow();
326
            addRow();
327
        }
327
        }
328
        else if (s.equals("edit")) {
328
        else if (s.equals("edit")) {
329
            editRow();
329
            editRow();
330
        }
330
        }
331
        else if (s.equals("remove")) {
331
        else if (s.equals("remove")) {
332
            removeRow();
332
            removeRow();
333
        }
333
        }
334
        else if (s.equals("about")) {
334
        else if (s.equals("about")) {
335
            JOptionPane.showMessageDialog(this, "jIncron 0.1.0", "About jIncron", JOptionPane.INFORMATION_MESSAGE);
335
            JOptionPane.showMessageDialog(this, "jIncron 0.1.0", "About jIncron", JOptionPane.INFORMATION_MESSAGE);
336
        }
336
        }
337
    }
337
    }
338
   
338
   
339
    public void valueChanged(ListSelectionEvent e) {
339
    public void valueChanged(ListSelectionEvent e) {
340
        updateMenus();
340
        updateMenus();
341
        updateButtons();
341
        updateButtons();
342
    }
342
    }
343
}
343
}
344
 
344