Ignore:
Timestamp:
2016-07-02T03:55:03+02:00 (9 years ago)
Author:
donvip
Message:

checkstyle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java

    r30808 r32528  
     1// License: WTFPL. For details, see LICENSE file.
    12package iodb;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    25
    36import java.awt.event.ActionEvent;
     
    58import java.io.InputStream;
    69import java.io.UnsupportedEncodingException;
    7 import java.net.*;
    8 import java.util.*;
     10import java.net.URLEncoder;
     11import java.util.List;
     12
    913import javax.swing.Action;
    1014import javax.swing.Icon;
    1115import javax.swing.JOptionPane;
     16
    1217import org.openstreetmap.josm.Main;
    1318import org.openstreetmap.josm.actions.JosmAction;
     
    1621import org.openstreetmap.josm.data.projection.Projection;
    1722import org.openstreetmap.josm.gui.layer.ImageryLayer;
    18 import static org.openstreetmap.josm.tools.I18n.tr;
    1923import org.openstreetmap.josm.tools.ImageProvider;
    2024import org.openstreetmap.josm.tools.Shortcut;
     
    2226/**
    2327 * Download a list of imagery offsets for the current position, let user choose which one to use.
    24  * 
     28 *
    2529 * @author Zverik
    2630 * @license WTFPL
     
    2933    private Icon iconOffsetOk;
    3034    private Icon iconOffsetBad;
    31    
     35
    3236    /**
    3337     * Initialize the action. Sets "Ctrl+Alt+I" shortcut: the only shortcut in this plugin.
     
    3741        super(tr("Get Imagery Offset..."), "getoffset", tr("Download offsets for current imagery from a server"),
    3842                Shortcut.registerShortcut("imageryoffset:get", tr("Imagery: {0}", tr("Get Imagery Offset...")),
    39                 KeyEvent.VK_I, Shortcut.ALT_CTRL), true);
     43                        KeyEvent.VK_I, Shortcut.ALT_CTRL), true);
    4044        iconOffsetOk = new ImageProvider("getoffset").setSize(ImageProvider.ImageSizes.MENU).get();
    4145        iconOffsetBad = new ImageProvider("getoffsetnow").setSize(ImageProvider.ImageSizes.MENU).get();
     
    4650     * The action just executes {@link DownloadOffsetsTask}.
    4751     */
     52    @Override
    4853    public void actionPerformed(ActionEvent e) {
    49         if( Main.map == null || Main.map.mapView == null || !Main.map.isVisible() )
     54        if (Main.map == null || Main.map.mapView == null || !Main.map.isVisible())
    5055            return;
    5156        Projection proj = Main.map.mapView.getProjection();
     
    5358        ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
    5459        String imagery = ImageryOffsetTools.getImageryID(layer);
    55         if( imagery == null )
     60        if (imagery == null)
    5661            return;
    57        
     62
    5863        DownloadOffsetsTask download = new DownloadOffsetsTask(center, layer, imagery);
    5964        Main.worker.submit(download);
     
    6772    protected void updateEnabledState() {
    6873        boolean state = true;
    69         if( Main.map == null || Main.map.mapView == null || !Main.map.isVisible() )
     74        if (Main.map == null || Main.map.mapView == null || !Main.map.isVisible())
    7075            state = false;
    7176        ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
    72         if( ImageryOffsetTools.getImageryID(layer) == null )
     77        if (ImageryOffsetTools.getImageryID(layer) == null)
    7378            state = false;
    7479        setEnabled(state);
    7580    }
    76    
     81
    7782    /**
    7883     * Display a dialog for choosing between offsets. If there are no offsets in
     
    8085     * @param offsets List of offset objects to choose from.
    8186     */
    82     private void showOffsetDialog( List<ImageryOffsetBase> offsets ) {
    83         if( offsets.isEmpty() ) {
     87    private void showOffsetDialog(List<ImageryOffsetBase> offsets) {
     88        if (offsets.isEmpty()) {
    8489            JOptionPane.showMessageDialog(Main.parent,
    8590                    tr("No data for this region. Please adjust imagery layer and upload an offset."),
     
    8893        }
    8994        OffsetDialog offsetDialog = new OffsetDialog(offsets);
    90         if( offsetDialog.showDialog() != null )
     95        if (offsetDialog.showDialog() != null)
    9196            offsetDialog.applyOffset();
    9297    }
     
    95100     * Update action icon based on an offset state.
    96101     */
    97     public void offsetStateChanged( boolean isOffsetGood ) {
     102    @Override
     103    public void offsetStateChanged(boolean isOffsetGood) {
    98104        putValue(Action.SMALL_ICON, isOffsetGood ? iconOffsetOk : iconOffsetBad);
    99105    }
     
    122128         * @param imagery Imagery ID for the layer.
    123129         */
    124         public DownloadOffsetsTask( LatLon center, ImageryLayer layer, String imagery ) {
     130        DownloadOffsetsTask(LatLon center, ImageryLayer layer, String imagery) {
    125131            super(null, tr("Loading imagery offsets..."));
    126132            try {
    127133                String query = "get?lat=" + center.latToString(CoordinateFormat.DECIMAL_DEGREES)
    128                         + "&lon=" + center.lonToString(CoordinateFormat.DECIMAL_DEGREES)
    129                         + "&imagery=" + URLEncoder.encode(imagery, "UTF8");
     134                + "&lon=" + center.lonToString(CoordinateFormat.DECIMAL_DEGREES)
     135                + "&imagery=" + URLEncoder.encode(imagery, "UTF8");
    130136                int radius = Main.pref.getInteger("iodb.radius", -1);
    131                 if( radius > 0 )
     137                if (radius > 0)
    132138                    query = query + "&radius=" + radius;
    133139                setQuery(query);
    134             } catch( UnsupportedEncodingException e ) {
     140            } catch (UnsupportedEncodingException e) {
    135141                throw new IllegalArgumentException(e);
    136142            }
     
    142148        @Override
    143149        protected void afterFinish() {
    144             if( !cancelled && offsets != null )
     150            if (!cancelled && offsets != null)
    145151                showOffsetDialog(offsets);
    146152        }
    147        
     153
    148154        /**
    149155         * Parses the response with {@link IODBReader}.
     
    152158         */
    153159        @Override
    154         protected void processResponse( InputStream inp ) throws UploadException {
     160        protected void processResponse(InputStream inp) throws UploadException {
    155161            offsets = null;
    156162            try {
    157163                offsets = new IODBReader(inp).parse();
    158             } catch( Exception e ) {
     164            } catch (Exception e) {
    159165                throw new UploadException(tr("Error processing XML response: {0}", e.getMessage()));
    160166            }
Note: See TracChangeset for help on using the changeset viewer.