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.Diagram; 030 import org.objectweb.jac.ide.Instance; 031 032 public class NewInstanceFigureCreationTool extends CreationTool { 033 034 DisplayContext context; 035 int count=0; 036 037 public NewInstanceFigureCreationTool(DrawingEditor newDrawingEditor, 038 DisplayContext context) { 039 super(newDrawingEditor); 040 this.context = context; 041 } 042 043 Point anchorPoint; 044 045 public void mouseDown(MouseEvent e, int x, int y) { 046 anchorPoint = new Point(x,y); 047 EventHandler.get().onInvoke( 048 context, 049 new InvokeEvent( 050 null, 051 this, 052 ClassRepository.get().getClass(getClass()) 053 .getMethod("createNewInstance(java.lang.String)"))); 054 // (view().add(getCreatedFigure())).displayBox(anchorPoint, anchorPoint); 055 } 056 057 public void mouseUp(MouseEvent e, int x, int y) { 058 } 059 060 public void createNewInstance(String name) { 061 if(name!=null) { 062 GenericObjectFigure cf = null; 063 Instance substance = new Instance(); 064 org.objectweb.jac.ide.GenericFigure figure = new org.objectweb.jac.ide.GenericFigure(substance); 065 substance.setName(name); 066 Diagram diagram = (Diagram)((DiagramView)editor()).getSubstance(); 067 diagram.addFigure(figure); 068 diagram.getContainer().addInstance(substance); 069 cf = new GenericObjectFigure(figure,diagram.getContainer(), 070 ((DiagramView)editor()).view()); 071 (view().add(cf)).displayBox(anchorPoint, anchorPoint); 072 } 073 editor().toolDone(); 074 } 075 076 } 077 078