Example usage for javax.swing JTree JTree

List of usage examples for javax.swing JTree JTree

Introduction

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

Prototype

@ConstructorProperties({ "model" })
public JTree(TreeModel newModel) 

Source Link

Document

Returns an instance of JTree which displays the root node -- the tree is created using the specified data model.

Usage

From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.gui.controls.datasource.WpsDialog.java

private void initTree(final Set<DataSource> sources) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Data Sources");
    List<Exception> exceptions = new ArrayList<>();

    for (DataSource source : sources) {

        String rootTitle = source.getUsedDriver() + ": " + source.getRessource();
        DefaultMutableTreeNode wpsRoot = new DefaultMutableTreeNode(rootTitle);

        try {//w  w w .  j  a va  2  s .  c o  m
            for (WpsDescription wpsDesc : source.getWpsList()) {
                DefaultMutableTreeNode wps = new WpsTreeNode(wpsDesc, WpsTreeNode.NodeType.WPS);

                for (WpsProcessDescription processDesc : wpsDesc.getProcesses()) {
                    DefaultMutableTreeNode processNode = new WpsTreeNode(processDesc,
                            WpsTreeNode.NodeType.PROCESS);
                    wps.add(processNode);
                }

                wpsRoot.add(wps);
            }
        } catch (DataSourceException ex) {
            // gather occured exceptions for later displaying
            exceptions.add(ex);
        }

        root.add(wpsRoot);
    }

    if (!exceptions.isEmpty()) {
        showErrorMessage(exceptionListToString(exceptions));
    }

    wpsTree = new JTree(root);
    treeScrollPane.setViewportView(wpsTree);
}

From source file:base.BasePlayer.AddGenome.java

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

    makeGenomes();//w  w  w.j  av a 2 s  .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);*/
}

From source file:guineu.modules.database.openQualityControlFileDB.DatasetOpenDialog.java

/**
 * Creates a tree with the studies and their correspondents data sets.
 * The information is taken from the database.
 *
 * @return New tree//from   w w  w  . j  a  va 2s.  c o m
 */
private JTree createTree() {
    db = new OracleRetrievement();
    String rootName = "Data";
    CheckNode rootNode = new CheckNode(rootName);

    List<String[]> QCdatasets = db.getQualityControlDatasets();

    for (String[] dataset : QCdatasets) {
        String info = "";
        for (String d : dataset) {
            info += d + " - ";
        }
        CheckNode stNode = new CheckNode(info);
        this.nodeTable.put(stNode, dataset);
        rootNode.add(stNode);
    }

    tree = new JTree(rootNode);

    tree.setCellRenderer(new CheckRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.addMouseListener(new NodeSelectionListener(tree));
    this.SPResults.setViewportView((Component) tree);

    return tree;
}

From source file:gdt.jgui.entity.JEntityStructurePanel.java

/**
 * Create the context./*from ww w  .  j a va2s  .co m*/
 * @param console the main console.
 * @param locator$ the locator.
 * @return the structure panel.
 */
@Override
public JContext instantiate(JMainConsole console, String locator$) {
    this.console = console;
    this.locator$ = locator$;
    Properties locator = Locator.toProperties(locator$);
    entihome$ = locator.getProperty(Entigrator.ENTIHOME);
    entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
    entityLabel$ = locator.getProperty(EntityHandler.ENTITY_LABEL);
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(entityLabel$);
    locator = new Properties();
    locator.setProperty(Locator.LOCATOR_TITLE, STRUCTURE);
    String icon$ = Support.readHandlerIcon(null, getClass(), "tree.png");
    locator.setProperty(Locator.LOCATOR_ICON, icon$);
    root.setUserObject(Locator.toString(locator));
    DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode(entityLabel$);
    root.add(parentNode);
    Entigrator entigrator = console.getEntigrator(entihome$);
    Sack parent = entigrator.getEntityAtKey(entityKey$);
    String parentLocator$ = EntityHandler.getEntityLocator(entigrator, parent);
    parentNode.setUserObject(parentLocator$);
    addChildren(parentNode);
    tree = new JTree(root);
    tree.addTreeSelectionListener(new SelectionListener());
    tree.setShowsRootHandles(true);
    tree.setCellRenderer(new NodeRenderer());
    tree.addMouseListener(new MousePopupListener());
    scrollPane.getViewport().add(tree);
    expandTree(tree, true);
    return this;
}

From source file:it.isislab.dmason.tools.batch.BatchWizard.java

/**
 * Create the frame./*from  ww w  .j a v a 2  s  .c  o  m*/
 */
public BatchWizard() {
    setPreferredSize(new Dimension(800, 600));
    setTitle("Batch wizard");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 849, 620);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(new GridLayout(1, 0, 0, 0));

    JPanel panel = new JPanel();
    panel.setToolTipText("");
    contentPane.add(panel);

    panel_1 = new JPanel();
    panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Param Option",
            TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));

    JPanel panel_2 = new JPanel();
    panel_2.setBorder(
            new TitledBorder(null, "Params List", TitledBorder.LEADING, TitledBorder.TOP, null, null));

    JPanel panel_3 = new JPanel();

    JPanel panel_4 = new JPanel();
    GroupLayout gl_panel = new GroupLayout(panel);
    gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel
            .createSequentialGroup().addContainerGap()
            .addComponent(
                    panel_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
                    .addGroup(gl_panel.createSequentialGroup()
                            .addComponent(panel_4, GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE).addGap(20))
                    .addGroup(gl_panel.createSequentialGroup()
                            .addComponent(panel_2, GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE).addGap(4))))
            .addComponent(panel_3, GroupLayout.DEFAULT_SIZE, 823, Short.MAX_VALUE));
    gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.TRAILING).addGroup(gl_panel
            .createSequentialGroup()
            .addComponent(panel_3, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
                    .addGroup(gl_panel.createSequentialGroup()
                            .addComponent(panel_2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addGap(25)
                            .addComponent(panel_4, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
                    .addComponent(panel_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap()));

    final JButton btnSave = new JButton("Save");
    btnSave.setEnabled(false);
    btnSave.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {

            File saveFile = SaveFileChooser();
            createXML(saveFile.getAbsoluteFile().getPath());
        }
    });

    lblTotTests = new JLabel(totTestsMessage);
    GroupLayout gl_panel_4 = new GroupLayout(panel_4);
    gl_panel_4.setHorizontalGroup(gl_panel_4.createParallelGroup(Alignment.TRAILING)
            .addGroup(gl_panel_4.createSequentialGroup().addGap(21).addComponent(lblTotTests)
                    .addPreferredGap(ComponentPlacement.RELATED, 515, Short.MAX_VALUE).addComponent(btnSave)
                    .addGap(21)));
    gl_panel_4.setVerticalGroup(gl_panel_4.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_panel_4.createSequentialGroup().addContainerGap()
                    .addGroup(gl_panel_4.createParallelGroup(Alignment.BASELINE).addComponent(btnSave)
                            .addComponent(lblTotTests))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    panel_4.setLayout(gl_panel_4);

    top = new DefaultMutableTreeNode("Parameters");

    JScrollPane scrollPaneTree = new JScrollPane();

    JLabel lblNumberOfWorkers = new JLabel("Number of Workers:");

    textFieldNumberOfWorkers = new JTextField();
    textFieldNumberOfWorkers.setText("1");
    textFieldNumberOfWorkers.setColumns(10);
    textFieldNumberOfWorkers.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            if (textFieldNumberOfWorkers.isVisible()) {
                boolean checkNumberOfWorkers = true;

                while (checkNumberOfWorkers) {

                    String dist = textFieldNumberOfWorkers.getText();
                    boolean validateDist = dist.matches("(\\d)+");
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldNumberOfWorkers.setText(newDist);
                    }

                    else {
                        checkNumberOfWorkers = false;
                    }
                }
            }
        }
    });

    checkBoxLoadBalancing = new JCheckBox("Load Balancing", false);
    checkBoxLoadBalancing.setEnabled(true);

    GroupLayout gl_panel_2 = new GroupLayout(panel_2);
    gl_panel_2.setHorizontalGroup(gl_panel_2.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_2
            .createSequentialGroup().addContainerGap()
            .addGroup(gl_panel_2.createParallelGroup(Alignment.LEADING)
                    .addComponent(scrollPaneTree, GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE)
                    .addGroup(gl_panel_2.createSequentialGroup().addComponent(lblNumberOfWorkers)
                            .addPreferredGap(ComponentPlacement.UNRELATED)
                            .addComponent(textFieldNumberOfWorkers, GroupLayout.PREFERRED_SIZE, 46,
                                    GroupLayout.PREFERRED_SIZE))
                    .addComponent(checkBoxLoadBalancing, GroupLayout.PREFERRED_SIZE, 114,
                            GroupLayout.PREFERRED_SIZE))
            .addContainerGap()));
    gl_panel_2.setVerticalGroup(gl_panel_2.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_2
            .createSequentialGroup().addContainerGap()
            .addComponent(scrollPaneTree, GroupLayout.PREFERRED_SIZE, 271, GroupLayout.PREFERRED_SIZE)
            .addGap(33)
            .addGroup(gl_panel_2.createParallelGroup(Alignment.BASELINE).addComponent(lblNumberOfWorkers)
                    .addComponent(textFieldNumberOfWorkers, GroupLayout.PREFERRED_SIZE,
                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(checkBoxLoadBalancing, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
            .addContainerGap(56, Short.MAX_VALUE)));

    final JTree treeParams = new JTree(top);
    scrollPaneTree.setViewportView(treeParams);
    treeParams.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent selected) {
            // DefaultMutableTreeNode parent =
            // selected.getPath().getParentPath()

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeParams.getLastSelectedPathComponent();
            if (node.getParent() != null) {
                if (node.getParent() == simParams || node.getParent().equals(generalParams)) {

                    selectedParam = (Param) node.getUserObject();
                    if (node.getParent() == simParams) {
                        selectedParamIndex = simParams.getIndex(node);
                        paramType = "simParam";
                    }

                    else {
                        selectedParamIndex = generalParams.getIndex(node);
                        paramType = "generalParam";
                    }
                    if (selectedParam instanceof ParamFixed) {
                        ParamFixed pf = (ParamFixed) selectedParam;
                        lblParamType.setText(pf.getName() + ": " + pf.getType());
                        if (suggestion.get(pf.getName()) != null) {
                            lblDomain.setText("Domain: " + suggestion.get(pf.getName()).getDomain());
                            lblSuggested.setText(
                                    "Suggested Value: " + suggestion.get(pf.getName()).getSuggestedValue());
                        }

                        textFieldRuns.setText("" + pf.getRuns());
                        textFieldValue.setText(pf.getValue());
                        rdbtnFixed.doClick();

                        lblMessage.setVisible(false);
                        setModifyControlEnable(true);

                    }

                    if (selectedParam instanceof ParamRange) {
                        ParamRange pf = (ParamRange) selectedParam;
                        lblParamType.setText(pf.getName() + ": " + pf.getType());
                        if (suggestion.get(pf.getName()) != null) {
                            lblDomain.setText("Domain: " + suggestion.get(pf.getName()).getDomain());
                            lblSuggested.setText(
                                    "Suggested Value: " + suggestion.get(pf.getName()).getSuggestedValue());
                        }
                        textFieldRuns.setText("" + pf.getRuns());
                        textFieldStartValue.setText(pf.getStart());
                        textFieldEndValue.setText(pf.getEnd());
                        textFieldIncrement.setText(pf.getIncrement());
                        rdbtnRange.doClick();

                        lblMessage.setVisible(false);
                        setModifyControlEnable(true);
                    }

                    if (selectedParam instanceof ParamList) {
                        ParamList pl = (ParamList) selectedParam;
                        if (suggestion.get(pl.getName()) != null) {
                            lblDomain.setText("Domain: " + suggestion.get(pl.getName()).getDomain());
                            lblSuggested.setText(
                                    "Suggested Value: " + suggestion.get(pl.getName()).getSuggestedValue());
                        }
                        lblParamType.setText(pl.getName() + ": " + pl.getType());
                        textFieldRuns.setText("" + pl.getRuns());
                        StringBuilder b = new StringBuilder();
                        boolean isFirst = true;
                        for (String element : pl.getValues()) {
                            if (isFirst) {
                                b.append(element);
                                isFirst = false;
                            } else
                                b.append("," + element);
                        }
                        textFieldList.setText(b.toString());
                        rdbtnByvalues.doClick();

                        setListControlvisibility(true);
                        lblMessage.setVisible(false);
                        setModifyControlEnable(true);
                    }
                    if (selectedParam instanceof ParamDistribution) {
                        DistributionType distType = DistributionType.none;
                        if (selectedParam instanceof ParamDistributionUniform) {
                            ParamDistributionUniform pu = (ParamDistributionUniform) selectedParam;
                            lblParamType.setText(pu.getName() + ": " + pu.getType());
                            if (suggestion.get(pu.getName()) != null) {
                                lblDomain.setText("Domain: " + suggestion.get(pu.getName()).getDomain());
                                lblSuggested.setText(
                                        "Suggested Value: " + suggestion.get(pu.getName()).getSuggestedValue());
                            }

                            textFieldRuns.setText("" + pu.getRuns());
                            textFieldA.setText(pu.getA());
                            textFieldB.setText(pu.getB());
                            textFieldNumberOfValues.setText("" + pu.getNumberOfValues());
                            distType = DistributionType.uniform;
                        }
                        if (selectedParam instanceof ParamDistributionExponential) {
                            ParamDistributionExponential pe = (ParamDistributionExponential) selectedParam;
                            lblParamType.setText(pe.getName() + ": " + pe.getType());
                            if (suggestion.get(pe.getName()) != null) {

                                lblDomain.setText("Domain: " + suggestion.get(pe.getName()).getDomain());
                                lblSuggested.setText(
                                        "Suggested Value: " + suggestion.get(pe.getName()).getSuggestedValue());
                            }

                            textFieldRuns.setText("" + pe.getRuns());
                            textFieldA.setText(pe.getLambda());
                            textFieldNumberOfValues.setText("" + pe.getNumberOfValues());
                            distType = DistributionType.exponential;
                        }
                        if (selectedParam instanceof ParamDistributionNormal) {
                            ParamDistributionNormal pn = (ParamDistributionNormal) selectedParam;
                            lblParamType.setText(pn.getName() + ": " + pn.getType());
                            if (suggestion.get(pn.getName()) != null) {
                                lblDomain.setText("Domain: " + suggestion.get(pn.getName()).getDomain());
                                lblSuggested.setText(
                                        "Suggested Value: " + suggestion.get(pn.getName()).getSuggestedValue());
                            }

                            textFieldRuns.setText("" + pn.getRuns());
                            textFieldA.setText(pn.getMean());
                            textFieldB.setText(pn.getStdDev());
                            textFieldNumberOfValues.setText("" + pn.getNumberOfValues());
                            distType = DistributionType.normal;

                        }

                        rdbtnByDistribution.doClick();
                        setDistributionControlVisibility(distType);
                        setDistributionComboBoxVisibility(true);
                        lblMessage.setVisible(false);
                        setModifyControlEnable(true);
                    }
                }
            }
        }
    });

    panel_2.setLayout(gl_panel_2);

    JLabel lblSelectSimulationJar = new JLabel("Select simulation jar:");

    textFieldSimJarPath = new JTextField();
    textFieldSimJarPath.setColumns(10);

    btnLoadParams = new JButton("Load Params");
    btnLoadParams.setEnabled(false);
    btnLoadParams.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ArrayList<Param> params = loadParams();
            if (params != null) {
                top.removeAllChildren();
                createNodes(top, params);
                treeParams.expandPath(new TreePath(top.getPath()));
                treeParams.expandPath(new TreePath(simParams.getPath()));
                treeParams.expandPath(new TreePath(generalParams.getPath()));
            }

            lblTotTests.setText(totTestsMessage + " " + getTotTests());
            btnSave.setEnabled(true);
        }
    });

    JButton bntChooseSimulation = new JButton();
    bntChooseSimulation.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {

            simulationFile = showFileChooser();
            if (simulationFile != null) {
                textFieldSimJarPath.setText(simulationFile.getAbsolutePath());
                btnLoadParams.setEnabled(true);

                isThin = isThinSimulation(simulationFile);
                checkBoxLoadBalancing.setEnabled(!isThin);

            }
        }

    });
    bntChooseSimulation.setIcon(
            new ImageIcon(BatchWizard.class.getResource("/it.isislab.dmason/resource/image/openFolder.png")));
    GroupLayout gl_panel_3 = new GroupLayout(panel_3);
    gl_panel_3.setHorizontalGroup(gl_panel_3.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_3
            .createSequentialGroup().addContainerGap().addComponent(lblSelectSimulationJar)
            .addPreferredGap(ComponentPlacement.RELATED)
            .addComponent(textFieldSimJarPath, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(bntChooseSimulation, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
            .addGap(26).addComponent(btnLoadParams).addContainerGap(172, Short.MAX_VALUE)));
    gl_panel_3.setVerticalGroup(gl_panel_3.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_3
            .createSequentialGroup().addContainerGap()
            .addGroup(gl_panel_3.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_3
                    .createParallelGroup(Alignment.BASELINE).addComponent(lblSelectSimulationJar)
                    .addComponent(textFieldSimJarPath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(bntChooseSimulation, GroupLayout.PREFERRED_SIZE, 25,
                            GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnLoadParams))
            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    panel_3.setLayout(gl_panel_3);

    lblParamType = new JLabel("Param : type");
    lblParamType.setFont(new Font("Tahoma", Font.BOLD, 11));

    JLabel lblRuns = new JLabel("Runs:");
    textFieldRuns = new JTextField();
    textFieldRuns.setColumns(10);
    textFieldRuns.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            if (textFieldRuns.isVisible()) {
                boolean checkRuns = true;

                while (checkRuns) {

                    String dist = textFieldRuns.getText();
                    boolean validateDist = dist.matches("(\\d)+");
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldRuns.setText(newDist);
                    }

                    else {
                        checkRuns = false;
                    }
                }
            }
        }
    });
    JLabel lblParameterSpace = new JLabel("Parameter Space");
    lblParameterSpace.setFont(new Font("Tahoma", Font.BOLD, 11));

    lblValue = new JLabel("Value:");

    textFieldValue = new JTextField();
    textFieldValue.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            String regex = "(\\d)+|((\\d)+\\.(\\d)+)";
            if (textFieldValue.isVisible()) {
                boolean checkValue = true;

                while (checkValue) {

                    String dist = textFieldValue.getText();
                    boolean validateDist = dist.matches(regex);
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldValue.setText(newDist);
                    }

                    else {
                        checkValue = false;
                    }
                }
            }
        }
    });
    textFieldValue.setColumns(10);
    /*textFieldValue.addKeyListener(new KeyListener() {
            
       @Override
       public void keyTyped(KeyEvent arg0) {}
            
       @Override
       public void keyReleased(KeyEvent arg0) {
    checkError();
            
            
       }
            
       @Override
       public void keyPressed(KeyEvent arg0) {}
    });
    */
    lblStartValue = new JLabel("Start value:");

    textFieldStartValue = new JTextField();
    textFieldStartValue.setText("1");
    textFieldStartValue.setColumns(10);
    textFieldStartValue.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            String regex = "(\\d)+|((\\d)+\\.(\\d)+)";
            if (textFieldStartValue.isVisible()) {
                boolean checkStartValue = true;

                while (checkStartValue) {

                    String dist = textFieldStartValue.getText();
                    boolean validateDist = dist.matches(regex);
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldStartValue.setText(newDist);
                    }

                    else {
                        checkStartValue = false;
                    }
                }
            }
        }
    });

    lblEndValue = new JLabel("End value:");

    textFieldEndValue = new JTextField();
    textFieldEndValue.setText("1");
    textFieldEndValue.setColumns(10);
    textFieldEndValue.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            String regex = "(\\d)+|((\\d)+\\.(\\d)+)";
            if (textFieldEndValue.isVisible()) {
                boolean checkEndValue = true;

                while (checkEndValue) {

                    String dist = textFieldEndValue.getText();
                    boolean validateDist = dist.matches(regex);
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldEndValue.setText(newDist);
                    }

                    else {
                        checkEndValue = false;
                    }
                }
            }
        }
    });

    lblIncrement = new JLabel("Increment:");

    textFieldIncrement = new JTextField();
    textFieldIncrement.setText("1");
    textFieldIncrement.setColumns(10);
    textFieldIncrement.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            String regex = "(\\d)+|((\\d)+\\.(\\d)+)";
            if (textFieldIncrement.isVisible()) {

                boolean checkIncrement = true;

                while (checkIncrement) {

                    String dist = textFieldIncrement.getText();
                    boolean validateDist = dist.matches(regex);
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldIncrement.setText(newDist);
                    }

                    else {
                        checkIncrement = false;
                    }
                }
            }
        }
    });

    rdbtnFixed = new JRadioButton("Fixed");
    rdbtnFixed.setSelected(true);
    rdbtnFixed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {

            setListControlvisibility(false);
            setDistributionComboBoxVisibility(false);
            setRangeControlVisibility(false);
            setFixedControlVisibility(true);
            setDistributionControlVisibility(DistributionType.none);
        }

    });

    rdbtnRange = new JRadioButton("Range");
    rdbtnRange.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setRangeControlVisibility(true);
            setFixedControlVisibility(false);
            setListControlvisibility(false);
            setDistributionComboBoxVisibility(false);
            setDistributionControlVisibility(DistributionType.none);
        }
    });

    rdbtnByvalues = new JRadioButton("By Values");
    rdbtnByvalues.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setRangeControlVisibility(false);
            setFixedControlVisibility(false);
            setListControlvisibility(true);
            setDistributionComboBoxVisibility(false);
            setDistributionControlVisibility(DistributionType.none);
        }
    });
    rdbtnByDistribution = new JRadioButton("By Distribution");
    rdbtnByDistribution.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setRangeControlVisibility(false);
            setFixedControlVisibility(false);
            setListControlvisibility(false);
            setDistributionComboBoxVisibility(true);
            setDistributionControlVisibility(DistributionType.none);
        }
    });
    // Group the radio buttons.
    ButtonGroup group = new ButtonGroup();
    group.add(rdbtnFixed);
    group.add(rdbtnRange);
    group.add(rdbtnByvalues);
    group.add(rdbtnByDistribution);

    setRangeControlVisibility(false);
    setFixedControlVisibility(false);

    lblMessage = new JLabel(message);

    btnModify = new JButton("Modify");
    btnModify.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {

            if (rdbtnFixed.isSelected()) {
                ParamFixed param = new ParamFixed(selectedParam.getName(), selectedParam.getType(),
                        Integer.parseInt(textFieldRuns.getText()), textFieldValue.getText());
                DefaultMutableTreeNode p = new DefaultMutableTreeNode(param);

                if (paramType.equals("simParam")) {
                    simParams.remove(selectedParamIndex);

                    simParams.insert(p, selectedParamIndex);
                } else {
                    generalParams.remove(selectedParamIndex);

                    generalParams.insert(p, selectedParamIndex);
                }

                treeParams.updateUI();

                /*
                 * ((ParamFixed)
                 * selectedParam).setValue(textFieldValue.getText());
                 * selectedParam
                 * .setRuns(Integer.parseInt(textFieldRuns.getText()));
                 * treeParams.repaint();
                 */
            }
            if (rdbtnRange.isSelected()) {
                ParamRange param = new ParamRange(selectedParam.getName(), selectedParam.getType(),
                        Integer.parseInt(textFieldRuns.getText()), textFieldStartValue.getText(),
                        textFieldEndValue.getText(), textFieldIncrement.getText());
                DefaultMutableTreeNode p = new DefaultMutableTreeNode(param);

                if (paramType.equals("simParam")) {
                    simParams.remove(selectedParamIndex);

                    simParams.insert(p, selectedParamIndex);
                } else {
                    generalParams.remove(selectedParamIndex);

                    generalParams.insert(p, selectedParamIndex);
                }
                treeParams.updateUI();
                // treeParams.repaint();

            }
            if (rdbtnByvalues.isSelected()) {
                StringTokenizer st = new StringTokenizer(textFieldList.getText(), ",");
                ArrayList<String> values = new ArrayList<String>();
                while (st.hasMoreTokens())
                    values.add(st.nextToken());

                ParamList param = new ParamList(selectedParam.getName(), selectedParam.getType(),
                        Integer.parseInt(textFieldRuns.getText()), values);
                DefaultMutableTreeNode p = new DefaultMutableTreeNode(param);

                if (paramType.equals("simParam")) {
                    simParams.remove(selectedParamIndex);

                    simParams.insert(p, selectedParamIndex);
                } else {
                    generalParams.remove(selectedParamIndex);

                    generalParams.insert(p, selectedParamIndex);
                }
                treeParams.updateUI();
                // treeParams.repaint();

            }
            if (rdbtnByDistribution.isSelected()) {
                DefaultMutableTreeNode p;
                switch (selectedDistribution) {
                case uniform:

                    p = new DefaultMutableTreeNode(
                            new ParamDistributionUniform(selectedParam.getName(), selectedParam.getType(),
                                    Integer.parseInt(textFieldRuns.getText()), textFieldA.getText(),
                                    textFieldB.getText(), Integer.parseInt(textFieldNumberOfValues.getText())));
                    break;
                case exponential:

                    p = new DefaultMutableTreeNode(new ParamDistributionExponential(selectedParam.getName(),
                            selectedParam.getType(), Integer.parseInt(textFieldRuns.getText()),
                            textFieldA.getText(), Integer.parseInt(textFieldNumberOfValues.getText())));
                    break;

                case normal:

                    p = new DefaultMutableTreeNode(
                            new ParamDistributionNormal(selectedParam.getName(), selectedParam.getType(),
                                    Integer.parseInt(textFieldRuns.getText()), textFieldA.getText(),
                                    textFieldA.getText(), Integer.parseInt(textFieldNumberOfValues.getText())));
                    break;
                default:
                    p = new DefaultMutableTreeNode();
                    break;
                }

                if (paramType.equals("simParam")) {
                    simParams.remove(selectedParamIndex);

                    simParams.insert(p, selectedParamIndex);
                } else {
                    generalParams.remove(selectedParamIndex);

                    generalParams.insert(p, selectedParamIndex);
                }
                treeParams.updateUI();
                // treeParams.repaint();

            }
            lblMessage.setVisible(true);
            setModifyControlEnable(false);
            setDistributionControlVisibility(DistributionType.none);
            setDistributionComboBoxVisibility(false);
            setListControlvisibility(false);

            int tot = getTotTests();
            if (tot >= testAlertThreshold)
                lblTotTests.setForeground(Color.RED);
            else
                lblTotTests.setForeground(Color.BLACK);

            lblTotTests.setText(totTestsMessage + " " + tot);

        }
    });

    btnCancel = new JButton("Cancel");
    btnCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            lblMessage.setVisible(true);
            setModifyControlEnable(false);

        }
    });

    lblCommaSeparatedList = new JLabel("List:");
    lblCommaSeparatedList.setVisible(false);

    textFieldList = new JTextField();
    textFieldList.setVisible(false);
    textFieldList.setToolTipText("Comma separated");
    textFieldList.setColumns(10);
    textFieldList.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            /*if(textFieldList.isVisible())
            {
            boolean checkList=true;
                    
            while(checkList){
                    
               String dist=textFieldList.getText();
               boolean validateDist=dist.matches("(\\d)+|((\\d)+\\.(\\d)+)(,(\\d)+|((\\d)+\\.(\\d)+))*");
               if(!validateDist){   
                  String   newDist=  JOptionPane.showInputDialog(null,"Insert comma separate number list","Number Format Error", 0);
                  textFieldList.setText(newDist);
               }
                    
               else{
                  checkList=false;
               }
            }
            }*/
        }
    });

    lblDistribution = new JLabel("Distribution");
    lblDistribution.setVisible(false);

    lblA = new JLabel("a:");
    lblA.setVisible(false);

    textFieldA = new JTextField();
    textFieldA.setText("1");
    textFieldA.setVisible(false);
    textFieldA.setColumns(10);
    textFieldA.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            String regex = "(\\d)+|((\\d)+\\.(\\d)+)";

            if (textFieldA.isVisible()) {
                boolean checkA = true;

                while (checkA) {

                    String dist = textFieldA.getText();
                    boolean validateDist = dist.matches(regex);
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldA.setText(newDist);
                    }

                    else {
                        checkA = false;
                    }
                }
            }
        }
    });

    lblB = new JLabel("b:");
    lblB.setVisible(false);

    textFieldB = new JTextField();
    textFieldB.setText("1");
    textFieldB.setVisible(false);
    textFieldB.setColumns(10);
    textFieldB.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {

            String regex = "(\\d)+|((\\d)+\\.(\\d)+)";
            if (textFieldB.isVisible()) {
                boolean checkB = true;

                while (checkB) {

                    String dist = textFieldB.getText();
                    boolean validateDist = dist.matches(regex);
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldB.setText(newDist);
                    }

                    else {
                        checkB = false;
                    }
                }
            }
        }
    });
    jComboBoxDistribution = new JComboBox();
    jComboBoxDistribution.setVisible(false);
    jComboBoxDistribution.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            // Prevent executing listener's actions two times
            if (e.getStateChange() != ItemEvent.SELECTED)
                return;
            selectedDistribution = ((DistributionType) jComboBoxDistribution.getSelectedItem());

            setDistributionControlVisibility(DistributionType.none);
            setDistributionControlVisibility(selectedDistribution);

        }
    });

    lblOfValues = new JLabel("# of values:");
    lblOfValues.setVisible(false);

    textFieldNumberOfValues = new JTextField();
    textFieldNumberOfValues.setText("1");
    textFieldNumberOfValues.setVisible(false);
    textFieldNumberOfValues.setColumns(10);
    textFieldNumberOfValues.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            if (textFieldNumberOfValues.isVisible()) {
                boolean checkNumberOfValues = true;

                while (checkNumberOfValues) {

                    String dist = textFieldNumberOfValues.getText();
                    boolean validateDist = dist.matches("(\\d)+");
                    if (!validateDist) {
                        String newDist = JOptionPane.showInputDialog(null, "Insert a number",
                                "Number Format Error", 0);
                        textFieldNumberOfValues.setText(newDist);
                    }

                    else {
                        checkNumberOfValues = false;
                    }
                }
            }
        }
    });

    lblSuggested = new JLabel("Suggested Value:");

    lblDomain = new JLabel("Domain:");

    GroupLayout gl_panel_1 = new GroupLayout(panel_1);
    gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING).addGroup(gl_panel_1
            .createSequentialGroup().addContainerGap()
            .addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING).addGroup(gl_panel_1
                    .createSequentialGroup()
                    .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addComponent(lblParamType)
                            .addComponent(lblMessage).addComponent(lblSuggested))
                    .addContainerGap(77, Short.MAX_VALUE))
                    .addGroup(gl_panel_1.createSequentialGroup().addComponent(btnModify)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnCancel)
                            .addContainerGap())
                    .addGroup(gl_panel_1.createSequentialGroup().addGroup(gl_panel_1
                            .createParallelGroup(Alignment.LEADING).addComponent(lblParameterSpace)
                            .addGroup(gl_panel_1.createSequentialGroup()
                                    .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
                                            .addComponent(rdbtnFixed).addComponent(rdbtnRange))
                                    .addGap(31)
                                    .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
                                            .addComponent(rdbtnByDistribution).addComponent(rdbtnByvalues)))
                            .addGroup(gl_panel_1.createSequentialGroup().addGroup(gl_panel_1
                                    .createParallelGroup(Alignment.TRAILING)
                                    .addGroup(gl_panel_1.createSequentialGroup().addComponent(lblValue)
                                            .addPreferredGap(ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                                            .addComponent(textFieldValue, GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                    .addGroup(Alignment.LEADING,
                                            gl_panel_1.createSequentialGroup().addComponent(lblStartValue)
                                                    .addPreferredGap(ComponentPlacement.RELATED, 46,
                                                            Short.MAX_VALUE)
                                                    .addComponent(textFieldStartValue,
                                                            GroupLayout.PREFERRED_SIZE,
                                                            GroupLayout.DEFAULT_SIZE,
                                                            GroupLayout.PREFERRED_SIZE))
                                    .addGroup(gl_panel_1.createSequentialGroup()
                                            .addComponent(lblCommaSeparatedList)
                                            .addPreferredGap(ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
                                            .addComponent(textFieldList, GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                    .addGroup(gl_panel_1.createSequentialGroup()
                                            .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
                                                    .addComponent(lblEndValue).addComponent(lblIncrement)
                                                    .addComponent(lblDistribution))
                                            .addGap(45)
                                            .addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING)
                                                    .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
                                                            .addGroup(gl_panel_1
                                                                    .createParallelGroup(Alignment.LEADING,
                                                                            false)
                                                                    .addComponent(jComboBoxDistribution, 0,
                                                                            GroupLayout.DEFAULT_SIZE,
                                                                            Short.MAX_VALUE)
                                                                    .addComponent(textFieldA,
                                                                            GroupLayout.PREFERRED_SIZE,
                                                                            GroupLayout.DEFAULT_SIZE,
                                                                            GroupLayout.PREFERRED_SIZE)
                                                                    .addComponent(textFieldB,
                                                                            GroupLayout.PREFERRED_SIZE,
                                                                            GroupLayout.DEFAULT_SIZE,
                                                                            GroupLayout.PREFERRED_SIZE)
                                                                    .addComponent(textFieldNumberOfValues,
                                                                            GroupLayout.PREFERRED_SIZE,
                                                                            GroupLayout.DEFAULT_SIZE,
                                                                            GroupLayout.PREFERRED_SIZE))
                                                            .addComponent(textFieldIncrement, 89, 89, 89))
                                                    .addComponent(textFieldEndValue, GroupLayout.PREFERRED_SIZE,
                                                            GroupLayout.DEFAULT_SIZE,
                                                            GroupLayout.PREFERRED_SIZE))))
                                    .addPreferredGap(ComponentPlacement.RELATED, 8, GroupLayout.PREFERRED_SIZE))
                            .addGroup(gl_panel_1.createSequentialGroup().addComponent(lblA).addPreferredGap(
                                    ComponentPlacement.RELATED, 173, GroupLayout.PREFERRED_SIZE))
                            .addGroup(gl_panel_1.createSequentialGroup().addComponent(lblB).addPreferredGap(
                                    ComponentPlacement.RELATED, 173, GroupLayout.PREFERRED_SIZE))
                            .addComponent(lblOfValues)
                            .addGroup(gl_panel_1.createSequentialGroup().addComponent(lblRuns)
                                    .addPreferredGap(ComponentPlacement.RELATED)
                                    .addComponent(textFieldRuns, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(ComponentPlacement.RELATED, 65,
                                            GroupLayout.PREFERRED_SIZE)))
                            .addGap(35))
                    .addGroup(gl_panel_1.createSequentialGroup().addComponent(lblDomain).addContainerGap(186,
                            Short.MAX_VALUE)))));
    gl_panel_1.setVerticalGroup(gl_panel_1.createParallelGroup(Alignment.LEADING).addGroup(gl_panel_1
            .createSequentialGroup().addGap(4).addComponent(lblMessage).addGap(18).addComponent(lblParamType)
            .addPreferredGap(ComponentPlacement.RELATED).addComponent(lblSuggested)
            .addPreferredGap(ComponentPlacement.RELATED).addComponent(lblDomain).addGap(7)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblRuns).addComponent(
                    textFieldRuns, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED).addComponent(lblParameterSpace)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(rdbtnFixed)
                    .addComponent(rdbtnByvalues))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(rdbtnRange)
                    .addComponent(rdbtnByDistribution))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
                    .addComponent(textFieldValue, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblValue))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
                    .addComponent(textFieldList, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCommaSeparatedList))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblStartValue)
                    .addComponent(textFieldStartValue, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblEndValue).addComponent(
                    textFieldEndValue, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
                    .addComponent(textFieldIncrement, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblIncrement))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
                    .addComponent(jComboBoxDistribution, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDistribution))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(gl_panel_1
                    .createParallelGroup(Alignment.BASELINE).addComponent(lblA).addComponent(textFieldA,
                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(gl_panel_1
                    .createParallelGroup(Alignment.BASELINE).addComponent(lblB).addComponent(textFieldB,
                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE).addComponent(lblOfValues).addComponent(
                    textFieldNumberOfValues, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED, 18, Short.MAX_VALUE).addGroup(gl_panel_1
                    .createParallelGroup(Alignment.BASELINE).addComponent(btnModify).addComponent(btnCancel))));
    panel_1.setLayout(gl_panel_1);
    panel.setLayout(gl_panel);

    setModifyControlEnable(false);
    loadDistribution();
}

From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java

/**
 * //from   w ww  . j  av a2 s.c  om
 */
private void createNavigationTree() {
    TreeSelectionListener tsl = new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent tse) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

            if (node == null || !(node.getUserObject() instanceof DataModelObjBaseWrapper)) {
                // Nothing is selected or object type isn't relevant
                clearPanels();
                return;
            }

            // ask if user he wants to discard changes if that's the case
            if (!aboutToShutdown()) {
                clearPanels();
                return;
            }

            DataModelObjBaseWrapper dataWrp = (DataModelObjBaseWrapper) (node.getUserObject());

            // get parent if it is a user
            /*DataModelObjBaseWrapper userObjWrp    = null;
            DataModelObjBaseWrapper groupObjWrp   = null;
            DataModelObjBaseWrapper collectionWrp = null;
            Object                  dataObj     = dataWrp.getDataObj();
            if (dataObj instanceof SpecifyUser)
            {
            // XXX Also might need to check to see if anyone is logged into the Group
            // when editing a Group
            SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
            SpecifyUser spUser      = (SpecifyUser)dataObj;
                    
            if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId()))
            {
                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                userObjWrp    = (DataModelObjBaseWrapper) node.getUserObject();
                groupObjWrp   = (DataModelObjBaseWrapper) parent.getUserObject();
                collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode)parent.getParent()).getUserObject();
                        
            } else
            {
                UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName());
                        
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run()
                    {
                        tree.clearSelection();
                    }
                });
                return;
            }
            }
                    
            nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class);
            nodesDivision   = nodesDiscipline != null ? nodesDiscipline.getDivision() : null;
            showInfoPanel(dataWrp, userObjWrp, groupObjWrp, collectionWrp, node.toString());
            updateUIEnabled(dataWrp);*/

            // get parent if it is a user
            DataModelObjBaseWrapper secondObjWrp = null;
            DataModelObjBaseWrapper collectionWrp = null;
            Object dataObj = dataWrp.getDataObj();
            if (dataObj instanceof SpecifyUser) {
                // XXX Also might need to check to see if anyone is logged into the Group
                // when editing a Group
                SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
                SpecifyUser spUser = (SpecifyUser) dataObj;

                if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId())) {
                    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                    secondObjWrp = (DataModelObjBaseWrapper) parent.getUserObject();
                    collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode) parent.getParent())
                            .getUserObject();
                } else {
                    UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName());

                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            tree.clearSelection();
                        }
                    });
                    return;
                }
            }

            nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class);
            nodesDivision = nodesDiscipline != null ? nodesDiscipline.getDivision() : null;
            showInfoPanel(dataWrp, secondObjWrp, collectionWrp, node.toString());
            updateUIEnabled(dataWrp);
        }
    };

    DefaultTreeModel model = createNavigationTreeModel();
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setRootVisible(false);
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.addTreeSelectionListener(tsl);

    // Expand the tree
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }

    for (int i = tree.getRowCount() - 1; i >= 1; i--) {
        if (tree.getPathForRow(i).getPathCount() > 3) {
            tree.collapseRow(i);
        }
    }

    navTreeMgr = new NavigationTreeMgr(tree, spUsers);

    // create object that will control the creation of popups
    // constructor will take care of hooking up right listeners to the tree.
    navTreeContextMgr = new NavigationTreeContextMenuMgr(navTreeMgr);

    IconManager.IconSize iconSize = IconManager.IconSize.Std20;
    ImageIcon sysIcon = IconManager.getIcon("SystemSetup", iconSize);
    JLabel label = createLabel("XXXX");

    label.setIcon(sysIcon);
    label.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));

    tree.setRowHeight(label.getPreferredSize().height);

    // Why doesn't this work?
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            tree.expandRow(1);
        }
    });

    //expandAll(tree, true);
}

From source file:net.sf.taverna.t2.workbench.views.results.workflow.RenderedResultComponent.java

/**
 * Update the component based on the node selected from the
 * ResultViewComponent tree./*ww  w  .jav  a 2 s. c o  m*/
 */
public void updateResult() {
    if (recognisedRenderersForMimeType == null)
        recognisedRenderersForMimeType = new ArrayList<>();
    if (otherRenderers == null)
        otherRenderers = new ArrayList<>();

    // Enable the combo box
    renderersComboBox.setEnabled(true);

    /*
     * Update the 'save result' buttons appropriately as the result node had
     * changed
     */
    for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) {
        JButton saveButton = (JButton) saveButtonsPanel.getComponent(i);
        SaveIndividualResultSPI action = (SaveIndividualResultSPI) saveButton.getAction();
        // Update the action with the new result reference
        action.setResultReference(path);
        saveButton.setEnabled(true);
    }

    if (DataBundles.isValue(path) || DataBundles.isReference(path)) {
        // Enable refresh button
        refreshButton.setEnabled(true);

        List<MimeType> mimeTypes = new ArrayList<>();
        try (InputStream inputstream = getInputStream(path)) {
            mimeTypes.addAll(getMimeTypes(inputstream));
        } catch (IOException e) {
            logger.warn("Error getting mimetype", e);
        }

        if (mimeTypes.isEmpty())
            // If MIME types is empty - add "plain/text" MIME type
            mimeTypes.add(new MimeType("text/plain"));
        else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) {
            /*
             * If MIME type is recognised as "chemical/x-fasta" only then
             * this might be an error from MIME magic (i.e., sometimes it
             * recognises stuff that is not "chemical/x-fasta" as
             * "chemical/x-fasta" and then Seq Vista renderer is used that
             * causes errors) - make sure we also add the renderers for
             * "text/plain" and "text/xml" as it is most probably just
             * normal xml text and push the "chemical/x-fasta" to the bottom
             * of the list.
             */
            mimeTypes.add(0, new MimeType("text/plain"));
            mimeTypes.add(1, new MimeType("text/xml"));
        }

        for (MimeType mimeType : mimeTypes) {
            List<Renderer> renderersList = rendererRegistry.getRenderersForMimeType(mimeType.toString());
            for (Renderer renderer : renderersList)
                if (!recognisedRenderersForMimeType.contains(renderer))
                    recognisedRenderersForMimeType.add(renderer);
        }
        // if there are no renderers then force text/plain
        if (recognisedRenderersForMimeType.isEmpty())
            recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain");

        /*
         * Add all other available renderers that are not recognised to be
         * able to handle the MIME type of the result
         */
        otherRenderers = new ArrayList<>(rendererRegistry.getRenderers());
        otherRenderers.removeAll(recognisedRenderersForMimeType);

        mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()];
        rendererList = new ArrayList<>();

        /*
         * First add the ones that can handle the MIME type of the result
         * item
         */
        for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) {
            mimeList[i] = recognisedRenderersForMimeType.get(i).getType();
            rendererList.add(recognisedRenderersForMimeType.get(i));
        }
        // Then add the other renderers just in case
        for (int i = 0; i < otherRenderers.size(); i++) {
            mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType();
            rendererList.add(otherRenderers.get(i));
        }

        renderersComboBox.setModel(new DefaultComboBoxModel<String>(mimeList));

        if (mimeList.length > 0) {
            int index = 0;

            // Find the index of the current MIME type for this output port.
            for (int i = 0; i < mimeList.length; i++)
                if (mimeList[i].equals(lastUsedMIMEtype)) {
                    index = i;
                    break;
                }

            int previousindex = renderersComboBox.getSelectedIndex();
            renderersComboBox.setSelectedIndex(index);
            /*
             * force rendering as setSelectedIndex will not fire an
             * itemstatechanged event if previousindex == index and we still
             * need render the result as we may have switched from a
             * different result item in a result list but the renderer index
             * stayed the same
             */
            if (previousindex == index)
                renderResult(); // draw the rendered result component
        }

    } else if (DataBundles.isError(path)) {
        // Disable refresh button
        refreshButton.setEnabled(false);

        // Hide wrap text check box - only works for actual data
        wrapTextCheckBox.setVisible(false);

        // Reset the renderers as we have an error item
        recognisedRenderersForMimeType = null;
        otherRenderers = null;

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace");

        try {
            ErrorDocument errorDocument = DataBundles.getError(path);
            try {
                buildErrorDocumentTree(root, errorDocument);
            } catch (IOException e) {
                logger.warn("Error building error document tree", e);
            }
        } catch (IOException e) {
            logger.warn("Error getting the error document", e);
        }

        JTree errorTree = new JTree(root);
        errorTree.setCellRenderer(new DefaultTreeCellRenderer() {
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                    boolean expanded, boolean leaf, int row, boolean hasFocus) {
                Component renderer = null;
                if (value instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
                    Object userObject = treeNode.getUserObject();
                    if (userObject instanceof ErrorDocument)
                        renderer = renderErrorDocument(tree, selected, expanded, leaf, row, hasFocus,
                                (ErrorDocument) userObject);
                }
                if (renderer == null)
                    renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                            hasFocus);
                if (renderer instanceof JLabel) {
                    JLabel label = (JLabel) renderer;
                    label.setIcon(null);
                }
                return renderer;
            }

            private Component renderErrorDocument(JTree tree, boolean selected, boolean expanded, boolean leaf,
                    int row, boolean hasFocus, ErrorDocument errorDocument) {
                return super.getTreeCellRendererComponent(tree,
                        "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf,
                        row, hasFocus);
            }
        });

        renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT }));
        renderedResultPanel.removeAll();
        renderedResultPanel.add(errorTree, CENTER);
        repaint();
    }
}

From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java

/** This method is called from within the constructor to
 * initialize the form./* w w w .  j ava 2  s.c  om*/
 */
private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jClearButton = new javax.swing.JButton();
    jConstrainButton = new javax.swing.JButton();
    jExcludeButton = new javax.swing.JButton();
    jOccurrenceButton = new javax.swing.JButton();
    jNameLabel = new javax.swing.JLabel();

    setLayout(null);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    tmpData.name("working ......");
    tmpData.tooltip("A root node");
    tmpData.visualAttribute("FAO");
    top = new DefaultMutableTreeNode(tmpData);
    //top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    //treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(true);
    //jTree1.getSelectionModel().setSelectionMode
    //        (TreeSelectionModel.SINGLE_TREE_SELECTION);
    //jTree1.setShowsRootHandles(true);
    //JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    setBorder(javax.swing.BorderFactory.createEtchedBorder());
    add(jScrollPane1);
    //jScrollPane1.setBounds(0, 40, 180, 200);

    jClearButton.setFont(new java.awt.Font("Tahoma", 1, 11));
    jClearButton.setText("X");
    jClearButton.setToolTipText("Clear all items from panel");
    jClearButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jClearButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
    jClearButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    jClearButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jClearButtonActionPerformed(evt);
        }
    });

    add(jClearButton);
    jClearButton.setBounds(160, 0, 18, 20);

    jConstrainButton.setText("Dates");
    jConstrainButton.setToolTipText("Constrain group by dates");
    jConstrainButton.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
    jConstrainButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    jConstrainButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jConstrainButtonActionPerformed(evt);
        }
    });

    add(jConstrainButton);
    jConstrainButton.setBounds(0, 20, 40, 21);

    jOccurrenceButton.setText("Occurs > 0x");
    jOccurrenceButton.setToolTipText("Set occurrence times");
    jOccurrenceButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jOccurrenceButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jOccurrenceButton.setMargin(new java.awt.Insets(6, 6, 6, 6));
    jOccurrenceButton.setIconTextGap(0);
    jOccurrenceButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jOccurrenceButtonActionPerformed(evt);
        }
    });
    add(jOccurrenceButton);
    jOccurrenceButton.setBounds(40, 20, 90, 21);

    //jExcludeButton.setMnemonic('E');
    jExcludeButton.setText("Exclude");
    jExcludeButton.setToolTipText("Exclude all items in group");
    jExcludeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jExcludeButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
    jExcludeButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jExcludeButtonActionPerformed(evt);
        }
    });

    add(jExcludeButton);
    jExcludeButton.setBounds(130, 20, 48, 21);
    jExcludeButton.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

    jNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jNameLabel.setText("Group 1");
    jNameLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    jNameLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    add(jNameLabel);
    jNameLabel.setBounds(0, 0, 160, 20);

    jTree1.addTreeExpansionListener(this);
    jTree1.setTransferHandler(new TextHandler());
    add(jScrollPane1);
    jScrollPane1.setViewportView(jTree1);
    //jTree1.setToolTipText("Double click on a folder to view the items inside");
    //jScrollPane1.getViewport().setToolTipText("Double click on a folder to view the items inside");
    jScrollPane1.setBounds(0, 40, 180, 160);
}

From source file:net.sf.taverna.t2.workbench.views.results.processor.RenderedProcessorResultComponent.java

/**
 * Update the component based on the node selected from the
 * ResultViewComponent tree./*from  ww w  . j  a v  a2 s  .c  om*/
 */
public void updateResult() {
    if (recognisedRenderersForMimeType == null)
        recognisedRenderersForMimeType = new ArrayList<>();
    if (otherRenderers == null)
        otherRenderers = new ArrayList<>();

    ProcessorResultTreeNode result = (ProcessorResultTreeNode) node;

    // Reference to the result data
    path = result.getReference();

    // Enable the combo box
    renderersComboBox.setEnabled(true);

    /*
     * Update the 'save result' buttons appropriately as the result node had
     * changed
     */
    for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) {
        JButton saveButton = (JButton) saveButtonsPanel.getComponent(i);
        SaveIndividualResultSPI action = (SaveIndividualResultSPI) (saveButton.getAction());
        // Update the action with the new result reference
        action.setResultReference(path);
        saveButton.setEnabled(true);
    }

    if (DataBundles.isValue(path) || DataBundles.isReference(path)) {
        // Enable refresh button
        refreshButton.setEnabled(true);

        List<MimeType> mimeTypes = new ArrayList<>();
        try (InputStream inputstream = RendererUtils.getInputStream(path)) {
            mimeTypes.addAll(getMimeTypes(inputstream));
        } catch (IOException e) {
            logger.warn("Error getting mimetype", e);
        }

        if (mimeTypes.isEmpty()) {
            // If MIME types is empty - add "plain/text" MIME type
            mimeTypes.add(new MimeType("text/plain"));
        } else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) {
            /*
             * If MIME type is recognised as "chemical/x-fasta" only then
             * this might be an error from MIME magic (i.e., sometimes it
             * recognises stuff that is not "chemical/x-fasta" as
             * "chemical/x-fasta" and then Seq Vista renderer is used that
             * causes errors) - make sure we also add the renderers for
             * "text/plain" and "text/xml" as it is most probably just
             * normal xml text and push the "chemical/x-fasta" to the bottom
             * of the list.
             */
            mimeTypes.add(0, new MimeType("text/plain"));
            mimeTypes.add(1, new MimeType("text/xml"));
        }

        for (MimeType mimeType : mimeTypes)
            for (Renderer renderer : rendererRegistry.getRenderersForMimeType(mimeType.toString()))
                if (!recognisedRenderersForMimeType.contains(renderer))
                    recognisedRenderersForMimeType.add(renderer);
        // if there are no renderers then force text/plain
        if (recognisedRenderersForMimeType.isEmpty())
            recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain");

        /*
         * Add all other available renderers that are not recognised to be
         * able to handle the MIME type of the result
         */
        otherRenderers = rendererRegistry.getRenderers();
        otherRenderers.removeAll(recognisedRenderersForMimeType);

        mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()];
        rendererList = new ArrayList<>();

        /*
         * First add the ones that can handle the MIME type of the result
         * item
         */
        for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) {
            mimeList[i] = recognisedRenderersForMimeType.get(i).getType();
            rendererList.add(recognisedRenderersForMimeType.get(i));
        }
        // Then add the other renderers just in case
        for (int i = 0; i < otherRenderers.size(); i++) {
            mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType();
            rendererList.add(otherRenderers.get(i));
        }

        renderersComboBox.setModel(new DefaultComboBoxModel<>(mimeList));

        if (mimeList.length > 0) {
            int index = 0;

            // Find the index of the current MIME type for this output port.
            for (int i = 0; i < mimeList.length; i++)
                if (mimeList[i].equals(lastUsedMIMEtype)) {
                    index = i;
                    break;
                }

            int previousindex = renderersComboBox.getSelectedIndex();
            renderersComboBox.setSelectedIndex(index);
            /*
             * force rendering as setSelectedIndex will not fire an
             * itemstatechanged event if previousindex == index and we still
             * need render the result as we may have switched from a
             * different result item in a result list but the renderer index
             * stayed the same
             */
            if (previousindex == index)
                renderResult(); // draw the rendered result component
        }
    } else if (DataBundles.isError(path)) {
        // Disable refresh button
        refreshButton.setEnabled(false);

        @SuppressWarnings("unused")
        ErrorDocument errorDocument;
        try {
            errorDocument = DataBundles.getError(path);
        } catch (IOException e) {
            logger.warn("Error getting the error document", e);
        }

        // Reset the renderers as we have an error item
        recognisedRenderersForMimeType = null;
        otherRenderers = null;

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace");

        // TODO handle error documents
        // ResultsUtils.buildErrorDocumentTree(root, errorDocument, referenceService);

        JTree errorTree = new JTree(root);

        errorTree.setCellRenderer(new DefaultTreeCellRenderer() {
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                    boolean expanded, boolean leaf, int row, boolean hasFocus) {
                Component renderer = null;
                if (value instanceof DefaultMutableTreeNode) {
                    Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
                    if (userObject instanceof ErrorDocument)
                        renderer = getErrorDocumentRenderer(tree, selected, expanded, leaf, row, hasFocus,
                                (ErrorDocument) userObject);
                }
                if (renderer == null)
                    renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                            hasFocus);
                if (renderer instanceof JLabel) {
                    JLabel label = (JLabel) renderer;
                    label.setIcon(null);
                }
                return renderer;
            }

            private Component getErrorDocumentRenderer(JTree tree, boolean selected, boolean expanded,
                    boolean leaf, int row, boolean hasFocus, ErrorDocument errorDocument) {
                return super.getTreeCellRendererComponent(tree,
                        "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf,
                        row, hasFocus);
            }
        });

        renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT }));
        renderedResultPanel.removeAll();
        renderedResultPanel.add(errorTree, CENTER);
        repaint();
    }
}

From source file:uk.co.petertribble.jangle.SnmpTreePanel.java

private void buildUI() {
    for (SnmpObject sno : oidList) {
        model.addElement(sno);//from  w w w .j  av  a  2 s  .com
    }
    /*
     * We create a SnmpTreeNode for each element in the list and add it to
     * a Hash with the name as the key. Then we walk the list - if a node
     * has a parent, we add it to the parent, else we need to create
     * intermediate nodes to fill in the tree.
     */
    // root node
    SnmpTreeNode rootNode = new SnmpTreeNode("SNMP");
    // real nodes
    Map<String, SnmpTreeNode> m = new HashMap<String, SnmpTreeNode>();
    // intermediate nodes
    Map<String, SnmpTreeNode> m2 = new HashMap<String, SnmpTreeNode>();
    for (SnmpObject sno : oidList) {
        m.put(sno.toString(), new SnmpTreeNode(sno));
    }
    for (SnmpObject sno : oidList) {
        String s = sno.toString();
        SnmpTreeNode mynode = m.get(s);
        String parent = SnmpUtil.getParentOID(s);
        while (parent != null) {
            if (m.containsKey(parent)) {
                /*
                 * If there's a parent node, add this as a child.
                 * This almost never happens.
                 */
                m.get(parent).add(mynode);
                mynode = m.get(parent);
            } else if (m2.containsKey(parent)) {
                /*
                 * If we've already created a parent node, add this node
                 * to that.
                 */
                m2.get(parent).add(mynode);
                mynode = m2.get(parent);
            } else {
                /*
                 * Need to create a new node
                 */
                SnmpTreeNode pnode = new SnmpTreeNode(parent);
                pnode.add(mynode);
                m2.put(parent, pnode);
                mynode = pnode;
            }
            parent = SnmpUtil.getParentOID(parent);
        }
        rootNode.add(mynode);
    }
    if (stree == null) {
        stree = new JTree(rootNode);
        stree.addTreeSelectionListener(this);
        jtpl.add(SnmpResources.getString("SNMP.TREE.TEXT"), new JScrollPane(stree));
    } else {
        stree.setModel(new DefaultTreeModel(rootNode));
    }
}