~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.callgraph/src/org/eclipse/linuxtools/internal/callgraph/graphlisteners/Projectionist.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2009 Red Hat, Inc.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 * 
 
8
 * Contributors:
 
9
 *     Red Hat - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.linuxtools.internal.callgraph.graphlisteners;
 
12
 
 
13
import org.eclipse.core.runtime.IProgressMonitor;
 
14
import org.eclipse.core.runtime.IStatus;
 
15
import org.eclipse.core.runtime.Status;
 
16
import org.eclipse.core.runtime.jobs.Job;
 
17
import org.eclipse.linuxtools.internal.callgraph.StapGraph;
 
18
import org.eclipse.swt.widgets.Display;
 
19
 
 
20
/**
 
21
 * A Projectionist is the gguy that operates a movie camera.
 
22
 * @author chwang
 
23
 *
 
24
 */
 
25
public class Projectionist extends Job {
 
26
        private StapGraph graph;
 
27
        private int frame_time = 2000;
 
28
        private boolean pause;
 
29
        private boolean busy;
 
30
        
 
31
 
 
32
        /**
 
33
         * @param name
 
34
         * @param listener    -- the keyListener instantiating this class
 
35
         * @param time -- Amount of time between frames
 
36
         */
 
37
        public Projectionist(String name, StapGraph graph, int time) {
 
38
                super(name);
 
39
                this.graph = graph;
 
40
                this.frame_time = time;
 
41
                pause = false;
 
42
                busy = false;
 
43
        }
 
44
 
 
45
        @Override
 
46
        public IStatus run(IProgressMonitor monitor) {
 
47
 
 
48
                long snapshot = System.currentTimeMillis();
 
49
                while (true) {
 
50
                        if (busy) {
 
51
                                try {
 
52
                                        Thread.sleep(300);
 
53
                                } catch (InterruptedException e1) {
 
54
                                        e1.printStackTrace();
 
55
                                }
 
56
                                continue;
 
57
                        }
 
58
                        
 
59
                        if (pause)
 
60
                                return Status.OK_STATUS;
 
61
                        
 
62
                        if (System.currentTimeMillis() - snapshot >= frame_time) {
 
63
                                snapshot = System.currentTimeMillis();
 
64
                                busy = true;
 
65
                                Display.getDefault().asyncExec(new Runnable() {
 
66
                                        @Override
 
67
                                        public void run() {
 
68
                                                graph.drawNextNode();
 
69
                                                busy = false;
 
70
                                        }
 
71
                                });
 
72
                                
 
73
                        } else {
 
74
                                try {
 
75
                                        Thread.sleep(500);
 
76
                                } catch (InterruptedException e) {
 
77
                                        e.printStackTrace();
 
78
                                }
 
79
                        }
 
80
                        if (monitor.isCanceled()) {
 
81
                                break;
 
82
                        }
 
83
                }
 
84
                
 
85
                return Status.CANCEL_STATUS;
 
86
        }
 
87
        
 
88
        /**
 
89
         * Projectionist will pause -- reschedule job to continue
 
90
         */
 
91
        public void pause() {
 
92
                pause = true;
 
93
        }
 
94
 
 
95
}