import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; public class VControl extends JFrame implements ActionListener { final ButtonGroup winGroup; JColorChooser label_color; JColorChooser win1_color; JColorChooser win2_color; JColorChooser win3_color; final static float dash1[] = {5.0f}; final static BasicStroke stroke = new BasicStroke(1.0f); final static BasicStroke dashed = new BasicStroke(1.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); String newline; JSlider cpu_slider; JPanel winPanel; int crit_slider_value = 50; /*Changing one state to the other one*/ int start_slider_value = 25; /*The value the slider starts with*/ int a; /*Temprorary value for controlling slider*/ int x=0, y=0, x1=0, y1=0, x_l1, y_l1, x_r1, y_r1, xb1=0, yb1=0, x2=0, y2=0, x_l2, y_l2, x_r2, y_r2, xb2=0, yb2=0, x3=0, y3=0, x_l3, y_l3, x_r3, y_r3, xb3=0, yb3=0; boolean flagWin1 = false; boolean flagWin2 = false; boolean flagWin3 = false; boolean mouseInside = false; JSlider win1_slider; JSlider win2_slider; JSlider win3_slider; int win1_slider_value = 0; int win2_slider_value = 0; int win3_slider_value = 0; String win1_str = "1 0 0 0 0 0"; String win2_str = "2 0 0 0 0 0"; String win3_str = "3 0 0 0 0 0"; //Dimensions of the panel// int h, w; static Color[] grays = new Color[256]; static Color[] wColor = new Color[21]; static { for(int i=0; i<256; i++) grays[i] = new Color(i, i, i); for(int i=50; i<200; i=i+15) { wColor[ (i-50)/15 ] = grays[i]; // System.out.println("color=" + (i-50)/15); } wColor[10] = grays[204]; for(int i=255; i>205; i=i-5) { wColor[ ((i-205)/5)+10 ] = grays[i]; // System.out.println("color=" + (((i-205)/5)+11) ); } } public VControl() { super("Kent State Medianet Lab"); WriteToFile("1 0","bypass.par"); WriteToFile("0.0","rate.par"); WriteToFile("1 0 0 100 100 0","adjustq"); BevelBorder bevel = new BevelBorder(BevelBorder.LOWERED); a = start_slider_value; label_color = new JColorChooser(Color.black); /* try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); SwingUtilities.updateComponentTreeUI(this); }catch(Exception e){} */ setSize(470,680); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0); } }); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); JLabel vcLabel = new JLabel(" ACTIVE NODE CONTROL CENTER ",JLabel.CENTER); vcLabel.setForeground(label_color.getColor()); vcLabel.setAlignmentX(Component.CENTER_ALIGNMENT); p.add(vcLabel); p.add(Box.createRigidArea(new Dimension(0,30))); JPanel nodeControlPanel = new JPanel(); nodeControlPanel.setBorder(bevel); nodeControlPanel.add(Box.createRigidArea(new Dimension(0,10))); nodeControlPanel.setLayout(new BoxLayout(nodeControlPanel, BoxLayout.Y_AXIS)); JLabel nodeControlLabel = new JLabel("NODE CONTROL",JLabel.CENTER); nodeControlLabel.setForeground(label_color.getColor()); nodeControlLabel.setAlignmentX(Component.CENTER_ALIGNMENT); nodeControlPanel.add(nodeControlLabel); nodeControlPanel.add(Box.createRigidArea(new Dimension(0,20))); JLabel netLabel = new JLabel("Network Bandwidth Kb/s",JLabel.CENTER); netLabel.setAlignmentX(Component.CENTER_ALIGNMENT); nodeControlPanel.add(netLabel); nodeControlPanel.add(Box.createRigidArea(new Dimension(0,20))); JSlider net_slider = new JSlider(JSlider.HORIZONTAL, 0, 4000, 4000); net_slider.setMinorTickSpacing(125); net_slider.setMajorTickSpacing(500); net_slider.setPaintTicks(true); net_slider.setPaintLabels(true); net_slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider sourse = (JSlider)e.getSource(); if (sourse.getValueIsAdjusting()) { int i = (int)sourse.getValue(); String str = "" + i + "000"; // System.out.println(""+str); WriteToFile(str,"rate.par"); } } }); nodeControlPanel.add(net_slider); nodeControlPanel.add(Box.createRigidArea(new Dimension(0,20))); JLabel cpuLabel = new JLabel("CPU Load",JLabel.CENTER); cpuLabel.setAlignmentX(Component.CENTER_ALIGNMENT); nodeControlPanel.add(cpuLabel); cpu_slider = new JSlider(JSlider.HORIZONTAL, 0, 100, start_slider_value); cpu_slider.setMinorTickSpacing(10); cpu_slider.setMajorTickSpacing(20); cpu_slider.setPaintTicks(true); cpu_slider.setPaintLabels(true); cpu_slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider sourse = (JSlider)e.getSource(); if (sourse.getValueIsAdjusting()) { int i = (int)sourse.getValue(); if((i<=crit_slider_value)&&(a<=crit_slider_value)) a=i; if((i<=crit_slider_value)&&(a>crit_slider_value)) { WriteToFile("1 0","bypass.par"); a=i; } if((i>crit_slider_value)&&(a>crit_slider_value)) a=i; if((i>crit_slider_value)&&(a<=crit_slider_value)) { WriteToFile("1 1","bypass.par"); a=i; } } } }); cpu_slider.setAlignmentX(Component.CENTER_ALIGNMENT); nodeControlPanel.add(Box.createRigidArea(new Dimension(0,20))); nodeControlPanel.add(cpu_slider); nodeControlPanel.add(Box.createRigidArea(new Dimension(0,10))); p.add(nodeControlPanel); p.add(Box.createRigidArea(new Dimension(0,20))); JPanel applicationControlPanel = new JPanel(); applicationControlPanel.setBorder(bevel); applicationControlPanel.add(Box.createRigidArea(new Dimension(0,10))); applicationControlPanel.setLayout(new BoxLayout(applicationControlPanel, BoxLayout.Y_AXIS)); JLabel applicationControlLabel = new JLabel(" APPLICATION CONTROL ",JLabel.CENTER); applicationControlLabel.setForeground(label_color.getColor()); applicationControlLabel.setAlignmentX(Component.CENTER_ALIGNMENT); applicationControlPanel.add(applicationControlLabel); applicationControlPanel.add(Box.createRigidArea(new Dimension(0,20))); JLabel winLabel = new JLabel("Focus windows tracking",JLabel.CENTER); winLabel.setAlignmentX(Component.CENTER_ALIGNMENT); applicationControlPanel.add(winLabel); JRadioButton win1 = new JRadioButton("1st",false); win1.setActionCommand("WIN1"); win1.addActionListener(this); JRadioButton win2 = new JRadioButton("2nd",false); win2.setActionCommand("WIN2"); win2.addActionListener(this); JRadioButton win3 = new JRadioButton("3rd",false); win3.setActionCommand("WIN3"); win3.addActionListener(this); winGroup = new ButtonGroup(); winGroup.add(win1); winGroup.add(win2); winGroup.add(win3); JPanel winPanel = new JPanel(); winPanel.setLayout(new BoxLayout(winPanel, BoxLayout.X_AXIS)); winPanel.add(win1); winPanel.add(win2); winPanel.add(win3); // p.add(winPanel); applicationControlPanel.add(Box.createRigidArea(new Dimension(0,5))); JButton setWindowJButton = new JButton("Manual tracking"); applicationControlPanel.add(Box.createRigidArea(new Dimension(0,20))); setWindowJButton.addActionListener(this); setWindowJButton.setAlignmentX(Component.CENTER_ALIGNMENT); applicationControlPanel.add(setWindowJButton); JButton machWindowJButton = new JButton("Machine tracking"); applicationControlPanel.add(Box.createRigidArea(new Dimension(0,20))); machWindowJButton.addActionListener(this); machWindowJButton.setAlignmentX(Component.CENTER_ALIGNMENT); applicationControlPanel.add(machWindowJButton); JButton conWindowJButton = new JButton("Content tracking"); applicationControlPanel.add(Box.createRigidArea(new Dimension(0,20))); conWindowJButton.addActionListener(this); conWindowJButton.setAlignmentX(Component.CENTER_ALIGNMENT); applicationControlPanel.add(conWindowJButton); applicationControlPanel.add(Box.createRigidArea(new Dimension(0,20))); p.add(applicationControlPanel); p.add(Box.createRigidArea(new Dimension(0,40))); JButton exitButton = new JButton("Exit"); exitButton.addActionListener(this); exitButton.setAlignmentX(Component.CENTER_ALIGNMENT); p.add(exitButton); Container content = getContentPane(); content.setLayout(new GridBagLayout()); content.add(p); // pack(); validate(); } public void actionPerformed(ActionEvent e) { String choice = e.getActionCommand(); // System.out.println("" + choice); if(choice == "Exit") System.exit(0); if(choice == "Manual tracking") { // System.out.println("" + choice); SetWin sw = new SetWin(); sw.setSize(740+10,480+135); sw.setVisible(true); } if(choice == "WIN1") WriteToFile("1 10 10 50 50 9","adjustq"); if(choice == "WIN2") WriteToFile("1 10 10 50 50 9\n2 60 60 100 100 9","adjustq"); if(choice == "WIN3") WriteToFile("1 0 0 30 30 9\n2 60 60 100 100 9\n3 60 10 100 50 9","adjustq"); // System.out.println("" + choice); } public static void main(String args[]) { VControl vc = new VControl(); vc.setVisible(true); } public void WriteToFile(String fileContent,String fileName) { byte buffer[] = new byte[1000]; String str; int bytes=0; try { str = fileContent; // System.out.println(fileContent); // System.out.println(str); str.getBytes(0,str.length(),buffer,0); bytes=str.length(); FileOutputStream fileOut = new FileOutputStream(fileName); fileOut.write(buffer,0,bytes); } catch(Exception e){} } public class SetWin extends JFrame implements ActionListener, MouseListener, MouseMotionListener { private Border lowered; private Container content; JLabel win2_label; public SetWin() { super("Kent Sate Medianet Lab"); /* Color[] grays = new Color[21]; for(int i=-10; i<10; i++) grays[i]= new Color(i, i, i); */ label_color = new JColorChooser(wColor[11]); label_color = new JColorChooser(wColor[11]); label_color = new JColorChooser(wColor[11]); BevelBorder bevel = new BevelBorder(BevelBorder.LOWERED); JPanel butPanel = new JPanel(); butPanel.setLayout(new BoxLayout(butPanel, BoxLayout.X_AXIS)); JButton but1 = new JButton("Set 1st window"); but1.addActionListener(this); butPanel.add(but1); JButton but2 = new JButton("Set 2nd window"); but2.addActionListener(this); butPanel.add(but2); JButton but3 = new JButton("Set 3rd window"); but3.addActionListener(this); butPanel.add(but3); butPanel.add(Box.createRigidArea(new Dimension(200,0))); JButton exitButton = new JButton("Exit"); exitButton.addActionListener(this); butPanel.add(exitButton); winPanel = new DrawWin(); // winPanel.add(Box.createRigidArea(new Dimension(0,480))); // winPanel.setMaximumSize(new Dimension(740,480)); winPanel.addMouseListener(this); winPanel.addMouseMotionListener(this); winPanel.setBorder(bevel); JPanel exitPanel = new JPanel(); // exitPanel.setLayout(new BoxLayout(exitPanel, BoxLayout.Y_AXIS)); exitPanel.setLayout(new GridLayout(2,3,2,2)); JLabel win1_label = new JLabel("1st window quality value",JLabel.CENTER); label_color.setColor(Color.red); win1_label.setForeground(label_color.getColor()); exitPanel.add(win1_label); win2_label = new JLabel("2nd window quality value",JLabel.CENTER); label_color.setColor(Color.blue); win2_label.setForeground(label_color.getColor()); exitPanel.add(win2_label); JLabel win3_label = new JLabel("3rd window quality value",JLabel.CENTER); label_color.setColor(Color.yellow); win3_label.setForeground(label_color.getColor()); exitPanel.add(win3_label); win1_slider = new JSlider(JSlider.HORIZONTAL, -10, 10, 0); win1_slider.setMinorTickSpacing(1); win1_slider.setMajorTickSpacing(2); win1_slider.setPaintTicks(true); win1_slider.setPaintLabels(true); win1_slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider sourse = (JSlider)e.getSource(); if (sourse.getValueIsAdjusting()) { win1_slider_value = (int)sourse.getValue(); AdjustQ(); winPanel.repaint(); } } }); exitPanel.add(win1_slider); win2_slider = new JSlider(JSlider.HORIZONTAL, -10, 10, 0); win2_slider.setMinorTickSpacing(1); win2_slider.setMajorTickSpacing(2); win2_slider.setPaintTicks(true); win2_slider.setPaintLabels(true); win2_slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider sourse = (JSlider)e.getSource(); if (sourse.getValueIsAdjusting()) { win2_slider_value = (int)sourse.getValue(); AdjustQ(); winPanel.repaint(); } } }); exitPanel.add(win2_slider); win3_slider = new JSlider(JSlider.HORIZONTAL, -10, 10, 0); win3_slider.setMinorTickSpacing(1); win3_slider.setMajorTickSpacing(2); win3_slider.setPaintTicks(true); win3_slider.setPaintLabels(true); win3_slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider sourse = (JSlider)e.getSource(); if (sourse.getValueIsAdjusting()) { win3_slider_value = (int)sourse.getValue(); AdjustQ(); winPanel.repaint(); } } }); exitPanel.add(win3_slider); content = getContentPane(); // content.setLayout(new GridBagLayout()); // content.add(wJLabel); content.add(butPanel,BorderLayout.NORTH); content.add(winPanel, BorderLayout.CENTER); content.add(exitPanel,BorderLayout.SOUTH); validate(); } public void actionPerformed(ActionEvent e) { String choice = e.getActionCommand(); if(choice == "Set 1st window") { flagWin1 = true; flagWin2 = false; flagWin3 = false; x_r1=y_r1=x_l1=y_l1=0; win1_slider.setValue(0); win1_slider_value=0; winPanel.repaint(); } if(choice == "Set 2nd window") { flagWin2 = true; flagWin1 = false; flagWin3 = false; x_r2=y_r2=x_l2=y_l2=0; win2_slider_value=0; win2_slider.setValue(0); winPanel.repaint(); } if(choice == "Set 3rd window") { flagWin3 = true; flagWin1 = false; flagWin2 = false; x_r3=y_r3=x_l3=y_l3=0; win3_slider_value=0; win3_slider.setValue(0); winPanel.repaint(); } AdjustQ(); if(choice == "Exit") setVisible(false); } public void mousePressed(MouseEvent e) { x = e.getX(); y = e.getY(); if(flagWin1 == true) { xb1 = x1 = x_l1 = x_r1 = x; yb1 = y1 = y_l1 = y_r1 = y; } if(flagWin2 == true) { xb2 = x2 = x_l2 = x_r2 = x; yb2 = y2 = y_l2 = y_r2 = y; } if(flagWin3 == true) { xb3 = x3 = x_l3 = x_r3 = x; yb3 = y3 = y_l3 = y_r3 = y; } winPanel.repaint(); } public void mouseReleased(MouseEvent e) { AdjustQ(); } public void mouseEntered(MouseEvent e) { mouseInside = true; } public void mouseExited(MouseEvent e) { mouseInside = false; } public void mouseClicked(MouseEvent e) { } void saySomething(String eventDescription, MouseEvent e) { System.out.println(eventDescription + " detected on " + e.getComponent().getClass().getName() + "." + newline); } public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { x = e.getX(); y = e.getY(); if(mouseInside == true) { if(flagWin1 == true) { if(((x>xb1&&y>yb1)&&(x>x1&&y>y1))||((x>xb1&&y>yb1)&&(xxb1&&yx1&&yxb1&&yy1))) { x_r1 = x; y_l1 = y; } if(((xyb1)&&(xy1))||((xyb1)&&(x>x1&&yx1&&y>y1))) { x_l1 = x; y_l1 = y; } } if(flagWin2 == true) { if(((x>xb2&&y>yb2)&&(x>x2&&y>y2))||((x>xb2&&y>yb2)&&(xxb2&&yx2&&yxb2&&yy2))) { x_r2 = x; y_l2 = y; } if(((xyb2)&&(xy2))||((xyb2)&&(x>x2&&yx2&&y>y2))) { x_l2 = x; y_l2 = y; } } if(flagWin3 == true) { if(((x>xb3&&y>yb3)&&(x>x3&&y>y3))||((x>xb3&&y>yb3)&&(xxb3&&yx3&&yxb3&&yy3))) { x_r3 = x; y_l3 = y; } if(((xyb3)&&(xy3))||((xyb3)&&(x>x3&&yx3&&y>y3))) { x_l3 = x; y_l3 = y; } } } winPanel.repaint(); } void sayAnything(String eventDescription, MouseEvent e) { System.out.println(eventDescription + " (" + e.getX() + "," + e.getY() + ")" + " detected on " + e.getComponent().getClass().getName() + newline); } } public class DrawWin extends JPanel { public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; super.paint(g2); w = getSize().width; h = getSize().height; g2.setStroke(stroke); g2.setColor(wColor[3]); for(int i=0;i<10;i++) { g2.drawLine(0,i*h/10,w,i*h/10); g2.drawLine(i*w/10,0,i*w/10,h); g2.drawString(i+"0",i*w/10+5,h-5); int c = 10 - i; g2.drawString(c+"0",5,i*h/10-5); } // g2.drawString(i+"0",i*w/10+10,h-10); // g2.setColor(Color.red); // g2.drawRect(0,0,740,480); g2.setColor(wColor[win1_slider_value+10]); g2.fillRect(x_l1,y_l1,x_r1-x_l1,y_r1-y_l1); // g2.setColor(Color.red); // g2.drawRect(x_l1,y_l1,x_r1-x_l1,y_r1-y_l1); g2.setColor(wColor[win2_slider_value+10]); g2.fillRect(x_l2,y_l2,x_r2-x_l2,y_r2-y_l2); // g2.setColor(Color.blue); // g2.drawRect(x_l2,y_l2,x_r2-x_l2,y_r2-y_l2); g2.setColor(wColor[win3_slider_value+10]); g2.fillRect(x_l3,y_l3,x_r3-x_l3,y_r3-y_l3); // g2.setColor(Color.yellow); // g2.drawRect(x_l3,y_l3,x_r3-x_l3,y_r3-y_l3); g2.setColor(Color.red); g2.drawRect(x_l1,y_l1,x_r1-x_l1,y_r1-y_l1); g2.drawString((100*x_l1/w)+","+(99-(100*y_r1/h)),x_l1+5,y_r1-5); g2.drawString((100*x_r1/w)+","+(99-(100*y_l1/h)),x_r1-37,y_l1+12); g2.setColor(Color.blue); g2.drawRect(x_l2,y_l2,x_r2-x_l2,y_r2-y_l2); g2.drawString((100*x_l2/w)+","+(99-(100*y_r2/h)),x_l2+5,y_r2-5); g2.drawString((100*x_r2/w)+","+(99-(100*y_l2/h)),x_r2-37,y_l2+12); g2.setColor(Color.yellow); g2.drawRect(x_l3,y_l3,x_r3-x_l3,y_r3-y_l3); g2.drawString((100*x_l3/w)+","+(99-(100*y_r3/h)),x_l3+5,y_r3-5); g2.drawString((100*x_r3/w)+","+(99-(100*y_l3/h)),x_r3-37,y_l3+12); g2.setStroke(dashed); g2.setColor(Color.red); g2.drawLine(x_l1+(x_r1-x_l1)/2,y_l1,x_l1+(x_r1-x_l1)/2,y_r1); g2.drawLine(x_l1,y_l1+(y_r1-y_l1)/2,x_r1,y_l1+(y_r1-y_l1)/2); g2.setColor(Color.blue); g2.drawLine(x_l2+(x_r2-x_l2)/2,y_l2,x_l2+(x_r2-x_l2)/2,y_r2); g2.drawLine(x_l2,y_l2+(y_r2-y_l2)/2,x_r2,y_l2+(y_r2-y_l2)/2); g2.setColor(Color.yellow); g2.drawLine(x_l3+(x_r3-x_l3)/2,y_l3,x_l3+(x_r3-x_l3)/2,y_r3); g2.drawLine(x_l3,y_l3+(y_r3-y_l3)/2,x_r3,y_l3+(y_r3-y_l3)/2); } public void update() { repaint(); } } //Cursor.getPredefinedCursor(); public void AdjustQ() { int x_l, y_l, x_r, y_r; x_l=(int)100.0*x_l1/w; y_l=(int)100.0*y_l1/h; x_r=(int)100.0*x_r1/w; y_r=(int)100.0*y_r1/h; win1_str = "1 " + x_l + " " + y_l + " " + x_r + " " + y_r + " " + win1_slider_value; x_l=(int)100.0*x_l2/w; y_l=(int)100.0*y_l2/h; x_r=(int)100.0*x_r2/w; y_r=(int)100.0*y_r2/h; win2_str = "2 " + x_l + " " + y_l + " " + x_r + " " + y_r + " " + win2_slider_value; x_l=(int)100.0*x_l3/w; y_l=(int)100.0*y_l3/h; x_r=(int)100.0*x_r3/w; y_r=(int)100.0*y_r3/h; win3_str = "3 " + x_l + " " + y_l + " " + x_r + " " + y_r + " " + win3_slider_value; String win_str = win1_str + "\n" + win2_str + "\n" + win3_str; WriteToFile(win_str,"adjustq"); } }