Compare commits
	
		
			3 Commits
		
	
	
		
			97c3cc3243
			...
			e74ddc99ca
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e74ddc99ca | |||
| 89181c0fa9 | |||
| 705620d0a2 | 
@@ -67,9 +67,22 @@ public class Main extends Application {
 | 
				
			|||||||
                primaryStage.setScene(new Scene(root));
 | 
					                primaryStage.setScene(new Scene(root));
 | 
				
			||||||
                primaryStage.show();
 | 
					                primaryStage.show();
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                Parent root = FXMLLoader.load(getClass().getResource("MainView.fxml"));
 | 
					                FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainView.fxml"));
 | 
				
			||||||
 | 
					                Parent root = fxmlLoader.load();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                MainController controller = fxmlLoader.getController();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                primaryStage.setOnCloseRequest(e -> {
 | 
				
			||||||
 | 
					                        if (!controller.handleCloseRequest()) {
 | 
				
			||||||
 | 
					                            e.consume();
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            Platform.exit();
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                primaryStage.setTitle("Numbers Station");
 | 
					                primaryStage.setTitle("Numbers Station");
 | 
				
			||||||
                primaryStage.setScene(new Scene(root));
 | 
					                primaryStage.setScene(new Scene(root));
 | 
				
			||||||
 | 
					                primaryStage.titleProperty().bindBidirectional(controller.windowTitle);
 | 
				
			||||||
                primaryStage.show();
 | 
					                primaryStage.show();
 | 
				
			||||||
                logger.info("Application started");
 | 
					                logger.info("Application started");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,14 +12,19 @@ import java.nio.file.Paths;
 | 
				
			|||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.logging.Level;
 | 
					import java.util.logging.Level;
 | 
				
			||||||
import java.util.logging.Logger;
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
 | 
					import java.util.Optional;
 | 
				
			||||||
import java.util.Random;
 | 
					import java.util.Random;
 | 
				
			||||||
import java.util.ResourceBundle;
 | 
					import java.util.ResourceBundle;
 | 
				
			||||||
 | 
					import javafx.beans.property.SimpleBooleanProperty;
 | 
				
			||||||
import javafx.beans.property.SimpleStringProperty;
 | 
					import javafx.beans.property.SimpleStringProperty;
 | 
				
			||||||
import javafx.beans.property.StringProperty;
 | 
					import javafx.beans.property.StringProperty;
 | 
				
			||||||
 | 
					import javafx.event.ActionEvent;
 | 
				
			||||||
import javafx.fxml.FXML;
 | 
					import javafx.fxml.FXML;
 | 
				
			||||||
import javafx.fxml.FXMLLoader;
 | 
					import javafx.fxml.FXMLLoader;
 | 
				
			||||||
import javafx.fxml.Initializable;
 | 
					import javafx.fxml.Initializable;
 | 
				
			||||||
import javafx.scene.control.Alert;
 | 
					import javafx.scene.control.Alert;
 | 
				
			||||||
 | 
					import javafx.scene.control.Alert.AlertType;
 | 
				
			||||||
 | 
					import javafx.scene.control.ButtonType;
 | 
				
			||||||
import javafx.scene.control.Label;
 | 
					import javafx.scene.control.Label;
 | 
				
			||||||
import javafx.scene.control.TextArea;
 | 
					import javafx.scene.control.TextArea;
 | 
				
			||||||
import javafx.scene.control.TextField;
 | 
					import javafx.scene.control.TextField;
 | 
				
			||||||
@@ -41,6 +46,10 @@ public class MainController implements Initializable {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private StringProperty selectedStationName = new SimpleStringProperty();
 | 
					    private StringProperty selectedStationName = new SimpleStringProperty();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private SimpleBooleanProperty unsavedChanges = new SimpleBooleanProperty();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public StringProperty windowTitle = new SimpleStringProperty("Numbers Station");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private Label lastRetrievedLabel;
 | 
					    private Label lastRetrievedLabel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,12 +109,23 @@ public class MainController implements Initializable {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                selectStationStage = new Stage();
 | 
					                selectStationStage = new Stage();
 | 
				
			||||||
                selectStationStage.initModality(Modality.APPLICATION_MODAL);
 | 
					                selectStationStage.initModality(Modality.APPLICATION_MODAL);
 | 
				
			||||||
                selectStationStage.setUserData("test");
 | 
					                selectStationStage.setUserData(null);
 | 
				
			||||||
                selectStationStage.setTitle("Numbers Station Selection");
 | 
					                selectStationStage.setTitle("Numbers Station Selection");
 | 
				
			||||||
                selectStationStage.setScene(new Scene(root));
 | 
					
 | 
				
			||||||
 | 
					                Scene scene = new Scene(root);
 | 
				
			||||||
 | 
					                scene.addEventFilter(KeyEvent.KEY_PRESSED, (e) -> controller.handleKeyPressed(e));
 | 
				
			||||||
 | 
					                selectStationStage.setScene(scene);
 | 
				
			||||||
                selectStationStage.show();
 | 
					                selectStationStage.show();
 | 
				
			||||||
                selectStationStage.setOnHiding(event -> {
 | 
					                selectStationStage.setOnHiding(event -> {
 | 
				
			||||||
                    String newStationName = (String)selectStationStage.getUserData();
 | 
					                    String newStationName = (String)selectStationStage.getUserData();
 | 
				
			||||||
 | 
					                    if (newStationName == null) {
 | 
				
			||||||
 | 
					                        return;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    if (unsavedChanges.get()) {
 | 
				
			||||||
 | 
					                        if (!confirmSaveChanges()) {
 | 
				
			||||||
 | 
					                            return;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                    StationSettings newSelectedStation = settings.getStations().stream()
 | 
					                    StationSettings newSelectedStation = settings.getStations().stream()
 | 
				
			||||||
                            .filter(station -> station.getName().equals(newStationName))
 | 
					                            .filter(station -> station.getName().equals(newStationName))
 | 
				
			||||||
                            .findFirst()
 | 
					                            .findFirst()
 | 
				
			||||||
@@ -122,12 +142,17 @@ public class MainController implements Initializable {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private void handleSetAsNextMessageButtonPress() {
 | 
					    private void handleSetAsNextMessageButtonPress() {
 | 
				
			||||||
 | 
					        saveMessage();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void saveMessage() {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            if (!Files.exists(selectedStation.stationPath())) {
 | 
					            if (!Files.exists(selectedStation.stationPath())) {
 | 
				
			||||||
                Files.createDirectories(selectedStation.stationPath());
 | 
					                Files.createDirectories(selectedStation.stationPath());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Files.write(selectedStation.nextMessagePath(), messageTextArea.getText().getBytes());
 | 
					            Files.write(selectedStation.nextMessagePath(), messageTextArea.getText().getBytes());
 | 
				
			||||||
 | 
					            unsavedChanges.set(false);
 | 
				
			||||||
        } catch (IOException e) {
 | 
					        } catch (IOException e) {
 | 
				
			||||||
            String message = "Failed to write next message to " + selectedStation.nextMessagePath().toString();
 | 
					            String message = "Failed to write next message to " + selectedStation.nextMessagePath().toString();
 | 
				
			||||||
            logger.log(Level.SEVERE, message, e);
 | 
					            logger.log(Level.SEVERE, message, e);
 | 
				
			||||||
@@ -210,6 +235,7 @@ public class MainController implements Initializable {
 | 
				
			|||||||
                 code == KeyCode.DIGIT7 ||
 | 
					                 code == KeyCode.DIGIT7 ||
 | 
				
			||||||
                 code == KeyCode.DIGIT8 ||
 | 
					                 code == KeyCode.DIGIT8 ||
 | 
				
			||||||
                 code == KeyCode.DIGIT9)) {
 | 
					                 code == KeyCode.DIGIT9)) {
 | 
				
			||||||
 | 
					                unsavedChanges.set(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (cursorPosition < messageTextArea.getLength()) {
 | 
					                if (cursorPosition < messageTextArea.getLength()) {
 | 
				
			||||||
                    char currentChar = messageTextArea.getText().charAt(cursorPosition);
 | 
					                    char currentChar = messageTextArea.getText().charAt(cursorPosition);
 | 
				
			||||||
@@ -232,6 +258,18 @@ public class MainController implements Initializable {
 | 
				
			|||||||
                splitPane.setDividerPositions(1.0);
 | 
					                splitPane.setDividerPositions(1.0);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        unsavedChanges.addListener((obs2, wasUnsaved, isNowUnsaved) -> {
 | 
				
			||||||
 | 
					            if (isNowUnsaved) {
 | 
				
			||||||
 | 
					                if (!windowTitle.get().startsWith("*")) {
 | 
				
			||||||
 | 
					                    windowTitle.set("*" + windowTitle.get());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                if (windowTitle.get().startsWith("*")) {
 | 
				
			||||||
 | 
					                    windowTitle.set(windowTitle.get().substring(1, windowTitle.get().length()));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void updateStationSettings(StationSettings newStationSettings) {
 | 
					    private void updateStationSettings(StationSettings newStationSettings) {
 | 
				
			||||||
@@ -296,6 +334,40 @@ public class MainController implements Initializable {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        unsavedChanges.set(false);
 | 
				
			||||||
        messageTextArea.setText(messageText);
 | 
					        messageTextArea.setText(messageText);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return Whether to continue with the action that prompted the confirmation
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public boolean confirmSaveChanges() {
 | 
				
			||||||
 | 
					        Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Do you want to save your changes to the message?", ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
 | 
				
			||||||
 | 
					        alert.setHeaderText(null);
 | 
				
			||||||
 | 
					        Optional<ButtonType> result = alert.showAndWait();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!result.isPresent()) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (result.get() == ButtonType.YES) {
 | 
				
			||||||
 | 
					            saveMessage();
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        } else if (result.get() == ButtonType.NO) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return whether close should continue or not
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public boolean handleCloseRequest() {
 | 
				
			||||||
 | 
					        if (unsavedChanges.get()) {
 | 
				
			||||||
 | 
					            return confirmSaveChanges();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,8 @@ import javafx.scene.control.ButtonType;
 | 
				
			|||||||
import javafx.scene.control.ListCell;
 | 
					import javafx.scene.control.ListCell;
 | 
				
			||||||
import javafx.scene.control.ListView;
 | 
					import javafx.scene.control.ListView;
 | 
				
			||||||
import javafx.scene.control.TextInputDialog;
 | 
					import javafx.scene.control.TextInputDialog;
 | 
				
			||||||
 | 
					import javafx.scene.input.KeyCode;
 | 
				
			||||||
 | 
					import javafx.scene.input.KeyEvent;
 | 
				
			||||||
import javafx.event.ActionEvent;
 | 
					import javafx.event.ActionEvent;
 | 
				
			||||||
import javafx.event.Event;
 | 
					import javafx.event.Event;
 | 
				
			||||||
import javafx.scene.Node;
 | 
					import javafx.scene.Node;
 | 
				
			||||||
@@ -96,6 +98,17 @@ public class StationSelectionController {
 | 
				
			|||||||
        stage.close();
 | 
					        stage.close();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @FXML
 | 
				
			||||||
 | 
					    public void handleKeyPressed(KeyEvent event) {
 | 
				
			||||||
 | 
					        KeyCode code = event.getCode();
 | 
				
			||||||
 | 
					        if (code == KeyCode.ENTER) {
 | 
				
			||||||
 | 
					            selectHighlightedStation();
 | 
				
			||||||
 | 
					        } else if (code == KeyCode.ESCAPE) {
 | 
				
			||||||
 | 
					            Stage stage = (Stage) stationListView.getScene().getWindow();
 | 
				
			||||||
 | 
					            stage.close();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private void handleRemoveButtonPress(ActionEvent event) {
 | 
					    private void handleRemoveButtonPress(ActionEvent event) {
 | 
				
			||||||
        int selectedIndex = stationListView.getSelectionModel().getSelectedIndex();
 | 
					        int selectedIndex = stationListView.getSelectionModel().getSelectedIndex();
 | 
				
			||||||
@@ -115,15 +128,7 @@ public class StationSelectionController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private void handleSelectButtonPress(Event e) {
 | 
					    private void handleSelectButtonPress(Event e) {
 | 
				
			||||||
        Node node = (Node) e.getSource();
 | 
					        selectHighlightedStation();
 | 
				
			||||||
        Stage stage = (Stage) node.getScene().getWindow();
 | 
					 | 
				
			||||||
        StationSettings selectedStation = stationListView.getSelectionModel().getSelectedItem();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (selectedStation != null) {
 | 
					 | 
				
			||||||
            stage.setUserData(selectedStation.getName());
 | 
					 | 
				
			||||||
            System.out.println("Selected Station: " + selectedStation.getName());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        stage.close();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void onStationListChanged(ListChangeListener.Change<? extends StationSettings> change) {
 | 
					    private void onStationListChanged(ListChangeListener.Change<? extends StationSettings> change) {
 | 
				
			||||||
@@ -155,4 +160,15 @@ public class StationSelectionController {
 | 
				
			|||||||
        settings.getStations().addAll(stationList);
 | 
					        settings.getStations().addAll(stationList);
 | 
				
			||||||
        settings.save();
 | 
					        settings.save();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void selectHighlightedStation() {
 | 
				
			||||||
 | 
					        Stage stage = (Stage) stationListView.getScene().getWindow();
 | 
				
			||||||
 | 
					        StationSettings selectedStation = stationListView.getSelectionModel().getSelectedItem();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (selectedStation != null) {
 | 
				
			||||||
 | 
					            stage.setUserData(selectedStation.getName());
 | 
				
			||||||
 | 
					            System.out.println("Selected Station: " + selectedStation.getName());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        stage.close();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -499,12 +499,25 @@ public class StationSettingsController {
 | 
				
			|||||||
                logger.log(Level.SEVERE, "SFTP connection failed", e);
 | 
					                logger.log(Level.SEVERE, "SFTP connection failed", e);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else if (messageMethod.get() == StationSettings.MessageMethod.WORDPRESS) {
 | 
					        } else if (messageMethod.get() == StationSettings.MessageMethod.WORDPRESS) {
 | 
				
			||||||
 | 
					            connectionTestDescription.set("Testing connection");
 | 
				
			||||||
 | 
					            connectionTestStatus.set(ConnectionStatus.NEUTRAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            System.setProperty("wordpress.username", username.get());
 | 
					            System.setProperty("wordpress.username", username.get());
 | 
				
			||||||
            System.setProperty("wordpress.password", password.get());
 | 
					            System.setProperty("wordpress.password", password.get());
 | 
				
			||||||
            System.setProperty("wordpress.url", stationAddress.get());
 | 
					            System.setProperty("wordpress.url", stationAddress.get());
 | 
				
			||||||
            Post post = new Post("Title of post", "content to post");
 | 
					            Post post = new Post("Title of post", "content to post");
 | 
				
			||||||
            WordpressClient client = new WordpressClient();
 | 
					            try {
 | 
				
			||||||
            String newPostId = client.newPost(post);
 | 
					                WordpressClient client = new WordpressClient();
 | 
				
			||||||
 | 
					                var postTypes = client.getPostTypes();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                logger.log(Level.INFO, "Wordpress connection successful");
 | 
				
			||||||
 | 
					                connectionTestDescription.set("Connection succeeded");
 | 
				
			||||||
 | 
					                connectionTestStatus.set(ConnectionStatus.SUCCESS);
 | 
				
			||||||
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                connectionTestDescription.set("Worpress connection failed");
 | 
				
			||||||
 | 
					                connectionTestStatus.set(ConnectionStatus.FAILURE);
 | 
				
			||||||
 | 
					                logger.log(Level.SEVERE, "Wordpress connection failed", e);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -93,7 +93,7 @@
 | 
				
			|||||||
                        <PasswordField fx:id="passwordField" layoutX="444.0" layoutY="95.0" prefHeight="25.0" prefWidth="135.0" AnchorPane.rightAnchor="0.0" />
 | 
					                        <PasswordField fx:id="passwordField" layoutX="444.0" layoutY="95.0" prefHeight="25.0" prefWidth="135.0" AnchorPane.rightAnchor="0.0" />
 | 
				
			||||||
                        <TextField fx:id="externalProgramCommandField" layoutX="-2.0" layoutY="131.0" prefHeight="25.0" prefWidth="580.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="0.0" />
 | 
					                        <TextField fx:id="externalProgramCommandField" layoutX="-2.0" layoutY="131.0" prefHeight="25.0" prefWidth="580.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="0.0" />
 | 
				
			||||||
                        <Button fx:id="testConnectionButton" layoutX="464.0" layoutY="7.0" mnemonicParsing="false" onAction="#handleTestConnectionButtonPress" text="Test connection" />
 | 
					                        <Button fx:id="testConnectionButton" layoutX="464.0" layoutY="7.0" mnemonicParsing="false" onAction="#handleTestConnectionButtonPress" text="Test connection" />
 | 
				
			||||||
                        <Label fx:id="connectionTestStatusLabel" layoutX="257.0" layoutY="11.0" prefHeight="17.0" prefWidth="196.0" AnchorPane.leftAnchor="257.0" AnchorPane.rightAnchor="125.0" />
 | 
					                        <Label fx:id="connectionTestStatusLabel" alignment="CENTER_RIGHT" layoutX="136.0" layoutY="11.0" prefHeight="17.0" prefWidth="317.0" textAlignment="RIGHT" AnchorPane.leftAnchor="136.0" AnchorPane.rightAnchor="125.0" />
 | 
				
			||||||
                     
 | 
					                     
 | 
				
			||||||
                   </children>
 | 
					                   </children>
 | 
				
			||||||
                     <VBox.margin>
 | 
					                     <VBox.margin>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user