• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/exist-core/src/main/java/org/exist/client/UploadDialog.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.client;
50

51
import java.awt.GridBagConstraints;
52
import java.awt.GridBagLayout;
53
import java.awt.Insets;
54
import java.util.Observable;
55
import java.util.Observer;
56

57
import javax.swing.BorderFactory;
58
import javax.swing.JButton;
59
import javax.swing.JFrame;
60
import javax.swing.JLabel;
61
import javax.swing.JProgressBar;
62
import javax.swing.JScrollPane;
63
import javax.swing.JTextArea;
64
import javax.swing.JTextField;
65

66
import org.exist.storage.ElementIndex;
67
import org.exist.util.ProgressIndicator;
68

69
/**
70
 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
71
 */
72
class UploadDialog extends JFrame {
73

74
        private static final long serialVersionUID = 1L;
75

76
        JTextField currentFile;
77
        JTextField currentDir;
78
        JLabel currentSize;
79
        JTextArea messages;
80
        JProgressBar progress;
81
        JProgressBar byDirProgress;
82

83
        boolean cancelled = false;
×
84
        final JButton closeBtn;
85
        
86
        public UploadDialog() {
87
                super(Messages.getString("UploadDialog.0")); //$NON-NLS-1$
×
88
                final GridBagLayout grid = new GridBagLayout();
×
89
                getContentPane().setLayout(grid);
×
90
                final GridBagConstraints c = new GridBagConstraints();
×
91
                c.insets = new Insets(5, 5, 5, 5);
×
92

93
                JLabel label = new JLabel(Messages.getString("UploadDialog.1")); //$NON-NLS-1$
×
94
        this.setIconImage(InteractiveClient.getElementalIcon(getClass()).getImage());
×
95
                c.gridx = 0;
×
96
                c.gridy = 0;
×
97
                c.anchor = GridBagConstraints.WEST;
×
98
                c.fill = GridBagConstraints.NONE;
×
99
                c.weightx = 0;
×
100
                grid.setConstraints(label, c);
×
101
                getContentPane().add(label);
×
102

103
                byDirProgress = new JProgressBar();
×
104
                byDirProgress.setStringPainted(true);
×
105
                byDirProgress.setString(Messages.getString("UploadDialog.2")); //$NON-NLS-1$
×
106
                byDirProgress.setIndeterminate(true);
×
107
                c.gridx = 1;
×
108
                c.gridy = 0;
×
109
                c.anchor = GridBagConstraints.EAST;
×
110
                c.fill = GridBagConstraints.HORIZONTAL;
×
111
                c.weightx = 1;
×
112
                grid.setConstraints(byDirProgress, c);
×
113
                getContentPane().add(byDirProgress);
×
114

115
                label = new JLabel(Messages.getString("UploadDialog.3")); //$NON-NLS-1$
×
116
                c.gridx = 0;
×
117
                c.gridy = 1;
×
118
                c.anchor = GridBagConstraints.WEST;
×
119
                c.fill = GridBagConstraints.NONE;
×
120
                c.weightx = 0;
×
121
                grid.setConstraints(label, c);
×
122
                getContentPane().add(label);
×
123

124
                currentDir = new JTextField(30);
×
125
                currentDir.setEditable(false);
×
126
                c.gridx = 1;
×
127
                c.gridy = 1;
×
128
                c.anchor = GridBagConstraints.EAST;
×
129
                c.fill = GridBagConstraints.HORIZONTAL;
×
130
                c.weightx = 1;
×
131
                grid.setConstraints(currentDir, c);
×
132
                getContentPane().add(currentDir);
×
133

134
                label = new JLabel(Messages.getString("UploadDialog.4")); //$NON-NLS-1$
×
135
                c.gridx = 0;
×
136
                c.gridy = 2;
×
137
                c.anchor = GridBagConstraints.WEST;
×
138
                c.fill = GridBagConstraints.NONE;
×
139
                c.weightx = 0;
×
140
                grid.setConstraints(label, c);
×
141
                getContentPane().add(label);
×
142

143
                currentFile = new JTextField(30);
×
144
                currentFile.setEditable(false);
×
145
                c.gridx = 1;
×
146
                c.gridy = 2;
×
147
                c.anchor = GridBagConstraints.EAST;
×
148
                c.fill = GridBagConstraints.HORIZONTAL;
×
149
                c.weightx = 1;
×
150
                grid.setConstraints(currentFile, c);
×
151
                getContentPane().add(currentFile);
×
152

153
                label = new JLabel(Messages.getString("UploadDialog.5")); //$NON-NLS-1$
×
154
                c.gridx = 0;
×
155
                c.gridy = 3;
×
156
                c.anchor = GridBagConstraints.WEST;
×
157
                c.fill = GridBagConstraints.NONE;
×
158
                c.weightx = 0;
×
159
                grid.setConstraints(label, c);
×
160
                getContentPane().add(label);
×
161

162
                currentSize = new JLabel(Messages.getString("UploadDialog.6")); //$NON-NLS-1$
×
163
                c.gridx = 1;
×
164
                c.gridy = 3;
×
165
                c.anchor = GridBagConstraints.EAST;
×
166
                c.fill = GridBagConstraints.HORIZONTAL;
×
167
                c.weightx = 1;
×
168
                grid.setConstraints(currentSize, c);
×
169
                getContentPane().add(currentSize);
×
170

171
                final JLabel status = new JLabel(Messages.getString("UploadDialog.7")); //$NON-NLS-1$
×
172
                c.gridx = 0;
×
173
                c.gridy = 4;
×
174
                c.anchor = GridBagConstraints.WEST;
×
175
                c.fill = GridBagConstraints.NONE;
×
176
                c.weightx = 0;
×
177
                grid.setConstraints(status, c);
×
178
                getContentPane().add(status);
×
179

180
                progress = new JProgressBar();
×
181
                progress.setIndeterminate(true);
×
182
                progress.setStringPainted(true);
×
183
                c.gridx = 1;
×
184
                c.gridy = 4;
×
185
                c.anchor = GridBagConstraints.EAST;
×
186
                c.fill = GridBagConstraints.HORIZONTAL;
×
187
                c.weightx = 1;
×
188
                grid.setConstraints(progress, c);
×
189
                getContentPane().add(progress);
×
190

191
                messages = new JTextArea(5, 50);
×
192
                messages.setEditable(false);
×
193
                messages.setLineWrap(true);
×
194
                final JScrollPane scroll =
×
195
                        new JScrollPane(
×
196
                                messages,
×
197
                                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
×
198
                                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
×
199
                scroll.setBorder(BorderFactory.createTitledBorder("Messages")); //$NON-NLS-1$
×
200
                c.gridx = 0;
×
201
                c.gridy = 5;
×
202
                c.gridwidth = 2;
×
203
                c.anchor = GridBagConstraints.WEST;
×
204
                c.fill = GridBagConstraints.BOTH;
×
205
                c.weightx = 1;
×
206
                c.weighty = 1;
×
207
                grid.setConstraints(scroll, c);
×
208
                getContentPane().add(scroll);
×
209

210
                closeBtn = new JButton(Messages.getString("UploadDialog.9")); //$NON-NLS-1$
×
211
                closeBtn.addActionListener(e -> {
×
212
            if (Messages.getString("UploadDialog.20").equals(closeBtn.getText())) //$NON-NLS-1$
×
213
                {setVisible(false);}
×
214
            else {
215
                cancelled = true;
×
216
                closeBtn.setText(Messages.getString("UploadDialog.11")); //$NON-NLS-1$
×
217
            }
218
        });
×
219
                c.gridx = 0;
×
220
                c.gridy = 6;
×
221
                c.gridwidth = 2;
×
222
                c.anchor = GridBagConstraints.EAST;
×
223
                c.fill = GridBagConstraints.NONE;
×
224
                c.weightx = 0;
×
225
                c.weighty = 0;
×
226
                grid.setConstraints(closeBtn, c);
×
227
                getContentPane().add(closeBtn);
×
228
                
229
                pack();
×
230
        }
×
231

232
        public Observer getObserver() {
233
                return new UploadProgressObserver();
×
234
        }
235

236
        public void setCurrent(String label) {
237
                currentFile.setText(label);
×
238
        }
×
239

240
        public void setCurrentDir(String dir) {
241
                currentDir.setText(dir);
×
242
        }
×
243

244
        public void setCurrentSize(long size) {
245
                if (size >= 1024)
×
246
                        {currentSize.setText(String.valueOf(size / 1024) + Messages.getString("UploadDialog.12"));} //$NON-NLS-1$
×
247
                else
248
                        {currentSize.setText(String.valueOf(size));}
×
249
        }
×
250

251
        public void setTotalSize(long size) {
252
                byDirProgress.setIndeterminate(false);
×
253
                byDirProgress.setString(null);
×
254
                byDirProgress.setMinimum(0);
×
255
                byDirProgress.setValue(0);
×
256
                byDirProgress.setMaximum((int) (size / 1024));
×
257
        }
×
258

259
        public void setStoredSize(long count) {
260
                byDirProgress.setValue((int) (count / 1024));
×
261
        }
×
262

263
        public boolean isCancelled() {
264
                return cancelled;
×
265
        }
266
        
267
        public void uploadCompleted() {
268
                closeBtn.setText(Messages.getString("UploadDialog.13")); //$NON-NLS-1$
×
269
                progress.setIndeterminate(false);
×
270
                progress.setValue(100);
×
271
                progress.setString(Messages.getString("UploadDialog.14")); //$NON-NLS-1$
×
272
                byDirProgress.setIndeterminate(false);
×
273
                byDirProgress.setString(null);
×
274
                byDirProgress.setValue(byDirProgress.getMaximum());
×
275
        }
×
276
        
277
        public void showMessage(String msg) {
278
                messages.append(msg + Messages.getString("UploadDialog.15")); //$NON-NLS-1$
×
279
                messages.setCaretPosition(messages.getDocument().getLength());
×
280
        }
×
281

282
        public void reset() {
283
                progress.setString(Messages.getString("UploadDialog.16")); //$NON-NLS-1$
×
284
                progress.setIndeterminate(true);
×
285
        }
×
286

287
        class UploadProgressObserver implements Observer {
×
288

289
                public void update(Observable o, Object arg) {
290
                        progress.setIndeterminate(false);
×
291
                        final ProgressIndicator ind = (ProgressIndicator) arg;
×
292
                        progress.setValue(ind.getPercentage());
×
293

294
                        if (o instanceof ElementIndex)
×
295
                                {progress.setString(Messages.getString("UploadDialog.18"));} //$NON-NLS-1$
×
296
                        else
297
                                {progress.setString(Messages.getString("UploadDialog.19"));} //$NON-NLS-1$
×
298
                }
×
299

300
        }
301
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc