All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jfxtras.scene.control.AccordionPane Maven / Gradle / Ivy

There is a newer version: 17-r1
Show newest version
package jfxtras.scene.control;

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.Skin;

public class AccordionPane extends Control {
	// ==================================================================================================================
	// CONSTRUCTOR
	
	/**
	 * 
	 */
	public AccordionPane()
	{
		construct();
	}
	
	/**
	 * 
	 */
	public AccordionPane(Tab... tabs)
	{
		construct();
		
		// add tabs
		for (Tab lTab : tabs) {
			this.tabs.add(lTab);
		}
	}
	
	/*
	 * 
	 */
	private void construct()
	{
		// setup the CSS
		// the -fx-skin attribute in the CSS sets which Skin class is used
		this.getStyleClass().add(AccordionPane.class.getSimpleName());
	}

	/**
	 * Return the path to the CSS file so things are setup right
	 */
	@Override public String getUserAgentStylesheet()
	{
		return AccordionPane.class.getResource("/jfxtras/internal/scene/control/" + AccordionPane.class.getSimpleName() + ".css").toExternalForm();
	}
	
	@Override public Skin createDefaultSkin() {
		return new jfxtras.internal.scene.control.skin.AccordionSkin(this); 
	}

	// ==================================================================================================================
	// PROPERTIES

	/** Id: for a fluent API */
	public AccordionPane withId(String value) { setId(value); return this; }

	/** tabs */
	public ObservableList tabs() { return tabs; }
	final private ObservableList tabs =  javafx.collections.FXCollections.observableArrayList();
	
	/**
	 * Convenience method
	 */
	public AccordionPane addTab(String name, Node node) {
		Tab lTab = new Tab().withText(name).withNode(node);
		tabs.add(lTab);
		return this;
	}
	
	/**
	 * Convenience method
	 */
	public AccordionPane addTab(String name, Node icon, Node node) {
		Tab lTab = new Tab().withText(name).withIcon(icon).withNode(node);
		tabs.add(lTab);
		return this;
	}
	
	/**
	 * Convenience method
	 */
	public AccordionPane addTab(Node icon, Node node) {
		Tab lTab = new Tab().withIcon(icon).withNode(node);
		tabs.add(lTab);
		return this;
	}
	
	/** visibleTab */
	public ObjectProperty visibleTabProperty() { return visibleTabObjectProperty; }
	volatile private ObjectProperty visibleTabObjectProperty = new SimpleObjectProperty(this, "visibleTab", null);
	public Tab getVisibleTab() { return visibleTabObjectProperty.getValue(); }
	public void setVisibleTab(Tab value) { visibleTabObjectProperty.setValue(value); }
	public AccordionPane withVisibleTab(Tab value) { setVisibleTab(value); return this; }

	// ==================================================================================================================
	// TAB

	public static class Tab {

		/** text */
		public ObjectProperty textProperty() { return textObjectProperty; }
		volatile private ObjectProperty textObjectProperty = new SimpleObjectProperty(this, "text", null);
		public String getText() { return textObjectProperty.getValue(); }
		public void setText(String value) { textObjectProperty.setValue(value); }
		public Tab withText(String value) { setText(value); return this; }
		
		/** icon */
		public ObjectProperty iconProperty() { return iconObjectProperty; }
		volatile private ObjectProperty iconObjectProperty = new SimpleObjectProperty(this, "icon", null);
		public Node getIcon() { return iconObjectProperty.getValue(); }
		public void setIcon(Node value) { iconObjectProperty.setValue(value); }
		public Tab withIcon(Node value) { setIcon(value); return this; }
		
		/** node */
		public ObjectProperty nodeProperty() { return nodeObjectProperty; }
		volatile private ObjectProperty nodeObjectProperty = new SimpleObjectProperty(this, "node", null);
		public Node getNode() { return nodeObjectProperty.getValue(); }
		public void setNode(Node value) { nodeObjectProperty.setValue(value); }
		public Tab withNode(Node value) { setNode(value); return this; }
		
		public String toString() {
			return super.toString() 
			     + ", text=" + getText()
			     ;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy