Changeset 12047 in josm for trunk


Ignore:
Timestamp:
2017-05-03T14:42:49+02:00 (8 years ago)
Author:
michael2402
Message:

Make TagMerger use the row based layout. Make merge buttons higher and easier to hit."

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

Legend:

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

    r12044 r12047  
    77import java.util.List;
    88
     9import javax.swing.AbstractAction;
     10import javax.swing.JButton;
    911import javax.swing.JComponent;
    1012import javax.swing.JLabel;
     
    152154    }
    153155
     156    /**
     157     * Add the undecide button to the middle of the merged row.
     158     */
     159    protected abstract static class AbstractUndecideRow extends AbstractMergePanel.MergeRow {
     160        @Override
     161        protected JComponent merged() {
     162            AbstractAction actUndecide = createAction();
     163            JButton button = new JButton(actUndecide);
     164            button.setName(getButtonName());
     165            return button;
     166        }
     167
     168        protected abstract AbstractAction createAction();
     169
     170        protected abstract String getButtonName();
     171
     172        @Override
     173        protected void addConstraints(GBC constraints, int columnIndex) {
     174            super.addConstraints(constraints, columnIndex);
     175            constraints.fill(GBC.NONE);
     176        }
     177    }
     178
     179    /**
     180     * The current row counter. Used when adding new rows.
     181     */
    154182    protected int currentRow = 0;
    155183
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMerger.java

    r12044 r12047  
    273273    }
    274274
    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> {
     275    private final class UndecideCoordinatesRow extends AbstractUndecideRow {
    298276        @Override
    299277        protected UndecideCoordinateConflictAction createAction() {
    300             return new UndecideCoordinateConflictAction();
     278            UndecideCoordinateConflictAction action = new UndecideCoordinateConflictAction();
     279            model.addChangeListener(action);
     280            return action;
    301281        }
    302282
     
    307287    }
    308288
    309     private final class UndecideDeletedStateRow extends AbstractUndecideRow<UndecideDeletedStateConflictAction> {
     289    private final class UndecideDeletedStateRow extends AbstractUndecideRow {
    310290        @Override
    311291        protected UndecideDeletedStateConflictAction createAction() {
    312             return new UndecideDeletedStateConflictAction();
     292            UndecideDeletedStateConflictAction action = new UndecideDeletedStateConflictAction();
     293            model.addChangeListener(action);
     294            return action;
    313295        }
    314296
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/tags/TagMerger.java

    r11747 r12047  
    55
    66import java.awt.Adjustable;
    7 import java.awt.GridBagConstraints;
    8 import java.awt.GridBagLayout;
    9 import java.awt.Insets;
    107import java.awt.event.ActionEvent;
    118import java.awt.event.AdjustmentEvent;
     
    1310import java.awt.event.MouseAdapter;
    1411import java.awt.event.MouseEvent;
     12import java.util.Arrays;
    1513import java.util.HashSet;
     14import java.util.List;
    1615import java.util.Set;
    1716
     
    2019import javax.swing.ImageIcon;
    2120import javax.swing.JButton;
    22 import javax.swing.JLabel;
    23 import javax.swing.JPanel;
     21import javax.swing.JComponent;
    2422import javax.swing.JScrollPane;
    2523import javax.swing.JTable;
     
    2927import org.openstreetmap.josm.data.conflict.Conflict;
    3028import org.openstreetmap.josm.data.osm.OsmPrimitive;
     29import org.openstreetmap.josm.gui.conflict.pair.AbstractMergePanel;
    3130import org.openstreetmap.josm.gui.conflict.pair.IConflictResolver;
    3231import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
    3332import org.openstreetmap.josm.gui.tagging.TagTableColumnModelBuilder;
     33import org.openstreetmap.josm.tools.GBC;
    3434import org.openstreetmap.josm.tools.ImageProvider;
    3535
     
    3838 * @since 1622
    3939 */
    40 public class TagMerger extends JPanel implements IConflictResolver {
    41 
    42     private JTable mineTable;
    43     private JTable mergedTable;
    44     private JTable theirTable;
    45     private final TagMergeModel model;
    46     private final String[] keyvalue;
    47     private transient AdjustmentSynchronizer adjustmentSynchronizer;
     40public class TagMerger extends AbstractMergePanel implements IConflictResolver {
     41    private static final String[] KEY_VALUE = new String[] {tr("Key"), tr("Value")};
     42
     43    private final TagMergeModel model = new TagMergeModel();
     44
     45    /**
     46     * the table for my tag set
     47     */
     48    private final JTable mineTable = generateTable(model, new MineTableCellRenderer());
     49    /**
     50     * the table for the merged tag set
     51     */
     52    private final JTable mergedTable = generateTable(model, new MergedTableCellRenderer());
     53    /**
     54     * the table for their tag set
     55     */
     56    private final JTable theirTable = generateTable(model, new TheirTableCellRenderer());
    4857
    4958    /**
     
    5160     */
    5261    public TagMerger() {
    53         model = new TagMergeModel();
    54         keyvalue = new String[]{tr("Key"), tr("Value")};
    55         build();
    56     }
    57 
    58     /**
    59      * embeds table in a new {@link JScrollPane} and returns th scroll pane
    60      *
    61      * @param table the table
    62      * @return the scroll pane embedding the table
    63      */
    64     protected JScrollPane embeddInScrollPane(JTable table) {
    65         JScrollPane pane = new JScrollPane(table);
    66         adjustmentSynchronizer.synchronizeAdjustment(pane.getVerticalScrollBar());
    67         return pane;
    68     }
    69 
    70     /**
    71      * builds the table for my tag set (table already embedded in a scroll pane)
    72      *
    73      * @return the table (embedded in a scroll pane)
    74      */
    75     protected JScrollPane buildMineTagTable() {
    76         mineTable = new JTable(model, new TagTableColumnModelBuilder(new MineTableCellRenderer(), keyvalue).build());
    7762        mineTable.setName("table.my");
    78         return embeddInScrollPane(mineTable);
    79     }
    80 
    81     /**
    82      * builds the table for their tag set (table already embedded in a scroll pane)
    83      *
    84      * @return the table (embedded in a scroll pane)
    85      */
    86     protected JScrollPane buildTheirTable() {
    87         theirTable = new JTable(model, new TagTableColumnModelBuilder(new TheirTableCellRenderer(), keyvalue).build());
    8863        theirTable.setName("table.their");
    89         return embeddInScrollPane(theirTable);
    90     }
    91 
    92     /**
    93      * builds the table for the merged tag set (table already embedded in a scroll pane)
    94      *
    95      * @return the table (embedded in a scroll pane)
    96      */
    97 
    98     protected JScrollPane buildMergedTable() {
    99         mergedTable = new JTable(model, new TagTableColumnModelBuilder(new MergedTableCellRenderer(), keyvalue).build());
    10064        mergedTable.setName("table.merged");
    101         return embeddInScrollPane(mergedTable);
    102     }
    103 
    104     /**
    105      * build the user interface
    106      */
    107     protected final void build() {
    108         GridBagConstraints gc = new GridBagConstraints();
    109         setLayout(new GridBagLayout());
    110 
    111         adjustmentSynchronizer = new AdjustmentSynchronizer();
    112 
    113         gc.gridx = 0;
    114         gc.gridy = 0;
    115         gc.gridwidth = 1;
    116         gc.gridheight = 1;
    117         gc.fill = GridBagConstraints.NONE;
    118         gc.anchor = GridBagConstraints.CENTER;
    119         gc.weightx = 0.0;
    120         gc.weighty = 0.0;
    121         gc.insets = new Insets(10, 0, 10, 0);
    122         JLabel lblMy = new JLabel(tr("My version (local dataset)"));
    123         add(lblMy, gc);
    124 
    125         gc.gridx = 2;
    126         gc.gridy = 0;
    127         gc.gridwidth = 1;
    128         gc.gridheight = 1;
    129         gc.fill = GridBagConstraints.NONE;
    130         gc.anchor = GridBagConstraints.CENTER;
    131         gc.weightx = 0.0;
    132         gc.weighty = 0.0;
    133         JLabel lblMerge = new JLabel(tr("Merged version"));
    134         add(lblMerge, gc);
    135 
    136         gc.gridx = 4;
    137         gc.gridy = 0;
    138         gc.gridwidth = 1;
    139         gc.gridheight = 1;
    140         gc.fill = GridBagConstraints.NONE;
    141         gc.anchor = GridBagConstraints.CENTER;
    142         gc.weightx = 0.0;
    143         gc.weighty = 0.0;
    144         gc.insets = new Insets(0, 0, 0, 0);
    145         JLabel lblTheir = new JLabel(tr("Their version (server dataset)"));
    146         add(lblTheir, gc);
    147 
    148         gc.gridx = 0;
    149         gc.gridy = 1;
    150         gc.gridwidth = 1;
    151         gc.gridheight = 1;
    152         gc.fill = GridBagConstraints.BOTH;
    153         gc.anchor = GridBagConstraints.FIRST_LINE_START;
    154         gc.weightx = 0.3;
    155         gc.weighty = 1.0;
    156         JScrollPane tabMy = buildMineTagTable();
    157         lblMy.setLabelFor(tabMy);
    158         add(tabMy, gc);
    159 
    160         gc.gridx = 1;
    161         gc.gridy = 1;
    162         gc.gridwidth = 1;
    163         gc.gridheight = 1;
    164         gc.fill = GridBagConstraints.NONE;
    165         gc.anchor = GridBagConstraints.CENTER;
    166         gc.weightx = 0.0;
    167         gc.weighty = 0.0;
    168         KeepMineAction keepMineAction = new KeepMineAction();
    169         mineTable.getSelectionModel().addListSelectionListener(keepMineAction);
    170         JButton btnKeepMine = new JButton(keepMineAction);
    171         btnKeepMine.setName("button.keepmine");
    172         add(btnKeepMine, gc);
    173 
    174         gc.gridx = 2;
    175         gc.gridy = 1;
    176         gc.gridwidth = 1;
    177         gc.gridheight = 1;
    178         gc.fill = GridBagConstraints.BOTH;
    179         gc.anchor = GridBagConstraints.FIRST_LINE_START;
    180         gc.weightx = 0.3;
    181         gc.weighty = 1.0;
    182         JScrollPane tabMerge = buildMergedTable();
    183         lblMerge.setLabelFor(tabMerge);
    184         add(tabMerge, gc);
    185 
    186         gc.gridx = 3;
    187         gc.gridy = 1;
    188         gc.gridwidth = 1;
    189         gc.gridheight = 1;
    190         gc.fill = GridBagConstraints.NONE;
    191         gc.anchor = GridBagConstraints.CENTER;
    192         gc.weightx = 0.0;
    193         gc.weighty = 0.0;
    194         KeepTheirAction keepTheirAction = new KeepTheirAction();
    195         JButton btnKeepTheir = new JButton(keepTheirAction);
    196         btnKeepTheir.setName("button.keeptheir");
    197         add(btnKeepTheir, gc);
    198 
    199         gc.gridx = 4;
    200         gc.gridy = 1;
    201         gc.gridwidth = 1;
    202         gc.gridheight = 1;
    203         gc.fill = GridBagConstraints.BOTH;
    204         gc.anchor = GridBagConstraints.FIRST_LINE_START;
    205         gc.weightx = 0.3;
    206         gc.weighty = 1.0;
    207         JScrollPane tabTheir = buildTheirTable();
    208         lblTheir.setLabelFor(tabTheir);
    209         add(tabTheir, gc);
    210         theirTable.getSelectionModel().addListSelectionListener(keepTheirAction);
    21165
    21266        DoubleClickAdapter dblClickAdapter = new DoubleClickAdapter();
     
    21468        theirTable.addMouseListener(dblClickAdapter);
    21569
    216         gc.gridx = 2;
    217         gc.gridy = 2;
    218         gc.gridwidth = 1;
    219         gc.gridheight = 1;
    220         gc.fill = GridBagConstraints.NONE;
    221         gc.anchor = GridBagConstraints.CENTER;
    222         gc.weightx = 0.0;
    223         gc.weighty = 0.0;
    224         UndecideAction undecidedAction = new UndecideAction();
    225         mergedTable.getSelectionModel().addListSelectionListener(undecidedAction);
    226         JButton btnUndecide = new JButton(undecidedAction);
    227         btnUndecide.setName("button.undecide");
    228         add(btnUndecide, gc);
     70        buildRows();
     71    }
     72
     73    private JTable generateTable(TagMergeModel model2, TagMergeTableCellRenderer renderer) {
     74        return new JTable(model, new TagTableColumnModelBuilder(renderer, KEY_VALUE).build());
     75    }
     76
     77    @Override
     78    protected List<? extends MergeRow> getRows() {
     79        return Arrays.asList(new TitleRow(), new TagTableRow(), new UndecidedRow());
    22980    }
    23081
     
    251102        mineTable.getSelectionModel().setSelectionInterval(index, index);
    252103        theirTable.getSelectionModel().setSelectionInterval(index, index);
     104    }
     105
     106    private final class TagTableRow extends MergeRow {
     107        private transient AdjustmentSynchronizer adjustmentSynchronizer = new AdjustmentSynchronizer();
     108
     109        /**
     110         * embeds table in a new {@link JScrollPane} and returns th scroll pane
     111         *
     112         * @param table the table
     113         * @return the scroll pane embedding the table
     114         */
     115        protected JScrollPane embeddInScrollPane(JTable table) {
     116            JScrollPane pane = new JScrollPane(table);
     117            adjustmentSynchronizer.synchronizeAdjustment(pane.getVerticalScrollBar());
     118            return pane;
     119        }
     120
     121        @Override
     122        protected JComponent mineField() {
     123            return embeddInScrollPane(mineTable);
     124        }
     125
     126        @Override
     127        protected JComponent mineButton() {
     128            KeepMineAction keepMineAction = new KeepMineAction();
     129            mineTable.getSelectionModel().addListSelectionListener(keepMineAction);
     130            JButton btnKeepMine = new JButton(keepMineAction);
     131            btnKeepMine.setName("button.keepmine");
     132            return btnKeepMine;
     133        }
     134
     135        @Override
     136        protected JComponent merged() {
     137            return embeddInScrollPane(mergedTable);
     138        }
     139
     140        @Override
     141        protected JComponent theirsButton() {
     142            KeepTheirAction keepTheirAction = new KeepTheirAction();
     143            theirTable.getSelectionModel().addListSelectionListener(keepTheirAction);
     144            JButton btnKeepTheir = new JButton(keepTheirAction);
     145            btnKeepTheir.setName("button.keeptheir");
     146            return btnKeepTheir;
     147        }
     148
     149        @Override
     150        protected JComponent theirsField() {
     151            return embeddInScrollPane(theirTable);
     152        }
     153
     154        @Override
     155        protected void addConstraints(GBC constraints, int columnIndex) {
     156            super.addConstraints(constraints, columnIndex);
     157            // Fill to bottom
     158            constraints.weighty = 1;
     159        }
     160    }
     161
     162    private final class UndecidedRow extends AbstractUndecideRow {
     163        @Override
     164        protected AbstractAction createAction() {
     165            UndecideAction undecidedAction = new UndecideAction();
     166            mergedTable.getSelectionModel().addListSelectionListener(undecidedAction);
     167            return undecidedAction;
     168        }
     169
     170        @Override
     171        protected String getButtonName() {
     172            return "button.undecide";
     173        }
    253174    }
    254175
Note: See TracChangeset for help on using the changeset viewer.