Repository navigation
Expand file tree
/
Copy pathJPGUI.java
More file actions
131 lines (124 loc) · 5.06 KB
/
Copy pathJPGUI.java
File metadata and controls
131 lines (124 loc) · 5.06 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
import java.util.List;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import java.awt.Font;
/**
* Graphical user interface for decision support application.
*
* @author Dr. Jody Paul
* @version 20241114.3
*/
public class JPGUI extends UserInterface {
/** Default point size for JOptionPane dialog text. */
private static final int DEFAULT_FONT_SIZE = 12;
static { // Establish a common font for JOptionPane dialogs.
Font font = new Font("Monospaced", Font.PLAIN, DEFAULT_FONT_SIZE);
UIManager.put("OptionPane.messageFont", font);
}
@Override
public void showIntroduction() {
JOptionPane.showMessageDialog(null,
INTRODUCTION,
"Decision Support Aid",
JOptionPane.INFORMATION_MESSAGE);
}
@Override
public List<Alternative> getAlternatives() {
List<Alternative> alternativeList = new ArrayList<Alternative>();
String alternative = JOptionPane.showInputDialog(
FIRST_ALT_PROMPT + " (Cancel to quit.)");
while (alternative != null && !("".equals(alternative))) {
alternativeList.add(new Alternative(alternative));
alternative = JOptionPane.showInputDialog(ADDITIONAL_ALT_PROMT);
}
if (alternativeList.size() < 1) {
System.err.println("No alternatives entered.");
System.exit(2);
}
return alternativeList;
}
@Override
public List<Factor> getFactors() {
List<Factor> factorList = new ArrayList<Factor>();
String factor = JOptionPane.showInputDialog(FIRST_FACTOR_PROMPT);
while (factor != null && !("".equals(factor))) {
factorList.add(new Factor(factor));
factor = JOptionPane.showInputDialog(ADDITIONAL_FACTOR_PROMPT);
}
if (factorList.size() < 1) {
System.err.println("No factors entered.");
System.exit(2);
}
return factorList;
}
@Override
public void getFactorRankings(final List<Factor> factorList,
final int standard) {
int lastFactor = factorList.size() - 1;
for (int i = 0; i < lastFactor; i++) {
String importance = JOptionPane.showInputDialog(
"<HTML>If <B><SIZE=+1>"
+ factorList.get(lastFactor).getName()
+ "</SIZE></B> has an <I>importance</I> of <B>"
+ standard
+ "</B>,<BR>"
+ "how important is <B><SIZE=+1>"
+ factorList.get(i).getName()
+ "</SIZE></B>?</HTML>");
if (importance == null || "".equals(importance)) {
factorList.get(i).setRank(standard);
} else {
factorList.get(i).setRank(Integer.valueOf(importance));
}
}
factorList.get(lastFactor).setRank(standard);
}
@Override
public double[][] getCrossRankings(final List<Alternative> alternatives,
final List<Factor> factors,
final int standard) {
double[][] crossRankings = new double[alternatives.size()]
[factors.size()];
for (int i = 0; i < factors.size(); i++) {
int firstAlternative = 0;
crossRankings[firstAlternative][i] = standard;
for (int j = firstAlternative + 1; j < alternatives.size(); j++) {
String rank = JOptionPane.showInputDialog(
"<HTML>Considering <B><SIZE=+1>"
+ factors.get(i).getName()
+ "</SIZE></B> only,<BR>"
+ "if <B><SIZE=+1>"
+ alternatives.get(firstAlternative).getDescriptor()
+ "</SIZE></B> has a value of <B><SIZE=+1>"
+ standard
+ "</SIZE></B> "
+ ",<BR>"
+ "what value would you associate with <B><SIZE=+1>"
+ alternatives.get(j).getDescriptor()
+ "</SIZE></B><BR>"
+ "(a higher value is <I>more desirable</I>)?</HTML>");
if (rank == null || "".equals(rank)) {
crossRankings[j][i] = standard;
} else {
crossRankings[j][i] = Integer.valueOf(rank);
}
}
}
return crossRankings;
}
@Override
public void showResults(final List<Alternative> alternatives) {
Alternative preferredAlternative = alternatives.get(0);
String s = "<HTML>Preferred choice: <B>";
s += preferredAlternative.getDescriptor();
s += "</B>\n-----\n";
for (Alternative a : alternatives) {
s += a + "\n";
}
JOptionPane.showMessageDialog(null,
s,
"Decider Results",
JOptionPane.INFORMATION_MESSAGE);
}
}