Ignore:
Timestamp:
2016-07-11T22:48:15+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/indoorhelper/src/model
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/indoorhelper/src/model/IndoorHelperModel.java

    r32468 r32637  
    2121import java.util.ArrayList;
    2222import java.util.List;
     23
    2324import javax.swing.JOptionPane;
    2425
     
    3637 * Class for the data model which includes indoor data and
    3738 * the functions to handle the plug-in
    38  * 
     39 *
    3940 * @author egru
    4041 */
    41 public class IndoorHelperModel{
    42 
    43         private java.util.List<IndoorLevel> levelList;
    44         private int workingLevel;
    45         private int workingIndex;
    46         private TagCatalog tags;
    47         private PresetCounter counter;
    48        
    49         /**
    50          * Constructor for the {@link IndoorHelperModel} which sets the current
    51          * workingLevel to 0 and creates the {@link TagCatalog}.
    52          */
    53         public IndoorHelperModel() {
    54                 this.workingLevel = 0;
    55                 this.levelList = new ArrayList<>();
    56                 this.tags = new TagCatalog();
    57                 this.counter = new PresetCounter();
    58         }       
    59        
    60         /**
    61          * Method to create a list of levels for the current building.
    62          * It also creates the filters which are needed to execute the indoor mapping.
    63          * minLevel should be lower than maxLevel or the same.
    64          *
    65          * @param minLevel the lowest level of the building
    66          * @param maxLevel the highest level of the building
    67          * @return boolean which indicates if the creation of the levelList was successful
    68          */
    69         public boolean setBuildingLevels(int minLevel, int maxLevel){
    70                
    71                 if(minLevel < maxLevel){
    72                        
    73                         for(int i=minLevel; i<=maxLevel;i++){
    74                                
    75                                 IndoorLevel level = new IndoorLevel(i);
    76                                 levelList.add(level);
    77                                
    78                                 // Get the filter dialog
    79                                 FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class);
    80                                
    81                                 if(filterDialog!=null){
    82                                         // Create a new filter
    83                                         //Filter filter = new Filter("\"indoor:level\"=\""+i+"\"", SearchMode.add, false, false, false);
    84                                         FilterPreferenceEntry entry = new FilterPreferenceEntry();
    85                                         entry.case_sensitive = false;
    86                                         entry.enable = false;
    87                                         entry.hiding = false;
    88                                         entry.inverted = false;
    89                                         entry.mapCSS_search = false;
    90                                         entry.mode = "add";
    91                                         entry.text = "\"indoor:level\"=\""+i+"\"";
    92                                         Filter filter = new Filter(entry);
    93                                        
    94                                         FilterTableModel filterTableModel = filterDialog.getFilterModel();
    95                                        
    96                                         boolean exists = false;
    97                                        
    98                                         // Search if the filter exists already.
    99                                         for(Filter listFilter : filterTableModel.getFilters()){
    100                                                 if(listFilter.equals(filter)){
    101                                                         exists = true;
    102                                                 }
    103                                         }
    104                                        
    105                                         // Only add the filter if it is not already in the filter dialog.
    106                                         if(exists==false){
    107                                                 filterTableModel.addFilter(filter);
    108                                         }
    109                                        
    110                                 }else{
    111                                         //Show error message if filter dialog is null.
    112                                         JOptionPane.showMessageDialog(null, "Filter Dialog is null.", "Error", JOptionPane.ERROR_MESSAGE);
    113                                 }
    114                         }
    115                        
    116                         return true;
    117                        
    118                 } else if(minLevel==maxLevel){
    119                        
    120                         IndoorLevel level = new IndoorLevel(minLevel);
    121                         levelList.add(level);
    122                        
    123                         // Get the filter dialog
    124                         FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class);
    125                        
    126                         if(filterDialog!=null){
    127                                 // Create a new filter
    128                                 //Filter filter = new Filter("\"indoor:level\"=\""+minLevel+"\"", SearchMode.add, false, false, false);
    129                                
    130                                 FilterPreferenceEntry entry = new FilterPreferenceEntry();
    131                                 entry.case_sensitive = false;
    132                                 entry.enable = false;
    133                                 entry.hiding = false;
    134                                 entry.inverted = false;
    135                                 entry.mapCSS_search = false;
    136                                 entry.mode = "add";
    137                                 entry.text = "\"indoor:level\"=\""+minLevel+"\"";
    138                                 Filter filter = new Filter(entry);
    139                                
    140                                 FilterTableModel filterTableModel = filterDialog.getFilterModel();
    141                                
    142                                 boolean exists = false;
    143                                
    144                                 // Search if the filter exists already.
    145                                 for(Filter listFilter : filterTableModel.getFilters()){
    146                                         if(listFilter.equals(filter)){
    147                                                 exists = true;
    148                                         }
    149                                 }
    150                                
    151                                 // Only add the filter if it is not already in the filter dialog.
    152                                 if(exists==false){
    153                                         filterTableModel.addFilter(filter);
    154                                 }
    155                         }else{
    156                                 JOptionPane.showMessageDialog(null, "Filter Dialog is null.", "Error", JOptionPane.ERROR_MESSAGE);
    157                         }
    158                        
    159                        
    160                         return true;
    161                        
    162                 }
    163                
    164                 return false;
    165                
    166         }
    167        
    168         /**
    169          * Getter for the levelList of the model.
    170          *
    171          * @return the levelList, or null if no levelList was created yet
    172          */
    173         public java.util.List<IndoorLevel> getLevelList(){
    174                 return this.levelList;
    175         }
    176        
    177         /**
    178          * Function to set the level the user wants to work on (with the level index) and activates the corresponding filter.
    179          *
    180          * @param index the index of the level the user wants to work on
    181          */
    182         public void setWorkingLevel(int index){
    183                 this.workingIndex = index;
    184                 this.workingLevel = this.getLevelNumberFromIndex(index);
    185                
    186                 FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class);
    187                 FilterTableModel filterTableModel = filterDialog.getFilterModel();
    188                
    189        
    190                 for(Filter filter : filterTableModel.getFilters()){
    191                         // disable the filter for the current level
    192                         if(filter.text.equals("\"indoor:level\"=\""+workingLevel+"\"")){
    193                                 filterTableModel.setValueAt(false, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_ENABLED);
    194                                 filterTableModel.setValueAt(false, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_HIDING);
    195                         } else if(filter.text.startsWith("\"indoor:level\"=\"")){
    196                                 filterTableModel.setValueAt(true, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_ENABLED);
    197                                 filterTableModel.setValueAt(true, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_HIDING);
    198                         }
    199                 }
    200         }
    201        
    202         /**
    203          * Function to get the current working level of the plug-in
    204          *
    205          * @return {@link Integer} which represents the current working level
    206          */
    207         public int getWorkingLevel(){
    208                 return this.workingLevel;
    209         }
    210        
    211         /**
    212          * Method to get the index of the current working level of the plug-in.
    213          *
    214          * @return {@link Integer} which represents the index
    215          */
    216         public int getWorkingIndex(){
    217                 return this.workingIndex;
    218         }
    219        
    220         /**
    221          * Returns the level number which is corresponding to a specific index.
    222          *
    223          * @param index index of the level
    224          * @return a level number as an {@link Integer}
    225          */
    226         public int getLevelNumberFromIndex(int index){
    227                 return levelList.get(index).getLevelNumber();
    228         }
    229        
    230         /**
    231          * Function to set the nameTag of a specific level.
    232          *
    233          * @param levelNumber number of the level
    234          * @param levelName tag which the user wants to set
    235          * @return boolean which indicates if the level was found in the levelList
    236          */
    237         public void setLevelName(int levelIndex, String levelName){
    238                 if((levelName.length()>0) && (levelName != null)){
    239                         levelList.get(levelIndex).setNameTag(levelName);
    240                 }
    241         }
    242        
    243         /**
    244          * Function to get a tag-set out of the {@link TagCatalog}.
    245          *
    246          * @param object the {@link IndoorObject} from which you want to get the tag-set
    247          * @return a {@link List} of {@link Tag}s
    248          */
    249         public List<Tag> getObjectTags(TagCatalog.IndoorObject object){
    250                 return this.tags.getTags(object);
    251         }
    252        
    253        
    254         /**
    255          * Method which adds the selected tag-set to the currently selected OSM data.
    256          * It also adds the level tag corresponding to the current working level.
    257          *
    258          * @param object the object which defines the tag-set you want to add
    259          * @param userTags the tags which are given by the user input
    260          */
    261         public void addTagsToOSM(IndoorObject object, List<Tag> userTags){
    262                 if(!Main.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty()){
    263                        
    264                         List<Tag> tags = this.getObjectTags(object);
    265                         tags.addAll(userTags);
    266                         tags.add(new Tag("indoor:level", Integer.toString(workingLevel)));
    267                        
    268                         if(!this.getLevelList().get(workingIndex).hasEmptyName()){
    269                                 tags.add(this.getLevelList().get(workingIndex).getNameTag());
    270                         }
    271                        
    272                         // Increment the counter for the presets
    273                         this.counter.count(object);
    274                        
    275                         //Add the tags to the current selection
    276                         for(Tag t : tags){
    277                                 Main.main.undoRedo.add(new ChangePropertyCommand(Main.main.getInProgressSelection(), t.getKey(), t.getValue()));
    278                         }
    279                        
    280                 } else if(Main.getLayerManager().getEditDataSet().selectionEmpty()){
    281                        
    282                         JOptionPane.showMessageDialog(null, "No data selected.", "Error", JOptionPane.ERROR_MESSAGE);
    283                 }
    284         }
    285        
    286         /**
     42public class IndoorHelperModel {
     43
     44    private java.util.List<IndoorLevel> levelList;
     45    private int workingLevel;
     46    private int workingIndex;
     47    private TagCatalog tags;
     48    private PresetCounter counter;
     49
     50    /**
     51     * Constructor for the {@link IndoorHelperModel} which sets the current
     52     * workingLevel to 0 and creates the {@link TagCatalog}.
     53     */
     54    public IndoorHelperModel() {
     55        this.workingLevel = 0;
     56        this.levelList = new ArrayList<>();
     57        this.tags = new TagCatalog();
     58        this.counter = new PresetCounter();
     59    }
     60
     61    /**
     62     * Method to create a list of levels for the current building.
     63     * It also creates the filters which are needed to execute the indoor mapping.
     64     * minLevel should be lower than maxLevel or the same.
     65     *
     66     * @param minLevel the lowest level of the building
     67     * @param maxLevel the highest level of the building
     68     * @return boolean which indicates if the creation of the levelList was successful
     69     */
     70    public boolean setBuildingLevels(int minLevel, int maxLevel) {
     71
     72        if (minLevel < maxLevel) {
     73
     74            for (int i = minLevel; i <= maxLevel; i++) {
     75
     76                IndoorLevel level = new IndoorLevel(i);
     77                levelList.add(level);
     78
     79                // Get the filter dialog
     80                FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class);
     81
     82                if (filterDialog != null) {
     83                    // Create a new filter
     84                    //Filter filter = new Filter("\"indoor:level\"=\""+i+"\"", SearchMode.add, false, false, false);
     85                    FilterPreferenceEntry entry = new FilterPreferenceEntry();
     86                    entry.case_sensitive = false;
     87                    entry.enable = false;
     88                    entry.hiding = false;
     89                    entry.inverted = false;
     90                    entry.mapCSS_search = false;
     91                    entry.mode = "add";
     92                    entry.text = "\"indoor:level\"=\""+i+"\"";
     93                    Filter filter = new Filter(entry);
     94
     95                    FilterTableModel filterTableModel = filterDialog.getFilterModel();
     96
     97                    boolean exists = false;
     98
     99                    // Search if the filter exists already.
     100                    for (Filter listFilter : filterTableModel.getFilters()) {
     101                        if (listFilter.equals(filter)) {
     102                            exists = true;
     103                        }
     104                    }
     105
     106                    // Only add the filter if it is not already in the filter dialog.
     107                    if (exists == false) {
     108                        filterTableModel.addFilter(filter);
     109                    }
     110
     111                } else {
     112                    //Show error message if filter dialog is null.
     113                    JOptionPane.showMessageDialog(null, "Filter Dialog is null.", "Error", JOptionPane.ERROR_MESSAGE);
     114                }
     115            }
     116
     117            return true;
     118
     119        } else if (minLevel == maxLevel) {
     120
     121            IndoorLevel level = new IndoorLevel(minLevel);
     122            levelList.add(level);
     123
     124            // Get the filter dialog
     125            FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class);
     126
     127            if (filterDialog != null) {
     128                // Create a new filter
     129                //Filter filter = new Filter("\"indoor:level\"=\""+minLevel+"\"", SearchMode.add, false, false, false);
     130
     131                FilterPreferenceEntry entry = new FilterPreferenceEntry();
     132                entry.case_sensitive = false;
     133                entry.enable = false;
     134                entry.hiding = false;
     135                entry.inverted = false;
     136                entry.mapCSS_search = false;
     137                entry.mode = "add";
     138                entry.text = "\"indoor:level\"=\""+minLevel+"\"";
     139                Filter filter = new Filter(entry);
     140
     141                FilterTableModel filterTableModel = filterDialog.getFilterModel();
     142
     143                boolean exists = false;
     144
     145                // Search if the filter exists already.
     146                for (Filter listFilter : filterTableModel.getFilters()) {
     147                    if (listFilter.equals(filter)) {
     148                        exists = true;
     149                    }
     150                }
     151
     152                // Only add the filter if it is not already in the filter dialog.
     153                if (exists == false) {
     154                    filterTableModel.addFilter(filter);
     155                }
     156            } else {
     157                JOptionPane.showMessageDialog(null, "Filter Dialog is null.", "Error", JOptionPane.ERROR_MESSAGE);
     158            }
     159
     160            return true;
     161        }
     162
     163        return false;
     164    }
     165
     166    /**
     167     * Getter for the levelList of the model.
     168     *
     169     * @return the levelList, or null if no levelList was created yet
     170     */
     171    public java.util.List<IndoorLevel> getLevelList() {
     172        return this.levelList;
     173    }
     174
     175    /**
     176     * Function to set the level the user wants to work on (with the level index) and activates the corresponding filter.
     177     *
     178     * @param index the index of the level the user wants to work on
     179     */
     180    public void setWorkingLevel(int index) {
     181        this.workingIndex = index;
     182        this.workingLevel = this.getLevelNumberFromIndex(index);
     183
     184        FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class);
     185        FilterTableModel filterTableModel = filterDialog.getFilterModel();
     186
     187
     188        for (Filter filter : filterTableModel.getFilters()) {
     189            // disable the filter for the current level
     190            if (filter.text.equals("\"indoor:level\"=\""+workingLevel+"\"")) {
     191                filterTableModel.setValueAt(false, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_ENABLED);
     192                filterTableModel.setValueAt(false, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_HIDING);
     193            } else if (filter.text.startsWith("\"indoor:level\"=\"")) {
     194                filterTableModel.setValueAt(true, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_ENABLED);
     195                filterTableModel.setValueAt(true, filterTableModel.getFilters().indexOf(filter), FilterTableModel.COL_HIDING);
     196            }
     197        }
     198    }
     199
     200    /**
     201     * Function to get the current working level of the plug-in
     202     *
     203     * @return {@link Integer} which represents the current working level
     204     */
     205    public int getWorkingLevel() {
     206        return this.workingLevel;
     207    }
     208
     209    /**
     210     * Method to get the index of the current working level of the plug-in.
     211     *
     212     * @return {@link Integer} which represents the index
     213     */
     214    public int getWorkingIndex() {
     215        return this.workingIndex;
     216    }
     217
     218    /**
     219     * Returns the level number which is corresponding to a specific index.
     220     *
     221     * @param index index of the level
     222     * @return a level number as an {@link Integer}
     223     */
     224    public int getLevelNumberFromIndex(int index) {
     225        return levelList.get(index).getLevelNumber();
     226    }
     227
     228    /**
     229     * Function to set the nameTag of a specific level.
     230     *
     231     * @param levelNumber number of the level
     232     * @param levelName tag which the user wants to set
     233     * @return boolean which indicates if the level was found in the levelList
     234     */
     235    public void setLevelName(int levelIndex, String levelName) {
     236        if ((levelName.length() > 0) && (levelName != null)) {
     237            levelList.get(levelIndex).setNameTag(levelName);
     238        }
     239    }
     240
     241    /**
     242     * Function to get a tag-set out of the {@link TagCatalog}.
     243     *
     244     * @param object the {@link IndoorObject} from which you want to get the tag-set
     245     * @return a {@link List} of {@link Tag}s
     246     */
     247    public List<Tag> getObjectTags(TagCatalog.IndoorObject object) {
     248        return this.tags.getTags(object);
     249    }
     250
     251
     252    /**
    287253     * Method which adds the selected tag-set to the currently selected OSM data.
    288          * It also adds the level tag corresponding to the current working level.
    289          *
    290          * @param object the object which defines the tag-set you want to add
    291          */
    292         public void addTagsToOSM(IndoorObject object){
    293                
    294                 if(!Main.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty()){
    295                         List<Tag> tags = this.getObjectTags(object);
    296                         tags.add(new Tag("indoor:level", Integer.toString(workingLevel)));
    297                        
    298                         // Increment the counter for the presets
    299                         this.counter.count(object);
    300                        
    301                         //Add the tags to the current selection
    302                         for(Tag t : tags){
    303                                 Main.main.undoRedo.add(new ChangePropertyCommand(Main.main.getInProgressSelection(), t.getKey(), t.getValue()));
    304                         }
    305                 } else if(Main.getLayerManager().getEditDataSet().selectionEmpty()){
    306                         JOptionPane.showMessageDialog(null, "No data selected.", "Error", JOptionPane.ERROR_MESSAGE);
    307                 }
    308         }
    309        
    310         /**
    311          * Returns the current ranking of the preset counter, which includes the 4 most used items.
    312          *
    313          * @return a list of the 4 most used IndoorObjects
    314          */
    315         public List<IndoorObject> getPresetRanking(){
    316                 return counter.getRanking();
    317         }
     254     * It also adds the level tag corresponding to the current working level.
     255     *
     256     * @param object the object which defines the tag-set you want to add
     257     * @param userTags the tags which are given by the user input
     258     */
     259    public void addTagsToOSM(IndoorObject object, List<Tag> userTags) {
     260        if (!Main.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty()) {
     261
     262            List<Tag> tags = this.getObjectTags(object);
     263            tags.addAll(userTags);
     264            tags.add(new Tag("indoor:level", Integer.toString(workingLevel)));
     265
     266            if (!this.getLevelList().get(workingIndex).hasEmptyName()) {
     267                tags.add(this.getLevelList().get(workingIndex).getNameTag());
     268            }
     269
     270            // Increment the counter for the presets
     271            this.counter.count(object);
     272
     273            //Add the tags to the current selection
     274            for (Tag t : tags) {
     275                Main.main.undoRedo.add(new ChangePropertyCommand(Main.main.getInProgressSelection(), t.getKey(), t.getValue()));
     276            }
     277
     278        } else if (Main.getLayerManager().getEditDataSet().selectionEmpty()) {
     279
     280            JOptionPane.showMessageDialog(null, "No data selected.", "Error", JOptionPane.ERROR_MESSAGE);
     281        }
     282    }
     283
     284    /**
     285     * Method which adds the selected tag-set to the currently selected OSM data.
     286     * It also adds the level tag corresponding to the current working level.
     287     *
     288     * @param object the object which defines the tag-set you want to add
     289     */
     290    public void addTagsToOSM(IndoorObject object) {
     291
     292        if (!Main.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty()) {
     293            List<Tag> tags = this.getObjectTags(object);
     294            tags.add(new Tag("indoor:level", Integer.toString(workingLevel)));
     295
     296            // Increment the counter for the presets
     297            this.counter.count(object);
     298
     299            //Add the tags to the current selection
     300            for (Tag t : tags) {
     301                Main.main.undoRedo.add(new ChangePropertyCommand(Main.main.getInProgressSelection(), t.getKey(), t.getValue()));
     302            }
     303        } else if (Main.getLayerManager().getEditDataSet().selectionEmpty()) {
     304            JOptionPane.showMessageDialog(null, "No data selected.", "Error", JOptionPane.ERROR_MESSAGE);
     305        }
     306    }
     307
     308    /**
     309     * Returns the current ranking of the preset counter, which includes the 4 most used items.
     310     *
     311     * @return a list of the 4 most used IndoorObjects
     312     */
     313    public List<IndoorObject> getPresetRanking() {
     314        return counter.getRanking();
     315    }
    318316}
  • applications/editors/josm/plugins/indoorhelper/src/model/IndoorLevel.java

    r32122 r32637  
    2222
    2323/**
    24  * 
     24 *
    2525 * The class to save a level of the building.
    26  * 
     26 *
    2727 * @author egru
    2828 *
     
    3030
    3131public class IndoorLevel {
    32        
    33         private Tag levelNumberTag;
    34         private Tag nameTag;
    35        
    36         /**
    37          * Constructor which adds the level number.
    38          *
    39          * @param levelNumber number of the level
    40          */
    41         public IndoorLevel(int levelNumber) {
    42                 this.setLevelNumber(levelNumber);
    43         }
    44        
    45         /**
    46          * Constructor which adds level number and name tag.
    47          *       
    48          * @param levelNumber number of the level
    49          * @param nameTag optional name tag for the level
    50          */
    51         public IndoorLevel(int levelNumber, String nameTag) {
    52                 this.setLevelNumber(levelNumber);
    53                 this.setNameTag(nameTag);
    54         }
    55        
    56         /**
    57          * Getter for the level tag
    58          *
    59          * @return the complete level number tag
    60          */
    61         public Tag getLevelNumberTag() {
    62                 return this.levelNumberTag;
    63         }
    64        
    65         /**
    66          * Function to get the level number
    67          *
    68          * @return level number as an Integer
    69          */
    70         public int getLevelNumber(){
    71                 return Integer.parseInt(this.levelNumberTag.getValue());
    72         }
    73        
    74         /**
    75          * Setter for the level number
    76          *
    77          * @param levelNumber number of the level
    78          */
    79         public void setLevelNumber(int levelNumber) {
    80                 this.levelNumberTag = new Tag("indoor:level", Integer.toString(levelNumber));
    81         }
    82        
    83         /**
    84          * Getter for the name tag
    85          *
    86          * @return the complete name tag
    87          */
    88         public Tag getNameTag() {
    89                 return this.nameTag;
    90         }
    91        
    92         /**
    93          * Function to get the optional name of the level.
    94          *
    95          * @return String with the optional name.
    96          */
    97         public String getName(){
    98                 return this.nameTag.getValue();
    99         }
    100        
    101         /**
    102          * Setter for the name tag
    103          *
    104          * @param nameTag String which optionally describes the level
    105          */
    106         public void setNameTag(String nameTag) {
    107                 this.nameTag = new Tag("indoor:level:name", nameTag);
    108         }
    109        
    110         public boolean hasEmptyName(){
    111                 if(this.nameTag==null){
    112                         return true;
    113                 } else {
    114                         return false;
    115                 }
    116         }
    117        
     32
     33    private Tag levelNumberTag;
     34    private Tag nameTag;
     35
     36    /**
     37     * Constructor which adds the level number.
     38     *
     39     * @param levelNumber number of the level
     40     */
     41    public IndoorLevel(int levelNumber) {
     42        this.setLevelNumber(levelNumber);
     43    }
     44
     45    /**
     46     * Constructor which adds level number and name tag.
     47     *
     48     * @param levelNumber number of the level
     49     * @param nameTag optional name tag for the level
     50     */
     51    public IndoorLevel(int levelNumber, String nameTag) {
     52        this.setLevelNumber(levelNumber);
     53        this.setNameTag(nameTag);
     54    }
     55
     56    /**
     57     * Getter for the level tag
     58     *
     59     * @return the complete level number tag
     60     */
     61    public Tag getLevelNumberTag() {
     62        return this.levelNumberTag;
     63    }
     64
     65    /**
     66     * Function to get the level number
     67     *
     68     * @return level number as an Integer
     69     */
     70    public int getLevelNumber() {
     71        return Integer.parseInt(this.levelNumberTag.getValue());
     72    }
     73
     74    /**
     75     * Setter for the level number
     76     *
     77     * @param levelNumber number of the level
     78     */
     79    public void setLevelNumber(int levelNumber) {
     80        this.levelNumberTag = new Tag("indoor:level", Integer.toString(levelNumber));
     81    }
     82
     83    /**
     84     * Getter for the name tag
     85     *
     86     * @return the complete name tag
     87     */
     88    public Tag getNameTag() {
     89        return this.nameTag;
     90    }
     91
     92    /**
     93     * Function to get the optional name of the level.
     94     *
     95     * @return String with the optional name.
     96     */
     97    public String getName() {
     98        return this.nameTag.getValue();
     99    }
     100
     101    /**
     102     * Setter for the name tag
     103     *
     104     * @param nameTag String which optionally describes the level
     105     */
     106    public void setNameTag(String nameTag) {
     107        this.nameTag = new Tag("indoor:level:name", nameTag);
     108    }
     109
     110    public boolean hasEmptyName() {
     111        if (this.nameTag == null) {
     112            return true;
     113        } else {
     114            return false;
     115        }
     116    }
    118117}
  • applications/editors/josm/plugins/indoorhelper/src/model/PresetCounter.java

    r32122 r32637  
    3333 */
    3434public class PresetCounter {
    35        
    36         private List<IndoorObject> rankingList;
    37         private List<ObjectCounter> counterList;
    38        
    39         /**
    40         * Initiates the counterList with the available IndoorObjects.
    41         */
    42        
    43         public PresetCounter(){
    44                 this.init();
    45         }
    46        
    47         private void init(){
    48                 counterList = new ArrayList<>();
    49                
    50                 counterList.add(new ObjectCounter(IndoorObject.CONCRETE_WALL, 0));
    51                 counterList.add(new ObjectCounter(IndoorObject.DOOR, 0));
    52                 counterList.add(new ObjectCounter(IndoorObject.ELEVATOR, 0));
    53                 counterList.add(new ObjectCounter(IndoorObject.ENTRANCE, 0));
    54                 counterList.add(new ObjectCounter(IndoorObject.GLASS_WALL, 0));
    55                 counterList.add(new ObjectCounter(IndoorObject.ROOM, 0));
    56                 counterList.add(new ObjectCounter(IndoorObject.SHELL, 0));
    57                 counterList.add(new ObjectCounter(IndoorObject.STAIRWAYS, 0));
    58                 counterList.add(new ObjectCounter(IndoorObject.STEPS, 0));
    59                 counterList.add(new ObjectCounter(IndoorObject.TOILET_FEMALE, 0));
    60                 counterList.add(new ObjectCounter(IndoorObject.TOILET_MALE, 0));
    61         }
    62        
    63         /**
    64         * Increments the counter of a specific IndoorObject in the list.
    65         * @param object the IndoorObject, which counter should be incremented
    66         */
    67         public void count(IndoorObject object){
    68                 ListIterator<ObjectCounter> iterator = this.counterList.listIterator();
    69                
    70                 // Go through the list and increment the corresponding objects counter value.
    71                 while(iterator.hasNext()){
    72                         ObjectCounter counterTemp = iterator.next();
    73                         if(counterTemp.getObject().equals(object)){
    74                                         counterList.get(iterator.nextIndex()-1).increment();   
    75                         }
    76                 }
    77                
    78                 //Sort the list.
    79                 this.sort();
    80         }
    81        
    82         private void sort(){
    83                 Collections.sort(counterList);
    84                 Collections.reverse(counterList);
    85         }
    86        
    87         public List<IndoorObject> getRanking(){
    88                 rankingList = new ArrayList<IndoorObject>();
    89                
    90                 rankingList.add(counterList.get(0).getObject());
    91                 rankingList.add(counterList.get(1).getObject());
    92                 rankingList.add(counterList.get(2).getObject());
    93                 rankingList.add(counterList.get(3).getObject());
    94                
    95                 return rankingList;
    96         }
    97        
    98         private class ObjectCounter implements Comparable<ObjectCounter>{
    99                 private IndoorObject object;
    100                 private int count;
    101                
    102                 public ObjectCounter(IndoorObject o, int c) {
    103                         this.object = o;
    104                         this.count = c;
    105                 }
    106                
    107                 public int getCount(){
    108                         return this.count;
    109                 }
    110                
    111                 public IndoorObject getObject(){
    112                         return this.object;
    113                 }
    114                
    115                 public void increment(){
    116                         this.count += 1;
    117                 }
    118                
    119                 @Override
    120                 public int compareTo(ObjectCounter o) {
    121                         if(this.getCount()<o.getCount()){
    122                                 return -1;
    123                         }
    124                         if(this.getCount()==o.getCount()){
    125                                 return 0;
    126                         }
    127                         if(this.getCount()>o.getCount()){
    128                                 return 1;
    129                         }
    130                        
    131                         return 0;
    132                 }
    133                
    134         }
    135        
     35   
     36    private List<IndoorObject> rankingList;
     37    private List<ObjectCounter> counterList;
     38   
     39    /**
     40    * Initiates the counterList with the available IndoorObjects.
     41    */
     42   
     43    public PresetCounter() {
     44        this.init();
     45    }
     46   
     47    private void init() {
     48        counterList = new ArrayList<>();
     49       
     50        counterList.add(new ObjectCounter(IndoorObject.CONCRETE_WALL, 0));
     51        counterList.add(new ObjectCounter(IndoorObject.DOOR, 0));
     52        counterList.add(new ObjectCounter(IndoorObject.ELEVATOR, 0));
     53        counterList.add(new ObjectCounter(IndoorObject.ENTRANCE, 0));
     54        counterList.add(new ObjectCounter(IndoorObject.GLASS_WALL, 0));
     55        counterList.add(new ObjectCounter(IndoorObject.ROOM, 0));
     56        counterList.add(new ObjectCounter(IndoorObject.SHELL, 0));
     57        counterList.add(new ObjectCounter(IndoorObject.STAIRWAYS, 0));
     58        counterList.add(new ObjectCounter(IndoorObject.STEPS, 0));
     59        counterList.add(new ObjectCounter(IndoorObject.TOILET_FEMALE, 0));
     60        counterList.add(new ObjectCounter(IndoorObject.TOILET_MALE, 0));
     61    }
     62   
     63    /**
     64    * Increments the counter of a specific IndoorObject in the list.
     65    * @param object the IndoorObject, which counter should be incremented
     66    */
     67    public void count(IndoorObject object) {
     68        ListIterator<ObjectCounter> iterator = this.counterList.listIterator();
     69       
     70        // Go through the list and increment the corresponding objects counter value.
     71        while (iterator.hasNext()) {
     72            ObjectCounter counterTemp = iterator.next();
     73            if (counterTemp.getObject().equals(object)) {
     74                    counterList.get(iterator.nextIndex()-1).increment();   
     75            }
     76        }
     77       
     78        //Sort the list.
     79        this.sort();
     80    }
     81   
     82    private void sort() {
     83        Collections.sort(counterList);
     84        Collections.reverse(counterList);
     85    }
     86   
     87    public List<IndoorObject> getRanking() {
     88        rankingList = new ArrayList<IndoorObject>();
     89       
     90        rankingList.add(counterList.get(0).getObject());
     91        rankingList.add(counterList.get(1).getObject());
     92        rankingList.add(counterList.get(2).getObject());
     93        rankingList.add(counterList.get(3).getObject());
     94       
     95        return rankingList;
     96    }
     97   
     98    private class ObjectCounter implements Comparable<ObjectCounter> {
     99        private IndoorObject object;
     100        private int count;
     101       
     102        ObjectCounter(IndoorObject o, int c) {
     103            this.object = o;
     104            this.count = c;
     105        }
     106       
     107        public int getCount() {
     108            return this.count;
     109        }
     110       
     111        public IndoorObject getObject() {
     112            return this.object;
     113        }
     114       
     115        public void increment() {
     116            this.count += 1;
     117        }
     118       
     119        @Override
     120        public int compareTo(ObjectCounter o) {
     121            if (this.getCount() < o.getCount()) {
     122                return -1;
     123            }
     124            if (this.getCount() == o.getCount()) {
     125                return 0;
     126            }
     127            if (this.getCount() > o.getCount()) {
     128                return 1;
     129            }
     130           
     131            return 0;
     132        }
     133       
     134    }
     135   
    136136}
  • applications/editors/josm/plugins/indoorhelper/src/model/TagCatalog.java

    r32122 r32637  
    3232
    3333public final class TagCatalog {
    34        
    35         /**
    36         * Function to get a specific tag-set out of the {@link TagCatalog}.
    37         *
    38         * @param o the object for which you want the tag-set
    39         * @return a list of tags for the specified object
    40          */     
    41         public List<Tag> getTags(IndoorObject o){
    42                
    43                 List<Tag> tagList = new ArrayList<Tag>();
    44                
    45                 switch(o){
    46                 case CONCRETE_WALL:
    47                         tagList.add(new Tag("indoor:area", "wall"));
    48                         tagList.add(new Tag("indoor:wall:material", "concrete"));
    49                         return tagList;
    50                 case DOOR:
    51                         tagList.add(new Tag("indoor:door", "yes"));
    52                         return tagList;
    53                 case ELEVATOR:
    54                         tagList.add(new Tag("indoor:area", "elevator"));
    55                         return tagList;
    56                 case ENTRANCE:
    57                         tagList.add(new Tag("indoor:entrance", "yes"));
    58                         return tagList;
    59                 case TOILET_FEMALE:
    60                         tagList.add(new Tag("indoor:area", "room"));
    61                         tagList.add(new Tag("amenity", "toilets"));
    62                         tagList.add(new Tag("female", "yes"));
    63                         return tagList;
    64                 case GLASS_WALL:
    65                         tagList.add(new Tag("indoor:area", "wall"));
    66                         tagList.add(new Tag("indoor:wall:material", "glass"));
    67                         return tagList;
    68                 case TOILET_MALE:
    69                         tagList.add(new Tag("indoor:area", "room"));
    70                         tagList.add(new Tag("amenity", "toilets"));
    71                         tagList.add(new Tag("male", "yes"));
    72                         return tagList;
    73                 case ROOM:
    74                         tagList.add(new Tag("indoor:area", "room"));
    75                         return tagList;
    76                 case SHELL:
    77                         tagList.add(new Tag("indoor:area", "shell"));
    78                         return tagList;
    79                 case STAIRWAYS:
    80                         tagList.add(new Tag("indoor:area", "stairways"));
    81                         return tagList;
    82                 case STEPS:
    83                         tagList.add(new Tag("indoor:highway", "steps"));
    84                         return tagList;
    85                 default:
    86                         tagList = null;
    87                         return tagList;
    88                 }
    89         }
    90        
    91         /**
    92         * {@link Enum} class for an easier access of elements in the {@link TagCatalog}
    93         *
    94         * @author egru
    95         *
    96         */
    97         public enum IndoorObject{
    98                 SHELL, CONCRETE_WALL, GLASS_WALL, ROOM, TOILET_MALE, TOILET_FEMALE, ELEVATOR, STAIRWAYS, STEPS, DOOR, ENTRANCE;
    99         }
     34   
     35    /**
     36    * Function to get a specific tag-set out of the {@link TagCatalog}.
     37    *
     38    * @param o the object for which you want the tag-set
     39    * @return a list of tags for the specified object
     40     */   
     41    public List<Tag> getTags(IndoorObject o) {
     42       
     43        List<Tag> tagList = new ArrayList<Tag>();
     44       
     45        switch(o) {
     46        case CONCRETE_WALL:
     47            tagList.add(new Tag("indoor:area", "wall"));
     48            tagList.add(new Tag("indoor:wall:material", "concrete"));
     49            return tagList;
     50        case DOOR:
     51            tagList.add(new Tag("indoor:door", "yes"));
     52            return tagList;
     53        case ELEVATOR:
     54            tagList.add(new Tag("indoor:area", "elevator"));
     55            return tagList;
     56        case ENTRANCE:
     57            tagList.add(new Tag("indoor:entrance", "yes"));
     58            return tagList;
     59        case TOILET_FEMALE:
     60            tagList.add(new Tag("indoor:area", "room"));
     61            tagList.add(new Tag("amenity", "toilets"));
     62            tagList.add(new Tag("female", "yes"));
     63            return tagList;
     64        case GLASS_WALL:
     65            tagList.add(new Tag("indoor:area", "wall"));
     66            tagList.add(new Tag("indoor:wall:material", "glass"));
     67            return tagList;
     68        case TOILET_MALE:
     69            tagList.add(new Tag("indoor:area", "room"));
     70            tagList.add(new Tag("amenity", "toilets"));
     71            tagList.add(new Tag("male", "yes"));
     72            return tagList;
     73        case ROOM:
     74            tagList.add(new Tag("indoor:area", "room"));
     75            return tagList;
     76        case SHELL:
     77            tagList.add(new Tag("indoor:area", "shell"));
     78            return tagList;
     79        case STAIRWAYS:
     80            tagList.add(new Tag("indoor:area", "stairways"));
     81            return tagList;
     82        case STEPS:
     83            tagList.add(new Tag("indoor:highway", "steps"));
     84            return tagList;
     85        default:
     86            tagList = null;
     87            return tagList;
     88        }
     89    }
     90   
     91    /**
     92    * {@link Enum} class for an easier access of elements in the {@link TagCatalog}
     93    *
     94    * @author egru
     95    *
     96    */
     97    public enum IndoorObject {
     98        SHELL, CONCRETE_WALL, GLASS_WALL, ROOM, TOILET_MALE, TOILET_FEMALE, ELEVATOR, STAIRWAYS, STEPS, DOOR, ENTRANCE;
     99    }
    100100
    101101}
Note: See TracChangeset for help on using the changeset viewer.