RecipeFrame.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package org.leumasjaffe.recipe.view;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import javax.swing.JFrame;
  5. import javax.swing.JTabbedPane;
  6. import org.leumasjaffe.recipe.model.Product;
  7. import org.leumasjaffe.recipe.model.Recipe;
  8. import com.fasterxml.jackson.databind.ObjectMapper;
  9. import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
  10. @SuppressWarnings("serial")
  11. public class RecipeFrame extends JFrame {
  12. public RecipeFrame() {
  13. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  14. JTabbedPane tabbedPane = new JTabbedPane();
  15. setContentPane(tabbedPane);
  16. SummaryPanel summaryPanel = new SummaryPanel();
  17. tabbedPane.addTab("Summary", summaryPanel);
  18. ObjectMapper mapper = new ObjectMapper();
  19. mapper.registerModule(new Jdk8Module());
  20. try {
  21. Recipe recipe = mapper.readValue(new File("src/test/resources/example.json"), Recipe.class);
  22. for (Product comp : recipe.getProducts()) {
  23. tabbedPane.addTab(comp.getName(), new ProductPanel(comp));
  24. }
  25. } catch (IOException e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
  29. pack();
  30. repaint();
  31. setVisible(true);
  32. }
  33. }