Guest User

Untitled

a guest
Jul 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. package application;
  2.  
  3.  
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.OutputStream;
  9. import java.io.OutputStreamWriter;
  10. import java.io.Writer;
  11. import java.net.URL;
  12. import java.util.ResourceBundle;
  13.  
  14. import Objects.Goal;
  15. import UtilityClasses.GoalManager;
  16. import javafx.application.Application;
  17. import javafx.collections.FXCollections;
  18. import javafx.collections.ObservableList;
  19. import javafx.fxml.FXML;
  20. import javafx.fxml.FXMLLoader;
  21. import javafx.fxml.Initializable;
  22. import javafx.stage.Stage;
  23. import javafx.scene.Scene;
  24. import javafx.scene.control.TableColumn;
  25. import javafx.scene.control.TableView;
  26. import javafx.scene.control.cell.PropertyValueFactory;
  27. import javafx.scene.layout.AnchorPane;
  28.  
  29.  
  30.  
  31. public class Main extends Application implements Initializable {
  32. private Stage primaryStage;
  33. private AnchorPane mainLayout;
  34. public static ObservableList<Goal> goalsData = FXCollections.observableArrayList();
  35.  
  36. @FXML
  37. static TableView<Goal> goalTable = new TableView<Goal>();
  38. @FXML
  39. static TableColumn<Goal, String> goalsColumn = new TableColumn<>();
  40. @FXML
  41. static TableColumn<Goal, String> statusColumn = new TableColumn<>();
  42.  
  43. @Override
  44. public void start(Stage primaryStage) {
  45.  
  46.  
  47. this.primaryStage = primaryStage;
  48. this.primaryStage.setTitle("MainWindow");
  49.  
  50. try {
  51. showMainView();
  52. } catch (IOException e) {
  53. System.out.println(e.getMessage());
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. }
  67.  
  68. public static void main(String[] args) {
  69.  
  70. try {
  71. setDefaultSettings();
  72. launch(args);
  73.  
  74. } catch (IOException e) {
  75. // TODO Auto-generated catch block
  76. e.printStackTrace();
  77. }
  78.  
  79.  
  80.  
  81. }
  82.  
  83. private void showMainView() throws IOException {
  84. SettingControlls mainController = new SettingControlls();
  85. FXMLLoader loader = new FXMLLoader();
  86. loader.setController(mainController);
  87. loader.setLocation(Main.class.getResource("mainFXML.fxml"));
  88. mainLayout = loader.load();
  89. Scene scene = new Scene(mainLayout);
  90. primaryStage.setScene(scene);
  91. primaryStage.show();
  92. }
  93. private static void setDefaultSettings() throws IOException {
  94.  
  95. File f = new File("Goals.txt");
  96. if(!f.exists()) {
  97. OutputStream os = new FileOutputStream("Goals.txt");
  98. Writer w = new OutputStreamWriter(os);
  99. w.close();
  100. }
  101.  
  102.  
  103. }
  104. private static ObservableList<Goal> getObservableList() throws FileNotFoundException, IOException {
  105.  
  106. ObservableList<Goal> ol = FXCollections.observableArrayList(new Goal("testGoal"));
  107. return ol;
  108.  
  109. }
  110.  
  111. @Override
  112. public void initialize(URL location, ResourceBundle resources) {
  113.  
  114. goalsData.add(new Goal("test"));
  115. System.out.println(goalsData.get(0).getGoal());
  116. goalsColumn.setCellValueFactory(new PropertyValueFactory<Goal, String>("goal"));
  117. statusColumn.setCellValueFactory(new PropertyValueFactory<Goal, String>("status"));
  118.  
  119.  
  120. goalTable.setItems(goalsData);
  121.  
  122. }
  123. }
  124.  
  125. package Objects;
  126.  
  127. import javafx.beans.property.SimpleStringProperty;
  128.  
  129. public class Goal {
  130.  
  131.  
  132. private SimpleStringProperty goal;
  133. private SimpleStringProperty status;
  134.  
  135. public Goal(String goal) {
  136.  
  137.  
  138. this.goal = new SimpleStringProperty(goal);
  139. this.status = new SimpleStringProperty("ongoing");
  140. }
  141. public Goal(String goal, String status) {
  142.  
  143.  
  144. this.goal = new SimpleStringProperty(goal);
  145. this.status = new SimpleStringProperty(status);
  146. }
  147.  
  148. public String getGoal() {
  149. return this.goal.get();
  150. }
  151. public String getStatus() {
  152. return this.status.get();
  153. }
  154. public void setGoal(String newGoal) {
  155.  
  156. this.goal = new SimpleStringProperty(newGoal);
  157. }
  158. public void setStatus(String newStatus) {
  159.  
  160. this.status = new SimpleStringProperty(newStatus);
  161. }
  162.  
  163. }
Add Comment
Please, Sign In to add comment