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

Last change on this file since 10179 was 10179, checked in by Don-vip, 8 years ago

sonar - squid:AssignmentInSubExpressionCheck - Assignments should not be made from within sub-expressions

  • Property svn:eol-style set to native
File size: 3.8 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.JLabel;
14import javax.swing.JPanel;
15import javax.swing.event.DocumentEvent;
16import javax.swing.event.DocumentListener;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.actions.downloadtasks.ChangesetContentDownloadTask;
20import org.openstreetmap.josm.gui.SideButton;
21import org.openstreetmap.josm.gui.widgets.ChangesetIdTextField;
22import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
23import org.openstreetmap.josm.io.OnlineResource;
24
25/**
26 * This panel allows to enter the ID of single changeset and to download
27 * the respective changeset.
28 * @since 2689
29 */
30public class SingleChangesetDownloadPanel extends JPanel {
31
32 private final ChangesetIdTextField tfChangesetId = new ChangesetIdTextField();
33
34 /**
35 * Constructs a new {@link SingleChangesetDownloadPanel}
36 */
37 public SingleChangesetDownloadPanel() {
38 build();
39 }
40
41 protected void build() {
42 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
43 setBorder(
44 BorderFactory.createCompoundBorder(
45 BorderFactory.createLineBorder(Color.GRAY),
46 BorderFactory.createEmptyBorder(0, 3, 0, 3)
47 )
48 );
49
50 add(new JLabel(tr("Changeset ID: ")));
51 add(tfChangesetId);
52 tfChangesetId.setToolTipText(tr("Enter a changeset id"));
53 SelectAllOnFocusGainedDecorator.decorate(tfChangesetId);
54
55 DownloadAction actDownload = new DownloadAction();
56 SideButton btn = new SideButton(actDownload);
57 tfChangesetId.addActionListener(actDownload);
58 tfChangesetId.getDocument().addDocumentListener(actDownload);
59 add(btn);
60
61 if (Main.pref.getBoolean("downloadchangeset.autopaste", true)) {
62 tfChangesetId.tryToPasteFromClipboard();
63 }
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 DownloadAction() {
82 putValue(SMALL_ICON, ChangesetCacheManager.DOWNLOAD_CONTENT_ICON);
83 putValue(SHORT_DESCRIPTION, tr("Download the changeset with the specified id, including the changeset content"));
84 updateEnabledState();
85 }
86
87 @Override
88 public void actionPerformed(ActionEvent arg0) {
89 if (!isEnabled())
90 return;
91 int id = getChangesetId();
92 if (id == 0)
93 return;
94 ChangesetContentDownloadTask task = new ChangesetContentDownloadTask(
95 SingleChangesetDownloadPanel.this,
96 Collections.singleton(id)
97 );
98 ChangesetCacheManager.getInstance().runDownloadTask(task);
99 }
100
101 protected void updateEnabledState() {
102 setEnabled(tfChangesetId.readIds() && !Main.isOffline(OnlineResource.OSM_API));
103 }
104
105 @Override
106 public void changedUpdate(DocumentEvent arg0) {
107 updateEnabledState();
108 }
109
110 @Override
111 public void insertUpdate(DocumentEvent arg0) {
112 updateEnabledState();
113 }
114
115 @Override
116 public void removeUpdate(DocumentEvent arg0) {
117 updateEnabledState();
118 }
119 }
120}
Note: See TracBrowser for help on using the repository browser.