1 package be
.nikiroo
.fanfix_swing
.gui
.browser
;
3 import java
.util
.HashMap
;
7 import javax
.swing
.tree
.DefaultMutableTreeNode
;
9 import be
.nikiroo
.fanfix
.Instance
;
11 public class SourceTab
extends BasicTab
<Map
<String
, List
<String
>>> {
12 public SourceTab(int index
, String listenerCommand
) {
13 super(index
, listenerCommand
);
17 protected Map
<String
, List
<String
>> createEmptyData() {
18 return new HashMap
<String
, List
<String
>>();
22 protected void fillData(Map
<String
, List
<String
>> data
) {
24 Map
<String
, List
<String
>> sourcesGrouped
= Instance
.getInstance()
25 .getLibrary().getSourcesGrouped();
26 for (String group
: sourcesGrouped
.keySet()) {
27 data
.put(group
, sourcesGrouped
.get(group
));
29 } catch (Exception e
) {
36 protected String
keyToElement(String key
) {
37 return key
.substring(1);
41 protected String
keyToDisplay(String key
) {
42 if (key
.trim().isEmpty()) {
43 return "[*]"; // Root node
46 // Get and remove type
47 String type
= key
.substring(0, 1);
48 key
= key
.substring(1);
50 if (!type
.equals(">")) {
51 // Only display the final name
52 int pos
= key
.toString().lastIndexOf("/");
54 key
= key
.toString().substring(pos
+ 1);
58 if (key
.toString().isEmpty()) {
66 protected int loadData(DefaultMutableTreeNode root
,
67 Map
<String
, List
<String
>> sourcesGrouped
, String filter
) {
69 for (String source
: sourcesGrouped
.keySet()) {
70 if (checkFilter(filter
, source
)
71 || checkFilter(filter
, sourcesGrouped
.get(source
))) {
72 List
<String
> children
= sourcesGrouped
.get(source
);
73 boolean hasChildren
= (children
.size() > 1)
74 || (children
.size() == 1
75 && !children
.get(0).trim().isEmpty());
76 DefaultMutableTreeNode sourceNode
= new DefaultMutableTreeNode(
77 ">" + source
+ (hasChildren ?
"/" : ""));
79 for (String subSource
: children
) {
80 if (checkFilter(filter
, source
)
81 || checkFilter(filter
, subSource
)) {
83 if (subSource
.isEmpty()
84 && sourcesGrouped
.get(source
).size() > 1) {
86 new DefaultMutableTreeNode(" " + source
));
87 } else if (!subSource
.isEmpty()) {
88 sourceNode
.add(new DefaultMutableTreeNode(
89 " " + source
+ "/" + subSource
));