コード例 #1
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
 /** This method cannot be called directly. */
 public void actionPerformed(ActionEvent e) {
   FileDialog chooser =
       new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
   chooser.setVisible(true);
   String filename = chooser.getFile();
   if (filename != null) {
     StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
   }
 }
コード例 #2
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
コード例 #3
0
 @Override
 public void execute() throws Exception {
   FileDialog fd = new FileDialog((Frame) context.getStage().getNativeWindow());
   fd.setMode(FileDialog.LOAD);
   fd.setTitle("Import Other Graphics File");
   fd.setVisible(true);
   if (fd.getFile() != null) {
     File file = new File(fd.getDirectory(), fd.getFile());
     u.p("opening a file" + file);
     try {
       load(file);
       context.main.recentFiles.add(file);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
コード例 #4
0
  /** Handle ItemEvents. */
  public void itemStateChanged(ItemEvent e) {

    final String dialog_title = ResourceHandler.getMessage("template_dialog.title");

    Component target = (Component) e.getSource();

    if (target == recursiveCheckBox) {
      converter.setRecurse(recursiveCheckBox.isSelected());
    } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) {
      converter.setStaticVersioning(staticVersioningRadioButton.isSelected());
    } else if (target == templateCh
        && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected

      // Get the current template selection
      String choiceStr = (String) templateCh.getSelectedItem();

      // If the user chooses 'other', display a file dialog to allow
      // them to select a template file.
      if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) {
        String templatePath = null;
        FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD);
        fd.show();

        // Capture the path entered, if any.
        if (fd.getDirectory() != null && fd.getFile() != null) {
          templatePath = fd.getDirectory() + fd.getFile();
        }

        // If the template file is valid add it and select it.
        if (templatePath != null && setTemplateFile(templatePath)) {
          if (!templateCh.testIfInList(templatePath)) {
            templateCh.addItem(templatePath);
          }
          templateCh.select(templatePath);
        } else {
          templateCh.select(templateCh.getPreviousSelection());
        }
        fd.dispose();
      } else {
        templateCh.select(choiceStr);
      }
    }
  }
コード例 #5
0
ファイル: RecordingFrame.java プロジェクト: tmbx/kas
  protected boolean browseFile() {
    File currentFile = new File(fnameField.getText());

    FileDialog fd = new FileDialog(this, "Save next session as...", FileDialog.SAVE);
    fd.setDirectory(currentFile.getParent());
    fd.setVisible(true);
    if (fd.getFile() != null) {
      String newDir = fd.getDirectory();
      String sep = System.getProperty("file.separator");
      if (newDir.length() > 0) {
        if (!sep.equals(newDir.substring(newDir.length() - sep.length()))) newDir += sep;
      }
      String newFname = newDir + fd.getFile();
      if (newFname.equals(fnameField.getText())) {
        fnameField.setText(newFname);
        return true;
      }
    }
    return false;
  }
コード例 #6
0
  public static File FileSaveDialog(String title) {
    // Open File Dialog:
    FileDialog filedialog = new FileDialog((Frame) null, title, FileDialog.SAVE);
    filedialog.setVisible(true);
    File fileSelected = null;
    try {
      fileSelected = new File(filedialog.getDirectory(), filedialog.getFile());
    } catch (Exception e) {

    }
    return fileSelected;
  }
コード例 #7
0
ファイル: PathogenFrame.java プロジェクト: stevenhwu/ABI
  protected void doExportData() {
    FileDialog dialog = new FileDialog(this, "Export Data File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      Writer writer = null;
      try {
        writer = new PrintWriter(file);
        treesPanel.writeDataFile(writer);
        writer.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing data file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
コード例 #8
0
ファイル: PathogenFrame.java プロジェクト: stevenhwu/ABI
  private void doExportTimeTree() {
    FileDialog dialog = new FileDialog(this, "Export Time Tree File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      PrintStream ps = null;
      try {
        ps = new PrintStream(file);
        writeTimeTreeFile(ps);
        ps.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing tree file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
コード例 #9
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
  /**
   * Shows a file-open selection dialog for the given working directory.
   *
   * @param aOwner the owning window to show the dialog in;
   * @param aCurrentDirectory the working directory to start the dialog in, can be <code>null</code>
   *     .
   * @return the selected file, or <code>null</code> if the user aborted the dialog.
   */
  public static final File showFileOpenDialog(
      final Window aOwner,
      final String aCurrentDirectory,
      final javax.swing.filechooser.FileFilter... aFileFilters) {
    if (HostUtils.isMacOS()) {
      final FileDialog dialog;
      if (aOwner instanceof Dialog) {
        dialog = new FileDialog((Dialog) aOwner, "Open file", FileDialog.LOAD);
      } else {
        dialog = new FileDialog((Frame) aOwner, "Open file", FileDialog.LOAD);
      }
      dialog.setDirectory(aCurrentDirectory);

      if ((aFileFilters != null) && (aFileFilters.length > 0)) {
        dialog.setFilenameFilter(new FilenameFilterAdapter(aFileFilters));
      }

      try {
        dialog.setVisible(true);
        final String selectedFile = dialog.getFile();
        return selectedFile == null ? null : new File(dialog.getDirectory(), selectedFile);
      } finally {
        dialog.dispose();
      }
    } else {
      final JFileChooser dialog = new JFileChooser();
      dialog.setCurrentDirectory((aCurrentDirectory == null) ? null : new File(aCurrentDirectory));

      for (javax.swing.filechooser.FileFilter filter : aFileFilters) {
        dialog.addChoosableFileFilter(filter);
      }

      File result = null;
      if (dialog.showOpenDialog(aOwner) == JFileChooser.APPROVE_OPTION) {
        result = dialog.getSelectedFile();
      }

      return result;
    }
  }
  public void actionPerformed(ActionEvent e) {
    System.out.println("April working");

    // Creates the "Open a File" dialog box

    FileDialog fd = new FileDialog(new Frame(), "Open April hillshade ASCII", FileDialog.LOAD);
    fd.setVisible(true);

    // Creates a new File object from the file that is opened

    File file = new File(fd.getDirectory() + fd.getFile());

    if ((fd.getDirectory() == null) || (fd.getFile() == null)) {
      System.out.println("April hillshade file not uploaded");
      return;
    } else {

      // Creates a GRIDJava object from the opened file

      GRIDJava2 gj = new GRIDJava2(file, true, store);

      // Adds the GRIDJava object to the panel

      panel.addGRIDJavaMethod(gj);

      // Creates a 2D array from the GRIDJava object

      double hillshade_April[][] = gj.getTwoDdoubleArray();

      // Converts hillshade values (0-255) to %

      for (int i = 0; i < hillshade_April.length; i++) {
        for (int j = 0; j < hillshade_April[i].length; j++) {

          if ((hillshade_April[i][j] != -9999) && (hillshade_April[i][j] != 0)) {
            double percentage1 = (hillshade_April[i][j] / 255.0); // half the way.... (* 100)
            double percentage2 = percentage1 * 100.0;
            hillshade_April[i][j] = percentage2;
          } else if (hillshade_April[i][j] == 0) {
            hillshade_April[i][j] = 0;
          } else {
            hillshade_April[i][j] = -9999;
          }
        }
      }

      store.setHillshade_April(hillshade_April);

      // ****************** End of hillshade conversion **********************

      // Creates a 1D array from the GRIDJava object

      int data1d[] = gj.getOneDintArray();

      // Creates an Image object

      Image temp = null;

      // Creates a MemoryImageSource object which uses methods from GRIDJava.java and takes in the
      // 1D array created above

      MemoryImageSource mis =
          new MemoryImageSource(
              gj.getNumberOfColumns(), gj.getNumberOfRows(), data1d, 0, gj.getNumberOfColumns());

      // Using a toolkit, this creates the image and assigns it to the Image object created earlier
      // (previously set to null)

      temp = panel.getToolkit().createImage(mis);

      // Displays the image on the panel

      panel.displayImage(temp);

      System.out.println("April hillshade uploaded");
    }
  }
コード例 #11
0
  public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed");
    if (e.getSource() == pen) // 画笔
    {
      System.out.println("pen");
      toolFlag = 0;
    }

    if (e.getSource() == eraser) // 橡皮
    {
      System.out.println("eraser");
      toolFlag = 1;
    }

    if (e.getSource() == clear) // 清除
    {
      System.out.println("clear");
      toolFlag = 2;
      paintInfo.removeAllElements();
      repaint();
    }

    if (e.getSource() == drLine) // 画线
    {
      System.out.println("drLine");
      toolFlag = 3;
    }

    if (e.getSource() == drCircle) // 画圆
    {
      System.out.println("drCircle");
      toolFlag = 4;
    }

    if (e.getSource() == drRect) // 画矩形
    {
      System.out.println("drRect");
      toolFlag = 5;
    }

    if (e.getSource() == colchooser) // 调色板
    {
      System.out.println("colchooser");
      Color newColor = JColorChooser.showDialog(this, "我的调色板", c);
      c = newColor;
    }

    if (e.getSource() == openPic) // 打开图画
    {

      openPicture.setVisible(true);

      if (openPicture.getFile() != null) {
        int tempflag;
        tempflag = toolFlag;
        toolFlag = 2;
        repaint();

        try {
          paintInfo.removeAllElements();
          File filein = new File(openPicture.getDirectory(), openPicture.getFile());
          picIn = new FileInputStream(filein);
          VIn = new ObjectInputStream(picIn);
          paintInfo = (Vector) VIn.readObject();
          VIn.close();
          repaint();
          toolFlag = tempflag;

        } catch (ClassNotFoundException IOe2) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read object");
        } catch (IOException IOe) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read file");
        }
      }
    }

    if (e.getSource() == savePic) // 保存图画
    {
      savePicture.setVisible(true);
      try {
        File fileout = new File(savePicture.getDirectory(), savePicture.getFile());
        picOut = new FileOutputStream(fileout);
        VOut = new ObjectOutputStream(picOut);
        VOut.writeObject(paintInfo);
        VOut.close();
      } catch (IOException IOe) {
        System.out.println("can not write object");
      }
    }
  }
  public void actionPerformed(ActionEvent e) {

    System.out.println("November 6pm working");

    // Creates the "Open a File" dialog box

    FileDialog fd =
        new FileDialog(new Frame(), "Open November 6pm hillshade ASCII", FileDialog.LOAD);
    fd.setVisible(true);

    // Creates a new File object from the file that is opened

    File file = new File(fd.getDirectory() + fd.getFile());

    // File file = new File("F:\\Model_Test_Files\\59_hillshade.txt");

    if ((fd.getDirectory() == null) || (fd.getFile() == null)) {
      System.out.println("November 6pm hillshade file not uploaded");
      return;
    } else {

      // Creates a GRIDJava object from the opened file

      GRIDJava2 gj = new GRIDJava2(file, true, store);

      // Adds the GRIDJava object to the panel

      panel.addGRIDJavaMethod(gj);

      // Creates a 2D array from the GRIDJava object

      double hillshade_November_6pm[][] = gj.getTwoDdoubleArray();

      store.setHillshade_Nov_6pm(hillshade_November_6pm);

      // ****************** End of hillshade conversion **********************

      // Creates a 1D array from the GRIDJava object

      int data1d[] = gj.getOneDintArray();

      // Creates an Image object

      Image temp = null;

      // Creates a MemoryImageSource object which uses methods from GRIDJava.java and takes in the
      // 1D array created above

      MemoryImageSource mis =
          new MemoryImageSource(
              gj.getNumberOfColumns(), gj.getNumberOfRows(), data1d, 0, gj.getNumberOfColumns());

      // Using a toolkit, this creates the image and assigns it to the Image object created earlier
      // (previously set to null)

      temp = panel.getToolkit().createImage(mis);

      // Displays the image on the panel

      panel.displayImage(temp);

      System.out.println("November 6pm hillshade uploaded");
    }
  }