├── .gitignore ├── LICENSE ├── README.md └── src └── abrand ├── Controller.java ├── Main.java ├── Stylesheet.css └── View.fxml /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | *.iml 3 | out/ 4 | /.idea/ 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GLWT(Good Luck With That) Public License 2 | Copyright (c) Everyone, except Author 3 | 4 | Everyone is permitted to copy, distribute, modify, merge, sell, publish, 5 | sublicense or whatever they want with this software but at their OWN RISK. 6 | 7 | Preamble 8 | 9 | The author has absolutely no clue what the code in this project does. 10 | It might just work or not, there is no third option. 11 | 12 | 13 | GOOD LUCK WITH THAT PUBLIC LICENSE 14 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION 15 | 16 | 0. You just DO WHATEVER YOU WANT TO as long as you NEVER LEAVE A 17 | TRACE TO TRACK THE AUTHOR of the original product to blame for or hold 18 | responsible. 19 | 20 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | 25 | Good luck and Godspeed. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | GLWT(Good Luck With That) Public License 3 | Copyright (c) Everyone, except Author 4 | 5 | Everyone is permitted to copy, distribute, modify, merge, sell, publish, 6 | sublicense or whatever they want with this software but at their OWN RISK. 7 | 8 | Preamble 9 | 10 | The author has absolutely no clue what the code in this project does. 11 | It might just work or not, there is no third option. 12 | 13 | 14 | GOOD LUCK WITH THAT PUBLIC LICENSE 15 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION 16 | 17 | 0. You just DO WHATEVER YOU WANT TO as long as you NEVER LEAVE A 18 | TRACE TO TRACK THE AUTHOR of the original product to blame for or hold 19 | responsible. 20 | 21 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | Good luck and Godspeed. 27 | ``` 28 | -------------------------------------------------------------------------------- /src/abrand/Controller.java: -------------------------------------------------------------------------------- 1 | package abrand; 2 | 3 | import javafx.application.Platform; 4 | import javafx.event.ActionEvent; 5 | import javafx.fxml.FXML; 6 | import javafx.fxml.Initializable; 7 | import javafx.scene.control.Alert; 8 | import javafx.scene.control.ButtonType; 9 | import javafx.scene.control.CheckMenuItem; 10 | import javafx.scene.control.TextArea; 11 | import javafx.stage.FileChooser; 12 | import javafx.stage.Stage; 13 | 14 | import java.io.*; 15 | import java.net.URL; 16 | import java.util.ResourceBundle; 17 | 18 | public class Controller implements Initializable { 19 | 20 | @FXML 21 | private TextArea textArea; 22 | 23 | private Stage stage; 24 | private final FileChooser fileChooser = new FileChooser(); 25 | 26 | @Override 27 | public void initialize(URL location, ResourceBundle resources) { 28 | fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); 29 | fileChooser 30 | .getExtensionFilters() 31 | .addAll( 32 | new FileChooser.ExtensionFilter("Text", "*.txt"), 33 | new FileChooser.ExtensionFilter("All Files", "*.*")); 34 | } 35 | 36 | public void init(Stage myStage) { 37 | this.stage = myStage; 38 | } 39 | 40 | @FXML 41 | public void exit() { 42 | if (textArea.getText().isEmpty()) { 43 | Platform.exit(); 44 | return; 45 | } 46 | 47 | Alert alert = new Alert( 48 | Alert.AlertType.CONFIRMATION, 49 | "Exit without saving?", 50 | ButtonType.YES, 51 | ButtonType.NO, 52 | ButtonType.CANCEL 53 | ); 54 | 55 | alert.setTitle("Confirm"); 56 | alert.showAndWait(); 57 | 58 | if (alert.getResult() == ButtonType.YES) { 59 | Platform.exit(); 60 | } 61 | if (alert.getResult() == ButtonType.NO) { 62 | save(); 63 | Platform.exit(); 64 | } 65 | } 66 | 67 | @FXML 68 | private void save() { 69 | try { 70 | fileChooser.setTitle("Save As"); 71 | File file = fileChooser.showSaveDialog(stage); 72 | 73 | if (file != null) { 74 | PrintWriter savedText = new PrintWriter(file); 75 | BufferedWriter out = new BufferedWriter(savedText); 76 | out.write(textArea.getText()); 77 | out.close(); 78 | } 79 | } catch (FileNotFoundException e) { 80 | System.out.println("Error: " + e); 81 | } catch (IOException e) { 82 | e.printStackTrace(); 83 | } 84 | } 85 | 86 | @FXML 87 | public void openFile() { 88 | fileChooser.setTitle("Open File"); 89 | File file = fileChooser.showOpenDialog(stage); 90 | 91 | if (file != null) { 92 | textArea.clear(); 93 | readText(file); 94 | } 95 | } 96 | 97 | 98 | // sets the textArea to the text of the opened file 99 | private void readText(File file) { 100 | String text; 101 | 102 | try (BufferedReader buffReader = new BufferedReader(new FileReader(file))) { 103 | while ((text = buffReader.readLine()) != null) { 104 | textArea.appendText(text + "\n"); 105 | } 106 | } catch (IOException e) { 107 | e.printStackTrace(); 108 | } 109 | } 110 | 111 | //TODO add confirmation window if text editor has text and wasn't saved 112 | 113 | @FXML 114 | public void newFile() { 115 | textArea.clear(); 116 | } 117 | 118 | @FXML 119 | public void about() { 120 | Alert alert = new Alert(Alert.AlertType.INFORMATION); 121 | 122 | alert.setTitle("About"); 123 | alert.setHeaderText("A project just for fun written by abrand."); 124 | alert.setContentText("github.com/abrandell"); 125 | alert.showAndWait(); 126 | } 127 | 128 | // TODO Add a proper font-size menu && color selection 129 | 130 | @FXML 131 | public void fontSize(ActionEvent e) { 132 | String choice = ((CheckMenuItem) e.getSource()).getId(); 133 | 134 | switch (choice) { 135 | case "small": 136 | textArea.setStyle("-fx-font-size: 14px"); 137 | break; 138 | case "default": 139 | textArea.setStyle("-fx-font-size: 22px"); 140 | break; 141 | case "large": 142 | textArea.setStyle("-fx-font-size: 30px"); 143 | break; 144 | default: 145 | textArea.setStyle("-fx-font-size: 22px"); 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/abrand/Main.java: -------------------------------------------------------------------------------- 1 | package abrand; 2 | 3 | import javafx.application.Application; 4 | import javafx.fxml.FXMLLoader; 5 | import javafx.scene.Parent; 6 | import javafx.scene.Scene; 7 | import javafx.stage.Stage; 8 | 9 | public class Main extends Application { 10 | 11 | 12 | public static void main(String[] args) { 13 | launch(args); 14 | } 15 | 16 | @Override 17 | public void start(Stage myStage) throws Exception { 18 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("View.fxml")); 19 | 20 | Parent root = fxmlLoader.load(); 21 | Controller controller = fxmlLoader.getController(); 22 | controller.init(myStage); 23 | 24 | myStage.setTitle("JavaFX Text Editor"); 25 | myStage.setScene(new Scene(root, 700, 500)); 26 | myStage.show(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/abrand/Stylesheet.css: -------------------------------------------------------------------------------- 1 | 2 | .master-pane { 3 | -fx-background-color: #2F343F; 4 | } 5 | 6 | .text-area { 7 | -fx-text-fill: #B4C4D0; 8 | -fx-font-size: 20; 9 | -fx-font-family: "Consolas"; 10 | -fx-focus-color: transparent; 11 | } 12 | 13 | 14 | .menu .label { 15 | -fx-text-fill: #D1D6C5; 16 | } 17 | 18 | menu-bar:hover, .menu-item:hover{ 19 | -fx-background-color: #404552; 20 | } 21 | 22 | .menu-bar { 23 | -fx-background-color: #2F343F; 24 | -fx-font-size: 16; 25 | -fx-font-family: "Consolas"; 26 | } 27 | 28 | 29 | .text-area .content { 30 | -fx-background-color: #393939 31 | 32 | } 33 | 34 | /*TODO right clicking on textArea didn't have the desired CSS effect, figure out why and replace this template 35 | 36 | /* 37 | * https://stackoverflow.com/questions/12299162/how-to-style-menu-button-and-menu-items 38 | * credit to Markus Weninger on stackOverflow for this template 39 | * https://stackoverflow.com/users/2938364/markus-weninger 40 | */ 41 | 42 | /*********************************************************************************************/ 43 | 44 | 45 | /* VARIABLE DEFINITIONS: Only these 4 variables have to be adjusted, the rest is copy-paste */ 46 | * { 47 | -fx-my-menu-color: #2F343F; /* Change according to your needs */ 48 | -fx-my-menu-color-highlighted: #404552; /* Change according to your needs */ 49 | -fx-my-menu-font-color: #D1D6C5; /* Change according to your needs */ 50 | -fx-my-menu-font-color-highlighted: #D1D6C5; /* Change according to your needs */ 51 | } 52 | 53 | 54 | /*** Top-level menu itself (not selected / hovered) ***/ 55 | .menu-bar > .container > .menu-button { 56 | -fx-background-color: -fx-my-menu-color; 57 | } 58 | 59 | /*** Top-level menu's label (not selected / hovered) ***/ 60 | .menu-bar > .container > .menu-button > .label { 61 | -fx-text-fill: -fx-my-menu-font-color; 62 | } 63 | 64 | /*** Top-level menu's label (disabled) ***/ 65 | .menu-bar > .container > .menu-button > .label:disabled { 66 | -fx-opacity: 1.0; 67 | } 68 | 69 | /*** Top-level menu itself (selected / hovered) ***/ 70 | .menu-bar > .container > .menu-button:hover, 71 | .menu-bar > .container > .menu-button:focused, 72 | .menu-bar > .container > .menu-button:showing { 73 | -fx-background-color: -fx-my-menu-color-highlighted; 74 | } 75 | 76 | /*** Top-level menu's label (selected / hovered) ***/ 77 | .menu-bar > .container > .menu-button:hover > .label, 78 | .menu-bar > .container > .menu-button:focused > .label, 79 | .menu-bar > .container > .menu-button:showing > .label { 80 | -fx-text-fill: -fx-my-menu-font-color-highlighted; 81 | } 82 | 83 | /* MENU ITEM (children of a MENU BUTTON) */ 84 | /*** The item itself (not hovered / focused) ***/ 85 | .menu-item { 86 | -fx-background-color: -fx-my-menu-color; 87 | } 88 | 89 | /*** The item's label (not hovered / focused) ***/ 90 | .menu-item .label { 91 | -fx-text-fill: -fx-my-menu-font-color; 92 | } 93 | 94 | /*** The item's label (disabled) ***/ 95 | .menu-item .label:disabled { 96 | -fx-opacity: 1.0; 97 | } 98 | 99 | /*** The item itself (hovered / focused) ***/ 100 | .menu-item:focused, .menu-item:hovered { 101 | -fx-background-color: -fx-my-menu-color-highlighted; 102 | } 103 | 104 | /*** The item's label (hovered / focused) ***/ 105 | .menu-item:focused .label, .menu-item:hovered .label { 106 | -fx-text-fill: -fx-my-menu-font-color-highlighted; 107 | } 108 | 109 | /* CONTEXT MENU */ 110 | /*** The context menu that contains a menu's menu items ***/ 111 | .context-menu { 112 | -fx-background-color: -fx-my-menu-color; 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/abrand/View.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | --------------------------------------------------------------------------------