Class TextStyle
- java.lang.Object
-
- com.supermap.data.TextStyle
-
public class TextStyle extends java.lang.Object
The text style class.Used to set the object style of {
GeoText
}.dispose()
When the text style object instance calls this member after released by usingdispose()
, an ObjectDisposedException exception will be thrown.- Example:
- The following codes demonstrate how to use the custom text style on a GeoText object and export the GeoText object to a PNG image.
public void textStyleTest() { //Suppose we open a workspace <a href="Workspace.html">workspace</a> object that contains a MapControl object. //Sets the text style. TextStyle textStyle = new TextStyle(); textStyle.setRotation(30.0); textStyle.setShadow(true); textStyle.setAlignment(TextAlignment.TOPCENTER); textStyle.setBackColor(java.awt.Color.BLUE); textStyle.setForeColor(java.awt.Color.BLACK); textStyle.setBackOpaque(true); textStyle.setBold(true); textStyle.setFontName("Arial"); textStyle.setFontHeight(100.0); textStyle.setFontWidth(100.0); textStyle.setSizeFixed(true); textStyle.setItalic(true); textStyle.setOutline(true); textStyle.setStrikeout(true); textStyle.setUnderline(true); textStyle.setWeight(500); System.out.println(" The text style is: " + textStyle.toString()); //Sets the text style to the text objects GeoText geotext = new GeoText(); TextPart part = new TextPart("SuperMap", new Point2D(150, 150), 10.0); geotext.addPart(part); geotext.setTextStyle(textStyle); //Gets Map object Map map = mapControl.getMap(); //Adds the text object to the tracking layer on the map and display it map.getTrackingLayer().add(geotext, ""); map.setViewBounds(new Rectangle2D(new Point2D(0, 0), new Point2D(300,300))); Bitmap bitmap = Bitmap.createBitmap(256, 256, Config.ARGB_8888); mapControl.outputMap(bitmap); String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath(); String path = rootPath + "/textstyle"; try{ FileOutputStream out = new FileOutputStream(path); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); } catch(Exception e){ e.printStackTrace(); } //Release resource. part.dispose(); geotext.dispose(); textStyle.dispose(); mapControl.dispose(); workspace.dispose(); }
-
-
Constructor Summary
Constructors Constructor and Description TextStyle()
Constructs a new TextStyle object.TextStyle(TextStyle textStyle)
Constructs a new object identical to the given TextStyle object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description TextStyle
clone()
Returns a copy of the current TextStyle object.void
dispose()
Release the resource occupy by this object.static boolean
drawToPNG(Geometry geometry, Resources resources, java.lang.String fileName, int width, int height)
Draws the specified geometry object into image.TextAlignment
getAlignment()
Returns the text alignment.Color
getBackColor()
Returns the background color of the text.int
getBackTransparency()
Gets the translucence of background.double
getFontHeight()
Returns the height of the text.java.lang.String
getFontName()
Returns the name of the text font.double
getFontScale()
Get the scale ratio of the label font.double
getFontWidth()
Returns the width of the text.Color
getForeColor()
Returns the foreground color of the text.boolean
getItalic()
Returns whether the text is italic, and true represents italic.double
getItalicAngle()
Returns the angle of italics, which ranges from positive to negative degree.boolean
getOutline()
Returns whether to outline and false indicates not to outline.double
getRotation()
Returns the rotation angle in degrees, with the rotation direction being anticlockwise.boolean
getShadow()
Returns whether the text has shadow, true means add shadow to the text.boolean
getStrikeout()
Returns whether strikeout for the text, true means strikeout.boolean
getUnderline()
Returns whether underline the text, true means underline.int
getWeight()
Deprecated.boolean
isBackOpaque()
Returns whether the annotation background is transparent.boolean
isBold()
Returns whether the annotation is bold.boolean
isSizeFixed()
Returns whether the size of the text is fixed.void
setAlignment(TextAlignment textAlignment)
Sets the text alignment.void
setBackColor(Color value)
Sets the background color of the text.void
setBackOpaque(boolean value)
Sets the text background is opaque.void
setBackTransparency(int value)
Sets the transparent of the background.void
setBold(boolean value)
Sets whether the text is bold.void
setFontHeight(double value)
Sets the height of the text.void
setFontName(java.lang.String value)
Sets the name of the text font.void
setFontScale(double value)
Set the scale ratio of the label font.void
setFontWidth(double value)
Sets the width of the text.void
setForeColor(Color value)
Sets the foreground color of the text.void
setItalic(boolean value)
Sets whether the text is italic, and true represents italic.void
setItalicAngle(double value)
Sets the angle of italics, which ranges from positive to negative degree.void
setOutline(boolean value)
Sets whether to use outline and false indicates not to outline.void
setRotation(double value)
Sets the rotation angle of text in the thematic map in degrees, with the rotation direction being anticlockwise.void
setShadow(boolean value)
Sets whether the text has shadow, true means add shadow to the text.void
setSizeFixed(boolean value)
Sets whether the size of the text is fixed.void
setStrikeout(boolean value)
Sets whether strikeout for the text, true means strikeout.void
setUnderline(boolean value)
Sets whether underline the text, true means underline.void
setWeight(int value)
Deprecated.java.lang.String
toString()
Returns a formatted string that represents the current TextStyle object.
-
-
-
Method Detail
-
dispose
public void dispose()
Release the resource occupy by this object.
-
getAlignment
public TextAlignment getAlignment()
Returns the text alignment.- Returns:
- A
TextAlignment
object. - Throws:
java.lang.EnumConstantNotPresentException
- If the text alignment returned is not a constant in theTextAlignment
class.- Default:
- The default value TopLeft(
TextAlignment.TOPLEFT
).
-
setAlignment
public void setAlignment(TextAlignment textAlignment)
Sets the text alignment.If the parameter of the
setAlignment()
method is not a constant of theTextAlignment
class, throw EnumConstantNotPresentException.- Parameters:
textAlignment
- the text alignment specified.- Throws:
java.lang.EnumConstantNotPresentException
- If the text alignment set is not a constant in theTextAlignment
class.
-
getBackColor
public Color getBackColor()
Returns the background color of the text.- Returns:
- The background color of the text.
- Default:
- the default color is black.
-
isBackOpaque
public boolean isBackOpaque()
Returns whether the annotation background is transparent.- Returns:
- True if the background is transparent; false otherwise.
-
isBold
public boolean isBold()
Returns whether the annotation is bold.- Returns:
- Returns true if it is bold; Otherwise false.
-
setBackColor
public void setBackColor(Color value)
Sets the background color of the text.- Parameters:
value
- The background color of the text.
-
setBold
public void setBold(boolean value)
Sets whether the text is bold.- Parameters:
value
- whether the specified text is bold.
-
getForeColor
public Color getForeColor()
Returns the foreground color of the text.- Returns:
- The foreground color of the text.
- Default:
- the default color is black.
-
setForeColor
public void setForeColor(Color value)
Sets the foreground color of the text.- Parameters:
value
- The foreground color of the text.
-
isSizeFixed
public boolean isSizeFixed()
Returns whether the size of the text is fixed. False means the size of the text is not fixed.- Returns:
- True if the text is fixed size; otherwise false.
- Default:
- The default is true, indicating fixed size.
-
setSizeFixed
public void setSizeFixed(boolean value)
Sets whether the size of the text is fixed. False means the size of the text is not fixed.- Parameters:
value
- specifies whether the size of the text is fixed.
-
getFontHeight
public double getFontHeight()
Returns the height of the text. Unit is 0.1 mm when the size is fixed, otherwise you need to use the geographic coordinate unit.- Returns:
- The height of the text font.
- Default:
- The default value is 6.
-
setFontHeight
public void setFontHeight(double value)
Sets the height of the text. Unit is 0.1 mm when the size is fixed, otherwise you need to use the geographic coordinate unit.- Parameters:
value
- The height of the text font.
-
getFontWidth
public double getFontWidth()
Returns the width of the text. Unit is 0.1 mm when the size is fixed, otherwise you need to use the geographic coordinate unit.- Returns:
- the width of the text.
- Default:
- The default value is 0.
-
setFontWidth
public void setFontWidth(double value)
Sets the width of the text. Unit is 0.1 mm when the size is fixed, otherwise you need to use the geographic coordinate unit.- Parameters:
value
- The width of the text.
-
getFontName
public java.lang.String getFontName()
Returns the name of the text font.- Returns:
- The name of the text font.
- Default:
- The default value of font name is Times New Roman.
-
setFontName
public void setFontName(java.lang.String value)
Sets the name of the text font.- Parameters:
value
- The name of the text font.
-
getItalic
public boolean getItalic()
Returns whether the text is italic, and true represents italic.- Returns:
- True if the text is italic; otherwise false.
- Default:
- false, that is do not use italic.
-
setItalic
public void setItalic(boolean value)
Sets whether the text is italic, and true represents italic.- Parameters:
value
- whether use italic for the specified annotation.
-
getItalicAngle
public double getItalicAngle()
Returns the angle of italics, which ranges from positive to negative degree. The unit is degree and the angle is accurate to 0.1 degree. When the angle is zero degree, the font is the default italic.The positive and negative represent left and right side of the vertical axis respectively. The angle ranges from 60 to -60 degree. The invalid value will be treated as the value of negative 60 when the input value is less than negative 60 and as the 60 when input value is greater than 60. For example, -30 indicate 30 degree rotation from the vertical axis with anticlockwise. As the illustration, it is the result of the italic angle about -30 and 30 degree.
It is valid only for the label thematic map in current version.
- Returns:
- the angle of inclination of the font.
- Default:
- The default value is 0.
-
setItalicAngle
public void setItalicAngle(double value)
Sets the angle of italics, which ranges from positive to negative degree. The unit is degree and the angle is accurate to 0.1 degree. When the angle is zero degree, the font is the default italic.The positive and negative represent left and right side of the vertical axis respectively. The angle ranges from 60 to -60 degree. The invalid value will be treated as the value of negative 60 when the input value is less than negative 60 and as the 60 when input value is greater than 60. For example, -30 indicate 30 degree rotation from the vertical axis with anticlockwise. As the illustration, it is the result of the italic angle about -30 and 30 degree.
It is valid only for the label thematic map in current version.
- Parameters:
value
- the angle of inclination of the font.
-
getOutline
public boolean getOutline()
Returns whether to outline and false indicates not to outline. The default value is false.- Returns:
- returns true if display the text with outline.
- Default:
- The default value is false that indicates the background is displayed without the outline.
-
setOutline
public void setOutline(boolean value)
Sets whether to use outline and false indicates not to outline. The default value is false.- Parameters:
value
- Whether to outline the text.
-
getRotation
public double getRotation()
Returns the rotation angle in degrees, with the rotation direction being anticlockwise.The rotation angle of the TextPart object after being stored with the data engine. The accuracy is 0.1 degrees. The rotation angle accuracy doesn't change for the TextPart constructed by the constructor.
- Returns:
- The rotation angle of the text.
- Default:
- The default value is 0.0.
-
setRotation
public void setRotation(double value)
Sets the rotation angle of text in the thematic map in degrees, with the rotation direction being anticlockwise. If you want to rotate common text, you can set the rotation of each child object of common using the interface TextPart.setRotation().- Parameters:
value
- The rotation angle of the text.
-
getShadow
public boolean getShadow()
Returns whether the text has shadow, true means add shadow to the text.- Returns:
- Returns true means the text has shadow; otherwise false.
- Default:
- The default value is false, representing the text is does not have shadow.
-
setShadow
public void setShadow(boolean value)
Sets whether the text has shadow, true means add shadow to the text.- Parameters:
value
- whether the specified text has shadow.
-
getStrikeout
public boolean getStrikeout()
Returns whether strikeout for the text, true means strikeout.- Returns:
- Returns true means strikeout the text; otherwise false.
- Default:
- false, that is do not strikeout.
-
setStrikeout
public void setStrikeout(boolean value)
Sets whether strikeout for the text, true means strikeout.- Parameters:
value
- Whether to strike out the text.
-
setBackOpaque
public void setBackOpaque(boolean value)
Sets the text background is opaque. True represents that the text background is opaque.- Parameters:
value
- Specifies whether the text background is opaque.
-
getUnderline
public boolean getUnderline()
Returns whether underline the text, true means underline.- Returns:
- Returns true means underline the text; otherwise false.
- Default:
- false, that is do not underline.
-
setUnderline
public void setUnderline(boolean value)
Sets whether underline the text, true means underline.- Parameters:
value
- Whether to underline the specified text.
-
getWeight
@Deprecated public int getWeight()
Deprecated.Returns the The value ranges from 0 and 900. For example, 400 represent normal and 700 represents bold. You can refer to the LOGFONT class in Microsoft MSDN help.- Returns:
- The size of the text font in points.
- Default:
- The default value of weight of font is 400 which represents normal.
-
setWeight
@Deprecated public void setWeight(int value)
Deprecated.Sets the value ranges from 0 and 900. For example, 400 represent normal and 700 represents bold. You can refer to the LOGFONT class in Microsoft MSDN help.- Parameters:
value
- The ponds of the text font.
-
clone
public TextStyle clone()
Returns a copy of the current TextStyle object. This object is a replica of this text style instance. Here the replica is a deep copy.- Overrides:
clone
in classjava.lang.Object
- Returns:
- The new TextStyle object generated from the clone operation.
-
toString
public java.lang.String toString()
Returns a formatted string that represents the current TextStyle object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A formatted string that indicates the current TextStyle.
-
getBackTransparency
public int getBackTransparency()
Gets the translucence of background.- Returns:
- The translucence of background.
-
setBackTransparency
public void setBackTransparency(int value)
Sets the transparent of the background.- Parameters:
value
- 0~255; 0 is transparent and 255 is opacity.
-
drawToPNG
public static boolean drawToPNG(Geometry geometry, Resources resources, java.lang.String fileName, int width, int height)
Draws the specified geometry object into image.- Parameters:
geometry
- The Geometry object.resources
- related resourcesfileName
- The path of the plotting file.width
- width.height
- Height.- Returns:
- Returns true if successful; otherwise false.
-
getFontScale
public double getFontScale()
Get the scale ratio of the label font.- Returns:
- scale ratio value.
-
setFontScale
public void setFontScale(double value)
Set the scale ratio of the label font.- Parameters:
value
- the specified scale ratio value.
-
-