From: Niki Roo Date: Sat, 2 Apr 2016 11:44:03 +0000 (+0200) Subject: Fix inclusion of lanterna's resources + fix warning X-Git-Tag: v1.1~10 X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=commitdiff_plain;h=ed91f27a4f628ec59b0e85cdbb0319287c503f9d Fix inclusion of lanterna's resources + fix warning --- diff --git a/Makefile b/Makefile index 83242cc..6348110 100644 --- a/Makefile +++ b/Makefile @@ -70,9 +70,10 @@ bin/files: src/be/nikiroo/jvcard/*/* src/be/nikiroo/jvcard/* @mkdir -p bin/ @find src/be/ -name '*.java' > bin/files -bin/lanterna: src/com/googlecode/lanterna/* src/com/googlecode/lanterna/*/* src/com/googlecode/lanterna/*/*/* +bin/lanterna: src/resources/* src/com/googlecode/lanterna/* src/com/googlecode/lanterna/*/* src/com/googlecode/lanterna/*/*/* @mkdir -p bin/ @find src/com/ -name '*.java' > bin/lanterna + cp -r src/resources/* bin/ javac -encoding UTF-8 -source 5 @bin/lanterna -d bin/ || rm bin/lanterna @test -e bin/lanterna diff --git a/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java b/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java index 6ff63bf..7199158 100644 --- a/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java +++ b/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java @@ -76,7 +76,7 @@ public class TransBundle extends Bundle { } if (values != null && values.length > 0) - return String.format(locale, result, (Object[]) values); + return String.format(locale, result, values); else return result; } diff --git a/src/be/nikiroo/jvcard/tui/TuiLauncher.java b/src/be/nikiroo/jvcard/tui/TuiLauncher.java index 066ba31..054fe4a 100644 --- a/src/be/nikiroo/jvcard/tui/TuiLauncher.java +++ b/src/be/nikiroo/jvcard/tui/TuiLauncher.java @@ -7,8 +7,6 @@ import be.nikiroo.jvcard.tui.panes.FileList; import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.TextColor; -import com.googlecode.lanterna.gui2.DefaultWindowManager; -import com.googlecode.lanterna.gui2.EmptySpace; import com.googlecode.lanterna.gui2.MultiWindowTextGUI; import com.googlecode.lanterna.gui2.Window; import com.googlecode.lanterna.screen.Screen; @@ -24,6 +22,8 @@ import com.googlecode.lanterna.terminal.Terminal; * */ public class TuiLauncher { + static private Screen screen = null; + /** * Start the TUI program. * @@ -42,6 +42,15 @@ public class TuiLauncher { TuiLauncher.start(textMode, win); } + /** + * Return the used {@link Screen}. + * + * @return the {@link Screen} + */ + static public Screen getScreen() { + return screen; + } + /** * Start the TUI program. * @@ -78,14 +87,16 @@ public class TuiLauncher { }); } - Screen screen = new TerminalScreen(terminal); + screen = new TerminalScreen(terminal); screen.startScreen(); // Create gui and start gui MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, - new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); - gui.addWindowAndWait(win); + TextColor.ANSI.BLUE); + gui.setTheme(UiColors.getCustomTheme()); + + gui.addWindowAndWait(win); screen.stopScreen(); } } diff --git a/src/be/nikiroo/jvcard/tui/UiColors.java b/src/be/nikiroo/jvcard/tui/UiColors.java index abac7d5..877c739 100644 --- a/src/be/nikiroo/jvcard/tui/UiColors.java +++ b/src/be/nikiroo/jvcard/tui/UiColors.java @@ -1,13 +1,20 @@ package be.nikiroo.jvcard.tui; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.MissingResourceException; +import java.util.Properties; import be.nikiroo.jvcard.resources.bundles.ColorBundle; import be.nikiroo.jvcard.resources.enums.ColorOption; import com.googlecode.lanterna.TextColor; +import com.googlecode.lanterna.graphics.PropertiesTheme; +import com.googlecode.lanterna.graphics.Theme; +import com.googlecode.lanterna.gui2.AbstractTextGUI; import com.googlecode.lanterna.gui2.Label; /** @@ -28,7 +35,8 @@ public class UiColors extends ColorBundle { } /** - * Create a new {@link Label} with the colours of the given {@link ColorOption}. + * Create a new {@link Label} with the colours of the given + * {@link ColorOption}. * * @param el * the {@link ColorOption} @@ -105,6 +113,33 @@ public class UiColors extends ColorBundle { return getInstance().colorMap.get(el.name() + "_FG"); } + /** + * Return a {@link Theme} following the colours defined in + * display.properties. + * + * @return the {@link Theme} + */ + static Theme getCustomTheme() { + // Create a properties-theme with our own custom values for some of it + Properties properties = new Properties(); + try { + ClassLoader classLoader = AbstractTextGUI.class.getClassLoader(); + InputStream resourceAsStream = classLoader + .getResourceAsStream("default-theme.properties"); + if (resourceAsStream == null) { + resourceAsStream = new FileInputStream( + "src/main/resources/default-theme.properties"); + } + properties.load(resourceAsStream); + resourceAsStream.close(); + } catch (IOException e) { + } + properties.put("com.googlecode.lanterna.background", "black"); + PropertiesTheme theme = new PropertiesTheme(properties); + + return theme; + } + /** * Get the (unique) instance of this class. * diff --git a/src/be/nikiroo/jvcard/tui/panes/ContactDetailsRaw.java b/src/be/nikiroo/jvcard/tui/panes/ContactDetailsRaw.java index 2de9919..5a616b9 100644 --- a/src/be/nikiroo/jvcard/tui/panes/ContactDetailsRaw.java +++ b/src/be/nikiroo/jvcard/tui/panes/ContactDetailsRaw.java @@ -13,7 +13,10 @@ import be.nikiroo.jvcard.resources.enums.StringId; import be.nikiroo.jvcard.tui.KeyAction; import be.nikiroo.jvcard.tui.KeyAction.DataType; import be.nikiroo.jvcard.tui.KeyAction.Mode; +import be.nikiroo.jvcard.tui.TuiLauncher; +import com.googlecode.lanterna.gui2.MultiWindowTextGUI; +import com.googlecode.lanterna.gui2.dialogs.ActionListDialogBuilder; import com.googlecode.lanterna.input.KeyType; public class ContactDetailsRaw extends MainContentList { @@ -114,6 +117,41 @@ public class ContactDetailsRaw extends MainContentList { }); // TODO: ui actions.add(new KeyAction(Mode.ASK_USER, 'a', StringId.KEY_ACTION_ADD) { + @Override + public boolean onAction() { + try{ + new ActionListDialogBuilder() + .setTitle("Action List Dialog") + .setDescription("Choose an item") + .addAction("First Item", new Runnable() { + @Override + public void run() { + // Do 1st thing... + } + }) + .addAction("Second Item", new Runnable() { + @Override + public void run() { + // Do 2nd thing... + } + }) + .addAction("Third Item", new Runnable() { + @Override + public void run() { + // Do 3rd thing... + } + }) + .build() + .showDialog( + new MultiWindowTextGUI(TuiLauncher.getScreen())); + + return true; + }catch(Exception e){ + e.printStackTrace(); + throw e; + } + } + @Override public Object getObject() { return contact;