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


Ignore:
Timestamp:
2015-04-18T12:33:06+02:00 (10 years ago)
Author:
simon04
Message:

fix #10868 - Add osm.notes.daysClosed to preference dialog

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited
1 moved

Legend:

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

    r8217 r8218  
    1515import org.openstreetmap.josm.data.Bounds;
    1616import org.openstreetmap.josm.data.notes.Note;
     17import org.openstreetmap.josm.data.preferences.IntegerProperty;
    1718import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1819import org.openstreetmap.josm.gui.layer.NoteLayer;
     
    3031    private static final String PATTERN_API_URL = "https?://.*/api/0.6/notes.*";
    3132    private static final String PATTERN_DUMP_FILE = "https?://.*/(.*\\.osn(.bz2)?)";
     33    /** Property defining the number of notes to be downloaded */
     34    public static final IntegerProperty DOWNLOAD_LIMIT = new IntegerProperty("osm.notes.downloadLimit", 1000);
     35    /** Property defining number of days a bug needs to be closed to no longer be downloaded */
     36    public static final IntegerProperty DAYS_CLOSED = new IntegerProperty("osm.notes.daysClosed", 7);
    3237
    3338    private DownloadTask downloadTask;
     
    143148            ProgressMonitor subMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    144149            try {
    145                 notesData = reader.parseNotes(null, null, subMonitor);
     150                notesData = reader.parseNotes(DOWNLOAD_LIMIT.get(), DAYS_CLOSED.get(), subMonitor);
    146151            } catch (BoundingBoxDownloader.MoreNotesException e) {
    147152                notesData = e.notes;
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

    r7509 r8218  
    1616import javax.swing.JPanel;
    1717import javax.swing.JRadioButton;
     18import javax.swing.JSeparator;
    1819
    1920import org.openstreetmap.josm.Main;
     
    4243    private OAuthAuthenticationPreferencesPanel pnlOAuthPreferences;
    4344    /** the panel for messages notifier preferences */
    44     private MessagesNotifierPanel pnlMessagesPreferences;
     45    private FeaturesPanel pnlFeaturesPreferences;
    4546
    4647    /**
     
    9495        pnlAuthenticationParameteters.add(pnlBasicAuthPreferences, BorderLayout.CENTER);
    9596
    96         //-- the panel for messages preferences
    9797        gc.gridy = 2;
     98        add(new JSeparator(), gc);
     99
     100        //-- the panel for API feature preferences
     101        gc.gridy = 3;
    98102        gc.fill = GridBagConstraints.NONE;
    99         pnlMessagesPreferences = new MessagesNotifierPanel();
    100         add(pnlMessagesPreferences, gc);
     103        pnlFeaturesPreferences = new FeaturesPanel();
     104        add(pnlFeaturesPreferences, gc);
    101105    }
    102106
     
    125129        pnlBasicAuthPreferences.initFromPreferences();
    126130        pnlOAuthPreferences.initFromPreferences();
    127         pnlMessagesPreferences.initFromPreferences();
     131        pnlFeaturesPreferences.initFromPreferences();
    128132    }
    129133
     
    152156        }
    153157        // save message notifications preferences. To be done after authentication preferences.
    154         pnlMessagesPreferences.saveToPreferences();
     158        pnlFeaturesPreferences.saveToPreferences();
    155159    }
    156160
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/FeaturesPanel.java

    r8217 r8218  
    1313import javax.swing.event.ChangeListener;
    1414
     15import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
    1516import org.openstreetmap.josm.gui.widgets.JosmTextField;
    1617import org.openstreetmap.josm.io.MessageNotifier;
     
    2122 * @since 6349
    2223 */
    23 public class MessagesNotifierPanel extends JPanel {
     24public class FeaturesPanel extends JPanel {
    2425
    2526    private JCheckBox notifier;
    2627    private JLabel intervalLabel;
    2728    private final JosmTextField notifierInterval = new JosmTextField(4);
     29    private final JosmTextField notesDaysClosed = new JosmTextField(4);
    2830
    2931    /**
    3032     * Constructs a new {@code MessagesNotifierPanel}.
    3133     */
    32     public MessagesNotifierPanel() {
     34    public FeaturesPanel() {
    3335        build();
    3436        initFromPreferences();
     
    5052       
    5153        intervalLabel = new JLabel(tr("Check interval (minutes):"));
    52         add(intervalLabel, GBC.std().insets(25,0,0,0));
     54        add(intervalLabel, GBC.std().insets(25, 0, 0, 0));
    5355
    5456        notifierInterval.setToolTipText(tr("Default value: {0}", MessageNotifier.PROP_INTERVAL.getDefaultValue()));
    5557        notifierInterval.setMinimumSize(notifierInterval.getPreferredSize());
    5658        add(notifierInterval, GBC.eol().insets(5,0,0,0));
     59
     60        final JLabel notesDaysClosedLabel = new JLabel(tr("Max age for closed notes (days):"));
     61        notesDaysClosedLabel.setToolTipText(tr("Specifies the number of days a note needs to be closed to no longer be downloaded"));
     62        add(notesDaysClosedLabel, GBC.std().insets(0, 20, 0, 0));
     63        notesDaysClosed.setToolTipText(tr("Default value: {0}", DownloadNotesTask.DAYS_CLOSED.getDefaultValue()));
     64        notesDaysClosed.setMinimumSize(notesDaysClosed.getPreferredSize());
     65        add(notesDaysClosed, GBC.eol().insets(5, 20, 0, 0));
     66
    5767    }
    5868   
     
    6272        notifierInterval.setEnabled(enabled);
    6373        notifierInterval.setEditable(enabled);
     74        notesDaysClosed.setEditable(enabled);
    6475    }
    6576
     
    7081        notifier.setSelected(MessageNotifier.PROP_NOTIFIER_ENABLED.get());
    7182        notifierInterval.setText(Integer.toString(MessageNotifier.PROP_INTERVAL.get()));
     83        notesDaysClosed.setText(Integer.toString(DownloadNotesTask.DAYS_CLOSED.get()));
    7284    }
    7385
     
    7991        boolean changed = MessageNotifier.PROP_NOTIFIER_ENABLED.put(enabled);
    8092        changed |= MessageNotifier.PROP_INTERVAL.parseAndPut(notifierInterval.getText());
     93        changed |= DownloadNotesTask.DAYS_CLOSED.parseAndPut(notesDaysClosed.getText());
    8194        // If parameters have changed, restart notifier
    8295        if (changed) {
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r8217 r8218  
    88import java.util.List;
    99
    10 import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.Bounds;
    1211import org.openstreetmap.josm.data.DataSource;
     
    162161
    163162    @Override
    164     public List<Note> parseNotes(Integer noteLimit, Integer daysClosed, ProgressMonitor progressMonitor) throws OsmTransferException, MoreNotesException {
     163    public List<Note> parseNotes(int noteLimit, int daysClosed, ProgressMonitor progressMonitor) throws OsmTransferException, MoreNotesException {
    165164        progressMonitor.beginTask("Downloading notes");
    166         noteLimit = checkNoteLimit(noteLimit);
    167         daysClosed = checkDaysClosed(daysClosed);
    168         String url = new StringBuilder()
    169         .append("notes?limit=")
    170         .append(noteLimit)
    171         .append("&closed=")
    172         .append(daysClosed)
    173         .append("&bbox=")
    174         .append(lon1)
    175         .append(",").append(lat1)
    176         .append(",").append(lon2)
    177         .append(",").append(lat2)
    178         .toString();
     165        CheckParameterUtil.ensureThat(noteLimit > 0, "Requested note limit is less than 1.");
     166        // see max_number_of_nodes in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/example.application.yml
     167        CheckParameterUtil.ensureThat(noteLimit <= 50000, "Requested note limit is over API hard limit of 50000.");
     168        CheckParameterUtil.ensureThat(daysClosed >= 0, "Requested note limit is less than 0.");
     169        String url = "notes?limit=" + noteLimit + "&closed=" + daysClosed + "&bbox=" + lon1 + "," + lat1 + "," + lon2 + "," + lat2;
    179170        try {
    180171            InputStream is = getInputStream(url, progressMonitor.createSubTaskMonitor(1, false));
     
    213204    }
    214205
    215     private Integer checkNoteLimit(Integer limit) {
    216         if (limit == null) {
    217             limit = Main.pref.getInteger("osm.notes.downloadLimit", 1000);
    218         }
    219         if (limit > 50000) {
    220             // see max_number_of_nodes in https://github.com/openstreetmap/openstreetmap-website/blob/master/config/example.application.yml
    221             Main.error("Requested note limit is over API hard limit of 50000. Reducing to 50000.");
    222             limit = 50000;
    223         }
    224         if (limit < 1) {
    225             Main.error("Requested note limit is less than 1. Setting to 1.");
    226             limit = 1;
    227         }
    228         return limit;
    229     }
    230 
    231     private Integer checkDaysClosed(Integer days) {
    232         if (days == null) {
    233             days = Main.pref.getInteger("osm.notes.daysClosed", 7);
    234         }
    235         if (days < -1) {
    236             Main.error("Requested days closed must be greater than -1");
    237             days = -1;
    238         }
    239         return days;
    240     }
    241 
    242206}
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r7531 r8218  
    354354     * Downloads notes from the API, given API limit parameters
    355355     *
    356      * @param noteLimit How many notes to download. Defaults to 1000 if not specified. API has a hard limit of 10000
     356     * @param noteLimit How many notes to download.
    357357     * @param daysClosed Return notes closed this many days in the past. -1 means all notes, ever. 0 means only unresolved notes.
    358358     * @param progressMonitor Progress monitor for user feedback
     
    360360     * @throws OsmTransferException if any errors happen
    361361     */
    362     public List<Note> parseNotes(Integer noteLimit, Integer daysClosed, ProgressMonitor progressMonitor) throws OsmTransferException {
     362    public List<Note> parseNotes(int noteLimit, int daysClosed, ProgressMonitor progressMonitor) throws OsmTransferException {
    363363        return null;
    364364    }
Note: See TracChangeset for help on using the changeset viewer.