1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.changeset;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.awt.FlowLayout;
|
---|
8 | import java.awt.event.ActionEvent;
|
---|
9 | import java.util.Collections;
|
---|
10 |
|
---|
11 | import javax.swing.AbstractAction;
|
---|
12 | import javax.swing.BorderFactory;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JPanel;
|
---|
15 | import javax.swing.event.DocumentEvent;
|
---|
16 | import javax.swing.event.DocumentListener;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 | import org.openstreetmap.josm.gui.SideButton;
|
---|
20 | import org.openstreetmap.josm.gui.widgets.ChangesetIdTextField;
|
---|
21 | import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
|
---|
22 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * This panel allows to enter the ID of single changeset and to download
|
---|
26 | * the respective changeset.
|
---|
27 | *
|
---|
28 | */
|
---|
29 | public class SingleChangesetDownloadPanel extends JPanel {
|
---|
30 |
|
---|
31 | private ChangesetIdTextField tfChangesetId;
|
---|
32 | private DownloadAction actDownload;
|
---|
33 |
|
---|
34 | protected void build() {
|
---|
35 | setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
|
---|
36 | setBorder(
|
---|
37 | BorderFactory.createCompoundBorder(
|
---|
38 | BorderFactory.createLineBorder(Color.GRAY),
|
---|
39 | BorderFactory.createEmptyBorder(0,3,0,3)
|
---|
40 | )
|
---|
41 | );
|
---|
42 |
|
---|
43 | add(new JLabel(tr("Changeset ID: ")));
|
---|
44 | add(tfChangesetId = new ChangesetIdTextField());
|
---|
45 | tfChangesetId.setToolTipText(tr("Enter a changeset id"));
|
---|
46 | SelectAllOnFocusGainedDecorator.decorate(tfChangesetId);
|
---|
47 |
|
---|
48 | actDownload = new DownloadAction();
|
---|
49 | SideButton btn = new SideButton(actDownload);
|
---|
50 | tfChangesetId.addActionListener(actDownload);
|
---|
51 | tfChangesetId.getDocument().addDocumentListener(actDownload);
|
---|
52 | add(btn);
|
---|
53 |
|
---|
54 | if (Main.pref.getBoolean("downloadchangeset.autopaste", true)) {
|
---|
55 | tfChangesetId.tryToPasteFromClipboard();
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Constructs a new {@link SingleChangesetDownloadPanel}
|
---|
61 | */
|
---|
62 | public SingleChangesetDownloadPanel() {
|
---|
63 | build();
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Replies the changeset id entered in this panel. 0 if no changeset id
|
---|
68 | * or an invalid changeset id is currently entered.
|
---|
69 | *
|
---|
70 | * @return the changeset id entered in this panel
|
---|
71 | */
|
---|
72 | public int getChangesetId() {
|
---|
73 | return tfChangesetId.getChangesetId();
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Downloads the single changeset from the OSM API
|
---|
78 | */
|
---|
79 | class DownloadAction extends AbstractAction implements DocumentListener{
|
---|
80 |
|
---|
81 | public DownloadAction() {
|
---|
82 | putValue(SMALL_ICON, ImageProvider.get("dialogs/changeset", "downloadchangesetcontent"));
|
---|
83 | putValue(SHORT_DESCRIPTION, tr("Download the changeset with the specified id, including the changeset content"));
|
---|
84 | updateEnabledState();
|
---|
85 | }
|
---|
86 |
|
---|
87 | public void actionPerformed(ActionEvent arg0) {
|
---|
88 | if (!isEnabled())
|
---|
89 | return;
|
---|
90 | int id = getChangesetId();
|
---|
91 | if (id == 0) return;
|
---|
92 | ChangesetContentDownloadTask task = new ChangesetContentDownloadTask(
|
---|
93 | SingleChangesetDownloadPanel.this,
|
---|
94 | Collections.singleton(id)
|
---|
95 | );
|
---|
96 | ChangesetCacheManager.getInstance().runDownloadTask(task);
|
---|
97 | }
|
---|
98 |
|
---|
99 | protected void updateEnabledState() {
|
---|
100 | setEnabled(tfChangesetId.readIds());
|
---|
101 | }
|
---|
102 |
|
---|
103 | public void changedUpdate(DocumentEvent arg0) {
|
---|
104 | updateEnabledState();
|
---|
105 | }
|
---|
106 |
|
---|
107 | public void insertUpdate(DocumentEvent arg0) {
|
---|
108 | updateEnabledState();
|
---|
109 | }
|
---|
110 |
|
---|
111 | public void removeUpdate(DocumentEvent arg0) {
|
---|
112 | updateEnabledState();
|
---|
113 | }
|
---|
114 | }
|
---|
115 | }
|
---|