Package org.joda.time

Examples of org.joda.time.DateTime


                // set 1/4h as one timeslot, now even half of an hour will be displayed
                settings.setMillisPerTimeslot(15 * 60 * 1000L);
                settings.setTimeslotsPerDay(4 * 8);

                settings.setStartDate(new DateTime(2009, 4, 6, 8, 0, 0, 0));
                TimeFinderPlanner planner = new TimeFinderPlanner(settings);

                // monday
                planner.addInterval(new IntervalLongImpl("Interval 1", 2009, 4, 6, 8, 30, 60));
                planner.addInterval(new IntervalLongImpl("Interval 2", 2009, 4, 6, 9, 0, 60));
View Full Code Here


                for (int y = 1; y < getHoursPerDay() + 1; y++) {
                    g2d.drawLine(0, y * hourWidth, xEnd, y * hourWidth);
                }

                RoundBox selectedBox = null;
                DateTime startDate = settings.getStartDate();
                // paint events
                for (IntervalLong interval : getCurrentIntervals()) {
                    long startMillisOffset = interval.getStart() - startDate.getMillis()
                            + startDate.getMillisOfDay();
                    int day = (int) (startMillisOffset / ICalendarSettings.DAY);

                    int duration_hourWidth = (int) (interval.getDuration() / settings.getMillisPerTimeslot()
                            * getHourFactor() * hourWidth);

                    int start_hourWidth = (int) ((startMillisOffset % CalendarSettings.DAY
                            - startDate.getMillisOfDay()) / ICalendarSettings.HOUR * hourWidth)
                            + (hourWidth * interval.getStartDateTime().getMinuteOfHour() / 60);

                    int numberOfConflicts = stepFunction.getMaxAssignments(interval);
                    int position = stepFunction.getOffset(interval);
                    int thickness = dayWidth / numberOfConflicts;
                    int offset = position * thickness;

                    Rectangle2D paintingRect = new Rectangle2D.Double(
                            day * dayWidth + offset, start_hourWidth,
                            thickness, duration_hourWidth);

                    String text = interval.getDescription();
                    if (text == null || text.length() == 0)
                        text = interval.getName();
                    RoundBox box = new RoundBox(text, numberOfConflicts);
                    box.setRect(paintingRect);

                    if (paintingRect.intersects(mousePositionX, mousePositionY, 1, 1)) {
                        selectedBox = box;
                        continue;
                    }

                    box.paintComponent(g2d);
                }

                // now paint a selected interval a bit larger *and* on the top of the other
                if (selectedBox != null) {
                    selectedBox.setTransparent(false);
                    selectedBox.zoom(g2d.getClip());
                    selectedBox.paintComponent(g2d);
                }
            }
        };

        final DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendDayOfWeekText().
                appendLiteral(" - ").
                appendDayOfMonth(2).
                appendLiteral(". ").
                appendMonthOfYearText().toFormatter();

        columnHeader = new JPanel() {

            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);

                Shape oldClip = g.getClip();
                DateTime tempDateTime = settings.getStartDate();
                for (int x = 0; x < visibleDays; x++) {
                    g.setClip(new Rectangle2D.Double(x * dayWidth, 0,
                            dayWidth, columnHeaderHeight));
                    g.drawString(fmt.print(tempDateTime),
                            xTextOffset + x * dayWidth, yHeaderTextOffset);
                    tempDateTime = tempDateTime.plusDays(1);
                }
                g.setClip(oldClip);
            }
        };

        rowHeader = new JPanel() {

            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                for (int y = 0; y < getHoursPerDay(); y++) {
                    g.drawString(String.format("%1$02d", y + getHourOffset()) + ":00",
                            xTextOffset, yHeaderTextOffset + y * hourWidth);
                }
            }
        };

        scroll = new JScrollPane();
        scroll.setRowHeaderView(rowHeader);

//        scroll.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, new JLabel() {
//
//            @Override
//            public String getText() {
//                return "no:" + getCurrentIntervals().size();
//            }
//        });

        scroll.setColumnHeaderView(columnHeader);

        JPanel timeNorthPanel = new JPanel();
        calendarDateField = CalendarFactory.createDateField();
        calendarDateField.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                // get the date only - not the time
                DateTime val = new DateTime(((Date) calendarDateField.getValue()).getTime());
                DateTime start = settings.getStartDate();
                setStartDate(start.withYear(val.getYear()).
                        withMonthOfYear(val.getMonthOfYear()).withDayOfMonth(val.getDayOfMonth()));
            }
        });
        timeNorthPanel.add(calendarDateField);
        timeNorthPanel.add(prevDaysButton = new SmallButton("<"));
View Full Code Here

        this(year, month, day, hour, minute, durationInMinutes);
        setDescription(description);
    }

    public IntervalLongImpl(int year, int month, int day, int hour, int minute, int durationInMinutes) {
        start = new DateTime(year, month, day, hour, minute, 0, 0).getMillis();
        setInterval(start, durationInMinutes * 60 * 1000);
    }
View Full Code Here

    public boolean isAssigned() {
        return assigned;
    }

    public DateTime getStartDateTime() {
        return new DateTime(start);
    }
View Full Code Here

    public DateTime getStartDateTime() {
        return new DateTime(start);
    }

    public DateTime getEndDateTime() {
        return new DateTime(start + duration);
    }
View Full Code Here

    }

    @Override
    protected void initDefault() {
        // set to the first monday in the current month
        setDefault("startDate", new DateTime().withDayOfMonth(1).weekOfWeekyear().roundCeilingCopy().
                plusHours(8));
        setDefault("milliSecondsPerTimeSlot", 1000 * 60 * 60L);
        setDefault("timeSlotsPerDay", 12);
        setDefault("numberOfDays", 5);
    }
View Full Code Here

        return settings.getStartDate().plusDays(startDayInt).plusMinutes(startMinutes);
    }
    public Log log = LogFactory.getLog(getClass());

    public IntervalInt toEvent(DateTime start, DateTime end) {
        DateTime settingsStartDate = settings.getStartDate();
        int startSlot = (int) ((start.getMillisOfDay()
                - settingsStartDate.getMillisOfDay()) / settings.getMillisPerTimeslot());
        if (startSlot < 0) {
            log.fatal("Cannot convert DateTimes - start would be negative: " + startSlot + " start=" + start + " end=" + end);
            return null;
        }
        if (startSlot >= settings.getTimeslotsPerDay()) {
            log.fatal("Cannot convert DateTimes - start would be too big: " + startSlot + " start=" + start + " end=" + end);
            return null;
        }

        int days = (int) ((start.getMillis()
                - (settingsStartDate.getMillis() - settingsStartDate.getMillisOfDay()))
                / ICalendarSettings.DAY);
        if (days < 0) {
            log.fatal("Cannot convert DateTimes - start would have negative day: " + days + " start=" + start + " end=" + end);
            return null;
        }
View Full Code Here

    /**
     * Format the Date as String, using the specified DateFormat.
     */
    @Override
    public String getAsText() {
        DateTime value = (DateTime) getValue();
        return (value != null ? format.print(value) : "");
    }
View Full Code Here

        settings = new CalendarSettings();
    }

    @Test
    public void testSetStartDate() {
        settings.setStartDate(new DateTime(2008, 10, 23, 0, 0, 0, 0));
        assertEquals(new DateTime(2008, 10, 23, 0, 0, 0, 0), settings.getStartDate());
    }
View Full Code Here

    public void testToEvent() {
//        System.out.println("ToEvent");

        IntervalInt event = new Event();
        event.setInterval(0, 1);
        DateTime start = settings.toDateTime(event.getStart());
        DateTime end = settings.toDateTime(event.getEnd());
        assertEqualsEvent(event, settings.toInterval(start, end));

        event.setInterval(settings.getTimeslotsPerDay(), 1);
        start = settings.toDateTime(event.getStart());
        end = settings.toDateTime(event.getEnd());
View Full Code Here

TOP

Related Classes of org.joda.time.DateTime

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.