Exemplo n.º 1
0
private void MenuPopup (MouseEvent ev, CGNode node)
    {
	if (!node.IsConcept())
	    return;

	String menuname = (String)menumap.get (node.GetType(true));
	if (menuname == null)
	    return;
	Hashtable templates = (Hashtable)menus.get (menuname);
	if (templates == null)
	    return;

	if( popup != null )
	  remove( popup );

	popup = new PopupMenu( menuname );
	
        Enumeration e = templates.keys();
        while (e.hasMoreElements()) {
            String key = (String)e.nextElement();
	    MenuItem mi = new MenuItem( key );
	    mi.setActionCommand( key );
	    mi.addActionListener( this );
	    popup.add( mi );
        }
        curnode = node;

	this.add( popup );

	popup.show( this, ev.getX(), ev.getY() );
    }
Exemplo n.º 2
0
private void ShowStatus (int x, int y)
    {
        String s = "";
        CGNode node = null;

        if (x >= 0 && y >= 0) {
            try {
                CanvasObject co = super.Find (x, y);
                if (co instanceof CGNode) {
                    node = (CGNode)co;
                }
            } catch (NoSuchElementException ex) {}

            if (node == null) {
                if (topnode == null)
                    s = "Button1: create";
            } else {
		s = "Button1: drag";
                if (node.IsConcept()) {
		    if (node.GetInst() != null)
			s += ", Shift-Button1: edit";
		    if (node == topnode)
			s += ", Shift-Ctrl-Button1: remove";
                    if (menumap.containsKey (node.GetType (true)))
                        s += ", Button3: menu";
                } else {
                    s += ", Shift-Ctrl-Button1: remove";
                }
            }
        }
	frame.status.setStatus (s);
    }
Exemplo n.º 3
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.º 4
0
private void Drop (MouseEvent ev)
    {
	switch (state) {
	case stateDrag:
	    state = stateIdle;
	    CheckResize ();
	    break;

	case stateCreate:
	    CGNode node = new CGNode (ev.getX(), ev.getY(), "something",
				      getFontMetrics (getFont()),
				      !curnode.IsConcept());
            curnode.AddChild (node, curarrow);
            node.SetParent (curnode, curarrow);
            ToBottom (curarrow);
            Add (node);

	    if (!node.IsConcept()) {
		int x = ev.getX() + node.Bbox().width + layoutXDist;
		CGNode node2 = new CGNode (x, ev.getY(), "something",
					   getFontMetrics (getFont()),
					   true);
		CGArrow arrow2 = new CGArrow (0, 0, 0, 0);
		node.AddChild (node2, arrow2);
		node2.SetParent (node, arrow2);
		Add (node2);
		Add (arrow2);
                ToBottom (arrow2);
	    }
            state = stateIdle;
            NotifyViewers();
            break;
	}
        ShowStatus (ev.getX(), ev.getY());
    }
Exemplo n.º 5
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.º 6
0
public void entryBoxHandler (EntryBox e, Object arg)
    {
	if (state != stateEdit)
	    return;
	state = stateIdle;
	if (e.GetButton() == 0) {
	    curnode.SetInst (e.GetText());
	    NotifyViewers();
	}
    }
Exemplo n.º 7
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.º 8
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.º 9
0
public void actionPerformed( ActionEvent e )
    {
        String s = e.getActionCommand();
        if (s == null)
            return;

	String menuname = (String)menumap.get (curnode.GetType(true));
	Hashtable templates = (Hashtable)menus.get (menuname);

        ConceptualGraph cg = (ConceptualGraph)templates.get(s);
        AutoUpdateOff ();
        CGNode top = ConvertInput (cg);
        CGArrow arrow = new CGArrow (0, 0, 0, 0);
        Add (arrow);
        ToBottom (arrow);
        curnode.AddChild (top, arrow);
        top.SetParent (curnode, arrow);
        Layout (curnode);
        AutoUpdateOn ();

        NotifyViewers ();
  }
Exemplo n.º 10
0
private CGNode ConvertInput (ConceptualGraph cg)
    {
        StringBuffer ostr = new StringBuffer();
        cg.getNode().print (ostr);
        String s = ostr.toString();
        s = s.substring (1, s.length()-1);

        CGNode node = new CGNode (0, 0, s, getFontMetrics(getFont()),
                                  cg.getNode() instanceof ConceptNode);
        Add (node);

        ConceptualGraph cg2;
        for (cg2 = cg.getWidth(); cg2 != null; cg2 = cg2.getDepth()) {
            CGNode node2 = ConvertInput (cg2);
            CGArrow arrow2 = new CGArrow (0, 0, 0, 0);
            Add (arrow2);
            ToBottom (arrow2);

            node.AddChild (node2, arrow2);
            node2.SetParent (node, arrow2);
        }
        return node;
    }
Exemplo n.º 11
0
private void Drag (MouseEvent ev)
    {
	switch (state) {
	case stateDrag:
            curnode.Move (ev.getX() - dragx, ev.getY() - dragy);
            dragx = ev.getX();
            dragy = ev.getY();
	    break;

	case stateCreate:
	    curarrow.MoveHeadTo (ev.getX(), ev.getY());
	    break;
        }
    }
Exemplo n.º 12
0
public void Layout (CGNode root)
    {
	int x, y;
	if (root == null) {
            if ((root = topnode) == null)
                return;
	    x = layoutXDist;
	    y = layoutYDist;
	} else {
	    x = root.Bbox().x;
	    y = root.Bbox().y;
	}
	AutoUpdateOff ();
	Vector vdist = new Vector();
	LayoutPass1 (root, y, vdist, 0);
	LayoutPass2 (root, x, vdist, 0);
	CheckResize ();
	AutoUpdateOn ();
    }
Exemplo n.º 13
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;
            }
        }
    }