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

refactor classes from corrector package, add javadoc

Location:
trunk/src/org/openstreetmap/josm/gui/correction
Files:
2 added
6 moved

Legend:

Unmodified
Added
Removed
  • 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.