Commit | Line | Data |
---|---|---|
df8de03f KL |
1 | /** |
2 | * Jexer - Java Text User Interface | |
3 | * | |
df8de03f KL |
4 | * License: LGPLv3 or later |
5 | * | |
7b5261bc KL |
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. | |
df8de03f KL |
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 | |
7b5261bc KL |
27 | * |
28 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
29 | * @version 1 | |
df8de03f KL |
30 | */ |
31 | package jexer; | |
32 | ||
33 | /** | |
7b5261bc KL |
34 | * This class encapsulates a user command event. User commands can be |
35 | * generated by menu actions, keyboard accelerators, and other UI elements. | |
36 | * Commands can operate on both the application and individual widgets. | |
df8de03f KL |
37 | */ |
38 | public class TCommand { | |
39 | ||
7b5261bc KL |
40 | /** |
41 | * The following types are predefined for the entire system. | |
42 | * | |
43 | * TODO: Switch this to int so that TCommand can be subclassed so that | |
44 | * applications can add more. | |
45 | */ | |
df8de03f | 46 | public enum Type { |
7b5261bc KL |
47 | /** |
48 | * Immediately abort the application (e.g. remote side closed | |
49 | * connection). | |
50 | */ | |
51 | ABORT, | |
52 | ||
53 | /** | |
54 | * File open dialog. | |
55 | */ | |
56 | OPEN, | |
57 | ||
58 | /** | |
59 | * Exit application. | |
60 | */ | |
61 | EXIT, | |
62 | ||
63 | /** | |
64 | * Spawn OS shell window. | |
65 | */ | |
66 | SHELL, | |
67 | ||
68 | /** | |
69 | * Cut selected text and copy to the clipboard. | |
70 | */ | |
71 | CUT, | |
72 | ||
73 | /** | |
74 | * Copy selected text to clipboard. | |
75 | */ | |
76 | COPY, | |
77 | ||
78 | /** | |
79 | * Paste from clipboard. | |
80 | */ | |
81 | PASTE, | |
82 | ||
83 | /** | |
84 | * Clear selected text without copying it to the clipboard. | |
85 | */ | |
86 | CLEAR, | |
87 | ||
88 | /** | |
89 | * Tile windows. | |
90 | */ | |
91 | TILE, | |
92 | ||
93 | /** | |
94 | * Cascade windows. | |
95 | */ | |
96 | CASCADE, | |
97 | ||
98 | /** | |
99 | * Close all windows. | |
100 | */ | |
101 | CLOSE_ALL, | |
102 | ||
103 | /** | |
104 | * Move (move/resize) window. | |
105 | */ | |
106 | WINDOW_MOVE, | |
107 | ||
108 | /** | |
109 | * Zoom (maximize/restore) window. | |
110 | */ | |
111 | WINDOW_ZOOM, | |
112 | ||
113 | /** | |
114 | * Next window (like Alt-TAB). | |
115 | */ | |
116 | WINDOW_NEXT, | |
117 | ||
118 | /** | |
119 | * Previous window (like Shift-Alt-TAB). | |
120 | */ | |
121 | WINDOW_PREVIOUS, | |
122 | ||
123 | /** | |
124 | * Close window. | |
125 | */ | |
126 | WINDOW_CLOSE, | |
df8de03f KL |
127 | |
128 | } | |
129 | ||
130 | /** | |
131 | * Type of command, one of EXIT, CASCADE, etc. | |
132 | */ | |
7b5261bc | 133 | private Type type; |
df8de03f KL |
134 | |
135 | /** | |
7b5261bc | 136 | * Public constructor. |
df8de03f KL |
137 | * |
138 | * @param type the Type of command, one of EXIT, CASCADE, etc. | |
139 | */ | |
7b5261bc KL |
140 | public TCommand(final Type type) { |
141 | this.type = type; | |
df8de03f KL |
142 | } |
143 | ||
144 | /** | |
7b5261bc KL |
145 | * Make human-readable description of this TCommand. |
146 | * | |
147 | * @return displayable String | |
df8de03f KL |
148 | */ |
149 | @Override | |
7b5261bc KL |
150 | public final String toString() { |
151 | return String.format("%s", type); | |
df8de03f KL |
152 | } |
153 | ||
4328bb42 | 154 | /** |
7b5261bc KL |
155 | * Comparison check. All fields must match to return true. |
156 | * | |
157 | * @param rhs another TCommand instance | |
158 | * @return true if all fields are equal | |
4328bb42 KL |
159 | */ |
160 | @Override | |
7b5261bc KL |
161 | public final boolean equals(final Object rhs) { |
162 | if (!(rhs instanceof TCommand)) { | |
163 | return false; | |
164 | } | |
4328bb42 | 165 | |
7b5261bc KL |
166 | TCommand that = (TCommand) rhs; |
167 | return (type == that.type); | |
4328bb42 KL |
168 | } |
169 | ||
7b5261bc KL |
170 | public static final TCommand cmAbort = new TCommand(TCommand.Type.ABORT); |
171 | public static final TCommand cmExit = new TCommand(TCommand.Type.EXIT); | |
172 | public static final TCommand cmQuit = new TCommand(TCommand.Type.EXIT); | |
173 | public static final TCommand cmOpen = new TCommand(TCommand.Type.OPEN); | |
174 | public static final TCommand cmShell = new TCommand(TCommand.Type.SHELL); | |
175 | public static final TCommand cmCut = new TCommand(TCommand.Type.CUT); | |
176 | public static final TCommand cmCopy = new TCommand(TCommand.Type.COPY); | |
177 | public static final TCommand cmPaste = new TCommand(TCommand.Type.PASTE); | |
178 | public static final TCommand cmClear = new TCommand(TCommand.Type.CLEAR); | |
179 | public static final TCommand cmTile = new TCommand(TCommand.Type.TILE); | |
180 | public static final TCommand cmCascade = new TCommand(TCommand.Type.CASCADE); | |
181 | public static final TCommand cmCloseAll = new TCommand(TCommand.Type.CLOSE_ALL); | |
182 | public static final TCommand cmWindowMove = new TCommand(TCommand.Type.WINDOW_MOVE); | |
183 | public static final TCommand cmWindowZoom = new TCommand(TCommand.Type.WINDOW_ZOOM); | |
184 | public static final TCommand cmWindowNext = new TCommand(TCommand.Type.WINDOW_NEXT); | |
185 | public static final TCommand cmWindowPrevious = new TCommand(TCommand.Type.WINDOW_PREVIOUS); | |
186 | public static final TCommand cmWindowClose = new TCommand(TCommand.Type.WINDOW_CLOSE); | |
df8de03f KL |
187 | |
188 | } |