Search in sources :

Example 1 with PartGroup

use of org.concord.energy3d.model.PartGroup 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 2 with PartGroup

use of org.concord.energy3d.model.PartGroup in project energy3d by concord-consortium.

the class MainFrame method getGroupAnnualAnalysisMenuItem.

private JMenuItem getGroupAnnualAnalysisMenuItem() {
    if (groupAnnualAnalysisMenuItem == null) {
        groupAnnualAnalysisMenuItem = new JMenuItem("Annual Analysis for Group...");
        groupAnnualAnalysisMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().checkCity()) {
                    if (EnergyPanel.getInstance().adjustCellSize()) {
                        return;
                    }
                    final PartGroup g = new GroupSelector().select();
                    if (g != null) {
                        final GroupAnnualAnalysis a = new GroupAnnualAnalysis(g);
                        a.show(g.getType() + ": " + g.getIds());
                    }
                    SceneManager.getInstance().hideAllEditPoints();
                }
            }
        });
    }
    return groupAnnualAnalysisMenuItem;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) GroupAnnualAnalysis(org.concord.energy3d.simulation.GroupAnnualAnalysis) PartGroup(org.concord.energy3d.model.PartGroup) JMenuItem(javax.swing.JMenuItem)

Example 3 with PartGroup

use of org.concord.energy3d.model.PartGroup in project energy3d by concord-consortium.

the class MainFrame method getGroupDailyAnalysisMenuItem.

private JMenuItem getGroupDailyAnalysisMenuItem() {
    if (groupDailyAnalysisMenuItem == null) {
        groupDailyAnalysisMenuItem = new JMenuItem("Daily Analysis for Group...");
        groupDailyAnalysisMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().checkCity()) {
                    if (EnergyPanel.getInstance().adjustCellSize()) {
                        return;
                    }
                    final PartGroup g = new GroupSelector().select();
                    if (g != null) {
                        final GroupDailyAnalysis a = new GroupDailyAnalysis(g);
                        a.show(g.getType() + ": " + g.getIds());
                    }
                    SceneManager.getInstance().hideAllEditPoints();
                }
            }
        });
    }
    return groupDailyAnalysisMenuItem;
}
Also used : ActionListener(java.awt.event.ActionListener) GroupDailyAnalysis(org.concord.energy3d.simulation.GroupDailyAnalysis) ActionEvent(java.awt.event.ActionEvent) PartGroup(org.concord.energy3d.model.PartGroup) JMenuItem(javax.swing.JMenuItem)

Example 4 with PartGroup

use of org.concord.energy3d.model.PartGroup in project energy3d by concord-consortium.

the class GroupSelector method select.

PartGroup select() {
    final JPanel gui = new JPanel(new BorderLayout(5, 5));
    gui.setBorder(BorderFactory.createTitledBorder("Types and IDs"));
    final DefaultListModel<Long> idListModel = new DefaultListModel<Long>();
    final JComboBox<String> typeComboBox = new JComboBox<String>(types);
    if (currentGroupType != null) {
        typeComboBox.setSelectedItem(currentGroupType);
    }
    typeComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            idListModel.clear();
            currentGroupType = (String) typeComboBox.getSelectedItem();
            final Class<?> c = getCurrentGroupClass();
            if (c != null) {
                final ArrayList<Long> idArray = getIdArray(c);
                for (final Long id : idArray) {
                    idListModel.addElement(id);
                }
            }
        }
    });
    final Class<?> c = getCurrentGroupClass();
    if (c != null) {
        final ArrayList<Long> idArray = getIdArray(c);
        for (final Long id : idArray) {
            idListModel.addElement(id);
        }
    }
    final JList<Long> idList = new JList<Long>(idListModel);
    idList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            SceneManager.getInstance().hideAllEditPoints();
            final List<Long> selectedValues = idList.getSelectedValuesList();
            for (final Long i : selectedValues) {
                final HousePart p = Scene.getInstance().getPart(i);
                p.setEditPointsVisible(true);
                p.draw();
            }
        }
    });
    gui.add(typeComboBox, BorderLayout.NORTH);
    gui.add(new JScrollPane(idList), BorderLayout.CENTER);
    if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Select a Group", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.CANCEL_OPTION) {
        return null;
    }
    final List<Long> selectedIds = idList.getSelectedValuesList();
    if (selectedIds.isEmpty()) {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "You must select a group of parts first.", "Error", JOptionPane.ERROR_MESSAGE);
        return null;
    }
    return new PartGroup((String) typeComboBox.getSelectedItem(), selectedIds);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) PartGroup(org.concord.energy3d.model.PartGroup) ArrayList(java.util.ArrayList) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DefaultListModel(javax.swing.DefaultListModel) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) ItemListener(java.awt.event.ItemListener) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) JList(javax.swing.JList) HousePart(org.concord.energy3d.model.HousePart)

Aggregations

PartGroup (org.concord.energy3d.model.PartGroup)4 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JMenuItem (javax.swing.JMenuItem)2 GroupAnnualAnalysis (org.concord.energy3d.simulation.GroupAnnualAnalysis)2 GroupDailyAnalysis (org.concord.energy3d.simulation.GroupDailyAnalysis)2 BorderLayout (java.awt.BorderLayout)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DefaultListModel (javax.swing.DefaultListModel)1 JComboBox (javax.swing.JComboBox)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1