Class DesignerGuides

java.lang.Object
com.iizigo.panel.DesignerGuides

public final class DesignerGuides extends Object
The store a Designer guide lives in: the $guides child of the panel's $designer container, an EditorDataPropCnr holding one EditorPropCnr per guide.

A guide is an integer pixel position relative to the top-left corner of the panel it belongs to, so guides are unique to one panel and are never copied or moved between panels. The name of a guide's container carries the axis and the order: x for a guide holding an x-position (a vertical line) and y for one holding a y-position (a horizontal line), followed by an integer starting at one - x1, x2, y1. The letter names the coordinate the guide stores, not the direction the line runs. The position itself is the IntProp named POSITION inside the guide's container, so that a guide can carry more than its position later without changing its shape.

EditorPropCnr is not index-based: usesPropIndex() is false, as for every PropCnr that does not override it, so nothing in the container enforces the order of its children and createUniqueAtom("x") would name the first guide x and the second x2. The number in the name is therefore what orders the guides, addGuide(UIPanelBase, char, int) chooses it, and getGuides(UIPanelBase, char) sorts by it. The whole store lives under $designer, which the property factory drops on every non-Designer load, so the runtime never receives a guide.

Nothing here paints, snaps or handles the pointer: this is storage, read by the client-side guide code. A guide change marks the panel changed through the property framework alone: $guides is an EditorDataPropCnr, which the file's save comparison sees, so a guide moved, added or removed compares against the state saved or loaded, and moved back it compares clean again.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    The axis letter of a guide holding an x-position, i.e.
    static final char
    The axis letter of a guide holding a y-position, i.e.
    static final String
    The name of the guides container under $designer.
    static final Atom
    The atom of the guides container.
    static final String
    The name of the integer position property inside a guide's container.
  • Method Summary

    Modifier and Type
    Method
    Description
    addGuide(UIPanelBase panel, char axis, int position)
    Adds a guide to a panel, named with the next free number on its axis: x1 when the panel has no x-guide, otherwise one past the highest number in use, so that a name is never reused while a higher one exists.
    static boolean
    Removes every guide of a panel.
    static int[]
    getGuides(UIPanelBase panel, char axis)
    Gets the guides of a panel on one axis, ordered by the number in their names, not by their position in the container.
    getGuidesCnr(UIPanelBase panel, boolean doCreate)
    Gets the guides container of a panel: $designer/$guides.
    static boolean
    Checks if a panel has any guide.
    static int
    numberOf(String name, char axis)
    The order number of a guide name on an axis: the positive integer after the axis letter, without a leading zero.
  • Field Details

    • GUIDES

      public static final String GUIDES
      The name of the guides container under $designer.
      See Also:
    • GUIDES_ATOM

      public static final Atom GUIDES_ATOM
      The atom of the guides container.
    • POSITION

      public static final String POSITION
      The name of the integer position property inside a guide's container.
      See Also:
    • AXIS_X

      public static final char AXIS_X
      The axis letter of a guide holding an x-position, i.e. a vertical line.
      See Also:
    • AXIS_Y

      public static final char AXIS_Y
      The axis letter of a guide holding a y-position, i.e. a horizontal line.
      See Also:
  • Method Details

    • getGuidesCnr

      public static EditorPropCnr getGuidesCnr(UIPanelBase panel, boolean doCreate)
      Gets the guides container of a panel: $designer/$guides. Created, it is an EditorDataPropCnr; found, it is whatever the file holds, so a panel saved before $guides became Designer data still answers its plain EditorPropCnr, whose guides paint but do not mark the panel changed until they are drawn again.
      Parameters:
      panel - The panel.
      doCreate - Flag to create $designer and $guides when not present.
      Returns:
      The guides container, or null if not present and not created, or if the panel is not an editor panel.
    • hasGuides

      public static boolean hasGuides(UIPanelBase panel)
      Checks if a panel has any guide.
      Parameters:
      panel - The panel.
      Returns:
      true if there is at least one guide on either axis.
    • getGuides

      public static int[] getGuides(UIPanelBase panel, char axis)
      Gets the guides of a panel on one axis, ordered by the number in their names, not by their position in the container.
      Parameters:
      panel - The panel.
      axis - AXIS_X or AXIS_Y.
      Returns:
      The positions in name order, an empty array for none.
      Throws:
      IllegalArgumentException - If the axis is not 'x' or 'y'.
    • addGuide

      public static EditorPropCnr addGuide(UIPanelBase panel, char axis, int position)
      Adds a guide to a panel, named with the next free number on its axis: x1 when the panel has no x-guide, otherwise one past the highest number in use, so that a name is never reused while a higher one exists.
      Parameters:
      panel - The panel.
      axis - AXIS_X or AXIS_Y.
      position - The pixel position relative to the top-left corner of the panel.
      Returns:
      The guide's container, added under $guides, or null if it could not be added.
      Throws:
      IllegalArgumentException - If the axis is not 'x' or 'y'.
    • clearGuides

      public static boolean clearGuides(UIPanelBase panel)
      Removes every guide of a panel. The $guides container is removed with them, so a panel without guides carries no empty container in its file.
      Parameters:
      panel - The panel.
      Returns:
      true if there was a guides container to remove, false otherwise.
    • numberOf

      public static int numberOf(String name, char axis)
      The order number of a guide name on an axis: the positive integer after the axis letter, without a leading zero. Public so that the client-side guide code and the tests share the one definition of what a guide name is.
      Parameters:
      name - The name, e.g. x12.
      axis - AXIS_X or AXIS_Y.
      Returns:
      The number, one or more, or zero if the name is not that axis letter followed by a positive integer.