Example usage for org.jfree.data.time Day getDayOfMonth

List of usage examples for org.jfree.data.time Day getDayOfMonth

Introduction

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

Prototype

public int getDayOfMonth() 

Source Link

Document

Returns the day of the month.

Usage

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

/**
 * Set up a day equal to 1 January 1900.  Request the next day, it should
 * be 2 January 1900./* w  w w . ja va 2  s . c o m*/
 */
@Test
public void test1Jan1900Next() {
    Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900);
    Day next = (Day) jan1st1900.next();
    assertEquals(2, next.getDayOfMonth());
}

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

/**
 * Set up a day equal to 31 December 9999.  Request the previous day, it
 * should be 30 December 9999.//from w  w w  .j  a va 2  s  . co  m
 */
@Test
public void test31Dec9999Previous() {
    Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999);
    Day previous = (Day) dec31st9999.previous();
    assertEquals(30, previous.getDayOfMonth());
}

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

/**
 * Set up a day equal to 1 January 1900.  Request the next day, it should
 * be 2 January 1900./* w  ww . ja v  a  2 s.c o m*/
 */
public void test1Jan1900Next() {
    Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900);
    Day next = (Day) jan1st1900.next();
    assertEquals(2, next.getDayOfMonth());
}

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

/**
 * Set up a day equal to 31 December 9999.  Request the previous day, it
 * should be 30 December 9999./*  www.  ja v a  2 s  .com*/
 */
public void test31Dec9999Previous() {
    Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999);
    Day previous = (Day) dec31st9999.previous();
    assertEquals(30, previous.getDayOfMonth());
}

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

/**
 * Some checks for the testNext() method.
 *///w  w w.j a  v a2  s  .com
@Test
public void testNext() {
    Day d = new Day(25, 12, 2000);
    d = (Day) d.next();
    assertEquals(2000, d.getYear());
    assertEquals(12, d.getMonth());
    assertEquals(26, d.getDayOfMonth());
    d = new Day(31, 12, 9999);
    assertNull(d.next());
}

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

/**
 * Some checks for the testNext() method.
 *///from   w  w  w  .  j  ava 2s  .  c  om
public void testNext() {
    Day d = new Day(25, 12, 2000);
    d = (Day) d.next();
    assertEquals(2000, d.getYear());
    assertEquals(12, d.getMonth());
    assertEquals(26, d.getDayOfMonth());
    d = new Day(31, 12, 9999);
    assertNull(d.next());
}

From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java

/**
 * Zoom in to this chart with specific amount of time.
 * @param field the calendar field./*from   w  w  w .  jav  a 2 s .  com*/
 * @param amount the amount of date or time to be added to the field.
 */
private void _zoom(int field, int amount) {
    this.chartPanel.restoreAutoBounds();

    final int itemCount = this.priceTimeSeries.getItemCount();
    final Day day = (Day) this.priceTimeSeries.getDataItem(itemCount - 1).getPeriod();
    // Candle stick takes up half day space.
    // Volume price chart's volume information takes up whole day space.
    final long end = day.getFirstMillisecond()
            + (this.getCurrentType() == Type.Candlestick ? (1000 * 60 * 60 * 12) : (1000 * 60 * 60 * 24 - 1));
    final Calendar calendar = Calendar.getInstance();
    // -1. Calendar's month is 0 based but JFreeChart's month is 1 based.
    calendar.set(day.getYear(), day.getMonth() - 1, day.getDayOfMonth(), 0, 0, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    calendar.add(field, amount);
    // Candle stick takes up half day space.
    // Volume price chart's volume information does not take up any space.
    final long start = Math.max(0, calendar.getTimeInMillis()
            - (this.getCurrentType() == Type.Candlestick ? (1000 * 60 * 60 * 12) : 0));
    final ValueAxis valueAxis = this.getPlot().getDomainAxis();

    if (priceTimeSeries.getItemCount() > 0) {
        if (start < priceTimeSeries.getTimePeriod(0).getFirstMillisecond()) {
            // To prevent zoom-out too much.
            // This happens when user demands for 10 years zoom, where we
            // are only having 5 years data.
            return;
        }
    }

    valueAxis.setRange(start, end);

    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;
    double max_volume = Double.MIN_VALUE;
    final DefaultHighLowDataset defaultHighLowDataset = (DefaultHighLowDataset) this.priceOHLCDataset;

    for (int i = itemCount - 1; i >= 0; i--) {
        final TimeSeriesDataItem item = this.priceTimeSeries.getDataItem(i);
        final Day d = (Day) item.getPeriod();
        if (d.getFirstMillisecond() < start) {
            break;
        }

        final double high = defaultHighLowDataset.getHighValue(0, i);
        final double low = defaultHighLowDataset.getLowValue(0, i);
        final double volume = defaultHighLowDataset.getVolumeValue(0, i);

        if (max < high) {
            max = high;
        }
        if (min > low) {
            min = low;
        }
        if (max_volume < volume) {
            max_volume = volume;
        }
    }

    if (min > max) {
        return;
    }

    final ValueAxis rangeAxis = this.getPlot().getRangeAxis();
    final Range rangeAxisRange = rangeAxis.getRange();
    // Increase each side by 1%
    double tolerance = 0.01 * (max - min);
    // The tolerance must within range [0.01, 1.0]
    tolerance = Math.min(Math.max(0.01, tolerance), 1.0);
    // The range must within the original chart range.
    min = Math.max(rangeAxisRange.getLowerBound(), min - tolerance);
    max = Math.min(rangeAxisRange.getUpperBound(), max + tolerance);

    this.getPlot().getRangeAxis().setRange(min, max);

    if (this.getPlot().getRangeAxisCount() > 1) {
        final double volumeUpperBound = this.getPlot().getRangeAxis(1).getRange().getUpperBound();
        final double suggestedVolumneUpperBound = max_volume * 4;
        // To prevent over zoom-in.
        if (suggestedVolumneUpperBound < volumeUpperBound) {
            this.getPlot().getRangeAxis(1).setRange(0, suggestedVolumneUpperBound);
        }
    }
}