Example usage for org.joda.time Interval Interval

List of usage examples for org.joda.time Interval Interval

Introduction

In this page you can find the example usage for org.joda.time Interval Interval.

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

private static List<Interval> intervals(List<DateTime> dateTimes) {
    checkNotNull(dateTimes, "Need a list of DateTimes.");
    checkArgument(dateTimes.size() > 1, "Need more than one DateTime.");

    List<Interval> intervals = new ArrayList<Interval>();
    DateTime dtStart = dateTimes.get(0);
    for (int i = 1; i < dateTimes.size(); i++) {
        DateTime dtStop = dateTimes.get(i);
        Interval interval = new Interval(DateTimes.lesser(dtStart, dtStop), DateTimes.greater(dtStart, dtStop));
        intervals.add(interval);//from w  ww .  j  a v a 2 s .  c o  m
        dtStart = dtStop;
    }
    return intervals;
}

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

public static Interval fromSecs(Long startSecs, Long endSecs) {
    return new Interval(DateTimes.fromSecs(startSecs), DateTimes.fromSecs(endSecs));
}

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

public static Interval fromSecs(long startSecs, long endSecs) {
    return new Interval(DateTimes.fromSecs(startSecs), DateTimes.fromSecs(endSecs));
}

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

public static Interval fromSecs(Integer startSecs, Integer endSecs) {
    return new Interval(DateTimes.fromSecs(startSecs), DateTimes.fromSecs(endSecs));
}

From source file:com.tkmtwo.timex.Intervals.java

License:Apache License

public static Interval fromSecs(int startSecs, int endSecs) {
    return new Interval(DateTimes.fromSecs(startSecs), DateTimes.fromSecs(endSecs));
}

From source file:com.tmathmeyer.sentinel.models.client.net.CachingDisplayableClient.java

License:Open Source License

/**
 * Gets all visible events in the range [from..to]
 * // w ww  . j av a  2  s  .c  om
 * @param from
 * @param to
 * @return list of visible events
 */
public List<T> getRange(DateTime from, DateTime to) {
    validateCache();
    // set up to filter events based on booleans in MainPanel
    List<T> filteredEvents = new ArrayList<T>();
    final Interval range = new Interval(from, to);

    // loop through and add only if isProjectEvent() matches corresponding
    // boolean
    for (T e : cache.values()) {
        if (range.overlaps(e.getInterval()) && filter(e)) {
            filteredEvents.add(e);
        }
    }
    return filteredEvents;
}

From source file:com.tmathmeyer.sentinel.models.data.Commitment.java

License:Open Source License

@Override
public Interval getInterval() {
    return new Interval(getStart(), getStart());
}

From source file:com.tmathmeyer.sentinel.models.data.Event.java

License:Open Source License

@Override
public Interval getInterval() {
    return new Interval(getStart(), getEnd());
}

From source file:com.tmathmeyer.sentinel.models.data.Event.java

License:Open Source License

@Override
public void setTime(DateTime newTime) {
    if (new Interval(new DateTime(this.start), new DateTime(this.end)).contains(newTime)) {
        // this is what stops the events from being dragged to the next day.
        // leaving it in case we might want it later
        // return;
    }/* w ww.j a  v a2 s .c  om*/

    Interval i;
    int daysBetween = 0;
    if (new DateTime(this.start).isAfter(newTime)) {
        i = new Interval(newTime, new DateTime(this.start));
        daysBetween = 0 - (int) i.toDuration().getStandardDays();
    } else {
        i = new Interval(new DateTime(this.start), newTime);
        daysBetween = (int) i.toDuration().getStandardDays();
    }

    MutableDateTime newEnd = new MutableDateTime(this.end);
    newEnd.addDays(daysBetween);

    MutableDateTime newStart = new MutableDateTime(this.start);
    newStart.addDays(daysBetween);

    this.end = newEnd.toDate();
    this.start = newStart.toDate();

}

From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayItem.java

License:Open Source License

/**
 * Creates a DayItem (drawable) based on an overlapping Displayable
 * (Information) on the given day/*w w  w  . ja  v a2 s  . c  o  m*/
 * 
 * @param eventPositionalInformation the positional information for the
 *            Displayable
 * @param displayedDay the day to display this panel on
 */
public DayItem(OverlappedDisplayable eventPositionalInformation, DateTime displayedDay) {
    bottom = new ResizingHandle(this, false);
    top = new ResizingHandle(this, true);
    top.setMinimumSize(new Dimension(0, 6));
    top.setMaximumSize(new Dimension(10000, 6));
    top.setPreferredSize(new Dimension(10000, 6));
    top.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
    this.add(top);
    isBeingDragged = false;
    this.displayedDay = displayedDay;
    this.eventPositionalInformation = eventPositionalInformation;
    height = 25;
    displayable = eventPositionalInformation.getEvent();
    length = new Interval(displayable.getStart(), displayable.getEnd());

    Color bg = Colors.TABLE_GRAY_HEADER;

    if (displayable instanceof Event) {
        bg = displayable.getColor();
        setBorder(new CompoundBorder(new LineBorder(Colors.TABLE_BACKGROUND),
                new CompoundBorder(new LineBorder(bg.darker()), new EmptyBorder(6, 6, 6, 6))));
    } else if (displayable instanceof Commitment) {
        Color b;
        Commitment.Status s = ((Commitment) displayable).getStatus();
        switch (s) {
        case COMPLETE:
            b = new Color(192, 255, 192);
            break;
        case IN_PROGRESS:
            b = new Color(255, 255, 192);
            break;
        case NOT_STARTED:
            b = new Color(240, 110, 110);
            break;
        default:
            b = Color.BLACK;
            break;
        }
        setBorder(new CompoundBorder(new LineBorder(Colors.TABLE_BACKGROUND),
                new CompoundBorder(new MatteBorder(1, 0, 0, 0, b),
                        new CompoundBorder(new LineBorder(bg.darker()), new EmptyBorder(0, 6, 0, 6)))));
        top.setEnabled(false);
        bottom.setEnabled(false);
    }
    setBackground(bg);
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    lblEventTitle = new JLabel();
    add(lblEventTitle);
    lblEventTitle.setFont(new Font("Tahoma", Font.BOLD, 14));
    lblEventTitle.putClientProperty("html.disable", true); // prevents html
    // parsing
    lblEventTitle.setText(displayable.getName());
    lblTimeInfo = new JLabel();
    putTimeOn();
    lblTimeInfo.setBorder(new EmptyBorder(0, 0, 3, 0));
    lblTimeInfo.setMaximumSize(new Dimension(32767, 20));
    lblTimeInfo.setFont(new Font("DejaVu Sans", Font.ITALIC, 14));
    add(lblTimeInfo);
    lblStarryNightdutch = new JLabel();
    add(lblStarryNightdutch);
    lblStarryNightdutch.setVerticalAlignment(SwingConstants.TOP);
    lblStarryNightdutch.setBackground(bg);
    lblStarryNightdutch.setFont(new Font("Tahoma", Font.PLAIN, 14));
    lblStarryNightdutch.setMinimumSize(new Dimension(0, 0));
    bottom.setMinimumSize(new Dimension(0, 6));
    bottom.setMaximumSize(new Dimension(10000, 6));
    bottom.setPreferredSize(new Dimension(10000, 6));
    this.add(Box.createVerticalGlue());
    bottom.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
    this.add(bottom);
    addMouseListener(new MouseListener() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (isBeingDragged) {
                if (puppet != null) {
                    day = puppet.day;
                    int previous = displayable.getStart().getDayOfWeek() % 7;
                    if (day > previous)
                        updateTime(displayable.getStart().plusDays(day - previous));
                    if (previous > day)
                        updateTime(displayable.getStart().minusDays(previous - day));
                }
                displayable.update();
                MainPanel.getInstance().display(displayable.getStart());
            }
            getParent().dispatchEvent(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() > 1) {
                MainPanel.getInstance().editSelectedDisplayable(displayable);
            } else {
                MainPanel.getInstance().updateSelectedDisplayable(displayable);
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            getParent().dispatchEvent(e);
        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseClicked(MouseEvent e) {

        }
    });

    this.addMouseMotionListener(new MouseMotionListener() {
        @Override
        public void mouseMoved(MouseEvent e) {
            getParent().dispatchEvent(e);
        }

        @Override
        public void mouseDragged(MouseEvent arg0) {
            isBeingDragged = true;
            getParent().dispatchEvent(arg0);
        }
    });
    width = new Rational(((eventPositionalInformation.getCollisions() > 1) ? 2 : 1),
            1 + eventPositionalInformation.getCollisions());
    x = eventPositionalInformation.getXpos();
    description = Arrays.asList(eventPositionalInformation.getEvent().getDescription().split(" "));
    if (x.toInt(10000) + width.toInt(10000) > 10000)
        width = width.multiply(new Rational(1, 2));
    recalcBounds(200, FIXED_HEIGHT);
}