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-2007 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.cnd.debugger.gdb.breakpoints;
043:
044: import javax.swing.JPanel;
045: import org.netbeans.api.debugger.DebuggerManager;
046: import org.netbeans.api.debugger.Breakpoint;
047: import org.netbeans.spi.debugger.ui.Controller;
048: import org.openide.DialogDisplayer;
049: import org.openide.NotifyDescriptor;
050: import org.openide.util.NbBundle;
051:
052: /**
053: * Panel for customizing function breakpoints.
054: * This panel is a part of "New Breakpoint" dialog.
055: *
056: * @author Nik Molchanov (copied and modified from JDPA debugger).
057: */
058:
059: // Implement HelpCtx.Provider interface to provide help ids for help system
060: // public class FunctionBreakpointPanel extends JPanel implements Controller {
061: //
062: public class AddressBreakpointPanel extends JPanel implements
063: Controller {
064:
065: private ConditionsPanel conditionsPanel;
066: private ActionsPanel actionsPanel;
067: private AddressBreakpoint breakpoint;
068: private boolean createBreakpoint = false;
069:
070: private static AddressBreakpoint createBreakpoint() {
071: AddressBreakpoint ab = AddressBreakpoint.create(
072: // EditorContextBridge.getCurrentFunction ()
073: "0x000000" // DEBUG // NOI18N
074: );
075: ab.setPrintText(NbBundle
076: .getBundle(AddressBreakpointPanel.class).getString(
077: "CTL_Address_Breakpoint_Print_Text")); // NOI18N
078:
079: return ab;
080: }
081:
082: /**
083: * Creates new form FunctionBreakpointPanel
084: */
085: public AddressBreakpointPanel() {
086: this (createBreakpoint());
087: createBreakpoint = true;
088: }
089:
090: /**
091: * Creates new form FunctionBreakpointPanel
092: */
093: public AddressBreakpointPanel(AddressBreakpoint b) {
094: breakpoint = b;
095: initComponents();
096:
097: tfAddress.setText(b.getAddress());
098:
099: conditionsPanel = new ConditionsPanel(b);
100: pConditions.add(conditionsPanel);
101: actionsPanel = new ActionsPanel(b);
102: pActions.add(actionsPanel, "Center"); // NOI18N
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 Form Editor.
109: */
110: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
111: private void initComponents() {
112: java.awt.GridBagConstraints gridBagConstraints;
113:
114: pSettings = new javax.swing.JPanel();
115: lAddress = new javax.swing.JLabel();
116: tfAddress = new javax.swing.JTextField();
117: pConditions = new javax.swing.JPanel();
118: pActions = new javax.swing.JPanel();
119:
120: setLayout(new java.awt.GridBagLayout());
121:
122: java.util.ResourceBundle bundle = java.util.ResourceBundle
123: .getBundle("org/netbeans/modules/cnd/debugger/gdb/breakpoints/Bundle"); // NOI18N
124: pSettings
125: .setBorder(javax.swing.BorderFactory
126: .createTitledBorder(bundle
127: .getString("L_Function_Breakpoint_BorderTitle"))); // NOI18N
128: pSettings.setMinimumSize(new java.awt.Dimension(249, 80));
129: pSettings.setLayout(new java.awt.GridBagLayout());
130:
131: lAddress
132: .setDisplayedMnemonic(java.util.ResourceBundle
133: .getBundle(
134: "org/netbeans/modules/cnd/debugger/gdb/breakpoints/Bundle")
135: .getString("MN_L_AddressBreakpoint").charAt(0));
136: lAddress.setLabelFor(tfAddress);
137: lAddress.setText(bundle.getString("L_Address_Breakpoint")); // NOI18N
138: gridBagConstraints = new java.awt.GridBagConstraints();
139: gridBagConstraints.gridx = 0;
140: gridBagConstraints.gridy = 0;
141: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
142: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
143: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
144: pSettings.add(lAddress, gridBagConstraints);
145: lAddress
146: .getAccessibleContext()
147: .setAccessibleDescription(
148: bundle
149: .getString("ACSD_L_Function_Breakpoint_Function_Name")); // NOI18N
150:
151: tfAddress.setToolTipText(bundle
152: .getString("TTT_TF_Function_Breakpoint_Function_Name")); // NOI18N
153: gridBagConstraints = new java.awt.GridBagConstraints();
154: gridBagConstraints.gridx = 1;
155: gridBagConstraints.gridy = 0;
156: gridBagConstraints.gridwidth = 2;
157: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158: gridBagConstraints.weightx = 1.0;
159: gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
160: pSettings.add(tfAddress, gridBagConstraints);
161: tfAddress
162: .getAccessibleContext()
163: .setAccessibleName(
164: bundle
165: .getString("ACSD_TF_Function_Breakpoint_Function_Name")); // NOI18N
166: tfAddress
167: .getAccessibleContext()
168: .setAccessibleDescription(
169: bundle
170: .getString("ACSD_TF_Function_Breakpoint_Function_Name")); // NOI18N
171:
172: gridBagConstraints = new java.awt.GridBagConstraints();
173: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
174: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
175: gridBagConstraints.weightx = 1.0;
176: add(pSettings, gridBagConstraints);
177:
178: pConditions.setLayout(new java.awt.BorderLayout());
179: gridBagConstraints = new java.awt.GridBagConstraints();
180: gridBagConstraints.gridx = 0;
181: gridBagConstraints.gridy = 1;
182: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
183: gridBagConstraints.weightx = 1.0;
184: gridBagConstraints.weighty = 1.0;
185: add(pConditions, gridBagConstraints);
186:
187: pActions.setLayout(new java.awt.BorderLayout());
188: gridBagConstraints = new java.awt.GridBagConstraints();
189: gridBagConstraints.gridx = 0;
190: gridBagConstraints.gridy = 2;
191: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192: gridBagConstraints.weightx = 1.0;
193: add(pActions, gridBagConstraints);
194: }// </editor-fold>//GEN-END:initComponents
195:
196: // Controller implementation ...............................................
197:
198: /**
199: * Called when "Ok" button is pressed.
200: *
201: * @return whether customizer can be closed
202: */
203: public boolean ok() {
204: String msg = valiadateMsg();
205: if (msg != null) {
206: DialogDisplayer.getDefault().notify(
207: new NotifyDescriptor.Message(msg));
208: return false;
209: }
210: conditionsPanel.ok();
211: actionsPanel.ok();
212: String address = tfAddress.getText().trim();
213: breakpoint.setAddress(address);
214:
215: // Check if this breakpoint already set
216: DebuggerManager dm = DebuggerManager.getDebuggerManager();
217: Breakpoint[] bs = dm.getBreakpoints();
218: int i, k = bs.length;
219: for (i = 0; i < k; i++) {
220: if (bs[i] instanceof AddressBreakpoint) {
221: AddressBreakpoint ab = (AddressBreakpoint) bs[i];
222: if (address.equals(ab.getAddress())) {
223: // Compare conditions
224: String condition = breakpoint.getCondition();
225: if (condition != null) {
226: if (!condition.equals(ab.getCondition())) {
227: continue;
228: }
229: } else {
230: if (ab.getCondition() != null) {
231: continue;
232: }
233: }
234: // Check if this breakpoint is enabled
235: if (!ab.isEnabled())
236: bs[i].enable();
237: return true;
238: }
239: }
240: }
241: // Create a new breakpoint
242: if (createBreakpoint) {
243: dm.addBreakpoint(breakpoint);
244: }
245: return true;
246: }
247:
248: /**
249: * Called when "Cancel" button is pressed.
250: *
251: * @return whether customizer can be closed
252: */
253: public boolean cancel() {
254: return true;
255: }
256:
257: /**
258: * Return <code>true</code> whether value of this customizer
259: * is valid (and OK button can be enabled).
260: *
261: * @return <code>true</code> whether value of this customizer
262: * is valid
263: */
264: @Override
265: public boolean isValid() {
266: return true;
267: }
268:
269: private String valiadateMsg() {
270: String function = tfAddress.getText().trim();
271: // Empty string is not a valid function name
272: if (function.length() == 0) {
273: return NbBundle.getBundle(AddressBreakpointPanel.class)
274: .getString("MSG_No_Address_Name_Spec"); // NOI18N
275: }
276: return null;
277: }
278:
279: // Variables declaration - do not modify//GEN-BEGIN:variables
280: private javax.swing.JLabel lAddress;
281: private javax.swing.JPanel pActions;
282: private javax.swing.JPanel pConditions;
283: private javax.swing.JPanel pSettings;
284: private javax.swing.JTextField tfAddress;
285: // End of variables declaration//GEN-END:variables
286:
287: }
|