Package com.nnamo.view.custompanels
Class MapPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.nnamo.view.custompanels.MapPanel
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
Custom
JPanel
that displays an interactive map using
JXMapViewer
, supporting the rendering of stops, routes, and real-time
vehicle positions.- Author:
- Riccardo Finocchiaro, Samuele Lombardi
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the current route ID.Gets the current stop ID.org.jxmapviewer.viewer.GeoPosition
Gets the current stop position as aGeoPosition
.org.jxmapviewer.JXMapViewer
getMap()
Gets the underlyingJXMapViewer
instance used in this panel.Gets theStopPainter
instance used for rendering stops on the map.void
renderStops
(List<StopModel> stops) Renders the provided list ofStopModel
as waypoints on the map.void
renderStopsRoute
(List<StopModel> stops) Renders the provided list ofStopModel
as a route on the map, updating the route overlay and painter.void
renderVehiclePositions
(List<com.google.transit.realtime.GtfsRealtime.VehiclePosition> realtimePositions, List<StaticVehiclePosition> staticPositions) Renders the provided list ofGtfsRealtime.VehiclePosition
as real-time vehicle waypoints on the map.void
Repaints the map and all overlay painters, updating the display of stops, routes, and vehicle positions.void
Resets the map to its default state, clearing route overlays and restoring the stop view.void
setClickWaypointBehaviour
(WaypointBehaviour waypointBehaviour) Sets the behaviour for waypoint clicks, allowing custom actions when a waypoint is clicked.void
setCurrentRouteId
(String routeId) Sets the current route ID and updates the map view accordingly.void
setCurrentStop
(String stopId, org.jxmapviewer.viewer.GeoPosition position) Sets the current stop ID and position, updating both the ID and position attributes.void
setCurrentStopId
(String stopId) Sets the current stop ID and position, updating the map view accordingly.void
setCurrentStopPosition
(org.jxmapviewer.viewer.GeoPosition position) Sets the current stop position on the map.void
setLocalMapCache
(File cacheDir) Sets the local cache directory for the map tile factory, allowing offline tile storage.void
setMapPanelMapPosition
(org.jxmapviewer.viewer.GeoPosition geoPosition, int zoomLevel) Sets the map position and zoom level for the map panel.void
setZoom
(int zoomLevel) Sets the zoom level for the map and notifies the zoom behaviour if set.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
MapPanel
Creates aMapPanel
with an embeddedJXMapViewer
, initializing painters for stops, routes, and vehicle positions. Sets up the map tile factory, default position, zoom, and listeners for user interaction.- Throws:
IOException
- if there is an error initializing the map tile factory- See Also:
-
-
Method Details
-
setClickWaypointBehaviour
Sets the behaviour for waypoint clicks, allowing custom actions when a waypoint is clicked.- Parameters:
waypointBehaviour
- theWaypointBehaviour
to set
-
repaintView
public void repaintView()Repaints the map and all overlay painters, updating the display of stops, routes, and vehicle positions.- See Also:
-
resetAction
public void resetAction()Resets the map to its default state, clearing route overlays and restoring the stop view. Hides the reset button and resets the painter overlays.- See Also:
-
renderStops
Renders the provided list ofStopModel
as waypoints on the map. Updates the overlay painter and saves the stops for future resets.- Parameters:
stops
- the list of stops to display as waypoints- See Also:
-
renderStopsRoute
Renders the provided list ofStopModel
as a route on the map, updating the route overlay and painter.- Parameters:
stops
- the list of stops representing the route to display- See Also:
-
renderVehiclePositions
public void renderVehiclePositions(List<com.google.transit.realtime.GtfsRealtime.VehiclePosition> realtimePositions, List<StaticVehiclePosition> staticPositions) Renders the provided list ofGtfsRealtime.VehiclePosition
as real-time vehicle waypoints on the map.- Parameters:
realtimePositions
- the list of vehicle positions to displaystaticPositions
- the list of static vehicle positions to display if no- See Also:
-
getCurrentRouteId
Gets the current route ID.- Returns:
- the current route ID
-
getCurrentStopPosition
public org.jxmapviewer.viewer.GeoPosition getCurrentStopPosition()Gets the current stop position as aGeoPosition
.- Returns:
- the current stop position
-
setCurrentRouteId
Sets the current route ID and updates the map view accordingly.- Parameters:
routeId
- the ID of the current route
-
getCurrentStopId
Gets the current stop ID.- Returns:
- the current stop ID
-
setCurrentStopPosition
public void setCurrentStopPosition(org.jxmapviewer.viewer.GeoPosition position) Sets the current stop position on the map.- Parameters:
position
- theGeoPosition
of the current stop
-
setCurrentStopId
Sets the current stop ID and position, updating the map view accordingly.- Parameters:
stopId
- the ID of the current stop
-
setCurrentStop
Sets the current stop ID and position, updating both the ID and position attributes.- Parameters:
stopId
- the ID of the current stopposition
- theGeoPosition
of the current stop
-
getMap
public org.jxmapviewer.JXMapViewer getMap()Gets the underlyingJXMapViewer
instance used in this panel.- Returns:
- the JXMapViewer instance
-
getStopPainter
Gets theStopPainter
instance used for rendering stops on the map.- Returns:
- the StopPainter instance
-
setMapPanelMapPosition
public void setMapPanelMapPosition(org.jxmapviewer.viewer.GeoPosition geoPosition, int zoomLevel) Sets the map position and zoom level for the map panel.- Parameters:
geoPosition
- theGeoPosition
to set as the map centerzoomLevel
- the zoom level to set for the map
-
setZoom
public void setZoom(int zoomLevel) Sets the zoom level for the map and notifies the zoom behaviour if set.- Parameters:
zoomLevel
- the zoom level to set for the map
-
setLocalMapCache
Sets the local cache directory for the map tile factory, allowing offline tile storage.- Parameters:
cacheDir
- the directory to use for caching map tiles
-