1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 import java.util.*; 30 import javax.swing.*; 31 32 public class ClassMethodBreakpointDialog extends JDialog { 33 34 static final int TEXT_COLS = 20; 35 static final int METHOD_COLS = 20; 36 static final int PARAMS_COLS = 42; 37 38 private String mainMsg = "Create a class-line breakpoint"; 39 private JTextField classText = new JTextField(TEXT_COLS); 40 private JTextField methodText = new JTextField(METHOD_COLS); 41 private JTextField paramsText = new JTextField(PARAMS_COLS); 42 43 public ClassMethodBreakpointDialog(Frame frame) { 44 super(frame, "Set a Breakpoint", true); 45 KeyListener george = new KeyAdapter() { 46 public void keyPressed(KeyEvent e) { 47 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 48 setBreakpoint(); 49 } 50 }}; 51 classText.addKeyListener(george); 52 methodText.addKeyListener(george); 53 paramsText.addKeyListener(george); 54 55 JPanel classTextPanel = new JPanel(); 56 classTextPanel.add(classText); 57 classTextPanel.setBorder(BorderFactory.createTitledBorder( 58 BorderFactory.createEmptyBorder(0,0,0,0), "Class")); 59 JPanel methodTextPanel = new JPanel(); 60 methodTextPanel.add(methodText); 61 methodTextPanel.setBorder(BorderFactory.createTitledBorder( 62 BorderFactory.createEmptyBorder(0,0,0,0), "Method")); 63 JPanel topPanel = new JPanel(); 64 topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS)); 65 topPanel.add(classTextPanel); 66 topPanel.add(methodTextPanel); 67 68 JPanel paramsTextPanel = new JPanel(); 69 paramsTextPanel.add(paramsText); 70 paramsTextPanel.setBorder(BorderFactory.createTitledBorder( 71 BorderFactory.createEmptyBorder(0,0,0,0), "Parameters")); 72 JPanel bottomPanel = new JPanel(); 73 bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS)); 74 bottomPanel.add(paramsTextPanel); 75 76 Object [] components = { mainMsg, topPanel, bottomPanel }; 77 78 JButton setButton = new JButton("Set"); 79 setButton.addActionListener(new ActionListener() { 80 public void actionPerformed(ActionEvent e) { 81 setBreakpoint(); 82 }}); 83 JButton clearButton = new JButton("Clear"); 84 clearButton.addActionListener(new ActionListener() { 85 public void actionPerformed(ActionEvent e) { 86 clear(); 87 }}); 88 JButton cancelButton = new JButton("Cancel"); 89 cancelButton.addActionListener(new ActionListener() { 90 public void actionPerformed(ActionEvent e) { 91 cancel(); 92 }}); 93 Object [] buttons = { setButton, clearButton, cancelButton }; 94 95 JOptionPane optionPane = 96 new JOptionPane 97 (components, 98 JOptionPane.QUESTION_MESSAGE, 99 JOptionPane.YES_NO_OPTION, 100 null, 101 buttons, 102 buttons[0]); 103 this.setContentPane(optionPane); 104 this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 105 } 106 107 public ClassMethodBreakpointDialog() { 108 this(null); 109 } 110 111 public void show() { 112 pack(); 113 super.show(); 114 classText.requestFocus(); 115 } 116 117 private void setBreakpoint() { 118 String cmd = "stop in "; 119 String className = classText.getText(); 120 String method = methodText.getText(); 121 String params = ""; 122 StringTokenizer tok = new StringTokenizer(paramsText.getText(), " ;,"); 123 if (tok.hasMoreTokens()) { 124 params += "("; 125 } 126 while (tok.hasMoreTokens()) { 127 params += tok.nextToken(); 128 params += (tok.hasMoreTokens() ? "," : ")"); 129 } 130 cmd += className + "." + method + params; 131 ComponentRepository.getCommandLine().executeCommand(cmd); 132 clear(); 133 hide(); 134 } 135 136 private void clear() { 137 classText.setText(""); 138 methodText.setText(""); 139 paramsText.setText(""); 140 } 141 142 private void cancel() { 143 hide(); 144 } 145 } | Popular Tags |