-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAntCUI_NEW.java
More file actions
366 lines (320 loc) · 15.4 KB
/
Copy pathAntCUI_NEW.java
File metadata and controls
366 lines (320 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class AntCUI extends UserInterface {
private boolean darkMode = false;
private static final String ANSI_RESET = "\u001B[0m";
private static final String ANSI_BLACK = "\u001B[30m";
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_GREEN = "\u001B[32m";
private static final String ANSI_YELLOW = "\u001B[33m";
private static final String ANSI_BLUE = "\u001B[34m";
private static final String ANSI_PURPLE = "\u001B[35m";
private static final String ANSI_CYAN = "\u001B[36m";
private static final String ANSI_WHITE = "\u001B[37m";
private static final String ANSI_BG_BLACK = "\u001B[40m";
private static final String ANSI_BG_WHITE = "\u001B[47m";
@Override
public void showIntroduction() {
clearScreen();
showNotification("Welcome to Enhanced Decision Support System", "INFO");
System.out.println(getThemeColor("TITLE") + INTRODUCTION + ANSI_RESET);
showStatusIndicator("Application initialized successfully");
System.out.println(getThemeColor("PROMPT") + "\nType 'help' for commands or 'theme' to toggle dark mode" + ANSI_RESET);
}
@Override
public List<Alternative> getAlternatives() {
List<Alternative> alternativeList = new ArrayList<Alternative>();
Scanner sc = new Scanner(System.in);
showStatusIndicator("Alternative input started");
System.out.println(getThemeColor("HEADER") + "\n=== ALTERNATIVES INPUT ===" + ANSI_RESET);
System.out.println(getThemeColor("PROMPT") + FIRST_ALT_PROMPT + ": " + ANSI_RESET);
String alternative = sc.nextLine().trim();
// Handle theme toggle command
if ("theme".equalsIgnoreCase(alternative)) {
toggleDarkMode();
showNotification("Theme toggled to " + (darkMode ? "Dark Mode" : "Light Mode"), "SUCCESS");
System.out.println(getThemeColor("PROMPT") + FIRST_ALT_PROMPT + ": " + ANSI_RESET);
alternative = sc.nextLine().trim();
}
// Handle help command
if ("help".equalsIgnoreCase(alternative)) {
showHelp();
System.out.println(getThemeColor("PROMPT") + FIRST_ALT_PROMPT + ": " + ANSI_RESET);
alternative = sc.nextLine().trim();
}
int altCount = 0;
while (alternative != null && !("".equals(alternative))) {
alternativeList.add(new Alternative(alternative));
altCount++;
showNotification("Alternative '" + alternative + "' added successfully", "SUCCESS");
System.out.println(getThemeColor("PROMPT") + ADDITIONAL_ALT_PROMT + " (or press Enter to finish): " + ANSI_RESET);
alternative = sc.nextLine().trim();
// Handle theme toggle during input
if ("theme".equalsIgnoreCase(alternative)) {
toggleDarkMode();
showNotification("Theme toggled to " + (darkMode ? "Dark Mode" : "Light Mode"), "SUCCESS");
System.out.println(getThemeColor("PROMPT") + ADDITIONAL_ALT_PROMT + " (or press Enter to finish): " + ANSI_RESET);
alternative = sc.nextLine().trim();
}
}
showStatusIndicator(altCount + " alternatives added successfully");
return alternativeList;
}
@Override
public List<Factor> getFactors() {
List<Factor> factorList = new ArrayList<Factor>();
Scanner sc = new Scanner(System.in);
showStatusIndicator("Factor input started");
System.out.println(getThemeColor("HEADER") + "\n=== FACTORS INPUT ===" + ANSI_RESET);
System.out.println(getThemeColor("PROMPT") + FIRST_FACTOR_PROMPT + ": " + ANSI_RESET);
String factor = sc.nextLine().trim();
// Handle theme toggle command
if ("theme".equalsIgnoreCase(factor)) {
toggleDarkMode();
showNotification("Theme toggled to " + (darkMode ? "Dark Mode" : "Light Mode"), "SUCCESS");
System.out.println(getThemeColor("PROMPT") + FIRST_FACTOR_PROMPT + ": " + ANSI_RESET);
factor = sc.nextLine().trim();
}
int factorCount = 0;
while (factor != null && !("".equals(factor))) {
factorList.add(new Factor(factor));
factorCount++;
showNotification("Factor '" + factor + "' added successfully", "SUCCESS");
System.out.println(getThemeColor("PROMPT") + ADDITIONAL_FACTOR_PROMPT + " (or press Enter to finish): " + ANSI_RESET);
factor = sc.nextLine().trim();
// Handle theme toggle during input
if ("theme".equalsIgnoreCase(factor)) {
toggleDarkMode();
showNotification("Theme toggled to " + (darkMode ? "Dark Mode" : "Light Mode"), "SUCCESS");
System.out.println(getThemeColor("PROMPT") + ADDITIONAL_FACTOR_PROMT + " (or press Enter to finish): " + ANSI_RESET);
factor = sc.nextLine().trim();
}
}
showStatusIndicator(factorCount + " factors added successfully");
return factorList;
}
@Override
public void getFactorRankings(final List<Factor> factors,
final int standard) {
Scanner sc = new Scanner(System.in);
int firstAttribute = 0;
factors.get(firstAttribute).setRank(standard);
showStatusIndicator("Factor ranking process started");
System.out.println(getThemeColor("HEADER") + "\n=== FACTOR RANKING ===" + ANSI_RESET);
System.out.println(getThemeColor("INFO") + "\nAssume that "
+ factors.get(firstAttribute).getName()
+ " has an importance of " + standard + ",\n"
+ " and that higher values are more important.\n" + ANSI_RESET);
for (int i = firstAttribute + 1; i < factors.size(); i++) {
System.out.println(getThemeColor("PROMPT") + " How important is "
+ factors.get(i).getName() + "? " + ANSI_RESET);
String importance = sc.nextLine().trim();
// Handle theme toggle during ranking
if ("theme".equalsIgnoreCase(importance)) {
toggleDarkMode();
showNotification("Theme toggled to " + (darkMode ? "Dark Mode" : "Light Mode"), "SUCCESS");
System.out.println(getThemeColor("PROMPT") + " How important is "
+ factors.get(i).getName() + "? " + ANSI_RESET);
importance = sc.nextLine().trim();
}
if (importance == null || "".equals(importance)) {
factors.get(i).setRank(standard);
showNotification("Using default importance " + standard + " for " + factors.get(i).getName(), "INFO");
} else {
try {
factors.get(i).setRank(Integer.valueOf(importance));
showNotification("Importance " + importance + " set for " + factors.get(i).getName(), "SUCCESS");
} catch (NumberFormatException e) {
showNotification("Invalid number format. Using default importance " + standard, "WARNING");
factors.get(i).setRank(standard);
}
}
}
showStatusIndicator("All factors ranked successfully");
}
@Override
public double[][] getCrossRankings(final List<Alternative> alternatives,
final List<Factor> factors,
final int standard) {
Scanner sc = new Scanner(System.in);
double[][] crossRankings =
new double[alternatives.size()][factors.size()];
showStatusIndicator("Cross-ranking process started");
System.out.println(getThemeColor("HEADER") + "\n=== CROSS-RANKING ===" + ANSI_RESET);
for (int i = 0; i < factors.size(); i++) {
int firstAlternative = 0;
crossRankings[firstAlternative][i] = standard;
System.out.println(getThemeColor("SECTION") + "\nConsidering " + factors.get(i).getName()
+ " only..." + ANSI_RESET);
System.out.println(getThemeColor("INFO") + " if "
+ alternatives.get(firstAlternative).getDescriptor()
+ " has a value of " + standard + "... " + ANSI_RESET);
for (int j = firstAlternative + 1; j < alternatives.size(); j++) {
System.out.println(getThemeColor("PROMPT") + " ...what value would you associate"
+ " with " + alternatives.get(j).getDescriptor() + ": " + ANSI_RESET);
String rank = sc.nextLine().trim();
// Handle theme toggle during cross-ranking
if ("theme".equalsIgnoreCase(rank)) {
toggleDarkMode();
showNotification("Theme toggled to " + (darkMode ? "Dark Mode" : "Light Mode"), "SUCCESS");
System.out.println(getThemeColor("PROMPT") + " ...what value would you associate"
+ " with " + alternatives.get(j).getDescriptor() + ": " + ANSI_RESET);
rank = sc.nextLine().trim();
}
if (rank == null || "".equals(rank)) {
crossRankings[j][i] = standard;
showNotification("Using default value " + standard + " for " + alternatives.get(j).getDescriptor(), "INFO");
} else {
try {
crossRankings[j][i] = Integer.valueOf(rank);
showNotification("Value " + rank + " set for " + alternatives.get(j).getDescriptor(), "SUCCESS");
} catch (NumberFormatException e) {
showNotification("Invalid number format. Using default value " + standard, "WARNING");
crossRankings[j][i] = standard;
}
}
}
showStatusIndicator("Completed ranking for factor: " + factors.get(i).getName());
}
showStatusIndicator("Cross-ranking completed for all factors");
return crossRankings;
}
@Override
public void showResults(final List<Alternative> alternatives) {
clearScreen();
Alternative preferredAlternative = alternatives.get(0);
showNotification("Analysis complete! Displaying results...", "SUCCESS");
System.out.println(getThemeColor("HEADER") + "\n================\nPREFERRED CHOICE" + ANSI_RESET);
System.out.println(getThemeColor("SUCCESS") + preferredAlternative.getDescriptor() + ANSI_RESET);
System.out.println(getThemeColor("SECTION") + "-----" + ANSI_RESET);
for (Alternative a : alternatives) {
if (a.equals(preferredAlternative)) {
System.out.println(getThemeColor("SUCCESS") + "★ " + a + " ★" + ANSI_RESET);
} else {
System.out.println(getThemeColor("TEXT") + " " + a + ANSI_RESET);
}
}
showStatusIndicator("Results displayed successfully");
System.out.println(getThemeColor("PROMPT") + "\nPress Enter to exit..." + ANSI_RESET);
try {
System.in.read();
} catch (Exception e) {
// Ignore exceptions on exit
}
}
/**
* Shows a toast-style notification with different colors based on type
* @param message The notification message
* @param type The type of notification (SUCCESS, WARNING, ERROR, INFO)
*/
private void showNotification(String message, String type) {
String color;
String symbol;
switch (type.toUpperCase()) {
case "SUCCESS":
color = ANSI_GREEN;
symbol = "✓";
break;
case "WARNING":
color = ANSI_YELLOW;
symbol = "⚠";
break;
case "ERROR":
color = ANSI_RED;
symbol = "✗";
break;
case "INFO":
default:
color = ANSI_CYAN;
symbol = "ℹ";
break;
}
System.out.println(color + "[" + symbol + "] " + message + ANSI_RESET);
}
/**
* Shows a status indicator with themed formatting
* @param status The status message to display
*/
private void showStatusIndicator(String status) {
System.out.println(getThemeColor("STATUS") + "↳ " + status + ANSI_RESET);
}
/**
* Toggles between dark and light mode
*/
private void toggleDarkMode() {
darkMode = !darkMode;
if (darkMode) {
System.out.print(ANSI_BG_BLACK + ANSI_WHITE);
} else {
System.out.print(ANSI_BG_WHITE + ANSI_BLACK);
}
}
/**
* Gets the appropriate color code based on current theme and element type
* @param elementType The type of UI element (TITLE, HEADER, PROMPT, etc.)
* @return ANSI color code string
*/
private String getThemeColor(String elementType) {
if (darkMode) {
switch (elementType) {
case "TITLE":
return ANSI_CYAN;
case "HEADER":
return ANSI_PURPLE;
case "SECTION":
return ANSI_BLUE;
case "PROMPT":
return ANSI_YELLOW;
case "SUCCESS":
return ANSI_GREEN;
case "INFO":
return ANSI_CYAN;
case "TEXT":
return ANSI_WHITE;
case "STATUS":
return ANSI_BLUE;
default:
return ANSI_WHITE;
}
} else {
switch (elementType) {
case "TITLE":
return ANSI_BLUE;
case "HEADER":
return ANSI_PURPLE;
case "SECTION":
return ANSI_CYAN;
case "PROMPT":
return ANSI_BLACK;
case "SUCCESS":
return ANSI_GREEN;
case "INFO":
return ANSI_BLUE;
case "TEXT":
return ANSI_BLACK;
case "STATUS":
return ANSI_CYAN;
default:
return ANSI_BLACK;
}
}
}
/**
* Clears the console screen
*/
private void clearScreen() {
System.out.print("\033[H\033[2J");
System.out.flush();
}
/**
* Shows help information
*/
private void showHelp() {
System.out.println(getThemeColor("HEADER") + "\n=== HELP ===" + ANSI_RESET);
System.out.println(getThemeColor("INFO") + "Available commands:" + ANSI_RESET);
System.out.println(getThemeColor("TEXT") + " • theme - Toggle between dark and light mode" + ANSI_RESET);
System.out.println(getThemeColor("TEXT") + " • help - Show this help message" + ANSI_RESET);
System.out.println(getThemeColor("TEXT") + " • [Enter] - Finish current input section" + ANSI_RESET);
}
}