commit
6735577c14
@ -0,0 +1,105 @@
|
|||||||
|
# ---> JetBrains
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
# ---> Java
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
replay_pid*
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="jpab" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Butterflies.iml" filepath="$PROJECT_DIR$/Butterflies.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="jfx-18.0.1" level="application" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.FlowPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<AnchorPane xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml">
|
||||||
|
<VBox>
|
||||||
|
<HBox alignment="CENTER_LEFT">
|
||||||
|
<Label text="name: "/>
|
||||||
|
<TextField fx:id="nameTF"/>
|
||||||
|
</HBox>
|
||||||
|
<FlowPane alignment="CENTER" hgap="10.0">
|
||||||
|
<Button defaultButton="true" onAction="#clickConfirm" text="OK"/>
|
||||||
|
<Button cancelButton="true" onAction="#clickCancel" text="Cancel"/>
|
||||||
|
</FlowPane>
|
||||||
|
</VBox>
|
||||||
|
</AnchorPane>
|
@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import java.lang.Integer?>
|
||||||
|
<BorderPane xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="view.MainWindow">
|
||||||
|
<fx:define>
|
||||||
|
<Integer fx:id="minus1" fx:value="-1"/>
|
||||||
|
</fx:define>
|
||||||
|
<center>
|
||||||
|
<SplitPane dividerPositions="0.3">
|
||||||
|
<ListView fx:id="butterfliesLV"/>
|
||||||
|
<VBox disable="${butterfliesLV.selectionModel.selectedIndex == minus1}" spacing="5.0">
|
||||||
|
<TextField fx:id="butterflyTF" promptText="name"/>
|
||||||
|
<AnchorPane>
|
||||||
|
<ListView fx:id="colorsLV" items="${butterfliesLV.selectionModel.selectedItem.colors}"
|
||||||
|
AnchorPane.bottomAnchor="0.0"
|
||||||
|
AnchorPane.topAnchor="0.0"
|
||||||
|
AnchorPane.rightAnchor="0.0"
|
||||||
|
AnchorPane.leftAnchor="0.0"/>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0"/>
|
||||||
|
</padding>
|
||||||
|
</AnchorPane>
|
||||||
|
<HBox spacing="5">
|
||||||
|
<ColorPicker fx:id="colorPicker"/>
|
||||||
|
<Button disable="${colorsLV.selectionModel.selectedIndex == minus1}"
|
||||||
|
onAction="#clickAddColors" text="Add colors"/>
|
||||||
|
<Button disable="${colorsLV.selectionModel.selectedIndex == minus1}"
|
||||||
|
onAction="#clickUnselectColor" text="Unselect"/>
|
||||||
|
<Button disable="${colorsLV.selectionModel.selectedIndex == minus1}"
|
||||||
|
onAction="#clickRemoveColor" text="Remove color"/>
|
||||||
|
</HBox>
|
||||||
|
</VBox>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
|
||||||
|
</padding>
|
||||||
|
</SplitPane>
|
||||||
|
</center>
|
||||||
|
<top>
|
||||||
|
<MenuBar>
|
||||||
|
<Menu text="Butterflies">
|
||||||
|
<MenuItem onAction="#clickAddButterfly" text="Add"/>
|
||||||
|
<MenuItem onAction="#clickRemoveButterfly" text="Delete"/>
|
||||||
|
<SeparatorMenuItem/>
|
||||||
|
<MenuItem onAction="#clickQuit" text="Quit"/>
|
||||||
|
</Menu>
|
||||||
|
</MenuBar>
|
||||||
|
</top>
|
||||||
|
</BorderPane>
|
@ -0,0 +1,5 @@
|
|||||||
|
package data;
|
||||||
|
|
||||||
|
public interface Loadable<T> {
|
||||||
|
public T load();
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package data;
|
||||||
|
|
||||||
|
import model.Butterfly;
|
||||||
|
import model.ButterflyManager;
|
||||||
|
|
||||||
|
public class Stub implements Loadable<ButterflyManager> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ButterflyManager load() {
|
||||||
|
ButterflyManager result = new ButterflyManager();
|
||||||
|
|
||||||
|
Butterfly jerry = new Butterfly("Jerry");
|
||||||
|
jerry.addColor(50, 100, 150);
|
||||||
|
jerry.addColor(20, 0, 240);
|
||||||
|
|
||||||
|
Butterfly tony = new Butterfly("Tony");
|
||||||
|
tony.addColor(50, 100, 150);
|
||||||
|
tony.addColor(150, 0, 150);
|
||||||
|
tony.addColor(0, 100, 0);
|
||||||
|
|
||||||
|
result.addButterfly("Jerry");
|
||||||
|
result.getButterflies().get(0).addColor(50, 100, 150);
|
||||||
|
result.getButterflies().get(0).addColor(150, 0, 150);
|
||||||
|
result.getButterflies().get(0).addColor(0, 100, 0);
|
||||||
|
|
||||||
|
result.addButterfly("Tony");
|
||||||
|
result.getButterflies().get(1).addColor(50, 100, 150);
|
||||||
|
result.getButterflies().get(1).addColor(20, 0, 240);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package launcher;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Launcher extends Application {
|
||||||
|
@Override
|
||||||
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
Parent root = FXMLLoader.load(getClass().getResource("/fxml/MainWindow.fxml"));
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
|
public class Butterfly {
|
||||||
|
|
||||||
|
private final StringProperty name = new SimpleStringProperty();
|
||||||
|
public String getName() {return name.get();}
|
||||||
|
public StringProperty nameProperty() {return name;}
|
||||||
|
public void setName(String name) {this.name.set(name);}
|
||||||
|
|
||||||
|
private final ObservableList<Color> colorsObs = FXCollections.observableArrayList();
|
||||||
|
private final ListProperty<Color> colors = new SimpleListProperty<>(colorsObs);
|
||||||
|
public ObservableList<Color> getColors() {return FXCollections.unmodifiableObservableList(colors.get());}
|
||||||
|
public ReadOnlyListProperty<Color> colorsProperty() {return colors;}
|
||||||
|
|
||||||
|
public Butterfly(String name) {
|
||||||
|
this.name.set(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addColor(int r, int g, int b) {
|
||||||
|
colorsObs.add(new Color(r, g, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeColor(Color toRemove) {
|
||||||
|
colorsObs.remove(toRemove);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import javafx.beans.property.ListProperty;
|
||||||
|
import javafx.beans.property.ReadOnlyListProperty;
|
||||||
|
import javafx.beans.property.SimpleListProperty;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
|
public class ButterflyManager {
|
||||||
|
|
||||||
|
private final ObservableList<Butterfly> butterfliesObs = FXCollections.observableArrayList();
|
||||||
|
private final ListProperty<Butterfly> butterflies = new SimpleListProperty<>(butterfliesObs);
|
||||||
|
public ObservableList<Butterfly> getButterflies() {return FXCollections.unmodifiableObservableList(butterflies.get());}
|
||||||
|
public ReadOnlyListProperty<Butterfly> butterfliesProperty() {return butterflies;}
|
||||||
|
|
||||||
|
public void addButterfly(String toAdd){
|
||||||
|
butterfliesObs.add(new Butterfly(toAdd));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeButterfly(Butterfly toRemove){
|
||||||
|
butterfliesObs.remove(toRemove);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package model;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
|
|
||||||
|
public class Color {
|
||||||
|
|
||||||
|
private final IntegerProperty red = new SimpleIntegerProperty();
|
||||||
|
public int getRed() {return red.get();}
|
||||||
|
public ReadOnlyIntegerProperty redProperty() {return red;}
|
||||||
|
private void setRed(int red) {this.red.set(red);}
|
||||||
|
|
||||||
|
private final IntegerProperty green = new SimpleIntegerProperty();
|
||||||
|
public int getGreen() {return green.get();}
|
||||||
|
public ReadOnlyIntegerProperty greenProperty() {return green;}
|
||||||
|
private void setGreen(int green) {this.green.set(green);}
|
||||||
|
|
||||||
|
private final IntegerProperty blue = new SimpleIntegerProperty();
|
||||||
|
public int getBlue() {return blue.get();}
|
||||||
|
public ReadOnlyIntegerProperty blueProperty() {return blue;}
|
||||||
|
private void setBlue(int blue) {this.blue.set(blue);}
|
||||||
|
|
||||||
|
private final ObjectProperty<javafx.scene.paint.Color> color = new SimpleObjectProperty<>();
|
||||||
|
public javafx.scene.paint.Color getColor() {return color.get();}
|
||||||
|
public ObjectProperty<javafx.scene.paint.Color> colorProperty() {return color;}
|
||||||
|
private void setColor(javafx.scene.paint.Color color) {this.color.set(color);}
|
||||||
|
|
||||||
|
public Color(int red, int green, int blue) {
|
||||||
|
|
||||||
|
color.addListener((__, ___, newV)->{
|
||||||
|
setRed((int)(newV.getRed() * 255));
|
||||||
|
setGreen((int)(newV.getGreen() * 255));
|
||||||
|
setBlue((int)(newV.getBlue() * 255));
|
||||||
|
});
|
||||||
|
|
||||||
|
color.set(new javafx.scene.paint.Color(
|
||||||
|
red / 255.,
|
||||||
|
green / 255.,
|
||||||
|
blue / 255.,
|
||||||
|
1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package view;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
public class CreationWindow {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField nameTF;
|
||||||
|
|
||||||
|
private String butterflyName = null;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickConfirm() {
|
||||||
|
butterflyName = nameTF.getText();
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickCancel() {
|
||||||
|
butterflyName = null;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close() {
|
||||||
|
nameTF.getScene().getWindow().hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getButterflyName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,184 @@
|
|||||||
|
package view;
|
||||||
|
|
||||||
|
import data.Stub;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import model.Butterfly;
|
||||||
|
import model.ButterflyManager;
|
||||||
|
import model.Color;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class MainWindow {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ColorPicker colorPicker;
|
||||||
|
@FXML
|
||||||
|
private TextField butterflyTF;
|
||||||
|
@FXML
|
||||||
|
private ListView<Color> colorsLV;
|
||||||
|
@FXML
|
||||||
|
private ListView<Butterfly> butterfliesLV;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickAddColors(ActionEvent actionEvent) {
|
||||||
|
if (colorPicker.getValue() != null) {
|
||||||
|
butterfliesLV.getSelectionModel()
|
||||||
|
.getSelectedItem()
|
||||||
|
.addColor((int) (colorPicker.getValue().getRed()),
|
||||||
|
(int) (colorPicker.getValue().getGreen()),
|
||||||
|
(int) (colorPicker.getValue().getBlue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickRemoveColor(ActionEvent actionEvent) {
|
||||||
|
|
||||||
|
if (butterfliesLV.getSelectionModel().getSelectedIndex() != -1 &&
|
||||||
|
colorsLV.getSelectionModel().getSelectedIndex() != -1)
|
||||||
|
{
|
||||||
|
butterfliesLV.getSelectionModel()
|
||||||
|
.getSelectedItem()
|
||||||
|
.removeColor(colorsLV.getSelectionModel().getSelectedItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickUnselectColor(ActionEvent actionEvent) {
|
||||||
|
colorsLV.getSelectionModel().select(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickAddButterfly(ActionEvent actionEvent) {
|
||||||
|
Stage creationWindowStage = new Stage();
|
||||||
|
creationWindowStage.initOwner(butterfliesLV.getScene().getWindow());
|
||||||
|
creationWindowStage.initModality(Modality.WINDOW_MODAL);
|
||||||
|
|
||||||
|
CreationWindow controller = initCreationWindow(creationWindowStage);
|
||||||
|
|
||||||
|
if (controller.getButterflyName() != null) {
|
||||||
|
mgr.addButterfly(controller.getButterflyName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private CreationWindow initCreationWindow(Stage creationWindowStage) {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/CreationWindow.fxml"));
|
||||||
|
CreationWindow controller = new CreationWindow();
|
||||||
|
loader.setController(controller);
|
||||||
|
try {
|
||||||
|
creationWindowStage.setScene(new Scene(loader.load()));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
new Alert(Alert.AlertType.ERROR,
|
||||||
|
"error while opening creation window",
|
||||||
|
ButtonType.OK).setHeaderText(null);
|
||||||
|
}
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickRemoveButterfly(ActionEvent actionEvent) {
|
||||||
|
if (butterfliesLV.getSelectionModel().getSelectedIndex() != -1) {
|
||||||
|
mgr.removeButterfly(butterfliesLV.getSelectionModel().getSelectedItem());
|
||||||
|
colorsLV.getItems().clear();
|
||||||
|
butterflyTF.setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clickQuit(ActionEvent actionEvent) {
|
||||||
|
butterfliesLV.getScene().getWindow().hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ButterflyManager mgr = new Stub().load();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void initialize() {
|
||||||
|
|
||||||
|
butterfliesLV.itemsProperty().bind(mgr.butterfliesProperty());
|
||||||
|
|
||||||
|
addListenerButterfliesLV();
|
||||||
|
addListenerColorsLV();
|
||||||
|
|
||||||
|
setCellFatoryButterfliesLV();
|
||||||
|
setCellFatoryColorsLV();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCellFatoryButterfliesLV() {
|
||||||
|
butterfliesLV.setCellFactory(__ -> new ListCell<>() {
|
||||||
|
@Override
|
||||||
|
protected void updateItem(Butterfly item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
|
||||||
|
if (!empty) {
|
||||||
|
textProperty().bind(item.nameProperty());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textProperty().unbind();
|
||||||
|
setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCellFatoryColorsLV() {
|
||||||
|
colorsLV.setCellFactory(__ -> new ListCell<>() {
|
||||||
|
@Override
|
||||||
|
protected void updateItem(Color item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
|
||||||
|
if (!empty) {
|
||||||
|
HBox hbox = new HBox();
|
||||||
|
initLayout(item, hbox);
|
||||||
|
setGraphic(hbox);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setGraphic(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initLayout(Color item, Pane layout) {
|
||||||
|
Rectangle rect = new Rectangle();
|
||||||
|
rect.fillProperty().bind(item.colorProperty());
|
||||||
|
rect.setHeight(20);
|
||||||
|
rect.setWidth(100);
|
||||||
|
|
||||||
|
layout.getChildren().add(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addListenerButterfliesLV() {
|
||||||
|
butterfliesLV.getSelectionModel().selectedItemProperty().addListener((__, oldV, newV) -> {
|
||||||
|
if (oldV != null) {
|
||||||
|
butterflyTF.textProperty().unbindBidirectional(oldV.nameProperty());
|
||||||
|
colorsLV.itemsProperty().unbind();
|
||||||
|
}
|
||||||
|
if (newV != null) {
|
||||||
|
butterflyTF.textProperty().bindBidirectional(newV.nameProperty());
|
||||||
|
colorsLV.itemsProperty().bind(newV.colorsProperty());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addListenerColorsLV() {
|
||||||
|
colorsLV.getSelectionModel().selectedItemProperty().addListener((__, oldV, newV) -> {
|
||||||
|
if (oldV != null) {
|
||||||
|
colorPicker.valueProperty().unbindBidirectional(oldV.colorProperty());
|
||||||
|
}
|
||||||
|
if (newV != null) {
|
||||||
|
colorPicker.valueProperty().bindBidirectional(newV.colorProperty());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue