use of org.concord.energy3d.undo.ChangeVolumetricHeatCapacityCommand 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;
}
Aggregations