source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/SingleChangesetDownloadPanel.java@ 12846

Last change on this file since 12846 was 12846, checked in by bastiK, 7 years ago

see #15229 - use Config.getPref() wherever possible

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