From 5699b4515b593b0b4fa33f01063f753d949008d1 Mon Sep 17 00:00:00 2001 From: str4d Date: Tue, 5 Jun 2012 02:12:30 +0000 Subject: [PATCH] Preparations for making the summary bar customisable --- .../i2p/router/web/SummaryBarRenderer.java | 53 ++++++++++++++++++- .../src/net/i2p/router/web/SummaryHelper.java | 29 ++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java index 2fd6c8073..fa04bccad 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java @@ -3,6 +3,9 @@ package net.i2p.router.web; import java.io.File; import java.io.IOException; import java.io.Writer; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import net.i2p.data.DataHelper; import net.i2p.router.RouterContext; @@ -12,6 +15,31 @@ import net.i2p.router.RouterContext; * */ public class SummaryBarRenderer { + static final Map sections; + static { + Map aMap = new HashMap();; + try { + aMap.put("HelpAndFAQ", SummaryBarRenderer.class.getMethod("renderHelpAndFAQHTML")); + aMap.put("I2PServices", SummaryBarRenderer.class.getMethod("renderI2PServicesHTML")); + aMap.put("I2PInternals", SummaryBarRenderer.class.getMethod("renderI2PInternalsHTML")); + aMap.put("General", SummaryBarRenderer.class.getMethod("renderGeneralHTML")); + aMap.put("ShortGeneral", SummaryBarRenderer.class.getMethod("renderShortGeneralHTML")); + aMap.put("NetworkReachability", SummaryBarRenderer.class.getMethod("renderNetworkReachabilityHTML")); + aMap.put("UpdateStatus", SummaryBarRenderer.class.getMethod("renderUpdateStatusHTML")); + aMap.put("RestartStatus", SummaryBarRenderer.class.getMethod("renderRestartStatusHTMLHTML")); + aMap.put("Peers", SummaryBarRenderer.class.getMethod("renderPeersHTML")); + aMap.put("FirewallAndReseedStatus", SummaryBarRenderer.class.getMethod("renderFirewallAndReseedStatusHTML")); + aMap.put("Bandwidth", SummaryBarRenderer.class.getMethod("renderBandwidthHTML")); + aMap.put("Tunnels", SummaryBarRenderer.class.getMethod("renderTunnelsHTML")); + aMap.put("Congestion", SummaryBarRenderer.class.getMethod("renderCongestionHTML")); + aMap.put("TunnelStatus", SummaryBarRenderer.class.getMethod("renderTunnelStatusHTML")); + aMap.put("Destinations", SummaryBarRenderer.class.getMethod("renderDestinationsHTML")); + aMap.put("NewsHeadings", SummaryBarRenderer.class.getMethod("renderNewsHeadingsHTML")); + } catch (java.lang.NoSuchMethodException e) { + } + sections = Collections.unmodifiableMap(aMap); + } + private final RouterContext _context; private final SummaryHelper _helper; private final NewsHelper _newshelper; @@ -265,6 +293,29 @@ public class SummaryBarRenderer { return buf.toString(); } + public String renderShortGeneralHTML() { + if (_helper == null) return ""; + StringBuilder buf = new StringBuilder(512); + buf.append("" + + "" + + "\n" + + + "" + + "" + + "
") + .append(_("Version")) + .append(":") + .append(_helper.getVersion()) + .append("
") + .append(_("Uptime")) + .append(":") + .append(_helper.getUptime()) + .append("
\n"); + return buf.toString(); + } + public String renderNetworkReachabilityHTML() { if (_helper == null) return ""; StringBuilder buf = new StringBuilder(512); @@ -487,7 +538,7 @@ public class SummaryBarRenderer { /** @since 0.9.1 */ public String renderNewsHeadingsHTML() { - if (_newshelper == null) return ""; + if (_newshelper == null || _newshelper.shouldShowNews()) return ""; StringBuilder buf = new StringBuilder(512); String consoleNonce = System.getProperty("router.consoleNonce"); if (consoleNonce != null) { diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java index 80456d604..282c1be1e 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java @@ -35,6 +35,35 @@ public class SummaryHelper extends HelperBase { // Opera 10.63 doesn't have the char, TODO check UA //static final String THINSP = " / "; static final String THINSP = " / "; + private static final char S = ','; + static final String PROP_SUMMARYBAR = "routerconsole.summarybar"; + + static final String PRESET_FULL = + "HelpAndFAQ" + S + + "I2PServices" + S + + "I2PInternals" + S + + "General" + S + + "NetworkReachability" + S + + "UpdateStatus" + S + + "RestartStatus" + S + + "Peers" + S + + "FirewallAndReseedStatus" + S + + "Bandwidth" + S + + "Tunnels" + S + + "Congestion" + S + + "TunnelStatus" + S + + "Destinations" + S + + ""; + + static final String PRESET_SHORT = + "ShortGeneral" + S + + "NewsHeadings" + S + + "UpdateStatus" + S + + "NetworkReachability" + S + + "FirewallAndReseedStatus" + S + + "Destinations" + S + + "RestartStatus" + S + + ""; /** * Retrieve the shortened 4 character ident for the router located within