001    package jp.osdl.jbento2.chart;
002    
003    import java.text.ParseException;
004    import java.util.Date;
005    
006    import jp.osdl.jbento2.StateDateFormatter;
007    
008    import org.jfree.data.general.AbstractDataset;
009    import org.jfree.data.time.Millisecond;
010    import org.jfree.data.time.TimeTableXYDataset;
011    
012    public class XYDateDataSetBuilder extends DataSetBuilderBase {
013    
014        private StateDateFormatter formatter = new StateDateFormatter("HH:mm:ss.S",
015                StateDateFormatter.DATE);
016    
017        protected void add(AbstractDataset dataset, String row, String column,
018                String value) {
019    
020            try {
021                ((TimeTableXYDataset) dataset).add(new Millisecond(nextDate(row)),
022                        Double.parseDouble(value), column);
023            } catch (ParseException e) {
024                System.err.println("row=\"" + row + "\", value=\"" + value
025                        + "\" : " + e.getMessage());
026            } catch (NumberFormatException e) {
027                System.err.println("row=\"" + row + "\", value=\"" + value
028                        + "\" : " + e.getMessage());
029            }
030        }
031    
032        protected AbstractDataset newDataset() {
033            return new TimeTableXYDataset();
034        }
035    
036        protected Date nextDate(String row) throws ParseException {
037            try {
038                return formatter.nextDate(row);
039            } catch (ParseException e) {
040                formatter = new StateDateFormatter("HH:mm:ss",
041                        StateDateFormatter.DATE);
042                return formatter.nextDate(row);
043            }
044        }
045    
046    }