Ticket #11713: raster_filters.diff

File raster_filters.diff, 6.5 KB (added by Nipel-Crumple, 9 years ago)
  • src/org/openstreetmap/josm/gui/MapView.java

     
    11581158                changedLayer = l;
    11591159                repaint();
    11601160            }
     1161        } else if (evt.getPropertyName().equals(Layer.FILTER_STATE_PROP)){
     1162            Layer l = (Layer) evt.getSource();
     1163            if (l.isVisible()) {
     1164                changedLayer = l;
     1165                repaint();
     1166            }
    11611167        } else if (evt.getPropertyName().equals(OsmDataLayer.REQUIRES_SAVE_TO_DISK_PROP)
    11621168                || evt.getPropertyName().equals(OsmDataLayer.REQUIRES_UPLOAD_TO_SERVER_PROP)) {
    11631169            OsmDataLayer layer = (OsmDataLayer) evt.getSource();
  • src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

     
    1616import java.awt.event.ActionEvent;
    1717import java.awt.event.MouseAdapter;
    1818import java.awt.event.MouseEvent;
     19import java.awt.image.BufferedImage;
    1920import java.awt.image.ImageObserver;
    2021import java.io.File;
    2122import java.io.IOException;
     
    985986                missedTiles.add(tile);
    986987                continue;
    987988            }
     989
     990            // applying all filters to this layer
     991            img = applyImageProcessors((BufferedImage) img);
     992
    988993            Rectangle sourceRect = tileToRect(tile);
    989994            if (borderRect != null && !sourceRect.intersects(borderRect)) {
    990995                continue;
  • src/org/openstreetmap/josm/gui/layer/ImageProcessor.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui.layer;
     3
     4import java.awt.image.BufferedImage;
     5
     6/**
     7 * This interface was created for processing {@link ImageryLayer}s
     8 * following the rules of created image processors
     9 *
     10 * @author Nipel-Crumple
     11 *
     12 * @since 8614
     13 *
     14 */
     15public interface ImageProcessor {
     16
     17    /**
     18     * This method should process given image according to image processors
     19     * which is contained in the {@link Layer}
     20     *
     21     * @param image that should be processed
     22     *
     23     * @return processed image
     24     */
     25    public BufferedImage process(BufferedImage image);
     26
     27}
  • src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

     
    2121import java.awt.image.Kernel;
    2222import java.text.AttributedCharacterIterator;
    2323import java.text.AttributedString;
     24import java.util.ArrayList;
    2425import java.util.Hashtable;
    2526import java.util.List;
    2627import java.util.Map;
     
    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);
    5758
     59    private final List<ImageProcessor> imageProcessors = new ArrayList<>();
     60
    5861    public static Color getFadeColor() {
    5962        return PROP_FADE_COLOR.get();
    6063    }
     
    251254    }
    252255
    253256    /**
     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     * @since 8614
     264     */
     265    public boolean addImageProcessor(ImageProcessor processor) {
     266        return imageProcessors.add(processor);
     267    }
     268
     269    /**
     270     * This method removes given {@link ImageProcessor} from this layer
     271     *
     272     * @param processor which is needed to be removed
     273     *
     274     * @return true if processor was removed
     275     *
     276     * @since 8614
     277     */
     278    public boolean removeImageProcessor(ImageProcessor processor) {
     279        return imageProcessors.remove(processor);
     280    }
     281
     282    /**
     283     * This method gets all {@link ImageProcessor}s of the layer
     284     *
     285     * @return list of image processors without removed one
     286     *
     287     * @since 8614
     288     */
     289    public List<ImageProcessor> getImageProcessors() {
     290        return imageProcessors;
     291    }
     292
     293    /**
     294     * Applies all the chosen {@link ImageProcessor}s to the image
     295     *
     296     * @param img - image which should be changed
     297     *
     298     * @return the new changed image
     299     *
     300     * @since 8614
     301     */
     302    public BufferedImage applyImageProcessors(BufferedImage img) {
     303        for (ImageProcessor processor : imageProcessors) {
     304            img = processor.process(img);
     305        }
     306        return img;
     307    }
     308
     309    /**
    254310     * Draws a red error tile when imagery tile cannot be fetched.
    255311     * @param img The buffered image
    256312     * @param message Additional error message to display
  • src/org/openstreetmap/josm/gui/layer/Layer.java

     
    8585    public static final String VISIBLE_PROP = Layer.class.getName() + ".visible";
    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;
    9091
     
    313314    }
    314315
    315316    /**
     317     * Sets new state to the layer after applying {@link ImageProcessor}
     318     *
     319     * @since 8614
     320     */
     321    public void setFilterStateChanged() {
     322        fireFilterStateChanged();
     323    }
     324
     325    /**
    316326     * Toggles the visibility state of this layer.
    317327     */
    318328    public void toggleVisible() {
     
    358368    }
    359369
    360370    /**
     371     * fires a property change for the property {@link #FILTER_STATE_PROP}
     372     *
     373     */
     374    protected void fireFilterStateChanged() {
     375        propertyChangeSupport.firePropertyChange(FILTER_STATE_PROP, null, null);
     376    }
     377
     378    /**
    361379     * Check changed status of layer
    362380     *
    363381     * @return True if layer was changed since last paint