@Override public void save(IMemento memento) { IMemento group = memento.createChild("agents"); for (AgentInfo info : _agents) { IMemento child = group.createChild("agent"); child.putString("field", info.field); child.putString("value", info.value); } memento.putString("chart-type", _chartType.getValue().toString()); String nucId = _filters.getValue(); if (nucId != null) { IMemento filter = memento.createChild("filter"); filter.putString("nuc-id", nucId); } // axis options IMemento axis = memento.createChild("axis-opt"); axis.putBoolean("mode", _chart.axisMode().get() == CyclistAxis.Mode.LINEAR); axis.putBoolean("force-zero", _chart.forceZero().get()); // chart options IMemento chart = memento.createChild("chart-opt"); chart.putBoolean("mode", _chart.getMode().get() == ChartMode.LINE); chart.putBoolean("total", _chart.getShowTotal().getValue()); }
private Node createAxisOptions() { final Button btn = new Button("Axis", GlyphRegistry.get(AwesomeIcon.CARET_DOWN)); btn.getStyleClass().add("flat-button"); final ContextMenu menu = new ContextMenu(); btn.setOnMousePressed( new EventHandler<Event>() { @Override public void handle(Event event) { menu.show(btn, Side.BOTTOM, 0, 0); } }); MenuItem item = new MenuItem("Y linear", GlyphRegistry.get(AwesomeIcon.CHECK)); item.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { _chart.axisMode().set(CyclistAxis.Mode.LINEAR); } }); item.getGraphic() .visibleProperty() .bind(Bindings.equal(_chart.axisMode(), CyclistAxis.Mode.LINEAR)); menu.getItems().add(item); item = new MenuItem("Y log", GlyphRegistry.get(AwesomeIcon.CHECK)); item.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { _chart.axisMode().set(CyclistAxis.Mode.LOG); } }); item.getGraphic() .visibleProperty() .bind(Bindings.equal(_chart.axisMode(), CyclistAxis.Mode.LOG)); item.disableProperty().bind(Bindings.equal(_chart.getMode(), InventoryChart.ChartMode.STACKED)); menu.getItems().add(item); item = new MenuItem("Y force zero", GlyphRegistry.get(AwesomeIcon.CHECK)); item.getGraphic().visibleProperty().bind(_chart.forceZero()); item.disableProperty().bind(Bindings.equal(_chart.getMode(), InventoryChart.ChartMode.STACKED)); menu.getItems().add(item); item.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { _chart.forceZero().set(!_chart.forceZero().get()); } }); return btn; }
private void addAgent(String type, String name) { AgentInfo info = new AgentInfo(type, name); AgentEntry entry = new AgentEntry(info); _agentListPanel.getContent().getChildren().add(entry); entry.setOnClose( item -> { _agents.remove(item.info); _agentListPanel.getContent().getChildren().remove(item); _chart.remove(item.info); }); addAgent(info); }
@Override public void restore(IMemento memento, Context ctx) { IMemento group = memento.getChild("agents"); if (group != null) { for (IMemento child : group.getChildren("agent")) { addAgent(child.getString("field"), child.getString("value")); } } _chartType.setValue(ChartType.valueOf(memento.getString("chart-type"))); IMemento filter = memento.getChild("filter"); if (filter != null) { String nucId = filter.getString("nuc-id"); _filters.getSelectionModel().select(nucId); } IMemento axis = memento.getChild("axis-opt"); _chart.axisMode().set(axis.getBoolean("mode") ? CyclistAxis.Mode.LINEAR : CyclistAxis.Mode.LOG); _chart.forceZero().set(axis.getBoolean("force-zero")); IMemento chart = memento.getChild("chart-opt"); _chart.setMode(chart.getBoolean("mode") ? ChartMode.LINE : ChartMode.STACKED); _chart.setShowTotal(chart.getBoolean("total")); }
private void export() { FileChooser chooser = new FileChooser(); chooser .getExtensionFilters() .add( new FileChooser.ExtensionFilter( "Image file (png, jpg, gif)", "*.png", "*.jpg", "*.gif")); File file = chooser.showSaveDialog(Cyclist.cyclistStage); if (file != null) { WritableImage image = _chart.snapshot(new SnapshotParameters(), null); try { ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file); } catch (IOException e) { log.error("Error writing image to file: " + e.getMessage()); } } }
private void addToChart(AgentInfo info) { List<Pair<Integer, Double>> series = new ArrayList<>(); Pair<Integer, Double> current = null; for (Inventory i : info.filteredInventory) { if (current == null || current.v1 != i.time) { if (current != null) { series.add(current); } current = new Pair<>(); current.v1 = i.time; current.v2 = i.amount; } else { current.v2 += i.amount; } } if (current != null) { series.add(current); } info.series = series; if (info.active) _chart.add(info); }
private Node createModeActions() { final Button button = new Button("Options", GlyphRegistry.get(AwesomeIcon.CARET_DOWN)); button.getStyleClass().add("flat-button"); // create menu final ContextMenu contextMenu = new ContextMenu(); // line chart MenuItem item = new MenuItem("Line chart", GlyphRegistry.get(AwesomeIcon.CHECK)); item.getGraphic() .visibleProperty() .bind(Bindings.equal(_chart.getMode(), InventoryChart.ChartMode.LINE)); item.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { _chart.setMode(InventoryChart.ChartMode.LINE); if (!_lastForceZero) _chart.forceZero().set(false); if (_saveAxisMode == CyclistAxis.Mode.LOG) _chart.axisMode().set(CyclistAxis.Mode.LOG); } }); contextMenu.getItems().add(item); // // area chart // item = new MenuItem("Area chart"); // item.setOnAction(new EventHandler<ActionEvent>() { // @Override // public void handle(ActionEvent event) { // _chart.setMode(InventoryChart.ChartMode.AREA); // } // }); // contextMenu.getItems().add(item); // stacked chart item = new MenuItem("Stacked chart", GlyphRegistry.get(AwesomeIcon.CHECK)); item.getGraphic() .visibleProperty() .bind(Bindings.equal(_chart.getMode(), InventoryChart.ChartMode.STACKED)); item.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { _lastForceZero = _chart.forceZero().get(); if (!_lastForceZero) _chart.forceZero().set(true); _saveAxisMode = _chart.axisMode().get(); _chart.setMode(InventoryChart.ChartMode.STACKED); } }); contextMenu.getItems().add(item); contextMenu.getItems().add(new SeparatorMenuItem()); MenuItem checked = new MenuItem("Show total", GlyphRegistry.get(AwesomeIcon.CHECK)); checked.getGraphic().visibleProperty().bind(_chart.getShowTotal()); checked.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { _chart.setShowTotal(!_chart.getShowTotal().getValue()); } }); contextMenu.getItems().add(checked); button.setOnMousePressed( new EventHandler<Event>() { @Override public void handle(Event event) { contextMenu.show(button, Side.BOTTOM, 0, 0); } }); return button; }
private void selectChartType(ChartType type) { _chart.selectChartType(type); }