-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from saalfeldlab/feat/1.2.0
Feat/1.2.0
- Loading branch information
Showing
8 changed files
with
170 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/kotlin/org/janelia/saalfeldlab/fx/ui/ScaleView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.janelia.saalfeldlab.fx.ui | ||
|
||
import javafx.beans.property.ObjectProperty | ||
import javafx.css.* | ||
import javafx.scene.Node | ||
import javafx.scene.layout.Pane | ||
import javafx.scene.layout.Region | ||
|
||
|
||
open class ScaleView protected constructor() : Pane(), Styleable { | ||
|
||
protected val paneWidthProperty: ObjectProperty<Number?> = SimpleStyleableObjectProperty(WIDTH, this, "paneWidth") | ||
protected val paneHeightProperty: ObjectProperty<Number?> = SimpleStyleableObjectProperty(HEIGHT, this, "paneHeight") | ||
|
||
|
||
init { | ||
styleClass += "scale-pane" | ||
} | ||
|
||
constructor(child: Node = Region()) : this() { | ||
children += child | ||
paneWidthProperty.addListener { _, _, new -> new?.let { width -> | ||
prefWidth = width.toDouble() | ||
(child as? Region)?.minWidthProperty()?.bind(paneWidthProperty) | ||
} } | ||
paneHeightProperty.addListener { _, _, new -> new?.let { height -> | ||
prefHeight = height.toDouble() | ||
(child as? Region)?.minHeightProperty()?.bind(paneHeightProperty) | ||
} } | ||
} | ||
|
||
override fun getCssMetaData(): MutableList<CssMetaData<out Styleable, *>> { | ||
return getClassCssMetaData() | ||
} | ||
|
||
companion object { | ||
|
||
private val WIDTH = object : CssMetaData<ScaleView, Number>("-pref-width", StyleConverter.getSizeConverter()) { | ||
override fun isSettable(styleable: ScaleView) = !styleable.paneWidthProperty.isBound | ||
|
||
override fun getStyleableProperty(styleable: ScaleView): StyleableProperty<Number> { | ||
@Suppress("UNCHECKED_CAST") | ||
return styleable.paneWidthProperty as StyleableProperty<Number> | ||
} | ||
|
||
override fun getInitialValue(styleable: ScaleView): Number { | ||
return styleable.prefWidth | ||
} | ||
} | ||
|
||
private val HEIGHT = object : CssMetaData<ScaleView, Number>("-pref-height", StyleConverter.getSizeConverter()) { | ||
override fun isSettable(styleable: ScaleView) = !styleable.paneHeightProperty.isBound | ||
|
||
override fun getStyleableProperty(styleable: ScaleView): StyleableProperty<Number> { | ||
@Suppress("UNCHECKED_CAST") | ||
return styleable.paneHeightProperty as StyleableProperty<Number> | ||
} | ||
|
||
override fun getInitialValue(styleable: ScaleView): Number { | ||
return styleable.prefHeight | ||
} | ||
} | ||
|
||
private val STYLEABLES: MutableList<CssMetaData<out Styleable, *>> = mutableListOf<CssMetaData<out Styleable, *>>().also { | ||
it += Region.getClassCssMetaData() | ||
it += WIDTH | ||
it += HEIGHT | ||
} | ||
|
||
fun getClassCssMetaData(): MutableList<CssMetaData<out Styleable, *>> = STYLEABLES | ||
} | ||
} |