Advertisement
Guest User

Untitled

a guest
May 27th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1.  
  2. import java.awt.Color;
  3. import java.awt.Container;
  4. import java.awt.Dimension;
  5. import java.awt.FlowLayout;
  6. import java.awt.event.ActionListener;
  7. import java.io.File;
  8. import java.io.FileNotFoundException;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.Font;
  11. import java.awt.Graphics;
  12.  
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JTextField;
  16. import javax.swing.JButton;
  17. import javax.swing.JList;
  18. import javax.swing.ListModel;
  19. import javax.swing.DefaultListModel;
  20. import javax.swing.JScrollPane;
  21. import javax.swing.JCheckBox;
  22. import javax.swing.JComboBox;
  23. import javax.swing.MutableComboBoxModel;
  24.  
  25. import javax.swing.DefaultComboBoxModel;
  26. import javax.swing.JPanel;
  27. import java.awt.GridBagLayout;
  28. import java.awt.GridBagConstraints;
  29. import javax.swing.JRadioButton;
  30. import javax.swing.ButtonGroup;
  31. import javax.swing.JMenuBar;
  32. import javax.swing.JMenu;
  33. import javax.swing.JMenuItem;
  34. import javax.swing.JFileChooser;
  35.  
  36. import java.util.ArrayList;
  37. import java.util.HashSet;
  38. import java.util.Scanner;
  39. import java.util.Set;
  40. import java.io.IOException;
  41. import java.util.*;
  42.  
  43.  
  44. public class Window extends JFrame implements ActionListener {
  45. private JPanel radioButtonPanel;
  46. private ButtonGroup radioButtons;
  47. private JRadioButton sourceHostsButton;
  48. private JRadioButton destinationHostsButton;
  49. private Font font;
  50. private GraphDisplay graph;
  51. private JComboBox ipComboBox;
  52.  
  53. public static final int CANVAS_WIDTH=1000;
  54. public static final int CANVAS_HEIGHT=325;
  55.  
  56. public static List<String> srcAddressList=null;
  57. public static List<String> destAddressList=null;
  58.  
  59. Set<String> srcIPHashTable;
  60. Set<String> destIPHashTable;
  61.  
  62.  
  63.  
  64. public Window() {
  65. super("Flow Volume Viewer");
  66. setLayout(new FlowLayout(0));
  67. setSize(1000,500);
  68. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  69. font = new Font("Sans-serif", Font.PLAIN, 20);
  70. setupRadioButtons();
  71. setupMenu();
  72. System.out.print(Window.srcAddressList);
  73. graph = new GraphDisplay();
  74. graph.setPreferredSize(new Dimension(CANVAS_WIDTH,CANVAS_HEIGHT));
  75. Container cont=getContentPane();
  76. cont.add(graph);
  77. setVisible(true);
  78.  
  79. }
  80.  
  81. public void setupRadioButtons(){
  82. radioButtonPanel = new JPanel();
  83. radioButtonPanel.setLayout(new GridBagLayout());
  84. GridBagConstraints c = new GridBagConstraints();
  85. c.gridx = 0;
  86. c.gridy = GridBagConstraints.RELATIVE;
  87. c.anchor = GridBagConstraints.WEST;
  88. radioButtons = new ButtonGroup();
  89. sourceHostsButton = new JRadioButton("Source hosts");
  90. sourceHostsButton.setFont(font);
  91. sourceHostsButton.setSelected(true);
  92. radioButtons.add(sourceHostsButton);
  93. radioButtonPanel.add(sourceHostsButton, c);
  94. destinationHostsButton = new JRadioButton("Destination hosts");
  95. destinationHostsButton.setFont(font);
  96. radioButtons.add(destinationHostsButton);
  97. radioButtonPanel.add(destinationHostsButton, c);
  98. add(radioButtonPanel);
  99. }
  100.  
  101.  
  102. public void setupMenu() {
  103.  
  104. JMenuBar menuBar = new JMenuBar();
  105. setJMenuBar(menuBar);
  106. JMenu fileMenu = new JMenu("File");
  107. fileMenu.setMnemonic('F');
  108. fileMenu.setFont(font);
  109. menuBar.add(fileMenu);
  110. JMenuItem fileMenuOpen = new JMenuItem("Open trace file");
  111. fileMenuOpen.setFont(font);
  112. List<String> srcAddressList = new ArrayList<String>();
  113. List<String> destAddressList = new ArrayList<String>();
  114.  
  115. fileMenuOpen.addActionListener(
  116. new ActionListener()
  117. {
  118. public void actionPerformed(ActionEvent e) {
  119. JFileChooser fileChooser = new JFileChooser(".");
  120. int retval = fileChooser.showOpenDialog(Window.this);
  121. if (retval == JFileChooser.APPROVE_OPTION) {
  122. File f = fileChooser.getSelectedFile();
  123. Scanner sc = null;
  124. try {
  125. sc = new Scanner(f);
  126. } catch (IOException e1) {
  127. return;
  128. }
  129.  
  130. }
  131.  
  132. }
  133. }
  134. );
  135. fileMenu.add(fileMenuOpen);
  136. JMenuItem fileMenuQuit = new JMenuItem("Quit");
  137. fileMenuQuit.setFont(font);
  138. fileMenu.add(fileMenuQuit);
  139. fileMenuQuit.addActionListener(
  140. new ActionListener()
  141. {
  142. public void actionPerformed(ActionEvent e) {
  143. System.exit(0);
  144. }
  145. }
  146. );
  147.  
  148.  
  149. }
  150.  
  151.  
  152.  
  153.  
  154. private class GraphDisplay extends JPanel{
  155. public void paintComponent(Graphics g) {
  156. super.paintComponent(g);
  157. setBackground(Color.WHITE);
  158. g.setFont(new Font("Sans-serif", Font.PLAIN, 20));
  159. g.drawLine(50, 20, 50, 270);
  160. g.drawLine(50, 270, 900, 270);
  161. g.drawLine(45, 270, 50, 270);
  162. g.drawString("Time[s]",450,320);
  163. g.drawString("Volume [bytes]", 10, 15);
  164. int a=50;
  165. int b=800/50;
  166. for (int c=0; c<=b; c++) {
  167. g.drawLine(50+c*a, 270, 50+c*a, 275);
  168. g.drawString(String.valueOf(a*c), 40+c*a, 295);
  169. }
  170. }
  171. }
  172.  
  173. public void setupComboBox() {
  174. ipComboBox = new JComboBox<String>();
  175. ipComboBox.setModel((MutableComboBoxModel<String>) ipComboBox.getModel());
  176. ipComboBox.setMaximumRowCount(8);
  177. ipComboBox.setFont(font);
  178. ipComboBox.setMinimumSize(new Dimension(300,25));
  179.  
  180. ipComboBox.addActionListener(this);
  181. add(ipComboBox);
  182. }
  183.  
  184.  
  185.  
  186.  
  187. public void actionPerformed(ActionEvent event) {
  188. if (sourceHostsButton.isSelected()) {
  189.  
  190. }
  191. if (destinationHostsButton.isSelected()) {
  192.  
  193. }
  194. }
  195.  
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement