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().getLibrary().getSourcesGrouped();
25 for (String group
: sourcesGrouped
.keySet()) {
26 data
.put(group
, sourcesGrouped
.get(group
));
28 } catch (Exception e
) {
35 protected String
keyToElement(String key
) {
36 return key
.substring(1);
40 protected String
keyToDisplay(String key
) {
41 if (key
.trim().isEmpty()) {
42 return "[*]"; // Root node
45 // Get and remove type
46 String type
= key
.substring(0, 1);
47 key
= key
.substring(1);
49 if (!type
.equals(">")) {
50 // Only display the final name
51 int pos
= key
.toString().lastIndexOf("/");
53 key
= key
.toString().substring(pos
+ 1);
57 if (key
.toString().isEmpty()) {
65 protected int loadData(DefaultMutableTreeNode root
, Map
<String
, List
<String
>> sourcesGrouped
, String filter
) {
67 for (String source
: sourcesGrouped
.keySet()) {
68 if (checkFilter(filter
, source
) || checkFilter(filter
, sourcesGrouped
.get(source
))) {
69 List
<String
> children
= sourcesGrouped
.get(source
);
70 boolean hasChildren
= (children
.size() > 1)
71 || (children
.size() == 1 && !children
.get(0).trim().isEmpty());
72 DefaultMutableTreeNode sourceNode
= new DefaultMutableTreeNode(">" + source
+ (hasChildren ?
"/" : ""));
74 for (String subSource
: children
) {
75 if (checkFilter(filter
, source
) || checkFilter(filter
, subSource
)) {
77 if (subSource
.isEmpty() && sourcesGrouped
.get(source
).size() > 1) {
78 sourceNode
.add(new DefaultMutableTreeNode(" " + source
));
79 } else if (!subSource
.isEmpty()) {
80 sourceNode
.add(new DefaultMutableTreeNode(" " + source
+ "/" + subSource
));