Exemplo n.º 1
0
 int getTotalUnseen(TreeNode n) {
   int unseen = 0;
   for (int i = 0; i < n.getChildCount(); i++) {
     TreeNode child = n.getChildAt(i);
     if (child instanceof PlaylistTreeNode) unseen += ((PlaylistTreeNode) child).numUnseenTracks;
     else if (child instanceof LibraryTreeNode)
       unseen += ((LibraryTreeNode) child).numUnseenTracks;
     else unseen += getTotalUnseen(child);
   }
   return unseen;
 }
Exemplo n.º 2
0
 boolean anyComments(TreeNode n) {
   for (int i = 0; i < n.getChildCount(); i++) {
     TreeNode child = n.getChildAt(i);
     if (child instanceof PlaylistTreeNode) {
       if (((PlaylistTreeNode) child).hasComments) return true;
     } else if (child instanceof LibraryTreeNode) {
       if (((LibraryTreeNode) child).hasComments) return true;
     } else {
       if (anyComments(child)) return true;
     }
   }
   return false;
 }
Exemplo n.º 3
0
 public Component getTreeCellRendererComponent(
     JTree tree,
     Object value,
     boolean sel,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   final TreeNode node = (TreeNode) value;
   final JLabel lbl =
       (JLabel)
           super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
   boolean useBold = false;
   boolean useRed = false;
   if (node instanceof PlaylistTreeNode) {
     PlaylistTreeNode ptn = (PlaylistTreeNode) node;
     Icon specIcon = specIcons.get(ptn.getPlaylist().getTitle().toLowerCase());
     if (specIcon != null) lbl.setIcon(specIcon);
     else lbl.setIcon(playlistIcon);
     lbl.setMaximumSize(MAX_LVL2_SZ);
     lbl.setPreferredSize(MAX_LVL2_SZ);
     int unseen = ptn.numUnseenTracks;
     if (!sel && unseen > 0) {
       lbl.setText("[" + unseen + "] " + lbl.getText());
       useBold = true;
     }
     if (ptn.hasComments) {
       useRed = true;
       useBold = true;
     }
   } else if (node instanceof LibraryTreeNode) {
     lbl.setIcon(libraryIcon);
     lbl.setMaximumSize(MAX_LVL2_SZ);
     lbl.setPreferredSize(MAX_LVL2_SZ);
     LibraryTreeNode ltn = (LibraryTreeNode) node;
     int unseen = ltn.numUnseenTracks;
     if (!sel && unseen > 0) {
       lbl.setText("[" + unseen + "] " + lbl.getText());
       useBold = true;
     }
     if (ltn.hasComments) {
       useRed = true;
       useBold = true;
     }
   } else if (node instanceof FriendTreeNode) {
     lbl.setIcon(friendIcon);
     lbl.setMaximumSize(MAX_LVL1_SZ);
     lbl.setPreferredSize(MAX_LVL1_SZ);
     int unseen = getTotalUnseen(node);
     if (!sel && unseen > 0) {
       lbl.setText("[" + unseen + "] " + lbl.getText());
       useBold = true;
     }
     if (anyComments(node)) {
       useBold = true;
       useRed = true;
     }
   } else if (node instanceof AddFriendsTreeNode) {
     lbl.setIcon(addFriendsIcon);
     lbl.setMaximumSize(MAX_LVL1_SZ);
     lbl.setPreferredSize(MAX_LVL1_SZ);
   } else if (node.getParent() == null) {
     lbl.setIcon(rootIcon);
     lbl.setMaximumSize(MAX_LVL0_SZ);
     lbl.setPreferredSize(MAX_LVL0_SZ);
     // Are there any unseen tracks at all?
     int unseen = getTotalUnseen(node);
     if (unseen > 0) useBold = true;
     if (anyComments(node)) {
       useBold = true;
       useRed = true;
     }
   }
   if (useBold) lbl.setFont(boldFont);
   else lbl.setFont(normalFont);
   if (sel) {
     lbl.setForeground(BLUE_GRAY);
     lbl.setBackground(LIGHT_GRAY);
   } else {
     lbl.setForeground(DARK_GRAY);
     lbl.setBackground(MID_GRAY);
   }
   if (useRed) lbl.setForeground(GREEN);
   return lbl;
 }