2011-07-15 09:22:23 +00:00
|
|
|
package net.i2p.itoopie.gui;
|
|
|
|
|
|
|
|
import java.awt.Color;
|
2011-07-16 08:31:13 +00:00
|
|
|
import java.awt.EventQueue;
|
2011-07-19 11:35:08 +00:00
|
|
|
import java.util.EnumMap;
|
2011-07-15 09:22:23 +00:00
|
|
|
|
|
|
|
import info.monitorenter.gui.chart.Chart2D;
|
|
|
|
import info.monitorenter.gui.chart.views.ChartPanel;
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
2011-07-16 08:31:13 +00:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.SwingConstants;
|
2011-07-19 11:35:08 +00:00
|
|
|
import javax.swing.SwingUtilities;
|
2011-07-15 09:22:23 +00:00
|
|
|
import javax.swing.event.ChangeEvent;
|
|
|
|
|
2011-07-19 11:35:08 +00:00
|
|
|
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
|
|
|
|
|
|
|
import net.i2p.itoopie.configuration.ConfigurationManager;
|
|
|
|
import net.i2p.itoopie.gui.StatusHandler.DEFAULT_STATUS;
|
2011-07-15 09:22:23 +00:00
|
|
|
import net.i2p.itoopie.gui.component.BandwidthChart;
|
2011-07-16 08:31:13 +00:00
|
|
|
import net.i2p.itoopie.gui.component.MultiLineLabel;
|
2011-07-15 09:22:23 +00:00
|
|
|
import net.i2p.itoopie.gui.component.ParticipatingTunnelsChart;
|
|
|
|
import net.i2p.itoopie.gui.component.TabLogoPanel;
|
2011-07-16 08:31:13 +00:00
|
|
|
import net.i2p.itoopie.gui.component.multilinelabel.MultiLineLabelUI;
|
|
|
|
import net.i2p.itoopie.i18n.Transl;
|
2011-07-19 11:35:08 +00:00
|
|
|
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
|
|
|
import net.i2p.itoopie.i2pcontrol.methods.GetRouterInfo;
|
|
|
|
import net.i2p.itoopie.i2pcontrol.methods.RouterInfo.ROUTER_INFO;
|
2011-07-15 09:22:23 +00:00
|
|
|
|
|
|
|
public class OverviewTab extends TabLogoPanel {
|
2011-07-19 11:35:08 +00:00
|
|
|
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
|
|
|
|
private final static int DEFAULT_INFO_UPDATE_INTERVAL = 30*1000; // Milliseconds.
|
|
|
|
|
2011-07-16 08:31:13 +00:00
|
|
|
JLabel lblI2P;
|
|
|
|
JLabel lblVersion;
|
|
|
|
JLabel lblVersionSpecified;
|
|
|
|
JLabel lblStatus;
|
|
|
|
JLabel lblStatusSpecified;
|
|
|
|
JLabel lblUptime;
|
|
|
|
JLabel lblUptimeSpecified;
|
|
|
|
JLabel lblNetworkStatus;
|
|
|
|
MultiLineLabel lblNetworkStatusSpecified;
|
2011-07-15 09:22:23 +00:00
|
|
|
|
|
|
|
public OverviewTab(String imageName) {
|
|
|
|
super(imageName);
|
|
|
|
super.setLayout(null);
|
2011-07-16 08:31:13 +00:00
|
|
|
|
2011-07-15 09:22:23 +00:00
|
|
|
Chart2D bwChart = BandwidthChart.getChart();
|
|
|
|
Chart2D partTunnelChart = ParticipatingTunnelsChart.getChart();
|
|
|
|
ChartPanel pt = new ChartPanel(partTunnelChart);
|
|
|
|
pt.setSize(300, 135);
|
|
|
|
pt.setLocation(15, 10);
|
|
|
|
pt.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
|
|
|
ChartPanel cp = new ChartPanel(bwChart);
|
2011-07-16 08:31:13 +00:00
|
|
|
cp.setSize(300, 135);
|
2011-07-15 09:22:23 +00:00
|
|
|
cp.setLocation(15, 155);
|
|
|
|
cp.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
2011-07-16 08:31:13 +00:00
|
|
|
|
2011-07-15 09:22:23 +00:00
|
|
|
add(pt);
|
|
|
|
add(cp);
|
2011-07-16 08:31:13 +00:00
|
|
|
|
|
|
|
lblI2P = new JLabel();
|
|
|
|
add(lblI2P);
|
|
|
|
lblI2P.setBounds(285, 30, 100, 15);
|
|
|
|
lblI2P.setText("I2P");
|
|
|
|
lblI2P.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
|
|
|
|
lblVersion = new JLabel();
|
|
|
|
add(lblVersion);
|
|
|
|
lblVersion.setBounds(285, 50, 100, 15);
|
|
|
|
lblVersion.setText(Transl._("Version:"));
|
|
|
|
lblVersion.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
|
|
|
|
lblVersionSpecified = new JLabel();
|
|
|
|
add(lblVersionSpecified);
|
|
|
|
lblVersionSpecified.setBounds(395, 50, 140, 15);
|
|
|
|
lblVersionSpecified.setHorizontalAlignment(SwingConstants.LEFT);
|
2011-07-19 11:35:08 +00:00
|
|
|
// lblVersionSpecified.setText("0.8.7-48rc"); // Delete Me
|
2011-07-16 08:31:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
lblUptime = new JLabel();
|
|
|
|
add(lblUptime);
|
|
|
|
lblUptime.setBounds(285, 70, 100, 15);
|
|
|
|
lblUptime.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
lblUptime.setText(Transl._("Uptime:"));
|
|
|
|
|
|
|
|
lblUptimeSpecified = new JLabel();
|
|
|
|
add(lblUptimeSpecified);
|
|
|
|
lblUptimeSpecified.setBounds(395, 70, 140, 15);
|
|
|
|
lblUptimeSpecified.setHorizontalAlignment(SwingConstants.LEFT);
|
2011-07-19 11:35:08 +00:00
|
|
|
// lblUptimeSpecified.setText("93 min"); // Delete Me
|
2011-07-16 08:31:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
lblStatus = new JLabel();
|
|
|
|
add(lblStatus);
|
|
|
|
lblStatus.setBounds(285, 90, 100, 15);
|
|
|
|
lblStatus.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
lblStatus.setText(Transl._("Status:"));
|
|
|
|
|
|
|
|
lblStatusSpecified = new JLabel();
|
|
|
|
add(lblStatusSpecified);
|
|
|
|
lblStatusSpecified.setBounds(395, 90, 140, 15);
|
|
|
|
lblStatusSpecified.setHorizontalAlignment(SwingConstants.LEFT);
|
2011-07-19 11:35:08 +00:00
|
|
|
// lblStatusSpecified.setText("Rejecting Tunnels"); // Delete Me
|
2011-07-16 08:31:13 +00:00
|
|
|
|
|
|
|
lblNetworkStatus = new JLabel();
|
|
|
|
add(lblNetworkStatus);
|
|
|
|
lblNetworkStatus.setBounds(285, 110, 100, 15);
|
|
|
|
lblNetworkStatus.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
lblNetworkStatus.setText(Transl._("Netstatus:"));
|
|
|
|
|
|
|
|
lblNetworkStatusSpecified = new MultiLineLabel();
|
|
|
|
add(lblNetworkStatusSpecified);
|
|
|
|
lblNetworkStatusSpecified.setBounds(395, 110, 130, 60);
|
|
|
|
lblNetworkStatusSpecified.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
|
lblNetworkStatusSpecified.setVerticalTextAlignment(JLabel.TOP);
|
2011-07-19 11:35:08 +00:00
|
|
|
// lblNetworkStatusSpecified.setText("WARN-Firewalled with Inbound TCP Enabled".replace('-', ' ')); // Delete Me
|
2011-07-16 08:31:13 +00:00
|
|
|
|
|
|
|
validate();
|
2011-07-19 11:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
final int updateInterval = _conf.getConf("overview.info.updateinterval", DEFAULT_INFO_UPDATE_INTERVAL);
|
|
|
|
|
|
|
|
(new Thread(){
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
while (true) {
|
|
|
|
populateInfo();
|
|
|
|
try {
|
|
|
|
Thread.sleep(updateInterval);
|
|
|
|
} catch (InterruptedException e){} // Doesn't matter.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void populateInfo(){
|
|
|
|
try {
|
|
|
|
EnumMap<ROUTER_INFO, Object> em = GetRouterInfo.execute(ROUTER_INFO.VERSION,
|
|
|
|
ROUTER_INFO.UPTIME, ROUTER_INFO.STATUS, ROUTER_INFO.NETWORK_STATUS);
|
|
|
|
|
|
|
|
|
|
|
|
lblVersionSpecified.setText((String) em.get(ROUTER_INFO.VERSION));
|
|
|
|
lblUptimeSpecified.setText((String) em.get(ROUTER_INFO.UPTIME));
|
|
|
|
lblUptimeSpecified.revalidate();
|
|
|
|
lblStatusSpecified.setText((String) em.get(ROUTER_INFO.STATUS));
|
|
|
|
lblNetworkStatusSpecified.setText(((String) em.get(ROUTER_INFO.NETWORK_STATUS)).replace("-", " "));
|
|
|
|
|
|
|
|
|
|
|
|
this.getRootPane().repaint(); // Repainting jlabel or jpanel is not enough.
|
|
|
|
|
|
|
|
StatusHandler.setDefaultStatus(DEFAULT_STATUS.CONNECTED);
|
|
|
|
} catch (InvalidPasswordException e) {
|
|
|
|
StatusHandler.setDefaultStatus(DEFAULT_STATUS.INVALID_PASSWORD);
|
|
|
|
} catch (JSONRPC2SessionException e) {
|
|
|
|
StatusHandler.setDefaultStatus(DEFAULT_STATUS.NOT_CONNECTED);
|
|
|
|
}
|
2011-07-15 09:22:23 +00:00
|
|
|
}
|
2011-07-19 11:35:08 +00:00
|
|
|
|
2011-07-15 09:22:23 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabFocus(ChangeEvent e) {
|
2011-07-19 11:35:08 +00:00
|
|
|
populateInfo();
|
2011-07-15 09:22:23 +00:00
|
|
|
}
|
|
|
|
|
2011-07-16 08:31:13 +00:00
|
|
|
/**
|
|
|
|
* Launch the application.
|
|
|
|
*/
|
|
|
|
public static void main(String[] args) {
|
|
|
|
EventQueue.invokeLater(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
JFrame frame = new JFrame();
|
|
|
|
frame.setBounds(0, 0, Main.FRAME_WIDTH, Main.FRAME_HEIGHT);
|
|
|
|
OverviewTab window = new OverviewTab("itoopie-opaque12");
|
|
|
|
frame.add(window);
|
|
|
|
frame.setVisible(true);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-07-19 11:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-15 09:22:23 +00:00
|
|
|
}
|