Expose width/height in TApplication constructor, attempt on ECMA48
[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 *
a2018e99 6 * Copyright (C) 2017 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
7b5261bc 38 /**
d4a29741
KL
39 * Immediately abort the application (e.g. remote side closed
40 * connection).
41 */
2ce6dab2 42 public static final int ABORT = 1;
df8de03f 43
d4a29741
KL
44 /**
45 * File open dialog.
46 */
2ce6dab2 47 public static final int OPEN = 2;
d4a29741
KL
48
49 /**
50 * Exit application.
51 */
2ce6dab2 52 public static final int EXIT = 3;
d4a29741
KL
53
54 /**
55 * Spawn OS shell window.
56 */
2ce6dab2 57 public static final int SHELL = 4;
d4a29741
KL
58
59 /**
60 * Cut selected text and copy to the clipboard.
61 */
2ce6dab2 62 public static final int CUT = 5;
d4a29741
KL
63
64 /**
65 * Copy selected text to clipboard.
66 */
2ce6dab2 67 public static final int COPY = 6;
d4a29741
KL
68
69 /**
70 * Paste from clipboard.
71 */
2ce6dab2 72 public static final int PASTE = 7;
d4a29741
KL
73
74 /**
75 * Clear selected text without copying it to the clipboard.
76 */
2ce6dab2 77 public static final int CLEAR = 8;
d4a29741
KL
78
79 /**
80 * Tile windows.
81 */
2ce6dab2 82 public static final int TILE = 9;
d4a29741
KL
83
84 /**
85 * Cascade windows.
86 */
2ce6dab2 87 public static final int CASCADE = 10;
d4a29741
KL
88
89 /**
90 * Close all windows.
91 */
2ce6dab2 92 public static final int CLOSE_ALL = 11;
d4a29741
KL
93
94 /**
95 * Move (move/resize) window.
96 */
2ce6dab2 97 public static final int WINDOW_MOVE = 12;
d4a29741
KL
98
99 /**
100 * Zoom (maximize/restore) window.
101 */
2ce6dab2 102 public static final int WINDOW_ZOOM = 13;
d4a29741
KL
103
104 /**
105 * Next window (like Alt-TAB).
106 */
2ce6dab2 107 public static final int WINDOW_NEXT = 14;
d4a29741
KL
108
109 /**
110 * Previous window (like Shift-Alt-TAB).
111 */
2ce6dab2 112 public static final int WINDOW_PREVIOUS = 15;
d4a29741
KL
113
114 /**
115 * Close window.
116 */
2ce6dab2
KL
117 public static final int WINDOW_CLOSE = 16;
118
119 /**
120 * Enter help system.
121 */
122 public static final int HELP = 20;
df8de03f 123
71a389c9
KL
124 /**
125 * Enter first menu.
126 */
127 public static final int MENU = 21;
128
129 /**
130 * Save file.
131 */
132 public static final int SAVE = 30;
133
df8de03f
KL
134 /**
135 * Type of command, one of EXIT, CASCADE, etc.
136 */
d4a29741 137 private int type;
df8de03f
KL
138
139 /**
d4a29741 140 * Protected constructor. Subclasses can be used to define new commands.
df8de03f
KL
141 *
142 * @param type the Type of command, one of EXIT, CASCADE, etc.
143 */
d4a29741 144 protected TCommand(final int type) {
7b5261bc 145 this.type = type;
df8de03f
KL
146 }
147
148 /**
7b5261bc
KL
149 * Make human-readable description of this TCommand.
150 *
151 * @return displayable String
df8de03f
KL
152 */
153 @Override
7b5261bc
KL
154 public final String toString() {
155 return String.format("%s", type);
df8de03f
KL
156 }
157
4328bb42 158 /**
7b5261bc
KL
159 * Comparison check. All fields must match to return true.
160 *
161 * @param rhs another TCommand instance
162 * @return true if all fields are equal
4328bb42
KL
163 */
164 @Override
7b5261bc
KL
165 public final boolean equals(final Object rhs) {
166 if (!(rhs instanceof TCommand)) {
167 return false;
168 }
4328bb42 169
7b5261bc
KL
170 TCommand that = (TCommand) rhs;
171 return (type == that.type);
4328bb42
KL
172 }
173
e826b451
KL
174 /**
175 * Hashcode uses all fields in equals().
176 *
177 * @return the hash
178 */
179 @Override
180 public int hashCode() {
181 return type;
182 }
183
2ce6dab2
KL
184 public static final TCommand cmAbort = new TCommand(ABORT);
185 public static final TCommand cmExit = new TCommand(EXIT);
186 public static final TCommand cmQuit = new TCommand(EXIT);
187 public static final TCommand cmOpen = new TCommand(OPEN);
188 public static final TCommand cmShell = new TCommand(SHELL);
189 public static final TCommand cmCut = new TCommand(CUT);
190 public static final TCommand cmCopy = new TCommand(COPY);
191 public static final TCommand cmPaste = new TCommand(PASTE);
192 public static final TCommand cmClear = new TCommand(CLEAR);
193 public static final TCommand cmTile = new TCommand(TILE);
194 public static final TCommand cmCascade = new TCommand(CASCADE);
195 public static final TCommand cmCloseAll = new TCommand(CLOSE_ALL);
196 public static final TCommand cmWindowMove = new TCommand(WINDOW_MOVE);
197 public static final TCommand cmWindowZoom = new TCommand(WINDOW_ZOOM);
198 public static final TCommand cmWindowNext = new TCommand(WINDOW_NEXT);
d4a29741 199 public static final TCommand cmWindowPrevious = new TCommand(WINDOW_PREVIOUS);
2ce6dab2
KL
200 public static final TCommand cmWindowClose = new TCommand(WINDOW_CLOSE);
201 public static final TCommand cmHelp = new TCommand(HELP);
71a389c9
KL
202 public static final TCommand cmSave = new TCommand(SAVE);
203 public static final TCommand cmMenu = new TCommand(MENU);
df8de03f
KL
204
205}