選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CalendarEntry.java 3.8KB

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