Search in sources :

Example 11 with SecurityHistoryNode

use of jgnash.engine.SecurityHistoryNode in project jgnash by ccavanaugh.

the class SecurityHistoryController method handleDeletePriceAction.

@FXML
private void handleDeletePriceAction() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final List<SecurityHistoryNode> historyNodes = new ArrayList<>(priceTableView.getSelectionModel().getSelectedItems());
    // work backwards through the deletion list
    Collections.reverse(historyNodes);
    for (final SecurityHistoryNode historyNode : historyNodes) {
        engine.removeSecurityHistory(selectedSecurityNode.get(), historyNode.getLocalDate());
    }
}
Also used : ArrayList(java.util.ArrayList) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Engine(jgnash.engine.Engine) FXML(javafx.fxml.FXML) InjectFXML(jgnash.uifx.util.InjectFXML)

Example 12 with SecurityHistoryNode

use of jgnash.engine.SecurityHistoryNode in project jgnash by ccavanaugh.

the class SecuritiesHistoryDialog method addNode.

private void addNode() {
    final SecurityHistoryNode history = new SecurityHistoryNode(dateField.getLocalDate(), closeField.getDecimal(), volumeField.longValue(), highField.getDecimal(), lowField.getDecimal());
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    if (engine != null) {
        engine.addSecurityHistory(securityCombo.getSelectedSecurityNode(), history);
    }
}
Also used : SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Engine(jgnash.engine.Engine)

Example 13 with SecurityHistoryNode

use of jgnash.engine.SecurityHistoryNode in project jgnash by ccavanaugh.

the class SecuritiesHistoryDialog method createChart.

private static JFreeChart createChart(final SecurityNode node) {
    Objects.requireNonNull(node);
    final List<SecurityHistoryNode> hNodes = node.getHistoryNodes();
    final Date max = DateUtils.asDate(hNodes.get(hNodes.size() - 1).getLocalDate());
    final Date min = DateUtils.asDate(hNodes.get(0).getLocalDate());
    final DateAxis timeAxis = new DateAxis(null);
    timeAxis.setVisible(false);
    timeAxis.setAutoRange(false);
    timeAxis.setRange(min, max);
    final NumberAxis valueAxis = new NumberAxis(null);
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setVisible(false);
    final XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setBaseToolTipGenerator(new SecurityItemLabelGenerator(node));
    renderer.setOutline(true);
    renderer.setSeriesPaint(0, new Color(225, 247, 223));
    final XYPlot plot = new XYPlot(null, timeAxis, valueAxis, renderer);
    final List<List<SecurityHistoryNode>> groups = node.getHistoryNodeGroupsBySplits();
    for (int i = 0; i < groups.size(); i++) {
        int size = groups.get(i).size();
        Date[] date = new Date[size];
        double[] high = new double[size];
        double[] low = new double[size];
        double[] open = new double[size];
        double[] close = new double[size];
        double[] volume = new double[size];
        for (int j = 0; j < size; j++) {
            final SecurityHistoryNode hNode = groups.get(i).get(j);
            date[j] = DateUtils.asDate(hNode.getLocalDate());
            high[j] = hNode.getAdjustedHigh().doubleValue();
            low[j] = hNode.getAdjustedLow().doubleValue();
            open[j] = hNode.getAdjustedPrice().doubleValue();
            close[j] = hNode.getAdjustedPrice().doubleValue();
            volume[j] = hNode.getVolume();
        }
        final AbstractXYDataset data = new DefaultHighLowDataset(node.getDescription() + i, date, high, low, open, close, volume);
        plot.setDataset(i, data);
    }
    plot.setInsets(new RectangleInsets(1, 1, 1, 1));
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(null);
    return chart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) DefaultHighLowDataset(org.jfree.data.xy.DefaultHighLowDataset) Color(java.awt.Color) Date(java.util.Date) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) XYAreaRenderer(org.jfree.chart.renderer.xy.XYAreaRenderer) XYPlot(org.jfree.chart.plot.XYPlot) RectangleInsets(org.jfree.ui.RectangleInsets) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) List(java.util.List)

Aggregations

SecurityHistoryNode (jgnash.engine.SecurityHistoryNode)13 LocalDate (java.time.LocalDate)7 Engine (jgnash.engine.Engine)7 SecurityNode (jgnash.engine.SecurityNode)5 ArrayList (java.util.ArrayList)4 FXML (javafx.fxml.FXML)4 InjectFXML (jgnash.uifx.util.InjectFXML)4 BigDecimal (java.math.BigDecimal)3 List (java.util.List)3 SecurityHistoryEvent (jgnash.engine.SecurityHistoryEvent)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 HttpURLConnection (java.net.HttpURLConnection)2 URLConnection (java.net.URLConnection)2 Date (java.util.Date)2 AbstractEngineTest (jgnash.engine.AbstractEngineTest)2 DefaultHighLowDataset (org.jfree.data.xy.DefaultHighLowDataset)2 Test (org.junit.Test)2 Color (java.awt.Color)1