package net.i2p.router.web;
import java.io.IOException;
import java.io.Writer;
import java.util.*;
import net.i2p.data.DataHelper;
import net.i2p.stat.Rate;
import net.i2p.router.RouterContext;
public class GraphHelper {
private RouterContext _context;
private Writer _out;
private int _periodCount;
private boolean _showEvents;
private int _width;
private int _height;
private int _refreshDelaySeconds;
/**
* Configure this bean to query a particular router context
*
* @param contextId begging few characters of the routerHash, or null to pick
* the first one we come across.
*/
public void setContextId(String contextId) {
try {
_context = ContextHelper.getContext(contextId);
} catch (Throwable t) {
t.printStackTrace();
}
}
public GraphHelper() {
_periodCount = 60; // SummaryListener.PERIODS;
_showEvents = false;
_width = 250;
_height = 100;
_refreshDelaySeconds = 60;
}
public void setOut(Writer out) { _out = out; }
public void setPeriodCount(String str) {
try { _periodCount = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
}
public void setShowEvents(boolean b) { _showEvents = b; }
public void setHeight(String str) {
try { _height = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
}
public void setWidth(String str) {
try { _width = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
}
public void setRefreshDelay(String str) {
try { _refreshDelaySeconds = Integer.parseInt(str); } catch (NumberFormatException nfe) {}
}
public String getImages() {
try {
_out.write("\n");
List listeners = StatSummarizer.instance().getListeners();
for (int i = 0; i < listeners.size(); i++) {
SummaryListener lsnr = (SummaryListener)listeners.get(i);
Rate r = lsnr.getRate();
String title = r.getRateStat().getName() + " for " + DataHelper.formatDuration(_periodCount * r.getPeriod());
_out.write("
\n");
}
if (_refreshDelaySeconds > 0)
_out.write("\n");
} catch (IOException ioe) {
ioe.printStackTrace();
}
return "";
}
public String getForm() {
try {
_out.write("