001 /* 002 Copyright (C) 2002-2003 Laurent Martelli <laurent@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 import CH.ifa.draw.framework.DrawingEditor; 022 import CH.ifa.draw.framework.Figure; 023 import CH.ifa.draw.standard.AbstractTool; 024 import org.objectweb.jac.aspects.gui.DisplayContext; 025 import java.awt.event.MouseEvent; 026 027 public abstract class AbstractActionTool extends AbstractTool { 028 029 protected DisplayContext context; 030 Class figureClass; 031 032 /** 033 * @param drawingEditor the editor the tool is attached to 034 * @param context the display context 035 * @param figureClass the type of figures the action applies to 036 */ 037 public AbstractActionTool(DrawingEditor drawingEditor, 038 DisplayContext context, 039 Class figureClass) { 040 super(drawingEditor); 041 this.context = context; 042 this.figureClass = figureClass; 043 } 044 045 /** 046 * Add the touched figure to the selection an invoke action 047 * @see #action 048 */ 049 public void mouseDown(MouseEvent e, int x, int y) { 050 Figure target = drawing().findFigure(x, y); 051 if (target != null && figureClass.isAssignableFrom(target.getClass())) { 052 view().addToSelection(target); 053 action(target); 054 } 055 } 056 057 public void mouseUp(MouseEvent e, int x, int y) { 058 editor().toolDone(); 059 } 060 061 public abstract void action(Figure figure); 062 063 public boolean isActive() { 064 // The AbstractTool implementation seems to always return false 065 // because isUsable()==false 066 return editor().tool() == this; 067 } 068 } 069