KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > AJNewValueDialog


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

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 JavaDoc;
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 JavaDoc TAB = " ";
45
46     public AJNewValueDialog(Frame JavaDoc frame, AJValueNode valueNode) {
47         super(frame, "Change a Value", true);
48         this.valueNode = valueNode;
49
50         String JavaDoc 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 JavaDoc[] 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 JavaDoc[] 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 JavaDoc getValueText() {
88         String JavaDoc 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 JavaDoc e4) {
105             err(e4);
106         } catch (IllegalArgumentException JavaDoc e6) {
107             err(e6);
108         } catch (DebuggerException de) {
109             ComponentRepository.getGUIDebugger().handleDebuggerException(de);
110         }
111     }
112
113     private void err(Throwable JavaDoc e) {
114         String JavaDoc message = e.getMessage();
115         if (e instanceof NumberFormatException JavaDoc) {
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 JavaDoc 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