source: src/main/java/genius/gui/dialogs/EditIssueDialog.java@ 209

Last change on this file since 209 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 6.5 KB
Line 
1package genius.gui.dialogs;
2
3import java.awt.CardLayout;
4import java.awt.event.ActionEvent;
5import java.util.List;
6
7import javax.swing.JOptionPane;
8
9import genius.core.issue.Issue;
10import genius.core.issue.IssueDiscrete;
11import genius.core.issue.IssueInteger;
12import genius.core.issue.IssueReal;
13import genius.core.issue.ValueDiscrete;
14import genius.core.utility.AdditiveUtilitySpace;
15import genius.core.utility.EvaluatorDiscrete;
16import genius.core.utility.EvaluatorInteger;
17import genius.core.utility.EvaluatorReal;
18import genius.gui.tree.NegotiatorTreeTableModel;
19import genius.gui.tree.DomainAndProfileEditorPanel;
20
21/**
22 *
23 * @author Richard Noorlandt
24 *
25 * This launches a editissue dialog window. Wouter: this is ugly. The
26 * EditIssueDialog also handles editing of evaluators. it gets access to
27 * the util space via the treeFrame, the parent of this dialog.
28 */
29public class EditIssueDialog extends NewIssueDialog {
30
31 private static final long serialVersionUID = 5730169200768833303L;
32 private Issue issue;
33
34 // Constructors
35 public EditIssueDialog(DomainAndProfileEditorPanel owner, Issue issue) {
36 this(owner, false, issue);
37 }
38
39 public EditIssueDialog(DomainAndProfileEditorPanel owner, boolean modal, Issue issue) {
40 this(owner, modal, "Edit Issue", issue);
41 this.issue = issue;
42 }
43
44 public EditIssueDialog(DomainAndProfileEditorPanel owner, boolean modal, String name, Issue issue) {
45 super(owner, modal, name);
46 this.issue = issue;
47 setPanelContents(issue);
48 }
49
50 /**
51 * Load the appropriate contents into the right panel.
52 *
53 * @param issue
54 */
55 private void setPanelContents(Issue issue) {
56 AdditiveUtilitySpace utilSpace = treeFrame.getNegotiatorTreeTableModel().getUtilitySpace();
57
58 nameField.setText(issue.getName());
59 numberField.setText("" + issue.getNumber());
60
61 if (!treeFrame.isDomain() || !treeFrame.hasNoProfiles()) {
62 nameField.setEnabled(false);
63 }
64
65 if (issue instanceof IssueDiscrete) {
66 this.issueType.setSelectedItem(DISCRETE);
67 this.issueType.setEnabled(false);
68 ((CardLayout) issuePropertyCards.getLayout()).show(issuePropertyCards, DISCRETE);
69 List<ValueDiscrete> values = ((IssueDiscrete) issue).getValues();
70
71 String valueString = "";
72 String descString = "";
73 for (ValueDiscrete val : values) {
74 valueString = valueString + val.getValue() + "\n";
75 String desc = ((IssueDiscrete) issue).getDesc(val);
76 if (desc != null)
77 descString = descString + desc;
78 descString = descString + "\n";
79 }
80 discreteTextArea.setText(valueString);
81 if (utilSpace != null) {
82 EvaluatorDiscrete eval = (EvaluatorDiscrete) utilSpace.getEvaluator(issue.getNumber());
83 if (eval != null) {
84 // load the eval values
85 valueString = "";
86
87 for (ValueDiscrete val : values) {
88 Integer util = eval.getValue(val); // get the utility
89 // for this value
90 // System.out.println("util="+util);
91 if (util != null)
92 valueString = valueString + util;
93
94 valueString = valueString + "\n";
95 }
96 discreteTextEvaluationArea.setText(valueString);
97 }
98 }
99 } else if (issue instanceof IssueInteger) {
100 this.issueType.setSelectedItem(INTEGER);
101 this.issueType.setEnabled(false);
102
103 ((CardLayout) issuePropertyCards.getLayout()).show(issuePropertyCards, INTEGER);
104 integerMinField.setText("" + ((IssueInteger) issue).getLowerBound());
105 integerMaxField.setText("" + ((IssueInteger) issue).getUpperBound());
106 if (utilSpace != null) {
107 EvaluatorInteger eval = (EvaluatorInteger) utilSpace.getEvaluator(issue.getNumber());
108
109 if (eval != null) {
110 integerUtilityLowestValue.setText("" + eval.getUtilLowestValue());
111 integerUtilityHighestValue.setText("" + eval.getUtilHighestValue());
112 }
113 }
114 } else if (issue instanceof IssueReal) {
115 this.issueType.setSelectedItem(REAL);
116 this.issueType.setEnabled(false);
117 ((CardLayout) issuePropertyCards.getLayout()).show(issuePropertyCards, REAL);
118 realMinField.setText("" + ((IssueReal) issue).getLowerBound());
119 realMaxField.setText("" + ((IssueReal) issue).getUpperBound());
120 if (utilSpace != null) {
121 EvaluatorReal eval = (EvaluatorReal) utilSpace.getEvaluator(issue.getNumber());
122 if (eval != null) {
123 switch (eval.getFuncType()) {
124 case LINEAR:
125 realLinearField.setText("" + eval.getLinearParam());
126 case CONSTANT:
127 realParameterField.setText("" + eval.getConstantParam());
128 default:
129 break;
130 }
131 }
132 }
133 }
134 }
135
136 /**
137 * Overrides getObjectiveNumber from NewObjectiveDialog
138 */
139 @Override
140 protected int getObjectiveNumber() throws InvalidInputException {
141 try {
142 return Integer.parseInt(numberField.getText());
143 } catch (Exception e) {
144 throw new InvalidInputException("Error reading objective number from (hidden) field.");
145 }
146 }
147
148 /**
149 * Overrides actionPerformed from NewIssueDialog.
150 */
151 @Override
152 public void actionPerformed(ActionEvent e) {
153 if (e.getSource() == okButton) {
154 if (issue == null)
155 return;
156
157 boolean valid = true;
158 if (issue instanceof IssueInteger) {
159 if (((NegotiatorTreeTableModel) treeFrame.getTreeTable().getTree().getModel())
160 .getUtilitySpace() != null) {
161 double utilLIV = Double.parseDouble(integerUtilityLowestValue.getText());
162 double utilHIV = Double.parseDouble(integerUtilityHighestValue.getText());
163 if (utilLIV < 0.0 || utilLIV > 1.0) {
164 valid = false;
165 JOptionPane.showConfirmDialog(null,
166 "The utility of the lowest value should be \n" + "in the range [0, 1]", "Input",
167 JOptionPane.PLAIN_MESSAGE);
168 } else if (utilHIV < 0.0 || utilHIV > 1.0) {
169 valid = false;
170 JOptionPane.showConfirmDialog(null,
171 "The utility of the heighest value should be \n" + "in the range [0, 1]", "Input",
172 JOptionPane.PLAIN_MESSAGE);
173 }
174 }
175 }
176 if (valid) {
177 updateIssue(issue);
178
179 // Notify the model that the contents of the treetable have
180 // changed
181 NegotiatorTreeTableModel model = (NegotiatorTreeTableModel) treeFrame.getTreeTable().getTree()
182 .getModel();
183
184 (model.getIssueValuePanel(issue)).displayValues(issue);
185 Object[] path = { model.getRoot() };
186 if (treeFrame.getTreeTable().getTree().getSelectionPath() != null) {
187 path = treeFrame.getTreeTable().getTree().getSelectionPath().getPath();
188 }
189 model.treeStructureChanged(this, path);
190
191 this.dispose();
192 }
193 } else if (e.getSource() == cancelButton) {
194 this.dispose();
195 }
196 }
197}
Note: See TracBrowser for help on using the repository browser.