⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timetablexydataset.java

📁 提供JFreechart图表功能, 提供JFreechart图表功能,提供JFreechart图表功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * -----------------------
 * TimeTableXYDataset.java
 * -----------------------
 * (C) Copyright 2004, 2005, 2007, by Andreas Schroeder and Contributors.
 *
 * Original Author:  Andreas Schroeder;
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *                   Rob Eden;
 *
 * Changes
 * -------
 * 01-Apr-2004 : Version 1 (AS);
 * 05-May-2004 : Now implements AbstractIntervalXYDataset (DG);
 * 15-Jul-2004 : Switched getX() with getXValue() and getY() with 
 *               getYValue() (DG);
 * 15-Sep-2004 : Added getXPosition(), setXPosition(), equals() and 
 *               clone() (DG);
 * 17-Nov-2004 : Updated methods for changes in DomainInfo interface (DG);
 * 25-Nov-2004 : Added getTimePeriod(int) method (DG);
 * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 
 *               release (DG);
 * 27-Jan-2005 : Modified to use TimePeriod rather than RegularTimePeriod (DG);
 * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
 * 25-Jul-2007 : Added clear() method by Rob Eden, see patch 1752205 (DG);
 *
 */

package org.jfree.data.time;

import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

import org.jfree.data.DefaultKeyedValues2D;
import org.jfree.data.DomainInfo;
import org.jfree.data.Range;
import org.jfree.data.general.DatasetChangeEvent;
import org.jfree.data.xy.AbstractIntervalXYDataset;
import org.jfree.data.xy.IntervalXYDataset;
import org.jfree.data.xy.TableXYDataset;
import org.jfree.util.PublicCloneable;

/**
 * A dataset for regular time periods that implements the 
 * {@link TableXYDataset} interface.
 * 
 * @see org.jfree.data.xy.TableXYDataset
 */
public class TimeTableXYDataset extends AbstractIntervalXYDataset
                                implements Cloneable, PublicCloneable,
                                           IntervalXYDataset, 
                                           DomainInfo, 
                                           TableXYDataset {
    
    /**
     * The data structure to store the values.  Each column represents
     * a series (elsewhere in JFreeChart rows are typically used for series,
     * but it doesn't matter that much since this data structure is private 
     * and symmetrical anyway), each row contains values for the same 
     * {@link RegularTimePeriod} (the rows are sorted into ascending order).
     */
    private DefaultKeyedValues2D values;
    
    /**
     * A flag that indicates that the domain is 'points in time'.  If this flag
     * is true, only the x-value (and not the x-interval) is used to determine 
     * the range of values in the domain.
     */
    private boolean domainIsPointsInTime;
    
    /** 
     * The point within each time period that is used for the X value when this
     * collection is used as an {@link org.jfree.data.xy.XYDataset}.  This can 
     * be the start, middle or end of the time period.   
     */
    private TimePeriodAnchor xPosition;

    /** A working calendar (to recycle) */
    private Calendar workingCalendar;

    /**
     * Creates a new dataset.
     */
    public TimeTableXYDataset() {
        // defer argument checking
        this(TimeZone.getDefault(), Locale.getDefault());
    }
    
    /**
     * Creates a new dataset with the given time zone.
     * 
     * @param zone  the time zone to use (<code>null</code> not permitted).
     */
    public TimeTableXYDataset(TimeZone zone) {
        // defer argument checking
        this(zone, Locale.getDefault());
    }

    /**
     * Creates a new dataset with the given time zone and locale.
     * 
     * @param zone  the time zone to use (<code>null</code> not permitted).
     * @param locale  the locale to use (<code>null</code> not permitted).
     */
    public TimeTableXYDataset(TimeZone zone, Locale locale) {
        if (zone == null) {
            throw new IllegalArgumentException("Null 'zone' argument.");
        }
        if (locale == null) {
            throw new IllegalArgumentException("Null 'locale' argument.");
        }
        this.values = new DefaultKeyedValues2D(true);
        this.workingCalendar = Calendar.getInstance(zone, locale);
        this.xPosition = TimePeriodAnchor.START;
    }
    
    /**
     * Returns a flag that controls whether the domain is treated as 'points in
     * time'.
     * <P>
     * This flag is used when determining the max and min values for the domain.
     * If true, then only the x-values are considered for the max and min 
     * values.  If false, then the start and end x-values will also be taken 
     * into consideration.
     *
     * @return The flag.
     */
    public boolean getDomainIsPointsInTime() {
        return this.domainIsPointsInTime;
    }

    /**
     * Sets a flag that controls whether the domain is treated as 'points in 
     * time', or time periods.  A {@link DatasetChangeEvent} is sent to all
     * registered listeners.
     *
     * @param flag  the new value of the flag.
     */
    public void setDomainIsPointsInTime(boolean flag) {
        this.domainIsPointsInTime = flag;
        notifyListeners(new DatasetChangeEvent(this, this));
    }
    
    /**
     * Returns the position within each time period that is used for the X 
     * value.
     * 
     * @return The anchor position (never <code>null</code>).
     */
    public TimePeriodAnchor getXPosition() {
        return this.xPosition;
    }

    /**
     * Sets the position within each time period that is used for the X values,
     * then sends a {@link DatasetChangeEvent} to all registered listeners.
     * 
     * @param anchor  the anchor position (<code>null</code> not permitted).
     */
    public void setXPosition(TimePeriodAnchor anchor) {
        if (anchor == null) {
            throw new IllegalArgumentException("Null 'anchor' argument.");
        }
        this.xPosition = anchor;
        notifyListeners(new DatasetChangeEvent(this, this));    
    }
        
    /**
     * Adds a new data item to the dataset and sends a 
     * {@link org.jfree.data.general.DatasetChangeEvent} to all registered
     * listeners.
     * 
     * @param period  the time period.
     * @param y  the value for this period.
     * @param seriesName  the name of the series to add the value.
     */
    public void add(TimePeriod period, double y, String seriesName) {
        add(period, new Double(y), seriesName, true);
    }
    
    /**
     * Adds a new data item to the dataset.
     * 
     * @param period  the time period (<code>null</code> not permitted).
     * @param y  the value for this period (<code>null</code> permitted).
     * @param seriesName  the name of the series to add the value 
     *                    (<code>null</code> not permitted).
     * @param notify  whether dataset listener are notified or not.
     */
    public void add(TimePeriod period, Number y, String seriesName, 
                    boolean notify) {
        this.values.addValue(y, period, seriesName);
        if (notify) {
            fireDatasetChanged();
        }
    }

    /**
     * Removes an existing data item from the dataset.
     * 
     * @param period  the (existing!) time period of the value to remove 
     *                (<code>null</code> not permitted).
     * @param seriesName  the (existing!) series name to remove the value 
     *                    (<code>null</code> not permitted).
     */
    public void remove(TimePeriod period, String seriesName) {
        remove(period, seriesName, true);
    }
    
    /**
     * Removes an existing data item from the dataset.
     * 
     * @param period  the (existing!) time period of the value to remove 
     *                (<code>null</code> not permitted).
     * @param seriesName  the (existing!) series name to remove the value 
     *                    (<code>null</code> not permitted).
     * @param notify  whether dataset listener are notified or not.
     */
    public void remove(TimePeriod period, String seriesName, boolean notify) {
        this.values.removeValue(period, seriesName);
        if (notify) {
            fireDatasetChanged();
        }
    }

    /**
     * Removes all data items from the dataset and sends a
     * {@link DatasetChangeEvent} to all registered listeners.
     * 
     * @since 1.0.7
     */
    public void clear() {
        if (this.values.getRowCount() > 0) {
            this.values.clear();
            fireDatasetChanged();
        }
    }
    
    /**
     * Returns the time period for the specified item.  Bear in mind that all
     * series share the same set of time periods.
     * 
     * @param item  the item index (0 <= i <= {@link #getItemCount()}).
     * 
     * @return The time period.
     */
    public TimePeriod getTimePeriod(int item) {
        return (TimePeriod) this.values.getRowKey(item);    
    }
    
    /**
     * Returns the number of items in ALL series.
     *
     * @return The item count.
     */
    public int getItemCount() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -