KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > ui > WatchPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface.ui;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.FontMetrics JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.JEditorPane JavaDoc;
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JScrollPane JavaDoc;
31 import javax.swing.border.CompoundBorder JavaDoc;
32 import javax.swing.border.EmptyBorder JavaDoc;
33 import javax.swing.text.EditorKit JavaDoc;
34 import org.openide.awt.Mnemonics;
35 import org.openide.util.NbBundle;
36
37
38 /**
39  * A GUI panel for customizing a Watch.
40
41  * @author Maros Sandor
42  * @author Peter Williams - copied from JPDA and modified for PHP debugger support.
43  * I'm going to find a way to generalize this panel, so most clients can use
44  * a common class with a few parameters.
45  */

46 public class WatchPanel {
47
48     private JPanel JavaDoc panel;
49     private JEditorPane JavaDoc editorPane;
50     private String JavaDoc expression;
51
52     public WatchPanel(String JavaDoc expression) {
53         this.expression = expression;
54     }
55     
56     public static void setupContext(JEditorPane JavaDoc editorPane) {
57         // !PW Not sure exactly why the JPDA debugger was doing this... it appears
58
// to be setting StreamDescriptionProperty to the the DataObject of some
59
// Java file on the callstack (probably topmost, but whatever getURL(csf, "Java")
60
// returns. StreamDescriptionProperty is part of the editor api and enables
61
// _something_, maybe code completion.
62
//
63
// TODO figure out what we want to do here. Watch context is very important
64
// to get this right (and FWIW, in my experience, JPDA does not necessarily get
65
// it right.)
66
// DebuggerEngine en = DebuggerManager.getDebuggerManager ().getCurrentEngine();
67
// JPDADebugger d = (JPDADebugger) en.lookupFirst(null, JPDADebugger.class);
68
// CallStackFrame csf = d.getCurrentCallStackFrame();
69
// if (csf != null) {
70
// DataObject dobj = null;
71
// SourcePath sp = (SourcePath) en.lookupFirst(null, SourcePath.class);
72
// String url = sp.getURL(csf, "Java");
73
// FileObject file;
74
// try {
75
// file = URLMapper.findFileObject (new URL (url));
76
// if (file != null) {
77
// try {
78
// dobj = DataObject.find (file);
79
// } catch (DataObjectNotFoundException ex) {
80
// // null dobj
81
// }
82
// }
83
// } catch (MalformedURLException e) {
84
// // null dobj
85
// }
86
// editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj);
87
// }
88
}
89
90     public JComponent JavaDoc getPanel() {
91         if (panel != null) return panel;
92
93         panel = new JPanel JavaDoc();
94         ResourceBundle JavaDoc bundle = NbBundle.getBundle(WatchPanel.class);
95
96         panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); // NOI18N
97
JLabel JavaDoc textLabel = new JLabel JavaDoc();
98         Mnemonics.setLocalizedText(textLabel, bundle.getString ("CTL_Watch_Name")); // NOI18N
99

100         editorPane = new JEditorPane JavaDoc("text/javascript", expression); // NOI18N
101
EditorKit JavaDoc kit = editorPane.getEditorKit();
102         if(kit == null || kit.getClass().getSimpleName().contains("PlainEditorKit")) { // NOI18N
103
editorPane.setContentType("text/x-javascript"); // NOI18N
104
}
105         editorPane.setKeymap(new FilteredKeymap(editorPane.getKeymap()));
106         
107         setupContext(editorPane);
108         
109         JScrollPane JavaDoc sp = new JScrollPane JavaDoc(editorPane, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
110                                                      JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
111         
112         textLabel.setBorder (new EmptyBorder JavaDoc (0, 0, 5, 0));
113         panel.setLayout (new BorderLayout JavaDoc ());
114         panel.setBorder (new EmptyBorder JavaDoc (11, 12, 1, 11));
115         panel.add (BorderLayout.NORTH, textLabel);
116         panel.add (BorderLayout.CENTER, sp);
117         
118         FontMetrics JavaDoc fm = editorPane.getFontMetrics(editorPane.getFont());
119         int size = 2*fm.getLeading() + fm.getMaxAscent() + fm.getMaxDescent() + 4;
120         
121         editorPane.setPreferredSize(new Dimension JavaDoc(30*size, (int) (1*size)));
122         
123         editorPane.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N
124
editorPane.setBorder (
125             new CompoundBorder JavaDoc (editorPane.getBorder (),
126             new EmptyBorder JavaDoc (2, 0, 2, 0))
127         );
128         editorPane.setText (expression);
129         editorPane.selectAll ();
130
131         textLabel.setLabelFor (editorPane);
132         editorPane.requestFocus ();
133         
134         return panel;
135     }
136
137     public String JavaDoc getExpression() {
138         return editorPane.getText().trim();
139     }
140 }
141
Popular Tags