Ignore:
Timestamp:
2009-10-31T18:40:46+01:00 (14 years ago)
Author:
Gubaer
Message:

Added history to place selection in Download Dialog

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java

    r2361 r2362  
    1818import java.net.URL;
    1919import java.util.ArrayList;
     20import java.util.Collections;
    2021import java.util.LinkedList;
    2122import java.util.List;
     
    4950import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    5051import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     52import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    5153import org.openstreetmap.josm.io.OsmTransferException;
    5254import org.openstreetmap.josm.tools.ImageProvider;
     
    5759
    5860public class PlaceSelection implements DownloadSelection {
    59 
    60     private JTextField tfSearchExpression;
     61    private static final String HISTORY_KEY = "download.places.history";
     62
     63    private HistoryComboBox cbSearchExpression;
    6164    private JButton btnSearch;
    6265    private NamedResultTableModel model;
     
    7982        // the search expression field
    8083        //
    81         tfSearchExpression = new JTextField();
    82         tfSearchExpression.setToolTipText(tr("Enter a place name to search for"));
     84        cbSearchExpression = new HistoryComboBox();
     85        cbSearchExpression.setToolTipText(tr("Enter a place name to search for"));
     86        List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>()));
     87        Collections.reverse(cmtHistory);
     88        cbSearchExpression.setPossibleItems(cmtHistory);
    8389        gc.gridx = 0;
    8490        gc.gridy = 1;
    8591        gc.gridwidth = 1;
    86         panel.add(tfSearchExpression,  gc);
     92        panel.add(cbSearchExpression,  gc);
    8793
    8894        // the search button
     
    9096        SearchAction searchAction = new SearchAction();
    9197        btnSearch = new JButton(searchAction);
    92         tfSearchExpression.getDocument().addDocumentListener(searchAction);
    93         tfSearchExpression.addActionListener(searchAction);
     98        ((JTextField)cbSearchExpression.getEditor().getEditorComponent()).getDocument().addDocumentListener(searchAction);
     99        ((JTextField)cbSearchExpression.getEditor().getEditorComponent()).addActionListener(searchAction);
    94100
    95101        gc.gridx = 1;
     
    120126        panel.add(scrollPane, BorderLayout.CENTER);
    121127       
    122         gui.addDownloadAreaSelector(panel, tr("Areas around Places"));
     128        gui.addDownloadAreaSelector(panel, tr("Areas around places"));
    123129
    124130        scrollPane.setPreferredSize(scrollPane.getPreferredSize());       
     
    255261       
    256262        public void actionPerformed(ActionEvent e) {
    257             if (!isEnabled() || tfSearchExpression.getText().trim().length() == 0)
     263            if (!isEnabled() || cbSearchExpression.getText().trim().length() == 0)
    258264                return;
    259             NameQueryTask task = new NameQueryTask(tfSearchExpression.getText());
     265            cbSearchExpression.addCurrentItemToHistory();
     266            Main.pref.putCollection(HISTORY_KEY, cbSearchExpression.getHistory());
     267            NameQueryTask task = new NameQueryTask(cbSearchExpression.getText());
    260268            Main.worker.submit(task);
    261269        }
    262270       
    263271        protected void updateEnabledState() {
    264             setEnabled(tfSearchExpression.getText().trim().length() > 0);
     272            setEnabled(cbSearchExpression.getText().trim().length() > 0);
    265273        }
    266274
     
    439447   
    440448    class NamedResultCellRenderer extends JLabel implements TableCellRenderer {
     449       
    441450        public NamedResultCellRenderer() {
    442451            setOpaque(true);
     
    506515        }
    507516    }
     517
    508518}
Note: See TracChangeset for help on using the changeset viewer.