X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTWindow.java;h=19c96fd141d2550209a9ca8fb14ae53bcbfbc378;hb=eb29bbb5ec70c43895dd0f053630c7e3cd402cba;hp=6cd11e5982fface1b1b8a44a29000c6cb8ddb794;hpb=78a56d5d6893759990718ec0479313da9526f08c;p=fanfix.git diff --git a/src/jexer/TWindow.java b/src/jexer/TWindow.java index 6cd11e5..19c96fd 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.*; @@ -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 ----------------------------------------------- // ------------------------------------------------------------------------ @@ -284,9 +289,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. */ @@ -496,6 +552,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. * @@ -520,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) ) { @@ -643,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); @@ -701,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()) @@ -901,6 +993,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)); @@ -989,38 +1087,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; } @@ -1059,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 { @@ -1114,7 +1220,7 @@ public class TWindow extends TWidget { return; } - if (command.equals(cmWindowZoom)) { + if (command.equals(cmWindowZoom) && ((flags & NOZOOMBOX) == 0)) { if (maximized) { restore(); } else { @@ -1160,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 { @@ -1319,5 +1427,4 @@ public class TWindow extends TWidget { getScreen().hLineXY(x, y, n, ch, attr); } - }