Example usage for javax.swing.tree DefaultMutableTreeNode getParent

List of usage examples for javax.swing.tree DefaultMutableTreeNode getParent

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getParent.

Prototype

public TreeNode getParent() 

Source Link

Document

Returns this node's parent or null if this node has no parent.

Usage

From source file:dotaSoundEditor.Controls.EditorPanel.java

protected void revertButtonActionPerformed(ActionEvent evt, Path vpkToRevert) {
    //TODO: See if we can abstract away some of this functionality
    if (currentTree.getSelectionRows().length != 0
            && ((TreeNode) currentTree.getSelectionPath().getLastPathComponent()).isLeaf()) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) currentTree.getSelectionPath()
                .getLastPathComponent();
        String selectedWaveString = ((DefaultMutableTreeNode) selectedNode).getUserObject().toString();
        String selectedWaveParentString = ((DefaultMutableTreeNode) ((DefaultMutableTreeNode) selectedNode)
                .getParent()).getUserObject().toString();
        selectedNode = (DefaultMutableTreeNode) this.getTreeNodeFromWavePath(selectedWaveString);
        //First go in and delete the sound in customSounds
        deleteSoundFileByWaveString(selectedWaveString);
        //Get the relevant wavestring from the internal scriptfile
        VPKArchive vpk = new VPKArchive();
        try {/*from  w  ww  . jav  a  2s  . c  om*/
            vpk.load(new File(vpkToRevert.toString()));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        String scriptDir = getCurrentScriptString();
        scriptDir = scriptDir.replace(Paths.get(installDir, "/dota/").toString(), "");
        scriptDir = scriptDir.replace("\\", "/"); //Match internal forward slashes
        scriptDir = scriptDir.substring(1); //Cut off leading slash
        byte[] bytes = null;
        VPKEntry entry = vpk.getEntry(scriptDir);
        try {
            ByteBuffer scriptBuffer = entry.getData();
            bytes = new byte[scriptBuffer.remaining()];
            scriptBuffer.get(bytes);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        String scriptFileString = new String(bytes, Charset.forName("UTF-8"));
        ArrayList<String> wavePathList = this.getWavePathsAsList(selectedNode.getParent());
        int waveStringIndex = wavePathList.indexOf(selectedWaveString);
        //Cut off every part of the scriptFileString before we get to the entry describing the relevant hero action, so we don't accidentally get the wrong wavepaths
        StringBuilder scriptFileStringShortened = new StringBuilder();
        Scanner scan = new Scanner(scriptFileString);
        boolean found = false;
        while (scan.hasNextLine()) {
            String curLine = scan.nextLine();
            if (curLine.equals(selectedWaveParentString)) {
                found = true;
            }
            if (found == true) {
                scriptFileStringShortened.append(curLine).append(System.lineSeparator());
            }
        }
        scriptFileString = scriptFileStringShortened.toString();
        ArrayList<String> internalWavePathsList = getWavePathListFromString(scriptFileString);
        String replacementString = internalWavePathsList.get(waveStringIndex);
        selectedNode.setUserObject(replacementString);
        ScriptParser parser = new ScriptParser(this.currentTreeModel);
        parser.writeModelToFile(getCurrentScriptString());
        //Modify the UI treeNode in addition to the backing TreeNode
        ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(replacementString);
        ((DefaultTreeModel) currentTree.getModel())
                .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent());
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * search for dump root node of for given node
 *
 * @param node starting to search for//ww  w  .  j a  v  a  2 s .  co  m
 * @return root node returns null, if no root was found.
 */
private DefaultMutableTreeNode getDumpRootNode(DefaultMutableTreeNode node) {
    // search for starting node
    while (node != null && !(node.getUserObject() instanceof ThreadDumpInfo)) {
        node = (DefaultMutableTreeNode) node.getParent();
    }

    return (node);
}

From source file:com.pironet.tda.TDA.java

/**
 * load a loggc log file based on the current selected thread dump
 *//*from   w w w  .  j a v a 2  s.c o  m*/
private void parseLoggcLogfile() {
    DefaultMutableTreeNode node = getDumpRootNode((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    if (node == null) {
        return;
    }

    // get pos of this node in the thread dump hierarchy.
    int pos = node.getParent().getIndex(node);

    ((Logfile) ((DefaultMutableTreeNode) node.getParent()).getUserObject()).getUsedParser()
            .setDumpHistogramCounter(pos);
    openLoggcFile();
}

From source file:com.pironet.tda.TDA.java

/**
 * get the dump with the given name, starting from the provided node.
 *//*from  w w w  .j  av  a2  s  .  c o  m*/
private DefaultMutableTreeNode getDumpRootNode(String dumpName, DefaultMutableTreeNode node) {
    DefaultMutableTreeNode lastNode = null;
    // search for starting node
    while (node != null && !(node.getUserObject() instanceof Logfile)) {
        lastNode = node;
        node = (DefaultMutableTreeNode) node.getParent();
    }

    if (node == null) {
        node = lastNode;
    }

    DefaultMutableTreeNode dumpNode = null;
    if (node != null) {
        for (int i = 0; i < node.getChildCount(); i++) {
            Object userObject = ((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject();
            if ((userObject instanceof ThreadDumpInfo)
                    && ((ThreadDumpInfo) userObject).getName().startsWith(dumpName)) {
                dumpNode = (DefaultMutableTreeNode) node.getChildAt(i);
                break;
            }
        }
    }

    return (dumpNode);
}

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

/**
 * Create the frame.//w ww.java  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:Creator.WidgetPanel.java

private void _JTree_WidgetLinksValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event__JTree_WidgetLinksValueChanged

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) _JTree_WidgetLinks.getLastSelectedPathComponent();

    if (node == null) //Nothing is selected.  
    {//ww  w. ja va2  s  .com
        return;
    }

    if (node.getParent() != null) {
        String s = node.getParent().toString() + "-" + node.getUserObject().toString();

        if (ws.containsKey(s)) {
            WidgetLink wl = ws.get(s);
            //System.out.println(wl); 

            // Select the Widget, IO name
            _ComboBox_Subgroup.setSelectedItem(wl.getSubGroup());

            String panelName = node.getParent().toString();

            if (panelName.startsWith("Rack")) {
                _ComboBox_DisplayPanel.setSelectedIndex(1);
            } /*else if (panelName.startsWith("Load")) {
              _ComboBox_DisplayPanel.setSelectedIndex(1 + cs.getNumRacks());
              } */else {
                _ComboBox_DisplayPanel.setSelectedItem(panelName);
            }

            int sel = _List_WidgetCodeList.getSelectedIndex();
            _List_WidgetCodeList.setSelectedIndex(sel >= 1 ? 0 : 1); // This will allow the next line to trigger the value changed field
            _List_WidgetCodeList.setSelectedValue(wl.getWidgetCodeName(), true);
            _List_WidgetVars.setSelectedValue(node.getUserObject().toString(), true);
            _FTF_WigetParam_xPosPer.setValue(wl.getPositionPercentage().getX());
            _FTF_WigetParam_yPosPer.setValue(wl.getPositionPercentage().getY());

        }

    }

}

From source file:Creator.WidgetPanel.java

private void _List_WidgetCodeListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event__List_WidgetCodeListValueChanged

    // _ScrollPane_WidgetSettings
    if (!evt.getValueIsAdjusting()) {

        // Load the variables of the widget
        String widgetCodeStr;//from   w  w  w .  ja  v a 2  s.  c  o m
        WidgetCode wc = null;
        WidgetLink wl = null;
        if (!_JTree_WidgetLinks.isSelectionEmpty()) {

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) _JTree_WidgetLinks
                    .getLastSelectedPathComponent();

            if (node == null) //Nothing is selected.  
            {
                return;
            }

            if (node.getParent() != null) {
                String s = node.getParent().toString() + "-" + node.getUserObject().toString();

                if (ws.containsKey(s)) {
                    wl = ws.get(s);
                    wc = widgetList.get(wl.getWidgetCodeName());
                }
            }
        }

        if (wc == null) {
            // No selected item on the JTree
            widgetCodeStr = _List_WidgetCodeList.getSelectedValue().toString();
            wc = widgetList.get(widgetCodeStr);
        } else {

            // Make sure the item selected matches the code in the widget link
            // This makes selecting 
            if (!wc.getWidgetName().equals(_List_WidgetCodeList.getSelectedValue().toString())) {

                widgetCodeStr = _List_WidgetCodeList.getSelectedValue().toString();
                wc = widgetList.get(widgetCodeStr);
            }

        }

        GridBagLayout gbl = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 1;
        c.weighty = 0;
        c.gridwidth = 1;
        c.gridheight = 1;
        c.ipadx = 0;
        c.ipady = 5;

        if (widgetCodeSettings == null) {
            widgetCodeSettings = new HashMap<>();
        } else {
            widgetCodeSettings.clear();
        }

        _Panel_WidgetSettings.removeAll();
        _Panel_WidgetSettings.setLayout(gbl);

        for (String name : wc.getVariables()) {
            JLabel label = new JLabel(name);
            label.setFont(new Font("Arial", Font.BOLD, 13));
            label.setHorizontalAlignment(SwingConstants.CENTER);
            JTextField textfield = new JTextField("");
            textfield.setHorizontalAlignment(SwingConstants.CENTER);
            if (wl != null) {
                textfield.setText(wl.getVariables().get(name));
            }

            textfield.setFont(new Font("Arial", Font.BOLD, 15));

            widgetCodeSettings.put(label.getText(), textfield);
            _Panel_WidgetSettings.add(label, c);
            c.gridy += 1;
            _Panel_WidgetSettings.add(textfield, c);
            c.gridy += 1;
        }

        _ScrollPane_WidgetSettings.revalidate();
        _ScrollPane_WidgetSettings.repaint();

    }

}

From source file:StAXEventTreeViewer.java

public void buildTree(DefaultTreeModel treeModel, DefaultMutableTreeNode current, File file)
        throws XMLStreamException, FileNotFoundException {

    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(file));
    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        switch (event.getEventType()) {
        case XMLStreamConstants.START_DOCUMENT:
            StartDocument startDocument = (StartDocument) event;
            DefaultMutableTreeNode version = new DefaultMutableTreeNode(startDocument.getVersion());
            current.add(version);/* www.  ja  v  a  2 s  .  com*/

            current.add(new DefaultMutableTreeNode(startDocument.isStandalone()));
            current.add(new DefaultMutableTreeNode(startDocument.standaloneSet()));
            current.add(new DefaultMutableTreeNode(startDocument.encodingSet()));
            current.add(new DefaultMutableTreeNode(startDocument.getCharacterEncodingScheme()));
            break;
        case XMLStreamConstants.START_ELEMENT:
            StartElement startElement = (StartElement) event;
            QName elementName = startElement.getName();

            DefaultMutableTreeNode element = new DefaultMutableTreeNode(elementName.getLocalPart());
            current.add(element);
            current = element;

            if (!elementName.getNamespaceURI().equals("")) {
                String prefix = elementName.getPrefix();
                if (prefix.equals("")) {
                    prefix = "[None]";
                }
                DefaultMutableTreeNode namespace = new DefaultMutableTreeNode(
                        "prefix=" + prefix + ",URI=" + elementName.getNamespaceURI());
                current.add(namespace);
            }

            for (Iterator it = startElement.getAttributes(); it.hasNext();) {
                Attribute attr = (Attribute) it.next();
                DefaultMutableTreeNode attribute = new DefaultMutableTreeNode("Attribute (name="
                        + attr.getName().getLocalPart() + ",value=" + attr.getValue() + "')");
                String attURI = attr.getName().getNamespaceURI();
                if (!attURI.equals("")) {
                    String attPrefix = attr.getName().getPrefix();
                    if (attPrefix.equals("")) {
                        attPrefix = "[None]";
                    }
                    attribute.add(new DefaultMutableTreeNode("prefix = " + attPrefix + ", URI = " + attURI));
                }
                current.add(attribute);
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            current = (DefaultMutableTreeNode) current.getParent();
            break;
        case XMLStreamConstants.CHARACTERS:
            Characters characters = (Characters) event;
            if (!characters.isIgnorableWhiteSpace() && !characters.isWhiteSpace()) {
                String data = characters.getData();
                if (data.length() != 0) {
                    current.add(new DefaultMutableTreeNode(characters.getData()));
                }
            }
            break;
        case XMLStreamConstants.DTD:
            DTD dtde = (DTD) event;
            current.add(new DefaultMutableTreeNode(dtde.getDocumentTypeDeclaration()));
        default:
            System.out.println(event.getClass().getName());
        }
    }
}

From source file:GUI.MainWindow.java

private void doDelete() {

    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    TreePath[] paths = VulnTree.getSelectionPaths();

    if (paths == null) {
        return;/* www .j  av  a2  s.c  om*/
    }

    for (int i = 0; i < paths.length; i++) {
        TreePath path = paths[i];
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (i == 0) {
            // This is the first delete operation
            DefaultMutableTreeNode previous = (DefaultMutableTreeNode) node.getPreviousSibling();
            // Consider saving deleted vulns into a scratchpad file TODO
            //System.out.println("previous:" + previous);

            // If it is null here we have no nodes above it, we get the next sibling below
            if (previous == null) {
                previous = (DefaultMutableTreeNode) node.getNextSibling();
            }

            // If it is still null here there are no nodes in the tree. Point to the root. Avoids NullPointerException
            if (previous == null) {
                previous = root;
            }

            TreePath p = new TreePath(previous.getPath());
            VulnTree.setSelectionPath(p);
        }

        if (node.getParent() != null) {
            dtm.removeNodeFromParent(node);
        }
    }

    if (root.getChildCount() == 0) {
        clearGUI();
    }

}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void saveSubTree(@SuppressWarnings("rawtypes") final Enumeration children,
        final List<Parameter> parameterList, final List<SubmodelParameter> submodelParameterList,
        final Set<ParameterInfo> invalids) throws IOException {

    final ObjectFactory factory = new ObjectFactory();
    while (children.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();

        @SuppressWarnings("unchecked")
        final Pair<ParameterInfo, JComponent> userData = (Pair<ParameterInfo, JComponent>) node.getUserObject();
        final ParameterInfo parameterInfo = userData.getFirst();
        final JComponent valueContainer = userData.getSecond();

        Parameter parameter = null;
        SubmodelParameter submodelParameter = null;
        if (parameterInfo instanceof ISubmodelGUIInfo) {
            final ISubmodelGUIInfo sgi = (ISubmodelGUIInfo) parameterInfo;
            if (sgi.getParent() != null) {
                final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                @SuppressWarnings("unchecked")
                final Pair<ParameterInfo, JComponent> parentUserData = (Pair<ParameterInfo, JComponent>) parentNode
                        .getUserObject();
                final SubmodelInfo parentParameterInfo = (SubmodelInfo) parentUserData.getFirst();
                if (invalids.contains(parentParameterInfo)
                        || !classEquals(parentParameterInfo.getActualType(), sgi.getParentValue())) {
                    invalids.add(parameterInfo);
                    continue;
                }/*www . j a v a  2 s  .  c o m*/
            }
        }

        if (parameterInfo instanceof SubmodelInfo) {
            submodelParameter = factory.createSubmodelParameter();
            submodelParameter.setName(parameterInfo.getName());
        } else {
            parameter = factory.createParameter();
            parameter.setName(parameterInfo.getName());
        }

        if (parameterInfo.isBoolean()) {
            final JCheckBox checkBox = (JCheckBox) valueContainer;
            parameter.getContent().add(String.valueOf(checkBox.isSelected()));
        } else if (parameterInfo.isEnum()) {
            final JComboBox comboBox = (JComboBox) valueContainer;
            parameter.getContent().add(String.valueOf(comboBox.getSelectedItem()));
        } else if (parameterInfo instanceof MasonChooserParameterInfo) {
            final JComboBox comboBox = (JComboBox) valueContainer;
            parameter.getContent().add(String.valueOf(comboBox.getSelectedIndex()));
        } else if (parameterInfo instanceof SubmodelInfo) {
            final JComboBox comboBox = (JComboBox) ((JPanel) valueContainer).getComponent(0);
            final ClassElement selectedElement = (ClassElement) comboBox.getSelectedItem();

            if (selectedElement.clazz == null)
                throw new IOException("No type is selected for parameter "
                        + parameterInfo.getName().replaceAll("([A-Z])", " $1") + ".");

            submodelParameter.setType(selectedElement.clazz.getName());
            saveSubTree(node.children(), submodelParameter.getParameterList(),
                    submodelParameter.getSubmodelParameterList(), invalids);
        } else if (parameterInfo.isFile()) {
            final JTextField textField = (JTextField) valueContainer.getComponent(0);
            parameter.getContent().add(textField.getToolTipText());
        } else if (parameterInfo instanceof MasonIntervalParameterInfo) {
            final JTextField textField = (JTextField) valueContainer.getComponent(0);
            parameter.getContent().add(textField.getText().trim());
        } else {
            final JTextField textField = (JTextField) valueContainer;
            String text = String.valueOf(ParameterInfo.getValue(textField.getText(), parameterInfo.getType()));
            if ("String".equals(parameterInfo.getType()) && parameterInfo.getValue() == null)
                text = textField.getText().trim();
            parameter.getContent().add(text);
        }

        if (parameter != null)
            parameterList.add(parameter);
        else if (submodelParameter != null)
            submodelParameterList.add(submodelParameter);
    }
}