2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
34 import jexer
.bits
.CellAttributes
;
35 import jexer
.bits
.GraphicsChars
;
36 import jexer
.event
.TKeypressEvent
;
37 import static jexer
.TKeypress
.*;
40 * TSubMenu is a special case menu item that wraps another TMenu.
42 public class TSubMenu
extends TMenuItem
{
45 * The menu window. Note package private access.
50 * Package private constructor.
52 * @param parent parent widget
53 * @param title menu title. Title must contain a keyboard shortcut,
54 * denoted by prefixing a letter with "&", e.g. "&File"
55 * @param x column relative to parent
56 * @param y row relative to parent
58 TSubMenu(final TMenu parent
, final String title
, final int x
, final int y
) {
59 super(parent
, TMenu
.MID_UNUSED
, x
, y
, title
);
64 this.menu
= new TMenu(parent
.getApplication(), x
, getAbsoluteY() - 1,
66 setWidth(menu
.getWidth() + 2);
68 this.menu
.isSubMenu
= true;
72 * Draw the menu title.
78 CellAttributes background
= getTheme().getColor("tmenu");
79 CellAttributes menuColor
;
80 CellAttributes menuMnemonicColor
;
81 if (getAbsoluteActive()) {
82 menuColor
= getTheme().getColor("tmenu.highlighted");
83 menuMnemonicColor
= getTheme().getColor("tmenu.mnemonic.highlighted");
86 menuColor
= getTheme().getColor("tmenu");
87 menuMnemonicColor
= getTheme().getColor("tmenu.mnemonic");
89 menuColor
= getTheme().getColor("tmenu.disabled");
90 menuMnemonicColor
= getTheme().getColor("tmenu.disabled");
95 getScreen().putCharXY(getWidth() - 2, 0, GraphicsChars
.CP437
[0x10],
102 * @param keypress keystroke event
105 public void onKeypress(final TKeypressEvent keypress
) {
107 if (menu
.getActive()) {
108 menu
.onKeypress(keypress
);
112 if (keypress
.equals(kbEnter
)) {
117 if (keypress
.equals(kbRight
)) {
122 if (keypress
.equals(kbDown
)) {
123 getParent().switchWidget(true);
127 if (keypress
.equals(kbUp
)) {
128 getParent().switchWidget(false);
132 if (keypress
.equals(kbLeft
)) {
133 TMenu parentMenu
= (TMenu
) getParent();
134 if (parentMenu
.isSubMenu
) {
135 getApplication().closeSubMenu();
137 getApplication().switchMenu(false);
142 if (keypress
.equals(kbEsc
)) {
143 getApplication().closeMenu();
149 * Override dispatch() to do nothing.
152 public void dispatch() {
153 assert (getEnabled());
154 if (getAbsoluteActive()) {
155 if (!menu
.getActive()) {
156 getApplication().addSubMenu(menu
);
157 menu
.setActive(true);
163 * Returns my active widget.
165 * @return widget that is active, or this if no children
168 public TWidget
getActiveChild() {
169 if (menu
.getActive()) {
172 // Menu not active, return me