New launcher class to start all 3 modes:
[jvcard.git] / src / be / nikiroo / jvcard / tui / panes / MainContentList.java
index 23892e58cd13a1cf654905b893f574408dce5e64..e4c40ba0bc5aaa1a4031d736c79a4867814a60c5 100644 (file)
@@ -3,10 +3,9 @@ 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.tui.UiColors;
+import be.nikiroo.jvcard.launcher.Main;
+import be.nikiroo.jvcard.resources.StringUtils;
+import be.nikiroo.jvcard.resources.Trans.StringId;
 import be.nikiroo.jvcard.tui.UiColors.Element;
 
 import com.googlecode.lanterna.TextColor;
@@ -56,8 +55,7 @@ abstract public class MainContentList extends MainContent implements Runnable {
                }
        }
 
-       public MainContentList(final UiColors.Element normalStyle,
-                       final UiColors.Element selectedStyle) {
+       public MainContentList() {
                super(Direction.VERTICAL);
 
                lines = new ActionListBox();
@@ -104,7 +102,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();
@@ -126,6 +124,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<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}
         */