mirror of
https://gitlab.com/kauron/jstudy
synced 2024-12-22 08:23:33 +01:00
parent
f29cb85566
commit
a0e3a1fb17
3 changed files with 32 additions and 12 deletions
|
@ -54,7 +54,7 @@ public class Controller implements Initializable {
|
|||
private MenuItem menuCloseTab, menuSave;
|
||||
|
||||
private final BooleanProperty tabIsTable = new SimpleBooleanProperty(false);
|
||||
private final Map<Tab, TableController> tabMap = new HashMap<>();
|
||||
private final Map<Tab, Initializable> tabMap = new HashMap<>();
|
||||
private String updateURL, updateFileName;
|
||||
private Tab theTest = null;
|
||||
|
||||
|
@ -67,9 +67,9 @@ public class Controller implements Initializable {
|
|||
tabIsTable.set(tabMap.get(n) != null);
|
||||
menuCloseTab.setDisable(!n.isClosable());
|
||||
menuSave.disableProperty().unbind();
|
||||
menuSave.setDisable(!tabMap.containsKey(n) || tabMap.get(n).saved.get());
|
||||
if (tabMap.containsKey(n))
|
||||
menuSave.disableProperty().bind(tabMap.get(n).saved);
|
||||
menuSave.setDisable(!isTableTab(n) || ((TableController) tabMap.get(n)).saved.get());
|
||||
if (isTableTab(n))
|
||||
menuSave.disableProperty().bind(((TableController) tabMap.get(n)).saved);
|
||||
}
|
||||
});
|
||||
tabPane.getTabs().removeListener((ListChangeListener<Tab>) c -> theTest = null);
|
||||
|
@ -77,8 +77,10 @@ public class Controller implements Initializable {
|
|||
root.getScene().getWindow().setOnCloseRequest(event -> {
|
||||
for (Tab tab : tabPane.getTabs()) {
|
||||
EventHandler<Event> handler = tab.getOnCloseRequest();
|
||||
if (tabMap.containsKey(tab))
|
||||
tabMap.get(tab).stopTimer();
|
||||
if (isTableTab(tab))
|
||||
((TableController) tabMap.get(tab)).stopTimer();
|
||||
else if (isTestTab(tab))
|
||||
((TestController) tabMap.get(tab)).stopTimer();
|
||||
if (tab.isClosable() && handler != null) {
|
||||
tabPane.getSelectionModel().select(tab);
|
||||
handler.handle(event);
|
||||
|
@ -90,6 +92,14 @@ public class Controller implements Initializable {
|
|||
new Thread(this::checkUpdate).start();
|
||||
}
|
||||
|
||||
private boolean isTableTab(Tab tab) {
|
||||
return tabMap.containsKey(tab) && tabMap.get(tab) instanceof TableController;
|
||||
}
|
||||
|
||||
private boolean isTestTab(Tab tab) {
|
||||
return tabMap.containsKey(tab) && tabMap.get(tab) instanceof TestController;
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
// Check new version via gitlab's REST API
|
||||
String newVersion;
|
||||
|
@ -227,9 +237,8 @@ public class Controller implements Initializable {
|
|||
@FXML
|
||||
private void onSaveAction(ActionEvent event) {
|
||||
Tab tab = tabPane.getSelectionModel().getSelectedItem();
|
||||
if (tabMap.containsKey(tab)) {
|
||||
tabMap.get(tab).onSaveAction(event);
|
||||
}
|
||||
if (isTableTab(tab))
|
||||
((TableController) tabMap.get(tab)).onSaveAction(event);
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -277,9 +286,9 @@ public class Controller implements Initializable {
|
|||
MenuItem merge = new MenuItem("Merge with other table");
|
||||
merge.setOnAction(event -> {
|
||||
Map<String, TableController> choices = new HashMap<>(tabMap.values().size() - 1);
|
||||
for (TableController tc : tabMap.values())
|
||||
if (tc != loader.getController())
|
||||
choices.put(tc.getName(), tc);
|
||||
for (Initializable tc : tabMap.values())
|
||||
if (tc instanceof TableController && tc != loader.getController())
|
||||
choices.put(((TableController) tc).getName(), ((TableController) tc));
|
||||
|
||||
ChoiceDialog<String> dialog = new ChoiceDialog<>();
|
||||
dialog.setTitle("Merging tables...");
|
||||
|
@ -330,6 +339,7 @@ public class Controller implements Initializable {
|
|||
theTest = new Tab("Test: " + tabPane.getSelectionModel().getSelectedItem().getText(), root);
|
||||
tabPane.getTabs().add(theTest);
|
||||
tabPane.getSelectionModel().selectLast();
|
||||
tabMap.put(theTest, loader.getController());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -129,5 +129,10 @@ public class TestController implements Initializable {
|
|||
item.set(ending);
|
||||
pauseCheckBox.setSelected(true);
|
||||
pauseCheckBox.setDisable(true);
|
||||
clock.stop();
|
||||
}
|
||||
|
||||
void stopTimer() {
|
||||
clock.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,11 @@ public class Clock {
|
|||
task = null;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
}
|
||||
|
||||
private void setObservable() {
|
||||
time.set(String.format("%02d:%02d", seconds / SEC_TO_MIN, seconds % SEC_TO_MIN));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue