|
|
@@ -7,6 +7,7 @@ import javax.swing.JButton;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
+import java.awt.Component;
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.FlowLayout;
|
|
|
import java.awt.event.KeyEvent;
|
|
|
@@ -14,12 +15,19 @@ import java.awt.event.KeyListener;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
|
import org.leumasjaffe.recipe.controller.GhostTextController;
|
|
|
|
|
|
+import lombok.AccessLevel;
|
|
|
+import lombok.experimental.FieldDefaults;
|
|
|
+import lombok.experimental.NonFinal;
|
|
|
+
|
|
|
@SuppressWarnings("serial")
|
|
|
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
|
|
|
public class TagInputPanel extends JPanel {
|
|
|
private static final Icon X_MARK;
|
|
|
static {
|
|
|
@@ -41,13 +49,15 @@ public class TagInputPanel extends JPanel {
|
|
|
add(btnRemove);
|
|
|
btnRemove.addActionListener(e -> {
|
|
|
setVisible(false);
|
|
|
+ TagInputPanel.this.model.remove(value);
|
|
|
TagInputPanel.this.remove(this);
|
|
|
TagInputPanel.this.revalidate();
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private JTextField textField;
|
|
|
+ @NonFinal Set<String> model = new HashSet<>();
|
|
|
+ JTextField textField;
|
|
|
|
|
|
public TagInputPanel() {
|
|
|
setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
|
|
|
@@ -70,8 +80,26 @@ public class TagInputPanel extends JPanel {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ public void setModel(Set<String> model) {
|
|
|
+ this.model = model;
|
|
|
+ clear();
|
|
|
+ for (final String tag : this.model) {
|
|
|
+ pushTag(tag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clear() {
|
|
|
+ for (Component comp : getComponents()) {
|
|
|
+ comp.setVisible(false);
|
|
|
+ }
|
|
|
+ removeAll();
|
|
|
+ textField.setVisible(true);
|
|
|
+ add(textField);
|
|
|
+ }
|
|
|
|
|
|
private void pushTag(final String tag) {
|
|
|
+ this.model.add(tag);
|
|
|
remove(textField);
|
|
|
add(new TagField(tag));
|
|
|
add(textField);
|