+ /**
+ * 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() - application.getDesktopTop());
+ setX(0);
+ setY(application.getDesktopTop());
+ 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);
+ }
+
+ /**
+ * 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.
+ *
+ * @return true if this window is modal
+ */
+ public final boolean isModal() {
+ if ((flags & MODAL) == 0) {
+ return false;
+ }
+ 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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Returns true if this window does not want menus to work while it is
+ * visible.
+ *
+ * @return true if this window does not want menus to work while it is
+ * visible
+ */
+ public final boolean hasOverriddenMenu() {
+ if ((flags & OVERRIDEMENU) != 0) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Retrieve the background color.
+ *
+ * @return the background color
+ */
+ public CellAttributes getBackground() {
+ if (!isModal()
+ && (inWindowMove || inWindowResize || inKeyboardResize)
+ ) {
+ assert (isActive());
+ return getTheme().getColor("twindow.background.windowmove");
+ } else if (isModal() && inWindowMove) {
+ assert (isActive());
+ return getTheme().getColor("twindow.background.modal");
+ } else if (isModal()) {
+ if (isActive()) {
+ return getTheme().getColor("twindow.background.modal");
+ }
+ return getTheme().getColor("twindow.background.modal.inactive");
+ } else if (isActive()) {
+ assert (!isModal());
+ return getTheme().getColor("twindow.background");
+ } else {
+ assert (!isModal());
+ return getTheme().getColor("twindow.background.inactive");
+ }
+ }
+
+ /**
+ * Retrieve the border color.
+ *
+ * @return the border color
+ */
+ public CellAttributes getBorder() {
+ if (!isModal()
+ && (inWindowMove || inWindowResize || inKeyboardResize)
+ ) {
+ if (!isActive()) {
+ // The user's terminal never passed a mouse up event, and now
+ // another window is active but we never finished a drag.
+ inWindowMove = false;
+ inWindowResize = false;
+ inKeyboardResize = false;
+ return getTheme().getColor("twindow.border.inactive");
+ }
+
+ return getTheme().getColor("twindow.border.windowmove");
+ } else if (isModal() && inWindowMove) {
+ assert (isActive());
+ return getTheme().getColor("twindow.border.modal.windowmove");
+ } else if (isModal()) {
+ if (isActive()) {
+ return getTheme().getColor("twindow.border.modal");
+ } else {
+ return getTheme().getColor("twindow.border.modal.inactive");
+ }
+ } else if (isActive()) {
+ assert (!isModal());
+ return getTheme().getColor("twindow.border");
+ } else {
+ assert (!isModal());
+ return getTheme().getColor("twindow.border.inactive");
+ }
+ }
+
+ /**
+ * Retrieve the color used by the window movement/sizing controls.
+ *
+ * @return the color used by the zoom box, resize bar, and close box
+ */
+ public CellAttributes getBorderControls() {
+ if (isModal()) {
+ return getTheme().getColor("twindow.border.modal.windowmove");
+ }
+ return getTheme().getColor("twindow.border.windowmove");
+ }
+
+ /**
+ * Retrieve the border line type.
+ *
+ * @return the border line type
+ */
+ private int getBorderType() {
+ if (!isModal()
+ && (inWindowMove || inWindowResize || inKeyboardResize)
+ ) {
+ assert (isActive());
+ return 1;
+ } else if (isModal() && inWindowMove) {
+ assert (isActive());
+ return 1;
+ } else if (isModal()) {
+ if (isActive()) {
+ return 2;
+ } else {
+ return 1;
+ }
+ } else if (isActive()) {
+ return 2;
+ } else {
+ return 1;
+ }
+ }
+
+ /**
+ * Returns true if this window does not want the application-wide mouse
+ * cursor drawn over it.
+ *
+ * @return true if this window does not want the application-wide mouse
+ * cursor drawn over it
+ */
+ public boolean hasHiddenMouse() {
+ return hideMouse;
+ }
+
+ /**
+ * Set request to prevent the application-wide mouse cursor from being
+ * drawn over this window.
+ *
+ * @param hideMouse if true, this window does not want the
+ * application-wide mouse cursor drawn over it
+ */
+ public final void setHiddenMouse(final boolean hideMouse) {
+ this.hideMouse = hideMouse;
+ }
+
+ /**
+ * Get this window's help topic to load.
+ *
+ * @return the topic name
+ */
+ public String getHelpTopic() {
+ return helpTopic;
+ }
+
+ /**
+ * Generate a human-readable string for this window.
+ *
+ * @return a human-readable string
+ */
+ @Override
+ public String toString() {
+ return String.format("%s(%8x) \'%s\' Z %d position (%d, %d) " +
+ "geometry %dx%d hidden %s modal %s",
+ getClass().getName(), hashCode(), title, getZ(),
+ getX(), getY(), getWidth(), getHeight(), hidden, isModal());
+ }