use of javax.swing.event.MenuEvent in project artisynth_core by artisynth.
the class MeshThicken method addMenuBar.
public JMenuBar addMenuBar() {
JMenuBar menuBar = super.addMenuBar();
JMenu menu = new JMenu("Edit");
menu.addMenuListener(new MenuAdapter() {
public void menuSelected(MenuEvent m_evt) {
createEditMenu((JMenu) m_evt.getSource());
}
});
menuBar.add(menu);
return menuBar;
}
use of javax.swing.event.MenuEvent in project artisynth_core by artisynth.
the class MeshViewer method createMenuBar.
private void createMenuBar() {
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("File");
menu.addMenuListener(new MenuAdapter() {
public void menuSelected(MenuEvent m_evt) {
createFileMenu((JMenu) m_evt.getSource());
}
});
menuBar.add(menu);
menu = new JMenu("View");
menu.addMenuListener(new MenuAdapter() {
public void menuSelected(MenuEvent m_evt) {
createViewMenu((JMenu) m_evt.getSource());
}
});
menuBar.add(menu);
}
use of javax.swing.event.MenuEvent in project energy3d by concord-consortium.
the class PopupMenuForSky method getPopupMenu.
static JPopupMenu getPopupMenu() {
if (popupMenuForSky == null) {
final JMenuItem miInfo = new JMenuItem("Sky");
miInfo.setEnabled(false);
miInfo.setOpaque(true);
miInfo.setBackground(Config.isMac() ? Color.DARK_GRAY : Color.GRAY);
miInfo.setForeground(Color.WHITE);
final JCheckBoxMenuItem miHeliodon = new JCheckBoxMenuItem("Heliodon");
miHeliodon.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
MainPanel.getInstance().getHeliodonButton().doClick();
}
});
final JMenu weatherMenu = new JMenu("Weather");
JMenuItem mi = new JMenuItem("Monthly Sunshine Hours...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().checkCity()) {
new MonthlySunshineHours().showDialog();
}
}
});
weatherMenu.add(mi);
mi = new JMenuItem("Annual Environmental Temperature...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().checkCity()) {
new AnnualEnvironmentalTemperature().showDialog();
}
}
});
weatherMenu.add(mi);
mi = new JMenuItem("Daily Environmental Temperature...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().checkCity()) {
new DailyEnvironmentalTemperature().showDialog();
}
}
});
weatherMenu.add(mi);
final JMenu themeMenu = new JMenu("Theme");
final ButtonGroup themeButtonGroup = new ButtonGroup();
final JRadioButtonMenuItem miBlueSky = new JRadioButtonMenuItem("Blue Sky");
miBlueSky.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeThemeCommand c = new ChangeThemeCommand();
Scene.getInstance().setTheme(Scene.BLUE_SKY_THEME);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
themeButtonGroup.add(miBlueSky);
themeMenu.add(miBlueSky);
final JRadioButtonMenuItem miDesert = new JRadioButtonMenuItem("Desert");
miDesert.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeThemeCommand c = new ChangeThemeCommand();
Scene.getInstance().setTheme(Scene.DESERT_THEME);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
themeButtonGroup.add(miDesert);
themeMenu.add(miDesert);
final JRadioButtonMenuItem miGrassland = new JRadioButtonMenuItem("Grassland");
miGrassland.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeThemeCommand c = new ChangeThemeCommand();
Scene.getInstance().setTheme(Scene.GRASSLAND_THEME);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
themeButtonGroup.add(miGrassland);
themeMenu.add(miGrassland);
final JRadioButtonMenuItem miForest = new JRadioButtonMenuItem("Forest");
miForest.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final ChangeThemeCommand c = new ChangeThemeCommand();
Scene.getInstance().setTheme(Scene.FOREST_THEME);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
});
themeButtonGroup.add(miForest);
themeMenu.add(miForest);
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(miBlueSky, Scene.getInstance().getTheme() == Scene.BLUE_SKY_THEME);
Util.selectSilently(miDesert, Scene.getInstance().getTheme() == Scene.DESERT_THEME);
Util.selectSilently(miGrassland, Scene.getInstance().getTheme() == Scene.GRASSLAND_THEME);
Util.selectSilently(miForest, Scene.getInstance().getTheme() == Scene.FOREST_THEME);
}
});
final JMenuItem miDustLoss = new JMenuItem("Dust & Pollen...");
miDustLoss.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final JPanel gui = new JPanel(new BorderLayout());
final String title = "<html><b>Soiling loss factor:</b><br>Loss of productivity due to atmospheric dust and pollen<br>(a dimensionless parameter within [0, 1])</html>";
gui.add(new JLabel(title), BorderLayout.NORTH);
final JPanel inputPanel = new JPanel(new SpringLayout());
inputPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
gui.add(inputPanel, BorderLayout.CENTER);
final JTextField[] fields = new JTextField[12];
for (int i = 0; i < 12; i++) {
final JLabel l = new JLabel(AnnualGraph.THREE_LETTER_MONTH[i] + ": ", JLabel.LEFT);
inputPanel.add(l);
fields[i] = new JTextField(threeDecimalsFormat.format(Scene.getInstance().getAtmosphere().getDustLoss(i)), 5);
l.setLabelFor(fields[i]);
inputPanel.add(fields[i]);
}
SpringUtilities.makeCompactGrid(inputPanel, 12, 2, 6, 6, 6, 6);
while (true) {
if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Dust and pollen loss", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.CANCEL_OPTION) {
break;
}
boolean pass = true;
final double[] val = new double[12];
for (int i = 0; i < 12; i++) {
try {
val[i] = Double.parseDouble(fields[i].getText());
if (val[i] < 0 || val[i] > 1) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Dust and pollen loss value must be in 0-1.", "Range Error", JOptionPane.ERROR_MESSAGE);
pass = false;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), fields[i].getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
pass = false;
}
}
if (pass) {
boolean changed = false;
for (int i = 0; i < 12; i++) {
if (Math.abs(Scene.getInstance().getAtmosphere().getDustLoss(i) - val[i]) > 0.000001) {
changed = true;
break;
}
}
if (changed) {
final ChangeAtmosphericDustLossCommand c = new ChangeAtmosphericDustLossCommand();
for (int i = 0; i < 12; i++) {
Scene.getInstance().getAtmosphere().setDustLoss(val[i], i);
}
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
break;
}
}
}
});
popupMenuForSky = new JPopupMenu();
popupMenuForSky.setInvoker(MainPanel.getInstance().getCanvasPanel());
popupMenuForSky.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
Util.selectSilently(miHeliodon, MainPanel.getInstance().getHeliodonButton().isSelected());
}
@Override
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
}
@Override
public void popupMenuCanceled(final PopupMenuEvent e) {
}
});
popupMenuForSky.add(miInfo);
popupMenuForSky.add(miDustLoss);
popupMenuForSky.add(miHeliodon);
popupMenuForSky.addSeparator();
popupMenuForSky.add(weatherMenu);
popupMenuForSky.add(themeMenu);
}
return popupMenuForSky;
}
use of javax.swing.event.MenuEvent in project energy3d by concord-consortium.
the class PopupMenuForWindow method getPopupMenu.
static JPopupMenu getPopupMenu() {
if (popupMenuForWindow == null) {
final JMenu shutterMenu = new JMenu("Shutters");
popupMenuForWindow = createPopupMenu(true, true, new Runnable() {
@Override
public void run() {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
shutterMenu.setEnabled(selectedPart.getContainer() instanceof Wall);
}
}
});
final JMenu muntinMenu = new JMenu("Muntins");
final JCheckBoxMenuItem cbmiHorizontalBars = new JCheckBoxMenuItem("Horizontal Bars");
cbmiHorizontalBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setHorizontalBars(cbmiHorizontalBars.isSelected());
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
});
muntinMenu.add(cbmiHorizontalBars);
final JCheckBoxMenuItem cbmiVerticalBars = new JCheckBoxMenuItem("Vertical Bars");
cbmiVerticalBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setVerticalBars(cbmiVerticalBars.isSelected());
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
});
muntinMenu.add(cbmiVerticalBars);
muntinMenu.addSeparator();
final ButtonGroup muntinButtonGroup = new ButtonGroup();
final JRadioButtonMenuItem miMoreBars = new JRadioButtonMenuItem("More Bars");
miMoreBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setStyle(Window.MORE_MUNTIN_BARS);
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
}
});
muntinButtonGroup.add(miMoreBars);
muntinMenu.add(miMoreBars);
final JRadioButtonMenuItem miMediumBars = new JRadioButtonMenuItem("Medium Bars");
miMediumBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setStyle(Window.MEDIUM_MUNTIN_BARS);
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
}
});
muntinButtonGroup.add(miMediumBars);
muntinMenu.add(miMediumBars);
final JRadioButtonMenuItem miLessBars = new JRadioButtonMenuItem("Less Bars");
miLessBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setStyle(Window.LESS_MUNTIN_BARS);
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
}
});
muntinButtonGroup.add(miLessBars);
muntinMenu.add(miLessBars);
muntinMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window window = (Window) selectedPart;
switch(window.getStyle()) {
case Window.MORE_MUNTIN_BARS:
Util.selectSilently(miMoreBars, true);
break;
case Window.MEDIUM_MUNTIN_BARS:
Util.selectSilently(miMediumBars, true);
break;
case Window.LESS_MUNTIN_BARS:
Util.selectSilently(miLessBars, true);
break;
}
// NO_MUNTIN_BAR backward compatibility
Util.selectSilently(cbmiHorizontalBars, window.getStyle() != Window.NO_MUNTIN_BAR && window.getHorizontalBars());
Util.selectSilently(cbmiVerticalBars, window.getStyle() != Window.NO_MUNTIN_BAR && window.getVerticalBars());
}
}
@Override
public void menuDeselected(final MenuEvent e) {
muntinMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
muntinMenu.setEnabled(true);
}
});
final JCheckBoxMenuItem cbmiBothShutters = new JCheckBoxMenuItem("Both Shutters");
final JCheckBoxMenuItem cbmiLeftShutter = new JCheckBoxMenuItem("Left Shutter");
final JCheckBoxMenuItem cbmiRightShutter = new JCheckBoxMenuItem("Right Shutter");
cbmiLeftShutter.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
final ChangeWindowShuttersCommand c = new ChangeWindowShuttersCommand(w);
w.setLeftShutter(cbmiLeftShutter.isSelected());
w.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
shutterMenu.add(cbmiLeftShutter);
cbmiRightShutter.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
final ChangeWindowShuttersCommand c = new ChangeWindowShuttersCommand(w);
w.setRightShutter(cbmiRightShutter.isSelected());
w.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
shutterMenu.add(cbmiRightShutter);
cbmiBothShutters.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
final ChangeWindowShuttersCommand c = new ChangeWindowShuttersCommand(w);
w.setLeftShutter(cbmiBothShutters.isSelected());
w.setRightShutter(cbmiBothShutters.isSelected());
w.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
shutterMenu.add(cbmiBothShutters);
shutterMenu.addSeparator();
final JMenuItem miShutterColor = new JMenuItem("Color...");
miShutterColor.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 Window)) {
return;
}
final Window window = (Window) selectedPart;
final JColorChooser colorChooser = MainFrame.getInstance().getColorChooser();
final ReadOnlyColorRGBA color = window.getShutterColor();
if (color != null) {
colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
}
final ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final Color c = colorChooser.getColor();
final float[] newColor = c.getComponents(null);
final ColorRGBA color = new ColorRGBA(newColor[0], newColor[1], newColor[2], 1);
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (window.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows of this Building");
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 Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Shutter Color");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean changed = !color.equals(window.getShutterColor());
if (rb1.isSelected()) {
// apply to only this window
if (changed) {
final ChangeShutterColorCommand cmd = new ChangeShutterColorCommand(window);
window.setShutterColor(color);
window.draw();
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (!color.equals(x.getShutterColor())) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (!color.equals(x.getShutterColor())) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerShutterColorCommand cmd = new ChangeContainerShutterColorCommand(window.getContainer());
Scene.getInstance().setWindowColorInContainer(window.getContainer(), color, true);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 1;
} else {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (!color.equals(x.getShutterColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBuildingShutterColorCommand cmd = new ChangeBuildingShutterColorCommand(window);
Scene.getInstance().setShutterColorOfBuilding(window, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 2;
}
if (changed) {
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
if (choice == options[0]) {
break;
}
}
}
}
};
JColorChooser.createDialog(MainFrame.getInstance(), "Select Shutter Color", true, colorChooser, actionListener, null).setVisible(true);
}
});
shutterMenu.add(miShutterColor);
final JMenuItem miShutterLength = new JMenuItem("Relative Length...");
miShutterLength.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 Window)) {
return;
}
final Window window = (Window) selectedPart;
final String partInfo = window.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final String title = "<html>Relative Length of Shutter for " + partInfo + "</html>";
final String footnote = "<html><hr width=400></html>";
final JPanel gui = new JPanel(new BorderLayout());
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window Shutter", true);
final JRadioButton rb2 = new JRadioButton("All Window Shutters on this Wall");
final JRadioButton rb3 = new JRadioButton("All Window Shutters of this Building");
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;
}
gui.add(panel, BorderLayout.CENTER);
final JTextField inputField = new JTextField(window.getShutterLength() + "");
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(), "Shutter Length (Relative)");
while (true) {
dialog.setVisible(true);
inputField.selectAll();
inputField.requestFocusInWindow();
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean ok = true;
double val = 0;
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 || val > 1) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Relative shutter length must be within (0, 1).", "Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(val - window.getShutterLength()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeShutterLengthCommand c = new ChangeShutterLengthCommand(window);
window.setShutterLength(val);
window.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (Math.abs(val - x.getShutterLength()) > 0.000001) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (Math.abs(val - x.getShutterLength()) > 0.000001) {
changed = true;
break;
}
}
}
}
if (changed) {
Scene.getInstance().setShutterLengthInContainer(window.getContainer(), val);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (Math.abs(val - x.getShutterLength()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
Scene.getInstance().setShutterLengthOfBuilding(window, val);
}
selectedScopeIndex = 2;
}
if (changed) {
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
shutterMenu.add(miShutterLength);
shutterMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window window = (Window) selectedPart;
Util.selectSilently(cbmiLeftShutter, window.getLeftShutter());
Util.selectSilently(cbmiRightShutter, window.getRightShutter());
Util.selectSilently(cbmiBothShutters, window.getLeftShutter() && window.getRightShutter());
}
}
@Override
public void menuDeselected(final MenuEvent e) {
shutterMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
shutterMenu.setEnabled(true);
}
});
final JMenuItem miShgc = new JMenuItem("Solar Heat Gain Coefficient...");
miShgc.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 Window)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final Window window = (Window) selectedPart;
final String title = "<html>Solar Heat Gain Coefficient of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>Examples:<br><table><tr><td><font size=2>Single glass (clear)</td><td><font size=2>0.66</td></tr><tr><td><font size=2>Single glass (green tint)</td><td><font size=2>0.55</td></tr><tr><td><font size=2>Triple glass (air spaces)</td><td><font size=2>0.39</td></tr></table><hr></html>";
final JPanel gui = new JPanel(new BorderLayout());
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (selectedPart.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows of this Building");
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;
}
gui.add(panel, BorderLayout.CENTER);
final JTextField inputField = new JTextField(window.getSolarHeatGainCoefficient() + "");
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(), "Solar Heat Gain Coefficient (SHGC)");
while (true) {
dialog.setVisible(true);
inputField.selectAll();
inputField.requestFocusInWindow();
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean ok = true;
double val = 0;
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 || val > 1) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Solar heat gain coefficient must be between 0 and 1.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(val - window.getSolarHeatGainCoefficient()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeWindowShgcCommand c = new ChangeWindowShgcCommand(window);
window.setSolarHeatGainCoefficient(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (Math.abs(val - x.getSolarHeatGainCoefficient()) > 0.000001) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (Math.abs(val - x.getSolarHeatGainCoefficient()) > 0.000001) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerWindowShgcCommand c = new ChangeContainerWindowShgcCommand(window.getContainer());
Scene.getInstance().setWindowShgcInContainer(window.getContainer(), val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (Math.abs(val - x.getSolarHeatGainCoefficient()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBuildingWindowShgcCommand c = new ChangeBuildingWindowShgcCommand(foundation);
Scene.getInstance().setWindowShgcOfBuilding(foundation, val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miTint = new JMenuItem("Tint...");
miTint.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 Window)) {
return;
}
final Window window = (Window) selectedPart;
final JColorChooser colorChooser = MainFrame.getInstance().getColorChooser();
final ReadOnlyColorRGBA color = window.getColor();
if (color != null) {
colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
}
final ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final Color c = colorChooser.getColor();
final float[] newColor = c.getComponents(null);
final ColorRGBA color = new ColorRGBA(newColor[0], newColor[1], newColor[2], (float) (1.0 - window.getSolarHeatGainCoefficient()));
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (window.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows of this Building");
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 Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Window Tint");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean changed = !Util.isRGBEqual(color, window.getColor());
if (rb1.isSelected()) {
// apply to only this window
if (changed) {
final ChangePartColorCommand cmd = new ChangePartColorCommand(window);
window.setColor(color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (!Util.isRGBEqual(color, x.getColor())) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (!Util.isRGBEqual(color, x.getColor())) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerWindowColorCommand cmd = new ChangeContainerWindowColorCommand(window.getContainer());
Scene.getInstance().setWindowColorInContainer(window.getContainer(), color, false);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (!Util.isRGBEqual(color, x.getColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBuildingColorCommand cmd = new ChangeBuildingColorCommand(window);
Scene.getInstance().setPartColorOfBuilding(window, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
};
JColorChooser.createDialog(MainFrame.getInstance(), "Select Tint", true, colorChooser, actionListener, null).setVisible(true);
}
});
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 Window)) {
return;
}
final Window window = (Window) selectedPart;
final HousePart container = window.getContainer();
final Foundation foundation = window.getTopContainer();
final String partInfo = window.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(window.getWindowWidth()));
inputPanel.add(widthField);
inputPanel.add(new JLabel("Height (m): "));
final JTextField heightField = new JTextField(threeDecimalsFormat.format(window.getWindowHeight()));
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 Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (window.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows 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(), "Window 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 - window.getWindowWidth()) > 0.000001 || Math.abs(h - window.getWindowHeight()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final SetPartSizeCommand c = new SetPartSizeCommand(window);
window.setWindowWidth(w);
window.setWindowHeight(h);
window.draw();
window.getContainer().draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (Math.abs(w - x.getWindowWidth()) > 0.000001 || Math.abs(h - x.getWindowHeight()) > 0.000001) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (Math.abs(w - x.getWindowWidth()) > 0.000001 || Math.abs(h - x.getWindowHeight()) > 0.000001) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerWindowSizeCommand c = new ChangeContainerWindowSizeCommand(window.getContainer());
Scene.getInstance().setWindowSizeInContainer(window.getContainer(), w, h);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (Math.abs(w - x.getWindowWidth()) > 0.000001 || Math.abs(h - x.getWindowHeight()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForWindowsOnFoundationCommand c = new SetSizeForWindowsOnFoundationCommand(foundation);
foundation.setSizeForWindows(w, h);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
popupMenuForWindow.addSeparator();
popupMenuForWindow.add(miSize);
popupMenuForWindow.add(miTint);
popupMenuForWindow.add(createInsulationMenuItem(true));
popupMenuForWindow.add(miShgc);
popupMenuForWindow.add(muntinMenu);
popupMenuForWindow.add(shutterMenu);
popupMenuForWindow.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 Window) {
new EnergyDailyAnalysis().show("Daily Energy for Window");
}
}
});
popupMenuForWindow.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 Window) {
new EnergyAnnualAnalysis().show("Annual Energy for Window");
}
}
});
popupMenuForWindow.add(mi);
}
return popupMenuForWindow;
}
use of javax.swing.event.MenuEvent 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;
}
Aggregations