2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
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.
36 public class TCommand
{
38 // ------------------------------------------------------------------------
39 // Constants --------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 * Immediately abort the application (e.g. remote side closed
46 public static final int ABORT
= 1;
51 public static final int OPEN
= 2;
56 public static final int EXIT
= 3;
59 * Spawn OS shell window.
61 public static final int SHELL
= 4;
64 * Cut selected text and copy to the clipboard.
66 public static final int CUT
= 5;
69 * Copy selected text to clipboard.
71 public static final int COPY
= 6;
74 * Paste from clipboard.
76 public static final int PASTE
= 7;
79 * Clear selected text without copying it to the clipboard.
81 public static final int CLEAR
= 8;
86 public static final int TILE
= 9;
91 public static final int CASCADE
= 10;
96 public static final int CLOSE_ALL
= 11;
99 * Move (move/resize) window.
101 public static final int WINDOW_MOVE
= 12;
104 * Zoom (maximize/restore) window.
106 public static final int WINDOW_ZOOM
= 13;
109 * Next window (like Alt-TAB).
111 public static final int WINDOW_NEXT
= 14;
114 * Previous window (like Shift-Alt-TAB).
116 public static final int WINDOW_PREVIOUS
= 15;
121 public static final int WINDOW_CLOSE
= 16;
126 public static final int HELP
= 20;
131 public static final int MENU
= 21;
136 public static final int SAVE
= 30;
138 public static final TCommand cmAbort
= new TCommand(ABORT
);
139 public static final TCommand cmExit
= new TCommand(EXIT
);
140 public static final TCommand cmQuit
= new TCommand(EXIT
);
141 public static final TCommand cmOpen
= new TCommand(OPEN
);
142 public static final TCommand cmShell
= new TCommand(SHELL
);
143 public static final TCommand cmCut
= new TCommand(CUT
);
144 public static final TCommand cmCopy
= new TCommand(COPY
);
145 public static final TCommand cmPaste
= new TCommand(PASTE
);
146 public static final TCommand cmClear
= new TCommand(CLEAR
);
147 public static final TCommand cmTile
= new TCommand(TILE
);
148 public static final TCommand cmCascade
= new TCommand(CASCADE
);
149 public static final TCommand cmCloseAll
= new TCommand(CLOSE_ALL
);
150 public static final TCommand cmWindowMove
= new TCommand(WINDOW_MOVE
);
151 public static final TCommand cmWindowZoom
= new TCommand(WINDOW_ZOOM
);
152 public static final TCommand cmWindowNext
= new TCommand(WINDOW_NEXT
);
153 public static final TCommand cmWindowPrevious
= new TCommand(WINDOW_PREVIOUS
);
154 public static final TCommand cmWindowClose
= new TCommand(WINDOW_CLOSE
);
155 public static final TCommand cmHelp
= new TCommand(HELP
);
156 public static final TCommand cmSave
= new TCommand(SAVE
);
157 public static final TCommand cmMenu
= new TCommand(MENU
);
159 // ------------------------------------------------------------------------
160 // Variables --------------------------------------------------------------
161 // ------------------------------------------------------------------------
164 * Type of command, one of EXIT, CASCADE, etc.
168 // ------------------------------------------------------------------------
169 // Constructors -----------------------------------------------------------
170 // ------------------------------------------------------------------------
173 * Public constructor.
175 * @param type the Type of command, one of EXIT, CASCADE, etc.
177 public TCommand(final int type
) {
181 // ------------------------------------------------------------------------
182 // TCommand ---------------------------------------------------------------
183 // ------------------------------------------------------------------------
186 * Make human-readable description of this TCommand.
188 * @return displayable String
191 public final String
toString() {
192 return String
.format("%s", type
);
196 * Comparison check. All fields must match to return true.
198 * @param rhs another TCommand instance
199 * @return true if all fields are equal
202 public final boolean equals(final Object rhs
) {
203 if (!(rhs
instanceof TCommand
)) {
207 TCommand that
= (TCommand
) rhs
;
208 return (type
== that
.type
);
212 * Hashcode uses all fields in equals().
217 public int hashCode() {