1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.io;
|
---|
3 |
|
---|
4 | import java.awt.GridBagConstraints;
|
---|
5 | import java.awt.GridBagLayout;
|
---|
6 | import java.awt.Insets;
|
---|
7 | import java.beans.PropertyChangeEvent;
|
---|
8 | import java.beans.PropertyChangeListener;
|
---|
9 |
|
---|
10 | import javax.swing.JLabel;
|
---|
11 | import javax.swing.JPanel;
|
---|
12 | import javax.swing.JProgressBar;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.gui.io.SaveLayersModel.Mode;
|
---|
15 | import org.openstreetmap.josm.gui.progress.ProgressRenderer;
|
---|
16 |
|
---|
17 | class UploadAndSaveProgressRenderer extends JPanel implements ProgressRenderer, PropertyChangeListener {
|
---|
18 |
|
---|
19 | private JLabel lblTaskTitle;
|
---|
20 | private JLabel lblCustomText;
|
---|
21 | private JProgressBar progressBar;
|
---|
22 |
|
---|
23 | protected void build() {
|
---|
24 | setLayout(new GridBagLayout());
|
---|
25 | GridBagConstraints gc = new GridBagConstraints();
|
---|
26 | gc.gridx = 0;
|
---|
27 | gc.gridy = 0;
|
---|
28 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
29 | gc.weightx = 1.0;
|
---|
30 | gc.weighty = 0.0;
|
---|
31 | gc.insets = new Insets(5,0,0,5);
|
---|
32 | add(lblTaskTitle = new JLabel(""), gc);
|
---|
33 |
|
---|
34 | gc.gridx = 0;
|
---|
35 | gc.gridy = 1;
|
---|
36 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
37 | gc.weightx = 1.0;
|
---|
38 | gc.weighty = 0.0;
|
---|
39 | gc.insets = new Insets(5,0,0,5);
|
---|
40 | add(lblCustomText = new JLabel(""), gc);
|
---|
41 |
|
---|
42 | gc.gridx = 0;
|
---|
43 | gc.gridy = 2;
|
---|
44 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
45 | gc.weightx = 1.0;
|
---|
46 | gc.weighty = 0.0;
|
---|
47 | gc.insets = new Insets(5,0,0,5);
|
---|
48 | add(progressBar = new JProgressBar(JProgressBar.HORIZONTAL), gc);
|
---|
49 | }
|
---|
50 |
|
---|
51 | public UploadAndSaveProgressRenderer() {
|
---|
52 | build();
|
---|
53 | // initially not visible
|
---|
54 | setVisible(false);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void setCustomText(String message) {
|
---|
58 | lblCustomText.setText(message);
|
---|
59 | repaint();
|
---|
60 | }
|
---|
61 |
|
---|
62 | public void setIndeterminate(boolean indeterminate) {
|
---|
63 | progressBar.setIndeterminate(indeterminate);
|
---|
64 | repaint();
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void setMaximum(int maximum) {
|
---|
68 | progressBar.setMaximum(maximum);
|
---|
69 | repaint();
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void setTaskTitle(String taskTitle) {
|
---|
73 | lblTaskTitle.setText(taskTitle);
|
---|
74 | repaint();
|
---|
75 | }
|
---|
76 |
|
---|
77 | public void setValue(int value) {
|
---|
78 | progressBar.setValue(value);
|
---|
79 | repaint();
|
---|
80 | }
|
---|
81 |
|
---|
82 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
83 | if (evt.getPropertyName().equals(SaveLayersModel.MODE_PROP)) {
|
---|
84 | Mode mode = (Mode)evt.getNewValue();
|
---|
85 | switch(mode) {
|
---|
86 | case EDITING_DATA: setVisible(false); break;
|
---|
87 | case UPLOADING_AND_SAVING: setVisible(true); break;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | getParent().validate();
|
---|
91 | }
|
---|
92 | }
|
---|