note pending release
[fanfix.git] / src / jexer / TCommand.java
CommitLineData
daa4106c 1/*
df8de03f
KL
2 * Jexer - Java Text User Interface
3 *
e16dda65 4 * The MIT License (MIT)
df8de03f 5 *
a69ed767 6 * Copyright (C) 2019 Kevin Lamonte
df8de03f 7 *
e16dda65
KL
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
df8de03f 14 *
e16dda65
KL
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
df8de03f 17 *
e16dda65
KL
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
7b5261bc
KL
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
df8de03f
KL
28 */
29package jexer;
30
31/**
7b5261bc
KL
32 * This class encapsulates a user command event. User commands can be
33 * generated by menu actions, keyboard accelerators, and other UI elements.
34 * Commands can operate on both the application and individual widgets.
df8de03f
KL
35 */
36public class TCommand {
37
d36057df
KL
38 // ------------------------------------------------------------------------
39 // Constants --------------------------------------------------------------
40 // ------------------------------------------------------------------------
41
7b5261bc 42 /**
d4a29741
KL
43 * Immediately abort the application (e.g. remote side closed
44 * connection).
45 */
2ce6dab2 46 public static final int ABORT = 1;
df8de03f 47
d4a29741
KL
48 /**
49 * File open dialog.
50 */
2ce6dab2 51 public static final int OPEN = 2;
d4a29741
KL
52
53 /**
54 * Exit application.
55 */
2ce6dab2 56 public static final int EXIT = 3;
d4a29741
KL
57
58 /**
59 * Spawn OS shell window.
60 */
2ce6dab2 61 public static final int SHELL = 4;
d4a29741
KL
62
63 /**
64 * Cut selected text and copy to the clipboard.
65 */
2ce6dab2 66 public static final int CUT = 5;
d4a29741
KL
67
68 /**
69 * Copy selected text to clipboard.
70 */
2ce6dab2 71 public static final int COPY = 6;
d4a29741
KL
72
73 /**
74 * Paste from clipboard.
75 */
2ce6dab2 76 public static final int PASTE = 7;
d4a29741
KL
77
78 /**
79 * Clear selected text without copying it to the clipboard.
80 */
2ce6dab2 81 public static final int CLEAR = 8;
d4a29741
KL
82
83 /**
84 * Tile windows.
85 */
2ce6dab2 86 public static final int TILE = 9;
d4a29741
KL
87
88 /**
89 * Cascade windows.
90 */
2ce6dab2 91 public static final int CASCADE = 10;
d4a29741
KL
92
93 /**
94 * Close all windows.
95 */
2ce6dab2 96 public static final int CLOSE_ALL = 11;
d4a29741
KL
97
98 /**
99 * Move (move/resize) window.
100 */
2ce6dab2 101 public static final int WINDOW_MOVE = 12;
d4a29741
KL
102
103 /**
104 * Zoom (maximize/restore) window.
105 */
2ce6dab2 106 public static final int WINDOW_ZOOM = 13;
d4a29741
KL
107
108 /**
109 * Next window (like Alt-TAB).
110 */
2ce6dab2 111 public static final int WINDOW_NEXT = 14;
d4a29741
KL
112
113 /**
114 * Previous window (like Shift-Alt-TAB).
115 */
2ce6dab2 116 public static final int WINDOW_PREVIOUS = 15;
d4a29741
KL
117
118 /**
119 * Close window.
120 */
2ce6dab2
KL
121 public static final int WINDOW_CLOSE = 16;
122
123 /**
124 * Enter help system.
125 */
126 public static final int HELP = 20;
df8de03f 127
71a389c9
KL
128 /**
129 * Enter first menu.
130 */
131 public static final int MENU = 21;
132
133 /**
134 * Save file.
135 */
136 public static final int SAVE = 30;
137
abb84744
KL
138 /**
139 * Backend disconnected.
140 */
141 public static final int BACKEND_DISCONNECT = 100;
142
d36057df
KL
143 public static final TCommand cmAbort = new TCommand(ABORT);
144 public static final TCommand cmExit = new TCommand(EXIT);
145 public static final TCommand cmQuit = new TCommand(EXIT);
146 public static final TCommand cmOpen = new TCommand(OPEN);
147 public static final TCommand cmShell = new TCommand(SHELL);
148 public static final TCommand cmCut = new TCommand(CUT);
149 public static final TCommand cmCopy = new TCommand(COPY);
150 public static final TCommand cmPaste = new TCommand(PASTE);
151 public static final TCommand cmClear = new TCommand(CLEAR);
152 public static final TCommand cmTile = new TCommand(TILE);
153 public static final TCommand cmCascade = new TCommand(CASCADE);
154 public static final TCommand cmCloseAll = new TCommand(CLOSE_ALL);
155 public static final TCommand cmWindowMove = new TCommand(WINDOW_MOVE);
156 public static final TCommand cmWindowZoom = new TCommand(WINDOW_ZOOM);
157 public static final TCommand cmWindowNext = new TCommand(WINDOW_NEXT);
158 public static final TCommand cmWindowPrevious = new TCommand(WINDOW_PREVIOUS);
159 public static final TCommand cmWindowClose = new TCommand(WINDOW_CLOSE);
160 public static final TCommand cmHelp = new TCommand(HELP);
161 public static final TCommand cmSave = new TCommand(SAVE);
162 public static final TCommand cmMenu = new TCommand(MENU);
abb84744 163 public static final TCommand cmBackendDisconnect = new TCommand(BACKEND_DISCONNECT);
d36057df
KL
164
165 // ------------------------------------------------------------------------
166 // Variables --------------------------------------------------------------
167 // ------------------------------------------------------------------------
168
df8de03f
KL
169 /**
170 * Type of command, one of EXIT, CASCADE, etc.
171 */
d4a29741 172 private int type;
df8de03f 173
d36057df
KL
174 // ------------------------------------------------------------------------
175 // Constructors -----------------------------------------------------------
176 // ------------------------------------------------------------------------
177
df8de03f 178 /**
a69ed767 179 * Public constructor.
df8de03f
KL
180 *
181 * @param type the Type of command, one of EXIT, CASCADE, etc.
182 */
a69ed767 183 public TCommand(final int type) {
7b5261bc 184 this.type = type;
df8de03f
KL
185 }
186
d36057df
KL
187 // ------------------------------------------------------------------------
188 // TCommand ---------------------------------------------------------------
189 // ------------------------------------------------------------------------
190
df8de03f 191 /**
7b5261bc
KL
192 * Make human-readable description of this TCommand.
193 *
194 * @return displayable String
df8de03f
KL
195 */
196 @Override
7b5261bc
KL
197 public final String toString() {
198 return String.format("%s", type);
df8de03f
KL
199 }
200
4328bb42 201 /**
7b5261bc
KL
202 * Comparison check. All fields must match to return true.
203 *
204 * @param rhs another TCommand instance
205 * @return true if all fields are equal
4328bb42
KL
206 */
207 @Override
7b5261bc
KL
208 public final boolean equals(final Object rhs) {
209 if (!(rhs instanceof TCommand)) {
210 return false;
211 }
4328bb42 212
7b5261bc
KL
213 TCommand that = (TCommand) rhs;
214 return (type == that.type);
4328bb42
KL
215 }
216
e826b451
KL
217 /**
218 * Hashcode uses all fields in equals().
219 *
220 * @return the hash
221 */
222 @Override
223 public int hashCode() {
224 return type;
225 }
226
df8de03f 227}