Beispiel #1
0
  // Add a test case to testBox and tests array.
  private void addTest() {

    // 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(".");

    // Only let you select directories and add chooser to pane.
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    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();

              // Obtain the file URL.
              String fileURL = null;
              fileURL = f.getAbsolutePath();

              // Add a checkbox to the testing check pane.
              JCheckBox newTest = new JCheckBox(fileURL, true);
              testBox.setEditable(true);
              testBox.add(newTest);
              testBox.repaint();
              testBox.setEditable(false);
              // Add the test to the list of tests.
              tests.add(newTest);

              // 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);
  }
Beispiel #2
0
  /**
   * Displays a custom file chooser sheet with a custom approve button.
   *
   * @param chooser the chooser
   * @param parent the parent component of the dialog; can be {@code null}
   * @param approveButtonText the text of the {@code ApproveButton}
   * @param listener The listener for SheetEvents.
   */
  public static void showSheet(
      final JFileChooser chooser,
      Component parent,
      String approveButtonText,
      SheetListener listener) {
    if (approveButtonText != null) {
      chooser.setApproveButtonText(approveButtonText);
      chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    }

    // Begin Create Dialog
    Frame frame =
        parent instanceof Frame
            ? (Frame) parent
            : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    String title = chooser.getUI().getDialogTitle(chooser);
    chooser.getAccessibleContext().setAccessibleDescription(title);

    final JSheet sheet = new JSheet(frame);
    sheet.addSheetListener(listener);

    Container contentPane = sheet.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(chooser, BorderLayout.CENTER);
    // End Create Dialog

    final ActionListener actionListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent evt) {
            int option;
            if (evt.getActionCommand().equals("ApproveSelection")) {
              option = JFileChooser.APPROVE_OPTION;
            } else {
              option = JFileChooser.CANCEL_OPTION;
            }
            sheet.hide();
            sheet.fireOptionSelected(chooser, option);
            chooser.removeActionListener(this);
          }
        };
    chooser.addActionListener(actionListener);
    sheet.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            sheet.fireOptionSelected(chooser, JFileChooser.CANCEL_OPTION);
            chooser.removeActionListener(actionListener);
          }
        });
    chooser.rescanCurrentDirectory();
    sheet.pack();
    sheet.show();
    sheet.toFront();
  }
Beispiel #3
0
  public void createForm() {
    _nameLabel = new JLabel("Connection Name:");
    _usernameLabel = new JLabel("Username:"******"Password:"******"SVN URL:");
    _localLabel = new JLabel("Local Root:");

    _name = new JTextField(COLS);
    _name.setText(_workingCopy.getName());
    _username = new JTextField(COLS);
    _username.setText(_workingCopy.getUsername());
    _password = new JPasswordField(COLS);
    _password.setText(_workingCopy.getPassword());
    _url = new JTextField(COLS);
    _url.setText(_workingCopy.getUrl());

    _local = new JFileChooser();
    _local.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    _local.addActionListener(this);
    File current = new File(_workingCopy.getLocalRoot());
    _local.setSelectedFile(current);

    _error = new JLabel(" ");
    _error.setForeground(Color.red);

    _localButton = new JButton(".../" + current.getName());
    _localButton.addActionListener(this);

    _create = new JButton("Save Connection");
    _create.addActionListener(this);
    _cancel = new JButton("Cancel");
    _cancel.addActionListener(this);
    _test = new JButton("Test");
    _test.addActionListener(this);

    this.add(_nameLabel, "align right");
    this.add(_name);
    this.add(_usernameLabel, "align right");
    this.add(_username);
    this.add(_passwordLabel, "align right");
    this.add(_password);
    this.add(_urlLabel, "align right");
    this.add(_url);
    this.add(_localLabel, "align right");
    this.add(_localButton, "width 100%");
    this.add(_error, "span 2,align center");
    this.add(_cancel, "span 2, split 3, width 33%");
    this.add(_test, "width 33%");
    this.add(_create, "width 33%");
  }
  /** Constructor */
  public SaverCustomizer() {

    try {
      m_SaverEditor.addPropertyChangeListener(
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
              repaint();
              if (m_dsSaver != null) {
                System.err.println("Property change!!");
                m_dsSaver.setSaver(m_dsSaver.getSaver());
              }
            }
          });
      repaint();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    setLayout(new BorderLayout());
    m_fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    m_fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    m_fileChooser.setApproveButtonText("Select directory");
    m_fileChooser.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
              try {
                File selectedFile = m_fileChooser.getSelectedFile();
                m_directoryText.setText(selectedFile.toString());

                /* (m_dsSaver.getSaver()).setFilePrefix(m_prefixText.getText());
                (m_dsSaver.getSaver()).setDir(m_fileChooser.getSelectedFile().getPath());
                m_dsSaver.
                  setRelationNameForFilename(m_relationNameForFilename.isSelected()); */

              } catch (Exception ex) {
                ex.printStackTrace();
              }
            }
            // closing
            if (m_fileChooserFrame != null) {
              m_fileChooserFrame.dispose();
            }
          }
        });
  }
Beispiel #5
0
  @SuppressWarnings({"unchecked", "serial"})
  public SourcesSelector(final ProcessLog logger) {
    super(new BorderLayout(0, 5));
    this.logger = logger;
    JPanel buttons = new JPanel(new GridLayout(5, 1, 0, 10));
    buttons.add(
        new JButton(
            new AbstractAction("Add Source") {
              @Override
              public void actionPerformed(ActionEvent e) {
                chooser.showOpenDialog(null);
              }
            }));
    buttons.add(
        new JButton(
            new AbstractAction("Load Sources") {
              @Override
              public void actionPerformed(ActionEvent e) {
                // TODO: use an xml config file to load sources from a saved file
                refreshModules();
              }
            }));
    buttons.add(
        new JButton(
            new AbstractAction("Remove Source") {
              @Override
              public void actionPerformed(ActionEvent e) {
                int[] selected = list.getSelectedIndices();
                int pos = selected.length;
                while (pos > 0) dir.remove(selected[--pos]);
                refreshModules();
              }
            }));
    buttons.add(
        new JButton(
            new AbstractAction("Remove All Sources") {
              @Override
              public void actionPerformed(ActionEvent e) {
                dir.removeAllElements();
                refreshModules();
              }
            }));
    buttons.add(
        new JButton(
            new AbstractAction("Clear Log") {
              @Override
              public void actionPerformed(ActionEvent e) {
                logger.clear();
              }
            }));
    splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitter.setLeftComponent(buttons);
    dir = new DefaultListModel();
    chooser = new JFileChooser();
    chooser.setFileFilter(
        new FileFilter() {
          @Override
          public String getDescription() {
            return "Directories Or Jars";
          }

          @Override
          public boolean accept(File f) {
            return f.isDirectory() || f.toString().endsWith(".jar");
          }
        });
    chooser.setMultiSelectionEnabled(true);
    chooser.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            for (File f : chooser.getSelectedFiles()) {
              int ind = dir.indexOf(f);
              if (ind > -1) dir.remove(ind);
              dir.add(0, f);
            }
            refreshModules();
          }
        });
    list = new JList(dir);
    list.setCellRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            try {
              File f = (File) value;
              if (f.isDirectory()) {
                return super.getListCellRendererComponent(
                    list, f.toString(), index, isSelected, cellHasFocus);
              } else {
                return super.getListCellRendererComponent(
                    list, f.getName(), index, isSelected, cellHasFocus);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
          }
        });
    list.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            int[] selected = list.getSelectedIndices();
            if (selected.length > 0) {
              File f = (File) dir.get(selected[0]);
              if (f.isDirectory()) {
                chooser.setCurrentDirectory(f);
              } else {
                chooser.setCurrentDirectory(f.getParentFile());
              }
            }
          }
        });
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    JScrollPane scroller =
        new JScrollPane(
            list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    splitter.setRightComponent(scroller);
    add(splitter);
    splitter.setDividerLocation(0.5);
  }
  public void takeScreenshot(boolean flag) {
    BufferedImage bufferedimage;
    try {
      Robot robot = new Robot();
      Point point = getLocationOnScreen();
      Rectangle rectangle = new Rectangle(point.x, point.y, getWidth(), getHeight());
      bufferedimage = robot.createScreenCapture(rectangle);
    } catch (Throwable throwable) {
      JOptionPane.showMessageDialog(
          frame, "An error occured while trying to create a screenshot!", "Screenshot Error", 0);
      return;
    }
    String s = null;
    try {
      s = getNearestScreenshotFilename();
    } catch (IOException ioexception) {
      if (flag) {
        JOptionPane.showMessageDialog(
            frame,
            "A screenshot directory does not exist, and could not be created!",
            "No Screenshot Directory",
            0);
        return;
      }
    }
    if (s == null && flag) {
      JOptionPane.showMessageDialog(
          frame,
          "There are too many screenshots in the screenshot directory!\n"
              + "Delete some screen\n"
              + "shots and try again.",
          "Screenshot Directory Full",
          0);
      return;
    }
    if (!flag) {
      final JFileChooser fileChooser = new JFileChooser();
      final JDialog fileDialog = createFileChooserDialog(fileChooser, "Save Screenshot", this);
      final BufferedImage si = bufferedimage;
      JFileChooser _tmp = fileChooser;
      fileChooser.setFileSelectionMode(0);
      fileChooser.addChoosableFileFilter(new imageFileFilter());
      fileChooser.setCurrentDirectory(new File("C:/.hack3rClient/Scre/"));
      fileChooser.setSelectedFile(new File(s));
      JFileChooser _tmp1 = fileChooser;
      fileChooser.setDialogType(1);
      fileChooser.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent actionevent) {
              String s1 = actionevent.getActionCommand();
              if (s1.equals("ApproveSelection")) {
                File file = fileChooser.getSelectedFile();
                if (file != null && file.isFile()) {
                  int i =
                      JOptionPane.showConfirmDialog(
                          frame,
                          (new StringBuilder())
                              .append(file.getAbsolutePath())
                              .append(" already exists.\n" + "Do you want to replace it?")
                              .toString(),
                          "Save Screenshot",
                          2);
                  if (i != 0) {
                    return;
                  }
                }
                try {
                  ImageIO.write(si, "png", file);
                  // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client");
                  // JOptionPane.showMessageDialog(frame,"Screenshot Taken");
                } catch (IOException ioexception2) {
                  JOptionPane.showMessageDialog(
                      frame,
                      "An error occured while trying to save the screenshot!\n"
                          + "Please make sure you have\n"
                          + " write access to the screenshot directory.",
                      "Screenshot Error",
                      0);
                }
                fileDialog.dispose();
              } else if (s1.equals("CancelSelection")) {
                fileDialog.dispose();
              }
            }

            {
            }
          });
      fileDialog.setVisible(true);
    } else {
      try {
        ImageIO.write(
            bufferedimage,
            "png",
            new File((new StringBuilder()).append("C:/.hack3rClient/Scre/").append(s).toString()));
        JOptionPane.showMessageDialog(
            frame,
            "Image has been saved to C:/.hack3rclient/Scre. You can view your images by pushing File>View Images in the menu dropdowns.",
            "Screenshot manager",
            JOptionPane.INFORMATION_MESSAGE);
        // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client");
        // JOptionPane.showMessageDialog(frame,"Screenshot taken.");
      } catch (IOException ioexception1) {
        JOptionPane.showMessageDialog(
            frame,
            "An error occured while trying to save the screenshot!\n"
                + "Please make sure you have\n"
                + " write access to the screenshot directory.",
            "Screenshot Error",
            0);
      }
    }
  }
Beispiel #7
0
  // Save a test case.
  private void saveTest() {

    JFileChooser fileChooser = new JFileChooser(".");

    // Only let you select directories and add chooser to pane.
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    // 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)) {
              return;
            }

            // If the file chosen is valid.
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
              // Retrieve the requested file name and location.
              File f = theFileChooser.getSelectedFile();

              // Obtain the requested URL.
              String fileURL = f.getAbsolutePath();

              // This all makes a folder named by user with three files with the same name in it.

              // Make a folder named as user requested.
              f.mkdir();

              // Concatenate first part of .gui, .efg, .tst file names.
              fileURL = fileURL.concat(fileURL.substring(fileURL.lastIndexOf('/')));

              // Create the three files in the folder.
              File guiFile = new File(fileURL + ".GUI");
              File efgFile = new File(fileURL + ".EFG");
              File tstFile = new File(fileURL + ".TST");

              // Write a file to save the program details
              String programDetails = "path=" + programPath + "\n";
              programDetails += "main=" + mainClass;

              try {
                FileWriter fstream = new FileWriter(fileURL + ".PRG");
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(programDetails);
                out.close();
              } catch (Exception e) { // Catch exception if any
                System.err.println(e.getMessage());
              }

              try {
                guiFile.createNewFile();
                efgFile.createNewFile();
                tstFile.createNewFile();
              } catch (IOException e) {
                JOptionPane.showMessageDialog(null, "Could not create files.");
              }

              // Write the three files in the created directory.
              try {
                efgtstCapture.writeFiles(guiCapture.getStructure(), fileURL);
              } catch (InstantiationException e) {
                JOptionPane.showMessageDialog(null, "Could not save to files.");
              }
              updateGUI("Saved Test: " + fileURL);
            }
          }
        };

    // Add the action listener created above to file chooser, display it.
    fileChooser.addActionListener(actionListener);
    fileChooser.showSaveDialog(this);
  }
Beispiel #8
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);
  }