2 * Copyright 2000-2018 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.v7.client.ui.colorpicker;
18 import com.google.gwt.core.client.GWT;
19 import com.google.gwt.event.dom.client.MouseUpEvent;
20 import com.google.gwt.event.dom.client.MouseUpHandler;
21 import com.google.gwt.user.client.ui.Widget;
22 import com.vaadin.client.communication.RpcProxy;
23 import com.vaadin.client.communication.StateChangeEvent;
24 import com.vaadin.client.ui.colorpicker.VColorPickerGradient;
25 import com.vaadin.shared.ui.Connect;
26 import com.vaadin.shared.ui.Connect.LoadStyle;
27 import com.vaadin.v7.client.ui.AbstractLegacyComponentConnector;
28 import com.vaadin.v7.shared.ui.colorpicker.ColorPickerGradientServerRpc;
29 import com.vaadin.v7.shared.ui.colorpicker.ColorPickerGradientState;
30 import com.vaadin.v7.ui.components.colorpicker.ColorPickerGradient;
33 * A class that defines the default implementation for a color picker gradient
34 * connector. Connects the server side {@link ColorPickerGradient} with the
35 * client side counterpart {@link VColorPickerGradient}
39 @Connect(value = ColorPickerGradient.class, loadStyle = LoadStyle.LAZY)
40 public class ColorPickerGradientConnector
41 extends AbstractLegacyComponentConnector implements MouseUpHandler {
43 private ColorPickerGradientServerRpc rpc = RpcProxy
44 .create(ColorPickerGradientServerRpc.class, this);
47 protected Widget createWidget() {
48 return GWT.create(VColorPickerGradient.class);
52 public VColorPickerGradient getWidget() {
53 return (VColorPickerGradient) super.getWidget();
57 public ColorPickerGradientState getState() {
58 return (ColorPickerGradientState) super.getState();
62 public void onMouseUp(MouseUpEvent event) {
63 rpc.select(getWidget().getCursorX(), getWidget().getCursorY());
67 public void onStateChanged(StateChangeEvent stateChangeEvent) {
68 super.onStateChanged(stateChangeEvent);
69 if (stateChangeEvent.hasPropertyChanged("cursorX")
70 || stateChangeEvent.hasPropertyChanged("cursorY")) {
72 getWidget().setCursor(getState().cursorX, getState().cursorY);
74 if (stateChangeEvent.hasPropertyChanged("bgColor")) {
75 getWidget().setBGColor(getState().bgColor);
80 protected void init() {
82 getWidget().addMouseUpHandler(this);