Clover coverage report - Maven Clover report
Coverage timestamp: Thu Oct 11 2007 08:41:48 CEST
file stats: LOC: 108   Methods: 11
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ItemPaletteTool.java 41.7% 60.9% 36.4% 50%
coverage coverage
 1    /*
 2    * Copyright (C) 2007 Eric MIGNOT - mignots.eric@free.fr
 3    *
 4    * This library is free software; you can redistribute it and/or
 5    * modify it under the terms of the GNU Lesser General Public
 6    * License as published by the Free Software Foundation; either
 7    * version 2.1 of the License, or (at your option) any later version.
 8    *
 9    * This library is distributed in the hope that it will be useful,
 10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12    * Lesser General Public License for more details.
 13    *
 14    * You should have received a copy of the GNU Lesser General Public
 15    * License along with this library; if not, write to the Free Software
 16    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17    */
 18   
 19    package org.ericmignot.modeler.gui.palette;
 20   
 21    import java.awt.event.MouseEvent;
 22    import java.util.List;
 23   
 24    import javax.swing.JToggleButton;
 25   
 26    import org.ericmignot.modeler.gui.workarea.Item;
 27    import org.ericmignot.modeler.util.action.NotifyableAction;
 28   
 29    /**
 30    * A palette tool that will listen to mouse
 31    * event on the WorkArea, looking for a potential
 32    * Item to handle the event.
 33    */
 34    public abstract class ItemPaletteTool extends PaletteTool
 35    {
 36   
 37    protected JToggleButton button;
 38   
 39  36 public ItemPaletteTool()
 40    {
 41  36 this.button = null;
 42    }
 43   
 44  11 public boolean shouldItemRegister(Item item)
 45    {
 46  11 return false;
 47    }
 48   
 49  3 public boolean shouldWorkAreaRegister()
 50    {
 51  3 return true;
 52    }
 53   
 54  0 public void registerItem(Item item)
 55    {
 56    }
 57   
 58  0 public void unregisterItem(Item item)
 59    {
 60    }
 61   
 62  0 public void mousePressed(MouseEvent e){}
 63  0 public void itemPressed(Item item, int x, int y){}
 64  0 public void itemDragged(int x, int y){}
 65   
 66  0 public NotifyableAction manageReleased() {return null;}
 67   
 68  0 public void mouseReleased(MouseEvent e)
 69    {
 70  0 if (e.isConsumed()) return;
 71   
 72  0 NotifyableAction action = this.workAreaReleased(e.getX(), e.getY());
 73  0 if (action != null)
 74    {
 75  0 if (this.getController() != null)
 76    {
 77  0 this.getController().treatExecute(action);
 78    }
 79    }
 80  0 this.fireItemClicked();
 81  0 e.consume();
 82    }
 83   
 84  14 public NotifyableAction workAreaReleased(int x, int y)
 85    {
 86  14 List items = this.getItemsUnder(x, y);
 87  14 for (int i = 0; i < items.size(); i ++)
 88    {
 89  13 Item itemUnder = (Item) items.get(i);
 90  13 if (this.isItemCandidate(itemUnder))
 91    {
 92  13 NotifyableAction action = this.getAction(itemUnder, x, y);
 93  13 if (action != null)
 94    {
 95  12 this.targetedItem = itemUnder;
 96  12 action.setDoEvent(this.getDoEvent());
 97  12 action.setUndoEvent(this.getUndoEvent());
 98  12 return action;
 99    }
 100    }
 101    }
 102  2 return null;
 103    }
 104   
 105    public abstract boolean isItemCandidate(Item item);
 106    protected abstract NotifyableAction getAction(Item item, int x, int y);
 107   
 108    }