Search in sources :

Example 11 with MenuEvent

use of javax.swing.event.MenuEvent in project energy3d by concord-consortium.

the class MainFrame method getHelpMenu.

private JMenu getHelpMenu() {
    if (helpMenu == null) {
        helpMenu = new JMenu("Help");
        helpMenu.addMenuListener(new MenuListener() {

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

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

            @Override
            public void menuSelected(final MenuEvent e) {
            }
        });
        // User data and models
        final JMenu userHistoryMenu = new JMenu("View My History");
        helpMenu.add(userHistoryMenu);
        helpMenu.addSeparator();
        final JMenu userEventsMenu = new JMenu("Events");
        userHistoryMenu.add(userEventsMenu);
        JMenuItem mi = new JMenuItem("Event String");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new EventString().showGui();
            }
        });
        userEventsMenu.add(mi);
        mi = new JMenuItem("Event Time Series");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new EventTimeSeries().showGui();
            }
        });
        userEventsMenu.add(mi);
        mi = new JMenuItem("Event Frequency");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new EventFrequency().showGui();
            }
        });
        userEventsMenu.add(mi);
        final JMenu userResultsMenu = new JMenu("Results");
        userHistoryMenu.add(userResultsMenu);
        mi = new JMenuItem("Analysis Results");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                new ResultList().showGui();
            }
        });
        userResultsMenu.add(mi);
        if (!Config.isMac()) {
            helpMenu.add(getPreferencesMenuItem());
        }
        helpMenu.add(getRecoveryMenuItem());
        // the automatic updater can fail sometimes. This provides an independent check.
        final JMenuItem miUpdate = new JMenuItem("Check Update...");
        helpMenu.add(miUpdate);
        miUpdate.setEnabled(!Config.isWebStart() && !Config.isEclipse());
        miUpdate.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                File jarFile = null;
                try {
                    jarFile = new File(MainApplication.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
                } catch (final URISyntaxException e1) {
                    e1.printStackTrace();
                    JOptionPane.showMessageDialog(instance, e1.getMessage(), "URL Error (local energy3d.jar)", JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (!jarFile.toString().endsWith("energy3d.jar")) {
                    return;
                }
                final long localLastModified = jarFile.lastModified();
                new SwingWorker<Void, Void>() {

                    URLConnection connection = null;

                    String msg = null;

                    long remoteLastModified;

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            connection = new URL("http://energy.concord.org/energy3d/update/energy3d.jar").openConnection();
                            remoteLastModified = connection.getLastModified();
                        } catch (final Exception e1) {
                            e1.printStackTrace();
                            msg = e1.getMessage();
                        }
                        return null;
                    }

                    @Override
                    protected void done() {
                        if (connection == null) {
                            JOptionPane.showMessageDialog(instance, msg, "URL Error (remote energy3d.jar)", JOptionPane.ERROR_MESSAGE);
                        } else {
                            if (remoteLastModified <= localLastModified) {
                                JOptionPane.showMessageDialog(instance, "Your software is up to date.", "Update Status", JOptionPane.INFORMATION_MESSAGE);
                            } else {
                                JOptionPane.showMessageDialog(instance, "<html>Your software is out of date. But for some reason, it cannot update itself.<br>Please go to http://energy3d.concord.org to download and reinstall the latest version.</html>", "Update Status", JOptionPane.INFORMATION_MESSAGE);
                                Util.openBrowser("http://energy3d.concord.org");
                            }
                        }
                    }
                }.execute();
            }
        });
        helpMenu.addSeparator();
        // Energy3D web pages
        mi = new JMenuItem("Visit Virtual Solar Grid...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/vsg/syw.html");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("View Building Examples...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/styles.html");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("View User Work...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/models.html");
            }
        });
        helpMenu.add(mi);
        helpMenu.addSeparator();
        mi = new JMenuItem("Visit User Forum...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("https://energy.concord.org/energy3d/forum/");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("Visit Home Page...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy3d.concord.org");
            }
        });
        helpMenu.add(mi);
        mi = new JMenuItem("Contact Us...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                Util.openBrowser("http://energy.concord.org/energy3d/contact.html");
            }
        });
        helpMenu.add(mi);
        if (!Config.isMac()) {
            helpMenu.add(getAboutMenuItem());
        }
    }
    return helpMenu;
}
Also used : ResultList(org.concord.energy3d.agents.ResultList) MenuListener(javax.swing.event.MenuListener) ActionEvent(java.awt.event.ActionEvent) EventString(org.concord.energy3d.agents.EventString) URISyntaxException(java.net.URISyntaxException) EventString(org.concord.energy3d.agents.EventString) URLConnection(java.net.URLConnection) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) EventTimeSeries(org.concord.energy3d.agents.EventTimeSeries) ActionListener(java.awt.event.ActionListener) EventFrequency(org.concord.energy3d.agents.EventFrequency) SwingWorker(javax.swing.SwingWorker) JMenuItem(javax.swing.JMenuItem) File(java.io.File) JMenu(javax.swing.JMenu) MenuEvent(javax.swing.event.MenuEvent) MainApplication(org.concord.energy3d.MainApplication)

Example 12 with MenuEvent

use of javax.swing.event.MenuEvent in project energy3d by concord-consortium.

the class MainFrame method getThemeMenu.

private JMenu getThemeMenu() {
    if (themeMenu == null) {
        themeMenu = new JMenu("Theme");
        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(blueSkyMenuItem, Scene.getInstance().getTheme() == Scene.BLUE_SKY_THEME);
                Util.selectSilently(desertMenuItem, Scene.getInstance().getTheme() == Scene.DESERT_THEME);
                Util.selectSilently(grasslandMenuItem, Scene.getInstance().getTheme() == Scene.GRASSLAND_THEME);
                Util.selectSilently(forestMenuItem, Scene.getInstance().getTheme() == Scene.FOREST_THEME);
            }
        });
        themeMenu.add(getBlueSkyMenuItem());
        themeMenu.add(getDesertMenuItem());
        themeMenu.add(getGrasslandMenuItem());
        themeMenu.add(getForestMenuItem());
    }
    return themeMenu;
}
Also used : MenuListener(javax.swing.event.MenuListener) JMenu(javax.swing.JMenu) MenuEvent(javax.swing.event.MenuEvent)

Example 13 with MenuEvent

use of javax.swing.event.MenuEvent in project energy3d by concord-consortium.

the class MainFrame method getFileMenu.

private JMenu getFileMenu() {
    if (fileMenu == null) {
        fileMenu = new JMenu();
        fileMenu.addMenuListener(new MenuListener() {

            private void enableMenuItems(final boolean b) {
                replayFolderMenuItem.setEnabled(b);
                replayLastFolderMenuItem.setEnabled(b);
                replayControlsMenu.setEnabled(b);
                analyzeFolderMenuItem.setEnabled(b);
                saveMenuItem.setEnabled(b);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                // if any of these actions is registered with a keystroke, we must re-enable it
                enableMenuItems(true);
            }

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

            @Override
            public void menuSelected(final MenuEvent e) {
                MainPanel.getInstance().defaultTool();
                enableMenuItems(true);
                // cannot overwrite a template
                saveMenuItem.setEnabled(!Scene.isInternalFile());
                // prevent multiple replay or postprocessing commands
                final boolean inactive = !PlayControl.active;
                replayFolderMenuItem.setEnabled(inactive);
                final File lastFolder = DesignReplay.getInstance().getLastFolder();
                replayLastFolderMenuItem.setEnabled(lastFolder != null && inactive);
                replayLastFolderMenuItem.setText(lastFolder != null ? "Replay Last Folder: " + lastFolder : "Replay Last Folder");
                replayControlsMenu.setEnabled(!inactive);
                analyzeFolderMenuItem.setEnabled(inactive);
                // recent files
                if (!recentFileMenuItems.isEmpty()) {
                    for (final JComponent x : recentFileMenuItems) {
                        fileMenu.remove(x);
                    }
                }
                final String[] recentFiles = FileChooser.getInstance().getRecentFiles();
                if (recentFiles != null) {
                    final int n = recentFiles.length;
                    if (n > 0) {
                        for (int i = 0; i < n; i++) {
                            final JMenuItem x = new JMenuItem((i + 1) + "  " + Util.getFileName(recentFiles[i]));
                            x.setToolTipText(recentFiles[i]);
                            final File rf = new File(recentFiles[i]);
                            x.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() {
                                                try {
                                                    Scene.open(rf.toURI().toURL());
                                                    updateTitleBar();
                                                    FileChooser.getInstance().rememberFile(rf.getPath());
                                                } catch (final Throwable err) {
                                                    BugReporter.report(err, rf.getAbsolutePath());
                                                }
                                                return null;
                                            }
                                        });
                                    }
                                }
                            });
                            fileMenu.insert(x, fileMenuItemCount + i);
                            recentFileMenuItems.add(x);
                        }
                        final JSeparator s = new JSeparator();
                        fileMenu.add(s, fileMenuItemCount + n);
                        recentFileMenuItems.add(s);
                    }
                }
            }
        });
        fileMenu.setText("File");
        addItemToFileMenu(getNewMenuItem());
        addItemToFileMenu(getOpenMenuItem());
        addItemToFileMenu(getSaveMenuItem());
        addItemToFileMenu(getSaveasMenuItem());
        addItemToFileMenu(getSubmitToVsgMenuItem());
        addItemToFileMenu(new JSeparator());
        addItemToFileMenu(getImportMenuItem());
        addItemToFileMenu(getImportColladaMenuItem());
        addItemToFileMenu(getCopyImageMenuItem());
        addItemToFileMenu(getExportModelMenuItem());
        addItemToFileMenu(getExportImageMenuItem());
        addItemToFileMenu(getExportLogMenuItem());
        addItemToFileMenu(new JSeparator());
        addItemToFileMenu(getReplayFolderMenuItem());
        addItemToFileMenu(getReplayLastFolderMenuItem());
        replayControlsMenu = new JMenu("Replay Controls");
        replayControlsMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuCanceled(final MenuEvent e) {
                // if any of these actions is registered with a keystroke, we must re-enable it
                endReplayMenuItem.setEnabled(true);
                pauseReplayMenuItem.setEnabled(true);
                forwardReplayMenuItem.setEnabled(true);
                backwardReplayMenuItem.setEnabled(true);
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                endReplayMenuItem.setEnabled(true);
                pauseReplayMenuItem.setEnabled(true);
                forwardReplayMenuItem.setEnabled(true);
                backwardReplayMenuItem.setEnabled(true);
            }

            @Override
            public void menuSelected(final MenuEvent e) {
                endReplayMenuItem.setEnabled(PlayControl.active);
                pauseReplayMenuItem.setEnabled(PlayControl.active);
                pauseReplayMenuItem.setText((PlayControl.replaying ? "Pause Replay" : "Resume Replay") + " (Space Bar)");
                forwardReplayMenuItem.setEnabled(!PlayControl.replaying);
                backwardReplayMenuItem.setEnabled(!PlayControl.replaying);
            }
        });
        addItemToFileMenu(replayControlsMenu);
        replayControlsMenu.add(getPauseReplayMenuItem());
        replayControlsMenu.add(getBackwardReplayMenuItem());
        replayControlsMenu.add(getForwardReplayMenuItem());
        replayControlsMenu.add(getEndReplayMenuItem());
        addItemToFileMenu(getAnalyzeFolderMenuItem());
        addItemToFileMenu(new JSeparator());
        addItemToFileMenu(getScaleToFitRadioButtonMenuItem());
        addItemToFileMenu(getExactSizeRadioButtonMenuItem());
        addItemToFileMenu(getPageSetupMenuItem());
        addItemToFileMenu(getPreviewMenuItem());
        addItemToFileMenu(getPrintMenuItem());
        addItemToFileMenu(new JSeparator());
        fileMenu.add(getExitMenuItem());
    }
    return fileMenu;
}
Also used : MenuListener(javax.swing.event.MenuListener) ActionEvent(java.awt.event.ActionEvent) JComponent(javax.swing.JComponent) Point(java.awt.Point) JSeparator(javax.swing.JSeparator) ActionListener(java.awt.event.ActionListener) JMenuItem(javax.swing.JMenuItem) File(java.io.File) JMenu(javax.swing.JMenu) MenuEvent(javax.swing.event.MenuEvent)

Example 14 with MenuEvent

use of javax.swing.event.MenuEvent in project energy3d by concord-consortium.

the class MainFrame method getTextureMenu.

private JMenu getTextureMenu() {
    if (textureMenu == null) {
        textureMenu = new JMenu("Texture");
        final JMenuItem removeBuildingTextureMenuItem = new JMenuItem("Remove Building Texture");
        removeBuildingTextureMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
                Scene.getInstance().setTextureMode(TextureMode.None);
                Scene.getInstance().setEdited(true);
                if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                    MainPanel.getInstance().getEnergyButton().setSelected(false);
                }
                SceneManager.getInstance().getUndoManager().addEdit(c);
            }
        });
        textureMenu.add(removeBuildingTextureMenuItem);
        final JMenuItem outlineBuildingTextureMenuItem = new JMenuItem("Use Outline Building Texture");
        outlineBuildingTextureMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final ChangeBuildingTextureCommand c = new ChangeBuildingTextureCommand();
                Scene.getInstance().setTextureMode(TextureMode.Simple);
                Scene.getInstance().setEdited(true);
                if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                    MainPanel.getInstance().getEnergyButton().setSelected(false);
                }
                SceneManager.getInstance().getUndoManager().addEdit(c);
            }
        });
        textureMenu.add(outlineBuildingTextureMenuItem);
        textureMenu.addSeparator();
        final JMenu wallTextureMenu = new JMenu("Walls");
        textureMenu.add(wallTextureMenu);
        final JRadioButtonMenuItem wallTexture01MenuItem = createWallTextureMenuItem(Wall.TEXTURE_01, "icons/wall_01.png");
        final JRadioButtonMenuItem wallTexture02MenuItem = createWallTextureMenuItem(Wall.TEXTURE_02, "icons/wall_02.png");
        final JRadioButtonMenuItem wallTexture03MenuItem = createWallTextureMenuItem(Wall.TEXTURE_03, "icons/wall_03.png");
        final JRadioButtonMenuItem wallTexture04MenuItem = createWallTextureMenuItem(Wall.TEXTURE_04, "icons/wall_04.png");
        final JRadioButtonMenuItem wallTexture05MenuItem = createWallTextureMenuItem(Wall.TEXTURE_05, "icons/wall_05.png");
        final JRadioButtonMenuItem wallTexture06MenuItem = createWallTextureMenuItem(Wall.TEXTURE_06, "icons/wall_06.png");
        final ButtonGroup wallTextureButtonGroup = new ButtonGroup();
        wallTextureButtonGroup.add(wallTexture01MenuItem);
        wallTextureButtonGroup.add(wallTexture02MenuItem);
        wallTextureButtonGroup.add(wallTexture03MenuItem);
        wallTextureButtonGroup.add(wallTexture04MenuItem);
        wallTextureButtonGroup.add(wallTexture05MenuItem);
        wallTextureButtonGroup.add(wallTexture06MenuItem);
        wallTextureMenu.add(wallTexture01MenuItem);
        wallTextureMenu.add(wallTexture02MenuItem);
        wallTextureMenu.add(wallTexture03MenuItem);
        wallTextureMenu.add(wallTexture04MenuItem);
        wallTextureMenu.add(wallTexture05MenuItem);
        wallTextureMenu.add(wallTexture06MenuItem);
        wallTextureMenu.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) {
                if (Scene.getInstance().getTextureMode() == TextureMode.Full) {
                    switch(Scene.getInstance().getWallTextureType()) {
                        case Wall.TEXTURE_01:
                            Util.selectSilently(wallTexture01MenuItem, true);
                            break;
                        case Wall.TEXTURE_02:
                            Util.selectSilently(wallTexture02MenuItem, true);
                            break;
                        case Wall.TEXTURE_03:
                            Util.selectSilently(wallTexture03MenuItem, true);
                            break;
                        case Wall.TEXTURE_04:
                            Util.selectSilently(wallTexture04MenuItem, true);
                            break;
                        case Wall.TEXTURE_05:
                            Util.selectSilently(wallTexture05MenuItem, true);
                            break;
                        case Wall.TEXTURE_06:
                            Util.selectSilently(wallTexture06MenuItem, true);
                            break;
                    }
                }
            }
        });
        final JMenu roofTextureMenu = new JMenu("Roofs");
        textureMenu.add(roofTextureMenu);
        final JRadioButtonMenuItem roofTexture01MenuItem = createRoofTextureMenuItem(Wall.TEXTURE_01, "icons/roof_01.png");
        final JRadioButtonMenuItem roofTexture02MenuItem = createRoofTextureMenuItem(Wall.TEXTURE_02, "icons/roof_02.png");
        final JRadioButtonMenuItem roofTexture03MenuItem = createRoofTextureMenuItem(Wall.TEXTURE_03, "icons/roof_03.png");
        final JRadioButtonMenuItem roofTexture04MenuItem = createRoofTextureMenuItem(Wall.TEXTURE_04, "icons/roof_04.png");
        final JRadioButtonMenuItem roofTexture05MenuItem = createRoofTextureMenuItem(Wall.TEXTURE_05, "icons/roof_05.png");
        final JRadioButtonMenuItem roofTexture06MenuItem = createRoofTextureMenuItem(Wall.TEXTURE_06, "icons/roof_06.png");
        final ButtonGroup roofTextureButtonGroup = new ButtonGroup();
        roofTextureButtonGroup.add(roofTexture01MenuItem);
        roofTextureButtonGroup.add(roofTexture02MenuItem);
        roofTextureButtonGroup.add(roofTexture03MenuItem);
        roofTextureButtonGroup.add(roofTexture04MenuItem);
        roofTextureButtonGroup.add(roofTexture05MenuItem);
        roofTextureButtonGroup.add(roofTexture06MenuItem);
        roofTextureMenu.add(roofTexture01MenuItem);
        roofTextureMenu.add(roofTexture02MenuItem);
        roofTextureMenu.add(roofTexture03MenuItem);
        roofTextureMenu.add(roofTexture04MenuItem);
        roofTextureMenu.add(roofTexture05MenuItem);
        roofTextureMenu.add(roofTexture06MenuItem);
        roofTextureMenu.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) {
                if (Scene.getInstance().getTextureMode() == TextureMode.Full) {
                    switch(Scene.getInstance().getRoofTextureType()) {
                        case Roof.TEXTURE_01:
                            Util.selectSilently(roofTexture01MenuItem, true);
                            break;
                        case Roof.TEXTURE_02:
                            Util.selectSilently(roofTexture02MenuItem, true);
                            break;
                        case Roof.TEXTURE_03:
                            Util.selectSilently(roofTexture03MenuItem, true);
                            break;
                        case Roof.TEXTURE_04:
                            Util.selectSilently(roofTexture04MenuItem, true);
                            break;
                        case Roof.TEXTURE_05:
                            Util.selectSilently(roofTexture05MenuItem, true);
                            break;
                        case Roof.TEXTURE_06:
                            Util.selectSilently(roofTexture06MenuItem, true);
                            break;
                    }
                }
            }
        });
        textureMenu.addSeparator();
        final JMenu heliostatTextureMenu = new JMenu("Heliostats");
        textureMenu.add(heliostatTextureMenu);
        final ButtonGroup heliostatTextureButtonGroup = new ButtonGroup();
        final JRadioButtonMenuItem heliostat1MirrorTextureMenuItem = new JRadioButtonMenuItem("Whole Mirror");
        heliostat1MirrorTextureMenuItem.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeHeliostatTextureCommand c = new ChangeHeliostatTextureCommand();
                    Scene.getInstance().setHeliostatTextureType(Mirror.TEXTURE_ONE_MIRROR);
                    Scene.getInstance().setEdited(true);
                    if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                    Scene.getInstance().redrawAll();
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        heliostatTextureButtonGroup.add(heliostat1MirrorTextureMenuItem);
        final JRadioButtonMenuItem heliostat2X1MirrorsTextureMenuItem = new JRadioButtonMenuItem("2 \u00D7 1 Mirrors");
        heliostat2X1MirrorsTextureMenuItem.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeHeliostatTextureCommand c = new ChangeHeliostatTextureCommand();
                    Scene.getInstance().setHeliostatTextureType(Mirror.TEXTURE_2X1_MIRRORS);
                    Scene.getInstance().setEdited(true);
                    if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                    Scene.getInstance().redrawAll();
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        heliostatTextureButtonGroup.add(heliostat2X1MirrorsTextureMenuItem);
        final JRadioButtonMenuItem heliostat1X2MirrorsTextureMenuItem = new JRadioButtonMenuItem("1 \u00D7 2 Mirrors");
        heliostat1X2MirrorsTextureMenuItem.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeHeliostatTextureCommand c = new ChangeHeliostatTextureCommand();
                    Scene.getInstance().setHeliostatTextureType(Mirror.TEXTURE_1X2_MIRRORS);
                    Scene.getInstance().setEdited(true);
                    if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                    Scene.getInstance().redrawAll();
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        heliostatTextureButtonGroup.add(heliostat1X2MirrorsTextureMenuItem);
        final JRadioButtonMenuItem heliostat7X5MirrorsTextureMenuItem = new JRadioButtonMenuItem("7 \u00D7 5 Mirrors");
        heliostat7X5MirrorsTextureMenuItem.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final ChangeHeliostatTextureCommand c = new ChangeHeliostatTextureCommand();
                    Scene.getInstance().setHeliostatTextureType(Mirror.TEXTURE_7X5_MIRRORS);
                    Scene.getInstance().setEdited(true);
                    if (MainPanel.getInstance().getEnergyButton().isSelected()) {
                        MainPanel.getInstance().getEnergyButton().setSelected(false);
                    }
                    Scene.getInstance().redrawAll();
                    SceneManager.getInstance().getUndoManager().addEdit(c);
                }
            }
        });
        heliostatTextureButtonGroup.add(heliostat7X5MirrorsTextureMenuItem);
        heliostatTextureMenu.add(heliostat1MirrorTextureMenuItem);
        heliostatTextureMenu.add(heliostat2X1MirrorsTextureMenuItem);
        heliostatTextureMenu.add(heliostat1X2MirrorsTextureMenuItem);
        heliostatTextureMenu.add(heliostat7X5MirrorsTextureMenuItem);
        heliostatTextureMenu.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) {
                switch(Scene.getInstance().getHeliostatTextureType()) {
                    default:
                        Util.selectSilently(heliostat1MirrorTextureMenuItem, true);
                        break;
                    case Mirror.TEXTURE_2X1_MIRRORS:
                        Util.selectSilently(heliostat2X1MirrorsTextureMenuItem, true);
                        break;
                    case Mirror.TEXTURE_1X2_MIRRORS:
                        Util.selectSilently(heliostat1X2MirrorsTextureMenuItem, true);
                        break;
                    case Mirror.TEXTURE_7X5_MIRRORS:
                        Util.selectSilently(heliostat7X5MirrorsTextureMenuItem, true);
                        break;
                }
            }
        });
    }
    return textureMenu;
}
Also used : ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) MenuListener(javax.swing.event.MenuListener) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ChangeHeliostatTextureCommand(org.concord.energy3d.undo.ChangeHeliostatTextureCommand) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ChangeBuildingTextureCommand(org.concord.energy3d.undo.ChangeBuildingTextureCommand) ItemListener(java.awt.event.ItemListener) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) MenuEvent(javax.swing.event.MenuEvent)

Example 15 with MenuEvent

use of javax.swing.event.MenuEvent in project energy3d by concord-consortium.

the class MainFrame method getTemplatesMenu.

private JMenu getTemplatesMenu() {
    if (examplesMenu == null) {
        examplesMenu = new JMenu("Examples");
        examplesMenu.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) {
                MainPanel.getInstance().defaultTool();
            }
        });
        final JMenu benchmarksMenu = new JMenu("Benchmarks");
        examplesMenu.add(benchmarksMenu);
        final JMenu bestestMenu = new JMenu("Building Energy Simulation Tests");
        benchmarksMenu.add(bestestMenu);
        addModel(bestestMenu, "BESTEST Case 600", "benchmarks/bestest600.ng3");
        addModel(bestestMenu, "BESTEST Case 610", "benchmarks/bestest610.ng3");
        addModel(bestestMenu, "BESTEST Case 620", "benchmarks/bestest620.ng3");
        addModel(bestestMenu, "BESTEST Case 630", "benchmarks/bestest630.ng3");
        final JMenu simpleMenu = new JMenu("Simple Buildings");
        examplesMenu.add(simpleMenu);
        addModel(simpleMenu, "Apartment 1", "templates/apartment-template-1.ng3");
        addModel(simpleMenu, "Apartment 2", "templates/apartment-template-2.ng3");
        addModel(simpleMenu, "Box Gabled Roof", "templates/box-gabled-template.ng3");
        addModel(simpleMenu, "Bungalow", "templates/bungalow-template.ng3");
        addModel(simpleMenu, "Butterfly Roof", "templates/butterfly-template.ng3");
        addModel(simpleMenu, "Cape Cod", "templates/cape-cod-template.ng3");
        addModel(simpleMenu, "Colonial", "templates/colonial-template.ng3");
        addModel(simpleMenu, "Combination Roof", "templates/combination-roof-template.ng3");
        addModel(simpleMenu, "Cross Gabled Roof", "templates/cross-gabled-template.ng3");
        addModel(simpleMenu, "Cross Hipped Roof", "templates/cross-hipped-template.ng3");
        addModel(simpleMenu, "Dutch Colonial", "templates/gambrel-template.ng3");
        addModel(simpleMenu, "Flat Roof", "templates/flat-roof-template.ng3");
        addModel(simpleMenu, "Gable & Valley Roof", "templates/gable-valley-template.ng3");
        addModel(simpleMenu, "Gablet Roof", "templates/gablet-template.ng3");
        addModel(simpleMenu, "Hip Roof", "templates/hip-roof-template.ng3");
        addModel(simpleMenu, "Hip & Valley Roof", "templates/hip-valley-template.ng3");
        addModel(simpleMenu, "M-Shaped Roof", "templates/m-shaped-template.ng3");
        addModel(simpleMenu, "Mansard", "templates/mansard-template.ng3");
        addModel(simpleMenu, "Saltbox 1", "templates/saltbox-template-1.ng3");
        addModel(simpleMenu, "Saltbox 2", "templates/saltbox-template-2.ng3");
        addModel(simpleMenu, "Shed Roof", "templates/shed-roof-template.ng3");
        final JMenu complexMenu = new JMenu("Complex Buildings");
        examplesMenu.add(complexMenu);
        addModel(complexMenu, "Cape Cod with Front Porch", "templates/example-cape-cod-front-porch.ng3");
        addModel(complexMenu, "Cape Cod with Garage", "templates/example-cape-cod-attached-garage.ng3");
        addModel(complexMenu, "Cape Cod with Shed and Gable Dormers", "templates/example-cape-cod-shed-gable-dormers.ng3");
        addModel(complexMenu, "Colonial with Fence", "templates/example-colonial-fence.ng3");
        addModel(complexMenu, "Colonial with Front Porch", "templates/example-colonial-front-porch.ng3");
        addModel(complexMenu, "L-Shaped Colonial", "templates/example-colonial-l-shaped.ng3");
        addModel(complexMenu, "Dutch Colonial with Front Porch", "templates/example-dutch-colonial.ng3");
        addModel(complexMenu, "Federal", "templates/example-federal.ng3");
        addModel(complexMenu, "Victorian", "templates/example-victorian.ng3");
        addModel(complexMenu, "Shingle", "templates/example-shingle.ng3");
        addModel(complexMenu, "Sunroom", "templates/example-sunroom.ng3");
        addModel(complexMenu, "Barn House", "templates/example-barn-house.ng3");
        addModel(complexMenu, "Santa Fe Style House", "templates/example-santa-fe.ng3");
        final JMenu pvSolarMenu = new JMenu("Photovoltaic Systems");
        addModel(pvSolarMenu, "Solar Canopy: Wavy Top", "templates/example-solar-canopy-wavy-top.ng3");
        addModel(pvSolarMenu, "Solar Canopy: Curvy Top", "templates/example-solar-canopy-curvy-top.ng3");
        addModel(pvSolarMenu, "Solar Canopy: Bus Stop", "templates/example-solar-canopy-bus-stop.ng3");
        addModel(pvSolarMenu, "Solar Canopy: Parking Garage 1", "templates/example-solar-canopy-parking-garage-1.ng3");
        addModel(pvSolarMenu, "Solar Canopy: Parking Garage 2", "templates/example-solar-canopy-parking-garage-2.ng3");
        addModel(pvSolarMenu, "Solar Canopy: Overhang", "templates/example-solar-canopy-overhang.ng3");
        addModel(pvSolarMenu, "Solar Facades: Example 1", "templates/example-solar-facade1.ng3");
        addModel(pvSolarMenu, "Solar Facades: Example 2", "templates/example-solar-facade2.ng3");
        examplesMenu.add(pvSolarMenu);
        final JMenu cspSolarMenu = new JMenu("Concentrated Solar Power Systems");
        cspSolarMenu.setEnabled(false);
        examplesMenu.add(cspSolarMenu);
        final JMenu miscMenu = new JMenu("Miscellaneous");
        examplesMenu.add(miscMenu);
        addModel(miscMenu, "Temple", "templates/temple-template.ng3");
        addModel(miscMenu, "Tibetan Temple", "templates/tibetan-temple-template.ng3");
        addModel(miscMenu, "Church 1", "templates/church-template-1.ng3");
        addModel(miscMenu, "Church 2", "templates/church-template-2.ng3");
        addModel(miscMenu, "Church 3", "templates/cathedral-template.ng3");
        addModel(miscMenu, "Mexican Church", "templates/mexican-church-template.ng3");
        addModel(miscMenu, "Chinese Tower", "templates/chinese-tower-template.ng3");
        addModel(miscMenu, "Dome", "templates/dome-template.ng3");
        addModel(miscMenu, "Egyptian Pyramid", "templates/egyptian-pyramid-template.ng3");
        addModel(miscMenu, "Mayan Pyramid", "templates/mayan-pyramid-template.ng3");
        addModel(miscMenu, "Stadium", "templates/stadium-template.ng3");
    }
    return examplesMenu;
}
Also used : MenuListener(javax.swing.event.MenuListener) JMenu(javax.swing.JMenu) MenuEvent(javax.swing.event.MenuEvent)

Aggregations

MenuEvent (javax.swing.event.MenuEvent)42 MenuListener (javax.swing.event.MenuListener)39 JMenu (javax.swing.JMenu)38 ActionEvent (java.awt.event.ActionEvent)23 JMenuItem (javax.swing.JMenuItem)23 ActionListener (java.awt.event.ActionListener)22 ItemEvent (java.awt.event.ItemEvent)18 ItemListener (java.awt.event.ItemListener)18 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)14 ButtonGroup (javax.swing.ButtonGroup)13 JMenuBar (javax.swing.JMenuBar)10 JPanel (javax.swing.JPanel)10 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)10 BorderLayout (java.awt.BorderLayout)9 HousePart (org.concord.energy3d.model.HousePart)9 Foundation (org.concord.energy3d.model.Foundation)8 JDialog (javax.swing.JDialog)7 JTextField (javax.swing.JTextField)6 BoxLayout (javax.swing.BoxLayout)5 JRadioButton (javax.swing.JRadioButton)5