Changeset 6448 in josm


Ignore:
Timestamp:
2013-12-06T22:27:39+01:00 (6 years ago)
Author:
simon04
Message:

fix #3626 - Show history for any object in history dialog

If no object is selected, the objects are selected by id via dialog.

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  
    5656
    5757        DownloadObjectDialog dialog = new DownloadObjectDialog();
    58         if (dialog.showDialog().getValue() != 1) return;
     58        if (dialog.showDialog().getValue() != dialog.getContinueButtonIndex()) return;
    5959
    6060        processItems(dialog.isNewLayerRequested(), dialog.getOsmIds(), dialog.isReferrersRequested(), dialog.isFullRelationRequested());
  • trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java

    r6380 r6448  
    44import java.awt.event.ActionEvent;
    55import java.awt.event.KeyEvent;
    6 import java.util.Collection;
    76
    87import org.openstreetmap.josm.Main;
    98import org.openstreetmap.josm.data.osm.DataSet;
    10 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     9import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
    1110import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager;
    1211import org.openstreetmap.josm.tools.Shortcut;
     
    2120                tr("Display history information about OSM ways, nodes, or relations."),
    2221                Shortcut.registerShortcut("core:historyinfo",
    23                 tr("History"), KeyEvent.VK_H, Shortcut.CTRL), false);
     22                        tr("History"), KeyEvent.VK_H, Shortcut.CTRL), false);
    2423        putValue("help", ht("/Action/ObjectHistory"));
    2524        putValue("toolbar", "action/historyinfo");
    2625        Main.toolbar.register(this);
     26        setEnabled(true);
    2727    }
    2828
     
    3030    public void actionPerformed(ActionEvent ae) {
    3131        DataSet set = getCurrentDataSet();
    32         if (set != null) {
     32        if (set != null && !set.getAllSelected().isEmpty()) {
    3333            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            }
    3439        }
    3540    }
    3641
    37     @Override
    38     public void updateEnabledState() {
    39         if (getCurrentDataSet() == null) {
    40             setEnabled(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();
    4348        }
    4449    }
    4550
    46     @Override
    47     protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    48         setEnabled(!selection.isEmpty());
    49     }
    5051}
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadObjectDialog.java

    r5886 r6448  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.trc;
    65
    76import java.awt.Component;
    8 import java.awt.Dimension;
    97import java.awt.event.ItemEvent;
    108import java.awt.event.ItemListener;
    11 import java.awt.event.KeyEvent;
    129import 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;
     10import java.util.Arrays;
     11import java.util.Collection;
    1712
    18 import javax.swing.BorderFactory;
    19 import javax.swing.GroupLayout;
    2013import 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;
    2714
    2815import org.openstreetmap.josm.Main;
    2916import 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;
     17import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
    3818
    3919/**
     
    4121 * @since 5765
    4222 */
    43 public class DownloadObjectDialog extends ExtendedDialog implements WindowListener {
     23public class DownloadObjectDialog extends OsmIdSelectionDialog {
    4424
    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    
    5025    protected final JCheckBox referrers = new JCheckBox(tr("Download referrers (parent relations)"));
    5126    protected final JCheckBox fullRel   = new JCheckBox(tr("Download relation members"));
    5227    protected final JCheckBox newLayer  = new JCheckBox(tr("Separate Layer"));
    53    
     28
    5429    /**
    5530     * Constructs a new DownloadObjectDialog with Main.parent as parent component.
     
    6439     */
    6540    public DownloadObjectDialog(Component parent) {
    66         super(parent, tr("Download object"), new String[] {tr("Download object"), tr("Cancel")});
     41        super(parent, tr("Download object"), new String[]{tr("Download object"), tr("Cancel")});
    6742        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 */);
    6849    }
    69    
    70     protected void init() {
    71         GroupLayout layout = new GroupLayout(panel);
    72         panel.setLayout(layout);
    73         layout.setAutoCreateGaps(true);
    74         layout.setAutoCreateContainerGaps(true);
    7550
    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() {
    9552        newLayer.setToolTipText(tr("Select if the data should be downloaded into a new layer"));
    9653        newLayer.setSelected(Main.pref.getBoolean("download.newlayer"));
    97        
     54
    9855        referrers.setToolTipText(tr("Select if the referrers of the object should be downloaded as well, i.e.,"
    9956                + "parent relations and for nodes, additionally, parent ways"));
    10057        referrers.setSelected(Main.pref.getBoolean("downloadprimitive.referrers", true));
    101        
     58
    10259        fullRel.setToolTipText(tr("Select if the members of a relation should be downloaded as well"));
    10360        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         );
    12261
    12362        cbType.addItemListener(new ItemListener() {
    12463            @Override
    12564            public void itemStateChanged(ItemEvent e) {
    126                 tfId.setType(cbType.getType());
    127                 tfId.performValidation();
    12865                referrers.setText(cbType.getType() == OsmPrimitiveType.NODE
    12966                        ? tr("Download referrers (parent relations and ways)")
     
    13269        });
    13370
    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);
    14972    }
    15073
    151     @Override
    152     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 preferences
    174      *
    175      * @param cbHistory
    176      */
    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 preferences
    186      * @param cbHistory
    187      */
    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    
    21374    /**
    21475     * Determines if a new layer has been requested.
     
    21879        return newLayer.isSelected();
    21980    }
    220    
     81
    22182    /**
    22283     * Determines if relation members have been requested.
     
    22687        return fullRel.isSelected();
    22788    }
    228    
     89
    22990    /**
    23091     * Determines if referrers have been requested.
     
    23495        return referrers.isSelected();
    23596    }
    236    
    237     /**
    238      * Gets the requested OSM object IDs.
    239      * @return The list of requested OSM object IDs
    240      */
    241     public final List<PrimitiveId> getOsmIds() {
    242         return tfId.getIds();
    243     }
    24497
    245     @Override public void windowClosed(WindowEvent e) {
     98    @Override
     99    public void windowClosed(WindowEvent e) {
     100        super.windowClosed(e);
    246101        if (e != null && e.getComponent() == this && getValue() == 1) {
    247             Main.pref.putInteger("downloadprimitive.lasttype", cbType.getSelectedIndex());
    248102            Main.pref.put("downloadprimitive.referrers", referrers.isSelected());
    249103            Main.pref.put("downloadprimitive.full", fullRel.isSelected());
    250104            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_MESSAGE
    258                 );
    259                 return;
    260             }
    261            
    262             remindPrimitivesHistory(cbId);
    263105        }
    264106    }
    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) {}
    272107}
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java

    r6316 r6448  
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.data.osm.OsmPrimitive;
     19import org.openstreetmap.josm.data.osm.PrimitiveId;
    1920import org.openstreetmap.josm.data.osm.history.History;
    2021import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
     
    139140    }
    140141
    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);
    143144        if (notNewPrimitives.isEmpty()) {
    144145            JOptionPane.showMessageDialog(
     
    150151        }
    151152
    152         Collection<OsmPrimitive> toLoad = Utils.filter(primitives, unloadedHistoryPredicate);
     153        Collection<PrimitiveId> toLoad = Utils.filter(primitives, unloadedHistoryPredicate);
    153154        if (!toLoad.isEmpty()) {
    154155            HistoryLoadTask task = new HistoryLoadTask();
    155             task.add(notNewPrimitives);
     156            for (PrimitiveId p : notNewPrimitives) {
     157                task.add(p);
     158            }
    156159            Main.worker.submit(task);
    157160        }
     
    162165            public void run() {
    163166                try {
    164                     for (OsmPrimitive p : notNewPrimitives) {
    165                         final History h = HistoryDataSet.getInstance().getHistory(p.getPrimitiveId());
     167                    for (PrimitiveId p : notNewPrimitives) {
     168                        final History h = HistoryDataSet.getInstance().getHistory(p);
    166169                        if (h == null) {
    167170                            continue;
     
    183186    }
    184187
    185     private final Predicate<OsmPrimitive> unloadedHistoryPredicate = new Predicate<OsmPrimitive>() {
     188    private final Predicate<PrimitiveId> unloadedHistoryPredicate = new Predicate<PrimitiveId>() {
    186189
    187190        HistoryDataSet hds = HistoryDataSet.getInstance();
    188191
    189192        @Override
    190         public boolean evaluate(OsmPrimitive p) {
    191             History h = hds.getHistory(p.getPrimitiveId());
     193        public boolean evaluate(PrimitiveId p) {
     194            History h = hds.getHistory(p);
    192195            if (h == null)
    193196                // reload if the history is not in the cache yet
     
    201204    };
    202205
    203     private final Predicate<OsmPrimitive> notNewPredicate = new Predicate<OsmPrimitive>() {
     206    private final Predicate<PrimitiveId> notNewPredicate = new Predicate<PrimitiveId>() {
    204207
    205208        @Override
    206         public boolean evaluate(OsmPrimitive p) {
     209        public boolean evaluate(PrimitiveId p) {
    207210            return !p.isNew();
    208211        }
Note: See TracChangeset for help on using the changeset viewer.