Example usage for org.joda.time Duration getMillis

List of usage examples for org.joda.time Duration getMillis

Introduction

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

Prototype

public long getMillis() 

Source Link

Document

Gets the length of this duration in milliseconds.

Usage

From source file:kr.debop4j.timeperiod.TimePeriodBase.java

License:Apache License

/**
 * Sets duration.// w w w.  j a va  2  s  .co  m
 *
 * @param duration the duration
 */
public void setDuration(Duration duration) {
    assert duration.getMillis() >= Duration.ZERO
            .getMillis() : "Duration? ? 0 ?  .";
    if (hasStart())
        end = start.plus(duration);
}

From source file:kr.debop4j.timeperiod.TimePeriodBase.java

License:Apache License

@Override
public ITimePeriod copy(Duration offset) {

    log.trace(" [{}]? offset[{}]?  ? ...", this, offset);

    if (offset == Duration.ZERO)
        return new TimeRange(this);

    return new TimeRange(hasStart() ? start.plus(offset.getMillis()) : start,
            hasEnd() ? end.plus(offset.getMillis()) : end, readonly);
}

From source file:kr.debop4j.timeperiod.TimePeriodBase.java

License:Apache License

@Override
public void move(Duration offset) {
    if (offset == Duration.ZERO)
        return;/*from   ww  w  .jav  a2 s.  c o m*/
    assertMutable();

    log.trace("[{}]? offset[{}]? ??.", this, offset);

    if (hasStart())
        start = start.plus(offset.getMillis());
    if (hasEnd())
        end = end.plus(offset.getMillis());
}

From source file:kr.debop4j.timeperiod.TimePeriodChain.java

License:Apache License

/**   , ? ITimePeriod ? ? . ( ?) */
@Override//  w  ww.  j  a va  2 s.c o  m
public boolean remove(Object o) {
    shouldNotBeNull(o, "o");
    shouldBe(o instanceof ITimePeriod, "o is not ITimePeriod type. class=[%s]", o.getClass());

    if (size() <= 0)
        return false;

    ITimePeriod item = (ITimePeriod) o;

    log.trace(" [{}] ? ...", item);

    Duration itemDuration = item.getDuration();
    int index = indexOf(item);

    ITimePeriod next = null;
    if (itemDuration.getMillis() > 0 && index >= 0 && index < size() - 1)
        next = get(index);

    boolean removed = getPeriods().remove(item);

    if (removed && next != null) {
        log.trace("[{}] , chain? ? periods ? ? ...",
                item);

        for (int i = index; i < size(); i++) {
            DateTime start = get(i).getStart().minus(itemDuration);
            get(i).setup(start, start.plus(get(i).getDuration()));
        }
    }

    log.trace("[{}]  =[{}]", item, removed);

    return removed;
}

From source file:kr.debop4j.timeperiod.TimePeriodContainer.java

License:Apache License

@Override
public void move(Duration offset) {
    if (offset == null || offset.getMillis() == 0)
        return;//  w w w .  j  av a2 s.com

    log.trace(" ? offset[{}] ? ??.", offset);

    for (ITimePeriod period : this.periods)
        period.move(offset);
}

From source file:kr.debop4j.timeperiod.tools.Durations.java

License:Apache License

/**
 *  duration?   ? .  @param duration the duration
 *
 * @return the duration/*from w w  w. ja v  a  2s . c  o  m*/
 */
public static Duration negate(Duration duration) {
    return Duration.millis(-duration.getMillis());
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Adjust period./*from w  ww  .j a  v a 2s .c o  m*/
 *
 * @param start    the start
 * @param duration the duration
 * @return the pair
 */
public static Pair<DateTime, Duration> adjustPeriod(DateTime start, Duration duration) {
    shouldNotBeNull(start, "start");
    shouldNotBeNull(duration, "duration");
    return (duration.getMillis() < 0) ? Pair.create(start.plus(duration), new Duration(-duration.getMillis()))
            : Pair.create(start, duration);
}

From source file:linkacademyswingproject.MainDisplay.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    // TODO add your handling code here:
    if ((chosenTime != 0) || (chosenType != null)) {
        if (chosenColor != null) {
            if (chosenType.equals("Time")) {
                //                    int start = ((chosenTime)*60)*1000;
                int start = chosenTime;
                JPanel that = this;
                tmp = new Timer(start, new ActionListener() {
                    @Override/*from  ww w  .  jav a2  s.  c o  m*/
                    public void actionPerformed(ActionEvent e) {
                        JFrame wind = new JFrame("Alarm");
                        wind.setLayout(new FlowLayout());
                        Timer tmp = new Timer(jSlider1.getValue(), new ActionListener() {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                wind.getContentPane().setBackground(chosenColor);
                                disbleComponents(that, true);
                            }
                        });
                        tmp.start();
                        wind.setSize(new Dimension(300, 300));
                        wind.setVisible(true);
                    }
                });
                tmp.setRepeats(false);
                tmp.start();
                disbleComponents(this, false);
                jButton2.setEnabled(true);
            } else {
                DateTime then = new DateTime(chosenDate.getTime());
                DateTime now = new DateTime();
                Duration diff = new Duration(now, then);
                Long lWait = diff.getMillis();
                Integer wait = Integer.valueOf(lWait.intValue());
                if (wait > 0) {
                    JPanel that = this;
                    tmp = new Timer(wait, new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            JFrame wind = new JFrame("Alarm");
                            wind.setLayout(new FlowLayout());
                            Timer dur = new Timer(jSlider1.getValue(), new ActionListener() {

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    wind.getContentPane().setBackground(chosenColor);
                                    disbleComponents(that, true);
                                }
                            });
                            dur.start();
                            wind.setSize(new Dimension(300, 300));
                            wind.setVisible(true);
                        }
                    });
                    tmp.setRepeats(false);
                    tmp.start();
                    disbleComponents(this, false);
                    jButton2.setEnabled(true);
                } else {
                    JOptionPane.showMessageDialog(null, "Date for alarm must be in the future");
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "Must Select A color First");
        }
    } else {
        JOptionPane.showMessageDialog(null, "Must Select Time First");
    }
}

From source file:net.schweerelos.timeline.ui.TimelinePanel.java

License:Open Source License

public int convertDateToXCoord(DateTime date) {
    if (!tModel.isWithinRange(date)) {
        if (tModel.isBeforeStart(date)) {
            return 0;
        } else {/*  w w w  .ja va 2 s.com*/
            return getWidth();
        }
    }
    Duration visibleDuration = tModel.getDuration();
    Duration fromStart = new Duration(tModel.getStart(), date);
    float ratio = fromStart.getMillis() / (float) visibleDuration.getMillis();
    int xCoord = (int) Math.floor(ratio * getWidth());
    return xCoord;
}

From source file:net.schweerelos.timeline.ui.TimelinePanel.java

License:Open Source License

private Duration calculateSmallestVisibleDuration() {
    Duration visibleDuration = tModel.getDuration();
    float millisPerPixel = (float) visibleDuration.getMillis() / (float) getWidth();
    float secondsPerPixel = millisPerPixel / 1000;
    long minSeconds = (long) Math.ceil(secondsPerPixel * SHORTEST_VISIBLE_INTERVAL);
    return Duration.standardSeconds(minSeconds);
}