X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Ftui%2FConfigItem.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2Ftui%2FConfigItem.java;h=43e9fe8f11ce9bd7a03f8fe82e50ac1f8aaa9024;hb=b6d172980d63ca3fa6880f152373de46deaaadcc;hp=0000000000000000000000000000000000000000;hpb=28a82bab4c068af216ac38609a8dd2c0bf2f531a;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/tui/ConfigItem.java b/src/be/nikiroo/fanfix/reader/tui/ConfigItem.java new file mode 100644 index 0000000..43e9fe8 --- /dev/null +++ b/src/be/nikiroo/fanfix/reader/tui/ConfigItem.java @@ -0,0 +1,362 @@ +package be.nikiroo.fanfix.reader.tui; + +import java.util.List; + +import jexer.TAction; +import jexer.TButton; +import jexer.TLabel; +import jexer.TPanel; +import jexer.TWidget; +import be.nikiroo.utils.resources.Bundle; +import be.nikiroo.utils.resources.MetaInfo; +import be.nikiroo.utils.ui.ConfigItemBase; + +/** + * A graphical item that reflect a configuration option from the given + * {@link Bundle}. + *
+ * This graphical item can be edited, and the result will be saved back into the
+ * linked {@link MetaInfo}; you still have to save the {@link MetaInfo} should
+ * you wish to, of course.
+ *
+ * @author niki
+ *
+ * @param
+ * Has no effect if the class is using automatic dirty handling (see
+ * {@link ConfigItemBase#ConfigItem(MetaInfo, boolean)}).
+ *
+ * @param item
+ * the item number to get for an array of values, or -1 to get
+ * the whole value (has no effect if {@link MetaInfo#isArray()}
+ * is FALSE)
+ */
+ protected void setDirtyItem(int item) {
+ base.setDirtyItem(item);
+ }
+
+ /**
+ * Check if the value changed since the last load/save into the linked
+ * {@link MetaInfo}.
+ *
+ * Note that we consider NULL and an Empty {@link String} to be equals.
+ *
+ * @param value
+ * the value to test
+ * @param item
+ * the item number to get for an array of values, or -1 to get
+ * the whole value (has no effect if {@link MetaInfo#isArray()}
+ * is FALSE)
+ *
+ * @return TRUE if it has
+ */
+ protected boolean hasValueChanged(Object value, int item) {
+ return base.hasValueChanged(value, item);
+ }
+
+ /**
+ * Create an empty graphical component to be used later by
+ * {@link ConfigItem#createField(int)}.
+ *
+ * Note that {@link ConfigItem#reload(int)} will be called after it was
+ * created by {@link ConfigItem#createField(int)}.
+ *
+ * @param item
+ * the item number to get for an array of values, or -1 to get
+ * the whole value (has no effect if {@link MetaInfo#isArray()}
+ * is FALSE)
+ *
+ * @return the graphical component
+ */
+ abstract protected TWidget createEmptyField(int item);
+
+ /**
+ * Get the information from the {@link MetaInfo} in the subclass preferred
+ * format.
+ *
+ * @param item
+ * the item number to get for an array of values, or -1 to get
+ * the whole value (has no effect if {@link MetaInfo#isArray()}
+ * is FALSE)
+ *
+ * @return the information in the subclass preferred format
+ */
+ abstract protected Object getFromInfo(int item);
+
+ /**
+ * Set the value to the {@link MetaInfo}.
+ *
+ * @param value
+ * the value in the subclass preferred format
+ * @param item
+ * the item number to get for an array of values, or -1 to get
+ * the whole value (has no effect if {@link MetaInfo#isArray()}
+ * is FALSE)
+ */
+ abstract protected void setToInfo(Object value, int item);
+
+ /**
+ * The value present in the given item's related field in the subclass
+ * preferred format.
+ *
+ * @param item
+ * the item number to get for an array of values, or -1 to get
+ * the whole value (has no effect if {@link MetaInfo#isArray()}
+ * is FALSE)
+ *
+ * @return the value present in the given item's related field in the
+ * subclass preferred format
+ */
+ abstract protected Object getFromField(int item);
+
+ /**
+ * Set the value (in the subclass preferred format) into the field.
+ *
+ * @param value
+ * the value in the subclass preferred format
+ * @param item
+ * the item number to get for an array of values, or -1 to get
+ * the whole value (has no effect if {@link MetaInfo#isArray()}
+ * is FALSE)
+ */
+ abstract protected void setToField(Object value, int item);
+
+ /**
+ * Create a label which width is constrained in lock steps.
+ *
+ * @param x
+ * the X position of the label
+ * @param y
+ * the Y position of the label
+ * @param nhgap
+ * negative horisontal gap in pixel to use for the label, i.e.,
+ * the step lock sized labels will start smaller by that amount
+ * (the use case would be to align controls that start at a
+ * different horisontal position)
+ *
+ * @return the label
+ */
+ protected TWidget label(int x, int y, int nhgap) {
+ // TODO: see Swing version for lock-step sizes
+ // TODO: see Swing version for help info-buttons
+
+ String lbl = getInfo().getName();
+ return new TLabel(this, lbl, x, y);
+ }
+
+ /**
+ * Create a new {@link ConfigItem} for the given {@link MetaInfo}.
+ *
+ * @param