Changeset 32638 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-07-11T23:01:43+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/NanoLog
Files:
2 added
8 edited

Legend:

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

    r32286 r32638  
    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/NanoLog/build.xml

    r32329 r32638  
    55    <property name="commit.message" value="NanoLog"/>
    66    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    7     <property name="plugin.main.version" value="10279"/>
     7    <property name="plugin.main.version" value="10420"/>
    88    <property name="plugin.author" value="Ilya Zverev"/>
    99    <property name="plugin.class" value="nanolog.NanoLogPlugin"/>
  • applications/editors/josm/plugins/NanoLog/src/nanolog/Correlator.java

    r31981 r32638  
    2525 * @author zverik
    2626 */
    27 public class Correlator {
     27public final class Correlator {
     28
     29    private Correlator() {
     30        // Hide default constructor for utilities classes
     31    }
    2832
    2933    /**
    3034     * Matches entries to GPX so most points are on the trace.
    3135     */
    32     public static long crudeMatch( List<NanoLogEntry> entries, GpxData data ) {
     36    public static long crudeMatch(List<NanoLogEntry> entries, GpxData data) {
    3337        List<NanoLogEntry> sortedEntries = new ArrayList<>(entries);
    3438        Collections.sort(sortedEntries);
     
    3640        long firstGPXDate = -1;
    3741        outer:
    38         for( GpxTrack trk : data.tracks ) {
    39             for( GpxTrackSegment segment : trk.getSegments() ) {
    40                 for( WayPoint curWp : segment.getWayPoints() ) {
    41                     String curDateWpStr = (String)curWp.attr.get("time");
    42                     if( curDateWpStr == null ) {
     42        for (GpxTrack trk : data.tracks) {
     43            for (GpxTrackSegment segment : trk.getSegments()) {
     44                for (WayPoint curWp : segment.getWayPoints()) {
     45                    String curDateWpStr = (String) curWp.attr.get("time");
     46                    if (curDateWpStr == null) {
    4347                        continue;
    4448                    }
     
    4751                        firstGPXDate = DateUtils.fromString(curDateWpStr).getTime();
    4852                        break outer;
    49                     } catch( Exception e ) {
     53                    } catch (Exception e) {
    5054                        Main.warn(e);
    5155                    }
     
    5559
    5660        // No GPX timestamps found, exit
    57         if( firstGPXDate < 0 ) {
     61        if (firstGPXDate < 0) {
    5862            JOptionPane.showMessageDialog(Main.parent,
    5963                    tr("The selected GPX track does not contain timestamps. Please select another one."),
     
    6569    }
    6670
    67     public static void revertPos( List<NanoLogEntry> entries ) {
    68         for( NanoLogEntry entry : entries ) {
     71    public static void revertPos(List<NanoLogEntry> entries) {
     72        for (NanoLogEntry entry : entries) {
    6973            entry.setPos(entry.getBasePos());
    7074        }
     
    7377    /**
    7478     * Offset is in 1/1000 of a second.
    75      * @param entries
    76      * @param data
    77      * @param offset
    7879     */
    79     public static void correlate( List<NanoLogEntry> entries, GpxData data, long offset ) {
     80    public static void correlate(List<NanoLogEntry> entries, GpxData data, long offset) {
    8081        List<NanoLogEntry> sortedEntries = new ArrayList<>(entries);
    8182        //int ret = 0;
    8283        Collections.sort(sortedEntries);
    83         for( GpxTrack track : data.tracks ) {
    84             for( GpxTrackSegment segment : track.getSegments() ) {
     84        for (GpxTrack track : data.tracks) {
     85            for (GpxTrackSegment segment : track.getSegments()) {
    8586                long prevWpTime = 0;
    8687                WayPoint prevWp = null;
    8788
    88                 for( WayPoint curWp : segment.getWayPoints() ) {
    89 
    90                     String curWpTimeStr = (String)curWp.attr.get("time");
    91                     if( curWpTimeStr != null ) {
     89                for (WayPoint curWp : segment.getWayPoints()) {
     90
     91                    String curWpTimeStr = (String) curWp.attr.get("time");
     92                    if (curWpTimeStr != null) {
    9293                        try {
    9394                            long curWpTime = DateUtils.fromString(curWpTimeStr).getTime() + offset;
     
    9798                            prevWpTime = curWpTime;
    9899
    99                         } catch( UncheckedParseException e ) {
     100                        } catch (UncheckedParseException e) {
    100101                            Main.error("Error while parsing date \"" + curWpTimeStr + '"');
    101102                            Main.error(e);
     
    112113    }
    113114
    114     private static int matchPoints( List<NanoLogEntry> entries, WayPoint prevWp, long prevWpTime,
    115             WayPoint curWp, long curWpTime, long offset ) {
     115    private static int matchPoints(List<NanoLogEntry> entries, WayPoint prevWp, long prevWpTime,
     116            WayPoint curWp, long curWpTime, long offset) {
    116117        // Time between the track point and the previous one, 5 sec if first point, i.e. photos take
    117118        // 5 sec before the first track point can be assumed to be take at the starting position
     
    123124
    124125        // no photos match
    125         if( i < 0 )
     126        if (i < 0)
    126127            return 0;
    127128
    128129        Integer direction = null;
    129         if( prevWp != null ) {
     130        if (prevWp != null) {
    130131            direction = Long.valueOf(Math.round(180.0 / Math.PI * prevWp.getCoor().heading(curWp.getCoor()))).intValue();
    131132        }
     
    133134        // First trackpoint, then interval is set to five seconds, i.e. photos up to five seconds
    134135        // before the first point will be geotagged with the starting point
    135         if( prevWpTime == 0 || curWpTime <= prevWpTime ) {
    136             while( true ) {
    137                 if( i < 0 ) {
     136        if (prevWpTime == 0 || curWpTime <= prevWpTime) {
     137            while (true) {
     138                if (i < 0) {
    138139                    break;
    139140                }
    140141                final NanoLogEntry curImg = entries.get(i);
    141142                long time = curImg.getTime().getTime();
    142                 if( time > curWpTime || time < curWpTime - interval ) {
     143                if (time > curWpTime || time < curWpTime - interval) {
    143144                    break;
    144145                }
    145                 if( curImg.getPos() == null ) {
     146                if (curImg.getPos() == null) {
    146147                    curImg.setPos(curWp.getCoor());
    147148                    curImg.setDirection(direction);
     
    155156        // This code gives a simple linear interpolation of the coordinates between current and
    156157        // previous track point assuming a constant speed in between
    157         while( true ) {
    158             if( i < 0 ) {
     158        while (true) {
     159            if (i < 0) {
    159160                break;
    160161            }
    161162            NanoLogEntry curImg = entries.get(i);
    162163            long imgTime = curImg.getTime().getTime();
    163             if( imgTime < prevWpTime ) {
     164            if (imgTime < prevWpTime) {
    164165                break;
    165166            }
    166167
    167             if( curImg.getPos() == null && prevWp != null ) {
     168            if (curImg.getPos() == null && prevWp != null) {
    168169                // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless variable
    169                 double timeDiff = (double)(imgTime - prevWpTime) / interval;
     170                double timeDiff = (double) (imgTime - prevWpTime) / interval;
    170171                curImg.setPos(prevWp.getCoor().interpolate(curWp.getCoor(), timeDiff));
    171172                curImg.setDirection(direction);
     
    179180
    180181    private static int getLastIndexOfListBefore(List<NanoLogEntry> entries, long searchedTime) {
    181         int lstSize= entries.size();
     182        int lstSize = entries.size();
    182183
    183184        // No photos or the first photo taken is later than the search period
    184         if(lstSize == 0 || searchedTime < entries.get(0).getTime().getTime())
     185        if (lstSize == 0 || searchedTime < entries.get(0).getTime().getTime())
    185186            return -1;
    186187
     
    190191
    191192        // The searched index is somewhere in the middle, do a binary search from the beginning
    192         int curIndex= 0;
    193         int startIndex= 0;
    194         int endIndex= lstSize-1;
     193        int curIndex = 0;
     194        int startIndex = 0;
     195        int endIndex = lstSize-1;
    195196        while (endIndex - startIndex > 1) {
    196             curIndex= (endIndex + startIndex) / 2;
     197            curIndex = (endIndex + startIndex) / 2;
    197198            if (searchedTime > entries.get(curIndex).getTime().getTime()) {
    198                 startIndex= curIndex;
     199                startIndex = curIndex;
    199200            } else {
    200                 endIndex= curIndex;
     201                endIndex = curIndex;
    201202            }
    202203        }
     
    215216     * Returns date of a potential point on GPX track (which can be between points).
    216217     */
    217     public static long getGpxDate( GpxData data, LatLon pos ) {
     218    public static long getGpxDate(GpxData data, LatLon pos) {
    218219        EastNorth en = Main.getProjection().latlon2eastNorth(pos);
    219         for( GpxTrack track : data.tracks ) {
    220             for( GpxTrackSegment segment : track.getSegments() ) {
     220        for (GpxTrack track : data.tracks) {
     221            for (GpxTrackSegment segment : track.getSegments()) {
    221222                long prevWpTime = 0;
    222223                WayPoint prevWp = null;
    223                 for( WayPoint curWp : segment.getWayPoints() ) {
    224                     String curWpTimeStr = (String)curWp.attr.get("time");
    225                     if( curWpTimeStr != null ) {
     224                for (WayPoint curWp : segment.getWayPoints()) {
     225                    String curWpTimeStr = (String) curWp.attr.get("time");
     226                    if (curWpTimeStr != null) {
    226227                        try {
    227228                            long curWpTime = DateUtils.fromString(curWpTimeStr).getTime();
    228                             if( prevWp != null ) {
     229                            if (prevWp != null) {
    229230                                EastNorth c1 = Main.getProjection().latlon2eastNorth(prevWp.getCoor());
    230231                                EastNorth c2 = Main.getProjection().latlon2eastNorth(curWp.getCoor());
    231                                 if( !c1.equals(c2) ) {
     232                                if (!c1.equals(c2)) {
    232233                                    EastNorth middle = getSegmentAltitudeIntersection(c1, c2, en);
    233                                     if( middle != null && en.distance(middle) < 1 ) {
     234                                    if (middle != null && en.distance(middle) < 1) {
    234235                                        // found our point, no further search is neccessary
    235236                                        double prop = c1.east() == c2.east()
    236237                                                ? (middle.north() - c1.north()) / (c2.north() - c1.north())
    237238                                                : (middle.east() - c1.east()) / (c2.east() - c1.east());
    238                                         if( prop >= 0 && prop <= 1 ) {
     239                                        if (prop >= 0 && prop <= 1) {
    239240                                            return Math.round(prevWpTime + prop * (curWpTime - prevWpTime));
    240241                                        }
     
    245246                            prevWp = curWp;
    246247                            prevWpTime = curWpTime;
    247                         } catch( UncheckedParseException e ) {
     248                        } catch (UncheckedParseException e) {
    248249                            Main.error("Error while parsing date \"" + curWpTimeStr + '"');
    249250                            Main.error(e);
     
    265266     * to it starting at point p. If the line defined with p1-p2 intersects
    266267     * its altitude out of p1-p2, null is returned.
    267      * @param p1
    268      * @param p2
    269      * @param point
    270268     * @return Intersection coordinate or null
    271269     **/
  • applications/editors/josm/plugins/NanoLog/src/nanolog/GPXChooser.java

    r32329 r32638  
    11package nanolog;
    22
    3 import javax.swing.*;
     3import javax.swing.JDialog;
     4
    45import org.openstreetmap.josm.Main;
    56import org.openstreetmap.josm.gui.layer.GpxLayer;
     
    1920    public static GpxLayer topLayer() {
    2021        // return first found local layer
    21         for( Layer layer : Main.getLayerManager().getLayers() ) {
    22             if( layer instanceof GpxLayer && ((GpxLayer)layer).isLocalFile() )
    23                 return (GpxLayer)layer;
     22        for (Layer layer : Main.getLayerManager().getLayers()) {
     23            if (layer instanceof GpxLayer && ((GpxLayer) layer).isLocalFile())
     24                return (GpxLayer) layer;
    2425        }
    2526        return null;
  • applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogEntry.java

    r31981 r32638  
    77/**
    88 * This holds one NanoLog entry.
    9  * 
     9 *
    1010 * @author zverik
    1111 */
     
    1818    private LatLon basePos;
    1919
    20     public NanoLogEntry( Date time, String message, LatLon basePos, Integer baseDir ) {
     20    public NanoLogEntry(Date time, String message, LatLon basePos, Integer baseDir) {
    2121        this.basePos = basePos;
    2222        this.baseDir = baseDir;
     
    2727    }
    2828
    29     public NanoLogEntry( Date time, String message ) {
     29    public NanoLogEntry(Date time, String message) {
    3030        this(time, message, null, null);
    3131    }
    32    
     32
    3333    public Integer getDirection() {
    3434        return direction;
     
    4343    }
    4444
    45     public void setPos( LatLon pos ) {
     45    public void setPos(LatLon pos) {
    4646        this.pos = pos;
    4747    }
    4848
    49     public void setDirection( Integer direction ) {
     49    public void setDirection(Integer direction) {
    5050        this.direction = direction;
    5151    }
     
    6464
    6565    @Override
    66     public int compareTo( NanoLogEntry t ) {
     66    public int compareTo(NanoLogEntry t) {
    6767        return time.compareTo(t.time);
    6868    }
  • applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogLayer.java

    r32329 r32638  
    5757    private NLLMouseAdapter mouseListener;
    5858
    59     public NanoLogLayer( List<NanoLogEntry> entries ) {
     59    public NanoLogLayer(List<NanoLogEntry> entries) {
    6060        super(tr("NanoLog"));
    6161        log = new ArrayList<>(entries);
     
    7676    }
    7777
    78     public NanoLogLayer( File file ) throws IOException {
     78    public NanoLogLayer(File file) throws IOException {
    7979        this(readNanoLog(file));
    8080    }
    8181
    82     public void addListener( NanoLogLayerListener listener ) {
     82    public void addListener(NanoLogLayerListener listener) {
    8383        listeners.add(listener);
    8484    }
    8585
    86     public void removeListener( NanoLogLayerListener listener ) {
     86    public void removeListener(NanoLogLayerListener listener) {
    8787        listeners.remove(listener);
    8888    }
    8989
    9090    protected void fireMarkersChanged() {
    91         for( NanoLogLayerListener listener : listeners )
     91        for (NanoLogLayerListener listener : listeners) {
    9292            listener.markersUpdated(this);
     93        }
    9394    }
    9495
    9596    protected void fireMarkerSelected() {
    96         for( NanoLogLayerListener listener : listeners )
     97        for (NanoLogLayerListener listener : listeners) {
    9798            listener.markerActivated(this, selectedEntry < 0 ? null : log.get(selectedEntry));
     99        }
    98100    }
    99101
     
    102104    }
    103105
    104     public static List<NanoLogEntry> readNanoLog( File file ) throws IOException {
     106    public static List<NanoLogEntry> readNanoLog(File file) throws IOException {
    105107        final Pattern NANOLOG_LINE = Pattern.compile("(.+?)\\t(.+?)(?:\\s*\\{\\{(-?\\d+\\.\\d+),\\s*(-?\\d+\\.\\d+)(?:,\\s*(\\d+))?\\}\\})?");
    106108        final SimpleDateFormat fmt = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SS");
    107109        List<NanoLogEntry> result = new ArrayList<>();
    108110        try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"))) {
    109                 while( r.ready() ) {
    110                     String line = r.readLine();
    111                     if( line != null ) {
    112                         Matcher m = NANOLOG_LINE.matcher(line);
    113                         if( m.matches() ) {
    114                             String time = m.group(1);
    115                             String message = m.group(2);
    116                             String lat = m.group(3);
    117                             String lon = m.group(4);
    118                             String dir = m.group(5);
    119                             Date timeDate = null;
    120                             try {
    121                                 timeDate = fmt.parse(time);
    122                             } catch( ParseException e ) {
    123                             }
    124                             if( message == null || message.length() == 0 || timeDate == null )
    125                                 continue;
    126                             LatLon pos = null;
    127                             Integer direction = null;
    128                             if( lat != null && lon != null ) {
    129                                 try {
    130                                     pos = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
    131                                     direction = new Integer(dir);
    132                                 } catch( NumberFormatException e ) {
    133                                     // well...
    134                                 }
    135                             }
    136                             NanoLogEntry entry = new NanoLogEntry(timeDate, message, pos, direction);
    137                             result.add(entry);
    138                         }
    139                     }
    140                 }
     111            while (r.ready()) {
     112                String line = r.readLine();
     113                if (line != null) {
     114                    Matcher m = NANOLOG_LINE.matcher(line);
     115                    if (m.matches()) {
     116                        String time = m.group(1);
     117                        String message = m.group(2);
     118                        String lat = m.group(3);
     119                        String lon = m.group(4);
     120                        String dir = m.group(5);
     121                        Date timeDate = null;
     122                        try {
     123                            timeDate = fmt.parse(time);
     124                        } catch (ParseException e) {
     125                            Main.warn(e);
     126                        }
     127                        if (message == null || message.length() == 0 || timeDate == null)
     128                            continue;
     129                        LatLon pos = null;
     130                        Integer direction = null;
     131                        if (lat != null && lon != null) {
     132                            try {
     133                                pos = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
     134                                direction = new Integer(dir);
     135                            } catch (NumberFormatException e) {
     136                                Main.trace(e);
     137                            }
     138                        }
     139                        NanoLogEntry entry = new NanoLogEntry(timeDate, message, pos, direction);
     140                        result.add(entry);
     141                    }
     142                }
     143            }
    141144        }
    142145        return result;
     
    144147
    145148    @Override
    146     public void paint( Graphics2D g, MapView mv, Bounds box ) {
     149    public void paint(Graphics2D g, MapView mv, Bounds box) {
    147150        // todo
    148         for( int i = 0; i < log.size(); i++  ) {
     151        for (int i = 0; i < log.size(); i++) {
    149152            NanoLogEntry entry = log.get(i);
    150153            int radius = 4;
    151             if( entry.getPos() != null ) {
     154            if (entry.getPos() != null) {
    152155                Point p = mv.getPoint(entry.getPos());
    153156                g.setColor(selectedEntry == i ? Color.red : Color.yellow);
     
    168171
    169172    @Override
    170     public void mergeFrom( Layer from ) {
     173    public void mergeFrom(Layer from) {
    171174        // todo
    172175    }
    173176
    174177    @Override
    175     public boolean isMergable( Layer other ) {
     178    public boolean isMergable(Layer other) {
    176179        return other instanceof NanoLogLayer;
    177180    }
    178181
    179182    @Override
    180     public void visitBoundingBox( BoundingXYVisitor v ) {
    181         for( NanoLogEntry entry : log )
     183    public void visitBoundingBox(BoundingXYVisitor v) {
     184        for (NanoLogEntry entry : log) {
    182185            v.visit(entry.getPos());
     186        }
    183187    }
    184188
     
    187191        StringBuilder b = new StringBuilder();
    188192        int cnt = 0;
    189         for( NanoLogEntry e : log )
    190             if( e.getPos() != null )
     193        for (NanoLogEntry e : log) {
     194            if (e.getPos() != null)
    191195                cnt++;
     196        }
    192197        b.append(tr("NanoLog of {0} lines, {1} of them with coordinates.", log.size(), cnt));
    193198        return b.toString();
     
    212217    public void jumpToNextMarker() {
    213218        selectedEntry++;
    214         if( selectedEntry < 0 )
     219        if (selectedEntry < 0)
    215220            selectedEntry = 0;
    216         else if( selectedEntry >= log.size() )
     221        else if (selectedEntry >= log.size())
    217222            selectedEntry = log.size() - 1;
    218223        Main.map.repaint();
     
    222227    public void jumpToPreviousMarker() {
    223228        selectedEntry--;
    224         if( selectedEntry < 0 )
     229        if (selectedEntry < 0)
    225230            selectedEntry = 0;
    226         else if( selectedEntry >= log.size() )
     231        else if (selectedEntry >= log.size())
    227232            selectedEntry = log.size() - 1;
    228233        Main.map.repaint();
    229234    }
    230235
    231     protected void setSelected( int i ) {
     236    protected void setSelected(int i) {
    232237        int newSelected = i >= 0 && i < log.size() ? i : -1;
    233         if( newSelected != selectedEntry ) {
     238        if (newSelected != selectedEntry) {
    234239//            System.out.println("selected: " + log.get(newSelected).getMessage());
    235240            selectedEntry = newSelected;
     
    239244    }
    240245
    241     public void setSelected( NanoLogEntry entry ) {
    242         if( entry == null )
     246    public void setSelected(NanoLogEntry entry) {
     247        if (entry == null)
    243248            setSelected(-1);
    244249        else {
    245             for( int i = 0; i < log.size(); i++ ) {
    246                 if( entry.equals(log.get(i)) ) {
     250            for (int i = 0; i < log.size(); i++) {
     251                if (entry.equals(log.get(i))) {
    247252                    setSelected(i);
    248253                    break;
     
    255260        private int dragging;
    256261
    257         public int nearestEntry( MouseEvent e ) {
     262        public int nearestEntry(MouseEvent e) {
    258263            LatLon ll = Main.map.mapView.getLatLon(e.getX(), e.getY());
    259264            int radius = 8;
    260             if( ll != null ) {
     265            if (ll != null) {
    261266                LatLon lld = Main.map.mapView.getLatLon(e.getX() + radius, e.getY() + radius);
    262267                double distance = Math.max(lld.lat() - ll.lat(), lld.lon() - ll.lon());
    263268                boolean selectedIsSelected = false;
    264269                int newSelected = -1;
    265                 for( int i = 0; i < log.size(); i++ ) {
    266                     if( log.get(i).getPos() != null && log.get(i).getPos().distance(ll) < distance ) {
     270                for (int i = 0; i < log.size(); i++) {
     271                    if (log.get(i).getPos() != null && log.get(i).getPos().distance(ll) < distance) {
    267272                        newSelected = i;
    268                         if( i == selectedEntry )
     273                        if (i == selectedEntry)
    269274                            selectedIsSelected = true;
    270275                    }
    271276                }
    272                 if( newSelected >= 0 )
     277                if (newSelected >= 0)
    273278                    return selectedIsSelected ? selectedEntry : newSelected;
    274279            }
     
    277282
    278283        @Override
    279         public void mouseMoved( MouseEvent e ) {
     284        public void mouseMoved(MouseEvent e) {
    280285            int nearest = nearestEntry(e);
    281             if( nearest > 0 )
     286            if (nearest > 0)
    282287                setSelected(nearest);
    283288        }
    284289
    285290        @Override
    286         public void mouseDragged( MouseEvent e ) {
     291        public void mouseDragged(MouseEvent e) {
    287292            doDrag(e);
    288293        }
    289294
    290295        @Override
    291         public void mouseReleased( MouseEvent e ) {
    292             if( dragging > 0 ) {
     296        public void mouseReleased(MouseEvent e) {
     297            if (dragging > 0) {
    293298                dragging = 0;
    294299            }
     
    296301
    297302        @Override
    298         public void mousePressed( MouseEvent e ) {
     303        public void mousePressed(MouseEvent e) {
    299304            int nearest = nearestEntry(e);
    300             if( nearest > 0 && Main.getLayerManager().getActiveLayer() == NanoLogLayer.this ) {
     305            if (nearest > 0 && Main.getLayerManager().getActiveLayer() == NanoLogLayer.this) {
    301306                dragging = nearest;
    302307                doDrag(e);
     
    304309        }
    305310
    306         private void doDrag( MouseEvent e ) {
    307             if( dragging > 0 )
     311        private void doDrag(MouseEvent e) {
     312            if (dragging > 0)
    308313                dragTo(dragging, e.getX(), e.getY());
    309314        }
    310315    }
    311316
    312     protected void dragTo( int entry, int x, int y ) {
     317    protected void dragTo(int entry, int x, int y) {
    313318        GpxLayer gpx = GPXChooser.topLayer();
    314         if( gpx == null )
     319        if (gpx == null)
    315320            return;
    316321        EastNorth eastNorth = Main.map.mapView.getEastNorth(x, y);
    317322        double tolerance = eastNorth.distance(Main.map.mapView.getEastNorth(x + 300, y));
    318323        WayPoint wp = gpx.data.nearestPointOnTrack(eastNorth, tolerance);
    319         if( wp == null )
     324        if (wp == null)
    320325            return;
    321326        long newTime = Correlator.getGpxDate(gpx.data, wp.getCoor());
    322         if( newTime <= 0 )
     327        if (newTime <= 0)
    323328            return;
    324329        Correlator.revertPos(log);
     
    330335        private boolean toZero;
    331336
    332         public CorrelateEntries( boolean toZero ) {
    333             super(toZero ? tr("Correlate with GPX...") : tr("Put on GPX..."), "nanolog/correlate", tr("Correlate entries with GPS trace"), null, false);
     337        CorrelateEntries(boolean toZero) {
     338            super(toZero ? tr("Correlate with GPX...") : tr("Put on GPX..."), "nanolog/correlate",
     339                    tr("Correlate entries with GPS trace"), null, false);
    334340            this.toZero = toZero;
    335341        }
    336342
    337343        @Override
    338         public void actionPerformed( ActionEvent e ) {
     344        public void actionPerformed(ActionEvent e) {
    339345            // 1. Select GPX trace or display message to load one
    340346            // (better yet, disable when no GPX traces)
     
    342348            // 2. Correlate by default, sticking by date
    343349            // (if does not match, shift so hours-minutes stay)
    344             if( layer != null ) {
     350            if (layer != null) {
    345351                long offset = toZero ? 0 : Correlator.crudeMatch(log, layer.data);
    346352                Correlator.revertPos(log);
     
    356362    private class SaveLayer extends JosmAction {
    357363
    358         public SaveLayer() {
     364        SaveLayer() {
    359365            super(tr("Save layer..."), "nanolog/save", tr("Save NanoLog layer"), null, false);
    360366        }
    361367
    362368        @Override
    363         public void actionPerformed( ActionEvent e ) {
     369        public void actionPerformed(ActionEvent e) {
    364370            // todo
    365371            JOptionPane.showMessageDialog(Main.parent, "Sorry, no saving yet", "NanoLog", JOptionPane.ERROR_MESSAGE);
     
    367373    }
    368374
    369     public static interface NanoLogLayerListener {
    370         void markersUpdated( NanoLogLayer layer );
    371         void markerActivated( NanoLogLayer layer, NanoLogEntry entry );
     375    public interface NanoLogLayerListener {
     376        void markersUpdated(NanoLogLayer layer);
     377
     378        void markerActivated(NanoLogLayer layer, NanoLogEntry entry);
    372379    }
    373380}
  • applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogPanel.java

    r32447 r32638  
    1111import javax.swing.JList;
    1212
    13 import nanolog.NanoLogLayer.NanoLogLayerListener;
    14 
    1513import org.openstreetmap.josm.Main;
    1614import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
     
    2018import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    2119import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
     20
     21import nanolog.NanoLogLayer.NanoLogLayerListener;
    2222
    2323/**
     
    4040    public void updateMarkers() {
    4141        List<NanoLogEntry> entries = new ArrayList<>();
    42         for( NanoLogLayer l : Main.getLayerManager().getLayersOfType(NanoLogLayer.class) ) {
     42        for (NanoLogLayer l : Main.getLayerManager().getLayersOfType(NanoLogLayer.class)) {
    4343            entries.addAll(l.getEntries());
    4444        }
     
    5353    public void layerAdded(LayerAddEvent e) {
    5454        Layer newLayer = e.getAddedLayer();
    55         if (newLayer instanceof NanoLogLayer )
     55        if (newLayer instanceof NanoLogLayer)
    5656            ((NanoLogLayer) newLayer).addListener(this);
    5757        updateMarkers();
     
    6464
    6565    @Override
    66     public void markersUpdated( NanoLogLayer layer ) {
     66    public void markersUpdated(NanoLogLayer layer) {
    6767        updateMarkers();
    6868    }
    6969
    7070    @Override
    71     public void markerActivated( NanoLogLayer layer, NanoLogEntry entry ) {
     71    public void markerActivated(NanoLogLayer layer, NanoLogEntry entry) {
    7272        int idx = entry == null ? -1 : listModel.find(entry);
    73         if( idx >= 0 ) {
     73        if (idx >= 0) {
    7474            logPanel.setSelectedIndex(idx);
    7575            Rectangle rect = logPanel.getCellBounds(Math.max(0, idx-2), Math.min(idx+4, listModel.getSize()));
     
    8383
    8484        @Override
    85                 public int getSize() {
     85        public int getSize() {
    8686            return entries.size();
    8787        }
    8888
    8989        @Override
    90                 public String getElementAt( int index ) {
     90        public String getElementAt(int index) {
    9191            return TIME_FORMAT.format(entries.get(index).getTime()) + " " + entries.get(index).getMessage();
    9292        }
    9393
    94         public void setEntries( List<NanoLogEntry> entries ) {
     94        public void setEntries(List<NanoLogEntry> entries) {
    9595            this.entries = entries;
    9696            fireContentsChanged(this, 0, entries.size());
    9797        }
    9898
    99         public int find( NanoLogEntry entry ) {
     99        public int find(NanoLogEntry entry) {
    100100            return entries.indexOf(entry);
    101101        }
  • applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogPlugin.java

    r32447 r32638  
    1818/**
    1919 * Add NanoLog opening menu item and the panel.
    20  * 
     20 *
    2121 * @author zverik
    2222 */
    2323public class NanoLogPlugin extends Plugin {
    24     public NanoLogPlugin( PluginInformation info ) {
     24    public NanoLogPlugin(PluginInformation info) {
    2525        super(info);
    2626        Main.main.menu.fileMenu.insert(new OpenNanoLogLayerAction(), 4);
    2727    }
    28    
     28
    2929    @Override
    30     public void mapFrameInitialized( MapFrame oldFrame, MapFrame newFrame ) {
    31         if( oldFrame == null && newFrame != null ) {
     30    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     31        if (oldFrame == null && newFrame != null) {
    3232            NanoLogPanel panel = new NanoLogPanel();
    3333            newFrame.addToggleDialog(panel);
     
    3535        }
    3636    }
    37    
     37
    3838    private class OpenNanoLogLayerAction extends JosmAction {
    3939
    40         public OpenNanoLogLayerAction() {
     40        OpenNanoLogLayerAction() {
    4141            super(tr("Open NanoLog file..."), "nanolog.png", tr("Open NanoLog file..."), null, false);
    4242        }
    4343
    44         public void actionPerformed( ActionEvent e ) {
     44        @Override
     45        public void actionPerformed(ActionEvent e) {
    4546            JFileChooser fc = new JFileChooser();
    46             if( fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION ) {
     47            if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
    4748                try {
    4849                    List<NanoLogEntry> entries = NanoLogLayer.readNanoLog(fc.getSelectedFile());
    49                     if( !entries.isEmpty() ) {
     50                    if (!entries.isEmpty()) {
    5051                        NanoLogLayer layer = new NanoLogLayer(entries);
    5152                        Main.getLayerManager().addLayer(layer);
    5253                        layer.setupListeners();
    5354                    }
    54                 } catch( IOException ex ) {
     55                } catch (IOException ex) {
    5556                    JOptionPane.showMessageDialog(Main.parent, tr("Could not read NanoLog file:") + "\n" + ex.getMessage());
    5657                }
    5758            }
    58         }       
     59        }
    5960    }
    6061}
Note: See TracChangeset for help on using the changeset viewer.