diff --git a/src/main/java/io/github/albertus82/eqbulletin/gui/AbstractMenu.java b/src/main/java/io/github/albertus82/eqbulletin/gui/AbstractMenu.java index 11a3b5f2..06a735c2 100644 --- a/src/main/java/io/github/albertus82/eqbulletin/gui/AbstractMenu.java +++ b/src/main/java/io/github/albertus82/eqbulletin/gui/AbstractMenu.java @@ -30,7 +30,7 @@ abstract class AbstractMenu implements Multilanguage { protected MenuItem openBrowserMenuItem; protected MenuItem showMapMenuItem; protected MenuItem showMomentTensorMenuItem; - protected MenuItem findEventsSameAreaMenuItem; + protected MenuItem findSameAreaEventsMenuItem; @Getter(AccessLevel.NONE) private final LocalizedWidgets localizedWidgets = new LocalizedWidgets(); diff --git a/src/main/java/io/github/albertus82/eqbulletin/gui/MenuBar.java b/src/main/java/io/github/albertus82/eqbulletin/gui/MenuBar.java index d49c441c..930a5ac1 100644 --- a/src/main/java/io/github/albertus82/eqbulletin/gui/MenuBar.java +++ b/src/main/java/io/github/albertus82/eqbulletin/gui/MenuBar.java @@ -16,7 +16,7 @@ import io.github.albertus82.eqbulletin.gui.listener.ExitListener; import io.github.albertus82.eqbulletin.gui.listener.ExportCsvSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.FileMenuListener; -import io.github.albertus82.eqbulletin.gui.listener.FindEventsSameAreaSelectionListener; +import io.github.albertus82.eqbulletin.gui.listener.FindSameAreaEventsSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.GoogleMapsBrowserSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.OpenInBrowserSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.PreferencesListener; @@ -120,8 +120,8 @@ public class MenuBar extends AbstractMenu { new MenuItem(eventMenu, SWT.SEPARATOR); // Find events in the same area - findEventsSameAreaMenuItem = newLocalizedMenuItem(eventMenu, SWT.PUSH, LABEL_MENU_ITEM_FIND_EVENTS_SAME_AREA); - findEventsSameAreaMenuItem.addSelectionListener(new FindEventsSameAreaSelectionListener(gui::getResultsTable, gui::getSearchForm)); + findSameAreaEventsMenuItem = newLocalizedMenuItem(eventMenu, SWT.PUSH, LABEL_MENU_ITEM_FIND_EVENTS_SAME_AREA); + findSameAreaEventsMenuItem.addSelectionListener(new FindSameAreaEventsSelectionListener(gui::getResultsTable, gui::getSearchForm)); // Tools final Menu toolsMenu = new Menu(shell, SWT.DROP_DOWN); diff --git a/src/main/java/io/github/albertus82/eqbulletin/gui/ResultsTable.java b/src/main/java/io/github/albertus82/eqbulletin/gui/ResultsTable.java index 71ff73f9..d2b41ca6 100644 --- a/src/main/java/io/github/albertus82/eqbulletin/gui/ResultsTable.java +++ b/src/main/java/io/github/albertus82/eqbulletin/gui/ResultsTable.java @@ -52,7 +52,7 @@ import io.github.albertus82.eqbulletin.gui.listener.CopyLinkSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.EpicenterMapSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.ExportCsvSelectionListener; -import io.github.albertus82.eqbulletin.gui.listener.FindEventsSameAreaSelectionListener; +import io.github.albertus82.eqbulletin.gui.listener.FindSameAreaEventsSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.GoogleMapsBrowserSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.OpenInBrowserSelectionListener; import io.github.albertus82.eqbulletin.gui.listener.ResultsTableContextMenuDetectListener; @@ -543,8 +543,8 @@ private ContextMenu(@NonNull final ResultsTable rt) { new MenuItem(menu, SWT.SEPARATOR); // Find events in the same area - findEventsSameAreaMenuItem = newLocalizedMenuItem(menu, SWT.PUSH, LABEL_MENU_ITEM_FIND_EVENTS_SAME_AREA); - findEventsSameAreaMenuItem.addSelectionListener(new FindEventsSameAreaSelectionListener(() -> rt, () -> searchForm)); + findSameAreaEventsMenuItem = newLocalizedMenuItem(menu, SWT.PUSH, LABEL_MENU_ITEM_FIND_EVENTS_SAME_AREA); + findSameAreaEventsMenuItem.addSelectionListener(new FindSameAreaEventsSelectionListener(() -> rt, () -> searchForm)); new MenuItem(menu, SWT.SEPARATOR); diff --git a/src/main/java/io/github/albertus82/eqbulletin/gui/listener/EventMenuListener.java b/src/main/java/io/github/albertus82/eqbulletin/gui/listener/EventMenuListener.java index 97e24c8b..1e1b98f3 100644 --- a/src/main/java/io/github/albertus82/eqbulletin/gui/listener/EventMenuListener.java +++ b/src/main/java/io/github/albertus82/eqbulletin/gui/listener/EventMenuListener.java @@ -24,7 +24,7 @@ public void menuArmed(final TypedEvent e) { menuBar.getOpenBrowserMenuItem().setEnabled(selection != null && selection.getLink().isPresent()); menuBar.getGoogleMapsBrowserMenuItem().setEnabled(selection != null); menuBar.getEpicenterMapPopupMenuItem().setEnabled(selection != null); - menuBar.getFindEventsSameAreaMenuItem().setEnabled(selection != null); + menuBar.getFindSameAreaEventsMenuItem().setEnabled(selection != null); } } diff --git a/src/main/java/io/github/albertus82/eqbulletin/gui/listener/FindEventsSameAreaSelectionListener.java b/src/main/java/io/github/albertus82/eqbulletin/gui/listener/FindSameAreaEventsSelectionListener.java similarity index 79% rename from src/main/java/io/github/albertus82/eqbulletin/gui/listener/FindEventsSameAreaSelectionListener.java rename to src/main/java/io/github/albertus82/eqbulletin/gui/listener/FindSameAreaEventsSelectionListener.java index a3ff5cb3..491b6f4b 100644 --- a/src/main/java/io/github/albertus82/eqbulletin/gui/listener/FindEventsSameAreaSelectionListener.java +++ b/src/main/java/io/github/albertus82/eqbulletin/gui/listener/FindSameAreaEventsSelectionListener.java @@ -1,6 +1,5 @@ package io.github.albertus82.eqbulletin.gui.listener; -import java.util.Arrays; import java.util.function.Supplier; import org.eclipse.jface.viewers.TableViewer; @@ -9,20 +8,32 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Table; +import io.github.albertus82.eqbulletin.config.EarthquakeBulletinConfig; import io.github.albertus82.eqbulletin.gui.ResultsTable; import io.github.albertus82.eqbulletin.gui.SearchForm; +import io.github.albertus82.eqbulletin.gui.preference.Preference; import io.github.albertus82.eqbulletin.model.Earthquake; import io.github.albertus82.jface.maps.MapBounds; +import io.github.albertus82.jface.preference.IPreferencesConfiguration; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @Slf4j @RequiredArgsConstructor -public class FindEventsSameAreaSelectionListener extends SelectionAdapter { +public class FindSameAreaEventsSelectionListener extends SelectionAdapter { private static final double AUTHALIC_RADIUS = 6371.0072; + @NoArgsConstructor(access = AccessLevel.PRIVATE) + public static class Defaults { + public static final byte SAME_AREA_EVENTS_LATITUDE_INTERVAL = 1; + } + + private final IPreferencesConfiguration configuration = EarthquakeBulletinConfig.getPreferencesConfiguration(); + @NonNull private final Supplier resultsTableSupplier; @@ -36,7 +47,7 @@ public void widgetSelected(final SelectionEvent se) { final Table table = tableViewer.getTable(); if (selection != null && table != null && !table.isDisposed()) { final SearchForm form = searchFormSupplier.get(); - final float offset = 1; + final float offset = configuration.getByte(Preference.SAME_AREA_EVENTS_LATITUDE_INTERVAL, Defaults.SAME_AREA_EVENTS_LATITUDE_INTERVAL); // Latitude (parallels) final float lat = Math.min(MapBounds.LATITUDE_MAX_VALUE - offset, Math.max(MapBounds.LATITUDE_MIN_VALUE + offset, selection.getLatitude().getValue())); @@ -93,10 +104,4 @@ private static double computeArea(final double lat0deg, final double lat1deg, fi return a * b * c; } - public static void main(String[] args) { - final int offset = 1; - final float lat = Math.min(MapBounds.LATITUDE_MAX_VALUE - offset, Math.max(MapBounds.LATITUDE_MIN_VALUE + offset, 88)); - System.out.println(Arrays.toString(computeLons(lat, 170, offset))); - } - } diff --git a/src/main/java/io/github/albertus82/eqbulletin/gui/preference/Preference.java b/src/main/java/io/github/albertus82/eqbulletin/gui/preference/Preference.java index 18bda07c..c1053e52 100644 --- a/src/main/java/io/github/albertus82/eqbulletin/gui/preference/Preference.java +++ b/src/main/java/io/github/albertus82/eqbulletin/gui/preference/Preference.java @@ -1,11 +1,6 @@ package io.github.albertus82.eqbulletin.gui.preference; -import static io.github.albertus82.eqbulletin.gui.preference.PageDefinition.ADVANCED; -import static io.github.albertus82.eqbulletin.gui.preference.PageDefinition.CACHE; -import static io.github.albertus82.eqbulletin.gui.preference.PageDefinition.CONNECTION; -import static io.github.albertus82.eqbulletin.gui.preference.PageDefinition.CRITERIA; -import static io.github.albertus82.eqbulletin.gui.preference.PageDefinition.GENERAL; -import static io.github.albertus82.eqbulletin.gui.preference.PageDefinition.LOGGING; +import static io.github.albertus82.eqbulletin.gui.preference.PageDefinition.*; import java.awt.SystemTray; import java.net.Proxy; @@ -33,6 +28,7 @@ import io.github.albertus82.eqbulletin.gui.ResultsTable; import io.github.albertus82.eqbulletin.gui.SearchForm; import io.github.albertus82.eqbulletin.gui.TrayIcon; +import io.github.albertus82.eqbulletin.gui.listener.FindSameAreaEventsSelectionListener; import io.github.albertus82.eqbulletin.model.Format; import io.github.albertus82.eqbulletin.resources.Messages; import io.github.albertus82.eqbulletin.resources.Messages.Language; @@ -100,6 +96,7 @@ public enum Preference implements IPreference { CRITERIA_FORMAT(new PreferenceDetailsBuilder(CRITERIA).label(() -> Messages.get("label.form.format")).defaultValue(SearchForm.Defaults.FORMAT.getValue()).build(), new FieldEditorDetailsBuilder(DefaultRadioGroupFieldEditor.class).labelsAndValues(getFormatRadioOptions()).radioNumColumns(2).radioUseGroup(true).build()), CRITERIA_LIMIT(new PreferenceDetailsBuilder(CRITERIA).label(() -> Messages.get("label.form.limit") + " " + Messages.get("label.form.limit.note")).build(), new FieldEditorDetailsBuilder(EnhancedIntegerFieldEditor.class).emptyStringAllowed(true).numberValidRange(SearchForm.RESULTS_MIN_VALUE, SearchForm.RESULTS_MAX_VALUE).build()), CRITERIA_RESTRICT(new PreferenceDetailsBuilder(CRITERIA).defaultValue(SearchForm.Defaults.CRITERIA_RESTRICT).label(() -> Messages.get("label.form.criteria.restrict")).build(), new FieldEditorDetailsBuilder(DefaultBooleanFieldEditor.class).build()), + SAME_AREA_EVENTS_LATITUDE_INTERVAL(new PreferenceDetailsBuilder(CRITERIA).defaultValue(FindSameAreaEventsSelectionListener.Defaults.SAME_AREA_EVENTS_LATITUDE_INTERVAL).build(), new FieldEditorDetailsBuilder(ScaleIntegerFieldEditor.class).scaleMinimum(1).scaleMaximum(5).scalePageIncrement(1).build()), AUTOREFRESH_ENABLED(new PreferenceDetailsBuilder(CRITERIA).defaultValue(SearchForm.Defaults.AUTOREFRESH_ENABLED).build(), new FieldEditorDetailsBuilder(DefaultBooleanFieldEditor.class).build()), AUTOREFRESH_MINS(new PreferenceDetailsBuilder(CRITERIA).parent(AUTOREFRESH_ENABLED).label(() -> Messages.get("label.form.button.autorefresh")).build(), new FieldEditorDetailsBuilder(EnhancedIntegerFieldEditor.class).numberMinimum(SearchForm.AUTOREFRESH_MIN_VALUE).emptyStringAllowed(true).textLimit(SearchForm.AUTOREFRESH_TEXT_LIMIT).build()), diff --git a/src/main/resources/io/github/albertus82/eqbulletin/resources/messages.properties b/src/main/resources/io/github/albertus82/eqbulletin/resources/messages.properties index 8445d83e..e2eb1910 100644 --- a/src/main/resources/io/github/albertus82/eqbulletin/resources/messages.properties +++ b/src/main/resources/io/github/albertus82/eqbulletin/resources/messages.properties @@ -128,6 +128,7 @@ label.preferences.cache=Cache label.preferences.confirm.close=Confirm on close label.preferences.connection=Connection label.preferences.criteria=Default criteria +label.preferences.same.area.events.latitude.interval=Same area events latitude interval \u00B1\u00B0 label.preferences.general=General label.preferences.geofon.base.url=Geofon base URL label.preferences.html.bulletin.version=HTML bulletin version available at the specified URL diff --git a/src/main/resources/io/github/albertus82/eqbulletin/resources/messages_it.properties b/src/main/resources/io/github/albertus82/eqbulletin/resources/messages_it.properties index 7a0c7cf0..f4108607 100644 --- a/src/main/resources/io/github/albertus82/eqbulletin/resources/messages_it.properties +++ b/src/main/resources/io/github/albertus82/eqbulletin/resources/messages_it.properties @@ -128,6 +128,7 @@ label.preferences.cache=Cache label.preferences.confirm.close=Conferma chiusura label.preferences.connection=Connessione label.preferences.criteria=Criteri predefiniti +label.preferences.same.area.events.latitude.interval=Intervallo latitudine eventi nella stessa area \u00B1\u00B0 label.preferences.general=Generale label.preferences.geofon.base.url=URL base Geofon label.preferences.html.bulletin.version=Versione del bollettino HTML presente all'URL specificato