View Javadoc

1   package com.melloware.jukes.gui.view.node;
2   
3   import javax.swing.Icon;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   
8   import com.melloware.jukes.db.orm.Track;
9   import com.melloware.jukes.file.filter.MusicFilter;
10  import com.melloware.jukes.gui.tool.Resources;
11  
12  /**
13   * This class represents TRACKS in the navigation tree.
14   * <p>
15   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
16   * @author Emil A. Lefkof III <info@melloware.com>
17   * @version 4.0
18   *
19   * @see com.melloware.jukes.db.orm.Track
20   */
21  public final class TrackNode
22      extends AbstractTreeNode {
23  
24      private static final Log LOG = LogFactory.getLog(TrackNode.class);
25  
26      /**
27       * Constructs a <code>TrackNode</code> for the given parent and track.
28       * <p>
29       * @param aParent this node's parent
30       * @param aModel the associated model, an instance of Track
31       */
32      public TrackNode(NavigationNode aParent, Track aModel) {
33          super(aParent, aModel);
34          this.settings = ((AbstractTreeNode)aParent).settings;
35      }
36  
37      /**
38       * Returns this node's icon, ignores the selection.
39       * The icons is requested from a global resource repository.
40       * <p>
41       * @return this node's icon.
42       */
43      public Icon getIcon(final boolean sel) {
44          final String extension = getTrack().getTrackUrl().toLowerCase();
45          if ((extension.endsWith(MusicFilter.OGG)) || (extension.endsWith(MusicFilter.SPEEX))) {
46              return Resources.OGG_VORBIS_ICON;
47          } else if (extension.endsWith(MusicFilter.FLAC)) {
48              return Resources.FLAC_ICON;
49          } else {
50              return Resources.TRACK_TREE_ICON;
51          }
52      }
53  
54      /**
55       * Returns this node's name, the identifier of the associated track.
56       * <p>
57       * @return this node's name
58       */
59      public String getName() {
60          return getTrack().getDisplayText(this.settings.getDisplayFormatTrack());
61      }
62  
63      /**
64       * Returns this node's associated Track instance.
65       * <p>
66       * @return this node's associated Track instance.
67       * @see NavigationNode#getModel()
68       */
69      public Track getTrack() {
70          return (Track)getModel();
71      }
72  
73      /* (non-Javadoc)
74       * @see com.melloware.jukes.gui.tool.node.AbstractTreeNode#loadChildren()
75       */
76      public void loadChildren() {
77          if (!childrenLoaded) {
78              loadingChildren = true;
79              LOG.debug("Loading children");
80              loadingChildren = false;
81              childrenLoaded = true;
82          }
83      }
84  
85  }