001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.debug;
043:
044: import org.openide.*; //import org.openide.NotifyDescriptor.Message;
045: import org.openide.util.NbBundle;
046:
047: import java.net.URI;
048: import javax.swing.*;
049:
050: import org.netbeans.spi.debugger.ui.Controller;
051: import org.netbeans.api.debugger.DebuggerManager;
052:
053: import org.netbeans.modules.web.debug.breakpoints.*;
054:
055: /**
056: * Customizer of JspLineBreakpoint
057: *
058: * @author Martin Grebac
059: */
060: public class JspBreakpointPanel extends JPanel implements Controller {
061:
062: static final long serialVersionUID = -8164649328980808272L;
063:
064: private ActionsPanel actionsPanel;
065: private JspLineBreakpoint breakpoint;
066: private boolean createBreakpoint = false;
067:
068: public JspBreakpointPanel() {
069: this (JspLineBreakpoint.create(Context.getCurrentURL(), Context
070: .getCurrentLineNumber()));
071: createBreakpoint = true;
072: }
073:
074: /** Creates new form JspBreakpointPanel */
075: public JspBreakpointPanel(JspLineBreakpoint b) {
076:
077: breakpoint = b;
078: initComponents();
079: putClientProperty("HelpID", "jsp_breakpoint");//NOI18N
080:
081: // a11y
082: getAccessibleContext().setAccessibleDescription(
083: NbBundle.getMessage(JspBreakpointPanel.class,
084: "ACSD_LineBreakpointPanel")); // NOI18N
085:
086: String url = b.getURL();
087: try {
088: URI uri = new URI(url);
089: cboxJspSourcePath.setText(uri.getPath());
090: } catch (Exception e) {
091: cboxJspSourcePath.setText(url);
092: }
093:
094: int lnum = b.getLineNumber();
095: if (lnum < 1) {
096: tfLineNumber.setText(""); //NOI18N
097: } else {
098: tfLineNumber.setText(Integer.toString(lnum));
099: }
100:
101: actionsPanel = new ActionsPanel(b);
102: pActions.add(actionsPanel, "Center");
103: }
104:
105: /** This method is called from within the constructor to
106: * initialize the form.
107: * WARNING: Do NOT modify this code. The content of this method is
108: * always regenerated by the FormEditor.
109: */
110: private void initComponents() {
111: java.awt.GridBagConstraints gridBagConstraints;
112:
113: pSettings = new javax.swing.JPanel();
114: lblJspSourcePath = new javax.swing.JLabel();
115: cboxJspSourcePath = new javax.swing.JTextField();
116: lblLineNumber = new javax.swing.JLabel();
117: tfLineNumber = new javax.swing.JTextField();
118: pActions = new javax.swing.JPanel();
119: jPanel1 = new javax.swing.JPanel();
120:
121: setLayout(new java.awt.GridBagLayout());
122:
123: pSettings.setLayout(new java.awt.GridBagLayout());
124:
125: pSettings.setBorder(new javax.swing.border.TitledBorder(
126: NbBundle.getMessage(JspBreakpointPanel.class,
127: "LBL_Settings")));
128: lblJspSourcePath.setText(NbBundle.getBundle(
129: JspBreakpointPanel.class).getString("CTL_Source_name"));
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridx = 0;
132: gridBagConstraints.gridy = 1;
133: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
134: gridBagConstraints.insets = new java.awt.Insets(2, 4, 2, 2);
135: pSettings.add(lblJspSourcePath, gridBagConstraints);
136: lblJspSourcePath.getAccessibleContext()
137: .setAccessibleDescription(
138: NbBundle.getBundle(JspBreakpointPanel.class)
139: .getString("ACSN_CTL_Source_name"));
140:
141: cboxJspSourcePath.setEditable(false);
142:
143: gridBagConstraints = new java.awt.GridBagConstraints();
144: gridBagConstraints.gridx = 1;
145: gridBagConstraints.gridy = 1;
146: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
147: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148: gridBagConstraints.weightx = 1.0;
149: gridBagConstraints.insets = new java.awt.Insets(2, 6, 2, 2);
150: pSettings.add(cboxJspSourcePath, gridBagConstraints);
151: cboxJspSourcePath.getAccessibleContext().setAccessibleName(
152: NbBundle.getBundle(JspBreakpointPanel.class).getString(
153: "ACSN_CTL_Source_name"));
154: cboxJspSourcePath.getAccessibleContext()
155: .setAccessibleDescription(
156: NbBundle.getBundle(JspBreakpointPanel.class)
157: .getString("ACSD_CTL_Source_name"));
158:
159: lblLineNumber.setLabelFor(tfLineNumber);
160: lblLineNumber.setText(NbBundle.getBundle(
161: JspBreakpointPanel.class).getString("CTL_Line_number"));
162: lblLineNumber.setDisplayedMnemonic(NbBundle.getBundle(
163: JspBreakpointPanel.class).getString(
164: "CTL_Line_number_mnemonic").charAt(0));
165: gridBagConstraints = new java.awt.GridBagConstraints();
166: gridBagConstraints.gridx = 0;
167: gridBagConstraints.gridy = 2;
168: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
169: gridBagConstraints.insets = new java.awt.Insets(2, 4, 2, 2);
170: pSettings.add(lblLineNumber, gridBagConstraints);
171: lblLineNumber.getAccessibleContext().setAccessibleDescription(
172: NbBundle.getBundle(JspBreakpointPanel.class).getString(
173: "ACSD_CTL_Line_number"));
174:
175: tfLineNumber.setColumns(7);
176: tfLineNumber
177: .addFocusListener(new java.awt.event.FocusAdapter() {
178: public void focusGained(
179: java.awt.event.FocusEvent evt) {
180: tfLineNumberFocusGained(evt);
181: }
182:
183: public void focusLost(java.awt.event.FocusEvent evt) {
184: tfLineNumberFocusLost(evt);
185: }
186: });
187: tfLineNumber.addKeyListener(new java.awt.event.KeyAdapter() {
188: public void keyTyped(java.awt.event.KeyEvent evt) {
189: tfLineNumberKeyTyped(evt);
190: }
191: });
192:
193: gridBagConstraints = new java.awt.GridBagConstraints();
194: gridBagConstraints.gridx = 1;
195: gridBagConstraints.gridy = 2;
196: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
197: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
198: gridBagConstraints.weightx = 1.0;
199: gridBagConstraints.insets = new java.awt.Insets(2, 6, 2, 2);
200: pSettings.add(tfLineNumber, gridBagConstraints);
201: tfLineNumber.getAccessibleContext().setAccessibleName(
202: NbBundle.getBundle(JspBreakpointPanel.class).getString(
203: "ACSN_CTL_Line_number"));
204: tfLineNumber.getAccessibleContext().setAccessibleDescription(
205: NbBundle.getBundle(JspBreakpointPanel.class).getString(
206: "ACSD_CTL_Line_number"));
207:
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
210: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
211: gridBagConstraints.weightx = 1.0;
212: add(pSettings, gridBagConstraints);
213:
214: pActions.setLayout(new java.awt.BorderLayout());
215:
216: gridBagConstraints = new java.awt.GridBagConstraints();
217: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
218: gridBagConstraints.weightx = 1.0;
219: add(pActions, gridBagConstraints);
220:
221: gridBagConstraints = new java.awt.GridBagConstraints();
222: gridBagConstraints.gridx = 0;
223: gridBagConstraints.gridy = 2;
224: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
225: gridBagConstraints.weightx = 1.0;
226: gridBagConstraints.weighty = 1.0;
227: add(jPanel1, gridBagConstraints);
228:
229: }
230:
231: private void tfLineNumberKeyTyped(java.awt.event.KeyEvent evt) {
232: // Add your handling code here:
233: }
234:
235: private void tfLineNumberFocusGained(java.awt.event.FocusEvent evt) {
236: if (!evt.isTemporary()) {
237: ((JTextField) evt.getComponent()).selectAll();
238: }
239: }
240:
241: private void tfLineNumberFocusLost(java.awt.event.FocusEvent evt) {
242: // if (!evt.isTemporary()) {
243: // if (tfLineNumber.getText().trim().length() > 0) {
244: // try {
245: // int i = Integer.parseInt(tfLineNumber.getText ());
246: // if (i < 1) {
247: // DialogDisplayer.getDefault().notify (
248: // new Message (
249: // NbBundle.getBundle(JspBreakpointPanel.class).getString("CTL_Bad_line_number"), //NOI18N
250: // NotifyDescriptor.ERROR_MESSAGE
251: // )
252: // );
253: // } else if (event != null) {
254: // event.setLineNumber(i);
255: // }
256: // } catch (NumberFormatException e) {
257: // DialogDisplayer.getDefault().notify (
258: // new Message (
259: // NbBundle.getBundle(JspBreakpointPanel.class).getString("CTL_Bad_line_number"), //NOI18N
260: // NotifyDescriptor.ERROR_MESSAGE
261: // )
262: // );
263: // }
264: // }
265: // }
266: }
267:
268: /******************************/
269: /* CONTROLLER: */
270: /******************************/
271:
272: //interface org.netbeans.modules.debugger.Controller
273: public boolean ok() {
274: if (!isValid()) {
275: return false;
276: }
277:
278: actionsPanel.ok();
279: breakpoint.setLineNumber(Integer.parseInt(tfLineNumber
280: .getText().trim()));
281:
282: if (createBreakpoint) {
283: DebuggerManager.getDebuggerManager().addBreakpoint(
284: breakpoint);
285: }
286: return true;
287: }
288:
289: //interface org.netbeans.modules.debugger.Controller
290: public boolean cancel() {
291: return true;
292: }
293:
294: //interface org.netbeans.modules.debugger.Controller
295: public boolean isValid() {
296: try {
297: int line = Integer.parseInt(tfLineNumber.getText().trim());
298: return line > 0;
299: } catch (NumberFormatException e) {
300: return false;
301: }
302: }
303:
304: // Variables declaration - do not modify
305: private javax.swing.JTextField cboxJspSourcePath;
306: private javax.swing.JPanel jPanel1;
307: private javax.swing.JLabel lblJspSourcePath;
308: private javax.swing.JLabel lblLineNumber;
309: private javax.swing.JPanel pActions;
310: private javax.swing.JPanel pSettings;
311: private javax.swing.JTextField tfLineNumber;
312: // End of variables declaration
313:
314: }
|