List of usage examples for org.joda.time MutableDateTime setMillisOfDay
public void setMillisOfDay(final int millisOfDay)
From source file:com.metamx.druid.http.FileRequestLogger.java
License:Open Source License
@LifecycleStart public void start() { try {/*from w w w . j a v a2 s. c om*/ baseDir.mkdirs(); MutableDateTime mutableDateTime = new DateTime().toMutableDateTime(); mutableDateTime.setMillisOfDay(0); currentDay = mutableDateTime.toDateTime(); fileWriter = new FileWriter(new File(baseDir, currentDay.toString("yyyy-MM-dd'.log'")), true); long nextDay = currentDay.plusDays(1).getMillis(); Duration delay = new Duration(nextDay - new DateTime().getMillis()); ScheduledExecutors.scheduleWithFixedDelay(exec, delay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() { @Override public ScheduledExecutors.Signal call() { currentDay = currentDay.plusDays(1); try { synchronized (lock) { Closeables.closeQuietly(fileWriter); fileWriter = new FileWriter(new File(baseDir, currentDay.toString()), true); } } catch (Exception e) { Throwables.propagate(e); } return ScheduledExecutors.Signal.REPEAT; } }); } catch (IOException e) { Throwables.propagate(e); } }
From source file:com.tmathmeyer.sentinel.models.data.Commitment.java
License:Open Source License
/** * this is primarily used for multiday events * //from w w w . j av a 2s. co m * @param givenDay gets the time that this event starts on a given day * @return when this event starts */ public DateTime getStartTimeOnDay(DateTime givenDay) { MutableDateTime mDisplayedDay = new MutableDateTime(givenDay); mDisplayedDay.setMillisOfDay(1); // if it starts before the beginning of the day then its a multi day // event, or all day event if (this.getStart().isBefore(mDisplayedDay)) { mDisplayedDay.setMillisOfDay(0); return (mDisplayedDay.toDateTime()); } else return this.getStart(); }
From source file:com.tmathmeyer.sentinel.models.data.Commitment.java
License:Open Source License
/** * this is primarily used for multiday events * /*w ww . ja va 2 s . c om*/ * @param givenDay gets the time that this event ends on a given day * @return when this event ends */ public DateTime getEndTimeOnDay(DateTime givenDay) { MutableDateTime mDisplayedDay = new MutableDateTime(givenDay); ; mDisplayedDay.setMillisOfDay(86400000 - 2); if (this.getStart().plusMinutes(30).isAfter(mDisplayedDay)) { return mDisplayedDay.toDateTime(); } else return this.getStart().plusMinutes(30); }
From source file:com.tmathmeyer.sentinel.models.data.Event.java
License:Open Source License
/** * this is primarily used for multiday events * /*from w ww. j a va2 s. c o m*/ * @param givenDay gets the time that this event ends on a given day * @return when this event ends */ public DateTime getEndTimeOnDay(DateTime givenDay) { MutableDateTime mDisplayedDay = new MutableDateTime(givenDay); ; mDisplayedDay.setMillisOfDay(86400000 - 2); if (this.getEnd().isAfter(mDisplayedDay)) { return mDisplayedDay.toDateTime(); } else return this.getEnd(); }
From source file:com.tmathmeyer.sentinel.ui.navigation.MiniMonth.java
License:Open Source License
public MiniMonth(DateTime time, final MiniCalendarHostIface mc, boolean monthOnly) { this.setLayout(new GridLayout(7, 7)); MutableDateTime prevMonth = new MutableDateTime(time); prevMonth.setDayOfMonth(1);/*w w w .j ava2 s . co m*/ prevMonth.addMonths(-1); // What is prevMonth for? String[] dayLabel = { "S", "M", "T", "W", "R", "F", "S" }; MouseListener monthChanger = new MouseListener() { @Override public void mouseClicked(MouseEvent me) { } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } @Override public void mousePressed(MouseEvent me) { } @Override public void mouseReleased(MouseEvent me) { DayLabel d = (DayLabel) (me.getSource()); if (!(d instanceof DescriptiveDayLabel)) { mc.display(d.getMonth()); } } }; MutableDateTime referenceDay = new MutableDateTime(time); // reset to the first of the month at midnight, then find Sunday referenceDay.setDayOfMonth(1); referenceDay.setMillisOfDay(0); int first = referenceDay.getDayOfWeek(); referenceDay.addDays(-first); boolean flipFlop = false; // add day labels for (int i = 0; i < 7; i++) { DayLabel day = new DescriptiveDayLabel(dayLabel[i], time); day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6); add(day); day.addMouseListener(monthChanger); } // generate days, 6*7 covers all possible months, so we just loop // through and add each day for (int i = 0; i < (6 * 7); i++) { DayLabel day; if (monthOnly || MainPanel.getInstance().getView() == ViewSize.Month) { if (referenceDay.getDayOfMonth() == 1) flipFlop ^= true; // flops the flip flop flappity flip } else if (MainPanel.getInstance().getView() == ViewSize.Day) flipFlop = referenceDay.getDayOfYear() == time.getDayOfYear() && referenceDay.getYear() == time.getYear(); else if (MainPanel.getInstance().getView() == ViewSize.Week) { if (Months.getWeekStart(time).getMonthOfYear() == 12 && Months.getWeekStart(time).getDayOfMonth() >= 26) // Exception // case // for // weeks // between // years flipFlop = time.getMonthOfYear() == 12 ? i >= 35 : i <= 6; else flipFlop = referenceDay.getDayOfYear() >= Months.getWeekStart(time).getDayOfYear() && referenceDay.getDayOfYear() <= Months.getWeekStart(time).getDayOfYear() + 6; } if (flipFlop) day = new ActiveDayLabel(referenceDay.toDateTime()); else day = new InactiveDayLabel(referenceDay.toDateTime()); day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6); add(day); day.addMouseListener(monthChanger); referenceDay.addDays(1); // go to next day } }
From source file:com.tmathmeyer.sentinel.ui.views.day.DayCalendar.java
License:Open Source License
/** * Get visible events for the current day view * //from ww w .ja va 2 s.c o m * @return returns the list of events to display */ private List<Displayable> getVisibleDisplayables() { // Set up from and to datetime for search MutableDateTime f = new MutableDateTime(time); f.setMillisOfDay(0); DateTime from = f.toDateTime(); f.addDays(1); DateTime to = f.toDateTime(); // Return list of events to be displayed List<Displayable> visibleDisplayables = new ArrayList<Displayable>(); visibleDisplayables.addAll(EventClient.getInstance().getWithinRange(from, to)); visibleDisplayables.addAll(CommitmentClient.getInstance().getCommitments(from, to)); Collections.sort(visibleDisplayables, new Comparator<Displayable>() { public int compare(Displayable d1, Displayable d2) { return d1.getStart().getMinuteOfDay() < d2.getStart().getMinuteOfDay() ? -1 : d1.getStart().getMinuteOfDay() > d2.getStart().getMinuteOfDay() ? 1 : 0; } }); return visibleDisplayables; }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java
License:Open Source License
/** * /*from www . ja va 2s . co m*/ * @param fom the mutable date time */ public void generateHeaders(MutableDateTime fom) { // Set up label for month title monthLabel.setHorizontalAlignment(JLabel.CENTER); monthLabel.setFont(new java.awt.Font("DejaVu Sans", Font.BOLD, 25)); // Set up the container title panel (only holds monthLabel for now) calendarTitlePanel.setLayout(new BorderLayout()); calendarTitlePanel.add(monthLabel, BorderLayout.CENTER); // layout code mainCalendarView.setBackground(Colors.TABLE_BACKGROUND); mainCalendarView.setLayout(new BorderLayout()); top.setLayout(new GridLayout(1, 7)); mainCalendarView.add(top, BorderLayout.NORTH); mainCalendarView.add(inside, BorderLayout.CENTER); this.add(mainCalendarView, BorderLayout.CENTER); this.add(calendarTitlePanel, BorderLayout.NORTH); // end layout code fom.setDayOfMonth(1); fom.setMillisOfDay(0); int first = (fom.getDayOfWeek() % 7); fom.addDays(-first); // generate days on top for (int i = 0; i < 7; i++) { JLabel jl = new JLabel(fom.dayOfWeek().getAsText()); jl.setHorizontalAlignment(SwingConstants.CENTER); fom.addDays(1); top.add(jl); } }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java
License:Open Source License
/** * Adds or deletes a displayable from the days its occupies * /*from w w w . j av a2 s. c o m*/ * @param e * @param add */ protected void traverseDisplayable(Displayable e, Lambda<MonthDay> func) { // get and normalize the range of the disp Interval ival = e.getInterval(); MutableDateTime startDay = new MutableDateTime(ival.getStart()); MutableDateTime endDay = new MutableDateTime(ival.getEnd()); endDay.setMillisOfDay(0); startDay.setMillisOfDay(0); // bound it inside this visible month if (startDay.isBefore(firstOnMonth)) startDay = new MutableDateTime(firstOnMonth); if (endDay.isAfter(lastOnMonth)) endDay = new MutableDateTime(lastOnMonth); // go from start to end and add it to all the days in the way while (!endDay.isBefore(startDay)) { MonthDay md = this.days.get(startDay.getDayOfYear()); if (md != null) func.call(md); startDay.addDays(1); } }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java
License:Open Source License
/** * Fill calendar with month in referenceDay * //w w w . j a v a 2 s. com * @param referenceDay what month should we display */ protected void generateDays(MutableDateTime referenceDay) { // reset to the first of the month at midnight, then find Sunday referenceDay.setDayOfMonth(1); referenceDay.setMillisOfDay(0); int first = (referenceDay.getDayOfWeek() % 7); int daysInView = first + referenceDay.dayOfMonth().getMaximumValue(); int weeks = (int) Math.ceil(daysInView / 7.0); inside.setLayout(new java.awt.GridLayout(weeks, 7)); referenceDay.addDays(-first); firstOnMonth = new DateTime(referenceDay); // remove all old days inside.removeAll(); DateTime from = referenceDay.toDateTime(); // generate days, weeks*7 covers all possible months, so we just loop // through and add each day for (int i = 0; i < (weeks * 7); i++) { MonthDay md = new MonthDay(referenceDay.toDateTime(), getMarker(referenceDay), this); inside.add(md); md.reBorder(i < 7, (i % 7) == 0, i >= (weeks - 1) * 7); this.days.put(referenceDay.getDayOfYear(), md); referenceDay.addDays(1); // go to next day } referenceDay.addDays(-1);// go back one to counteract last add one lastOnMonth = new DateTime(referenceDay); setDisplayables(getVisibleItems(from, referenceDay.toDateTime())); monthLabel.setText(this.getTime().toString(Months.monthLblFormat)); // notify mini-calendar to change mainPanel.miniMove(time); // repaint when changed mainPanel.revalidate(); }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Generates the day displays in the week panel */// ww w.ja v a2 s .c om private void generateDay() { // clear out the specifics smithsonian.removeAll(); headerBox.removeAll(); // add the day grid back in hourLabels = new DayGridLabel(); smithsonian.add(hourLabels, "cell 0 0,grow"); MutableDateTime increment = new MutableDateTime(weekStartTime); increment.setMillisOfDay(0); DateTime now = DateTime.now().withMillisOfDay(0); displayableList = getVisibleDisplayables(); for (int i = 0; i < 7; i++) { // add day views to the day grid this.daysOfWeekArray[i] = new DayPanel(true, this); this.daysOfWeekArray[i].setEvents( getDisplayablesInInterval(increment.toDateTime(), increment.toDateTime().plusDays(1)), increment.toDateTime()); this.daysOfWeekArray[i] .setBorder(BorderFactory.createMatteBorder(1, 0, 1, i == 6 ? 0 : 1, Colors.BORDER)); this.smithsonian.add(this.daysOfWeekArray[i], "cell " + (i + 1) + " 0,grow"); // add day titles to the title grid dayHeaders[i].setText(increment.toDateTime().toString(dayTitleFmt)); dayHeaders[i] .setFont(dayHeaders[i].getFont().deriveFont(increment.isEqual(now) ? Font.BOLD : Font.PLAIN)); increment.addDays(1); } // populate and set up the multiDayEventGrid populateMultidayEventGrid(); // setup week title increment.addDays(-1); // smart titles if (weekStartTime.getYear() != increment.getYear()) weekTitle .setText(weekStartTime.toString(monthDayYearFmt) + " - " + increment.toString(monthDayYearFmt)); else if (weekStartTime.getMonthOfYear() != increment.getMonthOfYear()) weekTitle.setText(weekStartTime.toString(monthDayFmt) + " - " + increment.toString(monthDayYearFmt)); else weekTitle.setText(weekStartTime.toString(monthDayFmt) + " - " + increment.toString(dayYearFmt)); // notify mini-calendar to change mainPanel.miniMove(time); }