Package org.jfree.data.time

Examples of org.jfree.data.time.RegularTimePeriod


     *
     * @return The time period.
     */
    private RegularTimePeriod createInstance(Class periodClass,
            Date millisecond, TimeZone zone, Locale locale) {
        RegularTimePeriod result = null;
        try {
            Constructor c = periodClass.getDeclaredConstructor(new Class[] {
                    Date.class, TimeZone.class, Locale.class});
            result = (RegularTimePeriod) c.newInstance(new Object[] {
                    millisecond, zone, locale});
View Full Code Here


     *
     * @since 1.0.13.
     */
    public RegularTimePeriod createInstance(Date millisecond, TimeZone zone,
            Locale locale) {
        RegularTimePeriod result = null;
        try {
            Constructor c = this.periodClass.getDeclaredConstructor(
                    new Class[] {Date.class, TimeZone.class, Locale.class});
            result = (RegularTimePeriod) c.newInstance(new Object[] {
                    millisecond, zone, locale});
View Full Code Here

     */
    private static XYDataset createDataset(String name, double base,
                                           RegularTimePeriod start, int count) {

        TimeSeries series = new TimeSeries(name);
        RegularTimePeriod period = start;
        double value = base;
        for (int i = 0; i < count; i++) {
            series.add(period, value);   
            period = period.next();
            value = value * (1 + (Math.random() - 0.495) / 10.0);
        }

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(series);
View Full Code Here

     */
    public void testClone() {

        TimeSeries series = new TimeSeries("Test Series");

        RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002);
        try {
            series.add(jan1st2002, new Integer(42));
        }
        catch (SeriesException e) {
            System.err.println("Problem adding to series.");
View Full Code Here

        s2.setKey("Time Series 1");
        boolean b2 = s1.equals(s2);
        assertTrue("b2", b2);

        RegularTimePeriod p1 = new Day();
        RegularTimePeriod p2 = p1.next();
        s1.add(p1, 100.0);
        s1.add(p2, 200.0);
        boolean b3 = s1.equals(s2);
        assertFalse("b3", b3);
View Full Code Here

    class DataGatherer implements RequestDataVisitor {

        HashMap<RegularTimePeriod,Integer> data = new HashMap<RegularTimePeriod, Integer>();
       
        public void visit(RequestData r) {
            RegularTimePeriod period = getTimePeriod(r.getStartTime());
            Integer count = data.get(period);
      
            if (count == null) {
                count = new Integer(1);
            }
View Full Code Here

        long axisMax = this.last.getLastMillisecond(this.timeZone);
        g2.setFont(this.labelInfo[band].getLabelFont());
        g2.setPaint(this.labelInfo[band].getLabelPaint());

        // work out the number of periods to skip for labelling
        RegularTimePeriod p1 = this.labelInfo[band].createInstance(
            new Date(axisMin), this.timeZone
        );
        RegularTimePeriod p2 = this.labelInfo[band].createInstance(
            new Date(axisMax), this.timeZone
        );
        String label1 = this.labelInfo[band].getDateFormat().format(
            new Date(p1.getMiddleMillisecond(this.timeZone))
        );
        String label2 = this.labelInfo[band].getDateFormat().format(
            new Date(p2.getMiddleMillisecond(this.timeZone))
        );
        Rectangle2D b1 = TextUtilities.getTextBounds(label1, g2, g2.getFontMetrics());
        Rectangle2D b2 = TextUtilities.getTextBounds(label2, g2, g2.getFontMetrics());
        double w = Math.max(b1.getWidth(), b2.getWidth());
        long ww = Math.round(java2DToValue(dataArea.getX() + w + 5.0, dataArea, edge)) - axisMin;
        long length = p1.getLastMillisecond(this.timeZone) - p1.getFirstMillisecond(this.timeZone);
        int periods = (int) (ww / length) + 1;
       
        RegularTimePeriod p = this.labelInfo[band].createInstance(new Date(axisMin), this.timeZone);
        Rectangle2D b = null;
        long lastXX = 0L;
        float y = (float) (state.getCursor());
        TextAnchor anchor = TextAnchor.TOP_CENTER;
        if (edge == RectangleEdge.TOP) {
            anchor = TextAnchor.BOTTOM_CENTER;  
        }
        while (p.getFirstMillisecond(this.timeZone) <= axisMax) {
            float x = (float) valueToJava2D(p.getMiddleMillisecond(this.timeZone), dataArea, edge);
            DateFormat df = this.labelInfo[band].getDateFormat();
            String label = df.format(new Date(p.getMiddleMillisecond(this.timeZone)));
            long first = p.getFirstMillisecond(this.timeZone);
            long last = p.getLastMillisecond(this.timeZone);
            if (last > axisMax) {
                // this is the last period, but it is only partially visible so check that the
                // label will fit before displaying it...
                Rectangle2D bb = TextUtilities.getTextBounds(label, g2, g2.getFontMetrics());
                if ((x + bb.getWidth() / 2) > dataArea.getMaxX()) {
                    float xstart = (float) valueToJava2D(Math.max(first, axisMin), dataArea, edge);
                    if (bb.getWidth() < (dataArea.getMaxX() - xstart)) {
                        x = ((float) dataArea.getMaxX() + xstart) / 2.0f;  
                    }
                    else {
                        label = null;
                    }
                }
            }
            if (first < axisMin) {
                // this is the first period, but it is only partially visible so check that the
                // label will fit before displaying it...
                Rectangle2D bb = TextUtilities.getTextBounds(label, g2, g2.getFontMetrics());
                if ((x - bb.getWidth() / 2) < dataArea.getX()) {
                    float xlast = (float) valueToJava2D(Math.min(last, axisMax), dataArea, edge);
                    if (bb.getWidth() < (xlast - dataArea.getX())) {
                        x = (xlast + (float) dataArea.getX()) / 2.0f;  
                    }
                    else {
                        label = null;
                    }
                }
               
            }
            if (label != null) {
                g2.setPaint(this.labelInfo[band].getLabelPaint());
                b = TextUtilities.drawAlignedString(label, g2, x, y, anchor);
            }
            if (lastXX > 0L) {
                if (this.labelInfo[band].getDrawDividers()) {
                    long nextXX = p.getFirstMillisecond(this.timeZone);
                    long mid = (lastXX + nextXX) / 2;
                    float mid2d = (float) valueToJava2D(mid, dataArea, edge);
                    g2.setStroke(this.labelInfo[band].getDividerStroke());
                    g2.setPaint(this.labelInfo[band].getDividerPaint());
                    g2.draw(new Line2D.Float(mid2d, y, mid2d, y + (float) b1.getHeight()));
                }
            }
            lastXX = last;
            for (int i = 0; i < periods; i++) {
                p = p.next();  
            }
        }
        double used = 0.0;
        if (b != null) {
            used = b.getHeight();
View Full Code Here

     * @param zone  the time zone.
     *
     * @return The time period.
     */
    private RegularTimePeriod createInstance(Class periodClass, Date millisecond, TimeZone zone) {
        RegularTimePeriod result = null;
        try {
            Constructor c = periodClass.getDeclaredConstructor(
                new Class[] {Date.class, TimeZone.class}
            );
            result = (RegularTimePeriod) c.newInstance(new Object[] {millisecond, zone});  
View Full Code Here

     */
    public void testClone() {

        final TimeSeries series = new TimeSeries("Test Series");

        final RegularTimePeriod jan1st2002 = new Day(1, SerialDate.JANUARY, 2002);
        try {
            series.add(jan1st2002, new Integer(42));
        }
        catch (SeriesException e) {
            System.err.println("TimeSeriesTests.testClone: problem adding to series.");
View Full Code Here

        s2.setName("Time Series 1");
        final boolean b2 = s1.equals(s2);
        assertTrue("b2", b2);

        final RegularTimePeriod p1 = new Day();
        final RegularTimePeriod p2 = p1.next();
        s1.add(p1, 100.0);
        s1.add(p2, 200.0);
        final boolean b3 = s1.equals(s2);
        assertFalse("b3", b3);
View Full Code Here

TOP

Related Classes of org.jfree.data.time.RegularTimePeriod

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.