List of usage examples for javax.swing JTree expandPath
public void expandPath(TreePath path)
From source file:eu.europa.esig.dss.applet.view.validationpolicy.EditView.java
private void nodeActionAdd(MouseEvent mouseEvent, final int selectedRow, final TreePath selectedPath, final XmlDomAdapterNode clickedItem, final JTree tree) { final Element clickedElement = (Element) clickedItem.node; // popup menu for list -> add final JPopupMenu popup = new JPopupMenu(); //delete node final JMenuItem menuItemToDelete = new JMenuItem(ResourceUtils.getI18n("DELETE")); menuItemToDelete.addActionListener(new ActionListener() { @Override//w w w .j ava 2s . c o m public void actionPerformed(ActionEvent actionEvent) { // find the order# of the child to delete final int index = clickedItem.getParent().index(clickedItem); Node oldChild = clickedElement.getParentNode().removeChild(clickedElement); if (index > -1) { validationPolicyTreeModel.fireTreeNodesRemoved(selectedPath.getParentPath(), index, oldChild); } } }); popup.add(menuItemToDelete); //Add node/value final Map<XsdNode, Object> xsdTree = validationPolicyTreeModel.getXsdTree(); final List<XsdNode> children = getChildrenToAdd(clickedElement, xsdTree); for (final XsdNode xsdChild : children) { final String xmlName = xsdChild.getLastNameOfPath(); final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("ADD") + " (" + xmlName + " " + xsdChild.getType().toString().toLowerCase() + ")"); popup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Document document = getModel().getValidationPolicy().getDocument(); final Node newElement; if (xsdChild.getType() == XsdNodeType.TEXT) { // TEXT element always appended (last child) newElement = clickedElement.appendChild(document.createTextNode("VALUE")); } else if (xsdChild.getType() == XsdNodeType.ATTRIBUTE) { newElement = document.createAttributeNS(null, xmlName); ((Attr) newElement).setValue("VALUE"); clickedElement.setAttributeNode((Attr) newElement); } else if (xsdChild.getType() == XsdNodeType.ELEMENT) { final Element childToAdd = document .createElementNS("http://dss.esig.europa.eu/validation/diagnostic", xmlName); // find the correct possition to add the child // Get all allowed children Map<XsdNode, Object> childrenMap = getChild(getXPath(clickedElement), xsdTree); boolean toAddSeen = false; Element elementIsToAddBeforeThisOne = null; for (final XsdNode allowed : childrenMap.keySet()) { if (!toAddSeen && (allowed == xsdChild)) { toAddSeen = true; continue; } if (toAddSeen) { final NodeList elementsByTagNameNS = clickedElement.getElementsByTagNameNS( "http://dss.esig.europa.eu/validation/diagnostic", allowed.getLastNameOfPath()); if (elementsByTagNameNS.getLength() > 0) { // we found an element that is supposed to be after the one to add elementIsToAddBeforeThisOne = (Element) elementsByTagNameNS.item(0); break; } } } if (elementIsToAddBeforeThisOne != null) { newElement = clickedElement.insertBefore(childToAdd, elementIsToAddBeforeThisOne); } else { newElement = clickedElement.appendChild(childToAdd); } } else { throw new IllegalArgumentException("Unknow XsdNode NodeType " + xsdChild.getType()); } document.normalizeDocument(); int indexOfAddedItem = 0; final int childCount = clickedItem.childCount(); for (int i = 0; i < childCount; i++) { if (clickedItem.child(i).node == newElement) { indexOfAddedItem = i; break; } } TreeModelEvent event = new TreeModelEvent(validationPolicyTreeModel, selectedPath, new int[] { indexOfAddedItem }, new Object[] { newElement }); validationPolicyTreeModel.fireTreeNodesInserted(event); tree.expandPath(selectedPath); //Update model getModel().getValidationPolicy().setXmlDom(new XmlDom(document)); } }); } popup.show(tree, mouseEvent.getX(), mouseEvent.getY()); }
From source file:it.isislab.dmason.tools.batch.BatchWizard.java
/** * Create the frame.// w w w . j a v a 2 s.co 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:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private JPanel createAParameterBox(final boolean first) { final JLabel runLabel = new JLabel("<html><b>Number of runs:</b> 0</html>"); final JLabel warningLabel = new JLabel(); final JButton closeButton = new JButton(); closeButton.setOpaque(false);/*from w w w .j a va 2 s . c o m*/ closeButton.setBorder(null); closeButton.setFocusable(false); if (!first) { closeButton.setRolloverIcon(PARAMETER_BOX_REMOVE); closeButton.setRolloverEnabled(true); closeButton.setIcon(RGBGrayFilter.getDisabledIcon(closeButton, PARAMETER_BOX_REMOVE)); closeButton.setActionCommand(ACTIONCOMMAND_REMOVE_BOX); } final JScrollPane treeScrPane = new JScrollPane(); final DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(); final JTree tree = new JTree(treeRoot); ToolTipManager.sharedInstance().registerComponent(tree); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer(new ParameterBoxTreeRenderer()); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(final TreeSelectionEvent e) { final TreePath selectionPath = tree.getSelectionPath(); boolean success = true; if (editedNode != null && (selectionPath == null || !editedNode.equals(selectionPath.getLastPathComponent()))) success = modify(); if (success) { if (selectionPath != null) { cancelAllSelectionBut(tree); final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); if (!node.equals(editedNode)) { ParameterInATree userObj = null; final DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); if (!node.isRoot() && selectionPath.getPathCount() == model.getPathToRoot(node).length) { userObj = (ParameterInATree) node.getUserObject(); final ParameterInfo info = userObj.info; editedNode = node; editedTree = tree; edit(info); } else { tree.setSelectionPath(null); if (cancelButton.isEnabled()) cancelButton.doClick(); resetSettings(); enableDisableSettings(false); editedNode = null; editedTree = null; } updateDescriptionField(userObj); } else updateDescriptionField(); } else updateDescriptionField(); enableDisableParameterCombinationButtons(); } else { final DefaultTreeModel model = (DefaultTreeModel) editedTree.getModel(); final DefaultMutableTreeNode storedEditedNode = editedNode; editedNode = null; tree.setSelectionPath(null); editedNode = storedEditedNode; editedTree.setSelectionPath(new TreePath(model.getPathToRoot(editedNode))); } } }); treeScrPane.setViewportView(tree); treeScrPane.setBorder(null); treeScrPane.setViewportBorder(null); treeScrPane.setPreferredSize(new Dimension(450, 250)); final JButton upButton = new JButton(); upButton.setOpaque(false); upButton.setRolloverEnabled(true); upButton.setIcon(PARAMETER_UP_ICON); upButton.setRolloverIcon(PARAMETER_UP_ICON_RO); upButton.setDisabledIcon(PARAMETER_UP_ICON_DIS); upButton.setBorder(null); upButton.setToolTipText("Move up the selected parameter"); upButton.setActionCommand(ACTIONCOMMAND_MOVE_UP); final JButton downButton = new JButton(); downButton.setOpaque(false); downButton.setRolloverEnabled(true); downButton.setIcon(PARAMETER_DOWN_ICON); downButton.setRolloverIcon(PARAMETER_DOWN_ICON_RO); downButton.setDisabledIcon(PARAMETER_DOWN_ICON_DIS); downButton.setBorder(null); downButton.setToolTipText("Move down the selected parameter"); downButton.setActionCommand(ACTIONCOMMAND_MOVE_DOWN); final JPanel mainPanel = FormsUtils.build("~ f:p:g ~ p ~ r:p", "012||" + "333||" + "44_||" + "445||" + "446||" + "44_ f:p:g", runLabel, first ? "" : warningLabel, first ? warningLabel : closeButton, new FormsUtils.Separator(""), treeScrPane, upButton, downButton) .getPanel(); mainPanel.setBorder(BorderFactory.createTitledBorder("")); final JButton addButton = new JButton(); addButton.setOpaque(false); addButton.setRolloverEnabled(true); addButton.setIcon(PARAMETER_ADD_ICON); addButton.setRolloverIcon(PARAMETER_ADD_ICON_RO); addButton.setDisabledIcon(PARAMETER_ADD_ICON_DIS); addButton.setBorder(null); addButton.setToolTipText("Add selected parameter"); addButton.setActionCommand(ACTIONCOMMAND_ADD_PARAM); final JButton removeButton = new JButton(); removeButton.setOpaque(false); removeButton.setRolloverEnabled(true); removeButton.setIcon(PARAMETER_REMOVE_ICON); removeButton.setRolloverIcon(PARAMETER_REMOVE_ICON_RO); removeButton.setDisabledIcon(PARAMETER_REMOVE_ICON_DIS); removeButton.setBorder(null); removeButton.setToolTipText("Remove selected parameter"); removeButton.setActionCommand(ACTIONCOMMAND_REMOVE_PARAM); final JPanel result = FormsUtils.build("p ~ f:p:g", "_0 f:p:g||" + "10 p ||" + "20 p||" + "_0 f:p:g", mainPanel, addButton, removeButton).getPanel(); Style.registerCssClasses(result, Dashboard.CSS_CLASS_COMMON_PANEL); final ParameterCombinationGUI pcGUI = new ParameterCombinationGUI(tree, treeRoot, runLabel, warningLabel, addButton, removeButton, upButton, downButton); parameterTreeBranches.add(pcGUI); final ActionListener boxActionListener = new ActionListener() { //==================================================================================================== // methods //---------------------------------------------------------------------------------------------------- public void actionPerformed(final ActionEvent e) { final String cmd = e.getActionCommand(); if (ACTIONCOMMAND_ADD_PARAM.equals(cmd)) handleAddParameter(pcGUI); else if (ACTIONCOMMAND_REMOVE_PARAM.equals(cmd)) handleRemoveParameter(tree); else if (ACTIONCOMMAND_REMOVE_BOX.equals(cmd)) handleRemoveBox(tree); else if (ACTIONCOMMAND_MOVE_UP.equals(cmd)) handleMoveUp(); else if (ACTIONCOMMAND_MOVE_DOWN.equals(cmd)) handleMoveDown(); } //---------------------------------------------------------------------------------------------------- private void handleAddParameter(final ParameterCombinationGUI pcGUI) { final Object[] selectedValues = parameterList.getSelectedValues(); if (selectedValues != null && selectedValues.length > 0) { final AvailableParameter[] params = new AvailableParameter[selectedValues.length]; System.arraycopy(selectedValues, 0, params, 0, selectedValues.length); addParameterToTree(params, pcGUI); enableDisableParameterCombinationButtons(); } } //---------------------------------------------------------------------------------------------------- private void handleRemoveParameter(final JTree tree) { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { cancelButton.doClick(); final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); if (!node.isRoot()) { final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); if (parentNode.isRoot()) { removeParameter(tree, node, parentNode); enableDisableParameterCombinationButtons(); } } } } //---------------------------------------------------------------------------------------------------- private void handleRemoveBox(final JTree tree) { final int answer = Utilities.askUser(dashboard, false, "Comfirmation", "This operation deletes the combination.", "All related parameter returns back to the list on the left side.", "Are you sure?"); if (answer == 1) { final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); if (tree.getSelectionCount() > 0) { editedNode = null; tree.setSelectionPath(null); if (cancelButton.isEnabled()) cancelButton.doClick(); } final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot(); for (int i = 0; i < root.getChildCount(); ++i) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i); removeParameter(tree, node, root); } enableDisableParameterCombinationButtons(); parameterTreeBranches.remove(pcGUI); combinationsPanel.remove(result); combinationsPanel.revalidate(); updateNumberOfRuns(); } } //---------------------------------------------------------------------------------------------------- private void removeParameter(final JTree tree, final DefaultMutableTreeNode node, final DefaultMutableTreeNode parentNode) { final ParameterInATree userObj = (ParameterInATree) node.getUserObject(); final ParameterInfo originalInfo = findOriginalInfo(userObj.info); if (originalInfo != null) { final DefaultListModel model = (DefaultListModel) parameterList.getModel(); model.addElement(new AvailableParameter(originalInfo, currentModelHandler.getModelClass())); final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); treeModel.removeNodeFromParent(node); updateNumberOfRuns(); tree.expandPath(new TreePath(treeModel.getPathToRoot(parentNode))); } else throw new IllegalStateException( "Parameter " + userObj.info.getName() + " is not found in the model."); } //---------------------------------------------------------------------------------------------------- private void handleMoveUp() { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { boolean success = true; if (editedNode != null) success = modify(); if (success) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null || parent.getFirstChild().equals(node)) { tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel tree.setSelectionPath(new TreePath(node.getPath())); return; } final int index = parent.getIndex(node); final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel(); treemodel.removeNodeFromParent(node); treemodel.insertNodeInto(node, parent, index - 1); tree.setSelectionPath(new TreePath(node.getPath())); } } } //---------------------------------------------------------------------------------------------------- private void handleMoveDown() { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { boolean success = true; if (editedNode != null) success = modify(); if (success) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath .getLastPathComponent(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null || parent.getLastChild().equals(node)) { tree.setSelectionPath(null); // we need this to preserve the state of the parameter settings panel tree.setSelectionPath(new TreePath(node.getPath())); return; } final int index = parent.getIndex(node); final DefaultTreeModel treemodel = (DefaultTreeModel) tree.getModel(); treemodel.removeNodeFromParent(node); treemodel.insertNodeInto(node, parent, index + 1); tree.setSelectionPath(new TreePath(node.getPath())); } } } }; GUIUtils.addActionListener(boxActionListener, closeButton, upButton, downButton, addButton, removeButton); result.setPreferredSize(new Dimension(500, 250)); enableDisableParameterCombinationButtons(); Style.apply(result, dashboard.getCssStyle()); return result; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void expandNode(JTree whichTree, DefaultMutableTreeNode node, boolean recurse) { whichTree.expandPath(new TreePath(node.getPath())); if (recurse && node.getChildCount() > 0) { for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i); expandNode(whichTree, child, recurse); }/*from ww w . j ava 2 s . co m*/ } }
From source file:org.apache.jmeter.gui.action.SearchTreeDialog.java
/** * @param e {@link ActionEvent}// w ww . j a va 2s . c o m */ private void doSearch(ActionEvent e) { boolean expand = e.getSource() == searchAndExpandButton; String wordToSearch = searchTF.getText(); if (StringUtils.isEmpty(wordToSearch)) { return; } else { this.lastSearch = wordToSearch; } // reset previous result ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SEARCH_RESET)); // do search Searcher searcher = null; if (isRegexpCB.isSelected()) { searcher = new RegexpSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText()); } else { searcher = new RawTextSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText()); } GuiPackage guiPackage = GuiPackage.getInstance(); JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel(); Set<JMeterTreeNode> nodes = new HashSet<>(); for (JMeterTreeNode jMeterTreeNode : jMeterTreeModel.getNodesOfType(Searchable.class)) { try { if (jMeterTreeNode.getUserObject() instanceof Searchable) { Searchable searchable = (Searchable) jMeterTreeNode.getUserObject(); List<JMeterTreeNode> matchingNodes = jMeterTreeNode.getPathToThreadGroup(); List<String> searchableTokens = searchable.getSearchableTokens(); boolean result = searcher.search(searchableTokens); if (result) { nodes.addAll(matchingNodes); } } } catch (Exception ex) { logger.error("Error occured searching for word:" + wordToSearch, ex); } } GuiPackage guiInstance = GuiPackage.getInstance(); JTree jTree = guiInstance.getMainFrame().getTree(); for (JMeterTreeNode jMeterTreeNode : nodes) { jMeterTreeNode.setMarkedBySearch(true); if (expand) { jTree.expandPath(new TreePath(jMeterTreeNode.getPath())); } } GuiPackage.getInstance().getMainFrame().repaint(); searchTF.requestFocusInWindow(); this.setVisible(false); }
From source file:org.geopublishing.atlasViewer.GpCoreUtil.java
private final static void expandAll(final JTree tree, final TreePath parent, final boolean expand) { // Traverse children final TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (final Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) { final TreeNode n = e.nextElement(); final TreePath path = parent.pathByAddingChild(n); expandAll(tree, path, expand); }// www . j a v a2 s .com } // Expansion or collapse must be done bottom-up if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } }
From source file:org.geopublishing.atlasViewer.GpCoreUtil.java
/** * Expands a tree to the//from w w w.j a v a 2 s.c o m * * @param tree * @param droppedNode * @author <a href="mailto:skpublic@wikisquare.de">Stefan Alfons Tzeggai</a> */ public final static void expandToNode(final JTree tree, final MutableTreeNode droppedNode) { TreeNode lookAt = droppedNode; final List<TreeNode> parents = new ArrayList<TreeNode>(); parents.add(lookAt); while (lookAt.getParent() != null) { lookAt = lookAt.getParent(); parents.add(lookAt); } Collections.reverse(parents); for (final TreeNode node : parents) { final TreePath path = getPath(node); tree.expandPath(path); } }
From source file:org.kepler.objectmanager.library.LibraryManager.java
/** * Refresh and redraw any JTrees that the LibraryManager is keeping track * of.// w w w .j a v a2 s .co m * *@exception IllegalActionException * Description of the Exception */ public void refreshJTrees() throws IllegalActionException { if (isDebugging) { log.debug("refresh"); } // Iterate over all the registered JTrees and reset their models. //Iterator<WeakReference> treeItt = _trees.iterator(); int size = _trees.size(); int i = 0; while (i < size) { WeakReference<JTree> wf = _trees.elementAt(i); JTree ptree = (JTree) wf.get(); if (ptree == null) { _trees.remove(wf); size--; } else { ptree.setModel(getTreeModel()); // stop listening for expansion events since we are going to // expand the paths and do not want to modify the list ptree.removeTreeExpansionListener(this); // expand all the paths that were previously expanded final List<TreePath> expansions = _treeExpansionMap.get(ptree); for (TreePath path : expansions) { //System.out.println("expanding " + path); ptree.expandPath(path); } // start listening again for expansion events ptree.addTreeExpansionListener(this); /* EntityTreeModel etm = (EntityTreeModel) ptree.getModel(); // Of course this would be easier if // ptolemy.vergil.tree.EntityTreeModel // had a reload method similar to DefaultTreeModel // that did this for us // TODO etm.reload() ArrayList<NamedObj> path = new ArrayList<NamedObj>(); path.add(0, (NamedObj) etm.getRoot()); TreePath tp = new TreePath(path); etm.valueForPathChanged(tp, etm.getRoot()); */ i++; } } }
From source file:org.nuclos.client.explorer.ExplorerNode.java
/** * expand all children of this node//from w w w.j a v a 2s .com * @param tree */ public void expandAllChildren(final JTree tree) { for (int i = getChildCount() - 1; i >= 0; i--) { final TreePath treePath = new TreePath( (((DefaultMutableTreeNode) ExplorerNode.this.getChildAt(i))).getPath()); if (!tree.isExpanded(treePath)) { tree.expandPath(treePath); } } }
From source file:org.nuclos.client.explorer.ExplorerNode.java
static void expandTreeAsync(List<String> lstExpandedPaths, final JTree tree) { for (final String idPath : lstExpandedPaths) { SwingUtilities.invokeLater(new Runnable() { @Override/*from ww w .java 2 s .c om*/ public void run() { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); TreePath path = ExplorerNode.findDescendant(model, idPath); if (path != null) tree.expandPath(path); } }); } }