Skip to content

Commit

Permalink
Find events in the same area.
Browse files Browse the repository at this point in the history
  • Loading branch information
albertus82 committed Jan 20, 2024
1 parent 0a2bce4 commit a1b198a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ResultsTable> resultsTableSupplier;

Expand All @@ -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()));
Expand Down Expand Up @@ -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)));
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1b198a

Please sign in to comment.