Ignore:
Timestamp:
2016-05-14T15:45:35+02:00 (3 years ago)
Author:
Don-vip
Message:

see #11924 - Java 9 - replace calls to deprecated classes java.util.Observable / java.util.Observer by a new class ChangeNotifier + swing's ChangeListener

Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java

    r10179 r10210  
    77import java.awt.GridBagLayout;
    88import java.awt.Insets;
    9 import java.util.Observable;
    10 import java.util.Observer;
    119
    1210import javax.swing.BorderFactory;
     
    1412import javax.swing.JPanel;
    1513import javax.swing.UIManager;
     14import javax.swing.event.ChangeEvent;
     15import javax.swing.event.ChangeListener;
    1616
    1717import org.openstreetmap.gui.jmapviewer.JMapViewer;
     
    127127        setModel(model);
    128128        build();
    129         registerAsObserver(model);
    130     }
    131 
    132     protected void unregisterAsObserver(HistoryBrowserModel model) {
     129        registerAsChangeListener(model);
     130    }
     131
     132    protected void unregisterAsChangeListener(HistoryBrowserModel model) {
    133133        if (currentInfoPanel != null) {
    134             model.deleteObserver(currentInfoPanel);
     134            model.removeChangeListener(currentInfoPanel);
    135135        }
    136136        if (referenceInfoPanel != null) {
    137             model.deleteObserver(referenceInfoPanel);
     137            model.removeChangeListener(referenceInfoPanel);
    138138        }
    139139        if (currentLatLonViewer != null) {
    140             model.deleteObserver(currentLatLonViewer);
     140            model.removeChangeListener(currentLatLonViewer);
    141141        }
    142142        if (referenceLatLonViewer != null) {
    143             model.deleteObserver(referenceLatLonViewer);
     143            model.removeChangeListener(referenceLatLonViewer);
    144144        }
    145145        if (distanceViewer != null) {
    146             model.deleteObserver(distanceViewer);
     146            model.removeChangeListener(distanceViewer);
    147147        }
    148148        if (mapViewer != null) {
    149             model.deleteObserver(mapViewer);
    150         }
    151     }
    152 
    153     protected void registerAsObserver(HistoryBrowserModel model) {
     149            model.removeChangeListener(mapViewer);
     150        }
     151    }
     152
     153    protected void registerAsChangeListener(HistoryBrowserModel model) {
    154154        if (currentInfoPanel != null) {
    155             model.addObserver(currentInfoPanel);
     155            model.addChangeListener(currentInfoPanel);
    156156        }
    157157        if (referenceInfoPanel != null) {
    158             model.addObserver(referenceInfoPanel);
     158            model.addChangeListener(referenceInfoPanel);
    159159        }
    160160        if (currentLatLonViewer != null) {
    161             model.addObserver(currentLatLonViewer);
     161            model.addChangeListener(currentLatLonViewer);
    162162        }
    163163        if (referenceLatLonViewer != null) {
    164             model.addObserver(referenceLatLonViewer);
     164            model.addChangeListener(referenceLatLonViewer);
    165165        }
    166166        if (distanceViewer != null) {
    167             model.addObserver(distanceViewer);
     167            model.addChangeListener(distanceViewer);
    168168        }
    169169        if (mapViewer != null) {
    170             model.addObserver(mapViewer);
     170            model.addChangeListener(mapViewer);
    171171        }
    172172    }
     
    179179    public void setModel(HistoryBrowserModel model) {
    180180        if (this.model != null) {
    181             unregisterAsObserver(model);
     181            unregisterAsChangeListener(model);
    182182        }
    183183        this.model = model;
    184184        if (this.model != null) {
    185             registerAsObserver(model);
     185            registerAsChangeListener(model);
    186186        }
    187187    }
     
    241241     * A UI widgets which displays the Lan/Lon-coordinates of a {@link HistoryNode}.
    242242     */
    243     private static class LatLonViewer extends JPanel implements Observer {
     243    private static class LatLonViewer extends JPanel implements ChangeListener {
    244244
    245245        private final JosmTextArea lblLat = newTextArea();
     
    324324
    325325        @Override
    326         public void update(Observable o, Object arg) {
     326        public void stateChanged(ChangeEvent e) {
    327327            refresh();
    328328        }
    329329    }
    330330
    331     private static class MapViewer extends JMapViewer implements Observer {
     331    private static class MapViewer extends JMapViewer implements ChangeListener {
    332332
    333333        private final Updater updater;
     
    339339
    340340        @Override
    341         public void update(Observable o, Object arg) {
     341        public void stateChanged(ChangeEvent e) {
    342342            final Pair<LatLon, LatLon> coordinates = updater.getCoordinates();
    343343            if (coordinates == null) {
     
    362362    }
    363363
    364     private static class DistanceViewer extends JPanel implements Observer {
     364    private static class DistanceViewer extends JPanel implements ChangeListener {
    365365
    366366        private final JosmTextArea lblDistance = newTextArea();
     
    417417
    418418        @Override
    419         public void update(Observable o, Object arg) {
     419        public void stateChanged(ChangeEvent e) {
    420420            refresh();
    421421        }
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r10194 r10210  
    99import java.util.HashSet;
    1010import java.util.List;
    11 import java.util.Observable;
    1211import java.util.Set;
    1312
     
    4645import org.openstreetmap.josm.gui.layer.Layer;
    4746import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     47import org.openstreetmap.josm.gui.util.ChangeNotifier;
    4848import org.openstreetmap.josm.tools.CheckParameterUtil;
    4949import org.openstreetmap.josm.tools.date.DateUtils;
     
    7474 * @see HistoryBrowser
    7575 */
    76 public class HistoryBrowserModel extends Observable implements LayerChangeListener, DataSetListener {
     76public class HistoryBrowserModel extends ChangeNotifier implements LayerChangeListener, DataSetListener {
    7777    /** the history of an OsmPrimitive */
    7878    private History history;
     
    198198        initNodeListTableModels();
    199199        initMemberListTableModels();
    200         setChanged();
    201         notifyObservers();
     200        fireStateChanged();
    202201        versionTableModel.fireTableDataChanged();
    203202    }
     
    317316        initNodeListTableModels();
    318317        initMemberListTableModels();
    319         setChanged();
    320         notifyObservers();
     318        fireStateChanged();
    321319    }
    322320
     
    348346        initNodeListTableModels();
    349347        initMemberListTableModels();
    350         setChanged();
    351         notifyObservers();
     348        fireStateChanged();
    352349    }
    353350
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryViewerPanel.java

    r8510 r10210  
    4141    public final void setModel(HistoryBrowserModel model) {
    4242        if (this.model != null) {
    43             unregisterAsObserver(model);
     43            unregisterAsChangeListener(model);
    4444        }
    4545        this.model = model;
    4646        if (this.model != null) {
    47             registerAsObserver(model);
     47            registerAsChangeListener(model);
    4848        }
    4949    }
    5050
    51     protected final void unregisterAsObserver(HistoryBrowserModel model) {
     51    protected final void unregisterAsChangeListener(HistoryBrowserModel model) {
    5252        if (currentInfoPanel != null) {
    53             model.deleteObserver(currentInfoPanel);
     53            model.removeChangeListener(currentInfoPanel);
    5454        }
    5555        if (referenceInfoPanel != null) {
    56             model.deleteObserver(referenceInfoPanel);
     56            model.removeChangeListener(referenceInfoPanel);
    5757        }
    5858    }
    5959
    60     protected final void registerAsObserver(HistoryBrowserModel model) {
     60    protected final void registerAsChangeListener(HistoryBrowserModel model) {
    6161        if (currentInfoPanel != null) {
    62             model.addObserver(currentInfoPanel);
     62            model.addChangeListener(currentInfoPanel);
    6363        }
    6464        if (referenceInfoPanel != null) {
    65             model.addObserver(referenceInfoPanel);
     65            model.addChangeListener(referenceInfoPanel);
    6666        }
    6767    }
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r9816 r10210  
    173173    }
    174174
    175     protected void unregisterAsObserver(HistoryBrowserModel model) {
     175    protected void unregisterAsChangeListener(HistoryBrowserModel model) {
    176176        if (currentInfoPanel != null) {
    177             model.deleteObserver(currentInfoPanel);
     177            model.removeChangeListener(currentInfoPanel);
    178178        }
    179179        if (referenceInfoPanel != null) {
    180             model.deleteObserver(referenceInfoPanel);
    181         }
    182     }
    183 
    184     protected void registerAsObserver(HistoryBrowserModel model) {
     180            model.removeChangeListener(referenceInfoPanel);
     181        }
     182    }
     183
     184    protected void registerAsChangeListener(HistoryBrowserModel model) {
    185185        if (currentInfoPanel != null) {
    186             model.addObserver(currentInfoPanel);
     186            model.addChangeListener(currentInfoPanel);
    187187        }
    188188        if (referenceInfoPanel != null) {
    189             model.addObserver(referenceInfoPanel);
     189            model.addChangeListener(referenceInfoPanel);
    190190        }
    191191    }
     
    197197    public void setModel(HistoryBrowserModel model) {
    198198        if (this.model != null) {
    199             unregisterAsObserver(model);
     199            unregisterAsChangeListener(model);
    200200        }
    201201        this.model = model;
    202202        if (this.model != null) {
    203             registerAsObserver(model);
     203            registerAsChangeListener(model);
    204204        }
    205205    }
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r9680 r10210  
    1515import java.util.Collections;
    1616import java.util.Date;
    17 import java.util.Observable;
    18 import java.util.Observer;
    1917
    2018import javax.swing.AbstractAction;
     
    2422import javax.swing.JPanel;
    2523import javax.swing.JTextArea;
     24import javax.swing.event.ChangeEvent;
     25import javax.swing.event.ChangeListener;
    2626
    2727import org.openstreetmap.josm.Main;
     
    4848 * @since 1709
    4949 */
    50 public class VersionInfoPanel extends JPanel implements Observer {
     50public class VersionInfoPanel extends JPanel implements ChangeListener {
    5151    private final PointInTimeType pointInTimeType;
    5252    private final transient HistoryBrowserModel model;
     
    189189        this.model = model;
    190190        this.pointInTimeType = pointInTimeType;
    191         model.addObserver(this);
     191        model.addChangeListener(this);
    192192        build();
    193193    }
     
    198198
    199199    @Override
    200     public void update(Observable o, Object arg) {
     200    public void stateChanged(ChangeEvent e) {
    201201        HistoryOsmPrimitive primitive = getPrimitive();
    202202        if (primitive != null) {
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java

    r10021 r10210  
    1414import java.awt.event.KeyEvent;
    1515import java.awt.event.MouseEvent;
    16 import java.util.Observable;
    17 import java.util.Observer;
    1816
    1917import javax.swing.DefaultCellEditor;
     
    2523import javax.swing.SwingConstants;
    2624import javax.swing.UIManager;
     25import javax.swing.event.ChangeEvent;
     26import javax.swing.event.ChangeListener;
    2727import javax.swing.event.TableModelEvent;
    2828import javax.swing.event.TableModelListener;
     
    4545 * @since 1709
    4646 */
    47 public class VersionTable extends JTable implements Observer {
     47public class VersionTable extends JTable implements ChangeListener {
    4848    private VersionTablePopupMenu popupMenu;
    4949    private final transient HistoryBrowserModel model;
     
    5555    public VersionTable(HistoryBrowserModel model) {
    5656        super(model.getVersionTableModel(), new VersionTableColumnModel());
    57         model.addObserver(this);
     57        model.addChangeListener(this);
    5858        build();
    5959        this.model = model;
     
    117117
    118118    @Override
    119     public void update(Observable o, Object arg) {
     119    public void stateChanged(ChangeEvent e) {
    120120        repaint();
    121121    }
Note: See TracChangeset for help on using the changeset viewer.