1 package ini
.trakem2
.display
;
3 import ini
.trakem2
.display
.graphics
.DefaultGraphicsSource
;
4 import ini
.trakem2
.display
.graphics
.GraphicsSource
;
6 import java
.awt
.Rectangle
;
7 import java
.awt
.event
.MouseEvent
;
8 import java
.util
.Collection
;
10 public class DefaultMode
implements Mode
{
12 final private DefaultGraphicsSource gs
= new DefaultGraphicsSource();
13 final private Display display
;
15 public DefaultMode(final Display display
) {
16 this.display
= display
;
19 public GraphicsSource
getGraphicsSource() {
23 public boolean canChangeLayer() { return true; }
24 public boolean canZoom() { return true; }
25 public boolean canPan() { return true; }
27 private boolean dragging
= false;
29 public boolean isDragging() {
33 public void mousePressed(MouseEvent me
, int x_p
, int y_p
, double magnification
) {
34 final Collection
<Displayable
> sel
= display
.getSelection().getSelected();
35 dragging
= false; //reset
36 for (final Displayable d
: sel
) {
37 if (d
.contains(x_p
, y_p
)) {
42 final Collection
<Displayable
> affected
= display
.getSelection().getAffected();
43 if (display
.getLayerSet().prepareStep(affected
)) {
44 display
.getLayerSet().addTransformStep(affected
);
47 public void mouseDragged(MouseEvent me
, int x_p
, int y_p
, int x_d
, int y_d
, int x_d_old
, int y_d_old
) {
48 int dx
= x_d
- x_d_old
;
49 int dy
= y_d
- y_d_old
;
51 if (dragging
) execDrag(me
, dx
, dy
);
53 private void execDrag(MouseEvent me
, int dx
, int dy
) {
54 if (0 == dx
&& 0 == dy
) return;
55 // drag all selected and linked
56 display
.getSelection().translate(dx
, dy
);
58 public void mouseReleased(MouseEvent me
, int x_p
, int y_p
, int x_d
, int y_d
, int x_r
, int y_r
) {
59 // Record current state for selected Displayable set, if there was any change:
60 final int dx
= x_r
- x_p
;
61 final int dy
= y_r
- y_p
;
62 if (0 != dx
|| 0 != dy
) {
63 display
.getLayerSet().addTransformStep(display
.getSelection().getAffected()); // all selected and their links: i.e. all that will change
69 public void undoOneStep() {
70 display
.getLayerSet().undoOneStep();
71 Display
.repaint(display
.getLayerSet());
74 public void redoOneStep() {
75 display
.getLayerSet().redoOneStep();
76 Display
.repaint(display
.getLayerSet());
79 public boolean apply() { return true; } // already done
80 public boolean cancel() { return true; } // nothing to cancel
82 public Rectangle
getRepaintBounds() {
83 return display
.getSelection().getLinkedBox();
86 public void srcRectUpdated(Rectangle srcRect
, double magnification
) {}
87 public void magnificationUpdated(Rectangle srcRect
, double magnification
) {}