Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Set a single attribute.
- * @param key the attribute to set
- * @param value the value to set it to
- * @return if successful
- */
- boolean setAttr(Attr key, Object value);
- /**
- * Get an attribute but return our own default if it doesn't exist.
- * @param key the attribute to get
- * @param def the default if it doesn't exist
- * @return the value
- */
- Object getAttr(Attr key, Object def);
- /**
- * Get an attribute, return null if not found.
- * @param key the attribute to get
- * @return the value
- */
- Object getAttr(Attr key);
- /**
- * Check if an attribute has been set.
- * @param key the attribute to check
- * @return if it exists
- */
- boolean hasAttr(Attr key);
- /** All attribute enums need to implement this. */
- interface Attr {
- /**
- * Get the allowed types for an attribute.
- * By default attributes should accept Integer, however String and Enum
- * are both common types.
- * @return the allowed class
- */
- Class getType();
- /**
- * Get the default value for an attribute (if set).
- * @return the default value
- */
- Object getDefault();
- }
- /**
- * Used for set/get etc.
- */
- enum WidgetAttr implements Attr {
- /** Widget top offset. */
- TOP,
- /** Widget right offset. */
- RIGHT,
- /** Widget bottom offset. */
- BOTTOM,
- /** Widget left offset. */
- LEFT,
- /** Widget width. */
- WIDTH,
- /** Widget minimum width. */
- MIN_WIDTH,
- /** Widget maximum width. */
- MAX_WIDTH,
- /** Widget height. */
- HEIGHT,
- /** Widget minimum height. */
- MIN_HEIGHT,
- /** Widget maximum height. */
- MAX_HEIGHT,
- /** Tooltip on mouse hover. */
- TOOLTIP(String.class),
- /** How to display the widget "box". */
- DISPLAY(Display.class),
- /** What to do when the content overflows the box. */
- OVERFLOW(Overflow.class),
- /** Where to layout. */
- POSITION(Position.class),
- /** Padding top size. */
- PADDING_TOP,
- /** Padding right size. */
- PADDING_RIGHT,
- /** Padding bottom size. */
- PADDING_BOTTOM,
- /** Padding left size. */
- PADDING_LEFT,
- /** Border top size. */
- BORDER_TOP,
- /** Border top color. */
- BORDER_TOP_COLOR(Color.class),
- /** Border top style. */
- BORDER_TOP_STYLE(Border.class),
- /** Border right size. */
- BORDER_RIGHT,
- /** Border right color. */
- BORDER_RIGHT_COLOR(Color.class),
- /** Border right style. */
- BORDER_RIGHT_STYLE(Border.class),
- /** Border bottom size. */
- BORDER_BOTTOM,
- /** Border bottom color. */
- BORDER_BOTTOM_COLOR(Color.class),
- /** Border bottom style. */
- BORDER_BOTTOM_STYLE(Border.class),
- /** Border left size. */
- BORDER_LEFT,
- /** Border left color. */
- BORDER_LEFT_COLOR(Color.class),
- /** Border left style. */
- BORDER_LEFT_STYLE(Border.class),
- /** Margin top size. */
- MARGIN_TOP,
- /** Margin right size. */
- MARGIN_RIGHT,
- /** Margin bottom size. */
- MARGIN_BOTTOM,
- /** Margin left size. */
- MARGIN_LEFT,;
- /** The allowed type of data - Integer.class as default. */
- private final Class type;
- /** The default value - null by default. */
- private final Object def;
- /**
- * Default type is Integer.
- */
- private WidgetAttr() {
- this(Integer.class, null);
- }
- /**
- * Set the type explicitely.
- * @param allow this class and subclasses only
- */
- private WidgetAttr(final Class allow) {
- this(allow, null);
- }
- /**
- * Set the default value for an int attribute.
- * @param defValue default value
- */
- private WidgetAttr(final int defValue) {
- this(Integer.class, defValue);
- }
- /**
- * Set the type and default.
- * @param allow class
- * @param defValue default value
- */
- private WidgetAttr(final Class allow, final Object defValue) {
- type = allow;
- def = defValue;
- }
- @Override
- public final Class getType() {
- return type;
- }
- @Override
- public final Object getDefault() {
- return def;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment