You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BoundPoint.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 1998-2002 Xerox Corporation,
  3. * 2004 Contributors. All rights reserved.
  4. *
  5. * Use and copying of this software and preparation of derivative works based
  6. * upon this software are permitted. Any distribution of this software or
  7. * derivative works must comply with all applicable United States export
  8. * control laws.
  9. *
  10. * This software is made available AS IS, and Xerox Corporation makes no
  11. * warranty about the software, its performance or its conformity to any
  12. * specification.
  13. */
  14. package bean;
  15. import java.beans.*;
  16. import java.io.Serializable;
  17. /**
  18. * Add bound properties and serialization to Point objects
  19. */
  20. aspect BoundPoint {
  21. /*
  22. * privately declare a field on Point to hold the property
  23. * change support object. `this' is a reference to a Point object.
  24. */
  25. private PropertyChangeSupport Point.support = new PropertyChangeSupport(this);
  26. /*
  27. * Declare property change registration methods on Point,
  28. * and introduce implementation of the Serializable interface.
  29. */
  30. public void Point.addPropertyChangeListener(PropertyChangeListener listener){
  31. support.addPropertyChangeListener(listener);
  32. }
  33. public void Point.addPropertyChangeListener(String propertyName,
  34. PropertyChangeListener listener){
  35. support.addPropertyChangeListener(propertyName, listener);
  36. }
  37. public void Point.removePropertyChangeListener(String propertyName,
  38. PropertyChangeListener listener) {
  39. support.removePropertyChangeListener(propertyName, listener);
  40. }
  41. public void Point.removePropertyChangeListener(PropertyChangeListener listener) {
  42. support.removePropertyChangeListener(listener);
  43. }
  44. public void Point.hasListeners(String propertyName) {
  45. support.hasListeners(propertyName);
  46. }
  47. declare parents: Point implements Serializable;
  48. /**
  49. * Send property change event after X setter completes normally.
  50. * Use around advice to keep the old value on the stack.
  51. */
  52. void around(Point p): execution(void Point.setX(int)) && target(p) {
  53. int oldValue = p.getX();
  54. proceed(p);
  55. firePropertyChange(p, "x", oldValue, p.getX());
  56. }
  57. /**
  58. * Send property change event after Y setter completes normally.
  59. * Use around advice to keep the old value on the stack.
  60. */
  61. void around(Point p): execution(void Point.setY(int)) && target(p) {
  62. int oldValue = p.getY();
  63. proceed(p);
  64. firePropertyChange(p, "y", oldValue, p.getY());
  65. }
  66. /*
  67. * Utility to fire the property change event.
  68. */
  69. void firePropertyChange(Point p,
  70. String property,
  71. double oldval,
  72. double newval) {
  73. p.support.firePropertyChange(property,
  74. new Double(oldval),
  75. new Double(newval));
  76. }
  77. }