Skip to content

Commit

Permalink
MapCanvas
Browse files Browse the repository at this point in the history
  • Loading branch information
albertus82 committed Jan 11, 2024
1 parent a73d887 commit 527570c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/main/java/io/github/albertus82/eqbulletin/gui/MapCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.util.Util;
Expand Down Expand Up @@ -61,7 +57,11 @@ public static class Defaults {
private static final int AUTO_SCALE = 0;
private static final int MAX_HQ_RESIZE_RATIO = 250;

private static final LinkedList<Integer> zoomLevels = Arrays.stream(new Integer[] { AUTO_SCALE, 10, 12, 15, 20, 25, 30, 40, 50, 60, 80, 100, 120, 150, 200, 250, 300, 400, 500 }).sorted().collect(Collectors.toCollection(LinkedList::new));
private static final int[] zoomLevels = { AUTO_SCALE, 10, 12, 15, 20, 25, 30, 40, 50, 60, 80, 100, 120, 150, 200, 250, 300, 400, 500 };

static {
Arrays.sort(zoomLevels);
}

private final IPreferencesConfiguration configuration = EarthquakeBulletinConfig.getPreferencesConfiguration();

Expand Down Expand Up @@ -99,7 +99,7 @@ public static class Defaults {
zoomMenuItem.setMenu(zoomSubMenu);

final Map<Integer, MenuItem> zoomSubMenuItems = new HashMap<>();
for (final int level : zoomLevels) {
for (final int level : getZoomLevels()) {
final MenuItem item = newLocalizedMenuItem(zoomSubMenu, SWT.RADIO, () -> Messages.get("label.menu.item.zoom." + (level == AUTO_SCALE ? "auto" : "custom"), level));
zoomSubMenuItems.put(level, item);
item.addSelectionListener(new SelectionAdapter() {
Expand Down Expand Up @@ -265,8 +265,9 @@ private void cleanDirt(@NonNull final GC gc) {
}

static int[] getZoomNearestValues(float value) {
value = Math.max(zoomLevels.get(1), Math.min(value, zoomLevels.getLast())); // limit input range
final int[] values = new int[] { zoomLevels.get(1), zoomLevels.getLast() };
final int[] zoomLevels = getZoomLevels();
value = Math.max(zoomLevels[1], Math.min(value, zoomLevels[zoomLevels.length - 1])); // limit input range
final int[] values = new int[] { zoomLevels[1], zoomLevels[zoomLevels.length - 1] };
for (final int zoomLevel : zoomLevels) {
if (zoomLevel != AUTO_SCALE) {
if (zoomLevel < value) {
Expand Down Expand Up @@ -360,8 +361,8 @@ private MenuItem newLocalizedMenuItem(@NonNull final Menu parent, final int styl
return localizedWidgets.putAndReturn(new MenuItem(parent, style), textSupplier).getKey();
}

public static Collection<Integer> getZoomLevels() {
return Collections.unmodifiableCollection(zoomLevels);
public static int[] getZoomLevels() {
return zoomLevels.clone();
}

public static synchronized void setMapImage(final MapImage mapImage, final Earthquake earthquake) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ public static LocalizedLabelsAndValues getDecoderRadioOptions() {
}

public static LocalizedLabelsAndValues getZoomComboOptions() {
final Collection<Integer> values = MapCanvas.getZoomLevels();
final LocalizedLabelsAndValues options = new LocalizedLabelsAndValues(values.size());
final int[] values = MapCanvas.getZoomLevels();
final LocalizedLabelsAndValues options = new LocalizedLabelsAndValues(values.length);
for (final int level : values) {
final String value = Integer.toString(level);
options.add(() -> Messages.get("label.preferences.map.zoom.level." + (level == 0 ? "auto" : "custom"), value), value);
Expand Down

0 comments on commit 527570c

Please sign in to comment.