Changeset 35682 in osm


Ignore:
Timestamp:
2021-01-11T10:02:41+01:00 (6 days ago)
Author:
GerdP
Message:

see #17184: Memory Leaks

  • don't keep dialog in MultiTagAction, it is newly created each time when the shortcut is pressed
  • overwrite setVisible to clear tableModel in MultiTagDialog so that it doesn't keep refs to OSM objects
  • simplify code (sonar issues)
Location:
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagAction.java

    r35579 r35682  
    4949        if (dlg != null && dlg.isVisible()) {
    5050            dlg.doSelectionChanged(selection);
     51        } else {
     52                dlg = null;
    5153        }
    5254    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagDialog.java

    r35476 r35682  
    3535import javax.swing.ListSelectionModel;
    3636import javax.swing.UIManager;
    37 import javax.swing.event.ListSelectionEvent;
    3837import javax.swing.event.ListSelectionListener;
    3938import javax.swing.table.DefaultTableCellRenderer;
     
    138137                tableModel.updateData(MainApplication.getLayerManager().getEditDataSet().getSelected());
    139138            });
    140             ImageProvider.get(type);
    141139            p.add(jt);
    142140        }
     
    170168    }
    171169
    172     /*private OsmPrimitive getSelectedPrimitive() {
    173         int idx = tbl.getSelectedRow();
    174         if (idx>= 0) {
    175             return tableModel.getPrimitiveAt(tbl.convertRowIndexToModel(idx));
    176         } else {
    177             return null;
    178         }
    179     }*/
    180 
    181170    private final MouseAdapter tableMouseAdapter = new MouseAdapter() {
    182171        @Override
     
    189178    };
    190179
    191     private final ListSelectionListener selectionListener = new ListSelectionListener() {
    192         @Override
    193         public void valueChanged(ListSelectionEvent e) {
    194             currentSelection = getSelectedPrimitives();
    195             if (currentSelection != null && MainApplication.isDisplayingMapView()) {
    196                 if (highlightHelper.highlightOnly(currentSelection)) {
    197                     MainApplication.getMap().mapView.repaint();
    198                 }
    199             }
     180    private final ListSelectionListener selectionListener = e -> {
     181        currentSelection = getSelectedPrimitives();
     182        if (currentSelection != null && MainApplication.isDisplayingMapView()
     183                && highlightHelper.highlightOnly(currentSelection)) {
     184            MainApplication.getMap().mapView.repaint();
    200185        }
    201186    };
     
    297282        public void actionPerformed(ActionEvent e) {
    298283            String txt = cbTagSet.getText();
    299             System.out.println(txt);
     284            Logging.debug(txt);
    300285            List<String> history = cbTagSet.getHistory();
    301286            history.remove(txt);
     
    377362        }
    378363    }
     364
     365    @Override
     366    public void setVisible(boolean visible) {
     367        super.setVisible(visible);
     368        if (!visible) {
     369            tableModel.updateData(Collections.emptyList());
     370        }
     371    }
    379372}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTaggerTableModel.java

    r35436 r35682  
    77import java.util.HashSet;
    88import java.util.List;
     9import java.util.Locale;
    910import java.util.Set;
     11import java.util.stream.Collectors;
    1012
    1113import javax.swing.JTable;
     
    2830public class MultiTaggerTableModel extends AbstractTableModel implements DataSelectionListener {
    2931
    30     ArrayList<OsmPrimitive> list = new ArrayList<>(50);
     32    List<OsmPrimitive> list = new ArrayList<>();
    3133    String[] mainTags = new String[]{};
    3234    boolean[] isSpecialTag = new boolean[]{};
     
    6769        String var = mainTags[columnIndex-1];
    6870        OsmPrimitive p = list.get(rowIndex);
    69         if (var.equals("id")) {
     71        switch (var) {
     72        case "id":
    7073            return String.valueOf(p.getUniqueId());
    71         } else if (var.equals("type")) {
    72             return OsmPrimitiveType.from(p).getAPIName().substring(0, 1).toUpperCase();
    73         } else if (var.equals("area")) {
    74             if (p.getDisplayType() == OsmPrimitiveType.CLOSEDWAY) {
     74        case "type":
     75            return OsmPrimitiveType.from(p).getAPIName().substring(0, 1).toUpperCase(Locale.ENGLISH);
     76        case "area":
     77            if (p.getDisplayType() == OsmPrimitiveType.CLOSEDWAY)
    7578                return String.format("%.1f", Geometry.closedWayArea((Way) p));
    76             } else {
    77                 return "";
    78             }
    79         } else if (var.equals("length")) {
    80             if (p instanceof Way) {
     79            break;
     80        case "length":
     81            if (p instanceof Way)
    8182                return String.format("%.1f", ((Way) p).getLength());
    82             }
     83            break;
     84        default:
    8385        }
    8486        return "";
     
    179181        if (table.isEditing()) table.getCellEditor().stopCellEditing();
    180182
    181         list.clear();
    182         for (OsmPrimitive p : sel) {
    183             if (shownTypes.contains(p.getDisplayType())) {
    184                 list.add(p);
    185             }
    186         }
     183        list = sel.stream().filter(p -> shownTypes.contains(p.getDisplayType())).collect(Collectors.toList());
    187184        fireTableDataChanged();
    188185    }
Note: See TracChangeset for help on using the changeset viewer.