View Javadoc

1   /*
2    * Copyright 2005,2009 Ivan SZKIBA
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.ini4j.sample;
17  
18  import java.beans.PropertyChangeListener;
19  import java.beans.PropertyChangeSupport;
20  import java.beans.PropertyVetoException;
21  import java.beans.VetoableChangeListener;
22  import java.beans.VetoableChangeSupport;
23  
24  import java.net.URI;
25  
26  //<editor-fold defaultstate="collapsed" desc="apt documentation">
27  //|
28  //|                ---------------
29  //|                DwarfBean class
30  //|
31  //|DwarfBean class
32  //|
33  //</editor-fold>
34  //{
35  public class DwarfBean implements Dwarf
36  {
37      private int _age;
38      private int[] _fortuneNumber;
39      private double _height;
40      private String _homeDir;
41      private URI _homePage;
42      private final PropertyChangeSupport _pcSupport;
43      private final VetoableChangeSupport _vcSupport;
44      private double _weight;
45  
46      public DwarfBean()
47      {
48          _pcSupport = new PropertyChangeSupport(this);
49          _vcSupport = new VetoableChangeSupport(this);
50      }
51  
52      @Override public int getAge()
53      {
54          return _age;
55      }
56  
57      @Override public void setAge(int value)
58      {
59          int old = _age;
60  
61          _age = value;
62  
63          _pcSupport.firePropertyChange(PROP_AGE, old, value);
64      }
65  
66      @Override public int[] getFortuneNumber()
67      {
68          return _fortuneNumber;
69      }
70  
71      @Override public void setFortuneNumber(int[] value)
72      {
73          _fortuneNumber = value;
74      }
75  
76      @Override public double getHeight()
77      {
78          return _height;
79      }
80  
81      @Override public void setHeight(double value) throws PropertyVetoException
82      {
83          _vcSupport.fireVetoableChange(PROP_HEIGHT, _height, value);
84          double old = _height;
85  
86          _height = value;
87  
88          _pcSupport.firePropertyChange(PROP_HEIGHT, old, value);
89      }
90  
91      @Override public String getHomeDir()
92      {
93          return _homeDir;
94      }
95  
96      @Override public void setHomeDir(String value)
97      {
98          String old = _homeDir;
99  
100         _homeDir = value;
101 
102         _pcSupport.firePropertyChange(PROP_HOME_DIR, old, value);
103     }
104 
105     @Override public URI getHomePage()
106     {
107         return _homePage;
108     }
109 
110     @Override public void setHomePage(URI value)
111     {
112         URI old = _homePage;
113 
114         _homePage = value;
115 
116         _pcSupport.firePropertyChange(PROP_HOME_PAGE, old, value);
117     }
118 
119     @Override public double getWeight()
120     {
121         return _weight;
122     }
123 
124     @Override public void setWeight(double value)
125     {
126         double old = _weight;
127 
128         _weight = value;
129 
130         _pcSupport.firePropertyChange(PROP_WEIGHT, old, value);
131     }
132 
133     @Override public void addPropertyChangeListener(String property, PropertyChangeListener listener)
134     {
135         _pcSupport.addPropertyChangeListener(property, listener);
136     }
137 
138     @Override public void addVetoableChangeListener(String property, VetoableChangeListener listener)
139     {
140         _vcSupport.addVetoableChangeListener(property, listener);
141     }
142 
143     @Override public boolean hasAge()
144     {
145         return _age != 0;
146     }
147 
148     @Override public boolean hasHeight()
149     {
150         return _height != 0.0;
151     }
152 
153     @Override public boolean hasHomePage()
154     {
155         return _homePage != null;
156     }
157 
158     @Override public boolean hasWeight()
159     {
160         return _weight != 0.0;
161     }
162 
163     @Override public void removePropertyChangeListener(String property, PropertyChangeListener listener)
164     {
165         _pcSupport.removePropertyChangeListener(property, listener);
166     }
167 
168     @Override public void removeVetoableChangeListener(String property, VetoableChangeListener listener)
169     {
170         _vcSupport.removeVetoableChangeListener(property, listener);
171     }
172 }
173 //}