Package nl.bebr.mapviewer.swing
Class JXMapViewer
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.jdesktop.swingx.JXPanel
-
- nl.bebr.mapviewer.swing.JXMapViewer
-
- All Implemented Interfaces:
ImageObserver,MenuContainer,DesignMode,Serializable,Accessible,Scrollable,nl.bebr.mapviewer.data.MapViewer<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>>
public class JXMapViewer extends org.jdesktop.swingx.JXPanel implements DesignMode, nl.bebr.mapviewer.data.MapViewer<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>>
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 aGeoPosition. 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 Also:
SLMapServerInfo, Serialized Form
-
-
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 Modifier and Type Field Description static intMAX_ZOOMstatic intMIN_ZOOMstatic StringZOOM-
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.beans.DesignMode
PROPERTYNAME
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description JXMapViewer()Create a new JXMapViewer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddNotify()Point2DconvertGeoPositionToPoint(nl.bebr.mapviewer.data.GeoPosition pos)nl.bebr.mapviewer.data.GeoPositionconvertPointToGeoPosition(Point2D pt)protected voiddisableZoom()protected voiddrawMapTiles(Graphics g, int zoom, Rectangle viewportBounds)Draw the map tiles.protected voidenableZoom()nl.bebr.mapviewer.data.GeoPositiongetAddressLocation()Gets the current address location of the map.Point2DgetCenter()Gets center of the map in pixel coordinatesnl.bebr.mapviewer.data.GeoPositiongetCenterPosition()Gets center position of the mapImagegetLoadingImage()A property for an image which will be display when an image is still loading.org.jdesktop.swingx.painter.Painter<JXMapViewer>getOverlayPainter()Gets the current map overlaynl.bebr.mapviewer.data.GeoPosition[]getScreenCoordinates()nl.bebr.mapviewer.data.TileFactory<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>>getTileFactory()RectanglegetViewportBounds()intgetZoom()protected voidinitInputListeners()booleanisDesignTime()Indicates whether the component is being used at design time, such as in a visual editor like NetBeans' MatissebooleanisDoubleClickZoomEnabled()booleanisRecenterOnClickEnabled()Indicates if the map should recenter itself on mouse clicks.booleanisTypeSelectionEnabled()booleanisZoomEnabled()voidmarkZoomArea(Point startPoint, Point endPoint)Paints zoom selection area rectanglevoidremoveNotify()voidsetAddressLocation(nl.bebr.mapviewer.data.GeoPosition addressLocation)SetGeoPositionaddress of the center of the mapvoidsetCenter(Point2D center)Sets the new center of the map in pixel coordinates.voidsetCenterPosition(nl.bebr.mapviewer.data.GeoPosition geoPosition)Sets center position of the mapvoidsetDesignTime(boolean b)Indicate that the component is being used at design time, such as in a visual editor like NetBeans' MatissevoidsetDoubleClickZoomEnabled(boolean enabled)voidsetHorizontalWrapped(boolean wrapped)voidsetLoadingImage(Image loadingImage)A property for an image which will be display when an image is still loading.voidsetOverlayPainter(org.jdesktop.swingx.painter.Painter<JXMapViewer> overlay)Sets the map overlay.voidsetRecenterOnClickEnabled(boolean b)Sets whether the map should recenter itself on mouse clicks (middle mouse clicks?)voidsetRestrictOutsidePanning(boolean restrict)voidsetTileFactory(nl.bebr.mapviewer.data.TileFactory<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>> factory)SetTileFactoryvoidsetTypeSelectionEnabled(boolean typeSelectionEnabled, nl.bebr.mapviewer.data.TileFactoryInfo... tileFactoryInfos)voidsetZoom(int zoom)Set zoom levelvoidsetZoomEnabled(boolean zoomEnabled)voidsetZoomFromGeoPosition(nl.bebr.mapviewer.data.GeoPosition start, nl.bebr.mapviewer.data.GeoPosition end)voidzoomToArea(Point start, Point end)Zoom the map to specified area-
Methods inherited from class org.jdesktop.swingx.JXPanel
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, isInheritAlpha, isPaintBorderInsets, paint, paintComponent, setAlpha, setBackground, setBackgroundPainter, setInheritAlpha, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, 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
-
-
-
-
Field Detail
-
MAX_ZOOM
public static final int MAX_ZOOM
- See Also:
- Constant Field Values
-
MIN_ZOOM
public static final int MIN_ZOOM
- See Also:
- Constant Field Values
-
ZOOM
public static final String ZOOM
- See Also:
- Constant Field Values
-
-
Method Detail
-
initInputListeners
protected void initInputListeners()
-
setDesignTime
public void setDesignTime(boolean b)
Indicate that the component is being used at design time, such as in a visual editor like NetBeans' Matisse- Specified by:
setDesignTimein interfaceDesignMode- Parameters:
b- indicates if the component is being used at design time
-
isDesignTime
public boolean isDesignTime()
Indicates whether the component is being used at design time, such as in a visual editor like NetBeans' Matisse- Specified by:
isDesignTimein interfaceDesignMode- Returns:
- boolean indicating if the component is being used at design time
-
drawMapTiles
protected void drawMapTiles(Graphics g, int zoom, Rectangle viewportBounds)
Draw the map tiles. This method is for implementation use only.- Parameters:
g- Graphicszoom- zoom level to draw atviewportBounds- the bounds to draw within
-
setOverlayPainter
public void setOverlayPainter(org.jdesktop.swingx.painter.Painter<JXMapViewer> overlay)
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.- Parameters:
overlay- the map overlay to use- See Also:
org.jdesktop.swingx.painters.Painter
-
getOverlayPainter
public org.jdesktop.swingx.painter.Painter<JXMapViewer> getOverlayPainter()
Gets the current map overlay- Returns:
- the current map overlay
-
setRecenterOnClickEnabled
public void setRecenterOnClickEnabled(boolean b)
Sets whether the map should recenter itself on mouse clicks (middle mouse clicks?)- Parameters:
b- if should recenter
-
isRecenterOnClickEnabled
public boolean isRecenterOnClickEnabled()
Indicates if the map should recenter itself on mouse clicks.- Returns:
- boolean indicating if the map should recenter itself
-
getLoadingImage
public Image getLoadingImage()
A property for an image which will be display when an image is still loading.- Returns:
- the current property value
-
setLoadingImage
public void setLoadingImage(Image loadingImage)
A property for an image which will be display when an image is still loading.- Parameters:
loadingImage- the new property value
-
setTileFactory
public void setTileFactory(nl.bebr.mapviewer.data.TileFactory<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>> factory)
SetTileFactory- Parameters:
factory-
-
setZoom
public void setZoom(int zoom)
Set zoom level- Parameters:
zoom-
-
setAddressLocation
public void setAddressLocation(nl.bebr.mapviewer.data.GeoPosition addressLocation)
SetGeoPositionaddress of the center of the map- Parameters:
addressLocation-
-
getTileFactory
public nl.bebr.mapviewer.data.TileFactory<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>> getTileFactory()
- Specified by:
getTileFactoryin interfacenl.bebr.mapviewer.data.MapViewer<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>>
-
getZoom
public int getZoom()
- Specified by:
getZoomin interfacenl.bebr.mapviewer.data.MapViewer<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>>
-
getViewportBounds
public Rectangle getViewportBounds()
- Specified by:
getViewportBoundsin interfacenl.bebr.mapviewer.data.MapViewer<BufferedImage,nl.bebr.mapviewer.data.Tile<BufferedImage>>
-
getCenter
public Point2D getCenter()
Gets center of the map in pixel coordinates- Returns:
-
setCenter
public void setCenter(Point2D center)
Sets the new center of the map in pixel coordinates.- Parameters:
center- the new center of the map in pixel coordinates
-
setCenterPosition
public void setCenterPosition(nl.bebr.mapviewer.data.GeoPosition geoPosition)
Sets center position of the map- Parameters:
geoPosition- center position of the map
-
getCenterPosition
public nl.bebr.mapviewer.data.GeoPosition getCenterPosition()
Gets center position of the map- Returns:
-
getAddressLocation
public nl.bebr.mapviewer.data.GeoPosition getAddressLocation()
Gets the current address location of the map. This property does not change when the user pans the map. This property is bound.- Returns:
- the current map location (address)
-
setRestrictOutsidePanning
public void setRestrictOutsidePanning(boolean restrict)
-
setHorizontalWrapped
public void setHorizontalWrapped(boolean wrapped)
-
markZoomArea
public void markZoomArea(Point startPoint, Point endPoint)
Paints zoom selection area rectangle- Parameters:
startPoint-endPoint-
-
zoomToArea
public void zoomToArea(Point start, Point end)
Zoom the map to specified area- Parameters:
start-end-
-
setZoomEnabled
public void setZoomEnabled(boolean zoomEnabled)
-
isZoomEnabled
public boolean isZoomEnabled()
-
enableZoom
protected void enableZoom()
-
disableZoom
protected void disableZoom()
-
setTypeSelectionEnabled
public void setTypeSelectionEnabled(boolean typeSelectionEnabled, nl.bebr.mapviewer.data.TileFactoryInfo... tileFactoryInfos)
-
isTypeSelectionEnabled
public boolean isTypeSelectionEnabled()
-
setZoomFromGeoPosition
public void setZoomFromGeoPosition(nl.bebr.mapviewer.data.GeoPosition start, nl.bebr.mapviewer.data.GeoPosition end)
-
setDoubleClickZoomEnabled
public void setDoubleClickZoomEnabled(boolean enabled)
-
isDoubleClickZoomEnabled
public boolean isDoubleClickZoomEnabled()
-
getScreenCoordinates
public nl.bebr.mapviewer.data.GeoPosition[] getScreenCoordinates()
-
addNotify
public void addNotify()
- Overrides:
addNotifyin classJComponent
-
removeNotify
public void removeNotify()
- Overrides:
removeNotifyin classJComponent
-
convertGeoPositionToPoint
public Point2D convertGeoPositionToPoint(nl.bebr.mapviewer.data.GeoPosition pos)
-
convertPointToGeoPosition
public nl.bebr.mapviewer.data.GeoPosition convertPointToGeoPosition(Point2D pt)
-
-