Changeset 2046 in josm for trunk/src


Ignore:
Timestamp:
2009-09-04T07:54:40+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3385: Add auto-completion to changeset tag completion

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r2045 r2046  
    99import java.awt.GridBagLayout;
    1010import java.awt.event.ActionEvent;
     11import java.awt.event.ActionListener;
    1112import java.awt.event.KeyEvent;
    1213import java.io.IOException;
    1314import java.net.HttpURLConnection;
    1415import java.util.Collection;
     16import java.util.HashMap;
    1517import java.util.LinkedList;
    1618import java.util.List;
     19import java.util.Map;
    1720import java.util.logging.Logger;
    1821import java.util.regex.Matcher;
     
    5457import org.openstreetmap.josm.tools.WindowGeometry;
    5558import org.xml.sax.SAXException;
     59
     60import com.sun.corba.se.spi.orbutil.fsm.Action;
    5661
    5762
     
    596601        private JTabbedPane southTabbedPane;
    597602        private ButtonGroup bgChangesetHandlingOptions;
    598         private JRadioButton rbUseNewAndClose;
    599         private JRadioButton rbUseNewAndLeaveOpen;
    600         private JRadioButton rbUseExistingAndClose;
    601         private JRadioButton rbUseExistingAndLeaveOpen;
    602         private ChangesetProcessingType changesetProcessingType;
     603        private Map<ChangesetProcessingType, JRadioButton> rbChangesetHandlingOptions;
    603604
    604605        protected JPanel buildListsPanel() {
     
    613614            pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
    614615            bgChangesetHandlingOptions = new ButtonGroup();
    615 
    616             rbUseNewAndClose = new JRadioButton(tr("Use a new changeset and close it"));
    617             rbUseNewAndClose.setToolTipText(tr("Select to upload the data using a new changeset and to close the changeset after the upload"));
    618 
    619             rbUseNewAndLeaveOpen = new JRadioButton(tr("Use a new changeset and leave it open"));
    620             rbUseNewAndLeaveOpen.setToolTipText(tr("Select to upload the data using a new changeset and to leave the changeset open after the upload"));
    621 
    622             rbUseExistingAndClose = new JRadioButton();
    623             rbUseExistingAndLeaveOpen = new JRadioButton();
     616            rbChangesetHandlingOptions = new HashMap<ChangesetProcessingType, JRadioButton>();
     617            ChangesetProcessingTypeChangedAction a = new ChangesetProcessingTypeChangedAction();
     618            for(ChangesetProcessingType type: ChangesetProcessingType.values()) {
     619                rbChangesetHandlingOptions.put(type, new JRadioButton());
     620                rbChangesetHandlingOptions.get(type).addActionListener(a);
     621            }
     622            JRadioButton rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_CLOSE);
     623            rb.setText(tr("Use a new changeset and close it"));
     624            rb.setToolTipText(tr("Select to upload the data using a new changeset and to close the changeset after the upload"));
     625
     626            rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN);
     627            rb.setText(tr("Use a new changeset and leave it open"));
     628            rb.setToolTipText(tr("Select to upload the data using a new changeset and to leave the changeset open after the upload"));
    624629
    625630            pnl.add(new JLabel(tr("Upload to a new or to an existing changeset?")));
    626             pnl.add(rbUseNewAndClose);
    627             pnl.add(rbUseNewAndLeaveOpen);
    628             pnl.add(rbUseExistingAndClose);
    629             pnl.add(rbUseExistingAndLeaveOpen);
    630 
    631             rbUseNewAndClose.setVisible(false);
    632             rbUseNewAndLeaveOpen.setVisible(false);
    633             rbUseExistingAndClose.setVisible(false);
    634             rbUseExistingAndLeaveOpen.setVisible(false);
    635 
    636             bgChangesetHandlingOptions.add(rbUseNewAndClose);
    637             bgChangesetHandlingOptions.add(rbUseNewAndLeaveOpen);
    638             bgChangesetHandlingOptions.add(rbUseExistingAndClose);
    639             bgChangesetHandlingOptions.add(rbUseExistingAndLeaveOpen);
     631            pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_CLOSE));
     632            pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN));
     633            pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_CLOSE));
     634            pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN));
     635
     636            for(ChangesetProcessingType type: ChangesetProcessingType.values()) {
     637                rbChangesetHandlingOptions.get(type).setVisible(false);
     638                bgChangesetHandlingOptions.add(rbChangesetHandlingOptions.get(type));
     639            }
    640640            return pnl;
    641641        }
     
    682682            southTabbedPane.add(tagEditorPanel);
    683683            southTabbedPane.setTitleAt(0, tr("Settings"));
    684             southTabbedPane.setTitleAt(1, tr("Changeset Tags"));
     684            southTabbedPane.setTitleAt(1, tr("Tags of new changeset"));
    685685            JPanel pnl = new JPanel();
    686686            pnl.setLayout(new BorderLayout());
     
    765765            Main.pref.putCollection(HISTORY_KEY, cmt.getHistory());
    766766            Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected());
    767 
    768             if (rbUseNewAndClose.isSelected()) {
    769                 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
    770             } else if (rbUseNewAndLeaveOpen.isSelected()) {
    771                 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN;
    772             } else if (rbUseExistingAndClose.isSelected()) {
    773                 changesetProcessingType = ChangesetProcessingType.USE_EXISTING_AND_CLOSE;
    774             } else if (rbUseExistingAndLeaveOpen.isSelected()) {
    775                 changesetProcessingType = ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN;
    776             }
    777767        }
    778768
    779769        public void startUserInput() {
    780             rbUseNewAndClose.setVisible(true);
    781             rbUseNewAndLeaveOpen.setVisible(true);
    782             if (OsmApi.getOsmApi().getCurrentChangeset() != null) {
    783                 Changeset cs = OsmApi.getOsmApi().getCurrentChangeset();
    784                 rbUseExistingAndClose.setVisible(true);
    785                 rbUseExistingAndLeaveOpen.setVisible(true);
    786 
    787                 rbUseExistingAndClose.setText(tr("Use the existing changeset {0} and close it after upload",cs.getId()));
    788                 rbUseExistingAndClose.setToolTipText(tr("Select to upload to the existing changeset {0} and to close the changeset after this upload",cs.getId()));
    789 
    790                 rbUseExistingAndLeaveOpen.setText(tr("Use the existing changeset {0} and leave it open",cs.getId()));
    791                 rbUseExistingAndLeaveOpen.setToolTipText(tr("Select to upload to the existing changeset {0} and to leave the changeset open for further uploads",cs.getId()));
    792 
    793                 if (changesetProcessingType == null) {
    794                     rbUseNewAndClose.setSelected(true);
    795                 } else {
    796                     switch(changesetProcessingType) {
    797                         case USE_NEW_AND_CLOSE: rbUseNewAndClose.setSelected(true); break;
    798                         case USE_NEW_AND_LEAVE_OPEN: rbUseNewAndLeaveOpen.setSelected(true); break;
    799                         case USE_EXISTING_AND_CLOSE: rbUseExistingAndClose.setSelected(true); break;
    800                         case USE_EXISTING_AND_LEAVE_OPEN: rbUseExistingAndLeaveOpen.setSelected(true); break;
    801                     }
    802                 }
    803             } else {
    804                 if (changesetProcessingType == null) {
    805                     changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;
    806                 }
    807                 rbUseExistingAndClose.setVisible(false);
    808                 rbUseExistingAndLeaveOpen.setVisible(false);
    809                 switch(changesetProcessingType) {
    810                     case USE_NEW_AND_CLOSE: rbUseNewAndClose.setSelected(true); break;
    811                     case USE_NEW_AND_LEAVE_OPEN: rbUseNewAndLeaveOpen.setSelected(true); break;
    812                     default: rbUseNewAndClose.setSelected(true); break;
    813                 }
    814             }
     770            tagEditorPanel.initAutoCompletion(Main.main.getEditLayer());
     771            initChangesetProcessingType();
    815772            cmt.getEditor().selectAll();
    816773            cmt.requestFocus();
     
    818775
    819776        public ChangesetProcessingType getChangesetProcessingType() {
    820             if (changesetProcessingType == null) return ChangesetProcessingType.USE_NEW_AND_CLOSE;
    821             return changesetProcessingType;
     777            ChangesetProcessingType changesetProcessingType = null;
     778            for (ChangesetProcessingType type: ChangesetProcessingType.values()) {
     779                if (rbChangesetHandlingOptions.get(type).isSelected()) {
     780                    changesetProcessingType = type;
     781                    break;
     782                }
     783            }
     784            return changesetProcessingType == null ?
     785                    ChangesetProcessingType.USE_NEW_AND_CLOSE :
     786                        changesetProcessingType;
    822787        }
    823788
     
    828793            return changeset;
    829794        }
     795
     796        protected void initChangesetProcessingType() {
     797            for (ChangesetProcessingType type: ChangesetProcessingType.values()) {
     798                // show options for new changeset, disable others
     799                //
     800                rbChangesetHandlingOptions.get(type).setVisible(type.isUseNew());
     801            }
     802            if (OsmApi.getOsmApi().getCurrentChangeset() != null) {
     803                Changeset cs = OsmApi.getOsmApi().getCurrentChangeset();
     804                for (ChangesetProcessingType type: ChangesetProcessingType.values()) {
     805                    // show options for using existing changeset
     806                    //
     807                    if (!type.isUseNew()) {
     808                        rbChangesetHandlingOptions.get(type).setVisible(true);
     809                    }
     810                }
     811                JRadioButton rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_CLOSE);
     812                rb.setText(tr("Use the existing changeset {0} and close it after upload",cs.getId()));
     813                rb.setToolTipText(tr("Select to upload to the existing changeset {0} and to close the changeset after this upload",cs.getId()));
     814
     815                rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN);
     816                rb.setText(tr("Use the existing changeset {0} and leave it open",cs.getId()));
     817                rb.setToolTipText(tr("Select to upload to the existing changeset {0} and to leave the changeset open for further uploads",cs.getId()));
     818
     819                rbChangesetHandlingOptions.get(getChangesetProcessingType()).setSelected(true);
     820
     821            } else {
     822                ChangesetProcessingType type = getChangesetProcessingType();
     823                if (!type.isUseNew()) {
     824                    type = ChangesetProcessingType.USE_NEW_AND_CLOSE;
     825                }
     826                rbChangesetHandlingOptions.get(type).setSelected(true);
     827            }
     828        }
     829
     830        class ChangesetProcessingTypeChangedAction implements ActionListener {
     831            public void actionPerformed(ActionEvent e) {
     832                ChangesetProcessingType type = getChangesetProcessingType();
     833                if (type.isUseNew()) {
     834                    tagEditorPanel.setEnabled(true);
     835                    southTabbedPane.setTitleAt(1, tr("Tags of new changeset"));
     836                    cmt.setEnabled(true);
     837                } else {
     838                    tagEditorPanel.setEnabled(false);
     839                    cmt.setEnabled(false);
     840                    Changeset cs = OsmApi.getOsmApi().getCurrentChangeset();
     841                    if (cs != null) {
     842                        tagEditorPanel.getModel().initFromPrimitive(cs);
     843                        southTabbedPane.setTitleAt(1, tr("Tags of changeset {0} (read-only)", cs.getId()));
     844                        cmt.setText(cs.get("comment" == null ? "" : cs.get("comment")));
     845                    }
     846                }
     847            }
     848        }
    830849    }
    831850}
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r2040 r2046  
    55
    66import java.awt.BorderLayout;
     7import java.awt.Component;
    78import java.awt.GridBagConstraints;
    89import java.awt.GridBagLayout;
    910import java.awt.event.ActionEvent;
     11import java.beans.PropertyChangeEvent;
     12import java.beans.PropertyChangeListener;
    1013
    1114import javax.swing.AbstractAction;
     
    1720import javax.swing.event.ListSelectionListener;
    1821
     22import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache;
     23import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList;
     24import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1925import org.openstreetmap.josm.tools.ImageProvider;
    2026
     27/**
     28 * TagEditorPanel is a {@see JPanel} which can be embedded as UI component in
     29 * UIs. It provides a spreadsheet like tabular control for editing tag names
     30 * and tag values. Two action buttons are placed on the left, one for additing
     31 * a new tag and one for deleting the currently selected tags.
     32 *
     33 *
     34 */
    2135public class TagEditorPanel extends JPanel {
     36    /** the tag editor model */
    2237    private TagEditorModel model;
     38    /** the tag table */
    2339    private TagTable tagTable;
    2440
     41    private AutoCompletionCache acCache;
     42    private AutoCompletionList acList;
     43
     44
     45    /**
     46     * builds the panel with the table for editing tags
     47     *
     48     * @return the panel
     49     */
    2550    protected JPanel buildTagTableEditorPanel() {
     51
    2652        JPanel pnl = new JPanel();
    2753        model = new TagEditorModel();
     
    3359    }
    3460
     61    /**
     62     * builds the panel with the button row
     63     *
     64     * @return the panel
     65     */
    3566    protected JPanel buildButtonsPanel() {
    3667        JPanel pnl = new JPanel();
     
    4172        AddAction addAction = new AddAction();
    4273        pnl.add(new JButton(addAction));
     74        tagTable.addPropertyChangeListener(addAction);
    4375
    4476        // delete action
     
    4678        DeleteAction deleteAction = new DeleteAction();
    4779        tagTable.getSelectionModel().addListSelectionListener(deleteAction);
     80        tagTable.addPropertyChangeListener(deleteAction);
    4881        pnl.add(new JButton(deleteAction));
    4982        return pnl;
    5083    }
    5184
     85    /**
     86     * builds the GUI
     87     */
    5288    protected void build() {
    5389        setLayout(new GridBagLayout());
     
    74110        add(tablePanel,gc);
    75111    }
     112
     113    /**
     114     * constructor
     115     */
    76116    public TagEditorPanel() {
    77117        build();
    78118    }
    79119
     120    /**
     121     * Replies the tag editor model used by this panel.
     122     *
     123     * @return the tag editor model used by this panel
     124     */
    80125    public TagEditorModel getModel() {
    81126        return model;
    82127    }
    83128
    84     class AddAction extends AbstractAction  {
     129    /**
     130     * The action for adding a tag
     131     *
     132     */
     133    class AddAction extends AbstractAction implements PropertyChangeListener {
    85134        public AddAction() {
    86135            putValue(SMALL_ICON, ImageProvider.get("dialogs", "add"));
    87136            putValue(SHORT_DESCRIPTION, tr("Add a new tag"));
    88         }
     137            updateEnabledState();
     138        }
     139
    89140        public void actionPerformed(ActionEvent e) {
    90141            model.appendNewTag();
    91142        }
    92     }
    93 
    94     class DeleteAction extends AbstractAction implements ListSelectionListener {
     143
     144        protected void updateEnabledState() {
     145            setEnabled(tagTable.isEnabled());
     146        }
     147
     148        public void propertyChange(PropertyChangeEvent evt) {
     149            updateEnabledState();
     150        }
     151    }
     152
     153    /**
     154     * The action for deleting the currently selected tags
     155     *
     156     *
     157     */
     158    class DeleteAction extends AbstractAction implements ListSelectionListener, PropertyChangeListener {
    95159        public DeleteAction() {
    96160            putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     
    137201                    // should not happen
    138202                    //
    139                     throw new IllegalStateException("unexpected selected clolumn: getSelectedColumn() is "
     203                    throw new IllegalStateException("unexpected selected column: getSelectedColumn() is "
    140204                            + tagTable.getSelectedColumn());
    141205            } else if (tagTable.getSelectedColumnCount() == 2) {
     
    148212
    149213        public void updateEnabledState() {
    150             setEnabled(tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() >0);
     214            setEnabled(tagTable.isEnabled() &&
     215                    (tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() >0));
    151216        }
    152217        public void valueChanged(ListSelectionEvent e) {
    153218            updateEnabledState();
    154219        }
     220
     221        public void propertyChange(PropertyChangeEvent evt) {
     222            updateEnabledState();
     223        }
     224    }
     225
     226    public void initAutoCompletion(OsmDataLayer layer) {
     227        // initialize the autocompletion infrastructure
     228        //
     229        acCache = AutoCompletionCache.getCacheForLayer(layer);
     230        acCache.initFromJOSMDataset();
     231        acList = new AutoCompletionList();
     232
     233        TagCellEditor editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(0).getCellEditor());
     234        editor.setAutoCompletionCache(acCache);
     235        editor.setAutoCompletionList(acList);
     236        editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor());
     237        editor.setAutoCompletionCache(acCache);
     238        editor.setAutoCompletionList(acList);
     239    }
     240
     241    @Override
     242    public void setEnabled(boolean enabled) {
     243        tagTable.setEnabled(enabled);
     244        super.setEnabled(enabled);
    155245    }
    156246}
Note: See TracChangeset for help on using the changeset viewer.