Search in sources :

Example 1 with PvProjectDailyEnergyGraph

use of org.concord.energy3d.gui.PvProjectDailyEnergyGraph in project energy3d by concord-consortium.

the class PvAnnualAnalysis method runAnalysis.

@Override
void runAnalysis(final JDialog parent) {
    graph.info = "Calculating...";
    graph.repaint();
    onStart();
    final EnergyPanel e = EnergyPanel.getInstance();
    for (final int m : MONTHS) {
        SceneManager.getTaskManager().update(new Callable<Object>() {

            @Override
            public Object call() {
                if (!analysisStopped) {
                    final Calendar c = Heliodon.getInstance().getCalendar();
                    c.set(Calendar.MONTH, m);
                    final Calendar today = (Calendar) c.clone();
                    Scene.getInstance().updateTrackables();
                    final Throwable t = compute();
                    if (t != null) {
                        stopAnalysis();
                        EventQueue.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                BugReporter.report(t);
                            }
                        });
                    }
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Foundation) {
                        // synchronize with daily graph
                        final PvProjectDailyEnergyGraph g = e.getPvProjectDailyEnergyGraph();
                        if (g.hasGraph()) {
                            g.setCalendar(today);
                            g.updateGraph();
                        }
                    }
                    final Calendar today2 = today;
                    EventQueue.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            e.getDateSpinner().setValue(c.getTime());
                            if (selectedPart instanceof Foundation) {
                                final PvProjectDailyEnergyGraph g = e.getPvProjectDailyEnergyGraph();
                                e.getPvProjectTabbedPane().setSelectedComponent(g);
                                if (!g.hasGraph()) {
                                    g.setCalendar(today2);
                                    g.addGraph((Foundation) selectedPart);
                                }
                            }
                        }
                    });
                }
                return null;
            }
        });
    }
    SceneManager.getTaskManager().update(new Callable<Object>() {

        @Override
        public Object call() {
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    onCompletion();
                    if (Heliodon.getInstance().getCalendar().get(Calendar.MONTH) != Calendar.DECEMBER) {
                        // annual calculation aborted
                        return;
                    }
                    final String current = Graph.TWO_DECIMALS.format(getResult("Solar"));
                    final Map<String, Double> recordedResults = getRecordedResults("Solar");
                    final int n = recordedResults.size();
                    if (n > 0) {
                        String previousRuns = "";
                        final Object[] keys = recordedResults.keySet().toArray();
                        for (int i = n - 1; i >= 0; i--) {
                            previousRuns += keys[i] + " : " + Graph.TWO_DECIMALS.format(recordedResults.get(keys[i]) * 365.0 / 12.0) + " kWh<br>";
                        }
                        final Object[] options = new Object[] { "OK", "Copy Data" };
                        final String msg = "<html>The calculated annual output is <b>" + current + " kWh</b>.<br><hr>Results from previously recorded tests:<br>" + previousRuns + "</html>";
                        final JOptionPane optionPane = new JOptionPane(msg, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
                        final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Annual Photovoltaic Output");
                        dialog.setVisible(true);
                        final Object choice = optionPane.getValue();
                        if (choice == options[1]) {
                            String output = "";
                            for (int i = 0; i < n; i++) {
                                output += Graph.TWO_DECIMALS.format(recordedResults.get(keys[i]) * 365.0 / 12.0) + "\n";
                            }
                            output += current;
                            final Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
                            clpbrd.setContents(new StringSelection(output), null);
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>" + (n + 1) + " data points copied to system clipboard.<br><hr>" + output, "Confirmation", JOptionPane.INFORMATION_MESSAGE);
                        }
                    } else {
                        JOptionPane.showMessageDialog(parent, "<html>The calculated annual output is <b>" + current + " kWh</b>.</html>", "Annual Photovoltaic Output", JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            });
            return null;
        }
    });
}
Also used : Calendar(java.util.Calendar) JOptionPane(javax.swing.JOptionPane) StringSelection(java.awt.datatransfer.StringSelection) EnergyPanel(org.concord.energy3d.gui.EnergyPanel) PvProjectDailyEnergyGraph(org.concord.energy3d.gui.PvProjectDailyEnergyGraph) Foundation(org.concord.energy3d.model.Foundation) Clipboard(java.awt.datatransfer.Clipboard) HousePart(org.concord.energy3d.model.HousePart) JDialog(javax.swing.JDialog)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)1 StringSelection (java.awt.datatransfer.StringSelection)1 Calendar (java.util.Calendar)1 JDialog (javax.swing.JDialog)1 JOptionPane (javax.swing.JOptionPane)1 EnergyPanel (org.concord.energy3d.gui.EnergyPanel)1 PvProjectDailyEnergyGraph (org.concord.energy3d.gui.PvProjectDailyEnergyGraph)1 Foundation (org.concord.energy3d.model.Foundation)1 HousePart (org.concord.energy3d.model.HousePart)1