2021-02-17 21:36:12 +01:00
|
|
|
package app.controllers;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
2021-02-19 22:11:33 +01:00
|
|
|
import com.google.common.eventbus.EventBus;
|
|
|
|
import com.google.common.eventbus.Subscribe;
|
|
|
|
|
|
|
|
import app.events.EditorChangedEvent;
|
2021-02-23 00:46:43 +01:00
|
|
|
import app.events.LanguageChangedEvent;
|
2021-04-22 21:48:38 +02:00
|
|
|
import app.events.OpenFileEvent;
|
2021-02-23 13:30:45 +01:00
|
|
|
import app.events.FileSaveStateChangedEvent;
|
2021-02-19 22:11:33 +01:00
|
|
|
import javafx.fxml.FXML;
|
2021-02-17 21:36:12 +01:00
|
|
|
import javafx.fxml.Initializable;
|
2021-02-19 22:11:33 +01:00
|
|
|
import javafx.scene.control.Label;
|
2021-02-17 21:36:12 +01:00
|
|
|
|
2021-03-02 18:50:44 +01:00
|
|
|
/**
|
|
|
|
* A FXML controller that controls the modeline component of the UI
|
|
|
|
*/
|
2021-02-19 22:11:33 +01:00
|
|
|
public class ModelineController implements Initializable, Controller {
|
2021-04-22 21:48:38 +02:00
|
|
|
|
|
|
|
@FXML
|
|
|
|
private Label filename;
|
2021-02-17 21:36:12 +01:00
|
|
|
|
2021-02-23 13:30:45 +01:00
|
|
|
@FXML
|
|
|
|
private Label saveState;
|
|
|
|
|
2021-02-19 22:11:33 +01:00
|
|
|
@FXML
|
|
|
|
private Label columnrow;
|
2021-02-17 21:36:12 +01:00
|
|
|
|
2021-02-19 22:11:33 +01:00
|
|
|
@FXML
|
|
|
|
private Label language;
|
|
|
|
|
|
|
|
private EventBus eventBus;
|
2021-02-17 21:36:12 +01:00
|
|
|
|
2021-02-19 22:11:33 +01:00
|
|
|
@Override
|
|
|
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
|
|
|
setColumnRow(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEventBus(EventBus eventBus) {
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
this.eventBus.register(this);
|
|
|
|
}
|
|
|
|
|
2021-02-17 21:36:12 +01:00
|
|
|
/**
|
2021-02-19 22:11:33 +01:00
|
|
|
* Update the colum row counter
|
|
|
|
* @param column The column number
|
|
|
|
* @param row The row number
|
2021-02-17 21:36:12 +01:00
|
|
|
*/
|
2021-02-19 22:11:33 +01:00
|
|
|
public void setColumnRow(int column, int row) {
|
|
|
|
this.columnrow.setText(String.format("[%d:%d]", row, column));
|
2021-02-17 21:36:12 +01:00
|
|
|
}
|
|
|
|
|
2021-04-26 14:35:47 +02:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
/* SUBSCRIPTIONS */
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2021-02-23 00:46:43 +01:00
|
|
|
/**
|
|
|
|
* Updates the column-row number display whenever the editor cursor
|
|
|
|
* changes position.
|
2021-04-26 14:35:47 +02:00
|
|
|
*
|
|
|
|
* @param event
|
2021-02-23 00:46:43 +01:00
|
|
|
*/
|
2021-02-19 22:11:33 +01:00
|
|
|
@Subscribe
|
2021-04-26 14:35:47 +02:00
|
|
|
public void handle(EditorChangedEvent event) {
|
2021-03-02 02:05:50 +01:00
|
|
|
this.setColumnRow(event.getColumn(), event.getLine());
|
2021-02-19 22:11:33 +01:00
|
|
|
}
|
2021-02-23 00:46:43 +01:00
|
|
|
|
2021-02-23 13:30:45 +01:00
|
|
|
/**
|
|
|
|
* Updates the saveState label whenever the file either is saved or modified
|
2021-04-26 14:35:47 +02:00
|
|
|
*
|
|
|
|
* @param event
|
2021-02-23 13:30:45 +01:00
|
|
|
*/
|
|
|
|
@Subscribe
|
2021-04-26 14:35:47 +02:00
|
|
|
public void handle(FileSaveStateChangedEvent event) {
|
2021-02-23 13:30:45 +01:00
|
|
|
this.saveState.setText(event.getIsSaved() ? "Saved!" : "Modified");
|
|
|
|
}
|
|
|
|
|
2021-02-23 00:46:43 +01:00
|
|
|
/**
|
2021-04-26 14:35:47 +02:00
|
|
|
* Updates the modeline to display a new language when changed.
|
|
|
|
*
|
|
|
|
* @param event
|
2021-02-23 00:46:43 +01:00
|
|
|
*/
|
|
|
|
@Subscribe
|
|
|
|
private void handle(LanguageChangedEvent event) {
|
|
|
|
this.language.setText(event.getLanguage());
|
|
|
|
}
|
2021-04-22 21:48:38 +02:00
|
|
|
|
2021-04-26 14:35:47 +02:00
|
|
|
/**
|
|
|
|
* Updates the modeline to display the name of the current file when changed
|
|
|
|
*
|
|
|
|
* @param event
|
|
|
|
*/
|
2021-04-22 21:48:38 +02:00
|
|
|
@Subscribe
|
|
|
|
private void handle(OpenFileEvent event) {
|
|
|
|
this.filename.setText(
|
|
|
|
event.getPath().map(path -> path.getFileName().toString()).orElse("New file")
|
|
|
|
);
|
|
|
|
}
|
2021-02-19 22:11:33 +01:00
|
|
|
}
|