-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ChipViewController.java
93 lines (79 loc) · 3.07 KB
/
ChipViewController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package demos.gui.uicomponents;
import com.jfoenix.controls.JFXChipView;
import com.jfoenix.controls.JFXDefaultChip;
import com.jfoenix.controls.JFXListCell;
import com.jfoenix.effects.JFXDepthManager;
import com.jfoenix.svg.SVGGlyph;
import com.jfoenix.svg.SVGGlyphLoader;
import io.datafx.controller.ViewController;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.util.StringConverter;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Objects;
@ViewController(value = "/fxml/ui/ChipView.fxml", title = "Material Design Example")
public class ChipViewController {
@FXML
private JFXChipView<MyShape> chipView;
@PostConstruct
public void init() throws Exception {
chipView.setChipFactory((emailJFXChipView, email) -> new JFXDefaultChip<MyShape>(emailJFXChipView, email){
{
if (getItem().image != null) {
getItem().image.getStyleClass().add("chip-icon");
root.getChildren().add(0, getItem().image);
}
}
});
HashMap<String, MyShape> suggestions = new HashMap<>();
suggestions.put("Glass", new MyShape("Glass", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.glass")));
suggestions.put("Star", new MyShape("Star", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.star")));
suggestions.put("Music", new MyShape("Music", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.music")));
final SVGGlyph icoMoonGlyph = SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.heart");
icoMoonGlyph.getStyleClass().add("heart");
suggestions.put("Heart", new MyShape("Heart", icoMoonGlyph));
suggestions.put("Film", new MyShape("Film", SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg.film")));
chipView.setConverter(new StringConverter<MyShape>() {
@Override
public String toString(MyShape object) {
return object.toString();
}
@Override
public MyShape fromString(String string) {
MyShape found = suggestions.get(string);
return found == null ? new MyShape(string, null) : found;
}
});
chipView.getSuggestions().addAll(suggestions.values());
chipView.setSuggestionsCellFactory(param -> new JFXListCell<>());
JFXDepthManager.setDepth(chipView, 2);
}
class MyShape {
String name;
Node image;
public MyShape(String name, Node image) {
this.name = name;
this.image = image;
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MyShape email1 = (MyShape) o;
return Objects.equals(name, email1.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
}
}