package frame; import java.awt.Image; import java.awt.Point; import java.awt.Polygon; import java.awt.Rectangle; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import ch.ethz.ssh2.SFTPv3DirectoryEntry; //import java. /** * This class is for NodeItem objects. * Its attributes hold various information that each * Node within the mind map may or may not need * * @return */ public class SFTPNodeItem { //Class variables private String f; //File if it is a file private String path; private SFTPv3DirectoryEntry entry; private Point pos; //position of Node on the XY plane private int hbSize; //size of the icon hit box private Rectangle2D hitBox; //TODO change to Polygon.2D private Polygon arrowHead; private Line2D line; private Image nodeIcon; private boolean selected; private ArrayList childNodes; //List of child nodes connected to this node private boolean expanded; private boolean directory; private ArrayList parentNodeList; private int parentNodeIndex; private ArrayList contentPaneList; /** * Default constructor for a Node Item * Instantiates all variables * * @param File that the node represents */ public SFTPNodeItem(String inF) { //Instantiate variables here f = inF; path = ""; hbSize = 0; pos = new Point(0, 0); hitBox = new Rectangle(0, 0, hbSize, hbSize); line = new Line2D.Double(); childNodes = new ArrayList(); parentNodeList = new ArrayList(); contentPaneList = new ArrayList(); parentNodeIndex = -1; selected = false; expanded = false; directory = false; entry = new SFTPv3DirectoryEntry(); } /** * Set a new position for the Node * * @param int for x position * @param int for y position */ public void setPosition(int x, int y){ pos = new Point(x, y); updateHitBox(); } /** * Change the size of the Node's hit box * * @param int for size of hit box */ public void sethbSize(int a){ hbSize = a; updateHitBox(); } /** * Change the icon image of the Node * * @param Image to use for icon */ public void setIcon(Image ico){ nodeIcon = ico; } /** * Marks the Node as selected, i.e. it was clicked * */ public void selectNode(){ selected = true; } /** * Marks the Node as unselected, i.e. it was not clicked * */ public void unselectNode(){ selected = false; } /** * Adds a node to the ArrayList of childNodes * * @param NodeItem to add to the list of childNodes */ public void addChildNode(SFTPNodeItem a){ childNodes.add(a); } public void setParentNode(ArrayList list, int i) { parentNodeList = list; parentNodeIndex = i; } /** * Remove specified child node, if it exists, from childNodes arraylist * * Return may or may not be necessary? * * @return int that says whether or not it removed specified node, 0 OK, 1 for not */ public int removeChildNode(SFTPNodeItem sftpNodeItem){ if(childNodes.contains(sftpNodeItem)) { childNodes.remove(childNodes.indexOf(sftpNodeItem)); return 0; } return 1; } /** * Checks whether given point is on the edge of the hit box * * @param Point to check against hit box edge * @return boolean, true if on edge, else false */ public boolean onDragEdge(Point p) { Rectangle r = (Rectangle) hitBox.clone(); r.grow(3, 3); return r.contains(p); } /** * Resets hit box to be aligned with new position or size * */ public void updateHitBox(){ hitBox = new Rectangle((int)pos.getX(), (int)pos.getY(), hbSize, hbSize); } /** * Returns Node's associated file * * @return Node's File */ public String getFile(){ return f; } /** * Returns Node's x coordinate * * @return Node's x coordinate */ public int getX(){ return (int)pos.getX(); } /** * Returns Node's y coordinate * * @return Node's y coordinate */ public int getY(){ return (int)pos.getY(); } /** * Returns Node's hit box size * * @return Node's hit box size */ public int gethbSize(){ return hbSize; } /** * Returns Node's icon * * @return Image of Node's icon */ public Image getIcon(){ return nodeIcon; } /** * Returns boolean of Node selection * * @return boolean of Node selection */ public boolean isSelected() { return selected; } /** * Returns Node's hit box * * @return Rectangle of Node's hit box */ public Rectangle2D getHitBox(){ return hitBox; } /** * Returns Node's list of associated child nodes * * @return ArrayList of Node's childNodes */ public ArrayList getChildNodes(){ return childNodes; } /** * Change whether the node has been expanded * * @param Set expanded to given boolean */ public void setExpanded(boolean b) { expanded = b; } /** * Check whether the node has been expanded * * @return boolean expanded */ public boolean isExpanded() { return expanded; } /** * Get list that contains parent node * * @return Array list of node items that has the parent node */ public ArrayList getParentList() { return parentNodeList; } /** * Get index of parent node's location in list * * @return index of parent node */ public int getParentIndex() { return parentNodeIndex; } public ArrayList getContentPaneList() { return contentPaneList; } /** * Clears the childNodes array list * */ public void clearChildNodes() { childNodes.clear(); } public void setDirectory(boolean a) { directory = a; } public boolean isDirectory() { return directory; } public void setPath(String p) { path = p; } public String getPath() { return path; } public void setEntry(SFTPv3DirectoryEntry e) { entry = e; } public SFTPv3DirectoryEntry getEntry() { return entry; } /** * Returns the nodes line that connects to its parentNode. * @return The nodes line that connects to its parentNode. */ public Line2D getLine() { return line; } /** * Returns the instance variable arrowHead. * @return the arrowHead instance variable. */ public Polygon getArrowHead() { return arrowHead; } /** * * @param arrowHead The instance variable arrowHead will * be set to this parameter. */ public void setArrowHead(Polygon arrowHead) { this.arrowHead = arrowHead; } }