/ui/src/com/bluemarsh/jswat/ui/breakpoint/AbstractAdapter.java

http://jswat.googlecode.com/ · Java · 85 lines · 31 code · 8 blank · 46 comment · 2 complexity · 6c6874ad3b9fa39402bf7be607c8168e MD5 · raw file

  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 JSwat. The Initial Developer of the Original
  16. * Software is Nathan L. Fiedler. Portions created by Nathan L. Fiedler
  17. * are Copyright (C) 2006-2010. All Rights Reserved.
  18. *
  19. * Contributor(s): Nathan L. Fiedler.
  20. *
  21. * $Id: AbstractAdapter.java 288 2010-11-21 02:59:13Z nathanfiedler $
  22. */
  23. package com.bluemarsh.jswat.ui.breakpoint;
  24. import java.beans.PropertyChangeListener;
  25. import java.beans.PropertyChangeSupport;
  26. import javax.swing.JPanel;
  27. /**
  28. * An abstract implementation of a BreakpointAdapter.
  29. *
  30. * @author Nathan Fiedler
  31. */
  32. public abstract class AbstractAdapter extends JPanel implements BreakpointAdapter {
  33. /** silence compiler warnings */
  34. private static final long serialVersionUID = 1L;
  35. /** Manages property change listeners. */
  36. private PropertyChangeSupport propSupport;
  37. /**
  38. * Creates a new instance of AbstractAdapter.
  39. */
  40. public AbstractAdapter() {
  41. }
  42. @Override
  43. public void addPropertyChangeListener(PropertyChangeListener listener) {
  44. super.addPropertyChangeListener(listener);
  45. initPropSupport();
  46. propSupport.addPropertyChangeListener(listener);
  47. }
  48. /**
  49. * Fires the validInput property change in which the new property value
  50. * is that given in the parameter. If that value is null, then the
  51. * input is considered to be valid. Otherwise, the message will be made
  52. * visible to the user.
  53. *
  54. * @param msg invalid input message, or null if input is valid.
  55. */
  56. protected void fireInputPropertyChange(String msg) {
  57. initPropSupport();
  58. propSupport.firePropertyChange(PROP_INPUTVALID, "DummyValue", msg);
  59. }
  60. /**
  61. * Create the PropertyChangeSupport instance on demand.
  62. */
  63. private synchronized void initPropSupport() {
  64. // For some reason, the Synth LAF causes problems with invoking
  65. // methods before the object is completely constructed, so need
  66. // to ensure propery support is built on demand.
  67. if (propSupport == null) {
  68. propSupport = new PropertyChangeSupport(this);
  69. }
  70. }
  71. @Override
  72. public void removePropertyChangeListener(PropertyChangeListener listener) {
  73. super.removePropertyChangeListener(listener);
  74. initPropSupport();
  75. propSupport.removePropertyChangeListener(listener);
  76. }
  77. }