Changeset 8729 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-09-04T10:32:05+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r8728 r8729 56 56 import org.openstreetmap.josm.gui.SideButton; 57 57 import org.openstreetmap.josm.gui.help.HelpUtil; 58 import org.openstreetmap.josm.gui.layer.ImageryLayer; 58 59 import org.openstreetmap.josm.gui.layer.JumpToMarkerActions; 59 60 import org.openstreetmap.josm.gui.layer.Layer; … … 71 72 import org.openstreetmap.josm.tools.MultikeyShortcutAction.MultikeyInfo; 72 73 import org.openstreetmap.josm.tools.Shortcut; 74 import org.openstreetmap.josm.tools.Utils; 73 75 74 76 /** … … 113 115 114 116 private SideButton opacityButton; 117 private SideButton gammaButton; 115 118 116 119 private ActivateLayerAction activateLayerAction; … … 261 264 opacityButton = new SideButton(layerOpacityAction, false); 262 265 266 // -- layer gamma action 267 LayerGammaAction layerGammaAction = new LayerGammaAction(); 268 adaptTo(layerGammaAction, selectionModel); 269 gammaButton = new SideButton(layerGammaAction, false); 270 263 271 // -- delete layer action 264 272 DeleteLayerAction deleteLayerAction = new DeleteLayerAction(); … … 288 296 new SideButton(showHideLayerAction, false), 289 297 opacityButton, 298 gammaButton, 290 299 new SideButton(deleteLayerAction, false) 291 300 )); … … 513 522 514 523 /** 524 * Abstract action which allows to adjust a double value using a slider 525 */ 526 public static abstract class AbstractLayerPropertySliderAction extends AbstractAction implements IEnabledStateUpdating, LayerAction { 527 protected final JPopupMenu popup; 528 protected final JSlider slider; 529 private final double factor; 530 531 public AbstractLayerPropertySliderAction(String name, final double factor) { 532 super(name); 533 this.factor = factor; 534 updateEnabledState(); 535 536 popup = new JPopupMenu(); 537 slider = new JSlider(JSlider.VERTICAL); 538 slider.addChangeListener(new ChangeListener() { 539 @Override 540 public void stateChanged(ChangeEvent e) { 541 setValue((double) slider.getValue() / factor); 542 } 543 }); 544 popup.add(slider); 545 546 } 547 548 protected abstract void setValue(double value); 549 550 protected abstract double getValue(); 551 552 protected abstract SideButton getCorrespondingSideButton(); 553 554 @Override 555 public void actionPerformed(ActionEvent e) { 556 final SideButton sideButton = getCorrespondingSideButton(); 557 slider.setValue((int) (getValue() * factor)); 558 if (e.getSource() == sideButton) { 559 popup.show(sideButton, 0, sideButton.getHeight()); 560 } else { 561 // Action can be trigger either by opacity button or by popup menu (in case toggle buttons are hidden). 562 // In that case, show it in the middle of screen (because opacityButton is not visible) 563 popup.show(Main.parent, Main.parent.getWidth() / 2, (Main.parent.getHeight() - popup.getHeight()) / 2); 564 } 565 } 566 567 @Override 568 public Component createMenuComponent() { 569 return new JMenuItem(this); 570 } 571 572 } 573 574 /** 515 575 * Action which allows to change the opacity of one or more layers. 516 576 */ 517 public final class LayerOpacityAction extends Abstract Action implements IEnabledStateUpdating, LayerAction {577 public final class LayerOpacityAction extends AbstractLayerPropertySliderAction { 518 578 private transient Layer layer; 519 private JPopupMenu popup;520 private JSlider slider = new JSlider(JSlider.VERTICAL);521 579 522 580 /** … … 529 587 public LayerOpacityAction(Layer layer) { 530 588 this(); 531 putValue(NAME, tr("Opacity"));532 589 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 533 590 this.layer = layer; … … 541 598 */ 542 599 public LayerOpacityAction() { 543 putValue(NAME, tr("Opacity"));600 super(tr("Opacity"), 100); 544 601 putValue(SHORT_DESCRIPTION, tr("Adjust opacity of the layer.")); 545 602 putValue(SMALL_ICON, ImageProvider.get("dialogs/layerlist", "transparency")); 546 updateEnabledState(); 547 548 popup = new JPopupMenu(); 549 slider.addChangeListener(new ChangeListener() { 550 @Override 551 public void stateChanged(ChangeEvent e) { 552 setOpacity((double) slider.getValue()/100); 553 } 554 }); 555 popup.add(slider); 556 } 557 558 private void setOpacity(double value) { 603 } 604 605 @Override 606 protected void setValue(double value) { 559 607 if (!isEnabled()) return; 560 608 if (layer != null) { … … 567 615 } 568 616 569 private double getOpacity() { 617 @Override 618 protected double getValue() { 570 619 if (layer != null) 571 620 return layer.getOpacity(); … … 581 630 582 631 @Override 583 public void actionPerformed(ActionEvent e) { 584 slider.setValue((int) Math.round(getOpacity()*100)); 585 if (e.getSource() == opacityButton) { 586 popup.show(opacityButton, 0, opacityButton.getHeight()); 587 } else { 588 // Action can be trigger either by opacity button or by popup menu (in case toggle buttons are hidden). 589 // In that case, show it in the middle of screen (because opacityButton is not visible) 590 popup.show(Main.parent, Main.parent.getWidth() / 2, (Main.parent.getHeight() - popup.getHeight()) / 2); 591 } 632 protected SideButton getCorrespondingSideButton() { 633 return opacityButton; 592 634 } 593 635 … … 602 644 603 645 @Override 604 public Component createMenuComponent() {605 return new JMenuItem(this);606 }607 608 @Override609 646 public boolean supportLayers(List<Layer> layers) { 610 647 return true; 611 648 } 612 613 @Override 614 public boolean equals(Object obj) { 615 return obj instanceof LayerOpacityAction; 616 } 617 618 @Override 619 public int hashCode() { 620 return getClass().hashCode(); 649 } 650 651 /** 652 * Action which allows to change the gamma of one imagery layer. 653 */ 654 public final class LayerGammaAction extends AbstractLayerPropertySliderAction { 655 656 public LayerGammaAction() { 657 super(tr("Gamma"), 50); 658 putValue(SHORT_DESCRIPTION, tr("Adjust gamma value of the layer.")); 659 putValue(SMALL_ICON, ImageProvider.get("dialogs/layerlist", "gamma")); 660 } 661 662 @Override 663 protected void setValue(double value) { 664 for (ImageryLayer imageryLayer : Utils.filteredCollection(model.getSelectedLayers(), ImageryLayer.class)) { 665 imageryLayer.setGamma(value); 666 } 667 } 668 669 @Override 670 protected double getValue() { 671 return Utils.filteredCollection(model.getSelectedLayers(), ImageryLayer.class).iterator().next().getGamma(); 672 } 673 674 @Override 675 protected SideButton getCorrespondingSideButton() { 676 return gammaButton; 677 } 678 679 @Override 680 public void updateEnabledState() { 681 setEnabled(!Utils.filteredCollection(model.getSelectedLayers(), ImageryLayer.class).isEmpty()); 682 } 683 684 @Override 685 public boolean supportLayers(List<Layer> layers) { 686 return !Utils.filteredCollection(layers, ImageryLayer.class).isEmpty(); 621 687 } 622 688 } -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r8723 r8729 245 245 } 246 246 247 @Override 248 public void setGamma(double gamma) { 249 super.setGamma(gamma); 250 redraw(); 251 } 252 247 253 /** 248 254 * Marks layer as needing redraw on offset change -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r8723 r8729 20 20 import java.awt.image.ConvolveOp; 21 21 import java.awt.image.Kernel; 22 import java.awt.image.LookupOp; 23 import java.awt.image.ShortLookupTable; 22 24 import java.text.AttributedCharacterIterator; 23 25 import java.text.AttributedString; … … 75 77 protected double dy = 0.0; 76 78 79 protected GammaImageProcessor gammaImageProcessor = new GammaImageProcessor(); 80 77 81 private final ImageryAdjustAction adjustAction = new ImageryAdjustAction(this); 78 82 … … 92 96 } 93 97 addImageProcessor(createSharpener(PROP_SHARPEN_LEVEL.get())); 98 addImageProcessor(gammaImageProcessor); 94 99 } 95 100 … … 247 252 BufferedImageOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); 248 253 return createImageProcessor(op, false); 254 } 255 256 /** 257 * An image processor which adjusts the gamma value of an image. 258 */ 259 public static class GammaImageProcessor implements ImageProcessor { 260 private double gamma = 1; 261 final short[] gammaChange = new short[256]; 262 private LookupOp op3 = new LookupOp(new ShortLookupTable(0, new short[][]{gammaChange, gammaChange, gammaChange}), null); 263 private LookupOp op4 = new LookupOp(new ShortLookupTable(0, new short[][]{gammaChange, gammaChange, gammaChange, gammaChange}), null); 264 265 /** 266 * Returns the currently set gamma value. 267 */ 268 public double getGamma() { 269 return gamma; 270 } 271 272 /** 273 * Sets a new gamma value, {@code 1} stands for no correction. 274 */ 275 public void setGamma(double gamma) { 276 this.gamma = gamma; 277 for (int i = 0; i < 256; i++) { 278 gammaChange[i] = (short) (255 * Math.pow(i / 255., gamma)); 279 } 280 } 281 282 private LookupOp getOp(int bands) { 283 if (gamma == 1) { 284 return null; 285 } else if (bands == 3) { 286 return op3; 287 } else if (bands == 4) { 288 return op4; 289 } else { 290 return null; 291 } 292 } 293 294 @Override 295 public BufferedImage process(BufferedImage image) { 296 final LookupOp op = getOp(image.getRaster().getNumBands()); 297 final BufferedImage to = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); 298 return op == null ? image : op.filter(image, to); 299 } 300 } 301 302 /** 303 * Returns the currently set gamma value. 304 */ 305 public double getGamma() { 306 return gammaImageProcessor.getGamma(); 307 } 308 309 /** 310 * Sets a new gamma value, {@code 1} stands for no correction. 311 */ 312 public void setGamma(double gamma) { 313 gammaImageProcessor.setGamma(gamma); 249 314 } 250 315
Note:
See TracChangeset
for help on using the changeset viewer.