List of usage examples for javax.swing.tree DefaultMutableTreeNode add
public void add(MutableTreeNode newChild)
newChild
from its parent and makes it a child of this node by adding it to the end of this node's child array. From source file:studio.ui.Studio.java
private void createConnectionsTree() { if (treeConnections == null) { treeConnections = new KdbServicesTree(tabEditors); tools.setConnectionsView((KdbServicesTree) treeConnections); tabEditors.addFireDataListener((DataListener) treeConnections); }/*from w w w . j a v a 2 s .c o m*/ DefaultMutableTreeNode top = null; if (!(treeConnections.getModel() instanceof DefaultMutableTreeNode)) { top = new DefaultMutableTreeNode("KDB+ servers"); treeConnections.setModel(new KdbServicesTreeModel(top)); treeConnections.setCellRenderer(new KdbServicesTreeCellRender()); Collection<String> hostnames = studioConfig.getHosts(); if (hostnames != null && !hostnames.isEmpty()) { for (String hostname : hostnames) { try { InetAddress.getAllByName(hostname); top.add(new HostTreeNode(hostname, studioConfig.getConnections(hostname))); } catch (UnknownHostException ignored) { } } } } treeConnections.expandPath(new TreePath(top)); treeConnections.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); }
From source file:ubic.basecode.dataStructure.graph.DirectedGraph.java
private void addJTreeNode(DefaultMutableTreeNode startJTreeNode, DirectedGraphNode<K, V> startNode, Constructor<DefaultMutableTreeNode> constructor) { if (startJTreeNode == null) return;/*from www . j a v a 2s . c om*/ Set<DirectedGraphNode<K, V>> children = startNode.getChildNodes(); for (Iterator<DirectedGraphNode<K, V>> it = children.iterator(); it.hasNext();) { DirectedGraphNode<K, V> nextNode = it.next(); if (!nextNode.isVisited()) { DefaultMutableTreeNode newJTreeNode = null; try { newJTreeNode = constructor.newInstance(new Object[] { nextNode }); } catch (Exception e) { log.error(e, e); } startJTreeNode.add(newJTreeNode); nextNode.mark(); this.addJTreeNode(newJTreeNode, nextNode, constructor); } } }
From source file:ui.panel.UILicenseAdd.java
private JPanel createPnlFeature() { JPanel panel = p.createPanel(Layouts.gridbag); GridBagConstraints g = new GridBagConstraints(); lblSelectFeature = l.createLabel("Select Features", SwingConstants.LEFT); g.gridx = 0;/* w w w. j a v a 2 s .c om*/ g.gridy = 0; g.gridwidth = 2; g.insets = new Insets(5, 5, 5, 5); panel.add(lblSelectFeature, g); lblServiceApi = l.createLabel("Service APIs Used", SwingConstants.LEFT); g.gridx = 4; g.gridy = 0; g.gridwidth = 2; g.insets = new Insets(5, 5, 5, 5); panel.add(lblServiceApi, g); getFeaturesData(); DefaultMutableTreeNode root = new MyDataNode("Features", "Features"); for (String key : Data.featureList.keySet()) { try { DefaultMutableTreeNode element = new MyDataNode(key, Data.fieldNames.get(key)); JSONArray features = Data.featureList.get(key); ArrayList<DefaultMutableTreeNode> arrayFeatureCheckBox = new ArrayList<DefaultMutableTreeNode>(); for (int i = 0; i < features.length(); i++) { JSONObject feature = features.getJSONObject(i); DefaultMutableTreeNode featureElement = new MyDataNode((String) feature.get("name"), Data.fieldNames.get(feature.get("name"))); element.add(featureElement); arrayFeatureCheckBox.add(featureElement); } root.add(element); } catch (JSONException e) { e.printStackTrace(); } } tree = new JTree(root); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath path = tree.getSelectionModel().getSelectionPath(); model.removeAllElements(); String item = tree.getSelectionModel().getSelectionPath().getLastPathComponent().toString(); MyDataNode node = (MyDataNode) tree.getSelectionModel().getSelectionPath().getLastPathComponent(); String selected = node.getValue(); servicesList = new HashMap<String, String>(); try { if (selected.equalsIgnoreCase("Features")) { for (String key : Data.featureList.keySet()) { JSONArray featureArray = Data.featureList.get(key); for (int i = 0; i < featureArray.length(); i++) { JSONArray servicesArray = featureArray.getJSONObject(i).getJSONArray("services"); for (int x = 0; x < servicesArray.length(); x++) { servicesList.put(Integer.toString(servicesArray.getJSONObject(x).getInt("id")), servicesArray.getJSONObject(x).getString("name")); } } } } else if (path.getPathCount() == 2) { for (String key : Data.featureList.keySet()) { if (key.equals(selected)) { JSONArray featureArray = Data.featureList.get(key); for (int i = 0; i < featureArray.length(); i++) { JSONArray servicesArray = featureArray.getJSONObject(i) .getJSONArray("services"); for (int x = 0; x < servicesArray.length(); x++) { servicesList.put( Integer.toString(servicesArray.getJSONObject(x).getInt("id")), servicesArray.getJSONObject(x).getString("name")); } } } else { continue; } } } else { MyDataNode nodePath = (MyDataNode) path.getPathComponent(1); for (String key : Data.featureList.keySet()) { if (key.equals(nodePath.getValue())) { JSONArray featureArray = Data.featureList.get(key); for (int i = 0; i < featureArray.length(); i++) { System.out.println( featureArray.getJSONObject(i).getString("name") + ":" + selected); if (featureArray.getJSONObject(i).getString("name").equals(selected)) { JSONArray servicesArray = featureArray.getJSONObject(i) .getJSONArray("services"); System.out.println(servicesArray); for (int x = 0; x < servicesArray.length(); x++) { servicesList.put( Integer.toString(servicesArray.getJSONObject(x).getInt("id")), servicesArray.getJSONObject(x).getString("name")); } } else { continue; } } } else { continue; } } } } catch (JSONException ex) { ex.printStackTrace(); } for (String serviceKey : servicesList.keySet()) { model.addElement(servicesList.get(serviceKey)); } listServiceUsed.setModel(model); } }); checkTreeManager = new CheckTreeManager(tree); spTreeCheckBox = new JScrollPane(tree); spTreeCheckBox.setPreferredSize(new Dimension(300, 300)); g.gridx = 0; g.gridy = 1; g.gridwidth = 3; g.anchor = g.LINE_START; g.insets = new Insets(5, 5, 5, 5); panel.add(spTreeCheckBox, g); model = new DefaultListModel<>(); model.addElement(""); listServiceUsed = new JList<String>(model); spList = new JScrollPane(listServiceUsed); spList.setPreferredSize(new Dimension(300, 300)); g.gridx = 4; g.gridy = 1; g.gridwidth = 3; g.anchor = g.LINE_START; panel.add(spList, g); return panel; }
From source file:ui.panel.UILicenseDetail.java
public void getData(String licenseNumber) { root = new DefaultMutableTreeNode("Features"); try {/*from w w w .j ava2 s . c om*/ JSONObject response = api.getNodeLicenseDetails(Data.targetURL, Data.sessionKey, Data.bucketID, licenseNumber); JSONArray features = response.getJSONArray("features"); for (String key : Data.featureList.keySet()) { boolean contains = false; JSONArray featureArray = Data.featureList.get(key); DefaultMutableTreeNode element = new DefaultMutableTreeNode(Data.fieldNames.get(key)); ArrayList<DefaultMutableTreeNode> arrayFeatureCheckBox = new ArrayList<DefaultMutableTreeNode>(); for (int i = 0; i < features.length(); i++) { String feature = features.getString(i); for (int x = 0; x < featureArray.length(); x++) { try { if (feature.equals(featureArray.getJSONObject(x).getString("name"))) { DefaultMutableTreeNode featureElement = new DefaultMutableTreeNode( Data.fieldNames.get(featureArray.getJSONObject(x).getString("name"))); element.add(featureElement); arrayFeatureCheckBox.add(featureElement); contains = true; } } catch (JSONException e1) { e1.printStackTrace(); } } } if (contains) { root.add(element); } } } catch (JSONException e) { e.printStackTrace(); } }
From source file:view.MultipleValidationDialog.java
private void jtFilesValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jtFilesValueChanged jtValidation.setModel(null);/* w ww .java 2 s.co m*/ ArrayList<SignatureValidation> svList = null; if (jtFiles.getSelectionRows().length > 1) { jtFiles.setSelectionPath(evt.getOldLeadSelectionPath()); return; } if (evt.getNewLeadSelectionPath() == null) { panelSignatureDetails.setVisible(false); return; } for (Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> entry : hmValidation.entrySet()) { int numSigs = CCInstance.getInstance().getNumberOfSignatures(entry.getKey().getFilename()); if (String.valueOf(evt.getPath().getLastPathComponent()) .equals("(" + numSigs + ") " + entry.getKey().getFilename())) { svList = entry.getValue(); break; } } final DefaultMutableTreeNode top = new DefaultMutableTreeNode(null); if (svList == null) { return; } if (svList.isEmpty()) { panelSignatureDetails.setVisible(false); DefaultMutableTreeNode noSignatures = new TreeNodeWithState(Bundle.getBundle().getString("notSigned"), TreeNodeWithState.State.NOT_SIGNED); top.add(noSignatures); TreeModel tm = new DefaultTreeModel(top); jtValidation.setModel(tm); return; } for (SignatureValidation sv : svList) { DefaultMutableTreeNode sig = new DefaultMutableTreeNode(sv); TreeNodeWithState childChanged = null; if (sv.isCertification()) { if (sv.isValid()) { if (sv.isChanged() || !sv.isCoversEntireDocument()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.1") + "<br>" + Bundle.getBundle().getString("tn.2") + "</html>", TreeNodeWithState.State.CERTIFIED_WARNING); } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("certifiedOk"), TreeNodeWithState.State.CERTIFIED); } } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("changedAfterCertified"), TreeNodeWithState.State.INVALID); } } else if (sv.isValid()) { if (sv.isChanged()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.3") + "<br>" + Bundle.getBundle().getString("tn.4") + "</html>", TreeNodeWithState.State.VALID_WARNING); } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("signedOk"), TreeNodeWithState.State.VALID); } } else { childChanged = new TreeNodeWithState(Bundle.getBundle().getString("signedChangedOrCorrupted"), TreeNodeWithState.State.INVALID); } TreeNodeWithState childVerified = null; if (sv.getOcspCertificateStatus().equals(CertificateStatus.OK) || sv.getCrlCertificateStatus().equals(CertificateStatus.OK)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certOK"), TreeNodeWithState.State.VALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.REVOKED) || sv.getCrlCertificateStatus().equals(CertificateStatus.REVOKED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certRevoked"), TreeNodeWithState.State.INVALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHECKED) && sv.getCrlCertificateStatus().equals(CertificateStatus.UNCHECKED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certNotVerified"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHAINED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certNotChained"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.EXPIRED)) { childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certExpired"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.CHAINED_LOCALLY)) { childVerified = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.5") + "<br>" + Bundle.getBundle().getString("tn.6") + "</html>", TreeNodeWithState.State.VALID_WARNING); } TreeNodeWithState childTimestamp = null; if (sv.isValidTimeStamp()) { childTimestamp = new TreeNodeWithState(Bundle.getBundle().getString("validTimestamp"), TreeNodeWithState.State.VALID); } else { childTimestamp = new TreeNodeWithState(Bundle.getBundle().getString("signerDateTime"), TreeNodeWithState.State.WARNING); } sig.add(childChanged); sig.add(childVerified); sig.add(childTimestamp); top.add(sig); } TreeModel tm = new DefaultTreeModel(top); jtValidation.setModel(tm); if (jtValidation.getRowCount() > 0) { jtValidation.setSelectionRow(jtValidation.getRowCount() - 1); } }
From source file:view.WorkspacePanel.java
private void startValidationThread() { status = Status.VALIDATING;/*from www .ja va2s . c o m*/ svList.clear(); jtValidation.clearSelection(); jtValidation.setModel(null); showSignatureValidationDetails(null); Runnable r = new Runnable() { @Override public void run() { try { progressBar.setValue(0); jtValidation.setModel(null); jtValidation.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jtValidation.setRootVisible(false); ValidationTreeCellRenderer renderer = new ValidationTreeCellRenderer(); jtValidation.setCellRenderer(renderer); final int numSigs = CCInstance.getInstance() .getNumberOfSignatures(document.getDocumentLocation()); if (numSigs > 0) { jScrollPane2.setVisible(true); progressBar.setString(Bundle.getBundle().getString("pb.validatingSignature") + " 1 " + Bundle.getBundle().getString("of") + " " + numSigs); progressBar.setMaximum(numSigs); final DefaultMutableTreeNode top = new DefaultMutableTreeNode(null); ValidationListener vl = new ValidationListener() { int numParsed = 1; @Override public void onValidationComplete(SignatureValidation sv) { if (status.equals(Status.VALIDATING)) { sv.setListener(WorkspacePanel.this); svList.add(sv); DefaultMutableTreeNode sig = new DefaultMutableTreeNode(sv); TreeNodeWithState childChanged = null; if (sv.isCertification()) { if (sv.isValid()) { if (sv.isChanged() || !sv.isCoversEntireDocument()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.1") + "<br>" + Bundle.getBundle().getString("tn.2") + "</html>", TreeNodeWithState.State.CERTIFIED_WARNING); } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("certifiedOk"), TreeNodeWithState.State.CERTIFIED); } } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("changedAfterCertified"), TreeNodeWithState.State.INVALID); } } else if (sv.isValid()) { if (sv.isChanged()) { childChanged = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.3") + "<br>" + Bundle.getBundle().getString("tn.4") + "</html>", TreeNodeWithState.State.VALID_WARNING); } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("signedOk"), TreeNodeWithState.State.VALID); } } else { childChanged = new TreeNodeWithState( Bundle.getBundle().getString("signedChangedOrCorrupted"), TreeNodeWithState.State.INVALID); } TreeNodeWithState childVerified = null; if (sv.getOcspCertificateStatus().equals(CertificateStatus.OK) || sv.getCrlCertificateStatus().equals(CertificateStatus.OK)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certOK"), TreeNodeWithState.State.VALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.REVOKED) || sv.getCrlCertificateStatus().equals(CertificateStatus.REVOKED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certRevoked"), TreeNodeWithState.State.INVALID); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHECKED) && sv.getCrlCertificateStatus().equals(CertificateStatus.UNCHECKED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certNotVerified"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHAINED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certNotChained"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.EXPIRED)) { childVerified = new TreeNodeWithState( Bundle.getBundle().getString("certExpired"), TreeNodeWithState.State.WARNING); } else if (sv.getOcspCertificateStatus() .equals(CertificateStatus.CHAINED_LOCALLY)) { childVerified = new TreeNodeWithState( "<html>" + Bundle.getBundle().getString("tn.5") + "<br>" + Bundle.getBundle().getString("tn.6") + "</html>", TreeNodeWithState.State.VALID_WARNING); } TreeNodeWithState childTimestamp = null; if (sv.isValidTimeStamp()) { childTimestamp = new TreeNodeWithState( Bundle.getBundle().getString("validTimestamp"), TreeNodeWithState.State.VALID); } else { childTimestamp = new TreeNodeWithState( Bundle.getBundle().getString("signerDateTime"), TreeNodeWithState.State.WARNING); } sig.add(childChanged); sig.add(childVerified); sig.add(childTimestamp); top.add(sig); TreeModel tm = new DefaultTreeModel(top); jtValidation.setModel(tm); progressBar.setValue(progressBar.getValue() + 1); numParsed++; progressBar.setString( Bundle.getBundle().getString("pb.validatingSignature") + " " + numParsed + " " + Bundle.getBundle().getString("of") + " " + numSigs); } else { CCInstance.getInstance().setValidating(false); } } }; CCInstance.getInstance().validatePDF(document.getDocumentLocation(), vl); status = Status.READY; jtValidation.setVisible(true); progressBar.setString(Bundle.getBundle().getString("pb.validationCompleted")); if (rightPanel.isVisible() && jtValidation.getRowCount() > 0) { jtValidation.setSelectionRow(jtValidation.getRowCount() - 1); } imagePanel.setSignatureValidationList(svList); panelValidationResult.setVisible(true); status = Status.READY; } else { progressBar.setString(Bundle.getBundle().getString("notSigned")); status = Status.READY; jScrollPane2.setVisible(false); } } catch (IOException | DocumentException | GeneralSecurityException ex) { controller.Logger.getLogger().addEntry(ex); status = Status.READY; progressBar.setString(Bundle.getBundle().getString("validationError")); jScrollPane2.setVisible(false); } } }; Thread t = new Thread(r); t.start(); }