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 java.awt.Color; 027 import java.net.URL; 028 import java.util.ArrayList; 029 030 import javax.swing.JFrame; 031 import javax.swing.JOptionPane; 032 033 import EVolve.data.DataManager; 034 import EVolve.exceptions.CancelLoadDataException; 035 import EVolve.exceptions.DataProcessingException; 036 import EVolve.exceptions.EVolveException; 037 import EVolve.util.ProgressIndicator; 038 import EVolve.util.ToolsManager; 039 import EVolve.util.settings.SceneSetting; 040 import EVolve.visualization.VisualizationManager; 041 import EVolve.visualization.VizFactory.VisualizationFactory; 042 043 public class Scene { 044 public static final String VERSION = "EVolve 1.2.4"; 045 private static Scene e; 046 047 private DataSourceManager dsm; 048 private DataManager dm; 049 private VisualizationManager vm; 050 private UIManager um; 051 private ToolsManager tm; 052 private Filter filter; 053 private String autoDataFilename; 054 private String currentDataFilename; 055 private boolean dataLoaded; 056 057 private Scene() { 058 } 059 060 public static void start(ArrayList dsList, VisualizationFactory[] factory) { 061 e = new Scene(); 062 063 e.vm = new VisualizationManager(factory); 064 e.dsm = new DataSourceManager(dsList); 065 e.um = new UIManager(); 066 e.tm = new ToolsManager(); 067 068 e.autoDataFilename = null; 069 e.currentDataFilename = "nothing loaded yet.."; 070 071 e.dsm.init(); 072 e.vm.init(); 073 e.um.init(); 074 e.tm.init(); 075 SceneSetting.v().readDataFromFile(); 076 } 077 078 public static DataManager getDataManager() { 079 return e.dm; 080 } 081 082 public static VisualizationManager getVisualizationManager() { 083 return e.vm; 084 } 085 086 public static DataSourceManager getDataSourceManager() { 087 return e.dsm; 088 } 089 090 public static UIManager getUIManager() { 091 return e.um; 092 } 093 094 public static ToolsManager getToolsManager() { 095 return e.tm; 096 } 097 098 public static Filter getFilter() { 099 return e.filter; 100 } 101 102 public static JFrame getFrame() { 103 return e.um.getFrame(); 104 } 105 106 public static void setStatus(String status) { 107 e.um.setStatus(status); 108 } 109 110 public static int getColorRGB() { 111 return e.dm.getColorRGB(); 112 } 113 114 public static Color getColor() { 115 return e.dm.getColor(); 116 } 117 118 public static long getEventCounter() { 119 return e.dm.getEventCounter(); 120 } 121 122 public static Thread loadDataSource() { 123 setStatus("Loading data, please wait."); 124 e.dataLoaded = e.dm.isDataLoaded(); 125 e.filter = new Filter(); 126 Thread thread = new Thread() { 127 public void run() { 128 try { 129 e.um.disableFileMenus(); 130 e.um.disableFunctionMenus(); 131 e.dm.init(); 132 e.um.init(); 133 e.vm.init(); 134 setStatus("Data loaded."); 135 e.dm.setDataLoaded(true); 136 e.um.updateDatasourceCombo(); 137 e.um.enableFileMenus(); 138 e.um.enableMenu(); 139 } catch (CancelLoadDataException exp) { 140 e.dm.setDataLoaded(e.dataLoaded); 141 if (e.dataLoaded) { 142 e.um.updateDatasourceCombo(); 143 e.um.enableMenu(); 144 } 145 e.um.enableFileMenus(); 146 } catch (DataProcessingException exp) { 147 e.dm.setDataLoaded(false); 148 e.um.enableFileMenus(); 149 setStatus(exp.getMessage()); 150 } catch (EVolveException exp) { 151 e.dm.setDataLoaded(false); 152 setStatus(exp.getMessage());//"Invalid data format!"); 153 e.um.enableFileMenus(); 154 } catch (Exception exp) { 155 setStatus("Failed to load trace. Reason: "+exp.getMessage()); 156 e.um.enableFileMenus(); 157 } 158 } 159 }; 160 thread.start(); 161 return thread; 162 } 163 164 public static void autoLoadDataSource() { 165 try { 166 loadDataSource().join(); 167 } catch (InterruptedException e) { 168 169 } 170 } 171 172 public static void visualize() { 173 setStatus("Processing data, please wait."); 174 175 ProcessingThread thread = new ProcessingThread(); 176 ProgressIndicator progress = new ProgressIndicator(getFrame(),e.dm, thread); 177 178 thread.start(); 179 } 180 181 public static void autoVisualize() { 182 setStatus("Processing data, please wait."); 183 184 try { 185 e.dm.sendEvents(); 186 e.vm.visualize(); 187 setStatus("Visualization finished."); 188 } catch (DataProcessingException e) { 189 setStatus(e.getMessage()); 190 } 191 } 192 193 public static String getDataFileName() { 194 return e.autoDataFilename; 195 } 196 197 public static void setDataFilename(String filename) { 198 e.autoDataFilename = filename; 199 if (filename!=null) e.currentDataFilename = filename; 200 } 201 202 public static void clearFilters() { 203 e.filter = new Filter(); 204 } 205 206 public static void showErrorMessage(String msg) { 207 JOptionPane.showMessageDialog(e.um.getDesktop(),msg,"Error Message",JOptionPane.ERROR_MESSAGE); 208 } 209 210 public static void setCurrentDataFilename(String filename) { 211 e.currentDataFilename = filename; 212 } 213 214 public static String getCurrentDataFilename() { 215 return e.currentDataFilename; 216 } 217 218 public static void selectDataSource(DataManager dm, Filter filter) { 219 e.dm = dm; 220 e.filter = filter; 221 } 222 223 public static URL getGifURL(String filename) { 224 return e.getClass().getResource("img/"+filename); 225 } 226 }