Advertisement
Guest User

test

a guest
Jun 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.event.ActionEvent;
  4. import javafx.event.EventHandler;
  5. import javafx.fxml.FXML;
  6. import javafx.fxml.Initializable;
  7. import javafx.geometry.Pos;
  8. import javafx.scene.control.*;
  9. import javafx.scene.layout.FlowPane;
  10. import javafx.scene.layout.HBox;
  11. import javafx.scene.layout.VBox;
  12.  
  13. import java.io.*;
  14. import java.net.URL;
  15. import java.util.ArrayList;
  16. import java.util.Optional;
  17. import java.util.ResourceBundle;
  18. import java.util.Scanner;
  19.  
  20. public class Controller implements Initializable {
  21.  
  22. @FXML
  23. public FlowPane firstFlowPane;
  24. @FXML
  25. public Label choose_label;
  26. @FXML
  27. public RadioButton outgoing_rb;
  28. @FXML
  29. public RadioButton incoming_rb;
  30. @FXML
  31. public RadioButton deferred_rb;
  32. @FXML
  33. public ComboBox<String> outgoingType_cb;
  34. @FXML
  35. public Label quantity_label;
  36. @FXML
  37. public TextField quantity_tf;
  38. @FXML
  39. public Button enter_button;
  40. @FXML
  41. public TextField paymentDate_tf;
  42.  
  43. TextInputDialog dialogPane = new TextInputDialog();
  44.  
  45. public ArrayList<Double> all_Entries = null;
  46.  
  47. public Double Total = 0.0;
  48. File typeCBContent = new File("C:\\Users\\yunusbora\\Desktop\\Wallet\\src\\typeCBContent.txt");
  49.  
  50. //
  51. // public Controller() {
  52. // ToggleGroup rb_group = new ToggleGroup();
  53. // outgoing_rb.setToggleGroup(rb_group);
  54. // incoming_rb.setToggleGroup(rb_group);
  55. // deferred_rb.setToggleGroup(rb_group);
  56. // outgoingType_cb.setVisible(false);
  57. // quantity_tf.setVisible(false);
  58. // quantity_label.setVisible(false);
  59. //
  60. //
  61. // if(rb_group.getUserData() == null) {
  62. // outgoingType_cb.setVisible(false);
  63. // quantity_label.setVisible(false);
  64. // quantity_tf.setVisible(false);
  65. // }
  66. // rb_group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
  67. // @Override
  68. // public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
  69. // if(newValue == null) {
  70. // outgoingType_cb.setVisible(false);
  71. // quantity_label.setVisible(false);
  72. // quantity_tf.setVisible(false);
  73. //
  74. // }
  75. // }
  76. // }
  77. // );
  78. // }
  79.  
  80.  
  81. public void actionDefault() {
  82. outgoingType_cb.setVisible(true);
  83. quantity_label.setVisible(true);
  84. quantity_tf.setVisible(true);
  85. enter_button.setVisible(true);
  86. // if (!outgoingType_cb.itemsProperty().getValue().contains("Yeni seçenek ekle...")) {
  87. // outgoingType_cb.getItems().add("Yeni seçenek ekle...");
  88. // }
  89. outgoingType_cb.setVisibleRowCount(3);
  90. outgoingType_cb.getItems().addAll(readTypeCB());
  91. }
  92.  
  93. public void incomingAction() {
  94. actionDefault();
  95. outgoingType_cb.setPromptText("Giriş Tipini Belirtiniz");
  96. enter_button.setOnAction(e -> {
  97. Double incoming = Double.valueOf(quantity_tf.getText());
  98. all_Entries.add(incoming);
  99.  
  100. Double total_a = Total;
  101. for (Double all_Entry : all_Entries) {
  102. total_a = +all_Entry;
  103. }
  104. Total = total_a;
  105. });
  106. outgoingType_cb.itemsProperty().getValue().removeAll();
  107. }
  108.  
  109. public void outgoingAction() {
  110. actionDefault();
  111. outgoingType_cb.setPromptText("Lütfen harcama türünüzü seçiniz");
  112. if (!quantity_tf.getText().equals("")) {
  113. System.out.println("zaza");
  114. Double outgoing = Double.valueOf(quantity_tf.getText());
  115. Total = -outgoing;
  116. }
  117. }
  118.  
  119. public void deferredAction() {
  120. actionDefault();
  121. outgoingType_cb.setPromptText("Lütfen harcama türünüzü seçiniz");
  122. paymentDate_tf.setVisible(true);
  123. if (quantity_tf.getText().equals("")) {
  124. Double deferred = Double.valueOf(quantity_tf.getText());
  125. Total =- deferred;
  126. }
  127.  
  128. }
  129.  
  130. public Optional<String> dialogPaneCreator(String header, String title, String context) {
  131. dialogPane.setContentText(context);
  132. dialogPane.setTitle(title);
  133. dialogPane.setHeaderText(header);
  134. Optional<String> result = dialogPane.showAndWait();
  135. return result;
  136. }
  137.  
  138. @Override
  139. public void initialize(URL location, ResourceBundle resources) {
  140. final ToggleGroup rb_group = new ToggleGroup();
  141. outgoing_rb.setToggleGroup(rb_group);
  142. incoming_rb.setToggleGroup(rb_group);
  143. deferred_rb.setToggleGroup(rb_group);
  144. VBox typeVbox = new VBox(10);
  145. typeVbox.getChildren().addAll(choose_label, outgoing_rb, incoming_rb, deferred_rb);
  146. VBox processVbox = new VBox(10);
  147. processVbox.getChildren().addAll(outgoingType_cb,quantity_label, quantity_tf, paymentDate_tf, enter_button);
  148. HBox firstPartHbox = new HBox(10);
  149. firstPartHbox.getChildren().addAll(typeVbox, processVbox);
  150. firstFlowPane.getChildren().add(firstPartHbox);
  151. firstPartHbox.setAlignment(Pos.BASELINE_CENTER);
  152.  
  153. rb_group.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
  154. if(rb_group.getSelectedToggle() == null) {
  155. outgoingType_cb.setVisible(false);
  156. quantity_label.setVisible(false);
  157. quantity_tf.setVisible(false);
  158.  
  159. }
  160. else if(rb_group.getSelectedToggle() == incoming_rb) {
  161. incomingAction();
  162. }
  163. else if (rb_group.getSelectedToggle() == outgoing_rb) {
  164. outgoingAction();
  165. }
  166. else if (rb_group.getSelectedToggle() == deferred_rb) {
  167. deferredAction();
  168. }
  169. }
  170. );
  171.  
  172. outgoingType_cb.setOnAction(new EventHandler<ActionEvent>() {
  173. @Override
  174. public void handle(ActionEvent event) {
  175. System.out.println(outgoingType_cb.getValue());
  176.  
  177. if(outgoingType_cb.getValue() == "Yeni seçenek ekle...") {
  178. Optional<String> a = dialogPaneCreator("Lütfen harcama tipinizi giriniz!", "Yeni Harcama Tipi", "Harcama tipi : ");
  179. if (a.isPresent()) {
  180. outgoingType_cb.getItems().add(a.get());
  181. outgoingType_cb.setValue(a.get());
  182. try {
  183. writeTypeCB();
  184. } catch (FileNotFoundException e) {
  185. e.printStackTrace();
  186. }
  187. }
  188. }
  189. }
  190. });
  191. }
  192.  
  193. private void writeTypeCB() throws FileNotFoundException {
  194. String comboBoxItems = outgoingType_cb.itemsProperty().getValue().toString();
  195. System.out.println("comboBoxItems = " + comboBoxItems);
  196. if (!typeCBContent.exists()) {
  197. throw new FileNotFoundException("File is not exist" + typeCBContent);
  198. }
  199.  
  200. try {
  201. BufferedWriter bw = new BufferedWriter(new FileWriter(typeCBContent));
  202. bw.write(comboBoxItems.replace('[', ' ').replace(']', ' ').trim());
  203. bw.close();
  204. } catch (IOException e) {
  205. e.printStackTrace();
  206. }
  207. }
  208. private String[] readTypeCB() {
  209. String[] typesRead = null;
  210. String line;
  211. try {
  212. BufferedReader br = new BufferedReader(new FileReader(typeCBContent));
  213. while ((line = br.readLine()) != null) {
  214. typesRead = line.split(",");
  215. }
  216. }catch (IOException ex){
  217. ex.printStackTrace();
  218. }
  219. return typesRead;
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement