コード例 #1
0
ファイル: DialogTest1.java プロジェクト: expertman/J2SE
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand() == "Open") { // open버튼을 눌렀다면
     fdOpen.setVisible(true);
     System.out.println(fdOpen.getDirectory() + fdOpen.getFile());
   } else { // save버튼을 눌렀다면
     fdSave.setVisible(true);
     System.out.println(fdSave.getDirectory() + fdSave.getFile());
   }
 }
コード例 #2
0
ファイル: Layout.java プロジェクト: ptrsz/nagyhf
    @Override
    public void actionPerformed(ActionEvent event) {
      String command = event.getActionCommand();
      if (command.equals("add")) {
        MultipleInputDialog inputDialog = new MultipleInputDialog();
        data.add(inputDialog.getDialogCar());

      } else if (command.equals("save")) {
        try {
          FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.SAVE);
          fd.setVisible(true);
          String dir = fd.getDirectory();
          String filename = fd.getFile();

          FileOutputStream fileOut = new FileOutputStream(dir + filename);
          ObjectOutputStream out = new ObjectOutputStream(fileOut);
          out.writeObject(Layout.this.data);
          out.close();
          fileOut.close();
          System.out.println("save OK");
          System.out.println("Kiirva 1/1 adat " + data.get(1).getOne());

        } catch (IOException i) {
          i.printStackTrace();
        }
      } else if (command.equals("load")) {
        try {
          FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.LOAD);
          fd.setVisible(true);
          String dir = fd.getDirectory();
          String filename = fd.getFile();

          FileInputStream fileIn = new FileInputStream(dir + filename);
          ObjectInputStream in = new ObjectInputStream(fileIn);

          Layout.this.data = (ArrayList<Car>) in.readObject();
          dataTable.repaint();

          fileIn.close();
          in.close();

          System.out.println("beolvasva");
          repaint();

          System.out.println("olvasva 1/1 adat data-ban " + data.get(1).getOne());
        } catch (IOException i) {
          i.printStackTrace();
        } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else if (command.equals("browse")) {
        FileDialog jf = new FileDialog(Layout.this, "Choose something", FileDialog.LOAD);
        jf.setVisible(true);
      }
    }
コード例 #3
0
ファイル: GUIImpl.java プロジェクト: rockerdiaz/halfnes
 public void loadROM() {
   FileDialog fileDialog = new FileDialog(this);
   fileDialog.setMode(FileDialog.LOAD);
   fileDialog.setTitle("Select a ROM to load");
   // should open last folder used, and if that doesn't exist, the folder it's running in
   final String path = PrefsSingleton.get().get("filePath", System.getProperty("user.dir", ""));
   final File startDirectory = new File(path);
   if (startDirectory.isDirectory()) {
     fileDialog.setDirectory(path);
   }
   // and if the last path used doesn't exist don't set the directory at all
   // and hopefully the jFileChooser will open somewhere usable
   // on Windows it does - on Mac probably not.
   fileDialog.setFilenameFilter(new NESFileFilter());
   boolean wasInFullScreen = false;
   if (inFullScreen) {
     wasInFullScreen = true;
     // load dialog won't show if we are in full screen, so this fixes for now.
     toggleFullScreen();
   }
   fileDialog.setVisible(true);
   if (fileDialog.getFile() != null) {
     PrefsSingleton.get().put("filePath", fileDialog.getDirectory());
     loadROM(fileDialog.getDirectory() + fileDialog.getFile());
   }
   if (wasInFullScreen) {
     toggleFullScreen();
   }
 }
コード例 #4
0
  public static void main(String args[]) {
    Frame f = new SampleFrame("File Dialog Demo");
    f.setVisible(true);
    f.setSize(200, 200);

    FileDialog fd = new FileDialog(f, "File Dialog");

    fd.setVisible(true);
  }
コード例 #5
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());
   }
 }
コード例 #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
ファイル: ActionLoadListener.java プロジェクト: Enotkin/test
 /**
  * Чтение таблицы из файла
  *
  * @param e
  */
 public void actionPerformed(ActionEvent e) {
   load.setVisible(true);
   String fileName = load.getDirectory() + load.getFile();
   try {
     if (load.getFile() == null) {
       throw new NullFileException();
     }
     Load load = new Load();
     load.LoadXML(fileName, masters, records);
   } catch (NullFileException ex) {
     JOptionPane.showMessageDialog(carsList, ex.getMessage());
   }
   load.setFile("*.xml");
 }
コード例 #8
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();
     }
   }
 }
コード例 #9
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;
  }
コード例 #10
0
ファイル: getPicInfo.java プロジェクト: mahlum/Algorithmen
  public getPicInfo(Frame father) {
    try {
      FileDialog diag = new FileDialog(father);
      diag.setVisible(true);
      m_Img =
          getToolkit()
              .getImage(diag.getDirectory() + diag.getFile())
              .getScaledInstance(W, H, Image.SCALE_SMOOTH);
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(m_Img, 0);
      mt.waitForAll();
      PixelGrabber grab = new PixelGrabber(m_Img, 0, 0, W, H, m_Pix, 0, W);
      grab.grabPixels();
      m_ImgSrc = new MemoryImageSource(W, H, m_Pix, 0, W);
      m_Img = createImage(m_ImgSrc);
      System.out.println("Wait HERE !");
    } catch (InterruptedException e) {

    }
  }
コード例 #11
0
  /**
   * Prompt the user for a new file to the sketch, then call the other addFile() function to
   * actually add it.
   */
  public void handleAddFile() {
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    // if read-only, give an error
    if (isReadOnly(
        BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
      // if the files are read-only, need to first do a "save as".
      Base.showMessage(
          tr("Sketch is Read-Only"),
          tr(
              "Some files are marked \"read-only\", so you'll\n"
                  + "need to re-save the sketch in another location,\n"
                  + "and try again."));
      return;
    }

    // get a dialog, select a file to add to the sketch
    FileDialog fd =
        new FileDialog(
            editor,
            tr("Select an image or other data file to copy to your sketch"),
            FileDialog.LOAD);
    fd.setVisible(true);

    String directory = fd.getDirectory();
    String filename = fd.getFile();
    if (filename == null) return;

    // copy the file into the folder. if people would rather
    // it move instead of copy, they can do it by hand
    File sourceFile = new File(directory, filename);

    // now do the work of adding the file
    boolean result = addFile(sourceFile);

    if (result) {
      editor.statusNotice(tr("One file added to the sketch."));
      PreferencesData.set("last.folder", sourceFile.getAbsolutePath());
    }
  }
コード例 #12
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);
      }
    }
  }
コード例 #13
0
ファイル: VFileDialog.java プロジェクト: timburrow/ovj3
 public void setVisible(boolean v) {
   // for now, we probably never call this with "false" but
   // just to do something sane we do this ...
   super.setVisible(v);
   if (!v) {
     return;
   }
   fileName = this.getFile();
   directory = this.getDirectory();
   fullPath = directory + fileName;
   if (!getDirectoryExtension(directory).equals("fid")) {
     Util.sendToVnmr("write(\'error\',\'unknown file -- open ignored\')");
   } else {
     if (mode == FileDialog.LOAD) {
       openNmrFile();
     } else if (mode == FileDialog.SAVE) {
       saveFID();
     }
   }
   this.dispose();
 }
コード例 #14
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);
      }
    }
  }
コード例 #15
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;
    }
  }
コード例 #16
0
  paintboard1(String s) {
    super(s);
    addMouseMotionListener(this);
    addMouseListener(this);

    paintInfo = new Vector();

    /* 各工具按钮及选择项 */
    // 颜色选择
    ColChoice = new Choice();
    ColChoice.add("black");
    ColChoice.add("red");
    ColChoice.add("blue");
    ColChoice.add("green");
    ColChoice.addItemListener(this);
    // 画笔大小选择
    SizeChoice = new Choice();
    SizeChoice.add("1");
    SizeChoice.add("3");
    SizeChoice.add("5");
    SizeChoice.add("7");
    SizeChoice.add("9");
    SizeChoice.addItemListener(this);
    // 橡皮大小选择
    EraserChoice = new Choice();
    EraserChoice.add("5");
    EraserChoice.add("9");
    EraserChoice.add("13");
    EraserChoice.add("17");
    EraserChoice.addItemListener(this);
    // //////////////////////////////////////////////////
    toolPanel = new Panel();

    clear = new Button("清除");
    eraser = new Button("橡皮");
    pen = new Button("画笔");
    drLine = new Button("画直线");
    drCircle = new Button("画圆形");
    drRect = new Button("画矩形");

    openPic = new Button("打开图画");
    savePic = new Button("保存图画");

    colchooser = new Button("显示调色板");

    // 各组件事件监听
    clear.addActionListener(this);
    eraser.addActionListener(this);
    pen.addActionListener(this);
    drLine.addActionListener(this);
    drCircle.addActionListener(this);
    drRect.addActionListener(this);
    openPic.addActionListener(this);
    savePic.addActionListener(this);
    colchooser.addActionListener(this);

    颜色 = new Label("画笔颜色", Label.CENTER);
    大小B = new Label("画笔大小", Label.CENTER);
    大小E = new Label("橡皮大小", Label.CENTER);
    // 面板添加组件
    toolPanel.add(openPic);
    toolPanel.add(savePic);

    toolPanel.add(pen);
    toolPanel.add(drLine);
    toolPanel.add(drCircle);
    toolPanel.add(drRect);

    toolPanel.add(颜色);
    toolPanel.add(ColChoice);
    toolPanel.add(大小B);
    toolPanel.add(SizeChoice);
    toolPanel.add(colchooser);

    toolPanel.add(eraser);
    toolPanel.add(大小E);
    toolPanel.add(EraserChoice);

    toolPanel.add(clear);
    // 工具面板到APPLET面板
    add(toolPanel, BorderLayout.NORTH);

    setBounds(230, 50, 900, 650);
    setVisible(true);
    validate();
    // dialog for save and load

    openPicture = new FileDialog(this, "打开图画", FileDialog.LOAD);
    openPicture.setVisible(false);
    savePicture = new FileDialog(this, "保存图画", FileDialog.SAVE);
    savePicture.setVisible(false);

    openPicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            openPicture.setVisible(false);
          }
        });

    savePicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            savePicture.setVisible(false);
          }
        });

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
コード例 #17
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");
      }
    }
  }
コード例 #18
0
ファイル: dbfShow.java プロジェクト: akerigan/staxer
  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == firstRecord) {
      goTo(1);
      return;
    }
    if (event.getSource() == lastRecord) {
      goTo(db.getRecordCount());
      return;
    }
    if (event.getSource() == Next || event.getSource() == nextRecord) {
      if (db.getCurrentRecordNumber() < db.getRecordCount()) {
        goTo(db.getCurrentRecordNumber() + 1);
      }
      return;
    }

    if (event.getSource() == Prev || event.getSource() == prevRecord) {
      if (db.getCurrentRecordNumber() > 1) {
        goTo(db.getCurrentRecordNumber() - 1);
      }
      return;
    }

    if (event.getSource() == Add || event.getSource() == addRecord) {
      addRec();
      return;
    }
    if (event.getSource() == Update || event.getSource() == updateRecord) {
      updateRec();
      return;
    }
    if (event.getSource() == Clear || event.getSource() == clearRecord) {
      clearFields();
      return;
    }

    if (event.getSource() == opener) {
      FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD);
      fd.setFile("*.DBF");
      fd.pack();
      fd.setVisible(true);
      String DBFname = fd.getFile();
      String dirname = fd.getDirectory();
      if (DBFname == null) {
        return;
      }
      if (DBFname.length() < 1) {
        return;
      }
      String dbname = new String(dirname + DBFname);
      try {
        setupDBFields(dbname);
      } catch (Exception e1) {
        System.out.println(e1);
        System.exit(4);
      }
      pack();
      setVisible(true);
      return;
    }

    if (event.getSource() == packer) {
      packer.setEnabled(false);
      try {
        db.pack();
        trl.setText(" of " + db.getRecordCount());
      } catch (Exception e1) {
        e1.printStackTrace();
      }
      if (db.getRecordCount() == 0) {
        Update.setEnabled(false);
        Next.setEnabled(false);
        updateRecord.setEnabled(false);
        nextRecord.setEnabled(false);
        SBrecpos.setValues(0, 1, 0, 0);
      } else {
        goTo(1);
      }
      packer.setEnabled(true);
      return;
    }

    if (event.getSource() == quiter) {
      System.exit(0);
      return;
    }

    if (event.getSource() instanceof Button) {
      int i;
      Field f;
      for (i = 1; i <= db.getFieldCount(); i++) {
        try {
          f = db.getField(i);
          if (f.isMemoField()) {
            if (event.getActionCommand().equals(f.getName())) {
              md = new memoDialog(this, f);
              md.setVisible(true);
              return;
            }
          }
        } catch (Exception e1) {
          System.out.println(e1);
        }
      }
    }
  }
  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");
    }
  }
コード例 #20
0
  /**
   * Handles 'Save As' for a sketch.
   *
   * <p>This basically just duplicates the current sketch folder to a new location, and then calls
   * 'Save'. (needs to take the current state of the open files and save them to the new folder..
   * but not save over the old versions for the old sketch..)
   *
   * <p>Also removes the previously-generated .class and .jar files, because they can cause trouble.
   */
  protected boolean saveAs() throws IOException {
    // get new name for folder
    FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
    if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())
        || isUntitled()) {
      // default to the sketchbook folder
      fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
    } else {
      // default to the parent folder of where this was
      // on macs a .getParentFile() method is required

      fd.setDirectory(sketch.getFolder().getParentFile().getAbsolutePath());
    }
    String oldName = sketch.getName();
    fd.setFile(oldName);

    fd.setVisible(true);
    String newParentDir = fd.getDirectory();
    String newName = fd.getFile();

    // user canceled selection
    if (newName == null) return false;
    newName = SketchController.checkName(newName);

    File newFolder = new File(newParentDir, newName);

    // check if the paths are identical
    if (newFolder.equals(sketch.getFolder())) {
      // just use "save" here instead, because the user will have received a
      // message (from the operating system) about "do you want to replace?"
      return save();
    }

    // check to see if the user is trying to save this sketch inside itself
    try {
      String newPath = newFolder.getCanonicalPath() + File.separator;
      String oldPath = sketch.getFolder().getCanonicalPath() + File.separator;

      if (newPath.indexOf(oldPath) == 0) {
        Base.showWarning(
            tr("How very Borges of you"),
            tr(
                "You cannot save the sketch into a folder\n"
                    + "inside itself. This would go on forever."),
            null);
        return false;
      }
    } catch (IOException e) {
      // ignore
    }

    // if the new folder already exists, then need to remove
    // its contents before copying everything over
    // (user will have already been warned)
    if (newFolder.exists()) {
      FileUtils.recursiveDelete(newFolder);
    }
    // in fact, you can't do this on windows because the file dialog
    // will instead put you inside the folder, but it happens on osx a lot.

    try {
      sketch.saveAs(newFolder);
    } catch (IOException e) {
      // This does not pass on e, to prevent showing a backtrace for "normal"
      // errors.
      Base.showWarning(tr("Error"), e.getMessage(), null);
    }
    // Name changed, rebuild the sketch menus
    // editor.sketchbook.rebuildMenusAsync();
    editor.base.rebuildSketchbookMenus();
    editor.header.rebuild();

    // Make sure that it's not an untitled sketch
    setUntitled(false);

    // let Editor know that the save was successful
    return true;
  }
コード例 #21
0
ファイル: dbfShow.java プロジェクト: akerigan/staxer
  public dbfShow(String title, String fname) throws Exception {

    super(title);
    String dbname;
    addWindowListener(this);
    sp = new ScrollPane();
    viewPane = new Panel();
    sp.add(viewPane);
    this.add(sp);

    if (fname == null || fname.length() == 0) {
      FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD);
      fd.setFile("*.DBF");
      fd.pack();
      fd.setVisible(true);
      String DBFname = fd.getFile();
      String dirname = fd.getDirectory();

      if (DBFname == null) {
        System.exit(0);
      }
      if (DBFname.length() < 1) {
        System.exit(0);
      }
      dbname = new String(dirname + DBFname);
    } else {
      dbname = new String(fname);
    }

    MenuBar mb = new MenuBar();
    this.setMenuBar(mb);
    Menu file = new Menu("File");
    opener = new MenuItem("Open..");
    file.add(opener);
    opener.addActionListener(this);
    packer = new MenuItem("Pack");
    packer.addActionListener(this);
    file.add(packer);
    quiter = new MenuItem("Quit");
    file.add(quiter);
    quiter.addActionListener(this);
    mb.add(file);
    Menu record = new Menu("Record");
    firstRecord = new MenuItem("First");
    firstRecord.addActionListener(this);
    record.add(firstRecord);
    nextRecord = new MenuItem("Next");
    nextRecord.addActionListener(this);
    record.add(nextRecord);
    prevRecord = new MenuItem("Prev");
    prevRecord.addActionListener(this);
    record.add(prevRecord);
    lastRecord = new MenuItem("Last");
    lastRecord.addActionListener(this);
    record.add(lastRecord);
    addRecord = new MenuItem("Add");
    addRecord.addActionListener(this);
    record.add(addRecord);
    updateRecord = new MenuItem("Update");
    updateRecord.addActionListener(this);
    record.add(updateRecord);
    clearRecord = new MenuItem("Clear");
    clearRecord.addActionListener(this);
    record.add(clearRecord);
    mb.add(record);
    crl = new Label("Record", Label.RIGHT);
    trl = new Label(" of ", Label.LEFT);
    SBrecpos = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 0, 0);
    SBrecpos.addAdjustmentListener(this);
    delCB = new Checkbox("Deleted");
    delCB.addItemListener(this);
    Prev = new Button("<<Prev");
    Prev.addActionListener(this);
    Next = new Button("Next>>");
    Next.addActionListener(this);
    Add = new Button("Add");
    Add.addActionListener(this);
    Update = new Button("Update");
    Update.addActionListener(this);
    Clear = new Button("Clear");
    Clear.addActionListener(this);
    setupDBFields(dbname);
    setTitle(dbname + ",   org.xBaseJ Version:" + org.xBaseJ.DBF.xBaseJVersion);
    pack();
    setVisible(true);
  }
  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");
    }
  }