- * 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.
- *
- * @return the background color
- */
- public final 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)
- ) {
- assert (isActive());
- 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 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;
- }
- }
-
- /**
- * Called by TApplication.drawChildren() to render on screen.
- */
- @Override
- public void draw() {
- // Draw the box and background first.
- CellAttributes border = getBorder();
- CellAttributes background = getBackground();
- int borderType = getBorderType();
-
- getScreen().drawBox(0, 0, getWidth(), getHeight(), border,
- background, borderType, true);
-
- // Draw the title
- int titleLeft = (getWidth() - title.length() - 2) / 2;
- putCharXY(titleLeft, 0, ' ', border);
- putStringXY(titleLeft + 1, 0, title);
- putCharXY(titleLeft + title.length() + 1, 0, ' ', border);
-
- if (isActive()) {
-
- // Draw the close button
- 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
- if (!isModal()) {
-
- putCharXY(getWidth() - 5, 0, '[', border);
- putCharXY(getWidth() - 3, 0, ']', border);
- if (mouseOnMaximize() && mouse.isMouse1()) {
- putCharXY(getWidth() - 4, 0, GraphicsChars.CP437[0x0F],
- getTheme().getColor("twindow.border.windowmove"));
- } else {
- if (maximized) {
- putCharXY(getWidth() - 4, 0, GraphicsChars.CP437[0x12],
- getTheme().getColor("twindow.border.windowmove"));
- } else {
- putCharXY(getWidth() - 4, 0, GraphicsChars.UPARROW,
- getTheme().getColor("twindow.border.windowmove"));
- }
- }
-
- // Draw the resize corner
- if ((flags & RESIZABLE) != 0) {
- putCharXY(getWidth() - 2, getHeight() - 1,
- GraphicsChars.SINGLE_BAR,
- getTheme().getColor("twindow.border.windowmove"));
- putCharXY(getWidth() - 1, getHeight() - 1,
- GraphicsChars.LRCORNER,
- getTheme().getColor("twindow.border.windowmove"));
- }
- }
- }
- }
-
- // ------------------------------------------------------------------------
- // Event handlers ---------------------------------------------------------
- // ------------------------------------------------------------------------
-
- /**
- * Returns true if the mouse is currently on the close button.
- *
- * @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)
- ) {
- return true;
- }
- return false;
- }
-
- /**
- * Returns true if the mouse is currently on the maximize/restore button.