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
) {
25 Map
<String
, List
<String
>> sourcesGrouped
= Instance
.getInstance()
26 .getLibrary().getSourcesGrouped();
27 for (String group
: sourcesGrouped
.keySet()) {
28 data
.put(group
, sourcesGrouped
.get(group
));
30 } catch (Exception e
) {
37 protected String
keyToElement(String key
) {
38 return key
.substring(1);
42 protected String
keyToDisplay(String key
) {
43 if (key
.trim().isEmpty()) {
44 return "[*]"; // Root node
47 // Get and remove type
48 String type
= key
.substring(0, 1);
49 key
= key
.substring(1);
51 if (!type
.equals(">")) {
52 // Only display the final name
53 int pos
= key
.toString().lastIndexOf("/");
55 key
= key
.toString().substring(pos
+ 1);
59 if (key
.toString().isEmpty()) {
67 protected int loadData(DefaultMutableTreeNode root
,
68 Map
<String
, List
<String
>> sourcesGrouped
, String filter
) {
70 for (String source
: sourcesGrouped
.keySet()) {
71 if (checkFilter(filter
, source
)
72 || checkFilter(filter
, sourcesGrouped
.get(source
))) {
73 List
<String
> children
= sourcesGrouped
.get(source
);
74 boolean hasChildren
= (children
.size() > 1)
75 || (children
.size() == 1
76 && !children
.get(0).trim().isEmpty());
77 DefaultMutableTreeNode sourceNode
= new DefaultMutableTreeNode(
78 ">" + source
+ (hasChildren ?
"/" : ""));
80 for (String subSource
: children
) {
81 if (checkFilter(filter
, source
)
82 || checkFilter(filter
, subSource
)) {
84 if (subSource
.isEmpty()
85 && sourcesGrouped
.get(source
).size() > 1) {
87 new DefaultMutableTreeNode(" " + source
));
88 } else if (!subSource
.isEmpty()) {
89 sourceNode
.add(new DefaultMutableTreeNode(
90 " " + source
+ "/" + subSource
));