Skip to content

Commit

Permalink
Bug fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RedDragon0293 committed Jun 7, 2024
1 parent 689d135 commit 8e6e273
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/main/java/cn/reddragon/eportal/window/AccountWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,39 @@
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.io.IOException;

public class AccountWindow {
public static AccountController controller;
public static Stage fatherStage;
private static Stage stage;

public static Stage getStage() {
return stage;
}

public static void init(Stage parent) throws IOException {
private static void init() throws IOException {
FXMLLoader loader = new FXMLLoader(AccountWindow.class.getResource("account-view.fxml"));
Parent root = loader.load();
controller = loader.getController();
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.setTitle("账号管理");
stage.setScene(scene);
stage.initOwner(parent);
stage.initOwner(fatherStage);
stage.initModality(Modality.WINDOW_MODAL);
ListView<String> listView = controller.listView;
listView.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
controller.onSelectionChanged(newValue);
});
TextField f1 = controller.usernameField;
f1.textProperty().addListener((observableValue, oldValue, newValue) -> controller.onTextFieldChanged());
TextField f2 = controller.passwordField;
f2.textProperty().addListener(((observableValue, oldValue, newValue) -> controller.onTextFieldChanged()));
ObservableList<String> items = listView.getItems();
for (Account account : AccountManager.accounts) {
items.add(account.name());
Expand All @@ -43,6 +49,11 @@ public static void init(Stage parent) throws IOException {
}

public static void open() {
stage.show();
try {
init();
} catch (IOException e) {
throw new RuntimeException(e);
}
stage.showAndWait();
}
}
3 changes: 2 additions & 1 deletion src/main/java/cn/reddragon/eportal/window/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public void start(Stage stage) throws IOException {
stage.setTitle(Main.name + " " + Main.version);
stage.setScene(scene);
ConfigManager.loadConfigs();
AccountWindow.init(stage);
//AccountWindow.init(stage);
AccountWindow.fatherStage = stage;
ChoiceBox<String> box = (ChoiceBox<String>) root.lookup("#typeSelector");
for (LoginType it : LoginType.values())
if (!Objects.equals(it.displayName, ""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,32 @@ public class AccountController {
@FXML
public Label resultText;

public void onTextFieldChanged() {
if (usernameField.getText().isBlank() || passwordField.getText().isBlank()) {
addButton.setDisable(true);
editButton.setDisable(true);
deleteButton.setDisable(true);
} else {
addButton.setDisable(false);
editButton.setDisable(false);
deleteButton.setDisable(false);
}
}

public void onSelectionChanged(String newValue) {
if (newValue == null) {
usernameField.setText("");
passwordField.setText("");
return;
}
Account account = AccountManager.getAccount(newValue);
if (account != null) {
usernameField.setText(account.name());
passwordField.setText(account.password());
}
addButton.setDisable(true);
editButton.setDisable(newValue.isBlank());
deleteButton.setDisable(newValue.isBlank());
}

public void onAddButtonClicked() {
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/cn/reddragon/eportal/window/account-view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
</Label>
<HBox alignment="TOP_CENTER" prefWidth="200.0" spacing="20.0">
<children>
<Button fx:id="addButton" mnemonicParsing="false" onAction="#onAddButtonClicked" text="添加"/>
<Button fx:id="editButton" mnemonicParsing="false" onAction="#onEditButtonClicked" text="保存"/>
<Button fx:id="deleteButton" mnemonicParsing="false" onAction="#onDeleteButtonClicked"
text="删除"/>
<Button fx:id="addButton" disable="true" mnemonicParsing="false" onAction="#onAddButtonClicked"
text="添加"/>
<Button fx:id="editButton" disable="true" mnemonicParsing="false"
onAction="#onEditButtonClicked" text="修改"/>
<Button fx:id="deleteButton" disable="true" mnemonicParsing="false"
onAction="#onDeleteButtonClicked" text="删除"/>
</children>
</HBox>
<Label fx:id="resultText" alignment="CENTER" prefWidth="200.0" textAlignment="CENTER"/>
Expand Down

0 comments on commit 8e6e273

Please sign in to comment.