🚧 Set up View and VM

main
Alexis Drai 3 years ago
parent 6dddd3bdcf
commit 505db168a7

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -4,16 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="39201d7d-d87b-4c10-b0b0-e462b4f0b033" name="Changes" comment=":truck: Set up main window">
<change afterPath="$PROJECT_DIR$/src/data/Loadable.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/data/Stub.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Garment.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Perfume.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Product.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Shop.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/model/Size.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<list default="true" id="39201d7d-d87b-4c10-b0b0-e462b4f0b033" name="Changes" comment=":construction: Set up View and VM" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -44,11 +35,17 @@
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0"
}
}]]></component>
<component name="RecentsManager">
<key name="CreateClassDialog.RecentsKey">
<recent name="viewmodel" />
</key>
</component>
<component name="RunManager">
<configuration name="JFX" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="launcher.Launcher" />
@ -82,7 +79,21 @@
<option name="project" value="LOCAL" />
<updated>1665143741578</updated>
</task>
<option name="localTasksCounter" value="3" />
<task id="LOCAL-00003" summary=":necktie: Code the model">
<created>1665145559911</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1665145559911</updated>
</task>
<task id="LOCAL-00004" summary=":construction: Set up View and VM">
<created>1665149304635</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1665149304635</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -98,6 +109,8 @@
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value=":truck: Set up main window" />
<option name="LAST_COMMIT_MESSAGE" value=":truck: Set up main window" />
<MESSAGE value=":necktie: Code the model" />
<MESSAGE value=":construction: Set up View and VM" />
<option name="LAST_COMMIT_MESSAGE" value=":construction: Set up View and VM" />
</component>
</project>

@ -10,4 +10,23 @@
xmlns:fx="http://javafx.com/fxml"
fx:controller="view.MainWindow">
<center>
<VBox>
<!-- drop down menu (choose category)-->
<ListView fx:id="productsVMLV"/>
<Button onAction="#addGarment" text="Add garment"/>
<Button onAction="#addPerfume" text="Add perfume"/>
<Button onAction="#removeProduct" text="Remove product"/>
</VBox>
</center>
<right>
<VBox>
<Label text="name"/>
<TextField fx:id="nameTF"/>
<Label text="price"/>
<TextField fx:id="priceTF"/>
<HBox fx:id="detailHBox"/>
</VBox>
</right>
</BorderPane>

@ -10,4 +10,23 @@
xmlns:fx="http://javafx.com/fxml"
fx:controller="view.MainWindow">
<center>
<VBox>
<!-- drop down menu (choose category)-->
<ListView fx:id="productsVMLV"/>
<Button onAction="#addGarment" text="Add garment"/>
<Button onAction="#addPerfume" text="Add perfume"/>
<Button onAction="#removeProduct" text="Remove product"/>
</VBox>
</center>
<right>
<VBox>
<Label text="name"/>
<TextField fx:id="nameTF"/>
<Label text="price"/>
<TextField fx:id="priceTF"/>
<HBox fx:id="detailHBox"/>
</VBox>
</right>
</BorderPane>

@ -1,6 +1,7 @@
package data;
import model.*;
import util.Size;
public class Stub implements Loadable {

@ -1,5 +1,7 @@
package model;
import util.Size;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

@ -1,14 +1,17 @@
package model;
public abstract class Product {
public class Product {
private String name;
private double price;
public Product(String name, double price) {
this.name = name;
this.price = price;
setName(name);
setPrice(price);
}
public Product() {
}
public String getName() {
@ -23,7 +26,7 @@ public abstract class Product {
return price;
}
public void setPrice(float price) {
public void setPrice(double price) {
this.price = price;
}

@ -1,5 +1,7 @@
package model;
import data.Stub;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@ -1,4 +1,4 @@
package model;
package util;
/**
* XXS to XXL

@ -1,4 +1,88 @@
package view;
import javafx.beans.property.Property;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.util.StringConverter;
import javafx.util.converter.NumberStringConverter;
import viewmodel.GarmentVM;
import viewmodel.PerfumeVM;
import viewmodel.ProductVM;
import viewmodel.ShopVM;
import java.util.List;
public class MainWindow {
@FXML
private HBox detailHBox;
@FXML
private TextField nameTF;
@FXML
private TextField priceTF;
@FXML
private ListView<ProductVM> productsVMLV;
private ShopVM shopVM;
@FXML
private void addGarment() {
GarmentVM garmentVM = null;
// open a new window, get the input
shopVM.addGarmentVM(garmentVM);
}
@FXML
private void addPerfume() {
PerfumeVM perfumeVM = null;
// open a new window, get the input
shopVM.addPerfumeVM(perfumeVM); }
@FXML
private void removeProduct() {
shopVM.removeProduct(productsVMLV.getSelectionModel().getSelectedItem());
}
@FXML
private void initialize() {
shopVM = new ShopVM();
productsVMLV.itemsProperty().bind(shopVM.productsVMProperty());
addListenerProductsVMLV();
setCellFactoryProductsVMLV();
}
private void addListenerProductsVMLV() {
productsVMLV.getSelectionModel().selectedItemProperty().addListener((__, oldV, newV) -> {
if (oldV != null) {
nameTF.textProperty().unbindBidirectional(oldV.nameProperty());
priceTF.textProperty().unbindBidirectional(oldV.priceProperty());
}
if (newV != null) {
nameTF.textProperty().bindBidirectional(newV.nameProperty());
priceTF.textProperty().bindBidirectional(newV.priceProperty(), new NumberStringConverter());
}
});
}
private void setCellFactoryProductsVMLV() {
productsVMLV.setCellFactory(__ -> new ListCell<>() {
@Override
protected void updateItem(ProductVM item, boolean empty) {
super.updateItem(item, empty);
if (!empty) {
textProperty().bind(item.nameProperty());
} else {
textProperty().unbind();
setText("");
}
}
});
}
}

@ -0,0 +1,8 @@
package viewmodel;
public class GarmentVM extends ProductVM {
public GarmentVM(String name, double price) {
super(name, price);
}
}

@ -0,0 +1,7 @@
package viewmodel;
public class PerfumeVM extends ProductVM {
public PerfumeVM(String name, double price) {
super(name, price);
}
}

@ -0,0 +1,29 @@
package viewmodel;
import javafx.beans.property.*;
import model.Product;
public class ProductVM {
Product model;
private final StringProperty name = new SimpleStringProperty();
public ProductVM(String name, double price) {
model = new Product();
model.setPrice(price);
model.setName(name);
}
public String getName() {return name.get();}
public void setName(String name) {this.name.set(name);}
public StringProperty nameProperty() {return name;}
private final DoubleProperty price = new SimpleDoubleProperty();
public double getPrice() {return price.get();}
public DoubleProperty priceProperty() {return price;}
public void setPrice(double price) {this.price.set(price);}
}

@ -0,0 +1,45 @@
package viewmodel;
import data.Stub;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ReadOnlyListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import model.Perfume;
import model.Shop;
public class ShopVM {
private Shop model;
private final ObservableList<ProductVM> productsVMObs = FXCollections.observableArrayList();
private final ListProperty<ProductVM> productsVM = new SimpleListProperty<>(productsVMObs);
public ObservableList<ProductVM> getProductsVM() {return FXCollections.unmodifiableObservableList(productsVM.get());}
public ReadOnlyListProperty<ProductVM> productsVMProperty() {return productsVM;}
public ShopVM() {
// model = new Shop();
model = new Stub().load();
model.getProducts().forEach(p -> {
ProductVM productVM = new ProductVM(p.getName(), p.getPrice());
if(p instanceof Perfume) {
// PerfumeVM perfumeVM = (PerfumeVM) productVM;
// ... foreach... perfumeVM.addSmell
}
// productsVMObs.add
});
}
public void removeProduct(ProductVM productVM) {
productsVMObs.remove(productVM);
}
public void addGarmentVM(GarmentVM garmentVM) {
}
public void addPerfumeVM(PerfumeVM perfumeVM) {
}
}
Loading…
Cancel
Save