📄 main.java
字号:
package main;
//Copyright (C) 2008 Harald Unander, Wang Wenjuan
//
// This file is part of WlanTV.
//
// WlanTV is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// WlanTV is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with WlanTV. If not, see <http://www.gnu.org/licenses/>.
import java.awt.Color;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.SoftBevelBorder;
import model.Model;
import view.View;
public class Main {
public static final Rectangle GE = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
public static final int TRAINCHART_HEIGHT = GE.height*3/4;
public static final int LOG_HEIGHT = GE.height*1/4;
public static final int LEFT_WIDTH = GE.width*2/3;
public static final Font SMALLFONT = new Font("SansSerif",Font.PLAIN,10);
// public static final Font MONOFONT = new Font("Monospaced",Font.PLAIN,10);
// public static final Border bdr1 = new BevelBorder(SoftBevelBorder.LOWERED);
public static final Border bdr1 = new EtchedBorder(EtchedBorder.LOWERED);
public static final Border bdr2 = new BevelBorder(SoftBevelBorder.RAISED);
public static final Border bdr3 = new EtchedBorder(EtchedBorder.RAISED);
public static final Border emptyBdr0 = new EmptyBorder(0,0,0,0);
public static final Border emptyBdr2 = new EmptyBorder(2,2,2,2);
public static final Border emptyBdr3 = new EmptyBorder(3,3,3,3);
public static final Border emptyBdr4 = new EmptyBorder(4,4,4,4);
public static final Border loweredBdr = new CompoundBorder(bdr1, emptyBdr3);
public static final Border raisedBdr = new CompoundBorder(bdr2, emptyBdr2);
public static final Border etchedBdr = new CompoundBorder(bdr3, emptyBdr2);
public static final Color LIGHT_YELLOW = new Color(250,250,200);
public static final Color LIGHT_BLUE = new Color(230,230,230);
public static final String helpText =
"USAGE\n"+
" Zoom: Mouse scroll wheel\n"+
" Range select: Mouse left button press-move-release\n"+
" Pan: Mouse right button press-move-release\n"+
" Packet info: Left-click on packet\n"+
" Packet details: Right-click on packet\n"+
" Transaction info: Move mouse over transaction\n"+
" Add host alias: Click on MAC address in conversations pane\n\n"+
"Buttons and drop down lists are explained by tool tips.\n\n"+
"Program version: " + Main.class.getPackage().getImplementationVersion();
public static final String informationText =
"The WLAN Traffic Visualizer (WlanTV) presents innovative traffic charts\n"+
"and provides accurate busy and free bandwidth analysis from WLAN capture\n"+
"log files or live captures.\n"+
"\n"+
"It has been developed as a part of our Master Thesis:\n"+
"\"Accurate Measurement and Visualization of Traffic Load in IEEE 802.11 WLANs\"\n"+
"at the University of Agder, Grimstad, Norway\n"+
"\n"+
"Copyright (C) 2008 Harald Unander, Wang Wenjuan\n"+
"\n"+
"This program is free software: you can redistribute it and/or modify\n"+
"it under the terms of the GNU General Public License as published by\n"+
"the Free Software Foundation, either version 3 of the License, or\n"+
"(at your option) any later version.\n"+
"\n"+
"This program is distributed in the hope that it will be useful,\n"+
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"+
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"+
"GNU General Public License for more details.\n"+
"\n"+
"You should have received a copy of the GNU General Public License\n"+
"along with this program. If not, see <http://www.gnu.org/licenses/>.\n"+
"\n"+
"Contact information:\n"+
"haralduna@users.sourceforge.net\n"+
"http://wlantv.sourceforge.net\n"+
"\n"+
"This product contains icons provided by http://www.famfamfam.com\n\n";
public static MyLogging myLogging;
public static WlanTvProperties properties;
public static String tsharkExe;
public static void main(String[] args) {
try {
if (System.getProperty("os.name").toLowerCase().contains("linux"))
// UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
;
else
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// String[] u = UIManager.getLookAndFeelDefaults().toString().split(", ");
// for (String s : u) System.out.println(s);
Color col = UIManager.getColor("Panel.background");
UIManager.put("TextArea.background", col);
UIManager.put("Panel.background", col);
UIManager.put("ToolBar.background", col);
// UIManager.put("Label.font",Main.MONOFONT);
// UIManager.put("ComboBox.font",Main.MONOFONT);
UIManager.put("TextArea.font",Main.SMALLFONT);
tsharkExe = getExecutable();
start(args);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,
stack2string(e),
"Error",
JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
System.exit(-1);
}
}
private static void start(String[] args) throws Exception {
properties = new WlanTvProperties();
myLogging = new MyLogging();
try {
tsharkExe = getExecutable();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,e.getMessage());
System.exit(-1);
}
// Extract capture file name and prepare args for use by tshark
String captureFile = null;
String cmdString = null;
if (args.length > 0) {
StringBuffer sb = new StringBuffer();
boolean nextIsFileName = false;
for (String s : args) {
if (nextIsFileName) {
captureFile = s;
nextIsFileName = false;
}
if (s.equals("-r")) nextIsFileName = true;
sb.append(s+" ");
}
cmdString = sb.toString();
}
Model model = new Model();
View view = new View(model);
new Controller(view, captureFile, cmdString);
}
private static String getExecutable() throws Exception {
String osName = System.getProperty("os.name");
String tsharkExe;
if (osName.toLowerCase().contains("windows")) {
String path[] = System.getenv("path").split(";");
File f;
for (String s: path) {
tsharkExe = s+File.separator+"tshark.exe";
f = new File(tsharkExe);
if (f.exists()) {
// System.out.println(tsharkExe + " found");
return tsharkExe;
}
}
tsharkExe = "C:\\Program Files\\Wireshark\\tshark.exe";
f = new File(tsharkExe);
if (f.exists()) {
// System.out.println(tsharkExe + " found");
return tsharkExe;
}
tsharkExe = "C:\\Programfiler\\Wireshark\\tshark.exe";
f = new File(tsharkExe);
if (f.exists()) {
// System.out.println(tsharkExe + " found");
return tsharkExe;
}
tsharkExe = "";
throw (new Exception("tshark not found in path "+path));
}
else if (osName.toLowerCase().contains("linux")) {
String path[] = System.getenv("PATH").split(":");
for (String s: path) {
tsharkExe = s+File.separator+"tshark";
File f = new File(tsharkExe);
if (f.exists()) {
// System.out.println(tsharkExe + " found");
return tsharkExe;
}
}
tsharkExe = "";
throw (new Exception("tshark not found in path "+path));
}
else {
throw (new Exception("Unsupported OS "+osName));
}
}
public static String stack2string(Exception e) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
catch(Exception e2) {
return "bad stack2string";
}
}
public static String getDate() {
final SimpleDateFormat SDF = new SimpleDateFormat("ddMMMyy-HHmmss");
Calendar cal = new GregorianCalendar();
return SDF.format(cal.getTime());
}
public static String getDate1() {
final SimpleDateFormat SDF = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Calendar cal = new GregorianCalendar();
return SDF.format(cal.getTime());
}
public static Object load(File file) throws Exception {
Object obj = null;
ObjectInputStream in = null;
if(file.exists()) {
try {
in = new ObjectInputStream(new GZIPInputStream(new FileInputStream(file)));
obj = in.readObject();
in.close();
} catch (InvalidClassException e) {
// e.printStackTrace();
throw (e);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return obj;
}
public static void save(File file, Object object) {
try {
ObjectOutputStream out = new ObjectOutputStream(
new GZIPOutputStream(new FileOutputStream(file)));
out.writeObject(object);
out.close();
} catch(IOException e) {
e.printStackTrace();
}
}
public static String usToSec(long us) {
return String.format("%.3fs",us/1000000f);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -