blob: 807f82d23bcacee945145f099b67bf37c917c97b (
plain)
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
|
package de.fhswf.in.inf.se.notepadMinusMinus.view;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import de.fhswf.in.inf.se.notepadMinusMinus.Main;
import de.fhswf.in.inf.se.notepadMinusMinus.model.Grade;
import de.fhswf.in.inf.se.notepadMinusMinus.util.OverLimitIntegerStringConverter;
import javafx.application.Platform;
import javafx.collections.ListChangeListener.Change;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.ComboBoxTableCell;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.stage.FileChooser;
/**
* TODO Add comment here
*
* @author $Author: $
* @version $Revision: $, $Date: $ UTC
*/
public class MainViewController
{
@FXML
private TableView<Grade> gradeTable;
@FXML
private TableColumn<Grade, Integer> semesterColumn;
@FXML
private TableColumn<Grade, String> modulenameColumn;
@FXML
private TableColumn<Grade, Integer> ectsColumn;
@FXML
private TableColumn<Grade, BigDecimal> gradeColumn;
@FXML
private TableColumn<Grade, Integer> attemptColumn;
@FXML
private Label ectsSumLabel;
@FXML
private Label averageGradeLabel;
@FXML
private Button deleteButton;
@FXML
private ComboBox<BigDecimal> colloquiumComboBox;
@FXML
private ComboBox<BigDecimal> thesisComboBox;
private Main main;
/**
* TODO Add method comment here
*
*/
@FXML
private void initialize()
{
semesterColumn.setCellValueFactory(
cellData -> cellData.getValue().semesterProperty().asObject());
semesterColumn.setCellFactory(TextFieldTableCell
.forTableColumn(new OverLimitIntegerStringConverter(1)));
semesterColumn.setOnEditCommit(data -> {
data.getRowValue().setSemester(data.getNewValue());
});
modulenameColumn.setCellValueFactory(
cellData -> cellData.getValue().modulenameProperty());
modulenameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
modulenameColumn.setOnEditCommit(data -> {
data.getRowValue().setModulename(data.getNewValue().trim());
});
ectsColumn.setCellValueFactory(
cellData -> cellData.getValue().ectsProperty().asObject());
ectsColumn.setCellFactory(TextFieldTableCell
.forTableColumn(new OverLimitIntegerStringConverter(0)));
ectsColumn.setOnEditCommit(data -> {
data.getRowValue().setEcts(data.getNewValue());
});
gradeColumn.setCellValueFactory(
cellData -> cellData.getValue().gradeProperty());
gradeColumn.setCellFactory(
ComboBoxTableCell.forTableColumn(Grade.gradeValuesProperty()));
gradeColumn.setOnEditCommit(data -> {
data.getRowValue().setGrade(data.getNewValue());
});
attemptColumn.setCellValueFactory(
cellData -> cellData.getValue().attemptProperty().asObject());
attemptColumn.setCellFactory(TextFieldTableCell
.forTableColumn(new OverLimitIntegerStringConverter(1)));
attemptColumn.setOnEditCommit(data -> {
data.getRowValue().setAttempt(data.getNewValue());
});
deleteButton.disableProperty().bind(gradeTable.getSelectionModel()
.selectedIndexProperty().lessThan(0));
thesisComboBox.setItems(Grade.gradeValuesProperty());
colloquiumComboBox.setItems(Grade.gradeValuesProperty());
}
/**
* TODO Add method comment here
*
* @param main
*/
public void setMain(Main main)
{
this.main = main;
gradeTable.setItems(main.getGradesObject().gradesProperty());
thesisComboBox.valueProperty()
.bindBidirectional(main.getGradesObject().colloquiumProperty());
colloquiumComboBox.valueProperty()
.bindBidirectional(main.getGradesObject().thesisProperty());
gradeTable.getItems().addListener((Change<? extends Grade> change) -> {
ectsSumLabel.setText("0");
averageGradeLabel.setText("0.0");
int sumEcts = 0;
BigDecimal gradesSumWeighted = BigDecimal.ZERO;
for (Grade grade : gradeTable.getItems())
{
if (grade.getGrade().compareTo(BigDecimal.ZERO) != 0)
{
sumEcts += grade.getEcts();
gradesSumWeighted = gradesSumWeighted.add(grade.getGrade()
.multiply(new BigDecimal(grade.getEcts())));
}
}
if (sumEcts > 0)
{
ectsSumLabel.setText(String.valueOf(sumEcts));
averageGradeLabel.setText(gradesSumWeighted
.divide(new BigDecimal(sumEcts), 2, RoundingMode.HALF_UP)
.toString());
}
});
}
/**
* TODO Add method comment here
*
*/
@FXML
private void handleNewValue()
{
Grade grade = new Grade();
gradeTable.getItems().add(grade);
}
/**
* TODO Add method comment here
*
*/
@FXML
private void handleDeleteValue()
{
Grade delete = gradeTable.getSelectionModel().getSelectedItem();
if (delete != null)
{
gradeTable.getItems().remove(delete);
}
}
/**
* TODO Add method comment here
*
*/
@FXML
private void handleNew()
{
if (main != null)
{
gradeTable.getItems().clear();
main.setOpenFile(null);
}
}
/**
* TODO Add method comment here
*
*/
@FXML
private void handleOpen()
{
FileChooser fileChooser = new FileChooser();
// Set extension filter
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(
"XML files (*.xml)", "*.xml");
fileChooser.getExtensionFilters().add(extFilter);
// Set initial Directory to a good value
if (main != null && main.getGradesFilePath() != null)
{
fileChooser
.setInitialDirectory(main.getGradesFilePath().getParentFile());
}
else
{
String userDirectoryString = System.getProperty("user.home");
File userDirectory = new File(userDirectoryString);
fileChooser.setInitialDirectory(userDirectory);
}
// Show save file dialog
File file = fileChooser.showOpenDialog(main.getPrimaryStage());
if (file != null)
{
main.loadGradesFromFile(file);
}
}
/**
* TODO Add method comment here
*
*/
@FXML
private void handleSave()
{
if (main.getOpenFile() == null)
{
handleSaveAs();
}
else
{
if (main != null)
{
main.saveGradesToFile(main.getOpenFile());
}
}
}
/**
* TODO Add method comment here
*
*/
@FXML
private void handleSaveAs()
{
FileChooser fileChooser = new FileChooser();
// Only show XML files.
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(
"XML files (*.xml)", "*.xml");
fileChooser.getExtensionFilters().add(extFilter);
// Set initial Directory to a good value
if (main != null && main.getGradesFilePath() != null)
{
fileChooser
.setInitialDirectory(main.getGradesFilePath().getParentFile());
}
else
{
String userDirectoryString = System.getProperty("user.home");
File userDirectory = new File(userDirectoryString);
fileChooser.setInitialDirectory(userDirectory);
}
File file = fileChooser.showSaveDialog(main.getPrimaryStage());
if (file != null)
{
// Set the correct file ending
if (!file.getPath().endsWith(".xml"))
{
file = new File(file.getPath() + ".xml");
}
main.saveGradesToFile(file);
}
}
/**
* TODO Add method comment here
*
*/
@FXML
private void handleExit()
{
Platform.exit();
}
}
|