浏览代码

Hide Elements from the SummaryPanel when the Element has no ingredients.

Sam Jaffe 4 年之前
父节点
当前提交
848e5c190d
共有 2 个文件被更改,包括 8 次插入2 次删除
  1. 0 1
      README.md
  2. 8 1
      src/main/lombok/org/leumasjaffe/recipe/view/summary/SummaryPanel.java

+ 0 - 1
README.md

@@ -14,7 +14,6 @@ A java program for the purpose of storing and categorizing various recipes.
 - [x] Change number of servings from default
 - [ ] Propagate updates to CollatedDurationPanel
 - [ ] Propagate updates to summary.IngredientPanel
-- [ ] Hide summary.ElementPanel for no-ingredient Elements
 - [ ] Ensure that instructions are not cut off in lock-view
 - [ ] Support images
 - [ ] Ingredient/Tag searching for recipes

+ 8 - 1
src/main/lombok/org/leumasjaffe/recipe/view/summary/SummaryPanel.java

@@ -4,6 +4,10 @@ import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
+import java.util.Collection;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
 
 import javax.swing.JPanel;
 import javax.swing.JSeparator;
@@ -46,7 +50,10 @@ public class SummaryPanel extends JPanel {
 	JSpinner spnServingsToMake;
 	
 	public SummaryPanel(final ScaleFactor scale) {
-		controller = new ReplaceChildrenAction<>(RecipeCard::getElements, element -> {
+		final Predicate<Element> hasIngredients = e -> !e.getIngredients().isEmpty();
+		final Function<RecipeCard, Collection<Element>> func =
+				rc -> rc.getComponents().filter(hasIngredients).collect(Collectors.toList());
+		controller = new ReplaceChildrenAction<>(func, element -> {
 			JPanel wrapper = new JPanel(new VerticalLayout());
 			wrapper.add(new ElementPanel(element, scale));
 			wrapper.add(new JSeparator());