1 /*
2 * NeonZip - archive tool
3 * Copyright (C) 2001 Peter Ivanov
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 *
20 * @author Peter Ivanov
21 * <a href=mailto:peterivanov@europe.com>peterivanov@europe.com</a>,
22 * <br>Copyright (c) 2001 Peter K. Ivanov.
23 *
24 * @version (October 03 2001)
25 */
26
27 package net.sourceforge.neonzip;
28
29 import javax.swing;
30 import javax.swing.border;
31 import java.awt.event;
32 import java.awt;
33 import java.io.File;
34
35 public final class AddDialog extends JDialog {
36
37 /* Components */
38 private JButton btnAction;
39 private JButton btnFilter;
40 private JCheckBox checkSubfolders;
41 private JCheckBox checkFullpath;
42 private JFileChooser chooser;
43 private JTextField fFieldFilter;
44
45 /* Actions */
46 public static final int ADD_ACTION = 10;
47 public static final int FRESHEN_ACTION = 11;
48 public static final int MOVE_ACTION = 12;
49 public static final int UPDATE_ACTION = 13;
50
51 private int fCurrentAction = ADD_ACTION;
52
53 /* Compressions */
54 public static final int COMPRESSION_0 = 0; // none
55 public static final int COMPRESSION_1 = 1;
56 public static final int COMPRESSION_2 = 2;
57 public static final int COMPRESSION_3 = 3; // super fast
58 public static final int COMPRESSION_4 = 4;
59 public static final int COMPRESSION_5 = 5; // fast
60 public static final int COMPRESSION_6 = 6;
61 public static final int COMPRESSION_7 = 7; // normal
62 public static final int COMPRESSION_8 = 8;
63 public static final int COMPRESSION_9 = 9; // maximum
64
65 private int fCurrentCompression = COMPRESSION_9; // maximum compression by default
66
67 private boolean fSimpleAction = false;
68 private boolean fFilterAction = false;
69
70
71 public AddDialog(JFrame aOwner, boolean aModal) {
72 super(aOwner, aModal);
73 initComponents();
74 pack();
75 Utils.centerWindow(this);
76 }
77
78
79
80 private void initComponents() {
81 setTitle(Main.fResources.getString("key.title.add"));
82
83 JPanel root = new JPanel(new BorderLayout());
84 root.setBorder(new EmptyBorder(5, 5, 5, 5));
85 setContentPane(root);
86
87 // Register escape key to close Dialog
88 root.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ESCAPE"), "close_dialog");
89 root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close_dialog");
90 root.getActionMap().put("close_dialog", new CancelAction());
91
92 JPanel panelCenter = new JPanel();
93 chooser = new JFileChooser();
94 chooser.setControlButtonsAreShown(false);
95 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
96 chooser.setMultiSelectionEnabled(true);
97 panelCenter.add(chooser);
98
99 root.add(panelCenter, "Center");
100
101 JPanel panelSouth = new JPanel(new BorderLayout());
102 root.add(panelSouth, "South");
103
104 //JPanel panelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
105 JPanel panelButtons = new JPanel(new BorderLayout());
106 JPanel panelCenterButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
107 panelButtons.add(panelCenterButtons, "Center");
108 btnAction = new JButton(new SimpleAction());
109 getRootPane().setDefaultButton(btnAction);
110 panelCenterButtons.add(btnAction);
111
112 btnFilter = new JButton(new FilterAction());
113 panelCenterButtons.add(btnFilter);
114
115 JButton btnCancel = new JButton(new CancelAction());
116 panelCenterButtons.add(btnCancel);
117
118 panelSouth.add(panelButtons, "North");
119
120 JPanel panelFilters = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 5));
121 JLabel labelFileFilter = new JLabel(Main.fResources.getString("key.label.file_filter") + ":");
122 panelFilters.add(labelFileFilter);
123 fFieldFilter = new JTextField();
124 fFieldFilter.setColumns(35);
125 panelFilters.add(fFieldFilter);
126
127 panelButtons.add(panelFilters, "North");
128
129 JPanel panelControls = new JPanel(new BorderLayout());
130
131 JPanel panelWest = new JPanel();
132 panelWest.setLayout(new BoxLayout(panelWest, BoxLayout.Y_AXIS));
133
134 JLabel labelAction = new JLabel(Main.fResources.getString("key.label.action") + ":");
135 labelAction.setAlignmentX(Component.LEFT_ALIGNMENT);
136 panelWest.add(labelAction);
137
138 String[] actions = new String[4];
139 actions[0] = Main.fResources.getString("key.combos.add_files");
140 actions[1] = Main.fResources.getString("key.combos.freshen_files");
141 actions[2] = Main.fResources.getString("key.combos.move_files");
142 actions[3] = Main.fResources.getString("key.combos.update_files");
143 JComboBox comboAction = new JComboBox(actions);
144 comboAction.addActionListener(new ActionCombo());
145 comboAction.setAlignmentX(Component.LEFT_ALIGNMENT);
146 panelWest.add(comboAction);
147 panelWest.add(Box.createRigidArea(new Dimension(10, 10)));
148
149 JLabel labelCompression = new JLabel(Main.fResources.getString("key.label.compression") + ":");
150 labelCompression.setAlignmentX(Component.LEFT_ALIGNMENT);
151 panelWest.add(labelCompression);
152
153 String[] compressions = new String[10];
154 compressions[0] = "9 " + Main.fResources.getString("key.combos.maximum");
155 compressions[1] = "8";
156 compressions[2] = "7 " + Main.fResources.getString("key.combos.normal");
157 compressions[3] = "6";
158 compressions[4] = "5 " + Main.fResources.getString("key.combos.fast");
159 compressions[5] = "4";
160 compressions[6] = "3 " + Main.fResources.getString("key.combos.super_fast");
161 compressions[7] = "2";
162 compressions[8] = "1";
163 compressions[9] = "0 " + Main.fResources.getString("key.combos.none");
164 JComboBox comboCompressions = new JComboBox(compressions);
165 comboCompressions.addActionListener(new CompressionAction());
166 comboCompressions.setAlignmentX(Component.LEFT_ALIGNMENT);
167 panelWest.add(comboCompressions);
168
169 JPanel panelEast = new JPanel();
170 panelEast.setLayout(new FlowLayout());
171
172 JPanel panelFolders = new JPanel();
173 panelFolders.setLayout(new BoxLayout(panelFolders, BoxLayout.Y_AXIS));
174 panelFolders.setBorder(new TitledBorder(Main.fResources.getString("key.title.folders")));
175 panelEast.add(panelFolders);
176
177 checkSubfolders = new JCheckBox(Main.fResources.getString("key.checkbox.include_subfolders"));
178 JPanel panelSubfolders = new JPanel();
179 panelSubfolders.add(checkSubfolders);
180 panelFolders.add(panelSubfolders);
181
182 checkFullpath = new JCheckBox(Main.fResources.getString("key.checkbox.save_fullpath"));
183 JPanel panelFullpath = new JPanel();
184 panelFullpath.add(checkFullpath);
185 panelFolders.add(panelFullpath);
186
187 panelControls.add(panelWest, "West");
188 panelControls.add(panelEast, "East");
189
190 panelSouth.add(panelControls, "Center");
191 }
192
193
194
195 /**
196 * If true then all files located in all subfolders will be included
197 * accordingly to currently selected action.
198 * @return true if option is checked; false otherwise.
199 */
200 public boolean isSubfoldersSelected() {
201 return checkSubfolders.isSelected();
202 }
203
204
205
206 /**
207 * If true then complete path information will be stored also.
208 * @return true if option is checked; false otherwise;
209 */
210 public boolean isFullpathSelected() {
211 return checkFullpath.isSelected();
212 }
213
214
215
216 /**
217 * If SimpleAction button is clicked by user then files selected in
218 * JFileChooser will join to the action. Example:
219 * File[] files = JFileChooser.getSelectedFiles().
220 * @return true if user click on SimpleAction button; false otherwise;
221 */
222 public boolean isSimpleActionSelected() {
223 return fSimpleAction;
224 }
225
226
227
228 /**
229 * If FilterAction button is clicked by user then files specified
230 * by regular expression will join to the action. Example: *.java.
231 * @return true if user click on FilterAction button; false otherwise;
232 */
233 public boolean isFilterActionSelected() {
234 return fFilterAction;
235 }
236
237
238
239 /**
240 * Get selected by user action. Possible actions are:
241 * ADD_ACTION, FRESHEN_ACTION, UPDATE_ACTION, MOVE_ACTION
242 * @return some selected action.
243 */
244 public int getAction() {
245 return fCurrentAction;
246 }
247
248
249
250 /**
251 * Get selected compression method. Possible methods are:
252 * MAXIMUM_COMPRESSION, NORMAL_COMPRESSION, FAST_COMPRESSION,
253 * SUPERFAST_COMPRESSION, NONE_COMPRESSION
254 * @return some compression method.
255 */
256 public int getCompression() {
257 return fCurrentCompression;
258 }
259
260
261
262 /**
263 * Returns list of selected files in chooser.
264 */
265 public File[] getSelectedFiles() {
266 return chooser.getSelectedFiles();
267 }
268
269
270
271 /**
272 * Returns current directory.
273 */
274 public File getCurrentDirectory() {
275 return chooser.getCurrentDirectory();
276 }
277
278
279
280 /**
281 * Return filter for which files will be selected and added.
282 * @return String with filter.
283 */
284 public String getFileFilter() {
285 String filter = fFieldFilter.getText();
286 return filter;
287 }
288
289
290
291 private final class CancelAction extends AbstractAction {
292 CancelAction() {
293 super(Main.fResources.getString("key.button.cancel"));
294 }
295
296 public void actionPerformed(ActionEvent e) {
297 dispose();
298 }
299 }
300
301
302
303 private final class SimpleAction extends AbstractAction {
304 SimpleAction() {
305 super(Main.fResources.getString("key.button.add"));
306 }
307
308 public void actionPerformed(ActionEvent e) {
309 fSimpleAction = true;
310 dispose();
311 }
312 }
313
314
315
316 private final class FilterAction extends AbstractAction {
317 FilterAction() {
318 super(Main.fResources.getString("key.button.add_filter"));
319 }
320
321 public void actionPerformed(ActionEvent e) {
322 fFilterAction = true;
323 dispose();
324 }
325 }
326
327
328
329 private final class CompressionAction extends AbstractAction {
330 CompressionAction() {
331 }
332
333 public void actionPerformed(ActionEvent e) {
334 JComboBox combo = (JComboBox) e.getSource();
335 switch(combo.getSelectedIndex()) {
336 case 0: {
337 fCurrentCompression = COMPRESSION_9; // maximum
338 break;
339 }
340 case 1: {
341 fCurrentCompression = COMPRESSION_8;
342 break;
343 }
344 case 2: {
345 fCurrentCompression = COMPRESSION_7; // normal
346 break;
347 }
348 case 3: {
349 fCurrentCompression = COMPRESSION_6;
350 break;
351 }
352 case 4: {
353 fCurrentCompression = COMPRESSION_5; // fast
354 break;
355 }
356 case 5: {
357 fCurrentCompression = COMPRESSION_4;
358 break;
359 }
360 case 6: {
361 fCurrentCompression = COMPRESSION_3; // super fast
362 break;
363 }
364 case 7: {
365 fCurrentCompression = COMPRESSION_2;
366 break;
367 }
368 case 8: {
369 fCurrentCompression = COMPRESSION_1;
370 break;
371 }
372 case 9: {
373 fCurrentCompression = COMPRESSION_0; // none
374 break;
375 }
376 }
377 }
378 }
379
380
381
382 private final class ActionCombo extends AbstractAction {
383 ActionCombo() {
384 }
385
386 public void actionPerformed(ActionEvent e) {
387 JComboBox combo = (JComboBox) e.getSource();
388 switch(combo.getSelectedIndex()) {
389 case 0: {
390 btnAction.setText(Main.fResources.getString("key.button.add"));
391 btnFilter.setText(Main.fResources.getString("key.button.add_filter"));
392 fCurrentAction = ADD_ACTION;
393 break;
394 }
395 case 1: {
396 btnAction.setText(Main.fResources.getString("key.button.freshen"));
397 btnFilter.setText(Main.fResources.getString("key.button.freshen_filter"));
398 fCurrentAction = FRESHEN_ACTION;
399 break;
400 }
401 case 2: {
402 btnAction.setText(Main.fResources.getString("key.button.move"));
403 btnFilter.setText(Main.fResources.getString("key.button.move_filter"));
404 fCurrentAction = MOVE_ACTION;
405 break;
406 }
407 case 3: {
408 btnAction.setText(Main.fResources.getString("key.button.update"));
409 btnFilter.setText(Main.fResources.getString("key.button.update_filter"));
410 fCurrentAction = UPDATE_ACTION;
411 break;
412 }
413 }
414 }
415 }
416
417
418
419 }