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 // Get and remove type
42 String type
= key
.substring(0, 1);
43 key
= key
.substring(1);
45 if (!type
.equals(">")) {
46 // Only display the final name
47 int pos
= key
.toString().lastIndexOf("/");
49 key
= key
.toString().substring(pos
+ 1);
53 if (key
.toString().isEmpty()) {
61 protected int loadData(DefaultMutableTreeNode root
, Map
<String
, List
<String
>> sourcesGrouped
, String filter
) {
63 for (String source
: sourcesGrouped
.keySet()) {
64 if (checkFilter(filter
, source
) || checkFilter(filter
, sourcesGrouped
.get(source
))) {
65 boolean hasChildren
= sourcesGrouped
.get(source
).size() > 1;
66 DefaultMutableTreeNode sourceNode
= new DefaultMutableTreeNode(">" + source
+ (hasChildren ?
"/" : ""));
68 for (String subSource
: sourcesGrouped
.get(source
)) {
69 if (checkFilter(filter
, source
) || checkFilter(filter
, subSource
)) {
71 if (subSource
.isEmpty() && sourcesGrouped
.get(source
).size() > 1) {
72 sourceNode
.add(new DefaultMutableTreeNode(" " + source
));
73 } else if (!subSource
.isEmpty()) {
74 sourceNode
.add(new DefaultMutableTreeNode(" " + source
+ "/" + subSource
));