1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javafx.beans.property;
  27 
  28 /**
  29  * This class provides a convenient class to define read-only properties. It
  30  * creates two properties that are synchronized. One property is read-only
  31  * and can be passed to external users. The other property is read- and
  32  * writable and should be used internally only.
  33  * 
  34  * @since JavaFX 2.0
  35  */
  36 public class ReadOnlyLongWrapper extends SimpleLongProperty {
  37 
  38     private ReadOnlyPropertyImpl readOnlyProperty;
  39 
  40     /**
  41      * The constructor of {@code ReadOnlyLongWrapper}
  42      */
  43     public ReadOnlyLongWrapper() {
  44     }
  45 
  46     /**
  47      * The constructor of {@code ReadOnlyLongWrapper}
  48      * 
  49      * @param initialValue
  50      *            the initial value of the wrapped value
  51      */
  52     public ReadOnlyLongWrapper(long initialValue) {
  53         super(initialValue);
  54     }
  55 
  56     /**
  57      * The constructor of {@code ReadOnlyLongWrapper}
  58      * 
  59      * @param bean
  60      *            the bean of this {@code ReadOnlyLongProperty}
  61      * @param name
  62      *            the name of this {@code ReadOnlyLongProperty}
  63      */
  64     public ReadOnlyLongWrapper(Object bean, String name) {
  65         super(bean, name);
  66     }
  67 
  68     /**
  69      * The constructor of {@code ReadOnlyLongWrapper}
  70      * 
  71      * @param bean
  72      *            the bean of this {@code ReadOnlyLongProperty}
  73      * @param name
  74      *            the name of this {@code ReadOnlyLongProperty}
  75      * @param initialValue
  76      *            the initial value of the wrapped value
  77      */
  78     public ReadOnlyLongWrapper(Object bean, String name, long initialValue) {
  79         super(bean, name, initialValue);
  80     }
  81 
  82     /**
  83      * Returns the readonly property, that is synchronized with this
  84      * {@code ReadOnlyLongWrapper}.
  85      * 
  86      * @return the readonly property
  87      */
  88     public ReadOnlyLongProperty getReadOnlyProperty() {
  89         if (readOnlyProperty == null) {
  90             readOnlyProperty = new ReadOnlyPropertyImpl();
  91         }
  92         return readOnlyProperty;
  93     }
  94 
  95     /**
  96      * {@inheritDoc}
  97      */
  98     @Override
  99     protected void fireValueChangedEvent() {
 100         super.fireValueChangedEvent();
 101         if (readOnlyProperty != null) {
 102             readOnlyProperty.fireValueChangedEvent();
 103         }
 104     }
 105 
 106     private class ReadOnlyPropertyImpl extends ReadOnlyLongPropertyBase {
 107 
 108         @Override
 109         public long get() {
 110             return ReadOnlyLongWrapper.this.get();
 111         }
 112 
 113         @Override
 114         public Object getBean() {
 115             return ReadOnlyLongWrapper.this.getBean();
 116         }
 117 
 118         @Override
 119         public String getName() {
 120             return ReadOnlyLongWrapper.this.getName();
 121         }
 122     };
 123 }