View Javadoc

1   package org.catacomb.druid.swing.dnd;
2   
3   import org.catacomb.druid.swing.DTextCanvas;
4   import org.catacomb.interlish.structure.ChangeNotifiable;
5   import org.catacomb.report.E;
6   
7   
8   import java.awt.Color;
9   import java.awt.Graphics2D;
10  import java.awt.dnd.DnDConstants;
11  import java.awt.event.FocusEvent;
12  import java.awt.event.FocusListener;
13  
14  
15  public class RegionBoard implements FocusListener, RegionListener {
16  
17      protected DTextCanvas canvas;
18  
19      ChangeNotifiable changeNotifiable;
20  
21      private ClickableRegionStore crStore;
22  
23      boolean inFocus;
24  
25      RegionDropTarget dropTarget;
26      RegionDragSource dragSource;
27  
28      protected int fullTextHeight = 100;
29  
30  
31  
32      public RegionBoard(DTextCanvas c) {
33          super();
34          canvas = c;
35  
36          crStore = new ClickableRegionStore(c);
37          crStore.setRegionListener(this);
38  
39          canvas.addFocusListener(this);
40  
41          dropTarget = new RegionDropTarget(this);
42  
43  
44          dragSource = new RegionDragSource(this, DnDConstants.ACTION_COPY_OR_MOVE);
45  
46          canvas.setTransferHandler(new InternalTransferHandler());
47      }
48  
49  
50      public DTextCanvas getCanvas() {
51          return canvas;
52      }
53  
54  
55  
56      public void clearRegions() {
57          crStore.clear();
58      }
59  
60      public void requestFocus() {
61          canvas.requestFocusInWindow();
62      }
63  
64  
65      public void setAntialias(boolean b) {
66          canvas.setAntialias(b);
67      }
68  
69      public void repaint() {
70          canvas.repaint();
71      }
72  
73      public int getWidth() {
74          return canvas.getWidth();
75      }
76  
77      public int getHeight() {
78          return canvas.getHeight();
79      }
80  
81      public void setChangeNotifiable(ChangeNotifiable cn) {
82          changeNotifiable = cn;
83      }
84  
85      public void notifyChange(Object obj) {
86          if (changeNotifiable != null) {
87              changeNotifiable.changed(obj);
88          }
89      }
90  
91  
92      public void prePaintRegions(Graphics2D g) {
93          if (inFocus) {
94              g.setColor(Color.white);
95              g.drawRect(1, 1, canvas.getWidth()-2, canvas.getHeight()-2);
96          }
97  
98      }
99  
100 
101 
102 
103     protected void addLengthenedRegion(int[] cachedPosition, Object b) {
104         crStore.addLengthenedRegion(cachedPosition, b);
105     }
106 
107     protected void addClickRegion(int[] xywh, Object b, String s) {
108         crStore.addRegion(xywh, b, s,  Region.CLICK);
109     }
110 
111 
112     protected void addDragRegion(int[] xywh, Object b, String s) {
113         crStore.addRegion(xywh, b, s, Region.DRAG);
114     }
115 
116     protected void addDropRegion(int[] xywh, Object b, String s) {
117         crStore.addRegion(xywh, b, s, Region.DROP);
118     }
119 
120     protected void addDragOrDropRegion(int[] xywh, Object b, String s) {
121         crStore.addRegion(xywh, b, s, Region.DRAG_OR_DROP);
122     }
123 
124     protected void addRegion(int x, int y, int w, int h, Object obj, String s) {
125         crStore.addRegion(x, y, w, h, obj, s, Region.CLICK);
126 
127     }
128 
129     protected void addRegion(int x, int y, int w, int h, Object obj, String s, int ity) {
130         crStore.addRegion(x, y, w, h, obj, s, ity);
131 
132     }
133 
134 
135     public Region getDragOverRegion(int x, int y) {
136         crStore.dragOver(x, y);
137         return crStore.getDragOverRegion();
138     }
139 
140 
141     public Region getDragOverRegion() {
142         return crStore.getDragOverRegion();
143     }
144 
145 
146     public void dropOn(Object src, Region target) {
147         E.info("item dropped on region " + src + " " + target);
148 
149     }
150 
151 
152     public void regionClicked(Region reg) {
153         E.override("click regoin " + reg);
154     }
155 
156 
157     boolean hasFocus() {
158         return inFocus;
159     }
160 
161     public void focusGained(FocusEvent e) {
162         inFocus = true;
163         repaint();
164     }
165 
166 
167     public void focusLost(FocusEvent e) {
168         inFocus = false;
169         repaint();
170     }
171 
172 
173     public Region getHoverRegion() {
174         return crStore.getHoverRegion();
175     }
176 
177 
178     public void unecho(Region reg) {
179         crStore.unecho(reg);
180     }
181 
182     public void dropGeneral(Object dropee) {
183         E.override();
184 
185     }
186 
187 
188     public int getFullTextHeight() {
189         return fullTextHeight;
190     }
191 
192 
193 }