Changeset 32637 in osm for applications/editors/josm/plugins/indoorhelper
- Timestamp:
- 2016-07-11T22:48:15+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/indoorhelper
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/.project
r32134 r32637 17 17 </arguments> 18 18 </buildCommand> 19 <buildCommand> 20 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 21 <arguments> 22 </arguments> 23 </buildCommand> 19 24 </buildSpec> 20 25 <natures> 21 26 <nature>org.eclipse.jdt.core.javanature</nature> 27 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 22 28 </natures> 23 29 </projectDescription> -
applications/editors/josm/plugins/indoorhelper/old/ToolboxViewOLD.java
r32122 r32637 48 48 @Override 49 49 public void actionPerformed(ActionEvent e) { 50 if (activatorButton.getText().equals("OFF")){50 if (activatorButton.getText().equals("OFF")){ 51 51 activatorButton.setText("ON"); 52 52 … … 54 54 levSel.createFrame(); 55 55 56 } else if (activatorButton.getText().equals("ON")){56 } else if (activatorButton.getText().equals("ON")){ 57 57 activatorButton.setText("OFF"); 58 58 } -
applications/editors/josm/plugins/indoorhelper/src/controller/IndoorHelperController.java
r32468 r32637 49 49 50 50 /** 51 * 51 * 52 52 * Class for the Controller which provides the communication between 53 53 * the IndoorHelperModel and the different views. 54 * 54 * 55 55 * @author egru 56 56 * … … 58 58 public class IndoorHelperController { 59 59 60 private IndoorHelperModel model; 61 private ToolBoxView toolboxView; 62 private FittingView fittingView; 63 private LevelSelectorView selectorView; 64 private String sep = System.getProperty("file.separator"); 65 66 67 private int lastLevelIndex; 68 69 /** 70 * Constructor for the {@link IndoorHelperController} which initiates model and views. 71 * 72 */ 73 public IndoorHelperController(){ 74 this.model = new IndoorHelperModel(); 75 this.toolboxView = new ToolBoxView(); 76 77 this.lastLevelIndex = 0; 78 79 addToolboxListeners(); 80 Main.map.addToggleDialog(toolboxView); 81 } 82 83 /** 84 * Adds the button- and box-listeners to the {@link ToolBoxView}. 85 */ 86 private void addToolboxListeners(){ 87 88 if(this.toolboxView!=null){ 89 this.toolboxView.setPowerButtonListener(new ToolPowerButtonListener()); 90 this.toolboxView.setApplyButtonListener(new ToolApplyButtonListener()); 91 this.toolboxView.setLevelItemListener(new ToolLevelItemListener()); 92 this.toolboxView.setObjectItemListener(new ToolObjectItemListener()); 93 this.toolboxView.setPreset1Listener(new Preset1Listener()); 94 this.toolboxView.setPreset2Listener(new Preset2Listener()); 95 this.toolboxView.setPreset3Listener(new Preset3Listener()); 96 this.toolboxView.setPreset4Listener(new Preset4Listener()); 97 } 98 } 99 100 /** 101 * Adds the button-listeners to the {@link LevelSelectorView}. 102 */ 103 private void addLevelSelectorListeners(){ 104 if(this.selectorView!=null){ 105 this.selectorView.setOkButtonListener(new LevelOkButtonListener()); 106 this.selectorView.setCancelButtonListener(new LevelCancelButtonListener()); 107 } 108 } 109 110 /** 111 * Adds the button-listeners to the {@link FittingView}. 112 */ 113 private void addFittingListeners(){ 114 if(this.fittingView!=null){ 115 this.fittingView.setOkButtonListener(new FittingOkButtonListener()); 116 } 117 } 118 119 //******************************************************************** 120 //********************* TOOLBOX LISTENERS ************************ 121 //******************************************************************** 122 123 /** 124 * The listener which handles the power button. 125 * 126 * @author egru 127 * 128 */ 129 class ToolPowerButtonListener implements ActionListener{ 130 131 @Override 132 public void actionPerformed(ActionEvent e) { 133 if(toolboxView.getPowerButtonState()){ 134 selectorView = new LevelSelectorView(); 135 addLevelSelectorListeners(); 136 selectorView.setVisible(true); 137 setPluginPreferences(true); 138 } else if(!toolboxView.getPowerButtonState()){ 139 model = new IndoorHelperModel(); 140 selectorView.dispose(); 141 toolboxView.reset(); 142 setPluginPreferences(false); 143 144 // Delete the indoor filters 145 FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class); 146 147 if(filterDialog!=null){ 148 FilterTableModel filterTableModel = filterDialog.getFilterModel(); 149 150 for(int i=filterTableModel.getRowCount()-1;i>-1;i--){ 151 if(filterTableModel.getFilter(i).text.startsWith("\"indoor:level\"=\"")){ 152 filterTableModel.removeFilter(i); 153 } 154 } 155 156 } 157 } 158 } 159 } 160 161 162 /** 163 * The listener which provides the handling of the apply button. 164 * Gets the texts which were written by the user and writes them to the OSM-data. 165 * After that it checks the tagged data with the built-in validator file. 166 * 167 * @author egru 168 */ 169 class ToolApplyButtonListener implements ActionListener{ 170 171 @Override 172 public void actionPerformed(ActionEvent e) { 173 IndoorObject indoorObject = toolboxView.getSelectedObject(); 174 if(toolboxView.getNameText().isEmpty() && toolboxView.getRefText().isEmpty() && toolboxView.getLevelName().isEmpty()){ 175 model.addTagsToOSM(indoorObject); 176 } else { 177 List<Tag> tags = new ArrayList<>(); 178 if(!toolboxView.getLevelName().isEmpty()){ 179 model.getLevelList().get(toolboxView.getSelectedLevelIndex()).setNameTag(toolboxView.getLevelName()); 180 } 181 if(!toolboxView.getNameText().isEmpty()){ 182 tags.add(new Tag("name", toolboxView.getNameText())); 183 } 184 if(!toolboxView.getRefText().isEmpty()) { 185 tags.add(new Tag("ref", toolboxView.getRefText())); 186 } 187 model.addTagsToOSM(indoorObject, tags); 188 } 189 //Do the validation process 190 ValidateAction validateAction = new ValidateAction(); 191 validateAction.doValidate(true); 192 193 refreshPresets(); 194 } 195 } 196 197 /** 198 * <pre>The listener which is called when a new item in the level list is selected. 199 *It also sets the name-tag for a level, if the user has done an input in the textbox. 200 * </pre> 201 * @author egru 202 * 203 */ 204 class ToolLevelItemListener implements ItemListener{ 205 206 @Override 207 public void itemStateChanged(ItemEvent e) { 208 if(!toolboxView.levelListIsEmpty()){ 209 210 if(!toolboxView.getLevelName().isEmpty()){ 211 model.getLevelList().get(lastLevelIndex).setNameTag(toolboxView.getLevelName()); 212 } 213 214 if(!model.getLevelList().get(toolboxView.getSelectedLevelIndex()).hasEmptyName()){ 215 toolboxView.setLevelName(model.getLevelList().get(toolboxView.getSelectedLevelIndex()).getName()); 216 } else { 217 toolboxView.setLevelName(""); 218 } 219 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); 220 221 lastLevelIndex = toolboxView.getSelectedLevelIndex(); 222 } 223 } 224 } 225 226 227 228 /** 229 * The listener which is called when a new item in the object list is selected. 230 * 231 * @author egru 232 * 233 */ 234 class ToolObjectItemListener implements ItemListener{ 235 236 @Override 237 public void itemStateChanged(ItemEvent e) { 238 if(toolboxView.getSelectedObject().equals(IndoorObject.ROOM)){ 239 toolboxView.setTagUiElementsEnabled(true); 240 } else{ 241 toolboxView.setTagUiElementsEnabled(false); 242 } 243 } 244 245 } 246 247 /** 248 * Listener for preset button 1. 249 * @author egru 250 * 251 */ 252 class Preset1Listener implements ActionListener{ 253 254 @Override 255 public void actionPerformed(ActionEvent e) { 256 model.addTagsToOSM(toolboxView.getPreset1()); 257 258 } 259 260 } 261 262 /** 263 * Listener for preset button 2. 264 * @author egru 265 * 266 */ 267 class Preset2Listener implements ActionListener{ 268 269 @Override 270 public void actionPerformed(ActionEvent e) { 271 model.addTagsToOSM(toolboxView.getPreset2()); 272 273 } 274 275 } 276 277 /** 278 * Listener for preset button 3. 279 * @author egru 280 * 281 */ 282 class Preset3Listener implements ActionListener{ 283 284 @Override 285 public void actionPerformed(ActionEvent e) { 286 model.addTagsToOSM(toolboxView.getPreset3()); 287 288 } 289 290 } 291 292 /** 293 * Listener for preset button 4. 294 * @author egru 295 * 296 */ 297 class Preset4Listener implements ActionListener{ 298 299 @Override 300 public void actionPerformed(ActionEvent e) { 301 model.addTagsToOSM(toolboxView.getPreset4()); 302 303 } 304 305 } 306 307 /** 308 * Updates the preset button from the current ranking. 309 */ 310 private void refreshPresets(){ 311 toolboxView.setPresetButtons(model.getPresetRanking()); 312 } 313 314 315 //******************* 316 // SELECTOR LISTENERS 317 //******************* 318 319 /** 320 * <pre> 321 * The listener which handles the click on the OK-button of the {@link LevelSelectorView}. 322 * It sends the data of the view to the model and displays an error message, 323 * if the level-list couldn't be created. 324 * </pre> 325 * @author egru 326 * 327 */ 328 class LevelOkButtonListener implements ActionListener{ 329 330 @Override 331 public void actionPerformed(ActionEvent e) { 332 boolean levelSuccess = model.setBuildingLevels(selectorView.getMin(), selectorView.getMax()); 333 334 if(levelSuccess){ 335 toolboxView.setLevelList(model.getLevelList()); //set the levels to the ComboBox and 336 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); //sets the working level in the model 337 338 selectorView.dispose(); 339 340 fittingView = new FittingView(); 341 addFittingListeners(); 342 fittingView.setVisible(true); 343 } else{ 344 345 JOptionPane.showMessageDialog(null, "Lowest Level has to be lower than the highest level", 346 "Error", JOptionPane.ERROR_MESSAGE); 347 } 348 } 349 } 350 351 /** 352 * Closes the level selection view if the user hits the cancel button. 353 * 354 * @author egru 355 * 356 */ 357 class LevelCancelButtonListener implements ActionListener{ 358 359 @Override 360 public void actionPerformed(ActionEvent e) { 361 selectorView.dispose(); 362 toolboxView.setPowerButtonDisabled(); 363 setPluginPreferences(false); 364 } 365 366 } 367 368 369 370 //******************* 371 // FITTING LISTENERS 372 //******************* 373 /** 374 * Closes the {@link FittingView} if the OK-Button is clicked. 375 * Enables the UI elements of the toolbox 376 * 377 * @author egru 378 * 379 */ 380 class FittingOkButtonListener implements ActionListener{ 381 382 @Override 383 public void actionPerformed(ActionEvent e) { 384 fittingView.dispose(); 385 toolboxView.setAllUiElementsEnabled(true); 386 toolboxView.setTagUiElementsEnabled(false); 387 } 388 389 } 390 391 /* 392 HELPER METHODS 393 */ 394 395 /** 396 * Enables or disables the preferences for the mapcss-style and the validator. 397 * 398 * @param enabled Activates or disables the settings. 399 */ 400 private void setPluginPreferences(boolean enabled){ 401 Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 402 403 404 MapListSetting validatorMapListSetting = (MapListSetting) settings. 405 get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 406 List<Map<String, String>> validatorMaps = new ArrayList<>(); 407 if(validatorMapListSetting!=null){ 408 validatorMaps = validatorMapListSetting.getValue(); 409 } 410 411 MapListSetting styleMapListSetting = (MapListSetting) settings. 412 get("mappaint.style.entries"); 413 List<Map<String, String>> styleMaps = new ArrayList<>(); 414 if(styleMapListSetting != null){ 415 styleMaps = styleMapListSetting.getValue(); 416 } 417 418 if(enabled){ 419 //set the validator active 420 421 422 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 423 if(!validatorMaps.isEmpty()){ 424 validatorMapsNew.addAll(validatorMaps); 425 } 426 427 428 for(Map<String, String> map : validatorMapsNew){ 429 if(map.containsValue("Indoor")){ 430 validatorMapsNew.remove(map); 431 break; 432 } 433 } 434 435 Map<String, String> indoorValidator = new HashMap<>(); 436 indoorValidator.put("title", "Indoor"); 437 indoorValidator.put("active", "true"); 438 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 439 sep + "indoorhelper.validator.mapcss"); 440 441 validatorMapsNew.add(indoorValidator); 442 Main.pref.putListOfStructs 443 ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 444 validatorMapsNew); 445 446 447 448 449 //set mappaint active 450 451 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 452 if(!styleMaps.isEmpty()){ 453 styleMapsNew.addAll(styleMaps); 454 } 455 456 for(Map<String, String> map : styleMapsNew){ 457 if(map.containsValue("Indoor")){ 458 styleMapsNew.remove(map); 459 break; 460 } 461 } 462 Map<String, String> indoorMapPaint = new HashMap<>(); 463 indoorMapPaint.put("title", "Indoor"); 464 indoorMapPaint.put("active", "true"); 465 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 466 + sep + "indoor.mapcss"); 467 styleMapsNew.add(indoorMapPaint); 468 Main.pref.putListOfStructs 469 ("mappaint.style.entries", styleMapsNew); 470 471 updateSettings(); 472 }else{ 473 //set the validator inactive 474 475 476 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 477 if(!validatorMaps.isEmpty()){ 478 validatorMapsNew.addAll(validatorMaps); 479 } 480 481 for(Map<String, String> map : validatorMapsNew){ 482 if(map.containsValue("Indoor")){ 483 validatorMapsNew.remove(map); 484 break; 485 } 486 } 487 Map<String, String> indoorValidator = new HashMap<>(); 488 indoorValidator.put("title", "Indoor"); 489 indoorValidator.put("active", "false"); 490 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 491 sep + "indoorhelper.validator.mapcss"); 492 493 validatorMapsNew.add(indoorValidator); 494 Main.pref.putListOfStructs 495 ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 496 validatorMapsNew); 497 498 499 //set mappaint inactive 500 501 502 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 503 if(!styleMaps.isEmpty()){ 504 styleMapsNew.addAll(styleMaps); 505 } 506 for(Map<String, String> map : styleMapsNew){ 507 if(map.containsValue("Indoor")){ 508 styleMapsNew.remove(map); 509 break; 510 } 511 } 512 Map<String, String> indoorMapPaint = new HashMap<>(); 513 indoorMapPaint.put("title", "Indoor"); 514 indoorMapPaint.put("active", "false"); 515 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 516 + sep + "indoor.mapcss"); 517 styleMapsNew.add(indoorMapPaint); 518 Main.pref.putListOfStructs 519 ("mappaint.style.entries", styleMapsNew); 520 521 updateSettings(); 522 } 523 } 524 525 /** 526 * Forces JOSM to load the validator and mappaint settings. 527 */ 528 private void updateSettings(){ 529 Main.pref.init(false); 530 MapCSSTagChecker tagChecker = OsmValidator.getTest(MapCSSTagChecker.class); 60 private IndoorHelperModel model; 61 private ToolBoxView toolboxView; 62 private FittingView fittingView; 63 private LevelSelectorView selectorView; 64 private String sep = System.getProperty("file.separator"); 65 66 67 private int lastLevelIndex; 68 69 /** 70 * Constructor for the {@link IndoorHelperController} which initiates model and views. 71 * 72 */ 73 public IndoorHelperController() { 74 this.model = new IndoorHelperModel(); 75 this.toolboxView = new ToolBoxView(); 76 77 this.lastLevelIndex = 0; 78 79 addToolboxListeners(); 80 Main.map.addToggleDialog(toolboxView); 81 } 82 83 /** 84 * Adds the button- and box-listeners to the {@link ToolBoxView}. 85 */ 86 private void addToolboxListeners() { 87 88 if (this.toolboxView != null) { 89 this.toolboxView.setPowerButtonListener(new ToolPowerButtonListener()); 90 this.toolboxView.setApplyButtonListener(new ToolApplyButtonListener()); 91 this.toolboxView.setLevelItemListener(new ToolLevelItemListener()); 92 this.toolboxView.setObjectItemListener(new ToolObjectItemListener()); 93 this.toolboxView.setPreset1Listener(new Preset1Listener()); 94 this.toolboxView.setPreset2Listener(new Preset2Listener()); 95 this.toolboxView.setPreset3Listener(new Preset3Listener()); 96 this.toolboxView.setPreset4Listener(new Preset4Listener()); 97 } 98 } 99 100 /** 101 * Adds the button-listeners to the {@link LevelSelectorView}. 102 */ 103 private void addLevelSelectorListeners() { 104 if (this.selectorView != null) { 105 this.selectorView.setOkButtonListener(new LevelOkButtonListener()); 106 this.selectorView.setCancelButtonListener(new LevelCancelButtonListener()); 107 } 108 } 109 110 /** 111 * Adds the button-listeners to the {@link FittingView}. 112 */ 113 private void addFittingListeners() { 114 if (this.fittingView != null) { 115 this.fittingView.setOkButtonListener(new FittingOkButtonListener()); 116 } 117 } 118 119 //******************************************************************** 120 //********************* TOOLBOX LISTENERS ************************ 121 //******************************************************************** 122 123 /** 124 * The listener which handles the power button. 125 * 126 * @author egru 127 * 128 */ 129 class ToolPowerButtonListener implements ActionListener { 130 131 @Override 132 public void actionPerformed(ActionEvent e) { 133 if (toolboxView.getPowerButtonState()) { 134 selectorView = new LevelSelectorView(); 135 addLevelSelectorListeners(); 136 selectorView.setVisible(true); 137 setPluginPreferences(true); 138 } else if (!toolboxView.getPowerButtonState()) { 139 model = new IndoorHelperModel(); 140 selectorView.dispose(); 141 toolboxView.reset(); 142 setPluginPreferences(false); 143 144 // Delete the indoor filters 145 FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class); 146 147 if (filterDialog != null) { 148 FilterTableModel filterTableModel = filterDialog.getFilterModel(); 149 150 for (int i = filterTableModel.getRowCount()-1; i > -1; i--) { 151 if (filterTableModel.getFilter(i).text.startsWith("\"indoor:level\"=\"")) { 152 filterTableModel.removeFilter(i); 153 } 154 } 155 } 156 } 157 } 158 } 159 160 /** 161 * The listener which provides the handling of the apply button. 162 * Gets the texts which were written by the user and writes them to the OSM-data. 163 * After that it checks the tagged data with the built-in validator file. 164 * 165 * @author egru 166 */ 167 class ToolApplyButtonListener implements ActionListener { 168 169 @Override 170 public void actionPerformed(ActionEvent e) { 171 IndoorObject indoorObject = toolboxView.getSelectedObject(); 172 if (toolboxView.getNameText().isEmpty() && toolboxView.getRefText().isEmpty() && toolboxView.getLevelName().isEmpty()) { 173 model.addTagsToOSM(indoorObject); 174 } else { 175 List<Tag> tags = new ArrayList<>(); 176 if (!toolboxView.getLevelName().isEmpty()) { 177 model.getLevelList().get(toolboxView.getSelectedLevelIndex()).setNameTag(toolboxView.getLevelName()); 178 } 179 if (!toolboxView.getNameText().isEmpty()) { 180 tags.add(new Tag("name", toolboxView.getNameText())); 181 } 182 if (!toolboxView.getRefText().isEmpty()) { 183 tags.add(new Tag("ref", toolboxView.getRefText())); 184 } 185 model.addTagsToOSM(indoorObject, tags); 186 } 187 //Do the validation process 188 ValidateAction validateAction = new ValidateAction(); 189 validateAction.doValidate(true); 190 191 refreshPresets(); 192 } 193 } 194 195 /** 196 * <pre>The listener which is called when a new item in the level list is selected. 197 *It also sets the name-tag for a level, if the user has done an input in the textbox. 198 * </pre> 199 * @author egru 200 * 201 */ 202 class ToolLevelItemListener implements ItemListener { 203 204 @Override 205 public void itemStateChanged(ItemEvent e) { 206 if (!toolboxView.levelListIsEmpty()) { 207 208 if (!toolboxView.getLevelName().isEmpty()) { 209 model.getLevelList().get(lastLevelIndex).setNameTag(toolboxView.getLevelName()); 210 } 211 212 if (!model.getLevelList().get(toolboxView.getSelectedLevelIndex()).hasEmptyName()) { 213 toolboxView.setLevelName(model.getLevelList().get(toolboxView.getSelectedLevelIndex()).getName()); 214 } else { 215 toolboxView.setLevelName(""); 216 } 217 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); 218 219 lastLevelIndex = toolboxView.getSelectedLevelIndex(); 220 } 221 } 222 } 223 224 225 226 /** 227 * The listener which is called when a new item in the object list is selected. 228 * 229 * @author egru 230 * 231 */ 232 class ToolObjectItemListener implements ItemListener { 233 234 @Override 235 public void itemStateChanged(ItemEvent e) { 236 if (toolboxView.getSelectedObject().equals(IndoorObject.ROOM)) { 237 toolboxView.setTagUiElementsEnabled(true); 238 } else { 239 toolboxView.setTagUiElementsEnabled(false); 240 } 241 } 242 } 243 244 /** 245 * Listener for preset button 1. 246 * @author egru 247 * 248 */ 249 class Preset1Listener implements ActionListener { 250 251 @Override 252 public void actionPerformed(ActionEvent e) { 253 model.addTagsToOSM(toolboxView.getPreset1()); 254 255 } 256 } 257 258 /** 259 * Listener for preset button 2. 260 * @author egru 261 * 262 */ 263 class Preset2Listener implements ActionListener { 264 265 @Override 266 public void actionPerformed(ActionEvent e) { 267 model.addTagsToOSM(toolboxView.getPreset2()); 268 269 } 270 271 } 272 273 /** 274 * Listener for preset button 3. 275 * @author egru 276 * 277 */ 278 class Preset3Listener implements ActionListener { 279 280 @Override 281 public void actionPerformed(ActionEvent e) { 282 model.addTagsToOSM(toolboxView.getPreset3()); 283 284 } 285 286 } 287 288 /** 289 * Listener for preset button 4. 290 * @author egru 291 * 292 */ 293 class Preset4Listener implements ActionListener { 294 295 @Override 296 public void actionPerformed(ActionEvent e) { 297 model.addTagsToOSM(toolboxView.getPreset4()); 298 299 } 300 301 } 302 303 /** 304 * Updates the preset button from the current ranking. 305 */ 306 private void refreshPresets() { 307 toolboxView.setPresetButtons(model.getPresetRanking()); 308 } 309 310 311 //******************* 312 // SELECTOR LISTENERS 313 //******************* 314 315 /** 316 * <pre> 317 * The listener which handles the click on the OK-button of the {@link LevelSelectorView}. 318 * It sends the data of the view to the model and displays an error message, 319 * if the level-list couldn't be created. 320 * </pre> 321 * @author egru 322 * 323 */ 324 class LevelOkButtonListener implements ActionListener { 325 326 @Override 327 public void actionPerformed(ActionEvent e) { 328 boolean levelSuccess = model.setBuildingLevels(selectorView.getMin(), selectorView.getMax()); 329 330 if (levelSuccess) { 331 toolboxView.setLevelList(model.getLevelList()); //set the levels to the ComboBox and 332 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); //sets the working level in the model 333 334 selectorView.dispose(); 335 336 fittingView = new FittingView(); 337 addFittingListeners(); 338 fittingView.setVisible(true); 339 } else { 340 341 JOptionPane.showMessageDialog(null, "Lowest Level has to be lower than the highest level", 342 "Error", JOptionPane.ERROR_MESSAGE); 343 } 344 } 345 } 346 347 /** 348 * Closes the level selection view if the user hits the cancel button. 349 * 350 * @author egru 351 * 352 */ 353 class LevelCancelButtonListener implements ActionListener { 354 355 @Override 356 public void actionPerformed(ActionEvent e) { 357 selectorView.dispose(); 358 toolboxView.setPowerButtonDisabled(); 359 setPluginPreferences(false); 360 } 361 362 } 363 364 365 366 //******************* 367 // FITTING LISTENERS 368 //******************* 369 /** 370 * Closes the {@link FittingView} if the OK-Button is clicked. 371 * Enables the UI elements of the toolbox 372 * 373 * @author egru 374 * 375 */ 376 class FittingOkButtonListener implements ActionListener { 377 378 @Override 379 public void actionPerformed(ActionEvent e) { 380 fittingView.dispose(); 381 toolboxView.setAllUiElementsEnabled(true); 382 toolboxView.setTagUiElementsEnabled(false); 383 } 384 385 } 386 387 /* 388 HELPER METHODS 389 */ 390 391 /** 392 * Enables or disables the preferences for the mapcss-style and the validator. 393 * 394 * @param enabled Activates or disables the settings. 395 */ 396 private void setPluginPreferences(boolean enabled) { 397 Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 398 399 MapListSetting validatorMapListSetting = (MapListSetting) settings. 400 get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 401 List<Map<String, String>> validatorMaps = new ArrayList<>(); 402 if (validatorMapListSetting != null) { 403 validatorMaps = validatorMapListSetting.getValue(); 404 } 405 406 MapListSetting styleMapListSetting = (MapListSetting) settings. 407 get("mappaint.style.entries"); 408 List<Map<String, String>> styleMaps = new ArrayList<>(); 409 if (styleMapListSetting != null) { 410 styleMaps = styleMapListSetting.getValue(); 411 } 412 413 if (enabled) { 414 //set the validator active 415 416 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 417 if (!validatorMaps.isEmpty()) { 418 validatorMapsNew.addAll(validatorMaps); 419 } 420 421 for (Map<String, String> map : validatorMapsNew) { 422 if (map.containsValue("Indoor")) { 423 validatorMapsNew.remove(map); 424 break; 425 } 426 } 427 428 Map<String, String> indoorValidator = new HashMap<>(); 429 indoorValidator.put("title", "Indoor"); 430 indoorValidator.put("active", "true"); 431 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 432 sep + "indoorhelper.validator.mapcss"); 433 434 validatorMapsNew.add(indoorValidator); 435 Main.pref.putListOfStructs("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 436 validatorMapsNew); 437 438 //set mappaint active 439 440 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 441 if (!styleMaps.isEmpty()) { 442 styleMapsNew.addAll(styleMaps); 443 } 444 445 for (Map<String, String> map : styleMapsNew) { 446 if (map.containsValue("Indoor")) { 447 styleMapsNew.remove(map); 448 break; 449 } 450 } 451 Map<String, String> indoorMapPaint = new HashMap<>(); 452 indoorMapPaint.put("title", "Indoor"); 453 indoorMapPaint.put("active", "true"); 454 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 455 + sep + "indoor.mapcss"); 456 styleMapsNew.add(indoorMapPaint); 457 Main.pref.putListOfStructs("mappaint.style.entries", styleMapsNew); 458 459 updateSettings(); 460 } else { 461 //set the validator inactive 462 463 464 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 465 if (!validatorMaps.isEmpty()) { 466 validatorMapsNew.addAll(validatorMaps); 467 } 468 469 for (Map<String, String> map : validatorMapsNew) { 470 if (map.containsValue("Indoor")) { 471 validatorMapsNew.remove(map); 472 break; 473 } 474 } 475 Map<String, String> indoorValidator = new HashMap<>(); 476 indoorValidator.put("title", "Indoor"); 477 indoorValidator.put("active", "false"); 478 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 479 sep + "indoorhelper.validator.mapcss"); 480 481 validatorMapsNew.add(indoorValidator); 482 Main.pref.putListOfStructs("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 483 validatorMapsNew); 484 485 486 //set mappaint inactive 487 488 489 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 490 if (!styleMaps.isEmpty()) { 491 styleMapsNew.addAll(styleMaps); 492 } 493 for (Map<String, String> map : styleMapsNew) { 494 if (map.containsValue("Indoor")) { 495 styleMapsNew.remove(map); 496 break; 497 } 498 } 499 Map<String, String> indoorMapPaint = new HashMap<>(); 500 indoorMapPaint.put("title", "Indoor"); 501 indoorMapPaint.put("active", "false"); 502 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 503 + sep + "indoor.mapcss"); 504 styleMapsNew.add(indoorMapPaint); 505 Main.pref.putListOfStructs("mappaint.style.entries", styleMapsNew); 506 507 updateSettings(); 508 } 509 } 510 511 /** 512 * Forces JOSM to load the validator and mappaint settings. 513 */ 514 private void updateSettings() { 515 Main.pref.init(false); 516 MapCSSTagChecker tagChecker = OsmValidator.getTest(MapCSSTagChecker.class); 531 517 if (tagChecker != null) { 532 518 OsmValidator.initializeTests(Collections.singleton(tagChecker)); 533 519 } 534 520 535 521 MapPaintStyles.readFromPreferences(); 536 522 } 537 523 } 538 524 -
applications/editors/josm/plugins/indoorhelper/src/model/IndoorHelperModel.java
r32468 r32637 21 21 import java.util.ArrayList; 22 22 import java.util.List; 23 23 24 import javax.swing.JOptionPane; 24 25 … … 36 37 * Class for the data model which includes indoor data and 37 38 * the functions to handle the plug-in 38 * 39 * 39 40 * @author egru 40 41 */ 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 /** 42 public 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 /** 287 253 * 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 } 318 316 } -
applications/editors/josm/plugins/indoorhelper/src/model/IndoorLevel.java
r32122 r32637 22 22 23 23 /** 24 * 24 * 25 25 * The class to save a level of the building. 26 * 26 * 27 27 * @author egru 28 28 * … … 30 30 31 31 public 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 } 118 117 } -
applications/editors/josm/plugins/indoorhelper/src/model/PresetCounter.java
r32122 r32637 33 33 */ 34 34 public class PresetCounter { 35 36 37 38 39 40 41 42 43 public PresetCounter(){44 45 46 47 private void init(){48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 public void count(IndoorObject object){68 69 70 71 while(iterator.hasNext()){72 73 if(counterTemp.getObject().equals(object)){74 counterList.get(iterator.nextIndex()-1).increment(); 75 76 77 78 79 80 81 82 private void sort(){83 84 85 86 87 public List<IndoorObject> getRanking(){88 89 90 91 92 93 94 95 96 97 98 private class ObjectCounter implements Comparable<ObjectCounter>{99 100 101 102 publicObjectCounter(IndoorObject o, int c) {103 104 105 106 107 public int getCount(){108 109 110 111 public IndoorObject getObject(){112 113 114 115 public void increment(){116 117 118 119 120 121 if(this.getCount()<o.getCount()){122 123 124 if(this.getCount()==o.getCount()){125 126 127 if(this.getCount()>o.getCount()){128 129 130 131 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 136 136 } -
applications/editors/josm/plugins/indoorhelper/src/model/TagCatalog.java
r32122 r32637 32 32 33 33 public final class TagCatalog { 34 35 36 37 38 39 40 */ 41 public List<Tag> getTags(IndoorObject o){42 43 44 45 switch(o){46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 public enum IndoorObject{98 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 } 100 100 101 101 } -
applications/editors/josm/plugins/indoorhelper/src/org/openstreetmap/josm/plugins/indoorhelper/IndoorHelperPlugin.java
r32122 r32637 37 37 * 38 38 */ 39 public class IndoorHelperPlugin extends Plugin {39 public class IndoorHelperPlugin extends Plugin { 40 40 41 41 42 43 44 42 @SuppressWarnings("unused") 43 private IndoorHelperController controller; 44 String sep = System.getProperty("file.separator"); 45 45 46 /** 47 * Constructor for the plug-in. 48 * 49 * Exports the needed files and adds them to the settings. 50 * 51 * @param info general information about the plug-in 52 * @throws Exception 53 */ 54 public IndoorHelperPlugin(PluginInformation info) throws Exception { 55 super(info); 46 /** 47 * Constructor for the plug-in. 48 * 49 * Exports the needed files and adds them to the settings. 50 * 51 * @param info general information about the plug-in 52 */ 53 public IndoorHelperPlugin(PluginInformation info) throws Exception { 54 super(info); 56 55 57 this.exportValidator("/data/indoorhelper.validator.mapcss"); 58 this.exportStyleFile("indoor.mapcss"); 59 this.exportStyleFile("entrance_door_icon.png"); 60 this.exportStyleFile("entrance_icon.png"); 61 // this.setIndoorValidator(); 62 63 } 56 this.exportValidator("/data/indoorhelper.validator.mapcss"); 57 this.exportStyleFile("indoor.mapcss"); 58 this.exportStyleFile("entrance_door_icon.png"); 59 this.exportStyleFile("entrance_icon.png"); 60 // this.setIndoorValidator(); 61 } 62 63 /** 64 * Secures that the plug-in is only loaded, if a new MapFrame is created. 65 */ 66 @Override 67 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 68 super.mapFrameInitialized(oldFrame, newFrame); 69 70 if (oldFrame == null && newFrame != null) { 71 controller = new IndoorHelperController(); 72 } 73 } 74 75 /** 76 * Exports the mapcss validator file to the preferences directory. 77 */ 78 private void exportValidator(String resourceName) throws Exception { 79 InputStream stream = null; 80 OutputStream resStreamOut = null; 64 81 65 82 66 /** 67 * Secures that the plug-in is only loaded, if a new MapFrame is created. 68 */ 69 @Override 70 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 71 super.mapFrameInitialized(oldFrame, newFrame); 83 try { 84 stream = IndoorHelperPlugin.class.getResourceAsStream(resourceName); 85 if (stream == null) { 86 System.out.println("Validator: stream is null"); 87 throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); 88 } 72 89 73 if( oldFrame == null && newFrame != null ) { 74 controller = new IndoorHelperController();75 } 90 String outPath; 91 int readBytes; 92 byte[] buffer = new byte[4096]; 76 93 77 } 94 String valDirPath = Main.pref.getUserDataDirectory() + sep + "validator"; 95 File valDir = new File(valDirPath); 96 valDir.mkdirs(); 97 outPath = valDir.getAbsolutePath() +sep+ "indoorhelper.validator.mapcss"; 98 System.out.println("Validator:"+outPath); 78 99 79 80 /** 81 * Exports the mapcss validator file to the preferences directory. 82 * 83 * @param resourceName 84 * @throws Exception 85 */ 86 private void exportValidator(String resourceName) throws Exception { 87 InputStream stream = null; 88 OutputStream resStreamOut = null; 100 resStreamOut = new FileOutputStream(outPath); 101 while ((readBytes = stream.read(buffer)) > 0) { 102 resStreamOut.write(buffer, 0, readBytes); 103 } 104 resStreamOut.close(); 105 } catch (Exception ex) { 106 throw ex; 107 } finally { 108 stream.close(); 109 } 110 } 89 111 112 /** 113 * Exports the mapCSS file to the preferences directory. 114 */ 115 private void exportStyleFile(String resourceName) throws Exception { 116 InputStream stream = null; 117 OutputStream resStreamOut = null; 90 118 91 92 stream = IndoorHelperPlugin.class.getResourceAsStream(resourceName);93 if(stream == null) {94 System.out.println("Validator: stream is null");95 96 119 try { 120 stream = IndoorHelperPlugin.class.getResourceAsStream("/data/" + resourceName); 121 if (stream == null) { 122 System.out.println("MapPaint: stream is null"); 123 throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); 124 } 97 125 98 99 100 126 String outPath; 127 int readBytes; 128 byte[] buffer = new byte[4096]; 101 129 102 String valDirPath = Main.pref.getUserDataDirectory() + sep + "validator";103 104 105 outPath = valDir.getAbsolutePath() +sep+ "indoorhelper.validator.mapcss";106 System.out.println("Validator:"+outPath);130 String valDirPath = Main.pref.getUserDataDirectory() + sep + "styles"; 131 File valDir = new File(valDirPath); 132 valDir.mkdirs(); 133 outPath = valDir.getAbsolutePath() +sep+ resourceName; 134 System.out.println("MapPaint"+outPath); 107 135 108 resStreamOut = new FileOutputStream(outPath); 109 while ((readBytes = stream.read(buffer)) > 0) { 110 resStreamOut.write(buffer, 0, readBytes); 111 } 112 resStreamOut.close(); 113 } catch (Exception ex) { 114 throw ex; 115 } finally { 116 stream.close(); 117 } 118 } 119 120 /** 121 * Exports the mapCSS file to the preferences directory. 122 * 123 * @param resourceName 124 * @throws Exception 125 */ 126 private void exportStyleFile(String resourceName) throws Exception { 127 InputStream stream = null; 128 OutputStream resStreamOut = null; 129 130 131 try { 132 stream = IndoorHelperPlugin.class.getResourceAsStream("/data/" + resourceName); 133 if(stream == null) { 134 System.out.println("MapPaint: stream is null"); 135 throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); 136 } 137 138 String outPath; 139 int readBytes; 140 byte[] buffer = new byte[4096]; 141 142 String valDirPath = Main.pref.getUserDataDirectory() + sep + "styles"; 143 File valDir = new File(valDirPath); 144 valDir.mkdirs(); 145 outPath = valDir.getAbsolutePath() +sep+ resourceName; 146 System.out.println("MapPaint"+outPath); 147 148 resStreamOut = new FileOutputStream(outPath); 149 while ((readBytes = stream.read(buffer)) > 0) { 150 resStreamOut.write(buffer, 0, readBytes); 151 } 152 resStreamOut.close(); 153 } catch (Exception ex) { 154 throw ex; 155 } finally { 156 stream.close(); 157 } 158 } 159 160 /** 161 * Writes the indoor validator file in the user preferences if it isn't there 162 * and activates it. 163 */ 164 // private void setIndoorValidator(){ 165 // //get the current validator settings 166 // Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 167 // MapListSetting mapListSetting = (MapListSetting) settings. 168 // get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 169 // List<Map<String, String>> validatorMaps; 170 // if(mapListSetting!=null){ 171 // validatorMaps = mapListSetting.getValue(); 172 // } else{ 173 // validatorMaps = new ArrayList<>(); 174 // } 175 // boolean validatorExists = false; 136 resStreamOut = new FileOutputStream(outPath); 137 while ((readBytes = stream.read(buffer)) > 0) { 138 resStreamOut.write(buffer, 0, readBytes); 139 } 140 resStreamOut.close(); 141 } catch (Exception ex) { 142 throw ex; 143 } finally { 144 stream.close(); 145 } 146 } 147 148 /** 149 * Writes the indoor validator file in the user preferences if it isn't there 150 * and activates it. 151 */ 152 // private void setIndoorValidator() { 153 // //get the current validator settings 154 // Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 155 // MapListSetting mapListSetting = (MapListSetting) settings. 156 // get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 157 // List<Map<String, String>> validatorMaps; 158 // if (mapListSetting != null) { 159 // validatorMaps = mapListSetting.getValue(); 160 // } else { 161 // validatorMaps = new ArrayList<>(); 162 // } 163 // boolean validatorExists = false; 176 164 // 177 // 178 // for(Map<String, String> map : validatorMaps){179 // if(map.containsValue("Indoor")){180 // 181 // 182 // 165 // //check if indoor validator is already set 166 // for (Map<String, String> map : validatorMaps) { 167 // if (map.containsValue("Indoor")) { 168 // validatorExists = true; 169 // } 170 // } 183 171 // 184 // 185 // if(!validatorExists){186 // 187 // if(!validatorMaps.isEmpty()){188 // 189 // 190 // 191 // 192 // 193 // 194 // 172 // //put it in the settings if not 173 // if (!validatorExists) { 174 // List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 175 // if (!validatorMaps.isEmpty()) { 176 // validatorMapsNew.addAll(validatorMaps); 177 // } 178 // Map<String, String> indoorValidator = new HashMap<>(); 179 // indoorValidator.put("title", "Indoor"); 180 // indoorValidator.put("active", "true"); 181 // indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 182 // sep + "indoorhelper.validator.mapcss"); 195 183 // 196 // validatorMapsNew.add(indoorValidator); 197 // Main.pref.putListOfStructs 198 // ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 199 // validatorMapsNew); 200 // } 201 // } 202 203 184 // validatorMapsNew.add(indoorValidator); 185 // Main.pref.putListOfStructs 186 // ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 187 // validatorMapsNew); 188 // } 189 // } 204 190 } -
applications/editors/josm/plugins/indoorhelper/src/views/DialogPanel.java
r32122 r32637 44 44 @SuppressWarnings("serial") 45 45 public class DialogPanel extends JPanel { 46 private JPanel contentPanel; 47 private JToggleButton powerButton; 48 private JLabel levelLabel; 49 private JosmComboBox<String> levelBox; 50 private JLabel levelTagLabel; 51 private DisableShortcutsOnFocusGainedTextField levelTagField; 52 private JLabel objectLabel; 53 private JosmComboBox<TagCatalog.IndoorObject> objectBox; 54 private JLabel nameLabel; 55 private DisableShortcutsOnFocusGainedTextField nameField; 56 private JLabel refLabel; 57 private DisableShortcutsOnFocusGainedTextField refField; 58 private JPanel buttonBar; 59 private JButton applyButton; 60 private JSeparator separator1; 61 private JSeparator separator2; 62 63 /** 64 * Create the panel. 65 */ 66 public DialogPanel() { 67 contentPanel = new JPanel(); 68 powerButton = new JToggleButton(); 69 levelLabel = new JLabel(); 70 levelBox = new JosmComboBox<String>(); 71 levelTagLabel = new JLabel(); 72 levelTagField = new DisableShortcutsOnFocusGainedTextField(); 73 objectLabel = new JLabel(); 74 objectBox = new JosmComboBox<>(); 75 objectBox.setModel(new DefaultComboBoxModel<>(TagCatalog.IndoorObject.values())); 76 nameLabel = new JLabel(); 77 nameField = new DisableShortcutsOnFocusGainedTextField(); 78 refLabel = new JLabel(); 79 refField = new DisableShortcutsOnFocusGainedTextField(); 80 buttonBar = new JPanel(); 81 applyButton = new JButton(); 82 separator1 = new JSeparator(); 83 separator2 = new JSeparator(); 84 85 //======== this ======== 86 //Container contentPane = this.get; 87 //contentPane.setLayout(new BorderLayout()); 88 89 //======== dialogPane ======== 90 { 91 this.setBorder(new EmptyBorder(12, 12, 12, 12)); 92 this.setLayout(new BorderLayout()); 93 94 //======== contentPanel ======== 95 { 96 contentPanel.setLayout(new GridBagLayout()); 97 ((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 98 ((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0}; 99 ((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 100 ((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 101 102 //---- powerButton ---- 103 powerButton.setText(tr("POWER")); 104 powerButton.setToolTipText(tr("Activates the plug-in")); 105 contentPanel.add(powerButton, new GridBagConstraints(8, 0, 4, 1, 0.0, 0.0, 106 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 107 new Insets(0, 0, 5, 5), 0, 0)); 108 contentPanel.add(separator1, new GridBagConstraints(1, 1, 12, 1, 0.0, 0.0, 109 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 110 new Insets(0, 0, 5, 5), 0, 0)); 111 112 //---- levelLabel ---- 113 levelLabel.setText(tr("Working Level")); 114 contentPanel.add(levelLabel, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, 115 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 116 new Insets(0, 0, 5, 5), 0, 0)); 117 118 //---- levelBox ---- 119 levelBox.setEnabled(false); 120 levelBox.setEditable(false); 121 levelBox.setToolTipText(tr("Selects the working level.")); 122 contentPanel.add(levelBox, new GridBagConstraints(3, 2, 3, 1, 0.0, 0.0, 123 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 124 new Insets(0, 0, 5, 5), 0, 0)); 125 126 //---- levelTagLabel ---- 127 levelTagLabel.setText(tr("Level Name")); 128 contentPanel.add(levelTagLabel, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, 129 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 130 new Insets(0, 0, 5, 5), 0, 0)); 131 132 //---- levelTagField ---- 133 levelTagField.setEnabled(false); 134 levelTagField.setColumns(6); 135 levelTagField.setToolTipText(tr("Optional name-tag for a level.")); 136 contentPanel.add(levelTagField, new GridBagConstraints(8, 2, 5, 1, 0.0, 0.0, 137 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 138 new Insets(0, 0, 5, 5), 0, 0)); 139 contentPanel.add(separator2, new GridBagConstraints(1, 3, 12, 1, 0.0, 0.0, 140 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 141 new Insets(0, 0, 5, 5), 0, 0)); 142 143 //---- objectLabel ---- 144 objectLabel.setText(tr("Object")); 145 contentPanel.add(objectLabel, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 146 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 147 new Insets(0, 0, 5, 5), 0, 0)); 148 149 //---- objectBox ---- 150 objectBox.setEnabled(false); 151 objectBox.setPrototypeDisplayValue(IndoorObject.CONCRETE_WALL); 152 objectBox.setToolTipText(tr("The object preset you want to tag.")); 153 contentPanel.add(objectBox, new GridBagConstraints(3, 4, 3, 1, 0.0, 0.0, 154 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 155 new Insets(0, 0, 5, 5), 0, 0)); 156 157 //---- nameLabel ---- 158 nameLabel.setText(tr("Name")); 159 contentPanel.add(nameLabel, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 160 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 161 new Insets(0, 0, 5, 5), 0, 0)); 162 163 //---- nameField ---- 164 nameField.setEnabled(false); 165 nameField.addFocusListener(new FocusListener() { 166 167 @Override 168 public void focusLost(FocusEvent e) {} 169 170 @Override 171 public void focusGained(FocusEvent e) { 172 nameField.selectAll(); 173 } 174 }); 175 nameField.setToolTipText(tr("Sets the name tag when the room-object is selected.")); 176 contentPanel.add(nameField, new GridBagConstraints(3, 5, 3, 1, 0.0, 0.0, 177 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 178 new Insets(0, 0, 5, 5), 0, 0)); 179 180 //---- refLabel ---- 181 refLabel.setText(tr("Reference")); 182 contentPanel.add(refLabel, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0, 183 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 184 new Insets(0, 0, 0, 5), 0, 0)); 185 186 //---- refField ---- 187 refField.setEnabled(false); 188 refField.addFocusListener(new FocusListener() { 189 190 @Override 191 public void focusLost(FocusEvent e) {} 192 193 @Override 194 public void focusGained(FocusEvent e) { 195 refField.selectAll(); 196 } 197 }); 198 refField.setToolTipText(tr("Sets the ref tag when the room-object is selected.")); 199 contentPanel.add(refField, new GridBagConstraints(3, 6, 3, 1, 0.0, 0.0, 200 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 201 new Insets(0, 0, 0, 5), 0, 0)); 202 } 203 this.add(contentPanel, BorderLayout.CENTER); 204 205 //======== buttonBar ======== 206 { 207 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 208 buttonBar.setLayout(new GridBagLayout()); 209 ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80}; 210 ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0}; 211 212 //---- applyButton ---- 213 applyButton.setText(tr("Apply Tags")); 214 applyButton.setEnabled(false); 215 buttonBar.add(applyButton, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, 216 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 217 new Insets(0, 0, 0, 0), 0, 0)); 218 } 219 this.add(buttonBar, BorderLayout.SOUTH); 220 } 221 } 46 private JPanel contentPanel; 47 private JToggleButton powerButton; 48 private JLabel levelLabel; 49 private JosmComboBox<String> levelBox; 50 private JLabel levelTagLabel; 51 private DisableShortcutsOnFocusGainedTextField levelTagField; 52 private JLabel objectLabel; 53 private JosmComboBox<TagCatalog.IndoorObject> objectBox; 54 private JLabel nameLabel; 55 private DisableShortcutsOnFocusGainedTextField nameField; 56 private JLabel refLabel; 57 private DisableShortcutsOnFocusGainedTextField refField; 58 private JPanel buttonBar; 59 private JButton applyButton; 60 private JSeparator separator1; 61 private JSeparator separator2; 62 63 /** 64 * Create the panel. 65 */ 66 public DialogPanel() { 67 contentPanel = new JPanel(); 68 powerButton = new JToggleButton(); 69 levelLabel = new JLabel(); 70 levelBox = new JosmComboBox<String>(); 71 levelTagLabel = new JLabel(); 72 levelTagField = new DisableShortcutsOnFocusGainedTextField(); 73 objectLabel = new JLabel(); 74 objectBox = new JosmComboBox<>(); 75 objectBox.setModel(new DefaultComboBoxModel<>(TagCatalog.IndoorObject.values())); 76 nameLabel = new JLabel(); 77 nameField = new DisableShortcutsOnFocusGainedTextField(); 78 refLabel = new JLabel(); 79 refField = new DisableShortcutsOnFocusGainedTextField(); 80 buttonBar = new JPanel(); 81 applyButton = new JButton(); 82 separator1 = new JSeparator(); 83 separator2 = new JSeparator(); 84 85 //======== this ======== 86 //Container contentPane = this.get; 87 //contentPane.setLayout(new BorderLayout()); 88 89 //======== dialogPane ======== 90 { 91 this.setBorder(new EmptyBorder(12, 12, 12, 12)); 92 this.setLayout(new BorderLayout()); 93 94 //======== contentPanel ======== 95 { 96 contentPanel.setLayout(new GridBagLayout()); 97 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] { 98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 99 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0}; 100 ((GridBagLayout) contentPanel.getLayout()).columnWeights = new double[] { 101 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 102 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 103 104 //---- powerButton ---- 105 powerButton.setText(tr("POWER")); 106 powerButton.setToolTipText(tr("Activates the plug-in")); 107 contentPanel.add(powerButton, new GridBagConstraints(8, 0, 4, 1, 0.0, 0.0, 108 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 109 new Insets(0, 0, 5, 5), 0, 0)); 110 contentPanel.add(separator1, new GridBagConstraints(1, 1, 12, 1, 0.0, 0.0, 111 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 112 new Insets(0, 0, 5, 5), 0, 0)); 113 114 //---- levelLabel ---- 115 levelLabel.setText(tr("Working Level")); 116 contentPanel.add(levelLabel, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, 117 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 118 new Insets(0, 0, 5, 5), 0, 0)); 119 120 //---- levelBox ---- 121 levelBox.setEnabled(false); 122 levelBox.setEditable(false); 123 levelBox.setToolTipText(tr("Selects the working level.")); 124 contentPanel.add(levelBox, new GridBagConstraints(3, 2, 3, 1, 0.0, 0.0, 125 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 126 new Insets(0, 0, 5, 5), 0, 0)); 127 128 //---- levelTagLabel ---- 129 levelTagLabel.setText(tr("Level Name")); 130 contentPanel.add(levelTagLabel, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, 131 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 132 new Insets(0, 0, 5, 5), 0, 0)); 133 134 //---- levelTagField ---- 135 levelTagField.setEnabled(false); 136 levelTagField.setColumns(6); 137 levelTagField.setToolTipText(tr("Optional name-tag for a level.")); 138 contentPanel.add(levelTagField, new GridBagConstraints(8, 2, 5, 1, 0.0, 0.0, 139 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 140 new Insets(0, 0, 5, 5), 0, 0)); 141 contentPanel.add(separator2, new GridBagConstraints(1, 3, 12, 1, 0.0, 0.0, 142 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 143 new Insets(0, 0, 5, 5), 0, 0)); 144 145 //---- objectLabel ---- 146 objectLabel.setText(tr("Object")); 147 contentPanel.add(objectLabel, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 148 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 149 new Insets(0, 0, 5, 5), 0, 0)); 150 151 //---- objectBox ---- 152 objectBox.setEnabled(false); 153 objectBox.setPrototypeDisplayValue(IndoorObject.CONCRETE_WALL); 154 objectBox.setToolTipText(tr("The object preset you want to tag.")); 155 contentPanel.add(objectBox, new GridBagConstraints(3, 4, 3, 1, 0.0, 0.0, 156 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 157 new Insets(0, 0, 5, 5), 0, 0)); 158 159 //---- nameLabel ---- 160 nameLabel.setText(tr("Name")); 161 contentPanel.add(nameLabel, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 162 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 163 new Insets(0, 0, 5, 5), 0, 0)); 164 165 //---- nameField ---- 166 nameField.setEnabled(false); 167 nameField.addFocusListener(new FocusListener() { 168 169 @Override 170 public void focusLost(FocusEvent e) {} 171 172 @Override 173 public void focusGained(FocusEvent e) { 174 nameField.selectAll(); 175 } 176 }); 177 nameField.setToolTipText(tr("Sets the name tag when the room-object is selected.")); 178 contentPanel.add(nameField, new GridBagConstraints(3, 5, 3, 1, 0.0, 0.0, 179 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 180 new Insets(0, 0, 5, 5), 0, 0)); 181 182 //---- refLabel ---- 183 refLabel.setText(tr("Reference")); 184 contentPanel.add(refLabel, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0, 185 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 186 new Insets(0, 0, 0, 5), 0, 0)); 187 188 //---- refField ---- 189 refField.setEnabled(false); 190 refField.addFocusListener(new FocusListener() { 191 192 @Override 193 public void focusLost(FocusEvent e) {} 194 195 @Override 196 public void focusGained(FocusEvent e) { 197 refField.selectAll(); 198 } 199 }); 200 refField.setToolTipText(tr("Sets the ref tag when the room-object is selected.")); 201 contentPanel.add(refField, new GridBagConstraints(3, 6, 3, 1, 0.0, 0.0, 202 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 203 new Insets(0, 0, 0, 5), 0, 0)); 204 } 205 this.add(contentPanel, BorderLayout.CENTER); 206 207 //======== buttonBar ======== 208 { 209 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 210 buttonBar.setLayout(new GridBagLayout()); 211 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 80}; 212 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0}; 213 214 //---- applyButton ---- 215 applyButton.setText(tr("Apply Tags")); 216 applyButton.setEnabled(false); 217 buttonBar.add(applyButton, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, 218 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 219 new Insets(0, 0, 0, 0), 0, 0)); 220 } 221 this.add(buttonBar, BorderLayout.SOUTH); 222 } 223 } 222 224 223 225 } -
applications/editors/josm/plugins/indoorhelper/src/views/FittingView.java
r32122 r32637 21 21 import static org.openstreetmap.josm.tools.I18n.tr; 22 22 23 import java.awt.*; 23 import java.awt.BorderLayout; 24 import java.awt.Container; 25 import java.awt.FlowLayout; 26 import java.awt.GridBagConstraints; 27 import java.awt.GridBagLayout; 28 import java.awt.Insets; 24 29 import java.awt.event.ActionListener; 25 30 26 import javax.swing.*; 27 import javax.swing.border.*; 31 import javax.swing.JButton; 32 import javax.swing.JFrame; 33 import javax.swing.JLabel; 34 import javax.swing.JPanel; 35 import javax.swing.border.EmptyBorder; 28 36 29 37 … … 31 39 * The view for the pop-up hint that tells the user, that he has to start the fitting 32 40 * of his indoor building plans. 33 * 41 * 34 42 * @author egru 35 43 */ 36 44 @SuppressWarnings("serial") 37 45 public class FittingView extends JFrame { 38 39 private JPanel dialogPane;40 private JPanel contentPanel;41 private JLabel label1;42 private JPanel buttonBar;43 private JButton okButton;44 45 public FittingView() {46 initComponents();47 }48 46 49 private void initComponents() { 50 dialogPane = new JPanel(); 51 contentPanel = new JPanel(); 52 label1 = new JLabel(); 53 buttonBar = new JPanel(); 54 okButton = new JButton(); 47 private JPanel dialogPane; 48 private JPanel contentPanel; 49 private JLabel label1; 50 private JPanel buttonBar; 51 private JButton okButton; 55 52 56 //======== this ======== 57 setTitle(tr("Fitting")); 58 Container contentPane = getContentPane(); 59 contentPane.setLayout(new BorderLayout()); 53 public FittingView() { 54 initComponents(); 55 } 60 56 61 //======== dialogPane ======== 62 { 63 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 64 dialogPane.setLayout(new BorderLayout()); 57 private void initComponents() { 58 dialogPane = new JPanel(); 59 contentPanel = new JPanel(); 60 label1 = new JLabel(); 61 buttonBar = new JPanel(); 62 okButton = new JButton(); 65 63 66 //======== contentPanel ======== 67 { 68 contentPanel.setLayout(new FlowLayout()); 64 //======== this ======== 65 setTitle(tr("Fitting")); 66 Container contentPane = getContentPane(); 67 contentPane.setLayout(new BorderLayout()); 69 68 70 //---- label1 ---- 71 label1.setText(tr("<html>Please mind to start fitting your building-plans now.<br>" + 72 "To do so, use the PicLayer plug-in, which you can install<br>" + 73 "using the JOSM plug-in management.</html>")); 74 contentPanel.add(label1); 75 } 76 dialogPane.add(contentPanel, BorderLayout.CENTER); 69 //======== dialogPane ======== 70 { 71 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 72 dialogPane.setLayout(new BorderLayout()); 77 73 78 //======== buttonBar ======== 79 { 80 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 81 buttonBar.setLayout(new GridBagLayout()); 82 ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80}; 83 ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0}; 74 //======== contentPanel ======== 75 { 76 contentPanel.setLayout(new FlowLayout()); 84 77 85 //---- okButton ---- 86 okButton.setText(tr("OK")); 87 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 88 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 89 new Insets(0, 0, 0, 0), 0, 0)); 90 } 91 dialogPane.add(buttonBar, BorderLayout.SOUTH); 92 } 93 contentPane.add(dialogPane, BorderLayout.CENTER); 94 pack(); 95 setLocationRelativeTo(getOwner()); 96 } 97 98 /** 99 * Set the given {@link ActionListener} to the OK-Button of the {@link FittingView}. 100 * 101 * @param l the listener which should be set 102 */ 103 public void setOkButtonListener(ActionListener l){ 104 this.okButton.addActionListener(l); 105 } 78 //---- label1 ---- 79 label1.setText(tr("<html>Please mind to start fitting your building-plans now.<br>" + 80 "To do so, use the PicLayer plug-in, which you can install<br>" + 81 "using the JOSM plug-in management.</html>")); 82 contentPanel.add(label1); 83 } 84 dialogPane.add(contentPanel, BorderLayout.CENTER); 85 86 //======== buttonBar ======== 87 { 88 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 89 buttonBar.setLayout(new GridBagLayout()); 90 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 80}; 91 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0}; 92 93 //---- okButton ---- 94 okButton.setText(tr("OK")); 95 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 96 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 97 new Insets(0, 0, 0, 0), 0, 0)); 98 } 99 dialogPane.add(buttonBar, BorderLayout.SOUTH); 100 } 101 contentPane.add(dialogPane, BorderLayout.CENTER); 102 pack(); 103 setLocationRelativeTo(getOwner()); 104 } 105 106 /** 107 * Set the given {@link ActionListener} to the OK-Button of the {@link FittingView}. 108 * 109 * @param l the listener which should be set 110 */ 111 public void setOkButtonListener(ActionListener l) { 112 this.okButton.addActionListener(l); 113 } 106 114 } -
applications/editors/josm/plugins/indoorhelper/src/views/LevelSelectorView.java
r32122 r32637 21 21 import static org.openstreetmap.josm.tools.I18n.tr; 22 22 23 import java.awt.*; 23 import java.awt.BorderLayout; 24 import java.awt.Container; 25 import java.awt.GridBagConstraints; 26 import java.awt.GridBagLayout; 27 import java.awt.Insets; 24 28 import java.awt.event.ActionListener; 25 29 26 import javax.swing.*; 30 import javax.swing.JButton; 31 import javax.swing.JFrame; 32 import javax.swing.JLabel; 33 import javax.swing.JPanel; 34 import javax.swing.JSpinner; 27 35 import javax.swing.JSpinner.DefaultEditor; 28 import javax.swing.border. *;36 import javax.swing.border.EmptyBorder; 29 37 30 38 /** 31 39 * Class for the pop-up window which provides an level selector to get a user input. 32 40 * In this window the user declares the lowest and the highest level of the building he wants to map. 33 * 41 * 34 42 * @author egru 35 43 * … … 38 46 @SuppressWarnings("serial") 39 47 public class LevelSelectorView extends JFrame { 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 ((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0};80 ((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0};81 ((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4};82 ((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};115 ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};136 ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 * 161 162 163 public void setOkButtonListener(ActionListener l){164 165 166 167 168 169 * 170 171 172 public void setCancelButtonListener(ActionListener l){173 174 175 176 177 178 * 179 180 181 public int getMin(){182 183 184 185 186 187 * 188 189 190 public int getMax(){191 192 48 49 private JPanel dialogPane; 50 private JPanel contentPanel; 51 private JLabel minLabel; 52 private JSpinner minSpinner; 53 private JLabel maxLabel; 54 private JSpinner maxSpinner; 55 private JPanel buttonBar; 56 private JButton okButton; 57 private JButton cancelButton; 58 59 public LevelSelectorView() { 60 initComponents(); 61 } 62 63 private void initComponents() { 64 dialogPane = new JPanel(); 65 contentPanel = new JPanel(); 66 minLabel = new JLabel(); 67 minSpinner = new JSpinner(); 68 maxLabel = new JLabel(); 69 maxSpinner = new JSpinner(); 70 buttonBar = new JPanel(); 71 okButton = new JButton(); 72 cancelButton = new JButton(); 73 74 //======== this ======== 75 setTitle(tr("Level Selection")); 76 Container contentPane = getContentPane(); 77 contentPane.setLayout(new BorderLayout()); 78 79 //======== dialogPane ======== 80 { 81 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 82 dialogPane.setLayout(new BorderLayout()); 83 84 //======== contentPanel ======== 85 { 86 contentPanel.setLayout(new GridBagLayout()); 87 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; 88 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0}; 89 ((GridBagLayout) contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4}; 90 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 91 92 //---- minLabel ---- 93 minLabel.setText(tr("Lowest Level")); 94 contentPanel.add(maxLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, 95 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 96 new Insets(0, 0, 5, 5), 0, 0)); 97 JSpinner.DefaultEditor minEditor = (DefaultEditor) maxSpinner.getEditor(); 98 minEditor.getTextField().setColumns(2); 99 maxSpinner.setToolTipText(tr("The lowest level of your building.")); 100 contentPanel.add(maxSpinner, new GridBagConstraints(2, 0, 2, 1, 0.0, 0.0, 101 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 102 new Insets(0, 0, 5, 0), 0, 0)); 103 104 //---- maxLabel ---- 105 maxLabel.setText(tr("Highest Level")); 106 contentPanel.add(minLabel, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0, 107 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 108 new Insets(0, 0, 5, 5), 0, 0)); 109 JSpinner.DefaultEditor maxEditor = (DefaultEditor) minSpinner.getEditor(); 110 maxEditor.getTextField().setColumns(2); 111 minSpinner.setToolTipText(tr("The highest level of your building.")); 112 contentPanel.add(minSpinner, new GridBagConstraints(2, 2, 2, 1, 0.0, 0.0, 113 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 114 new Insets(0, 0, 5, 0), 0, 0)); 115 } 116 dialogPane.add(contentPanel, BorderLayout.CENTER); 117 118 //======== buttonBar ======== 119 { 120 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 121 buttonBar.setLayout(new GridBagLayout()); 122 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 123 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 124 125 //---- okButton ---- 126 okButton.setText(tr("OK")); 127 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 128 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 129 new Insets(0, 0, 0, 5), 0, 0)); 130 131 //---- cancelButton ---- 132 cancelButton.setText(tr("Cancel")); 133 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 134 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 135 new Insets(0, 0, 0, 0), 0, 0)); 136 } 137 dialogPane.add(contentPanel, BorderLayout.CENTER); 138 139 //======== buttonBar ======== 140 { 141 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 142 buttonBar.setLayout(new GridBagLayout()); 143 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 144 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 145 146 //---- okButton ---- 147 okButton.setText(tr("OK")); 148 buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 149 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 150 new Insets(0, 0, 0, 5), 0, 0)); 151 152 //---- cancelButton ---- 153 cancelButton.setText(tr("Cancel")); 154 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 155 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 156 new Insets(0, 0, 0, 0), 0, 0)); 157 } 158 dialogPane.add(buttonBar, BorderLayout.SOUTH); 159 } 160 contentPane.add(dialogPane, BorderLayout.CENTER); 161 pack(); 162 setLocationRelativeTo(getOwner()); 163 164 } 165 166 /** 167 * Set the listener for the OK button. 168 * 169 * @param l the listener to set 170 */ 171 public void setOkButtonListener(ActionListener l) { 172 this.okButton.addActionListener(l); 173 } 174 175 /** 176 * Set the listener for the cancel button. 177 * 178 * @param l the listener to set 179 */ 180 public void setCancelButtonListener(ActionListener l) { 181 this.cancelButton.addActionListener(l); 182 } 183 184 /** 185 * Getter for the lowest level. 186 * 187 * @return Integer which represents the lowest level of the building. 188 */ 189 public int getMin() { 190 return (int) this.minSpinner.getValue(); 191 } 192 193 /** 194 * Getter for the highest level. 195 * 196 * @return Integer which represents the highest level of the building. 197 */ 198 public int getMax() { 199 return (int) this.maxSpinner.getValue(); 200 } 193 201 } -
applications/editors/josm/plugins/indoorhelper/src/views/PresetButton.java
r32122 r32637 20 20 21 21 import javax.swing.JButton; 22 22 23 import model.TagCatalog.IndoorObject; 23 24 … … 30 31 @SuppressWarnings("serial") 31 32 class PresetButton extends JButton { 32 33 34 35 public PresetButton(IndoorObject object){36 this.setIndoorObject(object); 37 38 39 public IndoorObject getIndoorObject(){40 41 42 43 public void setIndoorObject(IndoorObject object){44 45 46 47 33 34 private IndoorObject indoorObject; 35 36 PresetButton(IndoorObject object) { 37 this.setIndoorObject(object); 38 } 39 40 public IndoorObject getIndoorObject() { 41 return this.indoorObject; 42 } 43 44 public void setIndoorObject(IndoorObject object) { 45 this.indoorObject = object; 46 this.setText(indoorObject.toString()); 47 this.setToolTipText(indoorObject.toString()); 48 } 48 49 49 50 } -
applications/editors/josm/plugins/indoorhelper/src/views/ToolBoxView.java
r32122 r32637 21 21 import static org.openstreetmap.josm.tools.I18n.tr; 22 22 23 import java.awt.*; 23 import java.awt.BorderLayout; 24 import java.awt.GridBagConstraints; 25 import java.awt.GridBagLayout; 26 import java.awt.Insets; 27 import java.awt.TextField; 24 28 import java.awt.event.ActionListener; 25 29 import java.awt.event.FocusEvent; … … 29 33 import java.util.ListIterator; 30 34 31 import javax.swing.*; 32 import javax.swing.border.*; 35 import javax.swing.JButton; 36 import javax.swing.JLabel; 37 import javax.swing.JPanel; 38 import javax.swing.JSeparator; 39 import javax.swing.JToggleButton; 40 import javax.swing.border.EmptyBorder; 41 33 42 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 34 43 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField; … … 40 49 41 50 /** 42 * 51 * 43 52 * This is the main toolbox of the indoorhelper plug-in. 44 * 53 * 45 54 * @author egru 46 55 * 47 56 */ 48 57 @SuppressWarnings("serial") 49 public class ToolBoxView extends ToggleDialog{ 50 private JPanel dialogPane; 51 private JPanel contentPanel; 52 private JToggleButton powerButton; 53 private JLabel levelLabel; 54 private JosmComboBox<String> levelBox; 55 private JLabel levelTagLabel; 56 private DisableShortcutsOnFocusGainedTextField levelTagField; 57 private JLabel objectLabel; 58 private JosmComboBox<TagCatalog.IndoorObject> objectBox; 59 private JLabel nameLabel; 60 private DisableShortcutsOnFocusGainedTextField nameField; 61 private JLabel refLabel; 62 private DisableShortcutsOnFocusGainedTextField refField; 63 private JPanel buttonBar; 64 private JButton applyButton; 65 private JSeparator separator1; 66 private JSeparator separator2; 67 private PresetButton preset1; 68 private PresetButton preset2; 69 private PresetButton preset3; 70 private PresetButton preset4; 71 72 public ToolBoxView(){ 73 super(tr("Indoor Mapping Helper"), "indoorhelper", 74 tr("Toolbox for indoor mapping assistance"), null, 300, true); 75 76 initComponents(); 77 } 78 79 /** 80 * Creates the layout of the plug-in. 81 */ 82 private void initComponents() { 83 dialogPane = new JPanel(); 84 contentPanel = new JPanel(); 85 powerButton = new JToggleButton(); 86 levelLabel = new JLabel(); 87 levelBox = new JosmComboBox<String>(); 88 levelTagLabel = new JLabel(); 89 levelTagField = new DisableShortcutsOnFocusGainedTextField(); 90 objectLabel = new JLabel(); 91 objectBox = new JosmComboBox<>(TagCatalog.IndoorObject.values()); 92 nameLabel = new JLabel(); 93 nameField = new DisableShortcutsOnFocusGainedTextField(); 94 refLabel = new JLabel(); 95 refField = new DisableShortcutsOnFocusGainedTextField(); 96 buttonBar = new JPanel(); 97 applyButton = new JButton(); 98 separator1 = new JSeparator(); 99 separator2 = new JSeparator(); 100 preset1 = new PresetButton(IndoorObject.ROOM); 101 preset2 = new PresetButton(IndoorObject.SHELL); 102 preset3 = new PresetButton(IndoorObject.CONCRETE_WALL); 103 preset4 = new PresetButton(IndoorObject.GLASS_WALL); 104 105 //======== this ======== 106 //Container contentPane = this.get; 107 //contentPane.setLayout(new BorderLayout()); 108 109 //======== dialogPane ======== 110 { 111 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 112 dialogPane.setLayout(new BorderLayout()); 113 114 //======== contentPanel ======== 115 { 116 contentPanel.setLayout(new GridBagLayout()); 117 ((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 118 ((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0}; 119 ((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 120 ((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 121 122 //---- powerButton ---- 123 powerButton.setText(tr("POWER")); 124 powerButton.setToolTipText(tr("Activates the plug-in")); 125 contentPanel.add(powerButton, new GridBagConstraints(8, 0, 4, 1, 0.0, 0.0, 126 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 127 new Insets(0, 0, 5, 5), 0, 0)); 128 contentPanel.add(separator1, new GridBagConstraints(1, 1, 12, 1, 0.0, 0.0, 129 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 130 new Insets(0, 0, 5, 5), 0, 0)); 131 132 //---- levelLabel ---- 133 levelLabel.setText(tr("Working Level")); 134 contentPanel.add(levelLabel, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, 135 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 136 new Insets(0, 0, 5, 5), 0, 0)); 137 138 //---- levelBox ---- 139 levelBox.setEnabled(false); 140 levelBox.setEditable(false); 141 levelBox.setToolTipText(tr("Selects the working level.")); 142 contentPanel.add(levelBox, new GridBagConstraints(3, 2, 3, 1, 0.0, 0.0, 143 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 144 new Insets(0, 0, 5, 5), 0, 0)); 145 146 //---- levelTagLabel ---- 147 levelTagLabel.setText(tr("Level Name")); 148 contentPanel.add(levelTagLabel, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, 149 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 150 new Insets(0, 0, 5, 5), 0, 0)); 151 152 //---- levelTagField ---- 153 levelTagField.setEnabled(false); 154 levelTagField.setColumns(6); 155 levelTagField.setToolTipText(tr("Optional name-tag for a level.")); 156 contentPanel.add(levelTagField, new GridBagConstraints(8, 2, 5, 1, 0.0, 0.0, 157 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 158 new Insets(0, 0, 5, 5), 0, 0)); 159 contentPanel.add(separator2, new GridBagConstraints(1, 3, 12, 1, 0.0, 0.0, 160 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 161 new Insets(0, 0, 5, 5), 0, 0)); 162 163 //---- objectLabel ---- 164 objectLabel.setText(tr("Object")); 165 contentPanel.add(objectLabel, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 166 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 167 new Insets(0, 0, 5, 5), 0, 0)); 168 169 //---- objectBox ---- 170 objectBox.setEnabled(false); 171 objectBox.setPrototypeDisplayValue(IndoorObject.CONCRETE_WALL); 172 objectBox.setToolTipText(tr("The object preset you want to tag.")); 173 contentPanel.add(objectBox, new GridBagConstraints(3, 4, 3, 1, 0.0, 0.0, 174 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 175 new Insets(0, 0, 5, 5), 0, 0)); 176 177 //---- nameLabel ---- 178 nameLabel.setText(tr("Name")); 179 contentPanel.add(nameLabel, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 180 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 181 new Insets(0, 0, 5, 5), 0, 0)); 182 183 //---- nameField ---- 184 nameField.setEnabled(false); 185 nameField.addFocusListener(new FocusListener() { 186 187 @Override 188 public void focusLost(FocusEvent e) {} 189 190 @Override 191 public void focusGained(FocusEvent e) { 192 nameField.selectAll(); 193 } 194 }); 195 nameField.setToolTipText(tr("Sets the name tag when the room-object is selected.")); 196 contentPanel.add(nameField, new GridBagConstraints(3, 5, 3, 1, 0.0, 0.0, 197 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 198 new Insets(0, 0, 5, 5), 0, 0)); 199 200 //---- refLabel ---- 201 refLabel.setText(tr("Reference")); 202 contentPanel.add(refLabel, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0, 203 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 204 new Insets(0, 0, 0, 5), 0, 0)); 205 206 //---- refField ---- 207 refField.setEnabled(false); 208 refField.addFocusListener(new FocusListener() { 209 210 @Override 211 public void focusLost(FocusEvent e) {} 212 213 @Override 214 public void focusGained(FocusEvent e) { 215 refField.selectAll(); 216 } 217 }); 218 refField.setToolTipText(tr("Sets the ref tag when the room-object is selected.")); 219 contentPanel.add(refField, new GridBagConstraints(3, 6, 3, 1, 0.0, 0.0, 220 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 221 new Insets(0, 0, 0, 5), 0, 0)); 222 223 //---- preset1 ---- 224 preset1.setEnabled(false); 225 contentPanel.add(preset1, new GridBagConstraints(16, 2, 1, 1, 0.0, 0.0, 226 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 227 new Insets(0, 0, 5, 5), 0, 0)); 228 contentPanel.add(separator2, new GridBagConstraints(1, 3, 13, 1, 0.0, 0.0, 229 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 230 new Insets(0, 0, 5, 5), 0, 0)); 231 232 //---- preset2 ---- 233 preset2.setEnabled(false); 234 contentPanel.add(preset2, new GridBagConstraints(16, 3, 1, 1, 0.0, 0.0, 235 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 236 new Insets(0, 0, 5, 5), 0, 0)); 237 238 //---- preset3 ---- 239 preset3.setEnabled(false); 240 contentPanel.add(preset3, new GridBagConstraints(16, 4, 1, 1, 0.0, 0.0, 241 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 242 new Insets(0, 0, 5, 5), 0, 0)); 243 244 //---- preset4 ---- 245 preset4.setEnabled(false); 246 contentPanel.add(preset4, new GridBagConstraints(16, 5, 1, 1, 0.0, 0.0, 247 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 248 new Insets(0, 0, 5, 5), 0, 0)); 249 } 250 dialogPane.add(contentPanel, BorderLayout.CENTER); 251 252 //======== buttonBar ======== 253 { 254 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 255 buttonBar.setLayout(new GridBagLayout()); 256 ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80}; 257 ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0}; 258 259 //---- applyButton ---- 260 applyButton.setText(tr("Apply Tags")); 261 applyButton.setEnabled(false); 262 buttonBar.add(applyButton, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, 263 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 264 new Insets(0, 0, 0, 0), 0, 0)); 265 } 266 dialogPane.add(buttonBar, BorderLayout.SOUTH); 267 } 268 //contentPane.add(dialogPane, BorderLayout.CENTER); 269 270 271 this.createLayout(dialogPane, false, null); 272 } 273 274 /** 275 * Returns the state of the power button. 276 * 277 * @return boolean which is true when the button is selected 278 */ 279 public boolean getPowerButtonState(){ 280 return this.powerButton.isSelected(); 281 } 282 283 /** 284 * Enables or disables the interactive UI elements of the toolbox. 285 * 286 * @param enabled set this true for enabled elements 287 */ 288 public void setAllUiElementsEnabled(boolean enabled){ 289 this.applyButton.setEnabled(enabled); 290 this.levelBox.setEnabled(enabled); 291 this.objectBox.setEnabled(enabled); 292 this.nameField.setEnabled(enabled); 293 this.refField.setEnabled(enabled); 294 this.levelTagField.setEnabled(enabled); 295 this.preset1.setEnabled(enabled); 296 this.preset2.setEnabled(enabled); 297 this.preset3.setEnabled(enabled); 298 this.preset4.setEnabled(enabled); 299 300 301 if(enabled==false) { 302 resetUiElements(); 303 this.levelTagField.setText(""); 304 } 305 } 306 307 /** 308 * Enables or disables the interactive text box elements name and ref. 309 * 310 * @param enabled set this true for enabled elements 311 */ 312 public void setTagUiElementsEnabled(boolean enabled){ 313 this.nameField.setEnabled(enabled); 314 this.refField.setEnabled(enabled); 315 316 if(enabled==false) resetUiElements(); 317 } 318 319 /** 320 * Disables the power-button of the plug-in. 321 */ 322 public void setPowerButtonDisabled(){ 323 this.powerButton.setSelected(false); 324 } 325 326 /** 327 * Getter for the selected {@link IndoorObject} in the objectBox. 328 * 329 * @return the selected indoor object in the object ComboBox. 330 */ 331 public IndoorObject getSelectedObject(){ 332 return (IndoorObject) this.objectBox.getSelectedItem(); 333 } 334 335 336 /** 337 * Sets the level list for the level selection comboBox. 338 * 339 * @param levelList the list of levels which you want to set 340 */ 341 public void setLevelList(List<IndoorLevel> levelList){ 342 this.levelBox.removeAllItems(); 343 344 ListIterator<IndoorLevel> listIterator = levelList.listIterator(); 345 346 while(listIterator.hasNext()){ 347 IndoorLevel level = listIterator.next(); 348 if(level.hasEmptyName()){ 349 this.levelBox.addItem(Integer.toString(level.getLevelNumber())); 350 } else{ 351 this.levelBox.addItem(level.getName()); 352 } 353 } 354 } 355 356 /** 357 * Getter for the selected working level. 358 * 359 * @return the index of the selected item in the level-box 360 */ 361 public int getSelectedLevelIndex(){ 362 return this.levelBox.getSelectedIndex(); 363 } 364 365 /** 366 * Checks if the level list is empty. 367 * 368 * @return boolean which is true if the level-list is empty 369 */ 370 public boolean levelListIsEmpty(){ 371 if(this.levelBox.getItemCount()==0){ 372 return true; 373 } else{ 374 return false; 375 } 376 } 377 378 /** 379 * Getter for the level-name-field. 380 * 381 * @return the {@link String} of the levelTagField 382 */ 383 public String getLevelName(){ 384 return this.levelTagField.getText(); 385 } 386 387 /** 388 * Setter for the level name field. 389 * 390 * @param name the String for the levelTagField 391 */ 392 public void setLevelName(String name){ 393 this.levelTagField.setText(name); 394 } 395 396 /** 397 * Getter for the name {@link TextField}. 398 * 399 * @return {@link String} of the name text field 400 */ 401 public String getNameText(){ 402 return this.nameField.getText(); 403 } 404 405 /** 406 * Getter for the ref {@link TextField}. 407 * 408 * @return {@link String} of the ref text field 409 */ 410 public String getRefText(){ 411 return this.refField.getText(); 412 } 413 414 /** 415 * Resets the view by making the UI elements disabled and deleting the level list. 416 */ 417 public void reset(){ 418 this.setAllUiElementsEnabled(false); 419 this.levelBox.removeAllItems(); 420 } 421 422 /** 423 * Clears the text boxes and sets an empty {@link String}. 424 */ 425 public void resetUiElements(){ 426 this.nameField.setText(""); 427 this.refField.setText(""); 428 } 429 430 /* 431 * ******************************** 432 * SETTERS FOR THE BUTTON LISTENERS 433 * ******************************** 434 */ 435 436 /** 437 * Set the listener for the power button. 438 * 439 * @param l the listener to set 440 */ 441 public void setPowerButtonListener(ActionListener l){ 442 this.powerButton.addActionListener(l); 443 } 444 445 /** 446 * Set the listener for the apply button. 447 * 448 * @param l the listener to set 449 */ 450 public void setApplyButtonListener(ActionListener l){ 451 this.applyButton.addActionListener(l); 452 } 453 454 /** 455 * Set the listener which is called when a new item in the level list is selected. 456 * 457 * @param l the listener to set 458 */ 459 public void setLevelItemListener(ItemListener l){ 460 this.levelBox.addItemListener(l); 461 } 462 463 464 /** 465 * Set the listener which is called when a new item in the object list is selected. 466 * 467 * @param l the listener to set 468 */ 469 public void setObjectItemListener(ItemListener l){ 470 this.objectBox.addItemListener(l); 471 } 472 473 // Preset Button Functions 474 475 public void setPresetButtons(List<IndoorObject> objects){ 476 this.preset1.setIndoorObject(objects.get(0)); 477 this.preset2.setIndoorObject(objects.get(1)); 478 this.preset3.setIndoorObject(objects.get(2)); 479 this.preset4.setIndoorObject(objects.get(3)); 480 } 481 482 public void setPreset1Listener(ActionListener l){ 483 this.preset1.addActionListener(l); 484 } 485 486 public void setPreset2Listener(ActionListener l){ 487 this.preset2.addActionListener(l); 488 } 489 490 public void setPreset3Listener(ActionListener l){ 491 this.preset3.addActionListener(l); 492 } 493 494 public void setPreset4Listener(ActionListener l){ 495 this.preset4.addActionListener(l); 496 } 497 498 public IndoorObject getPreset1(){ 499 return preset1.getIndoorObject(); 500 } 501 502 public IndoorObject getPreset2(){ 503 return preset2.getIndoorObject(); 504 } 505 506 public IndoorObject getPreset3(){ 507 return preset3.getIndoorObject(); 508 } 509 510 public IndoorObject getPreset4(){ 511 return preset4.getIndoorObject(); 512 } 58 public class ToolBoxView extends ToggleDialog { 59 private JPanel dialogPane; 60 private JPanel contentPanel; 61 private JToggleButton powerButton; 62 private JLabel levelLabel; 63 private JosmComboBox<String> levelBox; 64 private JLabel levelTagLabel; 65 private DisableShortcutsOnFocusGainedTextField levelTagField; 66 private JLabel objectLabel; 67 private JosmComboBox<TagCatalog.IndoorObject> objectBox; 68 private JLabel nameLabel; 69 private DisableShortcutsOnFocusGainedTextField nameField; 70 private JLabel refLabel; 71 private DisableShortcutsOnFocusGainedTextField refField; 72 private JPanel buttonBar; 73 private JButton applyButton; 74 private JSeparator separator1; 75 private JSeparator separator2; 76 private PresetButton preset1; 77 private PresetButton preset2; 78 private PresetButton preset3; 79 private PresetButton preset4; 80 81 public ToolBoxView() { 82 super(tr("Indoor Mapping Helper"), "indoorhelper", 83 tr("Toolbox for indoor mapping assistance"), null, 300, true); 84 85 initComponents(); 86 } 87 88 /** 89 * Creates the layout of the plug-in. 90 */ 91 private void initComponents() { 92 dialogPane = new JPanel(); 93 contentPanel = new JPanel(); 94 powerButton = new JToggleButton(); 95 levelLabel = new JLabel(); 96 levelBox = new JosmComboBox<String>(); 97 levelTagLabel = new JLabel(); 98 levelTagField = new DisableShortcutsOnFocusGainedTextField(); 99 objectLabel = new JLabel(); 100 objectBox = new JosmComboBox<>(TagCatalog.IndoorObject.values()); 101 nameLabel = new JLabel(); 102 nameField = new DisableShortcutsOnFocusGainedTextField(); 103 refLabel = new JLabel(); 104 refField = new DisableShortcutsOnFocusGainedTextField(); 105 buttonBar = new JPanel(); 106 applyButton = new JButton(); 107 separator1 = new JSeparator(); 108 separator2 = new JSeparator(); 109 preset1 = new PresetButton(IndoorObject.ROOM); 110 preset2 = new PresetButton(IndoorObject.SHELL); 111 preset3 = new PresetButton(IndoorObject.CONCRETE_WALL); 112 preset4 = new PresetButton(IndoorObject.GLASS_WALL); 113 114 //======== this ======== 115 //Container contentPane = this.get; 116 //contentPane.setLayout(new BorderLayout()); 117 118 //======== dialogPane ======== 119 { 120 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 121 dialogPane.setLayout(new BorderLayout()); 122 123 //======== contentPanel ======== 124 { 125 contentPanel.setLayout(new GridBagLayout()); 126 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] { 127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 128 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0, 0}; 129 ((GridBagLayout) contentPanel.getLayout()).columnWeights = new double[] { 130 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 131 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 132 133 //---- powerButton ---- 134 powerButton.setText(tr("POWER")); 135 powerButton.setToolTipText(tr("Activates the plug-in")); 136 contentPanel.add(powerButton, new GridBagConstraints(8, 0, 4, 1, 0.0, 0.0, 137 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 138 new Insets(0, 0, 5, 5), 0, 0)); 139 contentPanel.add(separator1, new GridBagConstraints(1, 1, 12, 1, 0.0, 0.0, 140 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 141 new Insets(0, 0, 5, 5), 0, 0)); 142 143 //---- levelLabel ---- 144 levelLabel.setText(tr("Working Level")); 145 contentPanel.add(levelLabel, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, 146 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 147 new Insets(0, 0, 5, 5), 0, 0)); 148 149 //---- levelBox ---- 150 levelBox.setEnabled(false); 151 levelBox.setEditable(false); 152 levelBox.setToolTipText(tr("Selects the working level.")); 153 contentPanel.add(levelBox, new GridBagConstraints(3, 2, 3, 1, 0.0, 0.0, 154 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 155 new Insets(0, 0, 5, 5), 0, 0)); 156 157 //---- levelTagLabel ---- 158 levelTagLabel.setText(tr("Level Name")); 159 contentPanel.add(levelTagLabel, new GridBagConstraints(7, 2, 1, 1, 0.0, 0.0, 160 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 161 new Insets(0, 0, 5, 5), 0, 0)); 162 163 //---- levelTagField ---- 164 levelTagField.setEnabled(false); 165 levelTagField.setColumns(6); 166 levelTagField.setToolTipText(tr("Optional name-tag for a level.")); 167 contentPanel.add(levelTagField, new GridBagConstraints(8, 2, 5, 1, 0.0, 0.0, 168 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 169 new Insets(0, 0, 5, 5), 0, 0)); 170 contentPanel.add(separator2, new GridBagConstraints(1, 3, 12, 1, 0.0, 0.0, 171 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 172 new Insets(0, 0, 5, 5), 0, 0)); 173 174 //---- objectLabel ---- 175 objectLabel.setText(tr("Object")); 176 contentPanel.add(objectLabel, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 177 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 178 new Insets(0, 0, 5, 5), 0, 0)); 179 180 //---- objectBox ---- 181 objectBox.setEnabled(false); 182 objectBox.setPrototypeDisplayValue(IndoorObject.CONCRETE_WALL); 183 objectBox.setToolTipText(tr("The object preset you want to tag.")); 184 contentPanel.add(objectBox, new GridBagConstraints(3, 4, 3, 1, 0.0, 0.0, 185 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 186 new Insets(0, 0, 5, 5), 0, 0)); 187 188 //---- nameLabel ---- 189 nameLabel.setText(tr("Name")); 190 contentPanel.add(nameLabel, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 191 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 192 new Insets(0, 0, 5, 5), 0, 0)); 193 194 //---- nameField ---- 195 nameField.setEnabled(false); 196 nameField.addFocusListener(new FocusListener() { 197 198 @Override 199 public void focusLost(FocusEvent e) {} 200 201 @Override 202 public void focusGained(FocusEvent e) { 203 nameField.selectAll(); 204 } 205 }); 206 nameField.setToolTipText(tr("Sets the name tag when the room-object is selected.")); 207 contentPanel.add(nameField, new GridBagConstraints(3, 5, 3, 1, 0.0, 0.0, 208 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 209 new Insets(0, 0, 5, 5), 0, 0)); 210 211 //---- refLabel ---- 212 refLabel.setText(tr("Reference")); 213 contentPanel.add(refLabel, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0, 214 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 215 new Insets(0, 0, 0, 5), 0, 0)); 216 217 //---- refField ---- 218 refField.setEnabled(false); 219 refField.addFocusListener(new FocusListener() { 220 221 @Override 222 public void focusLost(FocusEvent e) {} 223 224 @Override 225 public void focusGained(FocusEvent e) { 226 refField.selectAll(); 227 } 228 }); 229 refField.setToolTipText(tr("Sets the ref tag when the room-object is selected.")); 230 contentPanel.add(refField, new GridBagConstraints(3, 6, 3, 1, 0.0, 0.0, 231 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 232 new Insets(0, 0, 0, 5), 0, 0)); 233 234 //---- preset1 ---- 235 preset1.setEnabled(false); 236 contentPanel.add(preset1, new GridBagConstraints(16, 2, 1, 1, 0.0, 0.0, 237 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 238 new Insets(0, 0, 5, 5), 0, 0)); 239 contentPanel.add(separator2, new GridBagConstraints(1, 3, 13, 1, 0.0, 0.0, 240 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 241 new Insets(0, 0, 5, 5), 0, 0)); 242 243 //---- preset2 ---- 244 preset2.setEnabled(false); 245 contentPanel.add(preset2, new GridBagConstraints(16, 3, 1, 1, 0.0, 0.0, 246 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 247 new Insets(0, 0, 5, 5), 0, 0)); 248 249 //---- preset3 ---- 250 preset3.setEnabled(false); 251 contentPanel.add(preset3, new GridBagConstraints(16, 4, 1, 1, 0.0, 0.0, 252 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 253 new Insets(0, 0, 5, 5), 0, 0)); 254 255 //---- preset4 ---- 256 preset4.setEnabled(false); 257 contentPanel.add(preset4, new GridBagConstraints(16, 5, 1, 1, 0.0, 0.0, 258 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 259 new Insets(0, 0, 5, 5), 0, 0)); 260 } 261 dialogPane.add(contentPanel, BorderLayout.CENTER); 262 263 //======== buttonBar ======== 264 { 265 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 266 buttonBar.setLayout(new GridBagLayout()); 267 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 80}; 268 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0}; 269 270 //---- applyButton ---- 271 applyButton.setText(tr("Apply Tags")); 272 applyButton.setEnabled(false); 273 buttonBar.add(applyButton, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, 274 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 275 new Insets(0, 0, 0, 0), 0, 0)); 276 } 277 dialogPane.add(buttonBar, BorderLayout.SOUTH); 278 } 279 //contentPane.add(dialogPane, BorderLayout.CENTER); 280 281 282 this.createLayout(dialogPane, false, null); 283 } 284 285 /** 286 * Returns the state of the power button. 287 * 288 * @return boolean which is true when the button is selected 289 */ 290 public boolean getPowerButtonState() { 291 return this.powerButton.isSelected(); 292 } 293 294 /** 295 * Enables or disables the interactive UI elements of the toolbox. 296 * 297 * @param enabled set this true for enabled elements 298 */ 299 public void setAllUiElementsEnabled(boolean enabled) { 300 this.applyButton.setEnabled(enabled); 301 this.levelBox.setEnabled(enabled); 302 this.objectBox.setEnabled(enabled); 303 this.nameField.setEnabled(enabled); 304 this.refField.setEnabled(enabled); 305 this.levelTagField.setEnabled(enabled); 306 this.preset1.setEnabled(enabled); 307 this.preset2.setEnabled(enabled); 308 this.preset3.setEnabled(enabled); 309 this.preset4.setEnabled(enabled); 310 311 312 if (enabled == false) { 313 resetUiElements(); 314 this.levelTagField.setText(""); 315 } 316 } 317 318 /** 319 * Enables or disables the interactive text box elements name and ref. 320 * 321 * @param enabled set this true for enabled elements 322 */ 323 public void setTagUiElementsEnabled(boolean enabled) { 324 this.nameField.setEnabled(enabled); 325 this.refField.setEnabled(enabled); 326 327 if (enabled == false) resetUiElements(); 328 } 329 330 /** 331 * Disables the power-button of the plug-in. 332 */ 333 public void setPowerButtonDisabled() { 334 this.powerButton.setSelected(false); 335 } 336 337 /** 338 * Getter for the selected {@link IndoorObject} in the objectBox. 339 * 340 * @return the selected indoor object in the object ComboBox. 341 */ 342 public IndoorObject getSelectedObject() { 343 return (IndoorObject) this.objectBox.getSelectedItem(); 344 } 345 346 347 /** 348 * Sets the level list for the level selection comboBox. 349 * 350 * @param levelList the list of levels which you want to set 351 */ 352 public void setLevelList(List<IndoorLevel> levelList) { 353 this.levelBox.removeAllItems(); 354 355 ListIterator<IndoorLevel> listIterator = levelList.listIterator(); 356 357 while (listIterator.hasNext()) { 358 IndoorLevel level = listIterator.next(); 359 if (level.hasEmptyName()) { 360 this.levelBox.addItem(Integer.toString(level.getLevelNumber())); 361 } else { 362 this.levelBox.addItem(level.getName()); 363 } 364 } 365 } 366 367 /** 368 * Getter for the selected working level. 369 * 370 * @return the index of the selected item in the level-box 371 */ 372 public int getSelectedLevelIndex() { 373 return this.levelBox.getSelectedIndex(); 374 } 375 376 /** 377 * Checks if the level list is empty. 378 * 379 * @return boolean which is true if the level-list is empty 380 */ 381 public boolean levelListIsEmpty() { 382 if (this.levelBox.getItemCount() == 0) { 383 return true; 384 } else { 385 return false; 386 } 387 } 388 389 /** 390 * Getter for the level-name-field. 391 * 392 * @return the {@link String} of the levelTagField 393 */ 394 public String getLevelName() { 395 return this.levelTagField.getText(); 396 } 397 398 /** 399 * Setter for the level name field. 400 * 401 * @param name the String for the levelTagField 402 */ 403 public void setLevelName(String name) { 404 this.levelTagField.setText(name); 405 } 406 407 /** 408 * Getter for the name {@link TextField}. 409 * 410 * @return {@link String} of the name text field 411 */ 412 public String getNameText() { 413 return this.nameField.getText(); 414 } 415 416 /** 417 * Getter for the ref {@link TextField}. 418 * 419 * @return {@link String} of the ref text field 420 */ 421 public String getRefText() { 422 return this.refField.getText(); 423 } 424 425 /** 426 * Resets the view by making the UI elements disabled and deleting the level list. 427 */ 428 public void reset() { 429 this.setAllUiElementsEnabled(false); 430 this.levelBox.removeAllItems(); 431 } 432 433 /** 434 * Clears the text boxes and sets an empty {@link String}. 435 */ 436 public void resetUiElements() { 437 this.nameField.setText(""); 438 this.refField.setText(""); 439 } 440 441 /* 442 * ******************************** 443 * SETTERS FOR THE BUTTON LISTENERS 444 * ******************************** 445 */ 446 447 /** 448 * Set the listener for the power button. 449 * 450 * @param l the listener to set 451 */ 452 public void setPowerButtonListener(ActionListener l) { 453 this.powerButton.addActionListener(l); 454 } 455 456 /** 457 * Set the listener for the apply button. 458 * 459 * @param l the listener to set 460 */ 461 public void setApplyButtonListener(ActionListener l) { 462 this.applyButton.addActionListener(l); 463 } 464 465 /** 466 * Set the listener which is called when a new item in the level list is selected. 467 * 468 * @param l the listener to set 469 */ 470 public void setLevelItemListener(ItemListener l) { 471 this.levelBox.addItemListener(l); 472 } 473 474 475 /** 476 * Set the listener which is called when a new item in the object list is selected. 477 * 478 * @param l the listener to set 479 */ 480 public void setObjectItemListener(ItemListener l) { 481 this.objectBox.addItemListener(l); 482 } 483 484 // Preset Button Functions 485 486 public void setPresetButtons(List<IndoorObject> objects) { 487 this.preset1.setIndoorObject(objects.get(0)); 488 this.preset2.setIndoorObject(objects.get(1)); 489 this.preset3.setIndoorObject(objects.get(2)); 490 this.preset4.setIndoorObject(objects.get(3)); 491 } 492 493 public void setPreset1Listener(ActionListener l) { 494 this.preset1.addActionListener(l); 495 } 496 497 public void setPreset2Listener(ActionListener l) { 498 this.preset2.addActionListener(l); 499 } 500 501 public void setPreset3Listener(ActionListener l) { 502 this.preset3.addActionListener(l); 503 } 504 505 public void setPreset4Listener(ActionListener l) { 506 this.preset4.addActionListener(l); 507 } 508 509 public IndoorObject getPreset1() { 510 return preset1.getIndoorObject(); 511 } 512 513 public IndoorObject getPreset2() { 514 return preset2.getIndoorObject(); 515 } 516 517 public IndoorObject getPreset3() { 518 return preset3.getIndoorObject(); 519 } 520 521 public IndoorObject getPreset4() { 522 return preset4.getIndoorObject(); 523 } 513 524 } -
applications/editors/josm/plugins/indoorhelper/test/unit/PresetCounterTest.java
r32122 r32637 1 import static org.junit.Assert. *;1 import static org.junit.Assert.assertEquals; 2 2 3 3 import java.util.ArrayList; … … 11 11 public class PresetCounterTest { 12 12 13 14 15 16 17 18 19 13 /** 14 * Test case for testing the ranking functionality. 15 */ 16 @Test 17 public void testRanking() { 18 // input preparation 19 PresetCounter counter = new PresetCounter(); 20 20 21 22 23 24 25 26 27 21 counter.count(IndoorObject.CONCRETE_WALL); 22 counter.count(IndoorObject.CONCRETE_WALL); 23 counter.count(IndoorObject.CONCRETE_WALL); 24 counter.count(IndoorObject.ROOM); 25 counter.count(IndoorObject.ROOM); 26 counter.count(IndoorObject.STEPS); 27 counter.count(IndoorObject.TOILET_MALE); 28 28 29 29 List<IndoorObject> actualList = counter.getRanking(); 30 30 31 //expectation 32 List<IndoorObject> expectedList = new ArrayList<>(); 33 expectedList.add(IndoorObject.CONCRETE_WALL); 34 expectedList.add(IndoorObject.ROOM); 35 expectedList.add(IndoorObject.TOILET_MALE); 36 expectedList.add(IndoorObject.STEPS); 37 38 39 //assertion 40 assertEquals(expectedList.get(0), actualList.get(0)); 41 assertEquals(expectedList.get(1), actualList.get(1)); 42 assertEquals(expectedList.get(2), actualList.get(2)); 43 assertEquals(expectedList.get(3), actualList.get(3)); 31 //expectation 32 List<IndoorObject> expectedList = new ArrayList<>(); 33 expectedList.add(IndoorObject.CONCRETE_WALL); 34 expectedList.add(IndoorObject.ROOM); 35 expectedList.add(IndoorObject.TOILET_MALE); 36 expectedList.add(IndoorObject.STEPS); 44 37 45 38 46 } 39 //assertion 40 assertEquals(expectedList.get(0), actualList.get(0)); 41 assertEquals(expectedList.get(1), actualList.get(1)); 42 assertEquals(expectedList.get(2), actualList.get(2)); 43 assertEquals(expectedList.get(3), actualList.get(3)); 44 45 46 } 47 47 }
Note:
See TracChangeset
for help on using the changeset viewer.