Search in sources :

Example 1 with MonthlySunshineHours

use of org.concord.energy3d.simulation.MonthlySunshineHours in project energy3d by concord-consortium.

the class PopupMenuForSky method getPopupMenu.

static JPopupMenu getPopupMenu() {
    if (popupMenuForSky == null) {
        final JMenuItem miInfo = new JMenuItem("Sky");
        miInfo.setEnabled(false);
        miInfo.setOpaque(true);
        miInfo.setBackground(Config.isMac() ? Color.DARK_GRAY : Color.GRAY);
        miInfo.setForeground(Color.WHITE);
        final JCheckBoxMenuItem miHeliodon = new JCheckBoxMenuItem("Heliodon");
        miHeliodon.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                MainPanel.getInstance().getHeliodonButton().doClick();
            }
        });
        final JMenu weatherMenu = new JMenu("Weather");
        JMenuItem mi = new JMenuItem("Monthly Sunshine Hours...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().checkCity()) {
                    new MonthlySunshineHours().showDialog();
                }
            }
        });
        weatherMenu.add(mi);
        mi = new JMenuItem("Annual Environmental Temperature...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().checkCity()) {
                    new AnnualEnvironmentalTemperature().showDialog();
                }
            }
        });
        weatherMenu.add(mi);
        mi = new JMenuItem("Daily Environmental Temperature...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().checkCity()) {
                    new DailyEnvironmentalTemperature().showDialog();
                }
            }
        });
        weatherMenu.add(mi);
        final JMenu themeMenu = new JMenu("Theme");
        final ButtonGroup themeButtonGroup = new ButtonGroup();
        final JRadioButtonMenuItem miBlueSky = new JRadioButtonMenuItem("Blue Sky");
        miBlueSky.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeThemeCommand c = new ChangeThemeCommand();
                    Scene.getInstance().setTheme(Scene.BLUE_SKY_THEME);
                    Scene.getInstance().setEdited(true);
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        themeButtonGroup.add(miBlueSky);
        themeMenu.add(miBlueSky);
        final JRadioButtonMenuItem miDesert = new JRadioButtonMenuItem("Desert");
        miDesert.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeThemeCommand c = new ChangeThemeCommand();
                    Scene.getInstance().setTheme(Scene.DESERT_THEME);
                    Scene.getInstance().setEdited(true);
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        themeButtonGroup.add(miDesert);
        themeMenu.add(miDesert);
        final JRadioButtonMenuItem miGrassland = new JRadioButtonMenuItem("Grassland");
        miGrassland.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeThemeCommand c = new ChangeThemeCommand();
                    Scene.getInstance().setTheme(Scene.GRASSLAND_THEME);
                    Scene.getInstance().setEdited(true);
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        themeButtonGroup.add(miGrassland);
        themeMenu.add(miGrassland);
        final JRadioButtonMenuItem miForest = new JRadioButtonMenuItem("Forest");
        miForest.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeThemeCommand c = new ChangeThemeCommand();
                    Scene.getInstance().setTheme(Scene.FOREST_THEME);
                    Scene.getInstance().setEdited(true);
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        themeButtonGroup.add(miForest);
        themeMenu.add(miForest);
        themeMenu.addMenuListener(new MenuListener() {

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

            @Override
            public void menuDeselected(final MenuEvent e) {
                SceneManager.getInstance().refresh();
            }

            @Override
            public void menuSelected(final MenuEvent e) {
                Util.selectSilently(miBlueSky, Scene.getInstance().getTheme() == Scene.BLUE_SKY_THEME);
                Util.selectSilently(miDesert, Scene.getInstance().getTheme() == Scene.DESERT_THEME);
                Util.selectSilently(miGrassland, Scene.getInstance().getTheme() == Scene.GRASSLAND_THEME);
                Util.selectSilently(miForest, Scene.getInstance().getTheme() == Scene.FOREST_THEME);
            }
        });
        final JMenuItem miDustLoss = new JMenuItem("Dust & Pollen...");
        miDustLoss.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final JPanel gui = new JPanel(new BorderLayout());
                final String title = "<html><b>Soiling loss factor:</b><br>Loss of productivity due to atmospheric dust and pollen<br>(a dimensionless parameter within [0, 1])</html>";
                gui.add(new JLabel(title), BorderLayout.NORTH);
                final JPanel inputPanel = new JPanel(new SpringLayout());
                inputPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                gui.add(inputPanel, BorderLayout.CENTER);
                final JTextField[] fields = new JTextField[12];
                for (int i = 0; i < 12; i++) {
                    final JLabel l = new JLabel(AnnualGraph.THREE_LETTER_MONTH[i] + ": ", JLabel.LEFT);
                    inputPanel.add(l);
                    fields[i] = new JTextField(threeDecimalsFormat.format(Scene.getInstance().getAtmosphere().getDustLoss(i)), 5);
                    l.setLabelFor(fields[i]);
                    inputPanel.add(fields[i]);
                }
                SpringUtilities.makeCompactGrid(inputPanel, 12, 2, 6, 6, 6, 6);
                while (true) {
                    if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Dust and pollen loss", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                        break;
                    }
                    boolean pass = true;
                    final double[] val = new double[12];
                    for (int i = 0; i < 12; i++) {
                        try {
                            val[i] = Double.parseDouble(fields[i].getText());
                            if (val[i] < 0 || val[i] > 1) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "Dust and pollen loss value must be in 0-1.", "Range Error", JOptionPane.ERROR_MESSAGE);
                                pass = false;
                            }
                        } catch (final NumberFormatException exception) {
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), fields[i].getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                            pass = false;
                        }
                    }
                    if (pass) {
                        boolean changed = false;
                        for (int i = 0; i < 12; i++) {
                            if (Math.abs(Scene.getInstance().getAtmosphere().getDustLoss(i) - val[i]) > 0.000001) {
                                changed = true;
                                break;
                            }
                        }
                        if (changed) {
                            final ChangeAtmosphericDustLossCommand c = new ChangeAtmosphericDustLossCommand();
                            for (int i = 0; i < 12; i++) {
                                Scene.getInstance().getAtmosphere().setDustLoss(val[i], i);
                            }
                            updateAfterEdit();
                            SceneManager.getInstance().getUndoManager().addEdit(c);
                        }
                        break;
                    }
                }
            }
        });
        popupMenuForSky = new JPopupMenu();
        popupMenuForSky.setInvoker(MainPanel.getInstance().getCanvasPanel());
        popupMenuForSky.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
                Util.selectSilently(miHeliodon, MainPanel.getInstance().getHeliodonButton().isSelected());
            }

            @Override
            public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
            }

            @Override
            public void popupMenuCanceled(final PopupMenuEvent e) {
            }
        });
        popupMenuForSky.add(miInfo);
        popupMenuForSky.add(miDustLoss);
        popupMenuForSky.add(miHeliodon);
        popupMenuForSky.addSeparator();
        popupMenuForSky.add(weatherMenu);
        popupMenuForSky.add(themeMenu);
    }
    return popupMenuForSky;
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) MenuListener(javax.swing.event.MenuListener) PopupMenuListener(javax.swing.event.PopupMenuListener) JTextField(javax.swing.JTextField) PopupMenuEvent(javax.swing.event.PopupMenuEvent) ChangeAtmosphericDustLossCommand(org.concord.energy3d.undo.ChangeAtmosphericDustLossCommand) BorderLayout(java.awt.BorderLayout) JMenuItem(javax.swing.JMenuItem) ChangeThemeCommand(org.concord.energy3d.undo.ChangeThemeCommand) PopupMenuEvent(javax.swing.event.PopupMenuEvent) MenuEvent(javax.swing.event.MenuEvent) AnnualEnvironmentalTemperature(org.concord.energy3d.simulation.AnnualEnvironmentalTemperature) MonthlySunshineHours(org.concord.energy3d.simulation.MonthlySunshineHours) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JLabel(javax.swing.JLabel) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) DailyEnvironmentalTemperature(org.concord.energy3d.simulation.DailyEnvironmentalTemperature) JPopupMenu(javax.swing.JPopupMenu) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) SpringLayout(javax.swing.SpringLayout) ItemListener(java.awt.event.ItemListener) JMenu(javax.swing.JMenu)

Example 2 with MonthlySunshineHours

use of org.concord.energy3d.simulation.MonthlySunshineHours 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)

Example 3 with MonthlySunshineHours

use of org.concord.energy3d.simulation.MonthlySunshineHours in project energy3d by concord-consortium.

the class MainFrame method getMonthlySunshineHoursMenuItem.

private JMenuItem getMonthlySunshineHoursMenuItem() {
    if (monthlySunshineHoursMenuItem == null) {
        monthlySunshineHoursMenuItem = new JMenuItem("Monthly Sunshine Hours...");
        monthlySunshineHoursMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().checkCity()) {
                    new MonthlySunshineHours().showDialog();
                }
            }
        });
    }
    return monthlySunshineHoursMenuItem;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) MonthlySunshineHours(org.concord.energy3d.simulation.MonthlySunshineHours) JMenuItem(javax.swing.JMenuItem)

Aggregations

MonthlySunshineHours (org.concord.energy3d.simulation.MonthlySunshineHours)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JMenuItem (javax.swing.JMenuItem)2 AnnualEnvironmentalTemperature (org.concord.energy3d.simulation.AnnualEnvironmentalTemperature)2 DailyEnvironmentalTemperature (org.concord.energy3d.simulation.DailyEnvironmentalTemperature)2 BorderLayout (java.awt.BorderLayout)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 ButtonGroup (javax.swing.ButtonGroup)1 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)1 JLabel (javax.swing.JLabel)1 JMenu (javax.swing.JMenu)1 JPanel (javax.swing.JPanel)1 JPopupMenu (javax.swing.JPopupMenu)1 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)1 JTextField (javax.swing.JTextField)1 SpringLayout (javax.swing.SpringLayout)1