GUIUpdaterpublic class GUIUpdater extends org.gudy.azureus2.core3.util.AEThread implements org.gudy.azureus2.core3.config.ParameterListener
Fields Summary |
---|
private static final org.gudy.azureus2.core3.logging.LogIDs | LOGID | private static final boolean | DEBUG_TIMERCalculate timer statistics for GUI update | private MainWindow | mainWindow | private org.eclipse.swt.widgets.Display | display | boolean | finished | boolean | refreshed | static List | refreshables | int | waitTime | Map | averageTimes |
Constructors Summary |
---|
public GUIUpdater(MainWindow mainWindow)
super("GUI updater", true);
this.mainWindow = mainWindow;
this.display = mainWindow.getDisplay();
setPriority(Thread.MAX_PRIORITY -2);
COConfigurationManager.addParameterListener("GUI Refresh", this);
|
Methods Summary |
---|
public static void | addRefreshableItem(Refreshable item)
synchronized (refreshables)
{
refreshables.add(new WeakReference(item));
}
| private void | makeDebugToolTip(long lTimeStart, java.util.Map timeMap)
final int IDX_AVG = 0;
final int IDX_SIZE = 1;
final int IDX_MAX = 2;
final int IDX_LAST = 3;
final int IDX_TIME = 4;
long lastTime = lTimeStart;
for (Iterator iter = timeMap.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
if (!averageTimes.containsKey(key))
averageTimes.put(key, new Object[] { new Long(0), new Long(0),
new Long(0), new Long(0), new Long(System.currentTimeMillis()) });
Object[] average = (Object[]) averageTimes.get(key);
long l = ((Long) timeMap.get(key)).longValue();
long diff = l - lastTime;
if (diff > 0) {
long count = ((Long) average[IDX_SIZE]).longValue();
// Limit to 20. Gives slightly scewed averages, but doesn't
// require storing all 20 values and averaging them each time
if (count >= 20)
count = 19;
long lNewAverage = ((((Long) average[IDX_AVG]).longValue() * count) + diff)
/ (count + 1);
average[IDX_AVG] = new Long(lNewAverage);
average[IDX_SIZE] = new Long(count + 1);
if (diff > ((Long) average[IDX_MAX]).longValue())
average[IDX_MAX] = new Long(diff);
average[IDX_LAST] = new Long(diff);
average[IDX_TIME] = new Long(System.currentTimeMillis());
} else {
average[IDX_LAST] = new Long(diff);
}
averageTimes.put(key, average);
lastTime = l;
}
StringBuffer sb = new StringBuffer();
for (Iterator iter = averageTimes.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
Object[] average = (Object[]) averageTimes.get(key);
long lLastUpdated = ((Long) average[IDX_TIME]).longValue();
if (System.currentTimeMillis() - lLastUpdated > 10000) {
iter.remove();
continue;
}
long lTime = ((Long) average[IDX_AVG]).longValue();
if (lTime > 0) {
if (sb.length() > 0)
sb.append("\n");
sb.append(average[IDX_AVG] + "ms avg: ");
sb.append("[" + key + "]");
sb.append(average[IDX_SIZE] + " samples");
sb.append("; max:" + average[IDX_MAX]);
sb.append("; last:" + average[IDX_LAST]);
}
}
MainStatusBar mainStatusBar = mainWindow.getMainStatusBar();
if (mainStatusBar != null)
mainStatusBar.setDebugInfo(sb.toString());
| public void | parameterChanged(java.lang.String parameterName)
waitTime = COConfigurationManager.getIntParameter("GUI Refresh");
| public void | runSupport()
while (!finished) {
if(refreshed)
update();
try {
Thread.sleep(waitTime);
}
catch (Exception e) {
Debug.printStackTrace( e );
}
}
| public void | stopIt()
finished = true;
COConfigurationManager.removeParameterListener("GUI Refresh", this);
COConfigurationManager.removeParameterListener("config.style.refreshMT", this);
| private void | update()
refreshed = false;
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
try {
long lTimeStart = System.currentTimeMillis();
Map timeMap = DEBUG_TIMER ? new LinkedHashMap() : null;
if (display == null || display.isDisposed())
return;
IView view = null;
if (!mainWindow.getShell().isDisposed() && mainWindow.isVisible()
&& !mainWindow.getShell().getMinimized()) {
view = mainWindow.getCurrentView();
if (DEBUG_TIMER)
timeMap.put("Init", new Long(System.currentTimeMillis()));
if (view != null) {
view.refresh();
if (DEBUG_TIMER) {
String s = view.getFullTitle().replaceAll("[0-9.]++\\% : ", "");
timeMap.put("'" + s + "' Refresh", new Long(System.currentTimeMillis()));
}
Tab.refresh();
if (DEBUG_TIMER)
timeMap.put("Tab Refresh", new Long(System.currentTimeMillis()));
}
MainStatusBar mainStatusBar = mainWindow.getMainStatusBar();
if (mainStatusBar != null)
mainStatusBar.refreshStatusBar();
}
if (DEBUG_TIMER)
timeMap.put("Status Bar", new Long(System.currentTimeMillis()));
SystemTraySWT systemTraySWT = mainWindow.getSystemTraySWT();
if (systemTraySWT != null)
systemTraySWT.update();
if (DEBUG_TIMER)
timeMap.put("SysTray", new Long(System.currentTimeMillis()));
try {
MiniBarManager.getManager().refreshAll();
} catch (Exception e) {
Logger.log(new LogEvent(LOGID,
"Error while trying to update DL Bars", e));
}
TrayWindow tray = mainWindow.getTray();
if (tray != null) {
tray.refresh();
}
if (DEBUG_TIMER) {
timeMap.put("DLBars", new Long(System.currentTimeMillis()));
makeDebugToolTip(lTimeStart, timeMap);
}
synchronized (refreshables)
{
for(int i=0;i < refreshables.size();i++)
{
Refreshable item = (Refreshable)((WeakReference)refreshables.get(i)).get();
if(item == null)
{
refreshables.remove(i--);
continue;
}
item.refresh();
}
}
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "Error while trying to update GUI", e));
} finally {
refreshed = true;
}
}
});
|
|