| 1 | /** |
| 2 | * Jexer - Java Text User Interface |
| 3 | * |
| 4 | * License: LGPLv3 or later |
| 5 | * |
| 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. |
| 9 | * |
| 10 | * Copyright (C) 2015 Kevin Lamonte |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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 |
| 26 | * 02110-1301 USA |
| 27 | * |
| 28 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] |
| 29 | * @version 1 |
| 30 | */ |
| 31 | package jexer; |
| 32 | |
| 33 | import jexer.bits.MnemonicString; |
| 34 | |
| 35 | /** |
| 36 | * TMenu is a top-level collection of TMenuItems. |
| 37 | */ |
| 38 | public class TMenu extends TWindow { |
| 39 | |
| 40 | /** |
| 41 | * If true, this is a sub-menu. |
| 42 | */ |
| 43 | private boolean isSubMenu = false; |
| 44 | |
| 45 | /** |
| 46 | * The shortcut and title. |
| 47 | */ |
| 48 | private MnemonicString mnemonic; |
| 49 | |
| 50 | // Reserved menu item IDs |
| 51 | public static final int MID_UNUSED = -1; |
| 52 | |
| 53 | // File menu |
| 54 | public static final int MID_EXIT = 1; |
| 55 | public static final int MID_QUIT = MID_EXIT; |
| 56 | public static final int MID_OPEN_FILE = 2; |
| 57 | public static final int MID_SHELL = 3; |
| 58 | |
| 59 | // Edit menu |
| 60 | public static final int MID_CUT = 10; |
| 61 | public static final int MID_COPY = 11; |
| 62 | public static final int MID_PASTE = 12; |
| 63 | public static final int MID_CLEAR = 13; |
| 64 | |
| 65 | // Window menu |
| 66 | public static final int MID_TILE = 20; |
| 67 | public static final int MID_CASCADE = 21; |
| 68 | public static final int MID_CLOSE_ALL = 22; |
| 69 | public static final int MID_WINDOW_MOVE = 23; |
| 70 | public static final int MID_WINDOW_ZOOM = 24; |
| 71 | public static final int MID_WINDOW_NEXT = 25; |
| 72 | public static final int MID_WINDOW_PREVIOUS = 26; |
| 73 | public static final int MID_WINDOW_CLOSE = 27; |
| 74 | |
| 75 | /** |
| 76 | * Public constructor. |
| 77 | * |
| 78 | * @param parent parent application |
| 79 | * @param x column relative to parent |
| 80 | * @param y row relative to parent |
| 81 | * @param label mnemonic menu title. Label must contain a keyboard |
| 82 | * shortcut (mnemonic), denoted by prefixing a letter with "&", |
| 83 | * e.g. "&File" |
| 84 | */ |
| 85 | public TMenu(final TApplication parent, final int x, final int y, |
| 86 | final String label) { |
| 87 | |
| 88 | super(parent, label, x, y, parent.getScreen().getWidth(), |
| 89 | parent.getScreen().getHeight()); |
| 90 | |
| 91 | // My parent constructor added me as a window, get rid of that |
| 92 | parent.closeWindow(this); |
| 93 | |
| 94 | // Setup the menu shortcut |
| 95 | mnemonic = new MnemonicString(title); |
| 96 | this.title = mnemonic.getRawLabel(); |
| 97 | assert (mnemonic.getShortcutIdx() >= 0); |
| 98 | |
| 99 | // Recompute width and height to reflect an empty menu |
| 100 | width = this.title.length() + 4; |
| 101 | height = 2; |
| 102 | |
| 103 | this.active = false; |
| 104 | } |
| 105 | |
| 106 | } |