1 package be
.nikiroo
.fanfix_swing
.gui
.browser
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Collection
;
5 import java
.util
.Collections
;
6 import java
.util
.Comparator
;
7 import java
.util
.HashMap
;
11 import javax
.swing
.tree
.DefaultMutableTreeNode
;
13 import be
.nikiroo
.fanfix
.Instance
;
15 public class SourceTab
extends BasicTab
<Map
<String
, List
<String
>>> {
16 public SourceTab(int index
, String listenerCommand
) {
17 super(index
, listenerCommand
);
21 protected Map
<String
, List
<String
>> createEmptyData() {
22 return new HashMap
<String
, List
<String
>>();
26 protected void fillData(Map
<String
, List
<String
>> data
) {
29 Map
<String
, List
<String
>> sourcesGrouped
= Instance
.getInstance()
30 .getLibrary().getSourcesGrouped();
31 for (String group
: sourcesGrouped
.keySet()) {
32 data
.put(group
, sourcesGrouped
.get(group
));
34 } catch (Exception e
) {
41 protected String
keyToElement(String key
) {
42 return key
.substring(1);
46 protected String
keyToDisplay(String key
) {
47 if (key
.trim().isEmpty()) {
48 return "[*]"; // Root node
51 // Get and remove type
52 String type
= key
.substring(0, 1);
53 key
= key
.substring(1);
55 if (!type
.equals(">")) {
56 // Only display the final name
57 int pos
= key
.toString().lastIndexOf("/");
59 key
= key
.toString().substring(pos
+ 1);
63 if (key
.toString().isEmpty()) {
71 protected int loadData(DefaultMutableTreeNode root
,
72 Map
<String
, List
<String
>> sourcesGrouped
, String filter
) {
74 List
<String
> sources
= new ArrayList
<String
>(sourcesGrouped
.keySet());
76 for (String source
: sources
) {
77 if (checkFilter(filter
, source
)
78 || checkFilter(filter
, sourcesGrouped
.get(source
))) {
79 List
<String
> children
= sourcesGrouped
.get(source
);
80 boolean hasChildren
= (children
.size() > 1)
81 || (children
.size() == 1
82 && !children
.get(0).trim().isEmpty());
83 DefaultMutableTreeNode sourceNode
= new DefaultMutableTreeNode(
84 ">" + source
+ (hasChildren ?
"/" : ""));
87 for (String subSource
: children
) {
88 if (checkFilter(filter
, source
)
89 || checkFilter(filter
, subSource
)) {
91 if (subSource
.isEmpty()
92 && sourcesGrouped
.get(source
).size() > 1) {
94 new DefaultMutableTreeNode(" " + source
));
95 } else if (!subSource
.isEmpty()) {
96 sourceNode
.add(new DefaultMutableTreeNode(
97 " " + source
+ "/" + subSource
));