Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.geometry.Pos;
- import javafx.scene.control.*;
- import javafx.scene.layout.FlowPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import java.io.*;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Optional;
- import java.util.ResourceBundle;
- import java.util.Scanner;
- public class Controller implements Initializable {
- @FXML
- public FlowPane firstFlowPane;
- @FXML
- public Label choose_label;
- @FXML
- public RadioButton outgoing_rb;
- @FXML
- public RadioButton incoming_rb;
- @FXML
- public RadioButton deferred_rb;
- @FXML
- public ComboBox<String> outgoingType_cb;
- @FXML
- public Label quantity_label;
- @FXML
- public TextField quantity_tf;
- @FXML
- public Button enter_button;
- @FXML
- public TextField paymentDate_tf;
- TextInputDialog dialogPane = new TextInputDialog();
- public ArrayList<Double> all_Entries = null;
- public Double Total = 0.0;
- File typeCBContent = new File("C:\\Users\\yunusbora\\Desktop\\Wallet\\src\\typeCBContent.txt");
- //
- // public Controller() {
- // ToggleGroup rb_group = new ToggleGroup();
- // outgoing_rb.setToggleGroup(rb_group);
- // incoming_rb.setToggleGroup(rb_group);
- // deferred_rb.setToggleGroup(rb_group);
- // outgoingType_cb.setVisible(false);
- // quantity_tf.setVisible(false);
- // quantity_label.setVisible(false);
- //
- //
- // if(rb_group.getUserData() == null) {
- // outgoingType_cb.setVisible(false);
- // quantity_label.setVisible(false);
- // quantity_tf.setVisible(false);
- // }
- // rb_group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
- // @Override
- // public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
- // if(newValue == null) {
- // outgoingType_cb.setVisible(false);
- // quantity_label.setVisible(false);
- // quantity_tf.setVisible(false);
- //
- // }
- // }
- // }
- // );
- // }
- public void actionDefault() {
- outgoingType_cb.setVisible(true);
- quantity_label.setVisible(true);
- quantity_tf.setVisible(true);
- enter_button.setVisible(true);
- // if (!outgoingType_cb.itemsProperty().getValue().contains("Yeni seçenek ekle...")) {
- // outgoingType_cb.getItems().add("Yeni seçenek ekle...");
- // }
- outgoingType_cb.setVisibleRowCount(3);
- outgoingType_cb.getItems().addAll(readTypeCB());
- }
- public void incomingAction() {
- actionDefault();
- outgoingType_cb.setPromptText("Giriş Tipini Belirtiniz");
- enter_button.setOnAction(e -> {
- Double incoming = Double.valueOf(quantity_tf.getText());
- all_Entries.add(incoming);
- Double total_a = Total;
- for (Double all_Entry : all_Entries) {
- total_a = +all_Entry;
- }
- Total = total_a;
- });
- outgoingType_cb.itemsProperty().getValue().removeAll();
- }
- public void outgoingAction() {
- actionDefault();
- outgoingType_cb.setPromptText("Lütfen harcama türünüzü seçiniz");
- if (!quantity_tf.getText().equals("")) {
- System.out.println("zaza");
- Double outgoing = Double.valueOf(quantity_tf.getText());
- Total = -outgoing;
- }
- }
- public void deferredAction() {
- actionDefault();
- outgoingType_cb.setPromptText("Lütfen harcama türünüzü seçiniz");
- paymentDate_tf.setVisible(true);
- if (quantity_tf.getText().equals("")) {
- Double deferred = Double.valueOf(quantity_tf.getText());
- Total =- deferred;
- }
- }
- public Optional<String> dialogPaneCreator(String header, String title, String context) {
- dialogPane.setContentText(context);
- dialogPane.setTitle(title);
- dialogPane.setHeaderText(header);
- Optional<String> result = dialogPane.showAndWait();
- return result;
- }
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- final ToggleGroup rb_group = new ToggleGroup();
- outgoing_rb.setToggleGroup(rb_group);
- incoming_rb.setToggleGroup(rb_group);
- deferred_rb.setToggleGroup(rb_group);
- VBox typeVbox = new VBox(10);
- typeVbox.getChildren().addAll(choose_label, outgoing_rb, incoming_rb, deferred_rb);
- VBox processVbox = new VBox(10);
- processVbox.getChildren().addAll(outgoingType_cb,quantity_label, quantity_tf, paymentDate_tf, enter_button);
- HBox firstPartHbox = new HBox(10);
- firstPartHbox.getChildren().addAll(typeVbox, processVbox);
- firstFlowPane.getChildren().add(firstPartHbox);
- firstPartHbox.setAlignment(Pos.BASELINE_CENTER);
- rb_group.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
- if(rb_group.getSelectedToggle() == null) {
- outgoingType_cb.setVisible(false);
- quantity_label.setVisible(false);
- quantity_tf.setVisible(false);
- }
- else if(rb_group.getSelectedToggle() == incoming_rb) {
- incomingAction();
- }
- else if (rb_group.getSelectedToggle() == outgoing_rb) {
- outgoingAction();
- }
- else if (rb_group.getSelectedToggle() == deferred_rb) {
- deferredAction();
- }
- }
- );
- outgoingType_cb.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- System.out.println(outgoingType_cb.getValue());
- if(outgoingType_cb.getValue() == "Yeni seçenek ekle...") {
- Optional<String> a = dialogPaneCreator("Lütfen harcama tipinizi giriniz!", "Yeni Harcama Tipi", "Harcama tipi : ");
- if (a.isPresent()) {
- outgoingType_cb.getItems().add(a.get());
- outgoingType_cb.setValue(a.get());
- try {
- writeTypeCB();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- }
- });
- }
- private void writeTypeCB() throws FileNotFoundException {
- String comboBoxItems = outgoingType_cb.itemsProperty().getValue().toString();
- System.out.println("comboBoxItems = " + comboBoxItems);
- if (!typeCBContent.exists()) {
- throw new FileNotFoundException("File is not exist" + typeCBContent);
- }
- try {
- BufferedWriter bw = new BufferedWriter(new FileWriter(typeCBContent));
- bw.write(comboBoxItems.replace('[', ' ').replace(']', ' ').trim());
- bw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private String[] readTypeCB() {
- String[] typesRead = null;
- String line;
- try {
- BufferedReader br = new BufferedReader(new FileReader(typeCBContent));
- while ((line = br.readLine()) != null) {
- typesRead = line.split(",");
- }
- }catch (IOException ex){
- ex.printStackTrace();
- }
- return typesRead;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement