ImportEngine.java
01 /*
02  * This class is part of DocWhatsUp, a bug profiling and -reporting lib.
03  
04  * Copyright (C)
05  
06  * This library is free software; you can redistribute it and/or modify it
07  * under the terms of the GNU General Public License as published by the
08  * Free Software Foundation; either version 2 of the License, or (at your
09  * option) any later version.
10  
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *  
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  
20  * EXTENSION:
21  * Linking DocWhatsUp statically or dynamically with other modules is making a
22  * combined work based on DocWhatsUp.  Thus, the terms and conditions of the 
23  * GNU General Public License cover the whole combination.
24  *
25  * As a special exception, the copyright holder of DocWhatsUp give you
26  * permission to link DocWhatsUp with independent modules that communicate with
27  * DocWhatsUp solely through the DocWhatsUp.java interface, regardless of the 
28  * license terms of these independent modules, and to copy and distribute the
29  * resulting combined work under terms of your choice, provided that
30  * every copy of the combined work is accompanied by a complete copy of
31  * the source code of DocWhatsUp (the version of DocWhatsUp used to produce the
32  * combined work), being distributed under the terms of the GNU General
33  * Public License plus this exception.  An independent module is a module
34  * which is not derived from or based on DocWhatsUp.
35 
36  * Note that people who make modified versions of DocWhatsUp are not obligated
37  * to grant this special exception for their modified versions; it is
38  * their choice whether to do so.  The GNU General Public License gives
39  * permission to release a modified version without this exception; this
40  * exception also makes it possible to release a modified version which
41  * carries forward this exception.
42  
43  * Author: Philipp Bartsch; codeshaker@gmx.net
44  */
45 
46 package org.shaker.dwu;
47 
48 import javax.swing.JDialog;
49 import javax.swing.JFileChooser;
50 
51 
52 /**
53  * This pure static class provides methods to import settings from
54  * external applications.
55  
56  @author <A HREF="mailto:codeshaker@gmx.net">
57  *            Philipp Bartsch (codeshaker@gmx.net)</A>
58  *            <A HREF="../../../../gpl.txt">GPL License</A>
59  */
60 final class ImportEngine {
61 
62     
63     /**
64      * Invisible constructor. This class is a factory, so it`s not meant to be
65      * instantiated.
66      */
67     private ImportEngine () {}
68     
69     /**
70      * This method provides a FileChooser. Depending on the available filters,
71      * it offers functionality to import settings. The single filters save
72      * the settings themselve.
73      *
74      @param parent parental component ( JFileChooser is modal)
75      @return success flag
76      */
77     static boolean importSettings (final JDialog parent) {
78         final JFileChooser chooser = new JFileChooser();
79         chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
80         chooser.setFileHidingEnabled(false);
81         chooser.addChoosableFileFilter(new NS4Filter());
82         chooser.addChoosableFileFilter(new NS6Filter());
83         final int opt = chooser.showDialog(parent, "Select");
84         if (opt != JFileChooser.CANCEL_OPTION)
85             return ((ExtendedFilter)chooser.getFileFilter())
86                                .resolvePropFile(chooser.getSelectedFile());                                           
87         else
88             return false;                   
89     }
90 }