PreparationPanel.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package org.leumasjaffe.recipe.view;
  2. import javax.swing.JPanel;
  3. import org.jdesktop.swingx.VerticalLayout;
  4. import org.leumasjaffe.recipe.model.Preparation;
  5. import lombok.AccessLevel;
  6. import lombok.Getter;
  7. import lombok.experimental.FieldDefaults;
  8. import java.awt.GridBagLayout;
  9. import java.awt.GridBagConstraints;
  10. import java.awt.Insets;
  11. import javax.swing.JLabel;
  12. import java.awt.Component;
  13. import javax.swing.Box;
  14. @SuppressWarnings("serial")
  15. @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
  16. public class PreparationPanel extends JPanel {
  17. @Getter(AccessLevel.PACKAGE) JLabel lblDuration;
  18. @Getter(AccessLevel.PACKAGE) JPanel panelIngredients;
  19. public PreparationPanel(Preparation step) {
  20. GridBagLayout gridBagLayout = new GridBagLayout();
  21. gridBagLayout.columnWidths = new int[]{0, 0, 0};
  22. gridBagLayout.rowHeights = new int[]{0, 0};
  23. gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
  24. gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
  25. setLayout(gridBagLayout);
  26. JPanel panelLeft = new JPanel();
  27. GridBagConstraints gbc_panelLeft = new GridBagConstraints();
  28. gbc_panelLeft.insets = new Insets(0, 0, 0, 5);
  29. gbc_panelLeft.fill = GridBagConstraints.BOTH;
  30. gbc_panelLeft.gridx = 0;
  31. gbc_panelLeft.gridy = 0;
  32. add(panelLeft, gbc_panelLeft);
  33. GridBagLayout gbl_panelLeft = new GridBagLayout();
  34. gbl_panelLeft.columnWidths = new int[]{0, 0, 0, 0};
  35. gbl_panelLeft.rowHeights = new int[]{0, 0, 0};
  36. gbl_panelLeft.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
  37. gbl_panelLeft.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
  38. panelLeft.setLayout(gbl_panelLeft);
  39. JLabel lblIndex = new JLabel("Prep");
  40. GridBagConstraints gbc_lblIndex = new GridBagConstraints();
  41. gbc_lblIndex.fill = GridBagConstraints.HORIZONTAL;
  42. gbc_lblIndex.insets = new Insets(0, 0, 5, 5);
  43. gbc_lblIndex.gridx = 0;
  44. gbc_lblIndex.gridy = 0;
  45. panelLeft.add(lblIndex, gbc_lblIndex);
  46. Component horizontalGlue = Box.createHorizontalGlue();
  47. GridBagConstraints gbc_horizontalGlue = new GridBagConstraints();
  48. gbc_horizontalGlue.insets = new Insets(0, 0, 5, 5);
  49. gbc_horizontalGlue.gridx = 1;
  50. gbc_horizontalGlue.gridy = 0;
  51. panelLeft.add(horizontalGlue, gbc_horizontalGlue);
  52. lblDuration = new JLabel("Requires: " + step.getDuration().toString());
  53. GridBagConstraints gbc_lblDuration = new GridBagConstraints();
  54. gbc_lblDuration.insets = new Insets(0, 0, 5, 0);
  55. gbc_lblDuration.gridx = 2;
  56. gbc_lblDuration.gridy = 0;
  57. panelLeft.add(lblDuration, gbc_lblDuration);
  58. panelIngredients = new JPanel();
  59. panelIngredients.setLayout(new VerticalLayout(5));
  60. GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
  61. gbc_panelIngredients.gridwidth = 3;
  62. gbc_panelIngredients.insets = new Insets(0, 0, 0, 5);
  63. gbc_panelIngredients.fill = GridBagConstraints.BOTH;
  64. gbc_panelIngredients.gridx = 0;
  65. gbc_panelIngredients.gridy = 1;
  66. panelLeft.add(panelIngredients, gbc_panelIngredients);
  67. step.getIngredientsAsStream().map(IngredientPreparationPanel::new).forEach(panelIngredients::add);
  68. }
  69. }