Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r9840 r9926 115 115 private final LayerList layerList; 116 116 117 private final SideButton opacityButton;118 private final SideButton gammaButton;119 120 117 private final ActivateLayerAction activateLayerAction; 121 118 private final ShowHideLayerAction showHideLayerAction; … … 268 265 269 266 // -- layer opacity action 270 LayerOpacityAction layerOpacityAction = new LayerOpacityAction( );267 LayerOpacityAction layerOpacityAction = new LayerOpacityAction(model); 271 268 adaptTo(layerOpacityAction, selectionModel); 272 opacityButton = new SideButton(layerOpacityAction, false); 269 SideButton opacityButton = new SideButton(layerOpacityAction, false); 270 layerOpacityAction.setCorrespondingSideButton(opacityButton); 273 271 274 272 // -- layer gamma action 275 LayerGammaAction layerGammaAction = new LayerGammaAction( );273 LayerGammaAction layerGammaAction = new LayerGammaAction(model); 276 274 adaptTo(layerGammaAction, selectionModel); 277 gammaButton = new SideButton(layerGammaAction, false); 275 SideButton gammaButton = new SideButton(layerGammaAction, false); 276 layerGammaAction.setCorrespondingSideButton(gammaButton); 278 277 279 278 // -- delete layer action … … 533 532 */ 534 533 public abstract static class AbstractLayerPropertySliderAction extends AbstractAction implements IEnabledStateUpdating, LayerAction { 534 protected final LayerListModel model; 535 535 protected final JPopupMenu popup; 536 536 protected final JSlider slider; 537 537 private final double factor; 538 539 public AbstractLayerPropertySliderAction(String name, final double factor) { 538 private SideButton sideButton; 539 540 protected AbstractLayerPropertySliderAction(LayerListModel model, String name, final double factor) { 540 541 super(name); 542 this.model = model; 541 543 this.factor = factor; 542 544 updateEnabledState(); … … 551 553 }); 552 554 popup.add(slider); 553 554 555 } 555 556 … … 558 559 protected abstract double getValue(); 559 560 560 protected abstract SideButton getCorrespondingSideButton(); 561 /** 562 * Sets the corresponding side button. 563 * @param sideButton the corresponding side button 564 */ 565 final void setCorrespondingSideButton(SideButton sideButton) { 566 this.sideButton = sideButton; 567 } 561 568 562 569 @Override 563 570 public void actionPerformed(ActionEvent e) { 564 final SideButton sideButton = getCorrespondingSideButton();565 571 slider.setValue((int) (getValue() * factor)); 566 572 if (e.getSource() == sideButton) { … … 577 583 return new JMenuItem(this); 578 584 } 579 580 585 } 581 586 … … 583 588 * Action which allows to change the opacity of one or more layers. 584 589 */ 585 public final class LayerOpacityAction extends AbstractLayerPropertySliderAction {590 public static final class LayerOpacityAction extends AbstractLayerPropertySliderAction { 586 591 private transient Layer layer; 587 592 588 593 /** 589 * Creates a {@link LayerOpacityAction} which allows to change the 590 * opacity of one or more layers.591 * 594 * Creates a {@link LayerOpacityAction} which allows to change the opacity of one or more layers. 595 * 596 * @param model layer list model 592 597 * @param layer the layer. Must not be null. 593 598 * @throws IllegalArgumentException if layer is null 594 599 */ 595 public LayerOpacityAction(Layer layer) {596 this( );600 public LayerOpacityAction(LayerListModel model, Layer layer) { 601 this(model); 597 602 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 598 603 this.layer = layer; … … 601 606 602 607 /** 603 * Creates a {@link ShowHideLayerAction} which will toggle the visibility of 604 * the currently selected layers 605 * 606 */ 607 public LayerOpacityAction() { 608 super(tr("Opacity"), 100); 608 * Creates a {@link ShowHideLayerAction} which will toggle the visibility of the currently selected layers 609 * @param model layer list model 610 */ 611 public LayerOpacityAction(LayerListModel model) { 612 super(model, tr("Opacity"), 100); 609 613 putValue(SHORT_DESCRIPTION, tr("Adjust opacity of the layer.")); 610 614 putValue(SMALL_ICON, ImageProvider.get("dialogs/layerlist", "transparency")); … … 617 621 layer.setOpacity(value); 618 622 } else { 619 for (Layer l ayer: model.getSelectedLayers()) {620 l ayer.setOpacity(value);623 for (Layer l : model.getSelectedLayers()) { 624 l.setOpacity(value); 621 625 } 622 626 } … … 630 634 double opacity = 0; 631 635 List<Layer> layers = model.getSelectedLayers(); 632 for (Layer l ayer: layers) {633 opacity += l ayer.getOpacity();636 for (Layer l : layers) { 637 opacity += l.getOpacity(); 634 638 } 635 639 return opacity / layers.size(); 636 640 } 637 }638 639 @Override640 protected SideButton getCorrespondingSideButton() {641 return opacityButton;642 641 } 643 642 … … 645 644 public void updateEnabledState() { 646 645 if (layer == null) { 647 setEnabled(! getModel().getSelectedLayers().isEmpty());646 setEnabled(!model.getSelectedLayers().isEmpty()); 648 647 } else { 649 648 setEnabled(true); … … 660 659 * Action which allows to change the gamma of one imagery layer. 661 660 */ 662 public final class LayerGammaAction extends AbstractLayerPropertySliderAction { 663 664 public LayerGammaAction() { 665 super(tr("Gamma"), 50); 661 public static final class LayerGammaAction extends AbstractLayerPropertySliderAction { 662 663 /** 664 * Constructs a new {@code LayerGammaAction}. 665 * @param model layer list model 666 */ 667 public LayerGammaAction(LayerListModel model) { 668 super(model, tr("Gamma"), 50); 666 669 putValue(SHORT_DESCRIPTION, tr("Adjust gamma value of the layer.")); 667 670 putValue(SMALL_ICON, ImageProvider.get("dialogs/layerlist", "gamma")); … … 678 681 protected double getValue() { 679 682 return Utils.filteredCollection(model.getSelectedLayers(), ImageryLayer.class).iterator().next().getGamma(); 680 }681 682 @Override683 protected SideButton getCorrespondingSideButton() {684 return gammaButton;685 683 } 686 684 … … 1112 1110 Layer layer = (Layer) value; 1113 1111 if (layer instanceof NativeScaleLayer) { 1114 boolean active = layer != null && layer== Main.map.mapView.getNativeScaleLayer();1112 boolean active = ((NativeScaleLayer) layer) == Main.map.mapView.getNativeScaleLayer(); 1115 1113 cb.setSelected(active); 1116 1114 cb.setToolTipText(active … … 1271 1269 * the properties {@link Layer#VISIBLE_PROP} and {@link Layer#NAME_PROP}. 1272 1270 */ 1273 public final class LayerListModel extends AbstractTableModel implements MapView.LayerChangeListener, PropertyChangeListener {1271 public static final class LayerListModel extends AbstractTableModel implements MapView.LayerChangeListener, PropertyChangeListener { 1274 1272 /** manages list selection state*/ 1275 1273 private final DefaultListSelectionModel selectionModel; 1276 1274 private final CopyOnWriteArrayList<LayerListModelListener> listeners; 1275 private LayerList layerList; 1277 1276 1278 1277 /** … … 1281 1280 * @param selectionModel the list selection model 1282 1281 */ 1283 privateLayerListModel(DefaultListSelectionModel selectionModel) {1282 LayerListModel(DefaultListSelectionModel selectionModel) { 1284 1283 this.selectionModel = selectionModel; 1285 1284 listeners = new CopyOnWriteArrayList<>(); 1285 } 1286 1287 void setlayerList(LayerList layerList) { 1288 this.layerList = layerList; 1286 1289 } 1287 1290 … … 1732 1735 1733 1736 static class LayerList extends JTable { 1734 LayerList( TableModel dataModel) {1737 LayerList(LayerListModel dataModel) { 1735 1738 super(dataModel); 1739 dataModel.setlayerList(this); 1736 1740 } 1737 1741
Note:
See TracChangeset
for help on using the changeset viewer.