コード例 #1
0
 private void setupFileChooser() {
   fileChooser = new JFileChooser();
   fileChooser.setDialogTitle("Select directory to output ISArchive to...");
   fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
   fileChooser.setApproveButtonText("Output to selected directory");
   fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
 }
コード例 #2
0
ファイル: JSheet.java プロジェクト: karlvr/Quaqua
  /**
   * 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();
  }
コード例 #3
0
ファイル: JSheet.java プロジェクト: karlvr/Quaqua
 /**
  * Displays an "Open File" file chooser sheet. Note that the text that appears in the approve
  * button is determined by the L&F.
  *
  * @param chooser the chooser
  * @param parent the parent component of the dialog, can be {@code null}.
  * @param listener The listener for SheetEvents.
  */
 public static void showOpenSheet(JFileChooser chooser, Component parent, SheetListener listener) {
   chooser.setDialogType(JFileChooser.OPEN_DIALOG);
   showSheet(chooser, parent, null, listener);
 }
コード例 #4
0
  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);
      }
    }
  }
コード例 #5
0
ファイル: ThumbMaker.java プロジェクト: ctrueden/web-toys
  /** Called for button presses and checkbox toggles. */
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();

    // the source of the event is the add files button
    // so we need to let the user add some files!
    if (src == addFiles) {
      // create an appropriate file chooser
      JFileChooser myTempFileChooser = new JFileChooser((new File("")).getAbsolutePath());
      myTempFileChooser.setMultiSelectionEnabled(true);
      myTempFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
      myTempFileChooser.setFileHidingEnabled(true);

      // open the file chooser and get the user's selctions
      int returnCode = myTempFileChooser.showOpenDialog(this);

      // use the return info to add files if the
      // user selected any in the file chooser
      if (returnCode == JFileChooser.APPROVE_OPTION) {
        // grab the files the user selected
        File[] selectedFiles = myTempFileChooser.getSelectedFiles();

        // pull the files into the list
        changeFilesInList.importFileData(list, selectedFiles);
      }
    }

    // the source of the event was the process button
    else if (src == process) {
      if (((DefaultListModel) list.getModel()).size() == 0) return;

      setComponentsEnabled(false);
      final ThumbMaker tm = this;
      Thread t =
          new Thread(
              new Runnable() {
                public void run() {
                  tm.process();
                  setComponentsEnabled(true);
                }
              });
      t.start();

      // because we can't do it on quit, we are going to save
      // all the preference values when the user processes a set
      // of images
      savePreferences();
    }

    // the source of the event was the remove button
    else if (src == remove) {
      DefaultListModel model = (DefaultListModel) list.getModel();
      while (true) {
        int ndx = list.getSelectedIndex();
        if (ndx < 0) break;
        model.removeElementAt(ndx);
      }
    }

    // the source of the event was the preserve aspect check box
    else if (src == aspect) {
      boolean b = aspect.isSelected();
      colorLabel.setEnabled(b);
      colorBox.setEnabled(b);
      redLabel.setEnabled(b);
      red.setEnabled(b);
      redValue.setEnabled(b);
      greenLabel.setEnabled(b);
      green.setEnabled(b);
      greenValue.setEnabled(b);
      blueLabel.setEnabled(b);
      blue.setEnabled(b);
      blueValue.setEnabled(b);
    }

    // the source of the event is the "..." button,
    // we need to let the user select a destination file
    else if (src == dotDotDot) {
      // create an appropriate file chooser
      JFileChooser myTempFileChooser =
          new JFileChooser(new File(output.getText()).getAbsolutePath());
      myTempFileChooser.setMultiSelectionEnabled(false);
      myTempFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
      myTempFileChooser.setFileHidingEnabled(true);

      // open the file chooser and get the user's selctions
      int returnCode = myTempFileChooser.showOpenDialog(this);

      // use the return info to set the directory if the
      // user selected one in the file chooser
      if (returnCode == JFileChooser.APPROVE_OPTION) {
        // grab the file the user selected
        File selectedFile = myTempFileChooser.getSelectedFile();

        // stuff the file path into the text field
        output.setText(selectedFile.getAbsolutePath());
      }
    }
  }