All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jfoenix.skins.JFXListViewSkin Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package com.jfoenix.skins;

import com.jfoenix.controls.JFXListView;
import com.jfoenix.effects.JFXDepthManager;
import com.sun.javafx.scene.control.skin.ListViewSkin;
import javafx.application.Platform;
import javafx.collections.ListChangeListener.Change;
import javafx.scene.control.ListCell;
import javafx.scene.layout.Region;

/**
 * 

Material Design ListView Skin

* * @author Shadi Shaheen * @version 1.0 * @since 2016-03-09 */ public class JFXListViewSkin extends ListViewSkin { public JFXListViewSkin(final JFXListView listView) { super(listView); JFXDepthManager.setDepth(flow, listView.depthProperty().get()); listView.depthProperty().addListener((o, oldVal, newVal) -> JFXDepthManager.setDepth(flow, newVal)); } @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { return 200; } @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { final int itemsCount = getSkinnable().getItems().size(); if (getSkinnable().maxHeightProperty().isBound() || itemsCount <= 0) { return super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); } final double fixedCellSize = getSkinnable().getFixedCellSize(); double computedHeight = fixedCellSize != Region.USE_COMPUTED_SIZE ? fixedCellSize * itemsCount + snapVerticalInsets() : estimateHeight(); double height = super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); if (height > computedHeight) { height = computedHeight; } if (getSkinnable().getMaxHeight() > 0 && computedHeight > getSkinnable().getMaxHeight()) { return getSkinnable().getMaxHeight(); } return height; } private double estimateHeight() { // compute the border/padding for the list double borderWidth = snapVerticalInsets(); // compute the gap between list cells JFXListView listview = (JFXListView) getSkinnable(); double gap = listview.isExpanded() ? ((JFXListView) getSkinnable()).getVerticalGap() * (getSkinnable().getItems() .size()) : 0; // compute the height of each list cell double cellsHeight = 0; for (int i = 0; i < flow.getCellCount(); i++) { ListCell cell = flow.getCell(i); cellsHeight += cell.getHeight(); } return cellsHeight + gap + borderWidth; } private double snapVerticalInsets() { return getSkinnable().snappedBottomInset() + getSkinnable().snappedTopInset(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy