1 24 25 26 package org.aspectj.tools.ajbrowser; 27 28 import java.util.*; 29 import java.awt.Frame ; 30 import javax.swing.JPanel ; 31 import javax.swing.JFrame ; 32 import java.io.*; 33 import org.aspectj.ajde.*; 34 import org.aspectj.ajde.ui.*; 35 import org.aspectj.ajde.internal.*; 36 import org.aspectj.ajde.ui.internal.*; 37 import org.aspectj.ajde.ui.swing.*; 38 39 44 public class BrowserManager { 45 46 private static final BrowserManager INSTANCE = new BrowserManager(); 47 private BrowserProperties browserProjectProperties; 48 49 public static BrowserManager getDefault() { 50 return INSTANCE; 51 } 52 53 private List configFiles = new ArrayList(); 54 55 public static final String TITLE = "AspectJ Browser"; 56 57 private static TopFrame topFrame = null; 58 59 public void init(String [] configFilesArgs, boolean visible) { 60 try { 61 UserPreferencesAdapter preferencesAdapter = new UserPreferencesStore(); 62 browserProjectProperties = new BrowserProperties(preferencesAdapter); 63 TaskListManager taskListManager = new CompilerMessagesPanel(); 64 BasicEditor ajdeEditor = new BasicEditor(); 65 BrowserUIAdapter browserUIAdapter = new BrowserUIAdapter(); 66 topFrame = new TopFrame(); 67 configFiles = getConfigFilesList(configFilesArgs); 68 69 AjdeUIManager.getDefault().init( 70 ajdeEditor, 71 taskListManager, 72 browserProjectProperties, 73 preferencesAdapter, 74 browserUIAdapter, 75 new IconRegistry(), 76 topFrame, 77 true); 78 79 Ajde.getDefault().getBuildManager().addListener(BUILD_MESSAGES_LISTENER); 80 81 MultiStructureViewPanel multiViewPanel = new MultiStructureViewPanel( 82 AjdeUIManager.getDefault().getViewManager().getBrowserPanel(), 83 AjdeUIManager.getDefault().getFileStructurePanel() 84 ); 85 86 topFrame.init( 87 multiViewPanel, 88 (CompilerMessagesPanel)taskListManager, 89 Ajde.getDefault().getEditorManager().getEditorPanel() 90 ); 91 92 if (visible) topFrame.setVisible(true); 93 94 if (configFiles.size() == 0) { 95 Ajde.getDefault().getErrorHandler().handleWarning( 96 "No build configuration selected. " 97 + "Select a \".lst\" build configuration file in order to compile and navigate structure."); 98 } else { 99 } 101 102 AjdeUIManager.getDefault().getOptionsFrame().addOptionsPanel(new BrowserOptionsPanel()); 103 104 109 if (configFilesArgs.length > 0 && configFilesArgs[0] != null) { 110 Ajde.getDefault().getConfigurationManager().setActiveConfigFile(configFilesArgs[0]); 111 } 112 } catch (Throwable t) { 113 t.printStackTrace(); 114 Ajde.getDefault().getErrorHandler().handleError( 115 "AJDE failed to initialize.", 116 t); 117 } 118 } 119 120 public void resetEditorFrame() { 121 topFrame.resetSourceEditorPanel(); 122 } 123 124 public void resetEditor() { 125 BrowserManager.getDefault().getRootFrame().setSize(BrowserManager.getDefault().getRootFrame().getWidth()+1, BrowserManager.getDefault().getRootFrame().getHeight()+1); 126 BrowserManager.getDefault().getRootFrame().doLayout(); 127 BrowserManager.getDefault().getRootFrame().repaint(); 128 } 129 130 public void setStatusInformation(String text) { 131 topFrame.statusText_label.setText(text); 132 } 133 134 public void setEditorStatusText(String text) { 135 topFrame.setTitle(BrowserManager.TITLE + " - " + text); 136 } 137 138 public void run() { 139 Runner.run(Ajde.getDefault().getProjectProperties().getClassToExecute()); 140 } 141 142 public void saveAll() { 143 Ajde.getDefault().getEditorManager().saveContents(); 144 } 145 146 public void showMessages() { 147 topFrame.showMessagesPanel(); 148 } 149 150 public void hideMessages() { 151 topFrame.hideMessagesPanel(); 152 } 153 154 public JFrame getRootFrame() { 155 return topFrame; 156 } 157 158 public void openFile(String filePath) { 159 try { 160 if (filePath.endsWith(".lst")) { 161 AjdeUIManager.getDefault().getBuildConfigEditor().openFile(filePath); 162 topFrame.setEditorPanel(AjdeUIManager.getDefault().getBuildConfigEditor()); 163 } else if (filePath.endsWith(".java") || filePath.endsWith(".aj")){ 164 Ajde.getDefault().getEditorManager().showSourceLine(filePath, 0, false); 165 } else { 166 Ajde.getDefault().getErrorHandler().handleError("File: " + filePath 167 + " could not be opened because the extension was not recoginzed."); 168 } 169 } catch (IOException ioe) { 170 Ajde.getDefault().getErrorHandler().handleError("Could not open file: " + filePath, ioe); 171 } catch (InvalidResourceException ire) { 172 Ajde.getDefault().getErrorHandler().handleError("Invalid file: " + filePath, ire); 173 } 174 175 browserProjectProperties.setLastOpenSourceFilePath(filePath); 176 } 177 178 private List getConfigFilesList(String [] configFiles) { 179 List configs = new ArrayList(); 180 for (int i = 0; i < configFiles.length; i++) { 181 if (configFiles[i].endsWith(BuildConfigManager.CONFIG_FILE_SUFFIX)) { 182 configs.add(configFiles[i]); 183 } 184 } 185 return configs; 186 } 187 188 private static class Runner { 189 public static void run(String className) { 190 try { 191 Process p = Runtime.getRuntime().exec("java " 192 + className); 194 } catch(IOException ioe) { 195 Ajde.getDefault().getErrorHandler().handleError("Coud not run: " + className, ioe); 196 } 197 } 198 199 public static void invoke(String className) { 200 try { 201 if (className == null || className.length() == 0) { 202 Ajde.getDefault().getErrorHandler().handleWarning("No main class specified, please select a class to run."); 203 204 } else { 205 Class [] argTypes = { String [].class }; 206 java.lang.reflect.Method method = Class.forName(className).getDeclaredMethod("main", argTypes); 207 Object [] args = { new String [0] }; 208 method.invoke(null, args); 209 } 210 } catch(ClassNotFoundException cnfe) { 211 Ajde.getDefault().getErrorHandler().handleWarning("Main class not found: " + className + 212 "\nMake sure that you have \".\" on your classpath."); 213 } catch(NoSuchMethodException nsme) { 214 Ajde.getDefault().getErrorHandler().handleWarning("Class: " + className + " does not declare public static void main(String[])"); 215 } catch(java.lang.reflect.InvocationTargetException ite) { 216 Ajde.getDefault().getErrorHandler().handleWarning("Could not execute: " + className); 217 } catch(IllegalAccessException iae) { 218 Ajde.getDefault().getErrorHandler().handleWarning("Class: " + className + " does not declare public main method"); 219 } 220 } 221 } 222 223 private final BuildListener BUILD_MESSAGES_LISTENER = new BuildListener() { 224 225 public void compileStarted(String buildConfigFile) { } 226 227 public void compileFinished(String buildConfigFile, int buildTime, boolean succeeded, boolean warnings) { 228 int timeInSeconds = buildTime/1000; 229 if (succeeded && !warnings) { 230 hideMessages(); 231 } else { 232 showMessages(); 233 } 234 } 235 236 public void compileAborted(String buildConfigFile, String message) { } 237 }; 238 239 public List getConfigFiles() { 240 return configFiles; 241 } 242 243 public BrowserProperties getBrowserProjectProperties() { 244 return browserProjectProperties; 245 } 246 } 247 | Popular Tags |