From b554c5b647ebb90e259572adc33196d6812d6355 Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 9 Jan 2022 07:33:50 -0500 Subject: [PATCH] Clear graphs when changing router hostname/port finals --- history.txt | 2 ++ src/net/i2p/itoopie/gui/Main.java | 5 +-- src/net/i2p/itoopie/gui/OverviewTab.java | 37 +++++++++++++++------- src/net/i2p/itoopie/gui/SettingsFrame.java | 8 +++-- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/history.txt b/history.txt index 5fcb41310..23ead55ee 100644 --- a/history.txt +++ b/history.txt @@ -3,6 +3,7 @@ * Build fixes * Support i2pcontrol HTTP Java console webapp at port 7657 * Layout fixes and adjustments + * Fixes for long translated strings * Fixes for i2pd * Graph adjustments * Localize time format on graphs @@ -11,6 +12,7 @@ * Rename Configuration tab to "I2P Control" * Remove "Settings read from I2P router" message * Set graph values to 0 when router is gone + * Clear graph after changing router host/port * Update to jchart2d 3.2.2 2011-09-25 * Remove debug output * README updates diff --git a/src/net/i2p/itoopie/gui/Main.java b/src/net/i2p/itoopie/gui/Main.java index c329cfb52..04d8e06a3 100644 --- a/src/net/i2p/itoopie/gui/Main.java +++ b/src/net/i2p/itoopie/gui/Main.java @@ -81,7 +81,7 @@ public class Main { root.add(tabbedPane); tabbedPane.setBounds(0, 0, FRAME_WIDTH-9, TABBED_PANE_HEIGHT); - TabLogoPanel overviewTab = new OverviewTab("itoopie-opaque12"); + OverviewTab overviewTab = new OverviewTab("itoopie-opaque12"); tabbedPane.addTab(' ' + Transl._t("Overview") + ' ', null, overviewTab, null); tabbedPane.addChangeListener(new TabChangeListener(overviewTab)); @@ -92,7 +92,8 @@ public class Main { tabbedPane.addChangeListener(new TabChangeListener(configTab)); - TabLogoPanel settingsTab = new SettingsFrame("itoopie-opaque12"); + // pass overview tab to settingsframe to reset the charts on change + TabLogoPanel settingsTab = new SettingsFrame("itoopie-opaque12", overviewTab); tabbedPane.addTab(' ' + Transl._t("Settings") + ' ', icon, settingsTab, null); tabbedPane.addChangeListener(new TabChangeListener(settingsTab)); diff --git a/src/net/i2p/itoopie/gui/OverviewTab.java b/src/net/i2p/itoopie/gui/OverviewTab.java index e56365d8b..ed43967cf 100644 --- a/src/net/i2p/itoopie/gui/OverviewTab.java +++ b/src/net/i2p/itoopie/gui/OverviewTab.java @@ -5,6 +5,7 @@ import java.awt.EventQueue; import java.util.EnumMap; import info.monitorenter.gui.chart.Chart2D; +import info.monitorenter.gui.chart.ITrace2D; import info.monitorenter.gui.chart.views.ChartPanel; import javax.swing.BorderFactory; @@ -34,22 +35,24 @@ public class OverviewTab extends TabLogoPanel { private static ConfigurationManager _conf = ConfigurationManager.getInstance(); private final static int DEFAULT_INFO_UPDATE_INTERVAL = 30*1000; // Milliseconds. - JLabel lblI2P; - JLabel lblVersion; - JLabel lblVersionSpecified; - MultiLineLabel lblStatus; - MultiLineLabel lblStatusSpecified; - MultiLineLabel lblUptime; - JLabel lblUptimeSpecified; - MultiLineLabel lblNetworkStatus; - MultiLineLabel lblNetworkStatusSpecified; + private final JLabel lblI2P; + private final JLabel lblVersion; + private final JLabel lblVersionSpecified; + private final MultiLineLabel lblStatus; + private final MultiLineLabel lblStatusSpecified; + private final MultiLineLabel lblUptime; + private final JLabel lblUptimeSpecified; + private final MultiLineLabel lblNetworkStatus; + private final MultiLineLabel lblNetworkStatusSpecified; + private final BandwidthChart bwChart; + private final ParticipatingTunnelsChart partTunnelChart; public OverviewTab(String imageName) { super(imageName); super.setLayout(null); - final BandwidthChart bwChart = new BandwidthChart(); - Chart2D partTunnelChart = new ParticipatingTunnelsChart(); + bwChart = new BandwidthChart(); + partTunnelChart = new ParticipatingTunnelsChart(); ChartPanel pt = new ChartPanel(partTunnelChart); pt.setSize(300, 135); pt.setLocation(5, 10); @@ -143,6 +146,18 @@ public class OverviewTab extends TabLogoPanel { }).start(); } + /** + * @since 0.0.4 + */ + public void clearGraphs() { + for (ITrace2D trace : bwChart.getTraces()) { + trace.removeAllPoints(); + } + for (ITrace2D trace : partTunnelChart.getTraces()) { + trace.removeAllPoints(); + } + } + private void populateInfo(){ try { EnumMap em = GetRouterInfo.execute(ROUTER_INFO.VERSION, diff --git a/src/net/i2p/itoopie/gui/SettingsFrame.java b/src/net/i2p/itoopie/gui/SettingsFrame.java index a9c864436..445432a16 100644 --- a/src/net/i2p/itoopie/gui/SettingsFrame.java +++ b/src/net/i2p/itoopie/gui/SettingsFrame.java @@ -88,15 +88,17 @@ public class SettingsFrame extends TabLogoPanel { private JPasswordField txtRetypeNewPassword; */ - private ConfigurationManager _conf; + private final ConfigurationManager _conf; + private final OverviewTab _otab; /** * Create the application. */ - public SettingsFrame(String imageName) { + public SettingsFrame(String imageName, OverviewTab otab) { super(imageName); setLayout(null); _conf = ConfigurationManager.getInstance(); + _otab = otab; initialize(); } @@ -390,6 +392,8 @@ public class SettingsFrame extends TabLogoPanel { _conf.setConf("server.port", port); _conf.setConf("server.password", pwText); JSONRPC2Interface.testSettings(); + if (!oldIP.equals(ipText) || oldPort != port) + _otab.clearGraphs(); } catch (InvalidPasswordException e) { _conf.setConf("server.password", oldPW); JOptionPane.showConfirmDialog(