1 | // |
---|
2 | // $Id: DefaultUploadPolicy.java 289 2007-06-19 10:04:46 +0000 (mar., 19 juin |
---|
3 | // 2007) etienne_sf $ |
---|
4 | // |
---|
5 | // jupload - A file upload juploadContext. |
---|
6 | // Copyright 2007 The JUpload Team |
---|
7 | // |
---|
8 | // Created: 2006-05-04 |
---|
9 | // Creator: etienne_sf |
---|
10 | // Last modified: $Date: 2010-02-12 18:25:00 +0100 (ven, 12 Feb 2010) $ |
---|
11 | // |
---|
12 | // This program is free software; you can redistribute it and/or modify it under |
---|
13 | // the terms of the GNU General Public License as published by the Free Software |
---|
14 | // Foundation; either version 2 of the License, or (at your option) any later |
---|
15 | // version. This program is distributed in the hope that it will be useful, but |
---|
16 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
17 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
18 | // details. You should have received a copy of the GNU General Public License |
---|
19 | // along with this program; if not, write to the Free Software Foundation, Inc., |
---|
20 | // 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | |
---|
22 | package wjhk.jupload2.policies; |
---|
23 | |
---|
24 | import java.awt.BorderLayout; |
---|
25 | import java.awt.Color; |
---|
26 | import java.awt.Component; |
---|
27 | import java.awt.GridLayout; |
---|
28 | import java.awt.SystemColor; |
---|
29 | import java.awt.dnd.DropTarget; |
---|
30 | |
---|
31 | import javax.swing.BorderFactory; |
---|
32 | import javax.swing.BoxLayout; |
---|
33 | import javax.swing.JButton; |
---|
34 | import javax.swing.JLabel; |
---|
35 | import javax.swing.JPanel; |
---|
36 | import javax.swing.SwingConstants; |
---|
37 | |
---|
38 | import wjhk.jupload2.context.JUploadContext; |
---|
39 | import wjhk.jupload2.exception.JUploadException; |
---|
40 | import wjhk.jupload2.gui.JUploadPanel; |
---|
41 | |
---|
42 | /** |
---|
43 | * A SuperSimpleUploadPolicy - see |
---|
44 | * https://sourceforge.net/tracker/?func=detail&atid |
---|
45 | * =490055&aid=2954497&group_id=59144 |
---|
46 | * |
---|
47 | * @author nordfalk |
---|
48 | * @version $Revision: 978 $ |
---|
49 | */ |
---|
50 | |
---|
51 | public class SuperSimpleUploadPolicy extends DefaultUploadPolicy { |
---|
52 | |
---|
53 | /** |
---|
54 | * The main constructor : use default values, and the given postURL. |
---|
55 | * |
---|
56 | * @param juploadContext |
---|
57 | * The current juploadContext. As the reference to the current |
---|
58 | * upload policy exists almost everywhere, this parameter allows |
---|
59 | * any access to anyone on the juploadContext... including |
---|
60 | * reading the applet parameters. |
---|
61 | * @throws JUploadException |
---|
62 | * If an applet parameter is invalid |
---|
63 | */ |
---|
64 | public SuperSimpleUploadPolicy(JUploadContext juploadContext) |
---|
65 | throws JUploadException { |
---|
66 | super(juploadContext); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Implementation of |
---|
71 | * {@link wjhk.jupload2.policies.UploadPolicy#createTopPanel(JButton, JButton, JButton, JUploadPanel)} |
---|
72 | * |
---|
73 | * @see wjhk.jupload2.policies.UploadPolicy#createTopPanel(JButton, JButton, |
---|
74 | * JButton, JUploadPanel) |
---|
75 | */ |
---|
76 | public JPanel createTopPanel(JButton browse, JButton remove, |
---|
77 | JButton removeAll, JUploadPanel jUploadPanel) { |
---|
78 | JPanel jPanel = new JPanel(); |
---|
79 | |
---|
80 | jPanel.setLayout(new GridLayout(1, 3, 10, 5)); |
---|
81 | jPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); |
---|
82 | jPanel.add(browse); |
---|
83 | // jPanel.add(removeAll); |
---|
84 | jPanel.add(remove); |
---|
85 | remove.setVisible(false); // will appear after first file has been added |
---|
86 | |
---|
87 | jUploadPanel.getJComponent().setBorder( |
---|
88 | BorderFactory.createLineBorder(SystemColor.controlDkShadow)); |
---|
89 | |
---|
90 | jPanel.setBackground(Color.WHITE); |
---|
91 | |
---|
92 | return jPanel; |
---|
93 | } |
---|
94 | |
---|
95 | JPanel dndFilesHere; |
---|
96 | JPanel progressPanel; |
---|
97 | JPanel statusBar; |
---|
98 | |
---|
99 | /** |
---|
100 | * This methods allow the upload policy to override the default disposition |
---|
101 | * of the components on the applet. |
---|
102 | * |
---|
103 | * @see UploadPolicy#addComponentsToJUploadPanel(JUploadPanel) |
---|
104 | */ |
---|
105 | public void addComponentsToJUploadPanel(JUploadPanel jUploadPanel) { |
---|
106 | // Set the global layout of the panel. |
---|
107 | jUploadPanel.getJComponent().setLayout( |
---|
108 | new BoxLayout(jUploadPanel.getJComponent(), BoxLayout.Y_AXIS)); |
---|
109 | |
---|
110 | // The top panel is the upper part of the applet: above the file |
---|
111 | // list. |
---|
112 | // JPanel topPanel = new JPanel(); |
---|
113 | JPanel topPanel = createTopPanel(jUploadPanel.getBrowseButton(), |
---|
114 | jUploadPanel.getRemoveButton(), jUploadPanel |
---|
115 | .getRemoveAllButton(), jUploadPanel); |
---|
116 | if (topPanel != null) { |
---|
117 | jUploadPanel.getJComponent().add(topPanel); |
---|
118 | topPanel.addMouseListener(jUploadPanel.getMouseListener()); |
---|
119 | } |
---|
120 | |
---|
121 | Component c = jUploadPanel.getFilePanel().getDropComponent(); |
---|
122 | // Then, we add the file list. |
---|
123 | jUploadPanel.getJComponent().add(c); |
---|
124 | c.setVisible(false); |
---|
125 | |
---|
126 | c.setBackground(Color.WHITE); |
---|
127 | |
---|
128 | dndFilesHere = new JPanel(); |
---|
129 | new DropTarget(this.dndFilesHere, jUploadPanel.getDndListener()); |
---|
130 | |
---|
131 | dndFilesHere.setLayout(new BorderLayout()); |
---|
132 | dndFilesHere.setBackground(Color.WHITE); |
---|
133 | JLabel jlabel = new JLabel( |
---|
134 | getLocalizedString("dragDirectoriesAndFilesToHere")); |
---|
135 | jlabel.setFont(jlabel.getFont().deriveFont(36f)); |
---|
136 | jlabel.setHorizontalAlignment(SwingConstants.CENTER); |
---|
137 | dndFilesHere.add(jlabel, BorderLayout.CENTER); |
---|
138 | jUploadPanel.getJComponent().add(dndFilesHere); |
---|
139 | |
---|
140 | // The progress panel contains the progress bar, and the upload and stop |
---|
141 | // buttons. |
---|
142 | progressPanel = createProgressPanel(jUploadPanel |
---|
143 | .getPreparationProgressBar(), jUploadPanel |
---|
144 | .getUploadProgressBar(), jUploadPanel.getUploadButton(), |
---|
145 | jUploadPanel.getStopButton(), jUploadPanel); |
---|
146 | jUploadPanel.getJComponent().add(progressPanel); |
---|
147 | jUploadPanel.getJComponent().addMouseListener( |
---|
148 | jUploadPanel.getMouseListener()); |
---|
149 | |
---|
150 | progressPanel.setVisible(false); // will appear after 1st file drop |
---|
151 | progressPanel.setBackground(Color.WHITE); |
---|
152 | |
---|
153 | // Now, we add the log window. |
---|
154 | jUploadPanel.showOrHideLogWindow(); |
---|
155 | jUploadPanel.getJComponent().add(jUploadPanel.getJLogWindowPane()); |
---|
156 | |
---|
157 | // And, to finish with: the status bar. |
---|
158 | statusBar = createStatusBar(jUploadPanel.getStatusLabel(), jUploadPanel); |
---|
159 | if (null != statusBar) { |
---|
160 | jUploadPanel.getJComponent().add(statusBar); |
---|
161 | statusBar.addMouseListener(jUploadPanel.getMouseListener()); |
---|
162 | |
---|
163 | statusBar.setVisible(false); |
---|
164 | statusBar.setBackground(Color.WHITE); |
---|
165 | jUploadPanel.getStatusLabel().setText(" "); |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | /** {@inheritDoc} */ |
---|
170 | public void updateButtonState(int executionStatus) { |
---|
171 | super.updateButtonState(executionStatus); |
---|
172 | if (executionStatus == UploadPolicy.EXEC_STATUS_READY) { |
---|
173 | this.juploadContext.getUploadPanel().getRemoveButton().setVisible( |
---|
174 | true); |
---|
175 | this.dndFilesHere.setVisible(false); |
---|
176 | this.progressPanel.setVisible(true); |
---|
177 | this.statusBar.setVisible(true); |
---|
178 | this.juploadContext.getUploadPanel().getFilePanel() |
---|
179 | .getDropComponent().setVisible(true); |
---|
180 | } else if (executionStatus == UploadPolicy.EXEC_STATUS_UPLOADING) { |
---|
181 | this.juploadContext.getUploadPanel().getRemoveButton().setVisible( |
---|
182 | true); |
---|
183 | this.dndFilesHere.setVisible(false); |
---|
184 | this.progressPanel.setVisible(true); |
---|
185 | this.statusBar.setVisible(true); |
---|
186 | this.juploadContext.getUploadPanel().getFilePanel() |
---|
187 | .getDropComponent().setVisible(true); |
---|
188 | } |
---|
189 | |
---|
190 | } |
---|
191 | |
---|
192 | } |
---|