1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
44
45
46
47
48
49
50
51 public class SuperSimpleUploadPolicy extends DefaultUploadPolicy {
52
53
54
55
56
57
58
59
60
61
62
63
64 public SuperSimpleUploadPolicy(JUploadContext juploadContext)
65 throws JUploadException {
66 super(juploadContext);
67 }
68
69
70
71
72
73
74
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
84 jPanel.add(remove);
85 remove.setVisible(false);
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
101
102
103
104
105 public void addComponentsToJUploadPanel(JUploadPanel jUploadPanel) {
106
107 jUploadPanel.getJComponent().setLayout(
108 new BoxLayout(jUploadPanel.getJComponent(), BoxLayout.Y_AXIS));
109
110
111
112
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
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
141
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);
151 progressPanel.setBackground(Color.WHITE);
152
153
154 jUploadPanel.showOrHideLogWindow();
155 jUploadPanel.getJComponent().add(jUploadPanel.getJLogWindowPane());
156
157
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
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 }