Package org.ka2ddo.yaac.gui.drawlayer
Class DrawLayer
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.bbn.openmap.Layer
org.ka2ddo.yaac.gui.drawlayer.DrawLayer
- All Implemented Interfaces:
com.bbn.openmap.event.MapMouseListener
,com.bbn.openmap.event.ProjectionListener
,com.bbn.openmap.ProjectionPainter
,com.bbn.openmap.PropertyConsumer
,ActionListener
,ComponentListener
,KeyListener
,ImageObserver
,MenuContainer
,BeanContextChild
,BeanContextMembershipListener
,Serializable
,EventListener
public class DrawLayer
extends com.bbn.openmap.Layer
implements com.bbn.openmap.event.MapMouseListener, KeyListener, ComponentListener
This class implements an overlay on the OpenMap map panel that permits
the user to draw arbitrary geometrical lines and objects, suitable for
marking and highlighting areas of interest on the map. Note that these
overlays are completely independent of the information drawn from the
OpenStreetMap data sets and from received APRS stations and objects.
- Author:
- Andrew Pavlin, KA2DDO
- See Also:
-
Nested Class Summary
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 com.bbn.openmap.Layer
addAsBackground, AddAsBackgroundProperty, addToBeanContext, AddToBeanContextProperty, attributes, autoPalette, AutoPaletteProperty, beanContextChildSupport, coordTransform, DataPathPrefixProperty, DisplayPaletteCmd, DisplayPropertiesCmd, doHack, HidePaletteCmd, i18n, localHackList, maxScale, MaxScaleProperty, minScale, MinScaleProperty, palette, paletteListener, PrettyNameProperty, propertyPrefix, readyToPaint, RedrawCmd, removable, RemovableProperty, SWING_PACKAGE, TransformProperty, windowSupport
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
Fields inherited from interface com.bbn.openmap.PropertyConsumer
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
-
Constructor Summary
ConstructorDescriptionDrawLayer
(GeographicalMap geoMap, com.bbn.openmap.MouseDelegator mouseDelegator) Create a DrawLayer for the specified MouseDelegator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDrawable
(AbstractDrawable drawable) Add another drawable to the draw layer.void
addGraphicList
(com.bbn.openmap.omGraphics.OMGraphicList gl) load a list of OMGraphic objects into the DrawLayer.void
Unselects any drawable in the DrawLayer that was selected by the SELECT mode.void
Invoked when the component has been made invisible.void
Invoked when the component's position changes.void
Invoked when the component's size changes.void
Invoked when the component has been made visible.Get the current color selected for drawing lines.Get the one-pixel wide style of the line stroke.Get the descriptive name of the current line stroke type.float
Get the width (in pixels) for the line drawing the current shape.com.bbn.openmap.event.MapMouseListener
Get the listener to be informed of MapMouseEvents.getMode()
Get the current drawing mode of the DrawLayer.String[]
Get the MapBean mouse modes that this DrawLayer services.int
Get the current transparency (alpha) value for drawing the current shape.void
Invoked when a key has been pressed.void
Invoked when a key has been released.void
Invoked when a key has been typed.void
Read one drawable shape from a binary file.void
Load a polyline from a CSV file (one vertex per line), using the current stroke and color settings.void
Load drawing overlay.void
loadGPX
(InputStream din) Load a polyline from a GPX file.void
loadKML
(InputStream din) Read polylines from a KML file.boolean
mouseClicked
(MouseEvent mouseEvent) boolean
mouseDragged
(MouseEvent mouseEvent) void
mouseEntered
(MouseEvent mouseEvent) void
mouseExited
(MouseEvent mouseEvent) void
boolean
mouseMoved
(MouseEvent mouseEvent) boolean
mousePressed
(MouseEvent mouseEvent) boolean
mouseReleased
(MouseEvent mouseEvent) void
Render this layer's content into the MapBean.void
projectionChanged
(com.bbn.openmap.event.ProjectionEvent projectionEvent) Invoked when there has been a fundamental change to the Map.void
registerMouseMode
(com.bbn.openmap.MouseDelegator mouseDelegator) Register the drawing mode of this layer with the MouseDelegator.void
save
(DataOutput dos) Write the current set of drawn shapes to a save file in binary format.void
saveCSV
(PrintStream ps, boolean lonBeforeLat) Save all the polylines in the DrawLayer in a CSV file of longitude and latitude tuples (altitude is always reported as zero).void
Save drawing overlay.void
saveKML
(PrintStream ps) Save all the polylines currently in the DrawLayer as a KML file.void
setLineColor
(Color lineColor) Set the RGB Color for drawing the currently edited shape in the DrawLayer.void
setLineWidth
(float width) Set the width (in pixels) for the line drawing the current shape.void
Set the current drawing mode of the DrawLayer.void
setStroke
(BasicStroke s, String strokeType) Set the line stroke type to be used for the currently edited shape.void
setTransparency
(int transparency) Set the current transparency (alpha) value for drawing the current shape.Methods inherited from class com.bbn.openmap.Layer
actionPerformed, addComponentListener, added, addInfoDisplayListener, addLayerStatusListener, addMouseListener, addVetoableChangeListener, childrenAdded, childrenRemoved, clearListeners, connectToBeanContext, createWindowSupport, disconnectFromBeanContext, dispose, finalize, findAndInit, findAndInit, findAndUndo, fireHideToolTip, firePaletteEvent, fireRequestBrowserContent, fireRequestBrowserContent, fireRequestCursor, fireRequestInfoLine, fireRequestInfoLine, fireRequestInfoLine, fireRequestMessage, fireRequestMessage, fireRequestToolTip, fireRequestToolTip, fireRequestURL, fireRequestURL, fireStatusUpdate, fireStatusUpdate, fireVetoableChange, getAddAsBackground, getAddToBeanContext, getAttribute, getBeanContext, getCoordTransform, getGUI, getIcon, getMaxScale, getMinScale, getPackage, getPalette, getProjection, getProperties, getPropertyInfo, getPropertyPrefix, getWindowSupport, hasGUI, hidePalette, isAutoPalette, isProjectionOK, isReadyToPaint, isRemovable, notifyHideHack, prependDataPathPrefix, putAttribute, removeComponentListener, removeConfirmed, removed, removeInfoDisplayListener, removeLayerStatusListener, removeVetoableChangeListener, renderDataForProjection, repaint, resetPalette, setAddAsBackground, setAddToBeanContext, setAutoPalette, setBeanContext, setCoordTransform, setIcon, setLayerProperties, setMaxScale, setMinScale, setName, setPaletteVisible, setProjection, setProjection, setProperties, setProperties, setPropertyPrefix, setReadyToPaint, setRemovable, setVisible, setWindowSupport, showPalette
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, 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, unregisterKeyboardAction, update, updateUI
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, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, 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, 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, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.beans.beancontext.BeanContextChild
addPropertyChangeListener, removePropertyChangeListener
-
Field Details
-
DRAW_MOUSE_MODE_NAME
Mouse mode name for this Layer.- See Also:
-
-
Constructor Details
-
DrawLayer
Create a DrawLayer for the specified MouseDelegator.- Parameters:
geoMap
- GeographicalMap containing this DrawLayermouseDelegator
- MouseDelegator indicating which mouse mode the MapBean will sendmouse data to this overlay
-
-
Method Details
-
registerMouseMode
public void registerMouseMode(com.bbn.openmap.MouseDelegator mouseDelegator) Register the drawing mode of this layer with the MouseDelegator.- Parameters:
mouseDelegator
- MouseDelegator handling distribution of mouse events to different map layers
-
getMapMouseListener
public com.bbn.openmap.event.MapMouseListener getMapMouseListener()Get the listener to be informed of MapMouseEvents.- Overrides:
getMapMouseListener
in classcom.bbn.openmap.Layer
- Returns:
- MapMouseListener implementaion
-
getMouseModeServiceList
Get the MapBean mouse modes that this DrawLayer services.- Specified by:
getMouseModeServiceList
in interfacecom.bbn.openmap.event.MapMouseListener
- Returns:
- an array of the mouse modes serviced
-
getLineColor
Get the current color selected for drawing lines.- Returns:
- drawing Color
-
setLineColor
Set the RGB Color for drawing the currently edited shape in the DrawLayer.- Parameters:
lineColor
- Color to drw the current shape with
-
getTransparency
public int getTransparency()Get the current transparency (alpha) value for drawing the current shape.- Returns:
- the int transparency value from 0 (completely transparent and invisible) to 255 (completely opaque)
-
setTransparency
public void setTransparency(int transparency) Set the current transparency (alpha) value for drawing the current shape.- Parameters:
transparency
- the int transparency value from 0 (completely transparent and invisible) to 255 (completely opaque)
-
mousePressed
- Specified by:
mousePressed
in interfacecom.bbn.openmap.event.MapMouseListener
-
mouseReleased
- Specified by:
mouseReleased
in interfacecom.bbn.openmap.event.MapMouseListener
-
mouseClicked
- Specified by:
mouseClicked
in interfacecom.bbn.openmap.event.MapMouseListener
-
mouseEntered
- Specified by:
mouseEntered
in interfacecom.bbn.openmap.event.MapMouseListener
-
mouseExited
- Specified by:
mouseExited
in interfacecom.bbn.openmap.event.MapMouseListener
-
mouseDragged
- Specified by:
mouseDragged
in interfacecom.bbn.openmap.event.MapMouseListener
-
mouseMoved
- Specified by:
mouseMoved
in interfacecom.bbn.openmap.event.MapMouseListener
-
mouseMoved
public void mouseMoved()- Specified by:
mouseMoved
in interfacecom.bbn.openmap.event.MapMouseListener
-
keyPressed
Invoked when a key has been pressed. See the class description forKeyEvent
for a definition of a key pressed event.- Specified by:
keyPressed
in interfaceKeyListener
-
keyTyped
Invoked when a key has been typed. See the class description forKeyEvent
for a definition of a key typed event.- Specified by:
keyTyped
in interfaceKeyListener
-
keyReleased
Invoked when a key has been released. See the class description forKeyEvent
for a definition of a key released event.- Specified by:
keyReleased
in interfaceKeyListener
-
componentHidden
Invoked when the component has been made invisible.- Specified by:
componentHidden
in interfaceComponentListener
-
componentResized
Invoked when the component's size changes.- Specified by:
componentResized
in interfaceComponentListener
-
componentMoved
Invoked when the component's position changes.- Specified by:
componentMoved
in interfaceComponentListener
-
componentShown
Invoked when the component has been made visible.- Specified by:
componentShown
in interfaceComponentListener
-
projectionChanged
public void projectionChanged(com.bbn.openmap.event.ProjectionEvent projectionEvent) Invoked when there has been a fundamental change to the Map.Layers are expected to recompute their graphics (if this makes sense), and then
repaint()
themselves.- Specified by:
projectionChanged
in interfacecom.bbn.openmap.event.ProjectionListener
- Parameters:
projectionEvent
- ProjectionEvent
-
paint
Render this layer's content into the MapBean. Note that we reproject on every draw to deal with map pans/zooms/resizes.- Overrides:
paint
in classJComponent
- Parameters:
g
- Graphics object to use for rendering
-
clearSelectedDrawable
public void clearSelectedDrawable()Unselects any drawable in the DrawLayer that was selected by the SELECT mode. -
getMode
Get the current drawing mode of the DrawLayer.- Returns:
- current DrawMode
-
setMode
Set the current drawing mode of the DrawLayer.- Parameters:
mode
- DrawMode to use
-
addDrawable
Add another drawable to the draw layer.- Parameters:
drawable
- AbstractDrawable instance to add
-
setStroke
Set the line stroke type to be used for the currently edited shape.- Parameters:
s
- BasicStroke of the objectstrokeType
- name of the generic stroke type
-
setLineWidth
public void setLineWidth(float width) Set the width (in pixels) for the line drawing the current shape.- Parameters:
width
- int width in pixels
-
getlineStroke1Pixel
Get the one-pixel wide style of the line stroke.- Returns:
- BasicStroke
-
getLineStrokeType
Get the descriptive name of the current line stroke type.- Returns:
- stroke type name String
-
getLineWidth
public float getLineWidth()Get the width (in pixels) for the line drawing the current shape.- Returns:
- int width in pixels
-
save
Write the current set of drawn shapes to a save file in binary format.- Parameters:
dos
- DataOutput object to write the shapes to- Throws:
IOException
- if write fails for any reason
-
saveCSV
Save all the polylines in the DrawLayer in a CSV file of longitude and latitude tuples (altitude is always reported as zero).- Parameters:
ps
- PrintStream to write the CSV records tolonBeforeLat
- ignored
-
saveKML
Save all the polylines currently in the DrawLayer as a KML file.- Parameters:
ps
- PrintStream to write the XML data to
-
load
Read one drawable shape from a binary file.- Parameters:
din
- DataInput to read the shapes from- Throws:
IOException
- if read fails for any reason
-
loadCSV
Load a polyline from a CSV file (one vertex per line), using the current stroke and color settings.- Parameters:
din
- DataInput to read the CSV records fromlatBeforeLon
- boolean true if latitude is before longitude in the CSV record, false if longitude before latitude- Throws:
IOException
- if read fails for any reason other than end-of-file
-
loadGPX
Load a polyline from a GPX file.- Parameters:
din
- DataInput of the GPX file- Throws:
IOException
- if the file could not be read for any reason
-
loadKML
Read polylines from a KML file.- Parameters:
din
- DataInput of the KML file- Throws:
IOException
- if file cannot be read for any reason
-
addGraphicList
public void addGraphicList(com.bbn.openmap.omGraphics.OMGraphicList gl) load a list of OMGraphic objects into the DrawLayer.- Parameters:
gl
- OMGraphicList
-
loadDrawing
public void loadDrawing()Load drawing overlay. -
saveDrawing
public void saveDrawing()Save drawing overlay.
-