001    /*
002      Copyright (C) 2002 Renaud Pawlak <renaud@aopsys.com>
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public
015      License along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017    */
018    
019    package org.objectweb.jac.ide.diagrams;
020    
021    
022    import CH.ifa.draw.framework.DrawingEditor;
023    import java.awt.Point;
024    import java.awt.event.MouseEvent;
025    import org.objectweb.jac.aspects.gui.DisplayContext;
026    import org.objectweb.jac.aspects.gui.EventHandler;
027    import org.objectweb.jac.aspects.gui.InvokeEvent;
028    import org.objectweb.jac.core.rtti.ClassRepository;
029    import org.objectweb.jac.ide.Aspect;
030    import org.objectweb.jac.ide.Diagram;
031    import org.objectweb.jac.util.Log;
032    
033    public  class AspectFigureCreationTool extends CreationTool {
034    
035       DisplayContext context;
036    
037       public AspectFigureCreationTool(DrawingEditor newDrawingEditor, 
038                                      DisplayContext context) {
039          super(newDrawingEditor);
040          this.context = context;
041       }
042    
043       Point anchorPoint;
044    
045       /**
046        * Creates a new figure by cloning the prototype.
047        */
048       public void mouseDown(MouseEvent e, int x, int y) {
049          anchorPoint = new Point(x,y);
050          EventHandler.get().onInvoke(
051             context,
052             new InvokeEvent(
053                 null, 
054                 this, 
055                 ClassRepository.get().getClass(getClass())
056                 .getMethod("importAspect(org.objectweb.jac.ide.Aspect)")));
057             // (view().add(getCreatedFigure())).displayBox(anchorPoint, anchorPoint);
058       }
059    
060       /**
061        * Checks if the created figure is empty. If it is, the figure
062        * is removed from the drawing.
063        * @see Figure#isEmpty
064        */
065       public void mouseUp(MouseEvent e, int x, int y) {
066       }
067    
068       public void importAspect(Aspect cl) {
069          Log.trace("figures","createFigure for "+cl);
070          if (cl!=null) {
071             AspectFigure cf = null;
072             org.objectweb.jac.ide.ClassFigure figure = 
073                new org.objectweb.jac.ide.ClassFigure(cl);
074             Diagram diagram = (Diagram)((DiagramView)editor()).getSubstance();
075             diagram.addFigure(figure);
076             Log.trace("diagram","creating new figure "+figure+","+
077                       diagram.getContainer());
078             cf = new AspectFigure(figure,diagram.getContainer(),
079                                   ((DiagramView)editor()).view());
080             (view().add(cf)).displayBox(anchorPoint, anchorPoint);
081          }
082          editor().toolDone();
083       }
084    
085    }
086    
087