javafx官方文檔學習之二Control體系學習之架構理解

個人博文小站:http://www.xby1993.net 最新資訊都在那裏

Package javafx.scene.control

Control基類及其繼承者。是主要的與用戶交互的UI組件。java

1、接口篇。app

Control實現了Skinnable接口,這個Skinnable接口就是能夠用皮膚渲染組件的標誌,實現它使組件能夠自由地更換各類皮膚成爲可能,這裏只說是可能,由於還須要一個類Skin--皮膚的表明。能夠這樣理解誒一個Control組件就是一個Skinnable,而後須要Skin來提供渲染的皮膚。ide

Skinnable接口主要有如下方法:this

Skin<?> getSkin()

Returns the skin that renders this Controllua

void setSkin(Skin<?> value)

Sets the skin that will render this Controlspa

ObjectProperty<Skin<?>> skinProperty()

Skin is responsible for rendering this Control..net

Skin皮膚接口定義瞭如何獲取皮膚的方法。皮膚Skin也須要用一個Node來提供皮膚外觀。
code

public interface Skin<C extends >
void dispose()

Called by a Skinnable when the Skin is replaced on the Skinnable.對象

Node getNode()

Gets the Node which represents this Skin.繼承

C getSkinnable()

Gets the Skinnable to which this Skin is assigned.


Interface TextInputControl.Content

這個接口就是文本輸入內容的表明。Interface representing a text input's content.Since it is an ObservableStringValue, you can also bind to, or observe the content.他是一個能夠被觀察的字符串文本值對象。你經過它能夠綁定或者觀察該文本內容的變化。

void delete(int start, int end, boolean notifyListeners)

Removes a sequence of characters from the content.

java.lang.String get(int start, int end)

Retrieves a subset of the content.

void insert(int index, java.lang.String text, boolean notifyListeners)

Inserts a sequence of characters into the content.

int length()

Returns the number of characters represented by the content.


它的父類有:

Observable:在javafx.beans中,An Observable is an entity that wraps content and allows to observe the content for invalidations.An implementation of Observable may support lazy evaluation, which means that the content is not immediately recomputed after changes, but lazily the next time it is requested(他並不在改變後立刻進行驗算,只是在請求時才驗算,這就是懶驗真。)

void addListener(InvalidationListener listener)

Adds an InvalidationListener which will be notified whenever the Observable becomes invalid.

void removeListener(InvalidationListener listener)

Removes the given listener from the list of listeners, that are notified whenever the value of the Observable becomes invalid.

javafx.beans.value

InvalidationListener

An InvalidationListener is notified whenever an ObservableValue becomes invalid. It can be registered and unregistered with Observable.addListener(InvalidationListener) respectively Observable.removeListener(InvalidationListener)

For an in-depth explanation of invalidation events and how they differ from change events, see the documentation of ObservableValue.

The same instance of InvalidationListener can be registered to listen to multiple ObservableValues.

InvalidationListener主要用於監聽ObservableValue(能夠監聽的值對象),它只是在值無效的時候被通知。

須要實現如下方法:

void invalidated(Observable observable)

This method needs to be provided by an implementation of InvalidationListener.

javafx.beans.value

Interface ObservableValue<T>

ObservableValue是Observable的子類。

通常狀況相愛咱們無須直接實現這個類,而是經過繼承它的子類來實現自定義附加功能

The value of the ObservableValue can be requested with getValue().

咱們可使用ObservableValue來監聽到兩種Value Change Event,一個是Value Change,一個是Value invadidation.能夠經過InvalidationListener和ChangeListener來進行監聽。

因爲繼承了Observale接口故而,它支持懶驗證模式。

An implementation of ObservableValue may support lazy evaluation


Important note: attaching a ChangeListener enforces eager computation even if the implementation of the ObservableValue supports lazy evaluation.

雖然支持懶驗證模式,可是若是你附加一個ChangeListener到這個上面,這會致使懶驗證失效,由於它不得不在每次值改變時進行提交驗算通知ChangeListener,而這會致使大量的無謂消耗,因此除非確實有很是迫切的必要,不然不要破壞這種懶驗證模式。

void addListener(ChangeListener<? super T> listener)

Adds a ChangeListener which will be notified whenever the value of the ObservableValue changes.

T getValue()

Returns the current value of this ObservableValue

void removeListener(ChangeListener<? super T> listener)

Removes the given listener from the list of listeners, that are notified whenever the value of the ObservableValue changes.

javafx.beans.value

Interface ChangeListener<T>

實現它要覆蓋:

void changed(ObservableValue<? extends T> observable, T oldValue, T newValue)

This method needs to be provided by an implementation of ChangeListener.


好了如今回到咱們的TextInputControl.Content

它實現了ObservableStringValue類,而這個類有

javafx.beans.value

Interface ObservableStringValue

TextInputControl.Content

Interface representing a text input's content. Since it is an ObservableStringValue, you can also bind to, or observe the content.

這個表明了咱們的文本輸入內容,可是它能夠綁定文本內容,監聽文本內容的變化和有效性。

void delete(int start, int end, boolean notifyListeners)

Removes a sequence of characters from the content.

java.lang.String get(int start, int end)

Retrieves a subset of the content.

void insert(int index, java.lang.String text, boolean notifyListeners)

Inserts a sequence of characters into the content.

int length()

Returns the number of characters represented by the content.

addListener,removeListener,getValue等方法均繼承ObservableValue接口addListenergetValueremoveListener


下面咱們來說

Toggle開關接口:

javafx.scene.control

Interface Toggle

Represents a control that can be toggled between selected and non-selected states. In addition, a Toggle can be assigned a ToggleGroup, which manages all assigned Toggles such that only a single Toggle within the ToggleGroup may be selected at any one time.

Toggle表明着單選或者開關狀態,它是RadioButton,RadioMenuItem,ToggleButton的實現接口。使用時須要注意與ToggleGroup一塊兒使用,

這相似與Swing裏面的RadioButton和RadioButtonGroup的關係,須要使用ToggleGroup來組成和管理一個單選組或開關組使之這個組裏只能有一個組件狀態能夠改變。

ObservableMap<java.lang.Object,java.lang.Object> getProperties()

Returns an observable map of properties on this toggle for use primarily by application developers.

ToggleGroup getToggleGroup()

Returns The ToggleGroup to which this Toggle belongs.

java.lang.Object getUserData()

Returns a previously set Object property, or null if no such property has been set using the Node.setUserData(java.lang.Object) method.

boolean isSelected()

Indicates whether this Toggle is selected.

BooleanProperty selectedProperty()

The selected state for this Toggle.

void setSelected(boolean selected)

Sets this Toggle as selected or unselected.

void setToggleGroup(ToggleGroup toggleGroup)

Sets the ToggleGroup to which this Toggle belongs.

void setUserData(java.lang.Object value)

Convenience method for setting a single Object property that can be retrieved at a later date.

ObjectProperty<ToggleGroup> toggleGroupProperty()

The ToggleGroup to which this Toggle belongs.


-----------------

ToggleGroup

Toggle getSelectedToggle()

Gets the selected Toggle.

ObservableList<Toggle> getToggles()

The list of toggles within the ToggleGroup.

ReadOnlyObjectProperty<Toggle> selectedToggleProperty()

The selected toggle.

void selectToggle(Toggle value)

Selects the toggle.

相關文章
相關標籤/搜索