Changeset 6147 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2013-08-14T03:24:08+02:00 (11 years ago)
- 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 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 import java.awt.Adjustable;8 7 import java.awt.FlowLayout; 9 8 import java.awt.GridBagConstraints; … … 11 10 import java.awt.Insets; 12 11 import java.awt.event.ActionEvent; 13 import java.awt.event.AdjustmentEvent;14 import java.awt.event.AdjustmentListener;15 12 import java.awt.event.ItemEvent; 16 13 import java.awt.event.ItemListener; 17 14 import java.beans.PropertyChangeEvent; 18 15 import java.beans.PropertyChangeListener; 19 import java.util.ArrayList;20 16 import java.util.Collection; 21 import java.util.HashMap;22 17 import java.util.List; 23 18 import java.util.Observable; … … 43 38 import org.openstreetmap.josm.data.osm.Way; 44 39 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 40 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer; 45 41 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 46 42 import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTable; 47 import org.openstreetmap.josm.tools.CheckParameterUtil;48 43 import org.openstreetmap.josm.tools.ImageProvider; 49 44 … … 894 889 mergedEntriesTable.unlinkAsListener(); 895 890 theirEntriesTable.unlinkAsListener(); 896 }897 898 /**899 * Synchronizes scrollbar adjustments between a set of900 * {@link Adjustable}s. Whenever the adjustment of one of901 * the registerd Adjustables is updated the adjustment of902 * 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 synchronized920 * scrolling.921 *922 * @param adjustable the adjustable923 */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}s936 *937 */938 @Override939 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 synchronization951 * or not952 *953 * @param adjustable the adjustable954 */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 scrolling966 *967 * @param adjustable the adjustable968 * @return true, if the adjustable is participating in synchronized scrolling, false otherwise969 * @throws IllegalStateException thrown, if adjustable is not registered for synchronized scrolling970 */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 participates982 * in synchronized adjustment</ol>983 * <ol>state changes in this {@link AdjustmentSynchronizer} are reflected in the984 * {@link JCheckBox}</ol>985 * </li>986 *987 *988 * @param view the checkbox to control whether an adjustable participates in synchronized989 * adjustment990 * @param adjustable the adjustable991 * @exception IllegalArgumentException thrown, if view is null992 * @exception IllegalArgumentException thrown, if adjustable is null993 */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 box1003 //1004 view.addItemListener(new ItemListener() {1005 @Override1006 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 @Override1025 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 }1036 891 } 1037 892 -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r6084 r6147 29 29 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 30 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 31 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer; 31 32 import org.openstreetmap.josm.gui.util.GuiHelper; 32 33 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java
r5832 r6147 14 14 import javax.swing.event.TableModelListener; 15 15 16 import org.openstreetmap.josm.data.osm.history.History; 16 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer; 17 17 18 /** 18 19 * 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 10 10 import javax.swing.JTable; 11 11 import javax.swing.ListSelectionModel; 12 13 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer; 12 14 13 15 /** -
trunk/src/org/openstreetmap/josm/gui/util/AdjustmentSynchronizer.java
r6145 r6147 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui. history;2 package org.openstreetmap.josm.gui.util; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; … … 19 19 20 20 /** 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 26 25 */ 27 26 public class AdjustmentSynchronizer implements AdjustmentListener { … … 32 31 private final Observable observable; 33 32 33 /** 34 * Constructs a new {@code AdjustmentSynchronizer} 35 */ 34 36 public AdjustmentSynchronizer() { 35 37 synchronizedAdjustables = new ArrayList<Adjustable>(); … … 39 41 40 42 /** 41 * registers an {@link Adjustable} for participation in synchronized 42 * scrolling. 43 * Registers an {@link Adjustable} for participation in synchronized scrolling. 43 44 * 44 45 * @param adjustable the adjustable … … 55 56 56 57 /** 57 * event handler for {@link AdjustmentEvent}s 58 * 58 * Event handler for {@link AdjustmentEvent}s 59 59 */ 60 60 @Override … … 70 70 71 71 /** 72 * sets whether adjustable participates in adjustment synchronization 73 * or not 72 * Sets whether adjustable participates in adjustment synchronization or not 74 73 * 75 74 * @param adjustable the adjustable … … 85 84 86 85 /** 87 * returns true if an adjustable is participating in synchronized scrolling86 * Returns true if an adjustable is participating in synchronized scrolling 88 87 * 89 88 * @param adjustable the adjustable … … 99 98 100 99 /** 101 * wires a {@link JCheckBox} to the adjustment synchronizer, in such a waythat:100 * Wires a {@link JCheckBox} to the adjustment synchronizer, in such a way that: 102 101 * <li> 103 102 * <ol>state changes in the checkbox control whether the adjustable participates … … 107 106 * </li> 108 107 * 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 112 109 * @param adjustable the adjustable 113 110 * @exception IllegalArgumentException thrown, if view is null 114 111 * @exception IllegalArgumentException thrown, if adjustable is null 115 112 */ 116 p rotected void adapt(final JCheckBox view, final Adjustable adjustable) throws IllegalStateException{113 public void adapt(final JCheckBox view, final Adjustable adjustable) { 117 114 CheckParameterUtil.ensureParameterNotNull(adjustable, "adjustable"); 118 115 CheckParameterUtil.ensureParameterNotNull(view, "view");
Note:
See TracChangeset
for help on using the changeset viewer.