Spec-Zone .ru
спецификации, руководства, описания, API
001/* 
002 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.scene.web;
027
028import javafx.event.EventHandler;
029import javafx.geometry.Rectangle2D;
030import javafx.util.Builder;
031import javafx.util.Callback;
032
033/**
034 * The builder for the {@link WebEngine} class.
035 *
036 * @author Sergey Malenkov
037 * @deprecated This class is deprecated and will be removed in the next version
038 */
039@Deprecated
040public final class WebEngineBuilder
041        implements Builder<WebEngine> {
042
043    /**
044     * Creates new builder for the {@link WebEngine} class.
045     *
046     * @return the {@code WebEngineBuilder} object
047     */
048    public static WebEngineBuilder create() {
049        return new WebEngineBuilder();
050    }
051
052    /**
053     * Creates an instance of the {@link WebEngine} class
054     * based on the properties set on this builder.
055     */
056    public WebEngine build() {
057        WebEngine engine = new WebEngine();
058        applyTo(engine);
059        return engine;
060    }
061
062    /**
063     * Applies initialized values to the properties of the {@link WebEngine} class.
064     *
065     * @param engine  the {@link WebEngine} object to initialize
066     */
067    public void applyTo(WebEngine engine) {
068        if (confirmHandlerSet) {
069            engine.setConfirmHandler(confirmHandler);
070        }
071        if (createPopupHandlerSet) {
072            engine.setCreatePopupHandler(createPopupHandler);
073        }
074        if (onAlertSet) {
075            engine.setOnAlert(onAlert);
076        }
077        if (onResizedSet) {
078            engine.setOnResized(onResized);
079        }
080        if (onStatusChangedSet) {
081            engine.setOnStatusChanged(onStatusChanged);
082        }
083        if (onVisibilityChangedSet) {
084            engine.setOnVisibilityChanged(onVisibilityChanged);
085        }
086        if (promptHandlerSet) {
087            engine.setPromptHandler(promptHandler);
088        }
089        if (locationSet) {
090            engine.load(location);
091        }
092    }
093
094    /**
095     * Sets the {@link WebEngine#confirmHandlerProperty() confirmHandler}
096     * property for the instance constructed by this builder.
097     *
098     * @param value  new value of the {@code confirmHandler} property
099     * @return this builder
100     */
101    public WebEngineBuilder confirmHandler(Callback<String, Boolean> value) {
102        confirmHandler = value;
103        confirmHandlerSet = true;
104        return this;
105    }
106
107    private Callback<String, Boolean> confirmHandler;
108    private boolean confirmHandlerSet;
109
110    /**
111     * Sets the {@link WebEngine#createPopupHandlerProperty() createPopupHandler}
112     * property for the instance constructed by this builder.
113     *
114     * @param value  new value of the {@code createPopupHandler} property
115     * @return this builder
116     */
117    public WebEngineBuilder createPopupHandler(Callback<PopupFeatures, WebEngine> value) {
118        createPopupHandler = value;
119        createPopupHandlerSet = true;
120        return this;
121    }
122
123    private Callback<PopupFeatures, WebEngine> createPopupHandler;
124    private boolean createPopupHandlerSet;
125
126    /**
127     * Sets the {@link WebEngine#onAlertProperty() onAlert}
128     * property for the instance constructed by this builder.
129     *
130     * @param value  new value of the {@code onAlert} property
131     * @return this builder
132     */
133    public WebEngineBuilder onAlert(EventHandler<WebEvent<String>> value) {
134        onAlert = value;
135        onAlertSet = true;
136        return this;
137    }
138
139    private EventHandler<WebEvent<String>> onAlert;
140    private boolean onAlertSet;
141
142    /**
143     * Sets the {@link WebEngine#onResizedProperty() onResized}
144     * property for the instance constructed by this builder.
145     *
146     * @param value  new value of the {@code onResized} property
147     * @return this builder
148     */
149    public WebEngineBuilder onResized(EventHandler<WebEvent<Rectangle2D>> value) {
150        onResized = value;
151        onResizedSet = true;
152        return this;
153    }
154
155    private EventHandler<WebEvent<Rectangle2D>> onResized;
156    private boolean onResizedSet;
157
158    /**
159     * Sets the {@link WebEngine#onStatusChangedProperty() onStatusChanged}
160     * property for the instance constructed by this builder.
161     *
162     * @param value  new value of the {@code onStatusChanged} property
163     * @return this builder
164     */
165    public WebEngineBuilder onStatusChanged(EventHandler<WebEvent<String>> value) {
166        onStatusChanged = value;
167        onStatusChangedSet = true;
168        return this;
169    }
170
171    private EventHandler<WebEvent<String>> onStatusChanged;
172    private boolean onStatusChangedSet;
173
174    /**
175     * Sets the {@link WebEngine#onVisibilityChangedProperty() onVisibilityChanged}
176     * property for the instance constructed by this builder.
177     *
178     * @param value  new value of the {@code onVisibilityChanged} property
179     * @return this builder
180     */
181    public WebEngineBuilder onVisibilityChanged(EventHandler<WebEvent<Boolean>> value) {
182        onVisibilityChanged = value;
183        onVisibilityChangedSet = true;
184        return this;
185    }
186
187    private EventHandler<WebEvent<Boolean>> onVisibilityChanged;
188    private boolean onVisibilityChangedSet;
189
190    /**
191     * Sets the {@link WebEngine#promptHandlerProperty() promptHandler}
192     * property for the instance constructed by this builder.
193     *
194     * @param value  new value of the {@code promptHandler} property
195     * @return this builder
196     */
197    public WebEngineBuilder promptHandler(Callback<PromptData, String> value) {
198        promptHandler = value;
199        promptHandlerSet = true;
200        return this;
201    }
202
203    private Callback<PromptData, String> promptHandler;
204    private boolean promptHandlerSet;
205
206    /**
207     * Sets the {@link WebEngine#locationProperty() location}
208     * property for the instance constructed by this builder.
209     *
210     * @param value  new value of the {@code location} property
211     * @return this builder
212     */
213    public WebEngineBuilder location(String value) {
214        location = value;
215        locationSet = true;
216        return this;
217    }
218
219    private String location;
220    private boolean locationSet;
221}