View Javadoc
1   /**
2    * This file Copyright (c) 2010-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
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   * Image extended with {@link JCrop}.
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      * JCropEvent.
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      * JCropSelectionEvent.
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      * JCropReleaseEvent.
140      */
141     public static class JCropReleaseEvent extends Component.Event {
142         public JCropReleaseEvent(Component source) {
143             super(source);
144         }
145     }
146 
147     /**
148      * SelectionListener.
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      * ReleaseListener.
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 }