📄 annotationattributes.java
字号:
/*
Copyright (C) 2001, 2006, 2007 United States Government
as represented by the Administrator of the
National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.render;
import gov.nasa.worldwind.Restorable;
import gov.nasa.worldwind.util.Logging;
import gov.nasa.worldwind.util.RestorableSupport;
import java.awt.*;
/**
* {@link Annotation} attributes set. All {@link AbstractAnnotation} objects start life
* referencing a new instance of this object.
* <p>
* This class also defines a static <b>default</b> attributes bundle containing default values for all attributes.
* New <code>AnnotationAttributes</code> refer this static bundle as their default values source when an
* attribute has not been set.
* </p>
* <p>
* New <code>AnnotationAttributes</code> set have all their attributes pointing to the default values until
* they are set by the application. Most attributes refer to the default value by using minus one (<code>-1</code>)
* for munerics and <code>null</code> for objects.
* </p>
* <p>
* The default attributes set can be changed for a non static one under the application control. The process
* can be extended or cascaded to handle multiple levels of inheritance for default attributes.
* </p>
* @author Patrick Murris
* @version $Id: AnnotationAttributes.java 10542 2009-04-27 17:28:30Z dcollins $
* @see AbstractAnnotation
* @see FrameFactory
* @see MultiLineTextRenderer
*/
public class AnnotationAttributes implements Restorable
{
private static final AnnotationAttributes defaults = new AnnotationAttributes();
static
{
defaults.setFrameShape(FrameFactory.SHAPE_RECTANGLE);
defaults.setSize(new Dimension(160, 0));
defaults.setScale(1);
defaults.setOpacity(1);
defaults.setLeader(FrameFactory.LEADER_TRIANGLE);
defaults.setCornerRadius(20);
defaults.setAdjustWidthToText(Annotation.SIZE_FIT_TEXT);
defaults.setDrawOffset(new Point(40, 60));
defaults.setHighlightScale(1.2);
defaults.setInsets(new Insets(20, 15, 15, 15));
defaults.setFont(Font.decode("Arial-PLAIN-12"));
defaults.setTextAlign(MultiLineTextRenderer.ALIGN_LEFT);
defaults.setTextColor(Color.BLACK);
defaults.setBackgroundColor(Color.WHITE);
defaults.setBorderColor(new Color(171, 171, 171));
defaults.setBorderWidth(1);
defaults.setBorderStippleFactor(0);
defaults.setBorderStipplePattern((short)0xAAAA);
defaults.setAntiAliasHint(Annotation.ANTIALIAS_NICEST);
defaults.setImageScale(1);
defaults.setImageOffset(new Point(0, 0));
defaults.setImageOpacity(1);
defaults.setImageRepeat(Annotation.IMAGE_REPEAT_XY);
defaults.setDistanceMinScale(1);
defaults.setDistanceMaxScale(1);
defaults.setDistanceMinOpacity(.3);
defaults.setEffect(MultiLineTextRenderer.EFFECT_NONE);
}
private AnnotationAttributes defaultAttributes = defaults;
private String frameShape; // Use default (null)
private Dimension size; // Use default (null)
private double scale = -1; // Use default (-1)
private double opacity = -1; // Use default (-1)
private String leader; // Use default (null)
private int cornerRadius = -1; // Use default (-1)
private String adjustWidthToText; // Use default (null)
private Point drawOffset; // Use default (null)
private boolean isHighlighted = false;
private boolean isVisible = true;
private double highlightScale = -1; // Use default (-1)
private Font font; // Use default (null)
private int textAlign = -1; // Use default (-1)
private Color textColor; // Use default (null)
private Color backgroundColor; // Use default (null)
private Color borderColor; // Use default (null)
private double borderWidth = -1; // Use default (-1)
private int borderStippleFactor = -1; // Use default (-1)
private short borderStipplePattern = (short) 0x0000; // Use default (zero)
private int antiAliasHint = -1; // Use default (-1)
private Insets insets; // Use default (null)
private Object imageSource;
private double imageScale = -1; // Use default (-1)
private Point imageOffset; // Use default (null)
private double imageOpacity = -1; // Use default (-1)
private String imageRepeat; // Use default (null)
private double distanceMinScale = -1; // Use default (-1)
private double distanceMaxScale = -1; // Use default (-1)
private double distanceMinOpacity = -1; // Use default (-1)
private String effect; // Use default (null)
//** Public properties **********************************************************************
/**
* Set the fallback default attributes set.
* @param attr the default attributes set.
*/
public void setDefaults(AnnotationAttributes attr)
{
if (attr == null)
{
String message = Logging.getMessage("nullValue.AnnotationAttributesIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.defaultAttributes = attr;
}
/**
* Get the callout frame shape. Can be one of {@link FrameFactory}.SHAPE_RECTANGLE (default), SHAPE_ELLIPSE
* or SHAPE_NONE.
* @return the callout frame shape.
*/
public String getFrameShape()
{
return this.frameShape != null ? this.frameShape : defaultAttributes.getFrameShape();
}
/**
* Set the callout frame shape. Can be one of {@link FrameFactory}.SHAPE_RECTANGLE (default), SHAPE_ELLIPSE
* or SHAPE_NONE. Set to <code>null</code> to use the default shape.
* <p>
* Note that SHAPE_ELLIPSE draws an ellipse <u>inside</u> the callout bounding rectangle set by its
* size (see setSize()) or its text bounding rectangle (see setAdjustWidthToText() and setSize() with height
* set to zero). It is often necessary to have larger Insets dimensions (see setInsets()) to avoid having
* the text drawn outside the shape border.
* </p>
* @param shape the callout frame shape.
*/
public void setFrameShape(String shape)
{
this.frameShape = shape;
}
/**
* Get whether the <code>Annotation</code> is highlighted and should be drawn bigger - see setHighlightScale().
* @return true if highlighted.
*/
public boolean isHighlighted()
{
return isHighlighted;
}
/**
* Set whether the <code>Annotation</code> is highlighted and should be drawn bigger - see setHighlightScale().
* @param highlighted true if highlighted.
*/
public void setHighlighted(boolean highlighted)
{
isHighlighted = highlighted;
}
/**
* Get the scaling factor applied to highlighted <code>Annotations</code>.
* @return the scaling factor applied to highlighted <code>Annotations</code>.
*/
public double getHighlightScale()
{
return highlightScale > 0 ? this.highlightScale : defaultAttributes.getHighlightScale();
}
/**
* Set the scaling factor applied to highlighted <code>Annotations</code>. Set to minus one (<code>-1</code>)
* to use the default value.
* @param highlightScale the scaling factor applied to highlighted <code>Annotations</code>.
*/
public void setHighlightScale(double highlightScale)
{
this.highlightScale = highlightScale;
}
/**
* Get the annotation callout preferred total dimension in pixels.
* @return the callout preferred total dimension in pixels.
*/
public Dimension getSize()
{
return this.size != null ? this.size : defaultAttributes.getSize();
}
/**
* Set the annotation callout preferred total dimension in pixels.
* <p>
* If necessary, the text will be wraped into several lines so as not to exceed the callout preferred
* <code><b>width</b></code> (minus the <code>Insets</code> <code>left</code> and <code>right</code> dimensions
* - see setInsets()).
* However, if setAdjustWidthToText() is set to true, the final callout width will follow that of the final
* text bounding rectangle.
* </p>
* <p>
* If necessary, the text will also be truncated so as not to exceed the given <code><b>height</b></code>.
* A <code>zero</code> value (default) will have the callout follow the final text bounding rectangle height
* (including the <code>Insets</code> <code>top</code> and <code>bottom</code>).
* </p>
* Set to <code>null</code> to use the default size.
* @param size the callout preferred total dimension in pixels.
*/
public void setSize(Dimension size)
{
this.size = size;
}
/**
* Get the scaling factor applied to the annotation. Default is 1.
* @return the scaling factor applied to the annotation
*/
public double getScale()
{
return this.scale >= 0 ? this.scale : defaultAttributes.getScale();
}
/**
* Set the scaling factor to apply to the annotation. Default is 1.
* Set to minus one (<code>-1</code>) to use the default value.
* @param scale the scaling factor to apply to the annotation
*/
public void setScale(double scale)
{
this.scale = scale;
}
/**
* Get the opacity factor applied to the annotation. Default is 1.
* @return the opacity factor applied to the annotation
*/
public double getOpacity()
{
return this.opacity >= 0 ? this.opacity : defaultAttributes.getOpacity();
}
/**
* Set the opacity factor to apply to the annotation. Default is 1.
* Set to minus one (<code>-1</code>) to use the default value.
* @param opacity the opacity factor to apply to the annotation
*/
public void setOpacity(double opacity)
{
this.opacity = opacity;
}
/**
* Get the callout shape leader type. Can be one of {@link FrameFactory}.LEADER_TRIANGLE (default) or LEADER_NONE.
* @return the callout shape leader type.
*/
public String getLeader()
{
return this.leader != null ? this.leader : defaultAttributes.getLeader();
}
/**
* Set the callout shape leader type. Can be one of {@link FrameFactory}.LEADER_TRIANGLE (default) or LEADER_NONE.
* @param leader the callout shape leader type.
*/
public void setLeader(String leader)
{
this.leader = leader;
}
/**
* Get the callout shape rounded corners radius in pixels. A value of <code>zero</code> means no rounded corners.
* @return the callout shape rounded corners radius in pixels.
*/
public int getCornerRadius()
{
return this.cornerRadius >= 0 ? this.cornerRadius : defaultAttributes.getCornerRadius();
}
/**
* Set the callout shape rounded corners radius in pixels. A value of <code>zero</code> means no rounded corners.
* Set this attribute to minus one (<code>-1</code>) to use the default value.
* @param radius the callout shape rounded corners radius in pixels.
*/
public void setCornerRadius(int radius)
{
this.cornerRadius = radius;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -