use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.
the class PopupMenuForWindow method getPopupMenu.
static JPopupMenu getPopupMenu() {
if (popupMenuForWindow == null) {
final JMenu shutterMenu = new JMenu("Shutters");
popupMenuForWindow = createPopupMenu(true, true, new Runnable() {
@Override
public void run() {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
shutterMenu.setEnabled(selectedPart.getContainer() instanceof Wall);
}
}
});
final JMenu muntinMenu = new JMenu("Muntins");
final JCheckBoxMenuItem cbmiHorizontalBars = new JCheckBoxMenuItem("Horizontal Bars");
cbmiHorizontalBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setHorizontalBars(cbmiHorizontalBars.isSelected());
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
});
muntinMenu.add(cbmiHorizontalBars);
final JCheckBoxMenuItem cbmiVerticalBars = new JCheckBoxMenuItem("Vertical Bars");
cbmiVerticalBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setVerticalBars(cbmiVerticalBars.isSelected());
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
});
muntinMenu.add(cbmiVerticalBars);
muntinMenu.addSeparator();
final ButtonGroup muntinButtonGroup = new ButtonGroup();
final JRadioButtonMenuItem miMoreBars = new JRadioButtonMenuItem("More Bars");
miMoreBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setStyle(Window.MORE_MUNTIN_BARS);
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
}
});
muntinButtonGroup.add(miMoreBars);
muntinMenu.add(miMoreBars);
final JRadioButtonMenuItem miMediumBars = new JRadioButtonMenuItem("Medium Bars");
miMediumBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setStyle(Window.MEDIUM_MUNTIN_BARS);
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
}
});
muntinButtonGroup.add(miMediumBars);
muntinMenu.add(miMediumBars);
final JRadioButtonMenuItem miLessBars = new JRadioButtonMenuItem("Less Bars");
miLessBars.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
w.setStyle(Window.LESS_MUNTIN_BARS);
w.draw();
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
}
}
});
muntinButtonGroup.add(miLessBars);
muntinMenu.add(miLessBars);
muntinMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window window = (Window) selectedPart;
switch(window.getStyle()) {
case Window.MORE_MUNTIN_BARS:
Util.selectSilently(miMoreBars, true);
break;
case Window.MEDIUM_MUNTIN_BARS:
Util.selectSilently(miMediumBars, true);
break;
case Window.LESS_MUNTIN_BARS:
Util.selectSilently(miLessBars, true);
break;
}
// NO_MUNTIN_BAR backward compatibility
Util.selectSilently(cbmiHorizontalBars, window.getStyle() != Window.NO_MUNTIN_BAR && window.getHorizontalBars());
Util.selectSilently(cbmiVerticalBars, window.getStyle() != Window.NO_MUNTIN_BAR && window.getVerticalBars());
}
}
@Override
public void menuDeselected(final MenuEvent e) {
muntinMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
muntinMenu.setEnabled(true);
}
});
final JCheckBoxMenuItem cbmiBothShutters = new JCheckBoxMenuItem("Both Shutters");
final JCheckBoxMenuItem cbmiLeftShutter = new JCheckBoxMenuItem("Left Shutter");
final JCheckBoxMenuItem cbmiRightShutter = new JCheckBoxMenuItem("Right Shutter");
cbmiLeftShutter.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
final ChangeWindowShuttersCommand c = new ChangeWindowShuttersCommand(w);
w.setLeftShutter(cbmiLeftShutter.isSelected());
w.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
shutterMenu.add(cbmiLeftShutter);
cbmiRightShutter.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
final ChangeWindowShuttersCommand c = new ChangeWindowShuttersCommand(w);
w.setRightShutter(cbmiRightShutter.isSelected());
w.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
shutterMenu.add(cbmiRightShutter);
cbmiBothShutters.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window w = (Window) selectedPart;
final ChangeWindowShuttersCommand c = new ChangeWindowShuttersCommand(w);
w.setLeftShutter(cbmiBothShutters.isSelected());
w.setRightShutter(cbmiBothShutters.isSelected());
w.draw();
Scene.getInstance().setEdited(true);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
}
}
});
shutterMenu.add(cbmiBothShutters);
shutterMenu.addSeparator();
final JMenuItem miShutterColor = new JMenuItem("Color...");
miShutterColor.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Window)) {
return;
}
final Window window = (Window) selectedPart;
final JColorChooser colorChooser = MainFrame.getInstance().getColorChooser();
final ReadOnlyColorRGBA color = window.getShutterColor();
if (color != null) {
colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
}
final ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final Color c = colorChooser.getColor();
final float[] newColor = c.getComponents(null);
final ColorRGBA color = new ColorRGBA(newColor[0], newColor[1], newColor[2], 1);
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (window.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows of this Building");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
}
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Shutter Color");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean changed = !color.equals(window.getShutterColor());
if (rb1.isSelected()) {
// apply to only this window
if (changed) {
final ChangeShutterColorCommand cmd = new ChangeShutterColorCommand(window);
window.setShutterColor(color);
window.draw();
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (!color.equals(x.getShutterColor())) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (!color.equals(x.getShutterColor())) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerShutterColorCommand cmd = new ChangeContainerShutterColorCommand(window.getContainer());
Scene.getInstance().setWindowColorInContainer(window.getContainer(), color, true);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 1;
} else {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (!color.equals(x.getShutterColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBuildingShutterColorCommand cmd = new ChangeBuildingShutterColorCommand(window);
Scene.getInstance().setShutterColorOfBuilding(window, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 2;
}
if (changed) {
Scene.getInstance().setEdited(true);
SceneManager.getInstance().refresh();
}
if (choice == options[0]) {
break;
}
}
}
}
};
JColorChooser.createDialog(MainFrame.getInstance(), "Select Shutter Color", true, colorChooser, actionListener, null).setVisible(true);
}
});
shutterMenu.add(miShutterColor);
final JMenuItem miShutterLength = new JMenuItem("Relative Length...");
miShutterLength.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Window)) {
return;
}
final Window window = (Window) selectedPart;
final String partInfo = window.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final String title = "<html>Relative Length of Shutter for " + partInfo + "</html>";
final String footnote = "<html><hr width=400></html>";
final JPanel gui = new JPanel(new BorderLayout());
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window Shutter", true);
final JRadioButton rb2 = new JRadioButton("All Window Shutters on this Wall");
final JRadioButton rb3 = new JRadioButton("All Window Shutters of this Building");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
}
gui.add(panel, BorderLayout.CENTER);
final JTextField inputField = new JTextField(window.getShutterLength() + "");
gui.add(inputField, BorderLayout.SOUTH);
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Shutter Length (Relative)");
while (true) {
dialog.setVisible(true);
inputField.selectAll();
inputField.requestFocusInWindow();
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean ok = true;
double val = 0;
try {
val = Double.parseDouble(inputField.getText());
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (val <= 0 || val > 1) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Relative shutter length must be within (0, 1).", "Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(val - window.getShutterLength()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeShutterLengthCommand c = new ChangeShutterLengthCommand(window);
window.setShutterLength(val);
window.draw();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (Math.abs(val - x.getShutterLength()) > 0.000001) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (Math.abs(val - x.getShutterLength()) > 0.000001) {
changed = true;
break;
}
}
}
}
if (changed) {
Scene.getInstance().setShutterLengthInContainer(window.getContainer(), val);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (Math.abs(val - x.getShutterLength()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
Scene.getInstance().setShutterLengthOfBuilding(window, val);
}
selectedScopeIndex = 2;
}
if (changed) {
SceneManager.getInstance().refresh();
Scene.getInstance().setEdited(true);
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
shutterMenu.add(miShutterLength);
shutterMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (selectedPart instanceof Window) {
final Window window = (Window) selectedPart;
Util.selectSilently(cbmiLeftShutter, window.getLeftShutter());
Util.selectSilently(cbmiRightShutter, window.getRightShutter());
Util.selectSilently(cbmiBothShutters, window.getLeftShutter() && window.getRightShutter());
}
}
@Override
public void menuDeselected(final MenuEvent e) {
shutterMenu.setEnabled(true);
}
@Override
public void menuCanceled(final MenuEvent e) {
shutterMenu.setEnabled(true);
}
});
final JMenuItem miShgc = new JMenuItem("Solar Heat Gain Coefficient...");
miShgc.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Window)) {
return;
}
final String partInfo = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final Window window = (Window) selectedPart;
final String title = "<html>Solar Heat Gain Coefficient of " + partInfo + "</html>";
final String footnote = "<html><hr><font size=2>Examples:<br><table><tr><td><font size=2>Single glass (clear)</td><td><font size=2>0.66</td></tr><tr><td><font size=2>Single glass (green tint)</td><td><font size=2>0.55</td></tr><tr><td><font size=2>Triple glass (air spaces)</td><td><font size=2>0.39</td></tr></table><hr></html>";
final JPanel gui = new JPanel(new BorderLayout());
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (selectedPart.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows of this Building");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
}
gui.add(panel, BorderLayout.CENTER);
final JTextField inputField = new JTextField(window.getSolarHeatGainCoefficient() + "");
gui.add(inputField, BorderLayout.SOUTH);
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(new Object[] { title, footnote, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Solar Heat Gain Coefficient (SHGC)");
while (true) {
dialog.setVisible(true);
inputField.selectAll();
inputField.requestFocusInWindow();
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean ok = true;
double val = 0;
try {
val = Double.parseDouble(inputField.getText());
} catch (final NumberFormatException exception) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), inputField.getText() + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
if (val < 0 || val > 1) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Solar heat gain coefficient must be between 0 and 1.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(val - window.getSolarHeatGainCoefficient()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final ChangeWindowShgcCommand c = new ChangeWindowShgcCommand(window);
window.setSolarHeatGainCoefficient(val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (Math.abs(val - x.getSolarHeatGainCoefficient()) > 0.000001) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (Math.abs(val - x.getSolarHeatGainCoefficient()) > 0.000001) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerWindowShgcCommand c = new ChangeContainerWindowShgcCommand(window.getContainer());
Scene.getInstance().setWindowShgcInContainer(window.getContainer(), val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (Math.abs(val - x.getSolarHeatGainCoefficient()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBuildingWindowShgcCommand c = new ChangeBuildingWindowShgcCommand(foundation);
Scene.getInstance().setWindowShgcOfBuilding(foundation, val);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
final JMenuItem miTint = new JMenuItem("Tint...");
miTint.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Window)) {
return;
}
final Window window = (Window) selectedPart;
final JColorChooser colorChooser = MainFrame.getInstance().getColorChooser();
final ReadOnlyColorRGBA color = window.getColor();
if (color != null) {
colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
}
final ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final Color c = colorChooser.getColor();
final float[] newColor = c.getComponents(null);
final ColorRGBA color = new ColorRGBA(newColor[0], newColor[1], newColor[2], (float) (1.0 - window.getSolarHeatGainCoefficient()));
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (window.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows of this Building");
panel.add(rb1);
panel.add(rb2);
panel.add(rb3);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
}
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Window Tint");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean changed = !Util.isRGBEqual(color, window.getColor());
if (rb1.isSelected()) {
// apply to only this window
if (changed) {
final ChangePartColorCommand cmd = new ChangePartColorCommand(window);
window.setColor(color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (!Util.isRGBEqual(color, x.getColor())) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (!Util.isRGBEqual(color, x.getColor())) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerWindowColorCommand cmd = new ChangeContainerWindowColorCommand(window.getContainer());
Scene.getInstance().setWindowColorInContainer(window.getContainer(), color, false);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
final Foundation foundation = window.getTopContainer();
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (!Util.isRGBEqual(color, x.getColor())) {
changed = true;
break;
}
}
}
if (changed) {
final ChangeBuildingColorCommand cmd = new ChangeBuildingColorCommand(window);
Scene.getInstance().setPartColorOfBuilding(window, color);
SceneManager.getInstance().getUndoManager().addEdit(cmd);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
};
JColorChooser.createDialog(MainFrame.getInstance(), "Select Tint", true, colorChooser, actionListener, null).setVisible(true);
}
});
final JMenuItem miSize = new JMenuItem("Size...");
miSize.addActionListener(new ActionListener() {
// remember the scope selection as the next action will likely be applied to the same scope
private int selectedScopeIndex = 0;
@Override
public void actionPerformed(final ActionEvent e) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
if (!(selectedPart instanceof Window)) {
return;
}
final Window window = (Window) selectedPart;
final HousePart container = window.getContainer();
final Foundation foundation = window.getTopContainer();
final String partInfo = window.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
final JPanel gui = new JPanel(new BorderLayout());
final JPanel inputPanel = new JPanel(new GridLayout(2, 2, 5, 5));
gui.add(inputPanel, BorderLayout.CENTER);
inputPanel.add(new JLabel("Width (m): "));
final JTextField widthField = new JTextField(threeDecimalsFormat.format(window.getWindowWidth()));
inputPanel.add(widthField);
inputPanel.add(new JLabel("Height (m): "));
final JTextField heightField = new JTextField(threeDecimalsFormat.format(window.getWindowHeight()));
inputPanel.add(heightField);
inputPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
final JPanel scopePanel = new JPanel();
scopePanel.setLayout(new BoxLayout(scopePanel, BoxLayout.Y_AXIS));
scopePanel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
final JRadioButton rb1 = new JRadioButton("Only this Window", true);
final JRadioButton rb2 = new JRadioButton("All Windows on this " + (window.getContainer() instanceof Wall ? "Wall" : "Roof"));
final JRadioButton rb3 = new JRadioButton("All Windows of this Building");
scopePanel.add(rb1);
scopePanel.add(rb2);
scopePanel.add(rb3);
final ButtonGroup bg = new ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rb3);
switch(selectedScopeIndex) {
case 0:
rb1.setSelected(true);
break;
case 1:
rb2.setSelected(true);
break;
case 2:
rb3.setSelected(true);
break;
}
gui.add(scopePanel, BorderLayout.NORTH);
final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
final JOptionPane optionPane = new JOptionPane(new Object[] { "Set Size for " + partInfo, gui }, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Window Size");
while (true) {
dialog.setVisible(true);
final Object choice = optionPane.getValue();
if (choice == options[1] || choice == null) {
break;
} else {
boolean ok = true;
double w = 0, h = 0;
try {
w = Double.parseDouble(widthField.getText());
h = Double.parseDouble(heightField.getText());
} catch (final NumberFormatException x) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Invalid input!", "Error", JOptionPane.ERROR_MESSAGE);
ok = false;
}
if (ok) {
double wmax = 10;
if (container instanceof Wall) {
wmax = ((Wall) container).getWallWidth() * 0.99;
}
double hmax = 10;
if (container instanceof Wall) {
hmax = ((Wall) container).getWallHeight() * 0.99;
}
if (w < 0.1 || w > wmax) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Width must be between 0.1 and " + (int) wmax + " m.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else if (h < 0.1 || h > hmax) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Height must be between 0.1 and " + (int) hmax + " m.", "Range Error", JOptionPane.ERROR_MESSAGE);
} else {
boolean changed = Math.abs(w - window.getWindowWidth()) > 0.000001 || Math.abs(h - window.getWindowHeight()) > 0.000001;
if (rb1.isSelected()) {
if (changed) {
final SetPartSizeCommand c = new SetPartSizeCommand(window);
window.setWindowWidth(w);
window.setWindowHeight(h);
window.draw();
window.getContainer().draw();
SceneManager.getInstance().refresh();
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 0;
} else if (rb2.isSelected()) {
if (!changed) {
if (window.getContainer() instanceof Wall) {
final Wall wall = (Wall) window.getContainer();
for (final Window x : wall.getWindows()) {
if (Math.abs(w - x.getWindowWidth()) > 0.000001 || Math.abs(h - x.getWindowHeight()) > 0.000001) {
changed = true;
break;
}
}
} else if (window.getContainer() instanceof Roof) {
final Roof roof = (Roof) window.getContainer();
for (final Window x : roof.getWindows()) {
if (Math.abs(w - x.getWindowWidth()) > 0.000001 || Math.abs(h - x.getWindowHeight()) > 0.000001) {
changed = true;
break;
}
}
}
}
if (changed) {
final ChangeContainerWindowSizeCommand c = new ChangeContainerWindowSizeCommand(window.getContainer());
Scene.getInstance().setWindowSizeInContainer(window.getContainer(), w, h);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 1;
} else if (rb3.isSelected()) {
if (!changed) {
for (final Window x : foundation.getWindows()) {
if (Math.abs(w - x.getWindowWidth()) > 0.000001 || Math.abs(h - x.getWindowHeight()) > 0.000001) {
changed = true;
break;
}
}
}
if (changed) {
final SetSizeForWindowsOnFoundationCommand c = new SetSizeForWindowsOnFoundationCommand(foundation);
foundation.setSizeForWindows(w, h);
SceneManager.getInstance().getUndoManager().addEdit(c);
}
selectedScopeIndex = 2;
}
if (changed) {
updateAfterEdit();
}
if (choice == options[0]) {
break;
}
}
}
}
}
}
});
popupMenuForWindow.addSeparator();
popupMenuForWindow.add(miSize);
popupMenuForWindow.add(miTint);
popupMenuForWindow.add(createInsulationMenuItem(true));
popupMenuForWindow.add(miShgc);
popupMenuForWindow.add(muntinMenu);
popupMenuForWindow.add(shutterMenu);
popupMenuForWindow.addSeparator();
JMenuItem mi = new JMenuItem("Daily Energy Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof Window) {
new EnergyDailyAnalysis().show("Daily Energy for Window");
}
}
});
popupMenuForWindow.add(mi);
mi = new JMenuItem("Annual Energy Analysis...");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (EnergyPanel.getInstance().adjustCellSize()) {
return;
}
if (SceneManager.getInstance().getSelectedPart() instanceof Window) {
new EnergyAnnualAnalysis().show("Annual Energy for Window");
}
}
});
popupMenuForWindow.add(mi);
}
return popupMenuForWindow;
}
use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.
the class MySlider method paintComponent.
@Override
public void paintComponent(Graphics g) {
final int STEP = 5;
final Dimension size = getSize();
final int y1 = 2 * size.height / 3;
for (int x = 0; x < size.width - STEP; x += STEP) {
final ColorRGBA color = SolarRadiation.computeColor(x, size.width);
g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
g.fillRect(x, 0, x + STEP, y1);
}
g.setColor(Color.WHITE);
g.fillRect(0, y1, size.width - 1, size.height - y1 - 1);
g.setColor(Color.GRAY);
g.drawRect(0, y1, size.width - 1, size.height - y1 - 1);
super.paintComponent(g);
}
use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.
the class FresnelReflector method init.
@Override
protected void init() {
super.init();
if (Util.isZero(copyLayoutGap)) {
// FIXME: Why is a transient member evaluated to zero?
copyLayoutGap = 0.2;
}
if (Util.isZero(moduleLength)) {
moduleLength = 3;
}
if (Util.isZero(length)) {
length = 2 * moduleLength;
}
if (Util.isZero(moduleWidth)) {
moduleWidth = 2;
}
if (Util.isZero(reflectance)) {
reflectance = 0.9;
}
if (Util.isZero(opticalEfficiency)) {
opticalEfficiency = 0.99;
}
if (Util.isZero(nSectionLength)) {
nSectionLength = 16;
}
if (Util.isZero(nSectionWidth)) {
nSectionWidth = 4;
}
detailed = Scene.getInstance().countParts(this.getClass()) < 50;
if (absorber != null) {
// FIXME: Somehow the absorber foundation, when copied, doesn't point to the right object. This is not a prefect solution, but it fixes the problem.
absorber = (Foundation) Scene.getInstance().getPart(absorber.getId());
}
mesh = new Mesh("Fresnel Reflector Face");
mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
mesh.setDefaultColor(SKY_BLUE);
mesh.setModelBound(new OrientedBoundingBox());
mesh.setUserData(new UserData(this));
root.attachChild(mesh);
reflector = new Box("Fresnel Reflector Box");
reflector.setModelBound(new OrientedBoundingBox());
final OffsetState offset = new OffsetState();
offset.setFactor(1);
offset.setUnits(1);
reflector.setRenderState(offset);
root.attachChild(reflector);
final int nModules = Math.max(1, getNumberOfModules());
outlines = new Line("Fresnel Reflector (Outline)");
outlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8 + (nModules - 1) * 2));
outlines.setDefaultColor(ColorRGBA.BLACK);
outlines.setModelBound(new OrientedBoundingBox());
outlines.setLineWidth(1f);
outlines.setStipplePattern((short) 0xffff);
Util.disablePickShadowLight(outlines);
root.attachChild(outlines);
lightBeams = new Line("Light Beams");
lightBeams.setLineWidth(1f);
lightBeams.setStipplePattern((short) 0xffff);
lightBeams.setModelBound(null);
Util.disablePickShadowLight(lightBeams);
lightBeams.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
lightBeams.setDefaultColor(new ColorRGBA(1f, 1f, 1f, 1f));
root.attachChild(lightBeams);
label = new BMText("Label", "#" + id, FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
Util.initHousePartLabel(label);
label.setFontScale(0.5);
label.setVisible(false);
root.attachChild(label);
modulesRoot = new Node("Modules Root");
root.attachChild(modulesRoot);
updateTextureAndColor();
if (!points.isEmpty()) {
oldReflectorCenter = points.get(0).clone();
}
oldLength = length;
oldModuleWidth = moduleWidth;
}
use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.
the class Scene method setTheme.
public void setTheme(final int theme) {
this.theme = theme;
ReadOnlyColorRGBA c;
switch(theme) {
case DESERT_THEME:
c = new ColorRGBA(1, 1, 1, 0.5f);
break;
case GRASSLAND_THEME:
c = new ColorRGBA(0, 0.9f, 0.5f, 0.5f);
break;
case FOREST_THEME:
c = new ColorRGBA(0, 0.9f, 0.6f, 0.5f);
break;
default:
c = landColor == null ? new ColorRGBA(0, 1, 0.75f, 0.5f) : landColor;
}
setLandColor(c);
SceneManager.getInstance().changeSkyTexture();
}
use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.
the class Scene method init.
private void init() {
root.detachAllChildren();
originalHouseRoot.detachAllChildren();
notReceivingShadowRoot.detachAllChildren();
root.attachChild(originalHouseRoot);
root.attachChild(notReceivingShadowRoot);
if (url != null) {
for (final HousePart p : parts) {
final boolean b = p instanceof Tree || p instanceof Human;
(b ? notReceivingShadowRoot : originalHouseRoot).attachChild(p.getRoot());
}
System.out.println("initSceneNow done");
}
root.updateWorldBound(true);
SceneManager.getInstance().updateHeliodonAndAnnotationSize();
SceneManager.getInstance().setAxesVisible(!hideAxes);
SceneManager.getInstance().getSolarLand().setVisible(solarMapForLand);
setTheme(theme);
SceneManager.getInstance().getLand().setDefaultColor(landColor != null ? landColor : new ColorRGBA(0, 1, 0, 0.5f));
PvModulesData.getInstance();
final EnergyPanel energyPanel = EnergyPanel.getInstance();
if (calendar != null) {
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
if (url == null) {
// if a new file is created, its default time is always set to noon so that the user does not get a dark night scene
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 0);
}
final Date time = calendar.getTime();
Heliodon.getInstance().setDate(time);
Heliodon.getInstance().setTime(time);
Util.setSilently(energyPanel.getDateSpinner(), time);
Util.setSilently(energyPanel.getTimeSpinner(), time);
if ("Boston".equals(city) || city == null || "".equals(city)) {
city = "Boston, MA";
latitude = 42;
}
// already silent
energyPanel.setLatitude(latitude);
Util.selectSilently(energyPanel.getCityComboBox(), city);
final LocationData ld = LocationData.getInstance();
if (ld.getLatitudes().get(city) != null) {
energyPanel.getCityComboBox().setToolTipText("<html>(" + ld.getLatitudes().get(city) + "°, " + ld.getLongitudes().get(city) + "°), elevation " + ld.getAltitudes().get(city).intValue() + "m<br>Use Edit>Set Region... to select country and region.</html>");
} else {
JOptionPane.showMessageDialog(MainFrame.getInstance(), city + " not supported. Please upgrade your Energy3D to the latest.", "Missing City", JOptionPane.ERROR_MESSAGE);
}
Scene.getInstance().updateTreeLeaves();
SceneManager.getInstance().changeSkyTexture();
if (!first) {
SceneManager.getInstance().setHeliodonVisible(isHeliodonVisible);
Util.selectSilently(MainPanel.getInstance().getHeliodonButton(), isHeliodonVisible);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().getSunAnimationButton().setEnabled(isHeliodonVisible);
}
});
}
Heliodon.getInstance().drawSun();
SceneManager.getInstance().setShading(Heliodon.getInstance().isNightTime());
}
// previous versions do not have the following classes
if (designSpecs == null) {
designSpecs = new DesignSpecs();
} else {
designSpecs.setDefaultValues();
}
if (pvDesignSpecs == null) {
pvDesignSpecs = new PvDesignSpecs();
} else {
pvDesignSpecs.setDefaultValues();
}
if (cspDesignSpecs == null) {
cspDesignSpecs = new CspDesignSpecs();
} else {
cspDesignSpecs.setDefaultValues();
}
if (pvCustomPrice == null) {
pvCustomPrice = new PvCustomPrice();
} else {
pvCustomPrice.setDefaultValues();
}
if (cspCustomPrice == null) {
cspCustomPrice = new CspCustomPrice();
} else {
cspCustomPrice.setDefaultValues();
}
if (ground == null) {
ground = new Ground();
}
if (atmosphere == null) {
atmosphere = new Atmosphere();
}
if (unit == null) {
unit = Unit.InternationalSystemOfUnits;
}
// restore the default values
if (Util.isZero(heatVectorLength)) {
heatVectorLength = 5000;
}
if (Util.isZero(heatFluxGridSize)) {
heatFluxGridSize = 2;
}
if (Util.isZero(solarStep)) {
solarStep = 2;
}
if (Util.isZero(timeStep)) {
timeStep = 15;
}
if (Util.isZero(solarPanelNx)) {
solarPanelNx = 4;
}
if (Util.isZero(solarPanelNy)) {
solarPanelNy = 4;
}
if (Util.isZero(rackNx)) {
rackNx = 8;
}
if (Util.isZero(rackNy)) {
rackNy = 8;
}
if (Util.isZero(mirrorNx)) {
mirrorNx = 4;
}
if (Util.isZero(mirrorNy)) {
mirrorNy = 4;
}
if (Util.isZero(parabolicDishN)) {
parabolicDishN = 4;
}
if (Util.isZero(rackCellSize)) {
rackCellSize = 1;
}
if (Util.isZero(solarContrast)) {
solarContrast = 50;
}
// in case we need to have more instruction sheets
if (instructionSheetText != null) {
if (instructionSheetText.length < INSTRUCTION_SHEET_NUMBER) {
final String[] tmp = new String[INSTRUCTION_SHEET_NUMBER];
System.arraycopy(instructionSheetText, 0, tmp, 0, instructionSheetText.length);
instructionSheetText = tmp;
}
}
if (instructionSheetTextType != null) {
if (instructionSheetTextType.length < INSTRUCTION_SHEET_NUMBER) {
final String[] tmp = new String[INSTRUCTION_SHEET_NUMBER];
System.arraycopy(instructionSheetTextType, 0, tmp, 0, instructionSheetTextType.length);
instructionSheetTextType = tmp;
}
}
setEdited(false);
setCopyBuffer(null);
Util.setSilently(energyPanel.getColorMapSlider(), solarContrast);
// need to do this to avoid logging
Util.setSilently(MainPanel.getInstance().getNoteTextArea(), note == null ? "" : note);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
energyPanel.updateThermostat();
// necessary for the scroll bars to show up appropriately
MainPanel.getInstance().setNoteVisible(MainPanel.getInstance().isNoteVisible());
// moved from OpenNow to here to avoid triggering EnergyComputer -> RedrawAllNow before open is completed
MainPanel.getInstance().getEnergyButton().setSelected(false);
SceneManager.getInstance().getUndoManager().discardAllEdits();
MainApplication.getEventLog().clear();
}
});
}
Aggregations