Search in sources :

Example 31 with ObservableList

use of javafx.collections.ObservableList in project trex-stateless-gui by cisco-system-traffic-generator.

the class RecordController method handleOnRecorderReceived.

private void handleOnRecorderReceived(WorkerStateEvent workerStateEvent) {
    List<CaptureInfo> monitors = recorderService.getValue();
    ObservableList<Recorder> currentRecorders = activeRecorders.getItems();
    monitors.stream().filter(monitor -> {
        final String mode = monitor.getMode();
        if (mode == null)
            return false;
        final boolean isModeSuitable = mode.equalsIgnoreCase("fixed") || mode.equalsIgnoreCase("cyclic");
        return isModeSuitable && monitor.getId() != pktCaptureService.getCurrentActiveMonitorId();
    }).map(this::captureInfo2Recorder).collect(toList()).forEach(newRecorder -> {
        Optional<Recorder> existed = currentRecorders.stream().filter(recorder -> recorder.getId() == newRecorder.getId()).findFirst();
        if (existed.isPresent()) {
            Recorder recorder = existed.get();
            recorder.setBytes(newRecorder.getBytes());
            recorder.setPackets(newRecorder.getPackets());
            recorder.setStatus(newRecorder.getStatus());
        } else {
            currentRecorders.add(newRecorder);
        }
    });
    currentRecorders.removeIf(recorder -> !monitors.stream().anyMatch(newRecorder -> newRecorder.getId() == recorder.getId()));
}
Also used : java.util(java.util) javafx.scene.control(javafx.scene.control) PktCaptureServiceException(com.cisco.trex.stl.gui.services.capture.PktCaptureServiceException) CaptureInfo(com.cisco.trex.stateless.model.capture.CaptureInfo) Logger(org.apache.log4j.Logger) Task(javafx.concurrent.Task) PortsManager(com.exalttech.trex.ui.PortsManager) Insets(javafx.geometry.Insets) PortModel(com.exalttech.trex.ui.models.PortModel) CapturedPackets(com.cisco.trex.stateless.model.capture.CapturedPackets) Initialization(com.exalttech.trex.util.Initialization) DataLinkType(org.pcap4j.packet.namednumber.DataLinkType) HBox(javafx.scene.layout.HBox) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) ScheduledService(javafx.concurrent.ScheduledService) org.pcap4j.core(org.pcap4j.core) PktCaptureService(com.cisco.trex.stl.gui.services.capture.PktCaptureService) EthernetPacket(org.pcap4j.packet.EthernetPacket) CapturedPkt(com.cisco.trex.stateless.model.capture.CapturedPkt) IllegalRawDataException(org.pcap4j.packet.IllegalRawDataException) Collectors(java.util.stream.Collectors) TrexAlertBuilder(com.exalttech.trex.ui.util.TrexAlertBuilder) File(java.io.File) Collectors.joining(java.util.stream.Collectors.joining) FXML(javafx.fxml.FXML) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) Duration(javafx.util.Duration) Collectors.toList(java.util.stream.Collectors.toList) ImageView(javafx.scene.image.ImageView) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) Recorder(com.cisco.trex.stl.gui.models.Recorder) Recorder(com.cisco.trex.stl.gui.models.Recorder) CaptureInfo(com.cisco.trex.stateless.model.capture.CaptureInfo)

Example 32 with ObservableList

use of javafx.collections.ObservableList in project jgnash by ccavanaugh.

the class IncomeExpensePayeePieChartDialogController method updateCharts.

private void updateCharts() {
    final Account account = accountComboBox.getValue();
    if (account != null) {
        final ObservableList<PieChart.Data>[] chartData = createPieDataSet(account);
        creditPieChart.setData(chartData[CREDIT]);
        debitPieChart.setData(chartData[DEBIT]);
        final NumberFormat numberFormat = NumericFormats.getFullCommodityFormat(account.getCurrencyNode());
        // Calculate the totals for percentage value
        final double creditTotal = chartData[CREDIT].parallelStream().mapToDouble(PieChart.Data::getPieValue).sum();
        final double debitTotal = chartData[DEBIT].parallelStream().mapToDouble(PieChart.Data::getPieValue).sum();
        final NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMaximumFractionDigits(1);
        percentFormat.setMinimumFractionDigits(1);
        // Install tooltips on the data after it has been added to the chart
        creditPieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip((data.getNode().getUserData() + "\n" + numberFormat.format(data.getPieValue()) + "(" + percentFormat.format(data.getPieValue() / creditTotal)) + ")")));
        // Install tooltips on the data after it has been added to the chart
        debitPieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip(((data.getNode().getUserData()) + "\n" + numberFormat.format(data.getPieValue()) + "(" + percentFormat.format(data.getPieValue() / debitTotal)) + ")")));
        creditPieChart.centerSubTitleProperty().set(numberFormat.format(creditTotal));
        debitPieChart.centerSubTitleProperty().set(numberFormat.format(debitTotal));
    } else {
        creditPieChart.setData(FXCollections.emptyObservableList());
        creditPieChart.setTitle("No Data");
        debitPieChart.setData(FXCollections.emptyObservableList());
        debitPieChart.setTitle("No Data");
    }
}
Also used : Account(jgnash.engine.Account) PieChart(javafx.scene.chart.PieChart) ObservableList(javafx.collections.ObservableList) Tooltip(javafx.scene.control.Tooltip) NumberFormat(java.text.NumberFormat)

Example 33 with ObservableList

use of javafx.collections.ObservableList in project POL-POM-5 by PlayOnLinux.

the class EnginesView method createEngineSubCategoryTabs.

private ObservableList<Tab> createEngineSubCategoryTabs(EngineSidebar sidebar) {
    // initialize the engines sub category panels
    final MappedList<List<EngineSubCategoryPanel>, EngineCategoryDTO> engineSubCategoryPanelGroups = new MappedList<>(this.engineCategories, engineCategory -> engineCategory.getSubCategories().stream().map(engineSubCategory -> {
        final EngineSubCategoryPanel engineSubCategoryPanel = new EngineSubCategoryPanel();
        engineSubCategoryPanel.setEngineCategory(engineCategory);
        engineSubCategoryPanel.setEngineSubCategory(engineSubCategory);
        engineSubCategoryPanel.setEnginesPath(this.enginesPath);
        engineSubCategoryPanel.setFilter(this.filter);
        engineSubCategoryPanel.setEngine(this.engines.get(engineCategory.getName().toLowerCase()));
        engineSubCategoryPanel.selectedListWidgetProperty().bind(sidebar.selectedListWidgetProperty());
        engineSubCategoryPanel.setOnEngineSelect(this::showEngineDetails);
        return engineSubCategoryPanel;
    }).collect(Collectors.toList()));
    final ConcatenatedList<EngineSubCategoryPanel> engineSubCategoryPanels = ConcatenatedList.create(engineSubCategoryPanelGroups);
    final FilteredList<EngineSubCategoryPanel> filteredEngineSubCategoryPanels = engineSubCategoryPanels.sorted(Comparator.comparing(engineSubCategoryPanel -> engineSubCategoryPanel.getEngineSubCategory().getName())).filtered(this.filter::filter);
    filteredEngineSubCategoryPanels.predicateProperty().bind(Bindings.createObjectBinding(() -> this.filter::filter, this.filter.searchTermProperty(), this.filter.showInstalledProperty(), this.filter.showNotInstalledProperty()));
    // map the panels to tabs
    return new MappedList<>(filteredEngineSubCategoryPanels, engineSubCategoryPanel -> new Tab(engineSubCategoryPanel.getEngineSubCategory().getDescription(), engineSubCategoryPanel));
}
Also used : MappedList(org.phoenicis.javafx.collections.MappedList) Tab(javafx.scene.control.Tab) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) MappedList(org.phoenicis.javafx.collections.MappedList) FilteredList(javafx.collections.transformation.FilteredList) ObservableList(javafx.collections.ObservableList) ConcatenatedList(org.phoenicis.javafx.collections.ConcatenatedList) EngineSubCategoryPanel(org.phoenicis.javafx.components.engine.control.EngineSubCategoryPanel)

Example 34 with ObservableList

use of javafx.collections.ObservableList in project POL-POM-5 by PlayOnLinux.

the class LibraryFeaturePanelSkin method createCombinedListWidget.

private CombinedListWidget<ShortcutDTO> createCombinedListWidget() {
    final FilteredList<ShortcutDTO> filteredShortcuts = ConcatenatedList.create(new MappedList<>(getControl().getCategories().sorted(Comparator.comparing(ShortcutCategoryDTO::getName)), ShortcutCategoryDTO::getShortcuts)).filtered(getControl().getFilter()::filter);
    filteredShortcuts.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty(), getControl().getFilter().selectedShortcutCategoryProperty()));
    final SortedList<ShortcutDTO> sortedShortcuts = filteredShortcuts.sorted(Comparator.comparing(shortcut -> shortcut.getInfo().getName()));
    final ObservableList<ListWidgetElement<ShortcutDTO>> listWidgetEntries = new MappedList<>(sortedShortcuts, ListWidgetElement::create);
    final CombinedListWidget<ShortcutDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
    // bind direction: controller property -> skin property
    getControl().selectedShortcutProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            combinedListWidget.select(newValue);
        } else {
            combinedListWidget.deselect();
        }
    });
    // bind direction: skin property -> controller properties
    combinedListWidget.selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final ShortcutDTO selectedItem = newValue.getItem();
            final MouseEvent event = newValue.getEvent();
            getControl().setSelectedShortcut(selectedItem);
            getControl().setOpenedDetailsPanel(new ShortcutInformation(selectedItem));
            if (event.getClickCount() == 2) {
                getControl().runShortcut(selectedItem);
            }
        } else {
            getControl().setSelectedShortcut(null);
            getControl().setOpenedDetailsPanel(new None());
        }
    });
    return combinedListWidget;
}
Also used : CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) StringBindings(org.phoenicis.javafx.utils.StringBindings) ObjectExpression(javafx.beans.binding.ObjectExpression) MappedList(org.phoenicis.javafx.collections.MappedList) MouseEvent(javafx.scene.input.MouseEvent) ShortcutEditing(org.phoenicis.javafx.components.library.panelstates.ShortcutEditing) Bindings(javafx.beans.binding.Bindings) SidebarBase(org.phoenicis.javafx.components.common.control.SidebarBase) org.phoenicis.javafx.components.library.control(org.phoenicis.javafx.components.library.control) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) ShortcutInformation(org.phoenicis.javafx.components.library.panelstates.ShortcutInformation) ShortcutCreation(org.phoenicis.javafx.components.library.panelstates.ShortcutCreation) TabPane(javafx.scene.control.TabPane) None(org.phoenicis.javafx.components.common.panelstates.None) FeaturePanelSkin(org.phoenicis.javafx.components.common.skin.FeaturePanelSkin) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) SwitchBinding(org.phoenicis.javafx.utils.SwitchBinding) SortedList(javafx.collections.transformation.SortedList) ListWidgetType(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetType) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) FilteredList(javafx.collections.transformation.FilteredList) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Observable(javafx.beans.Observable) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) OpenDetailsPanel(org.phoenicis.javafx.components.common.panelstates.OpenDetailsPanel) DetailsPanel(org.phoenicis.javafx.components.common.control.DetailsPanel) Optional(java.util.Optional) ObjectBindings(org.phoenicis.javafx.utils.ObjectBindings) ObservableList(javafx.collections.ObservableList) ConcatenatedList(org.phoenicis.javafx.collections.ConcatenatedList) Comparator(java.util.Comparator) CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) MouseEvent(javafx.scene.input.MouseEvent) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) ShortcutInformation(org.phoenicis.javafx.components.library.panelstates.ShortcutInformation) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) MappedList(org.phoenicis.javafx.collections.MappedList) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) None(org.phoenicis.javafx.components.common.panelstates.None)

Example 35 with ObservableList

use of javafx.collections.ObservableList in project Retrospector by NonlinearFruit.

the class OverallSectionController method update.

protected void update(List<Media> allMedia) {
    // Constants
    int last__days = 20;
    // Data Mining - Vars
    Map<String, Integer> categories = new HashMap<>();
    Map<LocalDate, Map<String, Integer>> last30Days = new HashMap<>();
    InfoBlipAccumulator info = new InfoBlipAccumulator();
    // Data Mining - Calcs
    for (Media m : allMedia) {
        categories.put(m.getCategory(), categories.getOrDefault(m.getCategory(), 0) + 1);
        info.accumulate(m);
        for (Review r : m.getReviews()) {
            if (ChronoUnit.DAYS.between(r.getDate(), LocalDate.now()) <= last__days) {
                Map<String, Integer> cat2Num = last30Days.getOrDefault(r.getDate(), new HashMap<>());
                Integer num = cat2Num.getOrDefault(m.getCategory(), 1);
                cat2Num.put(m.getCategory(), num + 1);
                last30Days.put(r.getDate(), cat2Num);
            }
            info.accumulate(r);
        }
    }
    // Stats
    statsBox.getChildren().clear();
    statsBox.getChildren().add(info.getInfo());
    // Chart # Media / Category
    chartMediaPerCategory.setData(FXCollections.observableArrayList(Arrays.asList(DataManager.getCategories()).stream().map(c -> {
        int count = categories.getOrDefault(c, 0);
        return new PieChart.Data(c + " - " + count, count);
    }).collect(Collectors.toList())));
    // Chart # Reviews / Day
    ObservableList list = FXCollections.observableArrayList();
    LocalDate now = LocalDate.now();
    for (String category : DataManager.getCategories()) {
        XYChart.Series data = new XYChart.Series();
        data.setName(category);
        for (int i = last__days; i > -1; i--) {
            LocalDate target = now.minusDays(i);
            int count = last30Days.getOrDefault(target, new HashMap<>()).getOrDefault(category, 0);
            String key = target.getDayOfMonth() + "";
            data.getData().add(new XYChart.Data(key, count));
        }
        list.add(data);
    }
    chartReviewsPerDay.setData(list);
}
Also used : Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) Review(retrospector.model.Review) StackedBarChart(javafx.scene.chart.StackedBarChart) URL(java.net.URL) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) CategoryAxis(javafx.scene.chart.CategoryAxis) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) Collectors(java.util.stream.Collectors) Media(retrospector.model.Media) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) ResourceBundle(java.util.ResourceBundle) LocalDate(java.time.LocalDate) Map(java.util.Map) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) DataManager(retrospector.model.DataManager) HashMap(java.util.HashMap) Media(retrospector.model.Media) Review(retrospector.model.Review) LocalDate(java.time.LocalDate) PieChart(javafx.scene.chart.PieChart) ObservableList(javafx.collections.ObservableList) XYChart(javafx.scene.chart.XYChart) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ObservableList (javafx.collections.ObservableList)77 List (java.util.List)46 ArrayList (java.util.ArrayList)31 Collectors (java.util.stream.Collectors)29 Map (java.util.Map)28 FXCollections (javafx.collections.FXCollections)28 HashMap (java.util.HashMap)21 Node (javafx.scene.Node)20 TableColumn (javafx.scene.control.TableColumn)20 Label (javafx.scene.control.Label)18 Optional (java.util.Optional)17 ActionEvent (javafx.event.ActionEvent)16 FXML (javafx.fxml.FXML)16 TableView (javafx.scene.control.TableView)16 MouseEvent (javafx.scene.input.MouseEvent)16 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 Button (javafx.scene.control.Button)15 BorderPane (javafx.scene.layout.BorderPane)15 File (java.io.File)14