1 22 package org.aspectj.debugger.gui; 23 24 import org.aspectj.debugger.base.*; 25 import org.aspectj.util.gui.*; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 import javax.swing.*; 30 import java.util.*; 31 import java.util.List ; 32 import java.io.*; 33 34 import com.sun.jdi.*; 35 36 public class Dialogs { 37 38 public static void showBreakpointDialog() { 39 new BreakpointDialog(ComponentRepository. 40 getComponentDirector()).show(); 41 } 42 43 public static void showSetBreakpointDialog() { 44 new SetBreakpointDialog(ComponentRepository. 45 getComponentDirector()).show(); 46 } 47 48 public static void showClearBreakpointDialog() { 49 new ClearBreakpointDialog(ComponentRepository. 50 getComponentDirector()).show(); 51 } 52 53 public static void showNewValueDialog(AJValueNode node) { 54 new AJNewValueDialog(ComponentRepository. 55 getComponentDirector(), node).popup(node); 56 } 57 58 public static void showRunDialog() { 59 new RunDialog().show(); 60 } 61 62 public static void showCatchDialog() { 63 new CatchDialog().show(); 64 } 65 66 public static void showWatchDialog() { 67 new WatchDialog().show(); 68 } 69 70 public static void showUseDialog() { 71 new UseDialog().show(); 72 } 74 75 public static void showDumpDialog() { 76 new DumpDialog().show(); 77 } 78 79 public static void showEvalDialog() { 80 new EvalDialog().show(); 81 } 82 83 public static void showFieldsDialog() { 84 new FieldsDialog().show(); 85 } 86 87 public static void showLocalsDialog() { 88 new LocalsDialog().show(); 89 } 90 91 public static void showPrintDialog() { 92 new PrintDialog().show(); 93 } 94 95 public static String showSuspendDialog() { 96 return showThreadDialog("suspend", "Suspend"); 97 } 98 99 public static String showResumeDialog() { 100 return showThreadDialog("resume", "Ruspend"); 101 } 102 103 public static String showWhereDialog() { 104 return showThreadDialog("view", "View"); 105 } 106 107 public static void showHelpDialog() { 108 109 } 110 111 public static void showExecuteDialog() { 112 new ExecuteDialog().show(); 113 } 114 115 public static void showAboutDialog() { 116 String msg = "by the aspectj.org team (C)"; 117 msg += "\n" + ComponentRepository.getAJDebugger().version(); 118 int type = JOptionPane.INFORMATION_MESSAGE; 119 String title = "About AJBuilder"; 120 JOptionPane.showMessageDialog 121 (ComponentRepository.getComponentDirector(), 122 msg, 123 title, 124 type); 125 } 126 127 static String showThreadDialog(String msg, String action) { 128 try { 129 Iterator iter = ComponentRepository.getAJDebugger().vm(). 130 allThreads().iterator(); 131 Vector v = new Vector(); 132 v.add(new AJToolBar.ThreadPair("All threads", -1)); 133 while (iter.hasNext()) { 134 Object o = iter.next(); 135 ThreadReference thread = 136 (ThreadReference)iter.next(); String name = thread.name(); 138 long id = thread.uniqueID(); 139 AJToolBar.ThreadPair pair = new AJToolBar.ThreadPair(name, id); 140 v.add(pair); 141 } 142 Object [] os = v.toArray(); 143 AJToolBar.ThreadPair selected = 144 (AJToolBar.ThreadPair) 145 JOptionPane.showInputDialog 146 (ComponentRepository.getComponentDirector(), 147 "Please select a thread to " + msg, 148 action + " a thread", 149 JOptionPane.QUESTION_MESSAGE, 150 null, 151 os, 152 os[0]); 153 if (selected != null && selected.id != -1) { 154 return selected.id + ""; 155 } 156 } catch (Exception e) { 157 } 158 return null; 159 } 160 161 public void showMonitorDialog() { 162 new MonitorDialog(ComponentRepository.getGUIDebugger()).show(); 163 } 164 165 public static void main(String [] args) { 166 String s = showSuspendDialog(); 167 System.out.println("> " + s); 168 } 169 } 170 171 class UseFileChooser extends JFileChooser { 172 public UseFileChooser() { 173 super("."); 174 } 175 176 public javax.swing.filechooser.FileFilter getFileFilter() { 177 return new javax.swing.filechooser.FileFilter () { 178 public boolean accept(File file) { 179 return file.isDirectory(); 180 } 181 public String getDescription() { 182 return "Paths to source files"; 183 } 184 }; 185 } 186 187 public void use() { 188 int val = showDialog(null, "Use"); 189 if (val != APPROVE_OPTION) return; 190 String sourcePath = getSelectedFile().getAbsolutePath(); 191 try { 192 ComponentRepository.getAJDebugger(). 193 useCommand(sourcePath); 194 } catch (DebuggerException de) { 195 } 196 } 197 } 198 199 class UseDialog extends SingleCommandDialog { 200 public UseDialog() { 201 super("Use", "Please select the source path", 202 "use", "Set"); 203 } 204 } 205 206 207 class RunDialog extends SingleCommandDialog { 208 public RunDialog() { 209 super("Run", "Please select a class to run", 210 "run", "Run"); 211 } 212 } 213 214 class CatchDialog extends SingleCommandDialog { 215 public CatchDialog() { 216 super("Catch", "Please select an exception class to catch", 217 "catch", "Catch"); 218 } 219 } 220 221 class WatchDialog extends SingleCommandDialog { 222 public WatchDialog() { 223 super("Watch", "Please select a field", 224 "watch access", "Watch"); 225 } 226 } 227 228 class DumpDialog extends SingleCommandDialog { 229 public DumpDialog() { 230 super("Dump", "Please select an object to dump", 231 "dump", "Dump"); 232 } 233 } 234 235 class PrintDialog extends SingleCommandDialog { 236 public PrintDialog() { 237 super("Print", "Please select a instance of value to print", 238 "print", "Print"); 239 } 240 } 241 242 class EvalDialog extends SingleCommandDialog { 243 public EvalDialog() { 244 super("Evaluate", "Please select a instance of value to evaluate", 245 "eval", "Evaluate"); 246 } 247 } 248 249 class FieldsDialog extends SingleCommandDialog { 250 public FieldsDialog() { 251 super("Fields", "Please select an object", 252 "fields", "View Fields"); 253 } 254 } 255 256 class LocalsDialog extends SingleCommandDialog { 257 public LocalsDialog() { 258 super("Locals", "Please select an object", 259 "locals", "View Locals"); 260 } 261 } 262 263 class ExecuteDialog extends SingleCommandDialog { 264 public ExecuteDialog() { 265 super("Execute", "Please enter a command", 266 null, "Execute"); 267 } 268 } 269 270 271 class SingleCommandDialog extends CenteredJDialog { 272 273 ClassTextField field = new ClassTextField(30); 274 String commandStr = null; 275 276 public SingleCommandDialog(String titleStr, String labelStr, 277 String commandStr, String buttonStr) { 278 super(ComponentRepository.getComponentDirector(), titleStr, true); 279 this.commandStr = commandStr; 280 JPanel panel = new JPanel(); 281 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 282 JLabel title = new JLabel(labelStr); 283 field.addActionListener(new ActionListener() { 284 public void actionPerformed(ActionEvent e) { 285 doStuff(); 286 }}); 287 JPanel buttons = new JPanel(); 288 JButton stuffButton = new JButton(buttonStr); 289 stuffButton.addActionListener(new ActionListener() { 290 public void actionPerformed(ActionEvent e) { 291 doStuff(); 292 }}); 293 JButton cancelButton = new JButton("Cancel"); 294 cancelButton.addActionListener(new ActionListener() { 295 public void actionPerformed(ActionEvent e) { 296 cancel(); 297 }}); 298 buttons.add(stuffButton); 299 buttons.add(cancelButton); 300 panel.add(title); 301 panel.add(field); 302 panel.add(buttons); 303 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 304 setContentPane(panel); 305 } 306 307 private void doStuff() { 308 String cmd = field.getText(); 309 String commandPrefix = commandStr != null ? commandStr + " " : ""; 310 ComponentRepository.getAJDebugger().execute(commandPrefix + cmd); 311 dispose(); 312 } 313 314 private void cancel() { 315 dispose(); 316 } 317 } 318 319 class MonitorDialog extends CenteredJFrame { 320 321 GUIDebugger guid; 322 323 public MonitorDialog(GUIDebugger guid) { 324 this.guid = guid; 325 } 326 } 327 | Popular Tags |