View Javadoc
1   package org.opentrafficsim.simulationengine.properties;
2   
3   /**
4    * Boolean property.
5    * <p>
6    * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
7    * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
8    * <p>
9    * $LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: averbraeck $,
10   * initial version 29 dec. 2014 <br>
11   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
12   */
13  public class BooleanProperty extends AbstractProperty<Boolean>
14  {
15      /** The current value of the property. */
16      private Boolean value;
17  
18      /** The shortName of the property. */
19      private String shortName;
20  
21      /** The description of the property. */
22      private String description;
23  
24      /** The property is read-only. */
25      private final Boolean readOnly;
26  
27      /**
28       * Construct an BooleanProperty.
29       * @param shortName String; the short name of the new BooleanProperty
30       * @param description String; description of the new BooleanProperty (may use HTML mark up)
31       * @param initialValue Integer; the initial value of the new BooleanProperty
32       * @param readOnly boolean; if true this BooleanProperty can not be altered
33       * @param displayPriority int; the displayPriority of the new BooleanProperty
34       */
35      public BooleanProperty(final String shortName, final String description, final Boolean initialValue,
36          final boolean readOnly, final int displayPriority)
37      {
38          super(displayPriority);
39          this.shortName = shortName;
40          this.description = description;
41          this.value = initialValue;
42          this.readOnly = readOnly;
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      public final Boolean getValue()
48      {
49          return this.value;
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public final String getShortName()
55      {
56          return this.shortName;
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public final String getDescription()
62      {
63          return this.description;
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public final void setValue(final Boolean newValue) throws PropertyException
69      {
70          if (this.readOnly)
71          {
72              throw new PropertyException("This property is read-only");
73          }
74          this.value = newValue;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final boolean isReadOnly()
80      {
81          return this.readOnly;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final String htmlStateDescription()
87      {
88          return getShortName() + ": " + (null == this.value ? "null" : this.value ? "true" : "false");
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      public AbstractProperty<Boolean> deepCopy()
94      {
95          return new BooleanProperty(this.shortName, this.description, this.value, this.readOnly, this.getDisplayPriority());
96      }
97  
98  }