Search in sources :

Example 1 with EventTimeSeries

use of org.concord.energy3d.agents.EventTimeSeries in project energy3d by concord-consortium.

the class MainFrame method getHelpMenu.

private JMenu getHelpMenu() {
    if (helpMenu == null) {
        helpMenu = new JMenu("Help");
        helpMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuCanceled(final MenuEvent e) {
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
            }

            @Override
            public void menuSelected(final MenuEvent e) {
            }
        });
        // User data and models
        final JMenu userHistoryMenu = new JMenu("View My History");
        helpMenu.add(userHistoryMenu);
        helpMenu.addSeparator();
        final JMenu userEventsMenu = new JMenu("Events");
        userHistoryMenu.add(userEventsMenu);
        JMenuItem mi = new JMenuItem("Event String");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new EventString().showGui();
            }
        });
        userEventsMenu.add(mi);
        mi = new JMenuItem("Event Time Series");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new EventTimeSeries().showGui();
            }
        });
        userEventsMenu.add(mi);
        mi = new JMenuItem("Event Frequency");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new EventFrequency().showGui();
            }
        });
        userEventsMenu.add(mi);
        final JMenu userResultsMenu = new JMenu("Results");
        userHistoryMenu.add(userResultsMenu);
        mi = new JMenuItem("Analysis Results");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new ResultList().showGui();
            }
        });
        userResultsMenu.add(mi);
        if (!Config.isMac()) {
            helpMenu.add(getPreferencesMenuItem());
        }
        helpMenu.add(getRecoveryMenuItem());
        // the automatic updater can fail sometimes. This provides an independent check.
        final JMenuItem miUpdate = new JMenuItem("Check Update...");
        helpMenu.add(miUpdate);
        miUpdate.setEnabled(!Config.isWebStart() && !Config.isEclipse());
        miUpdate.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                File jarFile = null;
                try {
                    jarFile = new File(MainApplication.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
                } catch (final URISyntaxException e1) {
                    e1.printStackTrace();
                    JOptionPane.showMessageDialog(instance, e1.getMessage(), "URL Error (local energy3d.jar)", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (!jarFile.toString().endsWith("energy3d.jar")) {
                    return;
                }
                final long localLastModified = jarFile.lastModified();
                new SwingWorker<Void, Void>() {

                    URLConnection connection = null;

                    String msg = null;

                    long remoteLastModified;

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            connection = new URL("http://energy.concord.org/energy3d/update/energy3d.jar").openConnection();
                            remoteLastModified = connection.getLastModified();
                        } catch (final Exception e1) {
                            e1.printStackTrace();
                            msg = e1.getMessage();
                        }
                        return null;
                    }

                    @Override
                    protected void done() {
                        if (connection == null) {
                            JOptionPane.showMessageDialog(instance, msg, "URL Error (remote energy3d.jar)", JOptionPane.ERROR_MESSAGE);
                        } else {
                            if (remoteLastModified <= localLastModified) {
                                JOptionPane.showMessageDialog(instance, "Your software is up to date.", "Update Status", JOptionPane.INFORMATION_MESSAGE);
                            } else {
                                JOptionPane.showMessageDialog(instance, "<html>Your software is out of date. But for some reason, it cannot update itself.<br>Please go to http://energy3d.concord.org to download and reinstall the latest version.</html>", "Update Status", JOptionPane.INFORMATION_MESSAGE);
                                Util.openBrowser("http://energy3d.concord.org");
                            }
                        }
                    }
                }.execute();
            }
        });
        helpMenu.addSeparator();
        // Energy3D web pages
        mi = new JMenuItem("Visit Virtual Solar Grid...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/vsg/syw.html");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("View Building Examples...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/styles.html");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("View User Work...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/models.html");
            }
        });
        helpMenu.add(mi);
        helpMenu.addSeparator();
        mi = new JMenuItem("Visit User Forum...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("https://energy.concord.org/energy3d/forum/");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("Visit Home Page...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy3d.concord.org");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("Contact Us...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/contact.html");
            }
        });
        helpMenu.add(mi);
        if (!Config.isMac()) {
            helpMenu.add(getAboutMenuItem());
        }
    }
    return helpMenu;
}
Also used : ResultList(org.concord.energy3d.agents.ResultList) MenuListener(javax.swing.event.MenuListener) ActionEvent(java.awt.event.ActionEvent) EventString(org.concord.energy3d.agents.EventString) URISyntaxException(java.net.URISyntaxException) EventString(org.concord.energy3d.agents.EventString) URLConnection(java.net.URLConnection) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) EventTimeSeries(org.concord.energy3d.agents.EventTimeSeries) ActionListener(java.awt.event.ActionListener) EventFrequency(org.concord.energy3d.agents.EventFrequency) SwingWorker(javax.swing.SwingWorker) JMenuItem(javax.swing.JMenuItem) File(java.io.File) JMenu(javax.swing.JMenu) MenuEvent(javax.swing.event.MenuEvent) MainApplication(org.concord.energy3d.MainApplication)

Example 2 with EventTimeSeries

use of org.concord.energy3d.agents.EventTimeSeries in project energy3d by concord-consortium.

the class MyEditorPane method buttonActionPerformed.

private void buttonActionPerformed(final String act, final QuestionnaireModel questionnaireModel, final DefaultButtonModel buttonModel) {
    if (act == null) {
        return;
    }
    // instruction sheet selection commands
    if (act.startsWith("Sheet")) {
        final int i = Integer.parseInt(act.substring(5).trim());
        EnergyPanel.getInstance().selectInstructionSheet(i - 1);
    } else if ("Questionnaire".equals(act)) {
        if (questionnaireModel != null) {
            MainApplication.addEvent(new QuestionnaireEvent(Scene.getURL(), System.currentTimeMillis(), questionnaireModel));
        }
    } else if (act.startsWith("Event Miner") || act.startsWith("Conformance Checker")) {
        final Agent a = MainApplication.getAgent(act);
        if (a != null) {
            final HashMap<String, Object> attributes = new HashMap<String, Object>();
            attributes.put("Agent", act);
            MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), '?', a.getName(), attributes));
            a.actuate();
        }
    } else // show actions
    if ("Event Frequency".equals(act)) {
        new EventFrequency().showGui();
    } else if ("Event Time Series".equals(act)) {
        new EventTimeSeries().showGui();
    } else if ("Event String".equals(act)) {
        new EventString().showGui();
    } else // heliodon commands
    if ("Heliodon".equals(act)) {
        MainPanel.getInstance().getHeliodonButton().setSelected(buttonModel.isSelected());
    } else if ("Heliodon On".equals(act)) {
        MainPanel.getInstance().getHeliodonButton().setSelected(true);
    } else if ("Heliodon Off".equals(act)) {
        MainPanel.getInstance().getHeliodonButton().setSelected(false);
    } else // sun motion commands
    if ("Sun Motion".equals(act)) {
        MainPanel.getInstance().getSunAnimationButton().setSelected(buttonModel.isSelected());
    } else if ("Sun Motion On".equals(act)) {
        MainPanel.getInstance().getSunAnimationButton().setSelected(true);
    } else if ("Sun Motion Off".equals(act)) {
        MainPanel.getInstance().getSunAnimationButton().setSelected(false);
    } else // shadow commands
    if ("Shadow".equals(act)) {
        MainPanel.getInstance().getShadowButton().setSelected(buttonModel.isSelected());
    } else if ("Shadow On".equals(act)) {
        MainPanel.getInstance().getShadowButton().setSelected(true);
    } else if ("Shadow Off".equals(act)) {
        MainPanel.getInstance().getShadowButton().setSelected(false);
    } else if (act.startsWith("Daily Analysis for Group")) {
        if (EnergyPanel.getInstance().checkCity()) {
            PartGroup g = null;
            final GroupSelector selector = new GroupSelector();
            for (final String s : GroupSelector.types) {
                final int index = act.indexOf(s);
                if (index > 0) {
                    selector.setCurrentGroupType(s);
                    try {
                        final String t = act.substring(index + s.length()).trim();
                        if (!t.equals("")) {
                            g = new PartGroup(s);
                            final String[] a = t.split(",");
                            for (final String x : a) {
                                g.addId(Integer.parseInt(x.trim()));
                            }
                        }
                    } catch (final Exception e) {
                        JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>Error in <i>" + act + "</i>.<br>Please select the IDs manually.</html>", "Input Error", JOptionPane.ERROR_MESSAGE);
                        g = null;
                    }
                    break;
                }
            }
            if (g == null) {
                g = selector.select();
            }
            if (g != null) {
                final PartGroup g2 = g;
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        // for some reason, this may be delayed in the AWT Event Queue in order to avoid a HTML form NullPointerException
                        final GroupDailyAnalysis a = new GroupDailyAnalysis(g2);
                        a.show(g2.getType() + ": " + g2.getIds());
                    }
                });
            }
            SceneManager.getInstance().hideAllEditPoints();
        }
    } else if (act.startsWith("Annual Analysis for Group")) {
        if (EnergyPanel.getInstance().checkCity()) {
            PartGroup g = null;
            final GroupSelector selector = new GroupSelector();
            for (final String s : GroupSelector.types) {
                final int index = act.indexOf(s);
                if (index > 0) {
                    selector.setCurrentGroupType(s);
                    try {
                        final String t = act.substring(index + s.length()).trim();
                        if (!t.equals("")) {
                            g = new PartGroup(s);
                            final String[] a = t.split(",");
                            for (final String x : a) {
                                g.addId(Integer.parseInt(x.trim()));
                            }
                        }
                    } catch (final Exception e) {
                        JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>Error in <i>" + act + "</i>.<br>Please select the IDs manually.</html>", "Input Error", JOptionPane.ERROR_MESSAGE);
                        g = null;
                    }
                    break;
                }
            }
            if (g == null) {
                g = selector.select();
            }
            if (g != null) {
                final PartGroup g2 = g;
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        // for some reason, this may be delayed in the AWT Event Queue in order to avoid a HTML form NullPointerException
                        final GroupAnnualAnalysis a = new GroupAnnualAnalysis(g2);
                        a.show(g2.getType() + ": " + g2.getIds());
                    }
                });
            }
            SceneManager.getInstance().hideAllEditPoints();
        }
    } else // environmental temperature graph
    if ("Daily Environmental Temperature".equals(act)) {
        if (EnergyPanel.getInstance().checkCity()) {
            new DailyEnvironmentalTemperature().showDialog();
        }
    } else if ("Annual Environmental Temperature".equals(act)) {
        if (EnergyPanel.getInstance().checkCity()) {
            new AnnualEnvironmentalTemperature().showDialog();
        }
    } else if ("Monthly Sunshine Hours".equals(act)) {
        if (EnergyPanel.getInstance().checkCity()) {
            new MonthlySunshineHours().showDialog();
        }
    } else {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>" + act + "</html>", "Information", JOptionPane.INFORMATION_MESSAGE);
    }
}
Also used : Agent(org.concord.energy3d.agents.Agent) AnnualEnvironmentalTemperature(org.concord.energy3d.simulation.AnnualEnvironmentalTemperature) HashMap(java.util.HashMap) GroupDailyAnalysis(org.concord.energy3d.simulation.GroupDailyAnalysis) GroupAnnualAnalysis(org.concord.energy3d.simulation.GroupAnnualAnalysis) MonthlySunshineHours(org.concord.energy3d.simulation.MonthlySunshineHours) EventString(org.concord.energy3d.agents.EventString) PartGroup(org.concord.energy3d.model.PartGroup) EventString(org.concord.energy3d.agents.EventString) ParseException(java.text.ParseException) BadLocationException(javax.swing.text.BadLocationException) DailyEnvironmentalTemperature(org.concord.energy3d.simulation.DailyEnvironmentalTemperature) EventTimeSeries(org.concord.energy3d.agents.EventTimeSeries) EventFrequency(org.concord.energy3d.agents.EventFrequency) QuestionnaireEvent(org.concord.energy3d.agents.QuestionnaireEvent) OperationEvent(org.concord.energy3d.agents.OperationEvent)

Aggregations

EventFrequency (org.concord.energy3d.agents.EventFrequency)2 EventString (org.concord.energy3d.agents.EventString)2 EventTimeSeries (org.concord.energy3d.agents.EventTimeSeries)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 SwingWorker (javax.swing.SwingWorker)1 MenuEvent (javax.swing.event.MenuEvent)1 MenuListener (javax.swing.event.MenuListener)1 BadLocationException (javax.swing.text.BadLocationException)1 MainApplication (org.concord.energy3d.MainApplication)1 Agent (org.concord.energy3d.agents.Agent)1