001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    
005    package graphlab.graph.old;
006    
007    import graphlab.graph.graph.EdgeModel;
008    import graphlab.graph.graph.GraphModel;
009    import graphlab.graph.graph.VertexModel;
010    import graphlab.platform.core.BlackBoard;
011    
012    import java.awt.*;
013    
014    /**
015     * a super accelerated renderer, not working completely yet.
016     */
017    public class SuperAcceleratedRenderer extends AcceleratedRenderer {
018        public SuperAcceleratedRenderer(GraphModel g, BlackBoard blackboard) {
019            super(g, blackboard);
020    //        t = new Thread(this);
021    //        t.setPriority(Thread.MIN_PRIORITY);
022            isRunning = true;
023        }
024    
025        private static final int FRAME_DELAY = 1000; // 20ms. implies 50fps (1000/20) = 50
026    
027        boolean isRunning;
028        //    JComponent gui;
029        long cycleTime;
030    
031        public void paint(Graphics2D g) {
032    
033    
034        }
035    
036    
037        public void run() {
038            cycleTime = System.currentTimeMillis();
039    //todo: should extend canvas for the following lines
040    //        createBufferStrategy(2);
041    //        BufferStrategy strategy = getBufferStrategy();
042    
043            // Game Loop
044            while (isRunning) {
045    //            updateGUI(strategy);
046                synchFramerate();
047            }
048        }
049    
050    
051        private void synchFramerate() {
052            cycleTime = cycleTime + FRAME_DELAY;
053            long difference = cycleTime - System.currentTimeMillis();
054            try {
055                Thread.sleep(Math.max(0, difference));
056            }
057            catch (InterruptedException e) {
058                e.printStackTrace();
059            }
060        }
061    
062        public void vertexAdded(VertexModel v) {
063            v.setLabel(v.getId() + "");
064            v.setVertexListener(this);
065        }
066    
067        public void edgeAdded(EdgeModel e) {
068            e.setLabel(e.getId());
069            e.setEdgeModelListener(this);
070    //        e.updateBounds();
071        }
072    }