Ticket #6734: patch.diff

File patch.diff, 6.2 KB (added by Don-vip, 13 years ago)
  • src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java

     
    1111import java.awt.event.ActionEvent;
    1212import java.awt.event.KeyEvent;
    1313import java.lang.reflect.InvocationTargetException;
     14import java.util.Collections;
     15import java.util.LinkedList;
    1416import java.util.List;
    1517import java.util.Set;
    1618import java.util.TreeSet;
     
    2325import javax.swing.JPanel;
    2426import javax.swing.JScrollPane;
    2527import javax.swing.JTextArea;
     28import javax.swing.JTextField;
    2629import javax.swing.KeyStroke;
    2730import javax.swing.SwingUtilities;
    2831import javax.swing.border.EtchedBorder;
     32import javax.swing.plaf.basic.BasicComboBoxEditor;
    2933
    3034import org.openstreetmap.josm.Main;
    3135import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
     
    3640import org.openstreetmap.josm.gui.ExtendedDialog;
    3741import org.openstreetmap.josm.gui.io.DownloadPrimitivesTask;
    3842import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     43import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    3944import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    4045import org.openstreetmap.josm.gui.widgets.OsmIdTextField;
    4146import org.openstreetmap.josm.gui.widgets.OsmPrimitiveTypesComboBox;
     
    5661        putValue("help", ht("/Action/DownloadObject"));
    5762    }
    5863
     64    /**
     65     * Restore the current history from the preferences
     66     *
     67     * @param cbHistory
     68     */
     69    protected void restorePrimitivesHistory(HistoryComboBox cbHistory) {
     70        List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(getClass().getName() + ".primitivesHistory", new LinkedList<String>()));
     71        // we have to reverse the history, because ComboBoxHistory will reverse it again
     72        // in addElement()
     73        //
     74        Collections.reverse(cmtHistory);
     75        cbHistory.setPossibleItems(cmtHistory);
     76    }
     77
     78    /**
     79     * Remind the current history in the preferences
     80     * @param cbHistory
     81     */
     82    protected void remindPrimitivesHistory(HistoryComboBox cbHistory) {
     83        cbHistory.addCurrentItemToHistory();
     84        Main.pref.putCollection(getClass().getName() + ".primitivesHistory", cbHistory.getHistory());
     85    }
     86
    5987    public void actionPerformed(ActionEvent e) {
    6088
    6189        JPanel all = new JPanel();
     
    6694
    6795        JLabel lbl1 = new JLabel(tr("Object type:"));
    6896        OsmPrimitiveTypesComboBox cbType = new OsmPrimitiveTypesComboBox();
    69         cbType.addItem(new SimpleListItem("mixed", trc("osm object types", "mixed")));
     97        cbType.addItem(trc("osm object types", "mixed"));
    7098        cbType.setToolTipText(tr("Choose the OSM object type"));
    7199        JLabel lbl2 = new JLabel(tr("Object ID:"));
    72         OsmIdTextField tfId = new OsmIdTextField();
    73         tfId.setToolTipText(tr("Enter the ID of the object that should be downloaded"));
     100        final OsmIdTextField tfId = new OsmIdTextField();
     101        HistoryComboBox cbId = new HistoryComboBox();
     102        cbId.setEditor(new BasicComboBoxEditor() {
     103            @Override
     104            protected JTextField createEditorComponent() {
     105                return tfId;
     106            }
     107        });
     108        cbId.setToolTipText(tr("Enter the ID of the object that should be downloaded"));
     109        restorePrimitivesHistory(cbId);
    74110        // forward the enter key stroke to the download button
    75111        tfId.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false));
    76112        JCheckBox layer = new JCheckBox(tr("Separate Layer"));
     
    90126                .addComponent(cbType, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
    91127            .addGroup(layout.createParallelGroup()
    92128                .addComponent(lbl2)
    93                 .addComponent(tfId, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
     129                .addComponent(cbId, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
    94130            .addComponent(referrers)
    95131            .addComponent(layer)
    96132            .addComponent(help)
     
    104140                )
    105141                .addGroup(layout.createParallelGroup()
    106142                    .addComponent(cbType)
    107                     .addComponent(tfId))
     143                    .addComponent(cbId))
    108144                )
    109145            .addComponent(referrers)
    110146            .addComponent(layer)
     
    141177            );
    142178            return;
    143179        }
    144 
     180        remindPrimitivesHistory(cbId);
    145181        processItems(layer.isSelected(), cbType.getType(), tfId.getIds(), referrers.isSelected());
    146182    }
    147183
     
    198234                        del.add(id);
    199235                    }
    200236                }
    201                 if (del != null && !del.isEmpty()) {
     237                if (!del.isEmpty()) {
    202238                    final ExtendedDialog dlg = reportProblemDialog(del,
    203239                            trn("Object deleted", "Objects deleted", del.size()),
    204240                            trn(
     
    248284            .setIcon(msgType)
    249285            .setContent(p, false);
    250286    }
    251 
    252     private static class SimpleListItem  {
    253         final String data;
    254         final String text;
    255 
    256         public SimpleListItem(String data, String text) {
    257             this.data = data;
    258             this.text = text;
    259         }
    260 
    261         @Override public String toString() {
    262             return text;
    263         }
    264     }
    265287}
  • src/org/openstreetmap/josm/gui/widgets/OsmPrimitiveTypesComboBox.java

     
    88/**
    99 * @author Matthias Julius
    1010 */
    11 public class OsmPrimitiveTypesComboBox extends JComboBox {
     11public class OsmPrimitiveTypesComboBox extends JComboBox<Object> {
    1212
    1313    public OsmPrimitiveTypesComboBox() {
    1414        for (OsmPrimitiveType type: OsmPrimitiveType.values()){