File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
src/main/java/org/codefx/libfx/control/webview Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -69,14 +69,19 @@ class DefaultWebViewHyperlinkListenerHandle implements WebViewHyperlinkListenerH
69
69
* Executes {@link #attachListenerInApplicationThread()} each time the web view's load worker changes its state to
70
70
* {@link State#SUCCEEDED SUCCEEDED}.
71
71
* <p>
72
- * The executer is only present while the listener is attached.
72
+ * The executer is only present while the listener is {@link # attached} .
73
73
*/
74
74
private Optional <ExecuteAlwaysWhen <State >> attachWhenLoadSucceeds ;
75
75
76
+ /**
77
+ * Indicates whether the listener is currently attached.
78
+ */
79
+ private boolean attached ;
80
+
76
81
// #end ATTRIBUTES
77
82
78
83
/**
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.
80
85
*
81
86
* @param webView
82
87
* the {@link WebView} to which the {@code eventListener} will be attached
@@ -103,6 +108,10 @@ public DefaultWebViewHyperlinkListenerHandle(
103
108
104
109
@ Override
105
110
public void attach () {
111
+ if (attached )
112
+ return ;
113
+
114
+ attached = true ;
106
115
if (Platform .isFxApplicationThread ())
107
116
attachInApplicationThreadEachTimeLoadSucceeds ();
108
117
else
@@ -144,6 +153,10 @@ private void attachListenerInApplicationThread() {
144
153
145
154
@ Override
146
155
public void detach () {
156
+ if (!attached )
157
+ return ;
158
+
159
+ attached = false ;
147
160
if (Platform .isFxApplicationThread ())
148
161
detachInApplicationThread ();
149
162
else
Original file line number Diff line number Diff line change 7
7
8
8
/**
9
9
* A {@link ListenerHandle} for a {@link WebViewHyperlinkListener}.
10
+ *
11
+ * @see ListenerHandle
12
+ * @see WebViewHyperlinkListener
10
13
*/
11
14
public interface WebViewHyperlinkListenerHandle extends ListenerHandle {
12
15
@@ -17,6 +20,8 @@ public interface WebViewHyperlinkListenerHandle extends ListenerHandle {
17
20
* {@link WebEngine#getLoadWorker() loadWorker}. If it is not called on the FX Application Thread, the listener will
18
21
* be added at some unspecified time in the future. If the {@code loadWorker} is currently loading, the listener is
19
22
* attached as soon as it is done.
23
+ *
24
+ * @see ListenerHandle#attach()
20
25
*/
21
26
@ Override
22
27
void attach ();
@@ -26,6 +31,8 @@ public interface WebViewHyperlinkListenerHandle extends ListenerHandle {
26
31
* <p>
27
32
* This method can be called from any thread and regardless of the state of the {@code WebView}'s
28
33
* {@link WebEngine#getLoadWorker() loadWorker}.
34
+ *
35
+ * @see ListenerHandle#detach()
29
36
*/
30
37
@ Override
31
38
void detach ();
You can’t perform that action at this time.
0 commit comments