Search in sources :

Example 1 with ChangeBuildingTextureCommand

use of org.concord.energy3d.undo.ChangeBuildingTextureCommand in project energy3d by concord-consortium.

the class PopupMenuForDoor method getPopupMenu.

static JPopupMenu getPopupMenu() {
    if (popupMenuForDoor == null) {
        final JMenuItem miSize = new JMenuItem("Size...");
        miSize.addActionListener(new ActionListener() {

            // remember the scope selection as the next action will likely be applied to the same scope
            private int selectedScopeIndex = 0;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Door)) {
                    return;
                }
                final Door door = (Door) selectedPart;
                final HousePart container = door.getContainer();
                final Foundation foundation = door.getTopContainer();
                final String partInfo = door.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
                final JPanel gui = new JPanel(new BorderLayout());
                final JPanel inputPanel = new JPanel(new GridLayout(2, 2, 5, 5));
                gui.add(inputPanel, BorderLayout.CENTER);
                inputPanel.add(new JLabel("Width (m): "));
                final JTextField widthField = new JTextField(threeDecimalsFormat.format(door.getDoorWidth()));
                inputPanel.add(widthField);
                inputPanel.add(new JLabel("Height (m): "));
                final JTextField heightField = new JTextField(threeDecimalsFormat.format(door.getDoorHeight()));
                inputPanel.add(heightField);
                inputPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                final JPanel scopePanel = new JPanel();
                scopePanel.setLayout(new BoxLayout(scopePanel, BoxLayout.Y_AXIS));
                scopePanel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                final JRadioButton rb1 = new JRadioButton("Only this Door", true);
                final JRadioButton rb2 = new JRadioButton("All Doors on this Wall");
                final JRadioButton rb3 = new JRadioButton("All Doors of this Building");
                scopePanel.add(rb1);
                scopePanel.add(rb2);
                scopePanel.add(rb3);
                final ButtonGroup bg = new ButtonGroup();
                bg.add(rb1);
                bg.add(rb2);
                bg.add(rb3);
                switch(selectedScopeIndex) {
                    case 0:
                        rb1.setSelected(true);
                        break;
                    case 1:
                        rb2.setSelected(true);
                        break;
                    case 2:
                        rb3.setSelected(true);
                        break;
                }
                gui.add(scopePanel, BorderLayout.NORTH);
                final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { "Set Size for " + partInfo, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Door Size");
                while (true) {
                    dialog.setVisible(true);
                    final Object choice = optionPane.getValue();
                    if (choice == options[1] || choice == null) {
                        break;
                    } else {
                        boolean ok = true;
                        double w = 0, h = 0;
                        try {
                            w = Double.parseDouble(widthField.getText());
                            h = Double.parseDouble(heightField.getText());
                        } catch (final NumberFormatException x) {
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), "Invalid input!", "Error", JOptionPane.ERROR_MESSAGE);
                            ok = false;
                        }
                        if (ok) {
                            double wmax = 10;
                            if (container instanceof Wall) {
                                wmax = ((Wall) container).getWallWidth() * 0.99;
                            }
                            double hmax = 10;
                            if (container instanceof Wall) {
                                hmax = ((Wall) container).getWallHeight() * 0.99;
                            }
                            if (w < 0.1 || w > wmax) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "Width must be between 0.1 and " + (int) wmax + " m.", "Range Error", JOptionPane.ERROR_MESSAGE);
                            } else if (h < 0.1 || h > hmax) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "Height must be between 0.1 and " + (int) hmax + " m.", "Range Error", JOptionPane.ERROR_MESSAGE);
                            } else {
                                boolean changed = Math.abs(w - door.getDoorWidth()) > 0.000001 || Math.abs(h - door.getDoorHeight()) > 0.000001;
                                if (rb1.isSelected()) {
                                    if (changed) {
                                        final SetPartSizeCommand c = new SetPartSizeCommand(door);
                                        door.setDoorWidth(w);
                                        door.setDoorHeight(h);
                                        door.draw();
                                        door.getContainer().draw();
                                        SceneManager.getInstance().refresh();
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 0;
                                } else if (rb2.isSelected()) {
                                    if (!changed) {
                                        if (door.getContainer() instanceof Wall) {
                                            final Wall wall = (Wall) door.getContainer();
                                            for (final Door x : wall.getDoors()) {
                                                if (Math.abs(w - x.getDoorWidth()) > 0.000001 || Math.abs(h - x.getDoorHeight()) > 0.000001) {
                                                    changed = true;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    if (changed) {
                                        if (door.getContainer() instanceof Wall) {
                                            final Wall wall = (Wall) door.getContainer();
                                            final ChangeDoorSizeOnWallCommand c = new ChangeDoorSizeOnWallCommand(wall);
                                            wall.setDoorSize(w, h);
                                            SceneManager.getInstance().getUndoManager().addEdit(c);
                                        }
                                    }
                                    selectedScopeIndex = 1;
                                } else if (rb3.isSelected()) {
                                    if (!changed) {
                                        for (final Door x : foundation.getDoors()) {
                                            if (Math.abs(w - x.getDoorWidth()) > 0.000001 || Math.abs(h - x.getDoorHeight()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final SetSizeForDoorsOnFoundationCommand c = new SetSizeForDoorsOnFoundationCommand(foundation);
                                        foundation.setSizeForDoors(w, h);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 2;
                                }
                                if (changed) {
                                    updateAfterEdit();
                                }
                                if (choice == options[0]) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        });
        final JMenu textureMenu = new JMenu("Texture");
        final ButtonGroup textureGroup = new ButtonGroup();
        final JRadioButtonMenuItem rbmiTextureNone = new JRadioButtonMenuItem("No Texture");
        rbmiTextureNone.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    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);
                }
            }
        });
        textureGroup.add(rbmiTextureNone);
        textureMenu.add(rbmiTextureNone);
        final JRadioButtonMenuItem rbmiTextureOutline = new JRadioButtonMenuItem("Outline Texture");
        rbmiTextureOutline.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    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);
                }
            }
        });
        textureGroup.add(rbmiTextureOutline);
        textureMenu.add(rbmiTextureOutline);
        textureMenu.addSeparator();
        final JRadioButtonMenuItem rbmiTexture01 = MainFrame.getInstance().createWallTextureMenuItem(Door.TEXTURE_01, "icons/door_01.png");
        textureGroup.add(rbmiTexture01);
        textureMenu.add(rbmiTexture01);
        textureMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuSelected(final MenuEvent e) {
                if (Scene.getInstance().getTextureMode() == TextureMode.None) {
                    Util.selectSilently(rbmiTextureNone, true);
                    return;
                }
                if (Scene.getInstance().getTextureMode() == TextureMode.Simple) {
                    Util.selectSilently(rbmiTextureOutline, true);
                    return;
                }
                switch(Scene.getInstance().getWallTextureType()) {
                    case Door.TEXTURE_01:
                        Util.selectSilently(rbmiTexture01, true);
                        break;
                }
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }
        });
        popupMenuForDoor = createPopupMenu(false, false, null);
        popupMenuForDoor.addSeparator();
        popupMenuForDoor.add(miSize);
        popupMenuForDoor.add(colorAction);
        popupMenuForDoor.add(textureMenu);
        popupMenuForDoor.add(createInsulationMenuItem(true));
        popupMenuForDoor.add(createVolumetricHeatCapacityMenuItem());
        popupMenuForDoor.addSeparator();
        JMenuItem mi = new JMenuItem("Daily Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Door) {
                    new EnergyDailyAnalysis().show("Daily Energy for Door");
                }
            }
        });
        popupMenuForDoor.add(mi);
        mi = new JMenuItem("Annual Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Door) {
                    new EnergyAnnualAnalysis().show("Annual Energy for Door");
                }
            }
        });
        popupMenuForDoor.add(mi);
    }
    return popupMenuForDoor;
}
Also used : JPanel(javax.swing.JPanel) EnergyAnnualAnalysis(org.concord.energy3d.simulation.EnergyAnnualAnalysis) ItemEvent(java.awt.event.ItemEvent) JRadioButton(javax.swing.JRadioButton) Wall(org.concord.energy3d.model.Wall) ActionEvent(java.awt.event.ActionEvent) SetPartSizeCommand(org.concord.energy3d.undo.SetPartSizeCommand) MenuListener(javax.swing.event.MenuListener) BoxLayout(javax.swing.BoxLayout) JTextField(javax.swing.JTextField) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) ChangeDoorSizeOnWallCommand(org.concord.energy3d.undo.ChangeDoorSizeOnWallCommand) Foundation(org.concord.energy3d.model.Foundation) JMenuItem(javax.swing.JMenuItem) HousePart(org.concord.energy3d.model.HousePart) MenuEvent(javax.swing.event.MenuEvent) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) SetSizeForDoorsOnFoundationCommand(org.concord.energy3d.undo.SetSizeForDoorsOnFoundationCommand) JOptionPane(javax.swing.JOptionPane) Door(org.concord.energy3d.model.Door) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) EnergyDailyAnalysis(org.concord.energy3d.simulation.EnergyDailyAnalysis) ItemListener(java.awt.event.ItemListener) ChangeBuildingTextureCommand(org.concord.energy3d.undo.ChangeBuildingTextureCommand) JDialog(javax.swing.JDialog) JMenu(javax.swing.JMenu)

Example 2 with ChangeBuildingTextureCommand

use of org.concord.energy3d.undo.ChangeBuildingTextureCommand 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 3 with ChangeBuildingTextureCommand

use of org.concord.energy3d.undo.ChangeBuildingTextureCommand in project energy3d by concord-consortium.

the class PopupMenuForWall method getPopupMenuForWall.

static JPopupMenu getPopupMenuForWall() {
    if (popupMenuForWall == null) {
        final JMenuItem miPaste = new JMenuItem("Paste");
        miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miPaste.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        Scene.getInstance().pasteToPickedLocationOnWall();
                        Scene.getInstance().setEdited(true);
                        return null;
                    }
                });
            }
        });
        final JMenuItem miClear = new JMenuItem("Clear");
        miClear.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        Scene.getInstance().removeAllChildren(SceneManager.getInstance().getSelectedPart());
                        EventQueue.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                MainPanel.getInstance().getEnergyButton().setSelected(false);
                                Scene.getInstance().setEdited(true);
                            }
                        });
                        return null;
                    }
                });
            }
        });
        final JMenuItem miDeleteAllConnectedWalls = new JMenuItem("Delete All Connected Walls");
        miDeleteAllConnectedWalls.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Wall) {
                    Scene.getInstance().deleteAllConnectedWalls((Wall) selectedPart);
                }
            }
        });
        final JMenuItem miThickness = new JMenuItem("Thickness...");
        miThickness.addActionListener(new ActionListener() {

            // remember the scope selection as the next action will likely be applied to the same scope
            private int selectedScopeIndex = 0;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Wall)) {
                    return;
                }
                final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
                final Wall w = (Wall) selectedPart;
                final String title = "<html>Thickness of " + partInfo + "</html>";
                final String footnote = "<html><hr><font size=2>Thickness of wall is in meters.<hr></html>";
                final JPanel gui = new JPanel(new BorderLayout());
                final JPanel panel = new JPanel();
                gui.add(panel, BorderLayout.CENTER);
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                final JRadioButton rb2 = new JRadioButton("All Walls on This Foundation");
                final JRadioButton rb3 = new JRadioButton("All Walls");
                panel.add(rb1);
                panel.add(rb2);
                panel.add(rb3);
                final ButtonGroup bg = new ButtonGroup();
                bg.add(rb1);
                bg.add(rb2);
                bg.add(rb3);
                switch(selectedScopeIndex) {
                    case 0:
                        rb1.setSelected(true);
                        break;
                    case 1:
                        rb2.setSelected(true);
                        break;
                    case 2:
                        rb3.setSelected(true);
                        break;
                }
                final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(w.getThickness() * Scene.getInstance().getAnnotationScale()));
                gui.add(inputField, BorderLayout.SOUTH);
                final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Thickness");
                while (true) {
                    inputField.selectAll();
                    inputField.requestFocusInWindow();
                    dialog.setVisible(true);
                    final Object choice = optionPane.getValue();
                    if (choice == options[1] || choice == null) {
                        break;
                    } else {
                        double val = 0;
                        boolean ok = true;
                        try {
                            val = Double.parseDouble(inputField.getText());
                        } catch (final NumberFormatException exception) {
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                            ok = false;
                        }
                        if (ok) {
                            if (val < 0.1 || val > 10) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "The thickness of a wall must be between 0.1 and 10 meters.", "Range Error", JOptionPane.ERROR_MESSAGE);
                            } else {
                                val /= Scene.getInstance().getAnnotationScale();
                                Wall.setDefaultThickess(val);
                                boolean changed = Math.abs(val - w.getThickness()) > 0.000001;
                                if (rb1.isSelected()) {
                                    if (changed) {
                                        final ChangeWallThicknessCommand c = new ChangeWallThicknessCommand(w);
                                        w.setThickness(val);
                                        w.draw();
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 0;
                                } else if (rb2.isSelected()) {
                                    final Foundation foundation = w.getTopContainer();
                                    if (!changed) {
                                        for (final Wall x : foundation.getWalls()) {
                                            if (Math.abs(val - x.getThickness()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeFoundationWallThicknessCommand c = new ChangeFoundationWallThicknessCommand(foundation);
                                        foundation.setThicknessOfWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 1;
                                } else if (rb3.isSelected()) {
                                    if (!changed) {
                                        for (final Wall x : Scene.getInstance().getAllWalls()) {
                                            if (Math.abs(val - x.getThickness()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeThicknessForAllWallsCommand c = new ChangeThicknessForAllWallsCommand(w);
                                        Scene.getInstance().setThicknessForAllWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 2;
                                }
                                if (changed) {
                                    updateAfterEdit();
                                }
                                if (choice == options[0]) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        });
        final JMenuItem miHeight = new JMenuItem("Height...");
        miHeight.addActionListener(new ActionListener() {

            // remember the scope selection as the next action will likely be applied to the same scope
            private int selectedScopeIndex = 0;

            private boolean changed;

            private double val;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Wall)) {
                    return;
                }
                final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
                final Wall w = (Wall) selectedPart;
                final String title = "<html>Height of " + partInfo + "</html>";
                final String footnote = "<html><hr><font size=2>Height of wall is in meters.<hr></html>";
                final JPanel gui = new JPanel(new BorderLayout());
                final JPanel panel = new JPanel();
                gui.add(panel, BorderLayout.CENTER);
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
                final JRadioButton rb3 = new JRadioButton("All Walls on This Foundation");
                final JRadioButton rb4 = new JRadioButton("All Walls");
                panel.add(rb1);
                panel.add(rb2);
                panel.add(rb3);
                panel.add(rb4);
                final ButtonGroup bg = new ButtonGroup();
                bg.add(rb1);
                bg.add(rb2);
                bg.add(rb3);
                bg.add(rb4);
                switch(selectedScopeIndex) {
                    case 0:
                        rb1.setSelected(true);
                        break;
                    case 1:
                        rb2.setSelected(true);
                        break;
                    case 2:
                        rb3.setSelected(true);
                        break;
                    case 3:
                        rb4.setSelected(true);
                        break;
                }
                final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(w.getHeight() * Scene.getInstance().getAnnotationScale()));
                gui.add(inputField, BorderLayout.SOUTH);
                final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Height");
                while (true) {
                    inputField.selectAll();
                    inputField.requestFocusInWindow();
                    dialog.setVisible(true);
                    final Object choice = optionPane.getValue();
                    if (choice == options[1] || choice == null) {
                        break;
                    } else {
                        boolean ok = true;
                        try {
                            val = Double.parseDouble(inputField.getText());
                        } catch (final NumberFormatException exception) {
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                            ok = false;
                        }
                        if (ok) {
                            if (val < 1 || val > 1000) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "The height of a wall must be between 1 and 1000 meters.", "Range Error", JOptionPane.ERROR_MESSAGE);
                            } else {
                                val /= Scene.getInstance().getAnnotationScale();
                                changed = Math.abs(val - w.getHeight()) > 0.000001;
                                if (rb1.isSelected()) {
                                    if (changed) {
                                        final ChangeWallHeightCommand c = new ChangeWallHeightCommand(w);
                                        w.setHeight(val, true);
                                        Scene.getInstance().redrawAllWallsNow();
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                        final Foundation foundation = w.getTopContainer();
                                        if (foundation.hasSolarReceiver()) {
                                            foundation.drawSolarReceiver();
                                            for (final HousePart x : Scene.getInstance().getParts()) {
                                                if (x instanceof FresnelReflector) {
                                                    final FresnelReflector reflector = (FresnelReflector) x;
                                                    if (foundation == reflector.getReceiver() && reflector.isSunBeamVisible()) {
                                                        reflector.drawSunBeam();
                                                    }
                                                } else if (x instanceof Mirror) {
                                                    final Mirror heliostat = (Mirror) x;
                                                    if (foundation == heliostat.getReceiver() && heliostat.isSunBeamVisible()) {
                                                        heliostat.drawSunBeam();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    selectedScopeIndex = 0;
                                } else if (rb2.isSelected()) {
                                    if (!changed) {
                                        w.visitNeighbors(new WallVisitor() {

                                            @Override
                                            public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                                                if (Math.abs(val - currentWall.getHeight()) > 0.000001) {
                                                    changed = true;
                                                }
                                            }
                                        });
                                    }
                                    if (changed) {
                                        final ChangeHeightForConnectedWallsCommand c = new ChangeHeightForConnectedWallsCommand(w);
                                        Scene.getInstance().setHeightOfConnectedWalls(w, val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 1;
                                } else if (rb3.isSelected()) {
                                    final Foundation foundation = w.getTopContainer();
                                    if (!changed) {
                                        for (final Wall x : foundation.getWalls()) {
                                            if (Math.abs(val - x.getHeight()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeFoundationWallHeightCommand c = new ChangeFoundationWallHeightCommand(foundation);
                                        foundation.setHeightOfWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 2;
                                } else if (rb4.isSelected()) {
                                    if (!changed) {
                                        for (final Wall x : Scene.getInstance().getAllWalls()) {
                                            if (Math.abs(val - x.getHeight()) > 0.000001) {
                                                changed = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (changed) {
                                        final ChangeHeightForAllWallsCommand c = new ChangeHeightForAllWallsCommand(w);
                                        Scene.getInstance().setHeightForAllWalls(val);
                                        SceneManager.getInstance().getUndoManager().addEdit(c);
                                    }
                                    selectedScopeIndex = 3;
                                }
                                if (changed) {
                                    updateAfterEdit();
                                }
                                if (choice == options[0]) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        });
        final JCheckBoxMenuItem miOutline = new JCheckBoxMenuItem("Outline...", true);
        miOutline.addActionListener(new ActionListener() {

            // remember the scope selection as the next action will likely be applied to the same scope
            private int selectedScopeIndex = 0;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Wall)) {
                    return;
                }
                final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
                final Wall w = (Wall) selectedPart;
                final String title = "<html>Outline of " + partInfo + "</html>";
                final String footnote = "<html>Hiding outline may create a continuous effect of a polygon<br>formed by many walls.</html>";
                final JPanel gui = new JPanel(new BorderLayout());
                final JPanel panel = new JPanel();
                gui.add(panel, BorderLayout.CENTER);
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
                final JRadioButton rb3 = new JRadioButton("All Walls on This Foundation");
                final JRadioButton rb4 = new JRadioButton("All Walls");
                panel.add(rb1);
                panel.add(rb2);
                panel.add(rb3);
                panel.add(rb4);
                final ButtonGroup bg = new ButtonGroup();
                bg.add(rb1);
                bg.add(rb2);
                bg.add(rb3);
                bg.add(rb4);
                switch(selectedScopeIndex) {
                    case 0:
                        rb1.setSelected(true);
                        break;
                    case 1:
                        rb2.setSelected(true);
                        break;
                    case 2:
                        rb3.setSelected(true);
                        break;
                    case 3:
                        rb4.setSelected(true);
                        break;
                }
                final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Outline");
                while (true) {
                    dialog.setVisible(true);
                    final Object choice = optionPane.getValue();
                    if (choice == options[1] || choice == null) {
                        break;
                    } else {
                        if (rb1.isSelected()) {
                            // final ChangeWallHeightCommand c = new ChangeWallHeightCommand(w);
                            w.showOutline(miOutline.isSelected());
                            w.draw();
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 0;
                        } else if (rb2.isSelected()) {
                            // final ChangeHeightForConnectedWallsCommand c = new ChangeHeightForConnectedWallsCommand(w);
                            Scene.getInstance().showOutlineOfConnectedWalls(w, miOutline.isSelected());
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 1;
                        } else if (rb3.isSelected()) {
                            final Foundation foundation = w.getTopContainer();
                            // final ChangeFoundationWallHeightCommand c = new ChangeFoundationWallHeightCommand(foundation);
                            foundation.showOutlineOfWalls(miOutline.isSelected());
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 2;
                        } else if (rb4.isSelected()) {
                            // final ChangeHeightForAllWallsCommand c = new ChangeHeightForAllWallsCommand(w);
                            Scene.getInstance().showOutlineForAllWalls(miOutline.isSelected());
                            // SceneManager.getInstance().getUndoManager().addEdit(c);
                            selectedScopeIndex = 3;
                        }
                        updateAfterEdit();
                        if (choice == options[0]) {
                            break;
                        }
                    }
                }
            }
        });
        popupMenuForWall = createPopupMenu(false, false, new Runnable() {

            @Override
            public void run() {
                final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
                miPaste.setEnabled(copyBuffer instanceof Window || copyBuffer instanceof SolarPanel || copyBuffer instanceof Rack);
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Wall) {
                    final Wall w = (Wall) selectedPart;
                    Util.selectSilently(miOutline, w.outlineShown());
                }
            }
        });
        popupMenuForWall.add(miPaste);
        popupMenuForWall.add(miDeleteAllConnectedWalls);
        popupMenuForWall.add(miClear);
        popupMenuForWall.addSeparator();
        popupMenuForWall.add(colorAction);
        popupMenuForWall.add(miOutline);
        popupMenuForWall.add(miThickness);
        popupMenuForWall.add(miHeight);
        popupMenuForWall.add(createInsulationMenuItem(false));
        popupMenuForWall.add(createVolumetricHeatCapacityMenuItem());
        popupMenuForWall.addSeparator();
        final JMenu textureMenu = new JMenu("Texture");
        popupMenuForWall.add(textureMenu);
        final ButtonGroup textureGroup = new ButtonGroup();
        final JRadioButtonMenuItem rbmiTextureNone = new JRadioButtonMenuItem("No Texture");
        rbmiTextureNone.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    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);
                }
            }
        });
        textureGroup.add(rbmiTextureNone);
        textureMenu.add(rbmiTextureNone);
        final JRadioButtonMenuItem rbmiTextureOutline = new JRadioButtonMenuItem("Outline Texture");
        rbmiTextureOutline.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    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);
                }
            }
        });
        textureGroup.add(rbmiTextureOutline);
        textureMenu.add(rbmiTextureOutline);
        textureMenu.addSeparator();
        final JRadioButtonMenuItem rbmiTexture01 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_01, "icons/wall_01.png");
        final JRadioButtonMenuItem rbmiTexture02 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_02, "icons/wall_02.png");
        final JRadioButtonMenuItem rbmiTexture03 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_03, "icons/wall_03.png");
        final JRadioButtonMenuItem rbmiTexture04 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_04, "icons/wall_04.png");
        final JRadioButtonMenuItem rbmiTexture05 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_05, "icons/wall_05.png");
        final JRadioButtonMenuItem rbmiTexture06 = MainFrame.getInstance().createWallTextureMenuItem(Wall.TEXTURE_06, "icons/wall_06.png");
        textureGroup.add(rbmiTexture01);
        textureGroup.add(rbmiTexture02);
        textureGroup.add(rbmiTexture03);
        textureGroup.add(rbmiTexture04);
        textureGroup.add(rbmiTexture05);
        textureGroup.add(rbmiTexture06);
        textureMenu.add(rbmiTexture01);
        textureMenu.add(rbmiTexture02);
        textureMenu.add(rbmiTexture03);
        textureMenu.add(rbmiTexture04);
        textureMenu.add(rbmiTexture05);
        textureMenu.add(rbmiTexture06);
        textureMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuSelected(final MenuEvent e) {
                if (Scene.getInstance().getTextureMode() == TextureMode.None) {
                    Util.selectSilently(rbmiTextureNone, true);
                    return;
                }
                if (Scene.getInstance().getTextureMode() == TextureMode.Simple) {
                    Util.selectSilently(rbmiTextureOutline, true);
                    return;
                }
                switch(Scene.getInstance().getWallTextureType()) {
                    case Wall.TEXTURE_01:
                        Util.selectSilently(rbmiTexture01, true);
                        break;
                    case Wall.TEXTURE_02:
                        Util.selectSilently(rbmiTexture02, true);
                        break;
                    case Wall.TEXTURE_03:
                        Util.selectSilently(rbmiTexture03, true);
                        break;
                    case Wall.TEXTURE_04:
                        Util.selectSilently(rbmiTexture04, true);
                        break;
                    case Wall.TEXTURE_05:
                        Util.selectSilently(rbmiTexture05, true);
                        break;
                    case Wall.TEXTURE_06:
                        Util.selectSilently(rbmiTexture06, true);
                        break;
                }
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }
        });
        final JMenu typeMenu = new JMenu("Type");
        popupMenuForWall.add(typeMenu);
        popupMenuForWall.addSeparator();
        final ButtonGroup typeGroup = new ButtonGroup();
        final JRadioButtonMenuItem rbmiSolidWall = new JRadioButtonMenuItem("Solid Wall");
        rbmiSolidWall.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.SOLID_WALL);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiSolidWall);
        typeGroup.add(rbmiSolidWall);
        final JRadioButtonMenuItem rbmiEmpty = new JRadioButtonMenuItem("Empty");
        rbmiEmpty.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.EMPTY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiEmpty);
        typeGroup.add(rbmiEmpty);
        final JRadioButtonMenuItem rbmiEdges = new JRadioButtonMenuItem("Vertical Edges");
        rbmiEdges.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.VERTICAL_EDGES_ONLY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiEdges);
        typeGroup.add(rbmiEdges);
        final JRadioButtonMenuItem rbmiColumns = new JRadioButtonMenuItem("Columns");
        rbmiColumns.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.COLUMNS_ONLY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiColumns);
        typeGroup.add(rbmiColumns);
        final JRadioButtonMenuItem rbmiRails = new JRadioButtonMenuItem("Rails");
        rbmiRails.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.RAILS_ONLY);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiRails);
        typeGroup.add(rbmiRails);
        final JRadioButtonMenuItem rbmiColumnsAndRailings = new JRadioButtonMenuItem("Columns & Railings");
        rbmiColumnsAndRailings.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.COLUMNS_RAILS);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiColumnsAndRailings);
        typeGroup.add(rbmiColumnsAndRailings);
        final JRadioButtonMenuItem rbmiFence = new JRadioButtonMenuItem("Fence");
        rbmiFence.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.FENCE);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiFence);
        typeGroup.add(rbmiFence);
        final JRadioButtonMenuItem rbmiSteelFrame = new JRadioButtonMenuItem("Steel Frame");
        rbmiSteelFrame.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Wall) {
                        final Wall wall = (Wall) selectedPart;
                        final ChangeWallTypeCommand c = new ChangeWallTypeCommand(wall);
                        wall.setType(Wall.STEEL_FRAME);
                        wall.draw();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiSteelFrame);
        typeGroup.add(rbmiSteelFrame);
        typeMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuSelected(final MenuEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Wall) {
                    final Wall wall = (Wall) selectedPart;
                    switch(wall.getType()) {
                        case Wall.SOLID_WALL:
                            Util.selectSilently(rbmiSolidWall, true);
                            break;
                        case Wall.EMPTY:
                            Util.selectSilently(rbmiEmpty, true);
                            break;
                        case Wall.VERTICAL_EDGES_ONLY:
                            Util.selectSilently(rbmiEdges, true);
                            break;
                        case Wall.COLUMNS_ONLY:
                            Util.selectSilently(rbmiColumns, true);
                            break;
                        case Wall.RAILS_ONLY:
                            Util.selectSilently(rbmiRails, true);
                            break;
                        case Wall.COLUMNS_RAILS:
                            Util.selectSilently(rbmiColumnsAndRailings, true);
                            break;
                        case Wall.STEEL_FRAME:
                            Util.selectSilently(rbmiSteelFrame, true);
                            break;
                    }
                }
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                typeMenu.setEnabled(true);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                typeMenu.setEnabled(true);
            }
        });
        JMenuItem mi = new JMenuItem("Daily Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Wall) {
                    new EnergyDailyAnalysis().show("Daily Energy for Wall");
                }
            }
        });
        popupMenuForWall.add(mi);
        mi = new JMenuItem("Annual Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Wall) {
                    new EnergyAnnualAnalysis().show("Annual Energy for Wall");
                }
            }
        });
        popupMenuForWall.add(mi);
    }
    return popupMenuForWall;
}
Also used : JPanel(javax.swing.JPanel) EnergyAnnualAnalysis(org.concord.energy3d.simulation.EnergyAnnualAnalysis) ChangeWallHeightCommand(org.concord.energy3d.undo.ChangeWallHeightCommand) ItemEvent(java.awt.event.ItemEvent) Wall(org.concord.energy3d.model.Wall) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) MenuListener(javax.swing.event.MenuListener) BoxLayout(javax.swing.BoxLayout) JTextField(javax.swing.JTextField) Snap(org.concord.energy3d.model.Snap) Callable(java.util.concurrent.Callable) ChangeHeightForConnectedWallsCommand(org.concord.energy3d.undo.ChangeHeightForConnectedWallsCommand) ChangeFoundationWallThicknessCommand(org.concord.energy3d.undo.ChangeFoundationWallThicknessCommand) WallVisitor(org.concord.energy3d.util.WallVisitor) Rack(org.concord.energy3d.model.Rack) BorderLayout(java.awt.BorderLayout) Foundation(org.concord.energy3d.model.Foundation) JMenuItem(javax.swing.JMenuItem) HousePart(org.concord.energy3d.model.HousePart) MenuEvent(javax.swing.event.MenuEvent) Window(org.concord.energy3d.model.Window) FresnelReflector(org.concord.energy3d.model.FresnelReflector) ChangeThicknessForAllWallsCommand(org.concord.energy3d.undo.ChangeThicknessForAllWallsCommand) ChangeWallThicknessCommand(org.concord.energy3d.undo.ChangeWallThicknessCommand) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ChangeHeightForAllWallsCommand(org.concord.energy3d.undo.ChangeHeightForAllWallsCommand) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) ChangeWallTypeCommand(org.concord.energy3d.undo.ChangeWallTypeCommand) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ChangeFoundationWallHeightCommand(org.concord.energy3d.undo.ChangeFoundationWallHeightCommand) SolarPanel(org.concord.energy3d.model.SolarPanel) EnergyDailyAnalysis(org.concord.energy3d.simulation.EnergyDailyAnalysis) ItemListener(java.awt.event.ItemListener) ChangeBuildingTextureCommand(org.concord.energy3d.undo.ChangeBuildingTextureCommand) Mirror(org.concord.energy3d.model.Mirror) JDialog(javax.swing.JDialog) JMenu(javax.swing.JMenu)

Example 4 with ChangeBuildingTextureCommand

use of org.concord.energy3d.undo.ChangeBuildingTextureCommand in project energy3d by concord-consortium.

the class PopupMenuForRoof method getPopupMenu.

static JPopupMenu getPopupMenu(final MouseEvent e) {
    if (e.isShiftDown()) {
        SceneManager.getTaskManager().update(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                Scene.getInstance().pasteToPickedLocationOnRoof();
                Scene.getInstance().setEdited(true);
                return null;
            }
        });
        return null;
    }
    if (popupMenuForRoof == null) {
        final JMenuItem miPaste = new JMenuItem("Paste");
        miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miPaste.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        Scene.getInstance().pasteToPickedLocationOnRoof();
                        Scene.getInstance().setEdited(true);
                        return null;
                    }
                });
            }
        });
        final JMenuItem miClear = new JMenuItem("Clear");
        miClear.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        Scene.getInstance().removeAllChildren(SceneManager.getInstance().getSelectedPart());
                        Scene.getInstance().setEdited(true);
                        return null;
                    }
                });
            }
        });
        final JMenuItem miOverhang = new JMenuItem("Overhang Length...");
        miOverhang.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (!(selectedPart instanceof Roof)) {
                    return;
                }
                final Roof roof = (Roof) selectedPart;
                while (true) {
                    SceneManager.getInstance().refresh(1);
                    final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), "Overhang Length (m)", roof.getOverhangLength() * Scene.getInstance().getAnnotationScale());
                    if (newValue == null) {
                        break;
                    } else {
                        try {
                            double val = Double.parseDouble(newValue);
                            final double min = Roof.OVERHANG_MIN * Scene.getInstance().getAnnotationScale() * 10;
                            if (val < min && val >= 0) {
                                val = min;
                            }
                            if (val < 0 || val > 10) {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), "Overhang value must be between " + min + " and 10.", "Error", JOptionPane.ERROR_MESSAGE);
                            } else {
                                if (Math.abs(val - roof.getOverhangLength() * Scene.getInstance().getAnnotationScale()) > 0.000001) {
                                    final ChangeRoofOverhangCommand c = new ChangeRoofOverhangCommand(roof);
                                    roof.setOverhangLength(val / Scene.getInstance().getAnnotationScale());
                                    roof.draw();
                                    final Foundation f = roof.getTopContainer();
                                    f.drawChildren();
                                    SceneManager.getInstance().refresh();
                                    updateAfterEdit();
                                    SceneManager.getInstance().getUndoManager().addEdit(c);
                                }
                                break;
                            }
                        } catch (final NumberFormatException exception) {
                            exception.printStackTrace();
                            JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            }
        });
        final JMenu typeMenu = new JMenu("Type");
        final ButtonGroup typeGroup = new ButtonGroup();
        final JRadioButtonMenuItem rbmiSolid = new JRadioButtonMenuItem("Solid");
        rbmiSolid.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Roof) {
                        final Roof roof = (Roof) selectedPart;
                        final ChangeRoofTypeCommand c = new ChangeRoofTypeCommand(roof);
                        roof.setType(Roof.SOLID);
                        roof.draw();
                        SceneManager.getInstance().refresh();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiSolid);
        typeGroup.add(rbmiSolid);
        final JRadioButtonMenuItem rbmiTransparent = new JRadioButtonMenuItem("Transparent");
        rbmiTransparent.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                    if (selectedPart instanceof Roof) {
                        final Roof roof = (Roof) selectedPart;
                        final ChangeRoofTypeCommand c = new ChangeRoofTypeCommand(roof);
                        roof.setType(Roof.TRANSPARENT);
                        roof.draw();
                        SceneManager.getInstance().refresh();
                        Scene.getInstance().setEdited(true);
                        SceneManager.getInstance().getUndoManager().addEdit(c);
                    }
                }
            }
        });
        typeMenu.add(rbmiTransparent);
        typeGroup.add(rbmiTransparent);
        typeMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuSelected(final MenuEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Roof) {
                    final Roof roof = (Roof) selectedPart;
                    switch(roof.getType()) {
                        case Roof.SOLID:
                            Util.selectSilently(rbmiSolid, true);
                            break;
                        case Roof.TRANSPARENT:
                            Util.selectSilently(rbmiTransparent, true);
                            break;
                    }
                }
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                typeMenu.setEnabled(true);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                typeMenu.setEnabled(true);
            }
        });
        final JMenu textureMenu = new JMenu("Texture");
        final ButtonGroup textureGroup = new ButtonGroup();
        final JRadioButtonMenuItem rbmiTextureNone = new JRadioButtonMenuItem("No Texture");
        rbmiTextureNone.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    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);
                }
            }
        });
        textureGroup.add(rbmiTextureNone);
        textureMenu.add(rbmiTextureNone);
        final JRadioButtonMenuItem rbmiTextureOutline = new JRadioButtonMenuItem("Outline Texture");
        rbmiTextureOutline.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(final ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    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);
                }
            }
        });
        textureGroup.add(rbmiTextureOutline);
        textureMenu.add(rbmiTextureOutline);
        textureMenu.addSeparator();
        final JRadioButtonMenuItem rbmiTexture01 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_01, "icons/roof_01.png");
        final JRadioButtonMenuItem rbmiTexture02 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_02, "icons/roof_02.png");
        final JRadioButtonMenuItem rbmiTexture03 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_03, "icons/roof_03.png");
        final JRadioButtonMenuItem rbmiTexture04 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_04, "icons/roof_04.png");
        final JRadioButtonMenuItem rbmiTexture05 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_05, "icons/roof_05.png");
        final JRadioButtonMenuItem rbmiTexture06 = MainFrame.getInstance().createRoofTextureMenuItem(Roof.TEXTURE_06, "icons/roof_06.png");
        textureGroup.add(rbmiTexture01);
        textureGroup.add(rbmiTexture02);
        textureGroup.add(rbmiTexture03);
        textureGroup.add(rbmiTexture04);
        textureGroup.add(rbmiTexture05);
        textureGroup.add(rbmiTexture06);
        textureMenu.add(rbmiTexture01);
        textureMenu.add(rbmiTexture02);
        textureMenu.add(rbmiTexture03);
        textureMenu.add(rbmiTexture04);
        textureMenu.add(rbmiTexture05);
        textureMenu.add(rbmiTexture06);
        textureMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuSelected(final MenuEvent e) {
                if (Scene.getInstance().getTextureMode() == TextureMode.None) {
                    Util.selectSilently(rbmiTextureNone, true);
                    return;
                }
                if (Scene.getInstance().getTextureMode() == TextureMode.Simple) {
                    Util.selectSilently(rbmiTextureOutline, true);
                    return;
                }
                switch(Scene.getInstance().getRoofTextureType()) {
                    case Roof.TEXTURE_01:
                        Util.selectSilently(rbmiTexture01, true);
                        break;
                    case Roof.TEXTURE_02:
                        Util.selectSilently(rbmiTexture02, true);
                        break;
                    case Roof.TEXTURE_03:
                        Util.selectSilently(rbmiTexture03, true);
                        break;
                    case Roof.TEXTURE_04:
                        Util.selectSilently(rbmiTexture04, true);
                        break;
                    case Roof.TEXTURE_05:
                        Util.selectSilently(rbmiTexture05, true);
                        break;
                    case Roof.TEXTURE_06:
                        Util.selectSilently(rbmiTexture06, true);
                        break;
                }
            }

            @Override
            public void menuDeselected(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }

            @Override
            public void menuCanceled(final MenuEvent e) {
                textureMenu.setEnabled(true);
            }
        });
        popupMenuForRoof = createPopupMenu(false, false, new Runnable() {

            @Override
            public void run() {
                final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
                miPaste.setEnabled(copyBuffer instanceof SolarPanel || copyBuffer instanceof Window || copyBuffer instanceof Rack);
            }
        });
        popupMenuForRoof.add(miPaste);
        popupMenuForRoof.add(miClear);
        popupMenuForRoof.addSeparator();
        popupMenuForRoof.add(miOverhang);
        popupMenuForRoof.add(colorAction);
        popupMenuForRoof.add(createInsulationMenuItem(false));
        popupMenuForRoof.add(createVolumetricHeatCapacityMenuItem());
        popupMenuForRoof.addSeparator();
        popupMenuForRoof.add(typeMenu);
        popupMenuForRoof.add(textureMenu);
        popupMenuForRoof.addSeparator();
        JMenuItem mi = new JMenuItem("Daily Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Roof) {
                    new EnergyDailyAnalysis().show("Daily Energy for Roof");
                }
            }
        });
        popupMenuForRoof.add(mi);
        mi = new JMenuItem("Annual Energy Analysis...");
        mi.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                if (EnergyPanel.getInstance().adjustCellSize()) {
                    return;
                }
                if (SceneManager.getInstance().getSelectedPart() instanceof Roof) {
                    new EnergyAnnualAnalysis().show("Annual Energy for Roof");
                }
            }
        });
        popupMenuForRoof.add(mi);
    }
    return popupMenuForRoof;
}
Also used : EnergyAnnualAnalysis(org.concord.energy3d.simulation.EnergyAnnualAnalysis) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) MenuListener(javax.swing.event.MenuListener) Callable(java.util.concurrent.Callable) Rack(org.concord.energy3d.model.Rack) Roof(org.concord.energy3d.model.Roof) ChangeRoofTypeCommand(org.concord.energy3d.undo.ChangeRoofTypeCommand) Foundation(org.concord.energy3d.model.Foundation) JMenuItem(javax.swing.JMenuItem) HousePart(org.concord.energy3d.model.HousePart) ChangeRoofOverhangCommand(org.concord.energy3d.undo.ChangeRoofOverhangCommand) MenuEvent(javax.swing.event.MenuEvent) Window(org.concord.energy3d.model.Window) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) SolarPanel(org.concord.energy3d.model.SolarPanel) EnergyDailyAnalysis(org.concord.energy3d.simulation.EnergyDailyAnalysis) ItemListener(java.awt.event.ItemListener) ChangeBuildingTextureCommand(org.concord.energy3d.undo.ChangeBuildingTextureCommand) JMenu(javax.swing.JMenu)

Aggregations

ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 ItemEvent (java.awt.event.ItemEvent)4 ItemListener (java.awt.event.ItemListener)4 ButtonGroup (javax.swing.ButtonGroup)4 JMenu (javax.swing.JMenu)4 JMenuItem (javax.swing.JMenuItem)4 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)4 MenuEvent (javax.swing.event.MenuEvent)4 MenuListener (javax.swing.event.MenuListener)4 ChangeBuildingTextureCommand (org.concord.energy3d.undo.ChangeBuildingTextureCommand)4 Foundation (org.concord.energy3d.model.Foundation)3 HousePart (org.concord.energy3d.model.HousePart)3 EnergyAnnualAnalysis (org.concord.energy3d.simulation.EnergyAnnualAnalysis)3 EnergyDailyAnalysis (org.concord.energy3d.simulation.EnergyDailyAnalysis)3 BorderLayout (java.awt.BorderLayout)2 Callable (java.util.concurrent.Callable)2 BoxLayout (javax.swing.BoxLayout)2 JDialog (javax.swing.JDialog)2 JOptionPane (javax.swing.JOptionPane)2