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 USA. */ 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.Class; 030 import org.objectweb.jac.ide.Diagram; 031 032 public class NewClassFigureCreationTool extends CreationTool { 033 034 DisplayContext context; 035 int count = 0; 036 037 public NewClassFigureCreationTool(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(null, 050 this, 051 ClassRepository.get().getClass(getClass()) 052 .getMethod("createNewClass(java.lang.String)"))); 053 // (view().add(getCreatedFigure())).displayBox(anchorPoint, anchorPoint); 054 } 055 056 public void mouseUp(MouseEvent e, int x, int y) { 057 } 058 059 public void createNewClass(String name) { 060 if (name!=null) { 061 Class substance = new Class(); 062 substance.setName(name); 063 Diagram diagram = (Diagram)((DiagramView)editor()).getSubstance(); 064 // Add the class to the package of the diagram 065 diagram.getContainer().addClass(substance); 066 // Add the class to the diagram 067 ((DiagramView)editor()).addClass(substance,anchorPoint); 068 } 069 editor().toolDone(); 070 } 071 } 072