use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class PopupMenuFactory method createPopupMenu.
static JPopupMenu createPopupMenu(final boolean hasCopyMenu, final boolean pastable, final Runnable runWhenBecomingVisible) {
final JMenuItem miInfo = new JMenuItem();
miInfo.setEnabled(false);
miInfo.setOpaque(true);
miInfo.setBackground(Config.isMac() ? Color.DARK_GRAY : Color.GRAY);
miInfo.setForeground(Color.WHITE);
final JPopupMenu popupMenu = new JPopupMenu();
popupMenu.setInvoker(MainPanel.getInstance().getCanvasPanel());
popupMenu.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart == null) {
return;
}
String s = selectedPart.toString();
if (selectedPart instanceof SolarPanel) {
final SolarPanel sp = (SolarPanel) selectedPart;
miInfo.setText(s.substring(0, s.indexOf(')') + 1) + ": " + sp.getModelName() + " ($" + (int) ProjectCost.getCost(selectedPart) + ")");
} else if (selectedPart instanceof Rack) {
final SolarPanel sp = ((Rack) selectedPart).getSolarPanel();
miInfo.setText(s.substring(0, s.indexOf(')') + 1) + ": " + sp.getModelName() + " ($" + (int) ProjectCost.getCost(selectedPart) + ")");
} else if (selectedPart instanceof Mirror) {
s = s.replace("Mirror", "Heliostat");
miInfo.setText(s.substring(0, s.indexOf(')') + 1) + " ($" + (int) ProjectCost.getCost(selectedPart) + ")");
} else {
miInfo.setText(s.substring(0, s.indexOf(')') + 1) + " ($" + (int) ProjectCost.getCost(selectedPart) + ")");
}
if (runWhenBecomingVisible != null) {
runWhenBecomingVisible.run();
}
}
@Override
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
}
@Override
public void popupMenuCanceled(final PopupMenuEvent e) {
}
});
final JMenuItem miCut = new JMenuItem(pastable ? "Cut" : "Delete");
miCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
miCut.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart != null) {
Scene.getInstance().setCopyBuffer(selectedPart);
SceneManager.getInstance().deleteCurrentSelection();
}
}
});
popupMenu.add(miInfo);
// popupMenu.addSeparator();
popupMenu.add(miCut);
if (hasCopyMenu) {
final JMenuItem miCopy = new JMenuItem("Copy");
miCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
miCopy.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart != null) {
Scene.getInstance().setCopyBuffer(selectedPart.copy(false));
}
}
});
popupMenu.add(miCopy);
}
return popupMenu;
}
use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class PopupMenuFactory method createVolumetricHeatCapacityMenuItem.
static JMenuItem createVolumetricHeatCapacityMenuItem() {
final JMenuItem mi = new JMenuItem("Volumeric Heat Capacity...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Thermal)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final Thermal t = (Thermal) selectedPart;
final String title = "<html>Volumeric Heat Capacity of " + partInfo + " [kWh/(m<sup>3</sup>·°C)]<hr><font size=2>Examples:<br>0.03 (fiberglass), 0.18 (asphalt), 0.25(oak wood), 0.33 (concrete), 0.37 (brick), 0.58 (stone)</html>";
while (true) {
// final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, t.getVolumetricHeatCapacity());
final String newValue = (String) JOptionPane.showInputDialog(MainFrame.getInstance(), title, "Input: " + partInfo, JOptionPane.QUESTION_MESSAGE, null, null, t.getVolumetricHeatCapacity());
if (newValue == null) {
break;
} else {
try {
final double val = Double.parseDouble(newValue);
if (val <= 0) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Volumeric heat capacity must be positive.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
if (val != t.getVolumetricHeatCapacity()) {
final ChangeVolumetricHeatCapacityCommand c = new ChangeVolumetricHeatCapacityCommand(selectedPart);
t.setVolumetricHeatCapacity(val);
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
break;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
});
return mi;
}
use of org.concord.energy3d.model.HousePart 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;
}
use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class PopupMenuForFresnelReflector method getPopupMenu.
static JPopupMenu getPopupMenu() {
if (popupMenuForFresnelReflector == null) {
final JMenuItem miMesh = new JMenuItem("Mesh...");
miMesh.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 FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
final Foundation foundation = r.getTopContainer();
final String partInfo = r.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("Length direction: "));
final JTextField nLengthField = new JTextField("" + r.getNSectionLength());
inputPanel.add(nLengthField);
inputPanel.add(new JLabel("Width direction: "));
final JTextField nWidthField = new JTextField("" + r.getNSectionWidth());
inputPanel.add(nWidthField);
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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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 mesh for " + partInfo, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Fresnel Reflector Mesh");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
int nSectionLength = 0, nSectionWidth = 0;
boolean ok = true;
try {
nSectionLength = Integer.parseInt(nLengthField.getText());
nSectionWidth = Integer.parseInt(nWidthField.getText());
} catch (final NumberFormatException nfe) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Invalid input!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (nSectionLength < 4) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Sections in the direction of length must be at least 4.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else if (nSectionWidth < 4) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Sections in the direction of width must be at least 4.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else if (!Util.isPowerOfTwo(nSectionLength) || !Util.isPowerOfTwo(nSectionWidth)) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Numbers of mesh sections must be power of two.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
if (rb1.isSelected()) {
r.setNSectionLength(nSectionLength);
r.setNSectionWidth(nSectionWidth);
r.draw();
SceneManager.getInstance().refresh();
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
foundation.setSectionsForFresnelReflectors(nSectionLength, nSectionWidth);
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
Scene.getInstance().setSectionsForAllFresnelReflectors(nSectionLength, nSectionWidth);
selectedScopeIndex = 2;
}
updateAfterEdit();
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JCheckBoxMenuItem cbmiDisableEditPoints = new JCheckBoxMenuItem("Disable Edit Points");
cbmiDisableEditPoints.addItemListener(new ItemListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void itemStateChanged(final ItemEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof FresnelReflector)) {
return;
}
final boolean disabled = cbmiDisableEditPoints.isSelected();
final FresnelReflector r = (FresnelReflector) selectedPart;
final String partInfo = r.toString().substring(0, r.toString().indexOf(')') + 1);
final JPanel gui = new JPanel(new BorderLayout(0, 20));
final JPanel panel = new JPanel();
gui.add(panel, BorderLayout.SOUTH);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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 String title = "<html>" + (disabled ? "Disable" : "Enable") + " edit points for " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>Disable the edit points of a Fresnel reflector prevents it<br>from being unintentionally moved.<hr></html>";
final Object[] options = new Object[] { "OK", "Cancel" };
final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[0]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), (disabled ? "Disable" : "Enable") + " Edit Points");
dialog.setVisible(true);
if (optionPane.getValue() == options[0]) {
if (rb1.isSelected()) {
final LockEditPointsCommand c = new LockEditPointsCommand(r);
r.setLockEdit(disabled);
SceneManager.getInstance().getUndoManager().addEdit(c);
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
final Foundation foundation = r.getTopContainer();
final LockEditPointsOnFoundationCommand c = new LockEditPointsOnFoundationCommand(foundation, r.getClass());
foundation.setLockEditForClass(disabled, r.getClass());
SceneManager.getInstance().getUndoManager().addEdit(c);
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final LockEditPointsForClassCommand c = new LockEditPointsForClassCommand(r);
Scene.getInstance().setLockEditForClass(disabled, r.getClass());
SceneManager.getInstance().getUndoManager().addEdit(c);
selectedScopeIndex = 2;
}
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
});
final JCheckBoxMenuItem cbmiDrawBeam = new JCheckBoxMenuItem("Draw Sun Beam");
cbmiDrawBeam.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
final ShowSunBeamCommand c = new ShowSunBeamCommand(r);
r.setSunBeamVisible(cbmiDrawBeam.isSelected());
r.drawSunBeam();
r.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
Scene.getInstance().setEdited(true);
}
});
final JMenuItem miSetAbsorber = new JMenuItem("Set Absorber...");
miSetAbsorber.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 FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
final String partInfo = r.toString().substring(0, r.toString().indexOf(')') + 1);
final JPanel gui = new JPanel(new BorderLayout(0, 20));
final JPanel panel = new JPanel();
gui.add(panel, BorderLayout.SOUTH);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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 List<Foundation> foundations = Scene.getInstance().getAllFoundations();
final JComboBox<String> comboBox = new JComboBox<String>();
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
}
});
comboBox.addItem("None");
for (final Foundation x : foundations) {
if (!x.getChildren().isEmpty()) {
comboBox.addItem(x.getId() + "");
}
}
if (r.getReceiver() != null) {
comboBox.setSelectedItem(r.getReceiver().getId() + "");
}
gui.add(comboBox, BorderLayout.CENTER);
final String title = "<html>Select the ID of the absorber<br>foundation for " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>The sunlight reflected by this Fresnel reflector will<br>focus on the top of the target, where the absorber<br>tube is located.<hr></html>";
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(), "Absorber");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
Foundation absorber = null;
if (comboBox.getSelectedIndex() > 0) {
int id = -1;
boolean ok = true;
try {
id = Integer.parseInt((String) comboBox.getSelectedItem());
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), comboBox.getSelectedItem() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
final HousePart p = Scene.getInstance().getPart(id);
if (p instanceof Foundation) {
absorber = (Foundation) p;
} else {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "ID must be that of a foundation.", "ID Error", JOptionPane.ERROR_MESSAGE);
}
}
}
boolean changed = absorber != r.getReceiver();
if (rb1.isSelected()) {
if (changed) {
final Foundation oldTarget = r.getReceiver();
final ChangeFresnelReflectorAbsorberCommand c = new ChangeFresnelReflectorAbsorberCommand(r);
r.setReceiver(absorber);
r.draw();
if (oldTarget != null) {
oldTarget.drawSolarReceiver();
}
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
final Foundation foundation = r.getTopContainer();
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (x.getReceiver() != absorber) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeFoundationFresnelReflectorAbsorberCommand c = new ChangeFoundationFresnelReflectorAbsorberCommand(foundation);
foundation.setAbsorberForFresnelReflectors(absorber);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (x.getReceiver() != absorber) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeAbsorberForAllFresnelReflectorsCommand c = new ChangeAbsorberForAllFresnelReflectorsCommand();
Scene.getInstance().setAbsorberForAllFresnelReflectors(absorber);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
if (absorber != null) {
absorber.drawSolarReceiver();
}
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
});
final JMenuItem miLength = new JMenuItem("Length...");
miLength.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 FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
final Foundation foundation = r.getTopContainer();
final String partInfo = r.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final JPanel gui = new JPanel(new BorderLayout());
final JPanel inputPanel = new JPanel(new GridLayout(1, 2, 5, 5));
gui.add(inputPanel, BorderLayout.CENTER);
inputPanel.add(new JLabel("Length: "));
final JTextField lengthField = new JTextField(threeDecimalsFormat.format(r.getLength()));
inputPanel.add(lengthField);
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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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 length for " + partInfo, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Fresnel Reflector Length");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
double length = 0;
boolean ok = true;
try {
length = Double.parseDouble(lengthField.getText());
} catch (final NumberFormatException x) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Invalid input!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (length < 1 || length > 1000) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Length must be between 1 and 1000 m.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = length != r.getLength();
if (rb1.isSelected()) {
if (changed) {
final SetPartSizeCommand c = new SetPartSizeCommand(r);
r.setLength(length);
r.ensureFullModules(false);
r.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (x.getLength() != length) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForFresnelReflectorsOnFoundationCommand c = new SetSizeForFresnelReflectorsOnFoundationCommand(foundation);
foundation.setLengthForFresnelReflectors(length);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (x.getLength() != length) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForAllFresnelReflectorsCommand c = new SetSizeForAllFresnelReflectorsCommand();
Scene.getInstance().setLengthForAllFresnelReflectors(length);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miModuleWidth = new JMenuItem("Module Width...");
miModuleWidth.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 FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
final Foundation foundation = r.getTopContainer();
final String partInfo = r.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final JPanel gui = new JPanel(new BorderLayout());
final JPanel inputPanel = new JPanel(new GridLayout(1, 2, 5, 5));
gui.add(inputPanel, BorderLayout.CENTER);
inputPanel.add(new JLabel("Module Width: "));
final JTextField moduleWidthField = new JTextField(threeDecimalsFormat.format(r.getModuleWidth()));
inputPanel.add(moduleWidthField);
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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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 module width for " + partInfo, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Fresnel Reflector Module Width");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
double moduleWidth = 0;
boolean ok = true;
try {
moduleWidth = Double.parseDouble(moduleWidthField.getText());
} catch (final NumberFormatException x) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Invalid input!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (moduleWidth < 0.1 || moduleWidth > 20) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Module width must be between 0.1 and 20 m.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = moduleWidth != r.getModuleWidth();
if (rb1.isSelected()) {
if (changed) {
final SetPartSizeCommand c = new SetPartSizeCommand(r);
r.setModuleWidth(moduleWidth);
r.ensureFullModules(false);
r.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (x.getModuleWidth() != moduleWidth) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForFresnelReflectorsOnFoundationCommand c = new SetSizeForFresnelReflectorsOnFoundationCommand(foundation);
foundation.setModuleWidthForFresnelReflectors(moduleWidth);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (x.getModuleWidth() != moduleWidth) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForAllFresnelReflectorsCommand c = new SetSizeForAllFresnelReflectorsCommand();
Scene.getInstance().setModuleWidthForAllFresnelReflectors(moduleWidth);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miModuleLength = new JMenuItem("Module Length...");
miModuleLength.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 FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
final Foundation foundation = r.getTopContainer();
final String partInfo = r.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final JPanel gui = new JPanel(new BorderLayout());
final JPanel inputPanel = new JPanel(new GridLayout(1, 2, 5, 5));
gui.add(inputPanel, BorderLayout.CENTER);
inputPanel.add(new JLabel("Module Length: "));
final JTextField moduleLengthField = new JTextField(threeDecimalsFormat.format(r.getModuleLength()));
inputPanel.add(moduleLengthField);
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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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 module length for " + partInfo, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Fresnel Reflector Module Length");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
double moduleLength = 0;
boolean ok = true;
try {
moduleLength = Double.parseDouble(moduleLengthField.getText());
} catch (final NumberFormatException x) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Invalid input!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (moduleLength < 1 || moduleLength > 100) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Module length must be between 1 and 100 m.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = moduleLength != r.getModuleLength();
if (rb1.isSelected()) {
if (changed) {
final SetPartSizeCommand c = new SetPartSizeCommand(r);
r.setModuleLength(moduleLength);
r.ensureFullModules(false);
r.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (x.getModuleLength() != moduleLength) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForFresnelReflectorsOnFoundationCommand c = new SetSizeForFresnelReflectorsOnFoundationCommand(foundation);
foundation.setModuleLengthForFresnelReflectors(moduleLength);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (x.getModuleLength() != moduleLength) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForAllFresnelReflectorsCommand c = new SetSizeForAllFresnelReflectorsCommand();
Scene.getInstance().setModuleLengthForAllFresnelReflectors(moduleLength);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miBaseHeight = new JMenuItem("Base Height...");
miBaseHeight.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 FresnelReflector)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final FresnelReflector r = (FresnelReflector) selectedPart;
final Foundation foundation = r.getTopContainer();
final String title = "<html>Base Height (m) of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2></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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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(r.getBaseHeight() * 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(), "Fresnel Reflector Base Height");
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()) / Scene.getInstance().getAnnotationScale();
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
boolean changed = val != r.getBaseHeight();
if (rb1.isSelected()) {
if (changed) {
final ChangeBaseHeightCommand c = new ChangeBaseHeightCommand(r);
r.setBaseHeight(val);
r.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (x.getBaseHeight() != val) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeFoundationSolarCollectorBaseHeightCommand c = new ChangeFoundationSolarCollectorBaseHeightCommand(foundation, r.getClass());
foundation.setBaseHeightForFresnelReflectors(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (x.getBaseHeight() != val) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBaseHeightForAllSolarCollectorsCommand c = new ChangeBaseHeightForAllSolarCollectorsCommand(r.getClass());
Scene.getInstance().setBaseHeightForAllFresnelReflectors(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
});
final JMenuItem miAzimuth = new JMenuItem("Azimuth...");
miAzimuth.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 FresnelReflector)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final FresnelReflector fresnel = (FresnelReflector) selectedPart;
final Foundation foundation = fresnel.getTopContainer();
final String title = "<html>Azimuth Angle (°) of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>The azimuth angle is measured clockwise from the true north.<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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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;
}
double a = fresnel.getRelativeAzimuth() + foundation.getAzimuth();
if (a > 360) {
a -= 360;
}
final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(a));
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(), "Fresnel Reflector Azimuth");
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) {
a = val - foundation.getAzimuth();
if (a < 0) {
a += 360;
}
boolean changed = Math.abs(a - fresnel.getRelativeAzimuth()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeAzimuthCommand c = new ChangeAzimuthCommand(fresnel);
fresnel.setRelativeAzimuth(a);
fresnel.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (Math.abs(a - x.getRelativeAzimuth()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeFoundationFresnelReflectorAzimuthCommand c = new ChangeFoundationFresnelReflectorAzimuthCommand(foundation);
foundation.setAzimuthForParabolicFresnelReflectors(a);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final ParabolicTrough x : Scene.getInstance().getAllParabolicTroughs()) {
if (Math.abs(a - x.getRelativeAzimuth()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeAzimuthForAllFresnelReflectorsCommand c = new ChangeAzimuthForAllFresnelReflectorsCommand();
Scene.getInstance().setAzimuthForAllFresnelReflectors(a);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
});
final JMenu labelMenu = new JMenu("Label");
final JCheckBoxMenuItem miLabelNone = new JCheckBoxMenuItem("None", true);
miLabelNone.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (miLabelNone.isSelected()) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof FresnelReflector) {
final FresnelReflector r = (FresnelReflector) selectedPart;
final SetFresnelReflectorLabelCommand c = new SetFresnelReflectorLabelCommand(r);
r.clearLabels();
r.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
}
}
});
labelMenu.add(miLabelNone);
final JCheckBoxMenuItem miLabelCustom = new JCheckBoxMenuItem("Custom");
miLabelCustom.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof FresnelReflector) {
final FresnelReflector r = (FresnelReflector) selectedPart;
final SetFresnelReflectorLabelCommand c = new SetFresnelReflectorLabelCommand(r);
r.setLabelCustom(miLabelCustom.isSelected());
if (r.getLabelCustom()) {
r.setLabelCustomText(JOptionPane.showInputDialog(MainFrame.getInstance(), "Custom Text", r.getLabelCustomText()));
}
r.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
}
});
labelMenu.add(miLabelCustom);
final JCheckBoxMenuItem miLabelId = new JCheckBoxMenuItem("ID");
miLabelId.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof FresnelReflector) {
final FresnelReflector r = (FresnelReflector) selectedPart;
final SetFresnelReflectorLabelCommand c = new SetFresnelReflectorLabelCommand(r);
r.setLabelId(miLabelId.isSelected());
r.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
}
});
labelMenu.add(miLabelId);
final JCheckBoxMenuItem miLabelEnergyOutput = new JCheckBoxMenuItem("Energy Output");
miLabelEnergyOutput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof FresnelReflector) {
final FresnelReflector r = (FresnelReflector) selectedPart;
final SetFresnelReflectorLabelCommand c = new SetFresnelReflectorLabelCommand(r);
r.setLabelEnergyOutput(miLabelEnergyOutput.isSelected());
r.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
}
});
labelMenu.add(miLabelEnergyOutput);
popupMenuForFresnelReflector = createPopupMenu(true, true, new Runnable() {
@Override
public void run() {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
Util.selectSilently(cbmiDisableEditPoints, r.getLockEdit());
Util.selectSilently(cbmiDrawBeam, r.isSunBeamVisible());
Util.selectSilently(miLabelNone, !r.isLabelVisible());
Util.selectSilently(miLabelCustom, r.getLabelCustom());
Util.selectSilently(miLabelId, r.getLabelId());
Util.selectSilently(miLabelEnergyOutput, r.getLabelEnergyOutput());
}
});
final JMenuItem miReflectance = new JMenuItem("Reflectance...");
miReflectance.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 FresnelReflector)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final FresnelReflector r = (FresnelReflector) selectedPart;
final String title = "<html>Reflectance (%) of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>Reflectance can be affected by pollen and dust.<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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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(r.getReflectance() * 100));
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(), "Fresnel Reflector Reflectance");
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 < 50 || val > 99) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Fresnel reflector reflectance must be between 50% and 99%.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(val * 0.01 - r.getReflectance()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeSolarReflectorReflectanceCommand c = new ChangeSolarReflectorReflectanceCommand(r);
r.setReflectance(val * 0.01);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
final Foundation foundation = r.getTopContainer();
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (Math.abs(x.getReflectance() - val * 0.01) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeFoundationSolarReflectorReflectanceCommand c = new ChangeFoundationSolarReflectorReflectanceCommand(foundation, r.getClass());
foundation.setReflectanceForSolarReflectors(val * 0.01, r.getClass());
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (Math.abs(x.getReflectance() - val * 0.01) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeReflectanceForAllSolarReflectorsCommand c = new ChangeReflectanceForAllSolarReflectorsCommand(r.getClass());
Scene.getInstance().setReflectanceForAllSolarReflectors(val * 0.01, r.getClass());
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miApertureRatio = new JMenuItem("Aperture Ratio...");
miApertureRatio.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 FresnelReflector)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final FresnelReflector r = (FresnelReflector) selectedPart;
final String title = "<html>Aperture percentage of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>The percentage of the effective area for reflection<br>after deducting the area of gaps, frames, etc.<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 Fresnel Reflector", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflectors on this Foundation");
final JRadioButton rb3 = new JRadioButton("All Fresnel Reflectors");
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(r.getOpticalEfficiency() * 100));
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(), "Aperture Percentage of Fresnel Reflector Surface");
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 < 70 || val > 100) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Fresnel reflector aperature percentage must be between 70% and 100%.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(val * 0.01 - r.getOpticalEfficiency()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeSolarReflectorOpticalEfficiencyCommand c = new ChangeSolarReflectorOpticalEfficiencyCommand(r);
r.setOpticalEfficiency(val * 0.01);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
final Foundation foundation = r.getTopContainer();
if (!changed) {
for (final FresnelReflector x : foundation.getFresnelReflectors()) {
if (Math.abs(val * 0.01 - x.getOpticalEfficiency()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeFoundationSolarReflectorOpticalEfficiencyCommand c = new ChangeFoundationSolarReflectorOpticalEfficiencyCommand(foundation, r.getClass());
foundation.setOpticalEfficiencyForSolarReflectors(val * 0.01, r.getClass());
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (Math.abs(val * 0.01 - x.getOpticalEfficiency()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeOpticalEfficiencyForAllSolarReflectorsCommand c = new ChangeOpticalEfficiencyForAllSolarReflectorsCommand(r.getClass());
Scene.getInstance().setOpticalEfficiencyForAllSolarReflectors(val * 0.01, r.getClass());
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miConversionEfficiency = new JMenuItem("Absorber Conversion Efficiency...");
miConversionEfficiency.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 FresnelReflector)) {
return;
}
final FresnelReflector r = (FresnelReflector) selectedPart;
final Foundation absorber = r.getReceiver();
if (absorber == null) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "This reflector does not link to an absorber.", "No Absorber", JOptionPane.ERROR_MESSAGE);
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final String title = "<html>Light-electricity conversion efficiency (%) of " + partInfo + "'s absorber</html>";
final String footnote = "<html><hr><font size=2><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 Fresnel Reflector's Absorber", true);
final JRadioButton rb2 = new JRadioButton("All Fresnel Reflector Absorbers");
panel.add(rb1);
panel.add(rb2);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
}
final JTextField inputField = new JTextField(EnergyPanel.TWO_DECIMALS.format(absorber.getSolarReceiverEfficiency() * 100));
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(), "Receiver Conversion Efficiency");
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 < 5 || val > 50) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Light-electricity conversion efficiency must be between 5% and 50%.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(val * 0.01 - absorber.getSolarReceiverEfficiency()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeSolarReceiverEfficiencyCommand c = new ChangeSolarReceiverEfficiencyCommand(absorber);
absorber.setSolarReceiverEfficiency(val * 0.01);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
for (final FresnelReflector x : Scene.getInstance().getAllFresnelReflectors()) {
if (Math.abs(val * 0.01 - x.getReceiver().getSolarReceiverEfficiency()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeSolarReceiverEfficiencyForAllReflectorsCommand c = new ChangeSolarReceiverEfficiencyForAllReflectorsCommand(r.getClass());
Scene.getInstance().setSolarReceiverEfficiencyForAllSolarReflectors(val * 0.01, r.getClass());
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
popupMenuForFresnelReflector.addSeparator();
popupMenuForFresnelReflector.add(miSetAbsorber);
popupMenuForFresnelReflector.addSeparator();
popupMenuForFresnelReflector.add(cbmiDisableEditPoints);
popupMenuForFresnelReflector.add(cbmiDrawBeam);
popupMenuForFresnelReflector.add(labelMenu);
popupMenuForFresnelReflector.addSeparator();
popupMenuForFresnelReflector.add(miLength);
popupMenuForFresnelReflector.add(miModuleWidth);
popupMenuForFresnelReflector.add(miModuleLength);
popupMenuForFresnelReflector.add(miBaseHeight);
popupMenuForFresnelReflector.add(miAzimuth);
popupMenuForFresnelReflector.addSeparator();
popupMenuForFresnelReflector.add(miReflectance);
popupMenuForFresnelReflector.add(miApertureRatio);
popupMenuForFresnelReflector.add(miConversionEfficiency);
popupMenuForFresnelReflector.addSeparator();
popupMenuForFresnelReflector.add(miMesh);
popupMenuForFresnelReflector.addSeparator();
JMenuItem mi = new JMenuItem("Daily Yield Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof FresnelReflector) {
new FresnelReflectorDailyAnalysis().show();
}
}
});
popupMenuForFresnelReflector.add(mi);
mi = new JMenuItem("Annual Yield Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof FresnelReflector) {
new FresnelReflectorAnnualAnalysis().show();
}
}
});
popupMenuForFresnelReflector.add(mi);
}
return popupMenuForFresnelReflector;
}
use of org.concord.energy3d.model.HousePart in project energy3d by concord-consortium.
the class PopupMenuForLand method getPopupMenu.
static JPopupMenu getPopupMenu() {
if (popupMenuForLand == null) {
final JMenuItem miInfo = new JMenuItem("Land");
miInfo.setEnabled(false);
miInfo.setOpaque(true);
miInfo.setBackground(Config.isMac() ? Color.DARK_GRAY : Color.GRAY);
miInfo.setForeground(Color.WHITE);
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().pasteToPickedLocationOnLand();
return null;
}
});
}
});
final JMenuItem miRemoveAllTrees = new JMenuItem("Remove All Trees");
miRemoveAllTrees.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllTrees();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(true);
}
});
return null;
}
});
}
});
final JMenuItem miRemoveAllHumans = new JMenuItem("Remove All Humans");
miRemoveAllHumans.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllHumans();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(true);
}
});
return null;
}
});
}
});
final JMenuItem miRemoveAllBuildings = new JMenuItem("Remove All Foundations");
miRemoveAllBuildings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
SceneManager.getTaskManager().update(new Callable<Object>() {
@Override
public Object call() throws Exception {
Scene.getInstance().removeAllFoundations();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(true);
}
});
return null;
}
});
}
});
final JMenuItem miImportEnergy3D = new JMenuItem("Import...");
miImportEnergy3D.setToolTipText("Import the content in an existing Energy3D file into the clicked location on the land as the center");
miImportEnergy3D.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
MainFrame.getInstance().importFile();
}
});
final JMenuItem miImportCollada = new JMenuItem("Import Collada...");
miImportCollada.setToolTipText("Import the content in an existing Collada file into the clicked location on the land as the center");
miImportCollada.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
MainFrame.getInstance().importColladaFile();
}
});
final JMenu miImportPrefabMenu = new JMenu("Import a Prefab");
addPrefabMenuItem("Back Hip Roof Porch", "prefabs/back-hip-roof-porch.ng3", miImportPrefabMenu);
addPrefabMenuItem("Balcony", "prefabs/balcony1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Bell Tower", "prefabs/bell-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Box", "prefabs/box.ng3", miImportPrefabMenu);
addPrefabMenuItem("Chimney", "prefabs/chimney.ng3", miImportPrefabMenu);
addPrefabMenuItem("Connecting Porch", "prefabs/connecting-porch.ng3", miImportPrefabMenu);
addPrefabMenuItem("Cylinder Tower", "prefabs/cylinder-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Fence", "prefabs/fence1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Flat-Top Porch", "prefabs/flat-top-porch.ng3", miImportPrefabMenu);
addPrefabMenuItem("Fountain", "prefabs/fountain.ng3", miImportPrefabMenu);
addPrefabMenuItem("Front Door Overhang", "prefabs/front-door-overhang.ng3", miImportPrefabMenu);
addPrefabMenuItem("Gable Dormer", "prefabs/gable-dormer.ng3", miImportPrefabMenu);
addPrefabMenuItem("Hexagonal Gazebo", "prefabs/hexagonal-gazebo.ng3", miImportPrefabMenu);
addPrefabMenuItem("Hexagonal Tower", "prefabs/hexagonal-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Lighthouse", "prefabs/lighthouse.ng3", miImportPrefabMenu);
addPrefabMenuItem("Octagonal Tower", "prefabs/octagonal-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Round Tower", "prefabs/round-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Shed Dormer", "prefabs/shed-dormer.ng3", miImportPrefabMenu);
addPrefabMenuItem("Solarium", "prefabs/solarium1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Square Tower", "prefabs/square-tower.ng3", miImportPrefabMenu);
addPrefabMenuItem("Stair", "prefabs/stair1.ng3", miImportPrefabMenu);
addPrefabMenuItem("Tall Front Door Overhang", "prefabs/tall-front-door-overhang.ng3", miImportPrefabMenu);
addPrefabMenuItem("Temple Front", "prefabs/temple-front.ng3", miImportPrefabMenu);
addPrefabMenuItem("Waterfront Deck", "prefabs/waterfront-deck.ng3", miImportPrefabMenu);
final JMenuItem miAlbedo = new JMenuItem("Albedo...");
miAlbedo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final String title = "<html>Background Albedo (dimensionless [0, 1])<hr><font size=2>Examples:<br>0.17 (soil), 0.25 (grass), 0.40 (sand), 0.55 (concrete), snow (0.9)</html>";
while (true) {
final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, Scene.getInstance().getGround().getAlbedo());
if (newValue == null) {
break;
} else {
try {
final double val = Double.parseDouble(newValue);
if (val < 0 || val > 1) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Albedo value must be in 0-1.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
if (val != Scene.getInstance().getGround().getAlbedo()) {
final ChangeBackgroundAlbedoCommand c = new ChangeBackgroundAlbedoCommand();
Scene.getInstance().getGround().setAlbedo(val);
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
break;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
});
final JMenuItem miSnowReflection = new JMenuItem("Snow Reflection...");
miSnowReflection.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final JPanel gui = new JPanel(new BorderLayout());
final String title = "<html>Increase of indirect solar radiation due to snow reflection<br>(a dimensionless parameter within [0, 0.2])</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.TRAILING);
inputPanel.add(l);
fields[i] = new JTextField(threeDecimalsFormat.format(Scene.getInstance().getGround().getSnowReflectionFactor(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, "Snow reflection factor", 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] > 0.2) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Snow reflection factor must be in 0-0.2.", "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) {
final ChangeSnowReflectionFactorCommand c = new ChangeSnowReflectionFactorCommand();
for (int i = 0; i < 12; i++) {
Scene.getInstance().getGround().setSnowReflectionFactor(val[i], i);
}
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
break;
}
}
}
});
final JMenuItem miThermalDiffusivity = new JMenuItem("Ground Thermal Diffusivity...");
miThermalDiffusivity.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final String title = "<html>Ground Thermal Diffusivity (m<sup>2</sup>/s)<hr><font size=2>Examples:<br>0.039 (sand), 0.046 (clay), 0.05 (silt)</html>";
while (true) {
final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, Scene.getInstance().getGround().getThermalDiffusivity());
if (newValue == null) {
break;
} else {
try {
final double val = Double.parseDouble(newValue);
if (val <= 0) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Ground thermal diffusivity must be positive.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
if (val != Scene.getInstance().getGround().getThermalDiffusivity()) {
final ChangeGroundThermalDiffusivityCommand c = new ChangeGroundThermalDiffusivityCommand();
Scene.getInstance().getGround().setThermalDiffusivity(val);
updateAfterEdit();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
break;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}
});
final JMenuItem miClearImage = new JMenuItem("Clear Image");
final JMenuItem miRescaleImage = new JMenuItem("Rescale Image...");
final JCheckBoxMenuItem miShowImage = new JCheckBoxMenuItem("Show Image");
final JMenu groundImageMenu = new JMenu("Ground Image");
groundImageMenu.addMenuListener(new MenuListener() {
@Override
public void menuCanceled(final MenuEvent e) {
miShowImage.setEnabled(true);
miClearImage.setEnabled(true);
}
@Override
public void menuDeselected(final MenuEvent e) {
miShowImage.setEnabled(true);
miClearImage.setEnabled(true);
}
@Override
public void menuSelected(final MenuEvent e) {
final boolean hasGroundImage = Scene.getInstance().isGroundImageEnabled();
miShowImage.setEnabled(hasGroundImage);
miClearImage.setEnabled(hasGroundImage);
Util.selectSilently(miShowImage, SceneManager.getInstance().getGroundImageLand().isVisible());
}
});
final JMenuItem miUseEarthView = new JMenuItem("Use Image from Earth View...");
miUseEarthView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new MapDialog(MainFrame.getInstance()).setVisible(true);
}
});
groundImageMenu.add(miUseEarthView);
final JMenuItem miUseImageFile = new JMenuItem("Use Image from File...");
miUseImageFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final File file = FileChooser.getInstance().showDialog(".png", FileChooser.pngFilter, false);
if (file == null) {
return;
}
try {
Scene.getInstance().setGroundImage(ImageIO.read(file), 1);
Scene.getInstance().setGroundImageEarthView(false);
} catch (final Throwable t) {
t.printStackTrace();
JOptionPane.showMessageDialog(MainFrame.getInstance(), t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
Scene.getInstance().setEdited(true);
}
});
groundImageMenu.add(miUseImageFile);
groundImageMenu.addSeparator();
miRescaleImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final String title = "Scale the ground image";
while (true) {
final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, Scene.getInstance().getGroundImageScale());
if (newValue == null) {
break;
} else {
try {
final double val = Double.parseDouble(newValue);
if (val <= 0) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "The scaling factor must be positive.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
// final ChangeGroundThermalDiffusivityCommand c = new ChangeGroundThermalDiffusivityCommand();
Scene.getInstance().setGroundImageScale(val);
// SceneManager.getInstance().getUndoManager().addEdit(c);
break;
}
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Scene.getInstance().setEdited(true);
}
});
groundImageMenu.add(miRescaleImage);
miClearImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
Scene.getInstance().setGroundImage(null, 1);
Scene.getInstance().setEdited(true);
}
});
groundImageMenu.add(miClearImage);
miShowImage.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final boolean b = miShowImage.isSelected();
SceneManager.getInstance().getGroundImageLand().setVisible(b);
Scene.getInstance().setShowGroundImage(b);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
});
groundImageMenu.add(miShowImage);
popupMenuForLand = new JPopupMenu();
popupMenuForLand.setInvoker(MainPanel.getInstance().getCanvasPanel());
popupMenuForLand.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
miPaste.setEnabled(copyBuffer instanceof Tree || copyBuffer instanceof Human || copyBuffer instanceof Foundation);
}
@Override
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
}
@Override
public void popupMenuCanceled(final PopupMenuEvent e) {
}
});
popupMenuForLand.add(miInfo);
// popupMenuForLand.addSeparator();
popupMenuForLand.add(miPaste);
popupMenuForLand.add(miRemoveAllTrees);
popupMenuForLand.add(miRemoveAllHumans);
popupMenuForLand.add(miRemoveAllBuildings);
popupMenuForLand.addSeparator();
popupMenuForLand.add(miImportEnergy3D);
popupMenuForLand.add(miImportCollada);
popupMenuForLand.add(miImportPrefabMenu);
popupMenuForLand.addSeparator();
popupMenuForLand.add(groundImageMenu);
popupMenuForLand.add(colorAction);
popupMenuForLand.add(miAlbedo);
popupMenuForLand.add(miSnowReflection);
popupMenuForLand.add(miThermalDiffusivity);
}
return popupMenuForLand;
}
Aggregations