1 package com.ca.commons.cbutil; 2 3 import javax.swing.*; 4 import java.awt.*; 5 6 21 22 27 public class CBpbar 28 { 29 33 34 ProgressMonitor pbar; 35 36 int count; 38 int pcntg; 40 int level; 42 static int MAXLEVEL = 6; int fanout[] = new int[MAXLEVEL]; 46 int visited[] = new int[MAXLEVEL]; 48 String notePrefix; 50 59 60 public CBpbar(Component C, String uberTitle, String notePrefix) 61 { 62 this.notePrefix = notePrefix; 63 64 65 pbar = new ProgressMonitor(C, uberTitle, notePrefix + " 0", 0, 100); 66 level = 0; 67 fanout[level] = 1; } 69 70 79 80 public void inc() 81 { 82 count++; 83 int oldpcntg = pcntg; 84 if (level < MAXLEVEL && level >= 0) 85 { 86 87 93 visited[level]++; 94 pcntg = 0; 95 int spread = 100; 96 for (int i = 0; i < level; i++) 97 { 98 pcntg += (spread * visited[i]) / fanout[i]; 99 spread = spread / fanout[i]; 100 } 101 102 if (pcntg != oldpcntg) 103 { 104 SwingUtilities.invokeLater(new Runnable () 105 { 106 public void run() 107 { 108 pbar.setProgress(pcntg); 109 pbar.setNote(notePrefix + " " + count); 110 } 111 }); 112 } 113 } 114 } 115 116 120 121 public void pop() 122 { 123 level--; 124 } 125 126 136 public void push(int fanout) 137 { 138 level++; 139 if (level < MAXLEVEL) this.fanout[level] = fanout; 140 } 141 142 145 146 public void close() 147 { 148 pbar.close(); 149 } 150 151 157 158 public boolean isCanceled() 159 { 160 return pbar.isCanceled(); 161 } 162 163 } | Popular Tags |