📄 annotationattributes.java
字号:
}
/**
* Get the background image offset in pixels (before background scaling).
* @return the background image offset in pixels
*/
public Point getImageOffset()
{
return this.imageOffset != null ? this.imageOffset : defaultAttributes.getImageOffset();
}
/**
* Set the background image offset in pixels (before background scaling). Set to <code>null</code> to use the
* default value.
* @param offset the background image offset in pixels
*/
public void setImageOffset(Point offset)
{
this.imageOffset = offset;
}
/**
* Get the opacity of the background image (0 to 1).
* @return the opacity of the background image (0 to 1).
*/
public double getImageOpacity()
{
return this.imageOpacity >= 0 ? this.imageOpacity : defaultAttributes.getImageOpacity();
}
/**
* Set the opacity of the background image (0 to 1). Set to minus one (<code>-1</code>) to use the default value.
* @param opacity the opacity of the background image (0 to 1).
*/
public void setImageOpacity(double opacity)
{
this.imageOpacity = opacity;
}
/**
* Get the repeat behavior or the background image. Can be one of {@link Annotation}.IMAGE_REPEAT_X,
* IMAGE_REPEAT_Y, IMAGE_REPEAT_XY (default) or IMAGE_REPEAT_NONE.
* @return the repeat behavior or the background image.
*/
public String getImageRepeat()
{
return this.imageRepeat != null ? this.imageRepeat : defaultAttributes.getImageRepeat();
}
/**
* Set the repeat behavior or the background image. Can be one of {@link Annotation}.IMAGE_REPEAT_X,
* IMAGE_REPEAT_Y, IMAGE_REPEAT_XY (default) or IMAGE_REPEAT_NONE. Set to <code>null</code> to use
* the default value.
* @param repeat the repeat behavior or the background image.
*/
public void setImageRepeat(String repeat)
{
this.imageRepeat = repeat;
}
/**
* Get the path to the image used for background image. Returns <code>null</code> if the image source is null
* or a memory BufferedImage.
* @return the path to the image used for background image.
*/
public String getPath()
{
return this.imageSource instanceof String ? (String) this.imageSource : null;
}
/**
* Get the minimum scale that can be applied to an annotation when it gets farther away from the eye than the view
* lookat point.
* @return the minimum scale that can be applied to an annotation when it gets away from the eye
*/
public double getDistanceMinScale()
{
return this.distanceMinScale >= 0 ? this.distanceMinScale : defaultAttributes.getDistanceMinScale();
}
/**
* Set the minimum scale that can be applied to an annotation when it gets farther away from the eye than the view
* lookat point. Set to minus one (<code>-1</code>) to use the default value.
* @param scale the minimum scale that can be applied to an annotation when it gets away from the eye
*/
public void setDistanceMinScale(double scale)
{
this.distanceMinScale = scale;
}
/**
* Get the maximum scale that can be applied to an annotation when it gets closer to the eye than the view
* lookat point.
* @return the maximum scale that can be applied to an annotation when it gets closer to the eye
*/
public double getDistanceMaxScale()
{
return this.distanceMaxScale >= 0 ? this.distanceMaxScale : defaultAttributes.getDistanceMaxScale();
}
/**
* Set the maximum scale that can be applied to an annotation when it gets closer to the eye than the view
* lookat point. Set to minus one (<code>-1</code>) to use the default value.
* @param scale the maximum scale that can be applied to an annotation when it gets closer to the eye
*/
public void setDistanceMaxScale(double scale)
{
this.distanceMaxScale = scale;
}
/**
* Get the minimum opacity an annotation can have when fading away from the eye (0 to 1).
* @return the minimum opacity an annotation can have when fading away from the eye.
*/
public double getDistanceMinOpacity()
{
return this.distanceMinOpacity >= 0 ? this.distanceMinOpacity : defaultAttributes.getDistanceMinOpacity();
}
/**
* Set the minimum opacity an annotation can have when fading away from the eye (0 to 1). Set to minus one
* (<code>-1</code>) to use the default value.
* @param opacity the minimum opacity an annotation can have when fading away from the eye.
*/
public void setDistanceMinOpacity(double opacity)
{
this.distanceMinOpacity = opacity;
}
/**
* Get the effect used to decorate the text. Can be one of {@link MultiLineTextRenderer}.EFFECT_SHADOW,
* EFFECT_OUTLINE or EFFECT_NONE (default).
* @return the effect used for text rendering
*/
public String getEffect()
{
return this.effect != null ? this.effect : defaultAttributes.getEffect();
}
/**
* Set the effect used to decorate the text. Can be one of {@link MultiLineTextRenderer}.EFFECT_SHADOW,
* EFFECT_OUTLINE or EFFECT_NONE (default). Set to <code>null</code> to use the default value.
* @param effect the effect to use for text rendering
*/
public void setEffect(String effect)
{
this.effect = effect;
}
/**
* Returns an XML state document String describing attributes that have been set by the application
* (attributes not pointing to their default value).
*
* @return XML state document string describing this AnnotationAttributes.
*/
public String getRestorableState()
{
RestorableSupport restorableSupport = RestorableSupport.newRestorableSupport();
// Creating a new RestorableSupport failed. RestorableSupport logged the problem, so just return null.
if (restorableSupport == null)
return null;
// Save application set attributes to the document root.
saveAttributes(this, restorableSupport, null);
// We only save this AnnotationAttributes' defaultAttributes when the application has set them to
// something other than the static member "defaults".
if (this.defaultAttributes != AnnotationAttributes.defaults)
{
RestorableSupport.StateObject defaultAttributesStateObj =
restorableSupport.addStateObject("defaultAttributes");
saveAttributes(this.defaultAttributes, restorableSupport, defaultAttributesStateObj);
}
return restorableSupport.getStateAsXml();
}
/**
* Restores attribute values found in the specified XML state document String. The document specified by
* <code>stateInXml</code> must be a well formed XML document String, or this will throw an
* IllegalArgumentException. Unknown structures in <code>stateInXml</code> are benign, because they will
* simply be ignored.
*
* @param stateInXml an XML document String describing an AnnotationAttributes.
* @throws IllegalArgumentException If <code>stateInXml</code> is null, or if <code>stateInXml</code> is not
* a well formed XML document String.
*/
public void restoreState(String stateInXml)
{
if (stateInXml == null)
{
String message = Logging.getMessage("nullValue.StringIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
RestorableSupport restorableSupport;
try
{
restorableSupport = RestorableSupport.parse(stateInXml);
}
catch (Exception e)
{
// Parsing the document specified by stateInXml failed.
String message = Logging.getMessage("generic.ExceptionAttemptingToParseStateXml", stateInXml);
Logging.logger().severe(message);
throw new IllegalArgumentException(message, e);
}
// Restore application set attributes from under the document root.
restoreAttributes(restorableSupport, null, this);
// Restore application set default attributes from under the "defaultAttributes" state element.
RestorableSupport.StateObject defaultAttributesStateObj =
restorableSupport.getStateObject("defaultAttributes");
if (defaultAttributesStateObj != null)
{
AnnotationAttributes newDefaultAttributes = this.defaultAttributes;
// We do not want to write to the static member "defaults". So if this AnnotationAttributes' does not
// have it's own defaultAttributes instance, we create one for it
if (newDefaultAttributes == AnnotationAttributes.defaults)
newDefaultAttributes = new AnnotationAttributes();
restoreAttributes(restorableSupport, defaultAttributesStateObj, newDefaultAttributes);
setDefaults(newDefaultAttributes);
}
}
/**
* Save the attributes specified by <code>source</code> in the specified <code>restorableSupport</code>.
* Only attributes that have been set by the application (attributes not pointing to their default value) will
* be saved. If <code>context</code> is not null, attributes will be saved beneath it. Otherwise, they will
* be saved at the document root.
*
* @param source the AnnotationAttriubutes to save.
* @param restorableSupport RestorableSupport to write attribute values to.
* @param context RestorableSupport.StateObject that attributes will be saved under, if not null.
* @throws IllegalArgumentException If either <code>source</code> or <code>restorableSupport</code> is null.
*/
private static void saveAttributes(AnnotationAttributes source,
RestorableSupport restorableSupport,
RestorableSupport.StateObject context)
{
if (source == null || restorableSupport == null)
throw new IllegalArgumentException();
if (source.frameShape != null)
restorableSupport.addStateValueAsString(context, "frameShape", source.frameShape);
restorableSupport.addStateValueAsBoolean(context, "highlighted", source.isHighlighted);
if (source.highlightScale >= 0)
restorableSupport.addStateValueAsDouble(context, "highlightScale", source.highlightScale);
if (source.size != null)
{
RestorableSupport.StateObject sizeStateObj = restorableSupport.addStateObject(context, "size");
if (sizeStateObj != null)
{
restorableSupport.addStateValueAsDouble(sizeStateObj, "width", source.size.getWidth());
restorableSupport.addStateValueAsDouble(sizeStateObj, "height", source.size.getHeight());
}
}
if (source.scale >= 0)
restorableSupport.addStateValueAsDouble(context, "scale", source.scale);
if (source.opacity >= 0)
restorableSupport.addStateValueAsDouble(context, "opacity", source.opacity);
if (source.leader != null)
restorableSupport.addStateValueAsString(context, "leader", source.leader);
if (source.cornerRadius >= 0)
restorableSupport.addStateValueAsInteger(context, "cornerRadius", source.cornerRadius);
if (source.adjustWidthToText != null)
restorableSupport.addStateValueAsString(context, "adjustWidthToText", source.adjustWidthToText);
if (source.drawOffset != null)
{
RestorableSupport.StateObject drawOffsetStateObj = restorableSupport.addStateObject(context, "drawOffset");
if (drawOffsetStateObj != null)
{
restorableSupport.addStateValueAsDouble(drawOffsetStateObj, "x", source.drawOffset.getX());
restorableSupport.addStateValueAsDouble(drawOffsetStateObj, "y", source.drawOffset.getY());
}
}
if (source.insets != null)
{
RestorableSupport.StateObject insetsStateObj = restorableSupport.addStateObject(context, "insets");
if (insetsStateObj != null)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -