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

checkstyle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.