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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2007-01-15 16:29:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070115162948-olisrjfshcvqa7qu
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

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.awt.BorderLayout;
 
22
import java.beans.PropertyChangeEvent;
 
23
import java.beans.PropertyChangeListener;
 
24
 
 
25
import javax.swing.JFrame;
 
26
import javax.swing.JLabel;
 
27
import javax.swing.JPanel;
 
28
 
 
29
import spin.Spin;
 
30
 
 
31
/**
 
32
 * A demonstration of a GUI using spin over.
 
33
 */
 
34
public class SpinOverGUI extends JPanel implements PropertyChangeListener {
 
35
 
 
36
  private JLabel label = new JLabel("???");
 
37
 
 
38
  /**
 
39
   * Constructor.
 
40
   */
 
41
  public SpinOverGUI() {
 
42
    setLayout(new BorderLayout());
 
43
 
 
44
    add(label, BorderLayout.CENTER);
 
45
    label.setHorizontalAlignment(JLabel.CENTER);
 
46
    label.setVerticalAlignment  (JLabel.CENTER);
 
47
  }
 
48
 
 
49
  /**
 
50
   * @see java.beans.PropertyChangeListener
 
51
   */
 
52
  public void propertyChange(PropertyChangeEvent evt) {
 
53
 
 
54
    Assert.isEDT();
 
55
    
 
56
    if ("value".equals(evt.getPropertyName())) {
 
57
      String text = (String)evt.getNewValue();
 
58
 
 
59
      label.setText(text);
 
60
    }
 
61
  }
 
62
 
 
63
  /**
 
64
   * Entrance to this demo.
 
65
   */
 
66
  public static void main(String[] args) {
 
67
 
 
68
    Bean        bean        = new BeanImpl();
 
69
    SpinOverGUI spinOverGUI = new SpinOverGUI();
 
70
    bean.addPropertyChangeListener((PropertyChangeListener)Spin.over(spinOverGUI));
 
71
 
 
72
    JFrame frame = new JFrame("Spin over");
 
73
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
74
    frame.getContentPane().add(spinOverGUI);
 
75
    frame.pack();
 
76
    frame.setVisible(true);
 
77
  }
 
78
}
 
79