💩 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"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project> </project>

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

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

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

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

@ -71,7 +71,9 @@ public class Product implements Serializable {
@Override @Override
public boolean equals(Object obj) { 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 GARMENT = 0;
private final static int PERFUME = 1; private final static int PERFUME = 1;
@FXML @FXML
private HBox detailHBox; private HBox detailHBox;
@FXML @FXML
@ -48,6 +49,13 @@ public class MainWindow {
prepareCreationWindow(PERFUME); prepareCreationWindow(PERFUME);
} }
@FXML
private void clickAddProduct() {
viewmodel.addGarmentVM(new GarmentVM("no_name", 0.0));
}
private void prepareCreationWindow(int code) { private void prepareCreationWindow(int code) {
Stage creationWindowStage = new Stage(); 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) { public ProductVM(String name, Double price) {
model = new Product(); model = new Product();
//loads //loads / sets
setName(name == null ? model.getName() : name); setName(name == null ? model.getName() : name);
setPrice(price == null ? model.getPrice() : price); setPrice(price == null ? model.getPrice() : price);
@ -71,17 +71,6 @@ public class ProductVM implements PropertyChangeListener {
setPrice((Double) evt.getNewValue()); 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 { public class ShopVM implements PropertyChangeListener {
private final Shop model; private Shop model;
public Shop getModel() { public Shop getModel() {
return model; return model;
@ -25,50 +25,49 @@ public class ShopVM implements PropertyChangeListener {
private final ObservableList<ProductVM> productsVMObs = FXCollections.observableArrayList(); private final ObservableList<ProductVM> productsVMObs = FXCollections.observableArrayList();
private final ListProperty<ProductVM> productsVM = new SimpleListProperty<>(productsVMObs); private final ListProperty<ProductVM> productsVM = new SimpleListProperty<>(productsVMObs);
public ObservableList<ProductVM> getProductsVM() { return FXCollections.unmodifiableObservableList(productsVM.get()); } public ObservableList<ProductVM> getProductsVM() {return FXCollections.unmodifiableObservableList(productsVM.get());}
public ReadOnlyListProperty<ProductVM> productsVMProperty() { return productsVM; } public ReadOnlyListProperty<ProductVM> productsVMProperty() {return productsVM;}
public ShopVM() { public ShopVM() {
Shop tmpModel;
try { try {
System.out.println("trying real load"); System.out.println("trying real load");
tmpModel = new Loader().load(); model = new Loader().load();
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException ex1) {
System.err.println(e.getMessage());
e.printStackTrace();
try { try {
System.out.println("trying stub load"); System.out.println("trying stub load");
tmpModel = new Stub().load(); model = new Stub().load();
} catch (IOException | ClassNotFoundException ex) { } catch (IOException | ClassNotFoundException ex2) {
System.out.println("giving up load and creating new"); 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 //subscribes
model.addListener(this); model.addListener(this);
//loads
model.getProducts().forEach(p -> productsVMObs.add(new ProductVM(p.getName(), p.getPrice())));
//will update with its methods //will update with its methods
} }
public void removeProduct(ProductVM productVM) { public void removeProduct(ProductVM productVM) {
productsVMObs.remove(productVM); productsVMObs.remove(productVM);
getModel().removeProduct(productVM.getModel()); getModel().removeProduct(productVM.getModel());
printModel();
} }
public void addGarmentVM(GarmentVM garmentVM) { public void addGarmentVM(GarmentVM garmentVM) {
productsVMObs.add(garmentVM); productsVMObs.add(garmentVM);
getModel().addProduct(garmentVM.getModel()); getModel().addProduct(garmentVM.getModel());
printModel();
} }
public void addPerfumeVM(PerfumeVM perfumeVM) { public void addPerfumeVM(PerfumeVM perfumeVM) {
productsVMObs.add(perfumeVM); productsVMObs.add(perfumeVM);
getModel().addProduct(perfumeVM.getModel()); getModel().addProduct(perfumeVM.getModel());
printModel();
} }
public void save() throws IOException { public void save() throws IOException {
@ -76,14 +75,16 @@ public class ShopVM implements PropertyChangeListener {
saver.save(getModel()); saver.save(getModel());
} }
private void printModel() {
System.out.println("printing model.................");
getModel().getProducts().forEach(p -> System.out.println(p.getName() + " : " + p.getPrice()));
}
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(Shop.PROP_SHOP_ADD)) { if (evt.getPropertyName().equals(Shop.PROP_SHOP_ADD)) {
ProductVM pvm = new ProductVM(evt.getNewValue()); ProductVM pvm = new ProductVM(evt.getNewValue());
productsVMObs.add( productsVMObs.add(((IndexedPropertyChangeEvent) evt).getIndex(), pvm);
((IndexedPropertyChangeEvent) evt).getIndex(),
pvm
);
} }
if (evt.getPropertyName().equals(Shop.PROP_SHOP_RMV)) { if (evt.getPropertyName().equals(Shop.PROP_SHOP_RMV)) {
productsVMObs.remove(new ProductVM(evt.getOldValue())); // redefined equals an toHash productsVMObs.remove(new ProductVM(evt.getOldValue())); // redefined equals an toHash

Loading…
Cancel
Save