From: Kevin Lamonte Date: Mon, 21 Aug 2017 21:12:35 +0000 (-0400) Subject: Fixes for TJIDE X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=68c5cd6bec3dc425ef5b55fec399d4bdc9afa7cb;p=nikiroo-utils.git Fixes for TJIDE --- diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index 66f7110..3d93e56 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -1043,6 +1043,10 @@ public class TApplication implements Runnable { desktop.setDimensions(0, 0, resize.getWidth(), resize.getHeight() - 1); } + + // Change menu edges if needed. + recomputeMenuX(); + // We are dirty, redraw the screen. doRepaint(); return; @@ -2296,6 +2300,12 @@ public class TApplication implements Runnable { for (TMenu menu: menus) { menu.setX(x); x += menu.getTitle().length() + 2; + + // Don't let the menu window exceed the screen width + int rightEdge = menu.getX() + menu.getWidth(); + if (rightEdge > getScreen().getWidth()) { + menu.setX(getScreen().getWidth() - menu.getWidth()); + } } } diff --git a/src/jexer/TButton.java b/src/jexer/TButton.java index 3b60cad..255dd99 100644 --- a/src/jexer/TButton.java +++ b/src/jexer/TButton.java @@ -73,11 +73,6 @@ public final class TButton extends TWidget { */ private TAction action; - /** - * How long to animate dispatch of the event in millis. - */ - private static final long DISPATCH_TIME = 75; - /** * Act as though the button was pressed. This is useful for other UI * elements to get the same action as if the user clicked the button. diff --git a/src/jexer/TWindow.java b/src/jexer/TWindow.java index cde0113..19c96fd 100644 --- a/src/jexer/TWindow.java +++ b/src/jexer/TWindow.java @@ -73,6 +73,11 @@ public class TWindow extends TWidget { */ public static final int NOCLOSEBOX = 0x08; + /** + * Window has no maximize box (default no). + */ + public static final int NOZOOMBOX = 0x10; + // ------------------------------------------------------------------------ // Common window attributes ----------------------------------------------- // ------------------------------------------------------------------------ @@ -592,12 +597,24 @@ public class TWindow extends TWidget { return false; } + /** + * Returns true if this window has a maximize/zoom box. + * + * @return true if this window has a maximize/zoom box + */ + public final boolean hasZoomBox() { + if ((flags & NOZOOMBOX) != 0) { + return true; + } + return false; + } + /** * Retrieve the background color. * * @return the background color */ - public final CellAttributes getBackground() { + public CellAttributes getBackground() { if (!isModal() && (inWindowMove || inWindowResize || inKeyboardResize) ) { @@ -715,7 +732,7 @@ public class TWindow extends TWidget { } // Draw the maximize button - if (!isModal()) { + if (!isModal() && ((flags & NOZOOMBOX) == 0)) { putCharXY(getWidth() - 5, 0, '[', border); putCharXY(getWidth() - 3, 0, ']', border); @@ -773,6 +790,9 @@ public class TWindow extends TWidget { * @return true if the mouse is currently on the maximize/restore button */ protected boolean mouseOnMaximize() { + if ((flags & NOZOOMBOX) != 0) { + return false; + } if ((mouse != null) && !isModal() && (mouse.getAbsoluteY() == getY()) @@ -1145,7 +1165,7 @@ public class TWindow extends TWidget { } // F5 - zoom - if (keypress.equals(kbF5)) { + if (keypress.equals(kbF5) && ((flags & NOZOOMBOX) == 0)) { if (maximized) { restore(); } else { @@ -1200,7 +1220,7 @@ public class TWindow extends TWidget { return; } - if (command.equals(cmWindowZoom)) { + if (command.equals(cmWindowZoom) && ((flags & NOZOOMBOX) == 0)) { if (maximized) { restore(); } else { @@ -1246,7 +1266,9 @@ public class TWindow extends TWidget { return; } - if (menu.getId() == TMenu.MID_WINDOW_ZOOM) { + if ((menu.getId() == TMenu.MID_WINDOW_ZOOM) + && ((flags & NOZOOMBOX) == 0) + ) { if (maximized) { restore(); } else { diff --git a/src/jexer/bits/ColorTheme.java b/src/jexer/bits/ColorTheme.java index 9618ccc..1c7c620 100644 --- a/src/jexer/bits/ColorTheme.java +++ b/src/jexer/bits/ColorTheme.java @@ -32,6 +32,7 @@ import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.Reader; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -114,9 +115,20 @@ public final class ColorTheme { * @throws IOException if the I/O fails */ public void load(final String filename) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(filename)); - String line = reader.readLine(); - for (; line != null; line = reader.readLine()) { + load(new FileReader(filename)); + } + + /** + * Read color theme mappings from a Reader. The reader is closed at the + * end. + * + * @param reader the reader to read from + * @throws IOException if the I/O fails + */ + public void load(final Reader reader) throws IOException { + BufferedReader bufferedReader = new BufferedReader(reader); + String line = bufferedReader.readLine(); + for (; line != null; line = bufferedReader.readLine()) { String key; String bold; String foreColor; @@ -154,7 +166,7 @@ public final class ColorTheme { colors.put(key, color); } // All done. - reader.close(); + bufferedReader.close(); } /** diff --git a/src/jexer/menu/TMenu.java b/src/jexer/menu/TMenu.java index c4a11df..7cf6eb5 100644 --- a/src/jexer/menu/TMenu.java +++ b/src/jexer/menu/TMenu.java @@ -349,6 +349,23 @@ public final class TMenu extends TWindow { return addItemInternal(id, label, key); } + /** + * Convenience function to add a custom menu item. + * + * @param id menu item ID. Must be greater than 1024. + * @param label menu item label + * @param key global keyboard accelerator + * @param enabled default state for enabled + * @return the new menu item + */ + public TMenuItem addItem(final int id, final String label, + final TKeypress key, final boolean enabled) { + + TMenuItem item = addItem(id, label, key); + item.setEnabled(enabled); + return item; + } + /** * Convenience function to add a custom menu item. *