+ JComponent field = base.createField(-1);
+ add(field, BorderLayout.CENTER);
+ }
+ }
+
+ /** The {@link MetaInfo} linked to the field. */
+ public MetaInfo<E> getInfo() {
+ return base.getInfo();
+ }
+
+ /**
+ * Retrieve the associated graphical component that was created with
+ * {@link ConfigItemBase#createEmptyField(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
+ */
+ protected JComponent getField(int item) {
+ return base.getField(item);
+ }
+
+ /**
+ * Manually specify that the given item is "dirty" and thus should be saved
+ * when asked.
+ * <p>
+ * 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}.
+ * <p>
+ * 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);
+ }
+
+ private void addItemWithMinusPanel(int item) {
+ JPanel minusPanel = createMinusPanel(item);
+ JComponent field = base.addItem(item, minusPanel);
+ minusPanel.add(field, BorderLayout.CENTER);
+ }
+
+ private JPanel createMinusPanel(final int item) {
+ JPanel minusPanel = new JPanel(new BorderLayout());
+
+ final JButton remove = new JButton();
+ setImage(remove, img64remove, "-");
+
+ remove.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ base.removeItem(item);
+ }
+ });
+
+ minusPanel.add(remove, BorderLayout.EAST);
+
+ main.add(minusPanel);
+ main.revalidate();
+ main.repaint();
+
+ return minusPanel;
+ }
+
+ /**
+ * Create an empty graphical component to be used later by
+ * {@link ConfigItem#createField(int)}.
+ * <p>
+ * 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 JComponent 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 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 JComponent label(int nhgap) {
+ final JLabel label = new JLabel(getInfo().getName());
+
+ Dimension ps = label.getPreferredSize();
+ if (ps == null) {
+ ps = label.getSize();
+ }
+
+ ps.height = Math.max(ps.height, getMinimumHeight());
+
+ int w = ps.width;
+ int step = 150;
+ for (int i = 2 * step - nhgap; i < 10 * step; i += step) {
+ if (w < i) {
+ w = i;
+ break;
+ }
+ }
+
+ final Runnable showInfo = new Runnable() {
+ @Override
+ public void run() {
+ StringBuilder builder = new StringBuilder();
+ String text = (getInfo().getDescription().replace("\\n", "\n"))
+ .trim();
+ for (String line : StringUtils.justifyText(text, 80,
+ Alignment.LEFT)) {
+ if (builder.length() > 0) {
+ builder.append("\n");
+ }
+ builder.append(line);