- Timestamp:
- 2019-12-14T20:59:55+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r15496 r15592 39 39 40 40 import org.openstreetmap.josm.actions.ExpertToggleAction; 41 import org.openstreetmap.josm.actions.ExpertToggleAction.ExpertModeChangeListener; 41 42 import org.openstreetmap.josm.actions.MergeLayerAction; 42 43 import org.openstreetmap.josm.data.coor.EastNorth; 43 44 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 45 import org.openstreetmap.josm.data.preferences.AbstractProperty.ValueChangeEvent; 44 46 import org.openstreetmap.josm.data.preferences.AbstractProperty.ValueChangeListener; 45 47 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … 130 132 /** the list of layers (technically its a JTable, but appears like a list) */ 131 133 private final LayerList layerList; 132 private final ValueChangeListener<? super Boolean> displayNumbersPrefListener;134 private final ColumnWidthAdaptionListener visibilityWidthListener; 133 135 134 136 private final ActivateLayerAction activateLayerAction; … … 223 225 layerList.getColumnModel().getColumn(2).setResizable(false); 224 226 225 int width = getLayerNumberWidth();226 227 layerList.getColumnModel().getColumn(3).setCellRenderer(new LayerVisibleCellRenderer()); 227 228 layerList.getColumnModel().getColumn(3).setCellEditor(new LayerVisibleCellEditor(new LayerVisibleCheckBox())); 228 layerList.getColumnModel().getColumn(3).setMaxWidth(width);229 layerList.getColumnModel().getColumn(3).setPreferredWidth(width);230 229 layerList.getColumnModel().getColumn(3).setResizable(false); 231 230 … … 252 251 } 253 252 254 displayNumbersPrefListener = change -> { 255 int numberWidth = getLayerNumberWidth(); 256 layerList.getColumnModel().getColumn(3).setMaxWidth(numberWidth); 257 layerList.getColumnModel().getColumn(3).setPreferredWidth(numberWidth); 258 repaint(); 259 }; 260 DISPLAY_NUMBERS.addListener(displayNumbersPrefListener); 253 visibilityWidthListener = new ColumnWidthAdaptionListener(3, 16); 254 DISPLAY_NUMBERS.addListener(visibilityWidthListener); 255 ExpertToggleAction.addExpertModeChangeListener(visibilityWidthListener); 256 layerManager.addLayerChangeListener(visibilityWidthListener); 257 visibilityWidthListener.updateColumnWidth(); 261 258 262 259 // init the model … … 343 340 } 344 341 345 private static int getLayerNumberWidth() {346 return displayLayerNumbers() ? 48 : 16;347 }348 349 342 /** 350 343 * Gets the layer manager this dialog is for. … … 388 381 JumpToMarkerActions.unregisterActions(); 389 382 layerList.setTransferHandler(null); 390 DISPLAY_NUMBERS.removeListener(displayNumbersPrefListener); 383 DISPLAY_NUMBERS.removeListener(visibilityWidthListener); 384 ExpertToggleAction.removeExpertModeChangeListener(visibilityWidthListener); 385 layerManager.removeLayerChangeListener(visibilityWidthListener); 391 386 super.destroy(); 392 387 instance = null; … … 395 390 static ImageIcon createBlankIcon() { 396 391 return ImageProvider.createBlankIcon(ImageSizes.LAYER); 392 } 393 394 private class ColumnWidthAdaptionListener implements ValueChangeListener<Boolean>, ExpertModeChangeListener, LayerChangeListener { 395 private final int minWidth; 396 private final int column; 397 398 ColumnWidthAdaptionListener(int column, int minWidth) { 399 this.column = column; 400 this.minWidth = minWidth; 401 } 402 403 @Override 404 public void expertChanged(boolean isExpert) { 405 updateColumnWidth(); 406 } 407 408 @Override 409 public void valueChanged(ValueChangeEvent<? extends Boolean> e) { 410 updateColumnWidth(); 411 } 412 413 @Override 414 public void layerAdded(LayerAddEvent e) { 415 updateColumnWidth(); 416 } 417 418 @Override 419 public void layerRemoving(LayerRemoveEvent e) { 420 updateColumnWidth(); 421 } 422 423 @Override 424 public void layerOrderChanged(LayerOrderChangeEvent e) { 425 //not needed 426 } 427 428 public void updateColumnWidth() { 429 int width = minWidth; 430 for (int row = 0; row < layerList.getRowCount(); row++) { 431 TableCellRenderer renderer = layerList.getCellRenderer(row, column); 432 Component comp = layerList.prepareRenderer(renderer, row, column); 433 width = Math.max(comp.getPreferredSize().width + 1, width); 434 } 435 layerList.getColumnModel().getColumn(column).setMaxWidth(width); 436 layerList.getColumnModel().getColumn(column).setPreferredWidth(width); 437 repaint(); 438 } 397 439 } 398 440 … … 419 461 */ 420 462 LayerVisibleCheckBox() { 421 setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);422 463 iconEye = ImageProvider.get("dialogs/layerlist", "eye"); 423 464 iconEyeTranslucent = ImageProvider.get("dialogs/layerlist", "eye-translucent");
Note:
See TracChangeset
for help on using the changeset viewer.