Ignore:
Timestamp:
2008-12-23T15:07:05+01:00 (16 years ago)
Author:
stoecker
Message:

removed usage of tab stops

Location:
trunk/src/org/openstreetmap/josm/corrector
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/corrector/CorrectionTable.java

    r1001 r1169  
    1313        extends JTable {
    1414
    15         private static final int MAX_VISIBLE_LINES = 10;
     15    private static final int MAX_VISIBLE_LINES = 10;
    1616
    1717    public static class BoldRenderer extends JLabel implements
    18                 TableCellRenderer {
     18            TableCellRenderer {
    1919
    20                 public Component getTableCellRendererComponent(JTable table,
    21                         Object value, boolean isSelected, boolean hasFocus, int row,
    22                         int column) {
     20        public Component getTableCellRendererComponent(JTable table,
     21                Object value, boolean isSelected, boolean hasFocus, int row,
     22                int column) {
    2323
    24                         Font f = getFont();
    25                         setFont(new Font(f.getName(), f.getStyle() | Font.BOLD, f.getSize()));
     24            Font f = getFont();
     25            setFont(new Font(f.getName(), f.getStyle() | Font.BOLD, f.getSize()));
    2626
    27                         setText((String)value);
     27            setText((String)value);
    2828
    29                         return this;
    30                 }
    31         }
     29            return this;
     30        }
     31    }
    3232
    33         private static BoldRenderer boldRenderer = null;
     33    private static BoldRenderer boldRenderer = null;
    3434
    35         protected CorrectionTable(TM correctionTableModel) {
    36                 super(correctionTableModel);
     35    protected CorrectionTable(TM correctionTableModel) {
     36        super(correctionTableModel);
    3737
    38                 final int correctionsSize = correctionTableModel.getCorrections().size();
    39                 final int lines = correctionsSize > MAX_VISIBLE_LINES ? MAX_VISIBLE_LINES
     38        final int correctionsSize = correctionTableModel.getCorrections().size();
     39        final int lines = correctionsSize > MAX_VISIBLE_LINES ? MAX_VISIBLE_LINES
    4040                : correctionsSize;
    41                 setPreferredScrollableViewportSize(new Dimension(400, lines
    42                         * getRowHeight()));
    43                 getColumnModel().getColumn(correctionTableModel.getApplyColumn())
     41        setPreferredScrollableViewportSize(new Dimension(400, lines
     42                * getRowHeight()));
     43        getColumnModel().getColumn(correctionTableModel.getApplyColumn())
    4444                .setPreferredWidth(40);
    45                 setRowSelectionAllowed(false);
    46         }
     45        setRowSelectionAllowed(false);
     46    }
    4747
    48         public TableCellRenderer getCellRenderer(int row, int column) {
    49                 if (getCorrectionTableModel().isBoldCell(row, column)) {
    50                         if (boldRenderer == null)
    51                                 boldRenderer = new BoldRenderer();
    52                         return boldRenderer;
    53                 }
    54                 return super.getCellRenderer(row, column);
    55         }
     48    public TableCellRenderer getCellRenderer(int row, int column) {
     49        if (getCorrectionTableModel().isBoldCell(row, column)) {
     50            if (boldRenderer == null)
     51                boldRenderer = new BoldRenderer();
     52            return boldRenderer;
     53        }
     54        return super.getCellRenderer(row, column);
     55    }
    5656
    57         @SuppressWarnings("unchecked")
     57    @SuppressWarnings("unchecked")
    5858    public TM getCorrectionTableModel() {
    59                 return (TM)getModel();
    60         }
     59        return (TM)getModel();
     60    }
    6161
    6262}
  • trunk/src/org/openstreetmap/josm/corrector/CorrectionTableModel.java

    r1001 r1169  
    1212        AbstractTableModel {
    1313
    14         private List<C> corrections;
    15         private boolean[] apply;
    16         private int applyColumn;
     14    private List<C> corrections;
     15    private boolean[] apply;
     16    private int applyColumn;
    1717
    18         public CorrectionTableModel(List<C> corrections) {
    19                 super();
    20                 this.corrections = corrections;
    21                 apply = new boolean[this.corrections.size()];
    22                 Arrays.fill(apply, true);
    23                 applyColumn = getColumnCount() - 1;
    24         }
    25 
    26         abstract public int getColumnCount();
    27 
    28         abstract protected boolean isBoldCell(int row, int column);
    29         abstract public String getCorrectionColumnName(int colIndex);
    30         abstract public Object getCorrectionValueAt(int rowIndex, int colIndex);
    31 
    32         public List<C> getCorrections() {
    33                 return corrections;
    34         }
    35        
    36         public int getApplyColumn() {
    37                 return applyColumn;
    38         }
    39        
    40     public boolean getApply(int i) {
    41         return apply[i];
     18    public CorrectionTableModel(List<C> corrections) {
     19        super();
     20        this.corrections = corrections;
     21        apply = new boolean[this.corrections.size()];
     22        Arrays.fill(apply, true);
     23        applyColumn = getColumnCount() - 1;
    4224    }
    4325
    44         public int getRowCount() {
    45         return corrections.size();
     26    abstract public int getColumnCount();
     27
     28    abstract protected boolean isBoldCell(int row, int column);
     29    abstract public String getCorrectionColumnName(int colIndex);
     30    abstract public Object getCorrectionValueAt(int rowIndex, int colIndex);
     31
     32    public List<C> getCorrections() {
     33        return corrections;
    4634    }
    4735
    48         @Override
    49     public Class<?> getColumnClass(int columnIndex) {
    50         if (columnIndex == applyColumn)
    51                 return Boolean.class;
    52         return String.class;
     36    public int getApplyColumn() {
     37        return applyColumn;
    5338    }
    5439
    55         @Override
    56         public String getColumnName(int columnIndex) {
    57         if (columnIndex == applyColumn)
    58                 return tr("Apply?");
    59                
    60                 return getCorrectionColumnName(columnIndex);
    61         }
    62 
    63         @Override
    64     public boolean isCellEditable(int rowIndex, int columnIndex) {
    65         return columnIndex == applyColumn;
     40    public boolean getApply(int i) {
     41        return apply[i];
    6642    }
    6743
    68         @Override
     44    public int getRowCount() {
     45        return corrections.size();
     46    }
     47
     48    @Override
     49    public Class<?> getColumnClass(int columnIndex) {
     50        if (columnIndex == applyColumn)
     51            return Boolean.class;
     52        return String.class;
     53    }
     54
     55    @Override
     56    public String getColumnName(int columnIndex) {
     57        if (columnIndex == applyColumn)
     58            return tr("Apply?");
     59
     60        return getCorrectionColumnName(columnIndex);
     61    }
     62
     63    @Override
     64    public boolean isCellEditable(int rowIndex, int columnIndex) {
     65        return columnIndex == applyColumn;
     66    }
     67
     68    @Override
    6969    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    70         if (columnIndex == applyColumn && aValue instanceof Boolean)
    71                 apply[rowIndex] = (Boolean)aValue;
     70        if (columnIndex == applyColumn && aValue instanceof Boolean)
     71            apply[rowIndex] = (Boolean)aValue;
    7272    }
    7373
    7474    public Object getValueAt(int rowIndex, int colIndex) {
    75         if (colIndex == applyColumn)
    76                 return apply[rowIndex];
    77        
    78         return getCorrectionValueAt(rowIndex, colIndex);
    79         }
     75        if (colIndex == applyColumn)
     76            return apply[rowIndex];
     77
     78        return getCorrectionValueAt(rowIndex, colIndex);
     79    }
    8080}
  • trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java

    r1002 r1169  
    2222public class ReverseWayTagCorrector extends TagCorrector<Way> {
    2323
    24         private static class PrefixSuffixSwitcher {
     24    private static class PrefixSuffixSwitcher {
    2525
    26                 private final String a;
    27                 private final String b;
    28                 private final Pattern startPattern;
    29                 private final Pattern endPattern;
     26        private final String a;
     27        private final String b;
     28        private final Pattern startPattern;
     29        private final Pattern endPattern;
    3030
    31                 private final String SEPARATOR = "[:_]?";
    32                
    33                 public PrefixSuffixSwitcher(String a, String b) {
     31        private final String SEPARATOR = "[:_]?";
     32
     33        public PrefixSuffixSwitcher(String a, String b) {
    3434            this.a = a;
    3535            this.b = b;
     
    4040                    SEPARATOR + "(" + a + "|" + b + ")$",
    4141                    Pattern.CASE_INSENSITIVE);
    42                 }
     42        }
    4343
    44                 public String apply(String text) {
    45                         Matcher m = startPattern.matcher(text);
    46                         if (!m.lookingAt())
    47                                 m = endPattern.matcher(text);
     44        public String apply(String text) {
     45            Matcher m = startPattern.matcher(text);
     46            if (!m.lookingAt())
     47                m = endPattern.matcher(text);
    4848
    49                         if (m.lookingAt()) {
    50                                 String leftRight = m.group(1).toLowerCase();
     49            if (m.lookingAt()) {
     50                String leftRight = m.group(1).toLowerCase();
    5151
    52                                 StringBuilder result = new StringBuilder();
    53                                 result.append(text.substring(0, m.start(1)));
    54                                 result.append(leftRight.equals(a) ? b : a);
    55                                 result.append(text.substring(m.end(1)));
    56                                
    57                                 return result.toString();
    58                         }
    59                         return text;
    60                 }
    61         }
     52                StringBuilder result = new StringBuilder();
     53                result.append(text.substring(0, m.start(1)));
     54                result.append(leftRight.equals(a) ? b : a);
     55                result.append(text.substring(m.end(1)));
    6256
    63         private static PrefixSuffixSwitcher[] prefixSuffixSwitchers =
    64                 new PrefixSuffixSwitcher[] {
    65                     new PrefixSuffixSwitcher("left", "right"),
    66                     new PrefixSuffixSwitcher("forward", "backward")
    67                 };
     57                return result.toString();
     58            }
     59            return text;
     60        }
     61    }
    6862
    69         @Override
    70         public Collection<Command> execute(Way way) throws UserCancelException {
    71                 Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap =
    72                         new HashMap<OsmPrimitive, List<TagCorrection>>();
     63    private static PrefixSuffixSwitcher[] prefixSuffixSwitchers =
     64            new PrefixSuffixSwitcher[] {
     65                new PrefixSuffixSwitcher("left", "right"),
     66                new PrefixSuffixSwitcher("forward", "backward")
     67            };
    7368
    74                 ArrayList<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
    75                 primitives.add(way);
    76                 primitives.addAll(way.nodes);
     69    @Override
     70    public Collection<Command> execute(Way way) throws UserCancelException {
     71        Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap =
     72                new HashMap<OsmPrimitive, List<TagCorrection>>();
    7773
    78                 for (OsmPrimitive primitive : primitives) {
    79                         tagCorrectionsMap.put(primitive, new ArrayList<TagCorrection>());
     74        ArrayList<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
     75        primitives.add(way);
     76        primitives.addAll(way.nodes);
    8077
    81                         for (String key : primitive.keySet()) {
    82                                 String newKey = key;
    83                                 String value = primitive.get(key);
    84                                 String newValue = value;
     78        for (OsmPrimitive primitive : primitives) {
     79            tagCorrectionsMap.put(primitive, new ArrayList<TagCorrection>());
    8580
    86                                 if (key.equals("oneway")) {
    87                                         if (value.equals("-1"))
    88                                                 newValue = OsmUtils.trueval;
    89                                         else {
    90                                                 Boolean boolValue = OsmUtils.getOsmBoolean(value);
    91                                                 if (boolValue != null && boolValue.booleanValue()) {
    92                                                         newValue = "-1";
    93                                                 }
    94                                         }
    95                                 } else {
    96                                         for (PrefixSuffixSwitcher prefixSuffixSwitcher : prefixSuffixSwitchers) {
    97                                                 newKey = prefixSuffixSwitcher.apply(key);
    98                                                 if (!key.equals(newKey))
    99                                                         break;
    100                                         }
    101                                 }
     81            for (String key : primitive.keySet()) {
     82                String newKey = key;
     83                String value = primitive.get(key);
     84                String newValue = value;
    10285
    103                                 if (!key.equals(newKey) || !value.equals(newValue))
    104                                         tagCorrectionsMap.get(primitive).add(
    105                                                 new TagCorrection(key, value, newKey, newValue));
    106                         }
    107                 }
     86                if (key.equals("oneway")) {
     87                    if (value.equals("-1"))
     88                        newValue = OsmUtils.trueval;
     89                    else {
     90                        Boolean boolValue = OsmUtils.getOsmBoolean(value);
     91                        if (boolValue != null && boolValue.booleanValue()) {
     92                            newValue = "-1";
     93                        }
     94                    }
     95                } else {
     96                    for (PrefixSuffixSwitcher prefixSuffixSwitcher : prefixSuffixSwitchers) {
     97                        newKey = prefixSuffixSwitcher.apply(key);
     98                        if (!key.equals(newKey))
     99                            break;
     100                    }
     101                }
    108102
    109                 Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap =
    110                         new HashMap<OsmPrimitive, List<RoleCorrection>>();
    111                 roleCorrectionMap.put(way, new ArrayList<RoleCorrection>());
     103                if (!key.equals(newKey) || !value.equals(newValue))
     104                    tagCorrectionsMap.get(primitive).add(
     105                            new TagCorrection(key, value, newKey, newValue));
     106            }
     107        }
    112108
    113                 for (Relation relation : Main.ds.relations) {
    114                         for (RelationMember member : relation.members) {
    115                                 if (!member.member.realEqual(way, true)
    116                                         || member.role.length() == 0)
    117                                         continue;
     109        Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap =
     110                new HashMap<OsmPrimitive, List<RoleCorrection>>();
     111        roleCorrectionMap.put(way, new ArrayList<RoleCorrection>());
    118112
    119                                 boolean found = false;
    120                                 String newRole = null;
    121                                 for (PrefixSuffixSwitcher prefixSuffixSwitcher : prefixSuffixSwitchers) {
    122                                         newRole = prefixSuffixSwitcher.apply(member.role);
    123                                         if (!newRole.equals(member.role)) {
    124                                                 found = true;
    125                                                 break;
    126                                         }
    127                                 }
     113        for (Relation relation : Main.ds.relations) {
     114            for (RelationMember member : relation.members) {
     115                if (!member.member.realEqual(way, true)
     116                        || member.role.length() == 0)
     117                    continue;
    128118
    129                                 if (found)
    130                                         roleCorrectionMap.get(way).add(
    131                                                 new RoleCorrection(relation, member, newRole));
    132                         }
    133                 }
     119                boolean found = false;
     120                String newRole = null;
     121                for (PrefixSuffixSwitcher prefixSuffixSwitcher : prefixSuffixSwitchers) {
     122                    newRole = prefixSuffixSwitcher.apply(member.role);
     123                    if (!newRole.equals(member.role)) {
     124                        found = true;
     125                        break;
     126                    }
     127                }
    134128
    135                 return applyCorrections(tagCorrectionsMap, roleCorrectionMap,
    136                         tr("When reverting this way, following changes to properties "
    137                                 + "of the way and its nodes are suggested in order "
    138                                 + "to maintain data consistency."));
    139         }
     129                if (found)
     130                    roleCorrectionMap.get(way).add(
     131                            new RoleCorrection(relation, member, newRole));
     132            }
     133        }
     134
     135        return applyCorrections(tagCorrectionsMap, roleCorrectionMap,
     136                tr("When reverting this way, following changes to properties "
     137                        + "of the way and its nodes are suggested in order "
     138                        + "to maintain data consistency."));
     139    }
    140140}
  • trunk/src/org/openstreetmap/josm/corrector/TagCorrection.java

    r1000 r1169  
    44public class TagCorrection implements Correction {
    55
    6         public final String oldKey;
    7         public final String newKey;
    8         public final String oldValue;
    9         public final String newValue;
     6    public final String oldKey;
     7    public final String newKey;
     8    public final String oldValue;
     9    public final String newValue;
    1010
    11         public TagCorrection(String oldKey, String oldValue, String newKey,
     11    public TagCorrection(String oldKey, String oldValue, String newKey,
    1212            String newValue) {
    13                 this.oldKey = oldKey;
    14                 this.oldValue = oldValue;
    15                 this.newKey = newKey;
    16                 this.newValue = newValue;
    17         }
     13        this.oldKey = oldKey;
     14        this.oldValue = oldValue;
     15        this.newKey = newKey;
     16        this.newValue = newValue;
     17    }
    1818
    19         public boolean isKeyChanged() {
    20                 return !newKey.equals(oldKey);
    21         }
     19    public boolean isKeyChanged() {
     20        return !newKey.equals(oldKey);
     21    }
    2222
    23         public boolean isValueChanged() {
    24                 return !newValue.equals(oldValue);
    25         }
     23    public boolean isValueChanged() {
     24        return !newValue.equals(oldValue);
     25    }
    2626}
  • trunk/src/org/openstreetmap/josm/corrector/TagCorrectionTable.java

    r1000 r1169  
    77        CorrectionTable<TagCorrectionTableModel> {
    88
    9         public TagCorrectionTable(List<TagCorrection> tagCorrections) {
    10                 super(new TagCorrectionTableModel(tagCorrections));
    11         }
     9    public TagCorrectionTable(List<TagCorrection> tagCorrections) {
     10        super(new TagCorrectionTableModel(tagCorrections));
     11    }
    1212
    1313}
  • trunk/src/org/openstreetmap/josm/corrector/TagCorrectionTableModel.java

    r1000 r1169  
    88public class TagCorrectionTableModel extends CorrectionTableModel<TagCorrection> {
    99
    10         public TagCorrectionTableModel(List<TagCorrection> tagCorrections) {
    11                 super(tagCorrections);
    12         }
     10    public TagCorrectionTableModel(List<TagCorrection> tagCorrections) {
     11        super(tagCorrections);
     12    }
    1313
    14         @Override
    15         public int getColumnCount() {
    16                 return 5;
    17         }
     14    @Override
     15    public int getColumnCount() {
     16        return 5;
     17    }
    1818
    19         @Override
    20         public String getCorrectionColumnName(int colIndex) {
    21                 switch (colIndex) {
    22                 case 0:
    23                         return tr("Old key");
    24                 case 1:
    25                         return tr("Old value");
    26                 case 2:
    27                         return tr("New key");
    28                 case 3:
    29                         return tr("New value");
    30                 }
    31                 return null;
    32         }
     19    @Override
     20    public String getCorrectionColumnName(int colIndex) {
     21        switch (colIndex) {
     22        case 0:
     23            return tr("Old key");
     24        case 1:
     25            return tr("Old value");
     26        case 2:
     27            return tr("New key");
     28        case 3:
     29            return tr("New value");
     30        }
     31        return null;
     32    }
    3333
    3434    public Object getCorrectionValueAt(int rowIndex, int colIndex) {
    35                 TagCorrection tagCorrection = getCorrections().get(rowIndex);
     35        TagCorrection tagCorrection = getCorrections().get(rowIndex);
    3636
    37                 switch (colIndex) {
    38                 case 0:
    39                         return tagCorrection.oldKey;
    40                 case 1:
    41                         return tagCorrection.oldValue;
    42                 case 2:
    43                         return tagCorrection.newKey;
    44                 case 3:
    45                         return tagCorrection.newValue;
    46                 }
    47                 return null;
    48         }
     37        switch (colIndex) {
     38        case 0:
     39            return tagCorrection.oldKey;
     40        case 1:
     41            return tagCorrection.oldValue;
     42        case 2:
     43            return tagCorrection.newKey;
     44        case 3:
     45            return tagCorrection.newValue;
     46        }
     47        return null;
     48    }
    4949
    50         protected boolean isBoldCell(int row, int column) {
    51                 TagCorrection tagCorrection = getCorrections().get(row);
    52                 return (column == 2 && tagCorrection.isKeyChanged())
    53                         || (column == 3 && tagCorrection.isValueChanged());
    54         }
     50    protected boolean isBoldCell(int row, int column) {
     51        TagCorrection tagCorrection = getCorrections().get(row);
     52        return (column == 2 && tagCorrection.isKeyChanged())
     53                || (column == 3 && tagCorrection.isValueChanged());
     54    }
    5555
    5656}
  • trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java

    r1107 r1169  
    3333public abstract class TagCorrector<P extends OsmPrimitive> {
    3434
    35         public abstract Collection<Command> execute(P primitive) 
    36             throws UserCancelException;
     35    public abstract Collection<Command> execute(P primitive)
     36        throws UserCancelException;
    3737
    38     private String[] applicationOptions = new String[] { 
    39         tr("Apply selected changes"), 
    40         tr("Don't apply changes"), 
    41         tr("Cancel") 
     38    private String[] applicationOptions = new String[] {
     39        tr("Apply selected changes"),
     40        tr("Don't apply changes"),
     41        tr("Cancel")
    4242    };
    43    
    44         protected Collection<Command> applyCorrections(
    45                 Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap,
    46                 Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap,
    47                 String description) throws UserCancelException {
    4843
    49                 boolean hasCorrections = false;
    50                 for (List<TagCorrection> tagCorrectionList : tagCorrectionsMap.values()) {
    51                         if (!tagCorrectionList.isEmpty()) {
    52                                 hasCorrections = true;
    53                                 break;
    54                         }
    55                 }
     44    protected Collection<Command> applyCorrections(
     45            Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap,
     46            Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap,
     47            String description) throws UserCancelException {
    5648
    57                 if (!hasCorrections)
    58                         for (List<RoleCorrection> roleCorrectionList : roleCorrectionMap
    59                                 .values()) {
    60                                 if (!roleCorrectionList.isEmpty()) {
    61                                         hasCorrections = true;
    62                                         break;
    63                                 }
    64                         }
     49        boolean hasCorrections = false;
     50        for (List<TagCorrection> tagCorrectionList : tagCorrectionsMap.values()) {
     51            if (!tagCorrectionList.isEmpty()) {
     52                hasCorrections = true;
     53                break;
     54            }
     55        }
    6556
    66                 if (hasCorrections) {
    67                         Collection<Command> commands = new ArrayList<Command>();
    68                         Map<OsmPrimitive, TagCorrectionTable> tagTableMap =
    69                             new HashMap<OsmPrimitive, TagCorrectionTable>();
    70                         Map<OsmPrimitive, RoleCorrectionTable> roleTableMap =
    71                             new HashMap<OsmPrimitive, RoleCorrectionTable>();
     57        if (!hasCorrections)
     58            for (List<RoleCorrection> roleCorrectionList : roleCorrectionMap
     59                    .values()) {
     60                if (!roleCorrectionList.isEmpty()) {
     61                    hasCorrections = true;
     62                    break;
     63                }
     64            }
    7265
    73                         NameVisitor nameVisitor = new NameVisitor();
     66        if (hasCorrections) {
     67            Collection<Command> commands = new ArrayList<Command>();
     68            Map<OsmPrimitive, TagCorrectionTable> tagTableMap =
     69                new HashMap<OsmPrimitive, TagCorrectionTable>();
     70            Map<OsmPrimitive, RoleCorrectionTable> roleTableMap =
     71                new HashMap<OsmPrimitive, RoleCorrectionTable>();
    7472
    75                         final JPanel p = new JPanel(new GridBagLayout());
     73            NameVisitor nameVisitor = new NameVisitor();
    7674
    77                         final JMultilineLabel label1 = new JMultilineLabel(description);
    78                         label1.setMaxWidth(400);
    79                         p.add(label1, GBC.eop());
     75            final JPanel p = new JPanel(new GridBagLayout());
    8076
    81                         final JMultilineLabel label2 = new JMultilineLabel(
    82                                 tr("Please select which property changes you want to apply."));
    83                         label2.setMaxWidth(400);
    84                         p.add(label2, GBC.eop());
     77            final JMultilineLabel label1 = new JMultilineLabel(description);
     78            label1.setMaxWidth(400);
     79            p.add(label1, GBC.eop());
    8580
    86                         for (OsmPrimitive primitive : tagCorrectionsMap.keySet()) {
    87                                 final List<TagCorrection> tagCorrections = tagCorrectionsMap
    88                                         .get(primitive);
     81            final JMultilineLabel label2 = new JMultilineLabel(
     82                    tr("Please select which property changes you want to apply."));
     83            label2.setMaxWidth(400);
     84            p.add(label2, GBC.eop());
    8985
    90                                 if (tagCorrections.isEmpty())
    91                                         continue;
     86            for (OsmPrimitive primitive : tagCorrectionsMap.keySet()) {
     87                final List<TagCorrection> tagCorrections = tagCorrectionsMap
     88                        .get(primitive);
    9289
    93                                 primitive.visit(nameVisitor);
     90                if (tagCorrections.isEmpty())
     91                    continue;
    9492
    95                                 final JLabel propertiesLabel = new JLabel(tr("Properties of "));
    96                                 p.add(propertiesLabel, GBC.std());
     93                primitive.visit(nameVisitor);
    9794
    98                                 final JLabel primitiveLabel = new JLabel(
    99                                         nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT);
    100                                 p.add(primitiveLabel, GBC.eol());
     95                final JLabel propertiesLabel = new JLabel(tr("Properties of "));
     96                p.add(propertiesLabel, GBC.std());
    10197
    102                                 final TagCorrectionTable table = new TagCorrectionTable(
    103                                         tagCorrections);
    104                                 final JScrollPane scrollPane = new JScrollPane(table);
    105                                 p.add(scrollPane, GBC.eop());
     98                final JLabel primitiveLabel = new JLabel(
     99                        nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT);
     100                p.add(primitiveLabel, GBC.eol());
    106101
    107                                 tagTableMap.put(primitive, table);
    108                         }
     102                final TagCorrectionTable table = new TagCorrectionTable(
     103                        tagCorrections);
     104                final JScrollPane scrollPane = new JScrollPane(table);
     105                p.add(scrollPane, GBC.eop());
    109106
    110                         for (OsmPrimitive primitive : roleCorrectionMap.keySet()) {
    111                                 final List<RoleCorrection> roleCorrections = roleCorrectionMap
    112                                         .get(primitive);
    113                                 if (roleCorrections.isEmpty())
    114                                         continue;
     107                tagTableMap.put(primitive, table);
     108            }
    115109
    116                                 primitive.visit(nameVisitor);
     110            for (OsmPrimitive primitive : roleCorrectionMap.keySet()) {
     111                final List<RoleCorrection> roleCorrections = roleCorrectionMap
     112                        .get(primitive);
     113                if (roleCorrections.isEmpty())
     114                    continue;
    117115
    118                                 final JLabel rolesLabel = new JLabel(
    119                                         tr("Roles in relations referring to"));
    120                                 p.add(rolesLabel, GBC.std());
     116                primitive.visit(nameVisitor);
    121117
    122                                 final JLabel primitiveLabel = new JLabel(
    123                                         nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT);
    124                                 p.add(primitiveLabel, GBC.eol());
     118                final JLabel rolesLabel = new JLabel(
     119                        tr("Roles in relations referring to"));
     120                p.add(rolesLabel, GBC.std());
    125121
    126                                 final RoleCorrectionTable table = new RoleCorrectionTable(
    127                                         roleCorrections);
    128                                 final JScrollPane scrollPane = new JScrollPane(table);
    129                                 p.add(scrollPane, GBC.eop());
     122                final JLabel primitiveLabel = new JLabel(
     123                        nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT);
     124                p.add(primitiveLabel, GBC.eol());
    130125
    131                                 roleTableMap.put(primitive, table);
    132                         }
     126                final RoleCorrectionTable table = new RoleCorrectionTable(
     127                        roleCorrections);
     128                final JScrollPane scrollPane = new JScrollPane(table);
     129                p.add(scrollPane, GBC.eop());
    133130
    134                         int answer = JOptionPane.showOptionDialog(Main.parent, p,
     131                roleTableMap.put(primitive, table);
     132            }
     133
     134            int answer = JOptionPane.showOptionDialog(Main.parent, p,
    135135                    tr("Automatic tag correction"), JOptionPane.YES_NO_CANCEL_OPTION,
    136                     JOptionPane.PLAIN_MESSAGE, null, 
     136                    JOptionPane.PLAIN_MESSAGE, null,
    137137                    applicationOptions, applicationOptions[0]);
    138138
    139                         if (answer == JOptionPane.YES_OPTION) {
    140                                 for (OsmPrimitive primitive : tagCorrectionsMap.keySet()) {
    141                                         List<TagCorrection> tagCorrections = 
     139            if (answer == JOptionPane.YES_OPTION) {
     140                for (OsmPrimitive primitive : tagCorrectionsMap.keySet()) {
     141                    List<TagCorrection> tagCorrections =
    142142                        tagCorrectionsMap.get(primitive);
    143                    
     143
    144144                    // create the clone
    145145                    OsmPrimitive clone = null;
     
    147147                    else if (primitive instanceof Node) clone = new Node((Node)primitive);
    148148                    else if (primitive instanceof Relation) clone = new Relation((Relation)primitive);
    149                    
     149
    150150                    // use this structure to remember keys that have been set already so that
    151151                    // they're not dropped by a later step
    152152                    Set<String> keysChanged = new HashSet<String>();
    153                    
     153
    154154                    // apply all changes to this clone
    155                                         for (int i = 0; i < tagCorrections.size(); i++) {
    156                                                 if (tagTableMap.get(primitive).getCorrectionTableModel().getApply(i)) {
    157                                                         TagCorrection tagCorrection = tagCorrections.get(i);
    158                                                         if (tagCorrection.isKeyChanged() && !keysChanged.contains(tagCorrection.oldKey)) clone.remove(tagCorrection.oldKey);
    159                                                         clone.put(tagCorrection.newKey, tagCorrection.newValue);
    160                                                         keysChanged.add(tagCorrection.newKey);
    161                                                 }
    162                                         }
    163                    
     155                    for (int i = 0; i < tagCorrections.size(); i++) {
     156                        if (tagTableMap.get(primitive).getCorrectionTableModel().getApply(i)) {
     157                            TagCorrection tagCorrection = tagCorrections.get(i);
     158                            if (tagCorrection.isKeyChanged() && !keysChanged.contains(tagCorrection.oldKey)) clone.remove(tagCorrection.oldKey);
     159                            clone.put(tagCorrection.newKey, tagCorrection.newValue);
     160                            keysChanged.add(tagCorrection.newKey);
     161                        }
     162                    }
     163
    164164                    // save the clone
    165165                    if (!keysChanged.isEmpty()) commands.add(new ChangeCommand(primitive, clone));
    166                                 }
    167                                 for (OsmPrimitive primitive : roleCorrectionMap.keySet()) {
    168                                         List<RoleCorrection> roleCorrections = roleCorrectionMap
    169                                                 .get(primitive);
    170                                         for (int i = 0; i < roleCorrections.size(); i++) {
    171                                                 if (roleTableMap.get(primitive)
    172                                                         .getCorrectionTableModel().getApply(i)) {
    173                                                         RoleCorrection roleCorrection = roleCorrections
    174                                                                 .get(i);
    175                                                         Relation newRelation = new Relation(
    176                                                                 roleCorrection.relation);
    177                                                         for (RelationMember member : newRelation.members)
    178                                                                 if (member.equals(roleCorrection.member))
    179                                                                         member.role = roleCorrection.newRole;
    180                                                         commands.add(new ChangeCommand(
    181                                                                 roleCorrection.relation, newRelation));
    182                                                 }
    183                                         }
    184                                 }
    185                         } else if (answer != JOptionPane.NO_OPTION) {
    186                             throw new UserCancelException();
    187                         }
    188                         return commands;
    189                 }
     166                }
     167                for (OsmPrimitive primitive : roleCorrectionMap.keySet()) {
     168                    List<RoleCorrection> roleCorrections = roleCorrectionMap
     169                            .get(primitive);
     170                    for (int i = 0; i < roleCorrections.size(); i++) {
     171                        if (roleTableMap.get(primitive)
     172                                .getCorrectionTableModel().getApply(i)) {
     173                            RoleCorrection roleCorrection = roleCorrections
     174                                    .get(i);
     175                            Relation newRelation = new Relation(
     176                                    roleCorrection.relation);
     177                            for (RelationMember member : newRelation.members)
     178                                if (member.equals(roleCorrection.member))
     179                                    member.role = roleCorrection.newRole;
     180                            commands.add(new ChangeCommand(
     181                                    roleCorrection.relation, newRelation));
     182                        }
     183                    }
     184                }
     185            } else if (answer != JOptionPane.NO_OPTION) {
     186                throw new UserCancelException();
     187            }
     188            return commands;
     189        }
    190190
    191                 return Collections.emptyList();
    192         }
     191        return Collections.emptyList();
     192    }
    193193}
Note: See TracChangeset for help on using the changeset viewer.