💩 Produce bad code that doesn't work

I think we're looking at a restart in the near future
main
Alexis Drai 3 years ago
parent a45996d56e
commit 9a16b0eaea

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
<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>

@ -5,17 +5,12 @@
</component>
<component name="ChangeListManager">
<list default="true" id="39201d7d-d87b-4c10-b0b0-e462b4f0b033" name="Changes" comment="🙈 Update gitignore">
<change afterPath="$PROJECT_DIR$/src/data/Loader.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/data/Savable.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/data/Saver.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EShop.iml" beforeDir="false" afterPath="$PROJECT_DIR$/EShop.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/fxml/MainWindow.fxml" beforeDir="false" afterPath="$PROJECT_DIR$/resources/fxml/MainWindow.fxml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/Loadable.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/Loadable.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/Stub.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/Stub.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/launcher/Launcher.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/launcher/Launcher.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/Loader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/Loader.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/model/Product.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/model/Product.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/model/Shop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/model/Shop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/view/MainWindow.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/view/MainWindow.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/viewmodel/ProductVM.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/viewmodel/ProductVM.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/viewmodel/ShopVM.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/viewmodel/ShopVM.java" afterDir="false" />
@ -38,16 +33,16 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/EShop.iml" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/data/Stub.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/model/Garment.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/model/Perfume.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/model/Garment.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/view/ProductCell.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/model/Product.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/viewmodel/ShopVM.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/viewmodel/ProductVM.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/model/Shop.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/EShop.iml" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/view/MainWindow.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/view/ProductCell.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/viewmodel/ProductVM.java" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/src/viewmodel/ShopVM.java" root0="FORCE_HIGHLIGHTING" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
@ -59,17 +54,18 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true",
"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="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="project.structure.last.edited" value="Modules" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2045977" />
</component>
<component name="RecentsManager">
<key name="CreateClassDialog.RecentsKey">
<recent name="viewmodel" />
@ -93,6 +89,7 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1665142782644</updated>
<workItem from="1665590389139" duration="1956000" />
</task>
<task id="LOCAL-00001" summary=":truck: Set up main window">
<created>1665143728540</created>
@ -153,6 +150,9 @@
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>

@ -8,6 +8,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="javaFX" level="application" />
<orderEntry type="library" name="jfx-18.0.1" level="application" />
</component>
</module>

@ -12,6 +12,7 @@
<ListView fx:id="productsVMLV"/>
<Button onAction="#clickAddGarment" text="Add garment"/>
<Button onAction="#clickAddPerfume" text="Add perfume"/>
<Button onAction="#clickAddProduct" text="Add product"/>
<Button onAction="#clickRemoveProduct" text="Remove product"/>
</VBox>
</center>

@ -3,6 +3,7 @@ package data;
import model.Shop;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

@ -71,7 +71,9 @@ public class Product implements Serializable {
@Override
public boolean equals(Object obj) {
return obj instanceof Product && ((Product) obj).getName().equals(getName());
return obj instanceof Product
&& ((Product) obj).getName() != null
&& ((Product) obj).getName().equals(getName());
}
}

@ -19,6 +19,7 @@ public class MainWindow {
private final static int GARMENT = 0;
private final static int PERFUME = 1;
@FXML
private HBox detailHBox;
@FXML
@ -48,6 +49,13 @@ public class MainWindow {
prepareCreationWindow(PERFUME);
}
@FXML
private void clickAddProduct() {
viewmodel.addGarmentVM(new GarmentVM("no_name", 0.0));
}
private void prepareCreationWindow(int code) {
Stage creationWindowStage = new Stage();
@ -123,4 +131,5 @@ public class MainWindow {
}
});
}
}

@ -22,7 +22,7 @@ public class ProductVM implements PropertyChangeListener {
public ProductVM(String name, Double price) {
model = new Product();
//loads
//loads / sets
setName(name == null ? model.getName() : name);
setPrice(price == null ? model.getPrice() : price);
@ -71,17 +71,6 @@ public class ProductVM implements PropertyChangeListener {
setPrice((Double) evt.getNewValue());
}
}
@Override
public int hashCode() {
return getName().hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof ProductVM && ((ProductVM) obj).getName().equals(getName());
}
}

@ -17,7 +17,7 @@ import java.io.IOException;
public class ShopVM implements PropertyChangeListener {
private final Shop model;
private Shop model;
public Shop getModel() {
return model;
@ -25,50 +25,49 @@ public class ShopVM implements PropertyChangeListener {
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 ObservableList<ProductVM> getProductsVM() {return FXCollections.unmodifiableObservableList(productsVM.get());}
public ReadOnlyListProperty<ProductVM> productsVMProperty() {return productsVM;}
public ShopVM() {
Shop tmpModel;
try {
System.out.println("trying real load");
tmpModel = new Loader().load();
} catch (IOException | ClassNotFoundException e) {
System.err.println(e.getMessage());
e.printStackTrace();
model = new Loader().load();
} catch (IOException | ClassNotFoundException ex1) {
try {
System.out.println("trying stub load");
tmpModel = new Stub().load();
} catch (IOException | ClassNotFoundException ex) {
model = new Stub().load();
} catch (IOException | ClassNotFoundException ex2) {
System.out.println("giving up load and creating new");
tmpModel= new Shop();
model = new Shop();
}
}
//loads
model = tmpModel;
model.getProducts().forEach(p -> productsVMObs.add(new ProductVM(p.getName(), p.getPrice())));
//subscribes
model.addListener(this);
//loads
model.getProducts().forEach(p -> productsVMObs.add(new ProductVM(p.getName(), p.getPrice())));
//will update with its methods
}
public void removeProduct(ProductVM productVM) {
productsVMObs.remove(productVM);
getModel().removeProduct(productVM.getModel());
printModel();
}
public void addGarmentVM(GarmentVM garmentVM) {
productsVMObs.add(garmentVM);
getModel().addProduct(garmentVM.getModel());
printModel();
}
public void addPerfumeVM(PerfumeVM perfumeVM) {
productsVMObs.add(perfumeVM);
getModel().addProduct(perfumeVM.getModel());
printModel();
}
public void save() throws IOException {
@ -76,14 +75,16 @@ public class ShopVM implements PropertyChangeListener {
saver.save(getModel());
}
private void printModel() {
System.out.println("printing model.................");
getModel().getProducts().forEach(p -> System.out.println(p.getName() + " : " + p.getPrice()));
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(Shop.PROP_SHOP_ADD)) {
ProductVM pvm = new ProductVM(evt.getNewValue());
productsVMObs.add(
((IndexedPropertyChangeEvent) evt).getIndex(),
pvm
);
productsVMObs.add(((IndexedPropertyChangeEvent) evt).getIndex(), pvm);
}
if (evt.getPropertyName().equals(Shop.PROP_SHOP_RMV)) {
productsVMObs.remove(new ProductVM(evt.getOldValue())); // redefined equals an toHash

Loading…
Cancel
Save