1 6 7 package com.thoughtriver.open.vectorvisuals; 8 9 import java.awt.*; 10 import java.awt.image.*; 11 12 import com.thoughtriver.open.vectorvisuals.task.*; 13 14 23 public class VVCanvas extends Canvas implements VVViewPane { 24 25 private static final long serialVersionUID = 3904965243971908914L; 26 27 31 private BufferStrategy bufferStrategy = null; 32 33 34 private VVDisplay vvDisplay = null; 35 36 39 public VVCanvas() { 40 } 41 42 45 public void setVVDisplay(final VVDisplay vvDisplay) { 46 this.vvDisplay = vvDisplay; 47 } 48 49 56 private Graphics getBufferedGraphics() { 57 58 if (bufferStrategy != null) { 60 return bufferStrategy.getDrawGraphics(); 61 } 62 63 try { 64 createBufferStrategy(2); 65 bufferStrategy = getBufferStrategy(); 66 } 67 catch (IllegalStateException ise) { 68 bufferStrategy = null; 69 return null; 70 } 71 72 return getBufferedGraphics(); 73 } 74 75 80 @Override 81 public synchronized void paint(final Graphics g) { 82 update(g); 83 } 84 85 92 @Override 93 public synchronized void update(final Graphics g) { 94 Graphics g2 = getBufferedGraphics(); 95 Graphics graphics = (g2 == null ? g : g2); 96 97 if (vvDisplay != null) { 98 vvDisplay.paint(graphics); 99 } 100 else { 101 super.paint(graphics); 102 } 103 104 if (g2 != null) { 105 bufferStrategy.show(); 106 } 107 108 } 109 110 115 @Override 116 public synchronized void repaint() { 117 if (vvDisplay.getTaskManager().getExecutionState() == ExecutionState.running) { 118 Graphics g = getBufferedGraphics(); 119 if (g != null) { 120 update(g); 121 bufferStrategy.show(); 122 return; 123 } 124 } 125 126 super.repaint(); 127 } 128 129 } 130 | Popular Tags |