use of org.concord.energy3d.model.Snap in project energy3d by concord-consortium.
the class Scene method deleteAllConnectedWalls.
public void deleteAllConnectedWalls(final Wall w) {
final List<HousePart> copy = new ArrayList<HousePart>();
w.visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall currentWall, final Snap prev, final Snap next) {
copy.add(currentWall);
}
});
final RemoveMultiplePartsCommand c = new RemoveMultiplePartsCommand(copy);
for (final HousePart p : copy) {
remove(p, false);
}
SceneManager.getInstance().getUndoManager().addEdit(c);
edited = true;
SceneManager.getInstance().refresh();
}
use of org.concord.energy3d.model.Snap in project energy3d by concord-consortium.
the class Scene method setHeightOfConnectedWalls.
public void setHeightOfConnectedWalls(final Wall w, final double height) {
w.visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall w, final Snap prev, final Snap next) {
w.setHeight(height, true);
}
});
redrawAllWallsNow();
final Foundation foundation = w.getTopContainer();
if (foundation.hasSolarReceiver()) {
foundation.drawSolarReceiver();
for (final HousePart x : Scene.getInstance().getParts()) {
if (x instanceof FresnelReflector) {
final FresnelReflector reflector = (FresnelReflector) x;
if (foundation == reflector.getReceiver() && reflector.isSunBeamVisible()) {
reflector.drawSunBeam();
}
} else if (x instanceof Mirror) {
final Mirror heliostat = (Mirror) x;
if (foundation == heliostat.getReceiver() && heliostat.isSunBeamVisible()) {
heliostat.drawSunBeam();
}
}
}
}
}
use of org.concord.energy3d.model.Snap 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);
}
use of org.concord.energy3d.model.Snap in project energy3d by concord-consortium.
the class Scene method showOutlineOfConnectedWalls.
public void showOutlineOfConnectedWalls(final Wall w, final boolean b) {
w.visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall currentWall, final Snap prev, final Snap next) {
currentWall.showOutline(b);
currentWall.draw();
}
});
SceneManager.getInstance().refresh();
}
use of org.concord.energy3d.model.Snap in project energy3d by concord-consortium.
the class Scene method setColorOfConnectedWalls.
public void setColorOfConnectedWalls(final Wall w, final ColorRGBA color) {
w.visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall currentWall, final Snap prev, final Snap next) {
currentWall.setColor(color);
currentWall.draw();
}
});
SceneManager.getInstance().refresh();
}
Aggregations