List of usage examples for org.joda.time Interval Interval
public Interval(Object interval, Chronology chronology)
From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayItem.java
License:Open Source License
@Override public void doLayout() { if (firstDraw) { height = (int) map( new Interval(displayable.getStartTimeOnDay(displayedDay), displayable.getEndTimeOnDay(displayedDay)).toDurationMillis(), this.getParent().getHeight()); height = Math.max(height, 45); recalcBounds(getParent().getWidth(), getParent().getHeight()); FontMetrics descriptionMetrics = getGraphics().getFontMetrics(lblStarryNightdutch.getFont()); for (String word : description) { wordLengths.put(word, new Integer(descriptionMetrics.stringWidth(word))); }/*from w ww . ja v a 2 s. c o m*/ int totalHeight = 8 + getFontMetrics(lblEventTitle.getFont()).getHeight() + getFontMetrics(lblTimeInfo.getFont()).getHeight() + 6; lblEventTitle.validate(); lblTimeInfo.validate(); spaceLength = descriptionMetrics.stringWidth(" "); lineLengths = infest(descriptionMetrics.getHeight(), totalHeight); firstDraw = false; } if (isBeingDragged) { width = new Rational(1, 1); x = new Rational(0, 1); this.setBackground(new Color(getBackground().getRed(), getBackground().getGreen(), getBackground().getBlue(), 150)); int parentWidth = this.getParent().getWidth(); recalcBounds(parentWidth, getParent().getHeight()); super.doLayout(); lblEventTitle.revalidate(); lblTimeInfo.revalidate(); return; } int parentWidth = this.getParent().getWidth(); recalcBounds(parentWidth, getParent().getHeight()); super.doLayout(); }
From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayItem.java
License:Open Source License
public void addMinutesToEnd(int minutes) { MutableDateTime d = displayable.getEnd().toMutableDateTime(); d.addMinutes(minutes);/*from w ww . j a v a2s .c o m*/ DateTime newEnd = d.toDateTime(); try { Interval potential = new Interval(displayable.getStart(), newEnd); if (potential.toDurationMillis() < 1000) { throw new IllegalArgumentException("cant make the event that short!!"); } height = Math.max(45, height + minutes); displayable.setEnd(newEnd); height = Math.max(45, height + minutes); length = potential; reval(); } catch (IllegalArgumentException e) { // if the date time interval is malformed (the user dragged to a bad spot) } }
From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayItem.java
License:Open Source License
public void addMinutesToStart(int minutes) { MutableDateTime d = displayable.getStart().toMutableDateTime(); d.addMinutes(minutes);/*from w w w. j a v a 2s .c o m*/ DateTime newStart = d.toDateTime(); try { Interval potential = new Interval(newStart, displayable.getEnd()); if (potential.toDurationMillis() < 1000) { throw new IllegalArgumentException("cant make the event that short!!"); } height = Math.max(45, height + minutes); displayable.setStart(newStart); height += minutes; length = potential; reval(); } catch (IllegalArgumentException e) { // if the date time interval is malformed (the user dragged to a bad spot) } }
From source file:com.tmathmeyer.sentinel.ui.views.day.DayCalendar.java
License:Open Source License
/** * Gets all the events in the week that also are in the given interval * /*from ww w.j a v a2 s .com*/ * @param intervalStart start of the interval to check * @param intervalEnd end of the interval to check * @return list of events that are both in the week and interval */ private List<Displayable> getDisplayablesInInterval(DateTime intervalStart, DateTime intervalEnd) { List<Displayable> retrievedDisplayables = new ArrayList<>(); Interval mInterval = new Interval(intervalStart, intervalEnd); for (Displayable d : displayableList) { if (isDisplayableInInterval(d, mInterval)) { retrievedDisplayables.add(d); } } return retrievedDisplayables; }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Adds all multiday event items into grids corresponding to the days of the * week then adds them to the top bar display *///from w ww .ja v a 2 s . c o m private void populateMultidayEventGrid() { List<Event> multidayEvents = getMultidayEvents(); multidayItemList.clear(); Collections.sort(multidayEvents, new Comparator<Event>() { @Override public int compare(Event o1, Event o2) { return o1.getEnd().compareTo(o2.getEnd()); } }); int rows = 0; while (!multidayEvents.isEmpty()) { JPanel multiGrid = new JPanel(); multiGrid.setBorder(BorderFactory.createEmptyBorder()); multiGrid.setLayout(new MigLayout("insets 0,gap 0", "[sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow]", "[]")); int gridIndex = 0; next: while (gridIndex < 7) { Interval mInterval = new Interval(daysOfWeekArray[gridIndex].getDisplayDate(), daysOfWeekArray[gridIndex].getDisplayDate().plusDays(1)); for (Event currEvent : multidayEvents) { if (isDisplayableInInterval(currEvent, mInterval)) { boolean firstPanel = true; WeekMultidayEventItem multidayPanel; do { if (firstPanel) { multidayPanel = new WeekMultidayEventItem(currEvent, MultidayEventItemType.Start, " " + currEvent.getName()); multidayPanel.setMinimumSize(new Dimension(0, 0)); multidayPanel.setBackground(currEvent.getColor()); if (multiGrid.getComponentCount() > 0) ((JComponent) multiGrid.getComponents()[multiGrid.getComponentCount() - 1]) .setBorder(BorderFactory.createMatteBorder(rows == 0 ? 1 : 0, (gridIndex == 1) ? 1 : 0, 1, 0, Colors.BORDER)); multidayPanel.setRows(rows); multidayPanel.setDynamicBorder(currEvent.getColor().darker(), false); multiGrid.add(multidayPanel, "cell " + gridIndex + " 0, grow"); multidayItemList.add(multidayPanel); firstPanel = false; } else { multidayPanel = new WeekMultidayEventItem(currEvent, MultidayEventItemType.Middle); multidayPanel.setBackground(currEvent.getColor()); multidayPanel.setRows(rows); multidayPanel.setDynamicBorder(currEvent.getColor().darker(), false); multiGrid.add(multidayPanel, "cell " + gridIndex + " 0, grow"); multidayItemList.add(multidayPanel); } gridIndex++; } while (gridIndex < 7 && daysOfWeekArray[gridIndex].getDisplayDate().isBefore(currEvent.getEnd())); if (multidayPanel.getType() == MultidayEventItemType.Start) multidayPanel.setType(MultidayEventItemType.Single); else multidayPanel.setType(MultidayEventItemType.End); multidayPanel.setDynamicBorder(currEvent.getColor().darker(), false); multidayEvents.remove(currEvent); continue next; } } // if we don't find anything, add spacer and go to next day gridIndex++; WeekMultidayEventItem spacer = new WeekMultidayEventItem(null, gridIndex == 1 ? MultidayEventItemType.Start : gridIndex == 7 ? MultidayEventItemType.End : MultidayEventItemType.Middle); spacer.setBackground(Colors.TABLE_BACKGROUND); spacer.setRows(rows); spacer.setSpacer(true); spacer.setDynamicBorder(Colors.BORDER, false); multiGrid.add(spacer, "cell " + (gridIndex - 1) + " 0, grow"); } if (multiGrid.getComponentCount() > 0) headerBox.add(multiGrid); rows++; } // need to set this manually, silly because scrollpanes are silly and // don't resize if (rows > 3) { add(headerScroller, "cell 1 2 8 1,grow"); rows = 3; } else { add(headerScroller, "cell 1 2 7 1,grow"); } ((MigLayout) getLayout()).setRowConstraints( "[][][" + (rows * 23 + 1) + "px:n:80px,grow]" + (rows > 0 ? "6" : "") + "[grow]"); }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Selects an event's corresponding Displayable * /* w ww . j a va 2s . c o m*/ * @param on Event being selected * @param setTo Displayable of Event being selected */ private void selectEvents(Event on, Displayable setTo) { // TODO: refactor this pattern DayPanel mLouvreTour; MutableDateTime startDay = new MutableDateTime(on.getStart()); MutableDateTime endDay = new MutableDateTime(on.getEnd()); endDay.setMillisOfDay(0); endDay.addDays(1); endDay.addMillis(-1); startDay.setMillisOfDay(0); Interval eventLength = new Interval(startDay, endDay); if (setTo == null || eventLength.toDuration().getStandardHours() > 24) { for (WeekMultidayEventItem multidayItem : multidayItemList) { if (setTo != null && multidayItem.getEvent().getUuid().equals(((Event) on).getUuid())) multidayItem.setSelected(true); else multidayItem.setSelected(false); } return; } // TODO: can be simplified now that multiday events are handled // elsewhere int index = 0; for (int i = 0; i < 7; i++) { if (startDay.getDayOfYear() == daysOfWeekArray[i].getDisplayDate().getDayOfYear()) { index = i; break; } } while (index < 7 && !endDay.isBefore(daysOfWeekArray[index].getDisplayDate())) { mLouvreTour = daysOfWeekArray[index]; try { mLouvreTour.select(setTo); } catch (NullPointerException ex) { // silently ignore as this is apparently not in the view } index++; } }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Gets all the events in the week that also are in the given interval * //w ww. ja v a2s. co m * @param intervalStart start of the interval to check * @param intervalEnd end of the interval to check * @return list of events that are both in the week and interval */ private List<Displayable> getDisplayablesInInterval(DateTime intervalStart, DateTime intervalEnd) { List<Displayable> retrievedDisplayables = new ArrayList<>(); Interval mInterval = new Interval(intervalStart, intervalEnd); for (Displayable d : displayableList) { if (new Interval(d.getStart(), d.getEnd()).toDuration().getStandardHours() > 24) continue; if (isDisplayableInInterval(d, mInterval)) { retrievedDisplayables.add(d); } } return retrievedDisplayables; }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Gets the multiday events in the scope of the week * /* w ww . j av a 2 s . c om*/ * @return list of multiday events */ private List<Event> getMultidayEvents() { List<Event> retrievedEvents = new ArrayList<>(); for (Displayable d : displayableList) { if (!(d instanceof Event)) continue; DateTime intervalStart = d.getStart(); DateTime intervalEnd = d.getEnd(); Interval mInterval = new Interval(intervalStart, intervalEnd); if (mInterval.toDuration().getStandardHours() > 24) retrievedEvents.add(((Event) d)); } return retrievedEvents; }
From source file:com.tripadvisor.seekbar.ClockView.java
License:Apache License
public void setBounds(DateTime minTime, DateTime maxTime, boolean isMaxClock) { // NOTE: To show correct end time on clock, since the Interval.contains() checks for // millisInstant >= thisStart && millisInstant < thisEnd // however we want // millisInstant >= thisStart && millisInstant <= thisEnd maxTime = maxTime.plusMillis(1);//from w w w . ja v a2 s . c o m mValidTimeInterval = new Interval(minTime, maxTime); maxTime = maxTime.minusMillis(1); mCircularClockSeekBar.reset(); if (isMaxClock) { mOriginalTime = maxTime; mCurrentValidTime = maxTime; int hourOfDay = maxTime.get(DateTimeFieldType.clockhourOfDay()) % 12; mCircularClockSeekBar.setProgress(hourOfDay * 10); setClockText(mOriginalTime); } else { mOriginalTime = minTime; mCurrentValidTime = minTime; int hourOfDay = minTime.get(DateTimeFieldType.clockhourOfDay()) % 12; mCircularClockSeekBar.setProgress(hourOfDay * 10); setClockText(mOriginalTime); } }
From source file:com.wealdtech.jackson.modules.IntervalDeserializer.java
License:Open Source License
@Override public Interval deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); DateTime start = deserializeDateTime(node, "start"); DateTime end = deserializeDateTime(node, "end"); return new Interval(start, end); }