X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2Fpanes%2FMainContentList.java;h=f7aaec4373c9c50a03f60e655933310c156d093d;hb=d5260eeb873fcf2ef9855dedcd9e2a3a3a990582;hp=cac03e2426c615b9e61b2420d049408ed4d15f67;hpb=ce822a7cd8ff95a031e477e37d23c114228cc5b6;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/panes/MainContentList.java b/src/be/nikiroo/jvcard/tui/panes/MainContentList.java index cac03e2..f7aaec4 100644 --- a/src/be/nikiroo/jvcard/tui/panes/MainContentList.java +++ b/src/be/nikiroo/jvcard/tui/panes/MainContentList.java @@ -3,10 +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.StringUtils; +import be.nikiroo.jvcard.launcher.Main; +import be.nikiroo.jvcard.resources.ColorOption; +import be.nikiroo.jvcard.resources.StringId; import be.nikiroo.jvcard.tui.UiColors; -import be.nikiroo.jvcard.tui.UiColors.Element; +import be.nikiroo.utils.StringUtils; import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.gui2.AbstractListBox.ListItemRenderer; @@ -27,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; } @@ -38,25 +39,24 @@ 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); } } - public MainContentList(final UiColors.Element normalStyle, - final UiColors.Element selectedStyle) { + public MainContentList() { super(Direction.VERTICAL); lines = new ActionListBox(); @@ -88,6 +88,7 @@ abstract public class MainContentList extends MainContent implements Runnable { * Will be set to {@code true} if the list box currently * has input focus, otherwise {@code false} */ + @Override public void drawItem(TextGUIGraphics graphics, ActionListBox listBox, int index, Runnable item, boolean selected, boolean focused) { @@ -103,7 +104,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 +126,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} */ @@ -157,7 +191,7 @@ abstract public class MainContentList extends MainContent implements Runnable { * @return the separator */ public String getSeparator() { - return StringId.DEAULT_FIELD_SEPARATOR.trans(); + return Main.trans(StringId.DEAULT_FIELD_SEPARATOR); } @Override @@ -192,16 +226,17 @@ abstract public class MainContentList extends MainContent implements Runnable { * * @return the text representation */ - protected List getLabel(int index, int width, boolean selected, + protected List getLabel(int index, + @SuppressWarnings("unused") int width, boolean selected, boolean focused) { List parts = new LinkedList(); 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;