SummaryPanel.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package org.leumasjaffe.recipe.view.summary;
  2. import java.awt.GridBagConstraints;
  3. import java.awt.GridBagLayout;
  4. import java.awt.Insets;
  5. import javax.swing.JPanel;
  6. import javax.swing.JSeparator;
  7. import javax.swing.JTextArea;
  8. import javax.swing.JTextField;
  9. import org.jdesktop.swingx.VerticalLayout;
  10. import org.leumasjaffe.recipe.model.Element;
  11. import org.leumasjaffe.recipe.model.RecipeCard;
  12. import org.leumasjaffe.recipe.view.CollatedDurationPanel;
  13. import org.leumasjaffe.recipe.view.ImagePanel;
  14. import lombok.AccessLevel;
  15. import lombok.experimental.FieldDefaults;
  16. import java.awt.Font;
  17. @SuppressWarnings("serial")
  18. @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
  19. public class SummaryPanel extends JPanel {
  20. public SummaryPanel(final RecipeCard card) {
  21. GridBagLayout gridBagLayout = new GridBagLayout();
  22. gridBagLayout.columnWidths = new int[]{0, 0, 0};
  23. gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
  24. gridBagLayout.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
  25. gridBagLayout.rowWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE};
  26. setLayout(gridBagLayout);
  27. JPanel panelHeader = new JPanel();
  28. GridBagConstraints gbc_panelHeader = new GridBagConstraints();
  29. gbc_panelHeader.gridwidth = 2;
  30. gbc_panelHeader.insets = new Insets(0, 0, 5, 0);
  31. gbc_panelHeader.fill = GridBagConstraints.BOTH;
  32. gbc_panelHeader.gridx = 0;
  33. gbc_panelHeader.gridy = 0;
  34. add(panelHeader, gbc_panelHeader);
  35. GridBagLayout gbl_panelHeader = new GridBagLayout();
  36. gbl_panelHeader.columnWidths = new int[]{0, 0};
  37. gbl_panelHeader.rowHeights = new int[]{0, 0, 0};
  38. gbl_panelHeader.columnWeights = new double[]{1.0, Double.MIN_VALUE};
  39. gbl_panelHeader.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
  40. panelHeader.setLayout(gbl_panelHeader);
  41. JTextField txtTitle = new JTextField();
  42. txtTitle.setText(card.getTitle());
  43. GridBagConstraints gbc_txtTitle = new GridBagConstraints();
  44. gbc_txtTitle.insets = new Insets(0, 0, 0, 5);
  45. gbc_txtTitle.fill = GridBagConstraints.HORIZONTAL;
  46. gbc_txtTitle.gridx = 0;
  47. gbc_txtTitle.gridy = 0;
  48. panelHeader.add(txtTitle, gbc_txtTitle);
  49. txtTitle.setColumns(10);
  50. CollatedDurationPanel panelDuration =
  51. new CollatedDurationPanel(card.getCollatedDuration());
  52. GridBagConstraints gbc_panelDuration = new GridBagConstraints();
  53. gbc_panelDuration.gridx = 0;
  54. gbc_panelDuration.gridy = 1;
  55. panelHeader.add(panelDuration, gbc_panelDuration);
  56. JPanel panelIngredients = new JPanel();
  57. GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
  58. gbc_panelIngredients.insets = new Insets(0, 0, 5, 5);
  59. gbc_panelIngredients.fill = GridBagConstraints.BOTH;
  60. gbc_panelIngredients.gridx = 0;
  61. gbc_panelIngredients.gridy = 1;
  62. add(panelIngredients, gbc_panelIngredients);
  63. panelIngredients.setLayout(new VerticalLayout());
  64. JPanel panel = new JPanel();
  65. GridBagConstraints gbc_panel = new GridBagConstraints();
  66. gbc_panel.insets = new Insets(0, 0, 5, 0);
  67. gbc_panel.fill = GridBagConstraints.BOTH;
  68. gbc_panel.gridx = 1;
  69. gbc_panel.gridy = 1;
  70. add(panel, gbc_panel);
  71. GridBagLayout gbl_panel = new GridBagLayout();
  72. gbl_panel.columnWidths = new int[]{0, 0};
  73. gbl_panel.rowHeights = new int[]{0, 0, 0, 0};
  74. gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
  75. gbl_panel.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
  76. panel.setLayout(gbl_panel);
  77. JPanel panelPhoto = new ImagePanel();
  78. GridBagConstraints gbc_panelPhoto = new GridBagConstraints();
  79. gbc_panelPhoto.insets = new Insets(0, 0, 5, 0);
  80. gbc_panelPhoto.gridx = 0;
  81. gbc_panelPhoto.gridy = 0;
  82. panel.add(panelPhoto, gbc_panelPhoto);
  83. JTextArea txaDesription = new JTextArea(5, 20);
  84. txaDesription.setFont(new Font("Verdana", Font.PLAIN, 10));
  85. txaDesription.setWrapStyleWord(true);
  86. txaDesription.setLineWrap(true);
  87. txaDesription.setText(card.getDescription());
  88. GridBagConstraints gbc_txaDesription = new GridBagConstraints();
  89. gbc_txaDesription.insets = new Insets(0, 0, 5, 0);
  90. gbc_txaDesription.fill = GridBagConstraints.BOTH;
  91. gbc_txaDesription.gridx = 0;
  92. gbc_txaDesription.gridy = 1;
  93. panel.add(txaDesription, gbc_txaDesription);
  94. for (final Element element : card.getElements()) {
  95. panelIngredients.add(new ElementPanel(element));
  96. panelIngredients.add(new JSeparator());
  97. }
  98. }
  99. }