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.scene.ParentBuilder;
029import javafx.util.Builder;
030import javafx.util.Callback;
031import javafx.event.EventHandler;
032import javafx.geometry.Rectangle2D;
033
034/**
035 * The builder for the {@link WebView} class.
036 *
037 * @author Sergey Malenkov
038 * @deprecated This class is deprecated and will be removed in the next version
039 */
040@Deprecated
041public final class WebViewBuilder
042        extends ParentBuilder<WebViewBuilder>
043        implements Builder<WebView> {
044
045    /**
046     * Creates new builder for the {@link WebView} class.
047     *
048     * @return the {@code WebViewBuilder} object
049     */
050    public static WebViewBuilder create() {
051        return new WebViewBuilder();
052    }
053
054    /**
055     * Creates an instance of the {@link WebView} class
056     * based on the properties set on this builder.
057     */
058    public WebView build() {
059        WebView x = new WebView();
060        applyTo(x);
061        return x;
062    }
063
064    /**
065     * Applies initialized values to the properties of the {@link WebView} class.
066     *
067     * @param view  the {@link WebView} object to initialize
068     */
069    public void applyTo(WebView view) {
070        super.applyTo(view);
071        if (fontScaleSet) {
072            view.setFontScale(fontScale);
073        }
074        if (maxHeightSet) {
075            view.setMaxHeight(maxHeight);
076        }
077        if (maxWidthSet) {
078            view.setMaxWidth(maxWidth);
079        }
080        if (minHeightSet) {
081            view.setMinHeight(minHeight);
082        }
083        if (minWidthSet) {
084            view.setMinWidth(minWidth);
085        }
086        if (prefHeightSet) {
087            view.setPrefHeight(prefHeight);
088        }
089        if (prefWidthSet) {
090            view.setPrefWidth(prefWidth);
091        }
092        if (engineBuilder != null) {
093            engineBuilder.applyTo(view.getEngine());
094        }
095    }
096
097    /**
098     * Sets the {@link WebView#fontScaleProperty() fontScale}
099     * property for the instance constructed by this builder.
100     *
101     * @param value  new value of the {@code fontScale} property
102     * @return this builder
103     */
104    public WebViewBuilder fontScale(double value) {
105        fontScale = value;
106        fontScaleSet = true;
107        return this;
108    }
109
110    private double fontScale;
111    private boolean fontScaleSet;
112
113    /**
114     * Sets the {@link WebView#maxHeightProperty() maxHeight}
115     * property for the instance constructed by this builder.
116     *
117     * @param value  new value of the {@code maxHeight} property
118     * @return this builder
119     */
120    public WebViewBuilder maxHeight(double value) {
121        maxHeight = value;
122        maxHeightSet = true;
123        return this;
124    }
125
126    private double maxHeight;
127    private boolean maxHeightSet;
128
129    /**
130     * Sets the {@link WebView#maxWidthProperty() maxWidth}
131     * property for the instance constructed by this builder.
132     *
133     * @param value  new value of the {@code maxWidth} property
134     * @return this builder
135     */
136    public WebViewBuilder maxWidth(double value) {
137        maxWidth = value;
138        maxWidthSet = true;
139        return this;
140    }
141
142    private double maxWidth;
143    private boolean maxWidthSet;
144
145    /**
146     * Sets the {@link WebView#minHeightProperty() minHeight}
147     * property for the instance constructed by this builder.
148     *
149     * @param value  new value of the {@code minHeight} property
150     * @return this builder
151     */
152    public WebViewBuilder minHeight(double value) {
153        minHeight = value;
154        minHeightSet = true;
155        return this;
156    }
157
158    private double minHeight;
159    private boolean minHeightSet;
160
161    /**
162     * Sets the {@link WebView#minWidthProperty() minWidth}
163     * property for the instance constructed by this builder.
164     *
165     * @param value  new value of the {@code minWidth} property
166     * @return this builder
167     */
168    public WebViewBuilder minWidth(double value) {
169        minWidth = value;
170        minWidthSet = true;
171        return this;
172    }
173
174    private double minWidth;
175    private boolean minWidthSet;
176
177    /**
178     * Sets the {@link WebView#prefHeightProperty() prefHeight}
179     * property for the instance constructed by this builder.
180     *
181     * @param value  new value of the {@code prefHeight} property
182     * @return this builder
183     */
184    public WebViewBuilder prefHeight(double value) {
185        prefHeight = value;
186        prefHeightSet = true;
187        return this;
188    }
189
190    private double prefHeight;
191    private boolean prefHeightSet;
192
193    /**
194     * Sets the {@link WebView#prefWidthProperty() prefWidth}
195     * property for the instance constructed by this builder.
196     *
197     * @param value  new value of the {@code prefWidth} property
198     * @return this builder
199     */
200    public WebViewBuilder prefWidth(double value) {
201        prefWidth = value;
202        prefWidthSet = true;
203        return this;
204    }
205
206    private double prefWidth;
207    private boolean prefWidthSet;
208
209    /**
210     * Sets the {@link WebEngine#confirmHandlerProperty() confirmHandler}
211     * property for the {@link WebView#getEngine() engine}
212     * property of the instance constructed by this builder.
213     *
214     * @param value  new value of the {@code confirmHandler} property
215     * @return this builder
216     */
217    public WebViewBuilder confirmHandler(Callback<String, Boolean> value) {
218        engineBuilder().confirmHandler(value);
219        return this;
220    }
221
222    /**
223     * Sets the {@link WebEngine#createPopupHandlerProperty() createPopupHandler}
224     * property for the {@link WebView#getEngine() engine}
225     * property of the instance constructed by this builder.
226     *
227     * @param value  new value of the {@code createPopupHandler} property
228     * @return this builder
229     */
230    public WebViewBuilder createPopupHandler(Callback<PopupFeatures, WebEngine> value) {
231        engineBuilder().createPopupHandler(value);
232        return this;
233    }
234
235    /**
236     * Sets the {@link WebEngine#onAlertProperty() onAlert}
237     * property for the {@link WebView#getEngine() engine}
238     * property of the instance constructed by this builder.
239     *
240     * @param value  new value of the {@code onAlert} property
241     * @return this builder
242     */
243    public WebViewBuilder onAlert(EventHandler<WebEvent<String>> value) {
244        engineBuilder().onAlert(value);
245        return this;
246    }
247
248    /**
249     * Sets the {@link WebEngine#onResizedProperty() onResized}
250     * property for the {@link WebView#getEngine() engine}
251     * property of the instance constructed by this builder.
252     *
253     * @param value  new value of the {@code onResized} property
254     * @return this builder
255     */
256    public WebViewBuilder onResized(EventHandler<WebEvent<Rectangle2D>> value) {
257        engineBuilder().onResized(value);
258        return this;
259    }
260
261    /**
262     * Sets the {@link WebEngine#onStatusChangedProperty() onStatusChanged}
263     * property for the {@link WebView#getEngine() engine}
264     * property of the instance constructed by this builder.
265     *
266     * @param value  new value of the {@code onStatusChanged} property
267     * @return this builder
268     */
269    public WebViewBuilder onStatusChanged(EventHandler<WebEvent<String>> value) {
270        engineBuilder().onStatusChanged(value);
271        return this;
272    }
273
274    /**
275     * Sets the {@link WebEngine#onVisibilityChangedProperty() onVisibilityChanged}
276     * property for the {@link WebView#getEngine() engine}
277     * property of the instance constructed by this builder.
278     *
279     * @param value  new value of the {@code onVisibilityChanged} property
280     * @return this builder
281     */
282    public WebViewBuilder onVisibilityChanged(EventHandler<WebEvent<Boolean>> value) {
283        engineBuilder().onVisibilityChanged(value);
284        return this;
285    }
286
287    /**
288     * Sets the {@link WebEngine#promptHandlerProperty() promptHandler}
289     * property for the {@link WebView#getEngine() engine}
290     * property of the instance constructed by this builder.
291     *
292     * @param value  new value of the {@code promptHandler} property
293     * @return this builder
294     */
295    public WebViewBuilder promptHandler(Callback<PromptData, String> value) {
296        engineBuilder().promptHandler(value);
297        return this;
298    }
299
300    /**
301     * Sets the {@link WebEngine#locationProperty() location}
302     * property for the {@link WebView#getEngine() engine}
303     * property of the instance constructed by this builder.
304     *
305     * @param value  new value of the {@code location} property
306     * @return this builder
307     */
308    public WebViewBuilder location(String value) {
309        engineBuilder().location(value);
310        return this;
311    }
312
313    private WebEngineBuilder engineBuilder;
314
315    private WebEngineBuilder engineBuilder() {
316        if (engineBuilder == null) {
317            engineBuilder = WebEngineBuilder.create();
318        }
319        return engineBuilder;
320    }
321}