Implementation of customisable summary bar via routerconsole.summaryBar property

The initial attempt using mapping of strings to methods is shorter and neater,
but also doesn't work so is commented out.
This commit is contained in:
str4d
2012-06-05 07:36:24 +00:00
parent 5699b4515b
commit 531c6c0f4c
3 changed files with 69 additions and 49 deletions

View File

@ -15,7 +15,7 @@ import net.i2p.router.RouterContext;
*
*/
public class SummaryBarRenderer {
static final Map<String, java.lang.reflect.Method> sections;
/*static final Map<String, java.lang.reflect.Method> ALL_SECTIONS;
static {
Map<String, java.lang.reflect.Method> aMap = new HashMap<String, java.lang.reflect.Method>();;
try {
@ -37,8 +37,8 @@ public class SummaryBarRenderer {
aMap.put("NewsHeadings", SummaryBarRenderer.class.getMethod("renderNewsHeadingsHTML"));
} catch (java.lang.NoSuchMethodException e) {
}
sections = Collections.unmodifiableMap(aMap);
}
ALL_SECTIONS = Collections.unmodifiableMap(aMap);
}*/
private final RouterContext _context;
private final SummaryHelper _helper;
@ -77,54 +77,62 @@ public class SummaryBarRenderer {
.append(_("I2P Router Console"))
.append("\" title=\"")
.append(_("I2P Router Console"))
.append("\"></a></div>\n")
.append("<hr>\n")
.append(renderHelpAndFAQHTML())
.append("<hr>\n");
.append("\"></a></div>\n");
File lpath = new File(_context.getBaseDir(), "docs/toolbar.html");
// you better have target="_top" for the links in there...
if (lpath.exists()) {
ContentHelper linkhelper = new ContentHelper();
linkhelper.setPage(lpath.getAbsolutePath());
linkhelper.setMaxLines("100");
buf.append(linkhelper.getContent());
} else {
buf.append(renderI2PServicesHTML())
.append("<hr>\n")
.append(renderI2PInternalsHTML());
out.write(buf.toString());
out.write(buf.toString());
String[] sections = _helper.getSummaryBarSections();
for (int i = 0; i < sections.length; i++) {
/*try {
String section = (String)ALL_SECTIONS.get(sections[i]).invoke(this);
if (section != null && section != "") {
out.write("<hr>" + i + "<hr>\n" + section);
}
} catch (Exception e) {
out.write("<hr>" +i + " - Exception<hr>\n" + e);
}*/
buf.setLength(0);
String section = sections[i];
buf.append("<hr>\n");
if ("HelpAndFAQ".equals(section))
buf.append(renderHelpAndFAQHTML());
else if ("I2PServices".equals(section))
buf.append(renderI2PServicesHTML());
else if ("I2PInternals".equals(section))
buf.append(renderI2PInternalsHTML());
else if ("General".equals(section))
buf.append(renderGeneralHTML());
else if ("ShortGeneral".equals(section))
buf.append(renderShortGeneralHTML());
else if ("NetworkReachability".equals(section))
buf.append(renderNetworkReachabilityHTML());
else if ("UpdateStatus".equals(section))
buf.append(renderUpdateStatusHTML());
else if ("RestartStatus".equals(section))
buf.append(renderRestartStatusHTML());
else if ("Peers".equals(section))
buf.append(renderPeersHTML());
else if ("FirewallAndReseedStatus".equals(section))
buf.append(renderFirewallAndReseedStatusHTML());
else if ("Bandwidth".equals(section))
buf.append(renderBandwidthHTML());
else if ("Tunnels".equals(section))
buf.append(renderTunnelsHTML());
else if ("Congestion".equals(section))
buf.append(renderCongestionHTML());
else if ("TunnelStatus".equals(section))
buf.append(renderTunnelStatusHTML());
else if ("Destinations".equals(section))
buf.append(renderDestinationsHTML());
else if ("NewsHeadings".equals(section))
buf.append(renderNewsHeadingsHTML());
// Only output section if there's more than the <hr> to print
if (buf.length() > 5)
out.write(buf.toString());
}
buf.append("<hr>\n")
.append(renderGeneralHTML())
.append("<hr>\n")
.append(renderNetworkReachabilityHTML())
.append("<hr>\n")
.append(renderUpdateStatusHTML())
.append(renderRestartStatusHTML())
.append("<hr>\n")
.append(renderPeersHTML())
.append("<hr>\n");
out.write(buf.toString());
buf.setLength(0);
buf.append(renderFirewallAndReseedStatusHTML())
.append(renderBandwidthHTML())
.append("<hr>\n")
.append(renderTunnelsHTML())
.append("<hr>\n")
.append(renderCongestionHTML())
.append("<hr>\n")
.append(renderTunnelStatusHTML())
.append("<hr>\n")
.append(renderDestinationsHTML())
.append("<hr>\n");
out.write(buf.toString());
}
public String renderHelpAndFAQHTML() {

View File

@ -36,7 +36,7 @@ public class SummaryHelper extends HelperBase {
//static final String THINSP = "&thinsp;/&thinsp;";
static final String THINSP = " / ";
private static final char S = ',';
static final String PROP_SUMMARYBAR = "routerconsole.summarybar";
static final String PROP_SUMMARYBAR = "routerconsole.summaryBar";
static final String PRESET_FULL =
"HelpAndFAQ" + S +
@ -739,6 +739,18 @@ public class SummaryHelper extends HelperBase {
return buf.toString();
}
public String[] getSummaryBarSections() {
String config = _context.getProperty(PROP_SUMMARYBAR, PRESET_FULL);
return config.split("" + S);
}
public void saveSummaryBarSections(String[] sections) {
StringBuilder buf = new StringBuilder(512);
for(int i = 0; i < sections.length; i++)
buf.append(sections[i]).append(S);
_context.router().saveConfig(PROP_SUMMARYBAR, buf.toString());
}
/** output the summary bar to _out */
public void renderSummaryBar() throws IOException {
SummaryBarRenderer renderer = new SummaryBarRenderer(_context, this);