You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ColorPickerGradientConnector.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  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
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.colorpicker;
  17. import com.google.gwt.core.client.GWT;
  18. import com.google.gwt.event.dom.client.MouseUpEvent;
  19. import com.google.gwt.event.dom.client.MouseUpHandler;
  20. import com.google.gwt.user.client.ui.Widget;
  21. import com.vaadin.client.annotations.OnStateChange;
  22. import com.vaadin.client.communication.RpcProxy;
  23. import com.vaadin.client.ui.AbstractComponentConnector;
  24. import com.vaadin.shared.ui.Connect;
  25. import com.vaadin.shared.ui.Connect.LoadStyle;
  26. import com.vaadin.shared.ui.colorpicker.ColorPickerGradientServerRpc;
  27. import com.vaadin.shared.ui.colorpicker.ColorPickerGradientState;
  28. import com.vaadin.ui.components.colorpicker.ColorPickerGradient;
  29. /**
  30. * A class that defines the default implementation for a color picker gradient
  31. * connector. Connects the server side
  32. * {@link com.vaadin.ui.components.colorpicker.ColorPickerGradient} with the
  33. * client side counterpart {@link VColorPickerGradient}
  34. *
  35. * @since 7.0.0
  36. */
  37. @Connect(value = ColorPickerGradient.class, loadStyle = LoadStyle.LAZY)
  38. public class ColorPickerGradientConnector extends AbstractComponentConnector
  39. implements MouseUpHandler {
  40. private ColorPickerGradientServerRpc rpc = RpcProxy
  41. .create(ColorPickerGradientServerRpc.class, this);
  42. @Override
  43. protected Widget createWidget() {
  44. return GWT.create(VColorPickerGradient.class);
  45. }
  46. @Override
  47. public VColorPickerGradient getWidget() {
  48. return (VColorPickerGradient) super.getWidget();
  49. }
  50. @Override
  51. public ColorPickerGradientState getState() {
  52. return (ColorPickerGradientState) super.getState();
  53. }
  54. @Override
  55. public void onMouseUp(MouseUpEvent event) {
  56. rpc.select(getWidget().getCursorX(), getWidget().getCursorY());
  57. }
  58. @Override
  59. protected void init() {
  60. super.init();
  61. getWidget().addMouseUpHandler(this);
  62. }
  63. @OnStateChange({ "cursorX", "cursorY" })
  64. void updateCursor() {
  65. getWidget().setCursor(getState().cursorX, getState().cursorY);
  66. }
  67. @OnStateChange("bgColor")
  68. void updateBgColor() {
  69. getWidget().setBGColor(getState().bgColor);
  70. }
  71. }