- @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() && ((flags & NOZOOMBOX) == 0)) {
-
- 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.
- *
- * @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())
- && (mouse.getAbsoluteX() == getX() + getWidth() - 4)
- ) {
- return true;
- }
- return false;
- }
-
- /**
- * Returns true if the mouse is currently on the resizable lower right
- * corner.
- *
- * @return true if the mouse is currently on the resizable lower right
- * corner
- */
- protected boolean mouseOnResize() {
- if (((flags & RESIZABLE) != 0)
- && !isModal()
- && (mouse != null)
- && (mouse.getAbsoluteY() == getY() + getHeight() - 1)
- && ((mouse.getAbsoluteX() == getX() + getWidth() - 1)
- || (mouse.getAbsoluteX() == getX() + getWidth() - 2))
- ) {
- return true;
- }
- return false;
- }
-
- /**
- * Subclasses should override this method to cleanup resources. This is
- * called by application.closeWindow().
- */
- public void onClose() {
- // Default: do nothing
- }
-
- /**
- * Called by application.switchWindow() when this window gets the
- * focus, and also by application.addWindow().
- */
- public void onFocus() {
- // Default: do nothing
- }
-
- /**
- * Called by application.switchWindow() when another window gets the
- * focus.
- */
- public void onUnfocus() {
- // Default: do nothing
- }
-
- /**
- * Called by application.hideWindow().
- */
- public void onHide() {