1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 import org.aspectj.util.gui.*; 27 28 import java.awt.Frame ; 29 import java.awt.event.*; 30 import javax.swing.*; 31 import javax.swing.tree.*; 32 import com.sun.jdi.*; 33 34 public class AJNewValueDialog extends CenteredJDialog { 35 36 private AJValueNode valueNode = null; 37 private JOptionPane optionPane = null; 38 private JTextField textField = null; 39 private JButton button1 = null; 40 private JButton button2 = null; 41 private JLabel messageLabel = null; 42 43 private final static int TEXTFIELD_WIDTH = 20; 44 private final static String TAB = " "; 45 46 public AJNewValueDialog(Frame frame, AJValueNode valueNode) { 47 super(frame, "Change a Value", true); 48 this.valueNode = valueNode; 49 50 String message1 = "Change a value"; 51 textField = new JTextField(TEXTFIELD_WIDTH); 52 textField.addKeyListener(new KeyAdapter() { 53 public void keyPressed(KeyEvent e) { 54 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 55 setValue(); 56 } 57 }}); 58 clearText(); 59 messageLabel = new JLabel(); 60 clearMessage(); 61 Object [] components = {message1, textField, messageLabel}; 62 63 button1 = new JButton("Change"); 64 button1.addActionListener(new ActionListener() { 65 public void actionPerformed(ActionEvent e) { 66 setValue(); 67 }}); 68 button2 = new JButton("Clear"); 69 button2.addActionListener(new ActionListener() { 70 public void actionPerformed(ActionEvent e) { 71 clearText(); 72 }}); 73 Object [] buttons = {button1, button2}; 74 75 optionPane = 76 new JOptionPane 77 (components, 78 JOptionPane.QUESTION_MESSAGE, 79 JOptionPane.YES_NO_OPTION, 80 null, 81 buttons, 82 buttons[0]); 83 this.setContentPane(optionPane); 84 this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 85 } 86 87 public String getValueText() { 88 String text = textField.getText(); 89 if ((valueNode instanceof AJObjectValueNode) && ((AJObjectValueNode) valueNode).isString()) { 90 text = '"' + text + '"'; 91 } 92 return text; 93 } 94 95 private void setValue() { 96 if (valueNode == null) { 97 return; 98 } 99 try { 100 valueNode.setValue(getValueText()); 101 ComponentRepository.getThreadGroupTreePane().getTree().reloadAll(); 102 clearText(); 103 setVisible(false); 104 } catch (NumberFormatException e4) { 105 err(e4); 106 } catch (IllegalArgumentException e6) { 107 err(e6); 108 } catch (DebuggerException de) { 109 ComponentRepository.getGUIDebugger().handleDebuggerException(de); 110 } 111 } 112 113 private void err(Throwable e) { 114 String message = e.getMessage(); 115 if (e instanceof NumberFormatException ) { 116 message += " is too BIG!"; 117 } 118 message(message); 119 clearText(); 120 AJUtil.ex(e); 121 } 122 123 public void popup(AJValueNode valueNode) { 124 this.valueNode = valueNode; 125 this.setTitle("change: " + valueNode); 126 this.clearText(); 127 this.clearMessage(); 128 this.pack(); 129 this.setVisible(true); 130 } 131 132 public void popup() { 133 this.setTitle("change: " + valueNode); 134 this.clearText(); 135 this.clearMessage(); 136 this.pack(); 137 this.setVisible(true); 138 } 139 140 private void message(String s) { 141 messageLabel.setText(s); 142 } 143 144 private void clearMessage() { 145 messageLabel.setText(""); 146 } 147 148 private void clearText() { 149 textField.setText(""); 150 textField.requestFocus(); 151 } 152 } 153 | Popular Tags |