Changeset 6207 in josm for trunk/src


Ignore:
Timestamp:
2013-08-29T01:04:44+02:00 (11 years ago)
Author:
Don-vip
Message:

Sonar - refactor duplicate code in history browsing panels

Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
1 added
2 edited

Legend:

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

    r6147 r6207  
    22package org.openstreetmap.josm.gui.history;
    33
    4 import java.awt.GridBagConstraints;
    5 import java.awt.GridBagLayout;
    6 import java.awt.Insets;
    74import java.awt.Rectangle;
    85
    9 import javax.swing.JPanel;
    10 import javax.swing.JScrollPane;
    116import javax.swing.JTable;
    127import javax.swing.ListSelectionModel;
    138import javax.swing.event.TableModelEvent;
    149import javax.swing.event.TableModelListener;
    15 
    16 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
    1710
    1811/**
     
    2619 *
    2720 */
    28 
    29 public class RelationMemberListViewer extends JPanel{
    30 
    31     private HistoryBrowserModel model;
    32     private VersionInfoPanel referenceInfoPanel;
    33     private VersionInfoPanel currentInfoPanel;
    34     private AdjustmentSynchronizer adjustmentSynchronizer;
    35     private SelectionSynchronizer selectionSynchronizer;
    36 
    37     protected JScrollPane embeddInScrollPane(JTable table) {
    38         JScrollPane pane = new JScrollPane(table);
    39         pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    40         pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    41         adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar());
    42         return pane;
    43     }
     21public class RelationMemberListViewer extends HistoryViewerPanel {
    4422
    4523    protected class MemberModelChanged implements TableModelListener {
     
    5735    }
    5836
    59     protected JTable buildReferenceMemberListTable() {
     37    protected JTable buildReferenceTable() {
    6038        JTable table = new JTable(
    6139                model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME),
     
    6947    }
    7048
    71     protected JTable buildCurrentMemberListTable() {
     49    protected JTable buildCurrentTable() {
    7250        JTable table = new JTable(
    7351                model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME),
     
    8159    }
    8260
    83     protected void build() {
    84         setLayout(new GridBagLayout());
    85         GridBagConstraints gc = new GridBagConstraints();
    86 
    87         // ---------------------------
    88         gc.gridx = 0;
    89         gc.gridy = 0;
    90         gc.gridwidth = 1;
    91         gc.gridheight = 1;
    92         gc.weightx = 0.5;
    93         gc.weighty = 0.0;
    94         gc.insets = new Insets(5,5,5,0);
    95         gc.fill = GridBagConstraints.HORIZONTAL;
    96         gc.anchor = GridBagConstraints.FIRST_LINE_START;
    97         referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
    98         add(referenceInfoPanel,gc);
    99 
    100         gc.gridx = 1;
    101         gc.gridy = 0;
    102         gc.gridwidth = 1;
    103         gc.gridheight = 1;
    104         gc.fill = GridBagConstraints.HORIZONTAL;
    105         gc.weightx = 0.5;
    106         gc.weighty = 0.0;
    107         gc.anchor = GridBagConstraints.FIRST_LINE_START;
    108         currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME);
    109         add(currentInfoPanel,gc);
    110 
    111         adjustmentSynchronizer = new AdjustmentSynchronizer();
    112         selectionSynchronizer = new SelectionSynchronizer();
    113 
    114         // ---------------------------
    115         gc.gridx = 0;
    116         gc.gridy = 1;
    117         gc.gridwidth = 1;
    118         gc.gridheight = 1;
    119         gc.weightx = 0.5;
    120         gc.weighty = 1.0;
    121         gc.fill = GridBagConstraints.BOTH;
    122         gc.anchor = GridBagConstraints.NORTHWEST;
    123         add(embeddInScrollPane(buildReferenceMemberListTable()),gc);
    124 
    125         gc.gridx = 1;
    126         gc.gridy = 1;
    127         gc.gridwidth = 1;
    128         gc.gridheight = 1;
    129         gc.weightx = 0.5;
    130         gc.weighty = 1.0;
    131         gc.fill = GridBagConstraints.BOTH;
    132         gc.anchor = GridBagConstraints.NORTHWEST;
    133         add(embeddInScrollPane(buildCurrentMemberListTable()),gc);
    134     }
    135 
     61    /**
     62     * Constructs a new {@code RelationMemberListViewer}.
     63     * @param model The history browsing model
     64     */
    13665    public RelationMemberListViewer(HistoryBrowserModel model) {
    137         setModel(model);
    138         build();
    139     }
    140 
    141     protected void unregisterAsObserver(HistoryBrowserModel model) {
    142         if (currentInfoPanel != null) {
    143             model.deleteObserver(currentInfoPanel);
    144         }
    145         if (referenceInfoPanel != null) {
    146             model.deleteObserver(referenceInfoPanel);
    147         }
    148     }
    149     protected void registerAsObserver(HistoryBrowserModel model) {
    150         if (currentInfoPanel != null) {
    151             model.addObserver(currentInfoPanel);
    152         }
    153         if (referenceInfoPanel != null) {
    154             model.addObserver(referenceInfoPanel);
    155         }
    156     }
    157 
    158     public void setModel(HistoryBrowserModel model) {
    159         if (this.model != null) {
    160             unregisterAsObserver(model);
    161         }
    162         this.model = model;
    163         if (this.model != null) {
    164             registerAsObserver(model);
    165         }
     66        super(model);
    16667    }
    16768}
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r6147 r6207  
    22package org.openstreetmap.josm.gui.history;
    33
    4 import java.awt.GridBagConstraints;
    5 import java.awt.GridBagLayout;
    6 import java.awt.Insets;
    7 
    8 import javax.swing.JPanel;
    9 import javax.swing.JScrollPane;
    104import javax.swing.JTable;
    115import javax.swing.ListSelectionModel;
    12 
    13 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
    146
    157/**
     
    2315 *
    2416 */
    25 public class TagInfoViewer extends JPanel{
     17public class TagInfoViewer extends HistoryViewerPanel {
    2618
    27     private HistoryBrowserModel model;
    28     private VersionInfoPanel referenceInfoPanel;
    29     private VersionInfoPanel currentInfoPanel;
    30     private AdjustmentSynchronizer adjustmentSynchronizer;
    31     private SelectionSynchronizer selectionSynchronizer;
    32 
    33     protected JScrollPane embeddInScrollPane(JTable table) {
    34         JScrollPane pane = new JScrollPane(table);
    35         pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    36         pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    37         adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar());
    38         return pane;
    39     }
    40 
    41     protected JTable buildReferenceTagTable() {
     19    protected JTable buildReferenceTable() {
    4220        JTable table = new JTable(
    4321                model.getTagTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME),
     
    5028    }
    5129
    52     protected JTable buildCurrentTagTable() {
     30    protected JTable buildCurrentTable() {
    5331        JTable table = new JTable(
    5432                model.getTagTableModel(PointInTimeType.CURRENT_POINT_IN_TIME),
     
    6139    }
    6240
    63     protected void build() {
    64         setLayout(new GridBagLayout());
    65         GridBagConstraints gc = new GridBagConstraints();
    66 
    67         // ---------------------------
    68         gc.gridx = 0;
    69         gc.gridy = 0;
    70         gc.gridwidth = 1;
    71         gc.gridheight = 1;
    72         gc.weightx = 0.5;
    73         gc.weighty = 0.0;
    74         gc.insets = new Insets(5,5,5,0);
    75         gc.fill = GridBagConstraints.HORIZONTAL;
    76         gc.anchor = GridBagConstraints.FIRST_LINE_START;
    77         referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
    78         add(referenceInfoPanel,gc);
    79 
    80         gc.gridx = 1;
    81         gc.gridy = 0;
    82         gc.gridwidth = 1;
    83         gc.gridheight = 1;
    84         gc.fill = GridBagConstraints.HORIZONTAL;
    85         gc.weightx = 0.5;
    86         gc.weighty = 0.0;
    87         gc.anchor = GridBagConstraints.FIRST_LINE_START;
    88         currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME);
    89         add(currentInfoPanel,gc);
    90 
    91         adjustmentSynchronizer = new AdjustmentSynchronizer();
    92         selectionSynchronizer = new SelectionSynchronizer();
    93 
    94         // ---------------------------
    95         gc.gridx = 0;
    96         gc.gridy = 1;
    97         gc.gridwidth = 1;
    98         gc.gridheight = 1;
    99         gc.weightx = 0.5;
    100         gc.weighty = 1.0;
    101         gc.fill = GridBagConstraints.BOTH;
    102         gc.anchor = GridBagConstraints.NORTHWEST;
    103         add(embeddInScrollPane(buildReferenceTagTable()),gc);
    104 
    105         gc.gridx = 1;
    106         gc.gridy = 1;
    107         gc.gridwidth = 1;
    108         gc.gridheight = 1;
    109         gc.weightx = 0.5;
    110         gc.weighty = 1.0;
    111         gc.fill = GridBagConstraints.BOTH;
    112         gc.anchor = GridBagConstraints.NORTHWEST;
    113         add(embeddInScrollPane(buildCurrentTagTable()),gc);
    114     }
    115 
     41    /**
     42     * Constructs a new {@code TagInfoViewer}.
     43     * @param model The history browsing model
     44     */
    11645    public TagInfoViewer(HistoryBrowserModel model) {
    117         setModel(model);
    118         build();
    119     }
    120 
    121     protected void unregisterAsObserver(HistoryBrowserModel model) {
    122         if (currentInfoPanel != null) {
    123             model.deleteObserver(currentInfoPanel);
    124         }
    125         if (referenceInfoPanel != null) {
    126             model.deleteObserver(referenceInfoPanel);
    127         }
    128     }
    129     protected void registerAsObserver(HistoryBrowserModel model) {
    130         if (currentInfoPanel != null) {
    131             model.addObserver(currentInfoPanel);
    132         }
    133         if (referenceInfoPanel != null) {
    134             model.addObserver(referenceInfoPanel);
    135         }
    136     }
    137 
    138     public void setModel(HistoryBrowserModel model) {
    139         if (this.model != null) {
    140             unregisterAsObserver(model);
    141         }
    142         this.model = model;
    143         if (this.model != null) {
    144             registerAsObserver(model);
    145         }
     46        super(model);
    14647    }
    14748}
Note: See TracChangeset for help on using the changeset viewer.