Ignore:
Timestamp:
2016-10-05T23:02:54+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/ImportImagePlugin
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ImportImagePlugin/.project

    r32286 r33028  
    1616                        </arguments>
    1717                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
    1823        </buildSpec>
    1924        <natures>
    2025                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2127        </natures>
    2228</projectDescription>
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java

    r31746 r33028  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.ImportImagePlugin;
    23
     
    6667    /**
    6768     * Constructor
    68      *
    69      * @param file
    70      * @throws IOException
    7169     */
    7270    public ImageLayer(File file) throws IOException {
     
    8078    /**
    8179     * create spatial referenced image.
    82      *
    83      * @return
    84      * @throws IOException
    8580     */
    8681    private Image createImage() throws IOException {
     
    9792
    9893        } catch (FactoryException e) {
    99             logger.error("Error while creating GridCoverage:",e);
     94            logger.error("Error while creating GridCoverage:", e);
    10095            throw new IOException(e.getMessage());
    10196        } catch (Exception e) {
    102             if(e.getMessage().contains("No projection file found"))
    103             {
    104                 ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"), new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")});
     97            if (e.getMessage().contains("No projection file found")) {
     98                ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"),
     99                    new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")});
     100                // CHECKSTYLE.OFF: LineLength
    105101                ex.setContent(tr("No projection file (.prj) found.<br>"
    106                         + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>"
    107                         + "(It can be changed later from the right click menu of the image layer.)",
    108                         ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode()));
     102                    + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>"
     103                    + "(It can be changed later from the right click menu of the image layer.)",
     104                    ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode()));
     105                // CHECKSTYLE.ON: LineLength
    109106                ex.showDialog();
    110107                int val = ex.getValue();
     
    128125                    }
    129126                } catch (Exception e1) {
    130                     logger.error("Error while creating GridCoverage:",e1);
     127                    logger.error("Error while creating GridCoverage:", e1);
    131128                    throw new IOException(e1);
    132129                }
    133             }
    134             else
    135             {
    136                 logger.error("Error while creating GridCoverage:",e);
     130            } else {
     131                logger.error("Error while creating GridCoverage:", e);
    137132                throw new IOException(e);
    138133            }
     
    267262    @Override
    268263    public String getToolTipText() {
    269         // TODO Auto-generated method stub
    270264        return this.getName();
    271265    }
    272 
    273266
    274267    public File getImageFile() {
     
    283276     * loads the image and reprojects it using a transformation
    284277     * calculated by the new reference system.
    285      *
    286      * @param newRefSys
    287      * @throws IOException
    288      * @throws FactoryException
    289      * @throws NoSuchAuthorityCodeException
    290      */
    291     void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException, FactoryException
    292     {
     278     */
     279    void resample(CoordinateReferenceSystem refSys) throws IOException, NoSuchAuthorityCodeException, FactoryException {
    293280        logger.debug("resample");
    294         GridCoverage2D coverage =  PluginOperations.createGridFromFile(this.imageFile, refSys, true);
     281        GridCoverage2D coverage = PluginOperations.createGridFromFile(this.imageFile, refSys, true);
    295282        coverage = PluginOperations.reprojectCoverage(coverage, CRS.decode(Main.getProjection().toCode()));
    296283        this.bbox = coverage.getEnvelope2D();
    297         this.image = ((PlanarImage)coverage.getRenderedImage()).getAsBufferedImage();
     284        this.image = ((PlanarImage) coverage.getRenderedImage()).getAsBufferedImage();
    298285
    299286        upperLeft = new EastNorth(coverage.getEnvelope2D().x, coverage
     
    312299     *
    313300     */
    314     public class LayerPropertiesAction extends AbstractAction
    315     {
     301    public class LayerPropertiesAction extends AbstractAction {
    316302        public ImageLayer imageLayer;
    317303
    318         public LayerPropertiesAction(ImageLayer imageLayer){
     304        public LayerPropertiesAction(ImageLayer imageLayer) {
    319305            super(tr("Layer Properties"));
    320306            this.imageLayer = imageLayer;
     
    322308
    323309        public void actionPerformed(ActionEvent arg0) {
    324 
    325310            LayerPropertiesDialog layerProps = new LayerPropertiesDialog(imageLayer, PluginOperations.crsDescriptions);
    326             layerProps.setLocation(Main.parent.getWidth() / 4 , Main.parent.getHeight() / 4);
     311            layerProps.setLocation(Main.parent.getWidth() / 4, Main.parent.getHeight() / 4);
    327312            layerProps.setVisible(true);
    328313        }
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImageFileImporter.java

    r32402 r33028  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.ImportImagePlugin;
    23
     
    4041    @Override
    4142    public void importData(List<File> files, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
    42         if (null == files || files.isEmpty())  return;
     43        if (null == files || files.isEmpty()) return;
    4344
    4445        for (File file: files) {
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java

    r32402 r33028  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.ImportImagePlugin;
    23
     
    2930 *
    3031 */
    31 public class ImportImagePlugin extends Plugin{
     32public class ImportImagePlugin extends Plugin {
    3233
    3334    private static Logger logger;
     
    4344
    4445    // path constants
    45     static final String PLUGIN_DIR = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/";
    46     static final String PLUGINPROPERTIES_PATH = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/pluginProperties.properties";
    47     static final String PLUGINLIBRARIES_DIR = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/lib/";
     46    static final String PLUGIN_DIR =
     47            Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/";
     48    static final String PLUGINPROPERTIES_PATH =
     49            Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/pluginProperties.properties";
     50    static final String PLUGINLIBRARIES_DIR =
     51            Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/lib/";
    4852    static final String PLUGINPROPERTIES_FILENAME = "pluginProperties.properties";
    49     static final String LOGGING_PROPERTIES_FILEPATH = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/log4j.properties/";
     53    static final String LOGGING_PROPERTIES_FILEPATH =
     54            Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/log4j.properties/";
    5055
    5156    public Properties getPluginProps() {
     
    5661     * constructor
    5762     *
    58      * @param info
    5963     * @throws IOException if any I/O error occurs
    6064     */
    61     public ImportImagePlugin(PluginInformation info) throws IOException{
     65    public ImportImagePlugin(PluginInformation info) throws IOException {
    6266        super(info);
    6367
     
    7377
    7478            // If resources are available load properties from plugin directory
    75             if(pluginProps == null || pluginProps.isEmpty())
    76             {
     79            if (pluginProps == null || pluginProps.isEmpty()) {
    7780                pluginProps = new Properties();
    7881                pluginProps.load(new File(PLUGINPROPERTIES_PATH).toURI().toURL().openStream());
     
    103106     * Checks whether plugin resources are available.
    104107     * If not, start install procedure.
    105      *
    106      * @throws IOException
    107      */
    108     private void checkInstallation() throws IOException
    109     {
     108     */
     109    private void checkInstallation() throws IOException {
    110110        // check plugin resource state
    111111        boolean isInstalled = true;
    112         if(!new File(PLUGINPROPERTIES_PATH).exists()
     112        if (!new File(PLUGINPROPERTIES_PATH).exists()
    113113                || !new File(PLUGIN_DIR).exists()
    114114                || !new File(PLUGINLIBRARIES_DIR).exists())
     
    123123            // check if plugin directory exist
    124124            File pluginDir = new File(PLUGIN_DIR);
    125             if(!pluginDir.exists()){
     125            if (!pluginDir.exists()) {
    126126                Utils.mkDirs(pluginDir);
    127127            }
     
    129129            // check if "lib" directory exist
    130130            File libDir = new File(PLUGINLIBRARIES_DIR);
    131             if(!libDir.exists()){
     131            if (!libDir.exists()) {
    132132                Utils.mkDirs(libDir);
    133133            }
     
    136136            if (pluginProps == null || pluginProps.isEmpty()) {
    137137                try (FileWriter fw = new FileWriter(new File(PLUGINPROPERTIES_PATH))) {
    138                         URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME);
    139                         pluginProps = new Properties();
    140                         pluginProps.load(propertiesURL.openStream());
    141                         pluginProps.store(fw, null);
     138                    URL propertiesURL = pluginClassLoader.getResource("resources/" + PLUGINPROPERTIES_FILENAME);
     139                    pluginProps = new Properties();
     140                    pluginProps.load(propertiesURL.openStream());
     141                    pluginProps.store(fw, null);
    142142                }
    143143                logger.debug("Plugin properties loaded");
     
    146146            if (!new File(LOGGING_PROPERTIES_FILEPATH).exists()) {
    147147                try (FileWriter fw = new FileWriter(new File(LOGGING_PROPERTIES_FILEPATH))) {
    148                         URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties");
    149                         Properties loggingProps = new Properties();
    150                         loggingProps.load(propertiesURL.openStream());
    151                         loggingProps.store(fw, null);
     148                    URL propertiesURL = pluginClassLoader.getResource("resources/log4j.properties");
     149                    Properties loggingProps = new Properties();
     150                    loggingProps.load(propertiesURL.openStream());
     151                    loggingProps.store(fw, null);
    152152                }
    153153                logger.debug("Logging properties created");
     
    160160    /**
    161161     * Initialize logger using plugin classloader.
    162      *
    163      * @param cl
    164162     */
    165163    private void initializeLogger(ClassLoader cl) {
     
    207205    /**
    208206     * get a plugin-specific classloader.
    209      *
    210      * @return
    211      * @throws MalformedURLException
    212      */
    213     private ClassLoader createPluginClassLoader() throws MalformedURLException
    214     {
     207     */
     208    private ClassLoader createPluginClassLoader() throws MalformedURLException {
    215209        ClassLoader loader = null;
    216210        loader = URLClassLoader.newInstance(
    217                 new URL[] { new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()},
     211                new URL[] {new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()},
    218212                ImportImagePlugin.class.getClassLoader()
    219213                );
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LayerPropertiesDialog.java

    r30738 r33028  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.ImportImagePlugin;
     3
    24import java.awt.Cursor;
    35import java.awt.Dimension;
     
    4244 *
    4345 */
    44 public class LayerPropertiesDialog extends JFrame{
     46public class LayerPropertiesDialog extends JFrame {
    4547
    4648    private Vector<String> supportedCRS;
     
    194196            lowerRightValueLabel.setBounds(new Rectangle(210, 315, 134, 16));
    195197            lowerRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    196             lowerRightValueLabel.setText((float)imageLayer.getBbox().getMinX() + ", " + (float)imageLayer.getBbox().getMaxY());
     198            lowerRightValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMaxY());
    197199            lowerLeftValueLabel = new JLabel();
    198200            lowerLeftValueLabel.setBounds(new Rectangle(30, 315, 133, 16));
    199201            lowerLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT);
    200             lowerLeftValueLabel.setText((float)imageLayer.getBbox().getMinX() + ", " + (float)imageLayer.getBbox().getMinY());
     202            lowerLeftValueLabel.setText((float) imageLayer.getBbox().getMinX() + ", " + (float) imageLayer.getBbox().getMinY());
    201203            upperRightValueLabel = new JLabel();
    202204            upperRightValueLabel.setBounds(new Rectangle(210, 255, 138, 16));
    203205            upperRightValueLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    204             upperRightValueLabel.setText((float)imageLayer.getBbox().getMaxX() + ", " + (float)imageLayer.getBbox().getMaxY());
     206            upperRightValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMaxY());
    205207            upperLeftValueLabel = new JLabel();
    206208            upperLeftValueLabel.setBounds(new Rectangle(30, 255, 133, 16));
    207209            upperLeftValueLabel.setHorizontalAlignment(SwingConstants.LEFT);
    208             upperLeftValueLabel.setText((float)imageLayer.getBbox().getMaxX() + ", " + (float)imageLayer.getBbox().getMinY());
     210            upperLeftValueLabel.setText((float) imageLayer.getBbox().getMaxX() + ", " + (float) imageLayer.getBbox().getMinY());
    209211            lowerRightLabel = new JLabel();
    210212            lowerRightLabel.setBounds(new Rectangle(287, 344, 74, 16));
     
    232234                crsDescription = imageLayer.getBbox().getCoordinateReferenceSystem().getIdentifiers().iterator().next().toString();
    233235            } catch (Exception e) {
     236                Main.debug(e);
    234237            }
    235238            crsValueLabel.setText(crsDescription + "(" + imageLayer.getBbox().getCoordinateReferenceSystem().getName().toString() + ")");
     
    294297                crsDescription = imageLayer.getSourceRefSys().getIdentifiers().iterator().next().toString();
    295298            } catch (Exception e) {
     299                Main.debug(e);
    296300            }
    297301            currentCRSValueLabel.setText(crsDescription);
     
    351355            okButton.addActionListener(new java.awt.event.ActionListener() {
    352356                @Override
    353                                 public void actionPerformed(java.awt.event.ActionEvent e) {
    354 
     357        public void actionPerformed(java.awt.event.ActionEvent e) {
    355358                    setVisible(false);
    356359                    dispose();
     
    373376            searchField.addKeyListener(new java.awt.event.KeyAdapter() {
    374377                @Override
    375                                 public void keyTyped(java.awt.event.KeyEvent e) {
     378                public void keyTyped(java.awt.event.KeyEvent e) {
    376379
    377380                    for (Iterator<String> iterator = supportedCRS.iterator(); iterator.hasNext();) {
     
    429432            useDefaultCRSButton.addActionListener(new java.awt.event.ActionListener() {
    430433                @Override
    431                                 public void actionPerformed(java.awt.event.ActionEvent e) {
    432 
     434        public void actionPerformed(java.awt.event.ActionEvent e) {
    433435                    try {
    434436
    435437                        setCursor(new Cursor(Cursor.WAIT_CURSOR));
    436                         if(PluginOperations.defaultSourceCRS != null){
     438                        if (PluginOperations.defaultSourceCRS != null) {
    437439                            imageLayer.resample(PluginOperations.defaultSourceCRS);
    438                         }else
    439                         {
    440                             JOptionPane.showMessageDialog(getContentPane(), "<html>No default reference system available.<br>Please select one from the list</html>");
     440                        } else {
     441                            JOptionPane.showMessageDialog(getContentPane(),
     442                                    "<html>No default reference system available.<br>Please select one from the list</html>");
    441443                        }
    442444
     
    450452                        // TODO Auto-generated catch block
    451453                        e2.printStackTrace();
    452                     }
    453                     finally{
     454                    } finally {
    454455                        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    455456                    }
     
    474475            applySelectedCRSButton.addActionListener(new java.awt.event.ActionListener() {
    475476                @Override
    476                                 public void actionPerformed(java.awt.event.ActionEvent e) {
     477        public void actionPerformed(java.awt.event.ActionEvent e) {
    477478
    478479                    String selection = crsJList.getSelectedValue();
     
    496497                        // TODO Auto-generated catch block
    497498                        e2.printStackTrace();
    498                     }
    499                     finally{
     499                    } finally {
    500500                        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    501501                    }
    502 
    503 
    504502                }
    505503            });
     
    521519                    .addActionListener(new java.awt.event.ActionListener() {
    522520                        @Override
    523                                                 public void actionPerformed(java.awt.event.ActionEvent e) {
    524 
    525                             if(crsJList.getSelectedValue() != null){
     521                        public void actionPerformed(java.awt.event.ActionEvent e) {
     522
     523                            if (crsJList.getSelectedValue() != null) {
    526524                                String selection = crsJList.getSelectedValue();
    527525                                String code = selection.substring(selection.indexOf("[-") + 2, selection.indexOf("-]"));
     
    531529                                    PluginOperations.defaultSourceCRSDescription = selection;
    532530
    533                                     ImportImagePlugin.pluginProps.setProperty("default_crs_eastingfirst", "" + eastingFirstCheckBox.isSelected());
     531                                    ImportImagePlugin.pluginProps.setProperty("default_crs_eastingfirst",
     532                                            "" + eastingFirstCheckBox.isSelected());
    534533                                    ImportImagePlugin.pluginProps.setProperty("default_crs_srid", code);
    535534                                    try (FileWriter fileWriter = new FileWriter(new File(ImportImagePlugin.PLUGINPROPERTIES_PATH))) {
    536                                         ImportImagePlugin.pluginProps.store(fileWriter, null);
     535                                        ImportImagePlugin.pluginProps.store(fileWriter, null);
    537536                                    }
    538537
     
    565564    }
    566565
    567 
    568 
    569566    /**
    570567     * Listener setting text in the search field if selection has changed.
     
    573570    class ListSelectionHandler implements ListSelectionListener {
    574571        @Override
    575                 public void valueChanged(ListSelectionEvent e) {
    576             if(e.getValueIsAdjusting())
    577             {
     572        public void valueChanged(ListSelectionEvent e) {
     573            if (e.getValueIsAdjusting()) {
    578574                searchField.setText(supportedCRS.get(e.getLastIndex()));
    579575                searchField.setEditable(true);
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/LoadImageAction.java

    r32402 r33028  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.ImportImagePlugin;
    23
     
    2930     */
    3031    public LoadImageAction() {
    31         super(tr("Import image"), (String)null, tr("Import georeferenced image"), null, true, "importimage/loadimage", true);
     32        super(tr("Import image"), (String) null, tr("Import georeferenced image"), null, true, "importimage/loadimage", true);
    3233    }
    3334
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/PluginOperations.java

    r31751 r33028  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.ImportImagePlugin;
    23
     
    3940 *
    4041 */
    41 public class PluginOperations {
     42public final class PluginOperations {
    4243
    4344    private static final Logger logger = Logger.getLogger(PluginOperations.class);
     
    5152    static String defaultSourceCRSDescription;
    5253
    53 
    54 
    55     public static enum SUPPORTEDIMAGETYPES {
     54    public enum SUPPORTEDIMAGETYPES {
    5655        tiff, tif, jpg, jpeg, bmp, png
    5756    }
    5857
    59     public static enum POSTFIXES_WORLDFILE {
     58    public enum POSTFIXES_WORLDFILE {
    6059        wld, jgw, jpgw, pgw, pngw, tfw, tifw, bpw, bmpw,
    61     };
     60    }
     61   
     62    private PluginOperations() {
     63        // Hide default constructor for utilities classes
     64    }
    6265
    6366    /**
    6467     * Reprojects a GridCoverage to a given CRS.
    65      *
    66      * @param coverage
    67      * @param targetCrs
    68      * @return destination
    69      * @throws FactoryException
    70      * @throws NoSuchAuthorityCodeException
    7168     */
    7269    public static GridCoverage2D reprojectCoverage(GridCoverage2D coverage,
     
    9289    /**
    9390     * Creates a org.geotools.coverage.grid.GridCoverage2D from a given file.
    94      *
    95      * @param file
    96      * @return
    97      * @throws IOException
    98      * @throws Exception
    9991     */
    10092    public static GridCoverage2D createGridFromFile(File file, CoordinateReferenceSystem refSys, boolean failIfNoPrjFile) throws IOException {
     
    111103
    112104        /*------- switch for file type -----------*/
    113         if (extension.equalsIgnoreCase(".tif") || extension.equalsIgnoreCase(".tiff"))
    114         {
     105        if (extension.equalsIgnoreCase(".tif") || extension.equalsIgnoreCase(".tiff")) {
    115106
    116107            // try to read GeoTIFF:
     
    119110                return coverage;
    120111            } catch (DataSourceException dse) {
    121                 if (!dse.getMessage().contains("Coordinate Reference System is not available")){
     112                if (!dse.getMessage().contains("Coordinate Reference System is not available")) {
    122113                    dse.printStackTrace();
    123114                }
     
    133124            for (int i = 0; i < postfixes.length; i++) {
    134125                File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
    135                 if (prjFile.exists()){
     126                if (prjFile.exists()) {
    136127                    tfwReader = new WorldFileReader(prjFile);
    137128                }
     
    162153            double lowerLeft_y = tfwReader.getYULC() - height;
    163154            Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height));
    164 
    165155            coverage = createGridCoverage(img, bbox, refSys);
    166         }
    167         //
    168         else if (extension.equalsIgnoreCase(".jpg")
    169                 || extension.equalsIgnoreCase(".jpeg"))
    170         {
     156
     157        } else if (extension.equalsIgnoreCase(".jpg")
     158                || extension.equalsIgnoreCase(".jpeg")) {
    171159            String[] postfixes = {"wld", "jgw", "jpgw"};
    172160            // try to read Worldfile:
     
    174162            for (int i = 0; i < postfixes.length; i++) {
    175163                File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
    176                 if (prjFile.exists()){
     164                if (prjFile.exists()) {
    177165                    tfwReader = new WorldFileReader(prjFile);
    178166                }
     
    197185            double lowerLeft_y = tfwReader.getYULC() - height;
    198186            Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height));
    199 
    200187            coverage = createGridCoverage(img, bbox, refSys);
    201         }
    202         else if(extension.equalsIgnoreCase(".bmp"))
    203         {
     188
     189        } else if (extension.equalsIgnoreCase(".bmp")) {
    204190            String[] postfixes = {"wld", "bmpw", "bpw"};
    205191            // try to read Worldfile:
     
    207193            for (int i = 0; i < postfixes.length; i++) {
    208194                File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
    209                 if (prjFile.exists()){
     195                if (prjFile.exists()) {
    210196                    tfwReader = new WorldFileReader(prjFile);
    211197                }
     
    230216            double lowerLeft_y = tfwReader.getYULC() - height;
    231217            Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height));
    232 
    233218            coverage = createGridCoverage(img, bbox, refSys);
    234         }
    235         else if(extension.equalsIgnoreCase(".png"))
    236         {
     219
     220        } else if (extension.equalsIgnoreCase(".png")) {
    237221
    238222            String[] postfixes = {"wld", "pgw", "pngw"};
     
    241225            for (int i = 0; i < postfixes.length; i++) {
    242226                File prjFile = new File(fileNameWithoutExt + "." + postfixes[i]);
    243                 if (prjFile.exists()){
     227                if (prjFile.exists()) {
    244228                    tfwReader = new WorldFileReader(prjFile);
    245229                }
    246230            }
    247             if(tfwReader == null) throw new IOException("No Worldfile found.");
     231            if (tfwReader == null) throw new IOException("No Worldfile found.");
    248232
    249233            if (refSys == null) {
     
    264248            double lowerLeft_y = tfwReader.getYULC() - height;
    265249            Envelope2D bbox = new Envelope2D(null, new Rectangle2D.Double(lowerLeft_x, lowerLeft_y, width, height));
    266 
    267250            coverage = createGridCoverage(img, bbox, refSys);
    268         }
    269         else{
     251
     252        } else {
    270253            throw new IOException("Image type not supported. Supported formats are: \n" +
    271254                    Arrays.toString(SUPPORTEDIMAGETYPES.values()));
     
    279262     * tries to parse it.
    280263     *
    281      *
    282264     * @param file image file, not the real world file (will be searched)
    283      * @return
    284      * @throws IOException
    285      */
    286     public static CoordinateReferenceSystem readPrjFile(File file) throws IOException
    287     {
    288 
     265     */
     266    public static CoordinateReferenceSystem readPrjFile(File file) throws IOException {
    289267        CoordinateReferenceSystem refSys = null;
    290268
     
    300278            StringBuilder sb = new StringBuilder();
    301279            String content = null;
    302             while((content = br.readLine()) != null) {
     280            while ((content = br.readLine()) != null) {
    303281                sb.append(content);
    304282            }
     
    313291    /**
    314292     * Method for external use.
    315      *
    316      * @param img
    317      * @param bbox
    318      * @param crs
    319      * @return
    320      */
    321     public static GridCoverage2D createGridCoverage(BufferedImage img, Envelope2D bbox, CoordinateReferenceSystem crs)
    322     {
     293     */
     294    public static GridCoverage2D createGridCoverage(BufferedImage img, Envelope2D bbox, CoordinateReferenceSystem crs) {
    323295        bbox.setCoordinateReferenceSystem(crs);
    324296        return new GridCoverageFactory().create("", img, bbox);
     
    328300     * Method for reading a GeoTIFF file.
    329301     *
    330      * @param file
    331302     * @param refSys if delivered, the coverage will be forced to use this crs
    332      * @return
    333      * @throws IOException
    334      * @throws FactoryException
    335      */
    336     public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException, FactoryException
    337     {
     303     */
     304    public static GridCoverage2D readGeoTiff(File file, CoordinateReferenceSystem refSys) throws IOException, FactoryException {
    338305        GridCoverage2D coverage = null;
    339306        Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true);
    340         if(refSys != null)
    341         {
     307        if (refSys != null) {
    342308            hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, refSys);
    343309        }
     
    354320    /**
    355321     * Loads CRS data from an EPSG database and creates descriptions for each one.
    356      *
    357      * @param pluginProps
    358      * @throws Exception
    359      */
    360     public static void loadCRSData(Properties pluginProps)
    361     {
     322     */
     323    public static void loadCRSData(Properties pluginProps) {
    362324        String defaultcrsString = pluginProps.getProperty("default_crs_srid");
    363325
     
    375337                String description = desc.toString() + " [-EPSG:" + string + "-]";
    376338                crsDescriptions.add(description);
    377                 if(defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)){
     339                if (defaultcrsString != null && defaultcrsString.equalsIgnoreCase("EPSG:" + string)) {
    378340                    boolean isEastingFirst = Boolean.valueOf(pluginProps.getProperty("default_crs_eastingfirst"));
    379341                    defaultSourceCRS = CRS.decode("EPSG:" + string, isEastingFirst);
  • applications/editors/josm/plugins/ImportImagePlugin/test/unit/org/openstreetmap/josm/plugins/ImportImagePlugin/GeoTiffReaderTest.java

    r32674 r33028  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.ImportImagePlugin;
    23
Note: See TracChangeset for help on using the changeset viewer.