Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CalendarEntry.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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;
  17. import java.util.Date;
  18. import com.vaadin.client.DateTimeService;
  19. import static com.vaadin.client.DateTimeService.asTwoDigits;
  20. public class CalendarEntry {
  21. private final String styleName;
  22. private Date start;
  23. private Date end;
  24. private String title;
  25. private String description;
  26. private boolean notime;
  27. @SuppressWarnings("deprecation")
  28. public CalendarEntry(String styleName, Date start, Date end, String title,
  29. String description, boolean notime) {
  30. this.styleName = styleName;
  31. if (notime) {
  32. Date d = new Date(start.getTime());
  33. d.setSeconds(0);
  34. d.setMinutes(0);
  35. this.start = d;
  36. if (end != null) {
  37. d = new Date(end.getTime());
  38. d.setSeconds(0);
  39. d.setMinutes(0);
  40. this.end = d;
  41. } else {
  42. end = start;
  43. }
  44. } else {
  45. this.start = start;
  46. this.end = end;
  47. }
  48. this.title = title;
  49. this.description = description;
  50. this.notime = notime;
  51. }
  52. public CalendarEntry(String styleName, Date start, Date end, String title,
  53. String description) {
  54. this(styleName, start, end, title, description, false);
  55. }
  56. public String getStyleName() {
  57. return styleName;
  58. }
  59. public Date getStart() {
  60. return start;
  61. }
  62. public void setStart(Date start) {
  63. this.start = start;
  64. }
  65. public Date getEnd() {
  66. return end;
  67. }
  68. public void setEnd(Date end) {
  69. this.end = end;
  70. }
  71. public String getTitle() {
  72. return title;
  73. }
  74. public void setTitle(String title) {
  75. this.title = title;
  76. }
  77. public String getDescription() {
  78. return description;
  79. }
  80. public void setDescription(String description) {
  81. this.description = description;
  82. }
  83. public boolean isNotime() {
  84. return notime;
  85. }
  86. public void setNotime(boolean notime) {
  87. this.notime = notime;
  88. }
  89. @SuppressWarnings("deprecation")
  90. public String getStringForDate(Date d) {
  91. // TODO format from DateTimeService
  92. String s = "";
  93. if (!notime) {
  94. if (!DateTimeService.isSameDay(d, start)) {
  95. s += (start.getYear() + 1900) + "." + (start.getMonth() + 1)
  96. + "." + start.getDate() + " ";
  97. }
  98. int i = start.getHours();
  99. s += asTwoDigits(i);
  100. s += ":";
  101. i = start.getMinutes();
  102. s += asTwoDigits(i);
  103. if (!start.equals(end)) {
  104. s += " - ";
  105. if (!DateTimeService.isSameDay(start, end)) {
  106. s += (end.getYear() + 1900) + "." + (end.getMonth() + 1)
  107. + "." + end.getDate() + " ";
  108. }
  109. i = end.getHours();
  110. s += asTwoDigits(i);
  111. s += ":";
  112. i = end.getMinutes();
  113. s += asTwoDigits(i);
  114. }
  115. s += " ";
  116. }
  117. if (title != null) {
  118. s += title;
  119. }
  120. return s;
  121. }
  122. }