|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.bbn.openmap.image.ImageServer
public class ImageServer
The image server is the class you want to deal with when creating images. It takes a properties file and creates images based on those properties. It also has this queuing thing going so that requests can stack up while the image generator is working on requests, and it will notify the requestor when the image is ready.
The ImageServer generally has the layers on the map predefined at construction, although you can change the layers that it has. When setting the layer array, do not use the same layer in two different slots of the array - it may not give you the expected map, and may mess around with the timing issues that the ImageGenerator takes care of. If you want to reorder the layers, do so before adding your request to the ImageServer. Additionally, each request has the option of not using certain layers in the ImageServer layer array, by turning off the appropriate bits in the layer mask. Understand that the image for a request will be created based on the layer array contents and the request layer mask at the time the request processing is started, not when it is submitted.
Right now, the ImageServer is single threaded - processing requests one after another. The request setup was written to support multi-threaded processing, though, where each image could be generated in it's own thread. That code is not written - maybe someday.
# If the ImageServer is created and given a prefix (in this example, # 'imageServer') the properties file should contain the properties: imageServer.layers=<layer1 layer2 ...> layer1.className=<classname> layer1.prettyName=<pretty name of layer> # Add other attributes as required by layer1... layer2.className=<classname> layer2.prettyName=<pretty name of layer> # Add other attributes as required by layer2... # First formatter listed is default. imageServer.formatters=<formatter1 formatter2 ...> formatter1.class=<classname of formatter 1> # Add other formatter1 properties formatter2.class=<classname of formatter 2>
NOTE: If you simply hand the ImageServer a standard openmap.properties file, it works with the addition of the first two attributes except WITHOUT the 'imageServer.' prefix. New for 4.5: If the layers property is not defined, then the openmap.layers property is used to define which layers are available for the ImageServer.
Field Summary | |
---|---|
static java.lang.String |
AntiAliasingProperty
Property to turn on anti-aliasing. |
protected java.awt.Paint |
background
Paint object used for map backgrounds. |
static java.lang.String |
BackgroundProperty
Property to set the background color. |
protected boolean |
doAntiAliasing
Flag to do graphics and text anti-aliasing on the map image. |
protected ImageFormatter |
formatter
The Image formatter for the output image. |
protected java.util.Map<java.lang.String,ImageFormatter> |
imageFormatters
Hashtable of ImageFormatters available to be used. |
static java.lang.String |
ImageFormattersProperty
Property for the image formatter list of available formats. |
static java.lang.String |
ImageServerLayersProperty
Property for space separated layers. |
protected Layer[] |
layers
The array of layers on the map. |
static java.util.logging.Logger |
logger
|
static java.lang.String |
OpenMapPrefix
OpenMap prefix |
protected ProjectionFactory |
projectionFactory
The ProjectionFactory to be used for image projections. |
protected java.lang.String |
propertiesPrefix
A place to hold on to a property prefix in case one is used. |
Fields inherited from interface com.bbn.openmap.PropertyConsumer |
---|
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty |
Constructor Summary | |
---|---|
protected |
ImageServer()
Empty constructor that expects to be configured later. |
|
ImageServer(Layer[] layers,
ImageFormatter formatter)
Create an ImageServer from an array of Layers and an ImageFormatter. |
|
ImageServer(java.util.Properties props)
To create the image server, you hand it a set of properties that let it create an array of layers, and also to set the properties for those layers. |
|
ImageServer(java.lang.String prefix,
java.util.Properties props)
Same as the other constructor, except that the properties can have a prefix in front of them. |
|
ImageServer(java.lang.String prefix,
java.util.Properties props,
java.util.Map<java.lang.String,Layer> instantiatedLayers)
Create an ImageServer that should be configured with a Properties file. |
Method Summary | |
---|---|
int |
calculateVisibleLayerMask()
This method returns a integer representing a mask created from the visibility settings of the layers. |
protected java.awt.Graphics |
createGraphics(ImageFormatter formatter,
int width,
int height)
Create a java.awt.Graphics to use for an image. |
byte[] |
createImage(Projection proj)
Use the ProjectionPainter interface of the layers to create an image. |
byte[] |
createImage(Projection proj,
int scaledWidth,
int scaledHeight)
Use the ProjectionPainter interface of the layers to create an image. |
byte[] |
createImage(Projection proj,
int scaledWidth,
int scaledHeight,
int includedLayerMask)
Use the ProjectionPainter interface of the layers to create an image. |
byte[] |
createImage(Projection proj,
int scaledWidth,
int scaledHeight,
int includedLayerMask,
java.awt.Paint background)
Use the ProjectionPainter interface of the layers to create an image. |
byte[] |
createImage(Projection proj,
int scaledWidth,
int scaledHeight,
java.util.List<java.lang.String> showLayers)
Use the ProjectionPainter interface of the layers to create an image. |
byte[] |
createImage(Projection proj,
int scaledWidth,
int scaledHeight,
java.util.List<java.lang.String> showLayers,
java.awt.Paint background)
Use the ProjectionPainter interface of the layers to create an image. |
static java.lang.String |
createImageFile(java.lang.String prefix,
java.util.Properties props,
Projection proj,
java.lang.String outputPath)
For convenience, to create an image file based on the contents of a properties file (like an openmap.properties file). |
byte[] |
createImageFromLayers(Projection proj,
int scaledWidth,
int scaledHeight,
java.util.List<Layer> showLayers)
Use the ProjectionPainter interface of the layers to create an image. |
byte[] |
createImageFromLayers(Projection proj,
int scaledWidth,
int scaledHeight,
java.util.List<Layer> layers,
java.awt.Paint background)
Create an image from a set of layers. |
java.awt.Paint |
getBackground()
Get the Paint to use for image backgrounds. |
java.awt.Paint |
getBackground(java.util.Properties props,
java.lang.String propertyKey)
Determine the background color based on property settings. |
boolean |
getDoAntiAliasing()
Find out whether anti-aliasing is used when creating the image. |
protected byte[] |
getFormattedImage(ImageFormatter formatter,
int scaledWidth,
int scaledHeight)
Format the image that is contained in the ImageFormatter, scaling to a particular size if the scaledWidth and scaledHeight are greater than 0. |
ImageFormatter |
getFormatter()
Get the ImageFormatter currently used for the image creation. |
java.util.Map<java.lang.String,ImageFormatter> |
getFormatters()
Get the Hashtable used to hold the ImageFormatters. |
protected ImageFormatter |
getFormatters(java.util.Properties p)
Create an ImageFormatter from the contents of a properties object. |
Layer[] |
getLayers()
Retrieve the current set of layers used for requests. |
protected Layer[] |
getLayers(java.util.Properties p)
Create an array of Layers from a properties object. |
protected Layer[] |
getLayers(java.util.Properties p,
java.util.Map<java.lang.String,Layer> instantiatedLayers)
Create an array of Layers from a properties object. |
protected Layer[] |
getMaskedLayers(int layerMask)
Given a integer that represents, bitwise, the layers that you want out of the current list held by the ImageServer layer array, return an array of those layers. |
ProjectionFactory |
getProjectionFactory()
|
java.util.Properties |
getProperties(java.util.Properties props)
Part of the PropertyConsumer interface. |
java.util.Properties |
getPropertyInfo(java.util.Properties list)
Part of the PropertyConsumer interface. |
java.lang.String |
getPropertyPrefix()
Part of the PropertyConsumer interface. |
boolean |
getTransparent()
Get the transparent flag. |
static void |
main(java.lang.String[] argv)
The ImageServer class main function will create a map image from a modified openmap.properties file. |
void |
setBackground(java.awt.Paint bg)
Set the Paint to use for image backgrounds. |
void |
setDoAntiAliasing(boolean set)
Set whether anti-aliasing is used when creating the image. |
void |
setFormatter(ImageFormatter f)
Set the ImageFormatter to be used for ImageCreation. |
boolean |
setFormatter(java.lang.String formatterLabel)
Set the default formatter to the one with the given label. |
void |
setFormatters(java.util.Map<java.lang.String,ImageFormatter> iFormatters,
java.lang.String defaultFormatterKey)
Set the ImageFormatter Hashtable to set up the possible choices for image formats. |
void |
setLayers(Layer[] newLayers)
Set the layers used on the NEXT request that is processed. |
void |
setProjectionFactory(ProjectionFactory projFactory)
|
void |
setProperties(java.util.Properties props)
Set the layers and image type in the properties. |
void |
setProperties(java.lang.String prefix,
java.util.Properties props)
Set the layers and image type in the properties. |
void |
setProperties(java.lang.String prefix,
java.util.Properties props,
java.util.Map<java.lang.String,Layer> instantiatedLayers)
Set the layers and image type in the properties. |
void |
setPropertyPrefix(java.lang.String prefix)
Part of the PropertyConsumer interface. |
void |
setTransparent(boolean transparent)
Set the transparent flag. |
java.lang.String |
writeImageFile(byte[] imageBytes,
java.lang.String outputPath,
boolean checkFormatterForExtension)
Takes a byte array and writes it out to a file path. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.util.logging.Logger logger
protected ImageFormatter formatter
protected java.util.Map<java.lang.String,ImageFormatter> imageFormatters
protected Layer[] layers
public static final java.lang.String ImageServerLayersProperty
public static final java.lang.String OpenMapPrefix
public static final java.lang.String ImageFormattersProperty
public static final java.lang.String AntiAliasingProperty
public static final java.lang.String BackgroundProperty
protected boolean doAntiAliasing
protected java.lang.String propertiesPrefix
protected ProjectionFactory projectionFactory
protected java.awt.Paint background
Constructor Detail |
---|
protected ImageServer()
public ImageServer(java.util.Properties props)
public ImageServer(java.lang.String prefix, java.util.Properties props)
public ImageServer(java.lang.String prefix, java.util.Properties props, java.util.Map<java.lang.String,Layer> instantiatedLayers)
public ImageServer(Layer[] layers, ImageFormatter formatter)
layers
- the array of layers.formatter
- the ImageFormatter to use for the output image format.Method Detail |
---|
public void setDoAntiAliasing(boolean set)
public boolean getDoAntiAliasing()
public void setLayers(Layer[] newLayers)
newLayers
- an array of com.bbn.openmap.Layer objects, already
configured and ready to respond to a projectionChanged method
call.public Layer[] getLayers()
public byte[] createImage(Projection proj)
proj
- projection of map.
public byte[] createImage(Projection proj, int scaledWidth, int scaledHeight)
proj
- projection of map.scaledWidth
- scaled pixel width of final image. If you don't want
it scaled, use -1.scaledHeight
- scaled pixel height of final image. If you don't want
it scaled, use -1.
public byte[] createImage(Projection proj, int scaledWidth, int scaledHeight, java.util.List<java.lang.String> showLayers)
proj
- projection of map.scaledWidth
- scaled pixel width of final image. If you don't want
it scaled, use -1.scaledHeight
- scaled pixel height of final image. If you don't want
it scaled, use -1.showLayers
- Layer marker names reflecting the layers that should be
part of this image.
public byte[] createImageFromLayers(Projection proj, int scaledWidth, int scaledHeight, java.util.List<Layer> showLayers)
proj
- projection of map.scaledWidth
- scaled pixel width of final image. If you don't want
it scaled, use -1.scaledHeight
- scaled pixel height of final image. If you don't want
it scaled, use -1.showLayers
- Layersthat should be part of this image.
public byte[] createImage(Projection proj, int scaledWidth, int scaledHeight, java.util.List<java.lang.String> showLayers, java.awt.Paint background)
proj
- projection of map.scaledWidth
- scaled pixel width of final image. If you don't want
it scaled, use -1.scaledHeight
- scaled pixel height of final image. If you don't want
it scaled, use -1.showLayers
- Layer marker names reflecting the layers that should be
part of this image.background
- the Paint to be used for the background of this image.
public byte[] createImageFromLayers(Projection proj, int scaledWidth, int scaledHeight, java.util.List<Layer> layers, java.awt.Paint background)
proj
- projection of map.scaledWidth
- scaled pixel width of final image. If you don't want
it scaled, use -1.scaledHeight
- scaled pixel height of final image. If you don't want
it scaled, use -1.layers
- A set of layers to paint into the image.background
- the Paint to be used for the background of this image.
public int calculateVisibleLayerMask()
public byte[] createImage(Projection proj, int scaledWidth, int scaledHeight, int includedLayerMask)
proj
- projection of map.scaledWidth
- scaled pixel width of final image. If you don't want
it scaled, use -1.scaledHeight
- scaled pixel height of final image. If you don't want
it scaled, use -1.includedLayerMask
- a mask signifying which of the ImageServer
layers to use in the image. It's assumed that the called knows
which layers are desired. Bit 1 of the mask refers to layer[0],
etc. A bit turned on means the layer will be included.
public byte[] createImage(Projection proj, int scaledWidth, int scaledHeight, int includedLayerMask, java.awt.Paint background)
proj
- projection of map.scaledWidth
- scaled pixel width of final image. If you don't want
it scaled, use -1.scaledHeight
- scaled pixel height of final image. If you don't want
it scaled, use -1.includedLayerMask
- a mask signifying which of the ImageServer
layers to use in the image. It's assumed that the called knows
which layers are desired. Bit 1 of the mask refers to layer[0],
etc. A bit turned on means the layer will be included.background
- the background Paint to use for the image, behind the
layers.
protected java.awt.Graphics createGraphics(ImageFormatter formatter, int width, int height)
formatter
- the ImageFormatter containing the image.width
- the pixel width of the image.height
- the pixel height of the image.protected byte[] getFormattedImage(ImageFormatter formatter, int scaledWidth, int scaledHeight)
public void setProperties(java.util.Properties props)
setProperties
in interface PropertyConsumer
props
- a properties object that the PropertyConsumer
can use to retrieve expected properties it can use for
configuration.public void setProperties(java.lang.String prefix, java.util.Properties props)
setProperties
in interface PropertyConsumer
prefix
- a String used by the PropertyConsumer to prepend
to each property value it wants to look up -
setList.getProperty(prefix.propertyKey). If the prefix
had already been set, then the prefix passed in should
replace that previous value.props
- a Properties object that the PropertyConsumer
can use to retrieve expected properties it can use for
configuration.public void setProperties(java.lang.String prefix, java.util.Properties props, java.util.Map<java.lang.String,Layer> instantiatedLayers)
public java.awt.Paint getBackground(java.util.Properties props, java.lang.String propertyKey)
props
- properties to checkpropertyKey
- first key to check for.
public java.util.Properties getProperties(java.util.Properties props)
getProperties
in interface PropertyConsumer
props
- a Properties object to load the PropertyConsumer
properties into. If getList equals null, then a new
Properties object should be created.
public java.util.Properties getPropertyInfo(java.util.Properties list)
getPropertyInfo
in interface PropertyConsumer
list
- a Properties object to load the PropertyConsumer
properties into. If getList equals null, then a new
Properties object should be created.
public void setPropertyPrefix(java.lang.String prefix)
setPropertyPrefix
in interface PropertyConsumer
prefix
- the prefix String.public java.lang.String getPropertyPrefix()
getPropertyPrefix
in interface PropertyConsumer
protected Layer[] getMaskedLayers(int layerMask)
layerMask
- bit mask for desired layers, bit 0 is layer 0.
public ImageFormatter getFormatter()
public void setFormatter(ImageFormatter f)
public boolean setFormatter(java.lang.String formatterLabel)
formatterLabel
- String for a particular formatter.
public java.util.Map<java.lang.String,ImageFormatter> getFormatters()
public void setFormatters(java.util.Map<java.lang.String,ImageFormatter> iFormatters, java.lang.String defaultFormatterKey)
iFormatters
- Hashtable of ImageFormattersdefaultFormatterKey
- the key label of the formatter to use for a
default.protected ImageFormatter getFormatters(java.util.Properties p)
p
- Properties used to initialize the Properties.
protected Layer[] getLayers(java.util.Properties p)
protected Layer[] getLayers(java.util.Properties p, java.util.Map<java.lang.String,Layer> instantiatedLayers)
p
- propertiesinstantiatedLayers
- a hashtable containing layers, with the prefix
layer name used as the key.public ProjectionFactory getProjectionFactory()
public void setProjectionFactory(ProjectionFactory projFactory)
public java.lang.String writeImageFile(byte[] imageBytes, java.lang.String outputPath, boolean checkFormatterForExtension) throws java.io.IOException
imageBytes
- the formatted bytes of the image.outputPath
- the path of the image file.checkFormatterForExtension
- if true, will check the current active
formatter for extension that will be added to the path if it
doesn't end with the image type.
java.io.IOException
public static java.lang.String createImageFile(java.lang.String prefix, java.util.Properties props, Projection proj, java.lang.String outputPath) throws java.net.MalformedURLException, java.io.IOException
prefix
- The prefix for the ImageServer properties (layers and
formatters) to use in the properties file. If defined, then this
method will look for 'prefix.layers' and prefix.formatters'
properties. If null, then this method will look 'layers' and
'formatters' properties.props
- The properties to use for defining the layers and plugins to
use on the map image. Standard openmap.properties formats for
layer definitions. See the standard openmap.properties file for
more details on how to define layers and plugins.proj
- The projection to use for the map. If null, then the
Environment projection properties will be looked for in the
Properties.outputPath
- The output path for the image file. The image file
should not have an appendix defined. This method will check which
formatter is being used, and will assign one based on the image
format (leave off the ., too).
java.net.MalformedURLException
java.io.IOException
public void setBackground(java.awt.Paint bg)
public java.awt.Paint getBackground()
public void setTransparent(boolean transparent)
ImageFormatter
does not support
transparency or the image is completely filled.
transparent
- public boolean getTransparent()
ImageFormatter
does not support
transparency or the image is completely filled.
public static void main(java.lang.String[] argv)
java com.bbn.openmap.image.ImageServer -properties (path to properties file) -file (path to output image)
The path to the output image should not have an appendix on it, that will get assigned depending on what image format is used.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |