X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2Fpanes%2FMainContentList.java;h=9e5f8ec0e8278108d0aee9d971e6b1d04378f592;hp=e1358eff66f9659ada469ade30dc0a0f97d886d8;hb=e119a1c1a924998b9315e46c96b1c750aab1deb9;hpb=2a96e7b2cf3f155cccc633272b2f547ffd8f4672 diff --git a/src/be/nikiroo/jvcard/tui/panes/MainContentList.java b/src/be/nikiroo/jvcard/tui/panes/MainContentList.java index e1358ef..9e5f8ec 100644 --- a/src/be/nikiroo/jvcard/tui/panes/MainContentList.java +++ b/src/be/nikiroo/jvcard/tui/panes/MainContentList.java @@ -3,11 +3,11 @@ package be.nikiroo.jvcard.tui.panes; import java.util.LinkedList; import java.util.List; -import be.nikiroo.jvcard.i18n.Trans.StringId; -import be.nikiroo.jvcard.tui.Main; -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; @@ -28,9 +28,9 @@ abstract public class MainContentList extends MainContent implements Runnable { */ 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; } @@ -39,20 +39,20 @@ abstract public class MainContentList extends MainContent implements Runnable { 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); } } @@ -103,7 +103,7 @@ abstract public class MainContentList extends MainContent implements Runnable { graphics.setBackgroundColor(part.getBackgroundColor()); String label = StringUtils.sanitize(part.getText(), - UiColors.getInstance().isUnicode()); + Main.isUnicode()); graphics.putString(position, 0, label); position += label.length(); @@ -125,6 +125,39 @@ abstract public class MainContentList extends MainContent implements Runnable { 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 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} */ @@ -198,10 +231,10 @@ abstract public class MainContentList extends MainContent implements Runnable { 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;