⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filebrowser.java

📁 Petri网分析工具PIPE is open-source
💻 JAVA
字号:
package pipe.gui.widgets;import java.io.File;import java.io.IOException;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import pipe.gui.ExtensionFilter;/** * @author Maxim * * Opens a file browser with appropriate settings for the given filetype/extension    */public class FileBrowser extends JFileChooser {  private String ext;  public FileBrowser(String filetype,String ext,String path) {    super();    if (filetype==null) filetype="file";        if (path!=null) {      File f=new File(path);      if(f.exists())setCurrentDirectory(f);      if(!f.isDirectory())setSelectedFile(f);    }        this.ext=ext;    ExtensionFilter filter=new ExtensionFilter(ext,filetype);    setFileFilter(filter);  }  public FileBrowser(String path) {    this("Petri net","xml",path); // default parameters  }  public FileBrowser() {    this(null);  }      public File openFile() {    if (showOpenDialog(null)==JFileChooser.APPROVE_OPTION)      try {        return getSelectedFile().getCanonicalFile();      } catch        (IOException e) {/* gulp */};      return null;      }    public String saveFile() {    if (showSaveDialog(null)==JFileChooser.APPROVE_OPTION)      try {        File f=getSelectedFile();        if(!f.getName().endsWith("."+ext)) f=new File(f.getCanonicalPath()+"."+ext); // force extension        if (f.exists() &&             JOptionPane.showConfirmDialog(              this,              f.getCanonicalPath()+"\nDo you want to overwrite this file?"            )!=JOptionPane.YES_OPTION           ) return null;        return f.getCanonicalPath();      } catch        (IOException e) {/* gulp */};      return null;      }  } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -