Package edu.cnu.mdi.util
Class PropertyUtils
java.lang.Object
edu.cnu.mdi.util.PropertyUtils
Defines the standard MDI property keys and provides type-checked construction
and retrieval helpers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic Stringstatic Colorstatic Colorstatic Colorstatic final Rectangle2D.Doublestatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddWheelZoom(Properties props) Get the "wheel zoom" boolean flag.static PropertiesfromKeyValues(Object... keyValues) Create a set of properties from the key values.static doublegetAspectRatio(Properties props) Get an aspect ratio from the propertiesstatic ColorgetBackground(Properties props) Get the background color from the propertiesstatic StringgetBackgroundImage(Properties props) Get the full path of an image file to be used as a background image.static booleangetBoolean(Properties props, String key, boolean defaultVal) Get a boolean from properties.static ARubberband.PolicyGet the box-zoom rubberband policy from properties.static ColorgetColor(Properties props, String key, Color defaultValue) Get a color from a properties.static booleangetConnectable(Properties props) Get the item connectable boolean flag.static booleangetConsoleLog(Properties props) Get the "console log" boolean flag.static IContainergetContainer(Properties props) Get a container from the propertiesstatic booleangetDeletable(Properties props) Get the view deletable boolean flag.static doublegetDouble(Properties props, String key) Get a double from properties.static doublegetDouble(Properties props, String key, double defaultValue) Get a double from properties.static booleangetDoubleClickable(Properties props) Get the view double-clickable boolean flag.static booleangetDraggable(Properties props) Get the draggable boolean flag.static intgetFeedbackFontSize(Properties props) Get the feedback font sizestatic ColorgetFillColor(Properties props) Get the fill color from the propertiesstatic floatgetFloat(Properties props, String key) Get a float from properties.static floatgetFloat(Properties props, String key, float defaultValue) Get a float from properties.static doublegetFraction(Properties props) Get a fraction (maybe of screen, maybe of app) from the propertiesstatic intgetHeight(Properties props) Get a height from the propertiesstatic intgetInt(Properties props, String key, int defaultValue) Get an int from properties.static JComponentgetJComponent(Properties props, String key) Get a JComponent from properties.static intgetLeft(Properties props) Get the left location in pixels.static ColorgetLineColor(Properties props) Get the line color from the propertiesstatic LineStylegetLineStyle(Properties props) Get the line style from the properties.static floatgetLineWidth(Properties props) Get a line width from the propertiesstatic booleangetLocked(Properties props) Get the locked flag.static longgetLong(Properties props, String key, long defaultValue) Get a long from properties.static booleangetMaximize(Properties props) Get the view maximize boolean flag.static booleangetResizable(Properties props) Get the view resizable boolean flag.static booleangetRightClickable(Properties props) Get the view right-clickable boolean flag.static booleangetRotatable(Properties props) Get the item rotatable boolean flag.static booleangetScrollable(Properties props) Get the "scrollable" boolean flag.static JComponentgetSplitWestComponent(Properties props) Get an optional component used to split the west part of a viewstatic StringgetString(Properties props, String key, String defaultValue) Get a String from properties.static booleangetStyleEditable(Properties props) Get the style editable boolean flag.static SymbolTypegetSymbol(Properties props) Get a symbol from the propertiesstatic intgetSymbolSize(Properties props) Get the symbol size in pixelsstatic ColorgetTextColor(Properties props) Get the text color from the propertiesstatic StringgetTitle(Properties props) Get a titlestatic longgetToolbarBits(Properties props) Get the tool bar bits.static intgetTop(Properties props) Get the top location in pixels.static booleangetUseContainer(Properties props) Get the "use container" boolean flag.static ObjectgetUserData(Properties props) Get the optional user data.static booleangetVisible(Properties props) Get the "is visible" boolean flag.static intgetWidth(Properties props) Get a width from the propertiesstatic Rectangle2D.DoublegetWorldRectangle(Properties props, String key, Rectangle2D.Double defaultValue) Get a world rectanglestatic Rectangle2D.DoublegetWorldSystem(Properties props) Get a world coordinate systemstatic voidregisterKey(String key) Register a new key with an expected type of Object.static voidregisterKey(String key, Class<?> expectedType) Register a new key and its expected type.static voidregisterKeyOverwrite(String key, Class<?> expectedType) Register a new key and its expected type, allowing overwriting an existing registration.
-
Field Details
-
ASPECT
- See Also:
-
BACKGROUND
- See Also:
-
BACKGROUNDIMAGE
- See Also:
-
BOXZOOMRBPOLICY
- See Also:
-
CONNECTABLE
- See Also:
-
CONSOLELOG
- See Also:
-
CONTAINER
- See Also:
-
CONTAINERCLASS
- See Also:
-
CONTAINERFACTORY
- See Also:
-
DELETABLE
- See Also:
-
DOUBLECLICKABLE
- See Also:
-
DRAGGABLE
- See Also:
-
ADDFEEDBACK
- See Also:
-
FEEDBACKFONTSIZE
- See Also:
-
FILLCOLOR
- See Also:
-
FRACTION
- See Also:
-
HEIGHT
- See Also:
-
LEFT
- See Also:
-
LINECOLOR
- See Also:
-
LINESTYLE
- See Also:
-
LINEWIDTH
- See Also:
-
MAXIMIZE
- See Also:
-
LOCKED
- See Also:
-
RADIUS
- See Also:
-
RESIZABLE
- See Also:
-
RIGHTCLICKABLE
- See Also:
-
ROTATABLE
- See Also:
-
SCROLLABLE
- See Also:
-
SPLITWESTCOMPONENT
- See Also:
-
STYLEEDITABLE
- See Also:
-
SYMBOL
- See Also:
-
SYMBOLSIZE
- See Also:
-
TEXTCOLOR
- See Also:
-
TITLE
- See Also:
-
TOOLBARBITS
- See Also:
-
TOP
- See Also:
-
USECONTAINER
- See Also:
-
USERDATA
- See Also:
-
VISIBLE
- See Also:
-
WHEELZOOM
- See Also:
-
WIDTH
- See Also:
-
WORLDSYSTEM
- See Also:
-
ANGLE_X
- See Also:
-
ANGLE_Y
- See Also:
-
ANGLE_Z
- See Also:
-
DIST_X
- See Also:
-
DIST_Y
- See Also:
-
DIST_Z
- See Also:
-
defaultFillColor
-
defaultLineColor
-
defaultTextColor
-
defaultDataDir
-
unknownString
- See Also:
-
defaultWorldRect
-
-
Method Details
-
fromKeyValues
Create a set of properties from the key values.nullor an empty array yields an empty, validProperties. Otherwise the arguments must be an even-length sequence of alternating keys and values. Keys for known property names (see the constants in this class) are additionally checked against their expected value type; an unrecognized key is accepted with a logged warning rather than rejected, so custom keys remain usable.- Parameters:
keyValues- the set of key values- Returns:
- a set of properties
- Throws:
IllegalArgumentException- ifkeyValueshas an odd length, if any key is not aString, if any value isnull, or if a known key's value is not an instance of its expected type
-
registerKey
Register a new key and its expected type. This allows for extensibility while maintaining some level of type safety.- Parameters:
key- the property key to registerexpectedType- the expected type of the value associated with this key- Throws:
IllegalArgumentException- if the key is null/blank or expected type is nullIllegalStateException- if the key is already registered with a different expected type
-
registerKey
Register a new key with an expected type of Object. This is a more permissive registration that allows any type of value for the key.- Parameters:
key- the property key to register- Throws:
IllegalArgumentException- if key is null or blank
-
registerKeyOverwrite
Register a new key and its expected type, allowing overwriting an existing registration. This is a more permissive registration that allows changing the expected type of an already registered key.- Parameters:
key- the property key to registerexpectedType- the expected type of the value associated with this key- Throws:
IllegalArgumentException- if the key is null/blank or expected type is null
-
getUseContainer
Get the "use container" boolean flag.- Parameters:
props- the properties- Returns:
- the use container flag. On error, return true.
-
getConsoleLog
Get the "console log" boolean flag.- Parameters:
props- the properties- Returns:
- the console log flag. On error, return false.
-
getFeedbackFontSize
Get the feedback font size- Parameters:
props- the properties- Returns:
- the (clamped) feedback font size
-
getBackgroundImage
Get the full path of an image file to be used as a background image.- Parameters:
props- the properties- Returns:
- the file path. On error return
null.
-
getLeft
Get the left location in pixels.- Parameters:
props- the properties- Returns:
- the left location. On error, return 0.
-
getTop
Get the top location in pixels.- Parameters:
props- the properties- Returns:
- the top location. On error, return 0.
-
getVisible
Get the "is visible" boolean flag.- Parameters:
props- the properties- Returns:
- the visible flag. On error, return true.
-
getScrollable
Get the "scrollable" boolean flag.- Parameters:
props- the properties- Returns:
- the scrollable flag. On error, return false.
-
addWheelZoom
Get the "wheel zoom" boolean flag.- Parameters:
props- the properties- Returns:
- the wheel zoom flag. On error, return false.
-
getToolbarBits
Get the tool bar bits.- Parameters:
props- the properties- Returns:
- the toolbar bits. On error, return 0.
-
getDraggable
Get the draggable boolean flag.- Parameters:
props- the properties- Returns:
- the draggable flag. On error, return false.
-
getMaximize
Get the view maximize boolean flag. For views.- Parameters:
props- the properties- Returns:
- the maximize flag. On error, return false.
-
getConnectable
Get the item connectable boolean flag.- Parameters:
props- the properties- Returns:
- the connectable flag. On error, return false.
-
getDoubleClickable
Get the view double-clickable boolean flag. For views and items.- Parameters:
props- the properties- Returns:
- the double-clickable flag. On error, return false.
-
getDeletable
Get the view deletable boolean flag. For views and items.- Parameters:
props- the properties- Returns:
- the deletable flag. On error, return true.
-
getResizable
Get the view resizable boolean flag. For items.- Parameters:
props- the properties- Returns:
- the resizable flag. On error, return true.
-
getRightClickable
Get the view right-clickable boolean flag. For views and items.- Parameters:
props- the properties- Returns:
- the right-clickable flag. On error, return true.
-
getRotatable
Get the item rotatable boolean flag. For views.- Parameters:
props- the properties- Returns:
- the rotatable flag. On error, return false.
-
getStyleEditable
Get the style editable boolean flag. For items.- Parameters:
props- the properties- Returns:
- the style editable flag. On error, return false.
-
getWorldSystem
Get a world coordinate system- Parameters:
props- the properties- Returns:
- a world rectangle. On error, return defaultWorldRect
-
getTitle
Get a title- Parameters:
props- the properties- Returns:
- a title On error return unknownString.
-
getContainer
Get a container from the properties- Parameters:
props- the properties- Returns:
- an IContainer, on error return null
-
getFraction
Get a fraction (maybe of screen, maybe of app) from the properties- Parameters:
props- the properties- Returns:
- a (screen) fraction, by default return Double.NaN.
-
getAspectRatio
Get an aspect ratio from the properties- Parameters:
props- the properties- Returns:
- an aspect ratio used (optionally) to size views
-
getSplitWestComponent
Get an optional component used to split the west part of a view- Parameters:
props- the properties- Returns:
- the component
-
getSymbol
Get a symbol from the properties- Parameters:
props- the properties- Returns:
- a SymbolType, on error return SymbolType.SQUARE
-
getSymbolSize
Get the symbol size in pixels- Parameters:
props- the properties- Returns:
- get the symbol size (width and height) in pixels. On error return 8.
-
getUserData
Get the optional user data. This is any object that the user wants to attach to the shape.- Parameters:
props- the properties- Returns:
- the user data (might be
null).
-
getBackground
Get the background color from the properties- Parameters:
props- the properties- Returns:
- the background color. On error return null.
-
getTextColor
Get the text color from the properties- Parameters:
props- the properties- Returns:
- the text color. On error return
defaultTextColor.
-
getFillColor
Get the fill color from the properties- Parameters:
props- the properties- Returns:
- the fill color. On error return
defaultFillColor.
-
getLineColor
Get the line color from the properties- Parameters:
props- the properties- Returns:
- the line color. On error return
defaultLineColor.
-
getLineStyle
Get the line style from the properties.- Parameters:
props- the properties.- Returns:
- the linestyle. On error return LineStyle.SOLID.
-
getLineWidth
Get a line width from the properties- Parameters:
props- the properties- Returns:
- the width. On error return 0.
-
getWidth
Get a width from the properties- Parameters:
props- the properties- Returns:
- the width. On error return Integer.MIN_VALUE (-2^31 = -2147483648)
-
getHeight
Get a height from the properties- Parameters:
props- the properties- Returns:
- the height. On error return Integer.MIN_VALUE (-2^31 = -2147483648)
-
getLocked
Get the locked flag. (Default is true)- Parameters:
props- the properties- Returns:
- the locked flag
-
getWorldRectangle
public static Rectangle2D.Double getWorldRectangle(Properties props, String key, Rectangle2D.Double defaultValue) Get a world rectangle- Parameters:
props- the propertieskey- the keydefaultValue- the default value- Returns:
- the world rectangle, or defaultValue upon failure.
-
getColor
Get a color from a properties. Tries to handle both a String (from the X11 database, e.g. "coral", "red", "powder blue") and a Java Color value.- Parameters:
props- the propertieskey- the keydefaultValue- the default value- Returns:
- the color, or defaultValue upon failure.
-
getJComponent
Get a JComponent from properties.- Parameters:
props- the propertieskey- the key- Returns:
- the JComponent value, or on error
null.
-
getBoxZoomRubberbandPolicy
Get the box-zoom rubberband policy from properties.- Parameters:
props- the properties- Returns:
- the rubberband policy. On error return null.
-
getString
Get a String from properties.- Parameters:
props- the propertieskey- the keydefaultValue- the default value- Returns:
- the String value, or on error the default value.
-
getInt
Get an int from properties. Tries to handle both a String (e.g., "67") and Integer value.- Parameters:
props- the propertieskey- the keydefaultValue- the default value- Returns:
- the integer value, or on error the default value.
-
getLong
Get a long from properties. Tries to handle both a String (e.g., "67") and Long value.- Parameters:
props- the propertieskey- the keydefaultValue- the default value- Returns:
- the integer value, or on error the default value.
-
getDouble
Get a double from properties. Tries to handle both a String (e.g., "67.0") and Double value.- Parameters:
props- the propertieskey- the key- Returns:
- the double value, or on error return Double.NaN.
-
getDouble
Get a double from properties. Tries to handle both a String (e.g., "67.0") and Double value.- Parameters:
props- the propertieskey- the keydefaultValue- the default value- Returns:
- the double value, or on error return defaultValue
-
getFloat
Get a float from properties. Tries to handle both a String (e.g., "67.0") and Float value.- Parameters:
props- the propertieskey- the key- Returns:
- the double value, or on error return Float.NaN.
-
getFloat
Get a float from properties. Tries to handle both a String (e.g., "67.0") and Float value.- Parameters:
props- the propertieskey- the keydefaultValue- the default value- Returns:
- the double value, or on error return defaultValue
-
getBoolean
Get a boolean from properties. Tries to handle both a String (e.g., "true") and Boolean value.- Parameters:
props- the propertieskey- the keydefaultVal- the default value- Returns:
- the boolean value, or on error the default
-