Example usage for javafx.event ActionEvent getTarget

List of usage examples for javafx.event ActionEvent getTarget

Introduction

In this page you can find the example usage for javafx.event ActionEvent getTarget.

Prototype

public EventTarget getTarget() 

Source Link

Document

Returns the event target of this event.

Usage

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

/**
 * This method is invoked when the "by category" button has been toggled
 *
 * @param actionEvent//from w  w w. ja v a 2  s.  c  o m
 */
public void byCategoryToggled(ActionEvent actionEvent) {
    final PieChart pieChart = new PieChart();
    pieChart.setTitle("Transaction balance by categories");
    pieChart.setLegendSide(LEFT);
    chartFrame.setCenter(pieChart);
    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {
                        ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(),
                                yearCombo.getValue());
                        if (period.isEmpty()) {
                            return null;
                        }
                        Platform.runLater(() -> pieChart.setTitle(format("%s for transactions from %s until %s",
                                pieChart.getTitle(), period.from().format(DATE_FORMATTER),
                                period.to().format(DATE_FORMATTER))));

                        categoryRepository.findAll().stream()
                                .sorted((c1, c2) -> c1.getName().compareTo(c2.getName())).forEach(category -> {
                                    List<Transaction> found = (accountCombo.getValue() == ALL_ACCOUNTS)
                                            ? transactionRepository.findByCategory(category)
                                            : transactionRepository.findByAccountAndCategory(
                                                    accountCombo.getValue(), category);
                                    if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                                        found = found.stream().filter(
                                                trx -> yearCombo.getValue().equals(trx.getDtOp().getYear()))
                                                .sorted((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp()))
                                                .collect(toList());
                                    }
                                    List<Transaction> transactions = new ArrayList<>(found.size());
                                    transactions.addAll(found);
                                    Platform.runLater(() -> {
                                        double value = getSum(transactions);
                                        String name = format("%s [%s]", category.getName(),
                                                CurrencyFormat.getInstance().format(value));
                                        PieChart.Data data = new PieChart.Data(name, value);
                                        pieChart.getData().add(data);
                                        data.getNode().addEventHandler(MOUSE_CLICKED,
                                                event -> handleCategoryChartMouseClickEvent(
                                                        (accountCombo.getValue() == ALL_ACCOUNTS) ? null
                                                                : accountCombo.getValue(),
                                                        category, yearCombo.getValue(), event));
                                    });
                                });
                        return null;
                    }
                };
            }
        };
        service.start();
    }
}

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

/**
 * This method is invoked when the daily balance button has been toggled
 *
 * @param actionEvent//from  ww  w  . j  a  v  a  2  s .  c  om
 */
public void dailyBalanceToggled(ActionEvent actionEvent) {
    LocalDateAxis xAxis = new LocalDateAxis();
    NumberAxis yAxis = new NumberAxis();

    final LineChart<LocalDate, Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setCreateSymbols(false);

    chartFrame.setCenter(lineChart);

    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        xAxis.setLabel("Day of year");
        yAxis.setLabel("Balance in Euro");
        lineChart.setTitle("Balance development day by day");

        ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(), yearCombo.getValue());
        if (period.isEmpty()) {
            return;
        }
        xAxis.setLowerBound(period.from());
        xAxis.setUpperBound(period.to());

        Service<Void> service = new Service<Void>() {

            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {

                    @Override
                    protected Void call() throws Exception {
                        Map<Account, List<Transaction>> transactionMap = getTransactions(
                                accountCombo.getValue(), yearCombo.getValue());

                        transactionMap.entrySet().forEach(entry -> {
                            Account account = entry.getKey();
                            List<Transaction> transactionList = entry.getValue();

                            XYChart.Series<LocalDate, Number> series = new XYChart.Series<>();
                            series.setName(format("%s [%s]", account.toPresentableString(),
                                    account.getFormattedBalance()));

                            // sort transactions by operation value descending
                            transactionList.sort((t1, t2) -> t2.getDtOp().compareTo(t1.getDtOp()));
                            account.calculateStartingBalance(transactionList);
                            series.getData()
                                    .add(new XYChart.Data<>(account.getBalanceDate(), account.getBalance()));

                            // sort transactions by operation value ascending
                            transactionList.sort((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp()));
                            transactionList.forEach(trx -> {
                                account.calculateCurrentBalance(trx);
                                series.getData().add(
                                        new XYChart.Data<>(account.getBalanceDate(), account.getBalance()));
                            });

                            Platform.runLater(() -> lineChart.getData().add(series));
                        });

                        return null;
                    }
                };
            }
        };
        service.start();
    }
}

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

public void yearlyInOutToggled(ActionEvent actionEvent) {
    final NumberAxis xAxis = new NumberAxis();
    final CategoryAxis yAxis = new CategoryAxis();
    yAxis.setLabel("In/Out in Euro");
    xAxis.setLabel("Year");

    final BarChart<Number, String> barChart = new BarChart<>(xAxis, yAxis);
    barChart.setTitle("Yearly in/out");

    chartFrame.setCenter(barChart);//from w  w  w. j a va  2 s  . c o m

    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        Account account = accountCombo.getValue();
        String accountLabel = getAccountLabel(account);

        XYChart.Series<Number, String> inSeries = new XYChart.Series<>();
        inSeries.setName("In" + accountLabel);
        barChart.getData().add(inSeries);

        XYChart.Series<Number, String> outSeries = new XYChart.Series<>();
        outSeries.setName("Out" + accountLabel);
        barChart.getData().add(outSeries);

        ValueRange<LocalDate> period = getTransactionOpRange(account, yearCombo.getValue());
        if (period.isEmpty()) {
            return;
        }
        ObservableList<String> categories = FXCollections.observableArrayList();
        for (int y = period.from().getYear(); y < period.to().getYear() + 6; y++) {
            categories.add(String.valueOf(y));
        }
        yAxis.setCategories(categories);
        Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {

                        List<TransactionVolume> incomingVolumes = (account == ALL_ACCOUNTS)
                                ? transactionRepository.getYearlyIncomingVolumes(false)
                                : transactionRepository.getYearlyIncomingVolumesOfAccount(account, false);
                        if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                            incomingVolumes = incomingVolumes.stream()
                                    .filter(v -> v.getYear().equals(yearCombo.getValue()))
                                    .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList());
                        }
                        for (TransactionVolume volume : incomingVolumes) {
                            XYChart.Data<Number, String> inData = new XYChart.Data<>(volume.getVolume(),
                                    String.valueOf(volume.getYear()));
                            Platform.runLater(() -> {
                                inSeries.getData().add(inData);
                                StackPane node = (StackPane) inData.getNode();
                                node.getChildren().add(
                                        new Label(CurrencyFormat.getInstance().format(volume.getVolume())));
                                node.addEventHandler(MOUSE_CLICKED,
                                        event -> handleYearlyInOutChartMouseClickEvent(
                                                (account == ALL_ACCOUNTS) ? null : account,
                                                ofYearDay(volume.getYear(), 1), event));
                            });
                        }

                        List<TransactionVolume> outgoingVolumes = (account == ALL_ACCOUNTS)
                                ? transactionRepository.getYearlyOutgoingVolumes(false)
                                : transactionRepository.getYearlyOutgoingVolumesOfAccount(account, false);
                        if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                            outgoingVolumes = outgoingVolumes.stream()
                                    .filter(v -> v.getYear().equals(yearCombo.getValue()))
                                    .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList());
                        }
                        for (TransactionVolume volume : outgoingVolumes) {
                            XYChart.Data<Number, String> outData = new XYChart.Data<>(volume.getVolume().abs(),
                                    String.valueOf(volume.getYear()));
                            Platform.runLater(() -> {
                                outSeries.getData().add(outData);
                                StackPane node = (StackPane) outData.getNode();
                                node.getChildren().add(
                                        new Label(CurrencyFormat.getInstance().format(volume.getVolume())));
                                node.addEventHandler(MOUSE_CLICKED,
                                        event -> handleYearlyInOutChartMouseClickEvent(
                                                (account == ALL_ACCOUNTS) ? null : account,
                                                ofYearDay(volume.getYear(), 1), event));
                            });
                        }

                        return null;
                    }
                };
            }
        };
        service.start();

    }
}

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

/**
 * This method is invoked when the monthly in/out button has been toggled
 *
 * @param actionEvent/*w  ww.  jav a2 s.co m*/
 */
public void monthlyInOutToggled(ActionEvent actionEvent) {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Month of Year");
    yAxis.setLabel("In/Out in Euro");

    final BarChart<String, Number> barChart = new BarChart<>(xAxis, yAxis);
    barChart.setTitle("Monthly in/out");

    chartFrame.setCenter(barChart);

    ToggleButton toggle = (ToggleButton) actionEvent.getTarget();
    if (toggle.isSelected()) {
        Account account = accountCombo.getValue();
        String accountLabel = getAccountLabel(account);

        XYChart.Series<String, Number> inSeries = new XYChart.Series<>();
        inSeries.setName("In" + accountLabel);
        barChart.getData().add(inSeries);

        XYChart.Series<String, Number> outSeries = new XYChart.Series<>();
        outSeries.setName("Out" + accountLabel);
        barChart.getData().add(outSeries);

        ValueRange<LocalDate> period = getTransactionOpRange(account, yearCombo.getValue());
        if (period.isEmpty()) {
            return;
        }
        ObservableList<String> monthLabels = FXCollections.observableArrayList();
        for (LocalDate date = period.from().withDayOfMonth(1); !date.isAfter(period.to()); date = date
                .plusMonths(1)) {
            monthLabels.add(getMonthLabel(date.getYear(), date.getMonthValue()));
        }
        xAxis.setCategories(monthLabels);
        Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {

                        List<TransactionVolume> incomingVolumes = (account == ALL_ACCOUNTS)
                                ? transactionRepository.getMonthlyIncomingVolumes(false)
                                : transactionRepository.getMonthlyIncomingVolumesOfAccount(account, false);
                        if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                            incomingVolumes = incomingVolumes.stream()
                                    .filter(v -> v.getYear().equals(yearCombo.getValue()))
                                    .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList());
                        }
                        for (TransactionVolume volume : incomingVolumes) {
                            String monthLabel = getMonthLabel(volume.getYear(), volume.getMonth());
                            XYChart.Data<String, Number> data = new XYChart.Data<>(monthLabel,
                                    volume.getVolume());
                            Platform.runLater(() -> {
                                inSeries.getData().add(data);
                                StackPane barNode = (StackPane) data.getNode();
                                // TODO make that look nicer
                                Label labelNode = new Label(
                                        CurrencyFormat.getInstance().format(volume.getVolume()));
                                labelNode.setPrefWidth(100);
                                labelNode.setAlignment(CENTER_RIGHT);
                                labelNode.setRotate(270);
                                barNode.getChildren().add(labelNode);
                                barNode.addEventHandler(MOUSE_CLICKED,
                                        event -> handleMonthlyInOutChartMouseClickEvent(
                                                (account == ALL_ACCOUNTS) ? null : account,
                                                of(volume.getYear(), volume.getMonth(), 1), event));
                            });
                        }

                        List<TransactionVolume> outgoingVolumes = (account == ALL_ACCOUNTS)
                                ? transactionRepository.getMonthlyOutgoingVolumes(false)
                                : transactionRepository.getMonthlyOutgoingVolumesOfAccount(account, false);
                        if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) {
                            outgoingVolumes = outgoingVolumes.stream()
                                    .filter(v -> v.getYear().equals(yearCombo.getValue()))
                                    .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList());
                        }
                        for (TransactionVolume volume : outgoingVolumes) {
                            String monthLabel = getMonthLabel(volume.getYear(), volume.getMonth());
                            XYChart.Data<String, Number> data = new XYChart.Data<>(monthLabel,
                                    volume.getVolume().abs());
                            Platform.runLater(() -> {
                                outSeries.getData().add(data);
                                StackPane node = (StackPane) data.getNode();
                                // TODO make that look nicer
                                Label labelNode = new Label(
                                        CurrencyFormat.getInstance().format(volume.getVolume()));
                                labelNode.setPrefWidth(100);
                                labelNode.setAlignment(CENTER_RIGHT);
                                labelNode.setRotate(270);
                                node.getChildren().add(labelNode);
                                node.addEventHandler(MOUSE_CLICKED,
                                        event -> handleMonthlyInOutChartMouseClickEvent(
                                                (account == ALL_ACCOUNTS ? null : account), volume.getDate(),
                                                event));
                            });
                        }

                        return null;
                    }
                };
            }
        };
        service.start();
    }
}

From source file:condorclient.CreateJobDialogController.java

@FXML
private void allocMethod(ActionEvent event) {
    String s = event.getTarget().toString();
    // System.out.println(s);
    String id = s.substring(s.indexOf("=") + 1, s.indexOf(","));//?1617
    if (id.equals("byslot")) {//?
        if (byslot.isSelected()) {
            allocMthod = 0;/*from   w  w  w  .j  a  va  2s  . c  om*/
            nodeNumText.setText("");
            // nodeNumText.setEditable(false);
            nodeNumText.setDisable(true);
            availNodeNumText.setText("");
            //availNodeNumText.setEditable(false);
            availNodeNumText.setDisable(true);
            nnumError.setText("");
            otherError.setText("");
            cpuNumText.setDisable(false);
            availCpuNumText.setText("" + slotNum);
            availCpuNumText.setDisable(true);
            for (int i = 0; i < showBoxNum; i++) {
                //  availMachines.getChildren().get(i).setDisable(true);
                // ((CheckBox) availMachines.getChildren().get(i)).setSelected(false);
                machineBox.getChildren().get(i).setDisable(true);
                ((CheckBox) machineBox.getChildren().get(i)).setSelected(false);
            }
        }
    } else if (id.equals("bynode")) {//?
        if (bynode.isSelected()) {
            allocMthod = 1;
            // nodeNumText.setText("");
            nodeNumText.setDisable(false);
            availNodeNumText.setText("" + nodeNum);
            availNodeNumText.setDisable(true);
            cpuNumText.setText("");
            cpuNumText.setDisable(true);
            availCpuNumText.setText("");
            availCpuNumText.setDisable(true);
            snumError.setText("");
            otherError.setText("");
            for (int i = 0; i < showBoxNum; i++) {
                // availMachines.getChildren().get(i).setDisable(true);
                machineBox.getChildren().get(i).setDisable(true);
                // ((CheckBox) availMachines.getChildren().get(i)).setSelected(false);
            }

        }
    } else {//?
        if (byappoint.isSelected()) {
            appointslotNum = 0;//?
            allocMthod = 2;
            nodeNumText.setDisable(true);
            nodeNumText.setText("");
            availNodeNumText.setText("");
            availNodeNumText.setDisable(true);
            cpuNumText.setText("");
            cpuNumText.setDisable(true);
            availCpuNumText.setText("");
            availCpuNumText.setDisable(true);
            nnumError.setText("");
            snumError.setText("");
            // otherError.setText("");
            for (int i = 0; i < showBoxNum; i++) {
                // availMachines.getChildren().get(i).setDisable(false);
                machineBox.getChildren().get(i).setDisable(false);
                //s
                // ((CheckBox) availMachines.getChildren().get(i)).setOnAction(new EventHandler<ActionEvent>() {
                /* ((CheckBox) machineBox.getChildren().get(i)).setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                  if (((CheckBox) event.getTarget()).isSelected()) {
                  otherError.setText("");
                  }
                  }
                  });*/
                //e

            }

        } else //s
        if (bycondor.isSelected()) {//?

            allocMthod = 3;
            nodeNumText.setDisable(true);
            nodeNumText.setText("");
            availNodeNumText.setText("");
            availNodeNumText.setDisable(true);
            cpuNumText.setText("");
            cpuNumText.setDisable(true);
            availCpuNumText.setText("");
            availCpuNumText.setDisable(true);
            nnumError.setText("");
            snumError.setText("");
            otherError.setText("");
            //reset checkbox
            // int cbn = availMachines.getChildren().size();
            int cbn = machineBox.getChildren().size();
            for (int i = 0; i < cbn; i++) {
                // ((CheckBox) availMachines.getChildren().get(i)).setDisable(true);
                //((CheckBox) availMachines.getChildren().get(i)).setSelected(false);
                ((CheckBox) machineBox.getChildren().get(i)).setDisable(true);
                ((CheckBox) machineBox.getChildren().get(i)).setSelected(false);
            }

        }
        //e

    }
    allocOk = true;
    enableButton();

}

From source file:condorclient.CreateJobDialogController.java

public void configAvailMachinesPane() {

    URL collector_url = null;/*from  w w w.  j a v a 2  s  .  com*/
    XMLHandler handler = new XMLHandler();
    String collectorStr = handler.getURL("collector");
    try {
        collector_url = new URL(collectorStr);
    } catch (MalformedURLException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }
    ClassAd ad = null;//birdbath.ClassAd;

    ClassAdStructAttr[][] startdAdsArray = null;

    Collector c = null;
    try {
        c = new Collector(collector_url);
    } catch (ServiceException ex) {
        Logger.getLogger(CondorClient.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        startdAdsArray = c.queryStartdAds("");//owner==\"lianxiang\"
    } catch (RemoteException ex) {
        Logger.getLogger(CondorClient.class.getName()).log(Level.SEVERE, null, ex);
    }

    String ip = null;
    String slotName = null;
    resourcesClassAds.clear();
    map.clear();

    for (ClassAdStructAttr[] x : startdAdsArray) {

        ad = new ClassAd(x);

        ip = ad.get("MyAddress");
        String ipStr = ip.substring(ip.indexOf("<") + 1, ip.indexOf(":"));
        // System.out.println(ad.toString());
        ObservableList<String> slotlist;

        slotlist = FXCollections.<String>observableArrayList();
        slotName = ad.get("Name");//

        if (!map.containsKey(ipStr)) {

            map.put(ipStr, slotlist);
        }

        map.get(ipStr).add(slotName);

        //PublicClaimId
    }

    showBoxNum = map.size();
    nodeNum = showBoxNum;
    selectedMachine = new int[nodeNum];
    //  vb=new VBox();
    //  machineBox.setSpacing(3);
    int i = 0;
    for (String s : map.keySet()) {
        CheckBox n = new CheckBox();
        String boxId = "box" + i;
        n.setId(boxId);
        n.setText(s);
        slotNum = slotNum + map.get(s).size();
        n.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                String s = event.getTarget().toString();
                // System.out.println(s);
                String id = s.substring(s.indexOf("=box") + 4, s.indexOf(","));
                System.out.println("boxid" + id);
                //String ip = s.substring(s.indexOf("]'") + 2, s.indexOf("'"));
                int intid = Integer.parseInt(id);//Integer.getInteger(id);
                //  System.out.println(intid + "id" + id);
                // CheckBox sbox = (CheckBox) availMachines.getChildren().get(intid);
                CheckBox sbox = (CheckBox) machineBox.getChildren().get(intid);
                if (sbox.isSelected()) {
                    selectedMachine[intid] = 1;
                    // System.out.println(selectedMachine[intid]);
                    apponitmap.putIfAbsent(sbox.getText().trim(), map.get(sbox.getText().trim()));//?ipslots
                    appointslotNum = appointslotNum + map.get(sbox.getText().trim()).size();//

                    System.out.println("machine id " + sbox.getText().trim() + "machine size"
                            + map.get(sbox.getText().trim()).size());
                } else {
                    selectedMachine[intid] = 0;
                    System.out.println("weixuanzhoong:" + selectedMachine[intid]);
                    if (apponitmap.containsKey(sbox.getText())) {
                        apponitmap.remove(sbox.getText());
                    }
                    appointslotNum = appointslotNum - map.get(sbox.getText().trim()).size();//
                }
                otherError.setText("");
                availCpuNumText.setText("");
                availCpuNumText.setText("" + appointslotNum);
                availCpuNumText.setDisable(true);
                availNodeNumText.setText("");
                availNodeNumText.setText("" + apponitmap.size());
                availNodeNumText.setDisable(true);
                // System.out.println("apponitmap.size():" + apponitmap.size() + "apponitmap.values().size():" + apponitmap.values().size());

            }
        });

        //availMachines.getChildren().add(n);
        machineBox.getChildren().add(n);

        //  boxContainer.getChildren().get(showBoxNum - 1).setVisible(true);
        i++;

    }
    // availMachines.getChildren().add(vb);

}

From source file:org.jgrades.lic.app.controller.BrowseFileWindowController.java

@FXML
void closeWindow(ActionEvent event) {
    ((Node) event.getTarget()).getScene().getWindow().hide();
}

From source file:org.noroomattheinn.visibletesla.MainController.java

@FXML
void inactivityOptionsHandler(ActionEvent event) {
    if (event.getTarget() == allowSleepMenuItem)
        app.api.allowSleeping();//from   w  w  w.ja v a 2  s .c o  m
    else
        app.api.stayAwake();
}