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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * Copyright 2000-2014 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.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.client.ui.VCalendar;
  40. import com.vaadin.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
  48. MouseUpHandler, 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
  202. - ((slots * EVENTHEIGHT) + BOTTOMSPACERHEIGHT + caption
  203. .getOffsetHeight());
  204. int newHeight = remainingSpace + BOTTOMSPACERHEIGHT;
  205. if (newHeight < 0) {
  206. newHeight = EVENTHEIGHT;
  207. }
  208. bottomspacer.setHeight(newHeight + "px");
  209. if (clear) {
  210. add(bottomspacer);
  211. }
  212. int more = eventCount - eventsAdded;
  213. if (more > 0) {
  214. if (bottomSpacerMouseDownHandler == null) {
  215. bottomSpacerMouseDownHandler = bottomspacer
  216. .addMouseDownHandler(this);
  217. }
  218. bottomspacer.setStyleName("v-calendar-bottom-spacer");
  219. bottomspacer.setText("+ " + more);
  220. } else {
  221. if (!scrollable && bottomSpacerMouseDownHandler != null) {
  222. bottomSpacerMouseDownHandler.removeHandler();
  223. bottomSpacerMouseDownHandler = null;
  224. }
  225. if (scrollable) {
  226. bottomspacer.setText("[ - ]");
  227. } else {
  228. bottomspacer.setStyleName("v-calendar-bottom-spacer-empty");
  229. bottomspacer.setText("");
  230. }
  231. }
  232. }
  233. private MonthEventLabel createMonthEventLabel(CalendarEvent e) {
  234. long rangeInMillis = e.getRangeInMilliseconds();
  235. boolean timeEvent = rangeInMillis <= DateConstants.DAYINMILLIS
  236. && !e.isAllDay();
  237. Date fromDatetime = e.getStartTime();
  238. // Create a new MonthEventLabel
  239. MonthEventLabel eventDiv = new MonthEventLabel();
  240. eventDiv.addStyleDependentName("month");
  241. eventDiv.addMouseDownHandler(this);
  242. eventDiv.addMouseUpHandler(this);
  243. eventDiv.setCalendar(calendar);
  244. eventDiv.setEventIndex(e.getIndex());
  245. eventDiv.setCalendarEvent(e);
  246. if (timeEvent) {
  247. eventDiv.setTimeSpecificEvent(true);
  248. if (e.getStyleName() != null) {
  249. eventDiv.addStyleDependentName(e.getStyleName());
  250. }
  251. eventDiv.setCaption(e.getCaption());
  252. eventDiv.setTime(fromDatetime);
  253. } else {
  254. eventDiv.setTimeSpecificEvent(false);
  255. Date from = e.getStart();
  256. Date to = e.getEnd();
  257. if (e.getStyleName().length() > 0) {
  258. eventDiv.addStyleName("month-event " + e.getStyleName());
  259. } else {
  260. eventDiv.addStyleName("month-event");
  261. }
  262. int fromCompareToDate = from.compareTo(date);
  263. int toCompareToDate = to.compareTo(date);
  264. eventDiv.addStyleDependentName("all-day");
  265. if (fromCompareToDate == 0) {
  266. eventDiv.addStyleDependentName("start");
  267. eventDiv.setCaption(e.getCaption());
  268. } else if (fromCompareToDate < 0 && cell == 0) {
  269. eventDiv.addStyleDependentName("continued-from");
  270. eventDiv.setCaption(e.getCaption());
  271. }
  272. if (toCompareToDate == 0) {
  273. eventDiv.addStyleDependentName("end");
  274. } else if (toCompareToDate > 0
  275. && (cell + 1) == getMonthGrid().getCellCount(row)) {
  276. eventDiv.addStyleDependentName("continued-to");
  277. }
  278. if (e.getStyleName() != null) {
  279. eventDiv.addStyleDependentName(e.getStyleName() + "-all-day");
  280. }
  281. }
  282. return eventDiv;
  283. }
  284. private void setUnlimitedCellHeight() {
  285. scrollable = true;
  286. addStyleDependentName("scrollable");
  287. }
  288. private void setLimitedCellHeight() {
  289. scrollable = false;
  290. removeStyleDependentName("scrollable");
  291. }
  292. public void addCalendarEvent(CalendarEvent e) {
  293. eventCount++;
  294. int slot = e.getSlotIndex();
  295. if (slot == -1) {
  296. for (int i = 0; i < events.length; i++) {
  297. if (events[i] == null) {
  298. events[i] = e;
  299. e.setSlotIndex(i);
  300. break;
  301. }
  302. }
  303. } else {
  304. events[slot] = e;
  305. }
  306. }
  307. @SuppressWarnings("deprecation")
  308. public void setMonthNameVisible(boolean b) {
  309. monthNameVisible = b;
  310. int dateOfMonth = date.getDate();
  311. caption.setText(dateOfMonth + " "
  312. + calendar.getMonthNames()[date.getMonth()]);
  313. }
  314. public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
  315. return addDomHandler(handler, MouseMoveEvent.getType());
  316. }
  317. @Override
  318. protected void onAttach() {
  319. super.onAttach();
  320. mouseUpRegistration = addDomHandler(this, MouseUpEvent.getType());
  321. mouseDownRegistration = addDomHandler(this, MouseDownEvent.getType());
  322. mouseOverRegistration = addDomHandler(this, MouseOverEvent.getType());
  323. }
  324. @Override
  325. protected void onDetach() {
  326. mouseUpRegistration.removeHandler();
  327. mouseDownRegistration.removeHandler();
  328. mouseOverRegistration.removeHandler();
  329. super.onDetach();
  330. }
  331. @Override
  332. public void onMouseUp(MouseUpEvent event) {
  333. if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
  334. return;
  335. }
  336. Widget w = (Widget) event.getSource();
  337. if (moveRegistration != null) {
  338. Event.releaseCapture(getElement());
  339. moveRegistration.removeHandler();
  340. moveRegistration = null;
  341. keyDownHandler.removeHandler();
  342. keyDownHandler = null;
  343. }
  344. if (w == bottomspacer && monthEventMouseDown) {
  345. GWT.log("Mouse up over bottomspacer");
  346. } else if (clickedWidget instanceof MonthEventLabel
  347. && monthEventMouseDown) {
  348. MonthEventLabel mel = (MonthEventLabel) clickedWidget;
  349. int endX = event.getClientX();
  350. int endY = event.getClientY();
  351. int xDiff = 0, yDiff = 0;
  352. if (startX != -1 && startY != -1) {
  353. xDiff = startX - endX;
  354. yDiff = startY - endY;
  355. }
  356. startX = -1;
  357. startY = -1;
  358. prevDayDiff = 0;
  359. prevWeekDiff = 0;
  360. if (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3) {
  361. eventMoved(moveEvent);
  362. } else if (calendar.getEventClickListener() != null) {
  363. CalendarEvent e = getEventByWidget(mel);
  364. calendar.getEventClickListener().eventClick(e);
  365. }
  366. moveEvent = null;
  367. } else if (w == this) {
  368. getMonthGrid().setSelectionReady();
  369. } else if (w instanceof Label && labelMouseDown) {
  370. String clickedDate = calendar.getDateFormat().format(date);
  371. if (calendar.getDateClickListener() != null) {
  372. calendar.getDateClickListener().dateClick(clickedDate);
  373. }
  374. }
  375. monthEventMouseDown = false;
  376. labelMouseDown = false;
  377. clickedWidget = null;
  378. }
  379. @Override
  380. public void onMouseDown(MouseDownEvent event) {
  381. if (calendar.isDisabled()
  382. || event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
  383. return;
  384. }
  385. Widget w = (Widget) event.getSource();
  386. clickedWidget = w;
  387. if (w instanceof MonthEventLabel) {
  388. // event clicks should be allowed even when read-only
  389. monthEventMouseDown = true;
  390. if (calendar.isEventMoveAllowed()) {
  391. startCalendarEventDrag(event, (MonthEventLabel) w);
  392. }
  393. } else if (w == bottomspacer) {
  394. if (scrollable) {
  395. setLimitedCellHeight();
  396. } else {
  397. setUnlimitedCellHeight();
  398. }
  399. reDraw(true);
  400. } else if (w instanceof Label) {
  401. labelMouseDown = true;
  402. } else if (w == this && !scrollable) {
  403. MonthGrid grid = getMonthGrid();
  404. if (grid.isEnabled() && calendar.isRangeSelectAllowed()) {
  405. grid.setSelectionStart(this);
  406. grid.setSelectionEnd(this);
  407. }
  408. }
  409. event.stopPropagation();
  410. event.preventDefault();
  411. }
  412. @Override
  413. public void onMouseOver(MouseOverEvent event) {
  414. event.preventDefault();
  415. getMonthGrid().setSelectionEnd(this);
  416. }
  417. @Override
  418. public void onMouseMove(MouseMoveEvent event) {
  419. if (clickedWidget instanceof MonthEventLabel && !monthEventMouseDown
  420. || (startY < 0 && startX < 0)) {
  421. return;
  422. }
  423. MonthEventLabel w = (MonthEventLabel) clickedWidget;
  424. if (calendar.isDisabledOrReadOnly()) {
  425. Event.releaseCapture(getElement());
  426. monthEventMouseDown = false;
  427. startY = -1;
  428. startX = -1;
  429. return;
  430. }
  431. int currentY = event.getClientY();
  432. int currentX = event.getClientX();
  433. int moveY = (currentY - startY);
  434. int moveX = (currentX - startX);
  435. if ((moveY < 5 && moveY > -6) && (moveX < 5 && moveX > -6)) {
  436. return;
  437. }
  438. int dateCellWidth = getWidth();
  439. int dateCellHeigth = getHeigth();
  440. Element parent = getMonthGrid().getElement();
  441. int relativeX = event.getRelativeX(parent);
  442. int relativeY = event.getRelativeY(parent);
  443. int weekDiff = 0;
  444. if (moveY > 0) {
  445. weekDiff = (startYrelative + moveY) / dateCellHeigth;
  446. } else {
  447. weekDiff = (moveY - (dateCellHeigth - startYrelative))
  448. / dateCellHeigth;
  449. }
  450. int dayDiff = 0;
  451. if (moveX >= 0) {
  452. dayDiff = (startXrelative + moveX) / dateCellWidth;
  453. } else {
  454. dayDiff = (moveX - (dateCellWidth - startXrelative))
  455. / dateCellWidth;
  456. }
  457. // Check boundaries
  458. if (relativeY < 0
  459. || relativeY >= (calendar.getMonthGrid().getRowCount() * dateCellHeigth)
  460. || relativeX < 0
  461. || relativeX >= (calendar.getMonthGrid().getColumnCount() * dateCellWidth)) {
  462. return;
  463. }
  464. GWT.log("Event moving delta: " + weekDiff + " weeks " + dayDiff
  465. + " days" + " (" + getCell() + "," + getRow() + ")");
  466. CalendarEvent e = moveEvent;
  467. if (e == null) {
  468. e = getEventByWidget(w);
  469. }
  470. Date from = e.getStart();
  471. Date to = e.getEnd();
  472. long daysMs = dayDiff * DateConstants.DAYINMILLIS;
  473. long weeksMs = weekDiff * DateConstants.WEEKINMILLIS;
  474. setDates(e, from, to, weeksMs + daysMs, false);
  475. e.setStart(from);
  476. e.setEnd(to);
  477. if (w.isTimeSpecificEvent()) {
  478. Date start = new Date();
  479. Date end = new Date();
  480. setDates(e, start, end, weeksMs + daysMs, true);
  481. e.setStartTime(start);
  482. e.setEndTime(end);
  483. } else {
  484. e.setStartTime(new Date(from.getTime()));
  485. e.setEndTime(new Date(to.getTime()));
  486. }
  487. updateDragPosition(w, dayDiff, weekDiff);
  488. }
  489. private void setDates(CalendarEvent e, Date start, Date end, long shift,
  490. boolean isDateTime) {
  491. Date currentStart;
  492. Date currentEnd;
  493. if (isDateTime) {
  494. currentStart = e.getStartTime();
  495. currentEnd = e.getEndTime();
  496. } else {
  497. currentStart = e.getStart();
  498. currentEnd = e.getEnd();
  499. }
  500. long duration = currentEnd.getTime() - currentStart.getTime();
  501. if (isDateTime) {
  502. start.setTime(dndSourceStartDateTime.getTime() + shift);
  503. } else {
  504. start.setTime(dndSourceDateFrom.getTime() + shift);
  505. }
  506. end.setTime((start.getTime() + duration));
  507. }
  508. private void eventMoved(CalendarEvent e) {
  509. calendar.updateEventToMonthGrid(e);
  510. if (calendar.getEventMovedListener() != null) {
  511. calendar.getEventMovedListener().eventMoved(e);
  512. }
  513. }
  514. public void startCalendarEventDrag(MouseDownEvent event,
  515. final MonthEventLabel w) {
  516. moveRegistration = addMouseMoveHandler(this);
  517. startX = event.getClientX();
  518. startY = event.getClientY();
  519. startYrelative = event.getRelativeY(w.getParent().getElement())
  520. % getHeigth();
  521. startXrelative = event.getRelativeX(w.getParent().getElement())
  522. % getWidth();
  523. CalendarEvent e = getEventByWidget(w);
  524. dndSourceDateFrom = (Date) e.getStart().clone();
  525. dndSourceDateTo = (Date) e.getEnd().clone();
  526. dndSourceStartDateTime = (Date) e.getStartTime().clone();
  527. dndSourceEndDateTime = (Date) e.getEndTime().clone();
  528. Event.setCapture(getElement());
  529. keyDownHandler = addKeyDownHandler(new KeyDownHandler() {
  530. @Override
  531. public void onKeyDown(KeyDownEvent event) {
  532. if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
  533. cancelEventDrag(w);
  534. }
  535. }
  536. });
  537. focus();
  538. GWT.log("Start drag");
  539. }
  540. protected void cancelEventDrag(MonthEventLabel w) {
  541. if (moveRegistration != null) {
  542. // reset position
  543. if (moveEvent == null) {
  544. moveEvent = getEventByWidget(w);
  545. }
  546. moveEvent.setStart(dndSourceDateFrom);
  547. moveEvent.setEnd(dndSourceDateTo);
  548. moveEvent.setStartTime(dndSourceStartDateTime);
  549. moveEvent.setEndTime(dndSourceEndDateTime);
  550. calendar.updateEventToMonthGrid(moveEvent);
  551. // reset drag-related properties
  552. Event.releaseCapture(getElement());
  553. moveRegistration.removeHandler();
  554. moveRegistration = null;
  555. keyDownHandler.removeHandler();
  556. keyDownHandler = null;
  557. setFocus(false);
  558. monthEventMouseDown = false;
  559. startY = -1;
  560. startX = -1;
  561. moveEvent = null;
  562. labelMouseDown = false;
  563. clickedWidget = null;
  564. }
  565. }
  566. public void updateDragPosition(MonthEventLabel w, int dayDiff, int weekDiff) {
  567. // Draw event to its new position only when position has changed
  568. if (dayDiff == prevDayDiff && weekDiff == prevWeekDiff) {
  569. return;
  570. }
  571. prevDayDiff = dayDiff;
  572. prevWeekDiff = weekDiff;
  573. if (moveEvent == null) {
  574. moveEvent = getEventByWidget(w);
  575. }
  576. calendar.updateEventToMonthGrid(moveEvent);
  577. }
  578. public int getRow() {
  579. return row;
  580. }
  581. public int getCell() {
  582. return cell;
  583. }
  584. public int getHeigth() {
  585. return intHeight + BORDERPADDINGSIZE;
  586. }
  587. public int getWidth() {
  588. return getOffsetWidth() - BORDERPADDINGSIZE;
  589. }
  590. public void setToday(boolean today) {
  591. if (today) {
  592. addStyleDependentName("today");
  593. } else {
  594. removeStyleDependentName("today");
  595. }
  596. }
  597. public boolean removeEvent(CalendarEvent targetEvent,
  598. boolean reDrawImmediately) {
  599. int slot = targetEvent.getSlotIndex();
  600. if (slot < 0) {
  601. return false;
  602. }
  603. CalendarEvent e = getCalendarEvent(slot);
  604. if (targetEvent.equals(e)) {
  605. events[slot] = null;
  606. eventCount--;
  607. if (reDrawImmediately) {
  608. reDraw(moveEvent == null);
  609. }
  610. return true;
  611. }
  612. return false;
  613. }
  614. private CalendarEvent getEventByWidget(MonthEventLabel eventWidget) {
  615. int index = getWidgetIndex(eventWidget);
  616. return getCalendarEvent(index - 1);
  617. }
  618. public CalendarEvent getCalendarEvent(int i) {
  619. return events[i];
  620. }
  621. public CalendarEvent[] getEvents() {
  622. return events;
  623. }
  624. public int getEventCount() {
  625. return eventCount;
  626. }
  627. public CalendarEvent getMoveEvent() {
  628. return moveEvent;
  629. }
  630. public void addEmphasisStyle() {
  631. addStyleDependentName("dragemphasis");
  632. }
  633. public void removeEmphasisStyle() {
  634. removeStyleDependentName("dragemphasis");
  635. }
  636. }