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

Last change on this file since 10490 was 10438, checked in by stoecker, 8 years ago

see #12994 - Old style SideButton

  • 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.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;
24import org.openstreetmap.josm.tools.ImageProvider;
25
26/**
27 * This panel allows to enter the ID of single changeset and to download
28 * the respective changeset.
29 * @since 2689
30 */
31public class SingleChangesetDownloadPanel extends JPanel {
32
33 private final ChangesetIdTextField tfChangesetId = new ChangesetIdTextField();
34
35 /**
36 * Constructs a new {@link SingleChangesetDownloadPanel}
37 */
38 public SingleChangesetDownloadPanel() {
39 build();
40 }
41
42 protected void build() {
43 setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
44 setBorder(
45 BorderFactory.createCompoundBorder(
46 BorderFactory.createLineBorder(Color.GRAY),
47 BorderFactory.createEmptyBorder(0, 3, 0, 3)
48 )
49 );
50
51 add(new JLabel(tr("Changeset ID: ")));
52 add(tfChangesetId);
53 tfChangesetId.setToolTipText(tr("Enter a changeset id"));
54 SelectAllOnFocusGainedDecorator.decorate(tfChangesetId);
55
56 DownloadAction actDownload = new DownloadAction();
57 SideButton btn = new SideButton(actDownload);
58 tfChangesetId.addActionListener(actDownload);
59 tfChangesetId.getDocument().addDocumentListener(actDownload);
60 add(btn);
61
62 if (Main.pref.getBoolean("downloadchangeset.autopaste", true)) {
63 tfChangesetId.tryToPasteFromClipboard();
64 }
65 }
66
67 /**
68 * Replies the changeset id entered in this panel. 0 if no changeset id
69 * or an invalid changeset id is currently entered.
70 *
71 * @return the changeset id entered in this panel
72 */
73 public int getChangesetId() {
74 return tfChangesetId.getChangesetId();
75 }
76
77 /**
78 * Downloads the single changeset from the OSM API
79 */
80 class DownloadAction extends AbstractAction implements DocumentListener {
81
82 DownloadAction() {
83 new ImageProvider("dialogs/changeset", "downloadchangesetcontent").getResource().attachImageIcon(this);
84 putValue(SHORT_DESCRIPTION, tr("Download the changeset with the specified id, including the changeset content"));
85 updateEnabledState();
86 }
87
88 @Override
89 public void actionPerformed(ActionEvent arg0) {
90 if (!isEnabled())
91 return;
92 int id = getChangesetId();
93 if (id == 0)
94 return;
95 ChangesetContentDownloadTask task = new ChangesetContentDownloadTask(
96 SingleChangesetDownloadPanel.this,
97 Collections.singleton(id)
98 );
99 ChangesetCacheManager.getInstance().runDownloadTask(task);
100 }
101
102 protected void updateEnabledState() {
103 setEnabled(tfChangesetId.readIds() && !Main.isOffline(OnlineResource.OSM_API));
104 }
105
106 @Override
107 public void changedUpdate(DocumentEvent arg0) {
108 updateEnabledState();
109 }
110
111 @Override
112 public void insertUpdate(DocumentEvent arg0) {
113 updateEnabledState();
114 }
115
116 @Override
117 public void removeUpdate(DocumentEvent arg0) {
118 updateEnabledState();
119 }
120 }
121}
Note: See TracBrowser for help on using the repository browser.