Changeset 12044 in josm


Ignore:
Timestamp:
2017-05-03T13:36:40+02:00 (3 weeks ago)
Author:
michael2402
Message:

Make conflict merge dialog layout more universal, make row titles in all panels the same

Location:
trunk/src/org/openstreetmap/josm/gui/conflict/pair
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMerger.java

    r11848 r12044  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.GridBagConstraints;
    7 import java.awt.GridBagLayout;
    8 import java.awt.Insets;
    96import java.awt.event.ActionEvent;
    107import java.text.DecimalFormat;
     8import java.util.Arrays;
    119import java.util.List;
    1210
     
    1513import javax.swing.BorderFactory;
    1614import javax.swing.JButton;
     15import javax.swing.JComponent;
    1716import javax.swing.JLabel;
    1817import javax.swing.JPanel;
     
    2524import org.openstreetmap.josm.gui.DefaultNameFormatter;
    2625import org.openstreetmap.josm.gui.conflict.ConflictColors;
     26import org.openstreetmap.josm.gui.conflict.pair.AbstractMergePanel;
    2727import org.openstreetmap.josm.gui.conflict.pair.IConflictResolver;
    2828import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
    2929import org.openstreetmap.josm.gui.history.VersionInfoPanel;
     30import org.openstreetmap.josm.tools.GBC;
    3031import org.openstreetmap.josm.tools.ImageProvider;
    3132import org.openstreetmap.josm.tools.Utils;
     
    3536 * @since 1654
    3637 */
    37 public class PropertiesMerger extends JPanel implements ChangeListener, IConflictResolver {
     38public class PropertiesMerger extends AbstractMergePanel implements ChangeListener, IConflictResolver {
    3839    private static final DecimalFormat COORD_FORMATTER = new DecimalFormat("###0.0000000");
    3940
     
    4950    private final JLabel lblTheirReferrers = buildValueLabel("label.theirreferrers");
    5051
    51     private final transient PropertiesMergeModel model;
     52    private final transient PropertiesMergeModel model = new PropertiesMergeModel();
    5253    private final VersionInfoPanel mineVersionInfo = new VersionInfoPanel();
    5354    private final VersionInfoPanel theirVersionInfo = new VersionInfoPanel();
     
    5758     */
    5859    public PropertiesMerger() {
    59         model = new PropertiesMergeModel();
    6060        model.addChangeListener(this);
    61         build();
     61        buildRows();
     62    }
     63
     64    @Override
     65    protected List<? extends MergeRow> getRows() {
     66        return Arrays.asList(
     67                new AbstractMergePanel.TitleRow(),
     68                new VersionInfoRow(),
     69                new MergeCoordinatesRow(),
     70                new UndecideCoordinatesRow(),
     71                new MergeDeletedStateRow(),
     72                new UndecideDeletedStateRow(),
     73                new ReferrersRow(),
     74                new EmptyFillRow());
    6275    }
    6376
     
    6982        lbl.setBorder(BorderFactory.createLoweredBevelBorder());
    7083        return lbl;
    71     }
    72 
    73     protected void buildHeaderRow() {
    74         GridBagConstraints gc = new GridBagConstraints();
    75 
    76         gc.gridx = 1;
    77         gc.gridy = 0;
    78         gc.gridwidth = 1;
    79         gc.gridheight = 1;
    80         gc.fill = GridBagConstraints.NONE;
    81         gc.anchor = GridBagConstraints.CENTER;
    82         gc.weightx = 0.0;
    83         gc.weighty = 0.0;
    84         gc.insets = new Insets(10, 0, 0, 0);
    85         JLabel lblMyVersion = new JLabel(tr("My version"));
    86         lblMyVersion.setToolTipText(tr("Properties in my dataset, i.e. the local dataset"));
    87         lblMyVersion.setLabelFor(mineVersionInfo);
    88         add(lblMyVersion, gc);
    89 
    90         gc.gridx = 3;
    91         JLabel lblMergedVersion = new JLabel(tr("Merged version"));
    92         lblMergedVersion.setToolTipText(
    93                 tr("Properties in the merged element. They will replace properties in my elements when merge decisions are applied."));
    94         add(lblMergedVersion, gc);
    95 
    96         gc.gridx = 5;
    97         JLabel lblTheirVersion = new JLabel(tr("Their version"));
    98         lblTheirVersion.setToolTipText(tr("Properties in their dataset, i.e. the server dataset"));
    99         lblMyVersion.setLabelFor(theirVersionInfo);
    100         add(lblTheirVersion, gc);
    101 
    102         gc.gridx = 1;
    103         gc.gridy = 1;
    104         gc.fill = GridBagConstraints.HORIZONTAL;
    105         gc.anchor = GridBagConstraints.LINE_START;
    106         gc.insets = new Insets(0, 0, 20, 0);
    107         add(mineVersionInfo, gc);
    108 
    109         gc.gridx = 5;
    110         add(theirVersionInfo, gc);
    111     }
    112 
    113     protected void buildCoordinateConflictRows() {
    114         GridBagConstraints gc = new GridBagConstraints();
    115 
    116         gc.gridx = 0;
    117         gc.gridy = 2;
    118         gc.gridwidth = 1;
    119         gc.gridheight = 1;
    120         gc.fill = GridBagConstraints.HORIZONTAL;
    121         gc.anchor = GridBagConstraints.LINE_START;
    122         gc.weightx = 0.0;
    123         gc.weighty = 0.0;
    124         gc.insets = new Insets(0, 5, 0, 5);
    125         add(new JLabel(tr("Coordinates:")), gc);
    126 
    127         gc.gridx = 1;
    128         gc.fill = GridBagConstraints.BOTH;
    129         gc.anchor = GridBagConstraints.CENTER;
    130         gc.weightx = 0.33;
    131         gc.weighty = 0.0;
    132         add(lblMyCoordinates, gc);
    133 
    134         gc.gridx = 2;
    135         gc.fill = GridBagConstraints.NONE;
    136         gc.anchor = GridBagConstraints.CENTER;
    137         gc.weightx = 0.0;
    138         gc.weighty = 0.0;
    139         KeepMyCoordinatesAction actKeepMyCoordinates = new KeepMyCoordinatesAction();
    140         model.addChangeListener(actKeepMyCoordinates);
    141         JButton btnKeepMyCoordinates = new JButton(actKeepMyCoordinates);
    142         btnKeepMyCoordinates.setName("button.keepmycoordinates");
    143         add(btnKeepMyCoordinates, gc);
    144 
    145         gc.gridx = 3;
    146         gc.fill = GridBagConstraints.BOTH;
    147         gc.anchor = GridBagConstraints.CENTER;
    148         gc.weightx = 0.33;
    149         gc.weighty = 0.0;
    150         add(lblMergedCoordinates, gc);
    151 
    152         gc.gridx = 4;
    153         gc.fill = GridBagConstraints.NONE;
    154         gc.anchor = GridBagConstraints.CENTER;
    155         gc.weightx = 0.0;
    156         gc.weighty = 0.0;
    157         KeepTheirCoordinatesAction actKeepTheirCoordinates = new KeepTheirCoordinatesAction();
    158         model.addChangeListener(actKeepTheirCoordinates);
    159         JButton btnKeepTheirCoordinates = new JButton(actKeepTheirCoordinates);
    160         add(btnKeepTheirCoordinates, gc);
    161 
    162         gc.gridx = 5;
    163         gc.fill = GridBagConstraints.BOTH;
    164         gc.anchor = GridBagConstraints.CENTER;
    165         gc.weightx = 0.33;
    166         gc.weighty = 0.0;
    167         add(lblTheirCoordinates, gc);
    168 
    169         // ---------------------------------------------------
    170         gc.gridx = 3;
    171         gc.gridy = 3;
    172         gc.fill = GridBagConstraints.NONE;
    173         gc.anchor = GridBagConstraints.CENTER;
    174         gc.weightx = 0.0;
    175         gc.weighty = 0.0;
    176         UndecideCoordinateConflictAction actUndecideCoordinates = new UndecideCoordinateConflictAction();
    177         model.addChangeListener(actUndecideCoordinates);
    178         JButton btnUndecideCoordinates = new JButton(actUndecideCoordinates);
    179         add(btnUndecideCoordinates, gc);
    180     }
    181 
    182     protected void buildDeletedStateConflictRows() {
    183         GridBagConstraints gc = new GridBagConstraints();
    184 
    185         gc.gridx = 0;
    186         gc.gridy = 4;
    187         gc.gridwidth = 1;
    188         gc.gridheight = 1;
    189         gc.fill = GridBagConstraints.BOTH;
    190         gc.anchor = GridBagConstraints.LINE_START;
    191         gc.weightx = 0.0;
    192         gc.weighty = 0.0;
    193         gc.insets = new Insets(0, 5, 0, 5);
    194         add(new JLabel(tr("Deleted State:")), gc);
    195 
    196         gc.gridx = 1;
    197         gc.fill = GridBagConstraints.BOTH;
    198         gc.anchor = GridBagConstraints.CENTER;
    199         gc.weightx = 0.33;
    200         gc.weighty = 0.0;
    201         add(lblMyDeletedState, gc);
    202 
    203         gc.gridx = 2;
    204         gc.fill = GridBagConstraints.NONE;
    205         gc.anchor = GridBagConstraints.CENTER;
    206         gc.weightx = 0.0;
    207         gc.weighty = 0.0;
    208         KeepMyDeletedStateAction actKeepMyDeletedState = new KeepMyDeletedStateAction();
    209         model.addChangeListener(actKeepMyDeletedState);
    210         JButton btnKeepMyDeletedState = new JButton(actKeepMyDeletedState);
    211         btnKeepMyDeletedState.setName("button.keepmydeletedstate");
    212         add(btnKeepMyDeletedState, gc);
    213 
    214         gc.gridx = 3;
    215         gc.fill = GridBagConstraints.BOTH;
    216         gc.anchor = GridBagConstraints.CENTER;
    217         gc.weightx = 0.33;
    218         gc.weighty = 0.0;
    219         add(lblMergedDeletedState, gc);
    220 
    221         gc.gridx = 4;
    222         gc.fill = GridBagConstraints.NONE;
    223         gc.anchor = GridBagConstraints.CENTER;
    224         gc.weightx = 0.0;
    225         gc.weighty = 0.0;
    226         KeepTheirDeletedStateAction actKeepTheirDeletedState = new KeepTheirDeletedStateAction();
    227         model.addChangeListener(actKeepTheirDeletedState);
    228         JButton btnKeepTheirDeletedState = new JButton(actKeepTheirDeletedState);
    229         btnKeepTheirDeletedState.setName("button.keeptheirdeletedstate");
    230         add(btnKeepTheirDeletedState, gc);
    231 
    232         gc.gridx = 5;
    233         gc.fill = GridBagConstraints.BOTH;
    234         gc.anchor = GridBagConstraints.CENTER;
    235         gc.weightx = 0.33;
    236         gc.weighty = 0.0;
    237         add(lblTheirDeletedState, gc);
    238 
    239         // ---------------------------------------------------
    240         gc.gridx = 3;
    241         gc.gridy = 5;
    242         gc.fill = GridBagConstraints.NONE;
    243         gc.anchor = GridBagConstraints.CENTER;
    244         gc.weightx = 0.0;
    245         gc.weighty = 0.0;
    246         UndecideDeletedStateConflictAction actUndecideDeletedState = new UndecideDeletedStateConflictAction();
    247         model.addChangeListener(actUndecideDeletedState);
    248         JButton btnUndecideDeletedState = new JButton(actUndecideDeletedState);
    249         btnUndecideDeletedState.setName("button.undecidedeletedstate");
    250         add(btnUndecideDeletedState, gc);
    251     }
    252 
    253     protected void buildReferrersRow() {
    254         GridBagConstraints gc = new GridBagConstraints();
    255 
    256         gc.gridx = 0;
    257         gc.gridy = 7;
    258         gc.gridwidth = 1;
    259         gc.gridheight = 1;
    260         gc.fill = GridBagConstraints.BOTH;
    261         gc.anchor = GridBagConstraints.LINE_START;
    262         gc.weightx = 0.0;
    263         gc.weighty = 0.0;
    264         gc.insets = new Insets(0, 5, 0, 5);
    265         add(new JLabel(tr("Referenced by:")), gc);
    266 
    267         gc.gridx = 1;
    268         gc.gridy = 7;
    269         gc.fill = GridBagConstraints.BOTH;
    270         gc.anchor = GridBagConstraints.CENTER;
    271         gc.weightx = 0.33;
    272         gc.weighty = 0.0;
    273         add(lblMyReferrers, gc);
    274 
    275         gc.gridx = 5;
    276         gc.gridy = 7;
    277         gc.fill = GridBagConstraints.BOTH;
    278         gc.anchor = GridBagConstraints.CENTER;
    279         gc.weightx = 0.33;
    280         gc.weighty = 0.0;
    281         add(lblTheirReferrers, gc);
    282     }
    283 
    284     protected final void build() {
    285         setLayout(new GridBagLayout());
    286         buildHeaderRow();
    287         buildCoordinateConflictRows();
    288         buildDeletedStateConflictRows();
    289         buildReferrersRow();
    29084    }
    29185
     
    399193    }
    400194
     195    private final class MergeDeletedStateRow extends AbstractMergePanel.MergeRow {
     196        @Override
     197        protected JComponent rowTitle() {
     198            return new JLabel(tr("Deleted State:"));
     199        }
     200
     201        @Override
     202        protected JComponent mineField() {
     203            return lblMyDeletedState;
     204        }
     205
     206        @Override
     207        protected JComponent mineButton() {
     208            KeepMyDeletedStateAction actKeepMyDeletedState = new KeepMyDeletedStateAction();
     209            model.addChangeListener(actKeepMyDeletedState);
     210            JButton btnKeepMyDeletedState = new JButton(actKeepMyDeletedState);
     211            btnKeepMyDeletedState.setName("button.keepmydeletedstate");
     212            return btnKeepMyDeletedState;
     213        }
     214
     215        @Override
     216        protected JComponent merged() {
     217            return lblMergedDeletedState;
     218        }
     219
     220        @Override
     221        protected JComponent theirsButton() {
     222            KeepTheirDeletedStateAction actKeepTheirDeletedState = new KeepTheirDeletedStateAction();
     223            model.addChangeListener(actKeepTheirDeletedState);
     224            JButton btnKeepTheirDeletedState = new JButton(actKeepTheirDeletedState);
     225            btnKeepTheirDeletedState.setName("button.keeptheirdeletedstate");
     226            return btnKeepTheirDeletedState;
     227        }
     228
     229        @Override
     230        protected JComponent theirsField() {
     231            return lblTheirDeletedState;
     232        }
     233    }
     234
     235    private final class MergeCoordinatesRow extends AbstractMergePanel.MergeRow {
     236        @Override
     237        protected JComponent rowTitle() {
     238            return new JLabel(tr("Coordinates:"));
     239        }
     240
     241        @Override
     242        protected JComponent mineField() {
     243            return lblMyCoordinates;
     244        }
     245
     246        @Override
     247        protected JComponent mineButton() {
     248            KeepMyCoordinatesAction actKeepMyCoordinates = new KeepMyCoordinatesAction();
     249            model.addChangeListener(actKeepMyCoordinates);
     250            JButton btnKeepMyCoordinates = new JButton(actKeepMyCoordinates);
     251            btnKeepMyCoordinates.setName("button.keepmycoordinates");
     252            return btnKeepMyCoordinates;
     253        }
     254
     255        @Override
     256        protected JComponent merged() {
     257            return lblMergedCoordinates;
     258        }
     259
     260        @Override
     261        protected JComponent theirsButton() {
     262            KeepTheirCoordinatesAction actKeepTheirCoordinates = new KeepTheirCoordinatesAction();
     263            model.addChangeListener(actKeepTheirCoordinates);
     264            JButton btnKeepTheirCoordinates = new JButton(actKeepTheirCoordinates);
     265            btnKeepTheirCoordinates.setName("button.keeptheircoordinates");
     266            return btnKeepTheirCoordinates;
     267        }
     268
     269        @Override
     270        protected JComponent theirsField() {
     271            return lblTheirCoordinates;
     272        }
     273    }
     274
     275    private abstract class AbstractUndecideRow<T extends AbstractAction & ChangeListener> extends AbstractMergePanel.MergeRow {
     276        @Override
     277        protected JComponent merged() {
     278            // we add the undecide button below this text field
     279            T actUndecideCoordinates = createAction();
     280            model.addChangeListener(actUndecideCoordinates);
     281            JButton button = new JButton(actUndecideCoordinates);
     282            button.setName(getButtonName());
     283            return button;
     284        }
     285
     286        protected abstract T createAction();
     287
     288        protected abstract String getButtonName();
     289
     290        @Override
     291        protected void addConstraints(GBC constraints, int columnIndex) {
     292            super.addConstraints(constraints, columnIndex);
     293            constraints.fill(GBC.NONE);
     294        }
     295    }
     296
     297    private final class UndecideCoordinatesRow extends AbstractUndecideRow<UndecideCoordinateConflictAction> {
     298        @Override
     299        protected UndecideCoordinateConflictAction createAction() {
     300            return new UndecideCoordinateConflictAction();
     301        }
     302
     303        @Override
     304        protected String getButtonName() {
     305            return "button.undecidecoordinates";
     306        }
     307    }
     308
     309    private final class UndecideDeletedStateRow extends AbstractUndecideRow<UndecideDeletedStateConflictAction> {
     310        @Override
     311        protected UndecideDeletedStateConflictAction createAction() {
     312            return new UndecideDeletedStateConflictAction();
     313        }
     314
     315        @Override
     316        protected String getButtonName() {
     317            return "button.undecidedeletedstate";
     318        }
     319    }
     320
     321    private final class VersionInfoRow extends AbstractMergePanel.MergeRowWithoutButton {
     322        @Override
     323        protected JComponent mineField() {
     324            return mineVersionInfo;
     325        }
     326
     327        @Override
     328        protected JComponent theirsField() {
     329            return theirVersionInfo;
     330        }
     331    }
     332
     333    private final class ReferrersRow extends AbstractMergePanel.MergeRow {
     334        @Override
     335        protected JComponent rowTitle() {
     336            return new JLabel(tr("Referenced by:"));
     337        }
     338
     339        @Override
     340        protected JComponent mineField() {
     341            return lblMyReferrers;
     342        }
     343
     344        @Override
     345        protected JComponent theirsField() {
     346            return lblTheirReferrers;
     347        }
     348    }
     349
     350    private final class EmptyFillRow extends AbstractMergePanel.MergeRow {
     351        @Override
     352        protected JComponent merged() {
     353            return new JPanel();
     354        }
     355
     356        @Override
     357        protected void addConstraints(GBC constraints, int columnIndex) {
     358            super.addConstraints(constraints, columnIndex);
     359            // fill to bottom
     360            constraints.weighty = 1;
     361        }
     362    }
     363
    401364    class KeepMyCoordinatesAction extends AbstractAction implements ChangeListener {
    402365        KeepMyCoordinatesAction() {
Note: See TracChangeset for help on using the changeset viewer.