Ignore:
Timestamp:
2009-02-10T20:57:50+01:00 (16 years ago)
Author:
hampelratte
Message:

added menu item to toggle the alpha channel of the wms images

Location:
applications/editors/josm/plugins/wmsplugin/src/wmsplugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java

    r13645 r13652  
    33import java.awt.Dimension;
    44import java.awt.Graphics;
     5import java.awt.Image;
    56import java.awt.Point;
     7import java.awt.Toolkit;
    68import java.awt.image.BufferedImage;
     9import java.awt.image.FilteredImageSource;
     10import java.awt.image.ImageProducer;
     11import java.awt.image.RGBImageFilter;
    712import java.io.IOException;
    813import java.io.ObjectInputStream;
     
    1217import javax.imageio.ImageIO;
    1318
     19import org.openstreetmap.josm.Main;
    1420import org.openstreetmap.josm.data.coor.EastNorth;
    1521import org.openstreetmap.josm.gui.NavigatableComponent;
     
    6975        }
    7076
     77        boolean alphaChannel = Main.pref.getBoolean("wmsplugin.alpha_channel");
     78        Image ppImg = image;
     79        if(!alphaChannel) {
     80            // set alpha value to 255
     81            ppImg = clearAlpha(image);
     82        }
     83           
    7184        // We haven't got a saved resized copy, so resize and cache it       
    72         reImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    73         reImg.getGraphics().drawImage(image,
     85        reImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
     86        reImg.getGraphics().drawImage(ppImg,
    7487            0, 0, width, height, // dest
    75             0, 0, image.getWidth(), image.getHeight(), // src
     88            0, 0, ppImg.getWidth(null), ppImg.getHeight(null), // src
    7689            null);
    7790
     
    95108            ImageIO.write(image, "png", ImageIO.createImageOutputStream(out));
    96109    }
     110
     111    private Image clearAlpha(Image img) {
     112                ImageProducer ip = img.getSource();
     113                RGBImageFilter filter = new RGBImageFilter() {
     114                        public int filterRGB(int x, int y, int rgb) {
     115                                return rgb | 0xff000000;
     116                        }
     117                };
     118                ImageProducer filt_ip = new FilteredImageSource(ip, filter);
     119                Image out_img = Toolkit.getDefaultToolkit().createImage(filt_ip);
     120
     121                return out_img;
     122        }
    97123}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r13645 r13652  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.lang.Math;
    65import java.awt.Component;
    76import java.awt.Graphics;
     
    1312import java.io.ObjectInputStream;
    1413import java.io.ObjectOutputStream;
     14import java.util.concurrent.ExecutorService;
     15import java.util.concurrent.Executors;
    1516
    1617import javax.swing.AbstractAction;
    1718import javax.swing.Icon;
    1819import javax.swing.ImageIcon;
     20import javax.swing.JCheckBoxMenuItem;
    1921import javax.swing.JFileChooser;
    20 import javax.swing.JCheckBoxMenuItem;
    2122import javax.swing.JMenuItem;
    2223import javax.swing.JOptionPane;
     
    2627import org.openstreetmap.josm.Main;
    2728import org.openstreetmap.josm.actions.ExtensionFileFilter;
     29import org.openstreetmap.josm.data.Bounds;
     30import org.openstreetmap.josm.data.coor.EastNorth;
     31import org.openstreetmap.josm.data.coor.LatLon;
    2832import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    29 import org.openstreetmap.josm.data.Bounds;
    30 import org.openstreetmap.josm.data.coor.LatLon;
    3133import org.openstreetmap.josm.gui.MapView;
    32 import java.util.concurrent.ExecutorService;
    33 import java.util.concurrent.Executors;
    34 
    3534import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    3635import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    3736import org.openstreetmap.josm.gui.layer.Layer;
    3837import org.openstreetmap.josm.tools.ImageProvider;
    39 import org.openstreetmap.josm.data.coor.EastNorth;
    4038
    4139/**
     
    6159    protected GeorefImage[][] images = new GeorefImage[dax][day];
    6260    JCheckBoxMenuItem startstop = new JCheckBoxMenuItem(tr("Automatic downloading"), true);
    63 
     61    protected JCheckBoxMenuItem alphaChannel = new JCheckBoxMenuItem(new ToggleAlphaAction());
    6462    protected String baseURL;
    6563    protected final int serializeFormatVersion = 4;
     
    7573    public WMSLayer(String name, String baseURL) {
    7674        super(name);
     75        alphaChannel.setSelected(Main.pref.getBoolean("wmsplugin.alpha_channel"));
    7776        background = true; /* set global background variable */
    7877        initializeImages();
     
    8180        mv = Main.map.mapView;
    8281        getPPD();
    83 
     82       
    8483        executor = Executors.newFixedThreadPool(3);
    8584    }
     
    166165            return;
    167166        }
    168 
     167       
    169168        for(int x = bminx; x<bmaxx; ++x)
    170169            for(int y = bminy; y<bmaxy; ++y){
     
    203202                new JSeparator(),
    204203                startstop,
     204                alphaChannel,
    205205                new JMenuItem(new changeResolutionAction()),
    206206                new JMenuItem(new downloadAction()),
     
    237237            getPPD();
    238238            mv.repaint();
     239        }
     240    }
     241   
     242    public class ToggleAlphaAction extends AbstractAction {
     243        public ToggleAlphaAction() {
     244            super(tr("Alpha channel"));
     245        }
     246        public void actionPerformed(ActionEvent ev) {
     247            JCheckBoxMenuItem checkbox = (JCheckBoxMenuItem) ev.getSource();
     248            boolean alphaChannel = checkbox.isSelected();
     249            Main.pref.put("wmsplugin.alpha_channel", alphaChannel);
     250            Main.map.repaint();
    239251        }
    240252    }
Note: See TracChangeset for help on using the changeset viewer.