Search in sources :

Example 1 with GeoLocation

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

the class MainFrame method getSubmitToVsgMenuItem.

private JMenuItem getSubmitToVsgMenuItem() {
    if (submitToVsgMenuItem == null) {
        submitToVsgMenuItem = new JMenuItem("Submit to Virtual Solar Grid...");
        submitToVsgMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final GeoLocation geo = Scene.getInstance().getGeoLocation();
                if (geo == null) {
                    JOptionPane.showMessageDialog(MainFrame.getInstance(), "No geolocation is set for this model. It cannot be submitted.", "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String legal = "<html><hr><font size=2>";
                legal += "Please be advised that your submission contains an address that may be sensitive,<br>";
                legal += "for example under the circumstance that you are under 18 years old and are working<br>";
                legal += "on a home project. By clicking the Accept Button below, you (and your parent or<br>";
                legal += "guardian if you are a minor) will authorize the Virtual Solar Grid to publish your<br>";
                legal += "work in the public domain. Your work will be a valuable contribution to an important<br>";
                legal += "citizen science project for studying how humanity can be powered by renewable energy.<br>";
                legal += "<hr></html>";
                final JPanel gui = new JPanel(new BorderLayout());
                String s = "<html><b>Authorization for the Virtual Solar Grid to publish your work</b></html>";
                s += "";
                final Object[] options = new Object[] { "Accept", "Decline", "Check Virtual Solar Grid" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { s, legal, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[1]);
                final JDialog dialog = optionPane.createDialog(instance, "Authorization for Publication");
                dialog.setVisible(true);
                final Object choice = optionPane.getValue();
                if (choice == options[0]) {
                    VsgSubmitter.submit();
                } else if (choice == options[1] || choice == null) {
                    return;
                } else if (choice == options[2]) {
                    Util.openBrowser("http://energy.concord.org/energy3d/vsg/syw.html");
                }
            }
        });
    }
    return submitToVsgMenuItem;
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) ActionEvent(java.awt.event.ActionEvent) GeoLocation(org.concord.energy3d.model.GeoLocation) EventString(org.concord.energy3d.agents.EventString) JMenuItem(javax.swing.JMenuItem) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 2 with GeoLocation

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

the class MapDialog method setGeoLocation.

private void setGeoLocation() {
    final GeoLocation geoLocation = Scene.getInstance().getGeoLocation();
    if (geoLocation != null) {
        latitudeSpinner.setValue(geoLocation.getLatitude());
        longitudeSpinner.setValue(geoLocation.getLongitude());
        zoomSpinner.setValue(geoLocation.getZoom());
        addressField.setText(geoLocation.getAddress());
    }
}
Also used : GeoLocation(org.concord.energy3d.model.GeoLocation)

Example 3 with GeoLocation

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

the class Scene method setGeoLocation.

public void setGeoLocation(final double latitude, final double longitude, final int zoom, final String address) {
    if (geoLocation == null) {
        geoLocation = new GeoLocation(latitude, longitude);
    }
    geoLocation.setLatitude(latitude);
    geoLocation.setLongitude(longitude);
    geoLocation.setZoom(zoom);
    geoLocation.setAddress(address);
}
Also used : GeoLocation(org.concord.energy3d.model.GeoLocation)

Example 4 with GeoLocation

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

the class VsgSubmitter method submit.

public static void submit() {
    final GeoLocation geo = Scene.getInstance().getGeoLocation();
    if (geo == null) {
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "No geolocation is set for this model. It cannot be submitted.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    final Calendar calendar = Heliodon.getInstance().getCalendar();
    if (calendar.get(Calendar.DAY_OF_MONTH) != 1) {
        String msg = "";
        msg += "All models must have run an annual simulation and the date must be set to be the first day of a month.<br>";
        msg += "The date of this model is not set to the first day of a month and cannot be accepted.";
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>" + msg + "</html>", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (Scene.getInstance().getSolarResults() == null) {
        String msg = "";
        msg += "All models must have run an annual simulation, but this model does not<br>";
        msg += "provide any annual simulation result and cannot be accepted.";
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>" + msg + "</html>", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    String s = "{\n";
    s += "\t\"lat\": " + EnergyPanel.FIVE_DECIMALS.format(geo.getLatitude()) + ",\n";
    s += "\t\"lng\": " + EnergyPanel.FIVE_DECIMALS.format(geo.getLongitude()) + ",\n";
    s += "\t\"address\": \"" + geo.getAddress() + "\",\n";
    switch(Scene.getInstance().getProjectType()) {
        case Foundation.TYPE_PV_PROJECT:
            s += "\t\"type\": \"PV\",\n";
            s += "\t\"module_number\": " + Scene.getInstance().countSolarPanels() + ",\n";
            break;
        case Foundation.TYPE_CSP_PROJECT:
            s += "\t\"type\": \"CSP\",\n";
            break;
    }
    if (Scene.getInstance().getDesigner() != null) {
        s += "\t\"author\": \"" + Scene.getInstance().getDesigner().getName() + "\",\n";
    }
    if (Scene.getInstance().getProjectName() != null) {
        s += "\t\"label\": \"" + Scene.getInstance().getProjectName() + "\",\n";
    }
    final double[][] solarResults = Scene.getInstance().getSolarResults();
    if (solarResults != null) {
        for (int i = 0; i < solarResults.length; i++) {
            s += "\t\"" + AnnualGraph.THREE_LETTER_MONTH[i] + "\": \"";
            for (int j = 0; j < solarResults[i].length; j++) {
                s += EnergyPanel.FIVE_DECIMALS.format(solarResults[i][j]).replaceAll(",", "") + " ";
            }
            s = s.trim() + "\",\n";
        }
    }
    s += "\t\"url\": \"tbd\"\n";
    s += "}";
    File file;
    try {
        file = SnapshotLogger.getInstance().saveSnapshot("vsg_model");
    } catch (final Exception ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Failed in saving a snapshot of your current design.", "Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    final File currentFile = file;
    final String info = s;
    EventQueue.invokeLater(() -> {
        final JTextArea textArea = new JTextArea(info);
        textArea.setEditable(false);
        final JPanel panel = new JPanel(new BorderLayout(10, 10));
        final JScrollPane scrollPane = new JScrollPane(textArea);
        scrollPane.setPreferredSize(new Dimension(400, 300));
        panel.add(scrollPane, BorderLayout.NORTH);
        final JTextField nameField = new JTextField(Scene.getInstance().getDesigner() == null ? "User" : Scene.getInstance().getDesigner().getName());
        final JTextField emailField = new JTextField(Scene.getInstance().getDesigner() == null ? "" : Scene.getInstance().getDesigner().getEmail());
        final JTextField organizationField = new JTextField(Scene.getInstance().getDesigner() == null ? "" : Scene.getInstance().getDesigner().getOrganization());
        final JPanel personalInfoPanel = new JPanel(new SpringLayout());
        personalInfoPanel.setBorder(BorderFactory.createTitledBorder("Contributor information (for earning scores and making contact only)"));
        personalInfoPanel.add(new JLabel("Name: "));
        personalInfoPanel.add(nameField);
        personalInfoPanel.add(new JLabel("Email: "));
        personalInfoPanel.add(emailField);
        personalInfoPanel.add(new JLabel("Organization: "));
        personalInfoPanel.add(organizationField);
        SpringUtilities.makeCompactGrid(personalInfoPanel, 3, 2, 8, 8, 8, 8);
        panel.add(personalInfoPanel, BorderLayout.CENTER);
        String s1 = "<html><font size=2>";
        s1 += "By pressing the Yes button below, you agree to contribute your work to the Virtual Solar Grid, a public<br>";
        s1 += "website that collects many virtual solar power systems. Your work will be reviewed by experts to determine<br>";
        s1 += "its readiness for publication. You will be notified about its status through the email you provide above.<br>";
        s1 += "If you agree on these terms, please continue. Otherwise, click the No button to abort.</font><br><br>";
        s1 += "<b>Do you want to submit your work to the Virtual Solar Grid now?";
        s1 += "</b></html>";
        panel.add(new JLabel(s1), BorderLayout.SOUTH);
        if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), panel, "Virtual Solar Grid", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.YES_OPTION) {
            Scene.getInstance().getDesigner().setName(nameField.getText());
            Scene.getInstance().getDesigner().setEmail(emailField.getText());
            Scene.getInstance().getDesigner().setOrganization(organizationField.getText());
            new Uploader(nameField.getText(), emailField.getText(), organizationField.getText(), info, currentFile).execute();
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) Calendar(java.util.Calendar) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) SpringLayout(javax.swing.SpringLayout) GeoLocation(org.concord.energy3d.model.GeoLocation) File(java.io.File)

Aggregations

GeoLocation (org.concord.energy3d.model.GeoLocation)4 BorderLayout (java.awt.BorderLayout)2 JPanel (javax.swing.JPanel)2 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 Calendar (java.util.Calendar)1 JDialog (javax.swing.JDialog)1 JLabel (javax.swing.JLabel)1 JMenuItem (javax.swing.JMenuItem)1 JOptionPane (javax.swing.JOptionPane)1 JScrollPane (javax.swing.JScrollPane)1 JTextArea (javax.swing.JTextArea)1 JTextField (javax.swing.JTextField)1 SpringLayout (javax.swing.SpringLayout)1 EventString (org.concord.energy3d.agents.EventString)1