2
Copyright 2008 WebAtlas
3
Authors : Mathieu Bastian, Mathieu Jacomy, Julian Bilcke
4
Website : http://www.gephi.org
6
This file is part of Gephi.
8
Gephi is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
13
Gephi is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with Gephi. If not, see <http://www.gnu.org/licenses/>.
21
package org.gephi.timeline.ui;
23
import java.util.ArrayList;
24
import java.util.List;
25
import java.util.Random;
26
import org.gephi.timeline.TimelineQuartzImpl;
27
import org.gephi.timeline.api.TimelineDataModel;
28
import org.gephi.timeline.api.TimelineDataModelListener;
29
import org.gephi.timeline.api.TimelineQuartz;
30
import org.gephi.timeline.api.TimelineQuartzListener;
34
* @author Julian Bilcke
36
public class FakeTimelineDataModel implements TimelineDataModel, TimelineQuartzListener {
38
private Random random;
39
private List<TimelineDataModelListener> listeners;
42
private TimelineQuartz quartz;
45
private List<Float> data;
46
private int data_getNbOfFakeRevisions = 800000;
49
public enum PlayMode {
54
PlayMode playMode = PlayMode.YOUNGEST;
56
public FakeTimelineDataModel() {
63
listeners = new ArrayList<TimelineDataModelListener>();
65
// WE GENERATE OUR FAKE DATASET
66
random = new Random();
67
data = new ArrayList<Float>();
68
for (int i = 0; i < data_getNbOfFakeRevisions; i++) {
69
data.add(0.15f + random.nextFloat() * 0.6f);
72
quartz = new TimelineQuartzImpl();
73
quartz.addTimelineQuartzListener(this);
76
public List<Float> getOverviewSample(int resolution) {
77
// TODO put a call to the timeline engine here ?
79
List<Float> tmp = new ArrayList<Float>();
81
int unit = data.size() / resolution; // eg. 16 = 10000 / 600
82
for (int i = 0; i < resolution; i++) {
83
tmp.add(data.get(i * unit)); // eg. 600 * chunks of 16
88
public void addTimelineDataModelListener(TimelineDataModelListener listener) {
89
listeners.add(listener);
92
public List<Float> getZoomSample(int resolution) {
94
if (resolution < 1) resolution = 1;
96
// TODO put a call to the timeline engine here ?
97
// get size from the timeline
98
int size = data.size(); // eg 200000000
100
int totalf = (int) (from * (float) size); // eg. 12000
101
int totalt = (int) (to * (float) size); // eg. 12000000
102
System.out.println("totalf: " + totalf);
103
System.out.println("totalt: " + totalt);
105
// get tmp from the timeline getFromRange(..,..)
106
List<Float> tmp = new ArrayList<Float>();
108
int unit = (totalt - totalf) / resolution; // eg. 16 = 10000 / 600
109
if (unit < 1) unit = 1;
110
System.out.println("unit: " + unit);
112
for (int i = 0; i < resolution; i++) {
113
tmp.add(data.get(totalf + i * unit)); // eg. 600 * chunks of 16
118
public void selectInterval(Float from, Float to) {
119
if (0.0f < to && to < 1.0f && 0.0f < from && from < 1.0f && from < to) {
124
public void selectTo(Float to) {
125
if (0.0f < to && to < 1.0f && from < to) {
130
public void selectFrom(Float from) {
131
if (0.0f < from && from < 1.0f && from < to) {
136
public Comparable getFirstComparable() {
139
public Comparable getLastComparable() {
140
return data.get(data.size()-1);
143
public Float getSelectionFrom() {
147
public Comparable getSelectionFromAsComparable() {
148
return data.get((int) (from * (float)data.size()));
150
public Float getSelectionTo() {
153
public Comparable getSelectionToAsComparable() {
154
return data.get((int) (to * (float)data.size()));
161
public void pause() {
165
public void isPlaying() {
168
public void quartzTick(long delay) {
169
// delay is the current "resolution" of the quartz
170
// this is provided ases convenience, in case you would need it for your
174
selectFrom(getSelectionFrom() + speed);
177
selectInterval(getSelectionFrom() + speed,
178
getSelectionTo() + speed);
181
selectTo(getSelectionTo() + speed);