List of usage examples for javafx.scene.control ToggleButton isSelected
public final boolean isSelected()
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Toggle Button Sample"); stage.setWidth(250);//w ww .j a va 2 s. c om stage.setHeight(180); final ToggleGroup group = new ToggleGroup(); group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) { System.out.println((Color) group.getSelectedToggle().getUserData()); } }); Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png"))); ToggleButton tb1 = new ToggleButton("A", rootIcon); System.out.println(tb1.isSelected()); tb1.setToggleGroup(group); tb1.setUserData(Color.LIGHTGREEN); tb1.setSelected(true); ToggleButton tb2 = new ToggleButton("B"); tb2.setToggleGroup(group); tb2.setUserData(Color.LIGHTBLUE); ToggleButton tb3 = new ToggleButton("C"); tb3.setToggleGroup(group); tb3.setUserData(Color.SALMON); HBox hbox = new HBox(); hbox.getChildren().add(tb1); hbox.getChildren().add(tb2); hbox.getChildren().add(tb3); ((Group) scene.getRoot()).getChildren().add(hbox); stage.setScene(scene); stage.show(); }
From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java
@FXML void deleteOverlayButton_onAction(ActionEvent event) { LinkedList<File> overlayFiles = new LinkedList<File>(); for (Node overlay : overlayViewFlowPane.getChildren()) { ToggleButton overlayButton = (ToggleButton) overlay; if (overlayButton.isSelected()) overlayFiles.add((File) overlayButton.getUserData()); }/*from w ww . j av a 2s. co m*/ if (confirmDelete(overlayFiles)) { for (File file : overlayFiles) { log.info("Deleting: " + file.getName()); file.delete(); } loadImages(overlayTreeView.getSelectionModel().getSelectedItem()); } }
From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java
/** * This method is invoked when the "by category" button has been toggled * * @param actionEvent// ww w . j a v a 2s . 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 www .ja va 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 v a 2 s . co 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//from ww w . j a v a 2 s .c om */ 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:net.rptools.tokentool.controller.ManageOverlays_Controller.java
private void loadImages(File dir) { // Clear Details panel clearDetails();//from w ww . ja v a 2 s . c o m currentDirectory = dir; File[] files = dir.listFiles(ImageUtil.SUPPORTED_FILENAME_FILTER); Task<Void> task = new Task<Void>() { @Override public Void call() { for (File file : files) { Path filePath = file.toPath(); if (loadOverlaysThread.isInterrupted()) { Platform.runLater(() -> overlayViewFlowPane.getChildren().clear()); break; } try { ToggleButton overlayButton = new ToggleButton(); ImageView imageViewNode = ImageUtil.getOverlayThumb(new ImageView(), filePath); overlayButton.getStyleClass().add("overlay-toggle-button"); overlayButton.setGraphic(imageViewNode); overlayButton.setUserData(file); overlayButton.setToggleGroup(overlayToggleGroup); overlayButton.addEventHandler(ActionEvent.ACTION, event -> { // No modifier keys used so add toggle group back to all buttons resetToggleGroup(); // Also set button to selected due to resetting toggle groups & no unselecting needed, makes for better interface IMO overlayButton.setSelected(true); // Update the Details panel with the last selected overlay File overlayFile = (File) overlayButton.getUserData(); updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), overlayButton.isSelected()); // Consume the event, no more logic needed event.consume(); }); overlayButton.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { // Allow multiple selections if shortcutKey+left_mouse is pressed if (event.getButton().equals(MouseButton.PRIMARY) && event.isShortcutDown()) { // Update the Details panel with the last selected overlay File overlayFile = (File) overlayButton.getUserData(); updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), true); // Remove the toggle group to allow multiple toggle button selection overlayButton.setToggleGroup(null); // Select the button overlayButton.setSelected(true); // Consume the event, no more logic needed event.consume(); } } }); Platform.runLater(() -> overlayViewFlowPane.getChildren().add(overlayButton)); } catch (IOException e) { log.error("Loading image: " + filePath.getFileName(), e); } } return null; } }; loadOverlaysThread.interrupt(); executorService.execute(task); }