de.rpgframework.jfx.section.IconSection Maven / Gradle / Ivy
package de.rpgframework.jfx.section;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.controlsfx.control.GridView;
import org.prelle.javafx.Section;
import org.prelle.javafx.SymbolIcon;
import de.rpgframework.genericrpg.data.DataItem;
import de.rpgframework.genericrpg.data.DataItemValue;
import de.rpgframework.jfx.RPGFrameworkJFXConstants;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionModel;
import javafx.scene.control.SingleSelectionModel;
import javafx.scene.image.Image;
import javafx.scene.layout.TilePane;
/**
* @author prelle
*
*/
public class IconSection> extends Section {
private final static Logger logger = System.getLogger(IconSection.class.getPackageName());
private final Image EMPTY = new Image(RPGFrameworkJFXConstants.class.getResourceAsStream("Person.png"));
final static int SIZE = 64;
protected Function iconResolver;
protected Button btnAdd;
protected Button btnDel;
protected IntegerProperty slots = new SimpleIntegerProperty(4);
protected ObservableList items = FXCollections.observableArrayList();
protected SelectionModel selectionModel = new SingleSelectionModel() {
@Override
protected D getModelItem(int index) {
return items.get(index);
}
@Override
protected int getItemCount() {
return items.size();
}
};
private ObjectProperty showHelpFor = new SimpleObjectProperty<>();
private ObjectProperty> onAddProperty = new SimpleObjectProperty<>();
private ObjectProperty> onDeleteProperty = new SimpleObjectProperty<>();
private GridView tiles;
// private ImageView[] iViews;
//-------------------------------------------------------------------
public IconSection(Function iconResolver, String title) {
this.iconResolver = iconResolver;
setTitle(title);
initComponents();
initLayout();
initInteractivity();
}
//-------------------------------------------------------------------
public ObservableList getItems() { return items; }
//-------------------------------------------------------------------
public IntegerProperty slotsProperty() { return slots; }
public int getSlots() { return slots.get(); }
public IconSection setSlots(int value) { slots.set(value); return this; }
//-------------------------------------------------------------------
public ReadOnlyObjectProperty showHelpForProperty() {
return showHelpFor;
}
//-------------------------------------------------------------------
private void initComponents() {
// tiles = new TilePane(10,10);
// tiles.setPrefTileHeight(SIZE+16);
// tiles.setPrefTileWidth(SIZE);
tiles = new GridView<>(items);
tiles.setHorizontalCellSpacing(10);
tiles.setVerticalCellSpacing(10);
tiles.setCellWidth(SIZE+4);
tiles.setCellHeight(SIZE+16);
// tiles.setCellFactory( gv -> new IconGridCell(this));
// iViews = new ImageView[20];
btnAdd = new Button(null, new SymbolIcon("add"));
btnDel = new Button(null, new SymbolIcon("delete"));
btnDel.setDisable(true);
getButtons().addAll(btnAdd, btnDel);
}
//-------------------------------------------------------------------
private void initLayout() {
setContent(tiles);
}
//-------------------------------------------------------------------
private void initInteractivity() {
slots.addListener( (ov,o,n) -> refresh());
items.addListener(new ListChangeListener() {
@Override
public void onChanged(Change extends D> changes) {
logger.log(Level.INFO, "Items changed");
refresh();
}});
btnAdd.setOnAction(ev -> onAdd(ev));
btnDel.setOnAction(ev -> onDelete(ev));
// card.pseudoClassStateChanged(PSEUDO_CLASS_SELECTED, !oldState);
// if (oldState) {
// selectionModel.clearSelection(handles.indexOf(charac));
// } else {
// selectionModel.select(handles.indexOf(charac));
// }
//
}
//-------------------------------------------------------------------
public void refresh() {
logger.log(Level.INFO, "refresh");
// List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy