1 19 20 package org.netbeans.modules.debugger.ui.actions; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.util.ResourceBundle ; 28 import javax.swing.AbstractAction ; 29 import javax.swing.Action ; 30 import javax.swing.JButton ; 31 32 import org.netbeans.api.debugger.DebuggerManager; 33 import org.netbeans.spi.debugger.ui.BreakpointType; 34 import org.netbeans.spi.debugger.ui.Controller; 35 36 import org.openide.DialogDescriptor; 37 import org.openide.DialogDisplayer; 38 import org.openide.util.NbBundle; 39 40 41 46 public class AddBreakpointAction extends AbstractAction { 47 48 private static AddBreakpointDialogManager abdm; 49 50 51 public AddBreakpointAction () { 52 putValue ( 53 Action.NAME, 54 NbBundle.getMessage ( 55 AddBreakpointAction.class, 56 "CTL_AddBreakpoint" 57 ) 58 ); 59 } 60 61 public void actionPerformed (ActionEvent e) { 62 DebuggerManager dm = DebuggerManager.getDebuggerManager (); 63 64 if (dm.lookup (null, BreakpointType.class).size () == 0) 65 return; 67 if (abdm == null) 69 abdm = new AddBreakpointDialogManager (); 70 abdm.getDialog ().setVisible (true); 71 } 72 73 75 80 static final class AddBreakpointDialogManager extends Object 81 implements ActionListener , PropertyChangeListener { 82 83 84 private boolean okPressed; 85 private Dialog dialog; 86 private AddBreakpointPanel panel; 87 private DialogDescriptor descriptor; 88 private Controller controller; 89 private JButton bOk; 90 private JButton bCancel; 91 92 93 Dialog getDialog () { 94 dialog = createDialog (); 95 okPressed = false; 96 setValid (); 97 startListening (); 98 panel.addPropertyChangeListener (this); 99 return dialog; 100 } 101 102 104 private Dialog createDialog () { 105 ResourceBundle bundle = NbBundle.getBundle (AddBreakpointAction.class); 106 107 panel = new AddBreakpointPanel (); 108 descriptor = new DialogDescriptor ( 110 panel, 111 bundle.getString ("CTL_Breakpoint_Title"), true, 113 this 114 ); 115 descriptor.setOptions (new JButton [] { 116 bOk = new JButton (bundle.getString ("CTL_Ok")), bCancel = new JButton (bundle.getString ("CTL_Cancel")) }); 119 bOk.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Ok")); bCancel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Cancel")); descriptor.setClosingOptions (new Object [0]); 122 Dialog d = DialogDisplayer.getDefault ().createDialog (descriptor); 123 d.pack (); 124 return d; 125 } 126 127 128 public void actionPerformed (ActionEvent evt) { 129 okPressed = bOk.equals (evt.getSource ()); 130 Controller controller = panel.getController (); 131 boolean close = false; 132 if (okPressed) 133 close = controller.ok (); 134 else 135 close = controller.cancel (); 136 137 if (!close) return; 138 panel.removePropertyChangeListener (this); 139 stopListening (); 140 dialog.setVisible (false); 141 dialog.dispose (); 142 dialog = null; 143 } 144 145 public void propertyChange (PropertyChangeEvent e) { 146 if (e.getPropertyName () == AddBreakpointPanel.PROP_TYPE) { 147 stopListening (); 148 setValid (); 149 startListening (); 150 151 } else 152 if (e.getPropertyName () == Controller.PROP_VALID) { 153 setValid (); 154 } 155 } 156 157 void startListening () { 158 controller = panel.getController (); 159 if (controller == null) return; 160 controller.addPropertyChangeListener (this); 161 } 162 163 void stopListening () { 164 if (controller == null) return; 165 controller.removePropertyChangeListener (this); 166 controller = null; 167 } 168 169 void setValid () { 170 Controller controller = panel.getController (); 171 if (controller == null) { 172 bOk.setEnabled (false); 173 return; 174 } 175 bOk.setEnabled (controller.isValid ()); 176 } 177 178 180 public boolean getOKPressed () { 181 return okPressed; 182 } 183 } 184 } 185 186 187 | Popular Tags |