Class TLcdMIFModelEncoder

java.lang.Object
com.luciad.format.mif.TLcdMIFModelEncoder
All Implemented Interfaces:
ILcdOutputStreamFactoryCapable, ILcdModelEncoder, Serializable

@LcdService(service=ILcdModelEncoder.class, priority=20000) public class TLcdMIFModelEncoder extends Object implements ILcdModelEncoder, ILcdOutputStreamFactoryCapable
This ILcdModelEncoder creates MIF (MapInfo Interchange Format) files from an ILcdModel containing any of the shapes displayed in the list below.

The TLcdMIFModelEncoder encodes

  • ILcdPoint as Point
  • ILcdPolygon as Region
  • ILcdPolyline as Line
  • ILcdCircle as Ellipse
  • ILcdEllipse as Ellipse
  • ILcdArc as Arc
  • ILcdBounds as Rect
  • ILcdShapeList as an expanded list of its composing shapes.

If the given shape is also ILcdDataObject, this model encoder will encode each of the properties of the TLcdDataType of the shape. Note that this exporter cannot export non-primitive properties with complex TLcdDataTypes. It will skip these properties. Also note that the exporter can only export properties for models that have an ILcdDataModelDescriptor with only a single model element data type.

Only a subset of the coordinate systems available in the MIF format is supported. Rotated ellipses are not supported.

See Also:
  • Constructor Details

    • TLcdMIFModelEncoder

      public TLcdMIFModelEncoder()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Description copied from interface: ILcdModelEncoder
      Returns a short, displayable name for the format this ILcdModelEncoder encodes to.
      Specified by:
      getDisplayName in interface ILcdModelEncoder
      Returns:
      the displayable name of this ILcdModelEncoder.
    • canExport

      public boolean canExport(ILcdModel aModel, String aDestination)
      Description copied from interface: ILcdModelEncoder
      Returns whether this encoder can export the specified model to the specified destination. This method will typically check whether the contents of the specified model are compatible with the format this encoder is written for.
      Specified by:
      canExport in interface ILcdModelEncoder
      Parameters:
      aModel - the model to be verified.
      aDestination - the location where the model should be exported to.
      Returns:
      true if this encoder can export the specified model to the specified location, false otherwise.
      See Also:
    • export

      public void export(ILcdModel aModel, String aDestination) throws IllegalArgumentException, IOException
      Description copied from interface: ILcdModelEncoder
      Exports the specified model to the specified destination.
      Specified by:
      export in interface ILcdModelEncoder
      Parameters:
      aModel - the model to be exported.
      aDestination - the location where the model should be saved. Typically, this is a name for the output file, but it can also point to a file containing the required properties to create a set of data files.
      Throws:
      IllegalArgumentException - if the model cannot be saved by this encoder (!canExport(aModel, aDestinationName)).
      IOException - if an I/O error occurs during encoding.
    • canSave

      public boolean canSave(ILcdModel aModel)
      Description copied from interface: ILcdModelEncoder
      Returns whether this model encoder can save the specified model to the location it originally came from. Often this will only be a simple test, for example checking the type of the model's model descriptor.
      Specified by:
      canSave in interface ILcdModelEncoder
      Parameters:
      aModel - the model to be verified.
      Returns:
      true if this encoder can save the model in the location where it originally came from, false otherwise.
      See Also:
    • save

      public void save(ILcdModel aModel) throws IllegalArgumentException, IOException
      Description copied from interface: ILcdModelEncoder
      Saves the model to the location where it originally came from.
      Specified by:
      save in interface ILcdModelEncoder
      Parameters:
      aModel - the model to be saved.
      Throws:
      IllegalArgumentException - if the model cannot be saved by this encoder (!canSave(aModel)).
      IOException - if an I/O error occurs during encoding.
    • createBufferedWriter

      protected BufferedWriter createBufferedWriter(String aFileName) throws IllegalArgumentException
      Called by the save and export methods to redirect output to the mif and mid files using a buffered writer.
      Parameters:
      aFileName - the file name to write to.
      Returns:
      a buffered writer to allow output to aDestination.
      Throws:
      IllegalArgumentException - if aFileName is the file name of an existing read-only file.
    • createMIDBufferedWriter

      protected BufferedWriter createMIDBufferedWriter(String aMIFFileName) throws IllegalArgumentException
      Called by the save and export methods to redirect output to the mid files using a buffered writer.
      Parameters:
      aMIFFileName - the file name of the mif file the mid file is accompanying.
      Returns:
      a buffered writer to allow output to the mid file accompanying aMIFFileName.
      Throws:
      IllegalArgumentException - if the accompanying mid the mif file name is an existing read only file
    • getOutputStreamFactory

      public ILcdOutputStreamFactory getOutputStreamFactory()
      Returns the factory to create output streams which are used in the methods createBufferedWriter(String) and createMIDBufferedWriter(String).
      Specified by:
      getOutputStreamFactory in interface ILcdOutputStreamFactoryCapable
      Returns:
      the factory to create output streams.
    • setOutputStreamFactory

      public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
      Sets the factory to create output streams which are used in the methods createBufferedWriter(String) and createMIDBufferedWriter(String).
      Specified by:
      setOutputStreamFactory in interface ILcdOutputStreamFactoryCapable
      Parameters:
      aOutputStreamFactory - the factory to create output streams.
    • writeCoordSysClause

      protected void writeCoordSysClause(ILcdModel aModel, BufferedWriter aBufferedWriter) throws IOException
      Writes the coordinate system clause to the given buffered writer.
      Parameters:
      aModel - the model whose reference is translated in a coordinate system clause.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • writeColumnClause

      protected void writeColumnClause(ILcdModel aModel, BufferedWriter aBufferedWriter) throws IOException
      Writes the columns clause to the given buffered writer.
      Parameters:
      aModel - whose model descriptors features are written as a columns clause.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • writeElements

      protected int writeElements(ILcdShapeList aShapeList, BufferedWriter aMIFBufferedWriter) throws IOException
      Writes the elements of the given ILcdShapeList to the given buffered writer.
      Parameters:
      aShapeList - the elements to be encoded.
      aMIFBufferedWriter - the writer for MIF data.
      Returns:
      the number of elements that were written.
      Throws:
      IOException - when writing to one of the buffered writers fails.
    • write2DRegion

      protected void write2DRegion(ILcdShapeList aShapeList, BufferedWriter aBufferedWriter) throws IOException
      Deprecated.
      Use #writeElements(ILcdShapeList, BufferedWriter)
      Writes the given ILcdShapeList containing ILcdPointList objects as a 2D region (Region).
      Parameters:
      aShapeList - the shape list to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DRegion

      protected void write2DRegion(ILcdComplexPolygon aComplexPolygon, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdComplexPolygon as a 2D region (Region).
      Parameters:
      aComplexPolygon - the complex polygon to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DRegion

      protected void write2DRegion(ILcdPolygon aPolygon, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdPolygon as a 2D region (Region 1).
      Parameters:
      aPolygon - the polygon to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DPLine

      protected void write2DPLine(ILcdShapeList aShapeList, BufferedWriter aBufferedWriter) throws IOException
      Deprecated.
      Use #writeElements(ILcdShapeList, BufferedWriter)
      Writes the given ILcdShapeList containing 1 point list as 2D polyline (PLine), 1 pen clause per shape list.
      Parameters:
      aShapeList - the shape list to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DPLine

      protected void write2DPLine(ILcdPointList aPointList, BufferedWriter aBufferedWriter, boolean aWritePenClause) throws IOException
      Writes the given ILcdPointList as a 2D polyline (PLine) with 1 pen clause if aWritePenClause is true.
      Parameters:
      aPointList - the point list to encode.
      aBufferedWriter - sink for output.
      aWritePenClause - whether to write a pen clause or not.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DPoint

      protected void write2DPoint(ILcdPoint aPoint, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdPoint as a point (Point) and adds a symbol clause.
      Parameters:
      aPoint - the point to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DEllipse

      protected void write2DEllipse(ILcdCircle aCircle, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdCircle as an ellipse (Ellipse).
      Parameters:
      aCircle - the circle to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DEllipse

      protected void write2DEllipse(ILcdEllipse aEllipse, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdEllipse as an ellipse (Ellipse).
      Parameters:
      aEllipse - the ellipse to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DArc

      protected void write2DArc(ILcdArc aArc, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdArc as an ellipse (Ellipse).
      Parameters:
      aArc - the arc to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DRectangle

      protected void write2DRectangle(ILcdBounds aBounds, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdBounds as a 2D rectangle (Rect).
      Parameters:
      aBounds - the bounds to encode.
      aBufferedWriter - sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • write2DText

      protected void write2DText(ILcdText aText, BufferedWriter aBufferedWriter) throws IOException
      Writes the given ILcdText as a TEXT.
      Parameters:
      aText - The text to write to the given Writer. Never null.
      aBufferedWriter - The Writer to which the text must be written. Never null.
      Throws:
      IOException - when writing the text to the Writer fails.
    • writeSymbolClause

      protected void writeSymbolClause(Object aObject, BufferedWriter aBufferedWriter) throws IOException
      Writes the symbol clause corresponding to a given object.
      Parameters:
      aObject - the object whose symbol is written.
      aBufferedWriter - the output sink.
      Throws:
      IOException - when writing to the buffered writer fails.
    • writePenClause

      protected void writePenClause(Object aObject, BufferedWriter aBufferedWriter) throws IOException
      Encodes the line style for TLcdMIFRegion or TLcdMIFPLine objects as a pen clause (Pen). For other objects a default pen clause is written.
      Parameters:
      aObject - the object to encode the line style for.
      aBufferedWriter - the sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • writeBrushClause

      protected void writeBrushClause(Object aObject, BufferedWriter aBufferedWriter) throws IOException
      Encodes fill style for TLcdMIFRegion objects as a brush clause (Brush).
      Parameters:
      aObject - the object to encode the fill style for (currently only TLcdMIFRegion).
      aBufferedWriter - the sink for output.
      Throws:
      IOException - when writing to the buffered writer fails.
    • writeCenterClause

      protected void writeCenterClause(Object aObject, BufferedWriter aBufferedWriter) throws IOException
      Encodes the focus point of an object.
      Parameters:
      aObject - the object whose center is encoded.
      aBufferedWriter - output sink.
      Throws:
      IOException - when writing to the buffered writer fails.
    • colorToString

      protected final String colorToString(Color aColor)
      Gets the MIF color representation for aColor. The following formula is used: ((aColor.getRed() * 65536) + (aColor.getGreen() * 256) + aColor.getBlue()).
      Parameters:
      aColor - The color for which to get the MIF representation. Must not be null.
      Returns:
      The color representation as a string.