/** * Returns the deep copy of node */ public FavoritesNode getDeepCopy(){ return new FavoritesNode((FavoritesItem)item.clone()); /* FavoritesNode copy = null; ObjectOutputStream out = null; ObjectInputStream in = null; try{ ByteArrayOutputStream bOut = new ByteArrayOutputStream(); out = new ObjectOutputStream(bOut); out.writeObject(this); out.flush(); in = new ObjectInputStream(new ByteArrayInputStream(bOut.toByteArray())); copy =(FavoritesNode) in.readObject(); out.close(); in.close(); }catch(Exception e){ System.err.println(e); } return copy; */ }
topNode.removeAllChildren(); rootNode = favNode.getDeepCopy(); while (favNode.getChildCount() > 0) { topNode.add((DefaultMutableTreeNode)favNode.getFirstChild());
TreeNode paren = getParent(); FavoritesItem item = (FavoritesItem)getUserObject(); writer.write(getOffset()+"<"+getXMLElement()+ " text=\""+item.getName()+"\" "); String target = item.getTarget(); if(target != null) if(hstitle != null) writer.write(" hstitle=\""+hstitle+"\""); Enumeration chldn = children(); if(chldn.equals(DefaultMutableTreeNode.EMPTY_ENUMERATION)) writer.write("/>\n"); while(offspring.hasMoreElements()){ FavoritesNode off = (FavoritesNode)offspring.nextElement(); debug("offspring: "+off); off.exportNode(writer); writer.write(getOffset()+"</"+ELEMENT+">\n");
/** * Exports nodes descendants to the OutputStream * * @param out The OutputStream */ public void export(OutputStream out) throws IOException{ OutputStreamWriter writer = new OutputStreamWriter(out); writer = exportHeader(out); //exportNode(writer); Enumeration chldn = children(); if(!(chldn.equals(DefaultMutableTreeNode.EMPTY_ENUMERATION))){ while(chldn.hasMoreElements()){ FavoritesNode node = (FavoritesNode)chldn.nextElement(); node.exportNode(writer); } } writer.write(FOOTER); //out.close(); writer.close(); }
if(rootParent.getChildCount() == 0) place = 0; else{ for(Enumeration en = rootParent.children(); en.hasMoreElements();){ FavoritesNode node = (FavoritesNode)en.nextElement(); if(node.isVisible()){ debug("is visible : "+node); place = rootParent.getIndex(node); break; FavoritesNode copy = ((FavoritesNode) nodes[j]).getDeepCopy(); rootParent.insert((DefaultMutableTreeNode)copy,place); connections.put((FavoritesNode)nodes[j],copy); FavoritesNode nodeBefore = (FavoritesNode)parent.getChildAt(firstIndex - 1); FavoritesNode rootNode = (FavoritesNode)connections.get(nodeBefore); place = rootParent.getIndex(rootNode)+1; for(int k = nodes.length - 1; k >= 0; k--){ FavoritesNode copyNode = ((FavoritesNode)nodes[k]).getDeepCopy(); rootParent.insert((DefaultMutableTreeNode)copyNode,place); connections.put((FavoritesNode)nodes[k],copyNode);
for(Enumeration children = node.preorderEnumeration();children.hasMoreElements();){ FavoritesNode chnode = (FavoritesNode)children.nextElement(); FavoritesNode copy = chnode.getDeepCopy(); FavoritesNode rootParent = (FavoritesNode)connections.get(chnode.getParent()); if (rootParent == null) { rootParent = rootNode; rootParent.add(copy); FavoritesItem item = (FavoritesItem)chnode.getUserObject(); debug("classify item: "+ item); String hsTitle = item.getHelpSetTitle(); if(!hsMap.containsKey(hsTitle)){ if(chnode.getVisibleChildCount() == 0){ if(item.emptyInitState() && item.isFolder()){ debug("empty init state"); Enumeration nodesToRem = node.breadthFirstEnumeration(); while(nodesToRem.hasMoreElements()) { FavoritesNode fn = (FavoritesNode)nodesToRem.nextElement(); if(!fn.isVisible()){ debug ("remove node:" +(FavoritesItem)fn.getUserObject()); toRemove.addElement(fn); debug("removing " + toRemove.elementAt(i)); try {
FavoritesNode oldParent = (FavoritesNode) getSelectedNode().getParent(); FavoritesItem selItem = (FavoritesItem) selNode.getUserObject(); FavoritesNode newNode = selNode.getDeepCopy(); FavoritesNode newChild = new FavoritesNode(childInfo); debug("new child: "+newChild); try { FavoritesNode fromRootNode = (FavoritesNode)connections.get(getSelectedNode()); if(fromRootNode != null) fromRootNode.removeFromParent(); oldParent.remove(getSelectedNode()); if (!newParent.getAllowsChildren()){ TreeNode parent = newParent.getParent(); if(parent != null){ int index = parent.getIndex(newParent); model.insertNodeInto(newNode,newParent,newParent.getChildCount()); FavoritesItem newItem = (FavoritesItem) newNode.getUserObject(); dataMap.put(newItem, hashCandidate); DefaultTreeModel model = (DefaultTreeModel) getModel(); model.reload(oldParent); model.reload(newParent); TreePath parentPath = new TreePath(newParent.getPath()); expandPath(parentPath);
public void actionPerformed(ActionEvent ev){ debug("paste"); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); TreePath path = tree.getSelectionPath(); FavoritesNode node = (FavoritesNode)path.getLastPathComponent(); if(node != null){ if(node.getAllowsChildren()){ for(Enumeration nodes = nodeClipboard.elements(); nodes.hasMoreElements();){ model.insertNodeInto((DefaultMutableTreeNode)nodes.nextElement(),(DefaultMutableTreeNode)node,node.getChildCount()); } } else{ DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent(); if(parent == null) return; int index = parent.getIndex(node); for(Enumeration en = nodeClipboard.elements(); en.hasMoreElements();index++){ model.insertNodeInto((DefaultMutableTreeNode)en.nextElement(),parent,index); } } saveFavorites(); } } }
public void actionPerformed(ActionEvent ev){ FavoritesItem favoriteFolder = new FavoritesItem(HelpUtilities.getString(locale, "favorites.folder")); favoriteFolder.setAsFolder(); FavoritesNode node = new FavoritesNode(favoriteFolder); TreePath nodePath = tree.getSelectionPath(); TreeNode parent = null; if(nodePath == null) parent = topNode; else{ FavoritesNode selNode = (FavoritesNode)nodePath.getLastPathComponent(); parent = selNode.getParent(); } DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); model.insertNodeInto(node,(DefaultMutableTreeNode)parent,parent.getChildCount()); TreePath path = new TreePath(node.getPath()); tree.expandPath(path); tree.setSelectionPath(path); tree.scrollPathToVisible(path); saveFavorites(); } }
dataMap.put(favorite,ID); FavoritesNode node = new FavoritesNode(favorite); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); model.insertNodeInto(node, topNode, topNode.getChildCount()); TreePath path = new TreePath(node.getPath()); tree.expandPath(path); tree.setSelectionPath(path);
FavoritesNode node = new FavoritesNode((FavoritesItem)item); FavoritesNode parent = (FavoritesNode) nodeStack.peek(); parent.add(node); if (! tag.isEmpty) { itemStack.push(item);
/** * Saves favorites file * * @param node The FavoritesNode */ public void saveFavorites(FavoritesNode node){ if(!enabledSave) return; try{ FileOutputStream out; String user_dir = System.getProperty("user.home"); File file = new File(user_dir+File.separator+".JavaHelp"); file.mkdirs(); String userFile = file.getPath()+File.separator+"Favorites.xml"; debug("new file:"+userFile); node.export(out = new FileOutputStream(userFile)); out.close(); }catch(SecurityException se){ enabledSave = false; se.printStackTrace(); }catch(Exception excp){ excp.printStackTrace(); } } /**
/** * Parse a reader into a DefaultMutableTreeNode. * Only one of these at a time. */ synchronized FavoritesNode parse(Reader src, HelpSet context, Locale locale) throws IOException { nodeStack = new Stack(); itemStack = new Stack(); tagStack = new Stack(); if (locale == null) { defaultLocale = Locale.getDefault(); } else { defaultLocale = locale; } lastLocale = defaultLocale; FavoritesNode node = new FavoritesNode(new FavoritesItem("Favorites")); nodeStack.push(node); currentParseHS = context; Parser parser = new Parser(src); // the XML parser instance parser.addParserListener(this); parser.parse(); return node; }
File file = new File(user_dir+File.separator+".JavaHelp"+File.separator+"Favorites.xml"); if(!file.exists()) return new FavoritesNode(new FavoritesItem("Favorites")); try{ url = file.toURL();
topNode = new FavoritesNode(new FavoritesItem("Favorites")); if (on1dot3) {