Changeset 15319 in osm for applications/editors/josm


Ignore:
Timestamp:
2009-05-30T13:00:04+02:00 (15 years ago)
Author:
guggis
Message:

resolved incompatibility issues with Java 1.5

Location:
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/LaunchAction.java

    r14322 r15319  
    2727@SuppressWarnings("serial")
    2828public class LaunchAction extends JosmAction implements SelectionChangedListener {
    29          
     29
    3030        protected void registerAsMenuItem() {
    31         JMenuBar menu = Main.main.menu;
    32         JMenu edit = null;
    33         JMenuItem item = new JMenuItem(this);
     31                JMenuBar menu = Main.main.menu;
     32                JMenu edit = null;
     33                JMenuItem item = new JMenuItem(this);
    3434
    35         for (int i = 0; i < menu.getMenuCount(); ++i) {
    36             if (menu.getMenu(i) != null
    37                     && tr("Edit").equals(menu.getMenu(i).getText())) {
    38                 edit = menu.getMenu(i);
    39                 break;
    40             }
    41         }
     35                for (int i = 0; i < menu.getMenuCount(); ++i) {
     36                        if (menu.getMenu(i) != null
     37                                        && tr("Edit").equals(menu.getMenu(i).getText())) {
     38                                edit = menu.getMenu(i);
     39                                break;
     40                        }
     41                }
    4242
    43         if (edit != null) {
    44                 edit.insertSeparator(edit.getItemCount());
    45                 JMenuItem mitem = edit.insert(this, edit.getItemCount());
    46                 mitem.setAccelerator(KeyStroke.getKeyStroke('T'));
    47         } else if (menu.getMenuCount() > 0) {
    48             edit = menu.getMenu(0);
    49             JMenuItem mitem = edit.insert(this, 0);
    50                 mitem.setAccelerator(KeyStroke.getKeyStroke('T'));
     43                if (edit != null) {
     44                        edit.insertSeparator(edit.getItemCount());
     45                        JMenuItem mitem = edit.insert(this, edit.getItemCount());
     46                        mitem.setAccelerator(KeyStroke.getKeyStroke('T'));
     47                } else if (menu.getMenuCount() > 0) {
     48                        edit = menu.getMenu(0);
     49                        JMenuItem mitem = edit.insert(this, 0);
     50                        mitem.setAccelerator(KeyStroke.getKeyStroke('T'));
    5151
    52         }
     52                }
    5353
    54         item.setVisible(true);
     54                item.setVisible(true);
    5555        }
    56        
    57 
    5856
    5957        public LaunchAction()  {
    6058                super(
    61                         tr("Edit tags"),
    62                         null, //TODO: set "tag-editor" and add /images/tag-editor.png to distrib
    63                         tr("Launches the tag editor dialog"),
    64                         Shortcut.registerShortcut(
    65                                         "edit:launchtageditor",
    66                                         tr("Launches the tag editor dialog"),
    67                                         KeyEvent.VK_T,
    68                                         Shortcut.GROUP_EDIT),                                           
    69                         false // don't register, plugin will add the action to the menu
     59                                tr("Edit tags"),
     60                                null, //TODO: set "tag-editor" and add /images/tag-editor.png to distrib
     61                                tr("Launches the tag editor dialog"),
     62                                Shortcut.registerShortcut(
     63                                                "edit:launchtageditor",
     64                                                tr("Launches the tag editor dialog"),
     65                                                KeyEvent.VK_T,
     66                                                Shortcut.GROUP_EDIT),
     67                                                false // don't register, plugin will add the action to the menu
    7068                );
    71                
    72                
     69
     70
    7371                // register as dataset selection listener
    7472                //
    7573                DataSet.selListeners.add(this);
    76                
     74
    7775                // insert a menu item
    7876                //
    7977                registerAsMenuItem();
    80                
     78
    8179                // initially not enabled; becomes enabled when the selection becomes non-empty
    8280                //
    8381                setEnabled(false);
    84                
     82
    8583        }
    86        
     84
    8785        /**
    88          *  
     86         *
    8987         * @return  the top window of the JOSM GUI; can be null
    9088         */
    9189        protected Window getTopWindow() {
    92                 if (Main.contentPane == null) {
     90                if (Main.contentPane == null)
    9391                        return null;
    94                 }
    9592                Component c = Main.contentPane;
    9693                while(c.getParent() != null) {
    9794                        c = c.getParent();
    9895                }
    99                 if (c instanceof Window) {
     96                if (c instanceof Window)
    10097                        return (Window)c;
    101                 } else {
     98                else
    10299                        return null;
    103                 }
    104100        }
    105        
     101
    106102        /**
    107          * tries to center the tag editor dialog on the top window or, alternatively, 
     103         * tries to center the tag editor dialog on the top window or, alternatively,
    108104         * on the screen
    109105         *
    110          * @param dialog the dialog to be placed on the screen 
     106         * @param dialog the dialog to be placed on the screen
    111107         */
    112108        protected void placeDialogOnScreen(TagEditorDialog dialog) {
    113109                Window w = getTopWindow();
    114                 if (w == null) {
    115                         // don't center 
     110                if (w == null)
     111                        // don't center
    116112                        return;
    117                 }
    118                
     113
    119114                GraphicsConfiguration gc = w.getGraphicsConfiguration();
    120115                Rectangle screenBounds = null;
     
    135130
    136131                dialog.setLocation(p);
    137                
     132
    138133        }
    139        
     134
    140135        /**
    141          * launch the editor 
     136         * launch the editor
    142137         */
    143138        protected void launchEditor() {
    144                 if (!isEnabled()) {
     139                if (!isEnabled())
    145140                        return;
    146                 }
    147141                TagEditorDialog dialog = TagEditorDialog.getInstance();
    148142                placeDialogOnScreen(dialog);
    149                 dialog.startEditSession();             
    150                 dialog.setVisible(true);               
     143                dialog.startEditSession();
     144                dialog.setVisible(true);
    151145        }
    152        
    153        
    154        
    155        
    156         @Override
     146
    157147        public void actionPerformed(ActionEvent e) {
    158148                launchEditor();
    159149        }
    160150
    161        
    162         @Override
    163151        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    164152                setEnabled(newSelection != null && newSelection.size() >0);
    165153        }
    166154
    167        
    168        
     155
     156
    169157
    170158}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/TagEditorDialog.java

    r14338 r15319  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.tageditor;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.awt.BorderLayout;
     
    4244import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.TabularTagSelector;
    4345
    44 import static org.openstreetmap.josm.tools.I18n.tr;
    45 
    4646/**
    4747 * The dialog for editing name/value-pairs (aka <em>tags</em>) associated with {@link OsmPrimitive}s.
     
    5151@SuppressWarnings("serial")
    5252public class TagEditorDialog extends JDialog {
    53        
     53
    5454        static private Logger logger = Logger.getLogger(TagEditorDialog.class.getName());
    55        
     55
    5656        /** the unique instance */
    5757        static protected  TagEditorDialog instance = null;
    58        
    59         /**
    60          * Access to the singleton instance 
     58
     59        /**
     60         * Access to the singleton instance
    6161         *
    62          * @return the singleton instance of the dialog 
     62         * @return the singleton instance of the dialog
    6363         */
    6464        static public TagEditorDialog getInstance() {
     
    6868                return instance;
    6969        }
    70        
    71        
    72         /**
    73          * default preferred size 
     70
     71
     72        /**
     73         * default preferred size
    7474         */
    7575        static public final Dimension PREFERRED_SIZE = new Dimension(700, 500);
    76        
    77        
    78         /** the properties table */ 
     76
     77
     78        /** the properties table */
    7979        private TagEditor tagEditor = null;
    8080        private TagEditorModel model = null;
     
    8282        /**  the auto completion list viewer */
    8383        private AutoCompletionListViewer aclViewer = null;
    84        
     84
    8585        /** the cache of auto completion values used by the tag editor */
    8686        private AutoCompletionCache acCache = null;
    87        
     87
    8888        /** widgets */
    8989        private JButton btnOK = null;
    90         private JButton btnCancel = null; 
     90        private JButton btnCancel = null;
    9191        private JButton btnAdd = null;
    9292        private JButton btnDelete = null;
     
    9494        private CancelAction cancelAction = null;
    9595
    96        
     96
    9797        public OKAction getOKAction() {
    9898                return okAction;
    9999        }
    100        
     100
    101101        /**
    102102         * @return the tag editor model
     
    106106        }
    107107
    108        
    109        
     108
     109
    110110        protected JPanel buildButtonRow() {
    111111                // create the rows of action buttons at the bottom
    112                 // of the dialog 
     112                // of the dialog
    113113                //
    114114                JPanel pnl = new JPanel();
    115115                pnl.setLayout(new FlowLayout(FlowLayout.RIGHT));
    116                
    117                 // the ok button 
     116
     117                // the ok button
    118118                //
    119119                okAction = new OKAction();
    120120                btnOK = new JButton(okAction);
    121121                getModel().addPropertyChangeListener(okAction);
    122                
    123                 // the cancel button 
     122
     123                // the cancel button
    124124                //
    125125                cancelAction = new CancelAction();
     
    127127                pnl.add(btnOK);
    128128                pnl.add(btnCancel);
    129                
     129
    130130                JPanel pnl1 = new JPanel();
    131131                pnl.setLayout(new FlowLayout(FlowLayout.LEFT));
    132                
     132
    133133                // the add button
    134134                //
    135135                btnAdd = new JButton(tagEditor.getAddAction());
    136136                btnDelete = new JButton(tagEditor.getDeleteAction());
    137        
     137
    138138                pnl1.add(btnAdd);
    139139                pnl1.add(btnDelete);
    140                
     140
    141141                JPanel pnl2 = new JPanel();
    142142                pnl2.setLayout(new BorderLayout());
    143143                pnl2.add(pnl1, BorderLayout.WEST);
    144144                pnl2.add(pnl, BorderLayout.EAST);
    145                
    146                 return pnl2;           
    147         }
    148        
    149         /**
    150          * build the GUI 
     145
     146                return pnl2;
     147        }
     148
     149        /**
     150         * build the GUI
    151151         */
    152152        protected void build() {
     
    158158                setSize(PREFERRED_SIZE);
    159159                setTitle(tr("JOSM Tag Editor Plugin"));
    160                
    161                
     160
     161
    162162                // create tag editor and inject an instance of the tag
    163163                // editor model
     
    165165                tagEditor = new TagEditor();
    166166                tagEditor.setTagEditorModel(model);
    167                
     167
    168168
    169169                // create the auto completion list viewer and connect it
    170                 // to the tag editor 
     170                // to the tag editor
    171171                //
    172172                AutoCompletionList autoCompletionList = new AutoCompletionList();
     
    174174                tagEditor.setAutoCompletionList(autoCompletionList);
    175175                tagEditor.setAutoCompletionCache(acCache);
    176                 aclViewer.addAutoCompletionListListener(tagEditor);             
    177                
     176                aclViewer.addAutoCompletionListListener(tagEditor);
     177
    178178                JPanel pnlTagGrid = new JPanel();
    179179                pnlTagGrid.setLayout(new BorderLayout());
     
    181181                pnlTagGrid.add(aclViewer, BorderLayout.EAST);
    182182                pnlTagGrid.setBorder(BorderFactory.createEmptyBorder(5, 0,0,0));
    183                
    184                
     183
     184
    185185                // create the preset selector
    186186                //
     
    188188                presetSelector.addPresetSelectorListener(
    189189                                new IPresetSelectorListener() {
    190                                         @Override
    191190                                        public void itemSelected(Item item) {
    192191                                                tagEditor.stopEditing();
    193192                                                model.applyPreset(item);
    194193                                                tagEditor.requestFocusInTopLeftCell();
    195                                         }                                       
     194                                        }
    196195                                }
    197196                );
    198                
    199                
     197
     198
    200199                JPanel pnlPresetSelector = new JPanel();
    201200                pnlPresetSelector.setLayout(new BorderLayout());
     
    219218                pnlTagSelector.add(tagSelector,BorderLayout.CENTER);
    220219                pnlTagSelector.setBorder(BorderFactory.createEmptyBorder(0,0,5,0        ));
    221                
    222                
    223                
    224                
    225                 // create the tabbed pane 
     220
     221
     222
     223
     224                // create the tabbed pane
    226225                //
    227226                JTabbedPane tabbedPane = new JTabbedPane();
    228227                tabbedPane.add(pnlPresetSelector, tr("Presets"));
    229228                tabbedPane.add(pnlTagSelector, tr("Tags"));
    230                
     229
    231230                // create split pane
    232231                //
    233232                JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
    234                                            tabbedPane, pnlTagGrid);
     233                                tabbedPane, pnlTagGrid);
    235234                splitPane.setOneTouchExpandable(true);
    236235                splitPane.setDividerLocation(200);
    237        
     236
    238237                Dimension minimumSize = new Dimension(100, 50);
    239238                presetSelector.setMinimumSize(minimumSize);
    240239                pnlTagGrid.setMinimumSize(minimumSize);
    241                
     240
    242241                getContentPane().add(splitPane,BorderLayout.CENTER);
    243                                
     242
    244243                getContentPane().add(buildButtonRow(), BorderLayout.SOUTH);
    245244
    246                
     245
    247246                addWindowListener(
    248247                                new WindowAdapter() {
     
    253252                                                                getModel().ensureOneTag();
    254253                                                                tagEditor.clearSelection();
    255                                                                 tagEditor.requestFocusInTopLeftCell();                                                         
    256                                                         }                                                       
     254                                                                tagEditor.requestFocusInTopLeftCell();
     255                                                        }
    257256                                                });
    258257                                        }
    259258                                }
    260259                );
    261                
    262                
     260
     261
    263262                // makes sure that 'Ctrl-Enter' in the properties table
    264263                // and in the aclViewer is handled by okAction
    265                 //             
     264                //
    266265                getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put((KeyStroke)cancelAction.getValue(Action.ACCELERATOR_KEY), okAction.getValue(AbstractAction.NAME));
    267266                getRootPane().getActionMap().put(cancelAction.getValue(Action.NAME), cancelAction);
     
    270269                getRootPane().getActionMap().put(okAction.getValue(Action.NAME), okAction);
    271270
    272                
    273                 // make sure the OK action is also enabled in sub components. I registered 
     271
     272                // make sure the OK action is also enabled in sub components. I registered
    274273                // the action in the input and action maps of the dialogs root pane and I expected
    275274                // it to get triggered regardless of what subcomponent had focus, but it didn't.
    276                 // 
     275                //
    277276                aclViewer.installKeyAction(okAction);
    278277                aclViewer.installKeyAction(cancelAction);
     
    280279                presetSelector.installKeyAction(cancelAction);
    281280        }
    282        
    283        
    284        
     281
     282
     283
    285284        /**
    286285         * constructor
     
    289288                acCache = new AutoCompletionCache();
    290289                model = new TagEditorModel();
    291                 build();       
    292         }
    293        
    294        
     290                build();
     291        }
     292
     293
    295294        @Override
    296295        public Dimension getPreferredSize() {
     
    298297        }
    299298
    300        
    301        
     299
     300
    302301        /**
    303302         * start an editing session. This method should be called before the dialog
    304          * is shown on the screen, i.e. before {@link Dialog#setVisible(boolean)} is 
    305          * called. 
    306          */
    307         public void startEditSession() {               
     303         * is shown on the screen, i.e. before {@link Dialog#setVisible(boolean)} is
     304         * called.
     305         */
     306        public void startEditSession() {
    308307                model.clearAppliedPresets();
    309                 model.initFromJOSMSelection();         
     308                model.initFromJOSMSelection();
    310309                acCache.initFromJOSMDataset();
    311310                getModel().ensureOneTag();
    312311        }
    313312
    314        
    315        
     313
     314
    316315        @SuppressWarnings("serial")
    317316        class CancelAction extends AbstractAction {
    318                
     317
    319318                public CancelAction() {
    320319                        putValue(Action.NAME, tr("Cancel"));
    321320                        putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0));
    322321                }
    323                
    324                 @Override
     322
    325323                public void actionPerformed(ActionEvent arg0) {
    326324                        setVisible(false);
    327                 }               
    328         }
    329        
    330 
    331        
     325                }
     326        }
     327
     328
     329
    332330        @SuppressWarnings("serial")
    333331        class OKAction extends AbstractAction implements PropertyChangeListener {
    334  
     332
    335333                public OKAction() {
    336334                        putValue(Action.NAME, tr("OK"));
    337335                        putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl ENTER"));
    338336                }
    339                
    340                 @Override
     337
    341338                public void actionPerformed(ActionEvent e) {
    342339                        run();
     
    347344                        setVisible(false);
    348345                        model.updateJOSMSelection();
    349                        
    350                         Collection<OsmPrimitive> sel = Main.ds.getSelected();                   
     346
     347                        Collection<OsmPrimitive> sel = Main.ds.getSelected();
    351348                        DataSet.fireSelectionChanged(sel);
    352349                        Main.parent.repaint(); // repaint all - drawing could have been changed
    353350                }
    354                
    355                 @Override
     351
    356352                public void propertyChange(PropertyChangeEvent evt) {
    357                         if (! evt.getPropertyName().equals(TagEditorModel.PROP_DIRTY)) {
     353                        if (! evt.getPropertyName().equals(TagEditorModel.PROP_DIRTY))
    358354                                return;
    359                         }
    360                         if (! evt.getNewValue().getClass().equals(Boolean.class)) {
     355                        if (! evt.getNewValue().getClass().equals(Boolean.class))
    361356                                return;
    362                         }
    363357                        boolean dirty = (Boolean)evt.getNewValue();
    364358                        setEnabled(dirty);
    365                 }               
     359                }
    366360        }
    367361}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionList.java

    r14324 r15319  
    1111 * AutoCompletionList manages a list of {@see AutoCompletionListItem}s.
    1212 *
    13  * The list is sorted, items with higher priority first, then according to lexicographic order 
    14  * on the value of the {@see AutoCompletionListItem}. 
     13 * The list is sorted, items with higher priority first, then according to lexicographic order
     14 * on the value of the {@see AutoCompletionListItem}.
    1515 *
    1616 * AutoCompletionList maintains two views on the list of {@see AutoCompletionListItem}s.
    1717 * <ol>
    1818 *   <li>the bare, unfiltered view which includes all items</li>
    19  *   <li>a filtered view, which includes only items which match a current filter expression</li>   
     19 *   <li>a filtered view, which includes only items which match a current filter expression</li>
    2020 * </ol>
    2121 *
     
    2828
    2929        /** the bare list of AutoCompletionItems */
    30         private ArrayList<AutoCompletionListItem> list = null; 
    31         /**  the filtered list of AutoCompletionItems */ 
    32         private ArrayList<AutoCompletionListItem> filtered = null;     
    33         /** the filter expression */ 
    34         private String filter = null; 
    35 
    36         /**
    37          * constructor 
     30        private ArrayList<AutoCompletionListItem> list = null;
     31        /**  the filtered list of AutoCompletionItems */
     32        private ArrayList<AutoCompletionListItem> filtered = null;
     33        /** the filter expression */
     34        private String filter = null;
     35
     36        /**
     37         * constructor
    3838         */
    3939        public AutoCompletionList() {
     
    4141                filtered = new ArrayList<AutoCompletionListItem>();
    4242        }
    43        
    44        
     43
     44
    4545        /**
    4646         * applies a filter expression to the list of {@see AutoCompletionListItem}s.
    4747         *
    48          * The matching criterion is a case insensitive substring match. 
     48         * The matching criterion is a case insensitive substring match.
    4949         *
    5050         * @param filter  the filter expression; must not be null
     
    5353         */
    5454        public void applyFilter(String filter) {
    55                 if (filter == null) {
     55                if (filter == null)
    5656                        throw new IllegalArgumentException("argument 'filter' must not be null");
    57                 }
    5857                this.filter = filter;
    5958                filter();
    6059        }
    61        
    62         /**
    63          * clears the current filter 
     60
     61        /**
     62         * clears the current filter
    6463         *
    6564         */
     
    6867                filter();
    6968        }
    70        
    71         /**
    72          * @return the current filter expression; null, if no filter expression is set 
     69
     70        /**
     71         * @return the current filter expression; null, if no filter expression is set
    7372         */
    7473        public String getFilter() {
    75                 return filter; 
    76         }
    77        
    78        
    79         /** 
     74                return filter;
     75        }
     76
     77
     78        /**
    8079         * adds an AutoCompletionListItem to the list. Only adds the item if it
    81          * is not null and if not in the list yet. 
    82          *  
    83          * @param item the item 
     80         * is not null and if not in the list yet.
     81         *
     82         * @param item the item
    8483         */
    8584        public void add(AutoCompletionListItem item) {
    86                 if (item == null) {
    87                         return;
    88                 }
     85                if (item == null)
     86                        return;
    8987                appendOrUpdatePriority(item);
    9088                sort();
    9189                filter();
    9290        }
    93        
    94        
     91
     92
    9593        /**
    9694         * adds another AutoCompletionList to this list. An item is only
    97          * added it is not null and if it does not exist in the list yet. 
     95         * added it is not null and if it does not exist in the list yet.
    9896         *
    9997         * @param other another auto completion list; must not be null
    100          * @exception IllegalArgumentException thrown, if other is null 
     98         * @exception IllegalArgumentException thrown, if other is null
    10199         */
    102100        public void add(AutoCompletionList other) {
    103                 if (other == null) {
     101                if (other == null)
    104102                        throw new IllegalArgumentException("argument 'other' must not be null");
    105                 }
    106103                for (AutoCompletionListItem item : other.list) {
    107104                        appendOrUpdatePriority(item);
     
    110107                filter();
    111108        }
    112        
    113        
     109
     110
    114111        /**
    115112         * adds a list of AutoCompletionListItem to this list. Only items which
    116          * are not null and which do not exist yet in the list are added. 
     113         * are not null and which do not exist yet in the list are added.
    117114         *
    118115         * @param other a list of AutoCompletionListItem; must not be null
    119          * @exception IllegalArgumentException thrown, if other is null 
     116         * @exception IllegalArgumentException thrown, if other is null
    120117         */
    121118        public void add(List<AutoCompletionListItem> other) {
    122                 if (other == null)      {
     119                if (other == null)
    123120                        throw new IllegalArgumentException("argument 'other' must not be null");
    124                 }
    125121                for (AutoCompletionListItem toadd : other) {
    126122                        appendOrUpdatePriority(toadd);
     
    144140                }
    145141        }
    146        
    147         /**
    148          * checks whether a specific item is already in the list. Matches for the 
    149          * the value <strong>and</strong> the priority of the item 
     142
     143        /**
     144         * checks whether a specific item is already in the list. Matches for the
     145         * the value <strong>and</strong> the priority of the item
    150146         *
    151147         * @param item the item to check
    152          * @return true, if item is in the list; false, otherwise 
     148         * @return true, if item is in the list; false, otherwise
    153149         */
    154150        public boolean contains(AutoCompletionListItem item) {
    155                 if (item == null) {
    156                         return false;
    157                 }
     151                if (item == null)
     152                        return false;
    158153                return list.contains(item);
    159154        }
    160        
     155
    161156        /**
    162157         * checks whether an item with the given value is already in the list. Ignores
    163158         * priority of the items.
    164159         *
    165          * @param value the value of an auto completion item 
    166          * @return true, if value is in the list; false, otherwise 
     160         * @param value the value of an auto completion item
     161         * @return true, if value is in the list; false, otherwise
    167162         */
    168163        public boolean contains(String value) {
    169                 if (value == null) {
    170                         return false;
    171                 }
     164                if (value == null)
     165                        return false;
    172166                for (AutoCompletionListItem item: list) {
    173                         if (item.getValue().equals(value)) {
    174                                 return true;
    175                         }
    176                 }
    177                 return false;
    178         }
    179        
    180         /**
    181          *
    182          * @param value a specific value
     167                        if (item.getValue().equals(value))
     168                                return true;
     169                }
     170                return false;
     171        }
     172
     173        /**
     174         *
     175         * @param value a specific value
    183176         * @return  the auto completion item for this value; null, if there is no
    184          *   such auto completion item 
     177         *   such auto completion item
    185178         */
    186179        public AutoCompletionListItem lookup(String value) {
    187                 if (value == null) {
     180                if (value == null)
    188181                        return null;
    189                 }
    190182                for (AutoCompletionListItem item : list) {
    191                         if (item.getValue().equals(value)) {
     183                        if (item.getValue().equals(value))
    192184                                return item;
    193                         }
    194185                }
    195186                return null;
    196187        }
    197        
    198        
     188
     189
    199190        /**
    200191         * removes the auto completion item with key <code>key</code>
    201          * @param key  the key; 
     192         * @param key  the key;
    202193         */
    203194        public void remove(String key) {
    204                 if (key == null) {
    205                         return;
    206                 }
     195                if (key == null)
     196                        return;
    207197                for (int i=0;i< list.size();i++) {
    208198                        AutoCompletionListItem item = list.get(i);
    209199                        if (item.getValue().equals(key)) {
    210200                                list.remove(i);
    211                                 return; 
    212                         }
    213                 }               
    214         }
    215        
    216        
    217        
    218         /**
    219          * sorts the list 
     201                                return;
     202                        }
     203                }
     204        }
     205
     206
     207
     208        /**
     209         * sorts the list
    220210         */
    221211        protected void sort() {
    222                 Collections.sort(list);         
    223         }
    224        
     212                Collections.sort(list);
     213        }
     214
    225215        protected void filter() {
    226216                filtered.clear();
     
    231221                        for (AutoCompletionListItem item: list) {
    232222                                filtered.add(item);
    233                         }                       
     223                        }
    234224                        return;
    235225                }
    236                
     226
    237227                // apply the pattern to list of possible values. If it matches, add the
    238                 // value to the list of filtered values 
    239                 // 
     228                // value to the list of filtered values
     229                //
    240230                for (AutoCompletionListItem item : list) {
    241231                        if (item.getValue().startsWith(filter)) {
     
    243233                        }
    244234                }
    245                
     235
    246236                fireTableDataChanged();
    247237        }
    248        
    249         /**
    250          * replies the number of filtered items 
    251          *  
    252          * @return the number of filtered items 
     238
     239        /**
     240         * replies the number of filtered items
     241         *
     242         * @return the number of filtered items
    253243         */
    254244        public int getFilteredSize() {
    255245                return this.filtered.size();
    256246        }
    257        
    258         /**
    259          * replies the idx-th item from the list of filtered items 
     247
     248        /**
     249         * replies the idx-th item from the list of filtered items
    260250         * @param idx the index; must be in the range 0<= idx < {@see #getFilteredSize()}
    261251         * @return the item
     
    264254         */
    265255        public AutoCompletionListItem getFilteredItem(int idx) {
    266                 if (idx < 0 || idx >= getFilteredSize()) {
     256                if (idx < 0 || idx >= getFilteredSize())
    267257                        throw new IndexOutOfBoundsException("idx out of bounds. idx=" + idx);
    268                 }
    269258                return filtered.get(idx);
    270259        }
    271        
    272        
     260
     261
    273262        /**
    274263         * removes all elements from the auto completion list
     
    279268                fireTableDataChanged();
    280269        }
    281        
    282        
    283         @Override public int getColumnCount() {
     270
     271
     272        public int getColumnCount() {
    284273                return 1;
    285274        }
    286275
    287         @Override public int getRowCount() {
    288        
    289             return list == null ? 0 : getFilteredSize();
    290     }
    291 
    292         @Override public Object getValueAt(int rowIndex, int columnIndex) {
     276        public int getRowCount() {
     277
     278                return list == null ? 0 : getFilteredSize();
     279        }
     280
     281        public Object getValueAt(int rowIndex, int columnIndex) {
    293282                return list == null ? null : getFilteredItem(rowIndex);
    294     }
    295        
     283        }
     284
    296285}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionListItem.java

    r14324 r15319  
    55 * Represents an entry in the list of auto completion values.
    66 *
    7  *  An AutoCompletionListItem has a <em>priority</em> and a <em>value</em>. 
    8  *  
     7 *  An AutoCompletionListItem has a <em>priority</em> and a <em>value</em>.
     8 *
    99 *  The priority helps to sort the auto completion items according to their importance. For instance,
    1010 *  in an auto completion list for tag names, standard tag names would be assigned a higher
     
    1212 *  {@see AutoCompletionItemPritority}.
    1313 *
    14  * The value is a string which will be displayed in the auto completion list.   
     14 * The value is a string which will be displayed in the auto completion list.
    1515 *
    1616 * @author gubaer
     
    1919public class AutoCompletionListItem implements Comparable<AutoCompletionListItem>{
    2020
    21         /** the pritority of this item */ 
     21        /** the pritority of this item */
    2222        private  AutoCompletionItemPritority priority;
    23         /** the value of this item */ 
     23        /** the value of this item */
    2424        private String value;
    25        
     25
    2626        /**
    27          * constructor 
     27         * constructor
    2828         */
    2929        public AutoCompletionListItem() {
     
    3131                priority = AutoCompletionItemPritority.UNKNOWN;
    3232        }
    33        
     33
    3434        public AutoCompletionListItem(String value, AutoCompletionItemPritority priority) {
    3535                this.value = value;
     
    3939        /**
    4040         *
    41          * @return the priority 
     41         * @return the priority
    4242         */
    4343        public AutoCompletionItemPritority getPriority() {
    44         return priority;
    45     }
     44                return priority;
     45        }
    4646
    4747        /**
    48          * sets the priority 
    49          * @param priority  the priority 
     48         * sets the priority
     49         * @param priority  the priority
    5050         */
    5151        public void setPriority(AutoCompletionItemPritority priority) {
    52         this.priority = priority;
    53     }
     52                this.priority = priority;
     53        }
    5454
    5555        /**
    5656         *
    57          * @return the value 
     57         * @return the value
    5858         */
    5959        public String getValue() {
    60         return value;
    61     }
     60                return value;
     61        }
    6262
    6363        /**
    64          * sets the value 
     64         * sets the value
    6565         * @param value the value; must not be null
    6666         * @exception IllegalArgumentException thrown, if value if null
    6767         */
    6868        public void setValue(String value) {
    69                 if (value == null)      {
     69                if (value == null)
    7070                        throw new IllegalArgumentException("argument 'value' must not be null");
    71                 }
    72         this.value = value;
    73     }
     71                this.value = value;
     72        }
    7473
    7574        @Override public String toString() {
     
    8685
    8786        @Override public int hashCode() {
    88             final int prime = 31;
    89             int result = 1;
    90             result = prime * result
    91                     + ((priority == null) ? 0 : priority.hashCode());
    92             result = prime * result + ((value == null) ? 0 : value.hashCode());
    93             return result;
    94     }
     87                final int prime = 31;
     88                int result = 1;
     89                result = prime * result
     90                + ((priority == null) ? 0 : priority.hashCode());
     91                result = prime * result + ((value == null) ? 0 : value.hashCode());
     92                return result;
     93        }
    9594
    9695        @Override public boolean equals(Object obj) {
    97             if (this == obj)
    98                     return true;
    99             if (obj == null)
    100                     return false;
    101             if (getClass() != obj.getClass())
    102                     return false;
    103             final AutoCompletionListItem other = (AutoCompletionListItem)obj;
    104             if (priority == null) {
    105                     if (other.priority != null)
    106                             return false;
    107             } else if (!priority.equals(other.priority))
    108                     return false;
    109             if (value == null) {
    110                     if (other.value != null)
    111                             return false;
    112             } else if (!value.equals(other.value))
    113                     return false;
    114             return true;
    115     }
    116        
    117 
    118         @Override public int compareTo(AutoCompletionListItem other) {
    119                 int ret = this.priority.compareTo(other.priority);
    120                 if (ret != 0) {
    121                         return ret;
    122                 } else {
    123                         return this.value.compareTo(other.value);
    124                 }
     96                if (this == obj)
     97                        return true;
     98                if (obj == null)
     99                        return false;
     100                if (getClass() != obj.getClass())
     101                        return false;
     102                final AutoCompletionListItem other = (AutoCompletionListItem)obj;
     103                if (priority == null) {
     104                        if (other.priority != null)
     105                                return false;
     106                } else if (!priority.equals(other.priority))
     107                        return false;
     108                if (value == null) {
     109                        if (other.value != null)
     110                                return false;
     111                } else if (!value.equals(other.value))
     112                        return false;
     113                return true;
    125114        }
    126115
    127        
    128        
    129        
    130        
     116
     117        public int compareTo(AutoCompletionListItem other) {
     118                int ret = this.priority.compareTo(other.priority);
     119                if (ret != 0)
     120                        return ret;
     121                else
     122                        return this.value.compareTo(other.value);
     123        }
     124
     125
     126
     127
     128
    131129}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionListRenderer.java

    r14324 r15319  
    1313 * This is the table cell renderer for the list of auto completion list items.
    1414 *
    15  * It uses an instance of {@Link JLabel} to render an {@link AutoCompletionListItem}. 
     15 * It uses an instance of {@Link JLabel} to render an {@link AutoCompletionListItem}.
    1616 *
    1717 *
     
    2323        static public final String RES_SELECTION_ICON = "/resources/selection.gif";
    2424        public static final Color BG_COLOR_SELECTED = new Color(143,170,255);
    25        
     25
    2626        /** the renderer component */
    27         private JLabel renderer;
    28        
     27        private final JLabel renderer;
     28
    2929        /** the icon used to decorate items of priority
    30          *  {@link AutoCompletionItemPritority#IS_IN_STANDARD} 
     30         *  {@link AutoCompletionItemPritority#IS_IN_STANDARD}
    3131         */
    3232        private Icon iconStandard;
    33        
    34         /** the icon used to decorate items of priority 
     33
     34        /** the icon used to decorate items of priority
    3535         *  {@link AutoCompletionItemPritority#IS_IN_SELECTION}
    3636         */
    3737        private Icon iconSelection;
    38        
     38
    3939        /**
    40          * constructor 
     40         * constructor
    4141         */
    4242        public AutoCompletionListRenderer() {
    4343                renderer = new JLabel();
    4444                renderer.setOpaque(true);
    45                
     45
    4646                loadIcons();
    4747        }
    48        
     48
    4949        /**
    50          * loads the icons 
     50         * loads the icons
    5151         */
    5252        protected void loadIcons() {
    5353                java.net.URL imgURL = getClass().getResource(RES_OSM_ICON);
    54             if (imgURL != null) {
    55                 iconStandard = new ImageIcon(imgURL);
    56             } else {
    57                 System.err.println("Could not load icon: " + RES_OSM_ICON);
    58                 iconStandard = null;
    59             }
    60            
     54                if (imgURL != null) {
     55                        iconStandard = new ImageIcon(imgURL);
     56                } else {
     57                        System.err.println("Could not load icon: " + RES_OSM_ICON);
     58                        iconStandard = null;
     59                }
     60
    6161                imgURL = getClass().getResource(RES_SELECTION_ICON);
    62             if (imgURL != null) {
    63                 iconSelection = new ImageIcon(imgURL);
    64             } else {
    65                 System.err.println("Could not load icon: " + RES_SELECTION_ICON);
    66                 iconSelection = null;
    67             }
     62                if (imgURL != null) {
     63                        iconSelection = new ImageIcon(imgURL);
     64                } else {
     65                        System.err.println("Could not load icon: " + RES_SELECTION_ICON);
     66                        iconSelection = null;
     67                }
    6868        }
    69        
    70        
     69
     70
    7171        /**
    72          * prepares the renderer for rendering a specific icon 
     72         * prepares the renderer for rendering a specific icon
    7373         *
    74          * @param item the item to be rendered 
     74         * @param item the item to be rendered
    7575         */
    7676        protected void prepareRendererIcon(AutoCompletionListItem item) {
     
    8585                }
    8686        }
    87        
     87
    8888        /**
    89          * resets the renderer 
     89         * resets the renderer
    9090         */
    9191        protected void resetRenderer() {
     
    9696                renderer.setForeground(Color.BLACK);
    9797        }
    98        
     98
    9999        /**
    100          * prepares background and text colors for a selected item 
     100         * prepares background and text colors for a selected item
    101101         */
    102102        protected void renderSelected() {
     
    104104                renderer.setForeground(Color.WHITE);
    105105        }
    106        
    107         @Override
     106
    108107        public Component getTableCellRendererComponent(JTable table, Object value,
    109108                        boolean isSelected, boolean hasFocus, int row, int column) {
    110                
     109
    111110                resetRenderer();
    112                 // set icon and text 
     111                // set icon and text
    113112                //
    114113                if (value instanceof AutoCompletionListItem) {
     
    121120                        renderer.setText("<null>");
    122121                }
    123                
    124                 // prepare background and foreground for a selected item 
     122
     123                // prepare background and foreground for a selected item
    125124                //
    126125                if (isSelected) {
    127126                        renderSelected();
    128127                }
    129                
    130                
     128
     129
    131130                return renderer;
    132        
     131
    133132        }
    134133
    135        
    136        
     134
     135
    137136}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/PresetItemListCellRenderer.java

    r14325 r15319  
    11package org.openstreetmap.josm.plugins.tageditor.editor;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
    24
    35import java.awt.Color;
     
    1113
    1214import org.openstreetmap.josm.plugins.tageditor.preset.Item;
    13 import static org.openstreetmap.josm.tools.I18n.tr;
    1415
    1516public class PresetItemListCellRenderer extends JLabel implements
    16                 ListCellRenderer {
     17ListCellRenderer {
    1718
    1819        private static final Logger logger = Logger.getLogger(PresetItemListCellRenderer.class.getName());
    1920        private static final Font DEFAULT_FONT =  new Font("SansSerif",Font.PLAIN,10);
    2021        public static final Color BG_COLOR_SELECTED = new Color(143,170,255);
    21        
    22         @Override
     22
    2323        public Component getListCellRendererComponent(JList list, Object value,
    2424                        int index, boolean isSelected, boolean cellHasFocus) {
    25                
    26        
     25
    2726                Item item = (Item)value;
    2827                if (item == null) {
     
    3837                        StringBuilder sb = new StringBuilder();
    3938                        sb.append(item.getParent().getName())
    40                           .append("/")
    41                           .append(item.getName());
     39                        .append("/")
     40                        .append(item.getName());
    4241                        setText(sb.toString());
    4342                        setOpaque(true);
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/PresetManager.java

    r14338 r15319  
    11package org.openstreetmap.josm.plugins.tageditor.editor;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
    24
    35import java.awt.Dimension;
     
    1416
    1517import org.openstreetmap.josm.plugins.tageditor.preset.Item;
    16 import static org.openstreetmap.josm.tools.I18n.tr;
    1718
    1819public class PresetManager extends JPanel {
    1920
    2021        static private Logger logger = Logger.getLogger(PresetManager.class.getName());
    21        
     22
    2223        private JComboBox presets;
    23         private JButton btnRemove; 
     24        private JButton btnRemove;
    2425        private JButton btnHighlight;
    2526        private TagEditorModel model = null;
    26        
     27
    2728        protected void build() {
    2829                setLayout(new FlowLayout(FlowLayout.LEFT));
    29                
     30
    3031                // create the combobox to display the list of applied presets
    3132                //
     
    3839                        }
    3940                };
    40                
     41
    4142                presets.addItemListener(
    42                         new ItemListener(){
    43                                 @Override
    44                                 public void itemStateChanged(ItemEvent e) {
    45                                         syncWidgetStates();
     43                                new ItemListener(){
     44                                        public void itemStateChanged(ItemEvent e) {
     45                                                syncWidgetStates();
     46                                        }
    4647                                }
    47                         }
    4848                );
    49                
     49
    5050                presets.setRenderer(new PresetItemListCellRenderer());
    5151                add(presets);
    52        
     52
    5353                btnHighlight = new JButton(tr("Highlight"));
    5454                btnHighlight.addActionListener(
    5555                                new ActionListener()  {
    56                                         @Override
    5756                                        public void actionPerformed(ActionEvent arg0) {
    5857                                                highlightCurrentPreset();
    5958                                        }
    6059                                }
    61                         );
    62                
     60                );
     61
    6362                add(btnHighlight);
    64                
     63
    6564                btnRemove = new JButton(tr("Remove"));
    6665                btnRemove.addActionListener(
    67                         new ActionListener()  {
    68                                 @Override
    69                                 public void actionPerformed(ActionEvent arg0) {
    70                                         removeCurrentPreset();
     66                                new ActionListener()  {
     67                                        public void actionPerformed(ActionEvent arg0) {
     68                                                removeCurrentPreset();
     69                                        }
    7170                                }
    72                         }
    7371                );
    7472
     
    7674                syncWidgetStates();
    7775        }
    78        
     76
    7977        protected void syncWidgetStates() {
    8078                btnRemove.setEnabled(presets.getSelectedItem() != null);
    8179                btnHighlight.setEnabled(presets.getSelectedItem() != null);
    8280        }
    83        
     81
    8482        protected void removeCurrentPreset() {
    8583                Item item= (Item)presets.getSelectedItem();
     
    8886                }
    8987        }
    90        
     88
    9189        protected void highlightCurrentPreset() {
    9290                model.highlightCurrentPreset();
    9391        }
    94        
     92
    9593        public PresetManager() {
    9694                build();
    9795        }
    98        
     96
    9997        public void setModel(TagEditorModel model) {
    10098                presets.setModel(model.getAppliedPresetsModel());
    10199                this.model = model;
    102100        }
    103        
    104        
    105        
     101
     102
     103
    106104}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/RunnableAction.java

    r14325 r15319  
    77public abstract class RunnableAction extends AbstractAction implements Runnable {
    88
    9         public RunnableAction() {               
     9        public RunnableAction() {
    1010        }
    1111
    12         @Override
    1312        public abstract void run();
    1413
    15         @Override
    1614        public void actionPerformed(ActionEvent arg0) {
    17                 run();         
     15                run();
    1816        }
    1917}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TableCellEditor.java

    r14520 r15319  
    33
    44import java.awt.Component;
    5 import java.util.Collection;
    65import java.util.logging.Level;
    76import java.util.logging.Logger;
     
    109import javax.swing.JTable;
    1110
    12 import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1411import org.openstreetmap.josm.plugins.tageditor.ac.AutoCompletionCache;
    1512import org.openstreetmap.josm.plugins.tageditor.ac.AutoCompletionContext;
     
    2825@SuppressWarnings("serial")
    2926public class TableCellEditor extends AbstractCellEditor implements javax.swing.table.TableCellEditor, IAutoCompletionListListener{
    30        
     27
    3128        /** the logger object */
    3229        static private Logger logger = Logger.getLogger(TableCellEditor.class.getName());
     
    3936        /** the cache of auto completion items derived from the current JOSM data set */
    4037        private AutoCompletionCache acCache = null;
    41        
     38
    4239        /** user input is matched against this list of auto completion items */
    4340        private AutoCompletionList autoCompletionList = null;
    44        
    45 
    46         /**
    47          * constructor 
     41
     42
     43        /**
     44         * constructor
    4845         */
    4946        public TableCellEditor() {
     
    5148                acCache = new AutoCompletionCache();
    5249        }
    53        
     50
    5451        /**
    5552         * initializes  the auto completion list when the table cell editor starts
    56          * to edit the key of a tag. In this case the auto completion list is 
     53         * to edit the key of a tag. In this case the auto completion list is
    5754         * initialized with the set of standard key values and the set of current key
    58          * values from the the current JOSM data set. Keys already present in the 
     55         * values from the the current JOSM data set. Keys already present in the
    5956         * current tag model are removed from the auto completion list.
    60          *  
    61          * @param model  the tag editor model 
    62          * @param currentTag  the current tag 
     57         *
     58         * @param model  the tag editor model
     59         * @param currentTag  the current tag
    6360         */
    6461        protected void initAutoCompletionListForKeys(TagEditorModel model, TagModel currentTag) {
    6562                AutoCompletionContext context = new AutoCompletionContext();
    6663                context.initFromJOSMSelection();
    67                
     64
    6865                if (autoCompletionList == null) {
    6966                        logger.warning("autoCompletionList is null. Make sure an instance of AutoCompletionList is injected into TableCellEditor.");
    7067                        return;
    7168                }
    72                
     69
    7370                autoCompletionList.clear();
    74                
    75                 // add the list of standard keys 
     71
     72                // add the list of standard keys
    7673                //
    7774                try {
     
    8077                        logger.log(Level.WARNING, "failed to initialize auto completion list with standard keys.", e);
    8178                }
    82                
    83                
    84                
     79
     80
     81
    8582                // add the list of keys in the current data set
    8683                //
     
    9087                        );
    9188                }
    92                
     89
    9390                // remove the keys already present in the current tag model
    9491                //
     
    10097                autoCompletionList.fireTableDataChanged();
    10198        }
    102        
    103        
     99
     100
    104101        /**
    105102         * initializes the auto completion list when the cell editor starts to edit
     
    108105         * current data set for the given key.
    109106         *
    110          * @param forKey the key 
     107         * @param forKey the key
    111108         */
    112109        protected void initAutoCompletionListForValues(String forKey) {
    113                
     110
    114111                if (autoCompletionList == null) {
    115112                        logger.warning("autoCompletionList is null. Make sure an instance of AutoCompletionList is injected into TableCellEditor.");
    116113                        return;
    117                 }               
     114                }
    118115                autoCompletionList.clear();
    119116                AutoCompletionContext context = new AutoCompletionContext();
    120117                context.initFromJOSMSelection();
    121                
     118
    122119                // add the list of standard values for the given key
    123120                //
     
    129126                        logger.log(Level.WARNING, "failed to initialize auto completion list with standard values", e);
    130127                }
    131                
     128
    132129                for (String value : acCache.getValues(forKey)) {
    133130                        autoCompletionList.add(
     
    135132                        );
    136133                }
    137                
     134
    138135                //  add the list of possible values for a key from the current selection
    139136                //
     
    142139                                //logger.info("adding ac item " + value + " with priority IN_SELECTION");;
    143140                                autoCompletionList.add(
    144                                                 new AutoCompletionListItem(value, AutoCompletionItemPritority.IS_IN_SELECTION)                                 
     141                                                new AutoCompletionListItem(value, AutoCompletionItemPritority.IS_IN_SELECTION)
    145142                                );
    146143                        }
    147144                }
    148145        }
    149        
    150        
    151         /**
    152          * replies the table cell editor
    153          */
    154         @Override public Component getTableCellEditorComponent(JTable table,
    155             Object value, boolean isSelected, int row, int column) {   
    156                         currentTag = (TagModel) value;
    157                        
    158                         if (column == 0) {                             
    159                                 editor.setText(currentTag.getName());
    160                                 currentColumn = 0;
    161                                 TagEditorModel model = (TagEditorModel)table.getModel();
    162                                 initAutoCompletionListForKeys(model, currentTag);               
    163                                 return editor;
    164                         } else if (column == 1) {
    165                
    166                                 if (currentTag.getValueCount() == 0) {
    167                                         editor.setText("");
    168                                 } else if (currentTag.getValueCount() == 1) {
    169                                         editor.setText(currentTag.getValues().get(0));
    170                                 } else {
    171                                         editor.setText("");
    172                                 }
    173                                 currentColumn = 1;
    174                                 initAutoCompletionListForValues(currentTag.getName());
    175                                 return editor;
     146
     147
     148        /**
     149         * replies the table cell editor
     150         */
     151        public Component getTableCellEditorComponent(JTable table,
     152                        Object value, boolean isSelected, int row, int column) {
     153                currentTag = (TagModel) value;
     154
     155                if (column == 0) {
     156                        editor.setText(currentTag.getName());
     157                        currentColumn = 0;
     158                        TagEditorModel model = (TagEditorModel)table.getModel();
     159                        initAutoCompletionListForKeys(model, currentTag);
     160                        return editor;
     161                } else if (column == 1) {
     162
     163                        if (currentTag.getValueCount() == 0) {
     164                                editor.setText("");
     165                        } else if (currentTag.getValueCount() == 1) {
     166                                editor.setText(currentTag.getValues().get(0));
    176167                        } else {
    177                                 logger.warning("column this table cell editor is requested for is out of range. column=" + column);
    178                                 return null;
    179                         }
    180     }
    181 
    182                
    183         @Override
     168                                editor.setText("");
     169                        }
     170                        currentColumn = 1;
     171                        initAutoCompletionListForValues(currentTag.getName());
     172                        return editor;
     173                } else {
     174                        logger.warning("column this table cell editor is requested for is out of range. column=" + column);
     175                        return null;
     176                }
     177        }
     178
    184179        public Object getCellEditorValue() {
    185180                return editor.getText();
    186     }
    187 
    188        
    189        
     181        }
     182
    190183        @Override
    191184        public void cancelCellEditing() {
     
    198191                        logger.warning("no tag editor model set. Can't update edited values. Please set tag editor model first");
    199192                        return super.stopCellEditing();
    200             }
    201                
     193                }
     194
    202195                if (currentColumn == 0) {
    203196                        tagEditorModel.updateTagName(currentTag, editor.getText());
    204197                } else if (currentColumn == 1){
    205198                        if (currentTag.getValueCount() > 1 && ! editor.getText().equals("")) {
    206                                 tagEditorModel.updateTagValue(currentTag, editor.getText());           
     199                                tagEditorModel.updateTagValue(currentTag, editor.getText());
    207200                        } else if (currentTag.getValueCount() <= 1) {
    208201                                tagEditorModel.updateTagValue(currentTag, editor.getText());
    209202                        }
    210203                }
    211            
    212                 return super.stopCellEditing(); 
     204
     205                return super.stopCellEditing();
    213206        }
    214207
     
    216209         * replies the {@link AutoCompletionList} this table cell editor synchronizes with
    217210         *
    218          * @return the auto completion list 
     211         * @return the auto completion list
    219212         */
    220213        public AutoCompletionList getAutoCompletionList() {
    221         return autoCompletionList;
    222     }
    223 
    224         /**
    225          * sets the {@link AutoCompletionList} this table cell editor synchronizes with 
    226          * @param autoCompletionList the auto completion list 
     214                return autoCompletionList;
     215        }
     216
     217        /**
     218         * sets the {@link AutoCompletionList} this table cell editor synchronizes with
     219         * @param autoCompletionList the auto completion list
    227220         */
    228221        public void setAutoCompletionList(AutoCompletionList autoCompletionList) {
    229         this.autoCompletionList = autoCompletionList;
    230         editor.setAutoCompletionList(autoCompletionList);
    231     }
    232        
     222                this.autoCompletionList = autoCompletionList;
     223                editor.setAutoCompletionList(autoCompletionList);
     224        }
     225
    233226        public void setAutoCompletionCache(AutoCompletionCache acCache) {
    234227                this.acCache = acCache;
    235228        }
    236        
    237 
    238        
    239         @Override
     229
    240230        public void autoCompletionItemSelected(String item) {
    241231                editor.setText(item);
     
    243233                editor.requestFocus();
    244234        }
    245        
     235
    246236        public TagFieldEditor getEditor() {
    247237                return editor;
    248238        }
    249        
     239
    250240        /**
    251241         * sets the tag editor model
    252          *  
    253          * @param tagEditorModel  the tag editor model 
     242         *
     243         * @param tagEditorModel  the tag editor model
    254244         */
    255245        public void setTagEditorModel(TagEditorModel tagEditorModel) {
    256246                this.tagEditorModel = tagEditorModel;
    257247        }
    258        
     248
    259249}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditor.java

    r14520 r15319  
    1111import javax.swing.ScrollPaneConstants;
    1212
    13 
    1413import org.openstreetmap.josm.plugins.tageditor.ac.AutoCompletionCache;
    1514import org.openstreetmap.josm.plugins.tageditor.ac.AutoCompletionList;
     
    2019 * TagEditor is a {@link JPanel} which consists of a two sub panels:
    2120 * <ul>
    22  *   <li>a small area in which a drop-down box with a list of presets is displayed. 
     21 *   <li>a small area in which a drop-down box with a list of presets is displayed.
    2322 *       Two buttons allow to highlight and remove a presets respectively.</li>
    2423 *   <li>the main table with the tag names and tag values
     
    3029 *    <li>an instance of {@link TagEditorModel} - use {@see #setTagEditorModel(TagEditorModel)}</li>
    3130 *    <li>an instance of {@link AutoCompletionCache} - inject it using {@see #setAutoCompletionCache(AutoCompletionCache)}.
    32  *      The table cell editor used by the table in this component uses the AutoCompletionCache in order to 
     31 *      The table cell editor used by the table in this component uses the AutoCompletionCache in order to
    3332 *      build up a list of auto completion values from the current data set</li>
    3433 *    <li>an instance of {@link AutoCompletionList} - inject it using {@see #setAutoCompletionList(AutoCompletionList)}.
    3534 *      The table cell editor used by the table in this component uses the AutoCompletionList
    36  *      to build up a list of auto completion values from the set of  standardized 
     35 *      to build up a list of auto completion values from the set of  standardized
    3736 *      OSM tags</li>
    3837 *  </ul>O
     
    4140 *  <pre>
    4241 *     AutoCompletionList autoCompletionList = .... // init the autocompletion list
    43  *     AutoCompletionCache autoCompletionCache = ... // init the auto completion cache 
    44  *     TagEditorModel model = ... // init the tag editor model 
    45  *    
     42 *     AutoCompletionCache autoCompletionCache = ... // init the auto completion cache
     43 *     TagEditorModel model = ... // init the tag editor model
     44 *
    4645 *     TagEditor tagEditor = new TagEditor();
    4746 *     tagEditor.setTagEditorModel(model);
    4847 *     tagEditor.setAutoCompletionList(autoCompletionList);
    49  *     tagEditor.setAutoCompletionCache(autoCompletionCache); 
     48 *     tagEditor.setAutoCompletionCache(autoCompletionCache);
    5049 *  </pre>
    5150 */
     
    5352
    5453        private static final Logger logger = Logger.getLogger(TagEditor.class.getName());
    55        
    56         private TagEditorModel tagEditorModel;
     54
     55        private final TagEditorModel tagEditorModel;
    5756        private TagTable tblTagEditor;
    5857        private PresetManager presetManager;
    5958        private AutoCompletionList autoCompletionList;
    60        
    61        
     59
     60
    6261        /**
    6362         * builds the GUI
     
    6665        protected void build() {
    6766                setLayout(new BorderLayout());
    68                
     67
    6968                // build the scrollable table for editing tag names and tag values
    7069                //
     
    7473                scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    7574                add(scrollPane, BorderLayout.CENTER);
    76                
     75
    7776                // this adapters ensures that the width of the tag table columns is adjusted
    78                 // to the width of the scroll pane viewport. Also tried to overwrite 
     77                // to the width of the scroll pane viewport. Also tried to overwrite
    7978                // getPreferredViewportSize() in JTable, but did not work.
    8079                //
     
    8281                                new ComponentAdapter() {
    8382                                        @Override public void componentResized(ComponentEvent e) {
    84                             super.componentResized(e);
    85                             Dimension d = scrollPane.getViewport().getExtentSize();
    86                             tblTagEditor.adjustColumnWidth(d.width);
    87                     }
     83                                                super.componentResized(e);
     84                                                Dimension d = scrollPane.getViewport().getExtentSize();
     85                                                tblTagEditor.adjustColumnWidth(d.width);
     86                                        }
    8887                                }
    8988                );
    90                
    91                 // build the preset manager which shows a list of applied presets 
    92                 // 
     89
     90                // build the preset manager which shows a list of applied presets
     91                //
    9392                presetManager = new PresetManager();
    9493                presetManager.setModel(tagEditorModel);
    9594                add(presetManager, BorderLayout.NORTH);
    9695        }
    97        
    98        
     96
     97
    9998        /**
    100          * constructor 
     99         * constructor
    101100         */
    102101        public TagEditor() {
    103                 // creates a default model and a default cache 
     102                // creates a default model and a default cache
    104103                //
    105                 tagEditorModel = new TagEditorModel();         
    106                
     104                tagEditorModel = new TagEditorModel();
     105
    107106                build();
    108107        }
    109108
    110        
     109
    111110        /**
    112          * replies the tag editor model 
    113          * @return the tag editor model 
     111         * replies the tag editor model
     112         * @return the tag editor model
    114113         */
    115114        public TagEditorModel getTagEditorModel() {
     
    120119         * sets the tag editor model
    121120         *
    122          * @param tagEditorModel the tag editor model 
     121         * @param tagEditorModel the tag editor model
    123122         */
    124123        public void setTagEditorModel(TagEditorModel tagEditorModel) {
     
    132131                presetManager.setModel(tagEditorModel);
    133132        }
    134        
     133
    135134        public RunnableAction getDeleteAction() {
    136135                return tblTagEditor.getDeleteAction();
    137136        }
    138        
     137
    139138        public RunnableAction getAddAction() {
    140139                return tblTagEditor.getAddAction();
    141140        }
    142        
    143        
    144        
     141
     142
     143
    145144        public void clearSelection() {
    146145                tblTagEditor.getSelectionModel().clearSelection();
    147146        }
    148        
    149147
    150        
     148
     149
    151150        public void stopEditing() {
    152151                TableCellEditor editor = (TableCellEditor) tblTagEditor.getCellEditor();
     
    155154                }
    156155        }
    157        
    158        
     156
     157
    159158        public AutoCompletionList getAutoCompletionList() {
    160159                return ((org.openstreetmap.josm.plugins.tageditor.editor.TableCellEditor)tblTagEditor.getCellEditor()).getAutoCompletionList();
     
    164163                tblTagEditor.setAutoCompletionList(autoCompletionList);
    165164        }
    166        
     165
    167166        public void setAutoCompletionCache(AutoCompletionCache acCache) {
    168167                tblTagEditor.setAutoCompletionCache(acCache);
    169168        }
    170169
    171         @Override
     170
    172171        public void autoCompletionItemSelected(String item) {
    173172                org.openstreetmap.josm.plugins.tageditor.editor.TableCellEditor editor = ((org.openstreetmap.josm.plugins.tageditor.editor.TableCellEditor)tblTagEditor.getCellEditor());
     
    180179                tblTagEditor.requestFocusInCell(0,0);
    181180        }
    182                
    183        
    184        
    185        
    186        
    187        
     181
     182
     183
     184
     185
     186
    188187}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditorModel.java

    r14520 r15319  
    1313
    1414import javax.swing.DefaultComboBoxModel;
    15 import javax.swing.SwingUtilities;
    1615import javax.swing.table.AbstractTableModel;
    1716
     
    2726
    2827/**
    29  * TagEditorModel is a table model. 
    30  *  
     28 * TagEditorModel is a table model.
     29 *
    3130 *
    3231 * @author gubaer
     
    3635public class TagEditorModel extends AbstractTableModel {
    3736        static private final Logger logger = Logger.getLogger(TagEditorModel.class.getName());
    38        
    39         static public final String PROP_DIRTY = TagEditorModel.class.getName() + ".dirty"; 
    40        
     37
     38        static public final String PROP_DIRTY = TagEditorModel.class.getName() + ".dirty";
     39
    4140        /** the list holding the tags */
    42         private  ArrayList<TagModel> tags = null; 
     41        private  ArrayList<TagModel> tags = null;
    4342        private  ArrayList<Item> items = null;
    44        
     43
    4544        /** indicates whether the model is dirty */
    46         private boolean dirty =  false; 
     45        private boolean dirty =  false;
    4746        private PropertyChangeSupport propChangeSupport = null;
    48        
     47
    4948        private DefaultComboBoxModel appliedPresets = null;
    5049
    51        
     50
    5251        /**
    5352         * constructor
     
    6362                propChangeSupport.addPropertyChangeListener(listener);
    6463        }
    65        
     64
    6665        public void removeProperyChangeListener(PropertyChangeListener listener) {
    6766                propChangeSupport.removePropertyChangeListener(listener);
    6867        }
    69        
     68
    7069        protected void fireDirtyStateChanged(final boolean oldValue, final boolean newValue) {
    7170                propChangeSupport.firePropertyChange(PROP_DIRTY, oldValue, newValue);
    7271        }
    73        
     72
    7473        protected void setDirty(boolean newValue) {
    7574                boolean oldValue = dirty;
     
    7978                }
    8079        }
    81        
    82         @Override public int getColumnCount() {
    83             return 2;
    84     }
    85 
    86         @Override public int getRowCount() {
    87             return tags.size();
    88     }
    89 
    90         @Override public Object getValueAt(int rowIndex, int columnIndex) {
    91                 if (rowIndex >= getRowCount()) {
     80
     81        public int getColumnCount() {
     82                return 2;
     83        }
     84
     85        public int getRowCount() {
     86                return tags.size();
     87        }
     88
     89        public Object getValueAt(int rowIndex, int columnIndex) {
     90                if (rowIndex >= getRowCount())
    9291                        throw new IndexOutOfBoundsException("unexpected rowIndex: rowIndex=" + rowIndex);
    93                 }
    94                
     92
    9593                TagModel tag = tags.get(rowIndex);
    9694                switch(columnIndex) {
    9795                case 0:
    98                 case 1: return tag; 
    99        
    100                 default: 
     96                case 1: return tag;
     97
     98                default:
    10199                        throw new IndexOutOfBoundsException("unexpected columnIndex: columnIndex=" + columnIndex);
    102                 }               
    103     }
    104        
    105        
    106         /**
    107          * removes all tags in the model 
     100                }
     101        }
     102
     103
     104        /**
     105         * removes all tags in the model
    108106         */
    109107        public void clear() {
     
    113111                fireTableDataChanged();
    114112        }
    115        
     113
    116114        /**
    117115         * adds a tag to the model
     
    122120         */
    123121        public void add(TagModel tag) {
    124                 if (tag == null) {
     122                if (tag == null)
    125123                        throw new IllegalArgumentException("argument 'tag' must not be null");
    126                 }
    127124                tags.add(tag);
    128125                setDirty(true);
    129126                fireTableDataChanged();
    130127        }
    131        
    132        
     128
     129
    133130        public void prepend(TagModel tag) {
    134                 if (tag == null) {
     131                if (tag == null)
    135132                        throw new IllegalArgumentException("argument 'tag' must not be null");
    136                 }
    137133                tags.add(0, tag);
    138134                setDirty(true);
    139135                fireTableDataChanged();
    140136        }
    141        
    142        
    143         /**
    144          * adds a tag given by a name/value pair to the tag editor model. 
     137
     138
     139        /**
     140         * adds a tag given by a name/value pair to the tag editor model.
    145141         *
    146142         * If there is no tag with name <code>name</name> yet, a new {@link TagModel} is created
    147143         * and append to this model.
    148144         *
    149          * If there is a tag with name <code>name</name>, <code>value</code> is merged to the list 
    150          * of values for this tag. 
     145         * If there is a tag with name <code>name</name>, <code>value</code> is merged to the list
     146         * of values for this tag.
    151147         *
    152148         * @param name the name; converted to "" if null
     
    156152                name = (name == null) ? "" : name;
    157153                value = (value == null) ? "" : value;
    158                
     154
    159155                TagModel tag = get(name);
    160156                if (tag == null) {
     
    163159                } else {
    164160                        tag.addValue(value);
    165                 }       
    166                 setDirty(true);
    167         }
    168        
    169        
    170         /**
    171          * replies the tag with name <code>name</code>; null, if no such tag exists 
    172          * @param name the tag name 
    173          * @return the tag with name <code>name</code>; null, if no such tag exists 
     161                }
     162                setDirty(true);
     163        }
     164
     165
     166        /**
     167         * replies the tag with name <code>name</code>; null, if no such tag exists
     168         * @param name the tag name
     169         * @return the tag with name <code>name</code>; null, if no such tag exists
    174170         */
    175171        public TagModel get(String name) {
    176172                name = (name == null) ? "" : name;
    177173                for (TagModel tag : tags) {
    178                         if (tag.getName().equals(name)) {
    179                                 return tag;
    180                         }
    181                 }
    182                 return null;
    183         }
    184        
     174                        if (tag.getName().equals(name))
     175                                return tag;
     176                }
     177                return null;
     178        }
     179
    185180        public TagModel get(int idx) {
    186181                TagModel tagModel = tags.get(idx);
     
    189184
    190185
    191        
     186
    192187        @Override public boolean isCellEditable(int row, int col) {
    193188                // all cells are editable
    194189                return true;
    195     }
    196 
    197 
    198         /**
    199          * deletes the names of the tags given by tagIndices 
    200          *
    201          * @param tagIndices a list of tag indices 
     190        }
     191
     192
     193        /**
     194         * deletes the names of the tags given by tagIndices
     195         *
     196         * @param tagIndices a list of tag indices
    202197         */
    203198        public void deleteTagNames(int [] tagIndices) {
    204                 if (tags == null) {
    205                         return;
    206                 }
     199                if (tags == null)
     200                        return;
    207201                for (int tagIdx : tagIndices) {
    208202                        TagModel tag = tags.get(tagIdx);
     
    218212         * deletes the values of the tags given by tagIndices
    219213         *
    220          * @param tagIndices the lit of tag indices 
     214         * @param tagIndices the lit of tag indices
    221215         */
    222216        public void deleteTagValues(int [] tagIndices) {
    223                 if (tags == null) {
    224                         return;
    225                 }
     217                if (tags == null)
     218                        return;
    226219                for (int tagIdx : tagIndices) {
    227220                        TagModel tag = tags.get(tagIdx);
     
    233226                setDirty(true);
    234227        }
    235        
     228
    236229        /**
    237230         * deletes the tags given by tagIndices
    238231         *
    239          * @param tagIndices the list of tag indices 
     232         * @param tagIndices the list of tag indices
    240233         */
    241234        public void deleteTags(int [] tagIndices) {
    242                 if (tags == null) {
    243                         return;
    244                 }
     235                if (tags == null)
     236                        return;
    245237                ArrayList<TagModel> toDelete = new ArrayList<TagModel>();
    246238                for (int tagIdx : tagIndices) {
     
    256248                setDirty(true);
    257249        }
    258        
    259        
    260         /**
    261          * creates a new tag and appends it to the model 
     250
     251
     252        /**
     253         * creates a new tag and appends it to the model
    262254         */
    263255        public void appendNewTag() {
     
    269261
    270262        /**
    271          * makes sure the model includes at least one (empty) tag 
     263         * makes sure the model includes at least one (empty) tag
    272264         */
    273265        public void ensureOneTag() {
     
    276268                }
    277269        }
    278        
     270
    279271        /**
    280272         * initializes the model with the tags in the current JOSM selection
     
    292284                setDirty(false);
    293285        }
    294        
    295        
    296         /**
    297          * checks whether the tag model includes a tag with a given key 
    298          *
    299          * @param key  the key 
    300          * @return true, if the tag model includes the tag; false, otherwise 
     286
     287
     288        /**
     289         * checks whether the tag model includes a tag with a given key
     290         *
     291         * @param key  the key
     292         * @return true, if the tag model includes the tag; false, otherwise
    301293         */
    302294        public boolean includesTag(String key) {
    303                 if (key == null) return false; 
     295                if (key == null) return false;
    304296                for (TagModel tag : tags) {
    305                         if (tag.getName().equals(key)) {
    306                                 return true;
    307                         }
     297                        if (tag.getName().equals(key))
     298                                return true;
    308299                }
    309300                return false;
    310301        }
    311        
     302
    312303
    313304        protected Command createUpdateTagCommand(Collection<OsmPrimitive> primitives, TagModel tag) {
    314                
     305
    315306                // tag still holds an unchanged list of different values for the same key.
    316                 // no property change command required 
    317                 if (tag.getValueCount() > 1) {
     307                // no property change command required
     308                if (tag.getValueCount() > 1)
    318309                        return null;
    319                 }
    320                
    321                 // tag name holds an empty key. Don't apply it to the selection.
    322                 //
    323                 if (tag.getName().trim().equals("")) {
    324                         return null;
    325                 }
    326                
     310
     311                // tag name holds an empty key. Don't apply it to the selection.
     312                //
     313                if (tag.getName().trim().equals(""))
     314                        return null;
     315
    327316                String newkey = tag.getName();
    328317                String newvalue = tag.getValue();
    329                
     318
    330319                ChangePropertyCommand command = new ChangePropertyCommand(primitives,newkey, newvalue);
    331                 return command;                 
    332         }
    333        
     320                return command;
     321        }
     322
    334323        protected Command createDeleteTagsCommand(Collection<OsmPrimitive> primitives) {
    335                
     324
    336325                List<String> currentkeys = getKeys();
    337326                ArrayList<Command> commands = new ArrayList<Command>();
    338                
     327
    339328                for (OsmPrimitive primitive : primitives) {
    340329                        if (primitive.keys == null) {
     
    343332                        for (String oldkey : primitive.keys.keySet()) {
    344333                                if (!currentkeys.contains(oldkey)) {
    345                                         ChangePropertyCommand deleteCommand = 
     334                                        ChangePropertyCommand deleteCommand =
    346335                                                new ChangePropertyCommand(primitive,oldkey,null);
    347336                                        commands.add(deleteCommand);
     
    349338                        }
    350339                }
    351                
     340
    352341                SequenceCommand command = new SequenceCommand(
    353                         trn("Remove old keys from up to {0} object", "Remove old keys from up to {0} objects", primitives.size(), primitives.size()),
    354                         commands
     342                                trn("Remove old keys from up to {0} object", "Remove old keys from up to {0} objects", primitives.size(), primitives.size()),
     343                                commands
    355344                );
    356                
     345
    357346                return command;
    358347        }
    359        
     348
    360349        /**
    361350         * updates the tags of the primitives in the current selection with the
    362          * values in the current tag model 
     351         * values in the current tag model
    363352         *
    364353         */
     
    366355                ArrayList<Command> commands = new ArrayList<Command>();
    367356                Collection<OsmPrimitive> selection = Main.ds.getSelected();
    368                 if (selection == null) {
    369                         return;
    370                 }
     357                if (selection == null)
     358                        return;
    371359                for (TagModel tag : tags) {
    372360                        Command command = createUpdateTagCommand(selection,tag);
     
    379367                        commands.add(deleteCommand);
    380368                }
    381                
     369
    382370                SequenceCommand command = new SequenceCommand(
    383                         trn("Updating properties of up to {0} object", "Updating properties of up to {0} objects", selection.size(), selection.size()),
    384                         commands                               
     371                                trn("Updating properties of up to {0} object", "Updating properties of up to {0} objects", selection.size(), selection.size()),
     372                                commands
    385373                );
    386                
     374
    387375                // executes the commands and adds them to the undo/redo chains
    388376                Main.main.undoRedo.add(command);
    389377        }
    390        
    391        
     378
     379
    392380        /**
    393381         * replies the list of keys of the tags managed by this model
     
    404392                return keys;
    405393        }
    406        
    407         /**
    408          * sorts the current tags according alphabetical order of names 
     394
     395        /**
     396         * sorts the current tags according alphabetical order of names
    409397         */
    410398        protected void sort() {
     
    412400                                tags,
    413401                                new Comparator<TagModel>() {
    414                                         @Override
    415402                                        public int compare(TagModel self, TagModel other) {
    416403                                                return self.getName().compareTo(other.getName());
    417                                         }                                       
     404                                        }
    418405                                }
    419406                );
    420407        }
    421408
    422        
    423        
    424 
    425         /**
    426          * applies the tags defined for a preset item to the tag model. 
    427          *
    428          * Mandatory tags are added to the list of currently edited tags. 
    429          * Optional tags are not added. 
    430          * The model remembers the currently applied presets. 
     409
     410
     411
     412        /**
     413         * applies the tags defined for a preset item to the tag model.
     414         *
     415         * Mandatory tags are added to the list of currently edited tags.
     416         * Optional tags are not added.
     417         * The model remembers the currently applied presets.
    431418         *
    432419         * @param item  the preset item. Must not be null.
     
    435422         */
    436423        public void applyPreset(Item item) {
    437                 if (item == null) {
     424                if (item == null)
    438425                        throw new IllegalArgumentException("argument 'item' must not be null");
    439                 }
    440426                // check whether item is already applied
    441427                //
    442428                for(int i=0; i < appliedPresets.getSize(); i++) {
    443                         if (appliedPresets.getElementAt(i).equals(item)) {
    444                                 // abort - preset already applied 
     429                        if (appliedPresets.getElementAt(i).equals(item))
     430                                // abort - preset already applied
    445431                                return;
    446                         }
    447                 }
    448                
    449                 // apply the tags proposed by the preset
     432                }
     433
     434                // apply the tags proposed by the preset
    450435                //
    451436                for(Tag tag : item.getTags()) {
     
    466451                        }
    467452                }
    468                
     453
    469454                // remember the preset and make it the current preset
    470455                //
     
    473458                fireTableDataChanged();
    474459        }
    475        
    476        
     460
     461
    477462        /**
    478463         * applies a tag given by a {@see KeyValuePair} to the model
    479464         *
    480          * @param pair the key value pair 
     465         * @param pair the key value pair
    481466         */
    482467        public void applyKeyValuePair(KeyValuePair pair) {
     
    490475                fireTableDataChanged();
    491476        }
    492        
    493        
     477
     478
    494479        public DefaultComboBoxModel getAppliedPresetsModel() {
    495480                return appliedPresets;
     
    497482
    498483        public void removeAppliedPreset(Item item) {
    499                 if (item == null) {
    500                         return;
    501                 }
     484                if (item == null)
     485                        return;
    502486                for (Tag tag: item.getTags()) {
    503487                        if (tag.getValue() != null) {
     
    521505                        }
    522506                }
    523                 appliedPresets.removeElement(item);             
    524                 fireTableDataChanged();
    525         }
    526        
     507                appliedPresets.removeElement(item);
     508                fireTableDataChanged();
     509        }
     510
    527511        public void clearAppliedPresets() {
    528512                appliedPresets.removeAllElements();
    529513                fireTableDataChanged();
    530514        }
    531        
     515
    532516        public void highlightCurrentPreset() {
    533517                fireTableDataChanged();
    534518        }
    535        
    536        
    537         /**
    538          * updates the name of a tag and sets the dirty state to  true if 
    539          * the new name is different from the old name. 
    540          *
    541          * @param tag   the tag 
    542          * @param newName  the new name 
     519
     520
     521        /**
     522         * updates the name of a tag and sets the dirty state to  true if
     523         * the new name is different from the old name.
     524         *
     525         * @param tag   the tag
     526         * @param newName  the new name
    543527         */
    544528        public void updateTagName(TagModel tag, String newName) {
     
    549533                }
    550534        }
    551        
     535
    552536        /**
    553537         * updates the value value of a tag and sets the dirty state to true if the
    554          * new name is different from the old name 
    555          *
    556          * @param tag  the tag 
    557          * @param newValue  the new value 
     538         * new name is different from the old name
     539         *
     540         * @param tag  the tag
     541         * @param newValue  the new value
    558542         */
    559543        public void updateTagValue(TagModel tag, String newValue) {
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagTable.java

    r14520 r15319  
    3434
    3535/**
    36  * This is the tabular editor component for OSM tags. 
     36 * This is the tabular editor component for OSM tags.
    3737 *
    3838 *
     
    4242@SuppressWarnings("serial")
    4343public class TagTable extends JTable  {
    44        
     44
    4545        private static Logger logger = Logger.getLogger(TagTable.class.getName());
    46        
    47 
    48        
     46
     47
     48
    4949        /** the table cell editor used by this table */
    5050        private TableCellEditor editor = null;
    51        
    52        
    53        
    54         /**
    55          * The table has three columns. In the first column, we display error and 
     51
     52
     53
     54        /**
     55         * The table has three columns. In the first column, we display error and
    5656         * warning indications. The second column is used for editing rendering and
    57          * editing tag keys, the third for rendering and editing tag values. 
     57         * editing tag keys, the third for rendering and editing tag values.
    5858         *
    5959         * @author gubaer
     
    6161         */
    6262        static class TagTableColumnModel extends DefaultTableColumnModel {
    63                
     63
    6464                public TagTableColumnModel() {
    6565                        TableColumn col = null;
    6666                        TableCellRenderer renderer = new TableCellRenderer();
    67                                                
    68                        
     67
     68
    6969                        // column 0 - tag key
    7070                        col = new TableColumn(0);
     
    7373                        col.setCellRenderer(renderer);
    7474                        addColumn(col);
    75                
     75
    7676                        // column 1 - tag value
    7777                        col = new TableColumn(1);
     
    8080                        col.setCellRenderer(renderer);
    8181                        addColumn(col);
    82                
    83                 }
    84         }
    85 
    86        
     82
     83                }
     84        }
     85
     86
    8787        /**
    8888         * Action to be run when the user navigates to the next cell in the table,
     
    9191         * <ul>
    9292         *   <li>it jumps over cells in the first column</li>
    93          *   <li>it automatically add a new empty row when the user leaves the 
     93         *   <li>it automatically add a new empty row when the user leaves the
    9494         *   last cell in the table</li>
    9595         * <ul>
     
    9999         */
    100100        class SelectNextColumnCellAction extends AbstractAction  {
    101                 @Override public void actionPerformed(ActionEvent e) {
     101                public void actionPerformed(ActionEvent e) {
    102102                        run();
    103         }
    104                
     103                }
     104
    105105                public void run() {
    106106                        int col = getSelectedColumn();
    107107                        int row = getSelectedRow();
    108108                        if (getCellEditor() != null) {
    109                                 getCellEditor().stopCellEditing();                             
    110                         }
    111                        
     109                                getCellEditor().stopCellEditing();
     110                        }
     111
    112112                        if (col == 0) {
    113113                                col++;
     
    123123                                row++;
    124124                        }
    125                         changeSelection(row, col, false, false);       
    126                
    127                 }
    128         }
    129        
    130        
     125                        changeSelection(row, col, false, false);
     126
     127                }
     128        }
     129
     130
    131131        /**
    132132         * Action to be run when the user navigates to the previous cell in the table,
     
    138138        class SelectPreviousColumnCellAction extends AbstractAction  {
    139139
    140                 @Override public void actionPerformed(ActionEvent e) {
     140                public void actionPerformed(ActionEvent e) {
    141141
    142142                        int col = getSelectedColumn();
    143143                        int row = getSelectedRow();
    144144                        if (getCellEditor() != null) {
    145                                 getCellEditor().stopCellEditing();                             
    146                         }
    147 
    148                        
     145                                getCellEditor().stopCellEditing();
     146                        }
     147
     148
    149149                        if (col == 0 && row == 0) {
    150150                                // change nothing
     
    155155                                row--;
    156156                        }
    157                         changeSelection(row, col, false, false);                       
    158         }
    159         }
    160        
     157                        changeSelection(row, col, false, false);
     158                }
     159        }
     160
    161161        /**
    162162         * Action to be run when the user invokes a delete action on the table, for
     
    169169         * the selected tags are set to the empty string.
    170170         *
    171          * If the current selection consists of cell in the third column only, the values of the 
     171         * If the current selection consists of cell in the third column only, the values of the
    172172         * selected tags are set to the empty string.
    173173         *
    174          *  If the current selection consists of cells in the second and the third column, 
     174         *  If the current selection consists of cells in the second and the third column,
    175175         *  the selected tags are removed from the model.
    176          *  
     176         *
    177177         *  This action listens to the table selection. It becomes enabled when the selection
    178          *  is non-empty, otherwise it is disabled.
    179          * 
    180          * @author guaber
     178         *  is non-empty, otherwise it is disabled.
     179         *
    181180         *
    182181         */
     
    184183
    185184                /**
    186                  * delete a selection of tag names 
     185                 * delete a selection of tag names
    187186                 */
    188187                protected void deleteTagNames() {
     
    191190                        model.deleteTagNames(rows);
    192191                }
    193                
     192
    194193                /**
    195                  * delete a selection of tag values 
     194                 * delete a selection of tag values
    196195                 */
    197196                protected void deleteTagValues() {
    198197                        int[] rows = getSelectedRows();
    199198                        TagEditorModel model = (TagEditorModel)getModel();
    200                         model.deleteTagValues(rows);                   
    201                 }
    202                
     199                        model.deleteTagValues(rows);
     200                }
     201
    203202                /**
    204                  * delete a selection of tags 
     203                 * delete a selection of tags
    205204                 */
    206205                protected void deleteTags() {
    207206                        int[] rows = getSelectedRows();
    208207                        TagEditorModel model = (TagEditorModel)getModel();
    209                         model.deleteTags(rows);                 
    210                 }
    211                
     208                        model.deleteTags(rows);
     209                }
     210
    212211                /**
    213                  * constructor 
     212                 * constructor
    214213                 */
    215214                public DeleteAction() {
     
    218217                        getColumnModel().getSelectionModel().addListSelectionListener(this);
    219218                }
    220                
    221                        
    222                
     219
     220
     221
     222                @Override
    223223                public void run() {
    224                         if (!isEnabled()) {
     224                        if (!isEnabled())
    225225                                return;
    226                         }
    227226                        getCellEditor().stopCellEditing();
    228227                        if (getSelectedColumnCount() == 1) {
     
    231230                                } else if (getSelectedColumn() == 1) {
    232231                                        deleteTagValues();
    233                                 } else {
     232                                } else
    234233                                        // should not happen
    235234                                        //
    236                                         throw new IllegalStateException("unexpected selected clolumn: getSelectedColumn() is " + getSelectedColumn());                                 
    237                                 }
     235                                        throw new IllegalStateException("unexpected selected clolumn: getSelectedColumn() is " + getSelectedColumn());
    238236                        } else if (getSelectedColumnCount() == 2) {
    239237                                deleteTags();
     
    242240                        if (model.getRowCount() == 0) {
    243241                                model.ensureOneTag();
    244                                 requestFocusInCell(0, 0);                                       
     242                                requestFocusInCell(0, 0);
    245243                        }
    246244                }
    247245
    248246                /**
    249                  * listens to the table selection model 
     247                 * listens to the table selection model
    250248                 */
    251                 @Override public void valueChanged(ListSelectionEvent e) {
     249                public void valueChanged(ListSelectionEvent e) {
    252250                        if (isEditing() && getSelectedColumnCount() == 1 && getSelectedRowCount() == 1) {
    253251                                setEnabled(false);
     
    258256                        } else {
    259257                                setEnabled(false);
    260                         }         
    261                
    262         }
    263         }
    264        
     258                        }
     259
     260                }
     261        }
     262
    265263        /**
    266264         * Action to be run when the user adds a new tag.
     
    269267         */
    270268        class AddAction extends RunnableAction {
    271                
     269
    272270                public AddAction() {
    273271                        putValue(Action.NAME, tr("Add"));
    274272                }
    275                                
     273
     274                @Override
    276275                public void run() {
    277                         getCellEditor().stopCellEditing();     
     276                        getCellEditor().stopCellEditing();
    278277                        ((TagEditorModel)getModel()).appendNewTag();
    279278                        final int rowIdx = getModel().getRowCount()-1;
    280                         requestFocusInCell(rowIdx, 0);                                         
    281                 }
    282         }
    283        
     279                        requestFocusInCell(rowIdx, 0);
     280                }
     281        }
     282
    284283
    285284        /** the delete action */
    286285        private RunnableAction deleteAction = null;
    287        
     286
    288287        /** the add action */
    289288        private RunnableAction addAction = null;
    290        
    291         /**
    292          *
    293          * @return the delete action used by this table 
     289
     290        /**
     291         *
     292         * @return the delete action used by this table
    294293         */
    295294        public RunnableAction getDeleteAction() {
    296295                return deleteAction;
    297296        }
    298        
     297
    299298        public RunnableAction getAddAction() {
    300299                return addAction;
    301300        }
    302301
    303        
    304         /**
    305          * initialize the table 
     302
     303        /**
     304         * initialize the table
    306305         */
    307306        protected void init() {
    308                
    309                
    310                 setAutoResizeMode(JTable.AUTO_RESIZE_OFF);             
     307
     308
     309                setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    311310                setCellSelectionEnabled(true);
    312311                setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    313                
    314 
    315                                
     312
     313
     314
    316315                // make ENTER behave like TAB
    317316                //
    318317                getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    319                         .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "selectNextColumnCell");
     318                .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "selectNextColumnCell");
    320319
    321320                // install custom navigation actions
     
    328327                //
    329328                deleteAction = new DeleteAction();
    330                
     329
    331330                // create the add action
    332331                //
    333332                addAction = new AddAction();
    334333                getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    335                         .put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_MASK), "addTag");
     334                .put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_MASK), "addTag");
    336335                getActionMap().put("addTag", addAction);
    337                
    338                
     336
     337
    339338                // create the table cell editor and set it to key and value columns
    340339                //
     
    343342                getColumnModel().getColumn(0).setCellEditor(editor);
    344343                getColumnModel().getColumn(1).setCellEditor(editor);
    345        
    346         }
    347        
    348         /**
    349          * constructor 
     344
     345        }
     346
     347        /**
     348         * constructor
    350349         *
    351350         * @param model
    352351         * @param columnModel
    353352         */
    354         public TagTable(TableModel model) { 
     353        public TagTable(TableModel model) {
    355354                super(model, new TagTableColumnModel());
    356355                init();
    357356        }
    358        
    359        
    360        
     357
     358
     359
    361360        /**
    362361         * adjusts the width of the columns for the tag name and the tag value
     
    375374                        tcm.getColumn(0).setMaxWidth(width);
    376375                        tcm.getColumn(1).setMinWidth(width);
    377                         tcm.getColumn(1).setMaxWidth(width);                   
    378                 }
    379         }
    380 
    381        
     376                        tcm.getColumn(1).setMaxWidth(width);
     377                }
     378        }
     379
     380
    382381        @Override protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
    383             int condition, boolean pressed) {
    384                
     382                        int condition, boolean pressed) {
     383
    385384                // handle delete key
    386385                //
    387             if (e.getKeyCode() == KeyEvent.VK_DELETE) {
    388                 getDeleteAction().run();
    389             }
    390             return super.processKeyBinding(ks, e, condition, pressed);
    391     }
    392        
    393        
    394         /**
    395          * @param autoCompletionList 
     386                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
     387                        getDeleteAction().run();
     388                }
     389                return super.processKeyBinding(ks, e, condition, pressed);
     390        }
     391
     392
     393        /**
     394         * @param autoCompletionList
    396395         */
    397396        public void setAutoCompletionList(AutoCompletionList autoCompletionList) {
    398                 if (autoCompletionList == null) {
    399                         return;
    400                 }
     397                if (autoCompletionList == null)
     398                        return;
    401399                if (editor != null) {
    402400                        editor.setAutoCompletionList(autoCompletionList);
    403                 } 
    404         }
    405        
     401                }
     402        }
     403
    406404        public void setAutoCompletionCache(AutoCompletionCache acCache) {
    407405                if (acCache == null) {
    408406                        logger.warning("argument acCache should not be null. Aborting.");
    409                         return; 
     407                        return;
    410408                }
    411409                if (editor != null) {
     
    413411                }
    414412        }
    415        
     413
    416414        public AutoCompletionList getAutoCompletionList() {
    417                 if (editor != null) {
     415                if (editor != null)
    418416                        return editor.getAutoCompletionList();
    419                 } else  {
     417                else
    420418                        return null;
    421                 }
    422         }
    423        
    424        
     419        }
     420
     421
    425422        public TableCellEditor getTableCellEditor() {
    426423                return editor;
     
    435432                editor.getEditor().addKeyListener(l);
    436433        }
    437        
    438        
     434
     435
    439436        public void requestFocusInCell(final int row, final int col) {
    440437
    441438                // the following code doesn't work reliably. If a table cell
    442                 // gains focus using editCellAt() and requestFocusInWindow() 
     439                // gains focus using editCellAt() and requestFocusInWindow()
    443440                // it isn't possible to tab to the next table cell using TAB or
    444441                // ENTER. Don't know why.
    445                 // 
     442                //
    446443                // tblTagEditor.editCellAt(row, col);
    447444                // if (tblTagEditor.getEditorComponent() != null) {
     
    451448                // this is a workaround. We move the focus to the respective cell
    452449                // using a simulated mouse click. In this case one can tab out of
    453                 // the cell using TAB and ENTER. 
    454                 // 
     450                // the cell using TAB and ENTER.
     451                //
    455452                Rectangle r = getCellRect(row,col, false);
    456453                Point p = new Point(r.x + r.width/2, r.y + r.height/2);
    457454                SwingUtilities.convertPointToScreen(p, this);
    458455                // logger.info("simulating mouse click event at point " + p.toString());
    459                
     456
    460457                try {
    461458                        Robot robot = new Robot();
     
    465462                } catch(AWTException e) {
    466463                        logger.log(Level.SEVERE, "failed to simulate mouse click event at (" + r.x + "," + r.y + "). Exception: " + e.toString());
    467                         return; 
    468                 }
    469 
    470         }
    471 
    472        
     464                        return;
     465                }
     466
     467        }
     468
     469
    473470}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/ui/NameIconCellRenderer.java

    r14328 r15319  
    1515
    1616public class NameIconCellRenderer extends JLabel implements TableCellRenderer {
    17        
     17
    1818        private static Logger logger = Logger.getLogger(NameIconCellRenderer.class.getName());
    1919        public static final Color BG_COLOR_SELECTED = new Color(143,170,255);
    20        
     20
    2121
    2222        protected void init() {
     
    2424                setFont(new Font("SansSerif",Font.PLAIN,10));
    2525        }
    26        
     26
    2727        public NameIconCellRenderer() {
    2828                init();
    2929        }
    30        
    31         @Override
     30
    3231        public Component getTableCellRendererComponent(JTable table, Object value,
    3332                        boolean isSelected, boolean hasFocus, int rowIndex, int colIndex) {
    34        
     33
    3534                if (isSelected) {
    36                         setBackground(BG_COLOR_SELECTED);                       
     35                        setBackground(BG_COLOR_SELECTED);
    3736                } else  {
    3837                        setBackground(Color.WHITE);
     
    4140                setText(provider.getName());
    4241                setIcon(provider.getIcon());
    43                 return this; 
     42                return this;
    4443        }
    4544}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/ui/PresetsTableModel.java

    r14328 r15319  
    1515
    1616        private static final Logger logger = Logger.getLogger(PresetsTableModel.class.getName());
    17        
    18          private ArrayList<TableModelListener> listeners = new ArrayList<TableModelListener>();
    19          private ArrayList<Item> items = new ArrayList<Item>();
    20          private ArrayList<Item> visibleItems = new ArrayList<Item>();
    21          private Presets presets = null;
    22          
    23          
    24          protected void initModelFromPresets(Presets presets) {
     17
     18        private final ArrayList<TableModelListener> listeners = new ArrayList<TableModelListener>();
     19        private final ArrayList<Item> items = new ArrayList<Item>();
     20        private final ArrayList<Item> visibleItems = new ArrayList<Item>();
     21        private Presets presets = null;
     22
     23
     24        protected void initModelFromPresets(Presets presets) {
    2525                for(Group group: presets.getGroups()) {
    2626                        for(Item item: group.getItems()) {
     
    2929                        }
    3030                }
    31          }
    32          
    33        
    34          public PresetsTableModel() {
    35          }
    36          
    37          public PresetsTableModel(Presets presets) {
    38                  setPresets(presets);
    39          }
    40          
    41        
     31        }
     32
     33
     34        public PresetsTableModel() {
     35        }
     36
     37        public PresetsTableModel(Presets presets) {
     38                setPresets(presets);
     39        }
     40
     41
    4242        public Presets getPresets() {
    4343                return presets;
     
    5757        public void addTableModelListener(TableModelListener l) {
    5858                synchronized(listeners) {
    59                         if (l == null) {
     59                        if (l == null)
    6060                                return;
    61                         }
    6261                        if (!listeners.contains(l)) {
    6362                                listeners.add(l);
     
    7170        }
    7271
    73         @Override
    7472        public int getColumnCount() {
    7573                return 2;
    7674        }
    7775
    78 
    79         @Override
    8076        public int getRowCount() {
    8177                return visibleItems.size();
    8278        }
    8379
    84         @Override
    8580        public Object getValueAt(int rowIndex, int columnIndex) {
    8681                Item item = visibleItems.get(rowIndex);
    8782                switch(columnIndex) {
    88                         case 0: return item.getParent();
    89                         case 1: return item;
    90                         default: return "unknown";
    91                
     83                case 0: return item.getParent();
     84                case 1: return item;
     85                default: return "unknown";
     86
    9287                }
    9388        }
     
    10499                                listeners.remove(l);
    105100                        }
    106                 }               
     101                }
    107102        }
    108103
    109104        @Override
    110105        public void setValueAt(Object value, int rowIndex, int columnIndex) {
    111                 // do nothing. No editing allowed               
     106                // do nothing. No editing allowed
    112107        }
    113108
    114        
    115109        public Item getVisibleItem(int idx) {
    116                 if (idx < 0 || idx >= this.visibleItems.size()) {
     110                if (idx < 0 || idx >= this.visibleItems.size())
    117111                        throw new IndexOutOfBoundsException("index out of bounds. idx=" + idx);
    118                 }
    119112                return visibleItems.get(idx);
    120113        }
    121        
    122        
    123        
     114
    124115        public void filter(String filter) {
    125116                synchronized(this) {
     
    129120                                        visibleItems.add(item);
    130121                                }
    131                         } else { 
     122                        } else {
    132123                                visibleItems.clear();
    133124                                filter = filter.toLowerCase();
    134125                                for(Item item: items) {
    135126                                        if (    (item.getName() != null && item.getName().toLowerCase().trim().startsWith(filter))
    136                                              || (item.getParent().getName() != null && item.getParent().getName().toLowerCase().trim().startsWith(filter))) {
     127                                                        || (item.getParent().getName() != null && item.getParent().getName().toLowerCase().trim().startsWith(filter))) {
    137128                                                visibleItems.add(item);
    138129                                        }
    139                                 }       
     130                                }
    140131                        }
    141132                        fireTableDataChanged();
    142133                        fireTableStructureChanged();
    143134                }
    144                
     135
    145136        }
    146137}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/ui/TabularPresetSelector.java

    r14328 r15319  
    3939        private PresetsTable presetsTable = null;
    4040        private JTextField   tfFilter = null;
    41         private ArrayList<IPresetSelectorListener> listeners = new ArrayList<IPresetSelectorListener>();
     41        private final ArrayList<IPresetSelectorListener> listeners = new ArrayList<IPresetSelectorListener>();
    4242        private JScrollPane scrollPane;
    4343        private JButton btnApply;
    44        
    45        
     44
     45
    4646        protected JPanel buildFilterPanel() {
    4747                JPanel pnl = new JPanel();
     
    5454                pnl.add(btn);
    5555                btn.addActionListener(
    56                         new ActionListener() {
    57                                 @Override
    58                                 public void actionPerformed(ActionEvent e) {
    59                                         filter(tfFilter.getText());                                             
    60                                 }
    61                                
    62                         }
     56                                new ActionListener() {
     57                                        public void actionPerformed(ActionEvent e) {
     58                                                filter(tfFilter.getText());
     59                                        }
     60
     61                                }
    6362                );
    6463                btn = new JButton(tr("Clear"));
     
    6665                btn.addActionListener(
    6766                                new ActionListener() {
    68                                         @Override
    6967                                        public void actionPerformed(ActionEvent e) {
    7068                                                tfFilter.setText("");
    7169                                                tfFilter.requestFocus();
    72                                         }                                       
    73                                 }
    74                         );             
     70                                        }
     71                                }
     72                );
    7573                return pnl;
    7674        }
    77        
    78        
    79        
     75
     76
     77
    8078        protected JScrollPane buildPresetGrid() {
    81                                        
     79
    8280                presetsTable = new PresetsTable(new PresetsTableModel(),new PresetsTableColumnModel());
    83                
     81
    8482                scrollPane = new JScrollPane(presetsTable);
    85                
     83
    8684                scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    8785                scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    88                
     86
    8987                // this adapters ensures that the width of the tag table columns is adjusted
    90                 // to the width of the scroll pane viewport. Also tried to overwrite 
     88                // to the width of the scroll pane viewport. Also tried to overwrite
    9189                // getPreferredViewportSize() in JTable, but did not work.
    9290                //
     
    9492                                new ComponentAdapter() {
    9593                                        @Override public void componentResized(ComponentEvent e) {
    96                             super.componentResized(e);
    97                             Dimension d = scrollPane.getViewport().getExtentSize();
    98                             presetsTable.adjustColumnWidth(d.width);
    99                     }
    100                                 }
    101                 );
    102                
    103                 // add the double click listener 
     94                                                super.componentResized(e);
     95                                                Dimension d = scrollPane.getViewport().getExtentSize();
     96                                                presetsTable.adjustColumnWidth(d.width);
     97                                        }
     98                                }
     99                );
     100
     101                // add the double click listener
    104102                //
    105103                presetsTable.addMouseListener(new DoubleClickAdapter());
    106                
     104
    107105                // replace Enter action. apply the current preset on enter
    108106                //
     
    117115                        }
    118116                };
    119                
     117
    120118                presetsTable.registerKeyboardAction(
    121                         enterAction,
    122                         "Enter",
    123                         KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
    124                         JComponent.WHEN_FOCUSED
    125                 );
    126                
     119                                enterAction,
     120                                "Enter",
     121                                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
     122                                JComponent.WHEN_FOCUSED
     123                );
     124
    127125                return scrollPane;
    128126        }
    129        
     127
    130128        protected JPanel buildControlButtonPanel() {
    131129                JPanel pnl = new JPanel();
     
    134132                pnl.add(btnApply);
    135133                btnApply.addActionListener(
    136                         new ActionListener() {
    137                                 @Override
    138                                 public void actionPerformed(ActionEvent arg0) {
    139                                         int row = presetsTable.getSelectedRow();
    140                                         if (row >=0) {
    141                                                 Item item = getModel().getVisibleItem(row);
    142                                                 fireItemSelected(item);
    143                                         }
    144                                 }                               
    145                         }
    146                 );
    147                 return pnl;             
    148         }
    149        
     134                                new ActionListener() {
     135                                        public void actionPerformed(ActionEvent arg0) {
     136                                                int row = presetsTable.getSelectedRow();
     137                                                if (row >=0) {
     138                                                        Item item = getModel().getVisibleItem(row);
     139                                                        fireItemSelected(item);
     140                                                }
     141                                        }
     142                                }
     143                );
     144                return pnl;
     145        }
     146
    150147        protected void build() {
    151148                setLayout(new BorderLayout());
     
    153150                add(buildPresetGrid(), BorderLayout.CENTER);
    154151                add(buildControlButtonPanel(), BorderLayout.SOUTH);
    155                
     152
    156153                // wire the text field for filter expressions to the prests
    157154                // table
     
    159156                tfFilter.getDocument().addDocumentListener(
    160157                                new DocumentListener() {
    161                                         @Override
    162158                                        public void changedUpdate(DocumentEvent arg0) {
    163159                                                onUpdate();
    164160                                        }
    165161
    166                                         @Override
    167162                                        public void insertUpdate(DocumentEvent arg0) {
    168163                                                onUpdate();
    169164                                        }
    170165
    171                                         @Override
    172166                                        public void removeUpdate(DocumentEvent arg0) {
    173167                                                onUpdate();
    174168                                        }
    175                                
     169
    176170                                        protected void onUpdate() {
    177                                             filter(tfFilter.getText());
    178                                         }
    179                                 }
    180                         );
    181                
     171                                                filter(tfFilter.getText());
     172                                        }
     173                                }
     174                );
     175
    182176                tfFilter.addActionListener(
    183177                                new ActionListener() {
    184                                         @Override
    185178                                        public void actionPerformed(ActionEvent e) {
    186179                                                filter(tfFilter.getText());
    187                                         }                                       
    188                                 }
    189                 );
    190                
     180                                        }
     181                                }
     182                );
     183
    191184                // wire the apply button to the selection model of the preset table
    192                 // 
     185                //
    193186                presetsTable.getSelectionModel().addListSelectionListener(
    194                         new ListSelectionListener() {
    195        
    196                                 @Override
    197                                 public void valueChanged(ListSelectionEvent e) {
    198                                         btnApply.setEnabled(presetsTable.getSelectedRowCount() != 0);
    199                                 }
    200                         }
    201                 );
    202                
    203        
     187                                new ListSelectionListener() {
     188                                        public void valueChanged(ListSelectionEvent e) {
     189                                                btnApply.setEnabled(presetsTable.getSelectedRowCount() != 0);
     190                                        }
     191                                }
     192                );
     193
     194
    204195                // load the set of presets and bind them to the preset table
    205196                //
     
    208199                presetsTable.getSelectionModel().clearSelection();
    209200                btnApply.setEnabled(false);
    210        
    211         }
    212        
     201
     202        }
     203
    213204        public void bindTo(Presets presets) {
    214205                PresetsTableModel model = (PresetsTableModel)presetsTable.getModel();
    215206                model.setPresets(presets);
    216207        }
    217        
     208
    218209        public TabularPresetSelector() {
    219210                build();
     
    227218                }
    228219        }
    229        
     220
    230221        public void removePresetSelectorListener(IPresetSelectorListener listener) {
    231222                synchronized(this.listeners) {
     
    235226                }
    236227        }
    237        
     228
    238229        protected void fireItemSelected(Item item) {
    239230                synchronized(this.listeners) {
     
    243234                }
    244235        }
    245        
    246        
    247 
    248        
     236
     237
     238
     239
    249240        private class DoubleClickAdapter extends MouseAdapter {
    250241                @Override
     
    257248                }
    258249        }
    259        
    260        
     250
     251
    261252        public void filter(String filter) {
    262253                presetsTable.getSelectionModel().clearSelection();
    263254                getModel().filter(filter);
    264                
     255
    265256                presetsTable.scrollRectToVisible(presetsTable.getCellRect(0, 0, false));
    266                
     257
    267258                // we change the number of rows by applying a filter condition. Because
    268259                // the table is embedded in a JScrollPane which again may be embedded in
    269                 // other JScrollPanes or JSplitPanes it seems that we have to recalculate 
     260                // other JScrollPanes or JSplitPanes it seems that we have to recalculate
    270261                // the layout and repaint the component tree. Maybe there is a more efficient way
    271262                // to keep the GUI in sync with the number of rows in table. By trial
    272                 // and error I ended up with the following lines. 
    273                 // 
     263                // and error I ended up with the following lines.
     264                //
    274265                Component c = presetsTable;
    275266                while(c != null) {
     
    279270                }
    280271        }
    281        
    282        
     272
     273
    283274        protected PresetsTableModel getModel() {
    284275                return (PresetsTableModel)presetsTable.getModel();
    285276        }
    286        
     277
    287278        public void installKeyAction(Action a) {
    288279                getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put((KeyStroke)a.getValue(AbstractAction.ACCELERATOR_KEY), a.getValue(AbstractAction.NAME));
     
    290281
    291282        }
    292        
     283
    293284}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/TagSpecifications.java

    r14329 r15319  
    77import java.io.Reader;
    88import java.util.ArrayList;
    9 import java.util.Collections;
    109import java.util.List;
    11 import java.util.Map;
    1210import java.util.logging.Level;
    1311import java.util.logging.Logger;
     
    3634 */
    3735public class TagSpecifications {
    38        
     36
    3937        final static public String ATTR_KEY = "key";
    4038        final static public String ATTR_TYPE = "type";
     
    4745        final static public String ELEM_TAG = "tag";
    4846        final static public String ELEM_LABEL = "label";
    49        
     47
    5048        final static public String DTD = "osm-tag-definitions.dtd";
    51        
    52        
    53         /** the default name of the resource file with the  tag specifications */ 
     49
     50
     51        /** the default name of the resource file with the  tag specifications */
    5452        static public final String RES_NAME_TAG_SPECIFICATIONS = "/resources/osm-tag-definitions.xml";
    55        
     53
    5654        /** the logger object */
    5755        private static Logger logger = Logger.getLogger(TagSpecification.class.getName());
    58        
     56
    5957        /** list of tag specifications managed list */
    6058        private ArrayList<TagSpecification> tagSpecifications = null;
    61        
    62          
    63        
     59
     60
     61
    6462        private static TagSpecifications instance = null;
    65        
     63
    6664        /**
    6765         * loads the the tag specifications from the resource file given by
    68          * {@link #RES_NAME_TAG_SPECIFICATIONS}. 
     66         * {@link #RES_NAME_TAG_SPECIFICATIONS}.
    6967         *
    7068         * @return the list of {@link TagSpecification}s
     
    8179                reader.close();
    8280                instance = spec;
    83                
    84         }
    85        
     81
     82        }
     83
    8684        static public TagSpecifications getInstance() throws Exception {
    8785                if (instance == null) {
     
    9088                return instance;
    9189        }
    92        
    93         /**
    94          * constructor 
     90
     91        /**
     92         * constructor
    9593         */
    9694        public TagSpecifications() {
    9795                tagSpecifications = new ArrayList<TagSpecification>();
    9896        }
    99        
    100        
    101         /**
    102          * loads the tag specifications from a specific reader 
     97
     98
     99        /**
     100         * loads the tag specifications from a specific reader
    103101         *
    104          * @param in  the reader to read from 
    105          * @throws Exception thrown, if an exception occurs 
     102         * @param in  the reader to read from
     103         * @throws Exception thrown, if an exception occurs
    106104         */
    107105        public void load(Reader in) throws Exception {
    108106                XMLReader parser;
    109                
     107
    110108                try {
    111109                        parser = XMLReaderFactory.createXMLReader();
     
    117115                        parser.setFeature("http://xml.org/sax/features/namespaces", true);
    118116                        parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    119                 parser.parse(new InputSource(in));
    120                
     117                        parser.parse(new InputSource(in));
     118
    121119                } catch (Exception e) {
    122120                        logger.log(Level.SEVERE, "failed to load tag specificatoin file", e);
     
    125123                        parser = null;
    126124                }
    127                
    128                
    129                
     125
     126
     127
    130128        }
    131129
     
    143141                return keys;
    144142        }
    145        
     143
    146144        public List<AutoCompletionListItem> getLabelsForAutoCompletion(String forKey, AutoCompletionContext context) {
    147145                ArrayList<AutoCompletionListItem> items = new ArrayList<AutoCompletionListItem>();
     
    162160                return items;
    163161        }
    164        
    165        
     162
     163
    166164        /**
    167165         * replies a list of {@see KeyValuePair}s for all {@see TagSpecification}s and
    168166         * {@see LableSpecification}s.
    169167         *
    170          * @return the list 
     168         * @return the list
    171169         */
    172170        public ArrayList<KeyValuePair> asList() {
    173171                ArrayList<KeyValuePair> entries = new ArrayList<KeyValuePair>();
    174                
     172
    175173                for (TagSpecification s : tagSpecifications) {
    176174                        for (LableSpecification l : s.getLables()) {
     
    178176                        }
    179177                }
    180                 return entries; 
    181         }
    182        
    183        
    184        
    185         /**
    186          * The SAX handler for reading XML files with tag specifications 
     178                return entries;
     179        }
     180
     181
     182
     183        /**
     184         * The SAX handler for reading XML files with tag specifications
    187185         *
    188          * @author gubaer 
     186         * @author gubaer
    189187         *
    190188         */
    191189        class Handler extends DefaultHandler {
    192                
     190
    193191                /**  the current tag specification. Not null, while parsing the content
    194192                 * between &lt;tag&gt; ... &lt;/tag&gt;
    195193                 */
    196194                private TagSpecification currentTagSpecification  = null;
    197                
    198                
     195
     196
    199197                @Override
    200198                public void endDocument() throws SAXException {
     
    202200                }
    203201
    204                
     202
    205203
    206204                @Override
     
    223221                 * parses a string value consisting of 'yes' or 'no' (exactly, case
    224222                 * sensitive)
    225                  *  
     223                 *
    226224                 * @param value the string value
    227225                 * @return true, if value is <code>yes</code>; false, if value is <code>no</code>
     
    229227                 */
    230228                protected boolean parseYesNo(String value) throws SAXException {
    231                         if ("yes".equals(value)) {
     229                        if ("yes".equals(value))
    232230                                return true;
    233                         } else if ("no".equals(value)) {
    234                                 return false; 
    235                         } else {
     231                        else if ("no".equals(value))
     232                                return false;
     233                        else
    236234                                throw new SAXException("expected 'yes' or 'no' as attribute value, got '" + value + "'");
    237                         }
    238                 }
    239                
     235                }
     236
    240237                /**
    241238                 * handles a start element with name <code>osm-tag-definitions</code>
    242239                 *
    243                  * @param atts  the XML attributes 
    244                  * @throws SAXException   
     240                 * @param atts  the XML attributes
     241                 * @throws SAXException
    245242                 */
    246243                protected void startElementOsmTagDefinitions(Attributes atts) throws SAXException {
    247244                        tagSpecifications = new ArrayList<TagSpecification>();
    248245                }
    249                
     246
    250247                /**
    251248                 * handles an end element with name <code>osm-tag-specifications</code>
     
    256253                        // do nothing
    257254                }
    258                
    259                 /**
    260                  * handles a start element with name <code>tag</code> 
    261                  *
    262                  * @param atts the XML attributes of the element 
     255
     256                /**
     257                 * handles a start element with name <code>tag</code>
     258                 *
     259                 * @param atts the XML attributes of the element
    263260                 * @throws SAXException
    264261                 */
     
    268265                                String name = atts.getQName(i);
    269266                                String value = atts.getValue(i);
    270                                
     267
    271268                                if (ATTR_KEY.equals(name)) {
    272269                                        currentTagSpecification.setKey(value);
    273                                 } else if (ATTR_TYPE.equals(name)) {   
     270                                } else if (ATTR_TYPE.equals(name)) {
    274271                                        currentTagSpecification.setType(value);
    275272                                } else if (ATTR_FOR_NODE.equals(name)) {
     
    279276                                } else if (ATTR_FOR_RELATION.equals(name)) {
    280277                                        currentTagSpecification.setApplicableToRelation(parseYesNo(value));
    281                                 } else {
     278                                } else
    282279                                        throw new SAXException("unknown attribut '" + name + "' on element 'tag'");
    283                                 }                               
    284                         }
    285                 }
    286                
    287                
    288                 /**
    289                  * handles an end element with name <code>tag</code>
     280                        }
     281                }
     282
     283
     284                /**
     285                 * handles an end element with name <code>tag</code>
    290286                 * @throws SAXException
    291287                 */
     
    293289                        tagSpecifications.add(currentTagSpecification);
    294290                        currentTagSpecification = null;
    295                        
    296                 }
    297                
    298                
    299                 /**
    300                  * handles a start element with name <code>label</code> 
    301                  *
    302                  * @param atts the XML attributes 
     291
     292                }
     293
     294
     295                /**
     296                 * handles a start element with name <code>label</code>
     297                 *
     298                 * @param atts the XML attributes
    303299                 * @throws SAXException
    304300                 */
    305301                protected void startElementLabel(Attributes atts) throws SAXException {
    306                         LableSpecification ls = new LableSpecification(); 
     302                        LableSpecification ls = new LableSpecification();
    307303                        for (int i=0; i< atts.getLength(); i++) {
    308304                                String name = atts.getQName(i);
    309305                                String value = atts.getValue(i);
    310                                
     306
    311307                                if (ATTR_VALUE.equals(name)) {
    312308                                        ls.setValue(value);
     
    317313                                } else if (ATTR_FOR_RELATION.equals(name)) {
    318314                                        ls.setApplicableToRelation(parseYesNo(value));
    319                                 } else {
     315                                } else
    320316                                        throw new SAXException("unknown attribut '" + name + "' on element 'lable'");
    321                                 }                               
    322317                        }
    323318                        currentTagSpecification.addLable(ls);
    324319                }
    325                
     320
    326321                /**
    327322                 * handles an end element with name <code>label</code>
     
    330325                 */
    331326                protected void endElementLabel() throws SAXException {
    332                         // do nothing 
    333                 }
    334                
     327                        // do nothing
     328                }
     329
    335330                @Override
    336331                public void startElement(String namespaceURI, String localName, String qName,
     
    342337                        } else if (ELEM_LABEL.equals(qName)) {
    343338                                startElementLabel(atts);
    344                         } else {
     339                        } else
    345340                                throw new SAXException("unknown element '" + qName + "'");
    346                         }
    347                 }
    348                
     341                }
     342
    349343                @Override
    350344                public void endElement(String namespaceURI, String localName, String qName)
    351                                 throws SAXException {
     345                throws SAXException {
    352346                        if (ELEM_ROOT.equals(qName)) {
    353347                                endElementOsmTagDefinitions();
     
    356350                        } else if (ELEM_LABEL.equals(qName)) {
    357351                                endElementLabel();
    358                         } else {
     352                        } else
    359353                                throw new SAXException("unknown element '" + qName + "'");
    360                         }
    361354                }
    362355
     
    366359                        logger.log(Level.WARNING, "XML parsing warning", e);
    367360                }
    368                
    369                
    370                
    371         }
    372        
    373        
     361
     362
     363
     364        }
     365
     366
    374367        /**
    375368         *
     
    378371        class ResourceEntityResolver implements EntityResolver {
    379372
    380                 @Override
    381373                public InputSource resolveEntity(String publicId, String systemId)
    382                                 throws SAXException, IOException {
    383                         if (systemId != null && systemId.endsWith(DTD)) {
     374                throws SAXException, IOException {
     375                        if (systemId != null && systemId.endsWith(DTD))
    384376                                return new InputSource(
    385377                                                TagSpecifications.class.getResourceAsStream(DTD)
    386378                                );
    387                         } else {
     379                        else
    388380                                throw new SAXException("couldn't load external DTD '" + systemId + "'");
    389                         }
    390                 }
    391                
    392         }
    393        
    394        
     381                }
     382
     383        }
     384
     385
    395386        static public void main(String args[]) throws Exception{
    396387                TagSpecifications.loadFromResources();
    397388        }
    398        
     389
    399390}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/ui/KeyValueCellRenderer.java

    r14330 r15319  
    1111
    1212public class KeyValueCellRenderer extends JLabel implements TableCellRenderer  {
    13        
     13
    1414        private static Logger logger = Logger.getLogger(KeyValueCellRenderer.class.getName());
    1515        public static final Color BG_COLOR_SELECTED = new Color(143,170,255);
    16        
     16
    1717
    1818        protected void init() {
     
    2020                setOpaque(true);
    2121        }
    22        
     22
    2323        public KeyValueCellRenderer() {
    2424                init();
    2525        }
    26        
    27         @Override
     26
    2827        public Component getTableCellRendererComponent(JTable table, Object value,
    2928                        boolean isSelected, boolean hasFocus, int rowIndex, int colIndex) {
    30        
     29
    3130                if (isSelected) {
    32                         setBackground(BG_COLOR_SELECTED);                       
     31                        setBackground(BG_COLOR_SELECTED);
    3332                } else  {
    3433                        setBackground(Color.WHITE);
     
    3635                setText((String)value);
    3736                setIcon(null);
    38                 return this; 
     37                return this;
    3938        }
    4039}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/ui/TabularTagSelector.java

    r14330 r15319  
    3535public class TabularTagSelector extends JPanel {
    3636
    37         private TagsTable tagsTable;   
     37        private TagsTable tagsTable;
    3838        private JTextField tfFilter;
    3939        private JButton btnApply;
    4040        private JScrollPane scrollPane;
    41         private ArrayList<ITagSelectorListener> listeners = new ArrayList<ITagSelectorListener>();
    42 
    43        
     41        private final ArrayList<ITagSelectorListener> listeners = new ArrayList<ITagSelectorListener>();
     42
     43
    4444        protected JPanel buildFilterPanel() {
    4545                JPanel pnl = new JPanel();
     
    5252                pnl.add(btn);
    5353                btn.addActionListener(
    54                         new ActionListener() {
    55                                 @Override
    56                                 public void actionPerformed(ActionEvent e) {
    57                                         filter(tfFilter.getText());                                             
    58                                 }
    59                                
    60                         }
     54                                new ActionListener() {
     55                                        public void actionPerformed(ActionEvent e) {
     56                                                filter(tfFilter.getText());
     57                                        }
     58
     59                                }
    6160                );
    6261                btn = new JButton(tr("Clear"));
     
    6463                btn.addActionListener(
    6564                                new ActionListener() {
    66                                         @Override
    6765                                        public void actionPerformed(ActionEvent e) {
    6866                                                tfFilter.setText("");
    6967                                                tfFilter.requestFocus();
    70                                         }                                       
    71                                 }
    72                         );             
     68                                        }
     69                                }
     70                );
    7371                return pnl;
    7472        }
    75        
     73
    7674        protected JScrollPane buildPresetGrid() {
    77                
     75
    7876                tagsTable = new TagsTable(new TagsTableModel(),new TagsTableColumnModel());
    7977                getModel().initFromTagSpecifications();
    80                
     78
    8179                scrollPane = new JScrollPane(tagsTable);
    82                
     80
    8381                scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    8482                scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    85                
     83
    8684                // this adapters ensures that the width of the tag table columns is adjusted
    87                 // to the width of the scroll pane viewport. Also tried to overwrite 
     85                // to the width of the scroll pane viewport. Also tried to overwrite
    8886                // getPreferredViewportSize() in JTable, but did not work.
    8987                //
     
    9189                                new ComponentAdapter() {
    9290                                        @Override public void componentResized(ComponentEvent e) {
    93                             super.componentResized(e);
    94                             Dimension d = scrollPane.getViewport().getExtentSize();
    95                             tagsTable.adjustColumnWidth(d.width);
    96                     }
    97                                 }
    98                 );
    99                
    100                 // add the double click listener 
     91                                                super.componentResized(e);
     92                                                Dimension d = scrollPane.getViewport().getExtentSize();
     93                                                tagsTable.adjustColumnWidth(d.width);
     94                                        }
     95                                }
     96                );
     97
     98                // add the double click listener
    10199                //
    102100                tagsTable.addMouseListener(new DoubleClickAdapter());
    103                
     101
    104102                // replace Enter action. apply the current preset on enter
    105103                //
     
    114112                        }
    115113                };
    116                
     114
    117115                tagsTable.registerKeyboardAction(
    118                         enterAction,
    119                         "Enter",
    120                         KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
    121                         JComponent.WHEN_FOCUSED
    122                 );
    123                
     116                                enterAction,
     117                                "Enter",
     118                                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
     119                                JComponent.WHEN_FOCUSED
     120                );
     121
    124122                return scrollPane;
    125123        }
    126        
    127        
     124
     125
    128126        protected JPanel buildControlButtonPanel() {
    129127                JPanel pnl = new JPanel();
     
    132130                pnl.add(btnApply);
    133131                btnApply.addActionListener(
    134                         new ActionListener() {
    135                                 @Override
    136                                 public void actionPerformed(ActionEvent arg0) {
    137                                         int row = tagsTable.getSelectedRow();
    138                                         if (row >=0) {
    139                                                 KeyValuePair item = getModel().getVisibleItem(row);
    140                                                 fireItemSelected(item);
    141                                         }
    142                                 }                               
    143                         }
    144                 );
    145                 return pnl;             
    146         }
    147        
     132                                new ActionListener() {
     133                                        public void actionPerformed(ActionEvent arg0) {
     134                                                int row = tagsTable.getSelectedRow();
     135                                                if (row >=0) {
     136                                                        KeyValuePair item = getModel().getVisibleItem(row);
     137                                                        fireItemSelected(item);
     138                                                }
     139                                        }
     140                                }
     141                );
     142                return pnl;
     143        }
     144
    148145        protected void build() {
    149146                setLayout(new BorderLayout());
     
    151148                add(buildPresetGrid(), BorderLayout.CENTER);
    152149                add(buildControlButtonPanel(), BorderLayout.SOUTH);
    153                
     150
    154151                // wire the text field for filter expressions to the prests
    155152                // table
     
    157154                tfFilter.getDocument().addDocumentListener(
    158155                                new DocumentListener() {
    159                                         @Override
    160156                                        public void changedUpdate(DocumentEvent arg0) {
    161157                                                onUpdate();
    162158                                        }
    163159
    164                                         @Override
    165160                                        public void insertUpdate(DocumentEvent arg0) {
    166161                                                onUpdate();
    167162                                        }
    168163
    169                                         @Override
    170164                                        public void removeUpdate(DocumentEvent arg0) {
    171165                                                onUpdate();
    172166                                        }
    173                                
     167
    174168                                        protected void onUpdate() {
    175                                             filter(tfFilter.getText());
    176                                         }
    177                                 }
    178                         );
    179                
     169                                                filter(tfFilter.getText());
     170                                        }
     171                                }
     172                );
     173
    180174                tfFilter.addActionListener(
    181175                                new ActionListener() {
    182                                         @Override
    183176                                        public void actionPerformed(ActionEvent e) {
    184177                                                filter(tfFilter.getText());
    185                                         }                                       
    186                                 }
    187                 );
    188                
     178                                        }
     179                                }
     180                );
     181
    189182                // wire the apply button to the selection model of the preset table
    190                 // 
     183                //
    191184                tagsTable.getSelectionModel().addListSelectionListener(
    192                         new ListSelectionListener() {
    193        
    194                                 @Override
    195                                 public void valueChanged(ListSelectionEvent e) {
    196                                         btnApply.setEnabled(tagsTable.getSelectedRowCount() != 0);
    197                                 }
    198                         }
    199                 );
    200                
    201        
     185                                new ListSelectionListener() {
     186                                        public void valueChanged(ListSelectionEvent e) {
     187                                                btnApply.setEnabled(tagsTable.getSelectedRowCount() != 0);
     188                                        }
     189                                }
     190                );
     191
     192
    202193                // load the set of presets and bind them to the preset table
    203194                //
    204195                tagsTable.getSelectionModel().clearSelection();
    205196                btnApply.setEnabled(false);
    206        
    207         }
    208        
    209          public TabularTagSelector() {
     197
     198        }
     199
     200        public TabularTagSelector() {
    210201                build();
    211202        }
    212          
    213          
    214          public void filter(String filter) {
     203
     204
     205        public void filter(String filter) {
    215206                tagsTable.getSelectionModel().clearSelection();
    216207                getModel().filter(filter);
    217                
     208
    218209                tagsTable.scrollRectToVisible(tagsTable.getCellRect(0, 0, false));
    219                
     210
    220211                // we change the number of rows by applying a filter condition. Because
    221212                // the table is embedded in a JScrollPane which again may be embedded in
    222                 // other JScrollPanes or JSplitPanes it seems that we have to recalculate 
     213                // other JScrollPanes or JSplitPanes it seems that we have to recalculate
    223214                // the layout and repaint the component tree. Maybe there is a more efficient way
    224215                // to keep the GUI in sync with the number of rows in table. By trial
    225                 // and error I ended up with the following lines. 
    226                 // 
     216                // and error I ended up with the following lines.
     217                //
    227218                Component c = tagsTable;
    228219                while(c != null) {
     
    232223                }
    233224        }
    234          
    235          protected TagsTableModel getModel() {
    236                  return (TagsTableModel)tagsTable.getModel();
    237          }       
     225
     226        protected TagsTableModel getModel() {
     227                return (TagsTableModel)tagsTable.getModel();
     228        }
    238229
    239230
     
    245236                }
    246237        }
    247        
     238
    248239        public void removeTagSelectorListener(ITagSelectorListener listener) {
    249240                synchronized(this.listeners) {
     
    253244                }
    254245        }
    255        
     246
    256247        protected void fireItemSelected(KeyValuePair pair) {
    257248                synchronized(this.listeners) {
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/ui/TagsTableModel.java

    r14330 r15319  
    11package org.openstreetmap.josm.plugins.tageditor.tagspec.ui;
     2import static org.openstreetmap.josm.tools.I18n.tr;
    23
    34import java.util.ArrayList;
     
    1415
    1516public class TagsTableModel extends AbstractTableModel {
    16        
     17
    1718        static private Logger logger = Logger.getLogger(TagsTableModel.class.getName());
    18        
     19
    1920        private ArrayList<KeyValuePair> items = null;
    2021        private ArrayList<KeyValuePair> visibleItems = null;
     
    2425                visibleItems = new ArrayList<KeyValuePair>();
    2526        }
    26        
     27
    2728        protected void sort() {
    2829                Collections.sort(
    29                         items,
    30                         new Comparator<KeyValuePair>() {
     30                                items,
     31                                new Comparator<KeyValuePair>() {
     32                                        public int compare(KeyValuePair self,
     33                                                        KeyValuePair other) {
     34                                                int ret =self.getKey().compareToIgnoreCase(other.getKey());
    3135
    32                                 @Override
    33                                 public int compare(KeyValuePair self,
    34                                                 KeyValuePair other) {
    35                                         int ret =self.getKey().compareToIgnoreCase(other.getKey());
    36                                        
    37                                         if (ret == 0) {
    38                                                 return self.getValue().compareToIgnoreCase(other.getValue());                                           
    39                                         } else {
    40                                                 return ret;
     36                                                if (ret == 0)
     37                                                        return self.getValue().compareToIgnoreCase(other.getValue());
     38                                                else
     39                                                        return ret;
    4140                                        }
    42                                 }                               
    43                         }                               
     41                                }
    4442                );
    4543        }
    46        
     44
    4745        protected void clear() {
    4846                items.clear();
    4947                visibleItems.clear();
    5048        }
    51        
     49
    5250        public void initFromTagSpecifications() {
    5351                clear();
    5452                TagSpecifications spec;
    55                
     53
    5654                try {
    5755                        spec = TagSpecifications.getInstance();
    5856                } catch(Exception e) {
    5957                        logger.log(Level.SEVERE, "failed to init TagTableModel. Exception:" + e);
    60                         return; 
     58                        return;
    6159                }
    62                
     60
    6361                items = spec.asList();
    6462                sort();
     
    6765                }
    6866        }
    69        
    70         @Override
     67
    7168        public int getColumnCount() {
    7269                return 2;
    7370        }
    7471
    75         @Override
    7672        public int getRowCount() {
    7773                return visibleItems.size();
    7874        }
    7975
    80         @Override
    8176        public Object getValueAt(int row, int col) {
    8277                KeyValuePair pair = visibleItems.get(row);
     
    8681                default:
    8782                        /* should not happen */
    88                         throw new IllegalArgumentException("unexpected column number " + col);                   
    89                 }       
     83                        throw new IllegalArgumentException(tr("unexpected column number {0}",col));
     84                }
    9085        }
    91        
     86
    9287        public void filter(String filter) {
    9388                synchronized(this) {
     
    9792                                        visibleItems.add(pair);
    9893                                }
    99                         } else { 
     94                        } else {
    10095                                visibleItems.clear();
    10196                                filter = filter.toLowerCase();
    10297                                for(KeyValuePair pair: items) {
    10398                                        if (pair.getKey().toLowerCase().trim().startsWith(filter)
    104                                                  ||  pair.getValue().toLowerCase().trim().startsWith(filter)) {
     99                                                        ||  pair.getValue().toLowerCase().trim().startsWith(filter)) {
    105100                                                visibleItems.add(pair);
    106101                                        }
    107                                 }       
     102                                }
    108103                        }
    109104                        fireTableDataChanged();
     
    114109        @Override
    115110        public boolean isCellEditable(int rowIndex, int columnIndex) {
    116                 return false; 
     111                return false;
    117112        }
    118113
    119114        public KeyValuePair getVisibleItem(int row) {
    120                 if (row < 0 || row >= visibleItems.size()) {
     115                if (row < 0 || row >= visibleItems.size())
    121116                        throw new IndexOutOfBoundsException("row is out of bound: row=" + row);
    122                 }
    123117                return visibleItems.get(row);
    124118        }
Note: See TracChangeset for help on using the changeset viewer.