001/*
002 * Copyright 2005,2009 Ivan SZKIBA
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.ini4j.sample;
017
018import java.beans.PropertyChangeListener;
019import java.beans.PropertyChangeSupport;
020import java.beans.PropertyVetoException;
021import java.beans.VetoableChangeListener;
022import java.beans.VetoableChangeSupport;
023
024import java.net.URI;
025
026//<editor-fold defaultstate="collapsed" desc="apt documentation">
027//|
028//|                ---------------
029//|                DwarfBean class
030//|
031//|DwarfBean class
032//|
033//</editor-fold>
034//{
035public class DwarfBean implements Dwarf
036{
037    private int _age;
038    private int[] _fortuneNumber;
039    private double _height;
040    private String _homeDir;
041    private URI _homePage;
042    private final PropertyChangeSupport _pcSupport;
043    private final VetoableChangeSupport _vcSupport;
044    private double _weight;
045
046    public DwarfBean()
047    {
048        _pcSupport = new PropertyChangeSupport(this);
049        _vcSupport = new VetoableChangeSupport(this);
050    }
051
052    @Override public int getAge()
053    {
054        return _age;
055    }
056
057    @Override public void setAge(int value)
058    {
059        int old = _age;
060
061        _age = value;
062
063        _pcSupport.firePropertyChange(PROP_AGE, old, value);
064    }
065
066    @Override public int[] getFortuneNumber()
067    {
068        return _fortuneNumber;
069    }
070
071    @Override public void setFortuneNumber(int[] value)
072    {
073        _fortuneNumber = value;
074    }
075
076    @Override public double getHeight()
077    {
078        return _height;
079    }
080
081    @Override public void setHeight(double value) throws PropertyVetoException
082    {
083        _vcSupport.fireVetoableChange(PROP_HEIGHT, _height, value);
084        double old = _height;
085
086        _height = value;
087
088        _pcSupport.firePropertyChange(PROP_HEIGHT, old, value);
089    }
090
091    @Override public String getHomeDir()
092    {
093        return _homeDir;
094    }
095
096    @Override public void setHomeDir(String value)
097    {
098        String old = _homeDir;
099
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//}