Search in sources :

Example 1 with OperationEvent

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

the class Scene method openNow.

public static void openNow(final URL file) throws Exception {
    SceneManager.getInstance().clearMouseState();
    SceneManager.getInstance().cursorWait(true);
    if (PrintController.getInstance().isPrintPreview()) {
        MainPanel.getInstance().getPreviewButton().setSelected(false);
        while (!PrintController.getInstance().isFinished()) {
            Thread.yield();
        }
    }
    url = file;
    if (!first) {
        SceneManager.getInstance().setHeliodonVisible(false);
        SceneManager.getInstance().setSunAnimation(false);
        Util.selectSilently(MainPanel.getInstance().getHeliodonButton(), false);
        Util.selectSilently(MainPanel.getInstance().getSunAnimationButton(), false);
    }
    SceneManager.getInstance().setSolarHeatMapWithoutUpdate(false);
    Wall.resetDefaultWallHeight();
    if (instance != null) {
        // in case of any possible memory leak
        instance.destroy();
    }
    if (url == null) {
        instance = new Scene();
        System.out.println("done");
    } else {
        System.out.println("Opening..." + file + "...");
        final ObjectInputStream in = new ObjectInputStream(file.openStream());
        instance = (Scene) in.readObject();
        in.close();
        for (final HousePart part : instance.parts) {
            part.getRoot();
        }
        instance.upgradeSceneToNewVersion();
        instance.cleanup();
        loadCameraLocation();
    }
    if (Util.isZero(instance.groundImageScale)) {
        instance.groundImageScale = 1;
    }
    SceneManager.getInstance().hideAllEditPoints();
    final CameraControl cameraControl = SceneManager.getInstance().getCameraControl();
    if (cameraControl != null) {
        cameraControl.reset();
    }
    instance.init();
    instance.applyGroundImage();
    EventQueue.invokeLater(new // update GUI must be called in Event Queue to prevent possible deadlocks
    Runnable() {

        @Override
        public void run() {
            MainPanel.getInstance().getAnnotationButton().setSelected(instance.isAnnotationsVisible);
            MainFrame.getInstance().updateTitleBar();
            SceneManager.getInstance().cursorWait(false);
            if (file != null) {
                final HashMap<String, Object> attributes = new HashMap<String, Object>();
                attributes.put("Open File", Scene.getURL());
                MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), "Open File", attributes));
            }
        }
    });
}
Also used : HashMap(java.util.HashMap) OperationEvent(org.concord.energy3d.agents.OperationEvent) HousePart(org.concord.energy3d.model.HousePart) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with OperationEvent

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

the class MonthlySunshineHours method showDialog.

public void showDialog() {
    final JDialog dialog = new JDialog(MainFrame.getInstance(), "Monthly Sunshine Hours", true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    final JPanel contentPane = new JPanel(new BorderLayout());
    dialog.setContentPane(contentPane);
    final JMenuBar menuBar = new JMenuBar();
    dialog.setJMenuBar(menuBar);
    final JMenu menuExport = new JMenu("Export");
    menuBar.add(menuExport);
    final JMenuItem mi = new JMenuItem("Copy Image");
    mi.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            new ClipImage().copyImageToClipboard(MonthlySunshineHours.this);
        }
    });
    menuExport.add(mi);
    final JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEtchedBorder());
    contentPane.add(panel, BorderLayout.CENTER);
    panel.add(this, BorderLayout.CENTER);
    final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    contentPane.add(buttonPanel, BorderLayout.SOUTH);
    final JButton button = new JButton("Close");
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            dialog.dispose();
        }
    });
    buttonPanel.add(button);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(final WindowEvent e) {
            dialog.dispose();
        }
    });
    dialog.pack();
    dialog.setLocationRelativeTo(MainFrame.getInstance());
    dialog.setVisible(true);
    TimeSeriesLogger.getInstance().logAnalysis(this);
    final HashMap<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("Location", Scene.getInstance().getCity());
    MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), getClass().getSimpleName(), attributes));
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) HashMap(java.util.HashMap) ActionEvent(java.awt.event.ActionEvent) ClipImage(org.concord.energy3d.util.ClipImage) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) JMenuItem(javax.swing.JMenuItem) OperationEvent(org.concord.energy3d.agents.OperationEvent) JDialog(javax.swing.JDialog) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 3 with OperationEvent

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

the class MyUndoManager method undo.

@Override
public void undo() throws CannotUndoException {
    super.undo();
    SaveCommand.setGloabalSignificant(true);
    Scene.getInstance().setEdited(!(editToBeUndone() instanceof SaveCommand));
    SaveCommand.setGloabalSignificant(false);
    refreshUndoRedoGui();
    TimeSeriesLogger.getInstance().logUndo();
    final HashMap<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("Action", getPresentationName());
    MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), "Undo", attributes));
}
Also used : HashMap(java.util.HashMap) OperationEvent(org.concord.energy3d.agents.OperationEvent)

Example 4 with OperationEvent

use of org.concord.energy3d.agents.OperationEvent 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 5 with OperationEvent

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

the class AnnualEnvironmentalTemperature method showDialog.

public void showDialog() {
    final JDialog dialog = new JDialog(MainFrame.getInstance(), "Annual Environmental Temperature", true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    final JPanel contentPane = new JPanel(new BorderLayout());
    dialog.setContentPane(contentPane);
    final JMenuBar menuBar = new JMenuBar();
    dialog.setJMenuBar(menuBar);
    final JCheckBoxMenuItem cbmiAirTemperature = new JCheckBoxMenuItem("Air Temperature");
    Util.selectSilently(cbmiAirTemperature, !hideData.get(lowestAirTemperature));
    final JCheckBoxMenuItem[] cbmiGroundTemperature = new JCheckBoxMenuItem[depth.length];
    for (int i = 0; i < depth.length; i++) {
        cbmiGroundTemperature[i] = new JCheckBoxMenuItem("Ground Temperature (" + depth[i] + "m)");
        Util.selectSilently(cbmiGroundTemperature[i], !hideData.get(lowestGroundTemperature[i]));
    }
    final JCheckBoxMenuItem cbmiShowAverage = new JCheckBoxMenuItem("Show Average");
    Util.selectSilently(cbmiShowAverage, showAverage);
    final JMenu menuView = new JMenu("View");
    menuBar.add(menuView);
    menuView.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(final MenuEvent e) {
            Util.selectSilently(cbmiAirTemperature, !hideData.get(lowestAirTemperature));
            for (int i = 0; i < depth.length; i++) {
                Util.selectSilently(cbmiGroundTemperature[i], !hideData.get(lowestGroundTemperature[i]));
            }
            Util.selectSilently(cbmiShowAverage, showAverage);
        }

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

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });
    cbmiAirTemperature.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            final JCheckBoxMenuItem source = (JCheckBoxMenuItem) e.getSource();
            hideData.put(lowestAirTemperature, !source.isSelected());
            AnnualEnvironmentalTemperature.this.repaint();
        }
    });
    menuView.add(cbmiAirTemperature);
    for (int i = 0; i < depth.length; i++) {
        final int i2 = i;
        cbmiGroundTemperature[i].addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                final JCheckBoxMenuItem source = (JCheckBoxMenuItem) e.getSource();
                hideData.put(lowestGroundTemperature[i2], !source.isSelected());
                AnnualEnvironmentalTemperature.this.repaint();
            }
        });
        menuView.add(cbmiGroundTemperature[i]);
    }
    menuView.addSeparator();
    cbmiShowAverage.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            final JCheckBoxMenuItem source = (JCheckBoxMenuItem) e.getSource();
            showAverage = source.isSelected();
            AnnualEnvironmentalTemperature.this.repaint();
        }
    });
    menuView.add(cbmiShowAverage);
    final JMenu menuExport = new JMenu("Export");
    menuBar.add(menuExport);
    final JMenuItem mi = new JMenuItem("Copy Image");
    mi.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            new ClipImage().copyImageToClipboard(AnnualEnvironmentalTemperature.this);
        }
    });
    menuExport.add(mi);
    final JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEtchedBorder());
    contentPane.add(panel, BorderLayout.CENTER);
    panel.add(this, BorderLayout.CENTER);
    final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    contentPane.add(buttonPanel, BorderLayout.SOUTH);
    final JButton button = new JButton("Close");
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            dialog.dispose();
        }
    });
    buttonPanel.add(button);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(final WindowEvent e) {
            dialog.dispose();
        }
    });
    dialog.pack();
    dialog.setLocationRelativeTo(MainFrame.getInstance());
    dialog.setVisible(true);
    TimeSeriesLogger.getInstance().logAnalysis(this);
    final HashMap<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("Location", Scene.getInstance().getCity());
    MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), getClass().getSimpleName(), attributes));
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) FlowLayout(java.awt.FlowLayout) HashMap(java.util.HashMap) MenuListener(javax.swing.event.MenuListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) BorderLayout(java.awt.BorderLayout) JMenuItem(javax.swing.JMenuItem) MenuEvent(javax.swing.event.MenuEvent) ClipImage(org.concord.energy3d.util.ClipImage) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) ItemListener(java.awt.event.ItemListener) OperationEvent(org.concord.energy3d.agents.OperationEvent) JDialog(javax.swing.JDialog) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

OperationEvent (org.concord.energy3d.agents.OperationEvent)8 HashMap (java.util.HashMap)7 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 JMenuItem (javax.swing.JMenuItem)4 BorderLayout (java.awt.BorderLayout)3 FlowLayout (java.awt.FlowLayout)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3 JButton (javax.swing.JButton)3 JDialog (javax.swing.JDialog)3 JMenu (javax.swing.JMenu)3 JMenuBar (javax.swing.JMenuBar)3 JPanel (javax.swing.JPanel)3 ClipImage (org.concord.energy3d.util.ClipImage)3 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)2 MenuEvent (javax.swing.event.MenuEvent)2 MenuListener (javax.swing.event.MenuListener)2