/ftr-gwt-library-date/src/main/java/eu/future/earth/gwt/client/date/week/staend/AbstractDayField.java

http://ftr-gwt-library.googlecode.com/ · Java · 148 lines · 105 code · 25 blank · 18 comment · 13 complexity · 5f76d3711449df2632a63e2735517eb4 MD5 · raw file

  1. /*
  2. * Copyright 2007 Future Earth, info@future-earth.eu
  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 eu.future.earth.gwt.client.date.week.staend;
  17. import org.cobogw.gwt.user.client.CSS;
  18. import org.cobogw.gwt.user.client.ui.RoundedPanel;
  19. import com.google.gwt.event.dom.client.ClickEvent;
  20. import com.google.gwt.event.dom.client.ClickHandler;
  21. import com.google.gwt.user.client.ui.HTML;
  22. import com.google.gwt.user.client.ui.HorizontalPanel;
  23. import com.google.gwt.user.client.ui.Label;
  24. import com.google.gwt.user.client.ui.SimplePanel;
  25. import com.google.gwt.user.client.ui.Widget;
  26. import eu.future.earth.gwt.client.FtrGwtDateCss;
  27. import eu.future.earth.gwt.client.date.DateEvent;
  28. import eu.future.earth.gwt.client.date.DateEvent.DateEventActions;
  29. import eu.future.earth.gwt.client.date.TimeEventRendererVertical;
  30. public abstract class AbstractDayField<T> extends DayField<T> implements ClickHandler {
  31. protected Label title;
  32. private SimplePanel top;
  33. private SimplePanel bottom;
  34. private Label titleDescription = null;
  35. private HTML space = new HTML("&nbsp;");
  36. private HorizontalPanel tit = new HorizontalPanel();
  37. public AbstractDayField(TimeEventRendererVertical<? extends T> renderer, T data) {
  38. super(renderer, data);
  39. title = new Label();
  40. titleDescription = new Label();
  41. tit.setBorderWidth(0);
  42. tit.setSpacing(0);
  43. tit.add(title);
  44. tit.add(space);
  45. tit.add(titleDescription);
  46. title.setWordWrap(false);
  47. if (renderer.getEventCornerSize() > 0) {
  48. top = new RoundedPanel(tit, RoundedPanel.TOP, renderer.getEventCornerSize());
  49. top.setHeight(renderer.getEventTopHeight() + "px");
  50. bottom = new RoundedPanel(RoundedPanel.BOTTOM, renderer.getEventCornerSize());
  51. bottom.setWidget(new SimplePanel());
  52. bottom.setHeight(renderer.getEventBottomHeight() + "px");
  53. } else {
  54. top = new SimplePanel();
  55. top.setWidget(tit);
  56. top.setHeight(renderer.getEventTopHeight() + "px");
  57. bottom = new SimplePanel();
  58. bottom.setHeight(renderer.getEventBottomHeight() + "px");
  59. }
  60. tit.setWidth("100%");
  61. setEventStyleName(FtrGwtDateCss.EVENT_DAY_PANEL, FtrGwtDateCss.EVENT_DAY_HEADER);
  62. }
  63. public void setEventStyleName(String newStyleName, String tileStyle) {
  64. super.setEventStyleName(newStyleName);
  65. if (top instanceof RoundedPanel) {
  66. ((RoundedPanel) top).setCornerStyleName(tileStyle);
  67. ((RoundedPanel) bottom).setCornerStyleName(newStyleName);
  68. } else {
  69. top.setStyleName(tileStyle);
  70. bottom.setStyleName(newStyleName);
  71. }
  72. space.setStyleName(tileStyle);
  73. tit.setStyleName(tileStyle);
  74. title.setStyleName(tileStyle);
  75. titleDescription.setStyleName(tileStyle);
  76. }
  77. public void setMainColor(String newColor) {
  78. super.setMainColor(newColor);
  79. if (dataWidget != null) {
  80. CSS.setProperty(dataWidget, CSS.A.BACKGROUND_COLOR, newColor);
  81. }
  82. if (top instanceof RoundedPanel) {
  83. ((RoundedPanel) bottom).setBorderColor(newColor);
  84. } else {
  85. CSS.setProperty(bottom, CSS.A.BACKGROUND_COLOR, newColor);
  86. }
  87. }
  88. public void setForeGroundColor(String newColor) {
  89. super.setForeGroundColor(newColor);
  90. if (dataWidget != null) {
  91. CSS.setProperty(dataWidget, CSS.A.COLOR, newColor);
  92. }
  93. if (titleDescription != null) {
  94. CSS.setProperty(titleDescription, CSS.A.COLOR, newColor);
  95. }
  96. CSS.setProperty(bottom, CSS.A.COLOR, newColor);
  97. }
  98. public void setWidth(int width) {
  99. if (width > 0) {
  100. super.setWidth(width + "px");
  101. }
  102. }
  103. protected void setBody(Widget body) {
  104. // clickable = getClickableItem();
  105. body.setStyleName(getEventStyleName());
  106. setWidgetInsizeResize(top, body, bottom);
  107. }
  108. public Widget getDraggableItem() {
  109. return title;
  110. }
  111. // private Widget clickable = null;
  112. public void setTitle(String newTitle) {
  113. title.setText(newTitle);
  114. }
  115. public void setTitleDescription(String newTitle) {
  116. titleDescription.setText(newTitle);
  117. titleDescription.setTitle(newTitle);
  118. }
  119. // public abstract Widget getClickableItem();
  120. public void onClick(ClickEvent event) {
  121. DateEvent.fire(this, DateEventActions.EDIT, getValue());
  122. }
  123. }