- Timestamp:
- 2013-12-06T22:27:39+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java
r6313 r6448 56 56 57 57 DownloadObjectDialog dialog = new DownloadObjectDialog(); 58 if (dialog.showDialog().getValue() != 1) return;58 if (dialog.showDialog().getValue() != dialog.getContinueButtonIndex()) return; 59 59 60 60 processItems(dialog.isNewLayerRequested(), dialog.getOsmIds(), dialog.isReferrersRequested(), dialog.isFullRelationRequested()); -
trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java
r6380 r6448 4 4 import java.awt.event.ActionEvent; 5 5 import java.awt.event.KeyEvent; 6 import java.util.Collection;7 6 8 7 import org.openstreetmap.josm.Main; 9 8 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm. data.osm.OsmPrimitive;9 import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog; 11 10 import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager; 12 11 import org.openstreetmap.josm.tools.Shortcut; … … 21 20 tr("Display history information about OSM ways, nodes, or relations."), 22 21 Shortcut.registerShortcut("core:historyinfo", 23 tr("History"), KeyEvent.VK_H, Shortcut.CTRL), false);22 tr("History"), KeyEvent.VK_H, Shortcut.CTRL), false); 24 23 putValue("help", ht("/Action/ObjectHistory")); 25 24 putValue("toolbar", "action/historyinfo"); 26 25 Main.toolbar.register(this); 26 setEnabled(true); 27 27 } 28 28 … … 30 30 public void actionPerformed(ActionEvent ae) { 31 31 DataSet set = getCurrentDataSet(); 32 if (set != null ) {32 if (set != null && !set.getAllSelected().isEmpty()) { 33 33 HistoryBrowserDialogManager.getInstance().showHistory(set.getAllSelected()); 34 } else { 35 HistoryObjectIDDialog dialog = new HistoryObjectIDDialog(); 36 if (dialog.showDialog().getValue() == dialog.getContinueButtonIndex()) { 37 HistoryBrowserDialogManager.getInstance().showHistory(dialog.getOsmIds()); 38 } 34 39 } 35 40 } 36 41 37 @Override38 public void updateEnabledState() { 39 if (getCurrentDataSet() == null) {40 s etEnabled(false);41 } else {42 updateEnabledState(getCurrentDataSet().getAllSelected());42 public static class HistoryObjectIDDialog extends OsmIdSelectionDialog { 43 44 public HistoryObjectIDDialog() { 45 super(Main.parent, tr("Show history"), new String[]{tr("Show history"), tr("Cancel")}); 46 setButtonIcons(new String[]{"dialogs/history.png", "cancel.png"}); 47 init(); 43 48 } 44 49 } 45 50 46 @Override47 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {48 setEnabled(!selection.isEmpty());49 }50 51 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadObjectDialog.java
r5886 r6448 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trc;6 5 7 6 import java.awt.Component; 8 import java.awt.Dimension;9 7 import java.awt.event.ItemEvent; 10 8 import java.awt.event.ItemListener; 11 import java.awt.event.KeyEvent;12 9 import java.awt.event.WindowEvent; 13 import java.awt.event.WindowListener; 14 import java.util.Collections; 15 import java.util.LinkedList; 16 import java.util.List; 10 import java.util.Arrays; 11 import java.util.Collection; 17 12 18 import javax.swing.BorderFactory;19 import javax.swing.GroupLayout;20 13 import javax.swing.JCheckBox; 21 import javax.swing.JLabel;22 import javax.swing.JOptionPane;23 import javax.swing.JPanel;24 import javax.swing.KeyStroke;25 import javax.swing.border.EtchedBorder;26 import javax.swing.plaf.basic.BasicComboBoxEditor;27 14 28 15 import org.openstreetmap.josm.Main; 29 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 30 import org.openstreetmap.josm.data.osm.PrimitiveId; 31 import org.openstreetmap.josm.gui.ExtendedDialog; 32 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 33 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 34 import org.openstreetmap.josm.gui.widgets.OsmIdTextField; 35 import org.openstreetmap.josm.gui.widgets.OsmPrimitiveTypesComboBox; 36 import org.openstreetmap.josm.tools.Utils; 37 import org.openstreetmap.josm.gui.widgets.JosmTextField; 17 import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog; 38 18 39 19 /** … … 41 21 * @since 5765 42 22 */ 43 public class DownloadObjectDialog extends ExtendedDialog implements WindowListener{23 public class DownloadObjectDialog extends OsmIdSelectionDialog { 44 24 45 protected final JPanel panel = new JPanel();46 protected final OsmPrimitiveTypesComboBox cbType = new OsmPrimitiveTypesComboBox();47 protected final OsmIdTextField tfId = new OsmIdTextField();48 protected final HistoryComboBox cbId = new HistoryComboBox();49 50 25 protected final JCheckBox referrers = new JCheckBox(tr("Download referrers (parent relations)")); 51 26 protected final JCheckBox fullRel = new JCheckBox(tr("Download relation members")); 52 27 protected final JCheckBox newLayer = new JCheckBox(tr("Separate Layer")); 53 28 54 29 /** 55 30 * Constructs a new DownloadObjectDialog with Main.parent as parent component. … … 64 39 */ 65 40 public DownloadObjectDialog(Component parent) { 66 super(parent, tr("Download object"), new String[] 41 super(parent, tr("Download object"), new String[]{tr("Download object"), tr("Cancel")}); 67 42 init(); 43 setButtonIcons(new String[]{"download.png", "cancel.png"}); 44 setToolTipTexts(new String[]{ 45 tr("Start downloading"), 46 tr("Close dialog and cancel downloading") 47 }); 48 configureContextsensitiveHelp("/Action/DownloadObject", true /* show help button */); 68 49 } 69 70 protected void init() {71 GroupLayout layout = new GroupLayout(panel);72 panel.setLayout(layout);73 layout.setAutoCreateGaps(true);74 layout.setAutoCreateContainerGaps(true);75 50 76 JLabel lbl1 = new JLabel(tr("Object type:")); 77 78 cbType.addItem(trc("osm object types", "mixed")); 79 cbType.setToolTipText(tr("Choose the OSM object type")); 80 JLabel lbl2 = new JLabel(tr("Object ID:")); 81 82 cbId.setEditor(new BasicComboBoxEditor() { 83 @Override 84 protected JosmTextField createEditorComponent() { 85 return tfId; 86 } 87 }); 88 cbId.setToolTipText(tr("Enter the ID of the object that should be downloaded")); 89 restorePrimitivesHistory(cbId); 90 91 // forward the enter key stroke to the download button 92 tfId.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false)); 93 tfId.setPreferredSize(new Dimension(400, tfId.getPreferredSize().height)); 94 51 protected Collection<Component> getComponentsBeforeHelp() { 95 52 newLayer.setToolTipText(tr("Select if the data should be downloaded into a new layer")); 96 53 newLayer.setSelected(Main.pref.getBoolean("download.newlayer")); 97 54 98 55 referrers.setToolTipText(tr("Select if the referrers of the object should be downloaded as well, i.e.," 99 56 + "parent relations and for nodes, additionally, parent ways")); 100 57 referrers.setSelected(Main.pref.getBoolean("downloadprimitive.referrers", true)); 101 58 102 59 fullRel.setToolTipText(tr("Select if the members of a relation should be downloaded as well")); 103 60 fullRel.setSelected(Main.pref.getBoolean("downloadprimitive.full", true)); 104 105 HtmlPanel help = new HtmlPanel(tr("Object IDs can be separated by comma or space.<br/>"106 + " Examples: <b><ul><li>1 2 5</li><li>1,2,5</li></ul><br/></b>"107 + " In mixed mode, specify objects like this: <b>w123, n110, w12, r15</b><br/>"));108 help.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));109 110 layout.setVerticalGroup(layout.createSequentialGroup()111 .addGroup(layout.createParallelGroup()112 .addComponent(lbl1)113 .addComponent(cbType, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))114 .addGroup(layout.createParallelGroup()115 .addComponent(lbl2)116 .addComponent(cbId, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))117 .addComponent(referrers)118 .addComponent(fullRel)119 .addComponent(newLayer)120 .addComponent(help)121 );122 61 123 62 cbType.addItemListener(new ItemListener() { 124 63 @Override 125 64 public void itemStateChanged(ItemEvent e) { 126 tfId.setType(cbType.getType());127 tfId.performValidation();128 65 referrers.setText(cbType.getType() == OsmPrimitiveType.NODE 129 66 ? tr("Download referrers (parent relations and ways)") … … 132 69 }); 133 70 134 layout.setHorizontalGroup(layout.createParallelGroup() 135 .addGroup(layout.createSequentialGroup() 136 .addGroup(layout.createParallelGroup() 137 .addComponent(lbl1) 138 .addComponent(lbl2) 139 ) 140 .addGroup(layout.createParallelGroup() 141 .addComponent(cbType) 142 .addComponent(cbId)) 143 ) 144 .addComponent(referrers) 145 .addComponent(fullRel) 146 .addComponent(newLayer) 147 .addComponent(help) 148 ); 71 return Arrays.<Component>asList(referrers, fullRel, newLayer); 149 72 } 150 73 151 @Override152 public void setupDialog() {153 154 setContent(panel, false);155 setButtonIcons(new String[] {"download.png", "cancel.png"});156 setToolTipTexts(new String[] {157 tr("Start downloading"),158 tr("Close dialog and cancel downloading")159 });160 setDefaultButton(1);161 configureContextsensitiveHelp("/Action/DownloadObject", true /* show help button */);162 cbType.setSelectedIndex(Main.pref.getInteger("downloadprimitive.lasttype", 0));163 tfId.setType(cbType.getType());164 if (Main.pref.getBoolean("downloadprimitive.autopaste", true)) {165 tryToPasteFromClipboard(tfId, cbType);166 }167 168 addWindowListener(this);169 super.setupDialog();170 }171 172 /**173 * Restore the current history from the preferences174 *175 * @param cbHistory176 */177 protected void restorePrimitivesHistory(HistoryComboBox cbHistory) {178 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(getClass().getName() + ".primitivesHistory", new LinkedList<String>()));179 // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement()180 Collections.reverse(cmtHistory);181 cbHistory.setPossibleItems(cmtHistory);182 }183 184 /**185 * Remind the current history in the preferences186 * @param cbHistory187 */188 protected void remindPrimitivesHistory(HistoryComboBox cbHistory) {189 cbHistory.addCurrentItemToHistory();190 Main.pref.putCollection(getClass().getName() + ".primitivesHistory", cbHistory.getHistory());191 }192 193 protected void tryToPasteFromClipboard(OsmIdTextField tfId, OsmPrimitiveTypesComboBox cbType) {194 String buf = Utils.getClipboardContent();195 if (buf != null) {196 if (buf.contains("node")) cbType.setSelectedIndex(0);197 if (buf.contains("way")) cbType.setSelectedIndex(1);198 if (buf.contains("relation")) cbType.setSelectedIndex(2);199 String[] res = buf.split("/");200 String txt;201 if (res.length>0) {202 txt = res[res.length-1];203 if (txt.isEmpty() && txt.length()>1) txt=res[res.length-2];204 } else {205 txt=buf;206 }207 if (buf.length() <= Main.pref.getInteger("downloadprimitive.max-autopaste-length", 2000)) {208 tfId.tryToPasteFrom(txt);209 }210 }211 }212 213 74 /** 214 75 * Determines if a new layer has been requested. … … 218 79 return newLayer.isSelected(); 219 80 } 220 81 221 82 /** 222 83 * Determines if relation members have been requested. … … 226 87 return fullRel.isSelected(); 227 88 } 228 89 229 90 /** 230 91 * Determines if referrers have been requested. … … 234 95 return referrers.isSelected(); 235 96 } 236 237 /**238 * Gets the requested OSM object IDs.239 * @return The list of requested OSM object IDs240 */241 public final List<PrimitiveId> getOsmIds() {242 return tfId.getIds();243 }244 97 245 @Override public void windowClosed(WindowEvent e) { 98 @Override 99 public void windowClosed(WindowEvent e) { 100 super.windowClosed(e); 246 101 if (e != null && e.getComponent() == this && getValue() == 1) { 247 Main.pref.putInteger("downloadprimitive.lasttype", cbType.getSelectedIndex());248 102 Main.pref.put("downloadprimitive.referrers", referrers.isSelected()); 249 103 Main.pref.put("downloadprimitive.full", fullRel.isSelected()); 250 104 Main.pref.put("download.newlayer", newLayer.isSelected()); 251 252 if (!tfId.readIds()) {253 JOptionPane.showMessageDialog(getParent(),254 tr("Invalid ID list specified\n"255 + "Cannot download object."),256 tr("Information"),257 JOptionPane.INFORMATION_MESSAGE258 );259 return;260 }261 262 remindPrimitivesHistory(cbId);263 105 } 264 106 } 265 266 @Override public void windowOpened(WindowEvent e) {}267 @Override public void windowClosing(WindowEvent e) {}268 @Override public void windowIconified(WindowEvent e) {}269 @Override public void windowDeiconified(WindowEvent e) {}270 @Override public void windowActivated(WindowEvent e) {}271 @Override public void windowDeactivated(WindowEvent e) {}272 107 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
r6316 r6448 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.PrimitiveId; 19 20 import org.openstreetmap.josm.data.osm.history.History; 20 21 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; … … 139 140 } 140 141 141 public void showHistory(final Collection< OsmPrimitive> primitives) {142 final Collection< OsmPrimitive> notNewPrimitives = Utils.filter(primitives, notNewPredicate);142 public void showHistory(final Collection<? extends PrimitiveId> primitives) { 143 final Collection<? extends PrimitiveId> notNewPrimitives = Utils.filter(primitives, notNewPredicate); 143 144 if (notNewPrimitives.isEmpty()) { 144 145 JOptionPane.showMessageDialog( … … 150 151 } 151 152 152 Collection< OsmPrimitive> toLoad = Utils.filter(primitives, unloadedHistoryPredicate);153 Collection<PrimitiveId> toLoad = Utils.filter(primitives, unloadedHistoryPredicate); 153 154 if (!toLoad.isEmpty()) { 154 155 HistoryLoadTask task = new HistoryLoadTask(); 155 task.add(notNewPrimitives); 156 for (PrimitiveId p : notNewPrimitives) { 157 task.add(p); 158 } 156 159 Main.worker.submit(task); 157 160 } … … 162 165 public void run() { 163 166 try { 164 for ( OsmPrimitivep : notNewPrimitives) {165 final History h = HistoryDataSet.getInstance().getHistory(p .getPrimitiveId());167 for (PrimitiveId p : notNewPrimitives) { 168 final History h = HistoryDataSet.getInstance().getHistory(p); 166 169 if (h == null) { 167 170 continue; … … 183 186 } 184 187 185 private final Predicate< OsmPrimitive> unloadedHistoryPredicate = new Predicate<OsmPrimitive>() {188 private final Predicate<PrimitiveId> unloadedHistoryPredicate = new Predicate<PrimitiveId>() { 186 189 187 190 HistoryDataSet hds = HistoryDataSet.getInstance(); 188 191 189 192 @Override 190 public boolean evaluate( OsmPrimitivep) {191 History h = hds.getHistory(p .getPrimitiveId());193 public boolean evaluate(PrimitiveId p) { 194 History h = hds.getHistory(p); 192 195 if (h == null) 193 196 // reload if the history is not in the cache yet … … 201 204 }; 202 205 203 private final Predicate< OsmPrimitive> notNewPredicate = new Predicate<OsmPrimitive>() {206 private final Predicate<PrimitiveId> notNewPredicate = new Predicate<PrimitiveId>() { 204 207 205 208 @Override 206 public boolean evaluate( OsmPrimitivep) {209 public boolean evaluate(PrimitiveId p) { 207 210 return !p.isNew(); 208 211 }
Note:
See TracChangeset
for help on using the changeset viewer.