import java.util.LinkedList;
import java.util.List;
-import be.nikiroo.jvcard.i18n.Trans.StringId;
-import be.nikiroo.jvcard.tui.StringUtils;
+import be.nikiroo.jvcard.launcher.Main;
+import be.nikiroo.jvcard.resources.StringUtils;
+import be.nikiroo.jvcard.resources.enums.ColorOption;
+import be.nikiroo.jvcard.resources.enums.StringId;
import be.nikiroo.jvcard.tui.UiColors;
-import be.nikiroo.jvcard.tui.UiColors.Element;
import com.googlecode.lanterna.TextColor;
import com.googlecode.lanterna.gui2.AbstractListBox.ListItemRenderer;
*/
public class TextPart {
private String text;
- private Element element;
+ private ColorOption element;
- public TextPart(String text, Element element) {
+ public TextPart(String text, ColorOption element) {
this.text = text;
this.element = element;
}
return text;
}
- public Element getElement() {
+ public ColorOption getElement() {
return element;
}
public TextColor getForegroundColor() {
if (element != null)
- return element.getForegroundColor();
- return Element.DEFAULT.getForegroundColor();
+ return UiColors.getForegroundColor(element);
+ return UiColors.getForegroundColor(ColorOption.DEFAULT);
}
public TextColor getBackgroundColor() {
if (element != null)
- return element.getBackgroundColor();
- return Element.DEFAULT.getBackgroundColor();
+ return UiColors.getBackgroundColor(element);
+ return UiColors.getBackgroundColor(ColorOption.DEFAULT);
}
}
- public MainContentList(final UiColors.Element normalStyle,
- final UiColors.Element selectedStyle) {
+ public MainContentList() {
super(Direction.VERTICAL);
lines = new ActionListBox();
graphics.setBackgroundColor(part.getBackgroundColor());
String label = StringUtils.sanitize(part.getText(),
- UiColors.getInstance().isUnicode());
+ Main.isUnicode());
graphics.putString(position, 0, label);
position += label.length();
lines.addItem(line, this);
}
+ /**
+ * Delete the given item.
+ *
+ * Remark: it will only delete the first found instance if multiple
+ * instances of this item are present.
+ *
+ * @param line
+ * the line to delete
+ *
+ * @return TRUE if the item was deleted
+ */
+ public boolean removeItem(String line) {
+ boolean deleted = false;
+
+ List<Runnable> copy = lines.getItems();
+ for (int index = 0; index < copy.size(); index++) {
+ if (copy.get(index).toString().equals(line)) {
+ deleted = true;
+ copy.remove(index);
+ break;
+ }
+ }
+
+ int index = getSelectedIndex();
+ clearItems();
+ for (Runnable run : copy) {
+ addItem(run.toString());
+ }
+ setSelectedIndex(index);
+
+ return deleted;
+ }
+
/**
* Clear all the items in this {@link MainContentList}
*/
* @return the separator
*/
public String getSeparator() {
- return StringId.DEAULT_FIELD_SEPARATOR.trans();
+ return Main.trans(StringId.DEAULT_FIELD_SEPARATOR);
}
@Override
if (selected && focused) {
parts.add(new TextPart("" + lines.getItems().get(index),
- Element.CONTACT_LINE_SELECTED));
+ ColorOption.CONTACT_LINE_SELECTED));
} else {
parts.add(new TextPart("" + lines.getItems().get(index),
- Element.CONTACT_LINE));
+ ColorOption.CONTACT_LINE));
}
return parts;