Example usage for javax.swing JTree setToggleClickCount

List of usage examples for javax.swing JTree setToggleClickCount

Introduction

In this page you can find the example usage for javax.swing JTree setToggleClickCount.

Prototype

@BeanProperty(description = "Number of clicks before a node will expand/collapse.")
public void setToggleClickCount(int clickCount) 

Source Link

Document

Sets the number of mouse clicks before a node will expand or close.

Usage

From source file:base.BasePlayer.AddGenome.java

public AddGenome() {
    super(new BorderLayout());

    makeGenomes();//from w  w  w  .j  a va  2s .  c o m
    tree = new JTree(root);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    sizeError.setForeground(Draw.redColor);
    sizeError.setVisible(true);
    treemodel = (DefaultTreeModel) tree.getModel();
    remscroll = new JScrollPane(remtable);
    tree.setCellRenderer(new DefaultTreeCellRenderer() {
        private static final long serialVersionUID = 1L;
        private Icon collapsedIcon = UIManager.getIcon("Tree.collapsedIcon");
        private Icon expandedIcon = UIManager.getIcon("Tree.expandedIcon");
        //   private Icon leafIcon = UIManager.getIcon("Tree.leafIcon");
        private Icon addIcon = UIManager.getIcon("Tree.closedIcon");

        //        private Icon saveIcon = UIManager.getIcon("OptionPane.informationIcon");
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean isLeaf, int row, boolean focused) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row,
                    focused);

            if (!isLeaf) {

                //setFont(getFont().deriveFont(Font.PLAIN));
                if (expanded) {
                    setIcon(expandedIcon);
                } else {
                    setIcon(collapsedIcon);
                }

                /*   if(((DefaultMutableTreeNode) value).getUserObject().toString().equals("Annotations")) {
                      this.setFocusable(false);
                      setFont(getFont().deriveFont(Font.BOLD));
                      setIcon(null);
                   }
                */
            } else {
                if (((DefaultMutableTreeNode) value).getUserObject().toString().equals("Annotations")) {

                    //      setFont(getFont().deriveFont(Font.PLAIN));
                    setIcon(null);
                } else if (((DefaultMutableTreeNode) value).getUserObject().toString().startsWith("Add new")) {

                    //       setFont(getFont().deriveFont(Font.PLAIN));

                    setIcon(addIcon);
                } else {
                    //      setFont(getFont().deriveFont(Font.ITALIC));
                    setIcon(null);
                    //   setIcon(leafIcon);
                }

            }

            return c;
        }
    });
    tree.addMouseListener(this);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            try {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

                if (node == null)
                    return;

                selectedNode = node;

                if (node.isLeaf()) {
                    checkUpdates.setEnabled(false);
                } else {
                    checkUpdates.setEnabled(true);
                }
                if (node.toString().startsWith("Add new") || node.toString().equals("Annotations")) {
                    remove.setEnabled(false);
                } else {
                    remove.setEnabled(true);
                }
                genometable.clearSelection();
                download.setEnabled(false);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    tree.setToggleClickCount(1);
    tree.setRootVisible(false);
    treescroll = new JScrollPane(tree);
    checkGenomes();
    genomeFileText = new JLabel("Select reference fasta-file");
    annotationFileText = new JLabel("Select annotation gff3-file");
    genomeName = new JTextField("Give name of the genome");
    openRef = new JButton("Browse");
    openAnno = new JButton("Browse");
    add = new JButton("Add");
    download = new JButton("Download");
    checkEnsembl = new JButton("Ensembl fetch");
    checkEnsembl.setMinimumSize(Main.buttonDimension);
    checkEnsembl.addActionListener(this);
    getLinks = new JButton("Get file links.");
    remove = new JButton("Remove");
    checkUpdates = new JButton("Check updates");
    download.setEnabled(false);
    getLinks.setEnabled(false);
    getLinks.addActionListener(this);
    remove.setEnabled(false);
    download.addActionListener(this);
    remove.addActionListener(this);
    panel.setBackground(Draw.sidecolor);
    checkUpdates.addActionListener(this);
    this.setBackground(Draw.sidecolor);
    frame.getContentPane().setBackground(Draw.sidecolor);
    GridBagConstraints c = new GridBagConstraints();

    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(2, 4, 2, 4);
    c.gridwidth = 2;
    genometable.setSelectionMode(0);
    genometable.setShowGrid(false);
    remtable.setSelectionMode(0);
    remtable.setShowGrid(false);
    JScrollPane scroll = new JScrollPane();
    scroll.getViewport().setBackground(Color.white);
    scroll.getViewport().add(genometable);

    remscroll.getViewport().setBackground(Color.white);

    genometable.addMouseListener(this);
    remtable.addMouseListener(this);
    //   panel.add(welcomeLabel,c);
    //   c.gridy++;
    c.anchor = GridBagConstraints.NORTHWEST;
    panel.add(new JLabel("Download genome reference and annotation"), c);
    c.gridx++;
    c.anchor = GridBagConstraints.NORTHEAST;
    panel.add(checkEnsembl, c);
    c.anchor = GridBagConstraints.NORTHWEST;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridy++;
    //c.fill = GridBagConstraints.NONE;
    panel.add(scroll, c);
    c.gridy++;
    c.fill = GridBagConstraints.NONE;
    panel.add(download, c);
    c.gridx = 1;
    panel.add(sizeError, c);
    c.gridx = 1;
    panel.add(getLinks, c);
    c.gridy++;
    c.gridx = 0;
    c.fill = GridBagConstraints.BOTH;
    panel.add(new JLabel("Add/Remove installed genomes manually"), c);
    c.gridy++;
    panel.add(treescroll, c);
    c.gridy++;

    c.fill = GridBagConstraints.NONE;
    c.gridwidth = 1;
    remove.setMinimumSize(Main.buttonDimension);
    panel.add(remove, c);
    c.gridx = 1;
    panel.add(checkUpdates, c);
    checkUpdates.setMinimumSize(Main.buttonDimension);
    checkUpdates.setEnabled(false);
    c.gridwidth = 2;
    c.gridx = 0;
    c.gridy++;
    try {
        if (Main.genomeDir != null) {
            genomedirectory.setText(Main.genomeDir.getCanonicalPath());
        }

        genomedirectory.setEditable(false);
        genomedirectory.setBackground(Color.white);
        genomedirectory.setForeground(Color.black);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    panel.add(new JLabel("Genome directory:"), c);
    c.gridy++;
    panel.add(genomedirectory, c);
    /*   c.fill = GridBagConstraints.BOTH;
       c.gridy++;
       panel.add(new JLabel("Add genome manually"),c);
       c.gridy++;   
       c.gridwidth = 2;      
       panel.add(new JSeparator(),c);
       c.gridwidth = 1;
       c.gridy++;
       panel.add(genomeFileText, c);
       c.fill = GridBagConstraints.NONE;
       c.gridx = 1;
       panel.add(openRef, c);      
               
       c.gridx = 0;
       openRef.addActionListener(this);
       c.gridy++;
       panel.add(annotationFileText,c);
       c.gridx=1;
       panel.add(openAnno, c);
       c.gridy++;
               
       panel.add(add,c);
            
       openAnno.addActionListener(this);
       add.addActionListener(this);
       add.setEnabled(false);
       */
    add(panel, BorderLayout.NORTH);
    if (Main.drawCanvas != null) {
        setFonts(Main.menuFont);
    }
    /*   html.append("<a href=http:Homo_sapiens_GRCh37:Ensembl_genes> Homo sapiens GRCh37 with Ensembl</a> or <a href=http:Homo_sapiens_GRCh37:RefSeq_genes>RefSeq</a> gene annotations<br>");
       html.append("<a href=http:Homo_sapiens_GRCh38:Ensembl_genes> Homo sapiens GRCh38 with Ensembl</a> or <a href=http:Homo_sapiens_GRCh38:RefSeq_genes>RefSeq</a> gene annotations<br><br>");
               
       html.append("<a href=http:Mus_musculus_GRCm38:Ensembl_genes> Mus musculus GRCm38 with Ensembl</a> or <a href=http:Mus_musculus_GRCm38:RefSeq_genes>RefSeq</a> gene annotations<br>");
       html.append("<a href=http:Rattus_norvegicus:Ensembl_genes> Rattus norvegicus with Ensembl gene annotations</a><br>");
       html.append("<a href=http:Saccharomyces_cerevisiae:Ensembl_genes> Saccharomyces cerevisiae with Ensembl gene annotation</a><br>");               
       html.append("<a href=http:Ciona_intestinalis:Ensembl_genes> Ciona intestinalis with Ensembl gene annotation</a><br>");
       Object[] row = {"Homo_sapiens_GRCh37"};
       Object[] row = {"Homo_sapiens_GRCh38"};
               
       model.addRow(row);
       /*   genomeName.setPreferredSize(new Dimension(300,20));
       this.add(genomeName);
       this.add(new JSeparator());
               
       this.add(openRef);
       openRef.addActionListener(this);
       this.add(genomeFileText);
       this.add(openAnno);
       openAnno.addActionListener(this);
       this.add(annotationFileText);
       this.add(add);
       add.addActionListener(this);
       if(annotation) {
          openRef.setVisible(false);
          genomeFileText.setVisible(false);
          genomeName.setEditable(false);
       }
       genomeFileText.setEditable(false);
       annotationFileText.setEditable(false);*/
}