LICENSE CHANGED TO MIT
[nikiroo-utils.git] / src / jexer / TCommand.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2016 Kevin Lamonte
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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.
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29 package jexer;
30
31 /**
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.
35 */
36 public class TCommand {
37
38 /**
39 * Immediately abort the application (e.g. remote side closed
40 * connection).
41 */
42 public static final int ABORT = 1;
43
44 /**
45 * File open dialog.
46 */
47 public static final int OPEN = 2;
48
49 /**
50 * Exit application.
51 */
52 public static final int EXIT = 3;
53
54 /**
55 * Spawn OS shell window.
56 */
57 public static final int SHELL = 4;
58
59 /**
60 * Cut selected text and copy to the clipboard.
61 */
62 public static final int CUT = 5;
63
64 /**
65 * Copy selected text to clipboard.
66 */
67 public static final int COPY = 6;
68
69 /**
70 * Paste from clipboard.
71 */
72 public static final int PASTE = 7;
73
74 /**
75 * Clear selected text without copying it to the clipboard.
76 */
77 public static final int CLEAR = 8;
78
79 /**
80 * Tile windows.
81 */
82 public static final int TILE = 9;
83
84 /**
85 * Cascade windows.
86 */
87 public static final int CASCADE = 10;
88
89 /**
90 * Close all windows.
91 */
92 public static final int CLOSE_ALL = 11;
93
94 /**
95 * Move (move/resize) window.
96 */
97 public static final int WINDOW_MOVE = 12;
98
99 /**
100 * Zoom (maximize/restore) window.
101 */
102 public static final int WINDOW_ZOOM = 13;
103
104 /**
105 * Next window (like Alt-TAB).
106 */
107 public static final int WINDOW_NEXT = 14;
108
109 /**
110 * Previous window (like Shift-Alt-TAB).
111 */
112 public static final int WINDOW_PREVIOUS = 15;
113
114 /**
115 * Close window.
116 */
117 public static final int WINDOW_CLOSE = 16;
118
119 /**
120 * Type of command, one of EXIT, CASCADE, etc.
121 */
122 private int type;
123
124 /**
125 * Protected constructor. Subclasses can be used to define new commands.
126 *
127 * @param type the Type of command, one of EXIT, CASCADE, etc.
128 */
129 protected TCommand(final int type) {
130 this.type = type;
131 }
132
133 /**
134 * Make human-readable description of this TCommand.
135 *
136 * @return displayable String
137 */
138 @Override
139 public final String toString() {
140 return String.format("%s", type);
141 }
142
143 /**
144 * Comparison check. All fields must match to return true.
145 *
146 * @param rhs another TCommand instance
147 * @return true if all fields are equal
148 */
149 @Override
150 public final boolean equals(final Object rhs) {
151 if (!(rhs instanceof TCommand)) {
152 return false;
153 }
154
155 TCommand that = (TCommand) rhs;
156 return (type == that.type);
157 }
158
159 /**
160 * Hashcode uses all fields in equals().
161 *
162 * @return the hash
163 */
164 @Override
165 public int hashCode() {
166 return type;
167 }
168
169 public static final TCommand cmAbort = new TCommand(ABORT);
170 public static final TCommand cmExit = new TCommand(EXIT);
171 public static final TCommand cmQuit = new TCommand(EXIT);
172 public static final TCommand cmOpen = new TCommand(OPEN);
173 public static final TCommand cmShell = new TCommand(SHELL);
174 public static final TCommand cmCut = new TCommand(CUT);
175 public static final TCommand cmCopy = new TCommand(COPY);
176 public static final TCommand cmPaste = new TCommand(PASTE);
177 public static final TCommand cmClear = new TCommand(CLEAR);
178 public static final TCommand cmTile = new TCommand(TILE);
179 public static final TCommand cmCascade = new TCommand(CASCADE);
180 public static final TCommand cmCloseAll = new TCommand(CLOSE_ALL);
181 public static final TCommand cmWindowMove = new TCommand(WINDOW_MOVE);
182 public static final TCommand cmWindowZoom = new TCommand(WINDOW_ZOOM);
183 public static final TCommand cmWindowNext = new TCommand(WINDOW_NEXT);
184 public static final TCommand cmWindowPrevious = new TCommand(WINDOW_PREVIOUS);
185 public static final TCommand cmWindowClose = new TCommand(WINDOW_CLOSE);
186
187 }