Changeset 14463 in josm
- Timestamp:
- 2018-11-28T22:42:32+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r14426 r14463 7 7 import java.awt.BorderLayout; 8 8 import java.awt.Component; 9 import java.awt.Container;10 9 import java.awt.Dimension; 11 10 import java.awt.FlowLayout; … … 469 468 } 470 469 Config.getPref().removePreferenceChangeListener(this); 471 destroyComponents(this, false); 472 } 473 474 private static void destroyComponents(Component component, boolean destroyItself) { 475 if (component instanceof Container) { 476 for (Component c: ((Container) component).getComponents()) { 477 destroyComponents(c, true); 478 } 479 } 480 if (destroyItself && component instanceof Destroyable) { 481 ((Destroyable) component).destroy(); 482 } 470 GuiHelper.destroyComponents(this, false); 483 471 } 484 472 -
trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java
r14214 r14463 28 28 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 29 29 import org.openstreetmap.josm.tools.CheckParameterUtil; 30 import org.openstreetmap.josm.tools.Destroyable; 30 31 import org.openstreetmap.josm.tools.Pair; 31 32 … … 35 36 * @since 2243 36 37 */ 37 public class CoordinateInfoViewer extends JPanel { 38 39 /** the model */ 40 private transient HistoryBrowserModel model; 41 /** the common info panel for the history node in role REFERENCE_POINT_IN_TIME */ 42 private VersionInfoPanel referenceInfoPanel; 43 /** the common info panel for the history node in role CURRENT_POINT_IN_TIME */ 44 private VersionInfoPanel currentInfoPanel; 38 public class CoordinateInfoViewer extends HistoryBrowserPanel { 39 45 40 /** the info panel for coordinates for the node in role REFERENCE_POINT_IN_TIME */ 46 41 private LatLonViewer referenceLatLonViewer; … … 53 48 54 49 protected void build() { 55 setLayout(new GridBagLayout());56 50 GridBagConstraints gc = new GridBagConstraints(); 57 51 … … 133 127 } 134 128 129 @Override 135 130 protected void unregisterAsChangeListener(HistoryBrowserModel model) { 136 if (currentInfoPanel != null) { 137 model.removeChangeListener(currentInfoPanel); 138 } 139 if (referenceInfoPanel != null) { 140 model.removeChangeListener(referenceInfoPanel); 141 } 131 super.unregisterAsChangeListener(model); 142 132 if (currentLatLonViewer != null) { 143 133 model.removeChangeListener(currentLatLonViewer); … … 154 144 } 155 145 146 @Override 156 147 protected void registerAsChangeListener(HistoryBrowserModel model) { 157 if (currentInfoPanel != null) { 158 model.addChangeListener(currentInfoPanel); 159 } 160 if (referenceInfoPanel != null) { 161 model.addChangeListener(referenceInfoPanel); 162 } 148 super.registerAsChangeListener(model); 163 149 if (currentLatLonViewer != null) { 164 150 model.addChangeListener(currentLatLonViewer); … … 175 161 } 176 162 177 /** 178 * Sets the model for this viewer 179 * 180 * @param model the model. 181 */ 182 public void setModel(HistoryBrowserModel model) { 183 if (this.model != null) { 184 unregisterAsChangeListener(model); 185 } 186 this.model = model; 187 if (this.model != null) { 188 registerAsChangeListener(model); 189 } 163 @Override 164 public void destroy() { 165 super.destroy(); 166 referenceLatLonViewer.destroy(); 167 currentLatLonViewer.destroy(); 168 distanceViewer.destroy(); 190 169 } 191 170 … … 244 223 * A UI widgets which displays the Lan/Lon-coordinates of a {@link HistoryNode}. 245 224 */ 246 private static class LatLonViewer extends JPanel implements ChangeListener {225 private static class LatLonViewer extends JPanel implements ChangeListener, Destroyable { 247 226 248 227 private final JosmTextArea lblLat = newTextArea(); … … 252 231 253 232 protected void build() { 254 setLayout(new GridBagLayout());255 233 setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); 256 234 GridBagConstraints gc = new GridBagConstraints(); … … 294 272 */ 295 273 LatLonViewer(HistoryBrowserModel model, PointInTimeType role) { 274 super(new GridBagLayout()); 296 275 this.updater = new Updater(model, role); 297 276 this.modifiedColor = PointInTimeType.CURRENT_POINT_IN_TIME == role … … 329 308 public void stateChanged(ChangeEvent e) { 330 309 refresh(); 310 } 311 312 @Override 313 public void destroy() { 314 lblLat.destroy(); 315 lblLon.destroy(); 331 316 } 332 317 } … … 374 359 } 375 360 376 private static class DistanceViewer extends JPanel implements ChangeListener {361 private static class DistanceViewer extends JPanel implements ChangeListener, Destroyable { 377 362 378 363 private final JosmTextArea lblDistance = newTextArea(); … … 380 365 381 366 DistanceViewer(HistoryBrowserModel model) { 382 this.updater = new Updater(model, PointInTimeType.REFERENCE_POINT_IN_TIME); 367 super(new GridBagLayout()); 368 updater = new Updater(model, PointInTimeType.REFERENCE_POINT_IN_TIME); 383 369 build(); 384 370 } 385 371 386 372 protected void build() { 387 setLayout(new GridBagLayout());388 373 setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); 389 374 GridBagConstraints gc = new GridBagConstraints(); … … 432 417 refresh(); 433 418 } 419 420 @Override 421 public void destroy() { 422 lblDistance.destroy(); 423 } 434 424 } 435 425 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowser.java
r14214 r14463 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 16 import org.openstreetmap.josm.data.osm.history.History; 17 import org.openstreetmap.josm.tools.Destroyable; 17 18 18 19 /** 19 20 * HistoryBrowser is an UI component which displays history information about an {@link OsmPrimitive}. 20 21 * 21 * 22 * @since 1709 22 23 */ 23 public class HistoryBrowser extends JPanel {24 public class HistoryBrowser extends JPanel implements Destroyable { 24 25 25 26 /** the model */ … … 106 107 } 107 108 108 109 109 /** 110 110 * populates the browser with the history of a specific {@link OsmPrimitive} … … 149 149 return model; 150 150 } 151 152 @Override 153 public void destroy() { 154 model.unlinkAsListener(); 155 for (Destroyable component : new Destroyable[] { 156 tagInfoViewer, nodeListViewer, relationMemberListViewer, coordinateInfoViewer}) { 157 component.destroy(); 158 } 159 } 151 160 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialog.java
r14153 r14463 126 126 /** 127 127 * Removes this history browser model as listener for data change and layer change events. 128 */ 128 * @deprecated not needeed anymore, job is done in {@link #dispose} 129 */ 130 @Deprecated 129 131 public void unlinkAsListener() { 130 132 getHistoryBrowser().getModel().unlinkAsListener(); … … 160 162 161 163 void run() { 162 getHistoryBrowser().getModel().unlinkAsListener();163 HistoryDataSet.getInstance().removeHistoryDataSetListener(HistoryBrowserDialog.this);164 164 HistoryBrowserDialogManager.getInstance().hide(HistoryBrowserDialog.this); 165 165 } … … 202 202 return browser; 203 203 } 204 205 @Override 206 public void dispose() { 207 HistoryDataSet.getInstance().removeHistoryDataSetListener(HistoryBrowserDialog.this); 208 GuiHelper.destroyComponents(this, false); 209 super.dispose(); 210 } 204 211 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
r14153 r14463 153 153 dialogs.addAll(this.dialogs.values()); 154 154 for (HistoryBrowserDialog dialog: dialogs) { 155 dialog.unlinkAsListener();156 155 hide(dialog); 157 156 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryViewerPanel.java
r10210 r14463 3 3 4 4 import java.awt.GridBagConstraints; 5 import java.awt.GridBagLayout;6 5 import java.awt.Insets; 7 6 8 import javax.swing.JPanel;9 7 import javax.swing.JScrollPane; 10 8 import javax.swing.JTable; … … 16 14 * @since 6207 17 15 */ 18 public abstract class HistoryViewerPanel extends JPanel {16 public abstract class HistoryViewerPanel extends HistoryBrowserPanel { 19 17 20 protected transient HistoryBrowserModel model;21 protected VersionInfoPanel referenceInfoPanel;22 protected VersionInfoPanel currentInfoPanel;23 18 protected transient AdjustmentSynchronizer adjustmentSynchronizer; 24 19 protected transient SelectionSynchronizer selectionSynchronizer; … … 35 30 } 36 31 37 /**38 * Sets the history browsing model.39 * @param model The history browsing model40 */41 public final void setModel(HistoryBrowserModel model) {42 if (this.model != null) {43 unregisterAsChangeListener(model);44 }45 this.model = model;46 if (this.model != null) {47 registerAsChangeListener(model);48 }49 }50 51 protected final void unregisterAsChangeListener(HistoryBrowserModel model) {52 if (currentInfoPanel != null) {53 model.removeChangeListener(currentInfoPanel);54 }55 if (referenceInfoPanel != null) {56 model.removeChangeListener(referenceInfoPanel);57 }58 }59 60 protected final void registerAsChangeListener(HistoryBrowserModel model) {61 if (currentInfoPanel != null) {62 model.addChangeListener(currentInfoPanel);63 }64 if (referenceInfoPanel != null) {65 model.addChangeListener(referenceInfoPanel);66 }67 }68 69 32 protected abstract JTable buildReferenceTable(); 70 33 … … 72 35 73 36 private void build() { 74 setLayout(new GridBagLayout());75 37 GridBagConstraints gc = new GridBagConstraints(); 76 38 -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r14221 r14463 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagConstraints;7 import java.awt.GridBagLayout;8 import java.awt.Insets;9 6 import java.awt.Point; 10 7 import java.awt.event.ActionEvent; … … 13 10 14 11 import javax.swing.AbstractAction; 15 import javax.swing.JPanel;16 12 import javax.swing.JPopupMenu; 17 13 import javax.swing.JScrollPane; … … 32 28 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 33 29 import org.openstreetmap.josm.gui.MainApplication; 34 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;35 30 import org.openstreetmap.josm.gui.util.GuiHelper; 36 31 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 47 42 * @since 1709 48 43 */ 49 public class NodeListViewer extends JPanel { 50 51 private transient HistoryBrowserModel model; 52 private VersionInfoPanel referenceInfoPanel; 53 private VersionInfoPanel currentInfoPanel; 54 private transient AdjustmentSynchronizer adjustmentSynchronizer; 55 private transient SelectionSynchronizer selectionSynchronizer; 56 private NodeListPopupMenu popupMenu; 44 public class NodeListViewer extends HistoryViewerPanel { 45 46 private final NodeListPopupMenu popupMenu = new NodeListPopupMenu(); 57 47 58 48 /** … … 61 51 */ 62 52 public NodeListViewer(HistoryBrowserModel model) { 63 setModel(model); 64 build(); 65 } 66 67 protected JScrollPane embeddInScrollPane(JTable table) { 53 super(model); 54 } 55 56 protected JScrollPane embedInScrollPane(JTable table) { 68 57 JScrollPane pane = new JScrollPane(table); 69 58 adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar()); … … 71 60 } 72 61 73 protected JTable buildReferenceNodeListTable() { 62 @Override 63 protected JTable buildReferenceTable() { 74 64 final DiffTableModel tableModel = model.getNodeListTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME); 75 65 final NodeListTableColumnModel columnModel = new NodeListTableColumnModel(); … … 84 74 } 85 75 86 protected JTable buildCurrentNodeListTable() { 76 @Override 77 protected JTable buildCurrentTable() { 87 78 final DiffTableModel tableModel = model.getNodeListTableModel(PointInTimeType.CURRENT_POINT_IN_TIME); 88 79 final NodeListTableColumnModel columnModel = new NodeListTableColumnModel(); … … 97 88 } 98 89 99 protected void build() {100 setLayout(new GridBagLayout());101 GridBagConstraints gc = new GridBagConstraints();102 103 // ---------------------------104 gc.gridx = 0;105 gc.gridy = 0;106 gc.gridwidth = 1;107 gc.gridheight = 1;108 gc.weightx = 0.5;109 gc.weighty = 0.0;110 gc.insets = new Insets(5, 5, 5, 0);111 gc.fill = GridBagConstraints.HORIZONTAL;112 gc.anchor = GridBagConstraints.FIRST_LINE_START;113 referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);114 add(referenceInfoPanel, gc);115 116 gc.gridx = 1;117 gc.gridy = 0;118 gc.gridwidth = 1;119 gc.gridheight = 1;120 gc.fill = GridBagConstraints.HORIZONTAL;121 gc.weightx = 0.5;122 gc.weighty = 0.0;123 gc.anchor = GridBagConstraints.FIRST_LINE_START;124 currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME);125 add(currentInfoPanel, gc);126 127 adjustmentSynchronizer = new AdjustmentSynchronizer();128 selectionSynchronizer = new SelectionSynchronizer();129 130 popupMenu = new NodeListPopupMenu();131 132 // ---------------------------133 gc.gridx = 0;134 gc.gridy = 1;135 gc.gridwidth = 1;136 gc.gridheight = 1;137 gc.weightx = 0.5;138 gc.weighty = 1.0;139 gc.fill = GridBagConstraints.BOTH;140 gc.anchor = GridBagConstraints.NORTHWEST;141 add(embeddInScrollPane(buildReferenceNodeListTable()), gc);142 143 gc.gridx = 1;144 gc.gridy = 1;145 gc.gridwidth = 1;146 gc.gridheight = 1;147 gc.weightx = 0.5;148 gc.weighty = 1.0;149 gc.fill = GridBagConstraints.BOTH;150 gc.anchor = GridBagConstraints.NORTHWEST;151 add(embeddInScrollPane(buildCurrentNodeListTable()), gc);152 }153 154 protected void unregisterAsChangeListener(HistoryBrowserModel model) {155 if (currentInfoPanel != null) {156 model.removeChangeListener(currentInfoPanel);157 }158 if (referenceInfoPanel != null) {159 model.removeChangeListener(referenceInfoPanel);160 }161 }162 163 protected void registerAsChangeListener(HistoryBrowserModel model) {164 if (currentInfoPanel != null) {165 model.addChangeListener(currentInfoPanel);166 }167 if (referenceInfoPanel != null) {168 model.addChangeListener(referenceInfoPanel);169 }170 }171 172 /**173 * Sets the history browser model.174 * @param model the history browser model175 */176 public void setModel(HistoryBrowserModel model) {177 if (this.model != null) {178 unregisterAsChangeListener(model);179 }180 this.model = model;181 if (this.model != null) {182 registerAsChangeListener(model);183 }184 }185 186 90 static final class ReversedChangeListener implements TableModelListener { 187 91 private final NodeListTableColumnModel columnModel; -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java
r8510 r14463 17 17 * <li>on the right, it displays the list of relation members for the version at {@link PointInTimeType#CURRENT_POINT_IN_TIME}</li> 18 18 * </ul> 19 * 19 * @since 1709 20 20 */ 21 21 public class RelationMemberListViewer extends HistoryViewerPanel { -
trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java
r13849 r14463 91 91 Supplier<Collection<? extends Tagged>> objectSp = () -> Arrays.asList(histoSp.get()); 92 92 93 tagMenu.add( new CopyValueAction(table, tagKeyFn, objectSp));94 tagMenu.add( new CopyKeyValueAction(table, tagKeyFn, objectSp));95 tagMenu.add( new CopyAllKeyValueAction(table, tagKeyFn, objectSp));93 tagMenu.add(trackJosmAction(new CopyValueAction(table, tagKeyFn, objectSp))); 94 tagMenu.add(trackJosmAction(new CopyKeyValueAction(table, tagKeyFn, objectSp))); 95 tagMenu.add(trackJosmAction(new CopyAllKeyValueAction(table, tagKeyFn, objectSp))); 96 96 tagMenu.addSeparator(); 97 tagMenu.add( new HelpAction(table, tagKeyFn, tagValuesFn, null, null));98 tagMenu.add( new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null));97 tagMenu.add(trackJosmAction(new HelpAction(table, tagKeyFn, tagValuesFn, null, null))); 98 tagMenu.add(trackJosmAction(new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null))); 99 99 100 100 table.addMouseListener(new PopupMenuLauncher(tagMenu)); -
trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java
r14432 r14463 41 41 import org.openstreetmap.josm.spi.preferences.Config; 42 42 import org.openstreetmap.josm.tools.CheckParameterUtil; 43 import org.openstreetmap.josm.tools.Destroyable; 43 44 import org.openstreetmap.josm.tools.GBC; 44 45 import org.openstreetmap.josm.tools.ImageProvider; … … 51 52 * @since 1709 52 53 */ 53 public class VersionInfoPanel extends JPanel implements ChangeListener {54 public class VersionInfoPanel extends JPanel implements ChangeListener, Destroyable { 54 55 private final PointInTimeType pointInTimeType; 55 56 private final transient HistoryBrowserModel model; … … 339 340 } 340 341 } 342 343 @Override 344 public void destroy() { 345 model.removeChangeListener(this); 346 } 341 347 } -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r14153 r14463 58 58 import org.openstreetmap.josm.tools.CheckParameterUtil; 59 59 import org.openstreetmap.josm.tools.ColorHelper; 60 import org.openstreetmap.josm.tools.Destroyable; 60 61 import org.openstreetmap.josm.tools.GBC; 61 62 import org.openstreetmap.josm.tools.ImageOverlay; … … 646 647 } 647 648 } 649 650 /** 651 * Destroys recursively all {@link Destroyable} components of a given container, and optionnally the container itself. 652 * @param component the component to destroy 653 * @param destroyItself whether to destroy the component itself 654 * @since 14463 655 */ 656 public static void destroyComponents(Component component, boolean destroyItself) { 657 if (component instanceof Container) { 658 for (Component c: ((Container) component).getComponents()) { 659 destroyComponents(c, true); 660 } 661 } 662 if (destroyItself && component instanceof Destroyable) { 663 ((Destroyable) component).destroy(); 664 } 665 } 648 666 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmEditorPane.java
r9175 r14463 16 16 17 17 import org.openstreetmap.josm.gui.util.GuiHelper; 18 import org.openstreetmap.josm.tools.Destroyable; 18 19 import org.openstreetmap.josm.tools.HttpClient; 19 20 import org.openstreetmap.josm.tools.LanguageInfo; … … 24 25 * @since 5886 25 26 */ 26 public class JosmEditorPane extends JEditorPane { 27 public class JosmEditorPane extends JEditorPane implements Destroyable { 28 29 private final PopupMenuLauncher launcher; 27 30 28 31 /** … … 31 34 */ 32 35 public JosmEditorPane() { 33 TextContextualPopupMenu.enableMenuFor(this, true);36 launcher = TextContextualPopupMenu.enableMenuFor(this, true); 34 37 } 35 38 … … 137 140 ); 138 141 } 142 143 @Override 144 public void destroy() { 145 TextContextualPopupMenu.disableMenuFor(this, launcher); 146 } 139 147 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextArea.java
r12630 r14463 11 11 import org.openstreetmap.josm.gui.MainApplication; 12 12 import org.openstreetmap.josm.gui.MapFrame; 13 import org.openstreetmap.josm.tools.Destroyable; 13 14 14 15 /** … … 16 17 * @since 5886 17 18 */ 18 public class JosmTextArea extends JTextArea implements FocusListener { 19 public class JosmTextArea extends JTextArea implements Destroyable, FocusListener { 20 21 private final PopupMenuLauncher launcher; 19 22 20 23 /** … … 88 91 public JosmTextArea(Document doc, String text, int rows, int columns) { 89 92 super(doc, text, rows, columns); 90 TextContextualPopupMenu.enableMenuFor(this, true);93 launcher = TextContextualPopupMenu.enableMenuFor(this, true); 91 94 addFocusListener(this); 92 95 } … … 119 122 } 120 123 } 124 125 @Override 126 public void destroy() { 127 removeFocusListener(this); 128 TextContextualPopupMenu.disableMenuFor(this, launcher); 129 } 121 130 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java
r12630 r14463 16 16 import org.openstreetmap.josm.gui.MainApplication; 17 17 import org.openstreetmap.josm.gui.MapFrame; 18 import org.openstreetmap.josm.tools.Destroyable; 18 19 19 20 /** … … 26 27 * @since 5886 27 28 */ 28 public class JosmTextField extends JTextField implements FocusListener {29 public class JosmTextField extends JTextField implements Destroyable, FocusListener { 29 30 31 private final PopupMenuLauncher launcher; 30 32 private String hint; 31 33 … … 69 71 public JosmTextField(Document doc, String text, int columns, boolean undoRedo) { 70 72 super(doc, text, columns); 71 TextContextualPopupMenu.enableMenuFor(this, undoRedo);73 launcher = TextContextualPopupMenu.enableMenuFor(this, undoRedo); 72 74 // Fix minimum size when columns are specified 73 75 if (columns > 0) { … … 184 186 repaint(); 185 187 } 188 189 @Override 190 public void destroy() { 191 removeFocusListener(this); 192 TextContextualPopupMenu.disableMenuFor(this, launcher); 193 } 186 194 }
Note:
See TracChangeset
for help on using the changeset viewer.