Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 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.shape;
027
028import com.sun.javafx.geom.BaseBounds;
029import com.sun.javafx.geom.PickRay;
030import com.sun.javafx.geom.transform.BaseTransform;
031import com.sun.javafx.scene.DirtyBits;
032import com.sun.javafx.scene.input.PickResultChooser;
033import com.sun.javafx.sg.PGMeshView;
034import com.sun.javafx.sg.PGNode;
035import com.sun.javafx.tk.Toolkit;
036import javafx.beans.property.ObjectProperty;
037import javafx.beans.property.SimpleObjectProperty;
038import javafx.beans.value.ChangeListener;
039import javafx.beans.value.ObservableValue;
040
041/**
042 * The {@code MeshView} class defines a surface with the specified 3D
043 * mesh data.
044 *
045 * @since JavaFX 8    
046 */
047public class MeshView extends Shape3D {
048
049    /**
050     * Creates a new instance of {@code MeshView} class.
051     */
052    public MeshView() {
053    }
054
055    /**
056     * Creates a new instance of {@code MeshView} class with the specified {@code Mesh}
057     * surface.
058     */
059    public MeshView(Mesh mesh) {
060        setMesh(mesh);
061    }
062
063    /**
064     * Specifies the 3D mesh data of this {@code MeshView}.
065     *
066     * @defaultValue null
067     */
068    private ObjectProperty<Mesh> mesh;
069
070    public final void setMesh(Mesh value) {
071        meshProperty().set(value);
072    }
073
074    public final Mesh getMesh() {
075        return mesh == null ? null : mesh.get();
076    }
077
078    private final ChangeListener<Boolean> meshListener = new ChangeListener<Boolean>() {
079        @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
080            if (newValue) {
081                impl_markDirty(DirtyBits.MESH_GEOM);
082                impl_geomChanged();
083            }
084        }
085    };
086
087    public final ObjectProperty<Mesh> meshProperty() {
088        if (mesh == null) {
089            mesh = new SimpleObjectProperty<Mesh>(MeshView.this, "mesh") {
090                private Mesh old = null;
091
092                @Override
093                protected void invalidated() {
094                    if (old != null) {
095                        old.dirtyProperty().removeListener(meshListener);
096                    }
097                    Mesh newMesh = get();
098                    if (newMesh != null) {
099                        newMesh.dirtyProperty().addListener(meshListener);
100                    }
101                    impl_markDirty(DirtyBits.MESH);
102                    impl_markDirty(DirtyBits.MESH_GEOM);
103                    impl_geomChanged();
104                    old = newMesh;
105                }
106            };
107        }
108        return mesh;
109    }
110
111    /**
112     * @treatAsPrivate implementation detail
113     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
114     */
115    @Deprecated
116    @Override public void impl_updatePG() {
117        super.impl_updatePG();
118        PGMeshView pgMeshView = (PGMeshView)impl_getPGNode();
119        if (impl_isDirty(DirtyBits.MESH_GEOM) && getMesh() != null) {
120            getMesh().impl_updatePG();
121        }
122        if (impl_isDirty(DirtyBits.MESH)) {
123            pgMeshView.setMesh((getMesh() == null) ? null : getMesh().getPGMesh());
124        }
125    }
126
127    /**
128     * @treatAsPrivate implementation detail
129     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
130     */
131    @Deprecated
132    @Override
133    protected PGNode impl_createPGNode() {
134        return Toolkit.getToolkit().createPGMeshView();
135    }
136
137    /**
138     * @treatAsPrivate implementation detail
139     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
140     */
141    @Deprecated
142    @Override
143    public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx) {
144        bounds = mesh.get().computeBounds(bounds);
145        bounds = tx.transform(bounds, bounds);
146        return bounds;
147    }
148
149    /**
150     * @treatAsPrivate implementation detail
151     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
152     */
153    @Deprecated
154    @Override
155    protected boolean impl_computeContains(double localX, double localY) {
156        throw new UnsupportedOperationException("Not supported yet.");
157    }
158
159    /**
160     * @treatAsPrivate implementation detail
161     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
162     */
163    @Override
164    @Deprecated
165    protected boolean impl_computeIntersects(PickRay pickRay, PickResultChooser pickResult) {
166        return getMesh().impl_computeIntersects(pickRay, pickResult, this, getCullFace(), true);
167    }
168
169}