1 24 package org.aspectj.debugger.gui; 25 26 import java.awt.*; 27 import java.awt.event.*; 28 import javax.swing.*; 29 import org.aspectj.util.gui.*; 30 31 37 public abstract class LineBreakpointDialog extends CenteredJDialog { 38 39 private GUIDebugger guid; 40 protected GUIDebugger guid() { 41 return guid; 42 } 43 protected Frame gui() { 44 return guid != null ? guid.getGui() : null; 45 } 46 47 private final static int TEXT_WIDTH = 30; 48 private final static int LINE_WIDTH = 10; 49 private final static String CLASS_NAME_STR = "Class name:"; 50 private final static String FILE_NAME_STR = "File name:"; 51 private final static String LINE_NUMBER_STR = "Line number:"; 52 private final static String METHOD_STR = "Method:"; 53 54 private JTextField classNameField = new JTextField(TEXT_WIDTH); 55 private JTextField fileNameField = new JTextField(TEXT_WIDTH); 56 private JTextField lineNumberField = new JTextField(LINE_WIDTH); 57 { 58 lineNumberField.setFocusAccelerator('n'); 59 } 60 private JTextField methodField = new JTextField(TEXT_WIDTH); 61 { 62 methodField.setFocusAccelerator('m'); 63 } 64 private JLabel lineNumberLabel = jlabel(LINE_NUMBER_STR); 65 { 66 lineNumberLabel.setLabelFor(lineNumberField); 67 lineNumberLabel.setDisplayedMnemonic('n'); 68 } 69 private JLabel methodLabel = jlabel(METHOD_STR); 70 { 71 methodLabel.setLabelFor(methodField); 72 methodLabel.setDisplayedMnemonic('m'); 73 } 74 private JRadioButton classNameRadioButton = 75 new JRadioButton(new ClassNameSelectAction()); 76 { 77 classNameRadioButton.setSelected(true); 78 classNameRadioButton.setMnemonic('a'); 79 } 80 private JRadioButton fileNameRadioButton = 81 new JRadioButton(new FileNameSelectAction()); 82 { 83 fileNameRadioButton.setMnemonic('F'); 84 } 85 private ButtonGroup buttonGroup = new ButtonGroup(); 86 { 87 88 buttonGroup.add(classNameRadioButton); 89 buttonGroup.add(fileNameRadioButton); 90 } 91 private JButton classNameButton = new JButton(new FindClassNameAction()); 92 private JButton fileNameButton = new JButton(new FindFileNameAction()); 93 private JButton okButton = new JButton(new OKAction()); 94 private JButton cancelButton = new JButton(new CancelAction()); 95 96 private final class ClassNameSelectAction extends AbstractAction { 97 public ClassNameSelectAction() { 98 super(CLASS_NAME_STR); 99 } 100 public void actionPerformed(ActionEvent e) { 101 fileNameField.setEnabled(false); 102 fileNameButton.setEnabled(false); 103 classNameField.setEnabled(true); 104 classNameButton.setEnabled(true); 105 methodField.setEnabled(true); 106 } 107 } 108 109 private final class FileNameSelectAction extends AbstractAction { 110 public FileNameSelectAction() { 111 super(FILE_NAME_STR); 112 } 113 public void actionPerformed(ActionEvent e) { 114 classNameField.setEnabled(false); 115 classNameButton.setEnabled(false); 116 methodField.setEnabled(false); 117 fileNameField.setEnabled(true); 118 fileNameButton.setEnabled(true); 119 } 120 } 121 122 private final class FindClassNameAction extends AbstractAction { 123 public FindClassNameAction() { 124 super("..."); 125 } 126 public void actionPerformed(ActionEvent e) { 127 classNameField.setText(findClassName()); 128 } 129 } 130 131 private final class FindFileNameAction extends AbstractAction { 132 public FindFileNameAction() { 133 super("..."); 134 } 135 public void actionPerformed(ActionEvent e) { 136 fileNameField.setText(findFileName()); 137 } 138 } 139 140 private final class OKAction extends AbstractAction { 141 public OKAction() { 142 super("OK"); 143 } 144 public void actionPerformed(ActionEvent e) { 145 ok(); 146 } 147 } 148 149 private final class CancelAction extends AbstractAction { 150 public CancelAction() { 151 super("Cancel"); 152 } 153 public void actionPerformed(ActionEvent e) { 154 cancel(); 155 } 156 } 157 158 public abstract String findClassName(); 159 public abstract String findFileName(); 160 161 public LineBreakpointDialog(GUIDebugger guid) { 162 super(guid != null ? guid.getGui() : null, 163 "Add Line Breakpoint", true); 164 this.guid = guid; 165 if (guid == null) { 166 addWindowListener(new WindowAdapter() { 167 public void windowClosing(WindowEvent we) { 168 System.exit(0); 169 } 170 }); 171 } 172 173 JPanel lineBreakpointPanel = new JPanel(); 174 lineBreakpointPanel.setBorder(BorderFactory.createTitledBorder 175 ("Line Breakpoint")); 176 GridBagConstraints c = new GridBagConstraints(); 177 c.fill = GridBagConstraints.EAST; 178 c.weightx = 0.5; 179 c.weighty = 0.5; 180 c.anchor = GridBagConstraints.WEST; 181 GridBagLayout gb = new GridBagLayout(); 182 gb.setConstraints(lineBreakpointPanel, c); 183 lineBreakpointPanel.setLayout(gb); 184 int gridy = 0; 185 186 c.gridx = 0; 187 c.gridy = gridy; 188 gb.setConstraints(classNameRadioButton, c); 189 lineBreakpointPanel.add(classNameRadioButton); 190 c.gridx = 1; 191 c.gridy = gridy; 192 gb.setConstraints(classNameField, c); 193 lineBreakpointPanel.add(classNameField); 194 c.gridx = 2; 195 c.gridy = gridy++; 196 gb.setConstraints(classNameButton, c); 197 lineBreakpointPanel.add(classNameButton); 198 199 c.gridx = 0; 200 c.gridy = gridy; 201 gb.setConstraints(fileNameRadioButton, c); 202 lineBreakpointPanel.add(fileNameRadioButton); 203 c.gridx = 1; 204 c.gridy = gridy; 205 gb.setConstraints(fileNameField, c); 206 lineBreakpointPanel.add(fileNameField); 207 c.gridx = 2; 208 c.gridy = gridy++; 209 gb.setConstraints(fileNameButton, c); 210 lineBreakpointPanel.add(fileNameButton); 211 212 c.gridx = 0; 213 c.gridy = gridy; 214 gb.setConstraints(lineNumberLabel, c); 215 lineBreakpointPanel.add(lineNumberLabel); 216 c.gridx = 1; 217 c.gridy = gridy++; 218 gb.setConstraints(lineNumberField, c); 219 lineBreakpointPanel.add(lineNumberField); 220 221 JPanel bottomPanel = new JPanel(); 222 bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); 223 bottomPanel.add(okButton); 224 bottomPanel.add(cancelButton); 225 226 getContentPane().setLayout(new BoxLayout(getContentPane(), 227 BoxLayout.Y_AXIS)); 228 getContentPane().add(lineBreakpointPanel); 229 getContentPane().add(bottomPanel); 230 } 231 232 private void ok() { 233 try { 234 if (ok_()) { 235 dispose(); 236 } 237 } catch (Throwable t) { 238 AJUtil.error(t); 239 } 240 } 241 242 private boolean ok_() throws Throwable { 243 int lineNumber = Integer.parseInt(lineNumberField.getText().trim()); 244 if (classNameRadioButton.isSelected()) { 245 String className = classNameField.getText(); 246 if (className == null) className = ""; 247 className = className.trim(); 248 if (className.equals("")) { 249 throw new Error ("Class name cannot be empty"); 250 } 251 if (guid != null) { 252 guid.getDebugger().stopAtCommand(className, 253 lineNumber); 254 return true; 255 } else { 256 System.out.println("className=" + className + 257 " line=" + lineNumber); 258 } 259 } 260 if (fileNameRadioButton.isSelected()) { 261 String fileName = fileNameField.getText(); 262 if (fileName == null) fileName = ""; 263 fileName = fileName.trim(); 264 if (fileName.equals("")) { 265 throw new Error ("File name cannot be empty"); 266 } 267 if (guid != null) { 268 guid.getDebugger().stopOnCommand(fileName, lineNumber); 269 return true; 270 } else { 271 System.out.println("fileName=" + fileName + 272 " line=" + lineNumber); 273 } 274 } 275 return false; 276 } 277 278 private void cancel() { 279 dispose(); 280 } 281 282 private JLabel jlabel(String str) { 283 JLabel label = new JLabel(str); 284 label.setForeground(Color.black); 285 return label; 286 } 287 } 288 | Popular Tags |