Beispiel #1
0
  // Remove a test case from testBox and tests array.
  private void removeTest() {

    // Make sure they want to remove the checked tests.
    String message = "Are you sure you would like to remove the selected tests?";
    int decision =
        JOptionPane.showConfirmDialog(null, message, "Remove", JOptionPane.OK_CANCEL_OPTION);

    // If they definitely do want to remove.
    if (decision == JOptionPane.OK_OPTION) {

      // Make array list copy, so as to avoid index errors.
      ArrayList<JCheckBox> newTests = (ArrayList<JCheckBox>) tests.clone();
      int removed = 0;

      for (int i = 0; i < tests.size(); i++) {
        if (tests.get(i).isSelected()) {
          // Remove from the tests copy.
          newTests.remove(i - removed);
          // Remove from the GUI box.
          testBox.setEditable(true);
          testBox.remove(tests.get(i));
          testBox.repaint();
          testBox.setEditable(false);
        }
      }

      // Update the tests with the newly made list.
      tests = newTests;
    }
  }
Beispiel #2
0
  // Choose and run the app to test.
  private void displayAppFrame() {

    // Set up the frame for the file chooser.
    final JFrame appframe = new JFrame("Select Application");
    appframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Container contentPane = appframe.getContentPane();
    JFileChooser fileChooser = new JFileChooser(".");

    // Ask user what type of executable the program is in, display chooser accordingly.
    int isJar =
        JOptionPane.showOptionDialog(
            null,
            "Is the program a .jar file?",
            "Question",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            null);
    if (isJar == JOptionPane.YES_OPTION) {
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    } else if (isJar == JOptionPane.NO_OPTION) {
      fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    } else {
      fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    }
    contentPane.add(fileChooser, BorderLayout.CENTER);

    // Make a new action listener for the file chooser.
    ActionListener actionListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {

            // Get the information to check if the file chosen is valid.
            JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
            String command = actionEvent.getActionCommand();

            // If the user cancels selecting a program.
            if (command.equals(JFileChooser.CANCEL_SELECTION)) {
              appframe.setVisible(false);
              appframe.dispose();
              return;
            }

            // If the file chosen is valid.
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
              // Retrieve the selected file and ask for the main class name.
              File f = theFileChooser.getSelectedFile();
              String className = JOptionPane.showInputDialog("Please enter the main class name: ");
              mainClass = className;
              programPath = f.getAbsolutePath();

              // Obtain the file URL.
              URL[] folderURL = new URL[1];
              String fileURL = null;
              String programName = "/";
              try {
                folderURL[0] = f.toURI().toURL();
                fileURL = new String(folderURL[0].toString());
              } catch (MalformedURLException e1) {
                System.err.println("File URL not correct.");
              }

              // check if OS is *nix, if so, add leading /
              String os = System.getProperty("os.name").toLowerCase();
              if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0) {
                fileURL = "/" + fileURL;
              }

              // Run the selected application.
              try {
                // Begin capturing the programs GUI.
                System.out.println("Before Capture: #Frames=" + Frame.getFrames().length);
                guiCapture.beginCapture();
                // Load the program through the CaptureAsYouGo
                guiCapture.loadApplication(className, folderURL, new String[] {});
                // Update the label that shows what program is running.
                programName = fileURL.substring(fileURL.lastIndexOf('/'));
                if (programName.length() == 1) {
                  programName = "Main Class - " + className;
                }
                appName.setText(programName);
              } catch (IOException e) {
                e.printStackTrace();
                System.out.println("TEST 1");
              } catch (Exception e) {
                e.printStackTrace();
                System.out.println("TEST 2");
              }

              // Make the file chooser disappear.
              appframe.setVisible(false);
              appframe.dispose();
            }
          }
        };

    // Add the action listener created above to file chooser, display it.
    fileChooser.addActionListener(actionListener);
    appframe.pack();
    appframe.setVisible(true);
  }