Last active
August 29, 2015 13:56
-
-
Save hastebrot/9331043 to your computer and use it in GitHub Desktop.
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
import javafx.beans.property.ObjectProperty | |
import javafx.beans.property.SimpleObjectProperty | |
import javafx.beans.value.ChangeListener | |
import javafx.scene.Node | |
import javafx.scene.control.Control | |
import javafx.scene.control.Skin | |
import javafx.scene.layout.StackPane | |
import com.sun.javafx.scene.control.behavior.BehaviorBase | |
import com.sun.javafx.scene.control.behavior.KeyBinding | |
import com.sun.javafx.scene.control.skin.BehaviorSkinBase | |
// def window = new InternalWindow() | |
// window.content = new Label("hello") | |
// panel.children << window | |
class InternalWindow extends Control { | |
//--------------------------------------------------------------------------------------------- | |
// CONSTANTS. | |
//--------------------------------------------------------------------------------------------- | |
private static final String DEFAULT_STYLE_CLASS = "internal-window" | |
//--------------------------------------------------------------------------------------------- | |
// CONSTRUCTORS. | |
//--------------------------------------------------------------------------------------------- | |
public InternalWindow() { | |
this.styleClass.add(DEFAULT_STYLE_CLASS) | |
} | |
//--------------------------------------------------------------------------------------------- | |
// PROPERTIES. | |
//--------------------------------------------------------------------------------------------- | |
private ObjectProperty<Node> contentProperty = new SimpleObjectProperty<Node>() | |
ObjectProperty<Node> contentProperty() { return this.contentProperty } | |
Node getContent() { return this.contentProperty.get() } | |
void setContent(Node node) { this.contentProperty.set(node) } | |
//--------------------------------------------------------------------------------------------- | |
// PROTECTED METHODS. | |
//--------------------------------------------------------------------------------------------- | |
protected Skin<InternalWindow> createDefaultSkin() { | |
return new InternalWindowSkin(this, new InternalWindowBehavior(this)) | |
} | |
} | |
class InternalWindowSkin extends BehaviorSkinBase<InternalWindow, InternalWindowBehavior> { | |
//--------------------------------------------------------------------------------------------- | |
// PRIVATE FIELDS. | |
//--------------------------------------------------------------------------------------------- | |
private final StackPane content = new StackPane() | |
//--------------------------------------------------------------------------------------------- | |
// CONSTRUCTORS. | |
//--------------------------------------------------------------------------------------------- | |
public InternalWindowSkin(InternalWindow control, InternalWindowBehavior behavior) { | |
super(control, behavior) | |
this.children.add(this.content) | |
this.skinnable.contentProperty().addListener({ | |
println "control content property changed: " + this.skinnable.content | |
this.content.children.setAll(this.skinnable.content) | |
} as ChangeListener<Node>) | |
this.content.children.setAll(this.skinnable.content) | |
} | |
//--------------------------------------------------------------------------------------------- | |
// PROTECTED METHODS. | |
//--------------------------------------------------------------------------------------------- | |
protected void handleControlPropertyChanged(String propertyReference) { | |
super.handleControlPropertyChanged(propertyReference) | |
println "control property changed: " + propertyReference | |
} | |
protected void layoutChildren(double x, double y, double w, double h) { | |
this.content.resizeRelocate(x, y, w, h) | |
} | |
} | |
class InternalWindowBehavior extends BehaviorBase<InternalWindow> { | |
//--------------------------------------------------------------------------------------------- | |
// CONSTRUCTORS. | |
//--------------------------------------------------------------------------------------------- | |
public InternalWindowBehavior(InternalWindow control) { | |
super(control, Collections.<KeyBinding>emptyList()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment