Changeset 10125 in josm


Ignore:
Timestamp:
2016-04-09T17:07:54+02:00 (8 years ago)
Author:
Don-vip
Message:

refactor classes from corrector package, add javadoc

Location:
trunk/src/org/openstreetmap/josm
Files:
14 added
2 edited
9 moved

Legend:

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

    r9539 r10125  
    1414
    1515import org.openstreetmap.josm.command.Command;
     16import org.openstreetmap.josm.data.correction.RoleCorrection;
     17import org.openstreetmap.josm.data.correction.TagCorrection;
    1618import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1719import org.openstreetmap.josm.data.osm.OsmUtils;
  • trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java

    r9975 r10125  
    2424import org.openstreetmap.josm.command.ChangeRelationMemberRoleCommand;
    2525import org.openstreetmap.josm.command.Command;
     26import org.openstreetmap.josm.data.correction.RoleCorrection;
     27import org.openstreetmap.josm.data.correction.TagCorrection;
    2628import org.openstreetmap.josm.data.osm.Node;
    2729import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2931import org.openstreetmap.josm.data.osm.Way;
    3032import org.openstreetmap.josm.gui.DefaultNameFormatter;
     33import org.openstreetmap.josm.gui.correction.RoleCorrectionTable;
     34import org.openstreetmap.josm.gui.correction.TagCorrectionTable;
    3135import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    3236import org.openstreetmap.josm.tools.GBC;
  • trunk/src/org/openstreetmap/josm/data/correction/Correction.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.data.correction;
    33
     4/**
     5 * Data correction. Represents any change.
     6 * @since 1001
     7 */
    48public interface Correction {
    59
  • trunk/src/org/openstreetmap/josm/data/correction/RoleCorrection.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.data.correction;
    33
    44import org.openstreetmap.josm.data.osm.Relation;
    55import org.openstreetmap.josm.data.osm.RelationMember;
    66
     7/**
     8 * Represents a change of a single {@link RelationMember} role.
     9 * @since 1001
     10 */
    711public class RoleCorrection implements Correction {
    812
     13    /** OSM relation */
    914    public final Relation relation;
     15    /** Relation member index */
    1016    public final int position;
     17    /** Relation member */
    1118    public final RelationMember member;
     19    /** New role */
    1220    public final String newRole;
    1321
    14     public RoleCorrection(Relation relation, int position,
    15                           RelationMember member, String newRole) {
     22    /**
     23     * Constructs a new {@code RoleCorrection}.
     24     * @param relation OSM relation
     25     * @param position relation member index
     26     * @param member relation member
     27     * @param newRole new role
     28     */
     29    public RoleCorrection(Relation relation, int position, RelationMember member, String newRole) {
    1630        this.relation = relation;
    1731        this.position = position;
  • trunk/src/org/openstreetmap/josm/data/correction/TagCorrection.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.data.correction;
    33
    44/**
    5  * TagCorrection reprepresents a change of a single
    6  * tag. Both key and value can be subject of this change.
     5 * Represents a change of a single tag.
     6 * Both key and value can be subject of this change.
     7 * @since 729
    78 */
    89public class TagCorrection implements Correction {
    910
     11    /** Old key */
    1012    public final String oldKey;
     13    /** New key */
    1114    public final String newKey;
     15    /** Old value */
    1216    public final String oldValue;
     17    /** New value */
    1318    public final String newValue;
    1419
    15     public TagCorrection(String oldKey, String oldValue, String newKey,
    16             String newValue) {
     20    /**
     21     * Constructs a new {@code TagCorrection}.
     22     * @param oldKey old key
     23     * @param oldValue old value
     24     * @param newKey new key
     25     * @param newValue new value
     26     */
     27    public TagCorrection(String oldKey, String oldValue, String newKey, String newValue) {
    1728        this.oldKey = oldKey;
    1829        this.oldValue = oldValue;
     
    2132    }
    2233
     34    /**
     35     * Determines if the key has changed.
     36     * @return {@code true} if the key has changed
     37     */
    2338    public boolean isKeyChanged() {
    2439        return !newKey.equals(oldKey);
    2540    }
    2641
     42    /**
     43     * Determines if the value has changed.
     44     * @return {@code true} if the value has changed
     45     */
    2746    public boolean isValueChanged() {
    2847        return !newValue.equals(oldValue);
  • trunk/src/org/openstreetmap/josm/gui/correction/CorrectionTable.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.gui.correction;
    33
    44import java.awt.Component;
     
    1010import javax.swing.table.TableCellRenderer;
    1111
    12 public abstract class CorrectionTable<T extends CorrectionTableModel<?>>
    13         extends JTable {
     12/**
     13 * Abstract correction table.
     14 * @param <T> type of table model
     15 */
     16public abstract class CorrectionTable<T extends CorrectionTableModel<?>> extends JTable {
    1417
    1518    private static final int MAX_VISIBLE_LINES = 10;
    1619
    17     public static class BoldRenderer extends JLabel implements
    18             TableCellRenderer {
     20    /**
     21     * Renders text in bold.
     22     */
     23    public static class BoldRenderer extends JLabel implements TableCellRenderer {
    1924
    2025        @Override
    2126        public Component getTableCellRendererComponent(JTable table,
    22                 Object value, boolean isSelected, boolean hasFocus, int row,
    23                 int column) {
    24 
     27                Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    2528            Font f = getFont();
    2629            setFont(new Font(f.getName(), f.getStyle() | Font.BOLD, f.getSize()));
    27 
    2830            setText((String) value);
    29 
    3031            return this;
    3132        }
     
    3839
    3940        final int correctionsSize = correctionTableModel.getCorrections().size();
    40         final int lines = correctionsSize > MAX_VISIBLE_LINES ? MAX_VISIBLE_LINES
    41                 : correctionsSize;
    42         setPreferredScrollableViewportSize(new Dimension(400, lines
    43                 * getRowHeight()));
    44         getColumnModel().getColumn(correctionTableModel.getApplyColumn())
    45                 .setPreferredWidth(40);
     41        final int lines = correctionsSize > MAX_VISIBLE_LINES ? MAX_VISIBLE_LINES : correctionsSize;
     42        setPreferredScrollableViewportSize(new Dimension(400, lines * getRowHeight()));
     43        getColumnModel().getColumn(correctionTableModel.getApplyColumn()).setPreferredWidth(40);
    4644        setRowSelectionAllowed(false);
    4745    }
     
    5755    }
    5856
     57    /**
     58     * Returns correction table model.
     59     * @return correction table model
     60     */
    5961    @SuppressWarnings("unchecked")
    6062    public T getCorrectionTableModel() {
  • trunk/src/org/openstreetmap/josm/gui/correction/CorrectionTableModel.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.gui.correction;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     
    99import javax.swing.table.AbstractTableModel;
    1010
     11import org.openstreetmap.josm.data.correction.Correction;
     12
     13/**
     14 * Abstract correction table model.
     15 * @param <C> type of correction
     16 */
    1117public abstract class CorrectionTableModel<C extends Correction> extends AbstractTableModel {
    1218
     
    1521    private final int applyColumn;
    1622
     23    /**
     24     * Constructs a new {@code CorrectionTableModel}.
     25     * @param corrections list of corrections
     26     */
    1727    public CorrectionTableModel(List<C> corrections) {
    1828        this.corrections = corrections;
     
    2737    protected abstract boolean isBoldCell(int row, int column);
    2838
     39    /**
     40     * Returns the column name for columns other than "Apply".
     41     * @param colIndex column index
     42     * @return the translated column name for given index
     43     * @see #getApplyColumn
     44     */
    2945    public abstract String getCorrectionColumnName(int colIndex);
    3046
     47    /**
     48     * Returns the correction value at given position.
     49     * @param rowIndex row index
     50     * @param colIndex column index
     51     * @return the correction value at given position
     52     */
    3153    public abstract Object getCorrectionValueAt(int rowIndex, int colIndex);
    3254
     55    /**
     56     * Returns the list of corrections.
     57     * @return the list of corrections
     58     */
    3359    public List<C> getCorrections() {
    3460        return corrections;
    3561    }
    3662
     63    /**
     64     * Returns the index of the "Apply" column.
     65     * @return the index of the "Apply" column
     66     */
    3767    public int getApplyColumn() {
    3868        return applyColumn;
    3969    }
    4070
     71    /**
     72     * Returns the "Apply" flag for given index.
     73     * @param i index
     74     * @return the "Apply" flag for given index
     75     */
    4176    public boolean getApply(int i) {
    4277        return apply[i];
  • trunk/src/org/openstreetmap/josm/gui/correction/RoleCorrectionTable.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.gui.correction;
    33
    44import java.util.List;
    55
    6 public class RoleCorrectionTable extends
    7         CorrectionTable<RoleCorrectionTableModel> {
     6import org.openstreetmap.josm.data.correction.RoleCorrection;
    87
     8/**
     9 * Role correction table.
     10 * @since 1001
     11 */
     12public class RoleCorrectionTable extends CorrectionTable<RoleCorrectionTableModel> {
     13
     14    /**
     15     * Constructs a new {@code RoleCorrectionTable}.
     16     * @param roleCorrections role corrections
     17     */
    918    public RoleCorrectionTable(List<RoleCorrection> roleCorrections) {
    1019        super(new RoleCorrectionTableModel(roleCorrections));
    1120    }
    12 
    1321}
  • trunk/src/org/openstreetmap/josm/gui/correction/RoleCorrectionTableModel.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.gui.correction;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     
    66import java.util.List;
    77
     8import org.openstreetmap.josm.data.correction.RoleCorrection;
    89import org.openstreetmap.josm.gui.DefaultNameFormatter;
    910
    10 public class RoleCorrectionTableModel extends
    11 CorrectionTableModel<RoleCorrection> {
     11/**
     12 * Role correction table model.
     13 * @since 1001
     14 */
     15public class RoleCorrectionTableModel extends CorrectionTableModel<RoleCorrection> {
    1216
     17    /**
     18     * Constructs a new {@code RoleCorrectionTableModel}.
     19     * @param roleCorrections list of role corrections
     20     */
    1321    public RoleCorrectionTableModel(List<RoleCorrection> roleCorrections) {
    1422        super(roleCorrections);
     
    2937        case 2:
    3038            return tr("New role");
     39        default:
     40            return null;
    3141        }
    32         return null;
    3342    }
    3443
     
    4453        case 2:
    4554            return roleCorrection.newRole;
     55        default:
     56            return null;
    4657        }
    47         return null;
    4858    }
    4959
     
    5262        return column == 2;
    5363    }
    54 
    5564}
  • trunk/src/org/openstreetmap/josm/gui/correction/TagCorrectionTable.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.gui.correction;
    33
    44import java.util.List;
    55
    6 public class TagCorrectionTable extends
    7         CorrectionTable<TagCorrectionTableModel> {
     6import org.openstreetmap.josm.data.correction.TagCorrection;
    87
     8/**
     9 * Tag correction table.
     10 * @since 729
     11 */
     12public class TagCorrectionTable extends CorrectionTable<TagCorrectionTableModel> {
     13
     14    /**
     15     * Constructs a new {@code TagCorrectionTable}.
     16     * @param tagCorrections tag corrections
     17     */
    918    public TagCorrectionTable(List<TagCorrection> tagCorrections) {
    1019        super(new TagCorrectionTableModel(tagCorrections));
    1120    }
    12 
    1321}
  • trunk/src/org/openstreetmap/josm/gui/correction/TagCorrectionTableModel.java

    r10113 r10125  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.corrector;
     2package org.openstreetmap.josm.gui.correction;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     
    66import java.util.List;
    77
     8import org.openstreetmap.josm.data.correction.TagCorrection;
     9
     10/**
     11 * Tag correction table model.
     12 * @since 729
     13 */
    814public class TagCorrectionTableModel extends CorrectionTableModel<TagCorrection> {
    915
     16    /**
     17     * Constructs a new {@code TagCorrectionTableModel}.
     18     * @param tagCorrections list of tag corrections
     19     */
    1020    public TagCorrectionTableModel(List<TagCorrection> tagCorrections) {
    1121        super(tagCorrections);
     
    2838        case 3:
    2939            return tr("New value");
     40        default:
     41            return null;
    3042        }
    31         return null;
    3243    }
    3344
     
    4556        case 3:
    4657            return tagCorrection.newValue;
     58        default:
     59            return null;
    4760        }
    48         return null;
    4961    }
    5062
     
    5365        TagCorrection tagCorrection = getCorrections().get(row);
    5466        return (column == 2 && tagCorrection.isKeyChanged())
    55                 || (column == 3 && tagCorrection.isValueChanged());
     67            || (column == 3 && tagCorrection.isValueChanged());
    5668    }
    57 
    5869}
Note: See TracChangeset for help on using the changeset viewer.