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