View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.contentdirectory.ui;
17  
18  import org.fourthline.cling.support.model.DIDLObject;
19  import org.fourthline.cling.support.model.container.Container;
20  import org.fourthline.cling.support.model.item.Item;
21  
22  import javax.swing.Icon;
23  import javax.swing.JTree;
24  import javax.swing.tree.DefaultMutableTreeNode;
25  import javax.swing.tree.DefaultTreeCellRenderer;
26  import java.awt.Component;
27  
28  /**
29   * @author Christian Bauer
30   */
31  public class ContentTreeCellRenderer extends DefaultTreeCellRenderer {
32  
33      public Component getTreeCellRendererComponent(
34              JTree tree,
35              Object value,
36              boolean sel,
37              boolean expanded,
38              boolean leaf,
39              int row,
40              boolean hasFocus) {
41  
42          super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
43  
44          DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
45  
46          if (node.getUserObject() instanceof Container) {
47  
48              Container container = (Container) node.getUserObject();
49              setText(container.getTitle());
50              setIcon(expanded ? getContainerOpenIcon() : getContainerClosedIcon());
51  
52          } else if (node.getUserObject() instanceof Item) {
53  
54              Item item = (Item) node.getUserObject();
55              setText(item.getTitle());
56  
57              DIDLObject.Class upnpClass = item.getClazz();
58              setIcon(getItemIcon(item, upnpClass != null ? upnpClass.getValue() : null));
59  
60          } else if (node.getUserObject() instanceof String) {
61              setIcon(getInfoIcon());
62          }
63  
64          onCreate();
65          return this;
66      }
67  
68      protected void onCreate() {
69  
70      }
71  
72      protected Icon getContainerOpenIcon() {
73          return null;
74      }
75  
76      protected Icon getContainerClosedIcon() {
77          return null;
78      }
79  
80      protected Icon getItemIcon(Item item, String upnpClass) {
81          return null;
82      }
83  
84      protected Icon getInfoIcon() {
85          return null;
86      }
87  
88  }