1 22 23 package org.aspectj.tools.ajdb; 24 25 import org.aspectj.debugger.gui.ComponentDirector; 26 import org.aspectj.debugger.tty.CommandLineDebugger; 27 import org.aspectj.debugger.ide.FullPathSourceShower; 28 import org.aspectj.debugger.ide.SourceShower; 31 import org.aspectj.debugger.ide.IDEInterface; 32 import org.aspectj.debugger.ide.IDEInterfaceImpl; 33 34 import org.aspectj.util.gui.CenteredJFrame; 35 36 import java.awt.Container ; 37 import java.awt.Component ; 38 import java.awt.event.ActionEvent ; 39 import javax.swing.*; 40 41 import java.util.Collection ; 42 import java.util.Iterator ; 43 import java.util.Vector ; 44 45 public class Main { 46 public static void main(String [] args) { 47 new Main().debug(args); 48 } 49 50 public Main() {} 51 52 62 public CommandLineDebugger debug(String [] args) { 63 64 CommandLineDebugger debugger = null; 66 67 boolean launch = false; 70 boolean gui = false; 71 boolean forte = false; 72 boolean jbuilder = false; 73 74 boolean wantsToExit = true; 78 79 SourceShower shower = FullPathSourceShower.proto; 81 82 IDEInterface ide = IDEInterfaceImpl.proto; 84 85 for (int i = 0; i < args.length; i++) { 88 if (args[i].equals("-noexit")) { 89 wantsToExit = false; 90 System.setProperty("no.logger", "true"); 91 args = shift(args, i--); 92 } else if (args[i].equals("-launch")) { 93 launch = true; 94 args = shift(args, i--); 95 } else if (args[i].equals("-gui")) { 96 gui = true; 97 args = shift(args, i--); 98 } else if (args[i].equals("-forte")) { 99 forte = true; 100 args = shift(args, i--); 101 } else if (args[i].equals("-jbuilder")) { 102 jbuilder = true; 103 args = shift(args, i--); 104 } else if (args[i].equals("-ide")) { 105 args = shift(args, i); 106 try { 107 ide = (IDEInterface)Class.forName(args[i]).newInstance(); 108 } catch (Throwable t) { t.printStackTrace(); } 109 args = shift(args, i); 110 } else if (args[i].equals("-shower")) { 111 args = shift(args, i); 112 try { 113 shower = (SourceShower)Class.forName(args[i]).newInstance(); 114 } catch (Throwable t) { t.printStackTrace(); } 115 args = shift(args, i); 116 } 117 } 118 119 126 137 if (gui) { 149 new ComponentDirector(args).go(); 150 } 151 debugger = new CommandLineDebugger(args); 152 if (!gui) { 153 debugger.setWantsToExit(wantsToExit); 154 } 155 156 debugger.go(); 158 return debugger; 159 } 160 161 164 private String [] shift(String [] args, int i) { 165 String [] newArgs = new String [args.length - 1]; 166 System.arraycopy(args, 0, newArgs, 0, i); 167 System.arraycopy(args, i+1, newArgs, i, args.length-i-1); 168 return newArgs; 169 } 170 171 185 199 private abstract class AbstractLauncher extends CenteredJFrame { 200 private final static int TEXT_WIDTH = 30; 201 private JTextField mainClassField = new JTextField(TEXT_WIDTH); 202 private JTextField classpathField = new JTextField(TEXT_WIDTH); 203 private JTextField sourcepathField = new JTextField(TEXT_WIDTH); 204 protected SourceShower shower; 205 protected IDEInterface ide; 206 protected SourceShower shower() { return shower; } 207 { 208 mainClassField.setText("New"); 209 sourcepathField.setText("C:/ajdb-src"); 210 } 211 protected String []args = null; 212 private JButton launchButton = 213 new JButton(new AbstractAction("Launch debugger") { 214 public void actionPerformed(ActionEvent e) { 215 launch(); 216 setVisible(false); 217 dispose(); 218 } 219 }); 220 private void launch() { 221 Collection list = new Vector (); 222 for (int i = 0; i < args.length; i++) { 223 list.add(args[i]); 224 } 225 add(list, "-classpath", classpathField); 226 add(list, "-sourcepath", sourcepathField); 227 add(list, "-now", mainClassField); 228 System.out.println("args: " + list); 229 String [] newArgs = new String [list.size()]; 230 Iterator iter = list.iterator(); 231 int i = 0; 232 while (iter.hasNext()) { 233 newArgs[i++] = iter.next() + ""; 234 } 235 ComponentDirector cd = debugger(newArgs); 236 cd.go(); 237 } 238 private void add(Collection list, String arg, JTextField field) { 239 String text = field.getText().trim(); 240 if (text == null || text.length() == 0) return; 241 if (arg.length() > 0) { 242 list.add(arg); 243 list.add(text); 244 } else { 245 list.add(text); 246 } 247 } 248 protected abstract ComponentDirector debugger(String [] args); 249 protected abstract String getIDEName(); 250 AbstractLauncher(String [] args, SourceShower shower, IDEInterface ide) { 251 super(); 252 setTitle(getIDEName() + " Debugger Launcher"); 253 this.args = args; 254 this.shower = shower; 255 this.ide = ide; 256 Container c = getContentPane(); 257 c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); 258 c.add(p("Main class", mainClassField)); 259 c.add(p("Class path", classpathField)); 260 c.add(p("Source path", sourcepathField)); 261 c.add(launchButton); 262 launchButton.requestFocus(); 263 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 264 } 265 void go() { 266 pack(); 267 setVisible(true); 268 } 269 private Component p(String title, Component c2) { 270 JPanel p = new JPanel(); 271 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); 272 p.add(new JLabel(title + ": ")); 273 p.add(c2); 274 return p; 275 } 276 277 } 278 } 279 | Popular Tags |