List of usage examples for javax.swing JTree JTree
@ConstructorProperties({ "model" }) public JTree(TreeModel newModel)
JTree
which displays the root node -- the tree is created using the specified data model. From source file:org.zaproxy.zap.view.NodeSelectDialog.java
private JTree getTreeSite() { if (treeSite == null) { this.siteTree = this.emptySiteTree(); treeSite = new JTree(this.siteTree); treeSite.setShowsRootHandles(true); treeSite.setName("nodeSelectTree"); treeSite.setToggleClickCount(1); treeSite.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); treeSite.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { @Override/*from w w w. j a v a 2s. co m*/ public void valueChanged(javax.swing.event.TreeSelectionEvent e) { SiteNode node = (SiteNode) treeSite.getLastSelectedPathComponent(); getSelectButton().setEnabled(node != null && (node.getParent() != null || allowRoot)); } }); treeSite.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { } @Override public void mouseReleased(java.awt.event.MouseEvent e) { mouseClicked(e); } @Override public void mouseClicked(java.awt.event.MouseEvent e) { // right mouse button action if (treeSite.getLastSelectedPathComponent() != null) { // They selected a site node, deselect any context getTreeContext().clearSelection(); } if (e.getClickCount() > 1) { // Its a double click - close the dialog to select this node nodeSelected(); } } }); treeSite.setCellRenderer(new SiteMapTreeCellRenderer(new ArrayList<SiteMapListener>())); } return treeSite; }
From source file:org.zaproxy.zap.view.NodeSelectDialog.java
private JTree getTreeContext() { if (treeContext == null) { this.contextTree = this.emptyContextTree(); treeContext = new JTree(this.contextTree); treeContext.setShowsRootHandles(true); treeContext.setName("nodeContextTree"); treeContext.setToggleClickCount(1); treeContext.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); treeContext.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { @Override//w w w. j a va 2 s. c o m public void valueChanged(javax.swing.event.TreeSelectionEvent e) { SiteNode node = (SiteNode) treeContext.getLastSelectedPathComponent(); getSelectButton().setEnabled(node != null && (node.getParent() != null || allowRoot)); } }); treeContext.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { } @Override public void mouseReleased(java.awt.event.MouseEvent e) { mouseClicked(e); } @Override public void mouseClicked(java.awt.event.MouseEvent e) { // right mouse button action if (treeContext.getLastSelectedPathComponent() != null) { // They selected a context node, deselect any site node getTreeSite().clearSelection(); } if (e.getClickCount() > 1) { // Its a double click - close the dialog to select this node contextSelected(); } } }); treeContext.setCellRenderer(new ContextsTreeCellRenderer()); } return treeContext; }
From source file:phex.gui.tabs.library.LibraryTab.java
private JPanel createTreePanel(MouseHandler mouseHandler) { JPanel panel = new JPanel(); CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("fill:d:grow", // columns "fill:d:grow, 1dlu, p"); //rows PanelBuilder tabBuilder = new PanelBuilder(layout, panel); sharingTreeModel = new SharingTreeModel(); mainTree = new JTree(sharingTreeModel); mainTree.setMinimumSize(new Dimension(0, 0)); mainTree.setRowHeight(0);//from w ww .ja v a 2 s.c o m mainTree.setCellRenderer(new SharingTreeRenderer()); mainTree.addMouseListener(mouseHandler); mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler()); ToolTipManager.sharedInstance().registerComponent(mainTree); // open up first level of nodes TreeNode root = (TreeNode) sharingTreeModel.getRoot(); int count = root.getChildCount(); for (int i = 0; i < count; i++) { mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) })); } JScrollPane treeScrollPane = new JScrollPane(mainTree); tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1)); FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL); shareToolbar.setBorderPainted(false); shareToolbar.setFloatable(false); tabBuilder.add(shareToolbar, cc.xy(1, 3)); FWAction action = new AddShareFolderAction(); addTabAction(ADD_SHARE_FOLDER_ACTION_KEY, action); shareToolbar.addAction(action); action = new RemoveShareFolderAction(); addTabAction(REMOVE_SHARE_FOLDER_ACTION_KEY, action); shareToolbar.addAction(action); if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) { action = new ExploreFolderAction(); addTabAction(EXPLORE_FOLDER_ACTION_KEY, action); } return panel; }
From source file:phex.gui.tabs.library.LibraryTreePane.java
private void prepareComponent() { CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("fill:d:grow", // columns "fill:d:grow, 1dlu, p"); //rows PanelBuilder tabBuilder = new PanelBuilder(layout, this); sharingTreeModel = new SharingTreeModel(); mainTree = new JTree(sharingTreeModel); mainTree.setMinimumSize(new Dimension(0, 0)); mainTree.setRowHeight(0);//from w w w . j a va2 s . c o m mainTree.setCellRenderer(new SharingTreeRenderer()); mainTree.addMouseListener(new MouseHandler()); mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler()); ToolTipManager.sharedInstance().registerComponent(mainTree); // open up first level of nodes TreeNode root = (TreeNode) sharingTreeModel.getRoot(); int count = root.getChildCount(); for (int i = 0; i < count; i++) { mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) })); } JScrollPane treeScrollPane = new JScrollPane(mainTree); tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1)); FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL); shareToolbar.setBorderPainted(false); shareToolbar.setFloatable(false); tabBuilder.add(shareToolbar, cc.xy(1, 3)); addShareFolderAction = new AddShareFolderAction(); shareToolbar.addAction(addShareFolderAction); removeShareFolderAction = new RemoveShareFolderAction(); shareToolbar.addAction(removeShareFolderAction); if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) { exploreFolderAction = new ExploreFolderAction(); } fileTreePopup = new FWPopupMenu(); fileTreePopup.addAction(addShareFolderAction); fileTreePopup.addAction(removeShareFolderAction); if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) { fileTreePopup.addAction(exploreFolderAction); } }
From source file:Proiect.uploadFTP.java
public void actionFTP() { adressf.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { InetAddress thisIp;/*ww w . j av a 2s . co m*/ try { thisIp = InetAddress.getLocalHost(); titleFTP.setText("Connection: " + thisIp.getHostAddress() + " -> " + adressf.getText()); } catch (UnknownHostException e1) { e1.printStackTrace(); } } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { saveState(); uploadFTP.dispose(); tree.dispose(); } }); connect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FTPClient client = new FTPClient(); FileInputStream fis = null; String pass = String.valueOf(passf.getPassword()); try { if (filename == null) { status.setText("File does not exist!"); } else { // Server address client.connect(adressf.getText()); // Login credentials client.login(userf.getText(), pass); if (client.isConnected()) { status.setText("Succesfull transfer!"); // File type client.setFileType(FTP.BINARY_FILE_TYPE); // File location File file = new File(filepath); fis = new FileInputStream(file); // Change the folder on the server client.changeWorkingDirectory(folderf.getText()); // Save the file on the server client.storeFile(filename, fis); } else { status.setText("Transfer failed!"); } } client.logout(); } catch (IOException e1) { Encrypter.printException(e1); } finally { try { if (fis != null) { fis.close(); } client.disconnect(); } catch (IOException e1) { Encrypter.printException(e1); } } } }); browsef.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int retval = chooserf.showOpenDialog(chooserf); if (retval == JFileChooser.APPROVE_OPTION) { status.setText(""); filename = chooserf.getSelectedFile().getName().toString(); filepath = chooserf.getSelectedFile().getPath(); filenf.setText(chooserf.getSelectedFile().getName().toString()); } } }); adv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tree.setSize(220, uploadFTP.getHeight()); tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY()); tree.setResizable(false); tree.setIconImage(Toolkit.getDefaultToolkit() .getImage(getClass().getClassLoader().getResource("assets/ico.png"))); tree.setUndecorated(true); tree.getRootPane().setBorder(BorderFactory.createLineBorder(Encrypter.color_black, 2)); tree.setVisible(true); tree.setLayout(new BorderLayout()); JLabel labeltree = new JLabel("Server documents"); labeltree.setOpaque(true); labeltree.setBackground(Encrypter.color_light); labeltree.setBorder(BorderFactory.createMatteBorder(8, 10, 10, 0, Encrypter.color_light)); labeltree.setForeground(Encrypter.color_blue); labeltree.setFont(Encrypter.font16); JButton refresh = new JButton(""); ImageIcon refresh_icon = getImageIcon("assets/icons/refresh.png"); refresh.setIcon(refresh_icon); refresh.setBackground(Encrypter.color_light); refresh.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); refresh.setForeground(Encrypter.color_black); refresh.setFont(Encrypter.font16); refresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); final FTPClient client = new FTPClient(); DefaultMutableTreeNode top = new DefaultMutableTreeNode(adressf.getText()); DefaultMutableTreeNode files = null; DefaultMutableTreeNode leaf = null; final JTree tree_view = new JTree(top); tree_view.setForeground(Encrypter.color_black); tree_view.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); tree_view.putClientProperty("JTree.lineStyle", "None"); tree_view.setBackground(Encrypter.color_light); JScrollPane scrolltree = new JScrollPane(tree_view); scrolltree.setBackground(Encrypter.color_light); scrolltree.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0)); UIManager.put("Tree.textBackground", Encrypter.color_light); UIManager.put("Tree.selectionBackground", Encrypter.color_blue); UIManager.put("Tree.selectionBorderColor", Encrypter.color_blue); tree_view.updateUI(); final String pass = String.valueOf(passf.getPassword()); try { client.connect(adressf.getText()); client.login(userf.getText(), pass); client.enterLocalPassiveMode(); if (client.isConnected()) { try { FTPFile[] ftpFiles = client.listFiles(); for (FTPFile ftpFile : ftpFiles) { files = new DefaultMutableTreeNode(ftpFile.getName()); top.add(files); if (ftpFile.getType() == FTPFile.DIRECTORY_TYPE) { FTPFile[] ftpFiles1 = client.listFiles(ftpFile.getName()); for (FTPFile ftpFile1 : ftpFiles1) { leaf = new DefaultMutableTreeNode(ftpFile1.getName()); files.add(leaf); } } } } catch (IOException e1) { Encrypter.printException(e1); } client.disconnect(); } else { status.setText("Failed connection!"); } } catch (IOException e1) { Encrypter.printException(e1); } finally { try { client.disconnect(); } catch (IOException e1) { Encrypter.printException(e1); } } tree.add(labeltree, BorderLayout.NORTH); tree.add(scrolltree, BorderLayout.CENTER); tree.add(refresh, BorderLayout.SOUTH); uploadFTP.addComponentListener(new ComponentListener() { public void componentMoved(ComponentEvent e) { tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY()); } public void componentShown(ComponentEvent e) { } public void componentResized(ComponentEvent e) { } public void componentHidden(ComponentEvent e) { } }); uploadFTP.addWindowListener(new WindowListener() { public void windowActivated(WindowEvent e) { tree.toFront(); } public void windowOpened(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } public void windowClosing(WindowEvent e) { } public void windowClosed(WindowEvent e) { } }); refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tree.dispose(); tree.setVisible(true); } }); } }); }
From source file:psidev.psi.mi.filemakers.xsd.AbstractXsdTreeStruct.java
/** * Returns an instance of <code>AbstractXslTree</code> * * @param autoduplicate//from ww w. j a va 2 s.c o m * indicates that new nodes will be automaticly created according to * the minimum defined in the schema (minOccurs) */ public AbstractXsdTreeStruct(boolean autoduplicate, boolean manageChoices) { this.autoDuplicate = autoduplicate; this.manageChoices = manageChoices; this.tree = new JTree(treeModel); }
From source file:psidev.psi.mi.filemakers.xsd.AbstractXsdTreeStruct.java
public AbstractXsdTreeStruct() { this.autoDuplicate = true; this.manageChoices = true; tree = new JTree(treeModel); }
From source file:qic.ui.EditorPanel.java
private void setupFileTree() { TreeModel model = new FileTreeModel(new File(".")); fileTree = new JTree(model); fileTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); fileTree.addTreeSelectionListener(tse -> { File file = (File) fileTree.getLastSelectedPathComponent(); if (isFileEditable(file)) { saveCurrentScriptToFile();/*www .j a va 2 s . com*/ currentScript = file; loadFileToTextArea(file); } }); fileTree.setSelectionRow(0); add(new JScrollPane(fileTree), BorderLayout.EAST); }
From source file:qic.ui.ScriptsPanel.java
private void setupFileTree() { TreeModel model = new FileTreeModel(new File("script")); fileTree = new JTree(model); fileTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); fileTree.addTreeSelectionListener(tse -> { File file = (File) fileTree.getLastSelectedPathComponent(); if (isFileEditable(file)) { saveCurrentScriptToFile();/*from ww w . j a v a2 s .c o m*/ currentScript = file; loadFileToTextArea(file); } }); fileTree.setSelectionRow(fileTree.getRowCount() > 3 ? 3 : 1); add(new JScrollPane(fileTree), BorderLayout.EAST); }
From source file:qic.ui.TermsPanel.java
private void setupFileTree() { TreeModel model = new FileTreeModel(new File("terms")); fileTree = new JTree(model); fileTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); fileTree.addTreeSelectionListener(tse -> { File file = (File) fileTree.getLastSelectedPathComponent(); if (isFileEditable(file)) { saveCurrentScriptToFile();//w ww . j a v a 2 s. c om currentScript = file; loadFileToTextArea(file); } }); fileTree.setSelectionRow(1); add(new JScrollPane(fileTree), BorderLayout.EAST); }