Changeset 13649 in josm for trunk


Ignore:
Timestamp:
2018-04-19T22:34:52+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #16204 - allow to create a new layer, draw, drag, open a few windows. Nothing more to hope in sandbox mode. At least JOSM is now more robust than ever.

Location:
trunk/src/org/openstreetmap/josm
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AbstractPasteAction.java

    r13151 r13649  
    1515import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    1616import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
     17import org.openstreetmap.josm.tools.Logging;
    1718import org.openstreetmap.josm.tools.Shortcut;
    1819
     
    7677        // Observed behaviour: getActionCommand() returns Action.NAME when triggered via menu, but shortcut text when triggered with it
    7778        if (e != null && !getValue(NAME).equals(e.getActionCommand())) {
    78             final PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    79             if (pointerInfo != null) {
    80                 final Point mp = pointerInfo.getLocation();
    81                 final Point tl = mapView.getLocationOnScreen();
    82                 final Point pos = new Point(mp.x-tl.x, mp.y-tl.y);
    83                 if (mapView.contains(pos)) {
    84                     mPosition = mapView.getEastNorth(pos.x, pos.y);
     79            try {
     80                final PointerInfo pointerInfo = MouseInfo.getPointerInfo();
     81                if (pointerInfo != null) {
     82                    final Point mp = pointerInfo.getLocation();
     83                    final Point tl = mapView.getLocationOnScreen();
     84                    final Point pos = new Point(mp.x-tl.x, mp.y-tl.y);
     85                    if (mapView.contains(pos)) {
     86                        mPosition = mapView.getEastNorth(pos.x, pos.y);
     87                    }
    8588                }
     89            } catch (SecurityException ex) {
     90                Logging.log(Logging.LEVEL_ERROR, "Unable to get mouse pointer info", ex);
    8691            }
    8792        }
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r13647 r13649  
    108108        File cacheDir = new File(Config.getDirs().getCacheDirectory(true), "jcs");
    109109
    110         if (!cacheDir.exists() && !cacheDir.mkdirs()) {
    111             Logging.warn("Cache directory " + cacheDir.toString() + " does not exists and could not create it");
    112         } else {
    113             File cacheDirLockPath = new File(cacheDir, ".lock");
    114             try {
    115                 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
    116                     Logging.warn("Cannot create cache dir lock file");
    117                 }
    118                 cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock();
    119 
    120                 if (cacheDirLock == null)
    121                     Logging.warn("Cannot lock cache directory. Will not use disk cache");
    122             } catch (IOException e) {
    123                 Logging.warn("Cannot create cache dir \"" + cacheDirLockPath.toString() + "\" lock file: " + e.toString());
    124                 Logging.warn("Will not use disk cache");
     110        try {
     111            if (!cacheDir.exists() && !cacheDir.mkdirs()) {
     112                Logging.warn("Cache directory " + cacheDir.toString() + " does not exists and could not create it");
     113            } else {
     114                File cacheDirLockPath = new File(cacheDir, ".lock");
     115                try {
     116                    if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
     117                        Logging.warn("Cannot create cache dir lock file");
     118                    }
     119                    cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock();
     120
     121                    if (cacheDirLock == null)
     122                        Logging.warn("Cannot lock cache directory. Will not use disk cache");
     123                } catch (IOException e) {
     124                    Logging.warn("Cannot create cache dir \"" + cacheDirLockPath.toString() + "\" lock file: " + e.toString());
     125                    Logging.warn("Will not use disk cache");
     126                }
    125127            }
    126         }
     128        } catch (SecurityException e) {
     129            Logging.log(Logging.LEVEL_WARN, "Unable to configure disk cache. Will not use it", e);
     130        }
     131
    127132        // this could be moved to external file
    128133        Properties props = new Properties();
     
    140145        props.setProperty("jcs.default.elementattributes.IsSpool",            "true");
    141146        // CHECKSTYLE.ON: SingleSpaceSeparator
    142         CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance();
    143         cm.configure(props);
    144         cacheManager = cm;
     147        try {
     148            CompositeCacheManager cm = CompositeCacheManager.getUnconfiguredInstance();
     149            cm.configure(props);
     150            cacheManager = cm;
     151        } catch (SecurityException e) {
     152            Logging.log(Logging.LEVEL_WARN, "Unable to initialize JCS", e);
     153        }
    145154    }
    146155
     
    173182            if (cacheManager == null)
    174183                initialize();
    175             return getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath);
     184            return cacheManager != null ? getCacheInner(cacheName, maxMemoryObjects, maxDiskObjects, cachePath) : null;
    176185        }
    177186    }
  • trunk/src/org/openstreetmap/josm/data/osm/MultipolygonBuilder.java

    r12620 r13649  
    3939public class MultipolygonBuilder {
    4040
    41     private static final ForkJoinPool THREAD_POOL =
    42             Utils.newForkJoinPool("multipolygon_creation.numberOfThreads", "multipolygon-builder-%d", Thread.NORM_PRIORITY);
     41    private static final ForkJoinPool THREAD_POOL = newForkJoinPool();
     42
     43    private static ForkJoinPool newForkJoinPool() {
     44        try {
     45            return Utils.newForkJoinPool(
     46                    "multipolygon_creation.numberOfThreads", "multipolygon-builder-%d", Thread.NORM_PRIORITY);
     47        } catch (SecurityException e) {
     48            Logging.log(Logging.LEVEL_ERROR, "Unable to create new ForkJoinPool", e);
     49            return null;
     50        }
     51    }
    4352
    4453    /**
     
    385394    private static List<PolygonLevel> findOuterWaysMultiThread(List<JoinedPolygon> boundaryWays) {
    386395        final IntersectionMatrix cache = new IntersectionMatrix(boundaryWays);
    387         return THREAD_POOL.invoke(new Worker(cache, boundaryWays, 0, boundaryWays.size(), new ArrayList<PolygonLevel>(),
    388                 Math.max(32, boundaryWays.size() / THREAD_POOL.getParallelism() / 3)));
     396        if (THREAD_POOL != null) {
     397            return THREAD_POOL.invoke(new Worker(cache, boundaryWays, 0, boundaryWays.size(), new ArrayList<PolygonLevel>(),
     398                    Math.max(32, boundaryWays.size() / THREAD_POOL.getParallelism() / 3)));
     399        } else {
     400            return new Worker(cache, boundaryWays, 0, boundaryWays.size(), new ArrayList<PolygonLevel>(), 0).computeDirectly();
     401        }
    389402    }
    390403
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r13206 r13649  
    9494public class StyledMapRenderer extends AbstractMapRenderer {
    9595
    96     private static final ForkJoinPool THREAD_POOL =
    97             Utils.newForkJoinPool("mappaint.StyledMapRenderer.style_creation.numberOfThreads", "styled-map-renderer-%d", Thread.NORM_PRIORITY);
     96    private static final ForkJoinPool THREAD_POOL = newForkJoinPool();
     97
     98    private static ForkJoinPool newForkJoinPool() {
     99        try {
     100            return Utils.newForkJoinPool(
     101                    "mappaint.StyledMapRenderer.style_creation.numberOfThreads", "styled-map-renderer-%d", Thread.NORM_PRIORITY);
     102        } catch (SecurityException e) {
     103            Logging.log(Logging.LEVEL_ERROR, "Unable to create new ForkJoinPool", e);
     104            return null;
     105        }
     106    }
    98107
    99108    /**
     
    16001609            // Reason: Make sure, ElemStyles.getStyleCacheWithRange is not called for the same primitive in parallel threads.
    16011610            // (Could be synchronized, but try to avoid this for performance reasons.)
    1602             THREAD_POOL.invoke(new ComputeStyleListWorker(circum, nc, relations, allStyleElems,
    1603                     Math.max(20, relations.size() / THREAD_POOL.getParallelism() / 3), styles));
    1604             THREAD_POOL.invoke(new ComputeStyleListWorker(circum, nc, new CompositeList<>(nodes, ways), allStyleElems,
    1605                     Math.max(100, (nodes.size() + ways.size()) / THREAD_POOL.getParallelism() / 3), styles));
     1611            if (THREAD_POOL != null) {
     1612                THREAD_POOL.invoke(new ComputeStyleListWorker(circum, nc, relations, allStyleElems,
     1613                        Math.max(20, relations.size() / THREAD_POOL.getParallelism() / 3), styles));
     1614                THREAD_POOL.invoke(new ComputeStyleListWorker(circum, nc, new CompositeList<>(nodes, ways), allStyleElems,
     1615                        Math.max(100, (nodes.size() + ways.size()) / THREAD_POOL.getParallelism() / 3), styles));
     1616            } else {
     1617                new ComputeStyleListWorker(circum, nc, relations, allStyleElems, 0, styles).computeDirectly();
     1618                new ComputeStyleListWorker(circum, nc, new CompositeList<>(nodes, ways), allStyleElems, 0, styles).computeDirectly();
     1619            }
    16061620
    16071621            if (!benchmark.renderSort()) {
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r13434 r13649  
    12111211    public void zoomChanged() {
    12121212        if (!GraphicsEnvironment.isHeadless()) {
    1213             PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    1214             if (pointerInfo != null) {
    1215                 Point mp = pointerInfo.getLocation();
    1216                 updateLatLonText(mp.x, mp.y);
     1213            try {
     1214                PointerInfo pointerInfo = MouseInfo.getPointerInfo();
     1215                if (pointerInfo != null) {
     1216                    Point mp = pointerInfo.getLocation();
     1217                    updateLatLonText(mp.x, mp.y);
     1218                }
     1219            } catch (SecurityException ex) {
     1220                Logging.log(Logging.LEVEL_ERROR, "Unable to get mouse pointer info", ex);
    12171221            }
    12181222        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r13493 r13649  
    468468            MainApplication.getMenu().windowMenu.remove(windowMenuItem);
    469469        }
    470         Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     470        try {
     471            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     472        } catch (SecurityException e) {
     473            Logging.log(Logging.LEVEL_ERROR, "Unable to remove AWT event listener", e);
     474        }
    471475        Config.getPref().removePreferenceChangeListener(this);
    472476        destroyComponents(this, false);
     
    977981    private void dynamicButtonsPropertyChanged() {
    978982        boolean propEnabled = PROP_DYNAMIC_BUTTONS.get();
    979         if (propEnabled) {
    980             Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK);
    981         } else {
    982             Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     983        try {
     984            if (propEnabled) {
     985                Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK);
     986            } else {
     987                Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     988            }
     989        } catch (SecurityException e) {
     990            Logging.log(Logging.LEVEL_ERROR, "Unable to add/remove AWT event listener", e);
    983991        }
    984992        titleBar.buttonsHide.setVisible(propEnabled);
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetMenu.java

    r12646 r13649  
    2424import org.openstreetmap.josm.gui.MainApplication;
    2525import org.openstreetmap.josm.tools.AlphanumComparator;
     26import org.openstreetmap.josm.tools.Logging;
    2627
    2728/**
     
    100101                pm.add(copyMenuComponent(c));
    101102            }
    102             PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    103             if (pointerInfo != null) {
    104                 Point p = pointerInfo.getLocation();
    105                 pm.show(Main.parent, p.x-Main.parent.getX(), p.y-Main.parent.getY());
     103            try {
     104                PointerInfo pointerInfo = MouseInfo.getPointerInfo();
     105                if (pointerInfo != null) {
     106                    Point p = pointerInfo.getLocation();
     107                    pm.show(Main.parent, p.x-Main.parent.getX(), p.y-Main.parent.getY());
     108                }
     109            } catch (SecurityException ex) {
     110                Logging.log(Logging.LEVEL_ERROR, "Unable to get mouse pointer info", ex);
    106111            }
    107112        }
  • trunk/src/org/openstreetmap/josm/gui/util/AdvancedKeyPressDetector.java

    r13270 r13649  
    8282            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
    8383        } catch (SecurityException ex) {
    84             Logging.warn(ex);
     84            Logging.log(Logging.LEVEL_WARN, "Unable to add AWT event listener", ex);
    8585        }
    8686        timer = new Timer(0, e -> {
     
    113113            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    114114        } catch (SecurityException ex) {
    115             Logging.warn(ex);
     115            Logging.log(Logging.LEVEL_WARN, "Unable to remove AWT event listener", ex);
    116116        }
    117117    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmImageView.java

    r12620 r13649  
    4444    public JosmImageView(Element elem) throws NoSuchFieldException {
    4545        super(elem);
    46         imageField = ImageView.class.getDeclaredField("image");
    47         stateField = ImageView.class.getDeclaredField("state");
    48         widthField = ImageView.class.getDeclaredField("width");
    49         heightField = ImageView.class.getDeclaredField("height");
     46        imageField = getDeclaredField("image");
     47        stateField = getDeclaredField("state");
     48        widthField = getDeclaredField("width");
     49        heightField = getDeclaredField("height");
    5050        Utils.setObjectsAccessible(imageField, stateField, widthField, heightField);
     51    }
     52
     53    private static Field getDeclaredField(String name) throws NoSuchFieldException {
     54        try {
     55            return ImageView.class.getDeclaredField(name);
     56        } catch (SecurityException e) {
     57            Logging.log(Logging.LEVEL_ERROR, "Unable to access field by reflection", e);
     58            return null;
     59        }
    5160    }
    5261
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java

    r12856 r13649  
    7272        try {
    7373            return Class.forName("sun.security.x509.GeneralName") != null;
    74         } catch (ClassNotFoundException e) {
     74        } catch (ClassNotFoundException | SecurityException e) {
    7575            Logging.trace(e);
    7676            return false;
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r13647 r13649  
    15471547            AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
    15481548                for (AccessibleObject o : objects) {
    1549                     o.setAccessible(true);
     1549                    if (o != null) {
     1550                        o.setAccessible(true);
     1551                    }
    15501552                }
    15511553                return null;
Note: See TracChangeset for help on using the changeset viewer.