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 javax.swing.*; 30 31 public class ClassLineBreakpointDialog extends JDialog { 32 33 static final int TEXT_COLS = 20; 34 static final int LINE_COLS = 5; 35 36 private String mainMsg = "Create a class-line breakpoint"; 37 private JTextField classText = new JTextField(TEXT_COLS); 38 private JTextField lineText = new JTextField(LINE_COLS); 39 40 public ClassLineBreakpointDialog(Frame frame) { 41 super(frame, "Set a Breakpoint", true); 42 classText.addKeyListener(new KeyAdapter() { 43 public void keyPressed(KeyEvent e) { 44 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 45 setBreakpoint(); 46 } 47 }}); 48 lineText.addKeyListener(new KeyAdapter() { 49 public void keyPressed(KeyEvent e) { 50 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 51 setBreakpoint(); 52 } 53 }}); 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 lineTextPanel = new JPanel(); 60 lineTextPanel.add(lineText); 61 lineTextPanel.setBorder(BorderFactory.createTitledBorder( 62 BorderFactory.createEmptyBorder(0,0,0,0), "Line")); 63 JPanel mainPanel = new JPanel(); 64 mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS)); 65 mainPanel.add(classTextPanel); 66 mainPanel.add(lineTextPanel); 67 Object [] components = { mainMsg, mainPanel }; 68 69 JButton setButton = new JButton("Set"); 70 setButton.addActionListener(new ActionListener() { 71 public void actionPerformed(ActionEvent e) { 72 setBreakpoint(); 73 }}); 74 JButton clearButton = new JButton("Clear"); 75 clearButton.addActionListener(new ActionListener() { 76 public void actionPerformed(ActionEvent e) { 77 clear(); 78 }}); 79 JButton cancelButton = new JButton("Cancel"); 80 cancelButton.addActionListener(new ActionListener() { 81 public void actionPerformed(ActionEvent e) { 82 cancel(); 83 }}); 84 Object [] buttons = { setButton, clearButton, cancelButton }; 85 86 JOptionPane optionPane = 87 new JOptionPane 88 (components, 89 JOptionPane.QUESTION_MESSAGE, 90 JOptionPane.YES_NO_OPTION, 91 null, 92 buttons, 93 buttons[0]); 94 this.setContentPane(optionPane); 95 this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 96 } 97 98 public ClassLineBreakpointDialog() { 99 this(null); 100 } 101 102 public void show() { 103 pack(); 104 super.show(); 105 classText.requestFocus(); 106 } 107 108 private void setBreakpoint() { 109 String className = classText.getText(); 110 int line = -1; 111 try { 112 line = Integer.parseInt(lineText.getText()); 113 } catch (NumberFormatException e) { 114 AJUtil.warn("The line field must contain a number"); 115 return; 116 } 117 String cmd = "stop at " + className + ":" + line; 118 ComponentRepository.getCommandLine().executeCommand(cmd); 119 clear(); 120 hide(); 121 } 122 123 private void clear() { 124 classText.setText(""); 125 lineText.setText(""); 126 } 127 128 private void cancel() { 129 hide(); 130 } 131 } | Popular Tags |