Changeset 5512 in josm for trunk


Ignore:
Timestamp:
2012-09-16T08:39:16+02:00 (12 years ago)
Author:
jttt
Message:

Fix #7980: Out of Heap Memory

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

Legend:

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

    r5459 r5512  
    110110
    111111    private Shortcut backspaceShortcut;
     112    private BackSpaceAction backspaceAction;
    112113    private final Shortcut snappingShortcut;
    113114
     
    118119    public DrawAction(MapFrame mapFrame) {
    119120        super(tr("Draw"), "node/autonode", tr("Draw nodes"),
    120             Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.DIRECT),
    121             mapFrame, ImageProvider.getCursor("crosshair", null));
     121                Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.DIRECT),
     122                mapFrame, ImageProvider.getCursor("crosshair", null));
    122123
    123124        snappingShortcut = Shortcut.registerShortcut("mapmode:drawanglesnapping",
    124             tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.DIRECT);
     125                tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.DIRECT);
    125126        snapChangeAction = new SnapChangeAction();
    126127        snapCheckboxMenuItem = addMenuItem();
    127128        snapHelper.setMenuCheckBox(snapCheckboxMenuItem);
     129        backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace",
     130                tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.DIRECT);
     131        backspaceAction = new BackSpaceAction();
    128132        cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");
    129133        cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway");
     
    207211        snapCheckboxMenuItem.getAction().setEnabled(true);
    208212
    209          timer = new Timer(0, new ActionListener() {
     213        timer = new Timer(0, new ActionListener() {
    210214            @Override
    211215            public void actionPerformed(ActionEvent ae) {
     
    218222        });
    219223        Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener);
    220         backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace",
    221             tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.DIRECT);
    222         Main.registerActionShortcut(new BackSpaceAction(), backspaceShortcut);
     224        Main.registerActionShortcut(backspaceAction, backspaceShortcut);
    223225
    224226        Main.map.mapView.addMouseListener(this);
     
    242244        Main.map.mapView.removeTemporaryLayer(this);
    243245        DataSet.removeSelectionListener(this);
    244         Main.unregisterShortcut(backspaceShortcut);
     246        Main.unregisterActionShortcut(backspaceAction, backspaceShortcut);
    245247        snapHelper.unsetFixedMode();
    246248        snapCheckboxMenuItem.getAction().setEnabled(false);
    247        
     249
    248250        Main.map.statusLine.getAnglePanel().removeMouseListener(snapHelper.anglePopupListener);
    249251        Main.map.statusLine.activateAnglePanel(false);
     
    274276            if (snappingShortcut.isEvent(e) || (useRepeatedShortcut && getShortcut().isEvent(e))) {
    275277                Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    276                 if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame)
     278                if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame) {
    277279                    processKeyEvent(e);
     280                }
    278281            }
    279282        } //  toggle angle snapping
     
    289292    private Timer timer;
    290293    void processKeyEvent(KeyEvent e) {
    291         if (!snappingShortcut.isEvent(e) && !(useRepeatedShortcut && getShortcut().isEvent(e))) 
    292             return;
    293        
     294        if (!snappingShortcut.isEvent(e) && !(useRepeatedShortcut && getShortcut().isEvent(e)))
     295            return;
     296
    294297        if (e.getID() == KeyEvent.KEY_PRESSED) {
    295298            if (timer.isRunning()) {
     
    413416
    414417        ArrayList<Way> reuseWays = new ArrayList<Way>(),
    415         replacedWays = new ArrayList<Way>();
     418                replacedWays = new ArrayList<Way>();
    416419        boolean newNode = false;
    417420        Node n = null;
     
    461464            if (n.getCoor().isOutSideWorld()) {
    462465                JOptionPane.showMessageDialog(
    463                     Main.parent,
    464                     tr("Cannot add a node outside of the world."),
    465                     tr("Warning"),
    466                     JOptionPane.WARNING_MESSAGE
    467                 );
     466                        Main.parent,
     467                        tr("Cannot add a node outside of the world."),
     468                        tr("Warning"),
     469                        JOptionPane.WARNING_MESSAGE
     470                        );
    468471                return;
    469472            }
     
    473476                // Insert the node into all the nearby way segments
    474477                List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(
    475                     Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate);
     478                        Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate);
    476479                if (snapHelper.isActive()) {
    477480                    tryToMoveNodeOnIntersection(wss,n);
     
    804807
    805808        determineCurrentBaseNodeAndPreviousNode(selection);
    806         if (previousNode == null) snapHelper.noSnapNow();
     809        if (previousNode == null) {
     810            snapHelper.noSnapNow();
     811        }
    807812
    808813        if (currentBaseNode == null || currentBaseNode == currentMouseNode)
     
    811816
    812817        double curHdg = Math.toDegrees(currentBaseNode.getEastNorth()
    813             .heading(currentMouseEastNorth));
     818                .heading(currentMouseEastNorth));
    814819        double baseHdg=-1;
    815820        if (previousNode != null) {
    816821            baseHdg =  Math.toDegrees(previousNode.getEastNorth()
    817                 .heading(currentBaseNode.getEastNorth()));
     822                    .heading(currentBaseNode.getEastNorth()));
    818823        }
    819824
     
    869874            if (selectedNode == selectedWay.getNode(0)){
    870875                currentBaseNode = selectedNode;
    871                 if (selectedWay.getNodesCount()>1) previousNode = selectedWay.getNode(1);
     876                if (selectedWay.getNodesCount()>1) {
     877                    previousNode = selectedWay.getNode(1);
     878                }
    872879            }
    873880            if (selectedNode == selectedWay.lastNode()) {
    874881                currentBaseNode = selectedNode;
    875                 if (selectedWay.getNodesCount()>1)
     882                if (selectedWay.getNodesCount()>1) {
    876883                    previousNode = selectedWay.getNode(selectedWay.getNodesCount()-2);
     884                }
    877885            }
    878886        }
     
    10181026        if (snapHelper.dir2!=null && currentBaseNode!=null) {
    10191027            EastNorth xPoint = Geometry.getSegmentSegmentIntersection(p1, p2, snapHelper.dir2, currentBaseNode.getEastNorth());
    1020             if (xPoint!=null) n.setEastNorth(xPoint);
     1028            if (xPoint!=null) {
     1029                n.setEastNorth(xPoint);
     1030            }
    10211031        }
    10221032    }
     
    10271037     * done in redrawIfRequired. This means, calling addHighlighting() without redrawIfRequired()
    10281038     * will leave the data in an inconsistent state.
    1029      * 
     1039     *
    10301040     * The status bar derives its information from oldHighlights, so in order to update the status
    10311041     * bar both addHighlighting() and repaintIfRequired() are needed, since former fills newHighlights
     
    10791089        // sanity checks
    10801090        if (Main.map.mapView == null || mousePos == null
    1081         // don't draw line if we don't know where from or where to
    1082         || currentBaseNode == null || currentMouseEastNorth == null
    1083         // don't draw line if mouse is outside window
    1084         || !Main.map.mapView.getBounds().contains(mousePos))
     1091                // don't draw line if we don't know where from or where to
     1092                || currentBaseNode == null || currentMouseEastNorth == null
     1093                // don't draw line if mouse is outside window
     1094                || !Main.map.mapView.getBounds().contains(mousePos))
    10851095            return;
    10861096
     
    10881098        snapHelper.drawIfNeeded(g2,mv);
    10891099        if (!drawHelperLine || wayIsFinished || shift)
    1090           return;
     1100            return;
    10911101
    10921102        if (!snapHelper.isActive()) { // else use color and stoke from  snapHelper.draw
     
    12051215        if (currentBaseNode != null && !ds.getSelected().isEmpty()) {
    12061216            Way continueFrom = getWayForNode(currentBaseNode);
    1207             if (alt && continueFrom != null) {
     1217            if (alt && continueFrom != null)
    12081218                return Collections.<OsmPrimitive>singleton(continueFrom);
    1209             }
    12101219        }
    12111220        return ds.getSelected();
     
    12501259            }
    12511260            // select last added node - maybe we will continue drawing from it
    1252             if (n!=null) getCurrentDataSet().addSelected(n);
     1261            if (n!=null) {
     1262                getCurrentDataSet().addSelected(n);
     1263            }
    12531264        }
    12541265    }
     
    12991310
    13001311            Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles",
    1301                 Arrays.asList("0","30","45","60","90","120","135","150","180"));
     1312                    Arrays.asList("0","30","45","60","90","120","135","150","180"));
    13021313
    13031314            snapAngles = new double[2*angles.size()];
     
    13251336
    13261337            highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"),
    1327                 new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128));
     1338                    new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128));
    13281339            highlightStroke = new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    13291340
    13301341            float dash1[] = { 4.0f };
    13311342            helperStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
    1332                 BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
     1343                    BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
    13331344        }
    13341345
     
    14111422            if (snapOn && (activeBaseHeading>=0)) {
    14121423                angle = curHeading - activeBaseHeading;
    1413                 if (angle < 0) angle+=360;
    1414                 if (angle > 360) angle=0;
     1424                if (angle < 0) {
     1425                    angle+=360;
     1426                }
     1427                if (angle > 360) {
     1428                    angle=0;
     1429                }
    14151430
    14161431                double nearestAngle;
     
    14551470            if (baseHeading >=0 ) { // there is previous line segment with some heading
    14561471                angle = hdg - baseHeading;
    1457                 if (angle < 0) angle+=360;
    1458                 if (angle > 360) angle=0;
     1472                if (angle < 0) {
     1473                    angle+=360;
     1474                }
     1475                if (angle > 360) {
     1476                    angle=0;
     1477                }
    14591478            }
    14601479            showStatusInfo(angle, hdg, distance, isSnapOn());
     
    15041523                    Way w = selectedWays.iterator().next();
    15051524                    Collection <EastNorth> pointsToProject = new ArrayList<EastNorth>();
    1506                     if (w.getNodesCount()<1000) for (Node n: w.getNodes()) {
    1507                         pointsToProject.add(n.getEastNorth());
     1525                    if (w.getNodesCount()<1000) {
     1526                        for (Node n: w.getNodes()) {
     1527                            pointsToProject.add(n.getEastNorth());
     1528                        }
    15081529                    }
    15091530                    if (customBaseHeading >=0 ) {
     
    15441565            double hdg = segmentPoint1.heading(segmentPoint2);
    15451566            hdg=Math.toDegrees(hdg);
    1546             if (hdg<0) hdg+=360;
    1547             if (hdg>360) hdg-=360;
     1567            if (hdg<0) {
     1568                hdg+=360;
     1569            }
     1570            if (hdg>360) {
     1571                hdg-=360;
     1572            }
    15481573            //fixed=true;
    15491574            //absoluteFix=true;
     
    15541579            if (snapOn) {
    15551580                // turn off snapping if we are in fixed mode or no actile snapping line exist
    1556                 if (fixed || !active) { snapOn=false; unsetFixedMode(); }
    1557                 else setFixedMode();
     1581                if (fixed || !active) { snapOn=false; unsetFixedMode(); } else {
     1582                    setFixedMode();
     1583                }
    15581584            } else {
    15591585                snapOn=true;
     
    16091635                }
    16101636            }
    1611             if (Math.abs(bestAngle-360) < 1e-3)
     1637            if (Math.abs(bestAngle-360) < 1e-3) {
    16121638                bestAngle=0;
     1639            }
    16131640            return bestAngle;
    16141641        }
     
    16231650
    16241651        private void unFixOrTurnOff() {
    1625             if (absoluteFix)
     1652            if (absoluteFix) {
    16261653                unsetFixedMode();
    1627             else
     1654            } else {
    16281655                toggleSnapping();
     1656            }
    16291657        }
    16301658
     
    17061734        public SnapChangeAction() {
    17071735            super(tr("Angle snapping"), "anglesnap",
    1708                 tr("Switch angle snapping mode while drawing"), null, false);
     1736                    tr("Switch angle snapping mode while drawing"), null, false);
    17091737            putValue("help", ht("/Action/Draw/AngleSnap"));
    17101738        }
     
    17121740        @Override
    17131741        public void actionPerformed(ActionEvent e) {
    1714             if (snapHelper!=null) snapHelper.toggleSnapping();
     1742            if (snapHelper!=null) {
     1743                snapHelper.toggleSnapping();
     1744            }
    17151745        }
    17161746    }
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r5170 r5512  
    6868
    6969    private final DataSetListenerAdapter datasetAdapter = new DataSetListenerAdapter(this);
    70     private Set<DataSet> changedDatasets = new HashSet<DataSet>();
     70    private final Set<DataSet> changedDatasets = new HashSet<DataSet>();
    7171    private final List<AutosaveLayerInfo> layersInfo = new ArrayList<AutosaveLayerInfo>();
    7272    private Timer timer;
     
    163163            info.layerName = info.layer.getName();
    164164        }
    165         if (changedDatasets.contains(info.layer.data)) {
     165        if (changedDatasets.remove(info.layer.data)) {
    166166            File file = getNewLayerFile(info);
    167167            if (file != null) {
Note: See TracChangeset for help on using the changeset viewer.