Changeset 8625 in josm for trunk


Ignore:
Timestamp:
2015-07-27T16:45:58+02:00 (9 years ago)
Author:
bastiK
Message:

applied #11713 - JOSM raster layers filters plugin development (patch by Nipel-Crumple, slightly modified)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
5 edited

Legend:

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

    r8615 r8625  
    11521152        if (evt.getPropertyName().equals(Layer.VISIBLE_PROP)) {
    11531153            repaint();
    1154         } else if (evt.getPropertyName().equals(Layer.OPACITY_PROP)) {
     1154        } else if (evt.getPropertyName().equals(Layer.OPACITY_PROP) ||
     1155                evt.getPropertyName().equals(Layer.FILTER_STATE_PROP)) {
    11551156            Layer l = (Layer) evt.getSource();
    11561157            if (l.isVisible()) {
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r8620 r8625  
    1717import java.awt.event.MouseAdapter;
    1818import java.awt.event.MouseEvent;
     19import java.awt.image.BufferedImage;
    1920import java.awt.image.ImageObserver;
    2021import java.io.File;
     
    10171018                continue;
    10181019            }
     1020
     1021            // applying all filters to this layer
     1022            img = applyImageProcessors((BufferedImage) img);
     1023
    10191024            Rectangle sourceRect = tileToRect(tile);
    10201025            if (borderRect != null && !sourceRect.intersects(borderRect)) {
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r8568 r8625  
    2222import java.text.AttributedCharacterIterator;
    2323import java.text.AttributedString;
     24import java.util.ArrayList;
    2425import java.util.Hashtable;
    2526import java.util.List;
     
    5556    public static final IntegerProperty PROP_FADE_AMOUNT = new IntegerProperty("imagery.fade_amount", 0);
    5657    public static final IntegerProperty PROP_SHARPEN_LEVEL = new IntegerProperty("imagery.sharpen_level", 0);
     58
     59    private final List<ImageProcessor> imageProcessors = new ArrayList<>();
    5760
    5861    public static Color getFadeColor() {
     
    249252        BufferedImageOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    250253        return op.filter(tmp, null);
     254    }
     255
     256    /**
     257     * This method adds the {@link ImageProcessor} to this Layer
     258     *
     259     * @param processor that processes the image
     260     *
     261     * @return true if processor was added, false otherwise
     262     */
     263    public boolean addImageProcessor(ImageProcessor processor) {
     264        return imageProcessors.add(processor);
     265    }
     266
     267    /**
     268     * This method removes given {@link ImageProcessor} from this layer
     269     *
     270     * @param processor which is needed to be removed
     271     *
     272     * @return true if processor was removed
     273     */
     274    public boolean removeImageProcessor(ImageProcessor processor) {
     275        return imageProcessors.remove(processor);
     276    }
     277
     278    /**
     279     * This method gets all {@link ImageProcessor}s of the layer
     280     *
     281     * @return list of image processors without removed one
     282     */
     283    public List<ImageProcessor> getImageProcessors() {
     284        return imageProcessors;
     285    }
     286
     287    /**
     288     * Applies all the chosen {@link ImageProcessor}s to the image
     289     *
     290     * @param img - image which should be changed
     291     *
     292     * @return the new changed image
     293     */
     294    public BufferedImage applyImageProcessors(BufferedImage img) {
     295        for (ImageProcessor processor : imageProcessors) {
     296            img = processor.process(img);
     297        }
     298        return img;
    251299    }
    252300
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r8542 r8625  
    8686    public static final String OPACITY_PROP = Layer.class.getName() + ".opacity";
    8787    public static final String NAME_PROP = Layer.class.getName() + ".name";
     88    public static final String FILTER_STATE_PROP = Layer.class.getName() + ".filterstate";
    8889
    8990    public static final int ICON_SIZE = 16;
     
    314315
    315316    /**
     317     * Sets new state to the layer after applying {@link ImageProcessor}.
     318     */
     319    public void setFilterStateChanged() {
     320        fireFilterStateChanged();
     321    }
     322
     323    /**
    316324     * Toggles the visibility state of this layer.
    317325     */
     
    356364    protected void fireOpacityChanged(double oldValue, double newValue) {
    357365        propertyChangeSupport.firePropertyChange(OPACITY_PROP, oldValue, newValue);
     366    }
     367
     368    /**
     369     * fires a property change for the property {@link #FILTER_STATE_PROP}.
     370     */
     371    protected void fireFilterStateChanged() {
     372        propertyChangeSupport.firePropertyChange(FILTER_STATE_PROP, null, null);
    358373    }
    359374
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r8620 r8625  
    6464     * Register a session layer exporter.
    6565     *
    66      * The exporter class must have an one-argument constructor with layerClass as formal parameter type.
     66     * The exporter class must have a one-argument constructor with layerClass as formal parameter type.
    6767     */
    6868    public static void registerSessionLayerExporter(Class<? extends Layer> layerClass, Class<? extends SessionLayerExporter> exporter) {
     
    9393     * Constructs a new {@code SessionWriter}.
    9494     * @param layers The ordered list of layers to save
    95      * @param active The index of active layer in {@code layers} (starts to 0). Ignored if set to -1
     95     * @param active The index of active layer in {@code layers} (starts at 0). Ignored if set to -1
    9696     * @param exporters The exporters to use to save layers
    9797     * @param zip {@code true} if a joz archive has to be created, {@code false otherwise}
Note: See TracChangeset for help on using the changeset viewer.