source: 3thparty/jupload/src/main/java/wjhk/jupload2/JUploadDaemon.java @ 3951

Revision 3951, 3.3 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1709 - Adicao de codigo fonte java do componente jupload

Line 
1package wjhk.jupload2;
2
3import javax.swing.JFrame;
4
5import wjhk.jupload2.context.JUploadContext;
6import wjhk.jupload2.context.JUploadContextExecutable;
7import wjhk.jupload2.policies.UploadPolicy;
8
9/**
10 *
11 * This class allows to use JUpload as a stand alone application. It can then be
12 * used to manage upload, as do the applet. Or it can be used as a daemon. In
13 * this case the applet 'paste' files to the daemon, and the daemon is
14 * responsible for the upload. This is a good point when uploading big files:
15 * the user can go on browsing, or close his/her browser. The daemon will keep
16 * on uploading the file(s). <BR>
17 * The configuration can be stored in the jar file, or in a property file
18 * available on the net, through a URL. See the {link {@link #main(String[])}
19 * method for details.<BR>
20 * The daemon parameters are the same for the applet and the daemon. They are
21 * described on the {@link UploadPolicy} page.
22 *
23 * @author etienne_sf
24 *
25 */
26public class JUploadDaemon extends JFrame {
27
28    /** A generated serialVersionUID */
29    private static final long serialVersionUID = 1L;
30
31    /**
32     * The URL, that 'perhaps' was given to the main method. Used only to
33     * transfer the value between the invokeLater and the actual execution of
34     * this method. It's not very clean, but I guess there will never be two
35     * execution of the daemon that will start in the same quarter of second
36     * with a different URL.
37     */
38    private static String propertiesURL = null;
39
40    /**
41     * The current execution context.
42     */
43    transient JUploadContext juploadContext = null;
44
45    /**
46     * Default constructor.
47     */
48    public JUploadDaemon() {
49        // TODO add a way to personalize the window title.
50        super("JUpload daemon");
51
52        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53    }
54
55    /**
56     * Create the GUI and show it. For thread safety, this method should be
57     * invoked from the event-dispatching thread.
58     */
59    private static void createAndShowGUI() {
60        JUploadDaemon juploadDaemon = new JUploadDaemon();
61        juploadDaemon.juploadContext = new JUploadContextExecutable(
62                juploadDaemon, propertiesURL);
63
64        // Display the window.
65        juploadDaemon.pack();
66        juploadDaemon.setVisible(true);
67    }
68
69    /**
70     * The start of the application, when launched as a Stand Alone one. If an
71     * argument is given, it must be a valid URL to the JUpload configuration
72     * file. The daemon will load it as a property file. The allowed parameters
73     * and values are the same as the applet parameters. These are indicated in
74     * the {@link wjhk.jupload2.policies.UploadPolicy} page.<BR>
75     * If this URL is not given, the /conf folder in the jar file must contain
76     * the daemon property file.
77     *
78     * @param args args[1] is optional, and may contain the URL pointing to the
79     *            configuration page.
80     */
81    public static void main(String[] args) {
82        propertiesURL = null;
83        if (args.length > 0) {
84            propertiesURL = args[0];
85        }
86        javax.swing.SwingUtilities.invokeLater(new Runnable() {
87            public void run() {
88                createAndShowGUI();
89            }
90        });
91    }
92}
Note: See TracBrowser for help on using the repository browser.