use of org.concord.energy3d.util.ClipImage in project energy3d by concord-consortium.
the class AnnualAnalysis method createOptionsMenu.
JMenu createOptionsMenu(final JDialog dialog, final List<HousePart> selectedParts, final boolean selectAll, final boolean exportStoredResults) {
final JMenuItem miClear = new JMenuItem("Clear Previous Results");
final JMenuItem miView = new JMenuItem("View Raw Data...");
final JMenuItem miExportStoredResults = new JMenuItem("Export Stored Hourly Results");
final JMenu menu = new JMenu("Options");
menu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
miClear.setEnabled(graph.hasRecords());
miView.setEnabled(graph.hasData());
miExportStoredResults.setEnabled(Scene.getInstance().getSolarResults() != null);
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
final JMenu chartMenu = new JMenu("Chart");
final ButtonGroup chartGroup = new ButtonGroup();
menu.add(chartMenu);
final JRadioButtonMenuItem miLine = new JRadioButtonMenuItem("Line");
miLine.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.LINE_CHART);
graph.repaint();
}
}
});
chartMenu.add(miLine);
chartGroup.add(miLine);
miLine.setSelected(graph.getGraphType() == Graph.LINE_CHART);
final JRadioButtonMenuItem miArea = new JRadioButtonMenuItem("Area");
miArea.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.AREA_CHART);
graph.repaint();
}
}
});
chartMenu.add(miArea);
chartGroup.add(miArea);
miArea.setSelected(graph.getGraphType() == Graph.AREA_CHART);
miClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final int i = JOptionPane.showConfirmDialog(dialog, "Are you sure that you want to clear all the previous results\nrelated to the selected object?", "Confirmation", JOptionPane.YES_NO_OPTION);
if (i != JOptionPane.YES_OPTION) {
return;
}
graph.clearRecords();
graph.repaint();
TimeSeriesLogger.getInstance().logClearGraphData(graph.getClass().getSimpleName());
}
});
menu.add(miClear);
miView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (selectedParts == null) {
DataViewer.viewRawData(dialog, graph, selectAll);
} else {
DataViewer.viewRawData(dialog, graph, selectedParts);
}
}
});
menu.add(miView);
final JMenuItem miCopyImage = new JMenuItem("Copy Image");
miCopyImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new ClipImage().copyImageToClipboard(graph);
}
});
menu.add(miCopyImage);
if (exportStoredResults) {
miExportStoredResults.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final double[][] solarResults = Scene.getInstance().getSolarResults();
if (solarResults != null) {
double sum = 0;
// Hack to fix the results in case we make a mistake that can be quickly remedied
final double scale = 1;
for (int i = 0; i < solarResults.length; i++) {
for (int j = 0; j < solarResults[i].length; j++) {
solarResults[i][j] *= scale;
sum += solarResults[i][j];
}
}
sum *= 365.0 / 12.0;
String s = "";
for (int i = 0; i < solarResults.length; i++) {
s += "\"" + AnnualGraph.THREE_LETTER_MONTH[i] + "\": \"";
for (int j = 0; j < solarResults[i].length; j++) {
s += EnergyPanel.FIVE_DECIMALS.format(solarResults[i][j]).replaceAll(",", "") + " ";
}
s = s.trim() + "\",\n\t";
}
s = s.substring(0, s.length() - 1);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(s), null);
JOptionPane.showMessageDialog(dialog, "A total of " + EnergyPanel.TWO_DECIMALS.format(sum) + " KWh was copied to the clipboard.", "Export", JOptionPane.INFORMATION_MESSAGE);
}
}
});
menu.add(miExportStoredResults);
}
return menu;
}
use of org.concord.energy3d.util.ClipImage in project energy3d by concord-consortium.
the class EnergyAngularAnalysis method show.
public void show(final String title) {
final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
String s = selectedPart.toString().substring(0, selectedPart.toString().indexOf(')') + 1);
if (selectedPart instanceof Foundation) {
s = s.replaceAll("Foundation", "Building");
if (selectedPart.getChildren().isEmpty()) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "There is no building on this foundation.", "No Building", JOptionPane.WARNING_MESSAGE);
return;
}
if (!isBuildingComplete((Foundation) selectedPart)) {
if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), "The selected building has not been completed.\nAre you sure to continue?", "Incomplete Building", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) {
return;
}
}
} else if (selectedPart instanceof Tree) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "Energy analysis is not applicable to a tree.", "Not Applicable", JOptionPane.WARNING_MESSAGE);
return;
}
final JDialog dialog = new JDialog(MainFrame.getInstance(), title + ": " + s, true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
graph.parent = dialog;
final JMenuBar menuBar = new JMenuBar();
dialog.setJMenuBar(menuBar);
final JMenuItem miClear = new JMenuItem("Clear Previous Results");
final JMenuItem miView = new JMenuItem("View Raw Data...");
final JMenuItem miCopyImage = new JMenuItem("Copy Image");
final JMenu menu = new JMenu("Options");
menu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
miClear.setEnabled(graph.hasRecords());
miView.setEnabled(graph.hasData());
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
menuBar.add(menu);
miClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final int i = JOptionPane.showConfirmDialog(dialog, "Are you sure that you want to clear all the previous results\nrelated to the selected object?", "Confirmation", JOptionPane.YES_NO_OPTION);
if (i != JOptionPane.YES_OPTION) {
return;
}
graph.clearRecords();
graph.repaint();
TimeSeriesLogger.getInstance().logClearGraphData(graph.getClass().getSimpleName());
}
});
menu.add(miClear);
miView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
DataViewer.viewRawData(dialog, graph, false);
}
});
menu.add(miView);
miCopyImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new ClipImage().copyImageToClipboard(graph);
}
});
menu.add(miCopyImage);
final JMenu showTypeMenu = new JMenu("Types");
showTypeMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
showTypeMenu.removeAll();
final Set<String> dataNames = graph.getDataNames();
if (!dataNames.isEmpty()) {
JMenuItem mi = new JMenuItem("Show All");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
for (final String name : dataNames) {
graph.hideData(name, false);
}
graph.repaint();
TimeSeriesLogger.getInstance().logShowCurve(graph.getClass().getSimpleName(), "All", true);
}
});
showTypeMenu.add(mi);
mi = new JMenuItem("Hide All");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
for (final String name : dataNames) {
graph.hideData(name, true);
}
graph.repaint();
TimeSeriesLogger.getInstance().logShowCurve(graph.getClass().getSimpleName(), "All", false);
}
});
showTypeMenu.add(mi);
showTypeMenu.addSeparator();
for (final String name : dataNames) {
final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(name, !graph.isDataHidden(name));
cbmi.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
graph.hideData(name, !cbmi.isSelected());
graph.repaint();
TimeSeriesLogger.getInstance().logShowCurve(graph.getClass().getSimpleName(), name, cbmi.isSelected());
}
});
showTypeMenu.add(cbmi);
}
}
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
menuBar.add(showTypeMenu);
final JMenu showRunsMenu = new JMenu("Runs");
showRunsMenu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
showRunsMenu.removeAll();
if (!AngularGraph.records.isEmpty()) {
JMenuItem mi = new JMenuItem("Show All");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
for (final Results r : AngularGraph.records) {
graph.hideRun(r.getID(), false);
}
graph.repaint();
TimeSeriesLogger.getInstance().logShowRun(graph.getClass().getSimpleName(), "All", true);
}
});
showRunsMenu.add(mi);
mi = new JMenuItem("Hide All");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
for (final Results r : AngularGraph.records) {
graph.hideRun(r.getID(), true);
}
graph.repaint();
TimeSeriesLogger.getInstance().logShowRun(graph.getClass().getSimpleName(), "All", false);
}
});
showRunsMenu.add(mi);
showRunsMenu.addSeparator();
for (final Results r : AngularGraph.records) {
final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(Integer.toString(r.getID()), !graph.isRunHidden(r.getID()));
cbmi.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
graph.hideRun(r.getID(), !cbmi.isSelected());
graph.repaint();
TimeSeriesLogger.getInstance().logShowRun(graph.getClass().getSimpleName(), "" + r.getID(), cbmi.isSelected());
}
});
showRunsMenu.add(cbmi);
}
}
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
menuBar.add(showRunsMenu);
final JPanel contentPane = new JPanel(new BorderLayout());
dialog.setContentPane(contentPane);
final JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEtchedBorder());
contentPane.add(panel, BorderLayout.CENTER);
panel.add(graph, BorderLayout.CENTER);
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
contentPane.add(buttonPanel, BorderLayout.SOUTH);
runButton = new JButton("Run");
runButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
runButton.setEnabled(false);
runAnalysis(dialog);
}
});
buttonPanel.add(runButton);
final JButton button = new JButton("Close");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
stopAnalysis();
if (graph.hasData()) {
final Object[] options = { "Yes", "No", "Cancel" };
final int i = JOptionPane.showOptionDialog(dialog, "Do you want to keep the results of this run?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
if (i == JOptionPane.CANCEL_OPTION) {
return;
}
if (i == JOptionPane.YES_OPTION) {
graph.keepResults();
}
}
windowLocation.setLocation(dialog.getLocationOnScreen());
dialog.dispose();
}
});
buttonPanel.add(button);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
stopAnalysis();
windowLocation.setLocation(dialog.getLocationOnScreen());
dialog.dispose();
}
});
dialog.pack();
if (windowLocation.x > 0 && windowLocation.y > 0) {
dialog.setLocation(windowLocation);
} else {
dialog.setLocationRelativeTo(MainFrame.getInstance());
}
dialog.setVisible(true);
}
use of org.concord.energy3d.util.ClipImage in project energy3d by concord-consortium.
the class MonthlySunshineHours method showDialog.
public void showDialog() {
final JDialog dialog = new JDialog(MainFrame.getInstance(), "Monthly Sunshine Hours", true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
final JPanel contentPane = new JPanel(new BorderLayout());
dialog.setContentPane(contentPane);
final JMenuBar menuBar = new JMenuBar();
dialog.setJMenuBar(menuBar);
final JMenu menuExport = new JMenu("Export");
menuBar.add(menuExport);
final JMenuItem mi = new JMenuItem("Copy Image");
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new ClipImage().copyImageToClipboard(MonthlySunshineHours.this);
}
});
menuExport.add(mi);
final JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEtchedBorder());
contentPane.add(panel, BorderLayout.CENTER);
panel.add(this, BorderLayout.CENTER);
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
contentPane.add(buttonPanel, BorderLayout.SOUTH);
final JButton button = new JButton("Close");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
dialog.dispose();
}
});
buttonPanel.add(button);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
dialog.dispose();
}
});
dialog.pack();
dialog.setLocationRelativeTo(MainFrame.getInstance());
dialog.setVisible(true);
TimeSeriesLogger.getInstance().logAnalysis(this);
final HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put("Location", Scene.getInstance().getCity());
MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), getClass().getSimpleName(), attributes));
}
use of org.concord.energy3d.util.ClipImage in project energy3d by concord-consortium.
the class DailyAnalysis method createOptionsMenu.
JMenu createOptionsMenu(final JDialog dialog, final List<HousePart> selectedParts, final boolean selectAll) {
final JMenuItem miClear = new JMenuItem("Clear Previous Results");
final JMenuItem miView = new JMenuItem("View Raw Data...");
final JMenu menu = new JMenu("Options");
menu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(final MenuEvent e) {
miClear.setEnabled(graph.hasRecords());
miView.setEnabled(graph.hasData());
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuCanceled(final MenuEvent e) {
}
});
final JMenu chartMenu = new JMenu("Chart");
final ButtonGroup chartGroup = new ButtonGroup();
menu.add(chartMenu);
final JRadioButtonMenuItem miLine = new JRadioButtonMenuItem("Line");
miLine.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.LINE_CHART);
graph.repaint();
}
}
});
chartMenu.add(miLine);
chartGroup.add(miLine);
miLine.setSelected(graph.getGraphType() == Graph.LINE_CHART);
final JRadioButtonMenuItem miArea = new JRadioButtonMenuItem("Area");
miArea.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
graph.setGraphType(Graph.AREA_CHART);
graph.repaint();
}
}
});
chartMenu.add(miArea);
chartGroup.add(miArea);
miArea.setSelected(graph.getGraphType() == Graph.AREA_CHART);
final JCheckBoxMenuItem miMilitaryTime = new JCheckBoxMenuItem("Military Time");
miMilitaryTime.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (graph instanceof DailyGraph) {
((DailyGraph) graph).setMilitaryTime(miMilitaryTime.isSelected());
graph.repaint();
}
}
});
menu.add(miMilitaryTime);
miClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final int i = JOptionPane.showConfirmDialog(dialog, "Are you sure that you want to clear all the previous results\nrelated to the selected object?", "Confirmation", JOptionPane.YES_NO_OPTION);
if (i != JOptionPane.YES_OPTION) {
return;
}
graph.clearRecords();
graph.repaint();
TimeSeriesLogger.getInstance().logClearGraphData(graph.getClass().getSimpleName());
}
});
menu.add(miClear);
miView.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (selectedParts == null) {
DataViewer.viewRawData(dialog, graph, selectAll);
} else {
DataViewer.viewRawData(dialog, graph, selectedParts);
}
}
});
menu.add(miView);
final JMenuItem miCopyImage = new JMenuItem("Copy Image");
miCopyImage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new ClipImage().copyImageToClipboard(graph);
}
});
menu.add(miCopyImage);
return menu;
}
use of org.concord.energy3d.util.ClipImage in project energy3d by concord-consortium.
the class MainFrame method getCopyImageMenuItem.
private JMenuItem getCopyImageMenuItem() {
if (copyImageMenuItem == null) {
copyImageMenuItem = new JMenuItem("Copy Image");
copyImageMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, (Config.isMac() ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK) | KeyEvent.ALT_MASK));
copyImageMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
new ClipImage().copyImageToClipboard(MainPanel.getInstance().getCanvasPanel());
}
});
}
return copyImageMenuItem;
}
Aggregations