示例#1
0
 public void valueChanged(TreeSelectionEvent e) {
   TreePath tp = e.getNewLeadSelectionPath();
   if (tp == null) return;
   Object selNode = tp.getLastPathComponent();
   if (selNode instanceof ButtonTreeNode) {
     ButtonTreeNode btn = (ButtonTreeNode) selNode;
     btn.onClick();
     setSelectionPath(e.getOldLeadSelectionPath());
     return;
   }
   if (!(selNode instanceof SelectableTreeNode)) return;
   SelectableTreeNode stn = (SelectableTreeNode) selNode;
   if (stn.wantSelect()) {
     sideBar.clearSelectionExcept(FriendTree.this);
     // If this is a library or playlist node with comments, and the comments tab is showing,
     // mark the
     // comments as read
     FriendTreeModel m = getModel();
     if (stn instanceof LibraryTreeNode) {
       LibraryTreeNode ltn = (LibraryTreeNode) stn;
       ContentPanel cp = frame.mainPanel.getContentPanel("library/" + ltn.userId);
       // library content panel gets created on demand, so might be null
       if (cp != null && cp.tabPane.getSelectedIndex() == 1)
         m.markLibraryCommentsAsRead(ltn.userId);
     } else if (stn instanceof PlaylistTreeNode) {
       PlaylistTreeNode ptn = (PlaylistTreeNode) stn;
       long plId = ptn.getPlaylist().getPlaylistId();
       ContentPanel cp = frame.mainPanel.getContentPanel("playlist/" + plId);
       if (cp.tabPane.getSelectedIndex() == 1) m.markPlaylistCommentsAsRead(plId);
     }
     if (stn.handleSelect()) m.firePathToRootChanged(stn);
   } else setSelectionPath(e.getOldLeadSelectionPath());
 }
示例#2
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;
 }