コード例 #1
0
 @Override
 public Component getTreeCellRendererComponent(
     JTree tree,
     Object value,
     boolean selected,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   invalidate();
   final VirtualFile file = getFile(value);
   final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
   if (file == null) {
     if (value instanceof DefaultMutableTreeNode) {
       final Object uo = node.getUserObject();
       if (uo instanceof String) {
         myColoredRenderer.getTreeCellRendererComponent(
             tree, value, selected, expanded, leaf, row, hasFocus);
         return myColoredRenderer;
       }
     }
     return myEmpty;
   }
   myCheckbox.setVisible(true);
   final TreeNodeState state = mySelectionManager.getState(node);
   myCheckbox.setEnabled(
       TreeNodeState.CLEAR.equals(state) || TreeNodeState.SELECTED.equals(state));
   myCheckbox.setSelected(!TreeNodeState.CLEAR.equals(state));
   myCheckbox.setOpaque(false);
   myCheckbox.setBackground(null);
   setBackground(null);
   myTextRenderer.getListCellRendererComponent(myFictive, file, 0, selected, hasFocus);
   revalidate();
   return this;
 }
コード例 #2
0
    private MyCheckboxTreeCellRenderer(
        final SelectionManager selectionManager,
        Map<VirtualFile, String> modulesSet,
        final Project project,
        final JTree tree,
        final Collection<VirtualFile> roots) {
      super(new BorderLayout());
      mySelectionManager = selectionManager;
      myModulesSet = modulesSet;
      myRoots = roots;
      setBackground(tree.getBackground());
      myColoredRenderer =
          new ColoredTreeCellRenderer() {
            @Override
            public void customizeCellRenderer(
                JTree tree,
                Object value,
                boolean selected,
                boolean expanded,
                boolean leaf,
                int row,
                boolean hasFocus) {
              append(value.toString());
            }
          };
      myFictive = new JBList();
      myFictive.setBackground(tree.getBackground());
      myFictive.setSelectionBackground(UIUtil.getListSelectionBackground());
      myFictive.setSelectionForeground(UIUtil.getListSelectionForeground());

      myTextRenderer =
          new WithModulesListCellRenderer(project, myModulesSet) {
            @Override
            protected void putParentPath(Object value, FilePath path, FilePath self) {
              if (myRoots.contains(self.getVirtualFile())) {
                super.putParentPath(value, path, self);
              }
            }
          };
      myTextRenderer.setBackground(tree.getBackground());

      myCheckbox = new JCheckBox();
      myCheckbox.setBackground(tree.getBackground());
      myEmpty = new JLabel("");

      add(myCheckbox, BorderLayout.WEST);
      add(myTextRenderer, BorderLayout.CENTER);
      myCheckbox.setVisible(true);
    }