Example usage for org.jfree.data.time Millisecond Millisecond

List of usage examples for org.jfree.data.time Millisecond Millisecond

Introduction

In this page you can find the example usage for org.jfree.data.time Millisecond Millisecond.

Prototype

public Millisecond(Date time, TimeZone zone) 

Source Link

Document

Creates a millisecond.

Usage

From source file:LineChart.java

private static JFreeChart createDataset(JTable table) {
    TimeZone tz = TimeZone.getTimeZone("GMT");

    XYDataset ds = null;//from www  . ja v  a  2 s . c o  m

    if (table.getColumnCount() > 0) {
        Class klass = table.getColumnClass(0);

        if ((klass == Date.class) || (klass == Time.class) || (klass == c.Month.class)
                || (klass == c.Minute.class) || (klass == c.Second.class) || (klass == Timestamp.class)) {
            TimeSeriesCollection tsc = new TimeSeriesCollection();

            for (int col = 1; col < table.getColumnCount(); col++) {
                TimeSeries series = null;

                try {
                    if (klass == Date.class) {
                        series = new TimeSeries(table.getColumnName(col), Day.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            Date date = (Date) table.getValueAt(row, 0);
                            Day day = new Day(date, tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                ((TimeSeries) series).addOrUpdate(day, (Number) table.getValueAt(row, col));
                            }
                        }
                    } else if (klass == Time.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            Time time = (Time) table.getValueAt(row, 0);
                            Millisecond ms = new Millisecond(time, tz);

                            //    Millisecond ms = new Millisecond(time);
                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(ms, (Number) table.getValueAt(row, col));
                            }
                        }
                    } else if (klass == Timestamp.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            Timestamp time = (Timestamp) table.getValueAt(row, 0);
                            Millisecond ms = new Millisecond(time, tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(ms, (Number) table.getValueAt(row, col));
                            }

                        }
                    } else if (klass == c.Month.class) {
                        series = new TimeSeries(table.getColumnName(col), Month.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            c.Month time = (c.Month) table.getValueAt(row, 0);
                            int m = time.i + 24000;
                            int y = m / 12;
                            m = 1 + m % 12;

                            Month month = new Month(m, y);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(month, (Number) table.getValueAt(row, col));
                            }

                        }
                    } else if (klass == c.Second.class) {
                        series = new TimeSeries(table.getColumnName(col), Second.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            c.Second time = (c.Second) table.getValueAt(row, 0);

                            Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(second, (Number) table.getValueAt(row, col));
                            }

                        }
                    } else if (klass == c.Minute.class) {
                        series = new TimeSeries(table.getColumnName(col), Minute.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            c.Minute time = (c.Minute) table.getValueAt(row, 0);

                            Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(minute, (Number) table.getValueAt(row, col));
                            }
                        }
                    }
                } catch (SeriesException e) {
                    System.err.println("Error adding to series");
                }

                if (series.getItemCount() > 0)
                    tsc.addSeries(series);
            }

            ds = tsc;
        } else if ((klass == double.class) || (klass == int.class) || (klass == short.class)
                || (klass == long.class) || (klass == Time.class)) {
            XYSeriesCollection xysc = new XYSeriesCollection();

            for (int col = 1; col < table.getColumnCount(); col++) {
                XYSeries series = null;

                try {
                    series = new XYSeries(table.getColumnName(col));

                    for (int row = 0; row < table.getRowCount(); row++) {
                        Number x = (Number) table.getValueAt(row, 0);

                        Object y = table.getValueAt(row, col);
                        if (y instanceof Number) {
                            series.add(x, (Number) y);
                        }
                    }
                } catch (SeriesException e) {
                    System.err.println("Error adding to series");
                }

                if (series.getItemCount() > 0)
                    xysc.addSeries(series);
            }

            ds = xysc;
        }
    }

    if (ds != null) {
        boolean legend = false;

        if (ds.getSeriesCount() > 1) {
            legend = true;
        }

        if (ds instanceof XYSeriesCollection) {
            return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true);
        } else if (ds instanceof TimeSeriesCollection)
            return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true);
    }

    return null;
}

From source file:studio.ui.LineChart.java

public static JFreeChart createDataset(KTableModel table) {
    TimeZone tz = TimeZone.getTimeZone("GMT");

    XYDataset ds = null;//from   w  ww . jav  a  2s.  c  o  m

    if (table.getColumnCount() > 0) {
        Class klass = table.getColumnClass(0);

        if ((klass == K.KTimestampVector.class) || (klass == K.KTimespanVector.class)
                || (klass == K.KDateVector.class) || (klass == K.KTimeVector.class)
                || (klass == K.KMonthVector.class) || (klass == K.KMinuteVector.class)
                || (klass == K.KSecondVector.class) || (klass == K.KDatetimeVector.class)) {
            TimeSeriesCollection tsc = new TimeSeriesCollection(tz);

            for (int col = 1; col < table.getColumnCount(); col++) {
                TimeSeries series = null;

                try {
                    if (klass == K.KDateVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Day.class);
                        K.KDateVector dates = (K.KDateVector) table.getColumn(0);

                        for (int row = 0; row < dates.getLength(); row++) {
                            K.KDate date = (K.KDate) dates.at(row);
                            Day day = new Day(date.toDate(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(day, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KTimeVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        K.KTimeVector times = (K.KTimeVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.KTime time = (K.KTime) times.at(row);
                            Millisecond ms = new Millisecond(time.toTime(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(ms, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KTimestampVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Day.class);
                        K.KTimestampVector dates = (K.KTimestampVector) table.getColumn(0);

                        for (int row = 0; row < dates.getLength(); row++) {
                            K.KTimestamp date = (K.KTimestamp) dates.at(row);
                            Day day = new Day(new java.util.Date(date.toTimestamp().getTime()), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(day, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KTimespanVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        K.KTimespanVector times = (K.KTimespanVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.KTimespan time = (K.KTimespan) times.at(row);
                            Millisecond ms = new Millisecond(time.toTime(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(ms, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KDatetimeVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);
                        K.KDatetimeVector times = (K.KDatetimeVector) table.getColumn(0);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.KDatetime time = (K.KDatetime) times.at(row);
                            Millisecond ms = new Millisecond(time.toTimestamp(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(ms, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KMonthVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Month.class);
                        K.KMonthVector times = (K.KMonthVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.Month time = (K.Month) times.at(row);
                            int m = time.i + 24000;
                            int y = m / 12;
                            m = 1 + m % 12;

                            Month month = new Month(m, y);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(month, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KSecondVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Second.class);
                        K.KSecondVector times = (K.KSecondVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.Second time = (K.Second) times.at(row);
                            Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(second, ((ToDouble) o).toDouble());

                        }
                    } else if (klass == K.KMinuteVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Minute.class);
                        K.KMinuteVector times = (K.KMinuteVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.Minute time = (K.Minute) times.at(row);
                            Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001);
                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(minute, ((ToDouble) o).toDouble());
                        }
                    }
                } catch (SeriesException e) {
                    System.err.println("Error adding to series");
                }

                if (series.getItemCount() > 0)
                    tsc.addSeries(series);
            }

            ds = tsc;
        } else if ((klass == K.KDoubleVector.class) || (klass == K.KFloatVector.class)
                || (klass == K.KShortVector.class) || (klass == K.KIntVector.class)
                || (klass == K.KLongVector.class)) {
            XYSeriesCollection xysc = new XYSeriesCollection();

            for (int col = 1; col < table.getColumnCount(); col++) {
                XYSeries series = null;

                try {
                    series = new XYSeries(table.getColumnName(col));

                    for (int row = 0; row < table.getRowCount(); row++) {
                        double x = ((ToDouble) table.getValueAt(row, 0)).toDouble();
                        double y = ((ToDouble) table.getValueAt(row, col)).toDouble();
                        series.add(x, y);
                    }
                } catch (SeriesException e) {
                    System.err.println("Error adding to series");
                }

                if (series.getItemCount() > 0)
                    xysc.addSeries(series);
            }

            ds = xysc;
        }
    }

    if (ds != null) {
        boolean legend = false;

        if (ds.getSeriesCount() > 1)
            legend = true;

        if (ds instanceof XYSeriesCollection)
            return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true);
        else if (ds instanceof TimeSeriesCollection)
            return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true);
    }

    return null;
}

From source file:org.jfree.data.time.MillisecondTest.java

/**
 * Tests the equals method.//  w  w w . ja v a2  s.  com
 */
@Test
public void testEquals() {
    Day day1 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour1 = new Hour(15, day1);
    Minute minute1 = new Minute(15, hour1);
    Second second1 = new Second(34, minute1);
    Millisecond milli1 = new Millisecond(999, second1);
    Day day2 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour2 = new Hour(15, day2);
    Minute minute2 = new Minute(15, hour2);
    Second second2 = new Second(34, minute2);
    Millisecond milli2 = new Millisecond(999, second2);
    assertTrue(milli1.equals(milli2));
}

From source file:org.jfree.data.time.junit.MillisecondTest.java

/**
 * Tests the equals method./*w ww.  j  av a 2  s  .  com*/
 */
public void testEquals() {
    Day day1 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour1 = new Hour(15, day1);
    Minute minute1 = new Minute(15, hour1);
    Second second1 = new Second(34, minute1);
    Millisecond milli1 = new Millisecond(999, second1);
    Day day2 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour2 = new Hour(15, day2);
    Minute minute2 = new Minute(15, hour2);
    Second second2 = new Second(34, minute2);
    Millisecond milli2 = new Millisecond(999, second2);
    assertTrue(milli1.equals(milli2));
}

From source file:org.jfree.data.time.Millisecond.java

/**
 * Returns the millisecond preceding this one.
 *
 * @return The millisecond preceding this one.
 *//*from  w  w  w. jav  a2s.  c  om*/
@Override
public RegularTimePeriod previous() {
    RegularTimePeriod result = null;
    if (this.millisecond != FIRST_MILLISECOND_IN_SECOND) {
        result = new Millisecond(this.millisecond - 1, getSecond());
    } else {
        Second previous = (Second) getSecond().previous();
        if (previous != null) {
            result = new Millisecond(LAST_MILLISECOND_IN_SECOND, previous);
        }
    }
    return result;
}

From source file:org.jfree.data.time.Millisecond.java

/**
 * Returns the millisecond following this one.
 *
 * @return The millisecond following this one.
 */// ww w  . j av  a2s .com
@Override
public RegularTimePeriod next() {
    RegularTimePeriod result = null;
    if (this.millisecond != LAST_MILLISECOND_IN_SECOND) {
        result = new Millisecond(this.millisecond + 1, getSecond());
    } else {
        Second next = (Second) getSecond().next();
        if (next != null) {
            result = new Millisecond(FIRST_MILLISECOND_IN_SECOND, next);
        }
    }
    return result;
}

From source file:edu.fullerton.viewerplugin.TsPlot.java

private void addTimeSeries(ChanDataBuffer dbuf, boolean compact, TimeSeriesCollection mtds)
        throws LdvTableException {
    String legend = getLegend(dbuf, compact);
    TimeSeries ts;/*from  ww w  .  j a v a2  s  .  com*/
    ts = new TimeSeries(legend, Millisecond.class);
    SimpleTimeZone utctz = new SimpleTimeZone(0, "UTC");

    float rate = dbuf.getChanInfo().getRate();
    double msPerSample = 1000 / rate;
    long startMs = TimeAndDate.gps2utc(dbuf.getTimeInterval().getStartGps()) * 1000;
    float[] data = dbuf.getData();
    for (int i = 0; i < dbuf.getDataLength(); i++) {
        long curMs = Math.round(msPerSample * i + startMs);
        Date t = new Date(curMs);
        ts.addOrUpdate(new Millisecond(t, utctz), data[i]);
        if (msPerSample >= 1000) {
            // this plots trend data as stair steps
            long endMs = Math.round(curMs + msPerSample - 1);
            Date t1 = new Date(endMs);
            ts.addOrUpdate(new Millisecond(t1, utctz), data[i]);
        }
    }

    mtds.addSeries(ts);
    if (addLinFit) {
        TimeSeries linTs = LinFit(ts);
        mtds.addSeries(linTs);
    }

}

From source file:edu.fullerton.viewerplugin.PluginSupport.java

/**
 * Generate a JFreeChart TimeSeries object from a ChanDataBuffer
 * Note:  the time axis is in UTC.  For GPS or delta T use XY series.
 * @param dbuf - ldvw data buffer// ww w. j  av a  2s  .co  m
 * @param legend - plot legend for this series
 * @return JFreeChart time series for adding to a plot
 */
public TimeSeries getTimeSeries(ChanDataBuffer dbuf, String legend, int sum) throws LdvTableException {
    sum = sum < 1 ? 1 : sum;
    TimeSeries ts;
    ts = new TimeSeries(legend, Millisecond.class);
    SimpleTimeZone utctz = new SimpleTimeZone(0, "UTC");

    float rate = dbuf.getChanInfo().getRate();
    double msPerSample = 1000 / rate;
    long startMs = TimeAndDate.gps2utc(dbuf.getTimeInterval().getStartGps()) * 1000;
    float[] data = dbuf.getData();
    for (int i = 0; i < dbuf.getDataLength(); i += sum) {
        float td = 0.f;
        int nsum = 0;
        for (int j = 0; j < sum && i + j < dbuf.getDataLength(); j++) {
            td += data[i + j];
            nsum++;
        }
        td /= nsum;

        long curMs = Math.round(msPerSample * i + startMs);
        Date t = new Date(curMs);
        ts.addOrUpdate(new Millisecond(t, utctz), td);
        if (msPerSample >= 1000) {
            // this plots trend data as stair steps
            long endMs = Math.round(curMs + msPerSample - 1);
            Date t1 = new Date(endMs);
            ts.addOrUpdate(new Millisecond(t1, utctz), td);
        }
    }
    return ts;
}