mirror of
https://gitlab.com/kauron/jstudy
synced 2024-11-13 07:33:44 +01:00
Removed editing facilities
This commit is contained in:
parent
e9e2c0704d
commit
5d5f400495
2 changed files with 0 additions and 103 deletions
|
@ -1,70 +0,0 @@
|
|||
package es.kauron.jstudy.controller;
|
||||
|
||||
import es.kauron.jstudy.model.TestItem;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class EditController implements Initializable {
|
||||
@FXML
|
||||
private TextField questionText, answerText;
|
||||
private ObservableList<TestItem> list;
|
||||
private int index;
|
||||
private TestItem item;
|
||||
private BooleanProperty saved;
|
||||
private String originalQuestion, originalAnswer;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
}
|
||||
|
||||
void setList(ObservableList<TestItem> list, BooleanProperty saved) {
|
||||
setList(list, -1, saved);
|
||||
}
|
||||
|
||||
void setList(ObservableList<TestItem> list, int index, BooleanProperty saved) {
|
||||
this.list = list; // Save attributes correctly
|
||||
this.index = index;
|
||||
this.saved = saved;
|
||||
// Copy current values to textViews
|
||||
// and initialize item to hold the current object in edition
|
||||
if (index < 0) item = new TestItem("","");
|
||||
else {
|
||||
questionText.setText(list.get(index).getQuestion());
|
||||
answerText.setText(list.get(index).getAnswer());
|
||||
item = new TestItem(list.get(index));
|
||||
}
|
||||
originalQuestion = questionText.getText();
|
||||
originalAnswer = answerText.getText();
|
||||
item.questionProperty().bind(questionText.textProperty());
|
||||
item.answerProperty().bind(answerText.textProperty());
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void onSaveAction(ActionEvent event) {
|
||||
if (index < 0) {
|
||||
if (!item.isValid())
|
||||
return;
|
||||
list.add(item);
|
||||
} else {
|
||||
list.set(index, item);
|
||||
}
|
||||
if (!originalQuestion.equals(item.getQuestion()) || !originalAnswer.equals(item.getAnswer())) saved.set(false);
|
||||
onCancelAction(event);
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void onCancelAction(ActionEvent event) {
|
||||
((Stage) ((Node) event.getSource())
|
||||
.getScene().getWindow())
|
||||
.close();
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<VBox spacing="5.0" xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.jstudy.controller.EditController">
|
||||
<children>
|
||||
<HBox alignment="CENTER_LEFT" spacing="5.0">
|
||||
<children>
|
||||
<Label prefWidth="60.0" text="Question" />
|
||||
<TextField fx:id="questionText" />
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="10.0" spacing="5.0">
|
||||
<children>
|
||||
<Label prefWidth="60.0" text="Answer" />
|
||||
<TextField fx:id="answerText" />
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_RIGHT" spacing="5.0">
|
||||
<children>
|
||||
<Button cancelButton="true" mnemonicParsing="false" onAction="#onCancelAction" text="Cancel" />
|
||||
<Button defaultButton="true" mnemonicParsing="false" onAction="#onSaveAction" text="Save" />
|
||||
</children>
|
||||
<VBox.margin>
|
||||
<Insets top="5.0" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</padding>
|
||||
</VBox>
|
Loading…
Reference in a new issue