-
Notifications
You must be signed in to change notification settings - Fork 66
Basic Template for Wrapping Class
jpsacha edited this page Nov 10, 2014
·
8 revisions
Imagine that we want wrap the class javafx.package.subpackage.FxClass
.
In the file FxClass.scala
/*
* Copyright (c) 2011-2014, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ScalaFX Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE SCALAFX PROJECT OR ITS CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package scalafx.package.subpackage
import javafx.package.{subpackage => jfxps}
import scalafx.Includes._
import scalafx.beans.property.ObjectProperty
import scalafx.delegate.SFXDelegate
import scala.language.implicitConversions
// Other necessary packages
/**
* Object companion for [[scalafx.package.subpackage.FxClass]].
*/
object FxClass {
/**
* Converts a ScalaFX FxClass to its JavaFX counterpart.
*
* @param fc ScalaFX FxClass
* @return JavaFX FxClass
*/
implicit def sfxFXClass2jfx(fc: FxClass): jfxps.FxClass = if (v != null) fc.delegate else null
}
/**
* Wraps a $JFX $URL0 $FC]].
*
* @constructor Creates a new $FC from a $JFX one.
* @param delegate A $JFX $FC to be wrapped. Its default value is a new $JFX $FC.
*
* @define FC FxClass
* @define URL0 [[http://docs.oracle.com/javase/8/javafx/package/subpackage/FxClass.html
* @define JFX JavaFX
* @define ORIGINALDOC Original Documentation]].
*/
class FxClass(override val delegate: jfxps.FxClass = new jfxps.FxClass) with SFXDelegate[jfxps.FxClass] {
/**
* Copy of first sentence in original property/method javadoc
*
* @see $URL0#valueOneProperty $ORIGINALDOC
*/
def valueOne: ScalaFXWrapper = delegate.valueOneProperty
def valueOne_(v: SFXClass1) {
valueOne() = v
}
/**
* Copy of first sentence in original property/method javadoc
*
* @see $URL0#valueTwoProperty $ORIGINALDOC
*/
def valueTwo: ObjectProperty[jfx.JFXClass2] = delegate.valueTwoProperty
def valueTwo_=(value: SFXClass2): Unit = {
// Use helper method to set value of an `ObjectProperty`, it gracefully deals with `value` that could be `null`
ObjectProperty.fillProperty[jfx.JFXClass2](this.valueTwo, value)
}
}
In *Includes
trait in scalafx.package.subpackage
package.
/**
* Converts a JavaFX `[[http://docs.oracle.com/javase/8/javafx/package/subpackage/FxClass.html]]`.
*
* @param fc JavaFX FxClass
* @return ScalaFX FxClass
*/
implicit def jfxFxClass2sfx(fc: jfxps.FxClass): FxClass = if (fc != null) new FxClass(fc) else null
Imagine that we want wrap the enum javafx.package.subpackage.FxEnum
.
/*
* Copyright (c) 2011-2014, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ScalaFX Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE SCALAFX PROJECT OR ITS CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package scalafx.package.subpackage
import javafx.package.{subpackage => jfxps}
import scalafx.delegate.{ SFXEnumDelegateCompanion, SFXEnumDelegate }
import scala.language.implicitConversions
/**
* Wrapper for [[scalafx.package.subpackage.FxEnum]]
*
* @define FC FxClass
* @define URL0 [[http://docs.oracle.com/javase/8/javafx/package/subpackage/FxClass.html
* @define JFX JavaFX
* @define ORIGINALDOC Original Documentation]].
*/
object FxEnum extends SFXEnumDelegateCompanion[jfxps.FxEnum, FxEnum] {
/**
* Copy of first sentence in original property/method javadoc
*
* @see $URL0#ENUM_VALUE_1 $ORIGINALDOC
*/
val EnumValue1 = new FxEnum(jfxps.FxEnum.ENUM_VALUE_1)
/**
* Copy of first sentence in original property/method javadoc
*
* @see $URL0#ENUM_VALUE_2 $ORIGINALDOC
*/
val EnumValue2 = new FxEnum(jfxps.FxEnum.ENUM_VALUE_2)
protected override def unsortedValues: Array[FxEnum] = Array(EnumValue1, EnumValue2)
}
/**
* Wraps JavaFX [[http://docs.oracle.com/javase/8/javafx/package/subpackage/FxEnum.html]].
*
* @constructor Creates a new FxEnum from a JavaFX one.
* @param delegate JavaFX FxEnum
*/
sealed case class FxEnum(override val delegate: jfxps.FxEnum) extends SFXEnumDelegate[jfxsc.FxEnum]
In *Includes
trait in scalafx.package.subpackage
package.
/**
* Converts a JavaFX `[[http://docs.oracle.com/javase/8/javafx/package/subpackage/FxEnum.html]]`.
*
* @param fe JavaFX FxEnum
* @return ScalaFX FxEnum
*/
implicit def jfxFxClass2sfx(e: jfxps.FxEnum): FxEnum = FxEnum.jfxEnum2sfx(e)