Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.awt.event.ActionEvent;
- import java.awt.Font;
- import java.awt.Graphics;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import javax.swing.JList;
- import javax.swing.ListModel;
- import javax.swing.DefaultListModel;
- import javax.swing.JScrollPane;
- import javax.swing.JCheckBox;
- import javax.swing.JComboBox;
- import javax.swing.MutableComboBoxModel;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JPanel;
- import java.awt.GridBagLayout;
- import java.awt.GridBagConstraints;
- import javax.swing.JRadioButton;
- import javax.swing.ButtonGroup;
- import javax.swing.JMenuBar;
- import javax.swing.JMenu;
- import javax.swing.JMenuItem;
- import javax.swing.JFileChooser;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.Scanner;
- import java.util.Set;
- import java.io.IOException;
- import java.util.*;
- public class Window extends JFrame implements ActionListener {
- private JPanel radioButtonPanel;
- private ButtonGroup radioButtons;
- private JRadioButton sourceHostsButton;
- private JRadioButton destinationHostsButton;
- private Font font;
- private GraphDisplay graph;
- private JComboBox ipComboBox;
- public static final int CANVAS_WIDTH=1000;
- public static final int CANVAS_HEIGHT=325;
- public static List<String> srcAddressList=null;
- public static List<String> destAddressList=null;
- Set<String> srcIPHashTable;
- Set<String> destIPHashTable;
- public Window() {
- super("Flow Volume Viewer");
- setLayout(new FlowLayout(0));
- setSize(1000,500);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- font = new Font("Sans-serif", Font.PLAIN, 20);
- setupRadioButtons();
- setupMenu();
- System.out.print(Window.srcAddressList);
- graph = new GraphDisplay();
- graph.setPreferredSize(new Dimension(CANVAS_WIDTH,CANVAS_HEIGHT));
- Container cont=getContentPane();
- cont.add(graph);
- setVisible(true);
- }
- public void setupRadioButtons(){
- radioButtonPanel = new JPanel();
- radioButtonPanel.setLayout(new GridBagLayout());
- GridBagConstraints c = new GridBagConstraints();
- c.gridx = 0;
- c.gridy = GridBagConstraints.RELATIVE;
- c.anchor = GridBagConstraints.WEST;
- radioButtons = new ButtonGroup();
- sourceHostsButton = new JRadioButton("Source hosts");
- sourceHostsButton.setFont(font);
- sourceHostsButton.setSelected(true);
- radioButtons.add(sourceHostsButton);
- radioButtonPanel.add(sourceHostsButton, c);
- destinationHostsButton = new JRadioButton("Destination hosts");
- destinationHostsButton.setFont(font);
- radioButtons.add(destinationHostsButton);
- radioButtonPanel.add(destinationHostsButton, c);
- add(radioButtonPanel);
- }
- public void setupMenu() {
- JMenuBar menuBar = new JMenuBar();
- setJMenuBar(menuBar);
- JMenu fileMenu = new JMenu("File");
- fileMenu.setMnemonic('F');
- fileMenu.setFont(font);
- menuBar.add(fileMenu);
- JMenuItem fileMenuOpen = new JMenuItem("Open trace file");
- fileMenuOpen.setFont(font);
- List<String> srcAddressList = new ArrayList<String>();
- List<String> destAddressList = new ArrayList<String>();
- fileMenuOpen.addActionListener(
- new ActionListener()
- {
- public void actionPerformed(ActionEvent e) {
- JFileChooser fileChooser = new JFileChooser(".");
- int retval = fileChooser.showOpenDialog(Window.this);
- if (retval == JFileChooser.APPROVE_OPTION) {
- File f = fileChooser.getSelectedFile();
- Scanner sc = null;
- try {
- sc = new Scanner(f);
- } catch (IOException e1) {
- return;
- }
- }
- }
- }
- );
- fileMenu.add(fileMenuOpen);
- JMenuItem fileMenuQuit = new JMenuItem("Quit");
- fileMenuQuit.setFont(font);
- fileMenu.add(fileMenuQuit);
- fileMenuQuit.addActionListener(
- new ActionListener()
- {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- );
- }
- private class GraphDisplay extends JPanel{
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- setBackground(Color.WHITE);
- g.setFont(new Font("Sans-serif", Font.PLAIN, 20));
- g.drawLine(50, 20, 50, 270);
- g.drawLine(50, 270, 900, 270);
- g.drawLine(45, 270, 50, 270);
- g.drawString("Time[s]",450,320);
- g.drawString("Volume [bytes]", 10, 15);
- int a=50;
- int b=800/50;
- for (int c=0; c<=b; c++) {
- g.drawLine(50+c*a, 270, 50+c*a, 275);
- g.drawString(String.valueOf(a*c), 40+c*a, 295);
- }
- }
- }
- public void setupComboBox() {
- ipComboBox = new JComboBox<String>();
- ipComboBox.setModel((MutableComboBoxModel<String>) ipComboBox.getModel());
- ipComboBox.setMaximumRowCount(8);
- ipComboBox.setFont(font);
- ipComboBox.setMinimumSize(new Dimension(300,25));
- ipComboBox.addActionListener(this);
- add(ipComboBox);
- }
- public void actionPerformed(ActionEvent event) {
- if (sourceHostsButton.isSelected()) {
- }
- if (destinationHostsButton.isSelected()) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement