diff --git a/src/main/java/io/github/dsheirer/controller/ControllerPanel.java b/src/main/java/io/github/dsheirer/controller/ControllerPanel.java
index 55fb25b7..552611e0 100644
--- a/src/main/java/io/github/dsheirer/controller/ControllerPanel.java
+++ b/src/main/java/io/github/dsheirer/controller/ControllerPanel.java
@@ -26,7 +26,7 @@ import io.github.dsheirer.gui.nowplaying.NowPlayingPanel;
import io.github.dsheirer.gui.playlist.ViewPlaylistRequest;
import io.github.dsheirer.icon.IconModel;
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
-import io.github.dsheirer.map.MapPanel;
+import io.github.dsheirer.gui.map.MapPanel;
import io.github.dsheirer.map.MapService;
import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences;
@@ -64,7 +64,7 @@ public class ControllerPanel extends JPanel
mAudioPanel = new AudioPanel(iconModel, userPreferences, settingsManager, audioPlaybackManager,
playlistManager.getAliasModel());
mNowPlayingPanel = new NowPlayingPanel(playlistManager, iconModel, userPreferences, detailTabsVisible);
- mMapPanel = new MapPanel(mapService, playlistManager.getAliasModel(), iconModel, userPreferences,
+ mMapPanel = new MapPanel(mapService, iconModel, userPreferences,
playlistManager.getRadioReference() != null ? playlistManager.getRadioReference().getFrequencyIndex() : null,
new RadioReferencePlaylistActions(playlistManager));
mTunerManagerPanel = new TunerViewPanel(tunerManager, userPreferences);
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/WaypointRenderer.java b/src/main/java/io/github/dsheirer/gui/map/MapLayer.java
similarity index 50%
rename from src/main/java/org/jdesktop/swingx/mapviewer/WaypointRenderer.java
rename to src/main/java/io/github/dsheirer/gui/map/MapLayer.java
index d7161de5..19ff34eb 100644
--- a/src/main/java/org/jdesktop/swingx/mapviewer/WaypointRenderer.java
+++ b/src/main/java/io/github/dsheirer/gui/map/MapLayer.java
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
- * Copyright (C) 2014-2022 Dennis Sheirer
+ * Copyright (C) 2014-2026 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,35 +17,19 @@
* ****************************************************************************
*/
-/*
- * WaypointRenderer.java
- *
- * Created on March 30, 2006, 5:56 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
+package io.github.dsheirer.gui.map;
-package org.jdesktop.swingx.mapviewer;
-
-import org.jdesktop.swingx.JXMapViewer;
-
-import java.awt.Graphics2D;
+import javafx.scene.canvas.GraphicsContext;
/**
- * A interface that draws waypoints. Implementations of WaypointRenderer can
- * be set on a WayPointPainter to draw waypoints on a JXMapViewer
- * @param the waypoint type
- * @author joshua.marinacci@sun.com
+ * Overlay drawn over the map tiles, in the order the layers were added to the {@link TileMapView}.
*/
-public interface WaypointRenderer
+public interface MapLayer
{
/**
- * paint the specified waypoint on the specified map and graphics context
- * @param g the graphics2D object
- * @param map the map
- * @param waypoint the waypoint
+ * Draws the layer. Called on the JavaFX thread.
+ * @param gc of the map canvas, in screen pixels
+ * @param map for converting positions to screen pixels
*/
- public void paintWaypoint(Graphics2D g, JXMapViewer map, W waypoint);
-
+ void draw(GraphicsContext gc, TileMapView map);
}
diff --git a/src/main/java/io/github/dsheirer/gui/map/MapPanel.java b/src/main/java/io/github/dsheirer/gui/map/MapPanel.java
new file mode 100644
index 00000000..baea278f
--- /dev/null
+++ b/src/main/java/io/github/dsheirer/gui/map/MapPanel.java
@@ -0,0 +1,59 @@
+/*
+ * *****************************************************************************
+ * Copyright (C) 2014-2026 Dennis Sheirer
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * ****************************************************************************
+ */
+
+package io.github.dsheirer.gui.map;
+
+import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
+import io.github.dsheirer.gui.theme.ThemeManager;
+import io.github.dsheirer.icon.IconModel;
+import io.github.dsheirer.map.MapService;
+import io.github.dsheirer.preference.UserPreferences;
+import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex;
+import javafx.application.Platform;
+import javafx.embed.swing.JFXPanel;
+import javafx.scene.Scene;
+
+/**
+ * Swing panel that holds the JavaFX map view for the main application window. The JavaFX view is created on the
+ * JavaFX application thread after construction.
+ */
+public class MapPanel extends JFXPanel
+{
+ /**
+ * Constructs an instance
+ * @param mapService for the entities to plot
+ * @param iconModel for alias icons
+ * @param userPreferences for the map view and the user's location
+ * @param frequencyIndex of the radio reference frequencies near the user, for the trunked system sites, or null
+ * @param playlistActions to add sites to the playlist or enable their channels, or null
+ */
+ public MapPanel(MapService mapService, IconModel iconModel, UserPreferences userPreferences,
+ RadioReferenceFrequencyIndex frequencyIndex, RadioReferencePlaylistActions playlistActions)
+ {
+ Platform.setImplicitExit(false);
+ ThemeManager.getInstance().registerSwing(this);
+
+ Platform.runLater(() -> {
+ MapView view = new MapView(mapService, iconModel, userPreferences, frequencyIndex, playlistActions, true);
+ Scene scene = new Scene(view);
+ ThemeManager.getInstance().register(scene);
+ setScene(scene);
+ });
+ }
+}
diff --git a/src/main/java/io/github/dsheirer/gui/map/MapView.java b/src/main/java/io/github/dsheirer/gui/map/MapView.java
new file mode 100644
index 00000000..3c1dc96d
--- /dev/null
+++ b/src/main/java/io/github/dsheirer/gui/map/MapView.java
@@ -0,0 +1,1141 @@
+/*
+ * *****************************************************************************
+ * Copyright (C) 2014-2026 Dennis Sheirer
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * ****************************************************************************
+ */
+
+package io.github.dsheirer.gui.map;
+
+import com.google.common.eventbus.Subscribe;
+import io.github.dsheirer.controller.channel.Channel;
+import io.github.dsheirer.eventbus.MyEventBus;
+import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
+import io.github.dsheirer.icon.IconModel;
+import io.github.dsheirer.identifier.Form;
+import io.github.dsheirer.identifier.Identifier;
+import io.github.dsheirer.identifier.IdentifierClass;
+import io.github.dsheirer.identifier.Role;
+import io.github.dsheirer.map.GeoPosition;
+import io.github.dsheirer.map.IPlottableUpdateListener;
+import io.github.dsheirer.map.MapService;
+import io.github.dsheirer.map.PlottableEntityHistory;
+import io.github.dsheirer.map.PlottableEntityModel;
+import io.github.dsheirer.map.TimestampedGeoPosition;
+import io.github.dsheirer.preference.PreferenceType;
+import io.github.dsheirer.preference.UserPreferences;
+import io.github.dsheirer.preference.map.MapPreference;
+import io.github.dsheirer.preference.radioreference.RadioReferencePreference;
+import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex;
+import io.github.dsheirer.service.radioreference.SiteRecord;
+import java.awt.Desktop;
+import java.net.URI;
+import java.nio.file.Path;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import javafx.animation.PauseTransition;
+import javafx.application.Platform;
+import javafx.beans.property.ReadOnlyStringWrapper;
+import javafx.collections.FXCollections;
+import javafx.collections.ListChangeListener;
+import javafx.collections.ObservableList;
+import javafx.collections.transformation.SortedList;
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.Hyperlink;
+import javafx.scene.control.Label;
+import javafx.scene.control.MenuItem;
+import javafx.scene.control.SelectionMode;
+import javafx.scene.control.Separator;
+import javafx.scene.control.SeparatorMenuItem;
+import javafx.scene.control.Spinner;
+import javafx.scene.control.SpinnerValueFactory;
+import javafx.scene.control.SplitPane;
+import javafx.scene.control.Tab;
+import javafx.scene.control.TabPane;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.TextField;
+import javafx.scene.control.Tooltip;
+import javafx.scene.input.ContextMenuEvent;
+import javafx.scene.input.MouseEvent;
+import javafx.scene.input.ScrollEvent;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Pane;
+import javafx.scene.layout.Priority;
+import javafx.scene.layout.Region;
+import javafx.scene.layout.StackPane;
+import javafx.scene.layout.VBox;
+import javafx.util.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Map tab: plotted tracks of the radios that reported locations, the user's location and the radio reference trunked
+ * system sites near the user, with the track lists and map controls beside the map. Use on the JavaFX thread.
+ */
+public class MapView extends SplitPane
+{
+ private static final Duration SAVE_VIEW_DELAY = Duration.millis(500);
+ private static final Duration HOVER_DELAY = Duration.millis(400);
+ private static final double CONTROLS_WIDTH = 300;
+ private static final double CARD_OFFSET = 16;
+ private static final double CARD_MARGIN = 2;
+ private static final int MAX_MENU_SITES = 3;
+ //Shown when no location was ever stored: Syracuse, NY
+ private static final GeoPosition DEFAULT_CENTER = new GeoPosition(43.048, -76.147);
+ private static final String FOLLOW = "Follow";
+ private static final String UNFOLLOW = "Unfollow";
+ private static final String SELECT_A_TRACK = "(select a track)";
+ private static final String NO_SYSTEM_NAME = "(no system name)";
+ private static final String LOCATION_NOT_SET = "Not set";
+ private static final Logger mLog = LoggerFactory.getLogger(MapView.class);
+
+ private final MapService mMapService;
+ private final PlottableEntityModel mEntityModel;
+ private final UserPreferences mUserPreferences;
+ private final RadioReferenceFrequencyIndex mFrequencyIndex;
+ private final RadioReferencePlaylistActions mPlaylistActions;
+ private final TileMapView mMap;
+ private final TrackLayer mTrackLayer;
+ private final SiteLayer mSiteLayer;
+ private final UserLocationLayer mUserLocationLayer = new UserLocationLayer();
+ private final Pane mCardPane = new Pane();
+ private final PauseTransition mSaveViewTimer = new PauseTransition(SAVE_VIEW_DELAY);
+ private final PauseTransition mHoverTimer = new PauseTransition(HOVER_DELAY);
+ private final ObservableList mTracks = FXCollections.observableArrayList();
+ private final ObservableList mHistory = FXCollections.observableArrayList();
+
+ private final Label mUserLocationLabel = new Label(LOCATION_NOT_SET);
+ private final Button mSetUserLocationButton = new Button("Set Current");
+ private final Button mCenterOnUserLocationButton = new Button("Center On");
+ private final Spinner mZoomSpinner = new Spinner<>();
+ private final CheckBox mShowSitesCheckBox = new CheckBox("Radio Reference Sites");
+ private final Label mSiteCountLabel = new Label();
+ private final TableView mTrackTable = new TableView<>();
+ private final Button mDeleteTrackButton = new Button("Delete");
+ private final Button mDeleteAllTracksButton = new Button("Delete All");
+ private final Button mClearMapButton = new Button("Clear Map");
+ private final Button mReplotAllTracksButton = new Button("Replot All");
+ private final Button mFollowButton = new Button(FOLLOW);
+ private final Label mFollowedEntityLabel = new Label();
+ private final ComboBox mTrackHistoryLengthComboBox = new ComboBox<>();
+ private final CheckBox mCenterOnSelectedCheckBox = new CheckBox("Center on Selection");
+ private final Label mSelectedTrackSystemLabel = new Label(SELECT_A_TRACK);
+ private final TableView mHistoryTable = new TableView<>(mHistory);
+ private final ComboBox mTileServerComboBox = new ComboBox<>();
+ private final TextField mTileServerKeyField = new TextField();
+ private final Hyperlink mTileServerKeyLink = new Hyperlink("Get a free key");
+
+ private PlottableEntityHistory mSelectedTrack;
+ private PlottableEntityHistory mFollowedTrack;
+ //Location most recently chosen on the map, which doesn't re-center the map when the preference update arrives
+ private GeoPosition mMapChosenPosition;
+ private ContextMenu mContextMenu;
+ private Region mCard;
+ private List mCardSites = Collections.emptyList();
+ private double mHoverX;
+ private double mHoverY;
+ private boolean mRestoringHistorySelection;
+
+ /**
+ * Constructs an instance
+ * @param mapService for the entities to plot
+ * @param iconModel for alias icons
+ * @param userPreferences for the map view and the user's location, which is shared with the radio reference editor
+ * @param frequencyIndex of the radio reference frequencies near the user, for the trunked system sites, or null
+ * @param playlistActions to add sites to the playlist or enable their channels, or null
+ * @param loadTiles true to download map tiles, or false for a blank map (tests and off-screen rendering)
+ */
+ public MapView(MapService mapService, IconModel iconModel, UserPreferences userPreferences,
+ RadioReferenceFrequencyIndex frequencyIndex, RadioReferencePlaylistActions playlistActions,
+ boolean loadTiles)
+ {
+ mMapService = mapService;
+ mEntityModel = mapService.getPlottableEntityModel();
+ mUserPreferences = userPreferences;
+ mFrequencyIndex = frequencyIndex;
+ mPlaylistActions = playlistActions;
+
+ Path tileCache = userPreferences.getDirectoryPreference().getDirectoryApplicationRoot().resolve("map_tiles");
+ mMap = new TileMapView(tileCache, loadTiles);
+ mSiteLayer = new SiteLayer(frequencyIndex != null ? frequencyIndex::getSites : Collections::emptyList);
+ mSiteLayer.setShowSites(userPreferences.getMapPreference().isShowRadioReferenceSites());
+ mTrackLayer = new TrackLayer(mEntityModel, iconModel);
+
+ //Radio reference sites under the tracks, and the user's location pin over the tracks
+ mMap.addLayer(mSiteLayer);
+ mMap.addLayer(mTrackLayer);
+ mMap.addLayer(mUserLocationLayer);
+
+ initMap();
+ initControls();
+
+ mCardPane.setMouseTransparent(true);
+ mCardPane.setPickOnBounds(false);
+ StackPane mapPane = new StackPane(mMap, mCardPane);
+ mapPane.setMinSize(0, 0);
+
+ initTileServerControls();
+ updateTileSource();
+
+ TabPane controls = createControls();
+ SplitPane.setResizableWithParent(controls, false);
+ getItems().addAll(controls, mapPane);
+
+ //Start the divider at the controls' width once the split pane has a width
+ widthProperty().addListener((observable, oldValue, newValue) -> {
+ if(oldValue.doubleValue() <= 0 && newValue.doubleValue() > 0)
+ {
+ setDividerPositions(Math.min(0.5, CONTROLS_WIDTH / newValue.doubleValue()));
+ }
+ });
+
+ //Show the stored location without moving the map, which starts at the stored view
+ RadioReferencePreference.Location location = mUserPreferences.getRadioReferencePreference().getLocation();
+ mUserLocationLayer.setPosition(location != null ? toGeoPosition(location) : null);
+ updateUserLocationLabel(location);
+
+ if(mFrequencyIndex != null)
+ {
+ //The index fills in the background
+ mFrequencyIndex.addUpdateListener(() -> Platform.runLater(this::sitesUpdated));
+ }
+
+ sitesUpdated();
+
+ //Listen before taking the existing tracks, so none is missed. The FX thread drops duplicates.
+ mMapService.addListener(new EntityListener());
+
+ for(PlottableEntityHistory entity: mEntityModel.getAll())
+ {
+ entityAdded(entity);
+ }
+
+ MyEventBus.getGlobalEventBus().register(this);
+ }
+
+ /**
+ * Map, for tests and off-screen rendering
+ */
+ public TileMapView getMap()
+ {
+ return mMap;
+ }
+
+ /**
+ * Sets the starting view: the last view, else the user's location, else the default center
+ */
+ private void initMap()
+ {
+ MapPreference mapPreference = mUserPreferences.getMapPreference();
+ MapPreference.Center center = mapPreference.getCenter();
+ RadioReferencePreference.Location location = mUserPreferences.getRadioReferencePreference().getLocation();
+ GeoPosition initial;
+
+ if(center != null)
+ {
+ initial = new GeoPosition(center.latitude(), center.longitude());
+ }
+ else if(location != null)
+ {
+ initial = toGeoPosition(location);
+ }
+ else
+ {
+ initial = DEFAULT_CENTER;
+ }
+
+ mMap.setZoom(mapPreference.getTileZoom());
+ mMap.setCenter(initial);
+
+ //Remember the view after each pan or zoom, once the map stops moving
+ mSaveViewTimer.setOnFinished(event -> saveView());
+ mMap.addViewListener(() -> {
+ mSaveViewTimer.playFromStart();
+ hideCard();
+ });
+
+ mMap.setOnContextMenuRequested(this::showContextMenu);
+ mMap.addEventHandler(MouseEvent.MOUSE_MOVED, this::mouseMoved);
+ mMap.addEventHandler(MouseEvent.MOUSE_EXITED, event -> hideCard());
+ mMap.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
+ hideCard();
+
+ if(mContextMenu != null && !event.isPopupTrigger())
+ {
+ mContextMenu.hide();
+ }
+ });
+ mMap.addEventHandler(ScrollEvent.SCROLL, event -> hideCard());
+ mHoverTimer.setOnFinished(event -> showCard());
+ }
+
+ private void initControls()
+ {
+ mUserLocationLabel.setTooltip(new Tooltip());
+ mSetUserLocationButton.setTooltip(new Tooltip("Sets your location, which is also used by the playlist " +
+ "editor's Radio Reference tab, to the center of the map"));
+ mSetUserLocationButton.setOnAction(event -> setUserLocation(mMap.getCenter()));
+ mCenterOnUserLocationButton.setTooltip(new Tooltip("Centers the map on your location"));
+ mCenterOnUserLocationButton.setDisable(true);
+ mCenterOnUserLocationButton.setOnAction(event -> mMap.setCenter(mUserLocationLayer.getPosition()));
+
+ SpinnerValueFactory.IntegerSpinnerValueFactory zoomFactory = new SpinnerValueFactory
+ .IntegerSpinnerValueFactory(MapPreference.MINIMUM_TILE_ZOOM, MapPreference.MAXIMUM_TILE_ZOOM, mMap.getZoom());
+ mZoomSpinner.setValueFactory(zoomFactory);
+ mZoomSpinner.setPrefWidth(80);
+ mZoomSpinner.setTooltip(new Tooltip("Map zoom level: higher is closer. Scroll over the map to zoom."));
+ zoomFactory.valueProperty().addListener((observable, oldValue, newValue) -> {
+ if(newValue != null)
+ {
+ mMap.setZoom(newValue);
+ }
+ });
+ mMap.zoomProperty().addListener((observable, oldValue, newValue) -> zoomFactory.setValue(newValue.intValue()));
+
+ mShowSitesCheckBox.setSelected(mSiteLayer.isShowSites());
+ mShowSitesCheckBox.setDisable(mFrequencyIndex == null);
+ mShowSitesCheckBox.setTooltip(new Tooltip("Show the trunked radio system sites within " +
+ (int)RadioReferenceFrequencyIndex.RADIUS_KILOMETERS + " km of your location. Requires a premium " +
+ "Radio Reference login and your location."));
+ mShowSitesCheckBox.setOnAction(event -> {
+ boolean show = mShowSitesCheckBox.isSelected();
+ mSiteLayer.setShowSites(show);
+ mUserPreferences.getMapPreference().setShowRadioReferenceSites(show);
+ hideCard();
+ mMap.requestRedraw();
+ });
+
+ initTrackTable();
+
+ mDeleteTrackButton.setDisable(true);
+ mDeleteTrackButton.setOnAction(event ->
+ mEntityModel.delete(new ArrayList<>(mTrackTable.getSelectionModel().getSelectedItems())));
+ mDeleteAllTracksButton.setOnAction(event -> {
+ mEntityModel.deleteAllTracks();
+ mTrackLayer.clear();
+ follow(null);
+ mMap.requestRedraw();
+ });
+ mClearMapButton.setTooltip(new Tooltip("Removes the tracks from the map. A track returns when it reports " +
+ "a new location, or with Replot All."));
+ mClearMapButton.setOnAction(event -> {
+ mTrackLayer.clear();
+ mMap.requestRedraw();
+ });
+ mReplotAllTracksButton.setOnAction(event -> {
+ if(mTrackLayer.addAll(mEntityModel.getAll()))
+ {
+ mMap.requestRedraw();
+ }
+ });
+ mFollowButton.setDisable(true);
+ mFollowButton.setTooltip(new Tooltip("Keeps the map centered on the selected track as it moves"));
+ mFollowButton.setOnAction(event -> follow(mFollowedTrack == null ? mSelectedTrack : null));
+
+ for(int length = 1; length <= 10; length++)
+ {
+ mTrackHistoryLengthComboBox.getItems().add(length);
+ }
+
+ mTrackHistoryLengthComboBox.setValue(mTrackLayer.getTrackHistoryLength());
+ mTrackHistoryLengthComboBox.setOnAction(event -> {
+ Integer length = mTrackHistoryLengthComboBox.getValue();
+
+ if(length != null)
+ {
+ mTrackLayer.setTrackHistoryLength(length);
+ mMap.requestRedraw();
+ }
+ });
+
+ mCenterOnSelectedCheckBox.setSelected(true);
+
+ initHistoryTable();
+ }
+
+ private void initTrackTable()
+ {
+ TableColumn id = new TableColumn<>("ID");
+ id.setCellValueFactory(cell -> new ReadOnlyStringWrapper(cell.getValue().getIdentifier() != null ?
+ cell.getValue().getIdentifier().toString() : "(no ID)"));
+ TableColumn alias = new TableColumn<>("Alias");
+ alias.setCellValueFactory(cell -> new ReadOnlyStringWrapper(mEntityModel.getAliasName(cell.getValue())));
+ TableColumn list = new TableColumn<>("List");
+ list.setCellValueFactory(cell ->
+ new ReadOnlyStringWrapper(PlottableEntityModel.getAliasListName(cell.getValue())));
+ mTrackTable.getColumns().addAll(List.of(id, alias, list));
+ mTrackTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN);
+ mTrackTable.setPlaceholder(new Label("No tracks"));
+ mTrackTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
+
+ SortedList sorted = new SortedList<>(mTracks);
+ sorted.comparatorProperty().bind(mTrackTable.comparatorProperty());
+ mTrackTable.setItems(sorted);
+
+ mTrackTable.getSelectionModel().getSelectedItems().addListener(
+ (ListChangeListener)change ->
+ mDeleteTrackButton.setDisable(mTrackTable.getSelectionModel().getSelectedItems().isEmpty()));
+ //The selected item is updated after the selected items list changes, so it has its own listener
+ mTrackTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
+ if(newValue != mSelectedTrack)
+ {
+ setSelected(newValue);
+ }
+
+ //Refresh the followed entity button and label
+ follow(mFollowedTrack);
+ });
+ }
+
+ private void initHistoryTable()
+ {
+ SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ DecimalFormat degreeFormat = new DecimalFormat("0.00000");
+ TableColumn time = new TableColumn<>("Time");
+ time.setCellValueFactory(cell -> new ReadOnlyStringWrapper(timeFormat.format(cell.getValue().getTimestamp())));
+ TableColumn latitude = new TableColumn<>("Latitude");
+ latitude.setCellValueFactory(cell ->
+ new ReadOnlyStringWrapper(degreeFormat.format(cell.getValue().getLatitude())));
+ TableColumn longitude = new TableColumn<>("Longitude");
+ longitude.setCellValueFactory(cell ->
+ new ReadOnlyStringWrapper(degreeFormat.format(cell.getValue().getLongitude())));
+ time.setPrefWidth(130);
+ latitude.setPrefWidth(75);
+ longitude.setPrefWidth(80);
+ mHistoryTable.getColumns().addAll(List.of(time, latitude, longitude));
+ mHistoryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN);
+ mHistoryTable.setPlaceholder(new Label("Select a track"));
+ mHistoryTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
+ if(newValue != null && !mRestoringHistorySelection && mCenterOnSelectedCheckBox.isSelected() &&
+ mFollowedTrack == null)
+ {
+ mMap.setCenter(newValue);
+ }
+ });
+ }
+
+ /**
+ * Tabs beside the map: Settings for how the map looks, and Tracks for the plotted tracks
+ */
+ private TabPane createControls()
+ {
+ HBox server = row(new Label("Tile Server:"), mTileServerComboBox);
+ HBox serverKey = row(mTileServerKeyField, mTileServerKeyLink);
+ HBox location = row(new Label("My Location:"), mUserLocationLabel);
+ HBox locationButtons = row(mSetUserLocationButton, mCenterOnUserLocationButton);
+ HBox zoom = row(new Label("Zoom:"), mZoomSpinner);
+ HBox sites = row(mShowSitesCheckBox, mSiteCountLabel);
+ HBox historyLength = row(new Label("Track History Length:"), mTrackHistoryLengthComboBox);
+
+ HBox.setHgrow(mTileServerComboBox, Priority.ALWAYS);
+ mTileServerComboBox.setMaxWidth(Double.MAX_VALUE);
+ HBox.setHgrow(mTileServerKeyField, Priority.ALWAYS);
+ serverKey.visibleProperty().bind(mTileServerKeyField.visibleProperty());
+ serverKey.managedProperty().bind(mTileServerKeyField.managedProperty());
+
+ Label layers = new Label("Layers");
+ layers.setStyle("-fx-font-weight: bold;");
+
+ VBox settings = tabContent(server, serverKey, new Separator(), location, locationButtons, new Separator(),
+ zoom, new Separator(), layers, sites);
+
+ HBox trackButtons = row(mDeleteTrackButton, mDeleteAllTracksButton, mClearMapButton);
+ HBox followButtons = row(mReplotAllTracksButton, mFollowButton, mFollowedEntityLabel);
+ HBox selectedSystem = row(new Label("Selected System:"), mSelectedTrackSystemLabel);
+
+ VBox.setVgrow(mTrackTable, Priority.ALWAYS);
+ VBox.setVgrow(mHistoryTable, Priority.ALWAYS);
+ mTrackTable.setMinHeight(80);
+ mHistoryTable.setMinHeight(80);
+
+ VBox tracks = tabContent(mTrackTable, trackButtons, followButtons, historyLength, mCenterOnSelectedCheckBox,
+ selectedSystem, mHistoryTable);
+
+//Uncomment this line to add a debug track generator button to the tracks tab
+// tracks.getChildren().add(createTrackGeneratorToggle());
+
+ Tab settingsTab = new Tab("Settings", settings);
+ Tab tracksTab = new Tab("Tracks", tracks);
+ TabPane tabs = new TabPane(settingsTab, tracksTab);
+ tabs.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
+ tabs.setMinWidth(220);
+ tabs.setPrefWidth(CONTROLS_WIDTH);
+ return tabs;
+ }
+
+ private static VBox tabContent(javafx.scene.Node... nodes)
+ {
+ VBox content = new VBox(6, nodes);
+ content.setPadding(new Insets(6));
+ return content;
+ }
+
+ private static HBox row(javafx.scene.Node... nodes)
+ {
+ HBox row = new HBox(6, nodes);
+ row.setAlignment(Pos.CENTER_LEFT);
+ return row;
+ }
+
+ /**
+ * Debug toggle that starts and stops a generator of test tracks
+ */
+ @SuppressWarnings("unused")
+ private javafx.scene.control.ToggleButton createTrackGeneratorToggle()
+ {
+ io.github.dsheirer.map.TrackGenerator generator = new io.github.dsheirer.map.TrackGenerator(mMapService);
+ javafx.scene.control.ToggleButton toggle = new javafx.scene.control.ToggleButton("Track Generator");
+ toggle.setOnAction(event -> {
+ if(toggle.isSelected())
+ {
+ generator.start();
+ }
+ else
+ {
+ generator.stop();
+ }
+ });
+ return toggle;
+ }
+
+ /**
+ * Tile server chooser, with a key field and a link to get a key for a server that needs one
+ */
+ private void initTileServerControls()
+ {
+ MapPreference preference = mUserPreferences.getMapPreference();
+ mTileServerComboBox.getItems().setAll(TileChoice.CHOICES);
+ mTileServerComboBox.setValue(TileChoice.get(preference.getTileServer(), preference.getTileStyle()));
+ mTileServerComboBox.setVisibleRowCount(TileChoice.CHOICES.size());
+ mTileServerComboBox.setTooltip(new Tooltip("Map tile server. Auto follows the theme, " +
+ "Light and Dark always use that style. Servers without a dark style are recolored for dark tiles."));
+ mTileServerComboBox.setOnAction(event -> {
+ TileChoice choice = mTileServerComboBox.getValue();
+
+ if(choice != null)
+ {
+ preference.setTileServer(choice.server().id());
+ preference.setTileStyle(choice.style().name());
+ updateTileSource();
+ }
+ });
+
+ mTileServerKeyField.setPromptText("API key");
+ mTileServerKeyField.setTooltip(new Tooltip("Free API key for this tile server, from the link beside it"));
+ mTileServerKeyField.setOnAction(event -> saveTileServerKey());
+ mTileServerKeyField.focusedProperty().addListener((observable, oldValue, focused) -> {
+ if(!focused)
+ {
+ saveTileServerKey();
+ }
+ });
+ mTileServerKeyLink.setOnAction(event -> {
+ TileServer server = getTileServer();
+
+ if(server != null && server.keyUrl() != null)
+ {
+ browse(server.keyUrl());
+ }
+ });
+ }
+
+ /**
+ * Stores the key the user entered for the selected server and reloads the tiles with it
+ */
+ private void saveTileServerKey()
+ {
+ TileServer server = getTileServer();
+
+ if(server != null && server.requiresKey())
+ {
+ mUserPreferences.getMapPreference().setTileServerKey(server.id(), mTileServerKeyField.getText());
+ updateTileSource();
+ }
+ }
+
+ /**
+ * Shows the selected server's tiles in the chosen style, or the style for the current theme, and its key field when it needs a key
+ */
+ private void updateTileSource()
+ {
+ TileChoice choice = mTileServerComboBox.getValue() != null ? mTileServerComboBox.getValue() :
+ TileChoice.CHOICES.getFirst();
+ TileServer server = choice.server();
+ String key = server.requiresKey() ? mUserPreferences.getMapPreference().getTileServerKey(server.id()) : null;
+
+ mTileServerKeyField.setVisible(server.requiresKey());
+ mTileServerKeyField.setManaged(server.requiresKey());
+
+ if(server.requiresKey() && !mTileServerKeyField.isFocused())
+ {
+ mTileServerKeyField.setText(key != null ? key : "");
+ }
+
+ mMap.setSource(choice.getSource(mUserPreferences.getApplicationPreference().isDarkMode(), key));
+ }
+
+ /**
+ * Server of the selected tile choice
+ */
+ private TileServer getTileServer()
+ {
+ TileChoice choice = mTileServerComboBox.getValue();
+ return choice != null ? choice.server() : TileServer.OPEN_STREET_MAP;
+ }
+
+ /**
+ * Opens the web page in the user's browser, off the JavaFX thread
+ */
+ private static void browse(String url)
+ {
+ Thread.ofVirtual().start(() -> {
+ try
+ {
+ if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE))
+ {
+ Desktop.getDesktop().browse(URI.create(url));
+ }
+ }
+ catch(Exception e)
+ {
+ mLog.warn("Unable to open [" + url + "] - " + e.getMessage());
+ }
+ });
+ }
+
+ /**
+ * Updates the site count and redraws the sites
+ */
+ private void sitesUpdated()
+ {
+ int count = mFrequencyIndex != null ? mFrequencyIndex.getSites().size() : 0;
+ mSiteCountLabel.setText(count == 1 ? "1 site" : count + " sites");
+ hideCard();
+ mMap.requestRedraw();
+ }
+
+ /**
+ * Updates the user's location on the map when it changes, here or in the radio reference editor
+ * @param preferenceType that was updated
+ */
+ @Subscribe
+ public void preferenceUpdated(PreferenceType preferenceType)
+ {
+ if(preferenceType == PreferenceType.RADIO_REFERENCE)
+ {
+ Platform.runLater(this::updateUserLocation);
+ }
+ else if(preferenceType == PreferenceType.APPLICATION)
+ {
+ //The theme may have changed between light and dark
+ Platform.runLater(this::updateTileSource);
+ }
+ }
+
+ /**
+ * Shows the user's location on the map. When the location changes, the map centers on it, unless it was chosen on
+ * the map. Clearing the location removes the pin and leaves the map as is.
+ */
+ private void updateUserLocation()
+ {
+ RadioReferencePreference.Location location = mUserPreferences.getRadioReferencePreference().getLocation();
+ GeoPosition position = location != null ? toGeoPosition(location) : null;
+ updateUserLocationLabel(location);
+
+ if(!Objects.equals(position, mUserLocationLayer.getPosition()))
+ {
+ mUserLocationLayer.setPosition(position);
+
+ //A location chosen on the map is already in view
+ if(position != null && !position.equals(mMapChosenPosition))
+ {
+ mMap.setCenter(position);
+ }
+
+ mMapChosenPosition = null;
+ mMap.requestRedraw();
+ }
+ }
+
+ private void updateUserLocationLabel(RadioReferencePreference.Location location)
+ {
+ mUserLocationLabel.setText(location != null ? location.coordinates() : LOCATION_NOT_SET);
+ mCenterOnUserLocationButton.setDisable(location == null);
+ mUserLocationLabel.getTooltip().setText(location != null ? location.describe() :
+ "Set your location with the Set Current button or in the playlist editor's Radio Reference tab");
+ }
+
+ /**
+ * Sets the user's location to a point chosen on the map, with the Set Current button or the map's 'Set My Location
+ * Here' menu item. The pin, the location label and the radio reference editor follow through the preference
+ * update. The map isn't re-centered, since the point is already in view.
+ * @param position chosen on the map
+ */
+ private void setUserLocation(GeoPosition position)
+ {
+ double latitude = round(position.getLatitude());
+ double longitude = round(Mercator.normalizeLongitude(position.getLongitude()));
+
+ if(RadioReferencePreference.Location.isValid(latitude, longitude))
+ {
+ mMapChosenPosition = new GeoPosition(latitude, longitude);
+ mUserPreferences.getRadioReferencePreference()
+ .setLocation(new RadioReferencePreference.Location(latitude, longitude, null));
+ }
+ }
+
+ /**
+ * Stores the map's center point and zoom level, so the map shows the same view when the application starts
+ */
+ private void saveView()
+ {
+ GeoPosition center = mMap.getCenter();
+ MapPreference preference = mUserPreferences.getMapPreference();
+
+ try
+ {
+ preference.setCenter(new MapPreference.Center(round(center.getLatitude()),
+ round(Mercator.normalizeLongitude(center.getLongitude()))));
+ }
+ catch(IllegalArgumentException e)
+ {
+ //Not a storable position - keep the previous center
+ }
+
+ preference.setTileZoom(mMap.getZoom());
+ }
+
+ /**
+ * Rounds degrees to six decimal places (about 0.1 meter)
+ */
+ private static double round(double degrees)
+ {
+ return Math.round(degrees * 1_000_000.0) / 1_000_000.0;
+ }
+
+ private static GeoPosition toGeoPosition(RadioReferencePreference.Location location)
+ {
+ return new GeoPosition(location.latitude(), location.longitude());
+ }
+
+ private void setSelected(PlottableEntityHistory selected)
+ {
+ mSelectedTrack = selected;
+ updateHistory();
+
+ if(selected != null)
+ {
+ Identifier system = selected.getIdentifierCollection().getIdentifier(IdentifierClass.CONFIGURATION,
+ Form.SYSTEM, Role.ANY);
+ mSelectedTrackSystemLabel.setText(system != null ? system.toString() : NO_SYSTEM_NAME);
+
+ if(mTrackLayer.add(selected))
+ {
+ mMap.requestRedraw();
+ }
+
+ //While following, the map stays on the followed track
+ if(mCenterOnSelectedCheckBox.isSelected() && mFollowedTrack == null)
+ {
+ centerOn(selected);
+ }
+ }
+ else
+ {
+ mSelectedTrackSystemLabel.setText(SELECT_A_TRACK);
+ }
+ }
+
+ /**
+ * Shows the selected track's location history
+ */
+ private void updateHistory()
+ {
+ if(mSelectedTrack != null)
+ {
+ TimestampedGeoPosition selected = mHistoryTable.getSelectionModel().getSelectedItem();
+ mHistory.setAll(mSelectedTrack.getTrackHistoryModel().getTrackHistory());
+
+ //Keep the selected row, without centering on it again
+ if(selected != null && mHistory.contains(selected))
+ {
+ mRestoringHistorySelection = true;
+ mHistoryTable.getSelectionModel().select(selected);
+ mRestoringHistorySelection = false;
+ }
+ }
+ else
+ {
+ mHistory.clear();
+ }
+ }
+
+ private void centerOn(PlottableEntityHistory entityHistory)
+ {
+ if(entityHistory != null && entityHistory.getLatestPosition() != null)
+ {
+ mMap.setCenter(entityHistory.getLatestPosition());
+ }
+ }
+
+ /**
+ * Follows an entity, keeping the map centered on it as it reports new locations, or stops following
+ * @param entityHistory to follow, or null to stop following
+ */
+ private void follow(PlottableEntityHistory entityHistory)
+ {
+ boolean changed = entityHistory != mFollowedTrack;
+ mFollowedTrack = entityHistory;
+
+ if(mFollowedTrack != null)
+ {
+ if(changed)
+ {
+ centerOn(mFollowedTrack);
+ }
+
+ mFollowButton.setText(UNFOLLOW);
+ mFollowButton.setDisable(false);
+ mFollowedEntityLabel.setText("Following: " + mFollowedTrack.getIdentifier());
+ //Disabled while following
+ mCenterOnSelectedCheckBox.setDisable(true);
+ }
+ else
+ {
+ mFollowButton.setText(FOLLOW);
+ mFollowButton.setDisable(mSelectedTrack == null);
+ mFollowedEntityLabel.setText(null);
+ mCenterOnSelectedCheckBox.setDisable(false);
+ }
+ }
+
+ private void entityAdded(PlottableEntityHistory entity)
+ {
+ if(!mTracks.contains(entity))
+ {
+ mTracks.add(entity);
+ }
+
+ mTrackLayer.add(entity);
+ mMap.requestRedraw();
+ }
+
+ private void entityUpdated(PlottableEntityHistory entity)
+ {
+ if(!mTracks.contains(entity))
+ {
+ //Deleted while the update was on its way
+ return;
+ }
+
+ //A cleared track returns when it reports a new location
+ mTrackLayer.add(entity);
+ mTrackTable.refresh();
+
+ if(entity == mSelectedTrack)
+ {
+ updateHistory();
+ }
+
+ if(entity == mFollowedTrack)
+ {
+ centerOn(entity);
+ }
+
+ mMap.requestRedraw();
+ }
+
+ private void entitiesRemoved(List entities)
+ {
+ mTracks.removeAll(entities);
+ mTrackLayer.removeAll(entities);
+
+ if(mFollowedTrack != null && entities.contains(mFollowedTrack))
+ {
+ follow(null);
+ }
+
+ mMap.requestRedraw();
+ }
+
+ /**
+ * Context menu for the point on the map: the radio reference site actions, then 'Set My Location Here'
+ */
+ private void showContextMenu(ContextMenuEvent event)
+ {
+ hideCard();
+
+ if(mContextMenu != null)
+ {
+ mContextMenu.hide();
+ }
+
+ GeoPosition position = mMap.getViewport().getPosition(event.getX(), event.getY());
+ ContextMenu menu = new ContextMenu();
+ List
- *
- *
- * You will notice that "getFoo()" is used in the setFoo method rather than
- * accessing "foo" directly for the gets. This is done intentionally so that if
- * a subclass overrides getFoo() to return, for instance, a constant value the
- * property change notification system will continue to work properly.
- *
- *
- *
- * The firePropertyChange method takes into account the old value and the new
- * value. Only if the two differ will it fire a property change event. So you
- * can be assured from the above code fragment that a property change event will
- * only occur if old is indeed different from getFoo()
- *
- *
- *
- * AbstractBean also supports vetoable
- * {@link PropertyChangeEvent} events. These events are similar to
- * PropertyChange events, except a special exception can be used
- * to veto changing the property. For example, perhaps the property is changing
- * from "fred" to "red", but a listener deems that "red" is unexceptable. In
- * this case, the listener can fire a veto exception and the property must
- * remain "fred". For example:
- *
- *
- * public class ABean extends AbstractBean {
- * private String foo;
- *
- * public void setFoo(String newFoo) throws PropertyVetoException {
- * String old = getFoo();
- * this.foo = newFoo;
- * fireVetoableChange("foo", old, getFoo());
- * }
- * public String getFoo() {
- * return foo;
- * }
- * }
- *
- * public class Tester {
- * public static void main(String... args) {
- * try {
- * ABean a = new ABean();
- * a.setFoo("fred");
- * a.addVetoableChangeListener(new VetoableChangeListener() {
- * public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
- * if ("red".equals(evt.getNewValue()) {
- * throw new PropertyVetoException("Cannot be red!", evt);
- * }
- * }
- * }
- * a.setFoo("red");
- * } catch (Exception e) {
- * e.printStackTrace(); // this will be executed
- * }
- * }
- * }
- *
- *
- *
- *
- * {@code AbstractBean} is not {@link java.io.Serializable}. Special care must
- * be taken when creating {@code Serializable} subclasses, as the
- * {@code Serializable} listeners will not be saved. Subclasses will need to
- * manually save the serializable listeners. The {@link AbstractSerializableBean}
- * is {@code Serializable} and already handles the listeners correctly. If
- * possible, it is recommended that {@code Serializable} beans should extend
- * {@code AbstractSerializableBean}. If it is not possible, the
- * {@code AbstractSerializableBean} bean implementation provides details on
- * how to correctly serialize an {@code AbstractBean} subclass.
- *
- *
- * @see AbstractSerializableBean
- * @status REVIEWED
- * @author rbair
- */
-@SuppressWarnings("nls")
-public abstract class AbstractBean {
- /**
- * Helper class that manages all the property change notification machinery.
- * PropertyChangeSupport cannot be extended directly because it requires
- * a bean in the constructor, and the "this" argument is not valid until
- * after super construction. Hence, delegation instead of extension
- */
- private transient PropertyChangeSupport pcs;
-
- /**
- * Helper class that manages all the veto property change notification machinery.
- */
- private transient VetoableChangeSupport vcs;
-
- /** Creates a new instance of AbstractBean */
- protected AbstractBean() {
- pcs = new PropertyChangeSupport(this);
- vcs = new VetoableChangeSupport(this);
- }
-
- /**
- * Creates a new instance of AbstractBean, using the supplied PropertyChangeSupport and
- * VetoableChangeSupport delegates. Neither of these may be null.
- * @param pcs the property change support
- * @param vcs the vetoable change support
- */
- protected AbstractBean(PropertyChangeSupport pcs, VetoableChangeSupport vcs) {
- if (pcs == null) {
- throw new NullPointerException("PropertyChangeSupport must not be null");
- }
- if (vcs == null) {
- throw new NullPointerException("VetoableChangeSupport must not be null");
- }
-
- this.pcs = pcs;
- this.vcs = vcs;
- }
-
- /**
- * Add a PropertyChangeListener to the listener list.
- * The listener is registered for all properties.
- * The same listener object may be added more than once, and will be called
- * as many times as it is added.
- * If listener is null, no exception is thrown and no action
- * is taken.
- *
- * @param listener The PropertyChangeListener to be added
- */
- public final void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- /**
- * Remove a PropertyChangeListener from the listener list.
- * This removes a PropertyChangeListener that was registered
- * for all properties.
- * If listener was added more than once to the same event
- * source, it will be notified one less time after being removed.
- * If listener is null, or was never added, no exception is
- * thrown and no action is taken.
- *
- * @param listener The PropertyChangeListener to be removed
- */
- public final void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- /**
- * Returns an array of all the listeners that were added to the
- * PropertyChangeSupport object with addPropertyChangeListener().
- *
- * If some listeners have been added with a named property, then
- * the returned array will be a mixture of PropertyChangeListeners
- * and PropertyChangeListenerProxys. If the calling
- * method is interested in distinguishing the listeners then it must
- * test each element to see if it's a
- * PropertyChangeListenerProxy, perform the cast, and examine
- * the parameter.
- *
- *
- * PropertyChangeListener[] listeners = bean.getPropertyChangeListeners();
- * for (int i = 0; i < listeners.length; i++) {
- * if (listeners[i] instanceof PropertyChangeListenerProxy) {
- * PropertyChangeListenerProxy proxy =
- * (PropertyChangeListenerProxy)listeners[i];
- * if (proxy.getPropertyName().equals("foo")) {
- * // proxy is a PropertyChangeListener which was associated
- * // with the property named "foo"
- * }
- * }
- * }
- *
- *
- * @see java.beans.PropertyChangeListenerProxy
- * @return all of the PropertyChangeListeners added or an
- * empty array if no listeners have been added
- */
- public final PropertyChangeListener[] getPropertyChangeListeners() {
- return pcs.getPropertyChangeListeners();
- }
-
- /**
- * Add a PropertyChangeListener for a specific property. The listener
- * will be invoked only when a call on firePropertyChange names that
- * specific property.
- * The same listener object may be added more than once. For each
- * property, the listener will be invoked the number of times it was added
- * for that property.
- * If propertyName or listener is null, no
- * exception is thrown and no action is taken.
- *
- * @param propertyName The name of the property to listen on.
- * @param listener The PropertyChangeListener to be added
- */
- public final void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- /**
- * Remove a PropertyChangeListener for a specific property.
- * If listener was added more than once to the same event
- * source for the specified property, it will be notified one less time
- * after being removed.
- * If propertyName is null, no exception is thrown and no
- * action is taken.
- * If listener is null, or was never added for the specified
- * property, no exception is thrown and no action is taken.
- *
- * @param propertyName The name of the property that was listened on.
- * @param listener The PropertyChangeListener to be removed
- */
- public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
- /**
- * Returns an array of all the listeners which have been associated
- * with the named property.
- *
- * @param propertyName The name of the property being listened to
- * @return all of the PropertyChangeListeners associated with
- * the named property. If no such listeners have been added,
- * or if propertyName is null, an empty array is
- * returned.
- */
- public final PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
- return pcs.getPropertyChangeListeners(propertyName);
- }
-
- /**
- * Report a bound property update to any registered listeners.
- * No event is fired if old and new are equal and non-null.
- *
- *
- * This is merely a convenience wrapper around the more general
- * firePropertyChange method that takes {@code
- * PropertyChangeEvent} value.
- *
- * @param propertyName The programmatic name of the property
- * that was changed.
- * @param oldValue The old value of the property.
- * @param newValue The new value of the property.
- */
- protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- pcs.firePropertyChange(propertyName, oldValue, newValue);
- }
-
- /**
- * Fire an existing PropertyChangeEvent to any registered listeners.
- * No event is fired if the given event's old and new values are
- * equal and non-null.
- * @param evt The PropertyChangeEvent object.
- */
- protected final void firePropertyChange(PropertyChangeEvent evt) {
- pcs.firePropertyChange(evt);
- }
-
-
- /**
- * Report a bound indexed property update to any registered
- * listeners.
- *
- * No event is fired if old and new values are equal
- * and non-null.
- *
- *
- * This is merely a convenience wrapper around the more general
- * firePropertyChange method that takes {@code PropertyChangeEvent} value.
- *
- * @param propertyName The programmatic name of the property that
- * was changed.
- * @param index index of the property element that was changed.
- * @param oldValue The old value of the property.
- * @param newValue The new value of the property.
- */
- protected final void fireIndexedPropertyChange(String propertyName, int index,
- Object oldValue, Object newValue) {
- pcs.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
- }
-
- /**
- * Check if there are any listeners for a specific property, including
- * those registered on all properties. If propertyName
- * is null, only check for listeners registered on all properties.
- *
- * @param propertyName the property name.
- * @return true if there are one or more listeners for the given property
- */
- protected final boolean hasPropertyChangeListeners(String propertyName) {
- return pcs.hasListeners(propertyName);
- }
-
- /**
- * Check if there are any listeners for a specific property, including
- * those registered on all properties. If propertyName
- * is null, only check for listeners registered on all properties.
- *
- * @param propertyName the property name.
- * @return true if there are one or more listeners for the given property
- */
- protected final boolean hasVetoableChangeListeners(String propertyName) {
- return vcs.hasListeners(propertyName);
- }
-
- /**
- * Add a VetoableListener to the listener list.
- * The listener is registered for all properties.
- * The same listener object may be added more than once, and will be called
- * as many times as it is added.
- * If listener is null, no exception is thrown and no action
- * is taken.
- *
- * @param listener The VetoableChangeListener to be added
- */
-
- public final void addVetoableChangeListener(VetoableChangeListener listener) {
- vcs.addVetoableChangeListener(listener);
- }
-
- /**
- * Remove a VetoableChangeListener from the listener list.
- * This removes a VetoableChangeListener that was registered
- * for all properties.
- * If listener was added more than once to the same event
- * source, it will be notified one less time after being removed.
- * If listener is null, or was never added, no exception is
- * thrown and no action is taken.
- *
- * @param listener The VetoableChangeListener to be removed
- */
- public final void removeVetoableChangeListener(VetoableChangeListener listener) {
- vcs.removeVetoableChangeListener(listener);
- }
-
- /**
- * Returns the list of VetoableChangeListeners. If named vetoable change listeners
- * were added, then VetoableChangeListenerProxy wrappers will returned
- *
- * @return List of VetoableChangeListeners and VetoableChangeListenerProxys
- * if named property change listeners were added.
- */
- public final VetoableChangeListener[] getVetoableChangeListeners(){
- return vcs.getVetoableChangeListeners();
- }
-
- /**
- * Add a VetoableChangeListener for a specific property. The listener
- * will be invoked only when a call on fireVetoableChange names that
- * specific property.
- * The same listener object may be added more than once. For each
- * property, the listener will be invoked the number of times it was added
- * for that property.
- * If propertyName or listener is null, no
- * exception is thrown and no action is taken.
- *
- * @param propertyName The name of the property to listen on.
- * @param listener The VetoableChangeListener to be added
- */
-
- public final void addVetoableChangeListener(String propertyName,
- VetoableChangeListener listener) {
- vcs.addVetoableChangeListener(propertyName, listener);
- }
-
- /**
- * Remove a VetoableChangeListener for a specific property.
- * If listener was added more than once to the same event
- * source for the specified property, it will be notified one less time
- * after being removed.
- * If propertyName is null, no exception is thrown and no
- * action is taken.
- * If listener is null, or was never added for the specified
- * property, no exception is thrown and no action is taken.
- *
- * @param propertyName The name of the property that was listened on.
- * @param listener The VetoableChangeListener to be removed
- */
-
- public final void removeVetoableChangeListener(String propertyName,
- VetoableChangeListener listener) {
- vcs.removeVetoableChangeListener(propertyName, listener);
- }
-
- /**
- * Returns an array of all the listeners which have been associated
- * with the named property.
- *
- * @param propertyName The name of the property being listened to
- * @return all the VetoableChangeListeners associated with
- * the named property. If no such listeners have been added,
- * or if propertyName is null, an empty array is
- * returned.
- */
- public final VetoableChangeListener[] getVetoableChangeListeners(String propertyName) {
- return vcs.getVetoableChangeListeners(propertyName);
- }
-
- /**
- * Report a vetoable property update to any registered listeners. If
- * anyone vetos the change, then fire a new event reverting everyone to
- * the old value and then rethrow the PropertyVetoException.
- *
- * No event is fired if old and new are equal and non-null.
- *
- * @param propertyName The programmatic name of the property
- * that is about to change..
- * @param oldValue The old value of the property.
- * @param newValue The new value of the property.
- * @exception PropertyVetoException if the recipient wishes the property
- * change to be rolled back.
- */
- protected final void fireVetoableChange(String propertyName,
- Object oldValue, Object newValue)
- throws PropertyVetoException {
- vcs.fireVetoableChange(propertyName, oldValue, newValue);
- }
-
- /**
- * Fire a vetoable property update to any registered listeners. If
- * anyone vetos the change, then fire a new event reverting everyone to
- * the old value and then rethrow the PropertyVetoException.
- *
- * No event is fired if old and new are equal and non-null.
- *
- * @param evt The PropertyChangeEvent to be fired.
- * @exception PropertyVetoException if the recipient wishes the property
- * change to be rolled back.
- */
- protected final void fireVetoableChange(PropertyChangeEvent evt)
- throws PropertyVetoException {
- vcs.fireVetoableChange(evt);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object clone() throws CloneNotSupportedException {
- AbstractBean result = (AbstractBean) super.clone();
- result.pcs = new PropertyChangeSupport(result);
- result.vcs = new VetoableChangeSupport(result);
- return result;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/org/jdesktop/beans/AbstractSerializableBean.java b/src/main/java/org/jdesktop/beans/AbstractSerializableBean.java
deleted file mode 100644
index 31c6c14a..00000000
--- a/src/main/java/org/jdesktop/beans/AbstractSerializableBean.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * $Id: AbstractSerializableBean.java 4088 2011-11-17 19:53:49Z kschaefe $
- *
- * Copyright 2008 Sun Microsystems, Inc., 4150 Network Circle,
- * Santa Clara, California 95054, U.S.A. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.jdesktop.beans;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.beans.VetoableChangeListener;
-import java.beans.VetoableChangeSupport;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
-/**
- * This subclass enhances {@code AbstractBean} by implementing the
- * {@code Serializable} interface. {@code AbstractSerializableBean} correctly
- * serializes all {@code Serializable} listeners that it contains. Implementors
- * that need to extends {@code AbstractBean} or one of its subclasses and
- * require serialization should use this class if possible. If it is not
- * possible to extend this class, the implementation can guide implementors on
- * how to properly serialize the listeners.
- *
- * @author Karl George Schaefer
- *
- * @see Serializable
- * @see ObjectInputStream
- * @see ObjectOutputStream
- */
-@SuppressWarnings("serial")
-public abstract class AbstractSerializableBean extends AbstractBean implements
- Serializable {
- /**
- * Creates a new instance of {@code AbstractSerializableBean}.
- */
- protected AbstractSerializableBean() {
- super();
- }
-
- /**
- * Creates a new instance of {@code AbstractSerializableBean}, using the
- * supplied support delegates. Neither of these may be {@code null}.
- *
- * @param pcs
- * the property change support class to use
- * @param vcs
- * the vetoable change support class to use
- * @throws NullPointerException
- * if any parameter is {@code null}
- */
- protected AbstractSerializableBean(PropertyChangeSupport pcs,
- VetoableChangeSupport vcs) {
- super(pcs, vcs);
- }
-
- private void writeObject(ObjectOutputStream s) throws IOException {
- s.defaultWriteObject();
-
- for (PropertyChangeListener l : getPropertyChangeListeners()) {
- if (l instanceof Serializable) {
- s.writeObject(l);
- }
- }
-
- for (VetoableChangeListener l : getVetoableChangeListeners()) {
- if (l instanceof Serializable) {
- s.writeObject(l);
- }
- }
-
- s.writeObject(null);
- }
-
- private void readObject(ObjectInputStream s) throws ClassNotFoundException,
- IOException {
- s.defaultReadObject();
-
- Object listenerOrNull;
- while (null != (listenerOrNull = s.readObject())) {
- if (listenerOrNull instanceof PropertyChangeListener) {
- addPropertyChangeListener((PropertyChangeListener) listenerOrNull);
- } else if (listenerOrNull instanceof VetoableChangeListener) {
- addVetoableChangeListener((VetoableChangeListener) listenerOrNull);
- }
- }
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/JXMapKit.form b/src/main/java/org/jdesktop/swingx/JXMapKit.form
deleted file mode 100644
index 59423d37..00000000
--- a/src/main/java/org/jdesktop/swingx/JXMapKit.form
+++ /dev/null
@@ -1,145 +0,0 @@
-
-
-
The JXMapKit is a pair of JXMapViewers preconfigured to be easy to use
- * with common features built in. This includes zoom buttons, a zoom slider,
- * and a mini-map in the lower right corner showing an overview of the map.
- * Each feature can be turned off using an appropriate
- * isXvisible property. For example, to turn
- * off the minimap call
- *
- *
jxMapKit.setMiniMapVisible(false);
- *
- *
- *
- * The JXMapViewer is preconfigured to connect to maps.swinglabs.org which
- * serves up global satellite imagery from NASA's
- * Blue
- * Marble NG image collection.
- *
- * @author joshy
- */
-public class JXMapKit extends JPanel
-{
- private static final long serialVersionUID = -8366577998349912380L;
- private boolean miniMapVisible = true;
- private boolean zoomSliderVisible = true;
- private boolean zoomButtonsVisible = true;
- private final boolean sliderReversed = false;
-
- @SuppressWarnings("javadoc")
- public enum DefaultProviders
- {
- SwingLabsBlueMarble, OpenStreetMaps, Custom
- }
-
- private DefaultProviders defaultProvider = DefaultProviders.SwingLabsBlueMarble;
-
- private boolean addressLocationShown = true;
-
- private boolean dataProviderCreditShown = true;
-
- /**
- * Creates a new JXMapKit
- */
- public JXMapKit()
- {
- initComponents();
- setDataProviderCreditShown(false);
-
- zoomSlider.setOpaque(false);
- try
- {
- Icon minusIcon = new ImageIcon(getClass().getResource("/org/jdesktop/swingx/mapviewer/resources/minus.png"));
- this.zoomOutButton.setIcon(minusIcon);
- this.zoomOutButton.setText("");
- Icon plusIcon = new ImageIcon(getClass().getResource("/org/jdesktop/swingx/mapviewer/resources/plus.png"));
- this.zoomInButton.setIcon(plusIcon);
- this.zoomInButton.setText("");
- }
- catch (Throwable thr)
- {
- System.out.println("error: " + thr.getMessage());
- thr.printStackTrace();
- }
-
- setTileFactory(new CylindricalProjectionTileFactory());
-
- mainMap.setCenterPosition(new GeoPosition(0, 0));
- miniMap.setCenterPosition(new GeoPosition(0, 0));
- mainMap.setRestrictOutsidePanning(true);
- miniMap.setRestrictOutsidePanning(true);
-
- rebuildMainMapOverlay();
-
- /*
- * // adapter to move the minimap after the main map has moved MouseInputAdapter ma = new MouseInputAdapter() {
- * public void mouseReleased(MouseEvent e) { miniMap.setCenterPosition(mapCenterPosition); } };
- * mainMap.addMouseMotionListener(ma); mainMap.addMouseListener(ma);
- */
-
- mainMap.addPropertyChangeListener("center", new PropertyChangeListener()
- {
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- Point2D mapCenter = (Point2D) evt.getNewValue();
- TileFactory tf = mainMap.getTileFactory();
- GeoPosition mapPos = tf.pixelToGeo(mapCenter, mainMap.getZoom());
- miniMap.setCenterPosition(mapPos);
- }
- });
-
- mainMap.addPropertyChangeListener("centerPosition", new PropertyChangeListener()
- {
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- mapCenterPosition = (GeoPosition) evt.getNewValue();
- miniMap.setCenterPosition(mapCenterPosition);
- Point2D pt = miniMap.getTileFactory().geoToPixel(mapCenterPosition, miniMap.getZoom());
- miniMap.setCenter(pt);
- miniMap.repaint();
- }
- });
-
- mainMap.addPropertyChangeListener("zoom", new PropertyChangeListener()
- {
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- zoomSlider.setValue(mainMap.getZoom());
- miniMap.setZoom(mainMap.getZoom() + 4);
- }
- });
-
- // an overlay for the mini-map which shows a rectangle representing the main map
- miniMap.setOverlayPainter(new Painter()
- {
- @Override
- public void paint(Graphics2D g, JXMapViewer map, int width, int height)
- {
- // get the viewport rect of the main map
- Rectangle mainMapBounds = mainMap.getViewportBounds();
-
- // convert to Point2Ds
- Point2D upperLeft2D = mainMapBounds.getLocation();
- Point2D lowerRight2D = new Point2D.Double(upperLeft2D.getX() + mainMapBounds.getWidth(), upperLeft2D
- .getY() + mainMapBounds.getHeight());
-
- // convert to GeoPostions
- GeoPosition upperLeft = mainMap.getTileFactory().pixelToGeo(upperLeft2D, mainMap.getZoom());
- GeoPosition lowerRight = mainMap.getTileFactory().pixelToGeo(lowerRight2D, mainMap.getZoom());
-
- // convert to Point2Ds on the mini-map
- upperLeft2D = map.getTileFactory().geoToPixel(upperLeft, map.getZoom());
- lowerRight2D = map.getTileFactory().geoToPixel(lowerRight, map.getZoom());
-
- g = (Graphics2D) g.create();
- Rectangle rect = map.getViewportBounds();
- // p("rect = " + rect);
- g.translate(-rect.x, -rect.y);
-// Point2D centerpos = map.getTileFactory().geoToPixel(mapCenterPosition, map.getZoom());
- // p("center pos = " + centerpos);
- g.setPaint(Color.RED);
- // g.drawRect((int)centerpos.getX()-30,(int)centerpos.getY()-30,60,60);
- g.drawRect((int) upperLeft2D.getX(), (int) upperLeft2D.getY(),
- (int) (lowerRight2D.getX() - upperLeft2D.getX()),
- (int) (lowerRight2D.getY() - upperLeft2D.getY()));
- g.setPaint(new Color(255, 0, 0, 50));
- g.fillRect((int) upperLeft2D.getX(), (int) upperLeft2D.getY(),
- (int) (lowerRight2D.getX() - upperLeft2D.getX()),
- (int) (lowerRight2D.getY() - upperLeft2D.getY()));
- // g.drawOval((int)lowerRight2D.getX(),(int)lowerRight2D.getY(),1,1);
- g.dispose();
- }
- });
-
- if (getDefaultProvider() == DefaultProviders.OpenStreetMaps)
- {
- setZoom(10);
- }
- else
- {
- setZoom(3);// joshy: hack, i shouldn't need this here
- }
- this.setCenterPosition(new GeoPosition(0, 0));
- }
-
- // private Point2D mapCenter = new Point2D.Double(0,0);
- private GeoPosition mapCenterPosition = new GeoPosition(0, 0);
- private boolean zoomChanging = false;
-
- /**
- * Set the current zoomlevel for the main map. The minimap will be updated accordingly
- * @param zoom the new zoom level
- */
- public void setZoom(int zoom)
- {
- zoomChanging = true;
- mainMap.setZoom(zoom);
- miniMap.setZoom(mainMap.getZoom() + 4);
- if (sliderReversed)
- {
- zoomSlider.setValue(zoomSlider.getMaximum() - zoom);
- }
- else
- {
- zoomSlider.setValue(zoom);
- }
- zoomChanging = false;
- }
-
- /**
- * Returns an action which can be attached to buttons or menu items to make the map zoom out
- * @return a preconfigured Zoom Out action
- */
- public Action getZoomOutAction()
- {
- Action act = new AbstractAction()
- {
- /**
- *
- */
- private static final long serialVersionUID = 5525706163434375107L;
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- setZoom(mainMap.getZoom() - 1);
- }
- };
- act.putValue(Action.NAME, "-");
- return act;
- }
-
- /**
- * Returns an action which can be attached to buttons or menu items to make the map zoom in
- * @return a preconfigured Zoom In action
- */
- public Action getZoomInAction()
- {
- Action act = new AbstractAction()
- {
- /**
- *
- */
- private static final long serialVersionUID = 5779971489365451352L;
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- setZoom(mainMap.getZoom() + 1);
- }
- };
- act.putValue(Action.NAME, "+");
- return act;
- }
-
- /**
- * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
- * content of this method is always regenerated by the Form Editor.
- */
- // //GEN-BEGIN:initComponents
- private void initComponents()
- {
- java.awt.GridBagConstraints gridBagConstraints;
-
- mainMap = new org.jdesktop.swingx.JXMapViewer();
- miniMap = new org.jdesktop.swingx.JXMapViewer();
- jPanel1 = new javax.swing.JPanel();
- zoomInButton = new javax.swing.JButton();
- zoomOutButton = new javax.swing.JButton();
- zoomSlider = new javax.swing.JSlider();
-
- setLayout(new java.awt.GridBagLayout());
-
- mainMap.setLayout(new java.awt.GridBagLayout());
-
- miniMap.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
- miniMap.setMinimumSize(new java.awt.Dimension(100, 100));
- miniMap.setPreferredSize(new java.awt.Dimension(100, 100));
- miniMap.setLayout(new java.awt.GridBagLayout());
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 1;
- gridBagConstraints.gridy = 0;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- mainMap.add(miniMap, gridBagConstraints);
-
- jPanel1.setOpaque(false);
- jPanel1.setLayout(new java.awt.GridBagLayout());
-
- zoomInButton.setAction(getZoomOutAction());
- zoomInButton.setIcon(new javax.swing.ImageIcon(getClass().getResource(
- "/org/jdesktop/swingx/mapviewer/resources/plus.png")));
- zoomInButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
- zoomInButton.setMaximumSize(new java.awt.Dimension(20, 20));
- zoomInButton.setMinimumSize(new java.awt.Dimension(20, 20));
- zoomInButton.setOpaque(false);
- zoomInButton.setPreferredSize(new java.awt.Dimension(20, 20));
- zoomInButton.addActionListener(new java.awt.event.ActionListener()
- {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt)
- {
- zoomInButtonActionPerformed(evt);
- }
- });
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 1;
- gridBagConstraints.gridy = 1;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- jPanel1.add(zoomInButton, gridBagConstraints);
-
- zoomOutButton.setAction(getZoomInAction());
- zoomOutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource(
- "/org/jdesktop/swingx/mapviewer/resources/minus.png")));
- zoomOutButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
- zoomOutButton.setMaximumSize(new java.awt.Dimension(20, 20));
- zoomOutButton.setMinimumSize(new java.awt.Dimension(20, 20));
- zoomOutButton.setOpaque(false);
- zoomOutButton.setPreferredSize(new java.awt.Dimension(20, 20));
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 1;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
- gridBagConstraints.weighty = 1.0;
- jPanel1.add(zoomOutButton, gridBagConstraints);
-
- zoomSlider.setMajorTickSpacing(1);
- zoomSlider.setMaximum(15);
- zoomSlider.setMinimum(10);
- zoomSlider.setMinorTickSpacing(1);
- zoomSlider.setOrientation(SwingConstants.VERTICAL);
- zoomSlider.setPaintTicks(true);
- zoomSlider.setSnapToTicks(true);
- zoomSlider.setMinimumSize(new java.awt.Dimension(35, 100));
- zoomSlider.setPreferredSize(new java.awt.Dimension(35, 190));
- zoomSlider.addChangeListener(new javax.swing.event.ChangeListener()
- {
- @Override
- public void stateChanged(javax.swing.event.ChangeEvent evt)
- {
- zoomSliderStateChanged(evt);
- }
- });
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridwidth = 2;
- gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
- jPanel1.add(zoomSlider, gridBagConstraints);
-
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridy = 0;
- gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
- mainMap.add(jPanel1, gridBagConstraints);
-
- gridBagConstraints = new java.awt.GridBagConstraints();
- gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
- gridBagConstraints.weightx = 1.0;
- gridBagConstraints.weighty = 1.0;
- add(mainMap, gridBagConstraints);
- }// //GEN-END:initComponents
-
- @SuppressWarnings("unused")
- private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt)
- {// GEN-FIRST:event_zoomInButtonActionPerformed
- // TODO add your handling code here:
- }// GEN-LAST:event_zoomInButtonActionPerformed
-
- @SuppressWarnings("unused")
- private void zoomSliderStateChanged(javax.swing.event.ChangeEvent evt)
- {// GEN-FIRST:event_zoomSliderStateChanged
- if (!zoomChanging)
- {
- setZoom(zoomSlider.getValue());
- }
- // TODO add your handling code here:
- }// GEN-LAST:event_zoomSliderStateChanged
-
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JPanel jPanel1;
- private org.jdesktop.swingx.JXMapViewer mainMap;
- private org.jdesktop.swingx.JXMapViewer miniMap;
- private javax.swing.JButton zoomInButton;
- private javax.swing.JButton zoomOutButton;
- private javax.swing.JSlider zoomSlider;
-
- // End of variables declaration//GEN-END:variables
-
- /**
- * Indicates if the mini-map is currently visible
- * @return the current value of the mini-map property
- */
- public boolean isMiniMapVisible()
- {
- return miniMapVisible;
- }
-
- /**
- * Sets if the mini-map should be visible
- * @param miniMapVisible a new value for the miniMap property
- */
- public void setMiniMapVisible(boolean miniMapVisible)
- {
- boolean old = this.isMiniMapVisible();
- this.miniMapVisible = miniMapVisible;
- miniMap.setVisible(miniMapVisible);
- firePropertyChange("miniMapVisible", old, this.isMiniMapVisible());
- }
-
- /**
- * Indicates if the zoom slider is currently visible
- * @return the current value of the zoomSliderVisible property
- */
- public boolean isZoomSliderVisible()
- {
- return zoomSliderVisible;
- }
-
- /**
- * Sets if the zoom slider should be visible
- * @param zoomSliderVisible the new value of the zoomSliderVisible property
- */
- public void setZoomSliderVisible(boolean zoomSliderVisible)
- {
- boolean old = this.isZoomSliderVisible();
- this.zoomSliderVisible = zoomSliderVisible;
- zoomSlider.setVisible(zoomSliderVisible);
- firePropertyChange("zoomSliderVisible", old, this.isZoomSliderVisible());
- }
-
- /**
- * Indicates if the zoom buttons are visible. This is a bound property and can be listed for using a
- * PropertyChangeListener
- * @return current value of the zoomButtonsVisible property
- */
- public boolean isZoomButtonsVisible()
- {
- return zoomButtonsVisible;
- }
-
- /**
- * Sets if the zoom buttons should be visible. This ia bound property. Changes can be listened for using a
- * PropertyChaneListener
- * @param zoomButtonsVisible new value of the zoomButtonsVisible property
- */
- public void setZoomButtonsVisible(boolean zoomButtonsVisible)
- {
- boolean old = this.isZoomButtonsVisible();
- this.zoomButtonsVisible = zoomButtonsVisible;
- zoomInButton.setVisible(zoomButtonsVisible);
- zoomOutButton.setVisible(zoomButtonsVisible);
- firePropertyChange("zoomButtonsVisible", old, this.isZoomButtonsVisible());
- }
-
- /**
- * Sets the tile factory for both embedded JXMapViewer components. Calling this method will also reset the center
- * and zoom levels of both maps, as well as the bounds of the zoom slider.
- * @param fact the new TileFactory
- */
- public void setTileFactory(TileFactory fact)
- {
- mainMap.setTileFactory(fact);
- mainMap.setZoom(fact.getInfo().getDefaultZoomLevel());
- mainMap.setCenterPosition(new GeoPosition(0, 0));
- miniMap.setTileFactory(fact);
- miniMap.setZoom(fact.getInfo().getDefaultZoomLevel() + 3);
- miniMap.setCenterPosition(new GeoPosition(0, 0));
- zoomSlider.setMinimum(fact.getInfo().getMinimumZoomLevel());
- zoomSlider.setMaximum(fact.getInfo().getMaximumZoomLevel());
- }
-
- /**
- * @param pos the new center position
- */
- public void setCenterPosition(GeoPosition pos)
- {
- mainMap.setCenterPosition(pos);
- miniMap.setCenterPosition(pos);
- }
-
- /**
- * @return the center geo position
- */
- public GeoPosition getCenterPosition()
- {
- return mainMap.getCenterPosition();
- }
-
- /**
- * @return the adress location
- */
- public GeoPosition getAddressLocation()
- {
- return mainMap.getAddressLocation();
- }
-
- /**
- * @param pos the address location
- */
- public void setAddressLocation(GeoPosition pos)
- {
- mainMap.setAddressLocation(pos);
- }
-
- /**
- * Returns a reference to the main embedded JXMapViewer component
- * @return the main map
- */
- public JXMapViewer getMainMap()
- {
- return this.mainMap;
- }
-
- /**
- * Returns a reference to the mini embedded JXMapViewer component
- * @return the minimap JXMapViewer component
- */
- public JXMapViewer getMiniMap()
- {
- return this.miniMap;
- }
-
- /**
- * returns a reference to the zoom in button
- * @return a jbutton
- */
- public JButton getZoomInButton()
- {
- return this.zoomInButton;
- }
-
- /**
- * returns a reference to the zoom out button
- * @return a jbutton
- */
- public JButton getZoomOutButton()
- {
- return this.zoomOutButton;
- }
-
- /**
- * returns a reference to the zoom slider
- * @return a jslider
- */
- public JSlider getZoomSlider()
- {
- return this.zoomSlider;
- }
-
- /**
- * @param b the visibility flag
- */
- public void setAddressLocationShown(boolean b)
- {
- boolean old = isAddressLocationShown();
- this.addressLocationShown = b;
- addressLocationPainter.setVisible(b);
- firePropertyChange("addressLocationShown", old, b);
- repaint();
- }
-
- /**
- * @return true if the address location is shown
- */
- public boolean isAddressLocationShown()
- {
- return addressLocationShown;
- }
-
- /**
- * @param b the visibility flag
- */
- public void setDataProviderCreditShown(boolean b)
- {
- boolean old = isDataProviderCreditShown();
- this.dataProviderCreditShown = b;
- dataProviderCreditPainter.setVisible(b);
- repaint();
- firePropertyChange("dataProviderCreditShown", old, b);
- }
-
- /**
- * @return true if the data provider credit is shown
- */
- public boolean isDataProviderCreditShown()
- {
- return dataProviderCreditShown;
- }
-
- @SuppressWarnings("unchecked")
- private void rebuildMainMapOverlay()
- {
- CompoundPainter cp = new CompoundPainter();
- cp.setCacheable(false);
- /*
- * List ptrs = new ArrayList(); if(isDataProviderCreditShown()) {
- * ptrs.add(dataProviderCreditPainter); } if(isAddressLocationShown()) { ptrs.add(addressLocationPainter); }
- */
- cp.setPainters(dataProviderCreditPainter, addressLocationPainter);
- mainMap.setOverlayPainter(cp);
- }
-
- /**
- * @param prov the default provider
- */
- public void setDefaultProvider(DefaultProviders prov)
- {
- DefaultProviders old = this.defaultProvider;
- this.defaultProvider = prov;
- if (prov == DefaultProviders.SwingLabsBlueMarble)
- {
- setTileFactory(new CylindricalProjectionTileFactory());
- setZoom(3);
- }
- if (prov == DefaultProviders.OpenStreetMaps)
- {
- TileFactoryInfo info = new OSMTileFactoryInfo();
- TileFactory tf = new DefaultTileFactory(info);
- setTileFactory(tf);
- setZoom(11);
- setAddressLocation(new GeoPosition(51.5, 0));
- }
- firePropertyChange("defaultProvider", old, prov);
- repaint();
- }
-
- /**
- * @return the default provider
- */
- public DefaultProviders getDefaultProvider()
- {
- return this.defaultProvider;
- }
-
- private AbstractPainter dataProviderCreditPainter = new AbstractPainter(false)
- {
- @Override
- protected void doPaint(Graphics2D g, JXMapViewer map, int width, int height)
- {
- g.setPaint(Color.WHITE);
- g.drawString("data ", 50, map.getHeight() - 10);
- }
- };
-
- private WaypointPainter addressLocationPainter = new WaypointPainter()
- {
- @Override
- public Set getWaypoints()
- {
- Set set = new HashSet();
- if (getAddressLocation() != null)
- {
- set.add(new DefaultWaypoint(getAddressLocation()));
- }
- else
- {
- set.add(new DefaultWaypoint(0, 0));
- }
- return set;
- }
- };
-
- /**
- * @param args the program args
- */
- public static void main(String... args)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- @Override
- public void run()
- {
- JXMapKit kit = new JXMapKit();
- kit.setDefaultProvider(DefaultProviders.OpenStreetMaps);
-
- TileFactoryInfo info = new OSMTileFactoryInfo();
- TileFactory tf = new DefaultTileFactory(info);
- kit.setTileFactory(tf);
- kit.setZoom(14);
- kit.setAddressLocation(new GeoPosition(51.5, 0));
- kit.getMainMap().setDrawTileBorders(true);
- kit.getMainMap().setRestrictOutsidePanning(true);
- kit.getMainMap().setHorizontalWrapped(false);
-
- ((DefaultTileFactory) kit.getMainMap().getTileFactory()).setThreadPoolSize(8);
- JFrame frame = new JFrame("JXMapKit test");
- frame.add(kit);
- frame.pack();
- frame.setSize(500, 300);
- frame.setVisible(true);
- }
- });
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/JXMapViewer.java b/src/main/java/org/jdesktop/swingx/JXMapViewer.java
deleted file mode 100644
index ef77d0c5..00000000
--- a/src/main/java/org/jdesktop/swingx/JXMapViewer.java
+++ /dev/null
@@ -1,804 +0,0 @@
-/*
- * *****************************************************************************
- * Copyright (C) 2014-2024 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- * ****************************************************************************
- */
-
-/*
- * MapViewer.java
- *
- * Created on March 14, 2006, 2:14 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Insets;
-import java.awt.Rectangle;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-import java.beans.DesignMode;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.Set;
-import jiconfont.icons.font_awesome.FontAwesome;
-import jiconfont.swing.IconFontSwing;
-import org.apache.commons.math3.util.FastMath;
-import org.jdesktop.swingx.mapviewer.GeoPosition;
-import org.jdesktop.swingx.mapviewer.Tile;
-import org.jdesktop.swingx.mapviewer.TileFactory;
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-import org.jdesktop.swingx.mapviewer.TileListener;
-import org.jdesktop.swingx.mapviewer.empty.EmptyTileFactory;
-import org.jdesktop.swingx.painter.AbstractPainter;
-import org.jdesktop.swingx.painter.Painter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.swing.JPanel;
-
-/**
- * A tile oriented map component that can easily be used with tile sources
- * on the web like Google and Yahoo maps, satellite data such as NASA imagery,
- * and also with file based sources like pre-processed NASA images.
- * A known map provider can be used with the SLMapServerInfo,
- * which will connect to a 2km resolution version of NASA's Blue Marble Next Generation
- * imagery. @see SLMapServerInfo for more information.
- *
- * Note, the JXMapViewer has three center point properties. The addressLocation property
- * represents an abstract center of the map. This would usually be something like the first item
- * in a search result. It is a {@link GeoPosition}. The centerPosition property represents
- * the current center point of the map. If the user pans the map then the centerPosition point will
- * change but the addressLocation will not. Calling recenterToAddressLocation() will move the map
- * back to that center address. The center property represents the same point as the centerPosition
- * property, but as a Point2D in pixel space instead of a GeoPosition in lat/long space. Note that
- * the center property is a Point2D in the entire world bitmap, not in the portion of the map currently
- * visible. You can use the getViewportBounds() method to find the portion of the map currently visible
- * and adjust your calculations accordingly. Changing the center property will change the centerPosition
- * property and vice versa. All three properties are bound.
- * @author Joshua.Marinacci@sun.com
- * @see org.jdesktop.swingx.mapviewer.bmng.SLMapServerInfo
- */
-public class JXMapViewer extends JPanel implements DesignMode
-{
- private static final long serialVersionUID = -3530746298586937321L;
-
- private final static Logger mLog = LoggerFactory.getLogger(JXMapViewer.class);
-
- private final boolean isNegativeYAllowed = true; // maybe rename to isNorthBounded and isSouthBounded?
-
- /**
- * The zoom level. Generally a value between 1 and 15 (TODO Is this true for all the mapping worlds? What does this
- * mean if some mapping system doesn't support the zoom level?
- */
- private int mZoomLevel = 1;
-
- /**
- * The position, in map coordinates of the center point. This is defined as the distance from the top and
- * left edges of the map in pixels. Dragging the map component will change the center position. Zooming in/out will
- * cause the center to be recalculated so as to remain in the center of the new "map".
- */
- private Point2D mCenter = new Point2D.Double(0, 0);
-
- /**
- * Indicates whether or not to draw the borders between tiles. Defaults to false. TODO Generally not very nice
- * looking, very much a product of testing Consider whether this should really be a property or not.
- */
- private boolean mDrawTileBorders = false;
-
- /**
- * Factory used by this component to grab the tiles necessary for painting the map.
- */
- private TileFactory mTileFactory;
-
- /**
- * The position in latitude/longitude of the "address" being mapped. This is a special coordinate that, when moved,
- * will cause the map to be moved as well. It is separate from "center" in that "center" tracks the current center
- * (in pixels) of the viewport whereas this will not change when panning or zooming. Whenever the addressLocation is
- * changed, however, the map will be repositioned.
- */
- private GeoPosition mAddressLocation;
-
- /**
- * The overlay to delegate to for painting the "foreground" of the map component. This would include painting
- * waypoints, day/night, etc. Also receives mouse events.
- */
- private Painter super JXMapViewer> mOverlay;
-
- private boolean mDesignTime;
-
- private Image mLoadingImage;
-
- private boolean mRestrictOutsidePanning = true;
- private boolean mHorizontalWrapped = true;
-
- /**
- * Create a new JXMapViewer. By default it will use the EmptyTileFactory
- */
- public JXMapViewer()
- {
- mTileFactory = new EmptyTileFactory();
- // setTileFactory(new GoogleTileFactory());
-
- // make a dummy loading image
- try
- {
- Image loading = IconFontSwing.buildImage(FontAwesome.LINK, 16);
- this.setLoadingImage(loading);
- }
- catch (Throwable ex)
- {
- mLog.error( "JXMapViewer could not load default 'loading.png'" );
- BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2 = img.createGraphics();
- g2.setColor(Color.black);
- g2.fillRect(0, 0, 16, 16);
- g2.dispose();
- this.setLoadingImage(img);
- }
-
- // setAddressLocation(new GeoPosition(37.392137,-121.950431)); // Sun campus
- }
-
- @Override
- protected void paintComponent(Graphics g)
- {
- super.paintComponent(g);
-
- doPaintComponent(g);
- }
-
- // the method that does the actual painting
- private void doPaintComponent(Graphics g)
- {/*
- * if (isOpaque() || isDesignTime()) { g.setColor(getBackground()); g.fillRect(0,0,getWidth(),getHeight()); }
- */
-
- if (isDesignTime())
- {
- // do nothing
- }
- else
- {
- int z = getZoom();
- Rectangle viewportBounds = getViewportBounds();
- drawMapTiles(g, z, viewportBounds);
- drawOverlays(z, g, viewportBounds);
- }
-
- super.paintBorder(g);
- }
-
- /**
- * Indicate that the component is being used at design time, such as in a visual editor like NetBeans' Matisse
- * @param b indicates if the component is being used at design time
- */
- @Override
- public void setDesignTime(boolean b)
- {
- this.mDesignTime = b;
- }
-
- /**
- * Indicates whether the component is being used at design time, such as in a visual editor like NetBeans' Matisse
- * @return boolean indicating if the component is being used at design time
- */
- @Override
- public boolean isDesignTime()
- {
- return mDesignTime;
- }
-
- /**
- * Draw the map tiles. This method is for implementation use only.
- * @param g Graphics
- * @param zoom zoom level to draw at
- * @param viewportBounds the bounds to draw within
- */
- protected void drawMapTiles(final Graphics g, final int zoom, Rectangle viewportBounds)
- {
- int size = getTileFactory().getTileSize(zoom);
- Dimension mapSize = getTileFactory().getMapSize(zoom);
-
- // calculate the "visible" viewport area in tiles
- int numWide = viewportBounds.width / size + 2;
- int numHigh = viewportBounds.height / size + 2;
-
- // TilePoint topLeftTile = getTileFactory().getTileCoordinate(
- // new Point2D.Double(viewportBounds.x, viewportBounds.y));
- TileFactoryInfo info = getTileFactory().getInfo();
- int tpx = (int) FastMath.floor(viewportBounds.getX() / info.getTileSize(0));
- int tpy = (int) FastMath.floor(viewportBounds.getY() / info.getTileSize(0));
- // TilePoint topLeftTile = new TilePoint(tpx, tpy);
-
- // p("top tile = " + topLeftTile);
- // fetch the tiles from the factory and store them in the tiles cache
- // attach the tileLoadListener
- for (int x = 0; x <= numWide; x++)
- {
- for (int y = 0; y <= numHigh; y++)
- {
- int itpx = x + tpx;// topLeftTile.getX();
- int itpy = y + tpy;// topLeftTile.getY();
- // TilePoint point = new TilePoint(x + topLeftTile.getX(), y + topLeftTile.getY());
- // only proceed if the specified tile point lies within the area being painted
- if (g.getClipBounds().intersects(
- new Rectangle(itpx * size - viewportBounds.x, itpy * size - viewportBounds.y, size, size)))
- {
- Tile tile = getTileFactory().getTile(itpx, itpy, zoom);
- int ox = ((itpx * getTileFactory().getTileSize(zoom)) - viewportBounds.x);
- int oy = ((itpy * getTileFactory().getTileSize(zoom)) - viewportBounds.y);
-
- // if the tile is off the map to the north/south, then just don't paint anything
- if (isTileOnMap(itpx, itpy, mapSize))
- {
- if (isOpaque())
- {
- g.setColor(getBackground());
- g.fillRect(ox, oy, size, size);
- }
- }
- else if (tile.isLoaded())
- {
- g.drawImage(tile.getImage(), ox, oy, null);
- }
- else
- {
- // Use tile at higher zoom level with 200% magnification
- Tile superTile = getTileFactory().getTile(itpx / 2, itpy / 2, zoom + 1);
-
- if (superTile.isLoaded())
- {
- int offX = (itpx % 2) * size / 2;
- int offY = (itpy % 2) * size / 2;
- g.drawImage(superTile.getImage(), ox, oy, ox + size, oy + size, offX, offY, offX + size / 2, offY + size / 2, null);
- }
- else
- {
- int imageX = (getTileFactory().getTileSize(zoom) - getLoadingImage().getWidth(null)) / 2;
- int imageY = (getTileFactory().getTileSize(zoom) - getLoadingImage().getHeight(null)) / 2;
- g.setColor(Color.GRAY);
- g.fillRect(ox, oy, size, size);
- g.drawImage(getLoadingImage(), ox + imageX, oy + imageY, null);
- }
- }
- if (isDrawTileBorders())
- {
-
- g.setColor(Color.black);
- g.drawRect(ox, oy, size, size);
- g.drawRect(ox + size / 2 - 5, oy + size / 2 - 5, 10, 10);
- g.setColor(Color.white);
- g.drawRect(ox + 1, oy + 1, size, size);
-
- String text = itpx + ", " + itpy + ", " + getZoom();
- g.setColor(Color.BLACK);
- g.drawString(text, ox + 10, oy + 30);
- g.drawString(text, ox + 10 + 2, oy + 30 + 2);
- g.setColor(Color.WHITE);
- g.drawString(text, ox + 10 + 1, oy + 30 + 1);
- }
- }
- }
- }
- }
-
- @SuppressWarnings("unused")
- private void drawOverlays(final int zoom, final Graphics g, final Rectangle viewportBounds)
- {
- if (mOverlay != null)
- {
- mOverlay.paint((Graphics2D) g, this, getWidth(), getHeight());
- }
- }
-
- @SuppressWarnings("unused")
- private boolean isTileOnMap(int x, int y, Dimension mapSize)
- {
- return !isNegativeYAllowed && y < 0 || y >= mapSize.getHeight();
- }
-
- /**
- * Sets the map overlay. This is a Painter which will paint on top of the map. It can be used to draw waypoints,
- * lines, or static overlays like text messages.
- * @param overlay the map overlay to use
- */
- public void setOverlayPainter(Painter super JXMapViewer> overlay)
- {
- Painter super JXMapViewer> old = getOverlayPainter();
- this.mOverlay = overlay;
-
- PropertyChangeListener listener = new PropertyChangeListener()
- {
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- if (evt.getNewValue().equals(Boolean.TRUE))
- {
- repaint();
- }
- }
- };
-
- if (old instanceof AbstractPainter)
- {
- AbstractPainter> ap = (AbstractPainter>) overlay;
- ap.removePropertyChangeListener("dirty", listener);
- }
-
- if (overlay instanceof AbstractPainter)
- {
- AbstractPainter> ap = (AbstractPainter>) overlay;
- ap.addPropertyChangeListener("dirty", listener);
- }
-
- firePropertyChange("mapOverlay", old, getOverlayPainter());
- repaint();
- }
-
- /**
- * Gets the current map overlay
- * @return the current map overlay
- */
- public Painter super JXMapViewer> getOverlayPainter()
- {
- return mOverlay;
- }
-
- /**
- * Returns the bounds of the viewport in pixels. This can be used to transform points into the world bitmap
- * coordinate space.
- * @return the bounds in pixels of the "view" of this map
- */
- public Rectangle getViewportBounds()
- {
- return calculateViewportBounds(getCenter());
- }
-
- private Rectangle calculateViewportBounds(Point2D centr)
- {
- Insets insets = getInsets();
- // calculate the "visible" viewport area in pixels
- int viewportWidth = getWidth() - insets.left - insets.right;
- int viewportHeight = getHeight() - insets.top - insets.bottom;
- double viewportX = (centr.getX() - viewportWidth / 2);
- double viewportY = (centr.getY() - viewportHeight / 2);
- return new Rectangle((int) viewportX, (int) viewportY, viewportWidth, viewportHeight);
- }
-
- /**
- * Set the current zoom level
- * @param zoom the new zoom level
- */
- public void setZoom(int zoom)
- {
- if (zoom == this.mZoomLevel)
- {
- return;
- }
-
- TileFactoryInfo info = getTileFactory().getInfo();
- // don't repaint if we are out of the valid zoom levels
- if (info != null && (zoom < info.getMinimumZoomLevel() || zoom > info.getMaximumZoomLevel()))
- {
- return;
- }
-
- // if(zoom >= 0 && zoom <= 15 && zoom != this.zoom) {
- int oldzoom = this.mZoomLevel;
- Point2D oldCenter = getCenter();
- Dimension oldMapSize = getTileFactory().getMapSize(oldzoom);
- this.mZoomLevel = zoom;
- this.firePropertyChange("zoom", oldzoom, zoom);
-
- Dimension mapSize = getTileFactory().getMapSize(zoom);
-
- setCenter(new Point2D.Double(oldCenter.getX() * (mapSize.getWidth() / oldMapSize.getWidth()), oldCenter.getY()
- * (mapSize.getHeight() / oldMapSize.getHeight())));
-
- repaint();
- }
-
- /**
- * Gets the current zoom level
- * @return the current zoom level
- */
- public int getZoom()
- {
- return this.mZoomLevel;
- }
-
- /**
- * Gets the current address location of the map. This property does not change when the user pans the map. This
- * property is bound.
- * @return the current map location (address)
- */
- public GeoPosition getAddressLocation()
- {
- return mAddressLocation;
- }
-
- /**
- * Gets the current address location of the map
- * @param addressLocation the new address location
- */
- public void setAddressLocation(GeoPosition addressLocation)
- {
- GeoPosition old = getAddressLocation();
- this.mAddressLocation = addressLocation;
- setCenter(getTileFactory().geoToPixel(addressLocation, getZoom()));
-
- firePropertyChange("addressLocation", old, getAddressLocation());
- repaint();
- }
-
- /**
- * Re-centers the map to have the current address location be at the center of the map, accounting for the map's
- * width and height.
- */
- public void recenterToAddressLocation()
- {
- setCenter(getTileFactory().geoToPixel(getAddressLocation(), getZoom()));
- repaint();
- }
-
- /**
- * Indicates if the tile borders should be drawn. Mainly used for debugging.
- * @return the value of this property
- */
- public boolean isDrawTileBorders()
- {
- return mDrawTileBorders;
- }
-
- /**
- * Set if the tile borders should be drawn. Mainly used for debugging.
- * @param drawTileBorders new value of this drawTileBorders
- */
- public void setDrawTileBorders(boolean drawTileBorders)
- {
- boolean old = isDrawTileBorders();
- this.mDrawTileBorders = drawTileBorders;
- firePropertyChange("drawTileBorders", old, isDrawTileBorders());
- repaint();
- }
-
- /**
- * A property indicating the center position of the map
- * @param geoPosition the new property value
- */
- public void setCenterPosition(GeoPosition geoPosition)
- {
- GeoPosition oldVal = getCenterPosition();
- setCenter(getTileFactory().geoToPixel(geoPosition, mZoomLevel));
- repaint();
- GeoPosition newVal = getCenterPosition();
- firePropertyChange("centerPosition", oldVal, newVal);
- }
-
- /**
- * A property indicating the center position of the map
- * @return the current center position
- */
- public GeoPosition getCenterPosition()
- {
- return getTileFactory().pixelToGeo(getCenter(), mZoomLevel);
- }
-
- /**
- * Get the current factory
- * @return the current property value
- */
- public TileFactory getTileFactory()
- {
- return mTileFactory;
- }
-
- /**
- * Set the current tile factory (must not be null)
- * @param factory the new property value
- */
- public void setTileFactory(TileFactory factory)
- {
- if (factory == null)
- throw new NullPointerException("factory must not be null");
-
- this.mTileFactory.removeTileListener(tileLoadListener);
- this.mTileFactory.dispose();
-
- this.mTileFactory = factory;
- this.setZoom(factory.getInfo().getDefaultZoomLevel());
-
- factory.addTileListener(tileLoadListener);
-
- repaint();
- }
-
- /**
- * A property for an image which will be display when an image is still loading.
- * @return the current property value
- */
- public Image getLoadingImage()
- {
- return mLoadingImage;
- }
-
- /**
- * A property for an image which will be display when an image is still loading.
- * @param loadingImage the new property value
- */
- public void setLoadingImage(Image loadingImage)
- {
- this.mLoadingImage = loadingImage;
- }
-
- /**
- * Gets the current pixel center of the map. This point is in the global bitmap coordinate system, not as lat/longs.
- * @return the current center of the map as a pixel value
- */
- public Point2D getCenter()
- {
- return mCenter;
- }
-
- /**
- * Sets the new center of the map in pixel coordinates.
- * @param center the new center of the map in pixel coordinates
- */
- public void setCenter(Point2D center)
- {
- Point2D old = this.getCenter();
-
- double centerX = center.getX();
- double centerY = center.getY();
-
- Dimension mapSize = getTileFactory().getMapSize(getZoom());
- int mapHeight = (int) mapSize.getHeight() * getTileFactory().getTileSize(getZoom());
- int mapWidth = (int) mapSize.getWidth() * getTileFactory().getTileSize(getZoom());
-
- if (isRestrictOutsidePanning())
- {
- Insets insets = getInsets();
- int viewportHeight = getHeight() - insets.top - insets.bottom;
- int viewportWidth = getWidth() - insets.left - insets.right;
-
- // don't let the user pan over the top edge
- Rectangle newVP = calculateViewportBounds(center);
- if (newVP.getY() < 0)
- {
- centerY = viewportHeight / 2;
- }
-
- // don't let the user pan over the left edge
- if (!isHorizontalWrapped() && newVP.getX() < 0)
- {
- centerX = viewportWidth / 2;
- }
-
- // don't let the user pan over the bottom edge
- if (newVP.getY() + newVP.getHeight() > mapHeight)
- {
- centerY = mapHeight - viewportHeight / 2;
- }
-
- // don't let the user pan over the right edge
- if (!isHorizontalWrapped() && (newVP.getX() + newVP.getWidth() > mapWidth))
- {
- centerX = mapWidth - viewportWidth / 2;
- }
-
- // if map is to small then just center it vert
- if (mapHeight < newVP.getHeight())
- {
- centerY = mapHeight / 2;// viewportHeight/2;// - mapHeight/2;
- }
-
- // if map is too small then just center it horiz
- if (!isHorizontalWrapped() && mapWidth < newVP.getWidth())
- {
- centerX = mapWidth / 2;
- }
- }
-
- // If center is outside (0, 0,mapWidth, mapHeight)
- // compute modulo to get it back in.
- {
- centerX = centerX % mapWidth;
- centerY = centerY % mapHeight;
-
- if (centerX < 0)
- centerX += mapWidth;
-
- if (centerY < 0)
- centerY += mapHeight;
- }
-
- GeoPosition oldGP = this.getCenterPosition();
- this.mCenter = new Point2D.Double(centerX, centerY);
- firePropertyChange("center", old, this.mCenter);
- firePropertyChange("centerPosition", oldGP, this.getCenterPosition());
- repaint();
- }
-
- /**
- * Calculates a zoom level so that all points in the specified set will be visible on screen. This is useful if you
- * have a bunch of points in an area like a city and you want to zoom out so that the entire city and it's points
- * are visible without panning.
- * @param positions A set of GeoPositions to calculate the new zoom from
- */
- public void calculateZoomFrom(Set positions)
- {
- // u.p("calculating a zoom based on: ");
- // u.p(positions);
- if (positions.size() < 2)
- {
- return;
- }
-
- int zoom = getZoom();
- Rectangle2D rect = generateBoundingRect(positions, zoom);
- // Rectangle2D viewport = map.getViewportBounds();
- int count = 0;
- while (!getViewportBounds().contains(rect))
- {
- // u.p("not contained");
- Point2D centr = new Point2D.Double(rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2);
- GeoPosition px = getTileFactory().pixelToGeo(centr, zoom);
- // u.p("new geo = " + px);
- setCenterPosition(px);
- count++;
- if (count > 30)
- break;
-
- if (getViewportBounds().contains(rect))
- {
- // u.p("did it finally");
- break;
- }
- zoom = zoom + 1;
- if (zoom > 15)
- {
- break;
- }
- setZoom(zoom);
- rect = generateBoundingRect(positions, zoom);
- }
- }
-
- private Rectangle2D generateBoundingRect(final Set positions, int zoom)
- {
- Point2D point1 = getTileFactory().geoToPixel(positions.iterator().next(), zoom);
- Rectangle2D rect = new Rectangle2D.Double(point1.getX(), point1.getY(), 0, 0);
-
- for (GeoPosition pos : positions)
- {
- Point2D point = getTileFactory().geoToPixel(pos, zoom);
- rect.add(point);
- }
- return rect;
- }
-
- // a property change listener which forces repaints when tiles finish loading
- private TileListener tileLoadListener = new TileListener()
- {
- @Override
- public void tileLoaded(Tile tile)
- {
- if (tile.getZoom() == getZoom())
- {
- repaint();
- /* this optimization doesn't save much and it doesn't work if you
- * wrap around the world
- Rectangle viewportBounds = getViewportBounds();
- TilePoint tilePoint = t.getLocation();
- Point point = new Point(tilePoint.getX() * getTileFactory().getTileSize(), tilePoint.getY() * getTileFactory().getTileSize());
- Rectangle tileRect = new Rectangle(point, new Dimension(getTileFactory().getTileSize(), getTileFactory().getTileSize()));
- if (viewportBounds.intersects(tileRect)) {
- //convert tileRect from world space to viewport space
- repaint(new Rectangle(
- tileRect.x - viewportBounds.x,
- tileRect.y - viewportBounds.y,
- tileRect.width,
- tileRect.height
- ));
- }*/
- }
- }
-
- };
-
- /**
- * @return true if panning is restricted or not
- */
- public boolean isRestrictOutsidePanning()
- {
- return mRestrictOutsidePanning;
- }
-
- /**
- * @param restrictOutsidePanning set if panning is restricted or not
- */
- public void setRestrictOutsidePanning(boolean restrictOutsidePanning)
- {
- this.mRestrictOutsidePanning = restrictOutsidePanning;
- }
-
- /**
- * @return true if horizontally wrapped or not
- */
- public boolean isHorizontalWrapped()
- {
- return mHorizontalWrapped;
- }
-
- /**
- * @param horizontalWrapped true if horizontal wrap is enabled
- */
- public void setHorizontalWrapped(boolean horizontalWrapped)
- {
- this.mHorizontalWrapped = horizontalWrapped;
- }
-
- /**
- * Converts the specified GeoPosition to a point in the JXMapViewer's local coordinate space. This method is
- * especially useful when drawing lat/long positions on the map.
- * @param pos a GeoPosition on the map
- * @return the point in the local coordinate space of the map
- */
- public Point2D convertGeoPositionToPoint(GeoPosition pos)
- {
- // convert from geo to world bitmap
- Point2D pt = getTileFactory().geoToPixel(pos, getZoom());
- // convert from world bitmap to local
- Rectangle bounds = getViewportBounds();
- return new Point2D.Double(pt.getX() - bounds.getX(), pt.getY() - bounds.getY());
- }
-
- /**
- * Converts the specified Point2D in the JXMapViewer's local coordinate space to a GeoPosition on the map. This
- * method is especially useful for determining the GeoPosition under the mouse cursor.
- * @param pt a point in the local coordinate space of the map
- * @return the point converted to a GeoPosition
- */
- public GeoPosition convertPointToGeoPosition(Point2D pt)
- {
- // convert from local to world bitmap
- Rectangle bounds = getViewportBounds();
- Point2D pt2 = new Point2D.Double(pt.getX() + bounds.getX(), pt.getY() + bounds.getY());
-
- // convert from world bitmap to geo
- GeoPosition pos = getTileFactory().pixelToGeo(pt2, getZoom());
- return pos;
- }
-
-
-
- /**
- * @return isNegativeYAllowed
- */
- public boolean isNegativeYAllowed()
- {
- return isNegativeYAllowed;
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/OSMTileFactoryInfo.java b/src/main/java/org/jdesktop/swingx/OSMTileFactoryInfo.java
deleted file mode 100644
index 0768771b..00000000
--- a/src/main/java/org/jdesktop/swingx/OSMTileFactoryInfo.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *
- * * ******************************************************************************
- * * Copyright (C) 2014-2019 Dennis Sheirer
- * *
- * * This program is free software: you can redistribute it and/or modify
- * * it under the terms of the GNU General Public License as published by
- * * the Free Software Foundation, either version 3 of the License, or
- * * (at your option) any later version.
- * *
- * * This program is distributed in the hope that it will be useful,
- * * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * * GNU General Public License for more details.
- * *
- * * You should have received a copy of the GNU General Public License
- * * along with this program. If not, see
- * * *****************************************************************************
- *
- *
- */
-
-package org.jdesktop.swingx;
-
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-
-/**
- * Uses OpenStreetMap
- * @author Martin Dummer
- */
-public class OSMTileFactoryInfo extends TileFactoryInfo
-{
- private static final int max = 19;
-
- /**
- * Default constructor
- */
- public OSMTileFactoryInfo()
- {
- super("OpenStreetMap",
- 1, max - 2, max,
- 256, true, true, // tile size is 256 and x/y orientation is normal
- "https://tile.openstreetmap.org",
- "x", "y", "z"); // 5/15/10.png
- }
-
- @Override
- public String getTileUrl(int x, int y, int zoom)
- {
- zoom = max - zoom;
- String url = this.baseURL + "/" + zoom + "/" + x + "/" + y + ".png";
- return url;
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/VirtualEarthTileFactoryInfo.java b/src/main/java/org/jdesktop/swingx/VirtualEarthTileFactoryInfo.java
deleted file mode 100644
index d9784011..00000000
--- a/src/main/java/org/jdesktop/swingx/VirtualEarthTileFactoryInfo.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx;
-
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-
-/*******************************************************************************
- * http://www.viavirtualearth.com/vve/Articles/RollYourOwnTileServer.ashx
- * @author Fabrizio Giudici
- * @version $Id: MicrosoftVirtualEarthProvider.java 115 2007-11-08 22:04:36Z
- * fabriziogiudici $
- ********************************************************************************/
-public class VirtualEarthTileFactoryInfo extends TileFactoryInfo
-{
- /**
- * Use road map
- */
- public final static MVEMode MAP = new MVEMode("map", "map", "r", ".png");
-
- /**
- * Use satellite map
- */
- public final static MVEMode SATELLITE = new MVEMode("satellite", "satellite", "a", ".jpeg");
-
- /**
- * Use hybrid map
- */
- public final static MVEMode HYBRID = new MVEMode("hybrid", "hybrid", "h", ".jpeg");
-
- /**
- * The map mode
- */
- public static class MVEMode
- {
- private String type;
- private String ext;
- private String name;
- private String label;
-
- private MVEMode(final String name, final String label, final String type, final String ext)
- {
- this.type = type;
- this.ext = ext;
- this.name = name;
- this.label = label;
- }
- }
-
- private final static int TOP_ZOOM_LEVEL = 19;
-
- private final static int MAX_ZOOM_LEVEL = 17;
-
- private final static int MIN_ZOOM_LEVEL = 2;
-
- private final static int TILE_SIZE = 256;
-
- private MVEMode mode;
-
- /**
- * @param mode the mode
- */
- public VirtualEarthTileFactoryInfo(MVEMode mode)
- {
- super("Virtual Earth", MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL, TOP_ZOOM_LEVEL, TILE_SIZE, false, false, "", "", "", "");
-
- this.mode = mode;
- }
-
- /**
- * @return the name of the selected mode
- */
- public String getModeName()
- {
- return mode.name;
- }
-
- /**
- * @return the label of the selected mode
- */
- public String getModeLabel()
- {
- return mode.label;
- }
-
- @Override
- public String getTileUrl(final int x, final int y, final int zoom)
- {
- final String quad = tileToQuadKey(x, y, TOP_ZOOM_LEVEL - 0 - zoom);
- return "http://" + mode.type + quad.charAt(quad.length() - 1) +
- ".ortho.tiles.virtualearth.net/tiles/"
- + mode.type + quad + mode.ext + "?g=1";
- }
-
- private String tileToQuadKey(final int tx, final int ty, final int zl)
- {
- String quad = "";
-
- for (int i = zl; i > 0; i--)
- {
- int mask = 1 << (i - 1);
- int cell = 0;
-
- if ((tx & mask) != 0)
- {
- cell++;
- }
-
- if ((ty & mask) != 0)
- {
- cell += 2;
- }
-
- quad += cell;
- }
-
- return quad;
- }
-}
-
diff --git a/src/main/java/org/jdesktop/swingx/input/CenterMapListener.java b/src/main/java/org/jdesktop/swingx/input/CenterMapListener.java
deleted file mode 100644
index 6eb0fba4..00000000
--- a/src/main/java/org/jdesktop/swingx/input/CenterMapListener.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.input;
-
-import org.jdesktop.swingx.JXMapViewer;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-
-/**
- * Centers the map on the mouse cursor
- * if left is double-clicked or middle mouse
- * button is pressed.
- * @author Martin Steiger
- * @author joshy
- */
-public class CenterMapListener extends MouseAdapter
-{
- private JXMapViewer viewer;
-
- /**
- * @param viewer the jxmapviewer
- */
- public CenterMapListener(JXMapViewer viewer)
- {
- this.viewer = viewer;
- }
-
- @Override
- public void mousePressed(MouseEvent evt)
- {
- boolean left = SwingUtilities.isLeftMouseButton(evt);
- boolean middle = SwingUtilities.isMiddleMouseButton(evt);
- boolean doubleClick = (evt.getClickCount() == 2);
-
- if (middle || (left && doubleClick))
- {
- recenterMap(evt);
- }
- }
-
- private void recenterMap(MouseEvent evt)
- {
- Rectangle bounds = viewer.getViewportBounds();
- double x = bounds.getX() + evt.getX();
- double y = bounds.getY() + evt.getY();
- viewer.setCenter(new Point2D.Double(x, y));
- viewer.setZoom(viewer.getZoom() - 1);
- viewer.repaint();
- }
-}
-
-
diff --git a/src/main/java/org/jdesktop/swingx/input/PanKeyListener.java b/src/main/java/org/jdesktop/swingx/input/PanKeyListener.java
deleted file mode 100644
index 2995ad3b..00000000
--- a/src/main/java/org/jdesktop/swingx/input/PanKeyListener.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.input;
-
-import org.jdesktop.swingx.JXMapViewer;
-
-import java.awt.*;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.geom.Point2D;
-
-/**
- * used to pan using the arrow keys
- * @author joshy
- */
-public class PanKeyListener extends KeyAdapter
-{
- private static final int OFFSET = 10;
-
- private JXMapViewer viewer;
-
- /**
- * @param viewer the jxmapviewer
- */
- public PanKeyListener(JXMapViewer viewer)
- {
- this.viewer = viewer;
- }
-
- @Override
- public void keyPressed(KeyEvent e)
- {
- int delta_x = 0;
- int delta_y = 0;
- int requestedZoom = 0;
-
- switch ( e.getKeyCode() )
- {
-
- case KeyEvent.VK_LEFT:
- case KeyEvent.VK_NUMPAD4:
- delta_x = -OFFSET;
- break;
- case KeyEvent.VK_RIGHT:
- case KeyEvent.VK_NUMPAD6:
- delta_x = OFFSET;
- break;
- case KeyEvent.VK_UP:
- case KeyEvent.VK_NUMPAD8:
- delta_y = -OFFSET;
- break;
- case KeyEvent.VK_DOWN:
- case KeyEvent.VK_NUMPAD2:
- delta_y = OFFSET;
- break;
- case KeyEvent.VK_MINUS:
- case KeyEvent.VK_SUBTRACT:
- requestedZoom = 1;
- break;
- case KeyEvent.VK_ADD:
- case KeyEvent.VK_EQUALS:
- requestedZoom = -1;
- break;
- }
-
- if (delta_x != 0 || delta_y != 0)
- {
- Rectangle bounds = viewer.getViewportBounds();
- double x = bounds.getCenterX() + delta_x;
- double y = bounds.getCenterY() + delta_y;
- viewer.setCenter(new Point2D.Double(x, y));
- viewer.repaint();
- }
-
- if( requestedZoom != 0 )
- {
- int zoomLevel = viewer.getZoom() + requestedZoom;
-
- viewer.setZoom( zoomLevel );
- }
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/input/PanMouseInputListener.java b/src/main/java/org/jdesktop/swingx/input/PanMouseInputListener.java
deleted file mode 100644
index 7bcc3564..00000000
--- a/src/main/java/org/jdesktop/swingx/input/PanMouseInputListener.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.input;
-
-import org.jdesktop.swingx.JXMapViewer;
-
-import javax.swing.*;
-import javax.swing.event.MouseInputAdapter;
-import java.awt.*;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-
-/**
- * Used to pan using press and drag mouse gestures
- * @author joshy
- */
-public class PanMouseInputListener extends MouseInputAdapter
-{
- private Point prev;
- private JXMapViewer viewer;
-
- /**
- * @param viewer the jxmapviewer
- */
- public PanMouseInputListener(JXMapViewer viewer)
- {
- this.viewer = viewer;
- }
-
- @Override
- public void mousePressed(MouseEvent evt)
- {
- prev = evt.getPoint();
- }
-
- @Override
- public void mouseDragged(MouseEvent evt)
- {
- if (!SwingUtilities.isLeftMouseButton(evt))
- return;
-
- Point current = evt.getPoint();
- double x = viewer.getCenter().getX() - (current.x - prev.x);
- double y = viewer.getCenter().getY() - (current.y - prev.y);
-
- if (!viewer.isNegativeYAllowed())
- {
- if (y < 0)
- {
- y = 0;
- }
- }
-
- int maxHeight = (int) (viewer.getTileFactory().getMapSize(viewer.getZoom()).getHeight() * viewer
- .getTileFactory().getTileSize(viewer.getZoom()));
- if (y > maxHeight)
- {
- y = maxHeight;
- }
-
- prev = current;
- viewer.setCenter(new Point2D.Double(x, y));
- viewer.repaint();
- viewer.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
- }
-
- @Override
- public void mouseReleased(MouseEvent evt)
- {
- if (!SwingUtilities.isLeftMouseButton(evt))
- return;
-
- prev = null;
- viewer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
-
- @Override
- public void mouseEntered(MouseEvent e)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- @Override
- public void run()
- {
- viewer.requestFocusInWindow();
- }
- });
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/input/ZoomMouseWheelListenerCenter.java b/src/main/java/org/jdesktop/swingx/input/ZoomMouseWheelListenerCenter.java
deleted file mode 100644
index a8b6b7f5..00000000
--- a/src/main/java/org/jdesktop/swingx/input/ZoomMouseWheelListenerCenter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.input;
-
-import org.jdesktop.swingx.JXMapViewer;
-
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
-
-/**
- * zooms using the mouse wheel on the view center
- * @author joshy
- */
-public class ZoomMouseWheelListenerCenter implements MouseWheelListener
-{
- private JXMapViewer viewer;
-
- /**
- * @param viewer the jxmapviewer
- */
- public ZoomMouseWheelListenerCenter(JXMapViewer viewer)
- {
- this.viewer = viewer;
- }
-
- @Override
- public void mouseWheelMoved(MouseWheelEvent e)
- {
- viewer.setZoom(viewer.getZoom() + e.getWheelRotation());
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/input/ZoomMouseWheelListenerCursor.java b/src/main/java/org/jdesktop/swingx/input/ZoomMouseWheelListenerCursor.java
deleted file mode 100644
index 140e6e4b..00000000
--- a/src/main/java/org/jdesktop/swingx/input/ZoomMouseWheelListenerCursor.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.input;
-
-import io.github.dsheirer.map.MapPanel;
-import org.jdesktop.swingx.JXMapViewer;
-
-import java.awt.*;
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
-import java.awt.geom.Point2D;
-
-/**
- * zooms to the current mouse cursor
- * using the mouse wheel
- * @author Martin Steiger
- */
-public class ZoomMouseWheelListenerCursor implements MouseWheelListener
-{
- private MapPanel mMapPanel;
- private JXMapViewer mViewer;
-
- /**
- * @param viewer the jxmapviewer
- */
- public ZoomMouseWheelListenerCursor(MapPanel mapPanel)
- {
- mMapPanel = mapPanel;
- mViewer = mMapPanel.getMapViewer();
- }
-
- @Override
- public void mouseWheelMoved(MouseWheelEvent evt)
- {
- Point current = evt.getPoint();
- Rectangle bound = mViewer.getViewportBounds();
-
- double dx = current.x - bound.width / 2;
- double dy = current.y - bound.height / 2;
-
- Dimension oldMapSize = mViewer.getTileFactory().getMapSize(mViewer.getZoom());
-
- mMapPanel.adjustZoom(evt.getWheelRotation());
-
- Dimension mapSize = mViewer.getTileFactory().getMapSize(mViewer.getZoom());
-
- Point2D center = mViewer.getCenter();
-
- double dzw = (mapSize.getWidth() / oldMapSize.getWidth());
- double dzh = (mapSize.getHeight() / oldMapSize.getHeight());
-
- double x = center.getX() + dx * (dzw - 1);
- double y = center.getY() + dy * (dzh - 1);
-
- mViewer.setCenter(new Point2D.Double(x, y));
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/AbstractTileFactory.java b/src/main/java/org/jdesktop/swingx/mapviewer/AbstractTileFactory.java
deleted file mode 100644
index 7e7e14cc..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/AbstractTileFactory.java
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- *
- * * ******************************************************************************
- * * Copyright (C) 2014-2019 Dennis Sheirer
- * *
- * * This program is free software: you can redistribute it and/or modify
- * * it under the terms of the GNU General Public License as published by
- * * the Free Software Foundation, either version 3 of the License, or
- * * (at your option) any later version.
- * *
- * * This program is distributed in the hope that it will be useful,
- * * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * * GNU General Public License for more details.
- * *
- * * You should have received a copy of the GNU General Public License
- * * along with this program. If not, see
- * * *****************************************************************************
- *
- *
- */
-package org.jdesktop.swingx.mapviewer;
-
-import org.apache.commons.math3.util.FastMath;
-import org.jdesktop.swingx.mapviewer.util.GeoUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.imageio.ImageIO;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLException;
-import javax.swing.SwingUtilities;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.ref.SoftReference;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.PriorityBlockingQueue;
-import java.util.concurrent.ThreadFactory;
-
-/**
- * The AbstractTileFactory provides
- * a basic implementation for the TileFactory.
- */
-public abstract class AbstractTileFactory extends TileFactory
-{
- private final static Logger mLog = LoggerFactory.getLogger( AbstractTileFactory.class );
- private boolean mSSLSuitesLogged = false;
-
- /**
- * Creates a new instance of DefaultTileFactory using the spcified TileFactoryInfo
- * @param info a TileFactoryInfo to configure this TileFactory
- */
- public AbstractTileFactory(TileFactoryInfo info)
- {
- super(info);
- }
-
- // private static final boolean doEagerLoading = true;
-
- private int threadPoolSize = 4;
- private ExecutorService service;
-
- // TODO the tile map should be static ALWAYS, regardless of the number
- // of GoogleTileFactories because each tile is, really, a singleton.
- private Map tileMap = new HashMap();
-
- private TileCache cache = new TileCache();
-
- /**
- * Returns the tile that is located at the given tilePoint
- * for this zoom. For example, if getMapSize() returns 10x20
- * for this zoom, and the tilePoint is (3,5), then the
- * appropriate tile will be located and returned.
- */
- @Override
- public Tile getTile(int x, int y, int zoom)
- {
- return getTile(x, y, zoom, true);
- }
-
- private Tile getTile(int tpx, int tpy, int zoom, boolean eagerLoad)
- {
- // wrap the tiles horizontally --> mod the X with the max width
- // and use that
- int tileX = tpx;// tilePoint.getX();
- int numTilesWide = (int) getMapSize(zoom).getWidth();
- if (tileX < 0)
- {
- tileX = numTilesWide - (FastMath.abs(tileX) % numTilesWide);
- }
-
- tileX = tileX % numTilesWide;
- int tileY = tpy;
- // TilePoint tilePoint = new TilePoint(tileX, tpy);
- String url = getInfo().getTileUrl(tileX, tileY, zoom);// tilePoint);
- // System.out.println("loading: " + url);
-
- Tile.Priority pri = Tile.Priority.High;
- if (!eagerLoad)
- {
- pri = Tile.Priority.Low;
- }
- Tile tile = null;
- // System.out.println("testing for validity: " + tilePoint + " zoom = " + zoom);
- if (!tileMap.containsKey(url))
- {
- if (!GeoUtil.isValidTile(tileX, tileY, zoom, getInfo()))
- {
- tile = new Tile(tileX, tileY, zoom);
- }
- else
- {
- tile = new Tile(tileX, tileY, zoom, url, pri, this);
- startLoading(tile);
- }
- tileMap.put(url, tile);
- }
- else
- {
- tile = tileMap.get(url);
- // if its in the map but is low and isn't loaded yet
- // but we are in high mode
- if (tile.getPriority() == Tile.Priority.Low && eagerLoad && !tile.isLoaded())
- {
- // System.out.println("in high mode and want a low");
- // tile.promote();
- promote(tile);
- }
- }
-
- /*
- * if (eagerLoad && doEagerLoading) { for (int i = 0; i<1; i++) { for (int j = 0; j<1; j++) { // preload the 4
- * tiles under the current one if(zoom > 0) { eagerlyLoad(tilePoint.getX()*2, tilePoint.getY()*2, zoom-1);
- * eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2, zoom-1); eagerlyLoad(tilePoint.getX()*2,
- * tilePoint.getY()*2+1, zoom-1); eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2+1, zoom-1); } } } }
- */
-
- return tile;
- }
-
- /*
- * private void eagerlyLoad(int x, int y, int zoom) { TilePoint t1 = new TilePoint(x,y); if(!isLoaded(t1,zoom)) {
- * getTile(t1,zoom,false); } }
- */
-
- // private boolean isLoaded(int x, int y, int zoom) {
- // String url = getInfo().getTileUrl(zoom,x,y);
- // return tileMap.containsKey(url);
- // }
-
- /**
- * @return the tile cache
- */
- public TileCache getTileCache()
- {
- return cache;
- }
-
- /**
- * @param cache the tile cache
- */
- public void setTileCache(TileCache cache)
- {
- this.cache = cache;
- }
-
- /** ==== threaded tile loading stuff === */
- /**
- * Thread pool for loading the tiles
- */
- private static BlockingQueue tileQueue = new PriorityBlockingQueue(5, new Comparator()
- {
- @Override
- public int compare(Tile o1, Tile o2)
- {
- if (o1.getPriority() == Tile.Priority.Low && o2.getPriority() == Tile.Priority.High)
- {
- return 1;
- }
- if (o1.getPriority() == Tile.Priority.High && o2.getPriority() == Tile.Priority.Low)
- {
- return -1;
- }
- return 0;
-
- }
- });
-
- /**
- * Subclasses may override this method to provide their own executor services. This method will be called each time
- * a tile needs to be loaded. Implementations should cache the ExecutorService when possible.
- * @return ExecutorService to load tiles with
- */
- protected synchronized ExecutorService getService()
- {
- if (service == null)
- {
- // System.out.println("creating an executor service with a threadpool of size " + threadPoolSize);
- service = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory()
- {
- private int count = 0;
-
- @Override
- public Thread newThread(Runnable r)
- {
- Thread t = new Thread(r, "map tile fetcher-pool-" + count++);
- t.setPriority(Thread.MIN_PRIORITY);
- t.setDaemon(true);
- return t;
- }
- });
- }
- return service;
- }
-
- @Override
- public void dispose()
- {
- if (service != null)
- {
- service.shutdown();
- service = null;
- }
- }
-
- /**
- * Set the number of threads to use for loading the tiles. This controls the number of threads used by the
- * ExecutorService returned from getService(). Note, this method should be called before loading the first tile.
- * Calls after the first tile are loaded will have no effect by default.
- * @param size the thread pool size
- */
- public void setThreadPoolSize(int size)
- {
- if (size <= 0)
- {
- throw new IllegalArgumentException("size invalid: " + size
- + ". The size of the threadpool must be greater than 0.");
- }
- threadPoolSize = size;
- }
-
- @Override
- protected synchronized void startLoading(Tile tile)
- {
- if (tile.isLoading())
- {
- System.out.println("already loading. bailing");
- return;
- }
- tile.setLoading(true);
- try
- {
- tileQueue.put(tile);
- getService().submit(createTileRunner(tile));
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- /**
- * Subclasses can override this if they need custom TileRunners for some reason
- * @param tile the tile (unused!)
- * @return the tile runner
- */
- protected Runnable createTileRunner(Tile tile)
- {
- return new TileRunner();
- }
-
- /**
- * Increase the priority of this tile so it will be loaded sooner.
- * @param tile the tile
- */
- public synchronized void promote(Tile tile)
- {
- if (tileQueue.contains(tile))
- {
- try
- {
- tileQueue.remove(tile);
- tile.setPriority(Tile.Priority.High);
- tileQueue.put(tile);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }
-
- /**
- * An inner class which actually loads the tiles. Used by the thread queue. Subclasses can override this if
- * necessary.
- */
- private class TileRunner implements Runnable
- {
- /**
- * Gets the full URI of a tile.
- * @param tile the tile
- * @throws URISyntaxException if the URI is invalid
- * @return a URI for the tile
- */
- protected URI getURI(Tile tile) throws URISyntaxException
- {
- if (tile.getURL() == null)
- {
- return null;
- }
- return new URI(tile.getURL());
- }
-
- /**
- * implementation of the Runnable interface.
- */
- @Override
- public void run()
- {
- /*
- * 3 strikes and you're out. Attempt to load the url. If it fails, decrement the number of tries left and
- * try again. Log failures. If I run out of try s just get out. This way, if there is some kind of serious
- * failure, I can get out and let other tiles try to load.
- */
- final Tile tile = tileQueue.remove();
-
- int trys = 3;
- while (!tile.isLoaded() && trys > 0)
- {
- try
- {
- BufferedImage img = null;
- URI uri = getURI(tile);
- img = cache.get(uri);
- if (img == null)
- {
- byte[] bimg = cacheInputStream(uri.toURL());
- // img = PaintUtils.loadCompatibleImage(new ByteArrayInputStream(bimg));
- img = ImageIO.read(new ByteArrayInputStream(bimg));
- cache.put(uri, bimg, img);
- img = cache.get(uri);
- }
- if (img == null)
- {
- trys--;
- }
- else
- {
- final BufferedImage i = img;
- SwingUtilities.invokeAndWait(new Runnable()
- {
- @Override
- public void run()
- {
- tile.image = new SoftReference(i);
- tile.setLoaded(true);
- fireTileLoadedEvent(tile);
- }
- });
- }
- }
- catch (OutOfMemoryError memErr)
- {
- cache.needMoreMemory();
- }
- catch(SSLException ssle)
- {
- if(ssle.getMessage() != null && ssle.getMessage().startsWith("No PSK available"))
- {
- //JDK 11 bug: https://bugs.openjdk.java.net/browse/JDK-8213202
- }
- else
- {
- mLog.error("SSL Exception");
- }
- }
- catch (Throwable e)
- {
- if (trys == 0)
- {
- mLog.error("Failed to load a tile at url: " + tile.getURL() + ", stopping", e );
- }
- else
- {
- mLog.error("Failed to load a tile at url: " + tile.getURL() + ", retrying", e );
- trys--;
- }
- }
- }
- tile.setLoading(false);
- }
-
- private byte[] cacheInputStream(URL url) throws IOException
- {
- //Ugly hack. We only use OSM tiles, so detect it here and comply with SOM Terms of Service (ie user agent)
- if(url.toString().startsWith("https://tile.openstreetmap.org"))
- {
- HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
- conn.addRequestProperty("User-Agent", "sdrtrunk");
-
- try
- {
- SSLContext sslContext = SSLContext.getInstance("TLSv1.3");
- sslContext.init(null, null, new SecureRandom());
- conn.setSSLSocketFactory(sslContext.getSocketFactory());
- }
- catch(KeyManagementException kme)
- {
- mLog.error("Error initializing SSL context");
- }
- catch(NoSuchAlgorithmException nsae)
- {
- mLog.error("Unable to use TLSv1.3 for OpenStreetMap tiles");
- }
-
- InputStream is = conn.getInputStream();
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
-
- byte[] buf = new byte[256];
- while (true)
- {
- int n = is.read(buf);
- if (n == -1)
- break;
- bout.write(buf, 0, n);
- }
-
- conn.disconnect();
-
- return bout.toByteArray();
- }
- else
- {
- InputStream ins = url.openStream();
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- byte[] buf = new byte[256];
- while (true)
- {
- int n = ins.read(buf);
- if (n == -1)
- break;
- bout.write(buf, 0, n);
- }
- return bout.toByteArray();
- }
- }
- }
-
- public static void main(String[] args)
- {
- String a = "https://tile.openstreetmap.org/12/1178/1504.png";
-// String a = "https://tile.openstreetmap.org/11/589/751.png";
-
- try
- {
- URL url = new URL(a);
-
- System.out.println("Fetching URL: " + url.getClass() + " " + url.toString());
-
- HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
- conn.addRequestProperty("User-Agent", "sdrtrunk");
- InputStream is = conn.getInputStream();
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
-
- byte[] buf = new byte[256];
- while (true)
- {
- int n = is.read(buf);
- if (n == -1)
- break;
- bout.write(buf, 0, n);
- }
-
- System.out.println("Bytes:" + Arrays.toString(bout.toByteArray()));
- }
- catch(IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/DefaultTileFactory.java b/src/main/java/org/jdesktop/swingx/mapviewer/DefaultTileFactory.java
deleted file mode 100644
index 2d430f3a..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/DefaultTileFactory.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * DefaultTileFactory.java
- *
- * Created on June 27, 2006, 2:20 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-/**
- * A tile factory which configures itself using a TileFactoryInfo object and uses a Google Maps like mercator
- * projection.
- * @author joshy
- */
-public class DefaultTileFactory extends AbstractTileFactory
-{
- /**
- * Creates a new instance of DefaultTileFactory using the spcified TileFactoryInfo
- * @param info a TileFactoryInfo to configure this TileFactory
- */
- public DefaultTileFactory(TileFactoryInfo info)
- {
- super(info);
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/DefaultWaypoint.java b/src/main/java/org/jdesktop/swingx/mapviewer/DefaultWaypoint.java
deleted file mode 100644
index b094af34..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/DefaultWaypoint.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Waypoint.java
- *
- * Created on March 30, 2006, 5:22 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-import org.jdesktop.beans.AbstractBean;
-
-/**
- * @author joshy
- */
-public class DefaultWaypoint extends AbstractBean implements Waypoint
-{
- private GeoPosition position;
-
- /**
- * Creates a new instance of Waypoint
- */
- public DefaultWaypoint()
- {
- this(new GeoPosition(0, 0));
- }
-
- /**
- * @param latitude the latitude
- * @param longitude the longitude
- */
- public DefaultWaypoint(double latitude, double longitude)
- {
- this(new GeoPosition(latitude, longitude));
- }
-
- /**
- * @param coord the geo coordinate
- */
- public DefaultWaypoint(GeoPosition coord)
- {
- this.position = coord;
- }
-
- @Override
- public GeoPosition getPosition()
- {
- return position;
- }
-
- /**
- * Set a new GeoPosition for this Waypoint
- * @param coordinate a new position
- */
- public void setPosition(GeoPosition coordinate)
- {
- GeoPosition old = getPosition();
- this.position = coordinate;
- firePropertyChange("position", old, getPosition());
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/DefaultWaypointRenderer.java b/src/main/java/org/jdesktop/swingx/mapviewer/DefaultWaypointRenderer.java
deleted file mode 100644
index 0c9ebd29..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/DefaultWaypointRenderer.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * WaypointRenderer.java
- *
- * Created on March 30, 2006, 5:24 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-import org.jdesktop.swingx.JXMapViewer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.imageio.ImageIO;
-import java.awt.*;
-import java.awt.geom.Point2D;
-import java.awt.image.BufferedImage;
-
-/**
- * This is a standard waypoint renderer.
- * @author joshy
- */
-public class DefaultWaypointRenderer implements WaypointRenderer
-{
- private final static Logger mLog =
- LoggerFactory.getLogger( DefaultWaypointRenderer.class );
-
- private BufferedImage img = null;
-
- /**
- * Uses a default waypoint image
- */
- public DefaultWaypointRenderer()
- {
- try
- {
- img = ImageIO.read(getClass().getResource("resources/standard_waypoint.png"));
- }
- catch (Exception ex)
- {
- mLog.error("couldn't read standard_waypoint.png", ex );
- }
- }
-
- @Override
- public void paintWaypoint(Graphics2D g, JXMapViewer map, Waypoint w)
- {
- if (img == null)
- return;
-
- Point2D point = map.getTileFactory().geoToPixel(w.getPosition(), map.getZoom());
-
- int x = (int)point.getX() -img.getWidth() / 2;
- int y = (int)point.getY() -img.getHeight();
-
- g.drawImage(img, x, y, null);
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/GeoBounds.java b/src/main/java/org/jdesktop/swingx/mapviewer/GeoBounds.java
deleted file mode 100644
index 3f76c4c5..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/GeoBounds.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.mapviewer;
-
-import org.apache.commons.math3.util.FastMath;
-
-import java.awt.geom.Rectangle2D;
-import java.util.Set;
-
-/**
- * The GeoBounds class provides access the the North East and South West corners of the bounds and provides
- * an intersects method.
- * @author Dan Andrews
- */
-public class GeoBounds
-{
-
- /** Internal representation of the bounds */
- private Rectangle2D[] rects;
-
- /**
- * Constructor.
- * @param minLat The minimum latitude.
- * @param minLng The minimum longitude.
- * @param maxLat The maximum latitude.
- * @param maxLng The maximum longitude.
- */
- public GeoBounds(double minLat, double minLng, double maxLat, double maxLng)
- {
- setRect(minLat, minLng, maxLat, maxLng);
- }
-
- /**
- * Constructor.
- * @param geoPositions A non null list of 2 or more different GeoBounds objects.
- */
- public GeoBounds(Set geoPositions)
- {
- if (geoPositions == null || geoPositions.size() < 2)
- {
- throw new IllegalArgumentException("The attribute 'geoPositions' cannot be null and must "
- + "have 2 or more elements.");
- }
- double minLat = Integer.MAX_VALUE;
- double minLng = Integer.MAX_VALUE;
- double maxLat = Integer.MIN_VALUE;
- double maxLng = Integer.MIN_VALUE;
- for (GeoPosition position : geoPositions)
- {
- minLat = FastMath.min(minLat, position.getLatitude());
- minLng = FastMath.min(minLng, position.getLongitude());
- maxLat = FastMath.max(maxLat, position.getLatitude());
- maxLng = FastMath.max(maxLng, position.getLongitude());
- }
- setRect(minLat, minLng, maxLat, maxLng);
- }
-
- /**
- * Sets the internal rectangle representation.
- * @param minLat The minimum latitude.
- * @param minLng The minimum longitude.
- * @param maxLat The maximum latitude.
- * @param maxLng The maximum longitude.
- */
- private void setRect(double minLat, double minLng, double maxLat, double maxLng)
- {
- if (!(minLat < maxLat))
- {
- throw new IllegalArgumentException("GeoBounds is not valid - minLat must be less that maxLat.");
- }
- if (!(minLng < maxLng))
- {
- if (minLng > 0 && minLng < 180 && maxLng < 0)
- {
- rects = new Rectangle2D[] {
- // split into two rects e.g. 176.8793 to 180 and -180 to
- // -175.0104
- new Rectangle2D.Double(minLng, minLat, 180 - minLng, maxLat - minLat),
- new Rectangle2D.Double(-180, minLat, maxLng + 180, maxLat - minLat) };
- }
- else
- {
- rects = new Rectangle2D[] { new Rectangle2D.Double(minLng, minLat, maxLng - minLng, maxLat - minLat) };
-
- throw new IllegalArgumentException("GeoBounds is not valid - minLng must be less that maxLng or "
- + "minLng must be greater than 0 and maxLng must be less than 0.");
- }
- }
- else
- {
- rects = new Rectangle2D[] { new Rectangle2D.Double(minLng, minLat, maxLng - minLng, maxLat - minLat) };
- }
- }
-
- /**
- * Determines if this bounds intersects the other bounds.
- * @param other The other bounds to test for intersection with.
- * @return Returns true if bounds intersect.
- */
- public boolean intersects(GeoBounds other)
- {
- boolean rv = false;
- for (Rectangle2D r1 : rects)
- {
- for (Rectangle2D r2 : other.rects)
- {
- rv = r1.intersects(r2);
- if (rv)
- {
- break;
- }
- }
- if (rv)
- {
- break;
- }
-
- }
- return rv;
- }
-
- /**
- * Gets the north west position.
- * @return Returns the north west position.
- */
- public GeoPosition getNorthWest()
- {
- return new GeoPosition(rects[0].getX(), rects[0].getMaxY());
- }
-
- /**
- * Gets the south east position.
- * @return Returns the south east position.
- */
- public GeoPosition getSouthEast()
- {
- Rectangle2D r = rects[0];
- if (rects.length > 1)
- {
- r = rects[1];
- }
- return new GeoPosition(r.getMaxX(), r.getY());
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/LocalResponseCache.java b/src/main/java/org/jdesktop/swingx/mapviewer/LocalResponseCache.java
deleted file mode 100644
index 81a97865..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/LocalResponseCache.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.mapviewer;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.CacheRequest;
-import java.net.CacheResponse;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.ResponseCache;
-import java.net.URI;
-import java.net.URLConnection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author joshy
- */
-public class LocalResponseCache extends ResponseCache
-{
- private final static Logger mLog =
- LoggerFactory.getLogger( LocalResponseCache.class );
-
- private final File cacheDir;
-
- private boolean checkForUpdates;
-
- private String baseURL;
-
- /**
- * Private constructor to prevent instantiation.
- * @param baseURL the URI that should be cached or null (for all URLs)
- * @param cacheDir the cache directory
- * @param checkForUpdates true if the URL is queried for newer versions of a file first
- */
- private LocalResponseCache(String baseURL, File cacheDir, boolean checkForUpdates)
- {
- this.baseURL = baseURL;
- this.cacheDir = cacheDir;
- this.checkForUpdates = checkForUpdates;
-
- if (!cacheDir.exists())
- {
- cacheDir.mkdirs();
- }
- }
-
- /**
- * Sets this cache as default response cache
- * @param baseURL the URL, the caching should be restricted to or null for none
- * @param cacheDir the cache directory
- * @param checkForUpdates true if the URL is queried for newer versions of a file first
- */
- public static void installResponseCache(String baseURL, File cacheDir, boolean checkForUpdates)
- {
- ResponseCache.setDefault(new LocalResponseCache(baseURL, cacheDir, checkForUpdates));
- }
-
- /**
- * Returns the local File corresponding to the given remote URI.
- * @param remoteUri the remote URI
- * @return the corresponding local file
- */
- public File getLocalFile(URI remoteUri)
- {
- if (baseURL != null)
- {
- String remote = remoteUri.toString();
-
- if (!remote.startsWith(baseURL))
- {
- return null;
- }
- }
-
-
- StringBuilder sb = new StringBuilder();
-
- String host = remoteUri.getHost();
- String query = remoteUri.getQuery();
- String path = remoteUri.getPath();
- String fragment = remoteUri.getFragment();
-
- if (host != null)
- {
- sb.append(host);
- }
- if (path != null)
- {
- sb.append(path);
- }
- if (query != null)
- {
- sb.append('?');
- sb.append(query);
- }
- if (fragment != null)
- {
- sb.append('#');
- sb.append(fragment);
- }
-
- String name;
-
- final int maxLen = 250;
-
- if (sb.length() < maxLen)
- {
- name = sb.toString();
- }
- else
- {
- name = sb.substring(0, maxLen);
- }
-
- name = name.replace('?', '$');
- name = name.replace('*', '$');
- name = name.replace(':', '$');
- name = name.replace('<', '$');
- name = name.replace('>', '$');
- name = name.replace('"', '$');
-
- File f = new File(cacheDir, name);
-
- return f;
- }
-
- /**
- * @param remoteUri the remote URI
- * @param localFile the corresponding local file
- * @return true if the resource at the given remote URI is newer than the resource cached locally.
- */
- private static boolean isUpdateAvailable(URI remoteUri, File localFile)
- {
- URLConnection conn;
- try
- {
- conn = remoteUri.toURL().openConnection();
- }
- catch (MalformedURLException ex)
- {
- mLog.error("An exception occurred - ", ex );
- return false;
- }
- catch (IOException ex)
- {
- mLog.error("An exception occurred - ", ex );
- return false;
- }
- if (!(conn instanceof HttpURLConnection))
- {
- // don't bother with non-http connections
- return false;
- }
-
- long localLastMod = localFile.lastModified();
- long remoteLastMod = 0L;
- HttpURLConnection httpconn = (HttpURLConnection) conn;
- // disable caching so we don't get in feedback loop with ResponseCache
- httpconn.setUseCaches(false);
- try
- {
- httpconn.connect();
- remoteLastMod = httpconn.getLastModified();
- }
- catch (IOException ex)
- {
- // log.error("An exception occurred", ex);();
- return false;
- }
- finally
- {
- httpconn.disconnect();
- }
-
- return (remoteLastMod > localLastMod);
- }
-
- @Override
- public CacheResponse get(URI uri, String rqstMethod, Map> rqstHeaders) throws IOException
- {
- File localFile = getLocalFile(uri);
-
- if (localFile == null)
- {
- // we don't want to cache this URL
- return null;
- }
-
- if (!localFile.exists())
- {
- // the file isn't already in our cache, return null
- return null;
- }
-
- if (checkForUpdates)
- {
- if (isUpdateAvailable(uri, localFile))
- {
- // there is an update available, so don't return cached version
- return null;
- }
- }
-
- return new LocalCacheResponse(localFile, rqstHeaders);
- }
-
- @Override
- public CacheRequest put(URI uri, URLConnection conn) throws IOException
- {
- // only cache http(s) GET requests
- if (!(conn instanceof HttpURLConnection) || !(((HttpURLConnection) conn).getRequestMethod().equals("GET")))
- {
- return null;
- }
-
- File localFile = getLocalFile(uri);
-
- if (localFile == null)
- {
- // we don't want to cache this URL
- return null;
- }
-
- new File(localFile.getParent()).mkdirs();
- return new LocalCacheRequest(localFile);
- }
-
- private class LocalCacheResponse extends CacheResponse
- {
- private FileInputStream fis;
- private final Map> headers;
-
- private LocalCacheResponse(File localFile, Map> rqstHeaders)
- {
- try
- {
- this.fis = new FileInputStream(localFile);
- }
- catch (FileNotFoundException ex)
- {
- // should not happen, since we already checked for existence
- mLog.error("An exception occurred - ", ex );
- }
- this.headers = rqstHeaders;
- }
-
- @Override
- public Map> getHeaders() throws IOException
- {
- return headers;
- }
-
- @Override
- public InputStream getBody() throws IOException
- {
- return fis;
- }
- }
-
- private class LocalCacheRequest extends CacheRequest
- {
- private final File localFile;
- private FileOutputStream fos;
-
- private LocalCacheRequest(File localFile)
- {
- this.localFile = localFile;
- try
- {
- this.fos = new FileOutputStream(localFile);
- }
- catch (FileNotFoundException ex)
- {
- // should not happen if cache dir is valid
- mLog.error("An exception occurred", ex );
- }
- }
-
- @Override
- public OutputStream getBody() throws IOException
- {
- return fos;
- }
-
- @Override
- public void abort()
- {
- // abandon the cache attempt by closing the stream and deleting
- // the local file
- try
- {
- fos.close();
- localFile.delete();
- }
- catch (IOException e)
- {
- // ignore
- }
- }
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/Tile.java b/src/main/java/org/jdesktop/swingx/mapviewer/Tile.java
deleted file mode 100644
index 91065e08..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/Tile.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Tile.java
- *
- * Created on March 14, 2006, 4:53 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-import org.jdesktop.beans.AbstractBean;
-
-import java.awt.image.BufferedImage;
-import java.lang.ref.SoftReference;
-
-/**
- * The Tile class represents a particular square image piece of the world bitmap at a particular zoom level.
- * @author joshy
- */
-
-public class Tile extends AbstractBean
-{
- /**
- * The loading priority
- */
- @SuppressWarnings("javadoc")
- public enum Priority
- {
- High, Low
- }
-
- private Priority priority = Priority.High;
-
- private TileFactory dtf;
-
- private boolean isLoading = false;
-
- // Most Recently Accessed Tiles. These are strong references, to prevent reloading
- // of most recently used tiles.
- // private static final Map recentlyAccessed = new HashMap();
- // private static final TileCache cache = new TileCache();
-
- /**
- * The url of the image to load for this tile
- */
- private String url;
-
- /**
- * Indicates that loading has succeeded. A PropertyChangeEvent will be fired when the loading is completed
- */
-
- private boolean loaded = false;
- /**
- * The zoom level this tile is for
- */
- private int zoom, x, y;
-
- /**
- * The image loaded for this Tile
- */
- SoftReference image = new SoftReference(null);
-
- /**
- * Create a new Tile at the specified tile point and zoom level
- * @param x the x value
- * @param y the y value
- * @param zoom the zoom level
- */
- public Tile(int x, int y, int zoom)
- {
- loaded = false;
- this.zoom = zoom;
- this.x = x;
- this.y = y;
- }
-
- /**
- * Create a new Tile that loads its data from the given URL. The URL must resolve to an image
- * @param x the x value
- * @param y the y value
- * @param zoom the zoom level
- * @param url the URL
- * @param priority the priority
- * @param dtf the tile factory
- */
- Tile(int x, int y, int zoom, String url, Priority priority, TileFactory dtf)
- {
- this.url = url;
- loaded = false;
- this.zoom = zoom;
- this.x = x;
- this.y = y;
- this.priority = priority;
- this.dtf = dtf;
- // startLoading();
- }
-
- /**
- * Indicates if this tile's underlying image has been successfully loaded yet.
- * @return true if the Tile has been loaded
- */
- public synchronized boolean isLoaded()
- {
- return loaded;
- }
-
- /**
- * Toggles the loaded state, and fires the appropriate property change notification
- * @param loaded the loaded flag
- */
- synchronized void setLoaded(boolean loaded)
- {
- boolean old = isLoaded();
- this.loaded = loaded;
- firePropertyChange("loaded", old, isLoaded());
- }
-
- /**
- * @return the Image associated with this Tile. This is a read only property This may return null at any time,
- * however if this returns null, a load operation will automatically be started for it.
- */
- public BufferedImage getImage()
- {
- BufferedImage img = image.get();
- if (img == null)
- {
- setLoaded(false);
-
- // tile factory can be null if the tile has invalid coords or zoom
- if (dtf != null)
- {
- dtf.startLoading(this);
- }
- }
-
- return img;
- }
-
- /**
- * @return the location in the world at this zoom level that this tile should be placed
- */
- /*
- * public TilePoint getLocation() { return location; }
- */
-
- /**
- * @return the zoom level that this tile belongs in
- */
- public int getZoom()
- {
- return zoom;
- }
-
- /**
- * @return the isLoading
- */
- public boolean isLoading()
- {
- return isLoading;
- }
-
- /**
- * @param isLoading the isLoading to set
- */
- public void setLoading(boolean isLoading)
- {
- this.isLoading = isLoading;
- }
-
- /**
- * Gets the loading priority of this tile.
- * @return the priority
- */
- public Priority getPriority()
- {
- return priority;
- }
-
- /**
- * Set the loading priority of this tile.
- * @param priority the priority to set
- */
- public void setPriority(Priority priority)
- {
- this.priority = priority;
- }
-
- /**
- * Gets the URL of this tile.
- * @return the url
- */
- public String getURL()
- {
- return url;
- }
-
- /**
- * @return the x value
- */
- public int getX()
- {
- return x;
- }
-
- /**
- * @return the y value
- */
- public int getY()
- {
- return y;
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/TileCache.java b/src/main/java/org/jdesktop/swingx/mapviewer/TileCache.java
deleted file mode 100644
index 713d9eb3..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/TileCache.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * TileCache.java
- *
- * Created on January 2, 2007, 7:17 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-
-/**
- * An implementation only class for now. For internal use only.
- * @author joshua.marinacci@sun.com
- */
-public class TileCache
-{
- private Map imgmap = new HashMap();
- private LinkedList imgmapAccessQueue = new LinkedList();
- private int imagesize = 0;
- private Map bytemap = new HashMap();
- private LinkedList bytemapAccessQueue = new LinkedList();
- private int bytesize = 0;
-
- /**
- * Default constructor - Empty
- */
- public TileCache()
- {
- }
-
- /**
- * Put a tile image into the cache. This puts both a buffered image and array of bytes that make up the compressed
- * image.
- * @param uri URI of image that is being stored in the cache
- * @param bimg bytes of the compressed image, ie: the image file that was loaded over the network
- * @param img image to store in the cache
- */
- public void put(URI uri, byte[] bimg, BufferedImage img)
- {
- synchronized (bytemap)
- {
- while (bytesize > 1000 * 1000 * 50)
- {
- URI olduri = bytemapAccessQueue.removeFirst();
- byte[] oldbimg = bytemap.remove(olduri);
- bytesize -= oldbimg.length;
- log("removed 1 img from byte cache");
- }
-
- bytemap.put(uri, bimg);
- bytesize += bimg.length;
- bytemapAccessQueue.addLast(uri);
- }
- addToImageCache(uri, img);
- }
-
- /**
- * Returns a buffered image for the requested URI from the cache. This method must return null if the image is not
- * in the cache. If the image is unavailable but it's compressed version *is* available, then the compressed version
- * will be expanded and returned.
- * @param uri URI of the image previously put in the cache
- * @return the image matching the requested URI, or null if not available
- * @throws IOException if retrieval fails
- */
- public BufferedImage get(URI uri) throws IOException
- {
- synchronized (imgmap)
- {
- if (imgmap.containsKey(uri))
- {
- imgmapAccessQueue.remove(uri);
- imgmapAccessQueue.addLast(uri);
- return imgmap.get(uri);
- }
- }
- synchronized (bytemap)
- {
- if (bytemap.containsKey(uri))
- {
- log("retrieving from bytes");
- bytemapAccessQueue.remove(uri);
- bytemapAccessQueue.addLast(uri);
- BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytemap.get(uri)));
- addToImageCache(uri, img);
- return img;
- }
- }
- return null;
- }
-
- /**
- * Request that the cache free up some memory. How this happens or how much memory is freed is up to the TileCache
- * implementation. Subclasses can implement their own strategy. The default strategy is to clear out all buffered
- * images but retain the compressed versions.
- */
- public void needMoreMemory()
- {
- imgmap.clear();
- log("HACK! need more memory: freeing up memory");
- }
-
- private void addToImageCache(final URI uri, final BufferedImage img)
- {
- synchronized (imgmap)
- {
- try {
- while (imagesize > 1000 * 1000 * 50)
- {
- URI olduri = imgmapAccessQueue.removeFirst();
- BufferedImage oldimg = imgmap.remove(olduri);
- imagesize -= oldimg.getWidth() * oldimg.getHeight() * 4;
- log("removed 1 img from image cache");
- }
- imgmap.put(uri, img);
- imagesize += img.getWidth() * img.getHeight() * 4;
- imgmapAccessQueue.addLast(uri);
- } catch (Exception ex) {
- log("Failed to load tile at URL. Tile is null");
- }
- }
-// log("added to cache: " + " uncompressed = " + imgmap.keySet().size() + " / " + imagesize / 1000 + "k"
-// + " compressed = " + bytemap.keySet().size() + " / " + bytesize / 1000 + "k");
- }
-
- private void log(String string)
- {
-// Log.debug( string );
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/TileFactory.java b/src/main/java/org/jdesktop/swingx/mapviewer/TileFactory.java
deleted file mode 100644
index 8e5fb5f1..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/TileFactory.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * TileFactory.java
- *
- * Created on March 17, 2006, 8:01 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-import org.jdesktop.swingx.mapviewer.util.GeoUtil;
-
-import java.awt.*;
-import java.awt.geom.Point2D;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A class that can produce tiles and convert coordinates to pixels
- * @author joshy
- */
-public abstract class TileFactory
-{
- private TileFactoryInfo info;
- private List tileListeners = new ArrayList();
-
- /**
- * Creates a new instance of TileFactory
- * @param info a TileFactoryInfo to configure this TileFactory
- */
- protected TileFactory(TileFactoryInfo info)
- {
- this.info = info;
- }
-
- /**
- * Gets the size of an edge of a tile in pixels at the current zoom level. Tiles must be square.
- * @param zoom the current zoom level
- * @return the size of an edge of a tile in pixels
- */
- public int getTileSize(int zoom)
- {
- return getInfo().getTileSize(zoom);
- }
-
- /**
- * Returns a Dimension containing the width and height of the map, in tiles at the current zoom level. So a
- * Dimension that returns 10x20 would be 10 tiles wide and 20 tiles tall. These values can be multipled by
- * getTileSize() to determine the pixel width/height for the map at the given zoom level
- * @return the size of the world bitmap in tiles
- * @param zoom the current zoom level
- */
- public Dimension getMapSize(int zoom)
- {
- return GeoUtil.getMapSize(zoom, getInfo());
- }
-
- /**
- * Return the Tile at a given TilePoint and zoom level
- * @return the tile that is located at the given tilePoint for this zoom level. For example, if getMapSize() returns
- * 10x20 for this zoom, and the tilePoint is (3,5), then the appropriate tile will be located and returned. This
- * method must not return null. However, it can return dummy tiles that contain no data if it wants. This is
- * appropriate, for example, for tiles which are outside of the bounds of the map and if the factory doesn't
- * implement wrapping.
- * @param x the x value
- * @param y the y value
- * @param zoom the current zoom level
- */
- public abstract Tile getTile(int x, int y, int zoom);
-
- /**
- * Convert a pixel in the world bitmap at the specified zoom level into a GeoPosition
- * @param pixelCoordinate a Point2D representing a pixel in the world bitmap
- * @param zoom the zoom level of the world bitmap
- * @return the converted GeoPosition
- */
- public GeoPosition pixelToGeo(Point2D pixelCoordinate, int zoom)
- {
- return GeoUtil.getPosition(pixelCoordinate, zoom, getInfo());
- }
-
- /**
- * Convert a GeoPosition to a pixel position in the world bitmap a the specified zoom level.
- * @param c a GeoPosition
- * @param zoomLevel the zoom level to extract the pixel coordinate for
- * @return the pixel point
- */
- public Point2D geoToPixel(GeoPosition c, int zoomLevel)
- {
- return GeoUtil.getBitmapCoordinate(c, zoomLevel, getInfo());
- }
-
- /**
- * Get the TileFactoryInfo describing this TileFactory
- * @return a TileFactoryInfo
- */
- public TileFactoryInfo getInfo()
- {
- return info;
- }
-
- /**
- * Adds a tile listener
- * @param listener the listener
- */
- public void addTileListener(TileListener listener)
- {
- tileListeners.add(listener);
- }
-
- /**
- * Removes a tile listener
- * @param listener the listener
- */
- public void removeTileListener(TileListener listener)
- {
- tileListeners.remove(listener);
- }
-
- /**
- * Disposes this TileFactory
- */
- public abstract void dispose();
-
- /**
- * Notifies all tile listeners
- * @param tile the tile
- */
- protected void fireTileLoadedEvent(Tile tile)
- {
- for (TileListener listener : tileListeners)
- {
- listener.tileLoaded(tile);
- }
- }
-
- /**
- * Override this method to load the tile using, for example, an ExecutorService.
- * @param tile The tile to load.
- */
- protected abstract void startLoading(Tile tile);
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/TileFactoryInfo.java b/src/main/java/org/jdesktop/swingx/mapviewer/TileFactoryInfo.java
deleted file mode 100644
index 41b50f91..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/TileFactoryInfo.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * TileFactoryInfo.java
- *
- * Created on June 26, 2006, 10:47 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-import org.apache.commons.math3.util.FastMath;
-
-import java.awt.geom.Point2D;
-
-/**
- * A TileFactoryInfo encapsulates all information specific to a map server. This includes everything from the url to
- * load the map tiles from to the size and depth of the tiles. Theoretically any map server can be used by installing a
- * customized TileFactoryInfo. Currently
- * @author joshy
- */
-public class TileFactoryInfo
-{
- private int minimumZoomLevel;
- private int maximumZoomLevel;
- private int totalMapZoom;
- // the size of each tile (assumes they are square)
- private int tileSize = 256;
-
- /*
- * The number of tiles wide at each zoom level
- */
- private int[] mapWidthInTilesAtZoom;
- /**
- * An array of coordinates in pixels that indicates the center in the world map for the given zoom level.
- */
- private Point2D[] mapCenterInPixelsAtZoom;// = new Point2D.Double[18];
-
- /**
- * An array of doubles that contain the number of pixels per degree of longitude at a give zoom level.
- */
- private double[] longitudeDegreeWidthInPixels;
-
- /**
- * An array of doubles that contain the number of radians per degree of longitude at a given zoom level (where
- * longitudeRadianWidthInPixels[0] is the most zoomed out)
- */
- private double[] longitudeRadianWidthInPixels;
-
- /**
- * The base url for loading tiles from.
- */
- protected String baseURL;
- private String xparam;
- private String yparam;
- private String zparam;
- private boolean xr2l = true;
- private boolean yt2b = true;
-
- private int defaultZoomLevel;
-
- /** A name for this info. */
- private String name;
-
- /**
- * Creates a new instance of TileFactoryInfo. Note that TileFactoryInfo should be considered invariate, meaning that
- * subclasses should ensure all of the properties stay the same after the class is constructed. Returning different
- * values of getTileSize() for example is considered an error and may result in unexpected behavior.
- * @param minimumZoomLevel The minimum zoom level
- * @param maximumZoomLevel the maximum zoom level
- * @param totalMapZoom the top zoom level, essentially the height of the pyramid
- * @param tileSize the size of the tiles in pixels (must be square)
- * @param xr2l if the x goes r to l (is this backwards?)
- * @param yt2b if the y goes top to bottom
- * @param baseURL the base url for grabbing tiles
- * @param xparam the x parameter for the tile url
- * @param yparam the y parameter for the tile url
- * @param zparam the z parameter for the tile url
- */
- /*
- * @param xr2l true if tile x is measured from the far left of the map to the far right, or else false if based on
- * the center line.
- * @param yt2b true if tile y is measured from the top (north pole) to the bottom (south pole) or else false if
- * based on the equator.
- */
- public TileFactoryInfo(int minimumZoomLevel, int maximumZoomLevel, int totalMapZoom, int tileSize, boolean xr2l,
- boolean yt2b, String baseURL, String xparam, String yparam, String zparam)
- {
- this("name not provided", minimumZoomLevel, maximumZoomLevel, totalMapZoom, tileSize, xr2l, yt2b, baseURL,
- xparam, yparam, zparam);
- }
-
- /**
- * Creates a new instance of TileFactoryInfo. Note that TileFactoryInfo should be considered invariate, meaning that
- * subclasses should ensure all of the properties stay the same after the class is constructed. Returning different
- * values of getTileSize() for example is considered an error and may result in unexpected behavior.
- * @param name A name to identify this information.
- * @param minimumZoomLevel The minimum zoom level
- * @param maximumZoomLevel the maximum zoom level
- * @param totalMapZoom the top zoom level, essentially the height of the pyramid
- * @param tileSize the size of the tiles in pixels (must be square)
- * @param xr2l if the x goes r to l (is this backwards?)
- * @param yt2b if the y goes top to bottom
- * @param baseURL the base url for grabbing tiles
- * @param xparam the x parameter for the tile url
- * @param yparam the y parameter for the tile url
- * @param zparam the z parameter for the tile url
- */
- /*
- * @param xr2l true if tile x is measured from the far left of the map to the far right, or else false if based on
- * the center line.
- * @param yt2b true if tile y is measured from the top (north pole) to the bottom (south pole) or else false if
- * based on the equator.
- */
- public TileFactoryInfo(String name, int minimumZoomLevel, int maximumZoomLevel, int totalMapZoom, int tileSize,
- boolean xr2l, boolean yt2b, String baseURL, String xparam, String yparam, String zparam)
- {
- this.name = name;
- this.minimumZoomLevel = minimumZoomLevel;
- this.maximumZoomLevel = maximumZoomLevel;
- this.totalMapZoom = totalMapZoom;
- this.baseURL = baseURL;
- this.xparam = xparam;
- this.yparam = yparam;
- this.zparam = zparam;
- this.setXr2l(xr2l);
- this.setYt2b(yt2b);
-
- this.tileSize = tileSize;
-
- // init the num tiles wide
- int tilesize = this.getTileSize(0);
-
- longitudeDegreeWidthInPixels = new double[totalMapZoom + 1];
- longitudeRadianWidthInPixels = new double[totalMapZoom + 1];
- mapCenterInPixelsAtZoom = new Point2D.Double[totalMapZoom + 1];
- mapWidthInTilesAtZoom = new int[totalMapZoom + 1];
-
- // for each zoom level
- for (int z = totalMapZoom; z >= 0; --z)
- {
- // how wide is each degree of longitude in pixels
- longitudeDegreeWidthInPixels[z] = tilesize / 360.0;
- // how wide is each radian of longitude in pixels
- longitudeRadianWidthInPixels[z] = tilesize / (2.0 * FastMath.PI);
- int t2 = tilesize / 2;
- mapCenterInPixelsAtZoom[z] = new Point2D.Double(t2, t2);
- mapWidthInTilesAtZoom[z] = tilesize / this.getTileSize(0);
- tilesize *= 2;
- }
-
- }
-
- /**
- * @return the minimum zoom level
- */
- public int getMinimumZoomLevel()
- {
- return minimumZoomLevel;
- }
-
- // public void setMinimumZoomLevel(int minimumZoomLevel) {
- // this.minimumZoomLevel = minimumZoomLevel;
- // }
-
- /**
- * @return the maximum zoom level
- */
- public int getMaximumZoomLevel()
- {
- return maximumZoomLevel;
- }
-
- /**
- * @return the total map zoom level
- */
- public int getTotalMapZoom()
- {
- return totalMapZoom;
- }
-
- /**
- * @param zoom the zoom level
- * @return the map width in tiles
- */
- public int getMapWidthInTilesAtZoom(int zoom)
- {
- return mapWidthInTilesAtZoom[zoom];
- }
-
- /**
- * @param zoom the zoom level
- * @return the map center in pixels
- */
- public Point2D getMapCenterInPixelsAtZoom(int zoom)
- {
- return mapCenterInPixelsAtZoom[zoom];
- }
-
- /**
- * Returns the tile url for the specified tile at the specified zoom level. By default it will generate a tile url
- * using the base url and parameters specified in the constructor. Thus if
baseURl =
- * http://www.myserver.com/maps?version=0.1 xparam = x yparam = y zparam = z tilepoint = [1,2] zoom level = 3
- *
Note that the URL can be
- * a file: url.
- * @param zoom the zoom level
- * @param x the x value
- * @param y the y value
- * @return a valid url to load the tile
- */
-
- public String getTileUrl(int x, int y, int zoom)
- {
- // System.out.println("getting tile at zoom: " + zoom);
- // System.out.println("map width at zoom = " + getMapWidthInTilesAtZoom(zoom));
- String ypart = "&" + yparam + "=" + y;
- // System.out.println("ypart = " + ypart);
-
- if (!yt2b)
- {
- int tilemax = getMapWidthInTilesAtZoom(zoom);
- // int y = tilePoint.getY();
- ypart = "&" + yparam + "=" + (tilemax / 2 - y - 1);
- }
- // System.out.println("new ypart = " + ypart);
- String url = baseURL + "&" + xparam + "=" + x + ypart +
- // "&" + yparam + "=" + tilePoint.getY() +
- "&" + zparam + "=" + zoom;
- return url;
- }
-
- /**
- * Get the tile size.
- * @param zoom the zoom level
- * @return the tile size
- */
- public int getTileSize(int zoom)
- {
- return tileSize;
- }
-
- /**
- * @param zoom the zoom level
- * @return the longitude degree width in pixels
- */
- public double getLongitudeDegreeWidthInPixels(int zoom)
- {
- return longitudeDegreeWidthInPixels[zoom];
- }
-
- /**
- * @param zoom the zoom level
- * @return the longitude radian width in pixels
- */
- public double getLongitudeRadianWidthInPixels(int zoom)
- {
- return longitudeRadianWidthInPixels[zoom];
- }
-
- /**
- * @return indicates if the X coordinates of tiles go from right to left or left to right.
- */
- public boolean isXr2l()
- {
- return xr2l;
- }
-
- /**
- * @param xr2l indicates if the X coordinates of tiles go from right to left or left to right.
- */
- public void setXr2l(boolean xr2l)
- {
- this.xr2l = xr2l;
- }
-
- /**
- * @return indicates if the Y coordinates of tiles go from right to left or left to right.
- */
- public boolean isYt2b()
- {
- return yt2b;
- }
-
- /**
- * @param yt2b indicates if the Y coordinates of tiles go from right to left or left to right.
- */
- public void setYt2b(boolean yt2b)
- {
- this.yt2b = yt2b;
- }
-
- /**
- * @return the default zoom level
- */
- public int getDefaultZoomLevel()
- {
- return defaultZoomLevel;
- }
-
- /**
- * @param defaultZoomLevel the default zoom level
- */
- public void setDefaultZoomLevel(int defaultZoomLevel)
- {
- this.defaultZoomLevel = defaultZoomLevel;
- }
-
- /**
- * The name of this info.
- * @return Returns the name of this info class for debugging or GUI widgets.
- */
- public String getName()
- {
- return name;
- }
-
- /**
- * @return the base URL
- */
- public String getBaseURL()
- {
- return baseURL;
- }
-
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/TileListener.java b/src/main/java/org/jdesktop/swingx/mapviewer/TileListener.java
deleted file mode 100644
index 55d1d13b..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/TileListener.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.mapviewer;
-
-/**
- * Notified when the status of a tile has changed
- * @author Martin Steiger
- */
-public interface TileListener
-{
- /**
- * Notification when a tile is loaded
- * @param tile the tile
- */
- public void tileLoaded(Tile tile);
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/Waypoint.java b/src/main/java/org/jdesktop/swingx/mapviewer/Waypoint.java
deleted file mode 100644
index b5c06033..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/Waypoint.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Waypoint.java
- *
- * Created on March 30, 2006, 5:22 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-
-/**
- * A Waypoint is a GeoPosition that can be
- * drawn on a may using a WaypointPainter.
- * @author joshy
- */
-public interface Waypoint
-{
- /**
- * Get the current GeoPosition of this Waypoint
- * @return the current position
- */
- public GeoPosition getPosition();
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/WaypointPainter.java b/src/main/java/org/jdesktop/swingx/mapviewer/WaypointPainter.java
deleted file mode 100644
index 17d31214..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/WaypointPainter.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * *****************************************************************************
- * Copyright (C) 2014-2022 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- * ****************************************************************************
- */
-
-/*
- * WaypointMapOverlay.java
- *
- * Created on April 1, 2006, 4:59 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer;
-
-import org.jdesktop.swingx.JXMapViewer;
-import org.jdesktop.swingx.painter.AbstractPainter;
-
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Paints waypoints on the JXMapViewer. This is an
- * instance of Painter that only can draw on to JXMapViewers.
- * @param the waypoint type
- * @author rbair
- */
-public class WaypointPainter extends AbstractPainter
-{
- private WaypointRenderer super W> renderer = new DefaultWaypointRenderer();
- private Set waypoints = new HashSet();
-
- /**
- * Creates a new instance of WaypointPainter
- */
- public WaypointPainter()
- {
- setAntialiasing(true);
- setCacheable(false);
- }
-
- /**
- * Sets the waypoint renderer to use when painting waypoints
- * @param r the new WaypointRenderer to use
- */
- public void setRenderer(WaypointRenderer r)
- {
- this.renderer = r;
- }
-
- /**
- * Gets the current set of waypoints to paint
- * @return a typed Set of Waypoints
- */
- public Set getWaypoints()
- {
- return Collections.unmodifiableSet(waypoints);
- }
-
- /**
- * Sets the current set of waypoints to paint
- * @param waypoints the new Set of Waypoints to use
- */
- public void setWaypoints(Set extends W> waypoints)
- {
- this.waypoints.clear();
- this.waypoints.addAll(waypoints);
- }
-
- @Override
- protected void doPaint(Graphics2D g, JXMapViewer map, int width, int height)
- {
- if (renderer == null)
- {
- return;
- }
-
- Rectangle viewportBounds = map.getViewportBounds();
-
- g.translate(-viewportBounds.getX(), -viewportBounds.getY());
-
- for (W w : getWaypoints())
- {
- renderer.paintWaypoint(g, map, w);
- }
-
- g.translate(viewportBounds.getX(), viewportBounds.getY());
-
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/bmng/CylindricalProjectionTileFactory.java b/src/main/java/org/jdesktop/swingx/mapviewer/bmng/CylindricalProjectionTileFactory.java
deleted file mode 100644
index 4ecf7e8c..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/bmng/CylindricalProjectionTileFactory.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.mapviewer.bmng;
-
-import org.apache.commons.math3.util.FastMath;
-import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
-import org.jdesktop.swingx.mapviewer.GeoPosition;
-
-import java.awt.*;
-import java.awt.geom.Point2D;
-
-/**
- * @author joshy
- */
-public class CylindricalProjectionTileFactory extends DefaultTileFactory
-{
- /**
- * Uses {@link SLMapServerInfo}
- */
- public CylindricalProjectionTileFactory()
- {
- this(new SLMapServerInfo());
- }
-
- /**
- * @param info the tile factory info
- */
- public CylindricalProjectionTileFactory(SLMapServerInfo info)
- {
- super(info);
- }
-
- @Override
- public Dimension getMapSize(int zoom)
- {
- int midpoint = ((SLMapServerInfo) getInfo()).getMidpoint();
- if (zoom < midpoint)
- {
- int w = (int) FastMath.pow(2, midpoint - zoom);
- return new Dimension(w, w / 2);
- // return super.getMapSize(zoom);
- }
- return new Dimension(2, 1);
- }
-
- @Override
- public Point2D geoToPixel(GeoPosition c, int zoom)
- {
- // calc the pixels per degree
- Dimension mapSizeInTiles = getMapSize(zoom);
- // double size_in_tiles = (double)getInfo().getMapWidthInTilesAtZoom(zoom);
- // double size_in_tiles = Math.pow(2, getInfo().getTotalMapZoom() - zoom);
- double size_in_pixels = mapSizeInTiles.getWidth() * getInfo().getTileSize(zoom);
- double ppd = size_in_pixels / 360;
-
- // the center of the world
- double centerX = this.getTileSize(zoom) * mapSizeInTiles.getWidth() / 2;
- double centerY = this.getTileSize(zoom) * mapSizeInTiles.getHeight() / 2;
-
- double x = c.getLongitude() * ppd + centerX;
- double y = -c.getLatitude() * ppd + centerY;
-
- return new Point2D.Double(x, y);
- }
-
- @Override
- public GeoPosition pixelToGeo(Point2D pix, int zoom)
- {
- // calc the pixels per degree
- Dimension mapSizeInTiles = getMapSize(zoom);
- double size_in_pixels = mapSizeInTiles.getWidth() * getInfo().getTileSize(zoom);
- double ppd = size_in_pixels / 360;
-
- // the center of the world
- double centerX = this.getTileSize(zoom) * mapSizeInTiles.getWidth() / 2;
- double centerY = this.getTileSize(zoom) * mapSizeInTiles.getHeight() / 2;
-
- double lon = (pix.getX() - centerX) / ppd;
- double lat = -(pix.getY() - centerY) / ppd;
-
- return new GeoPosition(lat, lon);
- }
-
- /*
- * x = lat * ppd + fact x - fact = lat * ppd (x - fact)/ppd = lat y = -lat*ppd + fact -(y-fact)/ppd = lat
- */
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/bmng/SLMapServerInfo.java b/src/main/java/org/jdesktop/swingx/mapviewer/bmng/SLMapServerInfo.java
deleted file mode 100644
index 47849cab..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/bmng/SLMapServerInfo.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * SDR Trunk
- * Copyright (C) 2014 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- ******************************************************************************/
-package org.jdesktop.swingx.mapviewer.bmng;
-
-import org.apache.commons.math3.util.FastMath;
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-
-/**
- * A TileFactoryInfo subclass which knows how to connect to the SwingLabs map server. This server contains 2k resolution
- * Blue Marble data from NASA.
- */
-public class SLMapServerInfo extends TileFactoryInfo
-{
- private static final int pyramid_top = 8 + 1;
- private static final int midpoint = 5;
- private static final int normal_tile_size = 675;
-
- /**
- * Uses the default base URL
- */
- public SLMapServerInfo()
- {
- this("http://maps.joshy.net/tiles/bmng_tiles_3");
- }
-
- /**
- * @param baseURL the base URL
- */
- public SLMapServerInfo(String baseURL)
- {
- // joshy: this was version one of the tiles
- // super(0, 5, 5, 256, true, false, "http://maps.joshy.net/bmng_tiles_1", "", "", "");
- // super(0, pyramid_top-1, pyramid_top,
- // 675,
- // true, false, "http://maps.joshy.net/bmng_tiles_2", "", "", "");
- // super(0, pyramid_top-1, pyramid_top,
- // normal_tile_size,
- // true, false, "file:/Users/joshy/projects/java.net/ImageTileCutter/tiles", "", "", "");
- super(0, pyramid_top - 1, pyramid_top, normal_tile_size, true, false, baseURL, "", "", "");
- setDefaultZoomLevel(0);
- }
-
- /**
- * @return the midpoint
- */
- public int getMidpoint()
- {
- return midpoint;
- }
-
- @Override
- public int getTileSize(int zoom)
- {
- int size = super.getTileSize(zoom);
- if (zoom < midpoint)
- {
- return size;
- }
- else
- {
- for (int i = 0; i < zoom + 1 - midpoint; i++)
- {
- size = size / 2;
- }
- return size;
- }
- }
-
- @Override
- public int getMapWidthInTilesAtZoom(int zoom)
- {
- if (zoom < midpoint)
- {
- return (int) FastMath.pow(2, midpoint - zoom);
- }
- else
- {
- return 1;
- }
- }
-
- @Override
- public String getTileUrl(int x, int y, int zoom)
- {
- int ty = y;
- int tx = x;
-
- // int width_in_tiles = (int)Math.pow(2,pyramid_top-zoom);
- int width_in_tiles = getMapWidthInTilesAtZoom(zoom);
- // System.out.println("width in tiles = " + width_in_tiles + " x = " + tx + " y = " + ty);
- if (ty < 0)
- {
- return null;
- }
- if (zoom < midpoint)
- {
- if (ty >= width_in_tiles / 2)
- {
- return null;
- }
- }
- else
- {
- if (ty != 0)
- {
- return null;
- }
- }
-
- String url = this.baseURL + "/" + zoom + "/" + ty + "/" + tx + ".jpg";
- // System.out.println("returning: " + url);
- return url;
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/empty/EmptyTileFactory.java b/src/main/java/org/jdesktop/swingx/mapviewer/empty/EmptyTileFactory.java
deleted file mode 100644
index 4470cf9e..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/empty/EmptyTileFactory.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * EmptyTileFactory.java
- *
- * Created on June 7, 2006, 4:58 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer.empty;
-
-import org.jdesktop.swingx.mapviewer.Tile;
-import org.jdesktop.swingx.mapviewer.TileFactory;
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-
-import java.awt.*;
-import java.awt.image.BufferedImage;
-
-/**
- * A null implementation of TileFactory. Draws empty areas.
- * @author joshy
- */
-public class EmptyTileFactory extends TileFactory
-{
- /**
- * The empty tile image.
- */
- private BufferedImage emptyTile;
-
- /**
- * Creates a new instance of EmptyTileFactory
- */
- public EmptyTileFactory()
- {
- this(new TileFactoryInfo("EmptyTileFactory 256x256", 1, 15, 17, 256, true, true, "", "x", "y", "z"));
- }
-
- /**
- * Creates a new instance of EmptyTileFactory using the specified info.
- * @param info the tile factory info
- */
- public EmptyTileFactory(TileFactoryInfo info)
- {
- super(info);
- int tileSize = info.getTileSize(info.getMinimumZoomLevel());
- emptyTile = new BufferedImage(tileSize, tileSize, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = emptyTile.createGraphics();
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g.setColor(Color.GRAY);
- g.fillRect(0, 0, tileSize, tileSize);
- g.setColor(Color.WHITE);
- g.drawOval(10, 10, tileSize - 20, tileSize - 20);
- g.fillOval(70, 50, 20, 20);
- g.fillOval(tileSize - 90, 50, 20, 20);
- g.fillOval(tileSize / 2 - 10, tileSize / 2 - 10, 20, 20);
- g.dispose();
- }
-
- /**
- * Gets an instance of an empty tile for the given tile position and zoom on the world map.
- * @param x The tile's x position on the world map.
- * @param y The tile's y position on the world map.
- * @param zoom The current zoom level.
- */
- @Override
- public Tile getTile(int x, int y, int zoom)
- {
- return new Tile(x, y, zoom)
- {
- @Override
- public synchronized boolean isLoaded()
- {
- return true;
- }
-
- @Override
- public BufferedImage getImage()
- {
- return emptyTile;
- }
-
- };
- }
-
- @Override
- public void dispose()
- {
- // noop
- }
-
- /**
- * Override this method to load the tile using, for example, an ExecutorService.
- * @param tile The tile to load.
- */
- @Override
- protected void startLoading(Tile tile)
- {
- // noop
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/esri/ESRITileFactory.java b/src/main/java/org/jdesktop/swingx/mapviewer/esri/ESRITileFactory.java
deleted file mode 100644
index 0fe2d038..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/esri/ESRITileFactory.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ESRITileFactory.java
- *
- * Created on November 7, 2006, 10:51 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer.esri;
-
-import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
-import org.jdesktop.swingx.mapviewer.GeoPosition;
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-import org.jdesktop.swingx.mapviewer.util.GeoUtil;
-
-import java.awt.geom.Point2D;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-
-/**
- * @author rbair
- */
-public class ESRITileFactory extends DefaultTileFactory
-{
- private static final String projection = "8"; // mercator projection
- private static final String format = "png"; // get pngs back
- private String userId;
- private String datasource; // should be enum
-
- /** Creates a new instance of ESRITileFactory */
- public ESRITileFactory()
- {
- super(new ESRITileProviderInfo());
- ((ESRITileProviderInfo) super.getInfo()).factory = this;
- datasource = "ArcWeb:TA.Streets.NA";
- }
-
- /**
- * @param id the ESRI user id
- */
- public void setUserID(String id)
- {
- this.userId = id;
- }
-
- private static final class ESRITileProviderInfo extends TileFactoryInfo
- {
- private ESRITileFactory factory;
-
- private ESRITileProviderInfo()
- {
- super(0, 17, 18, 256, false, true, "http://www.arcwebservices.com/services/v2006/restmap?actn=getMap", "","", "");
- }
-
- @Override
- public String getTileUrl(int x, int y, int zoom)
- {
- // "&usrid=&ds=&c=-117.1817|34.0556&sf=52500&fmt=&ocs=";
- // System.out.println("getting tile at zoom: " + zoom);
- // System.out.println("map width at zoom = " + getMapWidthInTilesAtZoom(zoom));
-
- // provide the center point of the tile, in lat/long coords
- int tileY = y;
- int tileX = x;
- int pixelX = tileX * factory.getTileSize(zoom) + (factory.getTileSize(zoom) / 2);
- int pixelY = tileY * factory.getTileSize(zoom) + (factory.getTileSize(zoom) / 2);
-
- GeoPosition latlong = GeoUtil.getPosition(new Point2D.Double(pixelX, pixelY), zoom, this);
-
- // Chris is going to hate me for this (relying on 72dpi!), but:
- // 72 pixels per inch. The earth is 24,859.82 miles in circumference, at the equator.
- // Thus, the earth is 24,859.82 * 5280 * 12 * 72 pixels in circumference.
-
- double numFeetPerDegreeLong = 24859.82 * 5280 / 360; // the number of feet per degree longitude at the
- // equator
- double numPixelsPerDegreeLong = getLongitudeDegreeWidthInPixels(zoom);
- double numPixelsPerFoot = 96 * 12;
- int sf = (int) (numFeetPerDegreeLong / (numPixelsPerDegreeLong / numPixelsPerFoot));
-
- // round lat and long to 5 decimal places
- BigDecimal lat = new BigDecimal(latlong.getLatitude());
- BigDecimal lon = new BigDecimal(latlong.getLongitude());
- lat = lat.setScale(5, RoundingMode.DOWN);
- lon = lon.setScale(5, RoundingMode.DOWN);
- System.out.println("Tile : [" + tileX + ", " + tileY + "]");
- System.out.println("Pixel : [" + pixelX + ", " + pixelY + "]");
- System.out.println("Lat/Long : [" + latlong.getLatitude() + ", " + latlong.getLongitude() + "]");
- System.out.println("Lat2/Long2: [" + lat.doubleValue() + ", " + lon.doubleValue() + "]");
-
- String url = baseURL + "&usrid=" + factory.userId + "&ds=" + factory.datasource + "&c=" + lon.doubleValue()
- + "%7C" + lat.doubleValue() + "&sf=" + sf + // 52500" +
- "&fmt=" + format + "&ocs=" + projection;
- System.out.println("the URL: " + url);
- return url;
- }
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/resources/loading.png b/src/main/java/org/jdesktop/swingx/mapviewer/resources/loading.png
deleted file mode 100644
index c65be32c..00000000
Binary files a/src/main/java/org/jdesktop/swingx/mapviewer/resources/loading.png and /dev/null differ
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/resources/minus.png b/src/main/java/org/jdesktop/swingx/mapviewer/resources/minus.png
deleted file mode 100644
index 8fe9a8d4..00000000
Binary files a/src/main/java/org/jdesktop/swingx/mapviewer/resources/minus.png and /dev/null differ
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/resources/plus.png b/src/main/java/org/jdesktop/swingx/mapviewer/resources/plus.png
deleted file mode 100644
index c4b2097f..00000000
Binary files a/src/main/java/org/jdesktop/swingx/mapviewer/resources/plus.png and /dev/null differ
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/resources/standard_waypoint.png b/src/main/java/org/jdesktop/swingx/mapviewer/resources/standard_waypoint.png
deleted file mode 100644
index 7b130695..00000000
Binary files a/src/main/java/org/jdesktop/swingx/mapviewer/resources/standard_waypoint.png and /dev/null differ
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/util/GeoUtil.java b/src/main/java/org/jdesktop/swingx/mapviewer/util/GeoUtil.java
deleted file mode 100644
index c3e819c1..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/util/GeoUtil.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * GeoUtil.java
- *
- * Created on June 26, 2006, 10:44 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer.util;
-
-import org.apache.commons.math3.util.FastMath;
-import org.jdesktop.swingx.JXMapViewer;
-import org.jdesktop.swingx.mapviewer.GeoBounds;
-import org.jdesktop.swingx.mapviewer.GeoPosition;
-import org.jdesktop.swingx.mapviewer.TileFactory;
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-
-import java.awt.*;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * These are math utilities for converting between pixels, tiles, and geographic coordinates. Implements a Google Maps
- * style mercator projection.
- * @author joshy
- */
-public final class GeoUtil
-{
- /**
- * @param zoom the zoom level
- * @param info the tile factory info
- * @return the size of the map at the given zoom, in tiles (num tiles tall by num tiles wide)
- */
- public static Dimension getMapSize(int zoom, TileFactoryInfo info)
- {
- return new Dimension(info.getMapWidthInTilesAtZoom(zoom), info.getMapWidthInTilesAtZoom(zoom));
- }
-
- /**
- * @param x the x value
- * @param y the y value
- * @param zoomLevel the zoom level
- * @param info the tile factory info
- * @return true if this point in tiles is valid at this zoom level. For example, if the zoom level is 0
- * (zoomed all the way out, where there is only one tile), then x,y must be 0,0
- */
- public static boolean isValidTile(int x, int y, int zoomLevel, TileFactoryInfo info)
- {
- // int x = (int)coord.getX();
- // int y = (int)coord.getY();
- // if off the map to the top or left
- if (x < 0 || y < 0)
- {
- return false;
- }
- // if of the map to the right
- if (info.getMapCenterInPixelsAtZoom(zoomLevel).getX() * 2 <= x * info.getTileSize(zoomLevel))
- {
- return false;
- }
- // if off the map to the bottom
- if (info.getMapCenterInPixelsAtZoom(zoomLevel).getY() * 2 <= y * info.getTileSize(zoomLevel))
- {
- return false;
- }
- // if out of zoom bounds
- if (zoomLevel < info.getMinimumZoomLevel() || zoomLevel > info.getMaximumZoomLevel())
- {
- return false;
- }
- return true;
- }
-
- /**
- * Given a position (latitude/longitude pair) and a zoom level, return the appropriate point in pixels. The
- * zoom level is necessary because pixel coordinates are in terms of the zoom level
- * @param c A lat/lon pair
- * @param zoomLevel the zoom level to extract the pixel coordinate for
- * @param info the tile factory info
- * @return the coordinate
- */
- public static Point2D getBitmapCoordinate(GeoPosition c, int zoomLevel, TileFactoryInfo info)
- {
- return getBitmapCoordinate(c.getLatitude(), c.getLongitude(), zoomLevel, info);
- }
-
- /**
- * Given a position (latitude/longitude pair) and a zoom level, return the appropriate point in pixels. The
- * zoom level is necessary because pixel coordinates are in terms of the zoom level
- * @param latitude the latitude
- * @param longitude the longitude
- * @param zoomLevel the zoom level to extract the pixel coordinate for
- * @param info the tile factory info
- * @return the coordinate
- */
- public static Point2D getBitmapCoordinate(double latitude, double longitude, int zoomLevel, TileFactoryInfo info)
- {
- double x = info.getMapCenterInPixelsAtZoom(zoomLevel).getX() + longitude
- * info.getLongitudeDegreeWidthInPixels(zoomLevel);
- double e = FastMath.sin(latitude * (FastMath.PI / 180.0));
- if (e > 0.9999)
- {
- e = 0.9999;
- }
- if (e < -0.9999)
- {
- e = -0.9999;
- }
- double y = info.getMapCenterInPixelsAtZoom(zoomLevel).getY() + 0.5 * FastMath.log((1 + e) / (1 - e)) * -1
- * (info.getLongitudeRadianWidthInPixels(zoomLevel));
- return new Point2D.Double(x, y);
- }
-
- /**
- * Convert an on screen pixel coordinate and a zoom level to a geo position
- * @param pixelCoordinate the coordinate in pixels
- * @param zoom the zoom level
- * @param info the tile factory info
- * @return a geo position
- */
- public static GeoPosition getPosition(Point2D pixelCoordinate, int zoom, TileFactoryInfo info)
- {
- // p(" --bitmap to latlon : " + coord + " " + zoom);
- double wx = pixelCoordinate.getX();
- double wy = pixelCoordinate.getY();
- // this reverses getBitmapCoordinates
- double flon = (wx - info.getMapCenterInPixelsAtZoom(zoom).getX()) / info.getLongitudeDegreeWidthInPixels(zoom);
- double e1 = (wy - info.getMapCenterInPixelsAtZoom(zoom).getY())
- / (-1 * info.getLongitudeRadianWidthInPixels(zoom));
- double e2 = (2 * FastMath.atan(FastMath.exp(e1)) - FastMath.PI / 2) / (FastMath.PI / 180.0);
- double flat = e2;
- GeoPosition wc = new GeoPosition(flat, flon);
- return wc;
- }
-
- /**
- * Gets the map bounds.
- * @param mapViewer The map viewer.
- * @return Returns the bounds.
- */
- public static GeoBounds getMapBounds(JXMapViewer mapViewer)
- {
- return new GeoBounds(getMapGeoBounds(mapViewer));
- }
-
- /**
- * Gets the bounds as a set of two GeoPosition objects.
- * @param mapViewer The map viewer.
- * @return Returns the set of two GeoPosition objects that represent the north west and south east
- * corners of the map.
- */
- private static Set getMapGeoBounds(JXMapViewer mapViewer)
- {
- Set set = new HashSet();
- TileFactory tileFactory = mapViewer.getTileFactory();
- int zoom = mapViewer.getZoom();
- Rectangle2D bounds = mapViewer.getViewportBounds();
- Point2D pt = new Point2D.Double(bounds.getX(), bounds.getY());
- set.add(tileFactory.pixelToGeo(pt, zoom));
- pt = new Point2D.Double(bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight());
- set.add(tileFactory.pixelToGeo(pt, zoom));
- return set;
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/util/MercatorUtils.java b/src/main/java/org/jdesktop/swingx/mapviewer/util/MercatorUtils.java
deleted file mode 100644
index f4caa9a2..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/util/MercatorUtils.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * MercatorUtils.java
- *
- * Created on October 7, 2006, 6:02 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer.util;
-
-import org.apache.commons.math3.util.FastMath;
-
-/**
- * A utility class of methods that help when
- * dealing with standard Mercator projections.
- * @author joshua.marinacci@sun.com
- */
-public final class MercatorUtils
-{
-
- /**
- * Creates a new instance of MercatorUtils
- */
- private MercatorUtils()
- {
- }
-
- /**
- * @param longitudeDegrees the longitude in degrees
- * @param radius the world radius in pixels
- * @return the x value
- */
- public static int longToX(double longitudeDegrees, double radius)
- {
- double longitude = FastMath.toRadians(longitudeDegrees);
- return (int) (radius * longitude);
- }
-
- /**
- * @param latitudeDegrees the latitude in degrees
- * @param radius the world radius in pixels
- * @return the y value
- */
- public static int latToY(double latitudeDegrees, double radius)
- {
- double latitude = FastMath.toRadians(latitudeDegrees);
- double y = radius / 2.0 * FastMath.log((1.0 + FastMath.sin(latitude)) / (1.0 - FastMath.sin(latitude)));
- return (int) y;
- }
-
- /**
- * @param x the x value
- * @param radius the world radius in pixels
- * @return the longitude in degrees
- */
- public static double xToLong(int x, double radius)
- {
- double longRadians = x / radius;
- double longDegrees = FastMath.toDegrees(longRadians);
- /*
- * The user could have panned around the world a lot of times. Lat long goes from -180 to 180. So every time a
- * user gets to 181 we want to subtract 360 degrees. Every time a user gets to -181 we want to add 360 degrees.
- */
- int rotations = (int) FastMath.floor((longDegrees + 180) / 360);
- double longitude = longDegrees - (rotations * 360);
- return longitude;
- }
-
- /**
- * @param y the y value
- * @param radius the world radius in pixels
- * @return the latitude in degrees
- */
- public static double yToLat(int y, double radius)
- {
- double latitude = (FastMath.PI / 2) - (2 * FastMath.atan(FastMath.exp(-1.0 * y / radius)));
- return FastMath.toDegrees(latitude);
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/wms/WMSService.java b/src/main/java/org/jdesktop/swingx/mapviewer/wms/WMSService.java
deleted file mode 100644
index 3ab61cc7..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/wms/WMSService.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * WMSService.java
- *
- * Created on October 7, 2006, 6:06 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer.wms;
-
-import org.apache.commons.math3.util.FastMath;
-import org.jdesktop.swingx.mapviewer.util.MercatorUtils;
-
-/**
- * A class that represents a WMS mapping service.
- * See http://en.wikipedia.org/wiki/Web_Map_Service for more information.
- * @author joshy
- */
-public class WMSService
-{
- private String baseUrl;
- private String layer;
-
- /**
- * Creates a new instance of WMSService
- * TODO: not working -> remove
- */
- public WMSService()
- {
- // by default use a known nasa server
- setLayer("BMNG");
- setBaseUrl("http://wms.jpl.nasa.gov/wms.cgi?");
- }
-
- /**
- * @param baseUrl the base URL
- * @param layer the layer
- */
- public WMSService(String baseUrl, String layer)
- {
- this.baseUrl = baseUrl;
- this.layer = layer;
- }
-
- /**
- * Convertes to a WMS URL
- * @param x the x coordinate
- * @param y the y coordinate
- * @param zoom the zomm factor
- * @param tileSize the tile size
- * @return a URL request string
- */
- public String toWMSURL(int x, int y, int zoom, int tileSize)
- {
- String format = "image/jpeg";
- String styles = "";
- String srs = "EPSG:4326";
- int ts = tileSize;
- int circumference = widthOfWorldInPixels(zoom, tileSize);
- double radius = circumference / (2 * FastMath.PI);
- double ulx = MercatorUtils.xToLong(x * ts, radius);
- double uly = MercatorUtils.yToLat(y * ts, radius);
- double lrx = MercatorUtils.xToLong((x + 1) * ts, radius);
- double lry = MercatorUtils.yToLat((y + 1) * ts, radius);
- String bbox = ulx + "," + uly + "," + lrx + "," + lry;
- String url = getBaseUrl() + "version=1.1.1&request=" + "GetMap&Layers=" + layer + "&format=" + format
- + "&BBOX=" + bbox + "&width=" + ts + "&height=" + ts + "&SRS=" + srs + "&Styles=" + styles +
- // "&transparent=TRUE"+
- "";
- return url;
- }
-
- private int widthOfWorldInPixels(int zoom, int TILE_SIZE)
- {
- // int TILE_SIZE = 256;
- int tiles = (int) FastMath.pow(2, zoom);
- int circumference = TILE_SIZE * tiles;
- return circumference;
- }
-
- /**
- * @return the layer
- */
- public String getLayer()
- {
- return layer;
- }
-
- /**
- * @param layer the layer
- */
- public void setLayer(String layer)
- {
- this.layer = layer;
- }
-
- /**
- * @return the base URL
- */
- public String getBaseUrl()
- {
- return baseUrl;
- }
-
- /**
- * @param baseUrl the base URL
- */
- public void setBaseUrl(String baseUrl)
- {
- this.baseUrl = baseUrl;
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/mapviewer/wms/WMSTileFactory.java b/src/main/java/org/jdesktop/swingx/mapviewer/wms/WMSTileFactory.java
deleted file mode 100644
index 6641bf4a..00000000
--- a/src/main/java/org/jdesktop/swingx/mapviewer/wms/WMSTileFactory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * WMSTileFactory.java
- *
- * Created on October 7, 2006, 6:07 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jdesktop.swingx.mapviewer.wms;
-
-import org.apache.commons.math3.util.FastMath;
-import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
-
-/**
- * A tile factory that uses a WMS service.
- * @author joshy
- */
-public class WMSTileFactory extends DefaultTileFactory
-{
- /**
- * Creates a new instance of WMSTileFactory
- * @param wms the WMSService
- */
- public WMSTileFactory(final WMSService wms)
- {
- // tile size and x/y orientation is r2l & t2b
- super(new TileFactoryInfo(0, 15, 17, 500, true, true, "", "x", "y", "zoom")
- {
- @Override
- public String getTileUrl(int x, int y, int zoom)
- {
- int zz = 17 - zoom;
- int z = 4;
- z = (int) FastMath.pow(2, (double) zz - 1);
- return wms.toWMSURL(x - z, z - 1 - y, zz, getTileSize(zoom));
- }
-
- });
- }
-
-}
diff --git a/src/main/java/org/jdesktop/swingx/painter/AbstractPainter.java b/src/main/java/org/jdesktop/swingx/painter/AbstractPainter.java
deleted file mode 100644
index bdc1a0ca..00000000
--- a/src/main/java/org/jdesktop/swingx/painter/AbstractPainter.java
+++ /dev/null
@@ -1,438 +0,0 @@
-/*
- * $Id: AbstractPainter.java 4082 2011-11-15 18:39:43Z kschaefe $
- *
- * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
- * Santa Clara, California 95054, U.S.A. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.jdesktop.swingx.painter;
-
-import org.jdesktop.beans.AbstractBean;
-import org.jdesktop.swingx.util.GraphicsUtilities;
-
-import java.awt.*;
-import java.awt.image.BufferedImage;
-import java.awt.image.BufferedImageOp;
-import java.lang.ref.SoftReference;
-
-/**
- *
A convenient base class from which concrete {@link Painter} implementations may
- * extend. It extends {@link org.jdesktop.beans.AbstractBean} as a convenience for
- * adding property change notification support. In addition, AbstractPainter
- * provides subclasses with the ability to cacheable painting operations, configure the
- * drawing surface with common settings (such as antialiasing and interpolation), and
- * toggle whether a subclass paints or not via the visibility property.
- *
- *
Subclasses of AbstractPainter generally need only override the
- * {@link #doPaint(Graphics2D, Object, int, int)} method. If a subclass requires more control
- * over whether caching is enabled, or for configuring the graphics state, then it
- * may override the appropriate protected methods to interpose its own behavior.
- *
- *
For example, here is the doPaint method of a simple Painter that
- * paints an opaque rectangle:
- *
- * public void doPaint(Graphics2D g, T obj, int width, int height) {
- * g.setPaint(Color.BLUE);
- * g.fillRect(0, 0, width, height);
- * }
- *
- *
- * @author rbair
- * @param an optional configuration parameter
- */
-@SuppressWarnings("nls")
-public abstract class AbstractPainter extends AbstractBean implements Painter {
- /**
- * An enum representing the possible interpolation values of Bicubic, Bilinear, and
- * Nearest Neighbor. These map to the underlying RenderingHints,
- * but are easier to use and serialization safe.
- */
- public enum Interpolation {
- /**
- * use bicubic interpolation
- */
- Bicubic(RenderingHints.VALUE_INTERPOLATION_BICUBIC),
- /**
- * use bilinear interpolation
- */
- Bilinear(RenderingHints.VALUE_INTERPOLATION_BILINEAR),
- /**
- * use nearest neighbor interpolation
- */
- NearestNeighbor(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
-
- private Object value;
-
- Interpolation(Object value) {
- this.value = value;
- }
-
- private void configureGraphics(Graphics2D g) {
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, value);
- }
- }
-
- //--------------------------------------------------- Instance Variables
- /**
- * The cached image, if shouldUseCache() returns true
- */
- private transient SoftReference cachedImage;
- private boolean cacheCleared = true;
- private boolean cacheable = false;
- private boolean dirty = false;
- private BufferedImageOp[] filters = new BufferedImageOp[0];
- private boolean antialiasing = true;
- private Interpolation interpolation = Interpolation.NearestNeighbor;
- private boolean visible = true;
- private boolean inPaintContext;
-
- /**
- * Creates a new instance of AbstractPainter.
- */
- public AbstractPainter() { }
-
- /**
- * Creates a new instance of AbstractPainter.
- * @param cacheable indicates if this painter should be cacheable
- */
- public AbstractPainter(boolean cacheable) {
- setCacheable(cacheable);
- }
-
- /**
- * A defensive copy of the Effects to apply to the results
- * of the AbstractPainter's painting operation. The array may
- * be empty but it will never be null.
- * @return the array of filters applied to this painter
- */
- public final BufferedImageOp[] getFilters() {
- BufferedImageOp[] results = new BufferedImageOp[filters.length];
- System.arraycopy(filters, 0, results, 0, results.length);
- return results;
- }
-
- /**
- *
A convenience method for specifying the filters to use based on
- * BufferedImageOps. These will each be individually wrapped by an ImageFilter
- * and then setFilters(Effect... filters) will be called with the resulting
- * array
- *
- *
- * @param effects the BufferedImageOps to wrap as filters
- */
- public void setFilters(BufferedImageOp ... effects) {
- if (effects == null) effects = new BufferedImageOp[0];
- BufferedImageOp[] old = getFilters();
- this.filters = new BufferedImageOp[effects.length];
- System.arraycopy(effects, 0, this.filters, 0, this.filters.length);
- setDirty(true);
- firePropertyChange("filters", old, getFilters());
- }
-
- /**
- * Returns if antialiasing is turned on or not. The default value is true.
- * This is a bound property.
- * @return the current antialiasing setting
- */
- public boolean isAntialiasing() {
- return antialiasing;
- }
- /**
- * Sets the antialiasing setting. This is a bound property.
- * @param value the new antialiasing setting
- */
- public void setAntialiasing(boolean value) {
- boolean old = isAntialiasing();
- antialiasing = value;
- if (old != value) setDirty(true);
- firePropertyChange("antialiasing", old, isAntialiasing());
- }
-
- /**
- * Gets the current interpolation setting. This property determines if interpolation will
- * be used when drawing scaled images. @see java.awt.RenderingHints.KEY_INTERPOLATION.
- * @return the current interpolation setting
- */
- public Interpolation getInterpolation() {
- return interpolation;
- }
-
- /**
- * Sets a new value for the interpolation setting. This setting determines if interpolation
- * should be used when drawing scaled images. @see java.awt.RenderingHints.KEY_INTERPOLATION.
- * @param value the new interpolation setting
- */
- public void setInterpolation(Interpolation value) {
- Object old = getInterpolation();
- this.interpolation = value == null ? Interpolation.NearestNeighbor : value;
- if (old != value) setDirty(true);
- firePropertyChange("interpolation", old, getInterpolation());
- }
-
- /**
- * Gets the visible property. This controls if the painter should
- * paint itself. It is true by default. Setting visible to false
- * is good when you want to temporarily turn off a painter. An example
- * of this is a painter that you only use when a button is highlighted.
- *
- * @return current value of visible property
- */
- public boolean isVisible() {
- return this.visible;
- }
-
- /**
- *
Sets the visible property. This controls if the painter should
- * paint itself. It is true by default. Setting visible to false
- * is good when you want to temporarily turn off a painter. An example
- * of this is a painter that you only use when a button is highlighted.
- *
- * @param visible New value of visible property.
- */
- public void setVisible(boolean visible) {
- boolean old = isVisible();
- this.visible = visible;
- if (old != visible) setDirty(true); //not the most efficient, but I must do this otherwise a CompoundPainter
- //or other aggregate painter won't know that it is now invalid
- //there might be a tricky solution but that is a performance optimization
- firePropertyChange("visible", old, isVisible());
- }
-
- /**
- *
Gets whether this AbstractPainter can be cached as an image.
- * If caching is enabled, then it is the responsibility of the developer to
- * invalidate the painter (via {@link #clearCache}) if external state has
- * changed in such a way that the painter is invalidated and needs to be
- * repainted.
- *
- * @return whether this is cacheable
- */
- public boolean isCacheable() {
- return cacheable;
- }
-
- /**
- *
Sets whether this AbstractPainter can be cached as an image.
- * If true, this is treated as a hint. That is, a cacheable may or may not be used.
- * The {@link #shouldUseCache} method actually determines whether the cacheable is used.
- * However, if false, then this is treated as an absolute value. That is, no
- * cacheable will be used.
- *
- *
If set to false, then #clearCache is called to free system resources.
- *
- * @param cacheable the cache flag
- */
- public void setCacheable(boolean cacheable) {
- boolean old = isCacheable();
- this.cacheable = cacheable;
- firePropertyChange("cacheable", old, isCacheable());
- if (!isCacheable()) {
- clearCache();
- }
- }
-
- /**
- *
Call this method to clear the cacheable. This may be called whether there is
- * a cacheable being used or not. If cleared, on the next call to paint,
- * the painting routines will be called.
- *
- *
SubclassesIf overridden in subclasses, you
- * must call super.clearCache, or physical
- * resources (such as an Image) may leak.
- */
- public void clearCache() {
- BufferedImage cache = cachedImage == null ? null : cachedImage.get();
- if (cache != null) {
- cache.flush();
- }
- cacheCleared = true;
- if (!isCacheable()) {
- cachedImage = null;
- }
- }
-
-// /**
-// * Only made package private for testing. Don't call this method outside
-// * of this class! This is NOT a bound property
-// */
-// private boolean isCacheCleared() {
-// return cacheCleared;
-// }
-
- /**
- *
Called to allow Painter subclasses a chance to see if any state
- * in the given object has changed from the last paint operation. If it has, then
- * the Painter has a chance to mark itself as dirty, thus causing a
- * repaint, even if cached.
- *
- * @param object the object to validate
- */
- protected void validate(T object) { /* do nothing */ }
-
- /**
- * Ye olde dirty bit. If true, then the painter is considered dirty and in need of
- * being repainted. This is a bound property.
- *
- * @return true if the painter state has changed and the painter needs to be
- * repainted.
- */
- protected boolean isDirty() {
- return dirty;
- }
-
- /**
- * Sets the dirty bit. If true, then the painter is considered dirty, and the cache
- * will be cleared. This property is bound.
- *
- * @param d whether this Painter is dirty.
- */
- protected void setDirty(boolean d) {
- boolean old = isDirty();
- this.dirty = d;
- firePropertyChange("dirty", old, isDirty());
- if (isDirty()) {
- clearCache();
- }
- }
-
- boolean isInPaintContext() {
- return inPaintContext;
- }
-
- void setInPaintContext(boolean inPaintContext) {
- this.inPaintContext = inPaintContext;
- }
-
- /**
- *
Returns true if the painter should use caching. This method allows subclasses to
- * specify the heuristics regarding whether to cache or not. If a Painter
- * has intelligent rules regarding painting times, and can more accurately indicate
- * whether it should be cached, it could implement that logic in this method.
- *
- * @return whether or not a cache should be used
- */
- protected boolean shouldUseCache() {
- return isCacheable() || filters.length > 0; //NOTE, I can only do this because getFilters() is final
- }
-
- /**
- *
This method is called by the paint method prior to
- * any drawing operations to configure the drawing surface. The default
- * implementation sets the rendering hints that have been specified for
- * this AbstractPainter.
- *
- *
This method can be overridden by subclasses to modify the drawing
- * surface before any painting happens.
- *
- * @param g the graphics surface to configure. This will never be null.
- * @see #paint(Graphics2D, Object, int, int)
- */
- protected void configureGraphics(Graphics2D g) {
- //configure antialiasing
- if(isAntialiasing()) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_OFF);
- }
-
- getInterpolation().configureGraphics(g);
- }
-
- /**
- * Subclasses must implement this method and perform custom painting operations
- * here.
- * @param width the width
- * @param height the height
- * @param g The Graphics2D object in which to paint
- * @param object an optional configuration parameter
- */
- protected abstract void doPaint(Graphics2D g, T object, int width, int height);
-
- @Override
- public final void paint(Graphics2D g, T obj, int width, int height) {
- if (g == null) {
- throw new NullPointerException("The Graphics2D must be supplied");
- }
-
- if(!isVisible() || width < 1 || height < 1) {
- return;
- }
-
- configureGraphics(g);
-
- //paint to a temporary image if I'm caching, or if there are filters to apply
- if (shouldUseCache() || filters.length > 0) {
- validate(obj);
- BufferedImage cache = cachedImage == null ? null : cachedImage.get();
- boolean invalidCache = null == cache ||
- cache.getWidth() != width ||
- cache.getHeight() != height;
-
- if (cacheCleared || invalidCache || isDirty()) {
- //rebuild the cacheable. I do this both if a cacheable is needed, and if any
- //filters exist. I only *save* the resulting image if caching is turned on
- if (invalidCache) {
- cache = GraphicsUtilities.createCompatibleTranslucentImage(width, height);
- }
- if (cache != null) {
- Graphics2D gfx = cache.createGraphics();
-
- try {
- gfx.setClip(0, 0, width, height);
-
- if (!invalidCache) {
- // If we are doing a repaint, but we didn't have to
- // recreate the image, we need to clear it back
- // to a fully transparent background.
- Composite composite = gfx.getComposite();
- gfx.setComposite(AlphaComposite.Clear);
- gfx.fillRect(0, 0, width, height);
- gfx.setComposite(composite);
- }
-
- configureGraphics(gfx);
- doPaint(gfx, obj, width, height);
- } finally {
- gfx.dispose();
- }
-
- if (!isInPaintContext()) {
- for (BufferedImageOp f : getFilters()) {
- cache = f.filter(cache, null);
- }
- }
-
- //only save the temporary image as the cacheable if I'm caching
- if (shouldUseCache()) {
- cachedImage = new SoftReference(cache);
- cacheCleared = false;
- }
- }
- }
-
- g.drawImage(cache, 0, 0, null);
- } else {
- //can't use the cacheable, so just paint
- doPaint(g, obj, width, height);
- }
-
- //painting has occured, so restore the dirty bit to false
- setDirty(false);
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/painter/CompoundPainter.java b/src/main/java/org/jdesktop/swingx/painter/CompoundPainter.java
deleted file mode 100644
index 90a8c3f8..00000000
--- a/src/main/java/org/jdesktop/swingx/painter/CompoundPainter.java
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- * $Id: CompoundPainter.java 4147 2012-02-01 17:13:24Z kschaefe $
- *
- * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
- * Santa Clara, California 95054, U.S.A. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.jdesktop.swingx.painter;
-
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-//import org.jdesktop.beans.JavaBean;
-
-/**
- *
A {@link Painter} implementation composed of an array of Painters.
- * CompoundPainter provides a means for combining several individual
- * Painters, or groups of them, into one logical unit. Each of the
- * Painters are executed in order. BufferedImageOp filter effects can
- * be applied to them together as a whole. The entire set of painting operations
- * may be cached together.
- *
- *
- *
- *
For example, if I want to create a CompoundPainter that started with a blue
- * background, had pinstripes on it running at a 45 degree angle, and those
- * pinstripes appeared to "fade in" from left to right, I would write the following:
- *
- * Color blue = new Color(0x417DDD);
- * Color translucent = new Color(blue.getRed(), blue.getGreen(), blue.getBlue(), 0);
- * panel.setBackground(blue);
- * panel.setForeground(Color.LIGHT_GRAY);
- * GradientPaint blueToTranslucent = new GradientPaint(
- * new Point2D.Double(.4, 0),
- * blue,
- * new Point2D.Double(1, 0),
- * translucent);
- * MattePainter veil = new MattePainter(blueToTranslucent);
- * veil.setPaintStretched(true);
- * Painter pinstripes = new PinstripePainter(45);
- * Painter backgroundPainter = new RectanglePainter(this.getBackground(), null);
- * Painter p = new CompoundPainter(backgroundPainter, pinstripes, veil);
- * panel.setBackgroundPainter(p);
- *
- *
- * @author rbair
- * @param an optional configuration parameter
- */
-//@JavaBean
-public class CompoundPainter extends AbstractPainter
-{
- private static class Handler implements PropertyChangeListener
- {
- private final WeakReference> ref;
-
- public Handler(CompoundPainter> painter)
- {
- ref = new WeakReference>(painter);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- CompoundPainter> painter = ref.get();
-
- if (painter == null)
- {
- AbstractPainter> src = (AbstractPainter>) evt.getSource();
- src.removePropertyChangeListener(this);
- }
- else
- {
- String property = evt.getPropertyName();
-
- if ("dirty".equals(property) && evt.getNewValue() == Boolean.FALSE)
- {
- return;
- }
-
- painter.setDirty(true);
- }
- }
- }
-
- private Handler handler;
-
- private List> painters = new CopyOnWriteArrayList>();
- private AffineTransform transform;
- private boolean clipPreserved = false;
-
- private boolean checkForDirtyChildPainters = true;
-
- /** Creates a new instance of CompoundPainter */
- public CompoundPainter()
- {
- this((Painter[]) null);
- }
-
- /**
- * Convenience constructor for creating a CompoundPainter for an array
- * of painters. A defensive copy of the given array is made, so that future
- * modification to the array does not result in changes to the CompoundPainter.
- *
- * @param painters array of painters, which will be painted in order
- */
- public CompoundPainter(Painter... painters)
- {
- handler = new Handler(this);
-
- setPainters(painters);
- }
-
- /**
- * Convenience constructor for creating a CompoundPainter for a list
- * of painters. A defensive copy of the given array is made, so that future
- * modification to the list does not result in changes to the CompoundPainter.
- *
- * @param painters array of painters, which will be painted in order
- */
- public CompoundPainter(List extends Painter> painters)
- {
- handler = new Handler(this);
-
- setPainters(painters);
- }
- /**
- * Sets the array of Painters to use. These painters will be executed in
- * order. A null value will be treated as an empty array. To prevent unexpected
- * behavior all values in provided array are copied to internally held array.
- * Any changes to the original array will not be reflected.
- *
- * @param painters array of painters, which will be painted in order
- */
- public void setPainters(List extends Painter> painters)
- {
- Collection> old = new ArrayList>(getPainters());
-
- for (Painter p : old)
- {
- if (p instanceof AbstractPainter)
- {
- ((AbstractPainter>) p).removePropertyChangeListener(handler);
- }
- }
-
- this.painters.clear();
- this.painters.addAll(painters);
-
- for (Painter p : this.painters)
- {
- if (p instanceof AbstractPainter)
- {
- ((AbstractPainter>) p).addPropertyChangeListener(handler);
- }
- }
-
- setDirty(true);
- firePropertyChange("painters", old, getPainters());
- }
-
- /**
- * Sets the array of Painters to use. These painters will be executed in
- * order. A null value will be treated as an empty array. To prevent unexpected
- * behavior all values in provided array are copied to internally held array.
- * Any changes to the original array will not be reflected.
- *
- * @param painters array of painters, which will be painted in order
- */
- public void setPainters(Painter... painters)
- {
- List extends Painter> l;
-
- if (painters == null)
- l = Collections.emptyList();
- else
- l = Arrays.asList(painters);
-
- setPainters(l);
- }
-
- /**
- * Adds a painter to the queue of painters
- * @param painter the painter that is added
- */
- public void addPainter(Painter painter)
- {
- Collection> old = new ArrayList>(getPainters());
-
- this.painters.add(painter);
-
- if (painter instanceof AbstractPainter)
- {
- ((AbstractPainter>) painter).addPropertyChangeListener(handler);
- }
-
- setDirty(true);
- firePropertyChange("painters", old, getPainters());
- }
-
- /**
- * Removes a painter from the queue of painters
- * @param painter the painter that is added
- */
- public void removePainter(Painter painter)
- {
- Collection> old = new ArrayList>(getPainters());
-
- this.painters.remove(painter);
-
- if (painter instanceof AbstractPainter)
- {
- ((AbstractPainter>) painter).removePropertyChangeListener(handler);
- }
-
- setDirty(true);
- firePropertyChange("painters", old, getPainters());
- }
-
-
- /**
- * Gets the array of painters used by this CompoundPainter
- * @return a defensive copy of the painters used by this CompoundPainter.
- * This will never be null.
- */
- public final Collection> getPainters()
- {
- return Collections.unmodifiableCollection(painters);
- }
-
- /**
- * Indicates if the clip produced by any painter is left set once it finishes painting.
- * Normally the clip will be reset between each painter. Setting clipPreserved to
- * true can be used to let one painter mask other painters that come after it.
- * @return if the clip should be preserved
- * @see #setClipPreserved(boolean)
- */
- public boolean isClipPreserved()
- {
- return clipPreserved;
- }
-
- /**
- * Sets if the clip should be preserved.
- * Normally the clip will be reset between each painter. Setting clipPreserved to
- * true can be used to let one painter mask other painters that come after it.
- *
- * @param shouldRestoreState new value of the clipPreserved property
- * @see #isClipPreserved()
- */
- public void setClipPreserved(boolean shouldRestoreState)
- {
- boolean oldShouldRestoreState = isClipPreserved();
- this.clipPreserved = shouldRestoreState;
- setDirty(true);
- firePropertyChange("clipPreserved", oldShouldRestoreState, shouldRestoreState);
- }
-
- /**
- * Gets the current transform applied to all painters in this CompoundPainter. May be null.
- * @return the current AffineTransform
- */
- public AffineTransform getTransform()
- {
- return transform;
- }
-
- /**
- * Set a transform to be applied to all painters contained in this CompoundPainter
- * @param transform a new AffineTransform
- */
- public void setTransform(AffineTransform transform)
- {
- AffineTransform old = getTransform();
- this.transform = transform;
- setDirty(true);
- firePropertyChange("transform", old, transform);
- }
-
- /**
- *
Iterates over all child Painters and gives them a chance
- * to validate themselves. If any of the child painters are dirty, then
- * this CompoundPainter marks itself as dirty.
- */
- @Override
- protected void validate(T object)
- {
- boolean dirty = false;
- for (Painter p : painters)
- {
- if (p instanceof AbstractPainter)
- {
- AbstractPainter ap = (AbstractPainter) p;
- ap.validate(object);
- if (ap.isDirty())
- {
- dirty = true;
- break;
- }
- }
- }
- clearLocalCacheOnly = true;
- setDirty(dirty); //super will call clear cache
- clearLocalCacheOnly = false;
- }
-
- //indicates whether the local cache should be cleared only, as opposed to the
- //cache's of all of the children. This is needed to optimize the caching strategy
- //when, during validate, the CompoundPainter is marked as dirty
- private boolean clearLocalCacheOnly = false;
-
- /**
- * Used by {@link #isDirty()} to check if the child Painters
- * should be checked for their dirty flag as part of
- * processing.
- * Default value is: true
- * This should be set to false if the cacheable state
- * of the child Painters are different from each other. This
- * will allow the cacheable == truePainters to
- * keep their cached image during regular repaints. In this case,
- * client code should call {@link #clearCache()} manually when the cacheable
- * Painters should be updated.
- * @return the dirty check flag
- *
- *
- * @see #isDirty()
- */
- public boolean isCheckingDirtyChildPainters()
- {
- return checkForDirtyChildPainters;
- }
-
- /**
- * Set the flag used by {@link #isDirty()} to check if the
- * child Painters should be checked for their
- * dirty flag as part of processing.
- * @param b the dirty check flag
- *
- * @see #isCheckingDirtyChildPainters()
- * @see #isDirty()
- */
- public void setCheckingDirtyChildPainters(boolean b)
- {
- boolean old = isCheckingDirtyChildPainters();
- this.checkForDirtyChildPainters = b;
- firePropertyChange("checkingDirtyChildPainters", old, isCheckingDirtyChildPainters());
- }
-
- /**
- *
This CompoundPainter is dirty if it, or (optionally)
- * any of its children, are dirty. If the super implementation returns
- * true, we return true. Otherwise, if
- * {@link #isCheckingDirtyChildPainters()} is true, we iterate
- * over all child Painters and query them to see
- * if they are dirty. If so, then true is returned.
- * Otherwise, we return false.
- *
- * @see #isCheckingDirtyChildPainters()
- */
- @Override
- protected boolean isDirty()
- {
- boolean dirty = super.isDirty();
- if (dirty)
- {
- return true;
- }
- else if (isCheckingDirtyChildPainters())
- {
- for (Painter p : painters)
- {
- if (p instanceof AbstractPainter)
- {
- AbstractPainter> ap = (AbstractPainter>) p;
- if (ap.isDirty())
- {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- @Override
- protected void setDirty(boolean d)
- {
- boolean old = super.isDirty();
- boolean ours = isDirty();
-
- super.setDirty(d);
-
- //must perform this check to ensure we do not double notify
- if (d != old && d == ours)
- {
- firePropertyChange("dirty", old, isDirty());
- }
- }
-
- /**
- *
Clears the cache of this Painter, and all child
- * Painters. This is done to ensure that resources
- * are collected, even if clearCache is called by some framework
- * or other code that doesn't realize this is a CompoundPainter.
- *
- *
Call #clearLocalCache if you only want to clear the cache of this
- * CompoundPainter
- */
- @Override
- public void clearCache()
- {
- if (!clearLocalCacheOnly)
- {
- for (Painter p : painters)
- {
- if (p instanceof AbstractPainter)
- {
- AbstractPainter> ap = (AbstractPainter>) p;
- ap.clearCache();
- }
- }
- }
- super.clearCache();
- }
-
- /**
- *
Clears the cache of this painter only, and not of any of the children.
- */
- public void clearLocalCache()
- {
- super.clearCache();
- }
-
- @Override
- protected void doPaint(Graphics2D g, T component, int width, int height)
- {
- for (Painter p : getPainters())
- {
- Graphics2D temp = (Graphics2D) g.create();
-
- try
- {
- p.paint(temp, component, width, height);
- if (isClipPreserved())
- {
- g.setClip(temp.getClip());
- }
- }
- finally
- {
- temp.dispose();
- }
- }
- }
-
- @Override
- protected void configureGraphics(Graphics2D g)
- {
- //applies the transform
- AffineTransform tx = getTransform();
- if (tx != null)
- {
- g.setTransform(tx);
- }
- }
-
- @Override
- protected boolean shouldUseCache()
- {
- return super.shouldUseCache(); // || (painters != null && painters.length > 1);
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/painter/Painter.java b/src/main/java/org/jdesktop/swingx/painter/Painter.java
deleted file mode 100644
index ac51207a..00000000
--- a/src/main/java/org/jdesktop/swingx/painter/Painter.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * *****************************************************************************
- * Copyright (C) 2014-2022 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- * ****************************************************************************
- */
-
-package org.jdesktop.swingx.painter;
-
-import java.awt.Graphics2D;
-
-/**
- *
A painting delegate. The Painter interface defines exactly one method,
- * paint. It is used in situations where the developer can change
- * the painting routine of a component without having to resort to subclassing
- * the component.
- *
- *
Painters are simply encapsulations of Java2D code and make
- * it fairly trivial to reuse existing Painters or to combine
- * them together. Implementations of this interface are also trivial to write,
- * such that if you can't find a Painter that does what you need,
- * you can write one with minimal effort. Writing a Painter requires
- * knowledge of Java2D.
- *
- *
A Painter may be created with a type parameter. This type will be
- * expected in the paint method. For example, you may wish to write a
- * Painter that only works with subclasses of {@link java.awt.Component}.
- * In that case, when the Painter is declared, you may declare that
- * it requires a Component, allowing the paint method to be type safe. Ex:
- *
- * Painter<Component> p = new Painter<Component>() {
- * public void paint(Graphics2D g, Component c, int width, int height) {
- * g.setColor(c.getBackground());
- * //and so forth
- * }
- * }
- *
Renders to the given {@link java.awt.Graphics2D} object. Implementations
- * of this method may modify state on the Graphics2D, and are not
- * required to restore that state upon completion. In most cases, it is recommended
- * that the caller pass in a scratch graphics object. The Graphics2D
- * must never be null.
- *
- *
State on the graphics object may be honored by the paint method,
- * but may not be. For instance, setting the antialiasing rendering hint on the
- * graphics may or may not be respected by the Painter implementation.
- *
- *
The supplied object parameter acts as an optional configuration argument.
- * For example, it could be of type Component. A Painter
- * that expected it could then read state from that Component and
- * use the state for painting. For example, an implementation may read the
- * backgroundColor and use that.
- *
- *
Generally, to enhance reusability, most standard Painters ignore
- * this parameter. They can thus be reused in any context. The object
- * may be null. Implementations must not throw a NullPointerException if the object
- * parameter is null.
- *
- *
Finally, the width and height arguments specify the
- * width and height that the Painter should paint into. More
- * specifically, the specified width and height instruct the painter that it should
- * paint fully within this width and height. Any specified clip on the
- * g param will further constrain the region.
- *
- *
For example, suppose I have a Painter implementation that draws
- * a gradient. The gradient goes from white to black. It "stretches" to fill the
- * painted region. Thus, if I use this Painter to paint a 500 x 500
- * region, the far left would be black, the far right would be white, and a smooth
- * gradient would be painted between. I could then, without modification, reuse the
- * Painter to paint a region that is 20x20 in size. This region would
- * also be black on the left, white on the right, and a smooth gradient painted
- * between.
- *
- * @param g The Graphics2D to render to. This must not be null.
- * @param object an optional configuration parameter. This may be null.
- * @param width width of the area to paint.
- * @param height height of the area to paint.
- */
- public void paint(Graphics2D g, T object, int width, int height);
-}
diff --git a/src/main/java/org/jdesktop/swingx/util/GraphicsUtilities.java b/src/main/java/org/jdesktop/swingx/util/GraphicsUtilities.java
deleted file mode 100644
index f5f50289..00000000
--- a/src/main/java/org/jdesktop/swingx/util/GraphicsUtilities.java
+++ /dev/null
@@ -1,855 +0,0 @@
-/*
- * *****************************************************************************
- * Copyright (C) 2014-2022 Dennis Sheirer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see
- * ****************************************************************************
- */
-
-package org.jdesktop.swingx.util;
-
-import javax.imageio.ImageIO;
-import javax.swing.JComponent;
-import java.awt.AlphaComposite;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.Insets;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.Transparency;
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.Raster;
-import java.awt.image.WritableRaster;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
-/**
- *
GraphicsUtilities contains a set of tools to perform
- * common graphics operations easily. These operations are divided into
- * several themes, listed below.
- *
- *
Compatible Images
- *
- *
Compatible images can, and should, be used to increase drawing
- * performance. This class provides a number of methods to load compatible
- * images directly from files or to convert existing images to compatibles
- * images.
- *
- *
Creating Thumbnails
- *
- *
This class provides a number of methods to easily scale down images.
- * Some of these methods offer a trade-off between speed and result quality and
- * should be used all the time. They also offer the advantage of producing
- * compatible images, thus automatically resulting into better runtime
- * performance.
- *
- *
All these methods are both faster than
- * {@link java.awt.Image#getScaledInstance(int, int, int)} and produce
- * better-looking results than the various drawImage() methods
- * in {@link java.awt.Graphics}, which can be used for image scaling.
- *
- *
Image Manipulation
- *
- *
This class provides two methods to get and set pixels in a buffered image.
- * These methods try to avoid unmanaging the image in order to keep good
- * performance.
Returns a new BufferedImage using the same color model
- * as the image passed as a parameter. The returned image is only compatible
- * with the image passed as a parameter. This does not mean the returned
- * image is compatible with the hardware.
- *
- * @param image the reference image from which the color model of the new
- * image is obtained
- * @return a new BufferedImage, compatible with the color model
- * of image
- */
- public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
- ColorModel cm = image.getColorModel();
- return new BufferedImage(cm,
- cm.createCompatibleWritableRaster(image.getWidth(),
- image.getHeight()),
- cm.isAlphaPremultiplied(), null);
- }
-
- /**
- *
Returns a new compatible image with the same width, height and
- * transparency as the image specified as a parameter. That is, the
- * returned BufferedImage will be compatible with the graphics hardware.
- * If this method is called in a headless environment, then
- * the returned BufferedImage will be compatible with the source
- * image.
- *
- * @see java.awt.Transparency
- * @see #createCompatibleImage(int, int)
- * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
- * @see #createCompatibleTranslucentImage(int, int)
- * @see #loadCompatibleImage(java.net.URL)
- * @see #toCompatibleImage(java.awt.image.BufferedImage)
- * @param image the reference image from which the dimension and the
- * transparency of the new image are obtained
- * @return a new compatible BufferedImage with the same
- * dimension and transparency as image
- */
- public static BufferedImage createCompatibleImage(BufferedImage image) {
- return createCompatibleImage(image, image.getWidth(), image.getHeight());
- }
-
- /**
- *
Returns a new compatible image of the specified width and height, and
- * the same transparency setting as the image specified as a parameter.
- * That is, the returned BufferedImage is compatible with
- * the graphics hardware. If the method is called in a headless
- * environment, then the returned BufferedImage will be compatible with
- * the source image.
- *
- * @see java.awt.Transparency
- * @see #createCompatibleImage(java.awt.image.BufferedImage)
- * @see #createCompatibleImage(int, int)
- * @see #createCompatibleTranslucentImage(int, int)
- * @see #loadCompatibleImage(java.net.URL)
- * @see #toCompatibleImage(java.awt.image.BufferedImage)
- * @param width the width of the new image
- * @param height the height of the new image
- * @param image the reference image from which the transparency of the new
- * image is obtained
- * @return a new compatible BufferedImage with the same
- * transparency as image and the specified dimension
- */
- public static BufferedImage createCompatibleImage(BufferedImage image,
- int width, int height) {
- return isHeadless() ?
- new BufferedImage(width, height, image.getType()) :
- getGraphicsConfiguration().createCompatibleImage(width, height,
- image.getTransparency());
- }
-
- /**
- *
Returns a new opaque compatible image of the specified width and
- * height. That is, the returned BufferedImage is compatible with
- * the graphics hardware. If the method is called in a headless
- * environment, then the returned BufferedImage will be compatible with
- * the source image.
- *
- * @see #createCompatibleImage(java.awt.image.BufferedImage)
- * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
- * @see #createCompatibleTranslucentImage(int, int)
- * @see #loadCompatibleImage(java.net.URL)
- * @see #toCompatibleImage(java.awt.image.BufferedImage)
- * @param width the width of the new image
- * @param height the height of the new image
- * @return a new opaque compatible BufferedImage of the
- * specified width and height
- */
- public static BufferedImage createCompatibleImage(int width, int height) {
- return isHeadless() ?
- new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) :
- getGraphicsConfiguration().createCompatibleImage(width, height);
- }
-
- /**
- *
Returns a new translucent compatible image of the specified width and
- * height. That is, the returned BufferedImage is compatible with
- * the graphics hardware. If the method is called in a headless
- * environment, then the returned BufferedImage will be compatible with
- * the source image.
- *
- * @see #createCompatibleImage(java.awt.image.BufferedImage)
- * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
- * @see #createCompatibleImage(int, int)
- * @see #loadCompatibleImage(java.net.URL)
- * @see #toCompatibleImage(java.awt.image.BufferedImage)
- * @param width the width of the new image
- * @param height the height of the new image
- * @return a new translucent compatible BufferedImage of the
- * specified width and height
- */
- public static BufferedImage createCompatibleTranslucentImage(int width,
- int height) {
- return isHeadless() ?
- new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB) :
- getGraphicsConfiguration().createCompatibleImage(width, height,
- Transparency.TRANSLUCENT);
- }
-
- /**
- *
- * Returns a new compatible image from a stream. The image is loaded from
- * the specified stream and then turned, if necessary into a compatible
- * image.
- *
- *
- * @see #createCompatibleImage(java.awt.image.BufferedImage)
- * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
- * @see #createCompatibleImage(int, int)
- * @see #createCompatibleTranslucentImage(int, int)
- * @see #toCompatibleImage(java.awt.image.BufferedImage)
- * @param in
- * the stream of the picture to load as a compatible image
- * @return a new translucent compatible BufferedImage of the
- * specified width and height
- * @throws java.io.IOException
- * if the image cannot be read or loaded
- */
- public static BufferedImage loadCompatibleImage(InputStream in) throws IOException {
- BufferedImage image = ImageIO.read(in);
- if(image == null) return null;
- return toCompatibleImage(image);
- }
-
- /**
- *
Returns a new compatible image from a URL. The image is loaded from the
- * specified location and then turned, if necessary into a compatible
- * image.
- *
- * @see #createCompatibleImage(java.awt.image.BufferedImage)
- * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
- * @see #createCompatibleImage(int, int)
- * @see #createCompatibleTranslucentImage(int, int)
- * @see #toCompatibleImage(java.awt.image.BufferedImage)
- * @param resource the URL of the picture to load as a compatible image
- * @return a new translucent compatible BufferedImage of the
- * specified width and height
- * @throws java.io.IOException if the image cannot be read or loaded
- */
- public static BufferedImage loadCompatibleImage(URL resource)
- throws IOException {
- BufferedImage image = ImageIO.read(resource);
- return toCompatibleImage(image);
- }
-
- /**
- *
Return a new compatible image that contains a copy of the specified
- * image. This method ensures an image is compatible with the hardware,
- * and therefore optimized for fast blitting operations.
- *
- *
If the method is called in a headless environment, then the returned
- * BufferedImage will be the source image.
- *
- * @see #createCompatibleImage(java.awt.image.BufferedImage)
- * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
- * @see #createCompatibleImage(int, int)
- * @see #createCompatibleTranslucentImage(int, int)
- * @see #loadCompatibleImage(java.net.URL)
- * @param image the image to copy into a new compatible image
- * @return a new compatible copy, with the
- * same width and height and transparency and content, of image
- */
- public static BufferedImage toCompatibleImage(BufferedImage image) {
- if (isHeadless()) {
- return image;
- }
-
- if (image.getColorModel().equals(
- getGraphicsConfiguration().getColorModel())) {
- return image;
- }
-
- BufferedImage compatibleImage =
- getGraphicsConfiguration().createCompatibleImage(
- image.getWidth(), image.getHeight(),
- image.getTransparency());
- Graphics g = compatibleImage.getGraphics();
-
- try {
- g.drawImage(image, 0, 0, null);
- } finally {
- g.dispose();
- }
-
- return compatibleImage;
- }
-
- /**
- *
Returns a thumbnail of a source image. newSize defines
- * the length of the longest dimension of the thumbnail. The other
- * dimension is then computed according to the dimensions ratio of the
- * original picture.
- *
This method favors speed over quality. When the new size is less than
- * half the longest dimension of the source image,
- * {@link #createThumbnail(BufferedImage, int)} or
- * {@link #createThumbnail(BufferedImage, int, int)} should be used instead
- * to ensure the quality of the result without sacrificing too much
- * performance.
- *
- * @see #createThumbnailFast(java.awt.image.BufferedImage, int, int)
- * @see #createThumbnail(java.awt.image.BufferedImage, int)
- * @see #createThumbnail(java.awt.image.BufferedImage, int, int)
- * @param image the source image
- * @param newSize the length of the largest dimension of the thumbnail
- * @return a new compatible BufferedImage containing a
- * thumbnail of image
- * @throws IllegalArgumentException if newSize is larger than
- * the largest dimension of image or <= 0
- */
- public static BufferedImage createThumbnailFast(BufferedImage image,
- int newSize) {
- float ratio;
- int width = image.getWidth();
- int height = image.getHeight();
-
- if (width > height) {
- if (newSize >= width) {
- throw new IllegalArgumentException("newSize must be lower than" +
- " the image width");
- } else if (newSize <= 0) {
- throw new IllegalArgumentException("newSize must" +
- " be greater than 0");
- }
-
- ratio = (float) width / (float) height;
- width = newSize;
- height = (int) (newSize / ratio);
- } else {
- if (newSize >= height) {
- throw new IllegalArgumentException("newSize must be lower than" +
- " the image height");
- } else if (newSize <= 0) {
- throw new IllegalArgumentException("newSize must" +
- " be greater than 0");
- }
-
- ratio = (float) height / (float) width;
- height = newSize;
- width = (int) (newSize / ratio);
- }
-
- BufferedImage temp = createCompatibleImage(image, width, height);
- Graphics2D g2 = temp.createGraphics();
-
- try {
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- g2.drawImage(image, 0, 0, temp.getWidth(), temp.getHeight(), null);
- } finally {
- g2.dispose();
- }
-
- return temp;
- }
-
- /**
- *
Returns a thumbnail of a source image.
- *
This method favors speed over quality. When the new size is less than
- * half the longest dimension of the source image,
- * {@link #createThumbnail(BufferedImage, int)} or
- * {@link #createThumbnail(BufferedImage, int, int)} should be used instead
- * to ensure the quality of the result without sacrificing too much
- * performance.
- *
- * @see #createThumbnailFast(java.awt.image.BufferedImage, int)
- * @see #createThumbnail(java.awt.image.BufferedImage, int)
- * @see #createThumbnail(java.awt.image.BufferedImage, int, int)
- * @param image the source image
- * @param newWidth the width of the thumbnail
- * @param newHeight the height of the thumbnail
- * @return a new compatible BufferedImage containing a
- * thumbnail of image
- * @throws IllegalArgumentException if newWidth is larger than
- * the width of image or if code>newHeight is larger
- * than the height of image or if one of the dimensions
- * is <= 0
- */
- public static BufferedImage createThumbnailFast(BufferedImage image,
- int newWidth, int newHeight) {
- if (newWidth >= image.getWidth() ||
- newHeight >= image.getHeight()) {
- throw new IllegalArgumentException("newWidth and newHeight cannot" +
- " be greater than the image" +
- " dimensions");
- } else if (newWidth <= 0 || newHeight <= 0) {
- throw new IllegalArgumentException("newWidth and newHeight must" +
- " be greater than 0");
- }
-
- BufferedImage temp = createCompatibleImage(image, newWidth, newHeight);
- Graphics2D g2 = temp.createGraphics();
-
- try {
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- g2.drawImage(image, 0, 0, temp.getWidth(), temp.getHeight(), null);
- } finally {
- g2.dispose();
- }
-
- return temp;
- }
-
- /**
- *
Returns a thumbnail of a source image. newSize defines
- * the length of the longest dimension of the thumbnail. The other
- * dimension is then computed according to the dimensions ratio of the
- * original picture.
- *
This method offers a good trade-off between speed and quality.
- * The result looks better than
- * {@link #createThumbnailFast(java.awt.image.BufferedImage, int)} when
- * the new size is less than half the longest dimension of the source
- * image, yet the rendering speed is almost similar.
- *
- * @see #createThumbnailFast(java.awt.image.BufferedImage, int, int)
- * @see #createThumbnailFast(java.awt.image.BufferedImage, int)
- * @see #createThumbnail(java.awt.image.BufferedImage, int, int)
- * @param image the source image
- * @param newSize the length of the largest dimension of the thumbnail
- * @return a new compatible BufferedImage containing a
- * thumbnail of image
- * @throws IllegalArgumentException if newSize is larger than
- * the largest dimension of image or <= 0
- */
- public static BufferedImage createThumbnail(BufferedImage image,
- int newSize) {
- int width = image.getWidth();
- int height = image.getHeight();
-
- boolean isTranslucent = image.getTransparency() != Transparency.OPAQUE;
- boolean isWidthGreater = width > height;
-
- if (isWidthGreater) {
- if (newSize >= width) {
- throw new IllegalArgumentException("newSize must be lower than" +
- " the image width");
- }
- } else if (newSize >= height) {
- throw new IllegalArgumentException("newSize must be lower than" +
- " the image height");
- }
-
- if (newSize <= 0) {
- throw new IllegalArgumentException("newSize must" +
- " be greater than 0");
- }
-
- float ratioWH = (float) width / (float) height;
- float ratioHW = (float) height / (float) width;
-
- BufferedImage thumb = image;
- BufferedImage temp = null;
-
- Graphics2D g2 = null;
-
- try {
- int previousWidth = width;
- int previousHeight = height;
-
- do {
- if (isWidthGreater) {
- width /= 2;
- if (width < newSize) {
- width = newSize;
- }
- height = (int) (width / ratioWH);
- } else {
- height /= 2;
- if (height < newSize) {
- height = newSize;
- }
- width = (int) (height / ratioHW);
- }
-
- if (temp == null || isTranslucent) {
- if (g2 != null) {
- //do not need to wrap with finally
- //outer finally block will ensure
- //that resources are properly reclaimed
- g2.dispose();
- }
- temp = createCompatibleImage(image, width, height);
- g2 = temp.createGraphics();
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- }
- if (g2 != null) // always the case
- g2.drawImage(thumb, 0, 0, width, height,
- 0, 0, previousWidth, previousHeight, null);
-
- previousWidth = width;
- previousHeight = height;
-
- thumb = temp;
- } while (newSize != (isWidthGreater ? width : height));
- } finally {
- if (g2 != null) {
- g2.dispose();
- }
- }
-
- if (width != thumb.getWidth() || height != thumb.getHeight()) {
- temp = createCompatibleImage(image, width, height);
- g2 = temp.createGraphics();
-
- try {
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- g2.drawImage(thumb, 0, 0, width, height, 0, 0, width, height, null);
- } finally {
- g2.dispose();
- }
-
- thumb = temp;
- }
-
- return thumb;
- }
-
- /**
- *
Returns a thumbnail of a source image.
- *
This method offers a good trade-off between speed and quality.
- * The result looks better than
- * {@link #createThumbnailFast(java.awt.image.BufferedImage, int)} when
- * the new size is less than half the longest dimension of the source
- * image, yet the rendering speed is almost similar.
- *
- * @see #createThumbnailFast(java.awt.image.BufferedImage, int)
- * @see #createThumbnailFast(java.awt.image.BufferedImage, int, int)
- * @see #createThumbnail(java.awt.image.BufferedImage, int)
- * @param image the source image
- * @param newWidth the width of the thumbnail
- * @param newHeight the height of the thumbnail
- * @return a new compatible BufferedImage containing a
- * thumbnail of image
- * @throws IllegalArgumentException if newWidth is larger than
- * the width of image or if code>newHeight is larger
- * than the height of image or if one the dimensions is not > 0
- */
- public static BufferedImage createThumbnail(BufferedImage image,
- int newWidth, int newHeight) {
- int width = image.getWidth();
- int height = image.getHeight();
-
- boolean isTranslucent = image.getTransparency() != Transparency.OPAQUE;
-
- if (newWidth >= width || newHeight >= height) {
- throw new IllegalArgumentException("newWidth and newHeight cannot" +
- " be greater than the image" +
- " dimensions");
- } else if (newWidth <= 0 || newHeight <= 0) {
- throw new IllegalArgumentException("newWidth and newHeight must" +
- " be greater than 0");
- }
-
- BufferedImage thumb = image;
- BufferedImage temp = null;
-
- Graphics2D g2 = null;
-
- try {
- int previousWidth = width;
- int previousHeight = height;
-
- do {
- if (width > newWidth) {
- width /= 2;
- if (width < newWidth) {
- width = newWidth;
- }
- }
-
- if (height > newHeight) {
- height /= 2;
- if (height < newHeight) {
- height = newHeight;
- }
- }
-
- if (temp == null || isTranslucent) {
- if (g2 != null) {
- //do not need to wrap with finally
- //outer finally block will ensure
- //that resources are properly reclaimed
- g2.dispose();
- }
- temp = createCompatibleImage(image, width, height);
- g2 = temp.createGraphics();
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- }
- if (g2 != null) // always the case
- g2.drawImage(thumb, 0, 0, width, height,
- 0, 0, previousWidth, previousHeight, null);
-
- previousWidth = width;
- previousHeight = height;
-
- thumb = temp;
- } while (width != newWidth || height != newHeight);
- } finally {
- if (g2 != null) {
- g2.dispose();
- }
- }
-
- if (width != thumb.getWidth() || height != thumb.getHeight()) {
- temp = createCompatibleImage(image, width, height);
- g2 = temp.createGraphics();
-
- try {
- g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- g2.drawImage(thumb, 0, 0, width, height, 0, 0, width, height, null);
- } finally {
- g2.dispose();
- }
-
- thumb = temp;
- }
-
- return thumb;
- }
-
- /**
- *
Returns an array of pixels, stored as integers, from a
- * BufferedImage. The pixels are grabbed from a rectangular
- * area defined by a location and two dimensions. Calling this method on
- * an image of type different from BufferedImage.TYPE_INT_ARGB
- * and BufferedImage.TYPE_INT_RGB will unmanage the image.
- *
- * @param img the source image
- * @param x the x location at which to start grabbing pixels
- * @param y the y location at which to start grabbing pixels
- * @param w the width of the rectangle of pixels to grab
- * @param h the height of the rectangle of pixels to grab
- * @param pixels a pre-allocated array of pixels of size w*h; can be null
- * @return pixels if non-null, a new array of integers
- * otherwise
- * @throws IllegalArgumentException is pixels is non-null and
- * of length < w*h
- */
- public static int[] getPixels(BufferedImage img,
- int x, int y, int w, int h, int[] pixels) {
- if (w == 0 || h == 0) {
- return new int[0];
- }
-
- if (pixels == null) {
- pixels = new int[w * h];
- } else if (pixels.length < w * h) {
- throw new IllegalArgumentException("pixels array must have a length" +
- " >= w*h");
- }
-
- int imageType = img.getType();
- if (imageType == BufferedImage.TYPE_INT_ARGB ||
- imageType == BufferedImage.TYPE_INT_RGB) {
- Raster raster = img.getRaster();
- return (int[]) raster.getDataElements(x, y, w, h, pixels);
- }
-
- // Unmanages the image
- return img.getRGB(x, y, w, h, pixels, 0, w);
- }
-
- /**
- *
Writes a rectangular area of pixels in the destination
- * BufferedImage. Calling this method on
- * an image of type different from BufferedImage.TYPE_INT_ARGB
- * and BufferedImage.TYPE_INT_RGB will unmanage the image.
- *
- * @param img the destination image
- * @param x the x location at which to start storing pixels
- * @param y the y location at which to start storing pixels
- * @param w the width of the rectangle of pixels to store
- * @param h the height of the rectangle of pixels to store
- * @param pixels an array of pixels, stored as integers
- * @throws IllegalArgumentException is pixels is non-null and
- * of length < w*h
- */
- public static void setPixels(BufferedImage img,
- int x, int y, int w, int h, int[] pixels) {
- if (pixels == null || w == 0 || h == 0) {
- return;
- } else if (pixels.length < w * h) {
- throw new IllegalArgumentException("pixels array must have a length" +
- " >= w*h");
- }
-
- int imageType = img.getType();
- if (imageType == BufferedImage.TYPE_INT_ARGB ||
- imageType == BufferedImage.TYPE_INT_RGB) {
- WritableRaster raster = img.getRaster();
- raster.setDataElements(x, y, w, h, pixels);
- } else {
- // Unmanages the image
- img.setRGB(x, y, w, h, pixels, 0, w);
- }
- }
-
- /**
- * Clears the data from the image.
- *
- * @param img
- * the image to erase
- */
- public static void clear(Image img) {
- Graphics g = img.getGraphics();
-
- try {
- if (g instanceof Graphics2D) {
- ((Graphics2D) g).setComposite(AlphaComposite.Clear);
- } else {
- g.setColor(new Color(0, 0, 0, 0));
- }
-
- g.fillRect(0, 0, img.getWidth(null), img.getHeight(null));
- } finally {
- g.dispose();
- }
- }
-
- /**
- * Sets the clip on a graphics object by merging a supplied clip with the existing one. The new
- * clip will be an intersection of the old clip and the supplied clip. The old clip shape will
- * be returned. This is useful for resetting the old clip after an operation is performed.
- *
- * @param g
- * the graphics object to update
- * @param clip
- * a new clipping region to add to the graphics clip.
- * @return the current clipping region of the supplied graphics object. This may return {@code
- * null} if the current clip is {@code null}.
- * @throws NullPointerException
- * if any parameter is {@code null}
- * @deprecated Use {@link ShapeUtils#mergeClip(Graphics,Shape)} instead
- */
- @Deprecated
- public static Shape mergeClip(Graphics g, Shape clip) {
- return ShapeUtils.mergeClip(g, clip);
- }
-
- /**
- * Draws an image on top of a component by doing a 3x3 grid stretch of the image
- * using the specified insets.
- * @param g the graphics object
- * @param comp the component
- * @param img the image
- * @param ins the insets
- */
- public static void tileStretchPaint(Graphics g,
- JComponent comp,
- BufferedImage img,
- Insets ins) {
-
- int left = ins.left;
- int right = ins.right;
- int top = ins.top;
- int bottom = ins.bottom;
-
- // top
- g.drawImage(img,
- 0,0,left,top,
- 0,0,left,top,
- null);
- g.drawImage(img,
- left, 0,
- comp.getWidth() - right, top,
- left, 0,
- img.getWidth() - right, top,
- null);
- g.drawImage(img,
- comp.getWidth() - right, 0,
- comp.getWidth(), top,
- img.getWidth() - right, 0,
- img.getWidth(), top,
- null);
-
- // middle
- g.drawImage(img,
- 0, top,
- left, comp.getHeight()-bottom,
- 0, top,
- left, img.getHeight()-bottom,
- null);
-
- g.drawImage(img,
- left, top,
- comp.getWidth()-right, comp.getHeight()-bottom,
- left, top,
- img.getWidth()-right, img.getHeight()-bottom,
- null);
-
- g.drawImage(img,
- comp.getWidth()-right, top,
- comp.getWidth(), comp.getHeight()-bottom,
- img.getWidth()-right, top,
- img.getWidth(), img.getHeight()-bottom,
- null);
-
- // bottom
- g.drawImage(img,
- 0,comp.getHeight()-bottom,
- left, comp.getHeight(),
- 0,img.getHeight()-bottom,
- left,img.getHeight(),
- null);
- g.drawImage(img,
- left, comp.getHeight()-bottom,
- comp.getWidth()-right, comp.getHeight(),
- left, img.getHeight()-bottom,
- img.getWidth()-right, img.getHeight(),
- null);
- g.drawImage(img,
- comp.getWidth()-right, comp.getHeight()-bottom,
- comp.getWidth(), comp.getHeight(),
- img.getWidth()-right, img.getHeight()-bottom,
- img.getWidth(), img.getHeight(),
- null);
- }
-}
diff --git a/src/main/java/org/jdesktop/swingx/util/ShapeUtils.java b/src/main/java/org/jdesktop/swingx/util/ShapeUtils.java
deleted file mode 100644
index 480d6224..00000000
--- a/src/main/java/org/jdesktop/swingx/util/ShapeUtils.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * $Id: ShapeUtils.java 4082 2011-11-15 18:39:43Z kschaefe $
- *
- * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
- * Santa Clara, California 95054, U.S.A. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.jdesktop.swingx.util;
-
-import org.apache.commons.math3.util.FastMath;
-
-import java.awt.*;
-import java.awt.font.GlyphVector;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Area;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
-
-/**
- *
- * @author joshy
- */
-public final class ShapeUtils {
-
- /** Creates a new instance of ShapeUtils */
- private ShapeUtils() {
- }
-
- /**
- * Generates a polygon with an inside radius of 0.
- * @param sides number of sides
- * @param outsideRadius the outside radius
- * @param normalize normalize
- * @return the generated shape
- */
- public static Shape generatePolygon(int sides, int outsideRadius, boolean normalize) {
- return generatePolygon(sides, outsideRadius, 0, normalize);
- }
-
- /**
- * Generates a polygon
- * @param sides number of sides
- * @param outsideRadius the outside radius
- * @param insideRadius the inside radius
- * @param normalize normalize
- * @return the generated shape
- */
- public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius,
- boolean normalize) {
- Shape shape = generatePolygon(sides, outsideRadius, insideRadius);
- if (normalize) {
- Rectangle2D bounds = shape.getBounds2D();
- GeneralPath path = new GeneralPath(shape);
- shape = path.createTransformedShape(AffineTransform.getTranslateInstance(
- -bounds.getX(), -bounds.getY()));
- }
- return shape;
- }
-
- /**
- * Generates a polygon
- * @param sides number of sides
- * @param outsideRadius the outside radius
- * @param insideRadius the inside radius
- * @return the generated shape
- */
- public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius) {
- if (sides < 3) {
- return new Ellipse2D.Float(0, 0, 10, 10);
- }
-
- AffineTransform trans = new AffineTransform();
- Polygon poly = new Polygon();
- for (int i = 0; i < sides; i++) {
- trans.rotate(FastMath.PI * 2 / sides / 2);
- Point2D out = trans.transform(new Point2D.Float(0, outsideRadius), null);
- poly.addPoint((int) out.getX(), (int) out.getY());
- trans.rotate(FastMath.PI * 2 / sides / 2);
- if (insideRadius > 0) {
- Point2D in = trans.transform(new Point2D.Float(0, insideRadius), null);
- poly.addPoint((int) in.getX(), (int) in.getY());
- }
- }
-
- return poly;
- }
-
- /**
- * @param font the font
- * @param ch a single character
- * @return the shape
- */
- public static Shape generateShapeFromText(Font font, char ch) {
- return generateShapeFromText(font, String.valueOf(ch));
- }
-
- /**
- * @param font the font
- * @param string the text string
- * @return the shape
- */
- public static Shape generateShapeFromText(Font font, String string) {
- BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(1, 1);
- Graphics2D g2 = img.createGraphics();
-
- try {
- GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string);
- Shape shape = vect.getOutline(0f, (float) -vect.getVisualBounds().getY());
-
- return shape;
- } finally {
- g2.dispose();
- }
- }
-
- /**
- * Sets the clip on a graphics object by merging a supplied clip with the existing one. The new
- * clip will be an intersection of the old clip and the supplied clip. The old clip shape will
- * be returned. This is useful for resetting the old clip after an operation is performed.
- *
- * @param g
- * the graphics object to update
- * @param clip
- * a new clipping region to add to the graphics clip.
- * @return the current clipping region of the supplied graphics object. This may return
- * {@code null} if the current clip is {@code null}.
- * @throws NullPointerException
- * if any parameter is {@code null}
- */
- public static Shape mergeClip(Graphics g, Shape clip) {
- Shape oldClip = g.getClip();
- if (oldClip == null) {
- g.setClip(clip);
- return null;
- }
- Area area = new Area(oldClip);
- area.intersect(new Area(clip));// new Rectangle(0,0,width,height)));
- g.setClip(area);
- return oldClip;
- }
-}
diff --git a/src/test/java/io/github/dsheirer/gui/map/MapViewportTest.java b/src/test/java/io/github/dsheirer/gui/map/MapViewportTest.java
new file mode 100644
index 00000000..bb05cb96
--- /dev/null
+++ b/src/test/java/io/github/dsheirer/gui/map/MapViewportTest.java
@@ -0,0 +1,113 @@
+/*
+ * *****************************************************************************
+ * Copyright (C) 2014-2026 Dennis Sheirer
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * ****************************************************************************
+ */
+package io.github.dsheirer.gui.map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import io.github.dsheirer.map.GeoPosition;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests the map projection and viewport conversions
+ */
+public class MapViewportTest
+{
+ @Test
+ void projectionRoundTrips()
+ {
+ assertEquals(0.5, Mercator.x(0), 1e-12);
+ assertEquals(0.5, Mercator.y(0), 1e-12);
+ assertEquals(0.0, Mercator.y(Mercator.MAX_LATITUDE), 1e-9, "top of the map");
+ assertEquals(43.048, Mercator.latitude(Mercator.y(43.048)), 1e-9);
+ assertEquals(-76.147, Mercator.longitude(Mercator.x(-76.147)), 1e-9);
+ assertEquals(-170.0, Mercator.normalizeLongitude(190.0), 1e-9);
+ }
+
+ @Test
+ void openStreetMapTileOfAPosition()
+ {
+ //Syracuse, NY is in tile 12/1181/1504 of the OpenStreetMap tiles
+ int zoom = 12;
+ assertEquals(1181, (int)Math.floor(Mercator.x(-76.147) * Mercator.tileCount(zoom)));
+ assertEquals(1504, (int)Math.floor(Mercator.y(43.048) * Mercator.tileCount(zoom)));
+ }
+
+ @Test
+ void centerIsInTheMiddleOfTheView()
+ {
+ MapViewport viewport = new MapViewport();
+ viewport.setSize(800, 600);
+ viewport.setZoom(12);
+ viewport.setCenter(new GeoPosition(43.048, -76.147));
+
+ assertEquals(400, viewport.getScreenX(-76.147), 0.5);
+ assertEquals(300, viewport.getScreenY(43.048), 0.5);
+ GeoPosition center = viewport.getPosition(400, 300);
+ assertEquals(43.048, center.getLatitude(), 1e-3);
+ assertEquals(-76.147, center.getLongitude(), 1e-3);
+ }
+
+ @Test
+ void zoomKeepsThePointUnderTheMouse()
+ {
+ MapViewport viewport = new MapViewport();
+ viewport.setSize(800, 600);
+ viewport.setZoom(10);
+ viewport.setCenter(new GeoPosition(43.048, -76.147));
+ GeoPosition before = viewport.getPosition(650, 120);
+
+ viewport.zoomAt(13, 650, 120);
+
+ GeoPosition after = viewport.getPosition(650, 120);
+ assertEquals(13, viewport.getZoom());
+ //Within a pixel at zoom 13, since the view edges are whole pixels
+ assertEquals(before.getLatitude(), after.getLatitude(), 2e-4);
+ assertEquals(before.getLongitude(), after.getLongitude(), 2e-4);
+ }
+
+ @Test
+ void panWrapsAroundTheWorldAndStopsAtThePoles()
+ {
+ MapViewport viewport = new MapViewport();
+ viewport.setSize(800, 600);
+ viewport.setZoom(3);
+ viewport.setCenter(new GeoPosition(0, 179));
+
+ viewport.pan(Mercator.worldSize(3) * 0.01, 0);
+ assertEquals(-177.4, viewport.getCenter().getLongitude(), 0.01, "wrapped past 180 degrees");
+
+ viewport.pan(0, -1_000_000);
+ assertEquals(0, viewport.getTop(), "stops at the top of the map");
+ viewport.pan(0, 1_000_000);
+ assertEquals(Mercator.worldSize(3) - 600, viewport.getTop(), "stops at the bottom of the map");
+ }
+
+ @Test
+ void positionsAcrossTheDateLineAreDrawnNearTheView()
+ {
+ MapViewport viewport = new MapViewport();
+ viewport.setSize(800, 600);
+ viewport.setZoom(4);
+ viewport.setCenter(new GeoPosition(0, 179.5));
+
+ //Just east of the date line is on the right of the view, not a world away
+ double x = viewport.getScreenX(-179.5);
+ assertEquals(400 + Mercator.worldSize(4) / 360.0, x, 1.0);
+ }
+}
diff --git a/src/test/java/io/github/dsheirer/map/RadioReferenceSiteMapTest.java b/src/test/java/io/github/dsheirer/gui/map/SiteLayerTest.java
similarity index 51%
rename from src/test/java/io/github/dsheirer/map/RadioReferenceSiteMapTest.java
rename to src/test/java/io/github/dsheirer/gui/map/SiteLayerTest.java
index 94dada8d..a0913fe4 100644
--- a/src/test/java/io/github/dsheirer/map/RadioReferenceSiteMapTest.java
+++ b/src/test/java/io/github/dsheirer/gui/map/SiteLayerTest.java
@@ -16,28 +16,22 @@
* along with this program. If not, see
* ****************************************************************************
*/
-
-package io.github.dsheirer.map;
+package io.github.dsheirer.gui.map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import io.github.dsheirer.map.GeoPosition;
import io.github.dsheirer.service.radioreference.SiteRecord;
-import java.awt.Point;
-import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
-import org.jdesktop.swingx.JXMapViewer;
-import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
-import org.jdesktop.swingx.mapviewer.GeoPosition;
-import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
import org.junit.jupiter.api.Test;
/**
* Tests the radio reference site markers and card on the map, without loading map tiles
*/
-public class RadioReferenceSiteMapTest
+public class SiteLayerTest
{
private static SiteRecord site(String system, String description, double latitude, double longitude, int channels)
{
@@ -56,45 +50,45 @@ public class RadioReferenceSiteMapTest
@Test
void hitTestFindsTowersUnderTheMouse()
{
- //Offline tile source with the OSM geometry - nothing is loaded without painting
- JXMapViewer map = new JXMapViewer();
- map.setTileFactory(new DefaultTileFactory(new TileFactoryInfo(1, 17, 19, 256, true, true,
- "file:///nonexistent", "x", "y", "z")));
- map.setSize(800, 600);
- map.setZoom(6);
- map.setCenterPosition(new GeoPosition(43.05, -76.15));
+ MapViewport viewport = new MapViewport();
+ viewport.setSize(800, 600);
+ viewport.setZoom(13);
+ viewport.setCenter(new GeoPosition(43.05, -76.15));
SiteRecord syracuse = site("System A", "Syracuse", 43.0481, -76.1474, 4);
SiteRecord sameTower = site("System B", "Syracuse", 43.0481, -76.1474, 4);
SiteRecord fulton = site("System C", "Fulton", 43.3226, -76.4171, 4);
- RadioReferenceSitePainter painter = new RadioReferenceSitePainter(() -> List.of(syracuse, sameTower, fulton));
+ SiteLayer layer = new SiteLayer(() -> List.of(syracuse, sameTower, fulton));
- Point2D pixel = map.getTileFactory().geoToPixel(new GeoPosition(43.0481, -76.1474), map.getZoom());
- Point tower = new Point((int)Math.round(pixel.getX() - map.getViewportBounds().getX()),
- (int)Math.round(pixel.getY() - map.getViewportBounds().getY()) - 8);
+ //Middle of the tower, above its base at the site location
+ double x = viewport.getScreenX(-76.1474);
+ double y = viewport.getScreenY(43.0481) - 8;
assertEquals(List.of("System A", "System B"),
- painter.getSitesAt(map, tower).stream().map(SiteRecord::systemName).toList(), "both towers at the spot");
- assertTrue(painter.getSitesAt(map, new Point(tower.x + 60, tower.y)).isEmpty());
+ layer.getSitesAt(viewport, x, y).stream().map(SiteRecord::systemName).toList(), "both towers at the spot");
+ assertTrue(layer.getSitesAt(viewport, x + 60, y).isEmpty());
- painter.setShowSites(false);
- assertTrue(painter.getSitesAt(map, tower).isEmpty(), "hidden sites aren't found");
+ layer.setShowSites(false);
+ assertTrue(layer.getSitesAt(viewport, x, y).isEmpty(), "hidden sites aren't found");
}
@Test
void cardShowsSystemSiteAndChannels()
{
- String html = RadioReferenceSiteCard.html(List.of(site("Fire & Rescue ", "Syracuse", 43.0481,
+ SiteCard.Content content = SiteCard.content(List.of(site("Fire & Rescue ", "Syracuse", 43.0481,
-76.1474, 30)), null);
-
- assertTrue(html.contains("Fire & Rescue <Interop>"), "escaped system name");
- assertTrue(html.contains("Project 25 Phase II"));
- assertTrue(html.contains("Site 3 · Syracuse · Onondaga County"));
- assertTrue(html.contains("NAC 1A3 · RFSS 1 · Zone 2"));
- assertTrue(html.contains("851.01250 C"), "control channel marked");
- assertTrue(html.contains("851.26250 A"), "alternate control channel marked");
- assertTrue(html.contains("+ 6 more channels"), "24 channels shown");
- assertFalse(html.contains(" mi") || html.contains(" km"), "no distance without a location");
+ assertEquals(1, content.entries().size());
+ SiteCard.Entry entry = content.entries().getFirst();
+ assertEquals("Fire & Rescue ", entry.title());
+ assertEquals(List.of("Project 25 Phase II · APCO-25 Common Air Interface Exclusive",
+ "Site 3 · Syracuse · Onondaga County", "NAC 1A3 · RFSS 1 · Zone 2"), entry.lines(),
+ "no distance without a location");
+ assertEquals(new SiteCard.Channel("851.01250", "C"), entry.channels().get(0), "control channel marked");
+ assertEquals(new SiteCard.Channel("851.26250", "A"), entry.channels().get(1), "alternate control marked");
+ assertEquals(new SiteCard.Channel("851.51250", null), entry.channels().get(2));
+ assertEquals(24, entry.channels().size(), "24 channels shown");
+ assertEquals(List.of("+ 6 more channels · C control, A alternate control"), entry.notes());
+ assertEquals(0, content.moreSites());
}
@Test
@@ -107,9 +101,10 @@ public class RadioReferenceSiteMapTest
sites.add(site("System " + index, "Syracuse", 43.0481, -76.1474, 2));
}
- String html = RadioReferenceSiteCard.html(sites, null);
- assertTrue(html.contains("System 2"));
- assertFalse(html.contains("System 3"));
- assertTrue(html.contains("+ 2 more sites here"));
+ SiteCard.Content content = SiteCard.content(sites, null);
+ assertEquals(List.of("System 0", "System 1", "System 2"),
+ content.entries().stream().map(SiteCard.Entry::title).toList());
+ assertEquals(2, content.moreSites());
+ assertFalse(content.entries().getFirst().notes().getFirst().contains("more channels"));
}
}
diff --git a/src/test/java/io/github/dsheirer/gui/map/TileServerTest.java b/src/test/java/io/github/dsheirer/gui/map/TileServerTest.java
new file mode 100644
index 00000000..99473385
--- /dev/null
+++ b/src/test/java/io/github/dsheirer/gui/map/TileServerTest.java
@@ -0,0 +1,137 @@
+/*
+ * *****************************************************************************
+ * Copyright (C) 2014-2026 Dennis Sheirer
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * ****************************************************************************
+ */
+package io.github.dsheirer.gui.map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests choosing tiles for the theme and the user's key, and recoloring light tiles for dark themes
+ */
+public class TileServerTest
+{
+ @Test
+ void serverWithoutDarkStyleIsRecoloredInDarkThemes()
+ {
+ TileSource light = TileServer.OPEN_STREET_MAP.getSource(false, null);
+ TileSource dark = TileServer.OPEN_STREET_MAP.getSource(true, null);
+
+ assertFalse(light.darken());
+ assertFalse(light.dark());
+ assertTrue(dark.darken());
+ assertTrue(dark.dark());
+ assertEquals("osm/light", dark.cacheName(), "recolored from the cached light tiles");
+ assertEquals("https://tile.openstreetmap.org/12/1181/1504.png", dark.getUrl(new TileKey(12, 1181, 1504)));
+ }
+
+ @Test
+ void serverWithDarkStyleFollowsTheTheme()
+ {
+ TileSource light = TileServer.ESRI_GRAY.getSource(false, null);
+ TileSource dark = TileServer.ESRI_GRAY.getSource(true, null);
+
+ assertFalse(dark.darken(), "dark style isn't recolored");
+ assertTrue(dark.dark());
+ assertEquals("esri.gray/dark", dark.cacheName());
+ assertNotEquals(light.cacheName(), dark.cacheName());
+ assertEquals("https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/" +
+ "12/1504/1181", dark.getUrl(new TileKey(12, 1181, 1504)), "row before column");
+ }
+
+ @Test
+ void keyedServerNeedsAKey()
+ {
+ TileSource missing = TileServer.CARTO.getSource(true, " ");
+ assertFalse(missing.isAvailable());
+ assertTrue(missing.unavailableReason().contains("API key"));
+
+ TileSource keyed = TileServer.CARTO.getSource(true, " abc+def ");
+ assertTrue(keyed.isAvailable());
+ assertNull(keyed.unavailableReason());
+ assertEquals("https://basemaps.cartocdn.com/rastertiles/dark_all/5/9/12.png?key=abc%2Bdef",
+ keyed.getUrl(new TileKey(5, 9, 12)), "key trimmed and encoded");
+ assertEquals("carto/dark", keyed.cacheName(), "cache doesn't depend on the key");
+ }
+
+ @Test
+ void subdomainsSpreadTheTiles()
+ {
+ TileSource source = TileServer.OPEN_TOPO_MAP.getSource(false, null);
+ assertEquals("https://a.tile.opentopomap.org/1/0/0.png", source.getUrl(new TileKey(1, 0, 0)));
+ assertEquals("https://b.tile.opentopomap.org/1/1/0.png", source.getUrl(new TileKey(1, 1, 0)));
+ assertEquals("https://c.tile.opentopomap.org/1/1/1.png", source.getUrl(new TileKey(1, 1, 1)));
+ }
+
+ @Test
+ void unknownServerIsOpenStreetMap()
+ {
+ assertEquals(TileServer.OPEN_STREET_MAP, TileServer.get(null));
+ assertEquals(TileServer.OPEN_STREET_MAP, TileServer.get("gone"));
+ assertEquals(TileServer.CARTO, TileServer.get("carto"));
+ }
+
+ @Test
+ void choiceFollowsTheThemeOrKeepsItsStyle()
+ {
+ TileChoice theme = TileChoice.get("carto", null);
+ assertEquals(TileChoice.Style.THEME, theme.style(), "stored server without a style follows the theme");
+ assertEquals("carto/dark", theme.getSource(true, "k").cacheName());
+ assertEquals("carto/light", theme.getSource(false, "k").cacheName());
+
+ TileChoice light = TileChoice.get("carto", "LIGHT");
+ assertEquals("carto/light", light.getSource(true, "k").cacheName(), "light in a dark theme");
+ assertFalse(light.getSource(true, "k").dark());
+
+ TileSource dark = TileChoice.get("osm", "DARK").getSource(false, null);
+ assertTrue(dark.dark(), "dark in a light theme");
+ assertTrue(dark.darken(), "recolored, no dark style");
+
+ assertEquals(TileChoice.Style.THEME, TileChoice.get("osm", "gone").style());
+ assertEquals(TileServer.SERVERS.size() * 3, TileChoice.CHOICES.size());
+ assertEquals("CARTO - Auto", theme.toString());
+ assertEquals("CARTO - Dark", TileChoice.get("carto", "DARK").toString());
+ }
+
+ @Test
+ void darkenerInvertsLightnessAndKeepsHue()
+ {
+ assertEquals(gray(TileDarkener.DARKEST), TileDarkener.darken(0xFFFFFFFF) & 0xFFFFFF, "white turns dark");
+ assertEquals(gray(TileDarkener.LIGHTEST), TileDarkener.darken(0xFF000000) & 0xFFFFFF, "black turns light");
+ assertEquals(0x80000000, TileDarkener.darken(0x80FFFFFF) & 0xFF000000, "alpha kept");
+
+ //Light blue water turns dark blue: blue stays the strongest channel and it gets darker
+ int water = TileDarkener.darken(0xFFAAD3DF);
+ int r = (water >> 16) & 0xFF;
+ int g = (water >> 8) & 0xFF;
+ int b = water & 0xFF;
+ assertTrue(b > g && g > r, "hue kept");
+ assertTrue(b < 0x80, "darker");
+ }
+
+ private static int gray(double lightness)
+ {
+ int value = (int)Math.round(lightness * 255.0);
+ return (value << 16) | (value << 8) | value;
+ }
+}