use of org.concord.energy3d.model.Foundation in project energy3d by concord-consortium.
the class ChangeRoofOverhangCommand method redo.
@Override
public void redo() throws CannotRedoException {
super.redo();
roof.setOverhangLength(newValue);
roof.draw();
// can't just use Roof.draw() as we also need to draw the wall parts
final Foundation f = roof.getTopContainer();
f.drawChildren();
SceneManager.getInstance().refresh();
}
use of org.concord.energy3d.model.Foundation in project energy3d by concord-consortium.
the class ChangeRoofOverhangCommand method undo.
@Override
public void undo() throws CannotUndoException {
super.undo();
newValue = roof.getOverhangLength();
roof.setOverhangLength(oldValue);
roof.draw();
// can't just use Roof.draw() as we also need to draw the wall parts
final Foundation f = roof.getTopContainer();
f.drawChildren();
SceneManager.getInstance().refresh();
}
use of org.concord.energy3d.model.Foundation in project energy3d by concord-consortium.
the class MainFrame method getAnnualParabolicDishAnalysisMenuItem.
private JMenuItem getAnnualParabolicDishAnalysisMenuItem() {
if (annualParabolicDishAnalysisMenuItem == null) {
annualParabolicDishAnalysisMenuItem = new JMenuItem("Annual Yield Analysis of Parabolic Dishes...");
annualParabolicDishAnalysisMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().checkCity()) {
int n = Scene.getInstance().countParts(ParabolicDish.class);
if (n <= 0) {
JOptionPane.showMessageDialog(MainFrame.this, "There is no parabolic dish to analyze.", "No Parabolic Dish", JOptionPane.WARNING_MESSAGE);
return;
}
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
final ParabolicDishAnnualAnalysis a = new ParabolicDishAnnualAnalysis();
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart != null) {
Foundation foundation;
if (selectedPart instanceof Foundation) {
foundation = (Foundation) selectedPart;
} else {
foundation = selectedPart.getTopContainer();
}
if (foundation != null) {
n = foundation.countParts(ParabolicDish.class);
if (n <= 0) {
JOptionPane.showMessageDialog(MainFrame.this, "There is no parabolic dish on this foundation to analyze.", "No Parabolic Dish", JOptionPane.WARNING_MESSAGE);
return;
}
}
}
a.show();
}
}
});
}
return annualParabolicDishAnalysisMenuItem;
}
use of org.concord.energy3d.model.Foundation in project energy3d by concord-consortium.
the class MainFrame method getAnnualParabolicTroughAnalysisMenuItem.
private JMenuItem getAnnualParabolicTroughAnalysisMenuItem() {
if (annualParabolicTroughAnalysisMenuItem == null) {
annualParabolicTroughAnalysisMenuItem = new JMenuItem("Annual Yield Analysis of Parabolic Troughs...");
annualParabolicTroughAnalysisMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().checkCity()) {
int n = Scene.getInstance().countParts(ParabolicTrough.class);
if (n <= 0) {
JOptionPane.showMessageDialog(MainFrame.this, "There is no parabolic trough to analyze.", "No Parabolic Trough", JOptionPane.WARNING_MESSAGE);
return;
}
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
final ParabolicTroughAnnualAnalysis a = new ParabolicTroughAnnualAnalysis();
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart != null) {
Foundation foundation;
if (selectedPart instanceof Foundation) {
foundation = (Foundation) selectedPart;
} else {
foundation = selectedPart.getTopContainer();
}
if (foundation != null) {
n = foundation.countParts(ParabolicTrough.class);
if (n <= 0) {
JOptionPane.showMessageDialog(MainFrame.this, "There is no parabolic trough on this foundation to analyze.", "No Parabolic Trough", JOptionPane.WARNING_MESSAGE);
return;
}
}
}
a.show();
}
}
});
}
return annualParabolicTroughAnalysisMenuItem;
}
use of org.concord.energy3d.model.Foundation in project energy3d by concord-consortium.
the class MainFrame method showColorDialogForParts.
void showColorDialogForParts() {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
ActionListener colorActionListener;
if (selectedPart == null) {
final ReadOnlyColorRGBA color = Scene.getInstance().getLandColor();
if (color != null) {
colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
}
colorActionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final float[] newColor = colorChooser.getColor().getComponents(null);
final ColorRGBA rgba = new ColorRGBA(newColor[0], newColor[1], newColor[2], 0.5f);
if (!Scene.getInstance().getLandColor().equals(rgba)) {
final ChangeLandColorCommand cmd = new ChangeLandColorCommand();
Scene.getInstance().setLandColor(rgba);
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
}
};
} else {
if (Scene.getInstance().getTextureMode() != TextureMode.None) {
// when the user wants to set the color, automatically switch to no texture
if (JOptionPane.showConfirmDialog(this, "To set color for an individual part, we have to remove the texture. Is that OK?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
return;
}
Scene.getInstance().setTextureMode(TextureMode.None);
}
final ReadOnlyColorRGBA color = selectedPart.getColor();
if (color != null) {
colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
}
colorActionListener = new ActionListener() {
private boolean changed;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart == null) {
return;
}
final Color c = colorChooser.getColor();
final float[] newColor = c.getComponents(null);
final boolean restartPrintPreview = Scene.getInstance().getRoofColor().equals(ColorRGBA.WHITE) || c.equals(Color.WHITE);
final ColorRGBA color = new ColorRGBA(newColor[0], newColor[1], newColor[2], newColor[3]);
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
if (selectedPart instanceof Wall) {
final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
final JRadioButton rb3 = new JRadioButton("All Walls of this Building");
final JRadioButton rb4 = new JRadioButton("All Walls");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
panel.add(rb4);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
bg.add(rb4);
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(), "Wall Color");
while (true) {
changed = false;
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1]) {
break;
} else {
changed = !color.equals(selectedPart.getColor());
if (rb1.isSelected()) {
// apply to only this part
if (changed) {
final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
selectedPart.setColor(color);
selectedPart.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
} else if (rb2.isSelected()) {
final Wall w = (Wall) selectedPart;
if (!changed) {
w.visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall currentWall, final Snap prev, final Snap next) {
if (!color.equals(currentWall.getColor())) {
changed = true;
}
}
});
}
if (changed) {
final ChangeColorOfConnectedWallsCommand cmd = new ChangeColorOfConnectedWallsCommand(w);
Scene.getInstance().setColorOfConnectedWalls(w, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
} else if (rb3.isSelected()) {
if (!changed) {
for (final HousePart x : Scene.getInstance().getPartsOfSameTypeInBuilding(selectedPart)) {
if (!color.equals(x.getColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBuildingColorCommand cmd = new ChangeBuildingColorCommand(selectedPart);
Scene.getInstance().setPartColorOfBuilding(selectedPart, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
} else if (rb4.isSelected()) {
if (!changed) {
for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
if (!color.equals(x.getColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
}
// remember the color decision for the next wall to be added
Scene.getInstance().setWallColor(color);
if (choice == options[0]) {
break;
}
}
}
} else if (selectedPart instanceof Roof) {
final JRadioButton rb1 = new JRadioButton("Only this Roof", true);
final JRadioButton rb2 = new JRadioButton("All Roofs");
panel.add(rb1);
panel.add(rb2);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
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(), "Roof Color");
while (true) {
changed = false;
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1]) {
break;
} else {
changed = !color.equals(selectedPart.getColor());
if (rb1.isSelected()) {
// apply to only this part
if (changed) {
final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
selectedPart.setColor(color);
selectedPart.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
} else {
if (!changed) {
for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
if (!color.equals(x.getColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
}
// remember the color decision for the next roof to be added
Scene.getInstance().setRoofColor(color);
if (choice == options[0]) {
break;
}
}
}
} else if (selectedPart instanceof Foundation) {
final JRadioButton rb1 = new JRadioButton("Only this Foundation", true);
final JRadioButton rb2 = new JRadioButton("All Foundations");
panel.add(rb1);
panel.add(rb2);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
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(), "Foundation Color");
while (true) {
changed = false;
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1]) {
break;
} else {
changed = !color.equals(selectedPart.getColor());
if (rb1.isSelected()) {
// apply to only this part
if (changed) {
final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
selectedPart.setColor(color);
selectedPart.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
} else {
if (!changed) {
for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
if (!color.equals(x.getColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
}
// remember the color decision for the next foundation to be added
Scene.getInstance().setFoundationColor(color);
if (choice == options[0]) {
break;
}
}
}
} else {
changed = !color.equals(selectedPart.getColor());
if (changed) {
final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
selectedPart.setColor(color);
selectedPart.draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(cmd);
if (selectedPart instanceof Door) {
// remember the color decision for the next part
Scene.getInstance().setDoorColor(color);
} else if (selectedPart instanceof Floor) {
Scene.getInstance().setFloorColor(color);
}
}
}
Scene.getInstance().setTextureMode(Scene.getInstance().getTextureMode());
if (restartPrintPreview && PrintController.getInstance().isPrintPreview()) {
PrintController.getInstance().restartAnimation();
}
MainPanel.getInstance().getEnergyButton().setSelected(false);
Scene.getInstance().setEdited(changed);
}
};
}
JColorChooser.createDialog(this, "Select Color", true, colorChooser, colorActionListener, null).setVisible(true);
}
Aggregations