+ putCharXY(getWidth() - 5, 0, '[', border);
+ putCharXY(getWidth() - 3, 0, ']', border);
+ if (mouseOnMaximize() && mouse.isMouse1()) {
+ putCharXY(getWidth() - 4, 0, GraphicsChars.CP437[0x0F],
+ getBorderControls());
+ } else {
+ if (maximized) {
+ putCharXY(getWidth() - 4, 0, GraphicsChars.CP437[0x12],
+ getBorderControls());
+ } else {
+ putCharXY(getWidth() - 4, 0, GraphicsChars.UPARROW,
+ getBorderControls());
+ }
+ }
+
+ // Draw the resize corner
+ if ((flags & RESIZABLE) != 0) {
+ putCharXY(getWidth() - 2, getHeight() - 1,
+ GraphicsChars.SINGLE_BAR, getBorderControls());
+ putCharXY(getWidth() - 1, getHeight() - 1,
+ GraphicsChars.LRCORNER, getBorderControls());
+ }
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // TWindow ----------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get window title.
+ *
+ * @return window title
+ */
+ public final String getTitle() {
+ return title;
+ }
+
+ /**
+ * Set window title.
+ *
+ * @param title new window title
+ */
+ public final void setTitle(final String title) {
+ this.title = title;
+ }
+
+ /**
+ * Get Z order. Lower number means more in-front.
+ *
+ * @return Z value. Lower number means more in-front.
+ */
+ public final int getZ() {
+ return z;
+ }
+
+ /**
+ * Set Z order. Lower number means more in-front.
+ *
+ * @param z the new Z value. Lower number means more in-front.
+ */
+ public final void setZ(final int z) {
+ this.z = z;
+ }
+
+ /**
+ * Add a keypress to be overridden for this window.
+ *
+ * @param key the key to start taking control of
+ */
+ protected void addShortcutKeypress(final TKeypress key) {
+ keyboardShortcuts.add(key);
+ }
+
+ /**
+ * Remove a keypress to be overridden for this window.
+ *
+ * @param key the key to stop taking control of
+ */
+ protected void removeShortcutKeypress(final TKeypress key) {
+ keyboardShortcuts.remove(key);
+ }
+
+ /**
+ * Remove all keypresses to be overridden for this window.
+ */
+ protected void clearShortcutKeypresses() {
+ keyboardShortcuts.clear();
+ }
+
+ /**
+ * Determine if a keypress is overridden for this window.
+ *
+ * @param key the key to check
+ * @return true if this window wants to process this key on its own
+ */
+ public boolean isShortcutKeypress(final TKeypress key) {
+ return keyboardShortcuts.contains(key);
+ }
+
+ /**
+ * Get the window's status bar, or null if it does not have one.
+ *
+ * @return the status bar, or null
+ */
+ public TStatusBar getStatusBar() {
+ return statusBar;
+ }
+
+ /**
+ * Set the window's status bar to a new one.
+ *
+ * @param text the status bar text
+ * @return the status bar
+ */
+ public TStatusBar newStatusBar(final String text) {
+ statusBar = new TStatusBar(this, text);
+ return statusBar;
+ }
+
+ /**
+ * Set the maximum width for this window.
+ *
+ * @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.
+ */
+ public final void center() {
+ if ((flags & CENTERED) != 0) {
+ if (getWidth() < getScreen().getWidth()) {
+ setX((getScreen().getWidth() - getWidth()) / 2);
+ } else {
+ setX(0);
+ }
+ setY(((application.getDesktopBottom()
+ - application.getDesktopTop()) - getHeight()) / 2);
+ if (getY() < 0) {
+ setY(0);
+ }
+ setY(getY() + application.getDesktopTop());
+ }
+ }
+
+ /**
+ * Maximize window.
+ */
+ public void maximize() {
+ if (maximized) {
+ return;
+ }
+
+ restoreWindowWidth = getWidth();
+ restoreWindowHeight = getHeight();
+ restoreWindowX = getX();
+ restoreWindowY = getY();
+ setWidth(getScreen().getWidth());
+ setHeight(application.getDesktopBottom() - 1);
+ setX(0);
+ setY(1);
+ maximized = true;
+
+ onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(),
+ getHeight()));
+ }
+
+ /**
+ * Restore (unmaximize) window.
+ */
+ public void restore() {
+ if (!maximized) {
+ return;
+ }
+
+ setWidth(restoreWindowWidth);
+ setHeight(restoreWindowHeight);
+ setX(restoreWindowX);
+ setY(restoreWindowY);
+ maximized = false;
+
+ onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(),
+ getHeight()));
+ }
+
+ /**
+ * Returns true if this window is hidden.
+ *
+ * @return true if this window is hidden, false if the window is shown
+ */
+ public final boolean isHidden() {
+ return hidden;
+ }
+
+ /**
+ * Returns true if this window is shown.
+ *
+ * @return true if this window is shown, false if the window is hidden
+ */
+ public final boolean isShown() {
+ return !hidden;
+ }
+
+ /**
+ * Hide window. A hidden window will still have its onIdle() called, and
+ * will also have onClose() called at application exit. Hidden windows
+ * will not receive any other events.
+ */
+ public void hide() {
+ application.hideWindow(this);
+ }
+
+ /**
+ * Show window.
+ */
+ public void show() {
+ application.showWindow(this);
+ }
+
+ /**
+ * Activate window (bring to top and receive events).
+ */
+ @Override
+ public void activate() {
+ application.activateWindow(this);
+ }
+
+ /**
+ * Close window. Note that windows without a close box can still be
+ * closed by calling the close() method.
+ */
+ @Override
+ public void close() {
+ application.closeWindow(this);