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


Ignore:
Timestamp:
2013-08-14T03:24:08+02:00 (11 years ago)
Author:
Don-vip
Message:

sonar - move duplicated class between history and conflict to util

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited
1 moved

Legend:

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

    r6146 r6147  
    55import static org.openstreetmap.josm.tools.I18n.trn;
    66
    7 import java.awt.Adjustable;
    87import java.awt.FlowLayout;
    98import java.awt.GridBagConstraints;
     
    1110import java.awt.Insets;
    1211import java.awt.event.ActionEvent;
    13 import java.awt.event.AdjustmentEvent;
    14 import java.awt.event.AdjustmentListener;
    1512import java.awt.event.ItemEvent;
    1613import java.awt.event.ItemListener;
    1714import java.beans.PropertyChangeEvent;
    1815import java.beans.PropertyChangeListener;
    19 import java.util.ArrayList;
    2016import java.util.Collection;
    21 import java.util.HashMap;
    2217import java.util.List;
    2318import java.util.Observable;
     
    4338import org.openstreetmap.josm.data.osm.Way;
    4439import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     40import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
    4541import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    4642import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTable;
    47 import org.openstreetmap.josm.tools.CheckParameterUtil;
    4843import org.openstreetmap.josm.tools.ImageProvider;
    4944
     
    894889        mergedEntriesTable.unlinkAsListener();
    895890        theirEntriesTable.unlinkAsListener();
    896     }
    897 
    898     /**
    899      * Synchronizes scrollbar adjustments between a set of
    900      * {@link Adjustable}s. Whenever the adjustment of one of
    901      * the registerd Adjustables is updated the adjustment of
    902      * the other registered Adjustables is adjusted too.
    903      *
    904      */
    905     class AdjustmentSynchronizer implements AdjustmentListener {
    906 
    907         private final  ArrayList<Adjustable> synchronizedAdjustables;
    908         private final  HashMap<Adjustable, Boolean> enabledMap;
    909 
    910         private final Observable observable;
    911 
    912         public AdjustmentSynchronizer() {
    913             synchronizedAdjustables = new ArrayList<Adjustable>();
    914             enabledMap = new HashMap<Adjustable, Boolean>();
    915             observable = new Observable();
    916         }
    917 
    918         /**
    919          * registers an {@link Adjustable} for participation in synchronized
    920          * scrolling.
    921          *
    922          * @param adjustable the adjustable
    923          */
    924         public void participateInSynchronizedScrolling(Adjustable adjustable) {
    925             if (adjustable == null)
    926                 return;
    927             if (synchronizedAdjustables.contains(adjustable))
    928                 return;
    929             synchronizedAdjustables.add(adjustable);
    930             setParticipatingInSynchronizedScrolling(adjustable, true);
    931             adjustable.addAdjustmentListener(this);
    932         }
    933 
    934         /**
    935          * event handler for {@link AdjustmentEvent}s
    936          *
    937          */
    938         @Override
    939         public void adjustmentValueChanged(AdjustmentEvent e) {
    940             if (! enabledMap.get(e.getAdjustable()))
    941                 return;
    942             for (Adjustable a : synchronizedAdjustables) {
    943                 if (a != e.getAdjustable() && isParticipatingInSynchronizedScrolling(a)) {
    944                     a.setValue(e.getValue());
    945                 }
    946             }
    947         }
    948 
    949         /**
    950          * sets whether adjustable participates in adjustment synchronization
    951          * or not
    952          *
    953          * @param adjustable the adjustable
    954          */
    955         protected void setParticipatingInSynchronizedScrolling(Adjustable adjustable, boolean isParticipating) {
    956             CheckParameterUtil.ensureParameterNotNull(adjustable, "adjustable");
    957             if (! synchronizedAdjustables.contains(adjustable))
    958                 throw new IllegalStateException(tr("Adjustable {0} not registered yet. Cannot set participation in synchronized adjustment.", adjustable));
    959 
    960             enabledMap.put(adjustable, isParticipating);
    961             observable.notifyObservers();
    962         }
    963 
    964         /**
    965          * returns true if an adjustable is participating in synchronized scrolling
    966          *
    967          * @param adjustable the adjustable
    968          * @return true, if the adjustable is participating in synchronized scrolling, false otherwise
    969          * @throws IllegalStateException thrown, if adjustable is not registered for synchronized scrolling
    970          */
    971         protected boolean isParticipatingInSynchronizedScrolling(Adjustable adjustable) throws IllegalStateException {
    972             if (! synchronizedAdjustables.contains(adjustable))
    973                 throw new IllegalStateException(tr("Adjustable {0} not registered yet.", adjustable));
    974 
    975             return enabledMap.get(adjustable);
    976         }
    977 
    978         /**
    979          * wires a {@link JCheckBox} to  the adjustment synchronizer, in such a way  that:
    980          * <li>
    981          *   <ol>state changes in the checkbox control whether the adjustable participates
    982          *      in synchronized adjustment</ol>
    983          *   <ol>state changes in this {@link AdjustmentSynchronizer} are reflected in the
    984          *      {@link JCheckBox}</ol>
    985          * </li>
    986          *
    987          *
    988          * @param view  the checkbox to control whether an adjustable participates in synchronized
    989          *      adjustment
    990          * @param adjustable the adjustable
    991          * @exception IllegalArgumentException thrown, if view is null
    992          * @exception IllegalArgumentException thrown, if adjustable is null
    993          */
    994         protected void adapt(final JCheckBox view, final Adjustable adjustable) throws IllegalStateException {
    995             CheckParameterUtil.ensureParameterNotNull(adjustable, "adjustable");
    996             CheckParameterUtil.ensureParameterNotNull(view, "view");
    997 
    998             if (! synchronizedAdjustables.contains(adjustable)) {
    999                 participateInSynchronizedScrolling(adjustable);
    1000             }
    1001 
    1002             // register an item lister with the check box
    1003             //
    1004             view.addItemListener(new ItemListener() {
    1005                 @Override
    1006                 public void itemStateChanged(ItemEvent e) {
    1007                     switch(e.getStateChange()) {
    1008                     case ItemEvent.SELECTED:
    1009                         if (!isParticipatingInSynchronizedScrolling(adjustable)) {
    1010                             setParticipatingInSynchronizedScrolling(adjustable, true);
    1011                         }
    1012                         break;
    1013                     case ItemEvent.DESELECTED:
    1014                         if (isParticipatingInSynchronizedScrolling(adjustable)) {
    1015                             setParticipatingInSynchronizedScrolling(adjustable, false);
    1016                         }
    1017                         break;
    1018                     }
    1019                 }
    1020             });
    1021 
    1022             observable.addObserver(
    1023                     new Observer() {
    1024                         @Override
    1025                         public void update(Observable o, Object arg) {
    1026                             boolean sync = isParticipatingInSynchronizedScrolling(adjustable);
    1027                             if (view.isSelected() != sync) {
    1028                                 view.setSelected(sync);
    1029                             }
    1030                         }
    1031                     }
    1032             );
    1033             setParticipatingInSynchronizedScrolling(adjustable, true);
    1034             view.setSelected(true);
    1035         }
    1036891    }
    1037892
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r6084 r6147  
    2929import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    3030import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     31import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
    3132import org.openstreetmap.josm.gui.util.GuiHelper;
    3233import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
  • trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java

    r5832 r6147  
    1414import javax.swing.event.TableModelListener;
    1515
    16 import org.openstreetmap.josm.data.osm.history.History;
     16import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
     17
    1718/**
    1819 * RelationMemberListViewer is a UI component which displays the  list of relation members of two
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r5832 r6147  
    1010import javax.swing.JTable;
    1111import javax.swing.ListSelectionModel;
     12
     13import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
    1214
    1315/**
  • trunk/src/org/openstreetmap/josm/gui/util/AdjustmentSynchronizer.java

    r6145 r6147  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.history;
     2package org.openstreetmap.josm.gui.util;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     
    1919
    2020/**
    21  * Synchronizes scrollbar adjustments between a set of
    22  * {@link Adjustable}s. Whenever the adjustment of one of
    23  * the registerd Adjustables is updated the adjustment of
    24  * the other registered Adjustables is adjusted too.
    25  *
     21 * Synchronizes scrollbar adjustments between a set of {@link Adjustable}s.
     22 * Whenever the adjustment of one of the registered Adjustables is updated
     23 * the adjustment of the other registered Adjustables is adjusted too.
     24 * @since 6147
    2625 */
    2726public class AdjustmentSynchronizer implements AdjustmentListener {
     
    3231    private final Observable observable;
    3332
     33    /**
     34     * Constructs a new {@code AdjustmentSynchronizer}
     35     */
    3436    public AdjustmentSynchronizer() {
    3537        synchronizedAdjustables = new ArrayList<Adjustable>();
     
    3941
    4042    /**
    41      * registers an {@link Adjustable} for participation in synchronized
    42      * scrolling.
     43     * Registers an {@link Adjustable} for participation in synchronized scrolling.
    4344     *
    4445     * @param adjustable the adjustable
     
    5556
    5657    /**
    57      * event handler for {@link AdjustmentEvent}s
    58      *
     58     * Event handler for {@link AdjustmentEvent}s
    5959     */
    6060    @Override
     
    7070
    7171    /**
    72      * sets whether adjustable participates in adjustment synchronization
    73      * or not
     72     * Sets whether adjustable participates in adjustment synchronization or not
    7473     *
    7574     * @param adjustable the adjustable
     
    8584
    8685    /**
    87      * returns true if an adjustable is participating in synchronized scrolling
     86     * Returns true if an adjustable is participating in synchronized scrolling
    8887     *
    8988     * @param adjustable the adjustable
     
    9998
    10099    /**
    101      * wires a {@link JCheckBox} to  the adjustment synchronizer, in such a way that:
     100     * Wires a {@link JCheckBox} to  the adjustment synchronizer, in such a way that:
    102101     * <li>
    103102     *   <ol>state changes in the checkbox control whether the adjustable participates
     
    107106     * </li>
    108107     *
    109      *
    110      * @param view  the checkbox to control whether an adjustable participates in synchronized
    111      *      adjustment
     108     * @param view  the checkbox to control whether an adjustable participates in synchronized adjustment
    112109     * @param adjustable the adjustable
    113110     * @exception IllegalArgumentException thrown, if view is null
    114111     * @exception IllegalArgumentException thrown, if adjustable is null
    115112     */
    116     protected void adapt(final JCheckBox view, final Adjustable adjustable) throws IllegalStateException {
     113    public void adapt(final JCheckBox view, final Adjustable adjustable) {
    117114        CheckParameterUtil.ensureParameterNotNull(adjustable, "adjustable");
    118115        CheckParameterUtil.ensureParameterNotNull(view, "view");
Note: See TracChangeset for help on using the changeset viewer.