Ignore:
Timestamp:
2016-08-20T03:01:04+02:00 (8 years ago)
Author:
donvip
Message:

add Eclipse project, checkstyle

Location:
applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoAction.java

    r30833 r32844  
    1 /**
    2  *  PointInfo - plugin for JOSM
    3  *  Marian Kyral
    4  *
    5  *  This program is free software; you can redistribute it and/or modify
    6  *  it under the terms of the GNU General Public License as published by
    7  *  the Free Software Foundation; either version 2 of the License, or
    8  *  (at your option) any later version.
    9  *
    10  *  This program is distributed in the hope that it will be useful,
    11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *  GNU General Public License for more details.
    14  *
    15  *  You should have received a copy of the GNU General Public License along
    16  *  with this program; if not, write to the Free Software Foundation, Inc.,
    17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    18  */
     1// License: GPL. For details, see LICENSE file.
    192package org.openstreetmap.josm.plugins.pointinfo;
    203
    214import static org.openstreetmap.josm.tools.I18n.tr;
     5
    226import java.awt.Cursor;
    237import java.awt.Point;
     
    2711import java.awt.event.MouseEvent;
    2812import java.awt.event.MouseListener;
    29 // import java.awt.event.KeyListener;
    30 import java.util.ArrayList;
    31 import java.util.Collection;
    32 import java.util.LinkedList;
    33 import javax.swing.SwingConstants;
     13
     14import javax.swing.ImageIcon;
    3415import javax.swing.JEditorPane;
    3516import javax.swing.JOptionPane;
    3617import javax.swing.JScrollPane;
    37 import javax.swing.ImageIcon;
    3818import javax.swing.event.HyperlinkEvent;
    3919import javax.swing.event.HyperlinkListener;
     
    4121import org.openstreetmap.josm.Main;
    4222import org.openstreetmap.josm.actions.mapmode.MapMode;
    43 import org.openstreetmap.josm.command.AddCommand;
    44 import org.openstreetmap.josm.command.Command;
    45 import org.openstreetmap.josm.command.SequenceCommand;
    4623import org.openstreetmap.josm.data.coor.LatLon;
    47 import org.openstreetmap.josm.data.osm.Node;
    48 import org.openstreetmap.josm.data.osm.Way;
     24import org.openstreetmap.josm.gui.MapFrame;
    4925import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    5026import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    51 import org.openstreetmap.josm.gui.MapFrame;
    5227import org.openstreetmap.josm.tools.ImageProvider;
     28import org.openstreetmap.josm.tools.OpenBrowser;
    5329import org.openstreetmap.josm.tools.Shortcut;
    54 import org.openstreetmap.josm.tools.OpenBrowser;
    5530import org.xml.sax.SAXException;
    5631
     
    5833
    5934    private static final long serialVersionUID = 1L;
    60 
    6135
    6236    protected boolean cancel;
     
    6640    private String coordinatesText = "";
    6741
    68     public PointInfoAction(MapFrame mapFrame) {
    69         super(tr("Point info"), "info-sml", tr("Point info."), Shortcut.registerShortcut("tools:pointInfo", tr("Tool: {0}", tr("Point info")), KeyEvent.VK_X, Shortcut.CTRL_SHIFT), mapFrame, getCursor());
     42    PointInfoAction(MapFrame mapFrame) {
     43        super(tr("Point info"), "info-sml", tr("Point info."),
     44                Shortcut.registerShortcut("tools:pointInfo", tr("Tool: {0}", tr("Point info")), KeyEvent.VK_X, Shortcut.CTRL_SHIFT),
     45                mapFrame, getCursor());
    7046    }
    7147
     
    7854        Main.map.mapView.setCursor(getCursor());
    7955        Main.map.mapView.addMouseListener(this);
    80 
    8156    }
    8257
     
    10075        try {
    10176            PleaseWaitRunnable infoTask = new PleaseWaitRunnable(tr("Connecting server")) {
    102 
    10377                @Override
    10478                protected void realRun() throws SAXException {
     
    10882                @Override
    10983                protected void finish() {
    110 
    11184                }
    11285
    11386                @Override
    11487                protected void afterFinish() {
    115                   if (htmlText.length() > 0) {
    116 
    117                     // Show result
    118                     JEditorPane msgLabel = new JEditorPane("text/html", htmlText);
    119                     msgLabel.setEditable(false);
    120                     msgLabel.setOpaque(false);
    121                     msgLabel.addHyperlinkListener(new HyperlinkListener() {
    122                       public void hyperlinkUpdate(HyperlinkEvent hle) {
    123                         if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
    124                           if (hle.getURL() == null || hle.getURL().toString().isEmpty()) {
    125                             return;
     88                    if (htmlText.length() > 0) {
     89                        // Show result
     90                        JEditorPane msgLabel = new JEditorPane("text/html", htmlText);
     91                        msgLabel.setEditable(false);
     92                        msgLabel.setOpaque(false);
     93                        msgLabel.addHyperlinkListener(new HyperlinkListener() {
     94                            @Override
     95                            public void hyperlinkUpdate(HyperlinkEvent hle) {
     96                                if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
     97                                    if (hle.getURL() == null || hle.getURL().toString().isEmpty()) {
     98                                        return;
     99                                    }
     100                                    System.out.println("URL: "+ hle.getURL());
     101                                    if (!hle.getURL().toString().startsWith("http")) {
     102                                        mRuian.performAction(hle.getURL().toString());
     103                                    } else {
     104                                        String ret = OpenBrowser.displayUrl(hle.getURL().toString());
     105                                        if (ret != null) {
     106                                            PointInfoUtils.showNotification(ret, "error");
     107                                        }
     108                                    }
     109                                }
    126110                            }
    127                           System.out.println("URL: "+ hle.getURL());
    128                           if (! hle.getURL().toString().startsWith("http")) {
    129                             mRuian.performAction(hle.getURL().toString());
    130                           } else {
    131                             String ret = OpenBrowser.displayUrl(hle.getURL().toString());
    132                             if (ret != null) {
    133                               PointInfoUtils.showNotification(ret, "error");
    134                             }
    135                           }
    136                         }
    137                       }
    138                     });
    139                     JScrollPane scrollPane = new JScrollPane(msgLabel);
    140                     Object[] objects = {scrollPane};
    141                     final ImageIcon icon = new ImageIcon(getClass().getResource("/images/dialogs/info-sml.png"));
    142                     JOptionPane.showMessageDialog(
    143                       null, objects, tr("PointInfo") + " " + coordinatesText, JOptionPane.PLAIN_MESSAGE,icon);
    144                   }
     111                        });
     112                        JScrollPane scrollPane = new JScrollPane(msgLabel);
     113                        Object[] objects = {scrollPane};
     114                        final ImageIcon icon = new ImageIcon(getClass().getResource("/images/dialogs/info-sml.png"));
     115                        JOptionPane.showMessageDialog(
     116                                null, objects, tr("PointInfo") + " " + coordinatesText, JOptionPane.PLAIN_MESSAGE, icon);
     117                    }
    145118                }
    146119
     
    150123                }
    151124            };
    152             Thread executeInfoThread = new Thread(infoTask);
    153             executeInfoThread.start();
     125            new Thread(infoTask).start();
    154126        } catch (Exception e) {
    155127            e.printStackTrace();
     
    161133        progressMonitor.beginTask(null, 3);
    162134        try {
    163               mRuian.prepareData(pos);
    164               htmlText = mRuian.getHtml();
    165               coordinatesText = PointInfoUtils.formatCoordinates(pos.lat(), pos.lon());
     135            mRuian.prepareData(pos);
     136            htmlText = mRuian.getHtml();
     137            coordinatesText = PointInfoUtils.formatCoordinates(pos.lat(), pos.lon());
    166138
    167139        } finally {
     
    170142        progressMonitor.invalidate();
    171143        if (htmlText.length() == 0) {
    172           PointInfoUtils.showNotification(tr("Data not available.")+ "\n(" + pos.toDisplayString() + ")", "warning");
    173           return;
     144            PointInfoUtils.showNotification(tr("Data not available.")+ "\n(" + pos.toDisplayString() + ")", "warning");
     145            return;
    174146        }
    175147    }
     
    199171        updateKeyModifiers(e);
    200172        if (e.getButton() == MouseEvent.BUTTON1) {
    201           infoAsync(e.getPoint());
     173            infoAsync(e.getPoint());
    202174        }
    203175    }
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoPlugin.java

    r30328 r32844  
    1 /**
    2  *  PointInfo - plugin for JOSM
    3  *  Marián Kyral
    4  *
    5  *  This program is free software; you can redistribute it and/or modify
    6  *  it under the terms of the GNU General Public License as published by
    7  *  the Free Software Foundation; either version 2 of the License, or
    8  *  (at your option) any later version.
    9  *
    10  *  This program is distributed in the hope that it will be useful,
    11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *  GNU General Public License for more details.
    14  *
    15  *  You should have received a copy of the GNU General Public License along
    16  *  with this program; if not, write to the Free Software Foundation, Inc.,
    17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    18  */
    19 
     1// License: GPL. For details, see LICENSE file.
    202package org.openstreetmap.josm.plugins.pointinfo;
    21 
    22 import java.util.ArrayList;
    233
    244import org.openstreetmap.josm.Main;
    255import org.openstreetmap.josm.gui.MainMenu;
    26 // import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    276import org.openstreetmap.josm.plugins.Plugin;
    287import org.openstreetmap.josm.plugins.PluginInformation;
    298
    30 
    31 
    329/**
    3310 * This is the main class for the PointInfo plugin.
    34  *
    3511 */
    36 public class PointInfoPlugin extends Plugin{
     12public class PointInfoPlugin extends Plugin {
    3713
    38   public PointInfoPlugin(PluginInformation info) {
    39   super(info);
    40   MainMenu.add(Main.main.menu.moreToolsMenu, new PointInfoAction(Main.map));
    41 
    42 //     @Override
    43 //     public PreferenceSetting getPreferenceSetting() {
    44 //         return new PreferenceEditor();
     14    public PointInfoPlugin(PluginInformation info) {
     15        super(info);
     16        MainMenu.add(Main.main.menu.moreToolsMenu, new PointInfoAction(Main.map));
    4517    }
    4618}
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoServer.java

    r30328 r32844  
    1 /**
    2  *  PointInfo - plugin for JOSM
    3  *  Marian Kyral
    4  *
    5  *  This program is free software; you can redistribute it and/or modify
    6  *  it under the terms of the GNU General Public License as published by
    7  *  the Free Software Foundation; either version 2 of the License, or
    8  *  (at your option) any later version.
    9  *
    10  *  This program is distributed in the hope that it will be useful,
    11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *  GNU General Public License for more details.
    14  *
    15  *  You should have received a copy of the GNU General Public License along
    16  *  with this program; if not, write to the Free Software Foundation, Inc.,
    17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    18  */
    19 
     1// License: GPL. For details, see LICENSE file.
    202package org.openstreetmap.josm.plugins.pointinfo;
    213
     
    235import java.io.InputStreamReader;
    246import java.net.URL;
    25 import java.util.ArrayList;
    26 import org.openstreetmap.josm.data.coor.LatLon;
    277
    288public class PointInfoServer {
     
    4626            while ((line = reader.readLine()) != null) {
    4727                if (sb.length() == 0)
    48                   sb.append(line);
     28                    sb.append(line);
    4929                else
    50                   sb.append(" "+line);
     30                    sb.append(" "+line);
    5131            }
    5232            return sb.toString();
  • applications/editors/josm/plugins/pointInfo/src/org/openstreetmap/josm/plugins/pointinfo/PointInfoUtils.java

    r30328 r32844  
    1 /**
    2  *  PointInfo - plugin for JOSM
    3  *  Marian Kyral
    4  *
    5  *  This program is free software; you can redistribute it and/or modify
    6  *  it under the terms of the GNU General Public License as published by
    7  *  the Free Software Foundation; either version 2 of the License, or
    8  *  (at your option) any later version.
    9  *
    10  *  This program is distributed in the hope that it will be useful,
    11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *  GNU General Public License for more details.
    14  *
    15  *  You should have received a copy of the GNU General Public License along
    16  *  with this program; if not, write to the Free Software Foundation, Inc.,
    17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    18  */
    19 
     1// License: GPL. For details, see LICENSE file.
    202package org.openstreetmap.josm.plugins.pointinfo;
    213
    224import java.text.DecimalFormat;
    235import java.text.DecimalFormatSymbols;
     6
    247import javax.swing.JOptionPane;
    258
    269import org.openstreetmap.josm.gui.Notification;
    27 
    2810
    2911public abstract class PointInfoUtils {
     
    3416     * @param type Type if message (info, warning, error, plain).
    3517     */
    36     public static void showNotification (String message, String type) {
    37       Notification note = new Notification(message);
     18    public static void showNotification(String message, String type) {
     19        Notification note = new Notification(message);
    3820
    39       if (type.equals("info"))
    40         note.setIcon(JOptionPane.INFORMATION_MESSAGE);
    41       else if (type.equals("warning"))
    42         note.setIcon(JOptionPane.WARNING_MESSAGE);
    43       else if (type.equals("error"))
    44         note.setIcon(JOptionPane.ERROR_MESSAGE);
    45       else
    46         note.setIcon(JOptionPane.PLAIN_MESSAGE);
     21        if (type.equals("info"))
     22            note.setIcon(JOptionPane.INFORMATION_MESSAGE);
     23        else if (type.equals("warning"))
     24            note.setIcon(JOptionPane.WARNING_MESSAGE);
     25        else if (type.equals("error"))
     26            note.setIcon(JOptionPane.ERROR_MESSAGE);
     27        else
     28            note.setIcon(JOptionPane.PLAIN_MESSAGE);
    4729
    48       note.setDuration(Notification.TIME_SHORT);
    49       note.show();
     30        note.setDuration(Notification.TIME_SHORT);
     31        note.show();
    5032    }
    5133
     
    5638     * @return String coordinatesText
    5739     */
    58     public static String formatCoordinates (double lat, double lon) {
     40    public static String formatCoordinates(double lat, double lon) {
    5941
    60       String r = "";
    61       DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    62       symbols.setDecimalSeparator('.');
    63       symbols.setGroupingSeparator(' ');
    64       DecimalFormat df = new DecimalFormat("#.00000", symbols);
     42        String r = "";
     43        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
     44        symbols.setDecimalSeparator('.');
     45        symbols.setGroupingSeparator(' ');
     46        DecimalFormat df = new DecimalFormat("#.00000", symbols);
    6547
    66       r = "(" + df.format(lat) + ", " +
     48        r = "(" + df.format(lat) + ", " +
    6749                df.format(lon) + ")";
    68       return r;
     50        return r;
    6951    }
    70 
    7152}
Note: See TracChangeset for help on using the changeset viewer.