jfxtras.labs.scene.control.grid.GridViewBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfxtras-labs Show documentation
Show all versions of jfxtras-labs Show documentation
Experimental components for JavaFX 2
The newest version!
/**
* GridViewBuilder.java
*
* Copyright (c) 2011-2015, JFXtras
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the organization nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package jfxtras.labs.scene.control.grid;
import java.util.HashMap;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ObservableList;
import javafx.util.Builder;
import javafx.util.Callback;
/**
*
* @author Hendrik Ebbers
*
*/
public class GridViewBuilder, T> implements
Builder> {
private static final String ITEMS = "items";
private static final String CELL_FACTORY = "cellFactory";
private static final String CELL_WIDTH = "cellWidth";
private static final String CELL_HEIGHT = "cellHeight";
private static final String HORIZONTAL_CELL_SPACING = "horizontalCellSpacing";
private static final String VERTICAL_CELL_SPACING = "verticalCellSpacing";
@SuppressWarnings("rawtypes")
private HashMap properties = new HashMap();
protected GridViewBuilder() {
super();
};
public static final > GridViewBuilder create(Class cls) {
return new GridViewBuilder();
}
public final GridViewBuilder items(ObservableList items) {
properties.put(ITEMS, new SimpleObjectProperty>(items));
return this;
}
public final GridViewBuilder cellFactory(Callback, GridCell> cellFactory) {
properties.put(CELL_FACTORY, new SimpleObjectProperty, GridCell>>(cellFactory));
return this;
}
public final GridViewBuilder cellWidth(double cellWidth) {
properties.put(CELL_WIDTH, new SimpleObjectProperty(cellWidth));
return this;
}
public final GridViewBuilder cellHeight(double cellHeight) {
properties.put(CELL_HEIGHT, new SimpleObjectProperty(cellHeight));
return this;
}
public final GridViewBuilder horizontalCellSpacing(double horizontalCellSpacing) {
properties.put(HORIZONTAL_CELL_SPACING, new SimpleObjectProperty(horizontalCellSpacing));
return this;
}
public final GridViewBuilder verticalCellSpacing(double verticalCellSpacing) {
properties.put(VERTICAL_CELL_SPACING, new SimpleObjectProperty(verticalCellSpacing));
return this;
}
@SuppressWarnings("unchecked")
@Override
public GridView build() {
final GridView control = new GridView<>();
for (String key : properties.keySet()) {
if (ITEMS.equals(key)) {
control.setItems(((SimpleObjectProperty>) properties
.get(key)).get());
} else if (CELL_FACTORY.equals(key)) {
control.setCellFactory(((SimpleObjectProperty, GridCell>>) properties
.get(key)).get());
} else if (CELL_WIDTH.equals(key)) {
control.setCellWidth(((SimpleObjectProperty) properties
.get(key)).get());
} else if (CELL_HEIGHT.equals(key)) {
control.setCellHeight(((SimpleObjectProperty) properties
.get(key)).get());
} else if (HORIZONTAL_CELL_SPACING.equals(key)) {
control.setHorizontalCellSpacing(((SimpleObjectProperty) properties
.get(key)).get());
} else if (VERTICAL_CELL_SPACING.equals(key)) {
control.setVerticalCellSpacing(((SimpleObjectProperty) properties
.get(key)).get());
}
}
return control;
}
}