Changeset 19417 in osm


Ignore:
Timestamp:
2010-01-12T21:26:57+01:00 (15 years ago)
Author:
jttt
Message:

Cleanup

Location:
applications/editors/josm/plugins/wmsplugin
Files:
1 added
7 edited

Legend:

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

    r18761 r19417  
    11package wmsplugin;
    22
    3 import java.awt.Color;
    43import java.awt.Dimension;
    54import java.awt.Graphics;
     
    1918
    2019public class GeorefImage implements Serializable {
    21     public BufferedImage image = null;
    22     private Image reImg = null;
    23     private Dimension reImgHash = new Dimension(0, 0);
    24     public EastNorth min, max;
    25     public boolean downloadingStarted;
    26     public boolean failed = false;
     20        public BufferedImage image = null;
     21        private Image reImg = null;
     22        private Dimension reImgHash = new Dimension(0, 0);
     23        public EastNorth min, max;
     24        public boolean downloadingStarted;
     25        public boolean failed = false;
    2726
    28     public GeorefImage(boolean downloadingStarted) {
    29         this.downloadingStarted = downloadingStarted;
    30     }
     27        public GeorefImage(boolean downloadingStarted) {
     28                this.downloadingStarted = downloadingStarted;
     29        }
    3130
    32     public boolean contains(EastNorth en, double dx, double dy) {
    33         return min.east()+dx <= en.east() && en.east() <= max.east()+dx
    34             && min.north()+dy <= en.north() && en.north() <= max.north()+dy;
    35     }
     31        public boolean contains(EastNorth en, double dx, double dy) {
     32                return min.east()+dx <= en.east() && en.east() <= max.east()+dx
     33                && min.north()+dy <= en.north() && en.north() <= max.north()+dy;
     34        }
    3635
    37     public boolean isVisible(NavigatableComponent nc, double dx, double dy) {
    38         EastNorth mi = new EastNorth(min.east()+dx, min.north()+dy);
    39         EastNorth ma = new EastNorth(max.east()+dx, max.north()+dy);
    40         Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma);
    41         Graphics g = nc.getGraphics();
     36        public boolean isVisible(NavigatableComponent nc, double dx, double dy) {
     37                EastNorth mi = new EastNorth(min.east()+dx, min.north()+dy);
     38                EastNorth ma = new EastNorth(max.east()+dx, max.north()+dy);
     39                Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma);
     40                Graphics g = nc.getGraphics();
    4241
    43         return (g.hitClip(minPt.x, maxPt.y,
    44                 maxPt.x - minPt.x, minPt.y - maxPt.y));
    45     }
     42                return (g.hitClip(minPt.x, maxPt.y,
     43                                maxPt.x - minPt.x, minPt.y - maxPt.y));
     44        }
    4645
    47     public boolean paint(Graphics g, NavigatableComponent nc, double dx, double dy) {
    48         if (image == null || min == null || max == null) return false;
     46        public boolean paint(Graphics g, NavigatableComponent nc, double dx, double dy) {
     47                if (image == null || min == null || max == null) return false;
    4948
    50         EastNorth mi = new EastNorth(min.east()+dx, min.north()+dy);
    51         EastNorth ma = new EastNorth(max.east()+dx, max.north()+dy);
    52         Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma);
     49                EastNorth mi = new EastNorth(min.east()+dx, min.north()+dy);
     50                EastNorth ma = new EastNorth(max.east()+dx, max.north()+dy);
     51                Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma);
    5352
    54         if(!isVisible(nc, dx, dy)){
    55             return false;
    56         }
     53                if(!isVisible(nc, dx, dy)){
     54                        return false;
     55                }
    5756
    58         // Width and height flicker about 2 pixels due to rounding errors, typically only 1
    59         int width = Math.abs(maxPt.x-minPt.x);
    60         int height = Math.abs(minPt.y-maxPt.y);
    61         int diffx, diffy;
    62         try {
    63             diffx = reImgHash.width - width;
    64             diffy = reImgHash.height - height;
    65         } catch(Exception e) {
    66             reImgHash = new Dimension(0, 0);
    67             diffx = 99;
    68             diffy = 99;
    69         }
    70         // This happens if you zoom outside the world
    71         if(width == 0 || height == 0)
    72             return false;
     57                // Width and height flicker about 2 pixels due to rounding errors, typically only 1
     58                int width = Math.abs(maxPt.x-minPt.x);
     59                int height = Math.abs(minPt.y-maxPt.y);
     60                int diffx, diffy;
    7361
    74         // We still need to re-render if the requested size is larger (otherwise we'll have black lines)
    75         // If it's only up to two pixels smaller, just draw the old image, the errors are minimal
    76         // but the performance improvements when moving are huge
    77         // Zooming is still slow because the images need to be resized
    78         if(diffx >= 0 && diffx <= 2 && diffy >= 0 && diffy <= 2 && reImg != null) {
    79             /*g.setColor(Color.RED);
     62                diffx = reImgHash.width - width;
     63                diffy = reImgHash.height - height;
     64                // This happens if you zoom outside the world
     65                if(width == 0 || height == 0)
     66                        return false;
     67
     68                // We still need to re-render if the requested size is larger (otherwise we'll have black lines)
     69                // If it's only up to two pixels smaller, just draw the old image, the errors are minimal
     70                // but the performance improvements when moving are huge
     71                // Zooming is still slow because the images need to be resized
     72                if(diffx >= 0 && diffx <= 2 && diffy >= 0 && diffy <= 2 && reImg != null) {
     73                        /*g.setColor(Color.RED);
    8074              g.drawRect(minPt.x, minPt.y-height, width, height);*/
    81             g.drawImage(reImg, minPt.x, maxPt.y, null);
    82             return true;
    83         }
     75                        g.drawImage(reImg, minPt.x, maxPt.y, null);
     76                        return true;
     77                }
    8478
    85         boolean alphaChannel = Main.pref.getBoolean("wmsplugin.alpha_channel");
     79                boolean alphaChannel = Main.pref.getBoolean("wmsplugin.alpha_channel");
    8680
    87         try {
    88             if(reImg != null) reImg.flush();
    89             long freeMem = Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory();
    90             //System.out.println("Free Memory:           "+ (freeMem/1024/1024) +" MB");
    91             // Notice that this value can get negative due to integer overflows
    92             //System.out.println("Img Size:              "+ (width*height*3/1024/1024) +" MB");
     81                try {
     82                        if(reImg != null) reImg.flush();
     83                        long freeMem = Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory();
     84                        //System.out.println("Free Memory:           "+ (freeMem/1024/1024) +" MB");
     85                        // Notice that this value can get negative due to integer overflows
     86                        //System.out.println("Img Size:              "+ (width*height*3/1024/1024) +" MB");
    9387
    94             int multipl = alphaChannel ? 4 : 3;
    95             // This happens when requesting images while zoomed out and then zooming in
    96             // Storing images this large in memory will certainly hang up JOSM. Luckily
    97             // traditional rendering is as fast at these zoom levels, so it's no loss.
    98             // Also prevent caching if we're out of memory soon
    99             if(width > 2000 || height > 2000 || width*height*multipl > freeMem) {
    100                 fallbackDraw(g, image, minPt, maxPt);
    101             } else {
    102                 // We haven't got a saved resized copy, so resize and cache it
    103                 reImg = new BufferedImage(width, height,
    104                     alphaChannel
    105                         ? BufferedImage.TYPE_INT_ARGB
    106                         : BufferedImage.TYPE_3BYTE_BGR  // This removes alpha
    107                     );
    108                 reImg.getGraphics().drawImage(image,
    109                     0, 0, width, height, // dest
    110                     0, 0, image.getWidth(null), image.getHeight(null), // src
    111                     null);
    112                 reImg.getGraphics().dispose();
     88                        int multipl = alphaChannel ? 4 : 3;
     89                        // This happens when requesting images while zoomed out and then zooming in
     90                        // Storing images this large in memory will certainly hang up JOSM. Luckily
     91                        // traditional rendering is as fast at these zoom levels, so it's no loss.
     92                        // Also prevent caching if we're out of memory soon
     93                        if(width > 2000 || height > 2000 || width*height*multipl > freeMem) {
     94                                fallbackDraw(g, image, minPt, maxPt);
     95                        } else {
     96                                // We haven't got a saved resized copy, so resize and cache it
     97                                reImg = new BufferedImage(width, height, alphaChannel?BufferedImage.TYPE_INT_ARGB:BufferedImage.TYPE_3BYTE_BGR);
     98                                reImg.getGraphics().drawImage(image,
     99                                                0, 0, width, height, // dest
     100                                                0, 0, image.getWidth(null), image.getHeight(null), // src
     101                                                null);
     102                                reImg.getGraphics().dispose();
    113103
    114                 reImgHash.setSize(width, height);
    115                 /*g.setColor(Color.RED);
     104                                reImgHash.setSize(width, height);
     105                                /*g.setColor(Color.RED);
    116106                  g.drawRect(minPt.x, minPt.y-height, width, height);*/
    117                 g.drawImage(reImg, minPt.x, maxPt.y, null);
    118             }
    119         } catch(Exception e) {
    120             fallbackDraw(g, image, minPt, maxPt);
    121         }
    122         return true;
    123     }
     107                                g.drawImage(reImg, minPt.x, maxPt.y, null);
     108                        }
     109                } catch(Exception e) {
     110                        fallbackDraw(g, image, minPt, maxPt);
     111                }
     112                return true;
     113        }
    124114
    125     private void fallbackDraw(Graphics g, Image img, Point min, Point max) {
    126         if(reImg != null) reImg.flush();
    127         reImg = null;
    128         g.drawImage(img,
    129             min.x, max.y, max.x, min.y, // dest
    130             0, 0, img.getWidth(null), img.getHeight(null), // src
    131             null);
    132     }
     115        private void fallbackDraw(Graphics g, Image img, Point min, Point max) {
     116                if(reImg != null) reImg.flush();
     117                reImg = null;
     118                g.drawImage(img,
     119                                min.x, max.y, max.x, min.y, // dest
     120                                0, 0, img.getWidth(null), img.getHeight(null), // src
     121                                null);
     122        }
    133123
    134     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    135         max = (EastNorth) in.readObject();
    136         min = (EastNorth) in.readObject();
    137         boolean hasImage = in.readBoolean();
    138         if (hasImage)
    139             image = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in));
    140         else {
    141             in.readObject(); // read null from input stream
    142             image = null;
    143         }
    144     }
     124        private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
     125                max = (EastNorth) in.readObject();
     126                min = (EastNorth) in.readObject();
     127                boolean hasImage = in.readBoolean();
     128                if (hasImage)
     129                        image = ImageIO.read(ImageIO.createImageInputStream(in));
     130                else {
     131                        in.readObject(); // read null from input stream
     132                        image = null;
     133                }
     134        }
    145135
    146     private void writeObject(ObjectOutputStream out) throws IOException {
    147         out.writeObject(max);
    148         out.writeObject(min);
    149         if(image == null) {
    150             out.writeBoolean(false);
    151             out.writeObject(null);
    152         } else {
    153             out.writeBoolean(true);
    154             ImageIO.write(image, "png", ImageIO.createImageOutputStream(out));
    155         }
    156     }
     136        private void writeObject(ObjectOutputStream out) throws IOException {
     137                out.writeObject(max);
     138                out.writeObject(min);
     139                if(image == null) {
     140                        out.writeBoolean(false);
     141                        out.writeObject(null);
     142                } else {
     143                        out.writeBoolean(true);
     144                        ImageIO.write(image, "png", ImageIO.createImageOutputStream(out));
     145                }
     146        }
    157147
    158     public void flushedResizedCachedInstance() {
    159         reImg = null;
    160     }
     148        public void flushedResizedCachedInstance() {
     149                reImg = null;
     150        }
    161151}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Map_Rectifier_WMSmenuAction.java

    r18761 r19417  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.awt.GridBagConstraints;
    56import java.awt.GridBagLayout;
    67import java.awt.Toolkit;
     
    3132     * Class that bundles all required information of a rectifier service
    3233     */
    33     public class rectifierService {
     34    public static class RectifierService {
    3435        private final String name;
    3536        private final String url;
     
    4546         * @param idValidator: regular expression that checks if a given ID is syntactically valid
    4647         */
    47         public rectifierService(String name, String url, String wmsUrl, String urlRegEx, String idValidator) {
     48        public RectifierService(String name, String url, String wmsUrl, String urlRegEx, String idValidator) {
    4849            this.name = name;
    4950            this.url = url;
     
    6162     * List of available rectifier services. May be extended from the outside
    6263     */
    63     public ArrayList<rectifierService> services = new ArrayList<rectifierService>();
     64    public ArrayList<RectifierService> services = new ArrayList<RectifierService>();
    6465
    6566    public Map_Rectifier_WMSmenuAction() {
     
    7677        // Add default services
    7778        services.add(
    78             new rectifierService("Metacarta Map Rectifier",
     79            new RectifierService("Metacarta Map Rectifier",
    7980                "http://labs.metacarta.com/rectifier/",
    8081                "http://labs.metacarta.com/rectifier/wms.cgi?id=__s__&srs=EPSG:4326"
     
    8990            // The RegEx already matches the new URL and old URLs will be forwarded
    9091            // to make the transition as smooth as possible for the users
    91             new rectifierService("Geothings Map Warper",
     92            new RectifierService("Geothings Map Warper",
    9293                "http://warper.geothings.net/",
    9394                "http://warper.geothings.net/maps/wms/__s__?request=GetMap&version=1.1.1"
     
    104105        // Clipboard content gets trimmed, so matching whitespace only ensures that this
    105106        // service will never be selected automatically.
    106         services.add(new rectifierService(tr("Custom WMS Link"), "", "", "^\\s+$", ""));
     107        services.add(new RectifierService(tr("Custom WMS Link"), "", "", "^\\s+$", ""));
    107108    }
    108109
     
    117118
    118119        JRadioButton firstBtn = null;
    119         for(rectifierService s : services) {
     120        for(RectifierService s : services) {
    120121            JRadioButton serviceBtn = new JRadioButton(s.name);
    121122            if(firstBtn == null)
     
    133134            if(!s.url.equals("")) {
    134135                panel.add(serviceBtn, GBC.std());
    135                 panel.add(new UrlLabel(s.url, tr("Visit Homepage")), GBC.eol().anchor(GBC.EAST));
     136                panel.add(new UrlLabel(s.url, tr("Visit Homepage")), GBC.eol().anchor(GridBagConstraints.EAST));
    136137            } else
    137                 panel.add(serviceBtn, GBC.eol().anchor(GBC.WEST));
     138                panel.add(serviceBtn, GBC.eol().anchor(GridBagConstraints.WEST));
    138139        }
    139140
     
    143144
    144145        panel.add(new JLabel(tr("WMS URL or Image ID:")), GBC.eol());
    145         panel.add(tfWmsUrl, GBC.eol().fill(GBC.HORIZONTAL));
     146        panel.add(tfWmsUrl, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    146147
    147148        ExtendedDialog diag = new ExtendedDialog(Main.parent,
     
    163164            String text = tfWmsUrl.getText().trim();
    164165            // Loop all services until we find the selected one
    165             for(rectifierService s : services) {
     166            for(RectifierService s : services) {
    166167                if(!s.isSelected())
    167168                    continue;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java

    r18761 r19417  
    1010import java.awt.event.MouseMotionListener;
    1111import java.util.List;
    12 import java.util.logging.Logger;
    1312
    1413import javax.swing.DefaultComboBoxModel;
     
    3231
    3332public class WMSAdjustAction extends MapMode implements MouseListener, MouseMotionListener{
    34     static private final Logger logger = Logger.getLogger(WMSAdjustAction.class.getName());
    35    
     33    //static private final Logger logger = Logger.getLogger(WMSAdjustAction.class.getName());
     34
    3635    GeorefImage selectedImage;
    3736    boolean mouseDown;
     
    4544    }
    4645
    47    
    48    
     46
     47
    4948    @Override public void enterMode() {
    50         super.enterMode();       
     49        super.enterMode();
    5150        if (!hasWMSLayersToAdjust()) {
    5251            warnNoWMSLayers();
     
    108107        prevEastNorth = null;
    109108    }
    110    
     109
    111110    @Override
    112111    public void mouseEntered(MouseEvent e) {
    113112    }
    114    
     113
    115114    @Override
    116115    public void mouseExited(MouseEvent e) {
    117116    }
    118    
     117
    119118    @Override
    120119    public void mouseMoved(MouseEvent e) {
     
    129128        return (l instanceof WMSLayer) && l.isVisible();
    130129    }
    131    
     130
    132131    /**
    133132    * the list cell renderer used to render layer list entries
    134     * 
     133    *
    135134    */
    136135   static public class LayerListCellRenderer extends DefaultListCellRenderer {
     
    158157
    159158   /**
    160     * Prompts the user with a list of WMS layers which can be adjusted 
    161     * 
    162     * @param adjustableLayers the list of adjustable layers 
    163     * @return  the selected layer; null, if no layer was selected 
     159    * Prompts the user with a list of WMS layers which can be adjusted
     160    *
     161    * @param adjustableLayers the list of adjustable layers
     162    * @return  the selected layer; null, if no layer was selected
    164163    */
    165164   protected Layer askAdjustLayer(List<? extends Layer> adjustableLayers) {
     
    168167       layerList.setModel(new DefaultComboBoxModel(adjustableLayers.toArray()));
    169168       layerList.setSelectedIndex(0);
    170    
     169
    171170       JPanel pnl = new JPanel();
    172171       pnl.setLayout(new GridBagLayout());
    173172       pnl.add(new JLabel(tr("Please select the WMS layer to adjust.")), GBC.eol());
    174173       pnl.add(layerList, GBC.eol());
    175    
     174
    176175       ExtendedDialog diag = new ExtendedDialog(
    177                Main.parent, 
    178                tr("Select WMS layer"), 
     176               Main.parent,
     177               tr("Select WMS layer"),
    179178               new String[] { tr("Start adjusting"),tr("Cancel") }
    180179               );
     
    190189
    191190   /**
    192     * Displays a warning message if there are no WMS layers to adjust 
    193     * 
     191    * Displays a warning message if there are no WMS layers to adjust
     192    *
    194193    */
    195194   protected void warnNoWMSLayers() {
     
    197196               Main.parent,
    198197               tr("There are currently no WMS layer to adjust."),
    199                tr("No layers to adjust"), 
     198               tr("No layers to adjust"),
    200199               JOptionPane.WARNING_MESSAGE
    201200       );
    202201   }
    203    
     202
    204203   /**
    205     * Replies true if there is at least one WMS layer 
    206     * 
     204    * Replies true if there is at least one WMS layer
     205    *
    207206    * @return true if there is at least one WMS layer
    208207    */
     
    216215    protected void updateEnabledState() {
    217216        setEnabled(hasWMSLayersToAdjust());
    218     }   
     217    }
    219218}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r19240 r19417  
    3737        return url != null && url.contains("{") && url.contains("}");
    3838    }
    39    
     39
    4040    protected String baseURL;
    4141    private final boolean urlWithPatterns;
     
    4848    }
    4949
    50     public void run() {
     50    @Override
     51        public void run() {
    5152        attempt();
    5253        mv.repaint();
     
    152153    }
    153154
    154     public boolean loadFromCache(){
     155    @Override
     156        public boolean loadFromCache(){
    155157        URL url = null;
    156158        try{
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSInfo.java

    r15858 r19417  
    3333    public int compareTo(WMSInfo in)
    3434    {
    35         Integer i = name.compareTo(in.name);
     35        int i = name.compareTo(in.name);
    3636        if(i == 0)
    3737            i = url.compareTo(in.url);
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r19240 r19417  
    5151    protected String resolution;
    5252    protected boolean stopAfterPaint = false;
    53     protected int ImageSize = 500;
     53    protected int imageSize = 500;
    5454    protected int dax = 10;
    5555    protected int day = 10;
     
    168168    private ProjectionBounds XYtoBounds (int x, int y) {
    169169        return new ProjectionBounds(
    170                 new EastNorth(      x * ImageSize / pixelPerDegree,       y * ImageSize / pixelPerDegree),
    171                 new EastNorth((x + 1) * ImageSize / pixelPerDegree, (y + 1) * ImageSize / pixelPerDegree));
     170                new EastNorth(      x * imageSize / pixelPerDegree,       y * imageSize / pixelPerDegree),
     171                new EastNorth((x + 1) * imageSize / pixelPerDegree, (y + 1) * imageSize / pixelPerDegree));
    172172    }
    173173
     
    228228            return;
    229229        ProjectionBounds bounds = mv.getProjectionBounds();
    230         int bminx= (int)Math.floor (((bounds.min.east() - dx) * pixelPerDegree) / ImageSize );
    231         int bminy= (int)Math.floor (((bounds.min.north() - dy) * pixelPerDegree) / ImageSize );
    232         int bmaxx= (int)Math.ceil  (((bounds.max.east() - dx) * pixelPerDegree) / ImageSize );
    233         int bmaxy= (int)Math.ceil  (((bounds.max.north() - dy) * pixelPerDegree) / ImageSize );
     230        int bminx= (int)Math.floor (((bounds.min.east() - dx) * pixelPerDegree) / imageSize );
     231        int bminy= (int)Math.floor (((bounds.min.north() - dy) * pixelPerDegree) / imageSize );
     232        int bmaxx= (int)Math.ceil  (((bounds.max.east() - dx) * pixelPerDegree) / imageSize );
     233        int bmaxy= (int)Math.ceil  (((bounds.max.north() - dy) * pixelPerDegree) / imageSize );
    234234
    235235        if((bmaxx - bminx > dax) || (bmaxy - bminy > day)){
     
    385385                    oos.writeInt(dax);
    386386                    oos.writeInt(day);
    387                     oos.writeInt(ImageSize);
     387                    oos.writeInt(imageSize);
    388388                    oos.writeDouble(pixelPerDegree);
    389389                    oos.writeObject(getName());
     
    423423                dax = ois.readInt();
    424424                day = ois.readInt();
    425                 ImageSize = ois.readInt();
     425                imageSize = ois.readInt();
    426426                pixelPerDegree = ois.readDouble();
    427427                setName((String)ois.readObject());
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java

    r19306 r19417  
    11package wmsplugin;
    22
    3 import java.awt.BorderLayout;
    4 import java.awt.FlowLayout;
    5 import javax.swing.JCheckBox;
    6 import javax.swing.JSpinner;
    7 import javax.swing.SpinnerNumberModel;
    8 import org.openstreetmap.josm.Main;
    93import static org.openstreetmap.josm.tools.I18n.tr;
    104
    115import java.awt.Dimension;
    126import java.awt.FlowLayout;
     7import java.awt.GridBagConstraints;
    138import java.awt.GridBagLayout;
    149import java.awt.event.ActionEvent;
     
    1914import javax.swing.Box;
    2015import javax.swing.JButton;
     16import javax.swing.JCheckBox;
    2117import javax.swing.JComboBox;
    2218import javax.swing.JLabel;
     
    2420import javax.swing.JPanel;
    2521import javax.swing.JScrollPane;
     22import javax.swing.JSpinner;
    2623import javax.swing.JTable;
    2724import javax.swing.JTextField;
     25import javax.swing.SpinnerNumberModel;
    2826import javax.swing.table.DefaultTableModel;
    2927
    3028import org.openstreetmap.josm.Main;
    31 import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
    3229import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    3330import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
     
    4239    JSpinner spinEast;
    4340    JSpinner spinNorth;
    44    
     41
    4542    public void addGui(final PreferenceTabbedPane gui) {
    4643        JPanel p = gui.createPreferenceTab("wms", tr("WMS Plugin Preferences"), tr("Modify list of WMS servers displayed in the WMS plugin menu"));
     
    4946        final JTable list = new JTable(model);
    5047        JScrollPane scroll = new JScrollPane(list);
    51         p.add(scroll, GBC.eol().fill(GBC.BOTH));
     48        p.add(scroll, GBC.eol().fill(GridBagConstraints.BOTH));
    5249        scroll.setPreferredSize(new Dimension(200,200));
    5350
     
    8279                JTextField key = new JTextField(40);
    8380                JTextField value = new JTextField(40);
    84                 p.add(key, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
     81                p.add(key, GBC.eop().insets(5,0,0,0).fill(GridBagConstraints.HORIZONTAL));
    8582                p.add(new JLabel(tr("WMS URL")), GBC.std().insets(0,0,5,0));
    86                 p.add(value, GBC.eol().insets(5,0,0,0).fill(GBC.HORIZONTAL));
     83                p.add(value, GBC.eol().insets(5,0,0,0).fill(GridBagConstraints.HORIZONTAL));
    8784                int answer = JOptionPane.showConfirmDialog(
    88                         gui, p, 
    89                         tr("Enter a menu name and WMS URL"), 
     85                        gui, p,
     86                        tr("Enter a menu name and WMS URL"),
    9087                        JOptionPane.OK_CANCEL_OPTION,
    9188                        JOptionPane.QUESTION_MESSAGE);
     
    118115                if (lines.length == 0) {
    119116                    JOptionPane.showMessageDialog(
    120                             gui, 
     117                            gui,
    121118                            tr("Please select at least one row to copy."),
    122119                            tr("Information"),
     
    125122                    return;
    126123                }
    127                
     124
    128125                outer: for(int i = 0; i < lines.length; i++) {
    129126                    String c1 = modeldef.getValueAt(lines[i], 0).toString();
    130127                    String c2 = modeldef.getValueAt(lines[i], 1).toString();
    131                    
     128
    132129                    // Check if an entry with exactly the same values already
    133130                    // exists
    134131                    for(int j = 0; j < model.getRowCount(); j++) {
    135                         if(c1.equals(model.getValueAt(j, 0).toString()) 
     132                        if(c1.equals(model.getValueAt(j, 0).toString())
    136133                                && c2.equals(model.getValueAt(j, 1).toString())) {
    137134                            // Select the already existing row so the user has
     
    142139                        }
    143140                    }
    144                    
     141
    145142                    model.addRow(new String[] {c1, c2});
    146143                    int lastLine = model.getRowCount() - 1;
     
    152149
    153150        p.add(buttonPanel);
    154         p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
     151        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    155152        // Add default item list
    156         p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GBC.BOTH));       
    157        
     153        p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GridBagConstraints.BOTH));
     154
    158155        browser = new JComboBox(new String[]{
    159156        "webkit-image {0}",
     
    163160        browser.setEditable(true);
    164161        browser.setSelectedItem(Main.pref.get("wmsplugin.browser", "webkit-image {0}"));
    165         p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL));
     162        p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    166163        p.add(browser);
    167164
    168165
    169166        //Overlap
    170         p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
    171          
    172         overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.doOverlap ); 
    173         JLabel labelEast = new JLabel(tr("% of east:")); 
    174         JLabel labelNorth = new JLabel(tr("% of north:")); 
    175         spinEast = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapEast, 1, 50, 1)); 
    176         spinNorth = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapNorth, 1, 50, 1)); 
    177          
    178         JPanel overlapPanel = new JPanel(new FlowLayout()); 
    179         overlapPanel.add(overlapCheckBox); 
    180         overlapPanel.add(labelEast); 
    181         overlapPanel.add(spinEast); 
    182         overlapPanel.add(labelNorth); 
    183         overlapPanel.add(spinNorth); 
    184          
    185         p.add(overlapPanel);   
     167        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     168
     169        overlapCheckBox = new JCheckBox(tr("Overlap tiles"), WMSPlugin.doOverlap );
     170        JLabel labelEast = new JLabel(tr("% of east:"));
     171        JLabel labelNorth = new JLabel(tr("% of north:"));
     172        spinEast = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapEast, 1, 50, 1));
     173        spinNorth = new JSpinner(new SpinnerNumberModel(WMSPlugin.overlapNorth, 1, 50, 1));
     174
     175        JPanel overlapPanel = new JPanel(new FlowLayout());
     176        overlapPanel.add(overlapCheckBox);
     177        overlapPanel.add(labelEast);
     178        overlapPanel.add(spinEast);
     179        overlapPanel.add(labelNorth);
     180        overlapPanel.add(spinNorth);
     181
     182        p.add(overlapPanel);
    186183    }
    187184
     
    223220        if (change) WMSPlugin.refreshMenu();
    224221
    225         WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected(); 
    226         WMSPlugin.overlapEast = (Integer) spinEast.getModel().getValue(); 
    227         WMSPlugin.overlapNorth = (Integer) spinNorth.getModel().getValue(); 
    228          
    229         Main.pref.put("wmsplugin.url.overlap",    String.valueOf(WMSPlugin.doOverlap)); 
    230         Main.pref.put("wmsplugin.url.overlapEast", String.valueOf(WMSPlugin.overlapEast)); 
    231         Main.pref.put("wmsplugin.url.overlapNorth", String.valueOf(WMSPlugin.overlapNorth)); 
     222        WMSPlugin.doOverlap = overlapCheckBox.getModel().isSelected();
     223        WMSPlugin.overlapEast = (Integer) spinEast.getModel().getValue();
     224        WMSPlugin.overlapNorth = (Integer) spinNorth.getModel().getValue();
     225
     226        Main.pref.put("wmsplugin.url.overlap",    String.valueOf(WMSPlugin.doOverlap));
     227        Main.pref.put("wmsplugin.url.overlapEast", String.valueOf(WMSPlugin.overlapEast));
     228        Main.pref.put("wmsplugin.url.overlapNorth", String.valueOf(WMSPlugin.overlapNorth));
    232229
    233230        Main.pref.put("wmsplugin.browser", browser.getEditor().getItem().toString());
Note: See TracChangeset for help on using the changeset viewer.