Skip to content

Commit 1298759

Browse files
author
nicolaiparlog
committed
'WebViewHyperlinkListenerHandle' implements 'ListenerHandle' contract.
1 parent de3708d commit 1298759

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/main/java/org/codefx/libfx/control/webview/DefaultWebViewHyperlinkListenerHandle.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ class DefaultWebViewHyperlinkListenerHandle implements WebViewHyperlinkListenerH
6969
* Executes {@link #attachListenerInApplicationThread()} each time the web view's load worker changes its state to
7070
* {@link State#SUCCEEDED SUCCEEDED}.
7171
* <p>
72-
* The executer is only present while the listener is attached.
72+
* The executer is only present while the listener is {@link #attached}.
7373
*/
7474
private Optional<ExecuteAlwaysWhen<State>> attachWhenLoadSucceeds;
7575

76+
/**
77+
* Indicates whether the listener is currently attached.
78+
*/
79+
private boolean attached;
80+
7681
// #end ATTRIBUTES
7782

7883
/**
79-
* Creates a new listener handle for the specified arguments.
84+
* Creates a new listener handle for the specified arguments. The listener is not attached to the web view.
8085
*
8186
* @param webView
8287
* the {@link WebView} to which the {@code eventListener} will be attached
@@ -103,6 +108,10 @@ public DefaultWebViewHyperlinkListenerHandle(
103108

104109
@Override
105110
public void attach() {
111+
if (attached)
112+
return;
113+
114+
attached = true;
106115
if (Platform.isFxApplicationThread())
107116
attachInApplicationThreadEachTimeLoadSucceeds();
108117
else
@@ -144,6 +153,10 @@ private void attachListenerInApplicationThread() {
144153

145154
@Override
146155
public void detach() {
156+
if (!attached)
157+
return;
158+
159+
attached = false;
147160
if (Platform.isFxApplicationThread())
148161
detachInApplicationThread();
149162
else

src/main/java/org/codefx/libfx/control/webview/WebViewHyperlinkListenerHandle.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
/**
99
* A {@link ListenerHandle} for a {@link WebViewHyperlinkListener}.
10+
*
11+
* @see ListenerHandle
12+
* @see WebViewHyperlinkListener
1013
*/
1114
public interface WebViewHyperlinkListenerHandle extends ListenerHandle {
1215

@@ -17,6 +20,8 @@ public interface WebViewHyperlinkListenerHandle extends ListenerHandle {
1720
* {@link WebEngine#getLoadWorker() loadWorker}. If it is not called on the FX Application Thread, the listener will
1821
* be added at some unspecified time in the future. If the {@code loadWorker} is currently loading, the listener is
1922
* attached as soon as it is done.
23+
*
24+
* @see ListenerHandle#attach()
2025
*/
2126
@Override
2227
void attach();
@@ -26,6 +31,8 @@ public interface WebViewHyperlinkListenerHandle extends ListenerHandle {
2631
* <p>
2732
* This method can be called from any thread and regardless of the state of the {@code WebView}'s
2833
* {@link WebEngine#getLoadWorker() loadWorker}.
34+
*
35+
* @see ListenerHandle#detach()
2936
*/
3037
@Override
3138
void detach();

0 commit comments

Comments
 (0)