1 package prefuse.util.display; 2 3 import java.util.Arrays ; 4 5 import prefuse.util.ArrayLib; 6 import prefuse.visual.VisualItem; 7 import prefuse.visual.sort.ItemSorter; 8 9 16 public class RenderingQueue { 17 18 private static final int DEFAULT_SIZE = 256; 19 20 public ItemSorter sort = new ItemSorter(); 21 22 public VisualItem[] ritems = new VisualItem[DEFAULT_SIZE]; 24 public int[] rscores = new int[DEFAULT_SIZE]; 25 public int rsize = 0; 26 27 public VisualItem[] pitems = new VisualItem[DEFAULT_SIZE]; 29 public int[] pscores = new int[DEFAULT_SIZE]; 30 public int psize = 0; 31 public boolean psorted = false; 32 33 transient static VisualItem[] items_buf; 35 transient static int[] scores_buf; 36 37 40 public void clear() { 41 Arrays.fill(ritems, 0, rsize, null); 42 Arrays.fill(pitems, 0, psize, null); 43 rsize = 0; 44 psize = 0; 45 } 46 47 51 public void addToRenderQueue(VisualItem item) { 52 if ( ritems.length == rsize ) { 53 int capacity = (3*ritems.length)/2 + 1; 54 VisualItem[] q = new VisualItem[capacity]; 55 int[] s = new int[capacity]; 56 System.arraycopy(ritems, 0, q, 0, rsize); 57 System.arraycopy(rscores, 0, s, 0, rsize); 58 ritems = q; 59 rscores = s; 60 } 61 ritems[rsize] = item; 62 rscores[rsize++] = (sort != null ? sort.score(item) : 0); 63 } 64 65 69 public void addToPickingQueue(VisualItem item) { 70 if ( pitems.length == psize ) { 71 int capacity = (3*pitems.length)/2 + 1; 72 VisualItem[] q = new VisualItem[capacity]; 73 int[] s = new int[capacity]; 74 System.arraycopy(pitems, 0, q, 0, psize); 75 System.arraycopy(pscores, 0, s, 0, psize); 76 pitems = q; 77 pscores = s; 78 } 79 pitems[psize] = item; 80 pscores[psize++] = (sort != null ? sort.score(item) : 0); 81 psorted = false; 82 } 83 84 87 public void sortRenderQueue() { 88 sort(ritems, rscores, rsize); 89 } 90 91 94 public void sortPickingQueue() { 95 sort(pitems, pscores, psize); 96 psorted = true; 97 } 98 99 102 private void sort(VisualItem[] items, int[] scores, int size) { 103 if ( sort == null ) return; 104 if ( items_buf == null || items_buf.length < size ) { 106 items_buf = new VisualItem[items.length]; 107 scores_buf = new int[scores.length]; 108 } 109 ArrayLib.sort(scores, items, scores_buf, items_buf, 0, size); 111 } 112 113 } | Popular Tags |