Package edu.harvard.wcfia.yoshikoder.dictionary

Examples of edu.harvard.wcfia.yoshikoder.dictionary.Node


    }

    protected void recurse(Map nameToNodes, Node node){
        if (node instanceof CategoryNode){
            for (Enumeration en = node.children(); en.hasMoreElements();){
                Node n = (Node)en.nextElement();
                recurse(nameToNodes, n);
            }
        } else {
            String nodeName = node.getName();
            List l = (List)nameToNodes.get(nodeName);
View Full Code Here


    }
   
    public void actionPerformed(ActionEvent e) {
        YKDictionary dict = yoshikoder.getDictionary();
        Map nameToNodes = new HashMap();
        Node root = dict.getDictionaryRoot();
        recurse(nameToNodes, root); // full nameToNodes
        StringBuffer sb = new StringBuffer();
        int duplicatePatterns = 0;
        for (Iterator iter = nameToNodes.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry)iter.next();
            List l = (List)entry.getValue();
            if (l.size() > 1){
                duplicatePatterns++;
                sb.append("\"" + (String)entry.getKey() + "\" appears in categories:\n");
                for (Iterator iterator = l.iterator(); iterator.hasNext();) {
                    Node node = (Node) iterator.next();
                    TreePath path = dict.getPath((Node)node.getParent());
                    sb.append("\t" + path.getPathComponent(0).toString());
                    for (int ii = 1; ii < path.getPathCount(); ii++) {
                        sb.append(">" + path.getPathComponent(ii).toString()); // path
                    }
                    sb.append("\n");
View Full Code Here

           
            if ((doc1 == null) || (doc2 == null)){
                return;           
            }
           
            Node n = yoshikoder.getSelectedNode();
            CategoryNode cnode = null;
            if (n instanceof CategoryNode)
              cnode = (CategoryNode)n;
            else // patternnode
              cnode = (CategoryNode)n.getParent();
            final CategoryNode catnode = cnode;
           
            dworker = new DialogWorker(yoshikoder){
                protected void doWork() throws Exception {
                    DocumentList dl = new DocumentListImpl();
View Full Code Here

    public void dragEnter(DropTargetDragEvent dtde) {
        dragOver(dtde);
    }

    public void dragOver(DropTargetDragEvent dtde) {
        Node node = getNodeForEvent(dtde);
        if (node instanceof PatternNode)
            dtde.rejectDrag();
        else
            dtde.acceptDrag(DnDConstants.ACTION_MOVE);
    }
View Full Code Here

        TreePath parentpath = targetTree.getClosestPathForLocation(pt.x, pt.y);

        // For simplicity's sake, we'll assume that the tree uses the
        // DefaultTreeModel
        // and DefaultMutableTreeNode classes.
        Node parent = (Node)parentpath.getLastPathComponent();

        // Now check to see if it was dropped on a folder. If not, reject it.
        if (parent instanceof PatternNode) {
            dtde.rejectDrop();
            return;
        }

        try {
            // Grab the data.
            Transferable tr = dtde.getTransferable();
            DataFlavor[] flavors = tr.getTransferDataFlavors();
            for (int i = 0; i < flavors.length; i++) {
                if (tr.isDataFlavorSupported(flavors[i])) {
                    // It's a usable node, so pull it out of the transferable
                    // object and add it
                    // to our tree.
                    dtde.acceptDrop(DnDConstants.ACTION_MOVE);
                    TreePath p = (TreePath)tr.getTransferData(flavors[i]);
                    Node node = (Node)p.getLastPathComponent();
                    YKDictionary dict = (YKDictionary)targetTree.getModel();
                    if (node instanceof PatternNode)
                        dict.addPattern((PatternNode)node, (CategoryNode)parent);
                    else if (node instanceof CategoryNode)
                      dict.addCategory((CategoryNode)node, (CategoryNode)parent);   
View Full Code Here

    }

    protected TreePath getTreePath(Node n){
        List l = new ArrayList();
        l.add(n);
        Node parent = n;
        while ((parent = (Node)parent.getParent()) != null)
            l.add(0, parent);
        return new TreePath( l.toArray(new Node[l.size()]) );
    }
View Full Code Here

            boolean sel, boolean expanded, boolean leaf, int row,
            boolean focus) {

        super.getTreeCellRendererComponent(tree, value, sel, expanded,
                leaf, row, hasFocus);
        Node n = (Node)value;
        if (n instanceof PatternNode)
            setIcon(patternIcon);
        else
            if (expanded)
                setIcon(categoryOpenIcon);
            else
                setIcon(categoryClosedIcon);
        setToolTipText(n.getPopup());

        return this;
    }
View Full Code Here

            CategoryNode cn = (CategoryNode)n;          
            sb.append(toHTML(cn));
            sb.append("<ul>\n");
            Enumeration<Node> en = cn.children();
            while (en.hasMoreElements()){
                Node child = en.nextElement();
                recurseHTML(child, sb);
            }
            sb.append("</ul>\n");
        } else {
            PatternNode pn = (PatternNode)n;
View Full Code Here

        if (n instanceof CategoryNode){
            CategoryNode cn = (CategoryNode)n;
            sb.append(toXML(cn));
            Enumeration<Node> en = cn.children();
            while (en.hasMoreElements()){
                Node child = en.nextElement();
                recurse(child, sb);
            }
            sb.append("</cnode>\n");
        } else {
            PatternNode pn = (PatternNode)n;
View Full Code Here

    public void endElement(String uri, String localName, String qName)
      throws SAXException{
   
        if (qName.equals("name")){ //$NON-NLS-1$
            String name = sb.toString();
            Node node = (Node)stack.peek();
            node.setName(name);
           
            if (inPattern){
                try {
                    PatternNode pn = (PatternNode)node;
                    Pattern p = engine.makeRegexp(name); // because there will be only one word in it
                    pn.setPattern(p);
                } catch (PatternSyntaxException pse){
                    throw new SAXException(pse);
                }
            }
       
        } else if (qName.equals("score")){ //$NON-NLS-1$
            String score = sb.toString();
            try {
                double d = Double.parseDouble(score);
                Node node = (Node)stack.peek();
                node.setScore(new Double(d));
            } catch (NumberFormatException nfe){
                throw new SAXException(nfe);
            }
           
        } else if (qName.equals("comment")){ //$NON-NLS-1$
            CategoryNode node = (CategoryNode)stack.peek();
            node.setDescription(sb.toString());
           
        } else if (qName.equals("category")){ //$NON-NLS-1$
          stack.pop();
     
        } else if (qName.equals("pattern")){ //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of edu.harvard.wcfia.yoshikoder.dictionary.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.