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; }
@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 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; }