List of usage examples for org.joda.time MutableDateTime MutableDateTime
public MutableDateTime(Object instant)
From source file:com.tmathmeyer.sentinel.ui.views.day.DayCalendar.java
License:Open Source License
/** * Get visible events for the current day view * /*from www . j a v a 2s .co 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
public MonthCalendar(DateTime on) { this.mainPanel = MainPanel.getInstance(); this.time = on; this.setLayout(new BorderLayout()); this.add(calendarTitlePanel, BorderLayout.NORTH); // add the UI generateDays(new MutableDateTime(on)); generateHeaders(new MutableDateTime(on)); // add drag and drop listeners addMouseMotionListener(new MouseMotionListener() { @Override//w ww. j a v a2 s. c o m public void mouseDragged(MouseEvent e) { MainPanel p = MainPanel.getInstance(); Displayable d = p.getSelectedEvent(); MonthDay md = getMonthDayAtCursor(); if (d != null && md != null) { md.setBackground(new Color(255, 255, 200)); d.setTime(md.getDay()); } else { escaped = false; e.consume(); repaint(); } } @Override public void mouseMoved(MouseEvent e) { if (tooltip) { repaint(); } setEscaped(false); } }); // add drag and drop listeners addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { external = false; } @Override public void mouseExited(MouseEvent arg0) { external = true; } @Override public void mousePressed(MouseEvent arg0) { external = false; } @Override public void mouseReleased(MouseEvent arg0) { if (external) { System.out.println("drop the events"); display(null); repaint(); setEscaped(false); } else { Displayable selected = MainPanel.getInstance().getSelectedEvent(); if (selected != null && escaped) { display(selected.getStart()); } } } }); }
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 ww w.j a va2s . 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
public void display(DateTime newTime) { this.escaped = false; time = newTime; generateDays(new MutableDateTime(time)); mainPanel.miniMove(time); }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java
License:Open Source License
public void next() { MutableDateTime fom = new MutableDateTime(time); fom.addMonths(1); time = fom.toDateTime(); generateDays(fom); }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthCalendar.java
License:Open Source License
public void previous() { MutableDateTime fom = new MutableDateTime(time); fom.addMonths(-1); time = fom.toDateTime(); generateDays(fom); }
From source file:com.tmathmeyer.sentinel.ui.views.month.MonthDay.java
License:Open Source License
public MonthDay(DateTime initDay, DayStyle style, final MonthCalendar parent) { this.day = initDay; this.style = style; Color grayit = Colors.TABLE_GRAY_HEADER, textit = Colors.TABLE_TEXT, bg = Colors.TABLE_BACKGROUND; switch (style) { case Normal:/*from w w w. j a va 2 s . c om*/ grayit = Colors.TABLE_GRAY_HEADER; textit = Colors.TABLE_GRAY_TEXT; break; case OutOfMonth: grayit = bg; break; case Today: grayit = Colors.TABLE_GRAY_HEADER; textit = Colors.TABLE_GRAY_TEXT; break; default: throw new IllegalStateException("DayStyle is not a valid DayStyle!"); } setBackground(bg); setForeground(textit); borderTop = grayit.equals(bg); setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS)); header.setBackground(grayit); header.setForeground(textit); header.setFont(new java.awt.Font("DejaVu Sans", style == DayStyle.Today ? Font.BOLD : Font.PLAIN, 12)); header.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); header.setText(Integer.toString(initDay.getDayOfMonth())); header.setAutoscrolls(true); header.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); header.setMaximumSize(new java.awt.Dimension(10000, 17)); header.setOpaque(true); if (style == DayStyle.Today) { Font font = header.getFont(); Map<TextAttribute, ?> attributes = font.getAttributes(); Map<TextAttribute, Object> newtributes = new HashMap<>(); newtributes.putAll(attributes); newtributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); header.setFont(font.deriveFont(newtributes)); } add(header); addMouseListener(new MouseListener() { @Override public void mousePressed(MouseEvent e) { parent.dispatchEvent(e); MainPanel.getInstance().setSelectedDay(day); MainPanel.getInstance().clearSelected(); parent.setEscaped(false); } @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { if (parent.isEscaped()) { MonthDay releasedDay = parent.getMonthDayAtCursor(); Displayable selected = MainPanel.getInstance().getSelectedEvent(); if (selected != null && releasedDay != null) { MutableDateTime newTime = new MutableDateTime(selected.getStart()); newTime.setYear(releasedDay.day.getYear()); newTime.setDayOfYear(releasedDay.day.getDayOfYear()); selected.setTime(newTime.toDateTime()); selected.update(); } } parent.dispatchEvent(e); } @Override public void mouseEntered(MouseEvent e) { parent.dispatchEvent(e); } @Override public void mouseExited(MouseEvent e) { setBackground(Colors.TABLE_BACKGROUND); parent.setEscaped(true); } }); header.addMouseListener(new MouseListener() { @Override public void mousePressed(MouseEvent e) { MainPanel.getInstance().setSelectedDay(day); MainPanel.getInstance().clearSelected(); } @Override public void mouseClicked(MouseEvent e) { MainPanel.getInstance().miniMove(day); MainPanel.getInstance().viewDay(); } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { setBackground(Colors.TABLE_BACKGROUND); } }); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { parent.repaint(); parent.dispatchEvent(e); } @Override public void mouseMoved(MouseEvent e) { parent.dispatchEvent(e); } }); }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Generates the day displays in the week panel *///from ww w . ja va 2 s. com 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); }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * updates the week start and end variables * /*from ww w . j av a2 s. c o m*/ * @param time a time in the week */ private void updateWeekStartAndEnd(DateTime time) { MutableDateTime mdt = new MutableDateTime(time); mdt.addDays(-(time.getDayOfWeek() % 7)); mdt.setMillisOfDay(0); this.weekStartTime = mdt.toDateTime(); mdt.addDays(7); this.weekEndTime = mdt.toDateTime(); }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Selects an event's corresponding Displayable * //from ww w. j av a 2s .co 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++; } }