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.

SimpleDayCell.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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.v7.client.ui.calendar.schedule;
  17. import java.util.Date;
  18. import com.google.gwt.core.client.GWT;
  19. import com.google.gwt.dom.client.Element;
  20. import com.google.gwt.dom.client.NativeEvent;
  21. import com.google.gwt.event.dom.client.KeyCodes;
  22. import com.google.gwt.event.dom.client.KeyDownEvent;
  23. import com.google.gwt.event.dom.client.KeyDownHandler;
  24. import com.google.gwt.event.dom.client.MouseDownEvent;
  25. import com.google.gwt.event.dom.client.MouseDownHandler;
  26. import com.google.gwt.event.dom.client.MouseMoveEvent;
  27. import com.google.gwt.event.dom.client.MouseMoveHandler;
  28. import com.google.gwt.event.dom.client.MouseOverEvent;
  29. import com.google.gwt.event.dom.client.MouseOverHandler;
  30. import com.google.gwt.event.dom.client.MouseUpEvent;
  31. import com.google.gwt.event.dom.client.MouseUpHandler;
  32. import com.google.gwt.event.shared.HandlerRegistration;
  33. import com.google.gwt.user.client.DOM;
  34. import com.google.gwt.user.client.Event;
  35. import com.google.gwt.user.client.ui.HTML;
  36. import com.google.gwt.user.client.ui.Label;
  37. import com.google.gwt.user.client.ui.Widget;
  38. import com.vaadin.client.ui.FocusableFlowPanel;
  39. import com.vaadin.v7.client.ui.VCalendar;
  40. import com.vaadin.v7.shared.ui.calendar.DateConstants;
  41. /**
  42. * A class representing a single cell within the calendar in month-view
  43. *
  44. * @since 7.1
  45. * @author Vaadin Ltd.
  46. */
  47. public class SimpleDayCell extends FocusableFlowPanel implements MouseUpHandler,
  48. MouseDownHandler, MouseOverHandler, MouseMoveHandler {
  49. private static int BOTTOMSPACERHEIGHT = -1;
  50. private static int EVENTHEIGHT = -1;
  51. private static final int BORDERPADDINGSIZE = 1;
  52. private final VCalendar calendar;
  53. private Date date;
  54. private int intHeight;
  55. private final HTML bottomspacer;
  56. private final Label caption;
  57. private final CalendarEvent[] events = new CalendarEvent[10];
  58. private final int cell;
  59. private final int row;
  60. private boolean monthNameVisible;
  61. private HandlerRegistration mouseUpRegistration;
  62. private HandlerRegistration mouseDownRegistration;
  63. private HandlerRegistration mouseOverRegistration;
  64. private boolean monthEventMouseDown;
  65. private boolean labelMouseDown;
  66. private int eventCount = 0;
  67. private int startX = -1;
  68. private int startY = -1;
  69. private int startYrelative;
  70. private int startXrelative;
  71. // "from" date of date which is source of Dnd
  72. private Date dndSourceDateFrom;
  73. // "to" date of date which is source of Dnd
  74. private Date dndSourceDateTo;
  75. // "from" time of date which is source of Dnd
  76. private Date dndSourceStartDateTime;
  77. // "to" time of date which is source of Dnd
  78. private Date dndSourceEndDateTime;
  79. private int prevDayDiff = 0;
  80. private int prevWeekDiff = 0;
  81. private HandlerRegistration moveRegistration;
  82. private CalendarEvent moveEvent;
  83. private Widget clickedWidget;
  84. private HandlerRegistration bottomSpacerMouseDownHandler;
  85. private boolean scrollable = false;
  86. private MonthGrid monthGrid;
  87. private HandlerRegistration keyDownHandler;
  88. public SimpleDayCell(VCalendar calendar, int row, int cell) {
  89. this.calendar = calendar;
  90. this.row = row;
  91. this.cell = cell;
  92. setStylePrimaryName("v-calendar-month-day");
  93. caption = new Label();
  94. bottomspacer = new HTML();
  95. bottomspacer.setStyleName("v-calendar-bottom-spacer-empty");
  96. bottomspacer.setWidth(3 + "em");
  97. caption.setStyleName("v-calendar-day-number");
  98. add(caption);
  99. add(bottomspacer);
  100. caption.addMouseDownHandler(this);
  101. caption.addMouseUpHandler(this);
  102. }
  103. @Override
  104. public void onLoad() {
  105. BOTTOMSPACERHEIGHT = bottomspacer.getOffsetHeight();
  106. EVENTHEIGHT = BOTTOMSPACERHEIGHT;
  107. }
  108. public void setMonthGrid(MonthGrid monthGrid) {
  109. this.monthGrid = monthGrid;
  110. }
  111. public MonthGrid getMonthGrid() {
  112. return monthGrid;
  113. }
  114. @SuppressWarnings("deprecation")
  115. public void setDate(Date date) {
  116. int dateOfMonth = date.getDate();
  117. if (monthNameVisible) {
  118. caption.setText(dateOfMonth + " "
  119. + calendar.getMonthNames()[date.getMonth()]);
  120. } else {
  121. caption.setText("" + dateOfMonth);
  122. }
  123. this.date = date;
  124. }
  125. public Date getDate() {
  126. return date;
  127. }
  128. public void reDraw(boolean clear) {
  129. setHeightPX(intHeight + BORDERPADDINGSIZE, clear);
  130. }
  131. /*
  132. * Events and whole cell content are drawn by this method. By the
  133. * clear-argument, you can choose to clear all old content. Notice that
  134. * clearing will also remove all element's event handlers.
  135. */
  136. public void setHeightPX(int px, boolean clear) {
  137. // measure from DOM if needed
  138. if (px < 0) {
  139. intHeight = getOffsetHeight() - BORDERPADDINGSIZE;
  140. } else {
  141. intHeight = px - BORDERPADDINGSIZE;
  142. }
  143. // Couldn't measure height or it ended up negative. Don't bother
  144. // continuing
  145. if (intHeight == -1) {
  146. return;
  147. }
  148. if (clear) {
  149. while (getWidgetCount() > 1) {
  150. remove(1);
  151. }
  152. }
  153. // How many events can be shown in UI
  154. int slots = 0;
  155. if (scrollable) {
  156. for (int i = 0; i < events.length; i++) {
  157. if (events[i] != null) {
  158. slots = i + 1;
  159. }
  160. }
  161. setHeight(intHeight + "px"); // Fixed height
  162. } else {
  163. // Dynamic height by the content
  164. DOM.removeElementAttribute(getElement(), "height");
  165. slots = (intHeight - caption.getOffsetHeight() - BOTTOMSPACERHEIGHT)
  166. / EVENTHEIGHT;
  167. if (slots > 10) {
  168. slots = 10;
  169. }
  170. }
  171. updateEvents(slots, clear);
  172. }
  173. public void updateEvents(int slots, boolean clear) {
  174. int eventsAdded = 0;
  175. for (int i = 0; i < slots; i++) {
  176. CalendarEvent e = events[i];
  177. if (e == null) {
  178. // Empty slot
  179. HTML slot = new HTML();
  180. slot.setStyleName("v-calendar-spacer");
  181. if (!clear) {
  182. remove(i + 1);
  183. insert(slot, i + 1);
  184. } else {
  185. add(slot);
  186. }
  187. } else {
  188. // Event slot
  189. eventsAdded++;
  190. if (!clear) {
  191. Widget w = getWidget(i + 1);
  192. if (!(w instanceof MonthEventLabel)) {
  193. remove(i + 1);
  194. insert(createMonthEventLabel(e), i + 1);
  195. }
  196. } else {
  197. add(createMonthEventLabel(e));
  198. }
  199. }
  200. }
  201. int remainingSpace = intHeight - ((slots * EVENTHEIGHT)
  202. + BOTTOMSPACERHEIGHT + caption.getOffsetHeight());
  203. int newHeight = remainingSpace + BOTTOMSPACERHEIGHT;
  204. if (newHeight < 0) {
  205. newHeight = EVENTHEIGHT;
  206. }
  207. bottomspacer.setHeight(newHeight + "px");
  208. if (clear) {
  209. add(bottomspacer);
  210. }
  211. int more = eventCount - eventsAdded;
  212. if (more > 0) {
  213. if (bottomSpacerMouseDownHandler == null) {
  214. bottomSpacerMouseDownHandler = bottomspacer
  215. .addMouseDownHandler(this);
  216. }
  217. bottomspacer.setStyleName("v-calendar-bottom-spacer");
  218. bottomspacer.setText("+ " + more);
  219. } else {
  220. if (!scrollable && bottomSpacerMouseDownHandler != null) {
  221. bottomSpacerMouseDownHandler.removeHandler();
  222. bottomSpacerMouseDownHandler = null;
  223. }
  224. if (scrollable) {
  225. bottomspacer.setText("[ - ]");
  226. } else {
  227. bottomspacer.setStyleName("v-calendar-bottom-spacer-empty");
  228. bottomspacer.setText("");
  229. }
  230. }
  231. }
  232. private MonthEventLabel createMonthEventLabel(CalendarEvent e) {
  233. long rangeInMillis = e.getRangeInMilliseconds();
  234. boolean timeEvent = rangeInMillis <= DateConstants.DAYINMILLIS
  235. && !e.isAllDay();
  236. Date fromDatetime = e.getStartTime();
  237. // Create a new MonthEventLabel
  238. MonthEventLabel eventDiv = new MonthEventLabel();
  239. eventDiv.addStyleDependentName("month");
  240. eventDiv.addMouseDownHandler(this);
  241. eventDiv.addMouseUpHandler(this);
  242. eventDiv.setCalendar(calendar);
  243. eventDiv.setEventIndex(e.getIndex());
  244. eventDiv.setCalendarEvent(e);
  245. if (timeEvent) {
  246. eventDiv.setTimeSpecificEvent(true);
  247. if (e.getStyleName() != null) {
  248. eventDiv.addStyleDependentName(e.getStyleName());
  249. }
  250. eventDiv.setCaption(e.getCaption());
  251. eventDiv.setTime(fromDatetime);
  252. } else {
  253. eventDiv.setTimeSpecificEvent(false);
  254. Date from = e.getStart();
  255. Date to = e.getEnd();
  256. if (!e.getStyleName().isEmpty()) {
  257. eventDiv.addStyleName("month-event " + e.getStyleName());
  258. } else {
  259. eventDiv.addStyleName("month-event");
  260. }
  261. int fromCompareToDate = from.compareTo(date);
  262. int toCompareToDate = to.compareTo(date);
  263. eventDiv.addStyleDependentName("all-day");
  264. if (fromCompareToDate == 0) {
  265. eventDiv.addStyleDependentName("start");
  266. eventDiv.setCaption(e.getCaption());
  267. } else if (fromCompareToDate < 0 && cell == 0) {
  268. eventDiv.addStyleDependentName("continued-from");
  269. eventDiv.setCaption(e.getCaption());
  270. }
  271. if (toCompareToDate == 0) {
  272. eventDiv.addStyleDependentName("end");
  273. } else if (toCompareToDate > 0
  274. && (cell + 1) == getMonthGrid().getCellCount(row)) {
  275. eventDiv.addStyleDependentName("continued-to");
  276. }
  277. if (e.getStyleName() != null) {
  278. eventDiv.addStyleDependentName(e.getStyleName() + "-all-day");
  279. }
  280. }
  281. return eventDiv;
  282. }
  283. private void setUnlimitedCellHeight() {
  284. scrollable = true;
  285. addStyleDependentName("scrollable");
  286. }
  287. private void setLimitedCellHeight() {
  288. scrollable = false;
  289. removeStyleDependentName("scrollable");
  290. }
  291. public void addCalendarEvent(CalendarEvent e) {
  292. eventCount++;
  293. int slot = e.getSlotIndex();
  294. if (slot == -1) {
  295. for (int i = 0; i < events.length; i++) {
  296. if (events[i] == null) {
  297. events[i] = e;
  298. e.setSlotIndex(i);
  299. break;
  300. }
  301. }
  302. } else {
  303. events[slot] = e;
  304. }
  305. }
  306. @SuppressWarnings("deprecation")
  307. public void setMonthNameVisible(boolean b) {
  308. monthNameVisible = b;
  309. int dateOfMonth = date.getDate();
  310. caption.setText(
  311. dateOfMonth + " " + calendar.getMonthNames()[date.getMonth()]);
  312. }
  313. public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
  314. return addDomHandler(handler, MouseMoveEvent.getType());
  315. }
  316. @Override
  317. protected void onAttach() {
  318. super.onAttach();
  319. mouseUpRegistration = addDomHandler(this, MouseUpEvent.getType());
  320. mouseDownRegistration = addDomHandler(this, MouseDownEvent.getType());
  321. mouseOverRegistration = addDomHandler(this, MouseOverEvent.getType());
  322. }
  323. @Override
  324. protected void onDetach() {
  325. mouseUpRegistration.removeHandler();
  326. mouseDownRegistration.removeHandler();
  327. mouseOverRegistration.removeHandler();
  328. super.onDetach();
  329. }
  330. @Override
  331. public void onMouseUp(MouseUpEvent event) {
  332. if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
  333. return;
  334. }
  335. Widget w = (Widget) event.getSource();
  336. if (moveRegistration != null) {
  337. Event.releaseCapture(getElement());
  338. moveRegistration.removeHandler();
  339. moveRegistration = null;
  340. keyDownHandler.removeHandler();
  341. keyDownHandler = null;
  342. }
  343. if (w == bottomspacer && monthEventMouseDown) {
  344. GWT.log("Mouse up over bottomspacer");
  345. } else if (clickedWidget instanceof MonthEventLabel
  346. && monthEventMouseDown) {
  347. MonthEventLabel mel = (MonthEventLabel) clickedWidget;
  348. int endX = event.getClientX();
  349. int endY = event.getClientY();
  350. int xDiff = 0, yDiff = 0;
  351. if (startX != -1 && startY != -1) {
  352. xDiff = startX - endX;
  353. yDiff = startY - endY;
  354. }
  355. startX = -1;
  356. startY = -1;
  357. prevDayDiff = 0;
  358. prevWeekDiff = 0;
  359. if (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3) {
  360. eventMoved(moveEvent);
  361. } else if (calendar.getEventClickListener() != null) {
  362. CalendarEvent e = getEventByWidget(mel);
  363. calendar.getEventClickListener().eventClick(e);
  364. }
  365. moveEvent = null;
  366. } else if (w == this) {
  367. getMonthGrid().setSelectionReady();
  368. } else if (w instanceof Label && labelMouseDown) {
  369. String clickedDate = calendar.getDateFormat().format(date);
  370. if (calendar.getDateClickListener() != null) {
  371. calendar.getDateClickListener().dateClick(clickedDate);
  372. }
  373. }
  374. monthEventMouseDown = false;
  375. labelMouseDown = false;
  376. clickedWidget = null;
  377. }
  378. @Override
  379. public void onMouseDown(MouseDownEvent event) {
  380. if (calendar.isDisabled()
  381. || event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
  382. return;
  383. }
  384. Widget w = (Widget) event.getSource();
  385. clickedWidget = w;
  386. if (w instanceof MonthEventLabel) {
  387. // event clicks should be allowed even when read-only
  388. monthEventMouseDown = true;
  389. if (calendar.isEventMoveAllowed()) {
  390. startCalendarEventDrag(event, (MonthEventLabel) w);
  391. }
  392. } else if (w == bottomspacer) {
  393. if (scrollable) {
  394. setLimitedCellHeight();
  395. } else {
  396. setUnlimitedCellHeight();
  397. }
  398. reDraw(true);
  399. } else if (w instanceof Label) {
  400. labelMouseDown = true;
  401. } else if (w == this && !scrollable) {
  402. MonthGrid grid = getMonthGrid();
  403. if (grid.isEnabled() && calendar.isRangeSelectAllowed()) {
  404. grid.setSelectionStart(this);
  405. grid.setSelectionEnd(this);
  406. }
  407. }
  408. event.stopPropagation();
  409. event.preventDefault();
  410. }
  411. @Override
  412. public void onMouseOver(MouseOverEvent event) {
  413. event.preventDefault();
  414. getMonthGrid().setSelectionEnd(this);
  415. }
  416. @Override
  417. public void onMouseMove(MouseMoveEvent event) {
  418. if (clickedWidget instanceof MonthEventLabel && !monthEventMouseDown
  419. || (startY < 0 && startX < 0)) {
  420. return;
  421. }
  422. MonthEventLabel w = (MonthEventLabel) clickedWidget;
  423. if (calendar.isDisabledOrReadOnly()) {
  424. Event.releaseCapture(getElement());
  425. monthEventMouseDown = false;
  426. startY = -1;
  427. startX = -1;
  428. return;
  429. }
  430. int currentY = event.getClientY();
  431. int currentX = event.getClientX();
  432. int moveY = (currentY - startY);
  433. int moveX = (currentX - startX);
  434. if ((moveY < 5 && moveY > -6) && (moveX < 5 && moveX > -6)) {
  435. return;
  436. }
  437. int dateCellWidth = getWidth();
  438. int dateCellHeigth = getHeigth();
  439. Element parent = getMonthGrid().getElement();
  440. int relativeX = event.getRelativeX(parent);
  441. int relativeY = event.getRelativeY(parent);
  442. int weekDiff = 0;
  443. if (moveY > 0) {
  444. weekDiff = (startYrelative + moveY) / dateCellHeigth;
  445. } else {
  446. weekDiff = (moveY - (dateCellHeigth - startYrelative))
  447. / dateCellHeigth;
  448. }
  449. int dayDiff = 0;
  450. if (moveX >= 0) {
  451. dayDiff = (startXrelative + moveX) / dateCellWidth;
  452. } else {
  453. dayDiff = (moveX - (dateCellWidth - startXrelative))
  454. / dateCellWidth;
  455. }
  456. // Check boundaries
  457. if (relativeY < 0
  458. || relativeY >= (calendar.getMonthGrid().getRowCount()
  459. * dateCellHeigth)
  460. || relativeX < 0
  461. || relativeX >= (calendar.getMonthGrid().getColumnCount()
  462. * dateCellWidth)) {
  463. return;
  464. }
  465. GWT.log("Event moving delta: " + weekDiff + " weeks " + dayDiff
  466. + " days" + " (" + getCell() + "," + getRow() + ")");
  467. CalendarEvent e = moveEvent;
  468. if (e == null) {
  469. e = getEventByWidget(w);
  470. }
  471. Date from = e.getStart();
  472. Date to = e.getEnd();
  473. long daysMs = dayDiff * DateConstants.DAYINMILLIS;
  474. long weeksMs = weekDiff * DateConstants.WEEKINMILLIS;
  475. setDates(e, from, to, weeksMs + daysMs, false);
  476. e.setStart(from);
  477. e.setEnd(to);
  478. if (w.isTimeSpecificEvent()) {
  479. Date start = new Date();
  480. Date end = new Date();
  481. setDates(e, start, end, weeksMs + daysMs, true);
  482. e.setStartTime(start);
  483. e.setEndTime(end);
  484. } else {
  485. e.setStartTime(new Date(from.getTime()));
  486. e.setEndTime(new Date(to.getTime()));
  487. }
  488. updateDragPosition(w, dayDiff, weekDiff);
  489. }
  490. private void setDates(CalendarEvent e, Date start, Date end, long shift,
  491. boolean isDateTime) {
  492. Date currentStart;
  493. Date currentEnd;
  494. if (isDateTime) {
  495. currentStart = e.getStartTime();
  496. currentEnd = e.getEndTime();
  497. } else {
  498. currentStart = e.getStart();
  499. currentEnd = e.getEnd();
  500. }
  501. long duration = currentEnd.getTime() - currentStart.getTime();
  502. if (isDateTime) {
  503. start.setTime(dndSourceStartDateTime.getTime() + shift);
  504. } else {
  505. start.setTime(dndSourceDateFrom.getTime() + shift);
  506. }
  507. end.setTime((start.getTime() + duration));
  508. }
  509. private void eventMoved(CalendarEvent e) {
  510. calendar.updateEventToMonthGrid(e);
  511. if (calendar.getEventMovedListener() != null) {
  512. calendar.getEventMovedListener().eventMoved(e);
  513. }
  514. }
  515. public void startCalendarEventDrag(MouseDownEvent event,
  516. final MonthEventLabel w) {
  517. moveRegistration = addMouseMoveHandler(this);
  518. startX = event.getClientX();
  519. startY = event.getClientY();
  520. startYrelative = event.getRelativeY(w.getParent().getElement())
  521. % getHeigth();
  522. startXrelative = event.getRelativeX(w.getParent().getElement())
  523. % getWidth();
  524. CalendarEvent e = getEventByWidget(w);
  525. dndSourceDateFrom = (Date) e.getStart().clone();
  526. dndSourceDateTo = (Date) e.getEnd().clone();
  527. dndSourceStartDateTime = (Date) e.getStartTime().clone();
  528. dndSourceEndDateTime = (Date) e.getEndTime().clone();
  529. Event.setCapture(getElement());
  530. keyDownHandler = addKeyDownHandler(new KeyDownHandler() {
  531. @Override
  532. public void onKeyDown(KeyDownEvent event) {
  533. if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
  534. cancelEventDrag(w);
  535. }
  536. }
  537. });
  538. focus();
  539. GWT.log("Start drag");
  540. }
  541. protected void cancelEventDrag(MonthEventLabel w) {
  542. if (moveRegistration != null) {
  543. // reset position
  544. if (moveEvent == null) {
  545. moveEvent = getEventByWidget(w);
  546. }
  547. moveEvent.setStart(dndSourceDateFrom);
  548. moveEvent.setEnd(dndSourceDateTo);
  549. moveEvent.setStartTime(dndSourceStartDateTime);
  550. moveEvent.setEndTime(dndSourceEndDateTime);
  551. calendar.updateEventToMonthGrid(moveEvent);
  552. // reset drag-related properties
  553. Event.releaseCapture(getElement());
  554. moveRegistration.removeHandler();
  555. moveRegistration = null;
  556. keyDownHandler.removeHandler();
  557. keyDownHandler = null;
  558. setFocus(false);
  559. monthEventMouseDown = false;
  560. startY = -1;
  561. startX = -1;
  562. moveEvent = null;
  563. labelMouseDown = false;
  564. clickedWidget = null;
  565. }
  566. }
  567. public void updateDragPosition(MonthEventLabel w, int dayDiff,
  568. int weekDiff) {
  569. // Draw event to its new position only when position has changed
  570. if (dayDiff == prevDayDiff && weekDiff == prevWeekDiff) {
  571. return;
  572. }
  573. prevDayDiff = dayDiff;
  574. prevWeekDiff = weekDiff;
  575. if (moveEvent == null) {
  576. moveEvent = getEventByWidget(w);
  577. }
  578. calendar.updateEventToMonthGrid(moveEvent);
  579. }
  580. public int getRow() {
  581. return row;
  582. }
  583. public int getCell() {
  584. return cell;
  585. }
  586. public int getHeigth() {
  587. return intHeight + BORDERPADDINGSIZE;
  588. }
  589. public int getWidth() {
  590. return getOffsetWidth() - BORDERPADDINGSIZE;
  591. }
  592. public void setToday(boolean today) {
  593. if (today) {
  594. addStyleDependentName("today");
  595. } else {
  596. removeStyleDependentName("today");
  597. }
  598. }
  599. public boolean removeEvent(CalendarEvent targetEvent,
  600. boolean reDrawImmediately) {
  601. int slot = targetEvent.getSlotIndex();
  602. if (slot < 0) {
  603. return false;
  604. }
  605. CalendarEvent e = getCalendarEvent(slot);
  606. if (targetEvent.equals(e)) {
  607. events[slot] = null;
  608. eventCount--;
  609. if (reDrawImmediately) {
  610. reDraw(moveEvent == null);
  611. }
  612. return true;
  613. }
  614. return false;
  615. }
  616. private CalendarEvent getEventByWidget(MonthEventLabel eventWidget) {
  617. int index = getWidgetIndex(eventWidget);
  618. return getCalendarEvent(index - 1);
  619. }
  620. public CalendarEvent getCalendarEvent(int i) {
  621. return events[i];
  622. }
  623. public CalendarEvent[] getEvents() {
  624. return events;
  625. }
  626. public int getEventCount() {
  627. return eventCount;
  628. }
  629. public CalendarEvent getMoveEvent() {
  630. return moveEvent;
  631. }
  632. public void addEmphasisStyle() {
  633. addStyleDependentName("dragemphasis");
  634. }
  635. public void removeEmphasisStyle() {
  636. removeStyleDependentName("dragemphasis");
  637. }
  638. }