1 package org.catacomb.druid.swing.dnd;
2
3 import org.catacomb.druid.swing.DTextCanvas;
4 import org.catacomb.report.E;
5
6 import java.awt.Color;
7 import java.awt.Graphics;
8 import java.awt.Rectangle;
9 import java.awt.event.MouseEvent;
10 import java.awt.event.MouseListener;
11 import java.awt.event.MouseMotionListener;
12
13
14
15 public class ClickableRegionStore extends RegionStore implements MouseListener, MouseMotionListener {
16
17 DTextCanvas canvas;
18
19 RegionListener regionListener;
20
21
22
23 public ClickableRegionStore(DTextCanvas c) {
24 super();
25 canvas = c;
26 canvas.addMouseListener(this);
27 canvas.addMouseMotionListener(this);
28 }
29
30
31 public void setRegionListener(RegionListener rl) {
32 regionListener = rl;
33 }
34
35
36 public void mouseClicked(MouseEvent e) {
37 canvas.requestFocus();
38 }
39
40
41
42 public void mousePressed(MouseEvent e) {
43 press(e.getX(), e.getY());
44
45 }
46
47
48
49
50
51 public void mouseReleased(MouseEvent e) {
52 Region reg = getPressRegion();
53 if (reg != null) {
54 if (regionListener != null) {
55 regionListener.regionClicked(reg);
56 } else {
57 E.info("region clicked but no listener " + reg);
58 }
59 }
60
61 }
62
63
64 public void mouseEntered(MouseEvent e) {
65 }
66
67
68 public void mouseExited(MouseEvent e) {
69 }
70
71
72 public void mouseDragged(MouseEvent e) {
73
74 }
75
76
77 public void mouseMoved(MouseEvent e) {
78
79 Region rpr = getHoverRegion();
80 hoverOver(e.getX(), e.getY());
81
82 Region rnw = getHoverRegion();
83
84 if ((rpr == null && rnw != null) ||
85 (rpr != null && rnw == null) ||
86 (rpr != null && !(rpr == rnw))) {
87
88
89 Graphics g = canvas.getGraphics();
90 if (rpr != null) {
91
92 unecho(rpr);
93
94 }
95
96 if (rnw != null) {
97 if (rnw.draggable()) {
98 g.setColor(Color.magenta);
99
100 g.drawRect(rnw.getX(), rnw.getY(), rnw.getW(), rnw.getH());
101 g.drawRect(rnw.getX()+1, rnw.getY()+1, rnw.getW()-2, rnw.getH()-2);
102
103 } else if (rnw.clickable()) {
104 g.setColor(Color.orange);
105
106 g.drawRect(rnw.getX(), rnw.getY(), rnw.getW(), rnw.getH());
107 g.drawRect(rnw.getX()+1, rnw.getY()+1, rnw.getW()-2, rnw.getH()-2);
108
109
110 }
111 }
112
113
114 }
115
116 }
117
118
119
120 public void unecho(Region r) {
121 Rectangle rect = new Rectangle(r.getX(), r.getY(), r.getW()+1, r.getH()+1);
122 canvas.paintImmediately(rect);
123 }
124
125
126
127 public void clearRegions() {
128 clear();
129 }
130
131
132
133
134
135
136
137 }