View Javadoc

1   package com.melloware.jukes.gui.view.node;
2   
3   import java.util.Iterator;
4   
5   import javax.swing.Icon;
6   
7   import org.apache.commons.lang.StringUtils;
8   import org.apache.commons.logging.Log;
9   import org.apache.commons.logging.LogFactory;
10  
11  import com.melloware.jukes.db.orm.Disc;
12  import com.melloware.jukes.db.orm.Track;
13  import com.melloware.jukes.gui.tool.Resources;
14  
15  /**
16   * This class represents ALBUMS in the navigation tree.
17   * <p>
18   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
19   * @author Emil A. Lefkof III <info@melloware.com>
20   * @version 4.0
21   *
22   * @see com.melloware.jukes.db.orm.Disc
23   */
24  public final class DiscNode
25      extends AbstractTreeNode {
26  
27      private static final Log LOG = LogFactory.getLog(DiscNode.class);
28  
29      /**
30       * Constructs a <code>DiscNode</code> for the given parent and disc.
31       * <p>
32       * @param aParent this node's parent
33       * @param aModel the associated model, an instance of Disc
34       */
35      public DiscNode(NavigationNode aParent, Disc aModel) {
36          super(aParent, aModel);
37          this.settings = ((AbstractTreeNode)aParent).settings;
38      }
39  
40      /**
41       * Returns this node's associated Disc instance.
42       * <p>
43       * @return this node's associated Disc instance.
44       * @see NavigationNode#getModel()
45       */
46      public Disc getDisc() {
47          return (Disc)getModel();
48      }
49  
50  
51      /**
52       * Returns this node's icon, ignores the selection.
53       * The icons is requested from a global resource repository.
54       * <p>
55       * @return this node's icon.
56       */
57      public Icon getIcon(final boolean sel) {
58      	Icon icon = null;
59      	if (StringUtils.contains(getDisc().getName().toLowerCase(), "from the vault")) {
60      		icon = Resources.DISC_GD_ICON;
61  		} else if (StringUtils.contains(getDisc().getName().toLowerCase(),"dark side of the moon")) {
62  			icon = Resources.DISC_PF_ICON;
63  		} else {
64  			icon = Resources.DISC_TREE_ICON;
65  		}
66          return icon;
67      }
68  
69      /**
70       * Returns this node's name, the identifier of the associated disc.
71       * <p>
72       * @return this node's name
73       */
74      public String getName() {
75          return getDisc().getDisplayText(this.settings.getDisplayFormatDisc());
76      }
77  
78      /* (non-Javadoc)
79       * @see com.melloware.jukes.gui.tool.node.AbstractTreeNode#loadChildren()
80       */
81      public void loadChildren() {
82          if (!childrenLoaded) {
83              loadingChildren = true;
84              LOG.debug("Loading children");
85              final Iterator iter = getDisc().getTracks().iterator();
86              while (iter.hasNext()) {
87                  final Track track = (Track)iter.next();
88                  if (LOG.isDebugEnabled()) {
89                      LOG.debug("Loading track " + track.getName());
90                  }
91                  this.add(new TrackNode(this, track));
92  
93              }
94  
95              loadingChildren = false;
96              childrenLoaded = true;
97          }
98  
99      }
100 
101 }