Ignore:
Timestamp:
2010-07-13T02:34:51+02:00 (14 years ago)
Author:
nakor
Message:

Dialog for choosing value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/download_along/src/org/openstreetmap/josm/plugin/download_along/DownloadAlong.java

    r22293 r22295  
    1212
    1313import javax.swing.JLabel;
     14import javax.swing.JList;
    1415import javax.swing.JMenuItem;
    1516import javax.swing.JOptionPane;
     
    3334
    3435public class DownloadAlong extends Plugin {
     36  private static final String PREF_DOWNLOAD_ALONG_TRACK_DISTANCE = "downloadAlong.downloadAlongTrack.distance";
     37  private static final String PREF_DOWNLOAD_ALONG_TRACK_AREA = "downloadAlong.downloadAlongTrack.area";
     38
    3539  JMenuItem DownloadAlong;
    3640
     
    4751                 */
    4852    private static final long serialVersionUID = 1L;
     53
    4954    public DownloadAlongAction() {
    5055      super(tr("Download along..."), "download_along",
     
    7176      }
    7277
     78      JPanel msg = new JPanel(new GridBagLayout());
     79      Integer dist[] = { 5000, 500, 50 };
     80      Integer area[] = { 20, 10, 5, 1 };
     81
     82      msg.add(new JLabel(tr("Download everything within:")), GBC.eol());
     83      String s[] = new String[dist.length];
     84      for (int i = 0; i < dist.length; ++i) {
     85        s[i] = tr("{0} meters", dist[i]);
     86      }
     87      JList buffer = new JList(s);
     88      buffer.setSelectedIndex(Main.pref.getInteger(
     89          PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, 0));
     90      msg.add(buffer, GBC.eol());
     91
     92      msg.add(new JLabel(tr("Maximum area per request:")), GBC.eol());
     93      s = new String[area.length];
     94      for (int i = 0; i < area.length; ++i) {
     95        s[i] = tr("{0} sq km", area[i]);
     96      }
     97      JList maxRect = new JList(s);
     98      maxRect.setSelectedIndex(Main.pref.getInteger(
     99          PREF_DOWNLOAD_ALONG_TRACK_AREA, 0));
     100      msg.add(maxRect, GBC.eol());
     101
     102      int ret = JOptionPane.showConfirmDialog(Main.parent, msg,
     103          tr("Download from OSM along this track"),
     104          JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
     105      switch (ret) {
     106      case JOptionPane.CANCEL_OPTION:
     107      case JOptionPane.CLOSED_OPTION:
     108        return;
     109      default:
     110        // continue
     111      }
     112
     113      Main.pref.putInteger(PREF_DOWNLOAD_ALONG_TRACK_DISTANCE, buffer
     114          .getSelectedIndex());
     115      Main.pref.putInteger(PREF_DOWNLOAD_ALONG_TRACK_AREA, maxRect
     116          .getSelectedIndex());
     117
    73118      /*
    74119       * Find the average latitude for the data we're contemplating, so we can
     
    96141       * because it has more than 50k nodes.
    97142       */
    98       // Integer i = buffer.getSelectedIndex();
    99       // int buffer_dist = dist[i < 0 ? 0 : i];
    100       int buffer_dist = 5000;
     143      Integer i = buffer.getSelectedIndex();
     144      int buffer_dist = dist[i < 0 ? 0 : i];
    101145      double buffer_y = buffer_dist / 100000.0;
    102146      double buffer_x = buffer_y / scale;
    103       // i = maxRect.getSelectedIndex();
    104       // double max_area = area[i < 0 ? 0 : i] / 10000.0 / scale;
    105       double max_area = 20 / 10000.0 / scale;
     147      i = maxRect.getSelectedIndex();
     148      double max_area = area[i < 0 ? 0 : i] / 10000.0 / scale;
    106149      Area a = new Area();
    107150      Rectangle2D r = new Rectangle2D.Double();
     
    148191      addToDownload(a, a.getBounds(), toDownload, max_area);
    149192
    150       JPanel msg = new JPanel(new GridBagLayout());
     193      msg = new JPanel(new GridBagLayout());
    151194
    152195      msg.add(new JLabel(tr("<html>This action will require {0} individual<br>"
     
    155198
    156199      if (toDownload.size() > 1) {
    157         int ret = JOptionPane.showConfirmDialog(Main.parent, msg,
     200        ret = JOptionPane.showConfirmDialog(Main.parent, msg,
    158201            tr("Download from OSM along this track"),
    159202            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
     
    183226    }
    184227
    185     private static void addToDownload(Area a, Rectangle2D r, Collection<Rectangle2D> results, double max_area) {
     228    private static void addToDownload(Area a, Rectangle2D r,
     229        Collection<Rectangle2D> results, double max_area) {
    186230      Area tmp = new Area(r);
    187231      // intersect with sought-after area
    188232      tmp.intersect(a);
    189233      if (tmp.isEmpty())
    190           return;
     234        return;
    191235      Rectangle2D bounds = tmp.getBounds2D();
    192236      if (bounds.getWidth() * bounds.getHeight() > max_area) {
    193           // the rectangle gets too large; split it and make recursive call.
    194           Rectangle2D r1;
    195           Rectangle2D r2;
    196           if (bounds.getWidth() > bounds.getHeight()) {
    197               // rectangles that are wider than high are split into a left and right half,
    198               r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth() / 2, bounds.getHeight());
    199               r2 = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() / 2, bounds.getY(),
    200                       bounds.getWidth() / 2, bounds.getHeight());
    201           } else {
    202               // others into a top and bottom half.
    203               r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() / 2);
    204               r2 = new Rectangle2D.Double(bounds.getX(), bounds.getY() + bounds.getHeight() / 2, bounds.getWidth(),
    205                       bounds.getHeight() / 2);
    206           }
    207           addToDownload(a, r1, results, max_area);
    208           addToDownload(a, r2, results, max_area);
     237        // the rectangle gets too large; split it and make recursive call.
     238        Rectangle2D r1;
     239        Rectangle2D r2;
     240        if (bounds.getWidth() > bounds.getHeight()) {
     241          // rectangles that are wider than high are split into a left and right
     242          // half,
     243          r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds
     244              .getWidth() / 2, bounds.getHeight());
     245          r2 = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() / 2,
     246              bounds.getY(), bounds.getWidth() / 2, bounds.getHeight());
     247        } else {
     248          // others into a top and bottom half.
     249          r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds
     250              .getWidth(), bounds.getHeight() / 2);
     251          r2 = new Rectangle2D.Double(bounds.getX(), bounds.getY()
     252              + bounds.getHeight() / 2, bounds.getWidth(),
     253              bounds.getHeight() / 2);
     254        }
     255        addToDownload(a, r1, results, max_area);
     256        addToDownload(a, r2, results, max_area);
    209257      } else {
    210           results.add(bounds);
    211       }
    212   }
    213    
    214    
     258        results.add(bounds);
     259      }
     260    }
     261
    215262    @Override
    216263    protected void updateEnabledState(
Note: See TracChangeset for help on using the changeset viewer.