X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWindow.java;h=cde0113a009b01a26c397b4badf814cb7281532f;hb=85c07c5e6db3a5e74f5ba2bd6e7ee2656d5b63a0;hp=cca51d673795aaf1aebbad968af9e42762a5f86e;hpb=9245321388306b5b49d6385ce2f46ea6a82ab619;p=fanfix.git diff --git a/src/jexer/TWindow.java b/src/jexer/TWindow.java index cca51d6..cde0113 100644 --- a/src/jexer/TWindow.java +++ b/src/jexer/TWindow.java @@ -30,6 +30,7 @@ package jexer; import java.util.HashSet; +import jexer.backend.Screen; import jexer.bits.Cell; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; @@ -38,7 +39,6 @@ import jexer.event.TKeypressEvent; import jexer.event.TMenuEvent; import jexer.event.TMouseEvent; import jexer.event.TResizeEvent; -import jexer.io.Screen; import jexer.menu.TMenu; import static jexer.TCommand.*; import static jexer.TKeypress.*; @@ -67,6 +67,12 @@ public class TWindow extends TWidget { */ public static final int CENTERED = 0x04; + /** + * Window has no close box (default no). Window can still be closed via + * TApplication.closeWindow() and TWindow.close(). + */ + public static final int NOCLOSEBOX = 0x08; + // ------------------------------------------------------------------------ // Common window attributes ----------------------------------------------- // ------------------------------------------------------------------------ @@ -278,9 +284,60 @@ public class TWindow extends TWidget { * @param maximumWindowWidth new maximum width */ public final void setMaximumWindowWidth(final int maximumWindowWidth) { + if ((maximumWindowWidth != -1) + && (maximumWindowWidth < minimumWindowWidth + 1) + ) { + throw new IllegalArgumentException("Maximum window width cannot " + + "be smaller than minimum window width + 1"); + } this.maximumWindowWidth = maximumWindowWidth; } + /** + * Set the minimum width for this window. + * + * @param minimumWindowWidth new minimum width + */ + public final void setMinimumWindowWidth(final int minimumWindowWidth) { + if ((maximumWindowWidth != -1) + && (minimumWindowWidth > maximumWindowWidth - 1) + ) { + throw new IllegalArgumentException("Minimum window width cannot " + + "be larger than maximum window width - 1"); + } + this.minimumWindowWidth = minimumWindowWidth; + } + + /** + * Set the maximum height for this window. + * + * @param maximumWindowHeight new maximum height + */ + public final void setMaximumWindowHeight(final int maximumWindowHeight) { + if ((maximumWindowHeight != -1) + && (maximumWindowHeight < minimumWindowHeight + 1) + ) { + throw new IllegalArgumentException("Maximum window height cannot " + + "be smaller than minimum window height + 1"); + } + this.maximumWindowHeight = maximumWindowHeight; + } + + /** + * Set the minimum height for this window. + * + * @param minimumWindowHeight new minimum height + */ + public final void setMinimumWindowHeight(final int minimumWindowHeight) { + if ((maximumWindowHeight != -1) + && (minimumWindowHeight > maximumWindowHeight - 1) + ) { + throw new IllegalArgumentException("Minimum window height cannot " + + "be larger than maximum window height - 1"); + } + this.minimumWindowHeight = minimumWindowHeight; + } + /** * Recenter the window on-screen. */ @@ -387,6 +444,14 @@ public class TWindow extends TWidget { application.activateWindow(this); } + /** + * Close window. Note that windows without a close box can still be + * closed by calling the close() method. + */ + public void close() { + application.closeWindow(this); + } + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -482,6 +547,27 @@ public class TWindow extends TWidget { // General behavior ------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * See if this window is undergoing any movement/resize/etc. + * + * @return true if the window is moving + */ + public boolean inMovements() { + if (inWindowResize || inWindowMove || inKeyboardResize) { + return true; + } + return false; + } + + /** + * Stop any pending movement/resize/etc. + */ + public void stopMovements() { + inWindowResize = false; + inWindowMove = false; + inKeyboardResize = false; + } + /** * Returns true if this window is modal. * @@ -494,6 +580,18 @@ public class TWindow extends TWidget { return true; } + /** + * Returns true if this window has a close box. + * + * @return true if this window has a close box + */ + public final boolean hasCloseBox() { + if ((flags & NOCLOSEBOX) != 0) { + return true; + } + return false; + } + /** * Retrieve the background color. * @@ -600,18 +698,20 @@ public class TWindow extends TWidget { if (isActive()) { // Draw the close button - putCharXY(2, 0, '[', border); - putCharXY(4, 0, ']', border); - if (mouseOnClose() && mouse.isMouse1()) { - putCharXY(3, 0, GraphicsChars.CP437[0x0F], - !isModal() - ? getTheme().getColor("twindow.border.windowmove") - : getTheme().getColor("twindow.border.modal.windowmove")); - } else { - putCharXY(3, 0, GraphicsChars.CP437[0xFE], - !isModal() - ? getTheme().getColor("twindow.border.windowmove") - : getTheme().getColor("twindow.border.modal.windowmove")); + if ((flags & NOCLOSEBOX) == 0) { + putCharXY(2, 0, '[', border); + putCharXY(4, 0, ']', border); + if (mouseOnClose() && mouse.isMouse1()) { + putCharXY(3, 0, GraphicsChars.CP437[0x0F], + !isModal() + ? getTheme().getColor("twindow.border.windowmove") + : getTheme().getColor("twindow.border.modal.windowmove")); + } else { + putCharXY(3, 0, GraphicsChars.CP437[0xFE], + !isModal() + ? getTheme().getColor("twindow.border.windowmove") + : getTheme().getColor("twindow.border.modal.windowmove")); + } } // Draw the maximize button @@ -655,6 +755,9 @@ public class TWindow extends TWidget { * @return true if mouse is currently on the close button */ protected boolean mouseOnClose() { + if ((flags & NOCLOSEBOX) != 0) { + return false; + } if ((mouse != null) && (mouse.getAbsoluteY() == getY()) && (mouse.getAbsoluteX() == getX() + 3) @@ -870,6 +973,12 @@ public class TWindow extends TWidget { } if (inWindowResize) { + // Do not permit resizing below the status line + if (mouse.getAbsoluteY() == application.getDesktopBottom()) { + inWindowResize = false; + return; + } + // Move window over setWidth(resizeWindowWidth + (mouse.getAbsoluteX() - moveWindowMouseX)); @@ -958,38 +1067,46 @@ public class TWindow extends TWidget { setY(getY() - 1); } } - if (keypress.equals(kbShiftLeft)) { - if ((getWidth() > minimumWindowWidth) - || (minimumWindowWidth <= 0) - ) { - setWidth(getWidth() - 1); + + /* + * Only permit keyboard resizing if the window was RESIZABLE. + */ + if ((flags & RESIZABLE) != 0) { + + if (keypress.equals(kbShiftLeft)) { + if ((getWidth() > minimumWindowWidth) + || (minimumWindowWidth <= 0) + ) { + setWidth(getWidth() - 1); + } } - } - if (keypress.equals(kbShiftRight)) { - if ((getWidth() < maximumWindowWidth) - || (maximumWindowWidth <= 0) - ) { - setWidth(getWidth() + 1); + if (keypress.equals(kbShiftRight)) { + if ((getWidth() < maximumWindowWidth) + || (maximumWindowWidth <= 0) + ) { + setWidth(getWidth() + 1); + } } - } - if (keypress.equals(kbShiftUp)) { - if ((getHeight() > minimumWindowHeight) - || (minimumWindowHeight <= 0) - ) { - setHeight(getHeight() - 1); + if (keypress.equals(kbShiftUp)) { + if ((getHeight() > minimumWindowHeight) + || (minimumWindowHeight <= 0) + ) { + setHeight(getHeight() - 1); + } } - } - if (keypress.equals(kbShiftDown)) { - if ((getHeight() < maximumWindowHeight) - || (maximumWindowHeight <= 0) - ) { - setHeight(getHeight() + 1); + if (keypress.equals(kbShiftDown)) { + if ((getHeight() < maximumWindowHeight) + || (maximumWindowHeight <= 0) + ) { + setHeight(getHeight() + 1); + } } - } - // Pass a resize event to my children - onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, - getWidth(), getHeight())); + // Pass a resize event to my children + onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, + getWidth(), getHeight())); + + } // if ((flags & RESIZABLE) != 0) return; } @@ -1009,7 +1126,9 @@ public class TWindow extends TWidget { // Ctrl-W - close window if (keypress.equals(kbCtrlW)) { - application.closeWindow(this); + if ((flags & NOCLOSEBOX) == 0) { + application.closeWindow(this); + } return; } @@ -1060,7 +1179,9 @@ public class TWindow extends TWidget { if (!(this instanceof TDesktop)) { if (command.equals(cmWindowClose)) { - application.closeWindow(this); + if ((flags & NOCLOSEBOX) == 0) { + application.closeWindow(this); + } return; } @@ -1104,7 +1225,9 @@ public class TWindow extends TWidget { if (!(this instanceof TDesktop)) { if (menu.getId() == TMenu.MID_WINDOW_CLOSE) { - application.closeWindow(this); + if ((flags & NOCLOSEBOX) == 0) { + application.closeWindow(this); + } return; } @@ -1282,5 +1405,4 @@ public class TWindow extends TWidget { getScreen().hLineXY(x, y, n, ch, attr); } - }