mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
#82 WIP - converted all classes to get icons from IconManager and removed icon management from the SettingsManager
This commit is contained in:
@@ -1,28 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package map;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import icon.IconManager;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.OSMTileFactoryInfo;
|
||||
import org.jdesktop.swingx.input.PanKeyListener;
|
||||
@@ -30,10 +27,12 @@ import org.jdesktop.swingx.input.ZoomMouseWheelListenerCursor;
|
||||
import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
|
||||
|
||||
import settings.MapViewSetting;
|
||||
import settings.SettingsManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MapPanel extends JPanel implements PlottableUpdateListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -42,107 +41,103 @@ public class MapPanel extends JPanel implements PlottableUpdateListener
|
||||
private MapService mMapService;
|
||||
private JXMapViewer mMapViewer = new JXMapViewer();
|
||||
private PlottableEntityPainter mMapPainter;
|
||||
|
||||
public MapPanel( MapService mapService, SettingsManager settingsManager )
|
||||
|
||||
public MapPanel(MapService mapService, IconManager iconManager, SettingsManager settingsManager)
|
||||
{
|
||||
mSettingsManager = settingsManager;
|
||||
mMapService = mapService;
|
||||
mMapPainter = new PlottableEntityPainter( mSettingsManager );
|
||||
|
||||
init();
|
||||
mSettingsManager = settingsManager;
|
||||
mMapService = mapService;
|
||||
mMapPainter = new PlottableEntityPainter(iconManager);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout( new MigLayout( "insets 0 0 0 0",
|
||||
"[grow,fill]", "[grow,fill]") );
|
||||
setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill]"));
|
||||
|
||||
/**
|
||||
* Set the entity painter as the overlay painter and register this panel
|
||||
* to receive new messages (plots)
|
||||
*/
|
||||
mMapViewer.setOverlayPainter( mMapPainter );
|
||||
mMapService.addListener( this );
|
||||
|
||||
/**
|
||||
* Map image source
|
||||
*/
|
||||
TileFactoryInfo info = new OSMTileFactoryInfo();
|
||||
DefaultTileFactory tileFactory = new DefaultTileFactory( info );
|
||||
mMapViewer.setTileFactory( tileFactory );
|
||||
/**
|
||||
* Set the entity painter as the overlay painter and register this panel
|
||||
* to receive new messages (plots)
|
||||
*/
|
||||
mMapViewer.setOverlayPainter(mMapPainter);
|
||||
mMapService.addListener(this);
|
||||
|
||||
/**
|
||||
* Defines how many threads will be used to fetch the background map
|
||||
* tiles (graphics)
|
||||
*/
|
||||
tileFactory.setThreadPoolSize( 8 );
|
||||
/**
|
||||
* Map image source
|
||||
*/
|
||||
TileFactoryInfo info = new OSMTileFactoryInfo();
|
||||
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
|
||||
mMapViewer.setTileFactory(tileFactory);
|
||||
|
||||
/**
|
||||
* Set initial location and zoom for the map upon display
|
||||
*/
|
||||
GeoPosition syracuse = new GeoPosition( 43.048, -76.147 );
|
||||
int zoom = 7;
|
||||
|
||||
MapViewSetting view = mSettingsManager
|
||||
.getMapViewSetting( "Default", syracuse, zoom );
|
||||
|
||||
mMapViewer.setAddressLocation( view.getGeoPosition() );
|
||||
mMapViewer.setZoom( view.getZoom() );
|
||||
/**
|
||||
* Defines how many threads will be used to fetch the background map
|
||||
* tiles (graphics)
|
||||
*/
|
||||
tileFactory.setThreadPoolSize(8);
|
||||
|
||||
/**
|
||||
* Set initial location and zoom for the map upon display
|
||||
*/
|
||||
GeoPosition syracuse = new GeoPosition(43.048, -76.147);
|
||||
int zoom = 7;
|
||||
|
||||
MapViewSetting view = mSettingsManager.getMapViewSetting("Default", syracuse, zoom);
|
||||
|
||||
mMapViewer.setAddressLocation(view.getGeoPosition());
|
||||
mMapViewer.setZoom(view.getZoom());
|
||||
|
||||
/**
|
||||
* Add a mouse adapter for panning and scrolling
|
||||
*/
|
||||
MapMouseListener listener = new MapMouseListener(mMapViewer, mSettingsManager);
|
||||
mMapViewer.addMouseListener(listener);
|
||||
mMapViewer.addMouseMotionListener(listener);
|
||||
|
||||
/**
|
||||
* Add a mouse adapter for panning and scrolling
|
||||
*/
|
||||
MapMouseListener listener =
|
||||
new MapMouseListener( mMapViewer, mSettingsManager );
|
||||
mMapViewer.addMouseListener( listener );
|
||||
mMapViewer.addMouseMotionListener( listener );
|
||||
|
||||
/* Map zoom listener */
|
||||
mMapViewer.addMouseWheelListener(
|
||||
new ZoomMouseWheelListenerCursor( mMapViewer ) );
|
||||
mMapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCursor(mMapViewer));
|
||||
|
||||
/* Keyboard panning listener */
|
||||
mMapViewer.addKeyListener( new PanKeyListener( mMapViewer ) );
|
||||
mMapViewer.addKeyListener(new PanKeyListener(mMapViewer));
|
||||
|
||||
/**
|
||||
* Add a selection listener
|
||||
*/
|
||||
SelectionAdapter sa = new SelectionAdapter( mMapViewer );
|
||||
mMapViewer.addMouseListener( sa );
|
||||
mMapViewer.addMouseMotionListener( sa );
|
||||
/**
|
||||
* Add a selection listener
|
||||
*/
|
||||
SelectionAdapter sa = new SelectionAdapter(mMapViewer);
|
||||
mMapViewer.addMouseListener(sa);
|
||||
mMapViewer.addMouseMotionListener(sa);
|
||||
|
||||
/**
|
||||
* Map component
|
||||
*/
|
||||
add( mMapViewer, "span" );
|
||||
/**
|
||||
* Map component
|
||||
*/
|
||||
add(mMapViewer, "span");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void entitiesUpdated()
|
||||
{
|
||||
EventQueue.invokeLater( new Runnable()
|
||||
{
|
||||
@Override
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mMapViewer.repaint();
|
||||
mMapViewer.repaint();
|
||||
}
|
||||
} );
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlottableEntity( PlottableEntity entity )
|
||||
@Override
|
||||
public void addPlottableEntity(PlottableEntity entity)
|
||||
{
|
||||
mMapPainter.addEntity( entity );
|
||||
|
||||
entitiesUpdated();
|
||||
mMapPainter.addEntity(entity);
|
||||
|
||||
entitiesUpdated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlottableEntity( PlottableEntity entity )
|
||||
@Override
|
||||
public void removePlottableEntity(PlottableEntity entity)
|
||||
{
|
||||
mMapPainter.removeEntity( entity );
|
||||
|
||||
entitiesUpdated();
|
||||
mMapPainter.removeEntity(entity);
|
||||
|
||||
entitiesUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package map;
|
||||
|
||||
import java.awt.Color;
|
||||
import alias.Alias;
|
||||
import controller.NamingThreadFactory;
|
||||
import icon.IconManager;
|
||||
import message.Message;
|
||||
import sample.Listener;
|
||||
import settings.SettingsManager;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -25,159 +33,144 @@ import java.util.Set;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import message.Message;
|
||||
import sample.Listener;
|
||||
import settings.SettingsManager;
|
||||
import alias.Alias;
|
||||
import controller.NamingThreadFactory;
|
||||
|
||||
public class MapService implements Listener<Message>
|
||||
{
|
||||
private int mMaxHistory = 2;
|
||||
private int mCullThresholdMinutes = 60;
|
||||
|
||||
private static final Color sDEFAULT_COLOR = Color.BLACK;
|
||||
|
||||
private final ScheduledExecutorService scheduler =
|
||||
Executors.newScheduledThreadPool(1,
|
||||
new NamingThreadFactory( "map tile fetcher" ) );
|
||||
|
||||
private ArrayList<PlottableUpdateListener> mListeners =
|
||||
new ArrayList<PlottableUpdateListener>();
|
||||
private int mMaxHistory = 2;
|
||||
private int mCullThresholdMinutes = 60;
|
||||
|
||||
private HashMap<String,PlottableEntity> mEntities =
|
||||
new HashMap<String,PlottableEntity>();
|
||||
private static final Color sDEFAULT_COLOR = Color.BLACK;
|
||||
|
||||
private SettingsManager mSettingsManager;
|
||||
|
||||
public MapService( SettingsManager resourceManager )
|
||||
{
|
||||
mSettingsManager = resourceManager;
|
||||
|
||||
// scheduler.scheduleAtFixedRate( new CullThread(), 5, 5, TimeUnit.MINUTES );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the max plottables (locations) history setting that is applied
|
||||
* to all plottable entities
|
||||
*/
|
||||
public int getMaxHistory()
|
||||
{
|
||||
return mMaxHistory;
|
||||
}
|
||||
private final ScheduledExecutorService scheduler =
|
||||
Executors.newScheduledThreadPool(1,
|
||||
new NamingThreadFactory("map tile fetcher"));
|
||||
|
||||
/**
|
||||
* Sets the max history trail for entities. Value is applied to all newly
|
||||
* created PlottableEntity and all existing entities.
|
||||
*/
|
||||
public void setMaxHistory( int maxHistory )
|
||||
{
|
||||
mMaxHistory = maxHistory;
|
||||
private ArrayList<PlottableUpdateListener> mListeners =
|
||||
new ArrayList<PlottableUpdateListener>();
|
||||
|
||||
/**
|
||||
* Update any existing entities with the new max history value
|
||||
*/
|
||||
for( PlottableEntity entity: mEntities.values() )
|
||||
{
|
||||
entity.setMaxHistory( mMaxHistory );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( Message message )
|
||||
private HashMap<String, PlottableEntity> mEntities =
|
||||
new HashMap<String, PlottableEntity>();
|
||||
|
||||
private IconManager mIconManager;
|
||||
|
||||
public MapService(IconManager resourceManager)
|
||||
{
|
||||
Plottable plottable = message.getPlottable();
|
||||
|
||||
if( plottable != null )
|
||||
{
|
||||
PlottableEntity entity = mEntities.get( plottable.getID() );
|
||||
|
||||
if( entity == null )
|
||||
{
|
||||
Alias alias = plottable.getAlias();
|
||||
mIconManager = resourceManager;
|
||||
|
||||
Color color = null;
|
||||
MapIcon icon = null;
|
||||
|
||||
if( alias != null )
|
||||
{
|
||||
color = alias.getMapColor();
|
||||
|
||||
String iconName = alias.getIconName();
|
||||
|
||||
if( iconName == null )
|
||||
{
|
||||
iconName = SettingsManager.DEFAULT_ICON;
|
||||
}
|
||||
|
||||
icon = mSettingsManager.getMapIcon( iconName );
|
||||
}
|
||||
|
||||
if( color == null )
|
||||
{
|
||||
color = sDEFAULT_COLOR;
|
||||
}
|
||||
|
||||
entity = new PlottableEntity( plottable, color );
|
||||
|
||||
entity.setMaxHistory( mMaxHistory );
|
||||
|
||||
mEntities.put( plottable.getID(), entity );
|
||||
|
||||
for( PlottableUpdateListener listener: mListeners )
|
||||
{
|
||||
listener.addPlottableEntity( entity );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.addPlottable( plottable );
|
||||
|
||||
for( PlottableUpdateListener listener: mListeners )
|
||||
{
|
||||
listener.entitiesUpdated();;
|
||||
}
|
||||
}
|
||||
}
|
||||
// scheduler.scheduleAtFixedRate( new CullThread(), 5, 5, TimeUnit.MINUTES );
|
||||
}
|
||||
|
||||
public void addListener( PlottableUpdateListener listener )
|
||||
{
|
||||
mListeners.add( listener );
|
||||
}
|
||||
|
||||
public void removeListener( PlottableUpdateListener listener )
|
||||
{
|
||||
mListeners.remove( listener );
|
||||
}
|
||||
|
||||
public class CullThread implements Runnable
|
||||
{
|
||||
@Override
|
||||
|
||||
/**
|
||||
* Returns the max plottables (locations) history setting that is applied
|
||||
* to all plottable entities
|
||||
*/
|
||||
public int getMaxHistory()
|
||||
{
|
||||
return mMaxHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the max history trail for entities. Value is applied to all newly
|
||||
* created PlottableEntity and all existing entities.
|
||||
*/
|
||||
public void setMaxHistory(int maxHistory)
|
||||
{
|
||||
mMaxHistory = maxHistory;
|
||||
|
||||
/**
|
||||
* Update any existing entities with the new max history value
|
||||
*/
|
||||
for(PlottableEntity entity : mEntities.values())
|
||||
{
|
||||
entity.setMaxHistory(mMaxHistory);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(Message message)
|
||||
{
|
||||
Plottable plottable = message.getPlottable();
|
||||
|
||||
if(plottable != null)
|
||||
{
|
||||
PlottableEntity entity = mEntities.get(plottable.getID());
|
||||
|
||||
if(entity == null)
|
||||
{
|
||||
Alias alias = plottable.getAlias();
|
||||
|
||||
Color color = null;
|
||||
|
||||
if(alias != null)
|
||||
{
|
||||
color = alias.getMapColor();
|
||||
}
|
||||
|
||||
if(color == null)
|
||||
{
|
||||
color = sDEFAULT_COLOR;
|
||||
}
|
||||
|
||||
entity = new PlottableEntity(plottable, color);
|
||||
|
||||
entity.setMaxHistory(mMaxHistory);
|
||||
|
||||
mEntities.put(plottable.getID(), entity);
|
||||
|
||||
for(PlottableUpdateListener listener : mListeners)
|
||||
{
|
||||
listener.addPlottableEntity(entity);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.addPlottable(plottable);
|
||||
|
||||
for(PlottableUpdateListener listener : mListeners)
|
||||
{
|
||||
listener.entitiesUpdated();
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(PlottableUpdateListener listener)
|
||||
{
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(PlottableUpdateListener listener)
|
||||
{
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
public class CullThread implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
long cutoffTime = System.currentTimeMillis() -
|
||||
( mCullThresholdMinutes * 1000 );
|
||||
long cutoffTime = System.currentTimeMillis() -
|
||||
(mCullThresholdMinutes * 1000);
|
||||
|
||||
Set<String> ids = Collections.unmodifiableSet( mEntities.keySet() );
|
||||
Set<String> ids = Collections.unmodifiableSet(mEntities.keySet());
|
||||
|
||||
for( String id: ids )
|
||||
{
|
||||
PlottableEntity entity = mEntities.get( id );
|
||||
|
||||
if( entity.getCurrentPlottable().getTimestamp() < cutoffTime )
|
||||
{
|
||||
mEntities.remove( id );
|
||||
for(String id : ids)
|
||||
{
|
||||
PlottableEntity entity = mEntities.get(id);
|
||||
|
||||
/**
|
||||
* Let all listeners know we've removed (culled) an entity
|
||||
*/
|
||||
for( PlottableUpdateListener listener: mListeners )
|
||||
{
|
||||
listener.removePlottableEntity( entity );
|
||||
}
|
||||
}
|
||||
}
|
||||
if(entity.getCurrentPlottable().getTimestamp() < cutoffTime)
|
||||
{
|
||||
mEntities.remove(id);
|
||||
|
||||
/**
|
||||
* Let all listeners know we've removed (culled) an entity
|
||||
*/
|
||||
for(PlottableUpdateListener listener : mListeners)
|
||||
{
|
||||
listener.removePlottableEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +1,79 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package map;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import icon.IconManager;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.painter.AbstractPainter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.painter.AbstractPainter;
|
||||
|
||||
import settings.SettingsManager;
|
||||
|
||||
public class PlottableEntityPainter extends AbstractPainter<JXMapViewer>
|
||||
{
|
||||
private PlottableEntityRenderer mRenderer;
|
||||
private Set<PlottableEntity> mEntities = new HashSet<PlottableEntity>();
|
||||
private PlottableEntityRenderer mRenderer;
|
||||
private Set<PlottableEntity> mEntities = new HashSet<PlottableEntity>();
|
||||
|
||||
public PlottableEntityPainter( SettingsManager settingsManager )
|
||||
{
|
||||
mRenderer = new PlottableEntityRenderer( settingsManager );
|
||||
setAntialiasing( true );
|
||||
setCacheable( false );
|
||||
}
|
||||
public PlottableEntityPainter(IconManager iconManager)
|
||||
{
|
||||
mRenderer = new PlottableEntityRenderer(iconManager);
|
||||
setAntialiasing(true);
|
||||
setCacheable(false);
|
||||
}
|
||||
|
||||
public void addEntity( PlottableEntity entity )
|
||||
{
|
||||
mEntities.add( entity );
|
||||
}
|
||||
|
||||
public void removeEntity( PlottableEntity entity )
|
||||
{
|
||||
mEntities.remove( entity );
|
||||
}
|
||||
|
||||
public void clearEntities()
|
||||
{
|
||||
mEntities.clear();
|
||||
}
|
||||
|
||||
private Set<PlottableEntity> getEntities()
|
||||
{
|
||||
return Collections.unmodifiableSet( mEntities );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPaint(Graphics2D g, JXMapViewer map, int width, int height)
|
||||
{
|
||||
Rectangle viewportBounds = map.getViewportBounds();
|
||||
public void addEntity(PlottableEntity entity)
|
||||
{
|
||||
mEntities.add(entity);
|
||||
}
|
||||
|
||||
g.translate( -viewportBounds.getX(), -viewportBounds.getY() );
|
||||
public void removeEntity(PlottableEntity entity)
|
||||
{
|
||||
mEntities.remove(entity);
|
||||
}
|
||||
|
||||
Set<PlottableEntity> entities = getEntities();
|
||||
|
||||
for (PlottableEntity entity: entities )
|
||||
{
|
||||
mRenderer.paintPlottableEntity( g, map, entity, true );
|
||||
}
|
||||
public void clearEntities()
|
||||
{
|
||||
mEntities.clear();
|
||||
}
|
||||
|
||||
g.translate( viewportBounds.getX(), viewportBounds.getY() );
|
||||
}
|
||||
private Set<PlottableEntity> getEntities()
|
||||
{
|
||||
return Collections.unmodifiableSet(mEntities);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPaint(Graphics2D g, JXMapViewer map, int width, int height)
|
||||
{
|
||||
Rectangle viewportBounds = map.getViewportBounds();
|
||||
|
||||
g.translate(-viewportBounds.getX(), -viewportBounds.getY());
|
||||
|
||||
Set<PlottableEntity> entities = getEntities();
|
||||
|
||||
for(PlottableEntity entity : entities)
|
||||
{
|
||||
mRenderer.paintPlottableEntity(g, map, entity, true);
|
||||
}
|
||||
|
||||
g.translate(viewportBounds.getX(), viewportBounds.getY());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,169 +1,162 @@
|
||||
/*******************************************************************************
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package map;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import icon.IconManager;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
|
||||
import settings.SettingsManager;
|
||||
|
||||
public class PlottableEntityRenderer
|
||||
{
|
||||
private SettingsManager mSettingsManager;
|
||||
private IconManager mIconManager;
|
||||
|
||||
public PlottableEntityRenderer( SettingsManager settingsManager )
|
||||
{
|
||||
mSettingsManager = settingsManager;
|
||||
}
|
||||
public PlottableEntityRenderer(IconManager iconManager)
|
||||
{
|
||||
mIconManager = iconManager;
|
||||
}
|
||||
|
||||
public void paintPlottableEntity( Graphics2D g,
|
||||
JXMapViewer viewer,
|
||||
PlottableEntity entity,
|
||||
boolean antiAliasing )
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D)g.create();
|
||||
public void paintPlottableEntity(Graphics2D g, JXMapViewer viewer, PlottableEntity entity, boolean antiAliasing)
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) g.create();
|
||||
|
||||
if( antiAliasing )
|
||||
{
|
||||
graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON );
|
||||
}
|
||||
if(antiAliasing)
|
||||
{
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the entity's preferred color for lines and labels
|
||||
*/
|
||||
graphics.setColor( entity.getColor() );
|
||||
/**
|
||||
* Use the entity's preferred color for lines and labels
|
||||
*/
|
||||
graphics.setColor(entity.getColor());
|
||||
|
||||
/**
|
||||
* Convert the lat/long geoposition to an x/y point on the viewer
|
||||
*/
|
||||
Point2D point = viewer.getTileFactory().geoToPixel(
|
||||
entity.getCurrentGeoPosition(), viewer.getZoom() );
|
||||
/**
|
||||
* Convert the lat/long geoposition to an x/y point on the viewer
|
||||
*/
|
||||
Point2D point = viewer.getTileFactory().geoToPixel(
|
||||
entity.getCurrentGeoPosition(), viewer.getZoom());
|
||||
|
||||
/**
|
||||
* Paint the route first, so the icon and label overlay it
|
||||
*/
|
||||
paintRoute( graphics, viewer, entity );
|
||||
/**
|
||||
* Paint the route first, so the icon and label overlay it
|
||||
*/
|
||||
paintRoute(graphics, viewer, entity);
|
||||
|
||||
/**
|
||||
* Paint the icon at the current location
|
||||
*/
|
||||
ImageIcon icon = getIcon( entity ).getImageIcon();
|
||||
|
||||
paintIcon( graphics, point, icon );
|
||||
/**
|
||||
* Paint the icon at the current location
|
||||
*/
|
||||
ImageIcon icon = getIcon(entity);
|
||||
|
||||
/**
|
||||
* Paint the label offset to the right of the icon
|
||||
*/
|
||||
paintLabel( graphics, point, entity, (int)( icon.getIconWidth() / 2 ), 0 );
|
||||
paintIcon(graphics, point, icon);
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*/
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
private MapIcon getIcon( PlottableEntity entity )
|
||||
{
|
||||
return mSettingsManager.getMapIcon( entity.getMapIconName() );
|
||||
}
|
||||
|
||||
private void paintIcon( Graphics2D graphics,
|
||||
Point2D point,
|
||||
ImageIcon icon )
|
||||
{
|
||||
graphics.drawImage( icon.getImage(),
|
||||
(int)point.getX() - ( icon.getIconWidth() / 2 ),
|
||||
(int)point.getY() - ( icon.getIconHeight() / 2 ),
|
||||
null );
|
||||
|
||||
}
|
||||
|
||||
private void paintLabel( Graphics2D graphics,
|
||||
Point2D point,
|
||||
PlottableEntity entity,
|
||||
int xOffset,
|
||||
int yOffset )
|
||||
{
|
||||
graphics.drawString( entity.getLabel(),
|
||||
(int)point.getX() + xOffset,
|
||||
(int)point.getY() + yOffset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a two-tone route from the entity's list of plottables (locations).
|
||||
* using black as a wider background route, and the entity's preferred color
|
||||
* as a narrower foreground route.
|
||||
*/
|
||||
private void paintRoute( Graphics2D graphics,
|
||||
JXMapViewer viewer,
|
||||
PlottableEntity entity )
|
||||
{
|
||||
Set<Plottable> plottables = entity.getPlottables();
|
||||
|
||||
if( plottables.size() > 1 )
|
||||
{
|
||||
// Draw the route with a black background line
|
||||
graphics.setColor( Color.BLACK );
|
||||
graphics.setStroke( new BasicStroke( 3 ) );
|
||||
/**
|
||||
* Paint the label offset to the right of the icon
|
||||
*/
|
||||
paintLabel(graphics, point, entity, (int) (icon.getIconWidth() / 2), 0);
|
||||
|
||||
drawRoute( plottables, graphics, viewer );
|
||||
/**
|
||||
* Cleanup
|
||||
*/
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
// Draw the route again, in the entity's preferred color
|
||||
graphics.setColor( entity.getColor() );
|
||||
graphics.setStroke( new BasicStroke( 1 ) );
|
||||
private ImageIcon getIcon(PlottableEntity entity)
|
||||
{
|
||||
return mIconManager.getIcon(entity.getMapIconName(), IconManager.DEFAULT_ICON_SIZE);
|
||||
}
|
||||
|
||||
drawRoute( plottables, graphics, viewer );
|
||||
}
|
||||
}
|
||||
private void paintIcon(Graphics2D graphics,
|
||||
Point2D point,
|
||||
ImageIcon icon)
|
||||
{
|
||||
graphics.drawImage(icon.getImage(),
|
||||
(int) point.getX() - (icon.getIconWidth() / 2),
|
||||
(int) point.getY() - (icon.getIconHeight() / 2),
|
||||
null);
|
||||
|
||||
/**
|
||||
* Draws a route from a list of plottables
|
||||
*/
|
||||
private void drawRoute( Set<Plottable> plottables,
|
||||
Graphics2D g,
|
||||
JXMapViewer viewer )
|
||||
{
|
||||
Point2D lastPoint = null;
|
||||
}
|
||||
|
||||
for (Plottable plottable: plottables )
|
||||
{
|
||||
// convert geo-coordinate to world bitmap pixel
|
||||
Point2D currentPoint = viewer.getTileFactory()
|
||||
.geoToPixel( plottable.getGeoPosition(), viewer.getZoom() );
|
||||
private void paintLabel(Graphics2D graphics,
|
||||
Point2D point,
|
||||
PlottableEntity entity,
|
||||
int xOffset,
|
||||
int yOffset)
|
||||
{
|
||||
graphics.drawString(entity.getLabel(),
|
||||
(int) point.getX() + xOffset,
|
||||
(int) point.getY() + yOffset);
|
||||
}
|
||||
|
||||
if( lastPoint != null )
|
||||
{
|
||||
g.drawLine( (int)lastPoint.getX(), (int)lastPoint.getY(),
|
||||
(int)currentPoint.getX(), (int)currentPoint.getY() );
|
||||
}
|
||||
|
||||
lastPoint = currentPoint;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Paints a two-tone route from the entity's list of plottables (locations).
|
||||
* using black as a wider background route, and the entity's preferred color
|
||||
* as a narrower foreground route.
|
||||
*/
|
||||
private void paintRoute(Graphics2D graphics,
|
||||
JXMapViewer viewer,
|
||||
PlottableEntity entity)
|
||||
{
|
||||
Set<Plottable> plottables = entity.getPlottables();
|
||||
|
||||
if(plottables.size() > 1)
|
||||
{
|
||||
// Draw the route with a black background line
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.setStroke(new BasicStroke(3));
|
||||
|
||||
drawRoute(plottables, graphics, viewer);
|
||||
|
||||
// Draw the route again, in the entity's preferred color
|
||||
graphics.setColor(entity.getColor());
|
||||
graphics.setStroke(new BasicStroke(1));
|
||||
|
||||
drawRoute(plottables, graphics, viewer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a route from a list of plottables
|
||||
*/
|
||||
private void drawRoute(Set<Plottable> plottables,
|
||||
Graphics2D g,
|
||||
JXMapViewer viewer)
|
||||
{
|
||||
Point2D lastPoint = null;
|
||||
|
||||
for(Plottable plottable : plottables)
|
||||
{
|
||||
// convert geo-coordinate to world bitmap pixel
|
||||
Point2D currentPoint = viewer.getTileFactory()
|
||||
.geoToPixel(plottable.getGeoPosition(), viewer.getZoom());
|
||||
|
||||
if(lastPoint != null)
|
||||
{
|
||||
g.drawLine((int) lastPoint.getX(), (int) lastPoint.getY(),
|
||||
(int) currentPoint.getX(), (int) currentPoint.getY());
|
||||
}
|
||||
|
||||
lastPoint = currentPoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user