Clover coverage report - Maven Clover report
Coverage timestamp: Thu Oct 11 2007 08:41:48 CEST
file stats: LOC: 117   Methods: 7
NCLOC: 87   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DragAndDropPaletteTool.java 43.8% 69% 57.1% 61.5%
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.Point;
 22    import java.awt.event.MouseEvent;
 23   
 24    import org.ericmignot.modeler.util.action.ActionException;
 25    import org.ericmignot.modeler.util.action.NotifyableAction;
 26    import org.ericmignot.modeler.util.graphic.MagneticGridMover;
 27   
 28    public abstract class DragAndDropPaletteTool extends ItemPaletteTool
 29    {
 30   
 31    protected MagneticGridMover magneticGridMover;
 32    protected int xPressed;
 33    protected int yPressed;
 34    protected NotifyableAction mousePressedAction;
 35   
 36  0 public void mousePressed(MouseEvent e)
 37    {
 38  0 if (e.isConsumed()) return;
 39  0 this.mousePressed(e.getX(), e.getY());
 40  0 e.consume();
 41    }
 42  7 protected void mousePressed(int x, int y)
 43    {
 44  7 this.xPressed = x;
 45  7 this.yPressed = y;
 46  7 this.targetedItem = null;
 47  7 this.mousePressedAction = this.workAreaReleased(this.xPressed, this.yPressed);
 48  7 if (this.mousePressedAction != null)
 49    {
 50  6 this.magneticGridMover = new MagneticGridMover(this.getController().getMagneticGridStep());
 51  6 this.magneticGridMover.setCandidatPointToMove(new Point(this.xPressed, this.yPressed));
 52  6 this.magneticGridMover.setInitialEvent(this.xPressed, this.yPressed);
 53  6 this.mousePressedImpl();
 54    }
 55    }
 56    protected abstract void mousePressedImpl();
 57   
 58   
 59  0 public void mouseDragged(MouseEvent e)
 60    {
 61  0 if (e.isConsumed()) return;
 62  0 this.mouseDragged(e.getX(), e.getY());
 63  0 e.consume();
 64    }
 65  6 protected void mouseDragged(int x, int y)
 66    {
 67  6 if (this.targetedItem != null)
 68    {
 69  6 Point p = this.magneticGridMover.getNewPositionFromMouseDraggedEvent(x, y);
 70  6 if (p != null)
 71    {
 72  4 Point delta = computeDelta(new Point(this.xPressed, this.yPressed), new Point(x, y));
 73  4 this.mouseDraggedImpl(delta);
 74  4 this.xPressed = x;
 75  4 this.yPressed = y;
 76  4 this.magneticGridMover.setCandidatPointToMove(p);
 77  4 this.magneticGridMover.setInitialEvent(p);
 78    }
 79    }
 80    }
 81  4 protected Point computeDelta(Point start, Point end)
 82    {
 83  4 Point delta = new Point(end.x-start.x, end.y-start.y);
 84  4 double zoom = this.getController().getZoomFactor();
 85  4 delta.x = (int)(delta.x / zoom);
 86  4 delta.y = (int)(delta.y / zoom);
 87  4 return delta;
 88    }
 89    protected abstract void mouseDraggedImpl(Point delta);
 90   
 91   
 92   
 93  0 public void mouseReleased(MouseEvent e)
 94    {
 95  0 if (e.isConsumed()) return;
 96  0 this.mouseReleased();
 97  0 e.consume();
 98    }
 99  1 public void mouseReleased()
 100    {
 101  1 if (this.mousePressedAction != null)
 102    {
 103  1 try {
 104  1 this.mousePressedAction.cancel(null);
 105    } catch (ActionException e) {
 106  0 e.printStackTrace();
 107    }
 108  1 if (this.getController() != null)
 109    {
 110  1 this.getController().treatExecute(mousePressedAction);
 111    }
 112  1 this.fireItemClicked();
 113    }
 114    }
 115   
 116   
 117    }