Changeset 30738 in osm for applications/editors/josm/plugins/ImportImagePlugin
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java
r29805 r30738 95 95 // add menu entries 96 96 //Main.main.menu.fileMenu.insert(loadFileAction, 8); 97 97 98 98 //Main.main.menu.fileMenu.insertSeparator(9); 99 99 100 100 ExtensionFileFilter.importers.add(new ImportImageFileImporter()); 101 101 … … 129 129 130 130 // if properties file doesn't exist, install plugin 131 if(!isInstalled) 132 { 131 if (!isInstalled) { 133 132 134 133 /*----------- Begin installation ---------------*/ … … 147 146 148 147 // create local properties file 149 if(pluginProps == null || pluginProps.isEmpty()){ 150 151 FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH)); 152 URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME); 153 pluginProps = new Properties(); 154 pluginProps.load(propertiesURL.openStream()); 155 pluginProps.store(fw, null); 156 fw.close(); 148 if (pluginProps == null || pluginProps.isEmpty()) { 149 try (FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) { 150 URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME); 151 pluginProps = new Properties(); 152 pluginProps.load(propertiesURL.openStream()); 153 pluginProps.store(fw, null); 154 } 157 155 logger.debug("Plugin properties loaded"); 158 156 } 159 157 160 if(!new File(LOGGING_PROPERTIES_FILEPATH).exists()) 161 { 162 FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH)); 163 URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties"); 164 Properties loggingProps = new Properties(); 165 loggingProps.load(propertiesURL.openStream()); 166 loggingProps.store(fw, null); 167 fw.close(); 158 if (!new File(LOGGING_PROPERTIES_FILEPATH).exists()) { 159 try (FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH))) { 160 URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties"); 161 Properties loggingProps = new Properties(); 162 loggingProps.load(propertiesURL.openStream()); 163 loggingProps.store(fw, null); 164 } 168 165 logger.debug("Logging properties created"); 169 166 } … … 172 169 } 173 170 } 174 175 171 176 172 /** -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LayerPropertiesDialog.java
r30532 r30738 31 31 import org.opengis.referencing.NoSuchAuthorityCodeException; 32 32 import org.opengis.referencing.crs.CoordinateReferenceSystem; 33 import org.openstreetmap.josm.Main; 33 34 34 35 /** … … 36 37 * - general and spatial information about the georeferenced image 37 38 * - a possiblitly to change the source reference system of the image 38 * 39 * 39 * 40 * 40 41 * @author Christoph Beekmans, Fabian Kowitz, Anna Robaszkiewicz, Oliver Kuhn, Martin Ulitzny 41 42 * 42 43 */ 43 44 public class LayerPropertiesDialog extends JFrame{ 44 45 45 46 private Vector<String> supportedCRS; 46 47 private ImageLayer imageLayer; … … 86 87 87 88 /** 88 * This method initializes 89 * 89 * This method initializes 90 * 90 91 */ 91 92 public LayerPropertiesDialog(ImageLayer imageLayer, Vector<String> supportedCRS) { … … 95 96 initialize(); 96 97 } 97 98 /** 99 * This method initializes 100 * 98 99 /** 100 * This method initializes 101 * 101 102 */ 102 103 public LayerPropertiesDialog(Vector<String> supportedCRS) { … … 105 106 initialize(); 106 107 } 107 108 108 109 109 110 /** 110 111 * This method initializes this 111 * 112 * 112 113 */ 113 114 private void initialize() { … … 115 116 this.setContentPane(getMainPanel()); 116 117 this.setPreferredSize(new Dimension(404, 485)); 117 118 } 119 120 /** 121 * This method initializes mainPanel 122 * 123 * @return javax.swing.JPanel 118 119 } 120 121 /** 122 * This method initializes mainPanel 123 * 124 * @return javax.swing.JPanel 124 125 */ 125 126 private JPanel getMainPanel() { … … 134 135 135 136 /** 136 * This method initializes jPanel 137 * 138 * @return javax.swing.JPanel 137 * This method initializes jPanel 138 * 139 * @return javax.swing.JPanel 139 140 */ 140 141 private JPanel getJPanel() { … … 155 156 156 157 /** 157 * This method initializes buttonPanel 158 * 159 * @return javax.swing.JPanel 158 * This method initializes buttonPanel 159 * 160 * @return javax.swing.JPanel 160 161 */ 161 162 private JPanel getButtonPanel() { … … 170 171 171 172 /** 172 * This method initializes jTabbedPane 173 * 174 * @return javax.swing.JTabbedPane 173 * This method initializes jTabbedPane 174 * 175 * @return javax.swing.JTabbedPane 175 176 */ 176 177 private JTabbedPane getJTabbedPane() { … … 184 185 185 186 /** 186 * This method initializes infoPanel 187 * 188 * @return javax.swing.JPanel 187 * This method initializes infoPanel 188 * 189 * @return javax.swing.JPanel 189 190 */ 190 191 private JPanel getInfoPanel() { … … 226 227 crsValueLabel = new JLabel(); 227 228 crsValueLabel.setBounds(new Rectangle(150, 150, 226, 16)); 228 229 229 230 String crsDescription = ""; 230 231 try { … … 233 234 } 234 235 crsValueLabel.setText(crsDescription + "(" + imageLayer.getBbox().getCoordinateReferenceSystem().getName().toString() + ")"); 235 236 236 237 crsLabel = new JLabel(); 237 238 crsLabel.setBounds(new Rectangle(15, 150, 118, 16)); … … 281 282 282 283 /** 283 * This method initializes crsPanel 284 * 285 * @return javax.swing.JPanel 284 * This method initializes crsPanel 285 * 286 * @return javax.swing.JPanel 286 287 */ 287 288 private JPanel getCrsPanel() { … … 295 296 } 296 297 currentCRSValueLabel.setText(crsDescription); 297 298 298 299 currentCRSLabel = new JLabel(); 299 300 currentCRSLabel.setBounds(new Rectangle(15, 33, 52, 16)); … … 339 340 340 341 /** 341 * This method initializes okButton 342 * 343 * @return javax.swing.JButton 342 * This method initializes okButton 343 * 344 * @return javax.swing.JButton 344 345 */ 345 346 private JButton getOkButton() { … … 349 350 okButton.setText("OK"); 350 351 okButton.addActionListener(new java.awt.event.ActionListener() { 351 public void actionPerformed(java.awt.event.ActionEvent e) { 352 352 @Override 353 public void actionPerformed(java.awt.event.ActionEvent e) { 354 353 355 setVisible(false); 354 356 dispose(); … … 360 362 361 363 /** 362 * This method initializes searchField 363 * 364 * @return javax.swing.JTextField 364 * This method initializes searchField 365 * 366 * @return javax.swing.JTextField 365 367 */ 366 368 private JTextField getSearchField() { … … 370 372 searchField.setToolTipText("Enter keywords or EPSG codes"); 371 373 searchField.addKeyListener(new java.awt.event.KeyAdapter() { 372 public void keyTyped(java.awt.event.KeyEvent e) { 373 374 @Override 375 public void keyTyped(java.awt.event.KeyEvent e) { 376 374 377 for (Iterator<String> iterator = supportedCRS.iterator(); iterator.hasNext();) { 375 String type = (String)iterator.next();378 String type = iterator.next(); 376 379 if (type.contains(searchField.getText())) { 377 380 crsJList.setSelectedIndex(supportedCRS.indexOf(type)); … … 379 382 break; 380 383 } 381 384 382 385 } 383 386 } … … 388 391 389 392 /** 390 * This method initializes crsListScrollPane 391 * 392 * @return javax.swing.JScrollPane 393 * This method initializes crsListScrollPane 394 * 395 * @return javax.swing.JScrollPane 393 396 */ 394 397 private JScrollPane getCrsListScrollPane() { … … 402 405 403 406 /** 404 * This method initializes crsJList 405 * 406 * @return javax.swing.JList 407 * This method initializes crsJList 408 * 409 * @return javax.swing.JList 407 410 */ 408 411 private JList<String> getCrsJList() { … … 415 418 416 419 /** 417 * This method initializes useDefaultCRSButton 418 * 419 * @return javax.swing.JButton 420 * This method initializes useDefaultCRSButton 421 * 422 * @return javax.swing.JButton 420 423 */ 421 424 private JButton getUseDefaultCRSButton() { … … 425 428 useDefaultCRSButton.setText("Apply Default"); 426 429 useDefaultCRSButton.addActionListener(new java.awt.event.ActionListener() { 427 public void actionPerformed(java.awt.event.ActionEvent e) { 428 430 @Override 431 public void actionPerformed(java.awt.event.ActionEvent e) { 432 429 433 try { 430 434 431 435 setCursor(new Cursor(Cursor.WAIT_CURSOR)); 432 436 if(PluginOperations.defaultSourceCRS != null){ … … 436 440 JOptionPane.showMessageDialog(getContentPane(), "<html>No default reference system available.<br>Please select one from the list</html>"); 437 441 } 438 442 439 443 } catch (NoSuchAuthorityCodeException e1) { 440 444 // TODO Auto-generated catch block … … 457 461 458 462 /** 459 * This method initializes applySelectedCRSButton 460 * 461 * @return javax.swing.JButton 463 * This method initializes applySelectedCRSButton 464 * 465 * @return javax.swing.JButton 462 466 */ 463 467 private JButton getApplySelectedCRSButton() { … … 469 473 applySelectedCRSButton.setText("<html>Apply<br>Selection</html>"); 470 474 applySelectedCRSButton.addActionListener(new java.awt.event.ActionListener() { 471 public void actionPerformed(java.awt.event.ActionEvent e) { 472 473 String selection = (String) crsJList.getSelectedValue(); 475 @Override 476 public void actionPerformed(java.awt.event.ActionEvent e) { 477 478 String selection = crsJList.getSelectedValue(); 474 479 String code = selection.substring(selection.indexOf("[-") + 2, selection.indexOf("-]")); 475 480 476 481 CoordinateReferenceSystem newRefSys = null; 477 482 try { 478 483 newRefSys = CRS.decode(code, eastingFirstCheckBox.isSelected()); 479 484 480 485 setCursor(new Cursor(Cursor.WAIT_CURSOR)); 481 486 482 487 imageLayer.resample(newRefSys); 483 488 … … 495 500 setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 496 501 } 497 498 502 503 499 504 } 500 505 }); … … 504 509 505 510 /** 506 * This method initializes setSelectedCRSAsDefaultButton 507 * 508 * @return javax.swing.JButton 511 * This method initializes setSelectedCRSAsDefaultButton 512 * 513 * @return javax.swing.JButton 509 514 */ 510 515 private JButton getSetSelectedCRSAsDefaultButton() { … … 515 520 setSelectedCRSAsDefaultButton 516 521 .addActionListener(new java.awt.event.ActionListener() { 517 public void actionPerformed(java.awt.event.ActionEvent e) { 518 522 @Override 523 public void actionPerformed(java.awt.event.ActionEvent e) { 524 519 525 if(crsJList.getSelectedValue() != null){ 520 String selection = (String)crsJList.getSelectedValue();526 String selection = crsJList.getSelectedValue(); 521 527 String code = selection.substring(selection.indexOf("[-") + 2, selection.indexOf("-]")); 522 528 523 529 try { 524 530 PluginOperations.defaultSourceCRS = CRS.decode(code, eastingFirstCheckBox.isSelected()); 525 531 PluginOperations.defaultSourceCRSDescription = selection; 526 532 527 533 ImportImagePlugin.pluginProps.setProperty("default_crs_eastingfirst", "" + eastingFirstCheckBox.isSelected()); 528 534 ImportImagePlugin.pluginProps.setProperty("default_crs_srid", code); 529 FileWriter fileWriter = new FileWriter(new File(ImportImagePlugin.PLUGINPROPERTIES_PATH));530 ImportImagePlugin.pluginProps.store(fileWriter, null);531 fileWriter.close();532 535 try (FileWriter fileWriter = new FileWriter(new File(ImportImagePlugin.PLUGINPROPERTIES_PATH))) { 536 ImportImagePlugin.pluginProps.store(fileWriter, null); 537 } 538 533 539 defaultCRSLabel.setText(selection); 534 535 } catch (IOException e2) { 536 // TODO Auto-generated catch block 537 e2.printStackTrace(); 538 } catch (NoSuchAuthorityCodeException e3) { 539 // TODO Auto-generated catch block 540 e3.printStackTrace(); 541 } catch (FactoryException e4) { 542 // TODO Auto-generated catch block 543 e4.printStackTrace(); 540 541 } catch (IOException | FactoryException e2) { 542 Main.error(e2); 544 543 } 545 } else{544 } else { 546 545 JOptionPane.showMessageDialog(getContentPane(), "Please make a selection from the list."); 547 546 } 548 549 550 547 } 551 548 }); … … 553 550 return setSelectedCRSAsDefaultButton; 554 551 } 555 556 /** 557 * This method initializes eastingFirstCheckBox 558 * 559 * @return javax.swing.JCheckBox 552 553 /** 554 * This method initializes eastingFirstCheckBox 555 * 556 * @return javax.swing.JCheckBox 560 557 */ 561 558 private JCheckBox getEastingFirstCheckBox() { … … 568 565 } 569 566 570 571 567 568 572 569 /** 573 570 * Listener setting text in the search field if selection has changed. … … 575 572 */ 576 573 class ListSelectionHandler implements ListSelectionListener { 577 public void valueChanged(ListSelectionEvent e) { 574 @Override 575 public void valueChanged(ListSelectionEvent e) { 578 576 if(e.getValueIsAdjusting()) 579 577 { -
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/PluginOperations.java
r30737 r30738 296 296 logger.debug("Loading .prj file: " + prjFile.getAbsolutePath()); 297 297 298 StringBuilder sb = new StringBuilder(); 299 String content = null; 300 BufferedReader br = new BufferedReader(new FileReader(prjFile)); 301 while((content = br.readLine()) != null) 302 { 303 sb.append(content); 304 } 305 br.close(); 306 try { 298 try (BufferedReader br = new BufferedReader(new FileReader(prjFile))) { 299 StringBuilder sb = new StringBuilder(); 300 String content = null; 301 while((content = br.readLine()) != null) { 302 sb.append(content); 303 } 307 304 refSys = CRS.parseWKT(sb.toString().trim()); 308 305 } catch (FactoryException e) {
Note:
See TracChangeset
for help on using the changeset viewer.