001 /* EVolve - an Extensible Software Visualization Framework 002 * Copyright (C) 2001-2002 Qin Wang 003 * 004 * This library is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Library General Public 006 * License as published by the Free Software Foundation; either 007 * version 2 of the License, or (at your option) any later version. 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Library General Public License for more details. 013 * 014 * You should have received a copy of the GNU Library General Public 015 * License along with this library; if not, write to the 016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 017 * Boston, MA 02111-1307, USA. 018 */ 019 020 /* 021 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/ 022 */ 023 024 package EVolve; 025 026 import EVolve.data.*; 027 import EVolve.visualization.*; 028 import EVolve.util.*; 029 import java.awt.*; 030 import javax.swing.*; 031 032 public class Scene { 033 public static final String VERSION = "EVolve 1.2"; 034 private static Scene e; 035 036 private DataManager dm; 037 private VisualizationManager vm; 038 private UIManager um; 039 private ToolsManager tm; 040 private Filter filter; 041 private String autoDataFilename; 042 private String currentDataFilename; 043 044 private Scene() { 045 } 046 047 public static void start(DataSource dataSource, VisualizationFactory[] factory) { 048 e = new Scene(); 049 050 e.dm = new DataManager(dataSource); 051 e.vm = new VisualizationManager(factory); 052 e.um = new UIManager(); 053 e.tm = new ToolsManager(); 054 e.filter = new Filter(); 055 e.autoDataFilename = null; 056 e.currentDataFilename = "nothing loaded yet.."; 057 058 e.vm.init(); 059 e.um.init(); 060 SceneSetting.v().initialScene(); 061 } 062 063 public static DataManager getDataManager() { 064 return e.dm; 065 } 066 067 public static VisualizationManager getVisualizationManager() { 068 return e.vm; 069 } 070 071 public static UIManager getUIManager() { 072 return e.um; 073 } 074 075 public static ToolsManager getToolsManager() { 076 return e.tm; 077 } 078 079 public static Filter getFilter() { 080 return e.filter; 081 } 082 083 public static JFrame getFrame() { 084 return e.um.getFrame(); 085 } 086 087 public static void setStatus(String status) { 088 e.um.setStatus(status); 089 } 090 091 public static int getColorRGB() { 092 return e.dm.getColorRGB(); 093 } 094 095 public static Color getColor() { 096 return e.dm.getColor(); 097 } 098 099 public static int getEventCounter() { 100 return e.dm.getEventCounter(); 101 } 102 103 public static void loadDataSource() { 104 setStatus("Loading data, please wait."); 105 e.filter = new Filter(); 106 Thread thread = new Thread() { 107 public void run() { 108 try { 109 e.um.disableFileMenus(); 110 e.vm.init(); 111 e.um.init(); 112 e.dm.init(); 113 setStatus("Data loaded."); 114 e.um.enableFileMenus(); 115 e.um.enableMenu(); 116 } catch (DataProcessingException exp) { 117 e.um.enableFileMenus(); 118 setStatus(exp.getMessage()); 119 } 120 } 121 }; 122 thread.start(); 123 } 124 125 public static void autoLoadDataSource() { 126 setStatus("Loading data, please wait."); 127 e.filter = new Filter(); 128 try { 129 e.um.disableFileMenus(); 130 e.vm.init(); 131 e.um.init(); 132 e.dm.init(); 133 setStatus("Data loaded."); 134 e.um.enableFileMenus(); 135 e.um.enableMenu(); 136 } catch (DataProcessingException exp) { 137 e.um.enableFileMenus(); 138 setStatus(exp.getMessage()); 139 } 140 } 141 142 public static void visualize() { 143 setStatus("Processing data, please wait."); 144 145 Thread thread = new Thread() { 146 public void run() { 147 try { 148 e.dm.sendEvents(); 149 e.vm.visualize(); 150 e.um.endTimer(); 151 setStatus("Visualization finished."); 152 } catch (DataProcessingException e) { 153 setStatus(e.getMessage()); 154 } 155 } 156 }; 157 thread.start(); 158 e.um.startTimer(); 159 } 160 161 public static void autoVisualize() { 162 setStatus("Processing data, please wait."); 163 164 try { 165 e.dm.sendEvents(); 166 e.vm.visualize(); 167 setStatus("Visualization finished."); 168 } catch (DataProcessingException e) { 169 setStatus(e.getMessage()); 170 } 171 } 172 173 public static String getDataFileName() { 174 return e.autoDataFilename; 175 } 176 177 public static void setDataFilename(String filename) { 178 e.autoDataFilename = filename; 179 if (filename!=null) e.currentDataFilename = filename; 180 } 181 182 public static void clearFilters() { 183 e.filter = new Filter(); 184 } 185 186 public static void showErrorMessage(String msg) { 187 JOptionPane.showMessageDialog(null,msg); 188 189 } 190 191 public static void setCurrentDataFilename(String filename) { 192 e.currentDataFilename = filename; 193 } 194 195 public static String getCurrentDataFilename() { 196 return e.currentDataFilename; 197 } 198 }