List of usage examples for javax.swing.tree DefaultTreeModel reload
public void reload()
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); CheckBoxNode accessibilityOptions[] = { new CheckBoxNode("A", false), new CheckBoxNode("B", true) }; CheckBoxNode browsingOptions[] = { new CheckBoxNode("C", true), new CheckBoxNode("D", true), new CheckBoxNode("E", true), new CheckBoxNode("F", false) }; Vector accessVector = new NamedVector("G", accessibilityOptions); Vector browseVector = new NamedVector("H", browsingOptions); Object rootNodes[] = { accessVector, browseVector }; Vector rootVector = new NamedVector("Root", rootNodes); tree = new JTree(rootVector); CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer(); tree.setCellRenderer(renderer);/* ww w .j ava 2 s . c o m*/ tree.setCellEditor(new CheckBoxNodeEditor(tree)); tree.setEditable(true); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(); JButton button = new JButton("new node"); buttonPanel.add(button); frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH); button.addActionListener(e -> { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New node"); root.add(newNode); model.reload(); }); frame.setSize(300, 450); frame.setVisible(true); }
From source file:MyTree.java
public boolean importData(JComponent comp, Transferable t) { if (!(comp instanceof MyTree)) { return false; }/*w w w . j av a 2 s . c om*/ if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } MyTree tree = (MyTree) comp; DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); try { List data = (List) t.getTransferData(DataFlavor.javaFileListFlavor); Iterator i = data.iterator(); while (i.hasNext()) { File f = (File) i.next(); root.add(new DefaultMutableTreeNode(f.getName())); } model.reload(); return true; } catch (Exception ioe) { System.out.println(ioe); } return false; }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Initialize the view components.//w w w.j a va 2 s . c om */ private void initView() { // create new view loadTracksPanel = new LoadTracksPanel(); // disable the IMPORT FILES button loadTracksPanel.getImportFilesButton().setEnabled(false); // initialize the flag to keep track of importing isImported = false; // populate the combobox with available file formats // note: these are annoatated as spring beans Set<String> parsers = TrackFileParserFactory.getInstance().getParserBeanNames(); for (String parser : parsers) { loadTracksPanel.getFileFormatComboBox().addItem(parser); } // format the table JTableHeader tracksTableHeader = loadTracksPanel.getTracksTable().getTableHeader(); tracksTableHeader.setBackground(GuiUtils.getHeaderColor()); tracksTableHeader.setFont(GuiUtils.getHeaderFont()); tracksTableHeader.setReorderingAllowed(false); /** * Action Listeners. */ // load directory loadTracksPanel.getLoadDirectoryButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (directory == null) { chooseDirectoryAndLoadData(); } else { // otherwise we ask the user if they want to reload the directory Object[] options = { "Load a different directory", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "It seems a directory was already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load a different directory: // reset the model of the directory tree DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel(); DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot(); rootNote.removeAllChildren(); model.reload(); chooseDirectoryAndLoadData(); loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath()); break; // cancel: do nothing } } } }); // import the selected files in the tree loadTracksPanel.getImportFilesButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // check if an import already took place if (!isImported) { // get the selected file(s) from the JTree TreePath[] selectionPaths = loadTracksPanel.getDirectoryTree().getSelectionPaths(); if (selectionPaths != null && selectionPaths.length != 0) { // at least a file was selected -- proceed with the import importFiles(); isImported = true; cellCoordController.showMessage(selectionPaths.length + " file(s) successfully imported!", "success loading", JOptionPane.INFORMATION_MESSAGE); // do basic computations preprocess(); // go to child controllers and show samples in the tables summaryDataController.showSamplesInTable(); computationMainController.showSamplesInTable(); // proceed with next step in the plugin cellCoordController.getCellCoordFrame().getNextButton().setEnabled(true); } else { // inform the user that no file was selected! cellCoordController.showMessage("You have to select at least one file!", "no files selected", JOptionPane.WARNING_MESSAGE); } } else { // an import already took place: ask for user input Object[] options = { "Load other file(s)", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(loadTracksPanel, "It seems some files were already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load other files // clear the sample list samples.clear(); // clear the track spot list trackSpotsBindingList.clear(); // clear the selection in the JTree loadTracksPanel.getDirectoryTree().clearSelection(); isImported = false; // inform the user they need to select other files JOptionPane.showMessageDialog(loadTracksPanel, "Please select other files", "", JOptionPane.INFORMATION_MESSAGE); break; // cancel: do nothing } } } }); // add view to parent component cellCoordController.getCellCoordFrame().getLoadTracksParentPanel().add(loadTracksPanel, gridBagConstraints); }
From source file:com.yosanai.java.aws.console.panel.InstancesPanel.java
public void loadInstances() { new Thread(new Runnable() { @Override//from w w w . j av a2 s. c o m public void run() { DefaultTreeModel treeModel = (DefaultTreeModel) trInstances.getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); tblInstances.clearSelection(); trInstances.clearSelection(); rootNode.removeAllChildren(); treeModel.reload(); tblInstances.setModel(instancesTableModel); DescribeInstancesResult result = awsConnectionProvider.getConnection().describeInstances(); while (0 < instancesTableModel.getRowCount()) { instancesTableModel.removeRow(0); } for (Reservation reservation : result.getReservations()) { for (Instance instance : reservation.getInstances()) { String name = null; StringBuilder tags = new StringBuilder(); for (Tag tag : instance.getTags()) { tags.append(tag.getKey()); tags.append("="); tags.append(tag.getValue()); if (StringUtils.equalsIgnoreCase(nameTag, tag.getKey())) { name = tag.getValue(); } } try { boolean apiTermination = awsConnectionProvider .getApiTermination(instance.getInstanceId()); instancesTableModel.addRow(new Object[] { instance.getInstanceId(), instance.getPublicDnsName(), instance.getPublicIpAddress(), instance.getPrivateDnsName(), instance.getPrivateIpAddress(), apiTermination ? "Yes" : "No", instance.getState().getName(), instance.getInstanceType(), instance.getKeyName(), StringUtils.join(reservation.getGroupNames(), ","), instance.getPlacement().getAvailabilityZone(), DATE_FORMAT.format(instance.getLaunchTime()), tags.toString() }); DefaultMutableTreeNode instanceNode = new DefaultMutableTreeNode( new InstanceObjectWrapper(instance, name), false); rootNode.add(instanceNode); treeModel.reload(); } catch (Exception ex) { Logger.getLogger(InstancesPanel.class.getName()).log(Level.SEVERE, null, ex); } } } } }).start(); }
From source file:base.BasePlayer.AddGenome.java
static void checkGenomes() { //DefaultMutableTreeNode File checkdir = Main.genomeDir, checkAnnodir; File[] addDir, annodir;//from w w w .j ava 2s . c om root.removeAllChildren(); int counter = 0; for (int i = model.getRowCount() - 1; i >= 0; i--) { model.removeRow(i); } for (int i = remmodel.getRowCount() - 1; i >= 0; i--) { remmodel.removeRow(i); } removables.clear(); int currentlen = 0, length = 0; if (checkdir == null) { try { checkdir = new File(userDir + "/genomes"); } catch (Exception e) { e.printStackTrace(); } } addDir = checkdir.listFiles(); for (int f = 0; f < addDir.length; f++) { try { if (!addDir[f].isDirectory()) { continue; } currentlen = genometable.getFontMetrics(genometable.getFont()).stringWidth(addDir[f].getName()); if (currentlen > length) { length = currentlen; } AddGenome.removables.add(addDir[f].getName()); checkAnnodir = new File(checkdir + "/" + addDir[f].getName() + "/annotation/"); annodir = checkAnnodir.listFiles(); DefaultMutableTreeNode genome = new DefaultMutableTreeNode(addDir[f].getName()); root.add(genome); if (annodir == null) { counter++; genome.add(new DefaultMutableTreeNode("Add new annotation...")); } else { counter += annodir.length + 3; for (int a = 0; a < annodir.length; a++) { currentlen = genometable.getFontMetrics(genometable.getFont()) .stringWidth(annodir[a].getName()); if (currentlen > length) { length = currentlen; } genome.add(new DefaultMutableTreeNode(annodir[a].getName())); } genome.add(new DefaultMutableTreeNode("Add new annotation...")); } } catch (Exception e) { e.printStackTrace(); } } if (counter == 0) { counter = 1; length = genometable.getFontMetrics(genometable.getFont()).stringWidth("Add new annotation..."); } counter++; root.add(new DefaultMutableTreeNode("Add new reference...")); genometable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); for (int i = 0; i < organisms.size(); i++) { if (!AddGenome.removables.contains(organisms.get(i))) { Object[] row = { organisms.get(i), "" + sizeHash.get(organisms.get(i))[0] / 1048576 }; model.addRow(row); currentlen = genometable.getFontMetrics(genometable.getFont()).stringWidth(organisms.get(i)); if (currentlen > length) { length = currentlen; } } } AddGenome.longestName = length; if (genometable.getRowCount() > 15) { genometable.setPreferredScrollableViewportSize((new Dimension( AddGenome.longestName + 20 + Main.defaultFontSize * 8, genometable.getRowHeight() * 15))); genometable.setMinimumSize(new Dimension(AddGenome.longestName + 20, genometable.getRowHeight() * 15)); } else { genometable.setPreferredScrollableViewportSize( (new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, genometable.getRowHeight() * (genometable.getRowCount() + 1)))); genometable.setMinimumSize(new Dimension(AddGenome.longestName + 20, genometable.getRowHeight() * (genometable.getRowCount() + 1))); } if (remtable.getRowCount() > 15) { remtable.setPreferredScrollableViewportSize((new Dimension( AddGenome.longestName + 20 + Main.defaultFontSize * 8, remtable.getRowHeight() * 15))); } else { remtable.setPreferredScrollableViewportSize( (new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, remtable.getRowHeight() * (remtable.getRowCount() + 1)))); } //Main.defaultFontSize = 12; genometable.getColumnModel().getColumn(0).setPreferredWidth(AddGenome.longestName + 10); genometable.getColumnModel().getColumn(0).setMinWidth(AddGenome.longestName + 10); // genometable.getColumnModel().getColumn(1).setPreferredWidth(Main.defaultFontSize*8); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.reload(); int rowheight = tree.getRowHeight(); if (rowheight < 1) { rowheight = Main.defaultFontSize + 4; } treescroll.setPreferredSize( new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight)); treescroll.setMinimumSize( new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight)); remscroll.setPreferredSize( new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight)); remscroll.setMinimumSize( new Dimension(AddGenome.longestName + 20 + Main.defaultFontSize * 8, counter * rowheight)); tree.expandPath(new TreePath(root)); setFonts(Main.menuFont); }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Load the data files into the tree.//from w ww .j a v a 2 s.co m * * @throws LoadDirectoryException - when the directory is empty! */ private void loadDataIntoTree() throws LoadDirectoryException { DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel(); DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot(); // change name (user object) of root node rootNote.setUserObject(directory.getName()); File[] listFiles = directory.listFiles(); if (listFiles.length != 0) { for (File file : listFiles) { if (!file.isDirectory()) { DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(file.getName(), Boolean.FALSE); rootNote.add(fileNode); } else { // reset the directory to null directory = null; throw new LoadDirectoryException("This directory has a wrong structure!"); } } } else { // reset the directory to null directory = null; throw new LoadDirectoryException("This directory seems to be empty!"); } model.reload(); loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath()); cellCoordController.showMessage("Directory successful loaded!\nYou can now select the files to import!", "", JOptionPane.INFORMATION_MESSAGE); loadTracksPanel.getImportFilesButton().setEnabled(true); }
From source file:GUI.MainWindow.java
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed System.out.println("New Test Selected, Clear the tree and GUI"); // Clear the tree DefaultTreeModel dtm = ((DefaultTreeModel) this.VulnTree.getModel()); DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot(); root.removeAllChildren();//from w w w . j a v a2 s . c om dtm.reload(); // Clear the GUI clearGUI(); // Clear save file this.save_file = null; }
From source file:GUI.MainWindow.java
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed // Create a new vuln Vulnerability vuln = new Vulnerability(); vuln.setTitle("NEW"); vuln.setIs_custom_risk(true);/*from www.j a va2 s . co m*/ vuln.setRisk_category("None"); vuln.setImport_tool("ReportCompiler"); vuln.setIdentifier(); // Add it to the tree DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot(); DefaultMutableTreeNode new_vuln = new DefaultMutableTreeNode(vuln); root.add(new_vuln); // Refresh the GUI dtm.reload(); // Now select TreePath path = new TreePath(new_vuln.getPath()); VulnTree.setSelectionPath(path); // Set focus on the title field this.VulnTitleTextField.requestFocus(); this.VulnTitleTextField.selectAll(); }
From source file:dataviewer.DataViewer.java
private void fill_tree() { txt_count.setText(""); DefaultTreeModel tm = (DefaultTreeModel) tr_files.getModel(); DefaultMutableTreeNode top;//from ww w . j ava2 s .c o m cur_path = new File(cur_path).getAbsolutePath(); if (cur_path.charAt(cur_path.length() - 1) == '.') { cur_path = cur_path.substring(0, cur_path.length() - 1); } if (cur_path.charAt(cur_path.length() - 1) == File.separatorChar) { cur_path = cur_path.substring(0, cur_path.length() - 1); } if (tm != null) { top = (DefaultMutableTreeNode) tm.getRoot(); top.removeAllChildren(); top.setUserObject(cur_path); } else { top = new DefaultMutableTreeNode(cur_path); } // get all children nodes and remove them // rename the user object ArrayList<String> files = this.getAllFileNames(cur_path); Collections.sort(files); int j = 1; int selected_index = -1; for (String f : files) { String ex = this.getExtension(f); boolean is_folder = (new File(cur_path + File.separator + f)).isDirectory(); if (is_folder || ex.equals(".txt") || ex.equals(".dat") || ex.equals(".csv") || ex.equals(".tsv")) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(f); top.add(node); if (f.equals(selected_file)) { selected_index = j; } j++; } } //DefaultTreeModel treeModel = new DefaultTreeModel(top); //tr_files.setModel(treeModel); if (tm == null) { tr_files.setModel(new DefaultTreeModel(top)); } else { try { tm.reload(); } catch (Exception e) { tm.reload(); } } if (selected_index > -1) { tr_files.setSelectionRow(selected_index); } tr_files.grabFocus(); }
From source file:GUI.MainWindow.java
private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed System.out.println("Trying to clash the current tree against personal vulns to auto merge"); DefaultTreeModel dtm_vulntree = (DefaultTreeModel) this.VulnTree.getModel(); DefaultMutableTreeNode existing_root = (DefaultMutableTreeNode) dtm_vulntree.getRoot(); DefaultTreeModel dtm_personal_vulns = (DefaultTreeModel) this.personal_vulns_window.PersonalVulnsTree .getModel();// w w w. ja v a 2 s .c o m DefaultMutableTreeNode new_root = (DefaultMutableTreeNode) dtm_personal_vulns.getRoot(); DefaultMutableTreeNode answer = new TreeUtils().autoMergePersonalVulns(existing_root, new_root); dtm_vulntree.setRoot(answer); dtm_vulntree.reload(); }