Changeset 6146 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2013-08-14T02:34:42+02:00 (11 years ago)
Author:
Don-vip
Message:

sonar - refactor inner classes of ListMerger to avoid lots of duplicate code

File:
1 edited

Legend:

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

    r6084 r6146  
    5151 * A UI component for resolving conflicts in two lists of entries of type T.
    5252 *
    53  * @param T  the type of the entries
     53 * @param <T>  the type of the entries
    5454 * @see ListMergeModel
    5555 */
     
    413413    }
    414414
     415    /**
     416     * Constructs a new {@code ListMerger}.
     417     * @param model
     418     */
    415419    public ListMerger(ListMergeModel<T> model) {
    416420        this.model = model;
     
    421425
    422426    /**
     427     * Base class of all other Copy* inner classes.
     428     */
     429    abstract class CopyAction extends AbstractAction implements ListSelectionListener {
     430       
     431        protected CopyAction(String icon_name, String action_name, String short_description) {
     432            ImageIcon icon = ImageProvider.get("dialogs/conflict", icon_name+".png");
     433            putValue(Action.SMALL_ICON, icon);
     434            if (icon == null) {
     435                putValue(Action.NAME, action_name);
     436            }
     437            putValue(Action.SHORT_DESCRIPTION, short_description);
     438            setEnabled(false);
     439        }
     440    }
     441   
     442    /**
    423443     * Action for copying selected nodes in the list of my nodes to the list of merged
    424444     * nodes. Inserts the nodes at the beginning of the list of merged nodes.
    425      *
    426445     */
    427     class CopyStartLeftAction extends AbstractAction implements ListSelectionListener {
     446    class CopyStartLeftAction extends CopyAction {
    428447
    429448        public CopyStartLeftAction() {
    430             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copystartleft.png");
    431             putValue(Action.SMALL_ICON, icon);
    432             if (icon == null) {
    433                 putValue(Action.NAME, tr("> top"));
    434             }
    435             putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected nodes to the start of the merged node list"));
    436             setEnabled(false);
    437         }
    438 
    439         @Override
    440         public void actionPerformed(ActionEvent arg0) {
    441             int [] rows = myEntriesTable.getSelectedRows();
    442             model.copyMyToTop(rows);
     449            super("copystartleft", tr("> top"), tr("Copy my selected nodes to the start of the merged node list"));
     450        }
     451
     452        @Override
     453        public void actionPerformed(ActionEvent e) {
     454            model.copyMyToTop(myEntriesTable.getSelectedRows());
    443455        }
    444456
     
    452464     * Action for copying selected nodes in the list of my nodes to the list of merged
    453465     * nodes. Inserts the nodes at the end of the list of merged nodes.
    454      *
    455466     */
    456     class CopyEndLeftAction extends AbstractAction implements ListSelectionListener {
     467    class CopyEndLeftAction extends CopyAction {
    457468
    458469        public CopyEndLeftAction() {
    459             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copyendleft.png");
    460             putValue(Action.SMALL_ICON, icon);
    461             if (icon == null) {
    462                 putValue(Action.NAME, tr("> bottom"));
    463             }
    464             putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected elements to the end of the list of merged elements."));
    465             setEnabled(false);
    466         }
    467 
    468         @Override
    469         public void actionPerformed(ActionEvent arg0) {
    470             int [] rows = myEntriesTable.getSelectedRows();
    471             model.copyMyToEnd(rows);
     470            super("copyendleft", tr("> bottom"), tr("Copy my selected elements to the end of the list of merged elements."));
     471        }
     472
     473        @Override
     474        public void actionPerformed(ActionEvent e) {
     475            model.copyMyToEnd(myEntriesTable.getSelectedRows());
    472476        }
    473477
     
    481485     * Action for copying selected nodes in the list of my nodes to the list of merged
    482486     * nodes. Inserts the nodes before the first selected row in the list of merged nodes.
    483      *
    484487     */
    485     class CopyBeforeCurrentLeftAction extends AbstractAction implements ListSelectionListener {
     488    class CopyBeforeCurrentLeftAction extends CopyAction {
    486489
    487490        public CopyBeforeCurrentLeftAction() {
    488             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copybeforecurrentleft.png");
    489             putValue(Action.SMALL_ICON, icon);
    490             if (icon == null) {
    491                 putValue(Action.NAME, "> before");
    492             }
    493             putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected elements before the first selected element in the list of merged elements."));
    494             setEnabled(false);
    495         }
    496 
    497         @Override
    498         public void actionPerformed(ActionEvent arg0) {
    499             int [] myRows = myEntriesTable.getSelectedRows();
     491            super("copybeforecurrentleft", tr("> before"),
     492                    tr("Copy my selected elements before the first selected element in the list of merged elements."));
     493        }
     494
     495        @Override
     496        public void actionPerformed(ActionEvent e) {
    500497            int [] mergedRows = mergedEntriesTable.getSelectedRows();
    501498            if (mergedRows == null || mergedRows.length == 0)
    502499                return;
     500            int [] myRows = myEntriesTable.getSelectedRows();
    503501            int current = mergedRows[0];
    504502            model.copyMyBeforeCurrent(myRows, current);
     
    509507            setEnabled(
    510508                    !myEntriesTable.getSelectionModel().isSelectionEmpty()
    511                     && ! mergedEntriesTable.getSelectionModel().isSelectionEmpty()
     509                    && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
    512510            );
    513511        }
     
    517515     * Action for copying selected nodes in the list of my nodes to the list of merged
    518516     * nodes. Inserts the nodes after the first selected row in the list of merged nodes.
    519      *
    520517     */
    521     class CopyAfterCurrentLeftAction extends AbstractAction implements ListSelectionListener {
     518    class CopyAfterCurrentLeftAction extends CopyAction {
    522519
    523520        public CopyAfterCurrentLeftAction() {
    524             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copyaftercurrentleft.png");
    525             putValue(Action.SMALL_ICON, icon);
    526             if (icon == null) {
    527                 putValue(Action.NAME, "> after");
    528             }
    529             putValue(Action.SHORT_DESCRIPTION, tr("Copy my selected elements after the first selected element in the list of merged elements."));
    530             setEnabled(false);
    531         }
    532 
    533         @Override
    534         public void actionPerformed(ActionEvent arg0) {
    535             int [] myRows = myEntriesTable.getSelectedRows();
     521            super("copyaftercurrentleft", tr("> after"),
     522                    tr("Copy my selected elements after the first selected element in the list of merged elements."));
     523        }
     524
     525        @Override
     526        public void actionPerformed(ActionEvent e) {
    536527            int [] mergedRows = mergedEntriesTable.getSelectedRows();
    537528            if (mergedRows == null || mergedRows.length == 0)
    538529                return;
     530            int [] myRows = myEntriesTable.getSelectedRows();
    539531            int current = mergedRows[0];
    540532            model.copyMyAfterCurrent(myRows, current);
     
    545537            setEnabled(
    546538                    !myEntriesTable.getSelectionModel().isSelectionEmpty()
    547                     && ! mergedEntriesTable.getSelectionModel().isSelectionEmpty()
     539                    && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
    548540            );
    549541        }
    550542    }
    551543
    552     class CopyStartRightAction extends AbstractAction implements ListSelectionListener {
     544    class CopyStartRightAction extends CopyAction {
    553545
    554546        public CopyStartRightAction() {
    555             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copystartright.png");
    556             putValue(Action.SMALL_ICON, icon);
    557             if (icon == null) {
    558                 putValue(Action.NAME, "< top");
    559             }
    560             putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected element to the start of the list of merged elements."));
    561             setEnabled(false);
    562         }
    563 
    564         @Override
    565         public void actionPerformed(ActionEvent arg0) {
    566             int [] rows = theirEntriesTable.getSelectedRows();
    567             model.copyTheirToTop(rows);
     547            super("copystartright", tr("< top"), tr("Copy their selected element to the start of the list of merged elements."));
     548        }
     549
     550        @Override
     551        public void actionPerformed(ActionEvent e) {
     552            model.copyTheirToTop(theirEntriesTable.getSelectedRows());
    568553        }
    569554
     
    574559    }
    575560
    576     class CopyEndRightAction extends AbstractAction implements ListSelectionListener {
     561    class CopyEndRightAction extends CopyAction {
    577562
    578563        public CopyEndRightAction() {
    579             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copyendright.png");
    580             putValue(Action.SMALL_ICON, icon);
    581             if (icon == null) {
    582                 putValue(Action.NAME, "< bottom");
    583             }
    584             putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected elements to the end of the list of merged elements."));
    585             setEnabled(false);
     564            super("copyendright", tr("< bottom"), tr("Copy their selected elements to the end of the list of merged elements."));
    586565        }
    587566
    588567        @Override
    589568        public void actionPerformed(ActionEvent arg0) {
    590             int [] rows = theirEntriesTable.getSelectedRows();
    591             model.copyTheirToEnd(rows);
     569            model.copyTheirToEnd(theirEntriesTable.getSelectedRows());
    592570        }
    593571
     
    598576    }
    599577
    600     class CopyBeforeCurrentRightAction extends AbstractAction implements ListSelectionListener {
     578    class CopyBeforeCurrentRightAction extends CopyAction {
    601579
    602580        public CopyBeforeCurrentRightAction() {
    603             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copybeforecurrentright.png");
    604             putValue(Action.SMALL_ICON, icon);
    605             if (icon == null) {
    606                 putValue(Action.NAME, "< before");
    607             }
    608             putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected elements before the first selected element in the list of merged elements."));
    609             setEnabled(false);
    610         }
    611 
    612         @Override
    613         public void actionPerformed(ActionEvent arg0) {
    614             int [] myRows = theirEntriesTable.getSelectedRows();
     581            super("copybeforecurrentright", tr("< before"),
     582                    tr("Copy their selected elements before the first selected element in the list of merged elements."));
     583        }
     584
     585        @Override
     586        public void actionPerformed(ActionEvent e) {
    615587            int [] mergedRows = mergedEntriesTable.getSelectedRows();
    616588            if (mergedRows == null || mergedRows.length == 0)
    617589                return;
     590            int [] myRows = theirEntriesTable.getSelectedRows();
    618591            int current = mergedRows[0];
    619592            model.copyTheirBeforeCurrent(myRows, current);
     
    624597            setEnabled(
    625598                    !theirEntriesTable.getSelectionModel().isSelectionEmpty()
    626                     && ! mergedEntriesTable.getSelectionModel().isSelectionEmpty()
     599                    && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
    627600            );
    628601        }
    629602    }
    630603
    631     class CopyAfterCurrentRightAction extends AbstractAction implements ListSelectionListener {
     604    class CopyAfterCurrentRightAction extends CopyAction {
    632605
    633606        public CopyAfterCurrentRightAction() {
    634             ImageIcon icon = ImageProvider.get("dialogs/conflict", "copyaftercurrentright.png");
    635             putValue(Action.SMALL_ICON, icon);
    636             if (icon == null) {
    637                 putValue(Action.NAME, "< after");
    638             }
    639             putValue(Action.SHORT_DESCRIPTION, tr("Copy their selected element after the first selected element in the list of merged elements"));
    640             setEnabled(false);
    641         }
    642 
    643         @Override
    644         public void actionPerformed(ActionEvent arg0) {
    645             int [] myRows = theirEntriesTable.getSelectedRows();
     607            super("copyaftercurrentright", tr("< after"),
     608                    tr("Copy their selected element after the first selected element in the list of merged elements"));
     609        }
     610
     611        @Override
     612        public void actionPerformed(ActionEvent e) {
    646613            int [] mergedRows = mergedEntriesTable.getSelectedRows();
    647614            if (mergedRows == null || mergedRows.length == 0)
    648615                return;
     616            int [] myRows = theirEntriesTable.getSelectedRows();
    649617            int current = mergedRows[0];
    650618            model.copyTheirAfterCurrent(myRows, current);
     
    655623            setEnabled(
    656624                    !theirEntriesTable.getSelectionModel().isSelectionEmpty()
    657                     && ! mergedEntriesTable.getSelectionModel().isSelectionEmpty()
     625                    && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
    658626            );
    659627        }
Note: See TracChangeset for help on using the changeset viewer.