Exemplo n.º 1
0
private void ConvertOutput (StringBuffer ostr, CGNode node)
    {
	node.SortChilds ();
        String s = node.GetText();

        if (node.IsConcept()) {
            ostr.append ("[" + s + "]");
        } else {
            ostr.append ("(" + s + ")");
        }

        int nchilds = node.NumChilds();
        if (nchilds == 1) {
            ostr.append ("->");
            ConvertOutput (ostr, node.ChildAt (0));
        } else if (nchilds > 1) {
            ostr.append ("-");
            for (int i = 0; i < nchilds; ++i) {
                ostr.append ("->");
                ConvertOutput (ostr, node.ChildAt (i));
                if (i+1 != nchilds)
                    ostr.append (",");
            }
            ostr.append (".");
        }
    }
Exemplo n.º 2
0
private void RemoveFromCanvas (CGNode root)
    {
	super.Remove (root);
	for (int i = root.NumChilds()-1; i >= 0; --i) {
	    super.Remove (root.ArrowAt(i));
	    RemoveFromCanvas (root.ChildAt(i));
	}
    }
Exemplo n.º 3
0
private void LayoutPass2 (CGNode root, int x, Vector vdist, int level)
    {
	Rectangle bbox = root.Bbox();
	int width = ((Integer)vdist.elementAt(level)).intValue();
	root.MoveTo (x + (width - bbox.width)/2, root.layout_y);

	int nchilds = root.NumChilds();
	for (int i = 0; i < nchilds; ++i) {
	    LayoutPass2 (root.ChildAt(i), x+width+layoutXDist, vdist, level+1);
	}
    }
Exemplo n.º 4
0
private int LayoutPass1 (CGNode root, int y, Vector vdist, int level)
    {
	Rectangle bbox = root.Bbox();
	root.layout_y = y;
	root.SortChilds ();

	if (level >= vdist.size()) {
	    vdist.addElement (new Integer (bbox.width));
	} else {
	    int width = ((Integer)vdist.elementAt(level)).intValue();
	    if (width < bbox.width) {
		vdist.setElementAt (new Integer (bbox.width), level);
	    }
	}
	int nchilds = root.NumChilds(), y2 = y;
	for (int i = 0; i < nchilds; ++i) {
	    y2 = LayoutPass1 (root.ChildAt(i), y2, vdist, level+1);
	}
	return Math.max (y + bbox.height + layoutYDist, y2);
    }
Exemplo n.º 5
0
private void Pick (MouseEvent ev)
    {
	if (state != stateIdle)
	    return;

	CGNode node = null;
	try {
	    CanvasObject co = super.Find (ev.getX(), ev.getY());
	    if (co instanceof CGNode) {
		node = (CGNode)co;
	    }
	} catch (NoSuchElementException ex) {}

        if (node != null && node.IsConcept() &&
            (ev.getModifiers() & Event.META_MASK) != 0) {
            // template menu

            MenuPopup (ev, node);
        } else {
            switch (ev.getModifiers() & (Event.SHIFT_MASK | Event.CTRL_MASK)) {
            case Event.SHIFT_MASK:
                // edit
                if (node != null) {
		    String s = node.GetInst();
		    if (s != null) {
			curnode = node;
			Edit (s);
		    }
                }
                break;

            case Event.CTRL_MASK:
                // drag
                if (node != null) {
                    state = stateDrag;
                    ToTop (node);
                    curnode = node;
                    dragx = ev.getX();
                    dragy = ev.getY();
                }
                break;

            case Event.SHIFT_MASK|Event.CTRL_MASK:
                // delete subtree
                if (node != null) {
		    // ZZZ only allowed for relations or topnode
		    if (node.IsConcept() && node != topnode)
			break;
                    CGNode parent = node.GetParent ();
                    if (parent == null || parent.IsConcept() ||
                        parent.NumChilds() > 1) {
                        
                        AutoUpdateOff ();
                        if (parent != null) {
                            parent.DelChild (node);
                            Remove (node.GetParentArrow());
                        }
                        RemoveFromCanvas (node);
                        AutoUpdateOn ();
                    }
                    if (node == topnode)
                        topnode = null;
                    NotifyViewers();
                }
                break;

            default:
                if (node == null && topnode == null) {
		    // create topnode
                    topnode = new CGNode (ev.getX(), ev.getY(),
					  "OPERATION:deposit",
                                          getFontMetrics (getFont()),
                                          true);
                    Add (topnode);
                    NotifyViewers ();
                } else if (node != null) {
		    // ZZZ drag
                    state = stateDrag;
                    ToTop (node);
                    curnode = node;
                    dragx = ev.getX();
                    dragy = ev.getY();
		}
		/*
		 * ZZZ creating subnodes not allowed
		else if (node != null && topnode != null) {
                    state = stateCreate;
                    curnode = node;
                    
                    Rectangle pos = node.Bbox();
                    curarrow = new CGArrow (pos.x+pos.width-1,
                                            pos.y+pos.height/2,
                                            ev.x, ev.y);
                    Add (curarrow);
                }
		*/
                break;
            }
        }
    }