Menu

#29 Added multi selection and load of gpx files

Enhancement
closed
r_x
5
2015-04-04
2012-09-14
Heckie
No

Previously it wasn't possible to open more than one gpx file. You had to open the 'Load GPX' dialog for each file you want to import.

Now it is possible to select multiple files within file gpx file dialog and load them. Loading many files maybe takes a second or two.
Therefore a progress bar indicates the processing state.


Because of some problems with repainting the progressbar, the loading of multiple files is done within a new thread. The MainGUI is locked in the meantime.
However, because of some ConcurrentModificationExceptions when zooming with the mouse wheel, this event is also disabled when loading multiple gpx files.
Therefore defaultMapController is now a member of PreviewMap. It's a workaround. Maybe there is a better solution.


I hope that this patch - or even an improved version - will become part of MOBAC.

Kind Regards,
Heckie

Discussion

  • Heckie

    Heckie - 2012-09-14

    Added multi selection and load of gpx files

     
  • r_x

    r_x - 2012-09-14

    I have modified your patch a bit as you have made GUI changes from within a non-Swing Thread, which is not allowed (see the changes in GpxLoad).
    May be that was the cause of the ConcurrentModificationExceptions. I have committed the modified version to SVN. Could you please check if disabling the mouse wheel is now still necessary?

     
  • Heckie

    Heckie - 2012-09-14

    Unfortunately disabling the mouse wheel is still necessary while loading the gpx file.

    Here is the exception.

    java.util.ConcurrentModificationException
    at java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
    at java.util.LinkedList$ListItr.next(Unknown Source)
    at mobac.gui.mapview.JMapViewer.paintComponent(JMapViewer.java:375)
    at mobac.gui.mapview.PreviewMap.paintComponent(PreviewMap.java:207)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.access$700(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at mobac.utilities.GUIExceptionHandler$EventQueueProxy.dispatchEvent(GUIExceptionHandler.java:299)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


    The problem is that mouse wheels events lead to repaints of JMapViewer. In JMapView.paintComponent(Graphics graphics) we iterate over all mapLayers (see line 375).
    I guess that gpx files are also entries of mapLayers. So while iterating over the map we add new elements. Therefore we get a ConcurrentModificationException.

    Because changing mapLayers may lead to ConcurrentModificationException in other situations maybe it's a good idea to use a synchronized list. See new patch (attachment).

    Actually I think that you don't want the user to zoom and do other things while loading gpx files. The user expects a modal operation.
    So it is not bad to disable mouse wheel events and the MainGUI while loading.

     
  • Heckie

    Heckie - 2012-09-14

    Patch with fixed ConcurrentModificationException

     
  • r_x

    r_x - 2012-09-14

    Ok, therefore this is not a fundamental problem - just a temporary. Therefore I have just catched the Exception in JMapViewer. Furthermore I have improved the GpxLoad implementation.

    Please give it a try.

     
  • Heckie

    Heckie - 2012-09-14

    The exceptionhandling in JMapViewer is fine although using a synchronized list isn't worse than that (see attachment MOBAC_multi_load_gpx_files_v2.patch).

    The improvement in GpxLoad is buggy:

    1. opening some gpx files and load them
    2. opening the same gpx files (at least 2 of them)
    3. Warning message appears ("One or more files are already opened....")
    4. Answer with "no"
    5. Message disappears but ProgressBar stays visible because of returning from doMultiLoad without passing the finally-block where the progressbar etc. is closed

    I also think it was better before because the name of the dublicate file was mentioned. The message was clearer.

     
  • r_x

    r_x - 2012-09-15

    I prefer the try-catch method because synchronization costs you every time resources but the error happens only under rare circumstances. And the JMapViewer.paint method is executed very often...

    MainGUI re-enabling and cursor is also fixed now.

     
  • Heckie

    Heckie - 2012-09-16

    The bug in GpxLoad is still there. The only difference is that you re-enable the MainGUI and set the cursor back to default. But the progressbar dialog stays in front.

    New Bug:
    After opening some files, opening the same files and answer to 'One or more files are already opened.' with 'yes' the question appears with every file.

    Heres is another patch (v3)

     
  • Heckie

    Heckie - 2012-09-16

    Patch GpxLoad, Question when selected already opened gpx files

     
  • r_x

    r_x - 2012-09-17

    Thanks for the patch. I have now applied it in SVN rev 2055.

     
  • Heckie

    Heckie - 2012-09-17

    Thanks, looks fine. That's it!

     
  • r_x

    r_x - 2012-09-18
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.