Ignore:
Timestamp:
2009-07-19T12:17:51+02:00 (15 years ago)
Author:
guggis
Message:

added compatibility mode for Main.ds / Main.getCurrentDataSet()

Location:
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor
Files:
2 added
7 edited

Legend:

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

    r15319 r16574  
    4343import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.ITagSelectorListener;
    4444import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.TabularTagSelector;
    45 
     45import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
    4646/**
    4747 * The dialog for editing name/value-pairs (aka <em>tags</em>) associated with {@link OsmPrimitive}s.
     
    345345                        model.updateJOSMSelection();
    346346
    347                         Collection<OsmPrimitive> sel = Main.ds.getSelected();
     347                        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
    348348                        DataSet.fireSelectionChanged(sel);
    349349                        Main.parent.repaint(); // repaint all - drawing could have been changed
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionCache.java

    r14324 r16574  
    88import org.openstreetmap.josm.Main;
    99import org.openstreetmap.josm.data.osm.OsmPrimitive;
    10 
     10import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
    1111/**
    1212 * AutoCompletionCache temporarily holds a cache of keys with a list of
     
    1818 *   <li>any value used in a tag for a specific key is part of the autocompletion list of
    1919 *     this key</li>
    20  * </ol> 
     20 * </ol>
    2121 *
    2222 * Building up auto completion lists should not
    2323 * slow down tabbing from input field to input field. Looping through the complete
    2424 * data set in order to build up the auto completion list for a specific input
    25  * field is not efficient enough, hence this cache.   
     25 * field is not efficient enough, hence this cache.
    2626 *
    2727 */
    2828public class AutoCompletionCache {
    29        
     29
    3030        /** the cache */
    3131        private HashMap<String, ArrayList<String>> cache;
    32        
     32
    3333        /**
    34          * constructor 
     34         * constructor
    3535         */
    3636        public AutoCompletionCache() {
     
    3939
    4040        /**
    41          * make sure, <code>key</code> is in the cache 
     41         * make sure, <code>key</code> is in the cache
    4242         *
    43          * @param key  the key 
     43         * @param key  the key
    4444         */
    4545        protected void cacheKey(String key) {
    46                 if (cache.containsKey(key)) {
     46                if (cache.containsKey(key))
    4747                        return;
    48                 } else {
     48                else {
    4949                        cache.put(key, new ArrayList<String>());
    5050                }
    5151        }
    52        
     52
    5353        /**
    54          * make sure, value is one of the auto completion values allowed for key 
     54         * make sure, value is one of the auto completion values allowed for key
    5555         *
    56          * @param key the key 
    57          * @param value the value 
     56         * @param key the key
     57         * @param value the value
    5858         */
    5959        protected void cacheValue(String key, String value) {
     
    6464                }
    6565        }
    66        
     66
    6767        /**
    6868         * make sure, the keys and values of all tags held by primitive are
    69          * in the auto completion cache 
    70          *  
    71          * @param primitive an OSM primitive 
     69         * in the auto completion cache
     70         *
     71         * @param primitive an OSM primitive
    7272         */
    7373        protected void cachePrimitive(OsmPrimitive primitive) {
     
    7777                }
    7878        }
    79        
     79
    8080        /**
    8181         * initializes the cache from the current JOSM dataset {@link OsmPrimitive}s.
     
    8484        public void initFromJOSMDataset() {
    8585                cache = new HashMap<String, ArrayList<String>>();
    86                 Collection<OsmPrimitive> ds = Main.ds.allNonDeletedPrimitives();
     86                Collection<OsmPrimitive> ds = getCurrentDataSet().allNonDeletedPrimitives();
    8787                for (OsmPrimitive primitive : ds) {
    8888                        cachePrimitive(primitive);
    8989                }
    9090        }
    91        
     91
    9292        /**
    9393         * replies the keys held by the cache
    94          *  
    95          * @return the list of keys held by the cache 
     94         *
     95         * @return the list of keys held by the cache
    9696         */
    9797        public List<String> getKeys() {
    9898                return new ArrayList<String>(cache.keySet());
    9999        }
    100        
    101        
     100
     101
    102102        /**
    103103         * replies the auto completion values allowed for a specific key. Replies
    104104         * an empty list if key is null or if key is not in {@link #getKeys()}.
    105105         *
    106          * @param key 
    107          * @return the list of auto completion values 
     106         * @param key
     107         * @return the list of auto completion values
    108108         */
    109109        public List<String> getValues(String key) {
    110                 if (!cache.containsKey(key)) {
     110                if (!cache.containsKey(key))
    111111                        return new ArrayList<String>();
    112                 } else {
     112                else
    113113                        return cache.get(key);
    114                 }
    115114        }
    116115}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionContext.java

    r14324 r16574  
    22
    33import org.openstreetmap.josm.Main;
     4import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
    45
    56public class AutoCompletionContext {
    6        
     7
    78        private boolean selectionIncludesNodes = false;
    89        private boolean selectionIncludesWays = false;
    910        private boolean selectionIncludesRelations = false;
    10         private boolean selectionEmpty = false; 
    11        
     11        private boolean selectionEmpty = false;
     12
    1213        public AutoCompletionContext(){
    1314        }
    1415
    1516        public void initFromJOSMSelection() {
    16                 selectionIncludesNodes = ! Main.ds.getSelectedNodes().isEmpty();
    17                 selectionIncludesWays = !Main.ds.getSelectedWays().isEmpty();
    18                 selectionIncludesRelations = !Main.ds.getSelectedRelations().isEmpty();
    19                 selectionEmpty = (Main.ds.getSelected().size() == 0);
     17                selectionIncludesNodes = ! getCurrentDataSet().getSelectedNodes().isEmpty();
     18                selectionIncludesWays = !getCurrentDataSet().getSelectedWays().isEmpty();
     19                selectionIncludesRelations = !getCurrentDataSet().getSelectedRelations().isEmpty();
     20                selectionEmpty = (getCurrentDataSet().getSelected().size() == 0);
    2021        }
    21        
    22        
     22
     23
    2324        public boolean isSelectionEmpty() {
    2425                return selectionEmpty;
     
    4849                this.selectionIncludesRelations = selectionIncludesRelations;
    4950        }
    50        
    51        
    52        
     51
     52
     53
    5354
    5455}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditorModel.java

    r15319 r16574  
    2323import org.openstreetmap.josm.plugins.tageditor.preset.Tag;
    2424import org.openstreetmap.josm.plugins.tageditor.tagspec.KeyValuePair;
    25 
     25import static org.openstreetmap.josm.plugins.tageditor.josm.CompatibilityUtil.getCurrentDataSet;
    2626
    2727/**
     
    273273         */
    274274        public void initFromJOSMSelection() {
    275                 Collection<OsmPrimitive> selection = Main.ds.getSelected();
     275                Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    276276                clear();
    277277                for (OsmPrimitive element : selection) {
     
    354354        public void updateJOSMSelection() {
    355355                ArrayList<Command> commands = new ArrayList<Command>();
    356                 Collection<OsmPrimitive> selection = Main.ds.getSelected();
     356                Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    357357                if (selection == null)
    358358                        return;
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagFieldEditor.java

    r14325 r16574  
    2020/**
    2121 * TagFieldEditor is an editor for tag names or tag values. It supports auto completion
    22  * from a list of auto completion items. 
     22 * from a list of auto completion items.
    2323 *
    2424 */
    2525public class TagFieldEditor extends JTextField  {
    26        
     26
    2727        static private Logger logger = Logger.getLogger(TagFieldEditor.class.getName());
    28        
    29        
     28
     29
    3030        /**
    31          * The document model for the editor 
     31         * The document model for the editor
    3232         */
    3333        class AutoCompletionDocument extends PlainDocument {
    34                
    35                   /**
    36                    * inserts a string at a specific position
    37                    *
    38                    */
    39                   public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
    40                           if (autoCompletionList == null) {
    41                                   super.insertString(offs, str, a);
    42                                   return;
    43                           }
    44                           String currentText = getText(0, getLength());
    45                           String prefix = currentText.substring(0, offs);
    46                           autoCompletionList.applyFilter(prefix+str);
    47                           if (autoCompletionList.getFilteredSize()>0) {
    48                                   // there are matches. Insert the new text and highlight the
    49                                   // auto completed suffix
    50                                   //
    51                                   String matchingString = autoCompletionList.getFilteredItem(0).getValue();
    52                                   remove(0,getLength());
    53                                   super.insertString(0,matchingString,a);
    54                                  
    55                                   // highlight from end to insert position
    56                                   //
    57                                   setCaretPosition(getLength());
    58                               moveCaretPosition(offs + str.length()); 
    59                           } else {
    60                                   // there are no matches. Insert the new text, do not highlight
    61                                   //
    62                                   String newText = prefix + str;
    63                                   remove(0,getLength());
    64                                   super.insertString(0,newText,a);
    65                                   setCaretPosition(getLength());
    66                           }
    67                   }
    68                  
    69                  
     34
     35                /**
     36                 * inserts a string at a specific position
     37                 *
     38                 */
     39                @Override
     40                public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
     41                        if (autoCompletionList == null) {
     42                                super.insertString(offs, str, a);
     43                                return;
     44                        }
     45                        // if the current offset isn't at the end of the document we don't autocomplete.
     46                        // If a highlighted autocompleted suffix was present and we get here Swing has
     47                        // already removed it from the document. getLength() therefore doesn't include the
     48                        // autocompleted suffix.
     49                        //
     50                        if (offs < getLength()) {
     51                                super.insertString(offs, str, a);
     52                                return;
     53                        }
     54
     55                        String currentText = getText(0, getLength());
     56                        String prefix = currentText.substring(0, offs);
     57                        autoCompletionList.applyFilter(prefix+str);
     58                        if (autoCompletionList.getFilteredSize()>0) {
     59                                // there are matches. Insert the new text and highlight the
     60                                // auto completed suffix
     61                                //
     62                                String matchingString = autoCompletionList.getFilteredItem(0).getValue();
     63                                remove(0,getLength());
     64                                super.insertString(0,matchingString,a);
     65
     66                                // highlight from end to insert position
     67                                //
     68                                setCaretPosition(getLength());
     69                                moveCaretPosition(offs + str.length());
     70                        } else {
     71                                // there are no matches. Insert the new text, do not highlight
     72                                //
     73                                String newText = prefix + str;
     74                                remove(0,getLength());
     75                                super.insertString(0,newText,a);
     76                                setCaretPosition(getLength());
     77                        }
     78                }
     79
     80
    7081        }
    7182
    72        
     83
    7384        /** the auto completion list user input is matched against */
    7485        protected AutoCompletionList autoCompletionList = null;
    75                
     86
    7687        /**
    7788         * creates the default document model for this editor
    7889         *
    7990         */
     91        @Override
    8092        protected Document createDefaultModel() {
    81              return new AutoCompletionDocument();
     93                return new AutoCompletionDocument();
    8294        }
    83  
     95
    8496        /**
    85          * constructor 
     97         * constructor
    8698         */
    8799        public TagFieldEditor() {
    88                
     100
    89101                addFocusListener(
    90                    new FocusAdapter() {
    91                                 @Override public void focusGained(FocusEvent e) {
    92                                         selectAll();
    93                                         applyFilter(getText());
    94                     }                                                   
    95                    }
    96                 );     
    97                
     102                                new FocusAdapter() {
     103                                        @Override public void focusGained(FocusEvent e) {
     104                                                selectAll();
     105                                                applyFilter(getText());
     106                                        }
     107                                }
     108                );
     109
    98110                addKeyListener(
    99                         new KeyAdapter() {
     111                                new KeyAdapter() {
    100112
    101                                 @Override
    102                                 public void keyReleased(KeyEvent e) {
    103                                         if (getText().equals("")) {
    104                                                 applyFilter("");
    105                                         }
    106                                 }                               
    107                         }
     113                                        @Override
     114                                        public void keyReleased(KeyEvent e) {
     115                                                if (getText().equals("")) {
     116                                                        applyFilter("");
     117                                                }
     118                                        }
     119                                }
    108120                );
    109         }       
    110        
     121        }
     122
    111123        protected void applyFilter(String filter) {
    112124                if (autoCompletionList != null) {
     
    114126                }
    115127        }
    116        
     128
    117129        /**
    118130         *
    119          * @return the auto completion list; may be null, if no auto completion list is set 
     131         * @return the auto completion list; may be null, if no auto completion list is set
    120132         */
    121133        public AutoCompletionList getAutoCompletionList() {
    122134                return autoCompletionList;
    123135        }
    124        
    125        
     136
    126137        /**
    127          * sets the auto completion list 
    128          * @param autoCompletionList the auto completion list; if null, auto completion is 
     138         * sets the auto completion list
     139         * @param autoCompletionList the auto completion list; if null, auto completion is
    129140         *   disabled
    130141         */
     
    133144        }
    134145
    135 
    136        
    137        
    138        
    139146}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/Item.java

    r14326 r16574  
    2020
    2121        private static Logger logger = Logger.getLogger(Item.class.getName());
    22        
     22
    2323        private String name;
    2424        private String iconName;
     
    2828        private Group parent;
    2929
    30         public Item() { 
     30        public Item() {
    3131                tags = new ArrayList<Tag>();
    3232        }
    33        
     33
    3434        public Group getParent() {
    3535                return parent;
     
    4040        }
    4141
    42        
     42
    4343        public String getLabel() {
    4444                return label;
     
    4949        }
    5050
    51        
     51
    5252        public Item(String name) {
    5353                setName(name);
     
    6969                this.iconName = iconName;
    7070        }
    71        
     71
    7272        public Icon getIcon() {
    7373                if (icon == null) {
    7474                        // load the icon from the JOSM resources, use Main classloader
    75                         // for loading 
     75                        // for loading
    7676                        URL url = Main.class.getResource("/images/" + getIconName());
    7777                        if (url == null) {
     
    8383                        Image i = icon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT);
    8484                        icon = new ImageIcon(i);
    85                        
     85
    8686                }
    87                 return icon;   
     87                return icon;
    8888        }
    89        
     89
    9090        public void addTag(Tag tag) {
    9191                tags.add(tag);
    9292        }
    93        
     93
    9494        public List<Tag> getTags() {
    95                 return tags; 
     95                return tags;
    9696        }
    97        
     97
    9898        public void dump(IndentWriter writer) throws IOException {
    9999                writer.indent();
     
    110110                writer.decLevel();
    111111                writer.writeLine("</item>");
    112         }
    113        
     112        }
     113
     114        @Override
    114115        public String toString() {
    115116                StringBuilder builder  = new StringBuilder();
    116117                builder.append("[")
    117                         .append(getClass().getName())
    118                         .append(":")
    119                         .append("name=")
    120                         .append(name)
    121                         .append("]");
    122                
     118                .append(getClass().getName())
     119                .append(":")
     120                .append("name=")
     121                .append(name)
     122                .append("]");
     123
    123124                return builder.toString();
    124125        }
    125        
    126        
    127126}
  • applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/tagspec/TagSpecification.java

    r14329 r16574  
    99/**
    1010 * A TagSpecifications specifies a tag. The specifications consists of the following
    11  * elements: 
     11 * elements:
    1212 * <ul>
    1313 *       <li>the <strong>key</strong> the of the tag</li>
    1414 *   <li>the <strong>type</strong> of the tag</li>
    15  *   <li>whether the tag is applicable to a node, a way or a relation</li> 
     15 *   <li>whether the tag is applicable to a node, a way or a relation</li>
    1616 * </ul>
    1717 * @author Gubaer
     
    1919 */
    2020public class TagSpecification {
    21        
     21
    2222        /** the key of the tag */
    2323        private String key;
    24        
     24
    2525        /** the type of the tag */
    2626        private String type;
    27        
     27
    2828        /** the type of the tag */
    29        
     29
    3030        private boolean applicableToNode = true;
    3131        private boolean applicableToWay = true;
    3232        private boolean applicableToRelation = true;
    33        
     33
    3434        private ArrayList<LableSpecification> lables = null;
    35        
    36        
     35
     36
    3737        /**
    3838         * constructor
     
    4141                lables = new ArrayList<LableSpecification>();
    4242        }
    43                
    44        
     43
     44        @Override
    4545        public String toString() {
    4646                StringBuilder builder = new StringBuilder();
     
    5454                return builder.toString();
    5555        }
    56        
     56
    5757        /**
    58          * @return the list of predefined labels for this tag; an empty list if no
    59          *   labels are defined 
     58         * @return th e list of predefined labels for this tag; an empty list if no
     59         *   labels are defined
    6060         */
    6161        public List<LableSpecification> getLables() {
    6262                return lables;
    6363        }
    64        
    65        
     64
     65
    6666        /**
    6767         * sets the list of lables for this tag specification
    6868         *
    6969         * @param lables  the list of lables; must not be null
    70          * @exception IllegalArgumentException thrown, if lables is null 
     70         * @exception IllegalArgumentException thrown, if lables is null
    7171         */
    7272        public void setLables(List<LableSpecification> lables) throws IllegalArgumentException {
    73                 if (lables == null) {
     73                if (lables == null)
    7474                        throw new IllegalArgumentException("argument 'lables' must not be null");
    75                 }
    7675                this.lables.clear();
    7776                for (LableSpecification l : lables) {
     
    7978                }
    8079        }
    81        
    82        
     80
     81
    8382        /**
    8483         * adds a lable to the list of lables for this tag specification. The lable
    8584         * is only added if i
    86          *  
     85         *
    8786         * @param lable the lable to add; must not be null
    8887         * @exception IllegalArgumentException thrown, if lable is null
    8988         */
    9089        public void addLable(LableSpecification lable) throws IllegalArgumentException  {
    91                 if (lable == null) {
     90                if (lable == null)
    9291                        throw new IllegalArgumentException("argument 'lable' must not be null");
    93                 }
    9492                if (!this.lables.contains(lable)) {
    9593                        this.lables.add(lable);
    9694                }
    9795        }
    98        
     96
    9997        public boolean isApplicable(AutoCompletionContext context) {
    10098                boolean ret = false;
    10199                if (context.isSelectionEmpty()) {
    102                         ret = true; 
     100                        ret = true;
    103101                } else {
    104102                        ret = ret || (applicableToNode && context.isSelectionIncludesNodes());
     
    108106                return ret;
    109107        }
    110        
     108
    111109        /* --------------------------------------------------------------------------- */
    112110        /* setters/getters                                                             */
     
    141139        public void setApplicableToRelation(boolean applicableToRelation) {
    142140                this.applicableToRelation = applicableToRelation;
    143         }
    144 
    145        
    146        
    147        
     141        }
    148142}
Note: See TracChangeset for help on using the changeset viewer.