|
|
@@ -3,12 +3,18 @@ package org.leumasjaffe.recipe.view;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JTabbedPane;
|
|
|
|
|
|
+import org.leumasjaffe.container.functional.Result;
|
|
|
import org.leumasjaffe.recipe.controller.IOController;
|
|
|
import org.leumasjaffe.recipe.model.Product;
|
|
|
import org.leumasjaffe.recipe.model.Recipe;
|
|
|
+
|
|
|
+import lombok.AccessLevel;
|
|
|
+import lombok.experimental.FieldDefaults;
|
|
|
+
|
|
|
import javax.swing.JMenuBar;
|
|
|
import javax.swing.JMenu;
|
|
|
import javax.swing.JMenuItem;
|
|
|
+import javax.swing.JOptionPane;
|
|
|
import javax.swing.KeyStroke;
|
|
|
import java.awt.event.KeyEvent;
|
|
|
import java.awt.event.WindowEvent;
|
|
|
@@ -16,9 +22,14 @@ import java.awt.Toolkit;
|
|
|
import java.awt.event.InputEvent;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
public class RecipeFrame extends JFrame {
|
|
|
+ IOController io = new IOController();
|
|
|
+ SummaryPanel summaryPanel;
|
|
|
+ JTabbedPane tabbedPane;
|
|
|
|
|
|
public RecipeFrame() {
|
|
|
+
|
|
|
final int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
@@ -49,20 +60,34 @@ public class RecipeFrame extends JFrame {
|
|
|
mntmQuit.addActionListener( e -> { this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } );
|
|
|
mnFile.add(mntmQuit);
|
|
|
|
|
|
- JTabbedPane tabbedPane = new JTabbedPane();
|
|
|
+ tabbedPane = new JTabbedPane();
|
|
|
setContentPane(tabbedPane);
|
|
|
|
|
|
- SummaryPanel summaryPanel = new SummaryPanel();
|
|
|
+ summaryPanel = new SummaryPanel();
|
|
|
tabbedPane.addTab("Summary", summaryPanel);
|
|
|
|
|
|
- Recipe recipe = IOController.loadFromFile("src/test/resources/example.json");
|
|
|
- for (Product comp : recipe.getProducts()) {
|
|
|
- summaryPanel.addProduct(comp);
|
|
|
- tabbedPane.addTab(comp.getName(), new ProductPanel(comp));
|
|
|
- }
|
|
|
+ // TODO Switch these around...
|
|
|
+// setModel(new Recipe());
|
|
|
+ open("src/test/resources/example.json");
|
|
|
|
|
|
pack();
|
|
|
repaint();
|
|
|
setVisible(true);
|
|
|
}
|
|
|
+
|
|
|
+ private void open(final String filename) {
|
|
|
+ Result.maybe(io::load).apply(filename).consume(this::setModel, this::errorPopup);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setModel(final Recipe recipe) {
|
|
|
+ // TODO Clear underlying panels
|
|
|
+ for (Product comp : recipe.getProducts()) {
|
|
|
+ summaryPanel.addProduct(comp);
|
|
|
+ tabbedPane.addTab(comp.getName(), new ProductPanel(comp));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void errorPopup(final Exception ex) {
|
|
|
+ JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), "File Error", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
}
|