Example usage for org.jfree.data.time Month getMonth

List of usage examples for org.jfree.data.time Month getMonth

Introduction

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

Prototype

public int getMonth() 

Source Link

Document

Returns the month.

Usage

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

/**
 * Some checks for the testNext() method.
 *///from   w  w  w. j  a v  a 2  s .  c  om
@Test
public void testNext() {
    Month m = new Month(12, 2000);
    m = (Month) m.next();
    assertEquals(new Year(2001), m.getYear());
    assertEquals(1, m.getMonth());
    m = new Month(12, 9999);
    assertNull(m.next());
}

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

/**
 * Some checks for the testNext() method.
 *///from   w  ww. j  a v  a  2s .  co  m
public void testNext() {
    Month m = new Month(12, 2000);
    m = (Month) m.next();
    assertEquals(new Year(2001), m.getYear());
    assertEquals(1, m.getMonth());
    m = new Month(12, 9999);
    assertNull(m.next());
}

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

/**
 * In GMT, the end of Feb 2000 is java.util.Date(951,868,799,999L).  Use
 * this to check the Month constructor./* w  w  w . j a  va  2s  .  com*/
 */
@Test
public void testDateConstructor1() {

    TimeZone zone = TimeZone.getTimeZone("GMT");
    Month m1 = new Month(new Date(951868799999L), zone);
    Month m2 = new Month(new Date(951868800000L), zone);

    assertEquals(MonthConstants.FEBRUARY, m1.getMonth());
    assertEquals(951868799999L, m1.getLastMillisecond(zone));

    assertEquals(MonthConstants.MARCH, m2.getMonth());
    assertEquals(951868800000L, m2.getFirstMillisecond(zone));

}

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

/**
 * In Auckland, the end of Feb 2000 is java.util.Date(951,821,999,999L).
 * Use this to check the Month constructor.
 *///from  ww  w.  j a  va 2  s .c o m
@Test
public void testDateConstructor2() {

    TimeZone zone = TimeZone.getTimeZone("Pacific/Auckland");
    Month m1 = new Month(new Date(951821999999L), zone);
    Month m2 = new Month(new Date(951822000000L), zone);

    assertEquals(MonthConstants.FEBRUARY, m1.getMonth());
    assertEquals(951821999999L, m1.getLastMillisecond(zone));

    assertEquals(MonthConstants.MARCH, m2.getMonth());
    assertEquals(951822000000L, m2.getFirstMillisecond(zone));

}

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

/**
 * In GMT, the end of Feb 2000 is java.util.Date(951,868,799,999L).  Use
 * this to check the Month constructor./*from   w  w  w  .  j a va 2  s  . c  o m*/
 */
public void testDateConstructor1() {

    TimeZone zone = TimeZone.getTimeZone("GMT");
    Calendar c = new GregorianCalendar(zone);
    Locale locale = Locale.UK;
    Month m1 = new Month(new Date(951868799999L), zone, locale);
    Month m2 = new Month(new Date(951868800000L), zone, locale);

    assertEquals(MonthConstants.FEBRUARY, m1.getMonth());
    assertEquals(951868799999L, m1.getLastMillisecond(c));

    assertEquals(MonthConstants.MARCH, m2.getMonth());
    assertEquals(951868800000L, m2.getFirstMillisecond(c));

}

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

/**
 * In Auckland, the end of Feb 2000 is java.util.Date(951,821,999,999L).
 * Use this to check the Month constructor.
 */// ww w  . j  a  v  a  2s. co  m
public void testDateConstructor2() {

    TimeZone zone = TimeZone.getTimeZone("Pacific/Auckland");
    Calendar c = new GregorianCalendar(zone);
    Month m1 = new Month(new Date(951821999999L), zone, Locale.UK);
    Month m2 = new Month(new Date(951822000000L), zone, Locale.UK);

    assertEquals(MonthConstants.FEBRUARY, m1.getMonth());
    assertEquals(951821999999L, m1.getLastMillisecond(c));

    assertEquals(MonthConstants.MARCH, m2.getMonth());
    assertEquals(951822000000L, m2.getFirstMillisecond(c));

}

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

/**
 * Tests the string parsing code...// w w w  .  j av a 2s  .c o m
 */
@Test
public void testParseMonth() {

    Month month = null;

    // test 1...
    try {
        month = Month.parseMonth("1990-01");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(1, month.getMonth());
    assertEquals(1990, month.getYear().getYear());

    // test 2...
    try {
        month = Month.parseMonth("02-1991");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(2, month.getMonth());
    assertEquals(1991, month.getYear().getYear());

    // test 3...
    try {
        month = Month.parseMonth("March 1993");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(3, month.getMonth());
    assertEquals(1993, month.getYear().getYear());

}

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

/**
 * Returns an integer indicating the order of this Month object relative to
 * the specified//from  w  ww  .  j av a  2  s. c  om
 * object: negative == before, zero == same, positive == after.
 *
 * @param o1  the object to compare.
 *
 * @return negative == before, zero == same, positive == after.
 */
@Override
public int compareTo(TimePeriod o1) {

    int result;

    // CASE 1 : Comparing to another Month object
    // --------------------------------------------
    if (o1 instanceof Month) {
        Month m = (Month) o1;
        result = this.year - m.getYearValue();
        if (result == 0) {
            result = this.month - m.getMonth();
        }
    }

    // CASE 2 : Comparing to another TimePeriod object
    // -----------------------------------------------
    else {
        // more difficult case - evaluate later...
        result = 0;
    }

    return result;

}

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

/**
 * Tests the string parsing code.../*w ww  . j  av a  2s .  co m*/
 */
public void testParseMonth() {

    Month month;

    // test 1...
    try {
        month = Month.parseMonth("1990-01");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(1, month.getMonth());
    assertEquals(1990, month.getYear().getYear());

    // test 2...
    try {
        month = Month.parseMonth("02-1991");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(2, month.getMonth());
    assertEquals(1991, month.getYear().getYear());

    // test 3...
    try {
        month = Month.parseMonth("March 1993");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(3, month.getMonth());
    assertEquals(1993, month.getYear().getYear());

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYDataset dataset = (XYDataset) datasets.getDatasets().get("1");

    final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend,
            false, false);/* w ww .  ja va 2  s . c o  m*/
    sparkLineGraph.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    sparkLineGraph.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        sparkLineGraph.addSubtitle(subTitle);
    }

    sparkLineGraph.setBorderVisible(false);
    sparkLineGraph.setBorderPaint(Color.BLACK);
    XYPlot plot = sparkLineGraph.getXYPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(color);

    // calculate the last marker color
    Paint colorLast = getLastPointColor();

    // Calculate average, minimum and maximum to draw plot borders.
    boolean isFirst = true;
    double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
    int count = 0;
    for (int i = 0; i < timeSeries.getItemCount(); i++) {
        if (timeSeries.getValue(i) != null) {
            count++;
            if (isFirst) {
                min = timeSeries.getValue(i).doubleValue();
                max = timeSeries.getValue(i).doubleValue();
                isFirst = false;
            }
            double n = timeSeries.getValue(i).doubleValue();
            //calculate avg, min, max
            avg += n;
            if (n < min)
                min = n;
            if (n > max)
                max = n;
        }
    }
    // average
    avg = avg / (double) count;

    // calculate min and max between thresholds!
    boolean isFirst2 = true;
    double lb = 0, ub = 0;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        if (isFirst2 == true) {
            ub = thres.doubleValue();
            lb = thres.doubleValue();
            isFirst2 = false;
        }
        if (thres.doubleValue() > ub)
            ub = thres.doubleValue();
        if (thres.doubleValue() < lb)
            lb = thres.doubleValue();
    }

    plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2));

    addMarker(1, avg, Color.GRAY, 0.8f, plot);
    //addAvaregeSeries(series, plot);
    addPointSeries(timeSeries, plot);

    int num = 3;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        TargetThreshold targThres = thresholds.get(thres);
        Color color = Color.WHITE;
        if (targThres != null && targThres.getColor() != null) {
            color = targThres.getColor();
        }
        if (targThres.isVisible()) {
            addMarker(num++, thres.doubleValue(), color, 0.5f, plot);
        }
    }

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setUpperMargin(0.2);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);

    plot.getRenderer().setSeriesPaint(0, Color.BLACK);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        public boolean getItemShapeVisible(int _series, int item) {
            TimeSeriesDataItem tsdi = timeSeries.getDataItem(item);
            if (tsdi == null)
                return false;
            Month period = (Month) tsdi.getPeriod();
            int currMonth = period.getMonth();
            int currYear = period.getYearValue();
            int lastMonthFilled = lastMonth.getMonth();
            int lastYearFilled = lastMonth.getYearValue();
            boolean isLast = false;
            if (currYear == lastYearFilled && currMonth == lastMonthFilled) {
                isLast = true;
            }
            return isLast;
        }
    };
    renderer.setSeriesPaint(0, Color.decode("0x000000"));

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(colorLast);
    renderer.setBaseOutlinePaint(Color.BLACK);
    renderer.setUseOutlinePaint(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    if (wlt_mode.doubleValue() == 0) {
        renderer.setBaseItemLabelsVisible(Boolean.FALSE, true);
    } else {
        renderer.setBaseItemLabelsVisible(Boolean.TRUE, true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
        renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"),
                new DecimalFormat("0.###")) {
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0)
                    return "";
                String columnKey = (String) dataset.getColumnKey(column);
                int separator = columnKey.indexOf('-');
                String month = columnKey.substring(0, separator);
                String year = columnKey.substring(separator + 1);
                int monthNum = Integer.parseInt(month);
                if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) {
                    if (wlt_mode.doubleValue() == 2 && column % 2 == 0)
                        return "";

                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.MONTH, monthNum - 1);
                    SimpleDateFormat dataFormat = new SimpleDateFormat("MMM");
                    return dataFormat.format(calendar.getTime());
                } else
                    return "" + monthNum;
            }
        });
    }

    if (wlt_mode.doubleValue() == 3) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2));

    } else if (wlt_mode.doubleValue() == 4) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4));
    }

    if (legend == true) {
        LegendItemCollection collection = createThresholdLegend(plot);
        LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage);
        collection.add(item);
        plot.setFixedLegendItems(collection);

    }

    plot.setRenderer(0, renderer);
    logger.debug("OUT");
    return sparkLineGraph;
}