mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Updates pull request from Roman Tsypuk to convert the build system from
ant to gradle. Removes linux and windows application launch scripts and produces an executable jar with all resources included.
This commit is contained in:
36
src/main/java/io/github/dsheirer/map/DefaultIcon.java
Normal file
36
src/main/java/io/github/dsheirer/map/DefaultIcon.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.settings.Setting;
|
||||
|
||||
public class DefaultIcon extends Setting
|
||||
{
|
||||
public DefaultIcon( String name )
|
||||
{
|
||||
super( name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't use this constructor. This is used by JAXB to unmarshall saved
|
||||
* map icons.
|
||||
*/
|
||||
public DefaultIcon()
|
||||
{
|
||||
}
|
||||
}
|
||||
187
src/main/java/io/github/dsheirer/map/MapIcon.java
Normal file
187
src/main/java/io/github/dsheirer/map/MapIcon.java
Normal file
@@ -0,0 +1,187 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.settings.Setting;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import java.awt.*;
|
||||
|
||||
public class MapIcon extends Setting implements Comparable<MapIcon>
|
||||
{
|
||||
private static final int sMAX_IMAGE_DIMENSION = 48;
|
||||
private String mPath;
|
||||
private ImageIcon mImageIcon;
|
||||
|
||||
/**
|
||||
* Only map icons created at runtime can be marked as non-editable, and
|
||||
* therefore this property is transient.
|
||||
*/
|
||||
@XmlTransient
|
||||
private boolean mEditable;
|
||||
|
||||
@XmlTransient
|
||||
private boolean mDefaultIcon;
|
||||
|
||||
/**
|
||||
* Wrapper class for a map icon.
|
||||
* @param name - name of the icon - also used as key to lookup the icon
|
||||
* @param path - file path to the icon
|
||||
* @param editable - defines if the map icon or details can be edited
|
||||
*
|
||||
* Note: the default icons are constructed with editable = false, so that
|
||||
* they cannot be deleted from the Icon Manager editor window
|
||||
*/
|
||||
public MapIcon( String name, String path, boolean editable )
|
||||
{
|
||||
super( name );
|
||||
mPath = path;
|
||||
mEditable = editable;
|
||||
}
|
||||
|
||||
public MapIcon( String name, String path )
|
||||
{
|
||||
this( name, path, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't use this constructor. This is used by JAXB to unmarshall saved
|
||||
* map icons.
|
||||
*/
|
||||
public MapIcon()
|
||||
{
|
||||
mEditable = true;
|
||||
}
|
||||
|
||||
|
||||
@XmlAttribute( name="editable" )
|
||||
public boolean isEditable()
|
||||
{
|
||||
return mEditable;
|
||||
}
|
||||
|
||||
@XmlAttribute( name="default" )
|
||||
public boolean isDefaultIcon()
|
||||
{
|
||||
return mDefaultIcon;
|
||||
}
|
||||
|
||||
public void setDefaultIcon( boolean isDefault )
|
||||
{
|
||||
mDefaultIcon = isDefault;
|
||||
}
|
||||
|
||||
public ImageIcon getImageIcon()
|
||||
{
|
||||
if( mImageIcon == null )
|
||||
{
|
||||
mImageIcon = new ImageIcon( mPath );
|
||||
|
||||
/**
|
||||
* If the image is too big, scale it down to max pixel size squared
|
||||
*/
|
||||
if( mImageIcon.getIconWidth() > sMAX_IMAGE_DIMENSION ||
|
||||
mImageIcon.getIconHeight() > sMAX_IMAGE_DIMENSION )
|
||||
{
|
||||
/**
|
||||
* getScaled instance will correct any negative value to the
|
||||
* correct value, maintaining original aspect ratio. So, we
|
||||
* only scale the larger value, and allow the image class to
|
||||
* determine the correct value for the other measurement
|
||||
*/
|
||||
int height = -1;
|
||||
int width = -1;
|
||||
|
||||
/**
|
||||
* Use the larger width or height value to determine the
|
||||
* scaling factor
|
||||
*/
|
||||
if( mImageIcon.getIconHeight() > mImageIcon.getIconWidth() )
|
||||
{
|
||||
height = sMAX_IMAGE_DIMENSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = sMAX_IMAGE_DIMENSION;
|
||||
}
|
||||
|
||||
mImageIcon = new ImageIcon( mImageIcon.getImage()
|
||||
.getScaledInstance( width, height, Image.SCALE_SMOOTH ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return mImageIcon;
|
||||
}
|
||||
|
||||
@XmlAttribute( name="path" )
|
||||
public String getPath()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
public void setPath( String path )
|
||||
{
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
if( mDefaultIcon )
|
||||
{
|
||||
return getName() + " (default)";
|
||||
}
|
||||
else
|
||||
{
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if( obj instanceof MapIcon )
|
||||
{
|
||||
MapIcon other = (MapIcon)obj;
|
||||
|
||||
return other.getName().contentEquals( getName() ) &&
|
||||
other.getPath().contentEquals( getPath() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return getName().hashCode() + getPath().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort order is determined by the icon name
|
||||
*/
|
||||
@Override
|
||||
public int compareTo( MapIcon other )
|
||||
{
|
||||
return getName().compareTo( other.getName() );
|
||||
}
|
||||
}
|
||||
173
src/main/java/io/github/dsheirer/map/MapMouseListener.java
Normal file
173
src/main/java/io/github/dsheirer/map/MapMouseListener.java
Normal file
@@ -0,0 +1,173 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class MapMouseListener extends MouseInputAdapter implements MouseWheelListener
|
||||
{
|
||||
private JXMapViewer mJXMapViewer;
|
||||
private SettingsManager mSettingsManager;
|
||||
private Point mPreviousPoint;
|
||||
private Point mCurrentPoint;
|
||||
|
||||
public MapMouseListener( JXMapViewer viewer, SettingsManager settingsManager )
|
||||
{
|
||||
mJXMapViewer = viewer;
|
||||
mSettingsManager = settingsManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged( MouseEvent event )
|
||||
{
|
||||
if ( !SwingUtilities.isLeftMouseButton( event ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Point current = event.getPoint();
|
||||
|
||||
double x = mJXMapViewer.getCenter().getX() -
|
||||
( current.getX() - mPreviousPoint.getX() );
|
||||
|
||||
double y = mJXMapViewer.getCenter().getY() -
|
||||
(current.getY() - mPreviousPoint.getY() );
|
||||
|
||||
if ( !mJXMapViewer.isNegativeYAllowed() )
|
||||
{
|
||||
if ( y < 0 )
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int maxHeight = (int)( mJXMapViewer.getTileFactory()
|
||||
.getMapSize( mJXMapViewer.getZoom() ).getHeight() *
|
||||
mJXMapViewer.getTileFactory()
|
||||
.getTileSize( mJXMapViewer.getZoom() ) );
|
||||
|
||||
if (y > maxHeight)
|
||||
{
|
||||
y = maxHeight;
|
||||
}
|
||||
|
||||
mPreviousPoint = current;
|
||||
|
||||
mJXMapViewer.setCenter( new Point2D.Double( x, y ) );
|
||||
|
||||
mJXMapViewer.repaint();
|
||||
|
||||
/* Set cursor to dragging */
|
||||
mJXMapViewer.setCursor( Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased( MouseEvent event )
|
||||
{
|
||||
if ( !SwingUtilities.isLeftMouseButton( event ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mPreviousPoint = null;
|
||||
|
||||
/* Reset the curson */
|
||||
mJXMapViewer.setCursor(
|
||||
Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered( MouseEvent event )
|
||||
{
|
||||
SwingUtilities.invokeLater( new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mJXMapViewer.requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed( MouseEvent event )
|
||||
{
|
||||
mCurrentPoint = event.getPoint();
|
||||
mPreviousPoint = event.getPoint();
|
||||
|
||||
boolean left = SwingUtilities.isLeftMouseButton( event );
|
||||
|
||||
boolean middle = SwingUtilities.isMiddleMouseButton( event );
|
||||
|
||||
boolean right = SwingUtilities.isRightMouseButton( event );
|
||||
|
||||
boolean doubleClick = ( event.getClickCount() == 2 );
|
||||
|
||||
if (middle || ( left && doubleClick ) )
|
||||
{
|
||||
recenterMap( event );
|
||||
}
|
||||
else if( right )
|
||||
{
|
||||
JPopupMenu popup = new JPopupMenu();
|
||||
|
||||
JMenuItem mapViewItem = new JMenuItem( "Set Default Location & Zoom" );
|
||||
mapViewItem.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent arg0 )
|
||||
{
|
||||
GeoPosition position = mJXMapViewer
|
||||
.convertPointToGeoPosition( mCurrentPoint );
|
||||
|
||||
mSettingsManager.setMapViewSetting( "Default", position,
|
||||
mJXMapViewer.getZoom() );
|
||||
}
|
||||
} );
|
||||
popup.add( mapViewItem );
|
||||
|
||||
popup.show( mJXMapViewer, event.getX(), event.getY() );
|
||||
}
|
||||
}
|
||||
|
||||
private void recenterMap( MouseEvent event )
|
||||
{
|
||||
Rectangle bounds = mJXMapViewer.getViewportBounds();
|
||||
|
||||
double x = bounds.getX() + event.getX();
|
||||
|
||||
double y = bounds.getY() + event.getY();
|
||||
|
||||
mJXMapViewer.setCenter( new Point2D.Double( x, y ) );
|
||||
|
||||
mJXMapViewer.setZoom( mJXMapViewer.getZoom() - 1 );
|
||||
|
||||
mJXMapViewer.repaint();
|
||||
}
|
||||
}
|
||||
143
src/main/java/io/github/dsheirer/map/MapPanel.java
Normal file
143
src/main/java/io/github/dsheirer/map/MapPanel.java
Normal file
@@ -0,0 +1,143 @@
|
||||
/*******************************************************************************
|
||||
* 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 io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.icon.IconManager;
|
||||
import io.github.dsheirer.settings.MapViewSetting;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.OSMTileFactoryInfo;
|
||||
import org.jdesktop.swingx.input.PanKeyListener;
|
||||
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 javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MapPanel extends JPanel implements PlottableUpdateListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SettingsManager mSettingsManager;
|
||||
private MapService mMapService;
|
||||
private JXMapViewer mMapViewer = new JXMapViewer();
|
||||
private PlottableEntityPainter mMapPainter;
|
||||
|
||||
public MapPanel(MapService mapService, IconManager iconManager, SettingsManager settingsManager)
|
||||
{
|
||||
mSettingsManager = settingsManager;
|
||||
mMapService = mapService;
|
||||
mMapPainter = new PlottableEntityPainter(iconManager);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/* Map zoom listener */
|
||||
mMapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCursor(mMapViewer));
|
||||
|
||||
/* Keyboard panning listener */
|
||||
mMapViewer.addKeyListener(new PanKeyListener(mMapViewer));
|
||||
|
||||
/**
|
||||
* Add a selection listener
|
||||
*/
|
||||
SelectionAdapter sa = new SelectionAdapter(mMapViewer);
|
||||
mMapViewer.addMouseListener(sa);
|
||||
mMapViewer.addMouseMotionListener(sa);
|
||||
|
||||
/**
|
||||
* Map component
|
||||
*/
|
||||
add(mMapViewer, "span");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entitiesUpdated()
|
||||
{
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mMapViewer.repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlottableEntity(PlottableEntity entity)
|
||||
{
|
||||
mMapPainter.addEntity(entity);
|
||||
|
||||
entitiesUpdated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlottableEntity(PlottableEntity entity)
|
||||
{
|
||||
mMapPainter.removeEntity(entity);
|
||||
|
||||
entitiesUpdated();
|
||||
}
|
||||
}
|
||||
168
src/main/java/io/github/dsheirer/map/MapService.java
Normal file
168
src/main/java/io/github/dsheirer/map/MapService.java
Normal file
@@ -0,0 +1,168 @@
|
||||
/*******************************************************************************
|
||||
* 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 io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.icon.IconManager;
|
||||
import io.github.dsheirer.message.Message;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MapService implements Listener<Message>
|
||||
{
|
||||
private int mMaxHistory = 2;
|
||||
private int mCullThresholdMinutes = 60;
|
||||
|
||||
private static final Color sDEFAULT_COLOR = Color.BLACK;
|
||||
|
||||
private List<PlottableUpdateListener> mListeners = new ArrayList<PlottableUpdateListener>();
|
||||
|
||||
private HashMap<String, PlottableEntity> mEntities =
|
||||
new HashMap<String, PlottableEntity>();
|
||||
|
||||
private IconManager mIconManager;
|
||||
|
||||
public MapService(IconManager resourceManager)
|
||||
{
|
||||
mIconManager = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getDisplayColor();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Set<String> ids = Collections.unmodifiableSet(mEntities.keySet());
|
||||
|
||||
for(String id : ids)
|
||||
{
|
||||
PlottableEntity entity = mEntities.get(id);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
138
src/main/java/io/github/dsheirer/map/Plottable.java
Normal file
138
src/main/java/io/github/dsheirer/map/Plottable.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Plottable implements Comparable<Plottable>
|
||||
{
|
||||
private long mTimestamp;
|
||||
private GeoPosition mGeoPosition;
|
||||
private String mID;
|
||||
private Alias mAlias;
|
||||
|
||||
HashMap<String,String> mAttributes = new HashMap<String,String>();
|
||||
|
||||
public Plottable()
|
||||
{
|
||||
}
|
||||
|
||||
public Plottable( long timestamp,
|
||||
GeoPosition position,
|
||||
String id,
|
||||
Alias alias,
|
||||
HashMap<String,String> attributes )
|
||||
{
|
||||
this( timestamp, position, id, alias );
|
||||
mAttributes = attributes;
|
||||
}
|
||||
|
||||
public Plottable( long timestamp,
|
||||
GeoPosition position,
|
||||
String id,
|
||||
Alias alias )
|
||||
{
|
||||
mTimestamp = timestamp;
|
||||
mGeoPosition = position;
|
||||
mID = id;
|
||||
mAlias = alias;
|
||||
}
|
||||
|
||||
public long getTimestamp()
|
||||
{
|
||||
return mTimestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp( long timestamp )
|
||||
{
|
||||
mTimestamp = timestamp;
|
||||
}
|
||||
|
||||
public GeoPosition getGeoPosition()
|
||||
{
|
||||
return mGeoPosition;
|
||||
}
|
||||
|
||||
public void setGeoPosition( GeoPosition position )
|
||||
{
|
||||
mGeoPosition = position;
|
||||
}
|
||||
|
||||
public String getID()
|
||||
{
|
||||
return mID;
|
||||
}
|
||||
|
||||
public void setID( String id )
|
||||
{
|
||||
mID = id;
|
||||
}
|
||||
|
||||
public Alias getAlias()
|
||||
{
|
||||
return mAlias;
|
||||
}
|
||||
|
||||
public void setAlias( Alias alias )
|
||||
{
|
||||
mAlias = alias;
|
||||
}
|
||||
|
||||
public HashMap<String,String> getAttributes()
|
||||
{
|
||||
return mAttributes;
|
||||
}
|
||||
|
||||
public void addAttribute( String key, String value )
|
||||
{
|
||||
mAttributes.put( key, value );
|
||||
}
|
||||
|
||||
public void removeAttribute( String key )
|
||||
{
|
||||
mAttributes.remove( key );
|
||||
}
|
||||
|
||||
public void clearAttributes()
|
||||
{
|
||||
mAttributes.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparisons for sorting of plottables is based on timestamps
|
||||
*/
|
||||
@Override
|
||||
public int compareTo( Plottable o )
|
||||
{
|
||||
if( mTimestamp == o.mTimestamp )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if( mTimestamp < o.mTimestamp )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
170
src/main/java/io/github/dsheirer/map/PlottableEntity.java
Normal file
170
src/main/java/io/github/dsheirer/map/PlottableEntity.java
Normal file
@@ -0,0 +1,170 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class PlottableEntity implements Comparable<PlottableEntity>
|
||||
{
|
||||
private TreeSet<Plottable> mPlottables = new TreeSet<Plottable>();
|
||||
|
||||
private Alias mAlias;
|
||||
private Color mColor;
|
||||
private String mID;
|
||||
|
||||
private int mMaxHistory = 2;
|
||||
|
||||
/**
|
||||
* Constructs the entity using the group and alias from the plottable and
|
||||
* adds the plottable as the first plottable entry in the history
|
||||
*/
|
||||
public PlottableEntity( Plottable plottable, Color color )
|
||||
{
|
||||
addPlottable( plottable );
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
public int getMaxHistory()
|
||||
{
|
||||
return mMaxHistory;
|
||||
}
|
||||
|
||||
public void setMaxHistory( int maxHistory )
|
||||
{
|
||||
if( maxHistory >= 1 )
|
||||
{
|
||||
mMaxHistory = maxHistory;
|
||||
}
|
||||
}
|
||||
|
||||
public Plottable getCurrentPlottable()
|
||||
{
|
||||
return mPlottables.last();
|
||||
}
|
||||
|
||||
public GeoPosition getCurrentGeoPosition()
|
||||
{
|
||||
return getCurrentPlottable().getGeoPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the plottable to this entity
|
||||
*/
|
||||
public void addPlottable( Plottable plottable )
|
||||
{
|
||||
/**
|
||||
* Grab the entity settings from the latest plot
|
||||
*/
|
||||
mAlias = plottable.getAlias();
|
||||
mID = plottable.getID();
|
||||
|
||||
/**
|
||||
* Add the plottable to the list
|
||||
*/
|
||||
mPlottables.add( plottable );
|
||||
|
||||
while( mPlottables.size() > mMaxHistory )
|
||||
{
|
||||
mPlottables.remove( mPlottables.first() );
|
||||
}
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
if( mAlias == null )
|
||||
{
|
||||
return mID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mAlias.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public String getMapIconName()
|
||||
{
|
||||
if( mAlias != null )
|
||||
{
|
||||
return mAlias.getIconName();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Color for rendering this entity (label, route, etc.)
|
||||
*/
|
||||
public Color getColor()
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
|
||||
public void setColor( Color color )
|
||||
{
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default id to use in the label
|
||||
*/
|
||||
public String getID()
|
||||
{
|
||||
return mID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the alias for this entity
|
||||
*/
|
||||
public Alias getAlias()
|
||||
{
|
||||
return mAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable sorted (time order) list of plottables
|
||||
*/
|
||||
public Set<Plottable> getPlottables()
|
||||
{
|
||||
return Collections.unmodifiableSet( mPlottables );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all plottables from this entity
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
mPlottables.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares by alias name
|
||||
*/
|
||||
@Override
|
||||
public int compareTo( PlottableEntity o )
|
||||
{
|
||||
return this.getAlias().getName().compareTo( o.getAlias().getName() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
|
||||
/*******************************************************************************
|
||||
* 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 io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.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;
|
||||
|
||||
public class PlottableEntityPainter extends AbstractPainter<JXMapViewer>
|
||||
{
|
||||
private PlottableEntityRenderer mRenderer;
|
||||
private Set<PlottableEntity> mEntities = new HashSet<PlottableEntity>();
|
||||
|
||||
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();
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*******************************************************************************
|
||||
* 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 io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.icon.IconManager;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlottableEntityRenderer
|
||||
{
|
||||
private IconManager mIconManager;
|
||||
|
||||
public PlottableEntityRenderer(IconManager iconManager)
|
||||
{
|
||||
mIconManager = iconManager;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
paintIcon(graphics, point, icon);
|
||||
|
||||
/**
|
||||
* Paint the label offset to the right of the icon
|
||||
*/
|
||||
paintLabel(graphics, point, entity, (int) (icon.getIconWidth() / 2), 0);
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*/
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
private ImageIcon getIcon(PlottableEntity entity)
|
||||
{
|
||||
return mIconManager.getIcon(entity.getMapIconName(), IconManager.DEFAULT_ICON_SIZE);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
public interface PlottableUpdateListener
|
||||
{
|
||||
public void entitiesUpdated();
|
||||
|
||||
public void addPlottableEntity( PlottableEntity entity );
|
||||
|
||||
public void removePlottableEntity( PlottableEntity entity );
|
||||
}
|
||||
103
src/main/java/io/github/dsheirer/map/SelectionAdapter.java
Normal file
103
src/main/java/io/github/dsheirer/map/SelectionAdapter.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
/**
|
||||
* Creates a selection rectangle based on mouse input
|
||||
* Also triggers repaint events in the viewer
|
||||
* @author Martin Steiger
|
||||
*/
|
||||
public class SelectionAdapter extends MouseAdapter
|
||||
{
|
||||
private boolean dragging;
|
||||
private JXMapViewer viewer;
|
||||
|
||||
private Point2D startPos = new Point2D.Double();
|
||||
private Point2D endPos = new Point2D.Double();
|
||||
|
||||
/**
|
||||
* @param viewer the jxmapviewer
|
||||
*/
|
||||
public SelectionAdapter(JXMapViewer viewer)
|
||||
{
|
||||
this.viewer = viewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
if (e.getButton() != MouseEvent.BUTTON3)
|
||||
return;
|
||||
|
||||
startPos.setLocation(e.getX(), e.getY());
|
||||
endPos.setLocation(e.getX(), e.getY());
|
||||
|
||||
dragging = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e)
|
||||
{
|
||||
if (!dragging)
|
||||
return;
|
||||
|
||||
endPos.setLocation(e.getX(), e.getY());
|
||||
|
||||
viewer.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if (!dragging)
|
||||
return;
|
||||
|
||||
if (e.getButton() != MouseEvent.BUTTON3)
|
||||
return;
|
||||
|
||||
viewer.repaint();
|
||||
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the selection rectangle
|
||||
*/
|
||||
public Rectangle getRectangle()
|
||||
{
|
||||
if (dragging)
|
||||
{
|
||||
int x1 = (int) Math.min(startPos.getX(), endPos.getX());
|
||||
int y1 = (int) Math.min(startPos.getY(), endPos.getY());
|
||||
int x2 = (int) Math.max(startPos.getX(), endPos.getX());
|
||||
int y2 = (int) Math.max(startPos.getY(), endPos.getY());
|
||||
|
||||
return new Rectangle(x1, y1, x2-x1, y2-y1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
56
src/main/java/io/github/dsheirer/map/SelectionPainter.java
Normal file
56
src/main/java/io/github/dsheirer/map/SelectionPainter.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* 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/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import org.jdesktop.swingx.painter.Painter;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Paints a selection rectangle
|
||||
* @author Martin Steiger
|
||||
*/
|
||||
public class SelectionPainter implements Painter<Object>
|
||||
{
|
||||
private Color fillColor = new Color(128, 192, 255, 128);
|
||||
private Color frameColor = new Color(0, 0, 255, 128);
|
||||
|
||||
private SelectionAdapter adapter;
|
||||
|
||||
/**
|
||||
* @param adapter the selection adapter
|
||||
*/
|
||||
public SelectionPainter(SelectionAdapter adapter)
|
||||
{
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g, Object t, int width, int height)
|
||||
{
|
||||
Rectangle rc = adapter.getRectangle();
|
||||
|
||||
if (rc != null)
|
||||
{
|
||||
g.setColor(frameColor);
|
||||
g.draw(rc);
|
||||
g.setColor(fillColor);
|
||||
g.fill(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user