~ubuntu-branches/ubuntu/oneiric/libspin-java/oneiric

« back to all changes in this revision

Viewing changes to src/spin/demo/BeanImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2007-12-16 15:15:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071216151547-0xwxaqstui65ozpd
Tags: 1.5-1
* New upstream release:
  - doesn't use ant anymore but maven; using a workaround with
    maven-ant-helper and our own build.xml
  - doesn't need the patch against build.xml anymore; therefore removing
    ths patch and the dpatch framework
  - depends on libcglib2.1-java; adding the package to Build-Depends-Indep
    and moving libspin-java to contrib because of the dependency
  - the jar now has the version number in the filename; adding a symlink
* Fix debian/watch.
* Clean up debian/rules.
* Move upstream URL from the description to the new Homepage field.
* Change XS-Vcs-* fields to Vcs-*.
* Set Standards-Version to 3.7.3 (no further changes required).
* Add get-orig-source target in debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Spin - transparent threading solution for non-freezing Swing applications.
3
 
 * Copyright (C) 2002 Sven Meier
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2.1 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Lesser General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 */
19
 
package spin.demo;
20
 
 
21
 
import java.beans.PropertyChangeEvent;
22
 
import java.beans.PropertyChangeListener;
23
 
import java.util.Date;
24
 
 
25
 
/**
26
 
 * Implementation of a bean.
27
 
 */
28
 
public class BeanImpl implements Bean {
29
 
 
30
 
  private PropertyChangeListener listener;
31
 
 
32
 
  private String value = new Date().toString();
33
 
 
34
 
  /**
35
 
   * Constructor.
36
 
   */
37
 
  public BeanImpl() {
38
 
 
39
 
    // alter continuously
40
 
    new Thread(new Runnable() {
41
 
      public void run() {
42
 
        try {
43
 
          while (true){
44
 
            Thread.sleep(1000);
45
 
 
46
 
            setValue(new java.util.Date().toString());
47
 
          }
48
 
        } catch (InterruptedException ex) {
49
 
          // ignore
50
 
        }
51
 
      }
52
 
    }).start();
53
 
  }
54
 
 
55
 
  /**
56
 
   * Add a listener to property changes.
57
 
   * 
58
 
   * @param listener listener to add
59
 
   */
60
 
  public void addPropertyChangeListener(PropertyChangeListener listener) {
61
 
    Assert.isNotEDT();
62
 
 
63
 
    this.listener = listener;
64
 
  }
65
 
 
66
 
  /**
67
 
   * Get the value.
68
 
   *
69
 
   * @return   the value
70
 
   */
71
 
  public String getValue() {
72
 
    Assert.isNotEDT();
73
 
    
74
 
    try {
75
 
      synchronized (this) {
76
 
        wait(5000);
77
 
      }
78
 
    } catch (InterruptedException ex) {
79
 
      // ignore
80
 
    }
81
 
 
82
 
    return value;
83
 
  }
84
 
 
85
 
  /**
86
 
   * Set the value.
87
 
   *
88
 
   * @param value value to set
89
 
   */
90
 
  public void setValue(String value) {
91
 
    String oldValue = this.value;
92
 
    
93
 
    this.value = value;
94
 
 
95
 
    String newValue = this.value;
96
 
    
97
 
    if (listener != null) {
98
 
      listener.propertyChange(new PropertyChangeEvent(this, "value", oldValue, newValue));
99
 
    }
100
 
  }
101
 
}