package frame; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Component; import java.awt.Desktop; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Vector; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollBar; import javax.swing.JScrollPane; import javax.swing.Timer; import javax.swing.event.MouseInputListener; import javax.swing.plaf.FileChooserUI; import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.SCPClient; import ch.ethz.ssh2.SFTPv3Client; import ch.ethz.ssh2.SFTPv3FileAttributes; import ch.ethz.ssh2.Session; import ch.ethz.ssh2.SFTPv3DirectoryEntry; import ch.ethz.ssh2.StreamGobbler; //import javax.swing.filechooser.FileSystemView; import filesystem.Extensions; import filesystem.FSInfo; import filesystem.FSUtil; /** * JPanel customized for remote connections * and acts as the content pane and workspace * for visual file browsing on remote server * * @author * @version */ @SuppressWarnings("serial") public class SlideBrowserSFTPPanel extends JPanel { //Class variables private ArrayList nodeList; private ArrayList selectedNodeList; private int selectedNodeIndex; private JPopupMenu backgroundPopUp; private JPopupMenu nodePopUp; private SlideBrowser sb; private boolean showHitBox; private boolean showHiddenFiles; private MouseInputListener mouse; private Point rClickPoint; private Point initialClick; private Extensions ext; private SFTPv3Client client; private int reply; private String replyString; private JMenuItem expandNodeMenuItem; private JMenuItem foldNodeMenuItem; private JMenuItem openMenuItem; private JMenuItem makeDirMenuItem; private JMenuItem deleteMenuItem; private JMenuItem copyMenuItem; private JMenuItem cutMenuItem; private JMenuItem pasteMenuItem; private JMenuItem renameMenuItem; private JMenuItem removeDirMenuItem; private Connection conn; private Session sess; private InputStream stdout; private InputStream stderr; private OutputStream stdin; String eol = System.getProperty("line.separator"); /** * Default constructor for the panel. Takes in the frame * that made/added the panel in order to call methods from * other frames * * @param Initial file to make first root node * @param frame = root frame that contains the panel */ public SlideBrowserSFTPPanel(String[] details, SlideBrowser frame) { //Ability to call methods in frame //Is this already possible without the parameter? sb = frame; //Focus the panel setFocusable(true); //Set background setBackground(Color.GRAY); //Attempt connection boolean error = false; //ArrayList for the nodes of this panel nodeList = new ArrayList(); ext = new Extensions(); try { /* Create a connection instance */ Connection conn = new Connection(details[1]); /* Now connect */ conn.connect(); /* Authenticate. * If you get an IOException saying something like * "Authentication method password not supported by the server at this stage." * then please check the FAQ. */ boolean isAuthenticated = conn.authenticateWithPassword(details[3], details[4]); if (isAuthenticated == false) { JOptionPane.showMessageDialog(sb, new JLabel("Authentication to " + details[1] + " failed."), "Authentication Failed", JOptionPane.WARNING_MESSAGE); } /* Create a session */ sess = conn.openSession(); sess.requestDumbPTY(); sess.startShell(); stdout = new StreamGobbler(sess.getStdout()); stderr = new StreamGobbler(sess.getStderr()); stdin = new BufferedOutputStream(sess.getStdin(), 8192); //Make SCP client client = new SFTPv3Client(conn); //Get files in parent directory int dotPos = client.canonicalPath(".").lastIndexOf('.'); String rootName = (client.canonicalPath(".").substring(dotPos+1)).toLowerCase(); SFTPNodeItem temp = new SFTPNodeItem(rootName); nodeList.add(temp); nodeList.get(0).setDirectory(true); nodeList.get(0).sethbSize(32); nodeList.get(0).setPosition(10, 10); nodeList.get(0).setIcon(getImage("/resources/32x32/folder.png")); nodeList.get(0).setPath(client.canonicalPath(".")); nodeList.get(0).setParentNode(nodeList, 0); nodeList.get(0).getEntry().filename = rootName; expandNode(nodeList, 0); } catch(IOException e) { error = true; //Something happened, remove tab and //disconnect JOptionPane.showMessageDialog(sb, new JLabel("Could not connect to " +details[1]), "Network Error", JOptionPane.WARNING_MESSAGE); } //Add MouseListener mouseAction mouse = new mouseSFTPAction(this); addMouseListener(mouse); addMouseMotionListener(mouse); //Make popup menu for background context menu backgroundPopUp = new JPopupMenu(); //Add item "Remove Tab" JMenuItem menuRemoveTab = new JMenuItem("Remove Tab", new ImageIcon(getClass().getResource("/resources/16x16/tab_delete.png"))); menuRemoveTab.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { sb.removeTab(); } }); //Add everything to background popup menu backgroundPopUp.add(menuRemoveTab); //Make popup menu for node context menu nodePopUp = new JPopupMenu(); //Add item "Expand node" expandNodeMenuItem = new JMenuItem("Expand node", new ImageIcon(getClass().getResource("/resources/16x16/folders_explorer.png"))); expandNodeMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { expandNode(selectedNodeList, selectedNodeIndex); } }); expandNodeMenuItem.setVisible(true); //Add item "Fold node" foldNodeMenuItem = new JMenuItem("Fold node", new ImageIcon(getClass().getResource("/resources/16x16/folders.png"))); foldNodeMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { foldNode(selectedNodeList, selectedNodeIndex); } }); foldNodeMenuItem.setVisible(false); //Add item "Delete" deleteMenuItem = new JMenuItem("Delete", new ImageIcon(getClass().getResource("/resources/16x16/delete.png"))); deleteMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { sb.terminalMessage(conn.getHostname() + ":rm " + selectedNodeList.get(selectedNodeIndex).getPath()); try { client.rm(selectedNodeList.get(selectedNodeIndex).getPath()); } catch (IOException e) { JOptionPane.showMessageDialog(sb, new JLabel("An I/O Error has occured." + eol + e.getMessage()), "I/O Error", JOptionPane.WARNING_MESSAGE); } foldNode(selectedNodeList, selectedNodeIndex); expandNode(selectedNodeList, selectedNodeIndex); repaint(); } }); deleteMenuItem.setVisible(false); //Add item "Cut" cutMenuItem = new JMenuItem("Cut", new ImageIcon(getClass().getResource("/resources/16x16/cut.png"))); cutMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { //sb.terminalMessage("Cut File: " + selectedNodeList.get(selectedNodeIndex).getFile().getAbsolutePath()); //FSUtil.getInstance().cut(selectedNodeList.get(selectedNodeIndex).getFile()); } }); cutMenuItem.setVisible(false); //Add item "Copy" copyMenuItem = new JMenuItem("Copy", new ImageIcon(getClass().getResource("/resources/16x16/copying_and_distribution.png"))); copyMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { //sb.terminalMessage("Copy File: " + selectedNodeList.get(selectedNodeIndex).getFile().getAbsolutePath()); //FSUtil.getInstance().copy(selectedNodeList.get(selectedNodeIndex).getFile()); } }); copyMenuItem.setVisible(false); //Add item "Paste" pasteMenuItem = new JMenuItem("Paste", new ImageIcon(getClass().getResource("/resources/16x16/paste_plain.png"))); pasteMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { //sb.terminalMessage("Paste File: " + selectedNodeList.get(selectedNodeIndex).getFile().getAbsolutePath()); //FSUtil.getInstance().paste(selectedNodeList.get(selectedNodeIndex).getFile()); //TODO also need to fold/expand cut directory if cut command used. foldNode(selectedNodeList, selectedNodeIndex); expandNode(selectedNodeList, selectedNodeIndex); repaint(); } }); pasteMenuItem.setVisible(false); //Add item "Rename" renameMenuItem = new JMenuItem("Rename", new ImageIcon(getClass().getResource("/resources/16x16/textfield_rename.png"))); renameMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { sb.terminalMessage("Rename File: " + selectedNodeList.get(selectedNodeIndex).getFile() + " @" + conn.getHostname() + ":" + conn.getPort()); //new renameFTPWindow(selectedNodeList.get(selectedNodeIndex).getFile(), client); foldNode(selectedNodeList, selectedNodeIndex); expandNode(selectedNodeList, selectedNodeIndex); repaint(); } }); renameMenuItem.setVisible(false); //Add item "Make Directory" makeDirMenuItem = new JMenuItem("Make Directory", new ImageIcon(getClass().getResource("/resources/16x16/folder_add.png"))); makeDirMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { makeDir(selectedNodeList, selectedNodeIndex); } }); makeDirMenuItem.setVisible(false); removeDirMenuItem = new JMenuItem("Remove Directory", new ImageIcon(getClass().getResource("/resources/16x16/folder_delete.png"))); removeDirMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { removeDir(selectedNodeList, selectedNodeIndex); } }); removeDirMenuItem.setVisible(false); //Add item "Remove node" //TODO make a different icon JMenuItem removeNodeMenuItem = new JMenuItem("Remove node", new ImageIcon(getClass().getResource("/resources/16x16/folder_delete.png"))); removeNodeMenuItem.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { removeNode(selectedNodeList, selectedNodeIndex); } }); //TODO properly implement //Add everything to node menu nodePopUp.add(expandNodeMenuItem); nodePopUp.add(foldNodeMenuItem); nodePopUp.add(removeNodeMenuItem); nodePopUp.addSeparator(); nodePopUp.add(makeDirMenuItem); //nodePopUp.add(cutMenuItem); //nodePopUp.add(copyMenuItem); //nodePopUp.add(pasteMenuItem); //nodePopUp.add(renameMenuItem); nodePopUp.addSeparator(); nodePopUp.add(removeDirMenuItem); nodePopUp.add(deleteMenuItem); //Instantiate other values: showHitBox = false; showHiddenFiles = false; rClickPoint = new Point(); selectedNodeList = new ArrayList(); selectedNodeIndex = 0; ext = new Extensions(); ext.addExtensionList(new File((getClass().getResource("/resources/photosExt.txt")).getPath()), "Photos"); ext.addExtensionList(new File((getClass().getResource("/resources/musicExt.txt")).getPath()), "Music"); ext.addExtensionList(new File((getClass().getResource("/resources/videoExt.txt")).getPath()), "Video"); ext.addExtensionList(new File((getClass().getResource("/resources/documentsExt.txt")).getPath()), "Documents"); } protected void makeDir(ArrayList selectedNodeList2, int selectedNodeIndex) { SFTPNodeItem parent = selectedNodeList2.get(selectedNodeIndex); if(!parent.isDirectory()) { selectedNodeList2 = parent.getParentList(); selectedNodeIndex = parent.getParentIndex(); parent = selectedNodeList2.get(selectedNodeIndex); } String dirname = JOptionPane.showInputDialog(null, "New Directory", "Name of directory", JOptionPane.QUESTION_MESSAGE); String path = parent.getPath(); path += "/" + dirname; SFTPv3FileAttributes parentAttributes = parent.getEntry().attributes; String perm = parentAttributes.getOctalPermissions(); perm = perm.substring(3, 6); try { client.mkdir(path, Integer.parseInt(perm)); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(sb, new JLabel("Bad Permissions" + eol + e.getMessage()), "Number Format Exception", JOptionPane.WARNING_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog(sb, new JLabel("An I/O Error has occured." + eol + e.getMessage()), "I/O Error", JOptionPane.WARNING_MESSAGE); } } protected void removeDir(ArrayList selectedNodeList2, int selectedNodeIndex) { int result = JOptionPane.showConfirmDialog(this, new JLabel("Remove Directory?"), "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (result == JOptionPane.YES_OPTION) { try { client.rmdir(selectedNodeList2.get(selectedNodeIndex).getPath()); } catch (IOException e) { JOptionPane.showMessageDialog(sb, new JLabel("An I/O Error has occured." + eol + e.getMessage()), "I/O Error", JOptionPane.WARNING_MESSAGE); } } } /** * Custom paintComponent method to draw all components within * this panel * * @param Graphics component to draw */ @Override protected void paintComponent(Graphics g) { //Set Graphics2d for additional graphical painting super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); //If the user does not want the hidden files shown. Paint the following way. //Paint Nodes and selected attributes for(int i = 0; i < nodeList.size(); i++) { //Draw child node lines, draw them first so that the lines are behind icons ArrayList childNodes = nodeList.get(i).getChildNodes(); if(childNodes.size() > 0) { for(int x = 0; x < childNodes.size(); x++) { //The actual drawing of the line. g.drawLine(nodeList.get(i).getX()+((nodeList.get(i).gethbSize())/2), nodeList.get(i).getY()+((nodeList.get(i).gethbSize())/2), childNodes.get(x).getX()+((childNodes.get(x).gethbSize())/2), childNodes.get(x).getY()+((childNodes.get(x).gethbSize())/2)); //Set the chileNodes line instance variable to specific coordinates //because g.drawLine does not return a modifiable line, it simply draws one. //The line object will be used to find where it intersects with a hitbox. Line2D childLine = childNodes.get(x).getLine(); childLine.setLine((double)nodeList.get(i).getX()+((nodeList.get(i).gethbSize())/2), (double)nodeList.get(i).getY()+((nodeList.get(i).gethbSize())/2), (double)childNodes.get(x).getX()+ ((childNodes.get(x).gethbSize())/2), (double)childNodes.get(x).getY() + ((childNodes.get(x).gethbSize())/2)); //The HitBox's (x,y) position is referring to the top //left corner of the HitBox. CalculateArrowHead theArrowHead = new CalculateArrowHead(childNodes.get(x).getHitBox(), childNodes.get(x).getLine(), 130, 15); childNodes.get(x).setArrowHead(theArrowHead.makeArrow()); g.fillPolygon(childNodes.get(x).getArrowHead()); g.drawPolygon(childNodes.get(x).getArrowHead()); } } //Draw node image //TODO figure out what observer is for g.drawImage(nodeList.get(i).getIcon(), nodeList.get(i).getX(), nodeList.get(i).getY(), nodeList.get(i).gethbSize(), nodeList.get(i).gethbSize(), this); //Draw hit box if(showHitBox){ g2d.draw(nodeList.get(i).getHitBox()); } //Draw file/directory name label g.drawString(nodeList.get(i).getFile(), nodeList.get(i).getX(), nodeList.get(i).getY()+(nodeList.get(i).gethbSize())+12); } } /** * Update position of a selected Node to the new position using * point given. Acts for dragging with mouse * * @return Point to where Node needs to be moved to */ public void updatePosition(Point p) { int index = 0; ArrayList list = nodeList; boolean selected = false; for(int i = 0; i < nodeList.size(); i++) { if(nodeList.get(i).isSelected()) { index = i; selected = true; break; } } if(selected) { //Boundary + Collision Checker //TODO fix invisible wall error //TODO non-hard-coded way //Rectangle bounds = (Rectangle) this.getBounds().clone(); //Rectangle bounds = new Rectangle(0, 0, 2000, 2000); //bounds.grow(-5, -5); boolean collision = false; //TODO fix collision detection //possibly use separating axis test /*Rectangle newHitBox = (Rectangle) nodeList.get(index).getHitBox().clone(); Rectangle newHitBoxX = new Rectangle((int)(newHitBox.getX()+p.getX()), (int)newHitBox.getY(), nodeList.get(index).gethbSize(), nodeList.get(index).gethbSize()); Rectangle newHitBoxY = new Rectangle(((int)newHitBox.getX()), (int)(newHitBox.getY()+p.getY()), nodeList.get(index).gethbSize(), nodeList.get(index).gethbSize()); for(int i = 0; i < nodeList.size(); i++) { if(i != index) { if(nodeList.get(i).getHitBox().intersects(newHitBoxX) || nodeList.get(i).getHitBox().intersects(newHitBoxY)) { collision = true; } } }*/ //TODO fix bounds for hit detection if(!collision){ //if(bounds.contains(nodeList.get(index).getX()+(int)p.getX(),10)) //{ list.get(index).setPosition((int)p.getX(), list.get(index).getY()); //} //if(bounds.contains(10, nodeList.get(index).getY()+(int)p.getY())) //{ list.get(index).setPosition(list.get(index).getX(), (int)p.getY()); //} } } else { JScrollPane scroll = sb.getScrollPane(); JScrollBar vScroll = scroll.getVerticalScrollBar(); JScrollBar hScroll = scroll.getHorizontalScrollBar(); int x = (int) (p.getX() - initialClick.getX()); int y = (int) (p.getY() - initialClick.getY()); vScroll.setValue(vScroll.getValue() - (int) (y / 15)); hScroll.setValue(hScroll.getValue() - (int) (x / 15)); } } /** * Check if a point is within a node's hit box * If true, the node is considered selected * Else, the node is unselected * For use to see if a node is clicked on * * @param Point of where the mouse clicked */ public void checkNodeClick(Point p){ initialClick = p; for(int i = 0; i < nodeList.size(); i++) { if(nodeList.get(i).getHitBox().contains(p)) { nodeList.get(i).selectNode(); } else { nodeList.get(i).unselectNode(); } } } /** * Check if a node has been double clicked * If true, the node is expanded * * @param Point of where the mouse clicked */ public void checkNodeDoubleClick(Point p) { for(int i = 0; i < nodeList.size(); i++) { if(nodeList.get(i).getHitBox().contains(p)) { if(nodeList.get(i).isExpanded()) { foldNode(nodeList, i); } else { expandNode(nodeList, i); } repaint(); } } } /** * Removes a node and its entire child tree from the workspace * * @param ArrayList that contains node to be folded * @param int index of the Node in the given ArrayList */ private void removeNode(ArrayList selectedNodeList2, int index) { //Remove all child nodes recursively removeAllChildNodes(selectedNodeList2, index); //Remove node from associated parent node if it has one if(selectedNodeList2.get(index).getParentIndex() != -1) { SFTPNodeItem parent = selectedNodeList2.get(index).getParentList().get(selectedNodeList2.get(index).getParentIndex()); parent.removeChildNode(selectedNodeList2.get(index)); } //Remove the node itself last selectedNodeList2.remove(index); } /** * Removes all child nodes from the given list * and recursively goes through child node list * to remove the entire tree below given node * * @param ArrayList that contains node to be removed * @param int index of the Node in the given ArrayList */ private void removeAllChildNodes(ArrayList selectedNodeList2, int index) { ArrayList childNodes = selectedNodeList2.get(index).getChildNodes(); if(childNodes.size() > 0) { for(int i = 0; i < childNodes.size(); i++) { if(childNodes.get(i).getChildNodes().size() > 0) { removeAllChildNodes(childNodes, i); } //Fold the node foldNode(childNodes, i); } } //Once all others have been folded, fold the given node foldNode(selectedNodeList2, index); } /** * Folds a node by grabbing a list of all child nodes * within the Node Item's directory and removing them from the * frame's list of nodes then removes the child nodes * * @param ArrayList that contains node to be folded * @param int index of the Node in the given ArrayList */ private void foldNode(ArrayList selectedNodeList2, int index) { if(selectedNodeList2.get(index).isDirectory()) { //Set expand to false so that it can be expanded selectedNodeList2.get(index).setExpanded(false); ArrayList childNodes = selectedNodeList2.get(index).getChildNodes(); for(int i = 0; i < childNodes.size(); i++) { if(childNodes.get(i).getChildNodes().size() > 0) { foldNode(childNodes, i); } else { nodeList.remove(childNodes.get(i)); } } selectedNodeList2.get(index).clearChildNodes(); } } /** * Retrieves image resource from within jar/project * Just specify the path of the image resource to get * * @return String fName is the path to the image resource */ private Image getImage(String fName){ URL url = getClass().getResource(fName); ImageIcon icon = new ImageIcon(url); return icon.getImage(); } /** * Determines popup menu to display based on context * of mouse click location * * @param Component to draw on * @param Point at which to display popup */ public void showPopUp(Component e, Point p){ boolean node = false; for(int i = 0; i < nodeList.size(); i++) { if(nodeList.get(i).getHitBox().contains(p)) { setRClickPoint(p); node = true; //deleteMenuItem.setVisible(true); //cutMenuItem.setVisible(true); //copyMenuItem.setVisible(true); //pasteMenuItem.setVisible(true); //renameMenuItem.setVisible(true); //pasteMenuItem.setEnabled(false); if(nodeList.get(i).isDirectory()) { if(!FSUtil.getInstance().isClipBoardEmpty()) pasteMenuItem.setEnabled(true); //openMenuItem.setVisible(false); if(nodeList.get(i).isExpanded()) { expandNodeMenuItem.setVisible(false); foldNodeMenuItem.setVisible(true); } else { expandNodeMenuItem.setVisible(true); foldNodeMenuItem.setVisible(false); } makeDirMenuItem.setVisible(true); removeDirMenuItem.setVisible(true); } else { expandNodeMenuItem.setVisible(false); foldNodeMenuItem.setVisible(false); //openMenuItem.setVisible(true); makeDirMenuItem.setVisible(true); removeDirMenuItem.setVisible(false); } nodePopUp.show(e, (int)p.getX(), (int)p.getY()); selectedNodeIndex = i; selectedNodeList = nodeList; break; } } if(!node) { setRClickPoint(p); backgroundPopUp.show(e, (int)p.getX(), (int)p.getY()); } } /** * Returns an array list of all nodes within the panel * * @return Entire Node List within this panel */ public ArrayList getNodeList(){ return nodeList; } /** * Toggles boolean for displaying hit boxes * */ public void toggleShowHitBoxes(){ if(showHitBox) { showHitBox = false; } else showHitBox = true; } /** * Toggles boolean for displaying hidden files * */ public void toggleShowHiddenFiles() { if(showHiddenFiles) { showHiddenFiles = false; } else showHiddenFiles = true; } /** * Expands a node by grabbing a list of all files/directories * within a Node Item's directory and associates all new * NodeItem objects as child nodes of the expanded node as * well as adds NodeItems to the total nodeList for the frame * * @param ArrayList that contains node to be expanded * @param int index of the Node in the given ArrayList */ private void expandNode(ArrayList nodeList2, int index) { //Only expand for directories if(nodeList2.get(index).isDirectory()) { //Only expand once nodeList2.get(index).setExpanded(true); //Attempt to get list of files Vector fList = new Vector(); try { fList = client.ls(nodeList2.get(index).getPath()); //TODO temporary square view; use until we have a //setting variable to determine how to space new node items int rowOffset = 40; int columnOffset = 40; int counter = 0; SFTPNodeItem tNode; for(int i = 0; i < fList.size(); i++){ SFTPv3DirectoryEntry item = (SFTPv3DirectoryEntry) fList.elementAt(i); tNode = new SFTPNodeItem(item.filename); nodeList.add(tNode); int tIndex = nodeList.indexOf(tNode); //Set hbsize and position nodeList.get(tIndex).sethbSize(32); nodeList.get(tIndex).setPosition(nodeList2.get(index).getX()+columnOffset, nodeList2.get(index).getY()+rowOffset); //Set icon if(item.attributes.isDirectory()) { nodeList.get(tIndex).setIcon(getImage("/resources/32x32/folder.png")); nodeList.get(tIndex).setDirectory(true); } else { String name = nodeList.get(tIndex).getFile(); String path = ext.getExtensionIcon(name); nodeList.get(tIndex).setIcon(getImage(path)); } //Add child node and set parent nodeList2.get(index).addChildNode(nodeList.get(tIndex)); nodeList.get(tIndex).setParentNode(nodeList, index); String pa = nodeList.get(tIndex).getParentList().get(nodeList.get(tIndex).getParentIndex()).getPath() + "/" + nodeList.get(tIndex).getFile(); nodeList.get(tIndex).setPath(pa); nodeList.get(tIndex).setEntry(item); //TODO increases temporary offset if(counter == 9) { columnOffset = 40; rowOffset += 40; counter = 0; } else { counter++; columnOffset += 40; rowOffset += 20; } } } catch (IOException e) { JOptionPane.showMessageDialog(sb, new JLabel("An I/O Error has occured." + eol + e.getMessage()), "I/O Error", JOptionPane.WARNING_MESSAGE); } } else { //TODO fix //SFTPFile temp = nodeList2.get(index).getFile(); //sb.terminalMessage("Double clicked: " + temp.getName()); } } /** * Sets point where a right clicked occured * * @param Point where click occured */ public void setRClickPoint(Point p) { rClickPoint = p; } public Connection getConnection() { return conn; } public Session getSession() { return sess; } public SFTPv3Client getClient() { return client; } }