Class PropertyUtils

java.lang.Object
edu.cnu.mdi.util.PropertyUtils

public final class PropertyUtils extends Object
Defines the standard MDI property keys and provides type-checked construction and retrieval helpers.
  • Field Details

  • Method Details

    • fromKeyValues

      public static Properties fromKeyValues(Object... keyValues)
      Create a set of properties from the key values.

      null or an empty array yields an empty, valid Properties. 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 - if keyValues has an odd length, if any key is not a String, if any value is null, or if a known key's value is not an instance of its expected type
    • registerKey

      public static void registerKey(String key, Class<?> expectedType)
      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 register
      expectedType - the expected type of the value associated with this key
      Throws:
      IllegalArgumentException - if the key is null/blank or expected type is null
      IllegalStateException - if the key is already registered with a different expected type
    • registerKey

      public static void registerKey(String key)
      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

      public static void registerKeyOverwrite(String key, Class<?> expectedType)
      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 register
      expectedType - the expected type of the value associated with this key
      Throws:
      IllegalArgumentException - if the key is null/blank or expected type is null
    • getUseContainer

      public static boolean getUseContainer(Properties props)
      Get the "use container" boolean flag.
      Parameters:
      props - the properties
      Returns:
      the use container flag. On error, return true.
    • getConsoleLog

      public static boolean getConsoleLog(Properties props)
      Get the "console log" boolean flag.
      Parameters:
      props - the properties
      Returns:
      the console log flag. On error, return false.
    • getFeedbackFontSize

      public static int getFeedbackFontSize(Properties props)
      Get the feedback font size
      Parameters:
      props - the properties
      Returns:
      the (clamped) feedback font size
    • getBackgroundImage

      public static String getBackgroundImage(Properties props)
      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

      public static int getLeft(Properties props)
      Get the left location in pixels.
      Parameters:
      props - the properties
      Returns:
      the left location. On error, return 0.
    • getTop

      public static int getTop(Properties props)
      Get the top location in pixels.
      Parameters:
      props - the properties
      Returns:
      the top location. On error, return 0.
    • getVisible

      public static boolean getVisible(Properties props)
      Get the "is visible" boolean flag.
      Parameters:
      props - the properties
      Returns:
      the visible flag. On error, return true.
    • getScrollable

      public static boolean getScrollable(Properties props)
      Get the "scrollable" boolean flag.
      Parameters:
      props - the properties
      Returns:
      the scrollable flag. On error, return false.
    • addWheelZoom

      public static boolean addWheelZoom(Properties props)
      Get the "wheel zoom" boolean flag.
      Parameters:
      props - the properties
      Returns:
      the wheel zoom flag. On error, return false.
    • getToolbarBits

      public static long getToolbarBits(Properties props)
      Get the tool bar bits.
      Parameters:
      props - the properties
      Returns:
      the toolbar bits. On error, return 0.
    • getDraggable

      public static boolean getDraggable(Properties props)
      Get the draggable boolean flag.
      Parameters:
      props - the properties
      Returns:
      the draggable flag. On error, return false.
    • getMaximize

      public static boolean getMaximize(Properties props)
      Get the view maximize boolean flag. For views.
      Parameters:
      props - the properties
      Returns:
      the maximize flag. On error, return false.
    • getConnectable

      public static boolean getConnectable(Properties props)
      Get the item connectable boolean flag.
      Parameters:
      props - the properties
      Returns:
      the connectable flag. On error, return false.
    • getDoubleClickable

      public static boolean getDoubleClickable(Properties props)
      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

      public static boolean getDeletable(Properties props)
      Get the view deletable boolean flag. For views and items.
      Parameters:
      props - the properties
      Returns:
      the deletable flag. On error, return true.
    • getResizable

      public static boolean getResizable(Properties props)
      Get the view resizable boolean flag. For items.
      Parameters:
      props - the properties
      Returns:
      the resizable flag. On error, return true.
    • getRightClickable

      public static boolean getRightClickable(Properties props)
      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

      public static boolean getRotatable(Properties props)
      Get the item rotatable boolean flag. For views.
      Parameters:
      props - the properties
      Returns:
      the rotatable flag. On error, return false.
    • getStyleEditable

      public static boolean getStyleEditable(Properties props)
      Get the style editable boolean flag. For items.
      Parameters:
      props - the properties
      Returns:
      the style editable flag. On error, return false.
    • getWorldSystem

      public static Rectangle2D.Double getWorldSystem(Properties props)
      Get a world coordinate system
      Parameters:
      props - the properties
      Returns:
      a world rectangle. On error, return defaultWorldRect
    • getTitle

      public static String getTitle(Properties props)
      Get a title
      Parameters:
      props - the properties
      Returns:
      a title On error return unknownString.
    • getContainer

      public static IContainer getContainer(Properties props)
      Get a container from the properties
      Parameters:
      props - the properties
      Returns:
      an IContainer, on error return null
    • getFraction

      public static double getFraction(Properties props)
      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

      public static double getAspectRatio(Properties props)
      Get an aspect ratio from the properties
      Parameters:
      props - the properties
      Returns:
      an aspect ratio used (optionally) to size views
    • getSplitWestComponent

      public static JComponent getSplitWestComponent(Properties props)
      Get an optional component used to split the west part of a view
      Parameters:
      props - the properties
      Returns:
      the component
    • getSymbol

      public static SymbolType getSymbol(Properties props)
      Get a symbol from the properties
      Parameters:
      props - the properties
      Returns:
      a SymbolType, on error return SymbolType.SQUARE
    • getSymbolSize

      public static int getSymbolSize(Properties props)
      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

      public static Object getUserData(Properties props)
      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

      public static Color getBackground(Properties props)
      Get the background color from the properties
      Parameters:
      props - the properties
      Returns:
      the background color. On error return null.
    • getTextColor

      public static Color getTextColor(Properties props)
      Get the text color from the properties
      Parameters:
      props - the properties
      Returns:
      the text color. On error return defaultTextColor.
    • getFillColor

      public static Color getFillColor(Properties props)
      Get the fill color from the properties
      Parameters:
      props - the properties
      Returns:
      the fill color. On error return defaultFillColor.
    • getLineColor

      public static Color getLineColor(Properties props)
      Get the line color from the properties
      Parameters:
      props - the properties
      Returns:
      the line color. On error return defaultLineColor.
    • getLineStyle

      public static LineStyle getLineStyle(Properties props)
      Get the line style from the properties.
      Parameters:
      props - the properties.
      Returns:
      the linestyle. On error return LineStyle.SOLID.
    • getLineWidth

      public static float getLineWidth(Properties props)
      Get a line width from the properties
      Parameters:
      props - the properties
      Returns:
      the width. On error return 0.
    • getWidth

      public static int getWidth(Properties props)
      Get a width from the properties
      Parameters:
      props - the properties
      Returns:
      the width. On error return Integer.MIN_VALUE (-2^31 = -2147483648)
    • getHeight

      public static int getHeight(Properties props)
      Get a height from the properties
      Parameters:
      props - the properties
      Returns:
      the height. On error return Integer.MIN_VALUE (-2^31 = -2147483648)
    • getLocked

      public static boolean getLocked(Properties props)
      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 properties
      key - the key
      defaultValue - the default value
      Returns:
      the world rectangle, or defaultValue upon failure.
    • getColor

      public static Color getColor(Properties props, String key, Color defaultValue)
      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 properties
      key - the key
      defaultValue - the default value
      Returns:
      the color, or defaultValue upon failure.
    • getJComponent

      public static JComponent getJComponent(Properties props, String key)
      Get a JComponent from properties.
      Parameters:
      props - the properties
      key - the key
      Returns:
      the JComponent value, or on error null.
    • getBoxZoomRubberbandPolicy

      public static ARubberband.Policy getBoxZoomRubberbandPolicy(Properties props)
      Get the box-zoom rubberband policy from properties.
      Parameters:
      props - the properties
      Returns:
      the rubberband policy. On error return null.
    • getString

      public static String getString(Properties props, String key, String defaultValue)
      Get a String from properties.
      Parameters:
      props - the properties
      key - the key
      defaultValue - the default value
      Returns:
      the String value, or on error the default value.
    • getInt

      public static int getInt(Properties props, String key, int defaultValue)
      Get an int from properties. Tries to handle both a String (e.g., "67") and Integer value.
      Parameters:
      props - the properties
      key - the key
      defaultValue - the default value
      Returns:
      the integer value, or on error the default value.
    • getLong

      public static long getLong(Properties props, String key, long defaultValue)
      Get a long from properties. Tries to handle both a String (e.g., "67") and Long value.
      Parameters:
      props - the properties
      key - the key
      defaultValue - the default value
      Returns:
      the integer value, or on error the default value.
    • getDouble

      public static double getDouble(Properties props, String key)
      Get a double from properties. Tries to handle both a String (e.g., "67.0") and Double value.
      Parameters:
      props - the properties
      key - the key
      Returns:
      the double value, or on error return Double.NaN.
    • getDouble

      public static double getDouble(Properties props, String key, double defaultValue)
      Get a double from properties. Tries to handle both a String (e.g., "67.0") and Double value.
      Parameters:
      props - the properties
      key - the key
      defaultValue - the default value
      Returns:
      the double value, or on error return defaultValue
    • getFloat

      public static float getFloat(Properties props, String key)
      Get a float from properties. Tries to handle both a String (e.g., "67.0") and Float value.
      Parameters:
      props - the properties
      key - the key
      Returns:
      the double value, or on error return Float.NaN.
    • getFloat

      public static float getFloat(Properties props, String key, float defaultValue)
      Get a float from properties. Tries to handle both a String (e.g., "67.0") and Float value.
      Parameters:
      props - the properties
      key - the key
      defaultValue - the default value
      Returns:
      the double value, or on error return defaultValue
    • getBoolean

      public static boolean getBoolean(Properties props, String key, boolean defaultVal)
      Get a boolean from properties. Tries to handle both a String (e.g., "true") and Boolean value.
      Parameters:
      props - the properties
      key - the key
      defaultVal - the default value
      Returns:
      the boolean value, or on error the default