Search in sources :

Example 6 with OperationEvent

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

the class DailyEnvironmentalTemperature method showDialog.

public void showDialog() {
    final JDialog dialog = new JDialog(MainFrame.getInstance(), "Daily 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[] cbmiGroundTemperature = new JCheckBoxMenuItem[depth.length];
    for (int i = 0; i < depth.length; i++) {
        cbmiGroundTemperature[i] = new JCheckBoxMenuItem(i == 0 ? "Air Temperature" : "Ground Temperature (" + depth[i] + "m)");
        Util.selectSilently(cbmiGroundTemperature[i], !hideData.get(groundTemperature[i]));
    }
    final JMenu menuView = new JMenu("View");
    menuBar.add(menuView);
    menuView.addMenuListener(new MenuListener() {

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

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

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });
    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(groundTemperature[i2], !source.isSelected());
                DailyEnvironmentalTemperature.this.repaint();
            }
        });
        menuView.add(cbmiGroundTemperature[i]);
    }
    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(DailyEnvironmentalTemperature.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());
    attributes.put("Date", Scene.getInstance().getDate().toString());
    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)

Example 7 with OperationEvent

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

the class MyUndoManager method redo.

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

Example 8 with OperationEvent

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

the class MainFrame method getNewMenuItem.

private JMenuItem getNewMenuItem() {
    if (newMenuItem == null) {
        newMenuItem = new JMenuItem("New");
        newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Config.isMac() ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK));
        newMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                boolean ok = false;
                if (Scene.getInstance().isEdited()) {
                    final int save = JOptionPane.showConfirmDialog(MainFrame.this, "Do you want to save changes?", "Save", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                    if (save == JOptionPane.YES_OPTION) {
                        save();
                        if (!Scene.getInstance().isEdited()) {
                            ok = true;
                        }
                    } else if (save != JOptionPane.CANCEL_OPTION) {
                        ok = true;
                    }
                } else {
                    ok = true;
                }
                if (ok) {
                    SceneManager.getTaskManager().update(new Callable<Object>() {

                        @Override
                        public Object call() throws Exception {
                            try {
                                Scene.newFile();
                                SceneManager.getInstance().resetCamera(ViewMode.NORMAL);
                                SceneManager.getInstance().getCameraControl().reset();
                                EventQueue.invokeLater(new Runnable() {

                                    @Override
                                    public void run() {
                                        updateTitleBar();
                                        EnergyPanel.getInstance().update();
                                        EnergyPanel.getInstance().clearAllGraphs();
                                        EnergyPanel.getInstance().selectInstructionSheet(0);
                                        MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), "New File", null));
                                    }
                                });
                            } catch (final Throwable err) {
                                BugReporter.report(err);
                            }
                            return null;
                        }
                    });
                }
            }
        });
    }
    return newMenuItem;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) OperationEvent(org.concord.energy3d.agents.OperationEvent) Callable(java.util.concurrent.Callable)

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