1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.vaadin.editor;
35
36 import info.magnolia.ui.vaadin.gwt.shared.jcrop.SelectionArea;
37
38 import java.lang.reflect.Method;
39 import java.util.EventObject;
40
41 import com.vaadin.ui.Component;
42 import com.vaadin.ui.Image;
43 import com.vaadin.util.ReflectTools;
44
45
46
47
48 public final class CroppableImage extends Image implements JCropHandler {
49
50 private final JCrop jcrop;
51
52 public CroppableImage() {
53 this.jcrop = new JCrop(this);
54 addExtension(jcrop);
55 }
56
57 public JCrop getJcrop() {
58 return jcrop;
59 }
60
61 @Override
62 public void fireEvent(EventObject event) {
63 super.fireEvent(event);
64 }
65
66 @Override
67 public void addSelectionListener(SelectionListener listener) {
68 addListener(SelectionListener.EVENT_ID, JCropSelectionEvent.class, listener, SelectionListener.EVENT_METHOD);
69 }
70
71 @Override
72 public void removeSelectionListener(SelectionListener listener) {
73 removeListener(SelectionListener.EVENT_ID, JCropSelectionEvent.class, listener);
74 }
75
76 @Override
77 public void addReleaseListener(ReleaseListener listener) {
78 addListener(ReleaseListener.EVENT_ID, JCropReleaseEvent.class, listener, ReleaseListener.EVENT_METHOD);
79 }
80
81 @Override
82 public void removeReleaseListener(ReleaseListener listener) {
83 removeListener(ReleaseListener.EVENT_ID, JCropReleaseEvent.class, listener);
84 }
85
86 @Override
87 public void setWidth(float width, Unit unit) {
88 super.setWidth(width, unit);
89 jcrop.invalidate();
90 }
91
92 @Override
93 public void setHeight(float height, Unit unit) {
94 super.setHeight(height, unit);
95 jcrop.invalidate();
96 }
97
98 @Override
99 public void addStyleName(String style) {
100 super.addStyleName(style);
101 jcrop.invalidate();
102 }
103
104 @Override
105 public void removeStyleName(String style) {
106 super.removeStyleName(style);
107 jcrop.invalidate();
108 }
109
110
111
112
113 public static class JCropEvent extends Component.Event {
114
115 private final SelectionArea area;
116
117 public JCropEvent(Component source, SelectionArea area) {
118 super(source);
119 this.area = area;
120 }
121
122 public SelectionArea getArea() {
123 return area;
124 }
125
126 }
127
128
129
130
131 public static class JCropSelectionEvent extends JCropEvent {
132
133 public JCropSelectionEvent(Component source, SelectionArea area) {
134 super(source, area);
135 }
136 }
137
138
139
140
141 public static class JCropReleaseEvent extends Component.Event {
142 public JCropReleaseEvent(Component source) {
143 super(source);
144 }
145 }
146
147
148
149
150 public interface SelectionListener {
151 public static String EVENT_ID = "jcrop_sl";
152 public static Method EVENT_METHOD =
153 ReflectTools.findMethod(SelectionListener.class, "onSelected", JCropSelectionEvent.class);
154 void onSelected(JCropSelectionEvent e);
155 }
156
157
158
159
160 public interface ReleaseListener {
161 public static String EVENT_ID = "jcrop_rl";
162 public static Method EVENT_METHOD =
163 ReflectTools.findMethod(ReleaseListener.class, "onRelease", JCropReleaseEvent.class);
164 void onRelease(JCropReleaseEvent e);
165 }
166
167 @Override
168 public void handleSelection(SelectionArea area) {
169
170 }
171
172 @Override
173 public void handleRelease() {
174
175 }
176 }