Example usage for javax.swing SwingWorker execute

List of usage examples for javax.swing SwingWorker execute

Introduction

In this page you can find the example usage for javax.swing SwingWorker execute.

Prototype

public final void execute() 

Source Link

Document

Schedules this SwingWorker for execution on a worker thread.

Usage

From source file:com.xilinx.virtex7.MainScreen.java

private JPanel testPanelItems2() {
    JPanel panel = new JPanel();
    panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    /*panel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Test Parameters-1"),
                BorderFactory.createEmptyBorder()));*/
    float w = (float) ((float) width * 0.4);
    //panel.setPreferredSize(new Dimension((int)w, 100));
    panel.add(new JLabel("Data Path-2:"));
    t3_o1 = new JCheckBox("Loopback");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t3_o1.setToolTipText("This loops back software generated traffic at DMA user interface");
    else if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV)
        t3_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY");

    t3_o1.setSelected(true);/*from  w  w  w .  j a v a 2s .  c o  m*/
    t3_o1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                t3_o1.setSelected(true);
                return;
            }
            if (t3_o1.isSelected()) {
                // disable others
                test3_option = DriverInfo.ENABLE_LOOPBACK;
                t3_o2.setSelected(false);
                t3_o3.setSelected(false);
            } else {
                if (!t3_o2.isSelected() && !t3_o3.isSelected()) {
                    test3_option = DriverInfo.CHECKER;
                    t3_o2.setSelected(true);
                }
            }
        }
    });
    //b1.setSelected(true);
    t3_o2 = new JCheckBox("HW Checker");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t3_o2.setToolTipText(
                "This enables Checker in hardware at DMA user interface verifying traffic generated by software");
    t3_o2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t3_o2.isSelected()) {
                // disable others
                test3_option = DriverInfo.CHECKER;
                t3_o1.setSelected(false);
                //t2_o3.setSelected(false);
                if (t3_o3.isSelected())
                    test3_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t3_o3.isSelected())
                    test3_option = DriverInfo.GENERATOR;
                else {
                    test3_option = DriverInfo.ENABLE_LOOPBACK;
                    t3_o1.setSelected(true);
                }
            }
        }
    });
    //b2.setEnabled(false);
    t3_o3 = new JCheckBox("HW Generator");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t3_o3.setToolTipText("This enables traffic generator in hardware at the DMA user interface");
    t3_o3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t3_o3.isSelected()) {
                // disable others
                test3_option = DriverInfo.GENERATOR;
                t3_o1.setSelected(false);
                //t2_o2.setSelected(false);
                if (t3_o2.isSelected())
                    test3_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t3_o2.isSelected())
                    test3_option = DriverInfo.CHECKER;
                else {
                    test3_option = DriverInfo.ENABLE_LOOPBACK;
                    t3_o1.setSelected(true);
                }
            }
        }
    });
    //b3.setEnabled(false);
    JPanel ip = new JPanel();
    ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS));
    ip.add(t3_o1);
    ip.add(t3_o2);
    ip.add(t3_o3);
    panel.add(ip);
    panel.add(new JLabel("Packet Size (bytes):"));
    t3_psize = new JTextField("32768", 5);
    panel.add(t3_psize);
    s3test = new JButton("Start");
    //s3test.setEnabled(false);
    s3test.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            //Check for led status and start the test
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy2 == LED_ON && lstats.phy3 == LED_ON)) {
                    JOptionPane.showMessageDialog(null, "DDR3 is not calibrated. Test cannot be started",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy2 == LED_OFF || lstats.phy3 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 is not calibrated and 10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON
                        && (lstats.phy2 == LED_OFF || lstats.phy3 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            if (s3test.getText().equals("Start")) {
                int psize = 0;
                dataMismatch4 = errcnt2 = false;
                try {
                    psize = Integer.parseInt(t3_psize.getText());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Only Natural numbers are allowed", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (psize < minpkt1 || psize > maxpkt1) {
                    JOptionPane.showMessageDialog(null,
                            "Packet size must be within " + minpkt1 + " to " + maxpkt1 + " bytes", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                di.startTest(2, test3_option, psize);
                t3_o1.setEnabled(false);
                t3_o2.setEnabled(false);
                t3_o3.setEnabled(false);
                t3_psize.setEnabled(false);
                s3test.setText("Stop");
                testStarted2 = true;
                updateLog("[Test Started for Data Path-2]", logStatus);

            } else if (s3test.getText().equals("Stop")) {
                // Disable button to avoid multiple clicks
                s3test.setEnabled(false);
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            stopTest3();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                };
                worker.execute();
            }
        }
    });
    panel.add(s3test);
    if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) {
        t3_o1.setSelected(false);
        t3_o2.setSelected(false);
        t3_o3.setSelected(false);
        t3_o1.setEnabled(false);
        t3_o2.setEnabled(false);
        t3_o3.setEnabled(false);
        t3_psize.setEnabled(false);
        t3_psize.setText("");
        s3test.setEnabled(false);
    }
    return panel;
}

From source file:com.xilinx.virtex7.MainScreen.java

private JPanel testPanelItems1() {
    JPanel panel = new JPanel();
    panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    /*panel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Test Parameters-1"),
                BorderFactory.createEmptyBorder()));*/
    float w = (float) ((float) width * 0.4);
    //panel.setPreferredSize(new Dimension((int)w, 100));
    panel.add(new JLabel("Data Path-1:"));
    t2_o1 = new JCheckBox("Loopback");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t2_o1.setToolTipText("This loops back software generated traffic at DMA user interface");
    else if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV)
        t2_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY");

    t2_o1.setSelected(true);//  w  ww  . j  a  va  2 s .co m
    t2_o1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                t2_o1.setSelected(true);
                return;
            }
            if (t2_o1.isSelected()) {
                // disable others
                test2_option = DriverInfo.ENABLE_LOOPBACK;
                t2_o2.setSelected(false);
                t2_o3.setSelected(false);
            } else {
                if (!t2_o2.isSelected() && !t2_o3.isSelected()) {
                    test2_option = DriverInfo.CHECKER;
                    t2_o2.setSelected(true);
                }
            }
        }
    });
    //b1.setSelected(true);
    t2_o2 = new JCheckBox("HW Checker");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t2_o2.setToolTipText(
                "This enables Checker in hardware at DMA user interface verifying traffic generated by software");
    t2_o2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t2_o2.isSelected()) {
                // disable others
                test2_option = DriverInfo.CHECKER;
                t2_o1.setSelected(false);
                //t2_o3.setSelected(false);
                if (t2_o3.isSelected())
                    test2_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t2_o3.isSelected())
                    test2_option = DriverInfo.GENERATOR;
                else {
                    test2_option = DriverInfo.ENABLE_LOOPBACK;
                    t2_o1.setSelected(true);
                }
            }
        }
    });
    //b2.setEnabled(false);
    t2_o3 = new JCheckBox("HW Generator");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t2_o3.setToolTipText("This enables traffic generator in hardware at the DMA user interface");
    t2_o3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t2_o3.isSelected()) {
                // disable others
                test2_option = DriverInfo.GENERATOR;
                t2_o1.setSelected(false);
                //t2_o2.setSelected(false);
                if (t2_o2.isSelected())
                    test2_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t2_o2.isSelected())
                    test2_option = DriverInfo.CHECKER;
                else {
                    test2_option = DriverInfo.ENABLE_LOOPBACK;
                    t2_o1.setSelected(true);
                }
            }
        }
    });
    //b3.setEnabled(false);
    JPanel ip = new JPanel();
    ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS));
    ip.add(t2_o1);
    ip.add(t2_o2);
    ip.add(t2_o3);
    panel.add(ip);
    panel.add(new JLabel("Packet Size (bytes):"));
    t2_psize = new JTextField("32768", 5);
    panel.add(t2_psize);
    stest = new JButton("Start");
    if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {

    } else
        stest.setEnabled(false);
    stest.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            //Check for led status and start the test
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_ON && lstats.phy1 == LED_ON)) {
                    JOptionPane.showMessageDialog(null, "DDR3 is not calibrated. Test cannot be started",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 is not calibrated and 10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            if (stest.getText().equals("Start")) {
                int psize = 0;
                dataMismatch2 = errcnt1 = false;
                try {
                    psize = Integer.parseInt(t2_psize.getText());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Only Natural numbers are allowed", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (psize < minpkt1 || psize > maxpkt1) {
                    JOptionPane.showMessageDialog(null,
                            "Packet size must be within " + minpkt1 + " to " + maxpkt1 + " bytes", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                di.startTest(1, test2_option, psize);
                t2_o1.setEnabled(false);
                t2_o2.setEnabled(false);
                t2_o3.setEnabled(false);
                t2_psize.setEnabled(false);
                stest.setText("Stop");
                testStarted1 = true;
                updateLog("[Test Started for Data Path-1]", logStatus);

            } else if (stest.getText().equals("Stop")) {
                // Disable button to avoid multiple clicks
                stest.setEnabled(false);
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            stopTest2();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                };
                worker.execute();
            }
        }
    });
    panel.add(stest);
    if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) {
        t2_o1.setSelected(false);
        t2_o2.setSelected(false);
        t2_o3.setSelected(false);
        t2_o1.setEnabled(false);
        t2_o2.setEnabled(false);
        t2_o3.setEnabled(false);
        t2_psize.setEnabled(false);
        t2_psize.setText("");
        stest.setEnabled(false);
    }
    return panel;
}

From source file:com.xilinx.virtex7.MainScreen.java

private JPanel testPanelItems3() {
    JPanel panel = new JPanel();
    panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    /*panel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Test Parameters-1"),
                BorderFactory.createEmptyBorder()));*/
    float w = (float) ((float) width * 0.4);
    //panel.setPreferredSize(new Dimension((int)w, 100));
    panel.add(new JLabel("Data Path-3:"));
    t4_o1 = new JCheckBox("Loopback");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t4_o1.setToolTipText("This loops back software generated traffic at DMA user interface");
    else if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV)
        t4_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY");

    t4_o1.setSelected(true);/*  ww  w.j av a  2 s. co  m*/
    t4_o1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                t4_o1.setSelected(true);
                return;
            }
            if (t4_o1.isSelected()) {
                // disable others
                test4_option = DriverInfo.ENABLE_LOOPBACK;
                t4_o2.setSelected(false);
                t4_o3.setSelected(false);
            } else {
                if (!t4_o2.isSelected() && !t4_o3.isSelected()) {
                    test4_option = DriverInfo.CHECKER;
                    t4_o2.setSelected(true);
                }
            }
        }
    });
    //b1.setSelected(true);
    t4_o2 = new JCheckBox("HW Checker");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t4_o2.setToolTipText(
                "This enables Checker in hardware at DMA user interface verifying traffic generated by software");
    t4_o2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t4_o2.isSelected()) {
                // disable others
                test4_option = DriverInfo.CHECKER;
                t4_o1.setSelected(false);
                //t2_o3.setSelected(false);
                if (t4_o3.isSelected())
                    test4_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t4_o3.isSelected())
                    test4_option = DriverInfo.GENERATOR;
                else {
                    test4_option = DriverInfo.ENABLE_LOOPBACK;
                    t4_o1.setSelected(true);
                }
            }
        }
    });
    //b2.setEnabled(false);
    t4_o3 = new JCheckBox("HW Generator");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t4_o3.setToolTipText("This enables traffic generator in hardware at the DMA user interface");
    t4_o3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t4_o3.isSelected()) {
                // disable others
                test4_option = DriverInfo.GENERATOR;
                t4_o1.setSelected(false);
                //t2_o2.setSelected(false);
                if (t4_o2.isSelected())
                    test4_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t4_o2.isSelected())
                    test4_option = DriverInfo.CHECKER;
                else {
                    test4_option = DriverInfo.ENABLE_LOOPBACK;
                    t4_o1.setSelected(true);
                }
            }
        }
    });
    //b3.setEnabled(false);
    JPanel ip = new JPanel();
    ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS));
    ip.add(t4_o1);
    ip.add(t4_o2);
    ip.add(t4_o3);
    panel.add(ip);
    panel.add(new JLabel("Packet Size (bytes):"));
    t4_psize = new JTextField("32768", 5);
    panel.add(t4_psize);
    s4test = new JButton("Start");
    if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {

    } else
        stest.setEnabled(false);
    s4test.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            //Check for led status and start the test
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy2 == LED_ON && lstats.phy3 == LED_ON)) {
                    JOptionPane.showMessageDialog(null, "DDR3 is not calibrated. Test cannot be started",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy2 == LED_OFF || lstats.phy3 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 is not calibrated and 10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON
                        && (lstats.phy2 == LED_OFF || lstats.phy3 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            if (s4test.getText().equals("Start")) {
                int psize = 0;
                dataMismatch6 = errcnt3 = false;
                try {
                    psize = Integer.parseInt(t4_psize.getText());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Only Natural numbers are allowed", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (psize < minpkt1 || psize > maxpkt1) {
                    JOptionPane.showMessageDialog(null,
                            "Packet size must be within " + minpkt1 + " to " + maxpkt1 + " bytes", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                di.startTest(3, test4_option, psize);
                t4_o1.setEnabled(false);
                t4_o2.setEnabled(false);
                t4_o3.setEnabled(false);
                t4_o2.setEnabled(false);
                t4_psize.setEnabled(false);
                s4test.setText("Stop");
                testStarted3 = true;
                updateLog("[Test Started for Data Path-3]", logStatus);

            } else if (s4test.getText().equals("Stop")) {
                // Disable button to avoid multiple clicks
                s4test.setEnabled(false);
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            stopTest4();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                };
                worker.execute();
            }
        }
    });
    panel.add(s4test);
    if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) {
        t4_o1.setSelected(false);
        t4_o2.setSelected(false);
        t4_o3.setSelected(false);
        t4_o1.setEnabled(false);
        t4_o2.setEnabled(false);
        t4_o3.setEnabled(false);
        t4_psize.setEnabled(false);
        t4_psize.setText("");
        s4test.setEnabled(false);
    }
    return panel;
}

From source file:com.xilinx.virtex7.MainScreen.java

private JPanel testPanelItems() {
    //JPanel panel1 = new JPanel();

    JPanel panel = new JPanel();

    panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

    panel.add(new JLabel("Data Path-0:"));
    t1_o1 = new JCheckBox("Loopback");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t1_o1.setToolTipText("This loops back software generated traffic in hardware");
    else if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV)
        t1_o1.setToolTipText("This loops back software generated raw Ethernet frames at 10G PHY");

    t1_o1.setSelected(true);/*  w  ww  . java 2  s  .  co m*/
    t1_o1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                t1_o1.setSelected(true);
                return;
            }
            if (t1_o1.isSelected()) {
                // disable others
                test1_option = DriverInfo.ENABLE_LOOPBACK;
                t1_o2.setSelected(false);
                t1_o3.setSelected(false);
            } else {
                if (!t1_o2.isSelected() && !t1_o3.isSelected()) {
                    test1_option = DriverInfo.CHECKER;
                    t1_o2.setSelected(true);
                }
            }
        }
    });
    //b1.setSelected(true);
    t1_o2 = new JCheckBox("HW Checker");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t1_o2.setToolTipText("This enables Checker in hardware verifying traffic generated by software");
    t1_o2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t1_o2.isSelected()) {
                // disable others
                test1_option = DriverInfo.CHECKER;
                t1_o1.setSelected(false);
                //t1_o3.setSelected(false);
                if (t1_o3.isSelected())
                    test1_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t1_o3.isSelected())
                    test1_option = DriverInfo.GENERATOR;
                else {
                    test1_option = DriverInfo.ENABLE_LOOPBACK;
                    t1_o1.setSelected(true);
                }

            }
        }
    });
    //b2.setEnabled(false);
    t1_o3 = new JCheckBox("HW Generator");
    if (mode == LandingPage.PERFORMANCE_MODE_GENCHK || mode == LandingPage.PERFORMANCE_MODE_GENCHK_DV)
        t1_o3.setToolTipText("This enables traffic generator in hardware");
    t1_o3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            if (t1_o3.isSelected()) {
                // disable others
                test1_option = DriverInfo.GENERATOR;
                t1_o1.setSelected(false);
                //t1_o2.setSelected(false);
                if (t1_o2.isSelected())
                    test1_option = DriverInfo.CHECKER_GEN;
            } else {
                if (t1_o2.isSelected())
                    test1_option = DriverInfo.CHECKER;
                else {
                    test1_option = DriverInfo.ENABLE_LOOPBACK;
                    t1_o1.setSelected(true);
                }
            }
        }
    });
    //b3.setEnabled(false);
    JPanel ip = new JPanel();
    ip.setLayout(new BoxLayout(ip, BoxLayout.PAGE_AXIS));
    ip.add(t1_o1);
    ip.add(t1_o2);
    ip.add(t1_o3);
    panel.add(ip);
    panel.add(new JLabel("Packet Size (bytes):"));
    t1_psize = new JTextField("32768", 5);

    panel.add(t1_psize);
    startTest = new JButton("Start");
    startTest.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            //Check for led status and start the test
            if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) {
                if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_ON && lstats.phy1 == LED_ON)) {
                    JOptionPane.showMessageDialog(null, "DDR3 is not calibrated. Test cannot be started",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_OFF && lstats.ddrCalib2 == LED_OFF
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 is not calibrated and 10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON
                        && (lstats.phy0 == LED_OFF || lstats.phy1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null, "10G-PHY link is down. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            if (startTest.getText().equals("Start")) {
                // checking condition for DDR3 SODIMM
                if (t1_o1.isSelected() && !(lstats.ddrCalib1 == LED_ON && lstats.ddrCalib2 == LED_ON)) {
                    if (lstats.ddrCalib1 == LED_OFF || lstats.ddrCalib2 == LED_OFF) {
                        JOptionPane.showMessageDialog(null,
                                "DDR3 SODIMM is not calibrated. Test cannot be started", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    }
                    return;
                } else if (t1_o2.isSelected() && (lstats.ddrCalib1 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 SODIMM-A is not calibrated. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                } else if (t1_o3.isSelected() && (lstats.ddrCalib2 == LED_OFF)) {
                    JOptionPane.showMessageDialog(null,
                            "DDR3 SODIMM-B is not calibrated. Test cannot be started", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                int psize = 0;
                dataMismatch0 = errcnt0 = false;
                try {
                    psize = Integer.parseInt(t1_psize.getText());
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Only Natural numbers are allowed", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (psize < minpkt0 || psize > maxpkt0) {
                    JOptionPane.showMessageDialog(null,
                            "Packet size must be within " + minpkt0 + " to " + maxpkt0 + " bytes", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
                di.startTest(0, test1_option, psize);
                // disable components
                t1_o1.setEnabled(false);
                t1_o2.setEnabled(false);
                t1_o3.setEnabled(false);
                t1_psize.setEnabled(false);
                startTest.setText("Stop");
                testStarted = true;
                updateLog("[Test Started for Data Path-0]", logStatus);
            } else if (startTest.getText().equals("Stop")) {
                startTest.setEnabled(false);
                SwingWorker worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            stopTest1();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                };
                worker.execute();
            }
        }
    });
    panel.add(startTest);
    if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) {
        t1_o1.setSelected(false);
        t1_o2.setSelected(false);
        t1_o3.setSelected(false);
        t1_o1.setEnabled(false);
        t1_o2.setEnabled(false);
        t1_o3.setEnabled(false);
        t1_psize.setEnabled(false);
        t1_psize.setText("");
        startTest.setEnabled(false);
    }
    //panel1.add(panel);
    return panel;
}

From source file:com.hammurapi.jcapture.CaptureFrame.java

protected void capture() throws Exception {
    try {/*from   w  w  w . j  av a 2s  .  c o  m*/
        Thread.sleep(200); // For Ubuntu.
    } catch (InterruptedException ie) {
        // Ignore
    }

    BufferedImage screenShot = captureConfig.createScreenShot(null, null).call().getRegions().get(0).getImage()
            .getImage();

    String prefix = getDatePrefix();

    String defaultImageFormat = applet.getParameter("imageFormat");
    if (defaultImageFormat == null || defaultImageFormat.trim().length() == 0) {
        defaultImageFormat = "PNG";
    }
    final String defaultFileExtension = defaultImageFormat.toLowerCase();

    final String fileName = JOptionPane.showInputDialog(CaptureFrame.this, "Upload as",
            applet.getParameter("pageName") + "-capture-" + prefix + "-" + nextCounter() + "."
                    + defaultFileExtension);
    if (fileName != null) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int idx = fileName.lastIndexOf('.');
            String imageFormat = idx == -1 ? defaultImageFormat : fileName.substring(idx + 1).toUpperCase();
            ImageIO.write(screenShot, imageFormat, baos);
            final byte[] imageBytes = baos.toByteArray();
            System.out.println("Image size: " + imageBytes.length);
            // Uploading
            SwingWorker<Boolean, Long> task = new SwingWorker<Boolean, Long>() {

                @Override
                protected Boolean doInBackground() throws Exception {

                    System.out.println("Uploading in background");
                    try {
                        HttpResponse iResponse = applet.post(CaptureFrame.this,
                                new ByteArrayInputStream(imageBytes), imageBytes.length, fileName,
                                "application/octet-stream");

                        System.out.println("Response status line: " + iResponse.getStatusLine());
                        if (iResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                            errorMessage = iResponse.getStatusLine();
                            errorTitle = "Error saving image";
                            return false;
                        }
                        return true;
                    } catch (Error e) {
                        errorMessage = e.toString();
                        errorTitle = "Upload error";
                        e.printStackTrace();
                        return false;
                    }
                }

                private Object errorMessage;
                private String errorTitle;

                protected void done() {
                    try {
                        if (get()) {
                            JSObject window = JSObject.getWindow(applet);
                            String toEval = "insertAtCarret('" + applet.getParameter("edid") + "','{{:"
                                    + fileName + "|}}')";
                            System.out.println("Evaluating: " + toEval);
                            window.eval(toEval);
                            CaptureFrame.this.setVisible(false);
                        } else {
                            JOptionPane.showMessageDialog(CaptureFrame.this, errorMessage, errorTitle,
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(CaptureFrame.this, e.toString(), "Exception",
                                JOptionPane.ERROR_MESSAGE);
                    }
                };

            };

            task.execute();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(applet, ex.toString(), "Error saving image",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java

private JButton getLimpiar() {
    JButton jButton = new JButton(LogicConstants.getIcon("button_limpiar"));
    jButton.setText("Limpiar");
    jButton.addActionListener(new ActionListener() {

        @Override/*w w  w .j  av  a2s  . co m*/
        public void actionPerformed(ActionEvent e) {

            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

                @Override
                protected Object doInBackground() throws Exception {
                    clearRecursos();
                    clearIncidencias();
                    cleanLayers();
                    if (visorHistorico != null) {
                        visorHistorico.updateControls();
                    }

                    return null;
                }

                @Override
                protected void done() {

                    HistoryMapViewer.enableSaveGpx(false);
                    HistoryMapViewer.getResultadoHistoricos().setSelected(false);

                    recursos.setSelectedIndex(-1);
                    incidencias.setSelectedIndex(-1);
                    // zona.setSelectedIndex(-1);

                    final Calendar instance = Calendar.getInstance();
                    calendarini.setDate(instance.getTime());
                    calendarfin.setDate(instance.getTime());

                    horafin.setValue(instance.getTime());
                    instance.set(Calendar.HOUR_OF_DAY, 0);
                    instance.set(Calendar.MINUTE, 0);
                    instance.set(Calendar.SECOND, 0);
                    horaini.setValue(instance.getTime());

                    soloUltimas.setSelected(false);
                    calendarini.setEnabled(true);
                    calendarfin.setEnabled(true);
                    horaini.setEnabled(true);
                    horafin.setEnabled(true);

                    consultar.setEnabled(false);
                    limpiar.setEnabled(false);
                    setError("");
                }
            };
            sw.execute();

        }
    });
    return jButton;
}

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java

/**
 * //from   w  w w  .  j  a v a2 s.c o  m
 */
private void importSchema(final boolean doLocalization) {
    FileDialog fileDlg = new FileDialog((Dialog) null);
    fileDlg.setTitle(getResourceString(doLocalization ? SL_CHS_LOC : SL_CHS_IMP));
    UIHelper.centerAndShow(fileDlg);

    String fileName = fileDlg.getFile();
    if (StringUtils.isNotEmpty(fileName)) {
        String title = getResourceString(doLocalization ? "SL_L10N_SCHEMA" : "SL_IMPORT_SCHEMA");

        final File file = new File(fileDlg.getDirectory() + File.separator + fileName);
        final SimpleGlassPane glassPane = new SimpleGlassPane(title, 18);
        glassPane.setBarHeight(12);
        glassPane.setFillColor(new Color(0, 0, 0, 85));

        setGlassPane(glassPane);
        glassPane.setVisible(true);

        SwingWorker<Integer, Integer> importWorker = new SwingWorker<Integer, Integer>() {
            private boolean isOK = false;

            @Override
            protected Integer doInBackground() throws Exception {
                DataProviderSessionIFace localSession = null;
                try {
                    localSession = DataProviderFactory.getInstance().createSession();

                    localSession.beginTransaction();

                    BuildSampleDatabase bsd = new BuildSampleDatabase();

                    Discipline discipline = localSession.get(Discipline.class,
                            AppContextMgr.getInstance().getClassObject(Discipline.class).getId());

                    isOK = bsd.loadSchemaLocalization(discipline, schemaType, DBTableIdMgr.getInstance(), null, //catFmtName,
                            null, //accFmtName,
                            doLocalization ? UpdateType.eLocalize : UpdateType.eImport, // isDoingUpdate
                            file, // external file
                            glassPane, localSession);
                    if (isOK) {
                        localSession.commit();
                    } else {
                        localSession.rollback();
                    }

                } catch (Exception ex) {
                    ex.printStackTrace();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BuildSampleDatabase.class, ex);

                } finally {
                    if (localSession != null) {
                        localSession.close();
                    }
                }

                return null;
            }

            @Override
            protected void done() {
                super.done();

                glassPane.setVisible(false);

                if (isOK) {
                    UIRegistry.showLocalizedMsg("Specify.ABT_EXIT");
                    CommandDispatcher.dispatch(new CommandAction("App", "AppReqExit"));
                }
            }
        };
        importWorker.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(final PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("progress")) {
                    glassPane.setProgress((Integer) evt.getNewValue());
                }
            }
        });
        importWorker.execute();
    }
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeographyAssignISOs.java

private void calcGeoStats() {
    synchronized (this) {
        if (blockStatsUpdates)
            return;

        if (allCountriesRB.isSelected()) {
            if (!countriesCBX.isSelected()) {
                countriesTotalLabel.setText("");
                statesTotalLabel.setText("");
                return;
            }/*from  w  w w .  jav  a2  s  .c o m*/
            if (!stateCBX.isSelected()) {
                statesTotalLabel.setText("");
            }
        } else {
            if (spCountriesCmbx.getSelectedIndex() < 1) {
                countriesTotalLabel.setText("");
                statesTotalLabel.setText("");
                return;
            }
            if (!spStatesCBX.isSelected()) {
                statesTotalLabel.setText("");
            }
        }

        SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
            Integer totalCountries = null;
            Integer totalStates = null;

            @Override
            protected Object doInBackground() throws Exception {
                boolean isAll = allCountriesRB.isSelected();
                int selInx = spCountriesCmbx.getSelectedIndex();

                String base = "SELECT COUNT(*) FROM geography WHERE GeographyCode IS NULL";

                totalCountries = (!isAll && selInx < 1) ? null
                        : getCountAsInt(base + " AND RankID = 200"
                                + (isAll ? "" : " AND GeographyID = " + countryIds.get(selInx)));

                if ((isAll && stateCBX.isSelected()) || (!isAll && spStatesCBX.isSelected())) {
                    String sql = base + " AND RankID = 300";
                    if (!isAll) {
                        sql += " AND ParentID = " + countryIds.get(selInx);
                    }
                    totalStates = getCountAsInt(sql);
                }
                return null;
            }

            @Override
            protected void done() {
                if (totalCountries != null) {
                    countriesTotalLabel.setText(totalCountries.toString());
                }
                if (totalStates != null) {
                    statesTotalLabel.setText(totalStates.toString());
                }
            }
        };
        worker.execute();
    }
}

From source file:com.mirth.connect.client.ui.LibraryResourcesPanel.java

public void initialize() {
    final String workingId = PlatformUI.MIRTH_FRAME.startWorking("Loading library resources...");

    SwingWorker<List<LibraryProperties>, Void> worker = new SwingWorker<List<LibraryProperties>, Void>() {

        @Override//w ww.j  a va  2 s .c o m
        public List<LibraryProperties> doInBackground() throws ClientException {
            List<ResourceProperties> resourceProperties = PlatformUI.MIRTH_FRAME.mirthClient.getResources();
            List<LibraryProperties> libraryProperties = new ArrayList<LibraryProperties>();
            for (ResourceProperties resource : resourceProperties) {
                if (resource instanceof LibraryProperties) {
                    libraryProperties.add((LibraryProperties) resource);
                }
            }
            return libraryProperties;
        }

        @Override
        public void done() {
            try {
                List<LibraryProperties> resources = get();
                if (resources == null) {
                    resources = new ArrayList<LibraryProperties>();
                }

                Object[][] data = new Object[resources.size()][3];
                int i = 0;

                for (LibraryProperties properties : resources) {
                    data[i][SELECTED_COLUMN] = null;
                    data[i][PROPERTIES_COLUMN] = properties;
                    data[i][TYPE_COLUMN] = properties.getType();
                    i++;

                    for (Map<String, String> resourceIds : selectedResourceIds.values()) {
                        if (resourceIds.containsKey(properties.getId())) {
                            resourceIds.put(properties.getId(), properties.getName());
                        }
                    }
                }

                ((RefreshTableModel) resourceTable.getModel()).refreshDataVector(data);

                treeTable.getSelectionModel().setSelectionInterval(0, 0);
                treeTable.getTreeSelectionModel().setSelectionPath(treeTable.getPathForRow(0));
                parent.resourcesReady();
            } catch (Throwable t) {
                if (t instanceof ExecutionException) {
                    t = t.getCause();
                }
                PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, t,
                        "Error loading library resources: " + t.toString());
            } finally {
                PlatformUI.MIRTH_FRAME.stopWorking(workingId);
            }
        }
    };

    worker.execute();
}

From source file:edu.ku.brc.specify.tasks.CleanupToolsTask.java

/**
 * /*www. j av a  2s  .c  o m*/
 */
private void updateNames(final Vector<AgentNameCleanupParserDlg.DataItem> dataItemsList) {
    final String PRC = "PROCESS";
    final SimpleGlassPane glassPane = UIRegistry.writeSimpleGlassPaneMsg("Processing agents...", 24);

    //prgDlg = new ProgressDialog(getResourceString("CLNUP_AG_PRG_TITLE"), true, false);
    //prgDlg.getProcessProgress().setIndeterminate(true);
    //prgDlg.setDesc(getResourceString("CLNUP_AG_INIT_MSG"));
    //UIHelper.centerAndShow(prgDlg);

    final SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
        double tot = 0; // 1 -> 100
        double step = 1.0;
        int cnt = 0;

        @Override
        protected Object doInBackground() throws Exception {
            step = 100.0 / dataItemsList.size();

            Connection conn = null;
            PreparedStatement pStmt = null;
            try {
                String sql = "UPDATE agent SET LastName=?, FirstName=?,MiddleInitial=? WHERE AgentID = ?";
                conn = DBConnection.getInstance().createConnection();
                pStmt = conn.prepareStatement(sql);

                for (DataItem di : dataItemsList) {
                    if (di.isIncluded()) {
                        setColumn(pStmt, 1, di.getLastName());
                        setColumn(pStmt, 2, di.getFirstName());
                        setColumn(pStmt, 3, di.getMidName());
                        pStmt.setInt(4, di.getAgentId());

                        if (pStmt.executeUpdate() != 1) {
                            log.error(String.format("Error updating AgentID %d", di.getAgentId()));
                        }
                    }

                    tot += step;
                    if (((int) tot) > cnt) {
                        cnt = (int) tot;
                        firePropertyChange(PRC, -1, cnt);
                    }
                }
                dataItemsList.clear();

            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (pStmt != null)
                        pStmt.close();
                    if (conn != null)
                        conn.close();

                } catch (SQLException ex) {
                }
            }
            return null;
        }

        @Override
        protected void done() {
            UIRegistry.clearSimpleGlassPaneMsg();
            UIRegistry.showLocalizedMsg("Done.");
        }
    };
    worker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (PRC.equals(evt.getPropertyName())) {
                glassPane.setProgress((Integer) evt.getNewValue());
            }
        }
    });
    worker.execute();
}