Changeset 2332 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-10-27T18:49:09+01:00 (15 years ago)
Author:
Gubaer
Message:

Some updates in download dialog and related

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java

    r2327 r2332  
    114114                    Main.parent,
    115115                    sb.toString(),
    116                     tr("Errors during Download"),
     116                    tr("Errors during download"),
    117117                    JOptionPane.ERROR_MESSAGE);
    118118            return;
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r2327 r2332  
    2525    private static DecimalFormat cDdFormatter = new DecimalFormat("###0.0000");
    2626
     27    /**
     28     * Replies true if lat is in the range [-90,90]
     29     *
     30     * @param lat the latitude
     31     * @return true if lat is in the range [-90,90]
     32     */
     33    public static boolean isValidLat(double lat) {
     34        return lat >= -90d && lat <= 90d;
     35    }
    2736
     37    /**
     38     * Replies true if lon is in the range [-180,180]
     39     *
     40     * @param lon the longitude
     41     * @return true if lon is in the range [-180,180]
     42     */
     43    public static boolean isValidLon(double lon) {
     44        return lon >= -180d && lon <= 180d;
     45    }
     46   
    2847    public static String dms(double pCoordinate) {
    2948
  • trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java

    r2327 r2332  
    1818
    1919import org.openstreetmap.josm.Main;
     20import org.openstreetmap.josm.data.Bounds;
    2021import org.openstreetmap.josm.data.Preferences;
    2122import org.openstreetmap.josm.gui.BookmarkList;
     
    100101    }
    101102
    102     public void boundingBoxChanged(DownloadDialog gui) {
    103         tempBookmark = new Preferences.Bookmark(gui.getSelectedDownloadArea());
     103   
     104    public void setDownloadArea(Bounds area) {
     105        if (area == null) return;
     106        tempBookmark = new Preferences.Bookmark(area);
    104107        bookmarks.clearSelection();
    105108    }
    106 
    107 
    108109}
  • trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java

    r2327 r2332  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Color;
    67import java.awt.Dimension;
    78import java.awt.GridBagLayout;
     9import java.awt.event.ActionEvent;
     10import java.awt.event.ActionListener;
    811import java.awt.event.FocusAdapter;
    912import java.awt.event.FocusEvent;
    10 import java.awt.event.FocusListener;
    11 
     13
     14import javax.swing.BorderFactory;
    1215import javax.swing.JLabel;
     16import javax.swing.JOptionPane;
    1317import javax.swing.JPanel;
    1418import javax.swing.JTextArea;
    1519import javax.swing.JTextField;
    16 import javax.swing.SwingUtilities;
     20import javax.swing.UIManager;
     21import javax.swing.border.Border;
    1722import javax.swing.event.DocumentEvent;
    1823import javax.swing.event.DocumentListener;
    19 
     24import javax.swing.text.JTextComponent;
     25
     26import org.openstreetmap.josm.Main;
    2027import org.openstreetmap.josm.data.Bounds;
    2128import org.openstreetmap.josm.data.coor.LatLon;
     
    3340public class BoundingBoxSelection implements DownloadSelection {
    3441
    35     private JTextField[] latlon = new JTextField[] {
    36             new JTextField(11),
    37             new JTextField(11),
    38             new JTextField(11),
    39             new JTextField(11) };
     42    private JTextField[] latlon = null;
    4043    final JTextArea osmUrl = new JTextArea();
    4144    final JTextArea showUrl = new JTextArea();
    4245
     46   
     47    protected void buildDownloadAreaInputFields() {
     48        latlon = new JTextField[4];
     49        for(int i=0; i< 4; i++) {
     50            latlon[i] = new JTextField(11);
     51            latlon[i].setMinimumSize(new Dimension(100,new JTextField().getMinimumSize().height));
     52            latlon[i].addFocusListener(new SelectAllOnFocusHandler(latlon[i]));
     53        }
     54        LatValueChecker latChecker = new LatValueChecker(latlon[0]);
     55        latlon[0].addFocusListener(latChecker);
     56        latlon[0].addActionListener(latChecker);
     57
     58        latChecker = new LatValueChecker(latlon[3]);
     59        latlon[2].addFocusListener(latChecker);
     60        latlon[2].addActionListener(latChecker);
     61       
     62        LonValueChecker lonChecker = new LonValueChecker(latlon[1]);
     63        latlon[1].addFocusListener(lonChecker);
     64        latlon[1].addActionListener(lonChecker);
     65
     66        lonChecker = new LonValueChecker(latlon[3]);
     67        latlon[3].addFocusListener(lonChecker);
     68        latlon[3].addActionListener(lonChecker);
     69       
     70    }
     71   
    4372    public void addGui(final DownloadDialog gui) {
    44 
     73        buildDownloadAreaInputFields();
    4574        JPanel dlg = new JPanel(new GridBagLayout());
    46 
    47         final FocusListener dialogUpdater = new FocusAdapter() {
    48             @Override public void focusLost(FocusEvent e) {
    49                 SwingUtilities.invokeLater(new Runnable() {
    50                     public void run() {
    51                         try {
    52                             double minlat = Double.parseDouble(latlon[0].getText());
    53                             double minlon = Double.parseDouble(latlon[1].getText());
    54                             double maxlat = Double.parseDouble(latlon[2].getText());
    55                             double maxlon = Double.parseDouble(latlon[3].getText());
    56                             Bounds b = new Bounds(minlat,minlon, maxlat,maxlon);
    57                             if (gui.getSelectedDownloadArea() == null) return;
    58                             if (gui.getSelectedDownloadArea() == null || !gui.getSelectedDownloadArea().equals(new Bounds(minlat,minlon, maxlat,maxlon))) {
    59                                 gui.boundingBoxChanged(b, BoundingBoxSelection.this);
    60                             }
    61                         } catch (NumberFormatException x) {
    62                             // ignore
    63                         }
    64                         updateUrl(gui);
    65                     }
    66                 });
    67             }
    68         };
    69 
    70         for (JTextField f : latlon) {
    71             f.setMinimumSize(new Dimension(100,new JTextField().getMinimumSize().height));
    72             f.addFocusListener(dialogUpdater);
    73         }
    7475
    7576        class osmUrlRefresher implements DocumentListener {
     
    8485        // windows look+feel but not for others. needs invokeLater to avoid strange
    8586        // side effects that will cancel out the newly made selection otherwise.
    86         osmUrl.addFocusListener(new FocusAdapter() {
    87             @Override public void focusGained(FocusEvent e) {
    88                 SwingUtilities.invokeLater(new Runnable() {
    89                     public void run() {
    90                         osmUrl.selectAll();
    91                     }
    92                 });
    93             }
    94         });
     87        osmUrl.addFocusListener(new SelectAllOnFocusHandler(osmUrl));
    9588        osmUrl.setLineWrap(true);
    9689        osmUrl.setBorder(latlon[0].getBorder());
     
    110103        showUrl.setEditable(false);
    111104        showUrl.setBackground(dlg.getBackground());
    112         showUrl.addFocusListener(new FocusAdapter(){
    113             @Override
    114             public void focusGained(FocusEvent e) {
    115                 showUrl.selectAll();
    116             }
    117         });
     105        showUrl.addFocusListener(new SelectAllOnFocusHandler(showUrl));
    118106
    119107        gui.addDownloadAreaSelector(dlg, tr("Bounding Box"));
    120108    }
    121109
    122     /**
    123      * Called when bounding box is changed by one of the other download dialog tabs.
    124      */
    125     public void boundingBoxChanged(DownloadDialog gui) {
    126         updateBboxFields(gui);
    127         updateUrl(gui);
     110   
     111    public void setDownloadArea(Bounds area) {
     112        updateBboxFields(area);
     113        updateUrl(area);
     114    }
     115   
     116    public Bounds getDownloadArea() {
     117        double[] values = new double[4];
     118        for (int i=0; i < 4; i++) {
     119            try {
     120                values[i] = Double.parseDouble(latlon[i].getText());
     121            } catch(NumberFormatException x) {
     122                return null;
     123            }
     124        }
     125        if (!LatLon.isValidLat(values[0]) || !LatLon.isValidLon(values[1]))
     126            return null;
     127        if (!LatLon.isValidLat(values[2]) || !LatLon.isValidLon(values[3]))
     128            return null;       
     129        return new Bounds(values);
    128130    }
    129131
     
    132134        if(b == null) return false;       
    133135        gui.boundingBoxChanged(b,BoundingBoxSelection.this);
    134         updateBboxFields(gui);
    135         updateUrl(gui);
     136        updateBboxFields(b);
     137        updateUrl(b);
    136138        return true;
    137139    }
    138140
    139     private void updateBboxFields(DownloadDialog gui) {
    140         Bounds b = gui.getSelectedDownloadArea();
    141         if (b == null) return;
    142         latlon[0].setText(Double.toString(b.getMin().lat()));
    143         latlon[1].setText(Double.toString(b.getMin().lon()));
    144         latlon[2].setText(Double.toString(b.getMax().lat()));
    145         latlon[3].setText(Double.toString(b.getMax().lon()));
     141    private void updateBboxFields(Bounds area) {
     142        if (area == null) return;
     143        latlon[0].setText(Double.toString(area.getMin().lat()));
     144        latlon[1].setText(Double.toString(area.getMin().lon()));
     145        latlon[2].setText(Double.toString(area.getMax().lat()));
     146        latlon[3].setText(Double.toString(area.getMax().lon()));
    146147        for (JTextField f : latlon) {
    147148            f.setCaretPosition(0);
     
    149150    }
    150151
    151     private void updateUrl(DownloadDialog gui) {
    152         if (gui.getSelectedDownloadArea() == null) return;
    153         showUrl.setText(OsmUrlToBounds.getURL(gui.getSelectedDownloadArea()));
     152    private void updateUrl(Bounds area) {
     153        if (area == null) return;
     154        showUrl.setText(OsmUrlToBounds.getURL(area));
     155    }
     156   
     157   
     158    class LatValueChecker extends FocusAdapter implements ActionListener{
     159        private JTextField tfLatValue;
     160       
     161        private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1);
     162        protected void setErrorMessage(String msg) {
     163            if (msg != null) {
     164                tfLatValue.setBorder(errorBorder);
     165                tfLatValue.setToolTipText(msg);
     166            } else {
     167                tfLatValue.setBorder(UIManager.getBorder("TextField.border"));
     168                tfLatValue.setToolTipText("");               
     169            }
     170        }
     171     
     172        public LatValueChecker(JTextField tfLatValue) {
     173            this.tfLatValue = tfLatValue;
     174        }
     175       
     176        protected void check() {
     177            double value = 0;
     178            try {
     179                value = Double.parseDouble(tfLatValue.getText());
     180            } catch(NumberFormatException ex) {
     181                setErrorMessage(tr("The string ''{0}'' isn''t a valid double value.", tfLatValue.getText()));
     182                return;
     183            }
     184            if (!LatLon.isValidLat(value)) {
     185                JOptionPane.showMessageDialog(
     186                        Main.parent,
     187                        tr("Value for latitude in range [-90,90] required.", tfLatValue.getText()),
     188                        tr("Error"),
     189                        JOptionPane.ERROR_MESSAGE
     190               );         
     191                setErrorMessage(tr("Value for latitude in range [-90,90] required.", tfLatValue.getText()));
     192                return;           
     193            }
     194        }
     195       
     196        @Override
     197        public void focusLost(FocusEvent e) {
     198            check();
     199        }
     200
     201        public void actionPerformed(ActionEvent e) {
     202            check();           
     203        }       
     204    }
     205   
     206    class LonValueChecker extends FocusAdapter implements ActionListener {
     207        private JTextField tfLonValue;
     208        private Border errorBorder = BorderFactory.createLineBorder(Color.RED, 1);
     209        protected void setErrorMessage(String msg) {
     210            if (msg != null) {
     211                tfLonValue.setBorder(errorBorder);
     212                tfLonValue.setToolTipText(msg);
     213            } else {
     214                tfLonValue.setBorder(UIManager.getBorder("TextField.border"));
     215                tfLonValue.setToolTipText("");               
     216            }
     217        }
     218       
     219        public LonValueChecker(JTextField tfLonValue) {
     220            this.tfLonValue = tfLonValue;
     221        }
     222       
     223        protected void check() {
     224            double value = 0;
     225            try {
     226                value = Double.parseDouble(tfLonValue.getText());
     227            } catch(NumberFormatException ex) {
     228               setErrorMessage(tr("The string ''{0}'' isn''t a valid double value.", tfLonValue.getText()));
     229               return;
     230            }
     231            if (!LatLon.isValidLon(value)) {
     232                setErrorMessage(tr("Value for longitude in range [-180,180] required.", tfLonValue.getText()));
     233                return;
     234            }
     235        }
     236       
     237        @Override
     238        public void focusLost(FocusEvent e) {
     239            check();
     240        }
     241
     242        public void actionPerformed(ActionEvent e) {
     243            check();
     244        }       
     245    }
     246   
     247    class SelectAllOnFocusHandler extends FocusAdapter {
     248        private JTextComponent tfTarget;
     249        public SelectAllOnFocusHandler(JTextComponent tfTarget) {
     250            this.tfTarget = tfTarget;           
     251        }
     252       
     253        @Override
     254        public void focusGained(FocusEvent e) {
     255            tfTarget.selectAll();
     256        }       
    154257    }
    155258}
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r2331 r2332  
    195195        for (DownloadSelection s : downloadSelections) {
    196196            if (s != eventSource) {
    197                 s.boundingBoxChanged(this);
     197                s.setDownloadArea(currentBounds);
    198198            }
    199199        }
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadSelection.java

    r1169 r2332  
    22package org.openstreetmap.josm.gui.download;
    33
     4import org.openstreetmap.josm.data.Bounds;
    45
    5 public interface DownloadSelection {
     6
     7public interface DownloadSelection  {
     8
    69    /**
    710     * Add the GUI elements to the dialog.
     
    912    void addGui(DownloadDialog gui);
    1013
     14   
    1115    /**
    12      * Update or clear display when a selection is made through another
    13      * DownloadSelection object
     16     * Sets the current download area. The area may be null to clear
     17     * the current download area.
     18     *
     19     * @param are the current download area
    1420     */
    15     void boundingBoxChanged(DownloadDialog gui);
     21    public void setDownloadArea(Bounds area);
     22}
    1623
    17 }
  • trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java

    r2331 r2332  
    310310                         )
    311311                    );
    312                     updatingSelf = true;
    313312                    gui.boundingBoxChanged(b,null);
    314                     updatingSelf = false;
    315313                }
    316314            }
     
    332330    }
    333331
    334     // if bounding box selected on other tab, de-select item
    335     public void boundingBoxChanged(DownloadDialog gui) {
    336         if (!updatingSelf) {
    337             searchResultDisplay.clearSelection();
    338         }
     332    public void setDownloadArea(Bounds area) {
     333       searchResultDisplay.clearSelection();
    339334    }
    340335}
  • trunk/src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java

    r2329 r2332  
    166166    }
    167167
    168     public void boundingBoxChanged(DownloadDialog gui) {
    169         Bounds b = gui.getSelectedDownloadArea();
    170         if (b == null)
     168    public void setDownloadArea(Bounds area) {
     169        if (area == null)
    171170            return;
    172171       
    173172        // test if a bounding box has been set set
    174         if (b.getMin().lat() == 0.0 && b.getMin().lon() == 0.0 && b.getMax().lat() == 0.0 && b.getMax().lon() == 0.0)
     173        if (area.getMin().lat() == 0.0 && area.getMin().lon() == 0.0 && area.getMax().lat() == 0.0 && area.getMax().lon() == 0.0)
    175174            return;
    176175
    177         int y1 = OsmMercator.LatToY(b.getMin().lat(), MAX_ZOOM);
    178         int y2 = OsmMercator.LatToY(b.getMax().lat(), MAX_ZOOM);
    179         int x1 = OsmMercator.LonToX(b.getMin().lon(), MAX_ZOOM);
    180         int x2 = OsmMercator.LonToX(b.getMax().lon(), MAX_ZOOM);
     176        int y1 = OsmMercator.LatToY(area.getMin().lat(), MAX_ZOOM);
     177        int y2 = OsmMercator.LatToY(area.getMax().lat(), MAX_ZOOM);
     178        int x1 = OsmMercator.LonToX(area.getMin().lon(), MAX_ZOOM);
     179        int x2 = OsmMercator.LonToX(area.getMax().lon(), MAX_ZOOM);
    181180
    182181        iSelectionRectStart = new Point(Math.min(x1, x2), Math.min(y1, y2));
     
    184183
    185184        // calc the screen coordinates for the new selection rectangle
    186         MapMarkerDot xmin_ymin = new MapMarkerDot(b.getMin().lat(), b.getMin().lon());
    187         MapMarkerDot xmax_ymax = new MapMarkerDot(b.getMax().lat(), b.getMax().lon());
     185        MapMarkerDot xmin_ymin = new MapMarkerDot(area.getMin().lat(), area.getMin().lon());
     186        MapMarkerDot xmax_ymax = new MapMarkerDot(area.getMax().lat(), area.getMax().lon());
    188187
    189188        Vector<MapMarker> marker = new Vector<MapMarker>(2);
  • trunk/src/org/openstreetmap/josm/gui/download/TileSelection.java

    r2327 r2332  
    8787    }
    8888
    89     /**
    90      * Called when bounding box is changed by one of the other download dialog tabs.
    91      */
    92     public void boundingBoxChanged(DownloadDialog gui) {
    93         updateBboxFields(gui);
    94     }
    95 
    96     private void updateBboxFields(DownloadDialog gui) {
     89    public void setDownloadArea(Bounds area) {
     90        if (area == null)
     91            return;
    9792        int z = ((Integer) tileZ.getValue()).intValue();
    98         Bounds b = gui.getSelectedDownloadArea();
    99         if (b == null)
    100             return;
    101         tileX0.setText(Integer.toString(lonToTileX(z, b.getMin().lon())));
    102         tileX1.setText(Integer.toString(lonToTileX(z, b.getMax().lon()-.00001)));
    103         tileY0.setText(Integer.toString(latToTileY(z, b.getMax().lat()-.00001)));
    104         tileY1.setText(Integer.toString(latToTileY(z, b.getMin().lat())));
     93        tileX0.setText(Integer.toString(lonToTileX(z, area.getMin().lon())));
     94        tileX1.setText(Integer.toString(lonToTileX(z, area.getMax().lon()-.00001)));
     95        tileY0.setText(Integer.toString(latToTileY(z, area.getMax().lat()-.00001)));
     96        tileY1.setText(Integer.toString(latToTileY(z, area.getMin().lat())));
    10597    }
    10698
Note: See TracChangeset for help on using the changeset viewer.