1 19 20 package org.netbeans.modules.scripting.php.dbginterface.breakpoints; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import org.netbeans.api.debugger.Breakpoint; 27 import org.netbeans.api.debugger.DebuggerManager; 28 import org.netbeans.api.debugger.DebuggerManagerAdapter; 29 import org.netbeans.modules.scripting.php.dbginterface.DebuggerAnnotation; 30 import org.netbeans.modules.scripting.php.dbginterface.breakpoints.*; 31 32 33 40 public class BreakpointAnnotationListener extends DebuggerManagerAdapter 41 implements PropertyChangeListener { 42 43 private Map <Breakpoint, DebuggerAnnotation> breakpointToAnnotation = new HashMap <Breakpoint, DebuggerAnnotation>(); 44 45 46 public String [] getProperties() { 47 return new String [] { DebuggerManager.PROP_BREAKPOINTS }; 48 } 49 50 55 public void breakpointAdded(Breakpoint b) { 56 if (! (b instanceof PhpBreakpoint)) { 57 return; 58 } 59 addAnnotation(b); 60 } 61 62 67 public void breakpointRemoved(Breakpoint b) { 68 if (! (b instanceof PhpBreakpoint)) { 69 return; 70 } 71 removeAnnotation(b); 72 } 73 74 79 80 public void propertyChange(PropertyChangeEvent evt) { 81 if (evt.getPropertyName() != Breakpoint.PROP_ENABLED) { 82 return; 83 } 84 removeAnnotation((Breakpoint) evt.getSource()); 85 addAnnotation((Breakpoint) evt.getSource()); 86 } 87 88 private void addAnnotation(Breakpoint b) { 89 breakpointToAnnotation.put(b, 90 new DebuggerAnnotation( 91 b.isEnabled() ? 92 DebuggerAnnotation.BREAKPOINT_ANNOTATION_TYPE : 93 DebuggerAnnotation.DISABLED_BREAKPOINT_ANNOTATION_TYPE, 94 ((PhpBreakpoint) b).getLine())); 95 b.addPropertyChangeListener(Breakpoint.PROP_ENABLED, this); 96 } 97 98 private void removeAnnotation(Breakpoint b) { 99 DebuggerAnnotation annotation = (DebuggerAnnotation) 100 breakpointToAnnotation.remove(b); 101 102 if (annotation == null) { 103 return; 104 } 105 106 annotation.detach(); 107 b.removePropertyChangeListener(Breakpoint.PROP_ENABLED, this); 108 } 109 } 110 | Popular Tags |