use of org.concord.energy3d.agents.Agent in project energy3d by concord-consortium.
the class MyUndoManager method addEdit.
@Override
public boolean addEdit(final UndoableEdit edit) {
final boolean result = super.addEdit(edit);
final boolean saveFlag = edit instanceof SaveCommand;
Scene.getInstance().setEdited(!saveFlag);
refreshUndoRedoGui();
if (edit instanceof MyEvent) {
for (final Agent a : MainApplication.getAgents()) {
a.sense((MyEvent) edit);
}
}
if (saveFlag) {
TimeSeriesLogger.getInstance().logSave();
} else {
TimeSeriesLogger.getInstance().logAction();
}
return result;
}
use of org.concord.energy3d.agents.Agent in project energy3d by concord-consortium.
the class MyEditorPane method buttonActionPerformed.
private void buttonActionPerformed(final String act, final QuestionnaireModel questionnaireModel, final DefaultButtonModel buttonModel) {
if (act == null) {
return;
}
// instruction sheet selection commands
if (act.startsWith("Sheet")) {
final int i = Integer.parseInt(act.substring(5).trim());
EnergyPanel.getInstance().selectInstructionSheet(i - 1);
} else if ("Questionnaire".equals(act)) {
if (questionnaireModel != null) {
MainApplication.addEvent(new QuestionnaireEvent(Scene.getURL(), System.currentTimeMillis(), questionnaireModel));
}
} else if (act.startsWith("Event Miner") || act.startsWith("Conformance Checker")) {
final Agent a = MainApplication.getAgent(act);
if (a != null) {
final HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put("Agent", act);
MainApplication.addEvent(new OperationEvent(Scene.getURL(), System.currentTimeMillis(), '?', a.getName(), attributes));
a.actuate();
}
} else // show actions
if ("Event Frequency".equals(act)) {
new EventFrequency().showGui();
} else if ("Event Time Series".equals(act)) {
new EventTimeSeries().showGui();
} else if ("Event String".equals(act)) {
new EventString().showGui();
} else // heliodon commands
if ("Heliodon".equals(act)) {
MainPanel.getInstance().getHeliodonButton().setSelected(buttonModel.isSelected());
} else if ("Heliodon On".equals(act)) {
MainPanel.getInstance().getHeliodonButton().setSelected(true);
} else if ("Heliodon Off".equals(act)) {
MainPanel.getInstance().getHeliodonButton().setSelected(false);
} else // sun motion commands
if ("Sun Motion".equals(act)) {
MainPanel.getInstance().getSunAnimationButton().setSelected(buttonModel.isSelected());
} else if ("Sun Motion On".equals(act)) {
MainPanel.getInstance().getSunAnimationButton().setSelected(true);
} else if ("Sun Motion Off".equals(act)) {
MainPanel.getInstance().getSunAnimationButton().setSelected(false);
} else // shadow commands
if ("Shadow".equals(act)) {
MainPanel.getInstance().getShadowButton().setSelected(buttonModel.isSelected());
} else if ("Shadow On".equals(act)) {
MainPanel.getInstance().getShadowButton().setSelected(true);
} else if ("Shadow Off".equals(act)) {
MainPanel.getInstance().getShadowButton().setSelected(false);
} else if (act.startsWith("Daily Analysis for Group")) {
if (EnergyPanel.getInstance().checkCity()) {
PartGroup g = null;
final GroupSelector selector = new GroupSelector();
for (final String s : GroupSelector.types) {
final int index = act.indexOf(s);
if (index > 0) {
selector.setCurrentGroupType(s);
try {
final String t = act.substring(index + s.length()).trim();
if (!t.equals("")) {
g = new PartGroup(s);
final String[] a = t.split(",");
for (final String x : a) {
g.addId(Integer.parseInt(x.trim()));
}
}
} catch (final Exception e) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>Error in <i>" + act + "</i>.<br>Please select the IDs manually.</html>", "Input Error", JOptionPane.ERROR_MESSAGE);
g = null;
}
break;
}
}
if (g == null) {
g = selector.select();
}
if (g != null) {
final PartGroup g2 = g;
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// for some reason, this may be delayed in the AWT Event Queue in order to avoid a HTML form NullPointerException
final GroupDailyAnalysis a = new GroupDailyAnalysis(g2);
a.show(g2.getType() + ": " + g2.getIds());
}
});
}
SceneManager.getInstance().hideAllEditPoints();
}
} else if (act.startsWith("Annual Analysis for Group")) {
if (EnergyPanel.getInstance().checkCity()) {
PartGroup g = null;
final GroupSelector selector = new GroupSelector();
for (final String s : GroupSelector.types) {
final int index = act.indexOf(s);
if (index > 0) {
selector.setCurrentGroupType(s);
try {
final String t = act.substring(index + s.length()).trim();
if (!t.equals("")) {
g = new PartGroup(s);
final String[] a = t.split(",");
for (final String x : a) {
g.addId(Integer.parseInt(x.trim()));
}
}
} catch (final Exception e) {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>Error in <i>" + act + "</i>.<br>Please select the IDs manually.</html>", "Input Error", JOptionPane.ERROR_MESSAGE);
g = null;
}
break;
}
}
if (g == null) {
g = selector.select();
}
if (g != null) {
final PartGroup g2 = g;
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// for some reason, this may be delayed in the AWT Event Queue in order to avoid a HTML form NullPointerException
final GroupAnnualAnalysis a = new GroupAnnualAnalysis(g2);
a.show(g2.getType() + ": " + g2.getIds());
}
});
}
SceneManager.getInstance().hideAllEditPoints();
}
} else // environmental temperature graph
if ("Daily Environmental Temperature".equals(act)) {
if (EnergyPanel.getInstance().checkCity()) {
new DailyEnvironmentalTemperature().showDialog();
}
} else if ("Annual Environmental Temperature".equals(act)) {
if (EnergyPanel.getInstance().checkCity()) {
new AnnualEnvironmentalTemperature().showDialog();
}
} else if ("Monthly Sunshine Hours".equals(act)) {
if (EnergyPanel.getInstance().checkCity()) {
new MonthlySunshineHours().showDialog();
}
} else {
JOptionPane.showMessageDialog(MainFrame.getInstance(), "<html>" + act + "</html>", "Information", JOptionPane.INFORMATION_MESSAGE);
}
}
use of org.concord.energy3d.agents.Agent in project energy3d by concord-consortium.
the class MainApplication method main.
public static void main(final String[] args) {
// testRegex();
System.out.println("Initiating...");
final long t = System.nanoTime();
// checkSingleInstance(MainApplication.class, args);
// startDeadlockDetectionThread();
agents = new ArrayList<Agent>();
// TODO: temporary test code below
// agents.add(new ConformanceChecker("Conformance Checker"));
// agents.add(new EventMinerSheet2("Event Miner Sheet 2"));
// agents.add(new EventMinerSheet3("Event Miner Sheet 3"));
final File testFile = new File(System.getProperty("user.dir"), "test.txt");
// can't use File.canWrite() to check if we can write a file to this folder. So we have to walk extra miles as follows.
try {
testFile.createNewFile();
testFile.delete();
} catch (final Throwable e) {
appDirectoryWritable = false;
}
System.setProperty("jogl.gljpanel.noglsl", "true");
if (System.getProperty("os.name").startsWith("Mac")) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Energy3D");
}
Config.setWebStart(System.getProperty("javawebstart.version", null) != null);
if (!Config.isWebStart()) {
System.setProperty("jogamp.gluegen.UseTempJarCache", "false");
}
final boolean isJarOrEclipse = !Config.isWebStart() && !System.getProperty("java.library.path").contains("jogl");
if (isJarOrEclipse) {
setupLibraryPath();
}
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (final Exception e) {
e.printStackTrace();
}
initializing = true;
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// this calls Swing GUI
final SceneManager sceneManager = SceneManager.getInstance();
// this calls Swing GUI
Scene.getInstance();
sceneManagerThread = new Thread(sceneManager, "Energy3D Main Application");
sceneManagerThread.start();
final MainFrame mainFrame = MainFrame.getInstance();
mainFrame.updateTitleBar();
mainFrame.setVisible(true);
new Thread("Energy3D Open File") {
@Override
public void run() {
try {
if (Config.isMac()) {
Thread.sleep(200);
}
if (isMacOpeningFile) {
return;
}
// somehow newFile() must be called to set up the scene before we can correctly load the content when an NG3 file is double-clicked without an open instance
if (Scene.getURL() == null) {
Scene.newFile();
}
if (Config.isWebStart()) {
if (args.length > 1 && !args[args.length - 1].startsWith("-")) {
mainFrame.open(args[args.length - 1]);
}
} else {
if (args.length > 0) {
mainFrame.open(args[0]);
}
}
} catch (final Exception e) {
e.printStackTrace();
} finally {
initializing = false;
}
}
}.start();
Updater.download();
}
});
/* initialize data logging */
addShutdownHook(new Runnable() {
@Override
public void run() {
TimeSeriesLogger.getInstance().close();
}
});
TimeSeriesLogger.getInstance().start();
SnapshotLogger.getInstance().start(20);
System.out.println("Initiatialization phase 2 done.");
System.out.println("Time = " + (System.nanoTime() - t) / 1000000000.0);
}
Aggregations