Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 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.control;
027
028import javafx.css.CssMetaData;
029import com.sun.javafx.scene.control.skin.ProgressBarSkin;
030import javafx.css.StyleableProperty;
031
032/**
033 * A specialization of the ProgressIndicator which is represented as a
034 * horizontal bar.
035 * <p>
036 * ProgressBar sets focusTraversable to false.
037 * </p>
038 *
039 * <p>
040 * This first example creates a ProgressBar with an indeterminate value :
041 * <pre><code>
042 * import javafx.scene.control.ProgressBar;
043 * 
044 * ProgressBar p1 = new ProgressBar();
045 * </code></pre>
046 * <p>
047 * This next example creates a ProgressBar which is 25% complete :
048 * <pre><code>
049 * import javafx.scene.control.ProgressBar;
050 * ProgressBar p2 = new ProgressBar();
051 * p2.setProgress(0.25F);
052 * </code></pre>
053 *
054 * Implementation of ProgressBar According to JavaFX UI Control API Specification
055 */
056public class ProgressBar extends ProgressIndicator {
057
058
059    /***************************************************************************
060     *                                                                         *
061     * Constructors                                                            *
062     *                                                                         *
063     **************************************************************************/
064
065    /**
066     * Creates a new indeterminate ProgressBar.
067     */
068    public ProgressBar() {
069        this(INDETERMINATE_PROGRESS);
070    }
071
072    /**
073     * Creates a new ProgressBar with the given progress value.
074     */
075    public ProgressBar(double progress) {
076        // focusTraversable is styleable through css. Calling setFocusTraversable
077        // makes it look to css like the user set the value and css will not 
078        // override. Initializing focusTraversable by calling set on the 
079        // CssMetaData ensures that css will be able to override the value.
080        ((StyleableProperty)focusTraversableProperty()).applyStyle(null, Boolean.FALSE);
081        setProgress(progress);
082        getStyleClass().setAll(DEFAULT_STYLE_CLASS);
083    }
084
085    /***************************************************************************
086     *                                                                         *
087     * Methods                                                                 *
088     *                                                                         *
089     **************************************************************************/
090
091    /** {@inheritDoc} */
092    @Override protected Skin<?> createDefaultSkin() {
093        return new ProgressBarSkin(this);
094    }
095
096    /***************************************************************************
097     *                                                                         *
098     * Stylesheet Handling                                                     *
099     *                                                                         *
100     **************************************************************************/
101
102    /**
103     * Initialize the style class to 'progress-bar'.
104     *
105     * This is the selector class from which CSS can be used to style
106     * this control.
107     */
108    private static final String DEFAULT_STYLE_CLASS = "progress-bar";
109        
110    /**
111      * Most Controls return true for focusTraversable, so Control overrides
112      * this method to return true, but ProgressBar returns false for
113      * focusTraversable's initial value; hence the override of the override. 
114      * This method is called from CSS code to get the correct initial value.
115      * @treatAsPrivate implementation detail
116      */
117    @Deprecated @Override
118    protected /*do not make final*/ Boolean impl_cssGetFocusTraversableInitialValue() {
119        return Boolean.FALSE;
120    }
121    
122}