當前位置: 首頁>>代碼示例>>Java>>正文


Java FileDialog.setFilenameFilter方法代碼示例

本文整理匯總了Java中java.awt.FileDialog.setFilenameFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java FileDialog.setFilenameFilter方法的具體用法?Java FileDialog.setFilenameFilter怎麽用?Java FileDialog.setFilenameFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.FileDialog的用法示例。


在下文中一共展示了FileDialog.setFilenameFilter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showSaveDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
public static File showSaveDialog(Frame f,String title,String extension) {
	if(extension.startsWith("."))
		extension = extension.substring(1);
	
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter(extension));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);

	String s = fd.getFile();
	if(s==null)
		return null;
	
	if(s.toLowerCase().endsWith("."+extension)) {
		return new File(fd.getDirectory() + s);
	}
	
	return new File(fd.getDirectory() + fd.getFile()+"."+extension);
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:22,代碼來源:FileDialogUtils.java

示例2: showSaveDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
protected File showSaveDialog() {
	FileDialog fd = new FileDialog(frame);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter("mov"));
	fd.setTitle("Save MOV File");
	fd.pack();
	fd.setLocationRelativeTo(frame);
	fd.setVisible(true);
	if(fd.getFile()==null)
		throw new UserCancelledException();
	String filepath = fd.getDirectory() + fd.getFile();
	if(!filepath.toLowerCase().endsWith(".mov")) {
		filepath += ".mov";
	}
	return new File(filepath);
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:17,代碼來源:ScreenCaptureDemo.java

示例3: browseForFile

import java.awt.FileDialog; //導入方法依賴的package包/類
/** If invoked from within a Frame: this pulls up a FileDialog to
 * browse for a file. If this is invoked from a secure applet: then
 * this will throw an exception.
 * 
 * @param ext an optional list of extensions
 * @return a File, or null if the user declined to select anything.
 */
public File browseForFile(String... ext) {
	Window w = SwingUtilities.getWindowAncestor(this);
	if(!(w instanceof Frame))
		throw new IllegalStateException();
	Frame frame = (Frame)w;
	FileDialog fd = new FileDialog(frame);
	if(ext!=null && ext.length>0 && (!(ext.length==1 && ext[0]==null)))
		fd.setFilenameFilter(new SuffixFilenameFilter(ext));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	String d = fd.getFile();
	if(d==null) return null;
	return new File(fd.getDirectory()+fd.getFile());
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:23,代碼來源:ImageQuantizationDemo.java

示例4: loadJar

import java.awt.FileDialog; //導入方法依賴的package包/類
public void loadJar() throws IOException {
	FileDialog fd = new FileDialog(new Frame());
	fd.setFilenameFilter(new SuffixFilenameFilter("jar"));
	fd.pack();
	fd.setVisible(true);
	if(fd.getFile()==null) return;
	File jarFile = new File(fd.getDirectory()+fd.getFile());
	try(ZipFile zf = new ZipFile(jarFile)) {
		try(InputStream in = zf.getInputStream(new ZipEntry(KEY_SETUP_ENTRY))) {
			if(in==null) throw new IOException("This jar does not appear to be built with a recent version of JarWriterApp.");
			ContainerProperties p = new ContainerProperties();
			p.load(in);
			p.install(getContentPane(), null);
		}
		zf.close();
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:18,代碼來源:JarWriterApp.java

示例5: create

import java.awt.FileDialog; //導入方法依賴的package包/類
public static KeyStoreEditor create(Frame parentWindow) {
	KeyStoreEditor editor = new KeyStoreEditor();
	String dialogTitle = "Create Keystore";
	Icon icon = QDialog.getIcon(QDialog.PLAIN_MESSAGE);
	QDialog.showDialog(parentWindow, dialogTitle, icon, editor, editor.footer, true, null, null);
	JComponent button = editor.footer.getLastSelectedComponent();
	if( button==editor.footer.getButton(DialogFooter.OK_OPTION) ) {
		FileDialog fd = new FileDialog(parentWindow, "Create Keystore", FileDialog.SAVE);
		fd.setFilenameFilter(new SuffixFilenameFilter("jks"));
		fd.setFile("keystore.jks");
		fd.pack();
		fd.setLocationRelativeTo(null);
		fd.setVisible(true);
		if(fd.getFile()==null)
			return null;
		editor.jksFile = new File(fd.getDirectory()+fd.getFile());
		editor.create(false);
		return editor;
	} else {
		return null;
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:23,代碼來源:KeyStoreEditor.java

示例6: main

import java.awt.FileDialog; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private static void main(String[] s) {
	try {
		JFrame frame = new JFrame();
		FileDialog fd = new FileDialog(frame);
		fd.setFilenameFilter(new SuffixFilenameFilter("wav", "wave"));
		fd.pack();
		fd.setVisible(true);
		if(fd.getFile()==null) return;
		File wavFile = new File(fd.getDirectory()+fd.getFile());
		FileInputStream in = null;
		try {
			in = new FileInputStream(wavFile);
			System.err.println("length: " + wavFile.length());
			WavCopier r = new WavCopier(in);
		} finally {
			in.close();
		}
		System.exit(0);
	} catch(IOException e) {
		e.printStackTrace();
		System.exit(1);
	}
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:25,代碼來源:WavCopier.java

示例7: actionPerformed

import java.awt.FileDialog; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog fileDialog = new FileDialog(ImageViewerGui.getMainFrame(), "Choose a file", FileDialog.LOAD);
    // does not work on Windows
    fileDialog.setFilenameFilter(new AllFilenameFilter());
    fileDialog.setMultipleMode(true);
    fileDialog.setDirectory(Settings.getSingletonInstance().getProperty("default.local.path"));
    fileDialog.setVisible(true);

    String directory = fileDialog.getDirectory();
    File[] fileNames = fileDialog.getFiles();
    if (fileNames.length > 0 && directory != null) {
        // remember the current directory for future
        Settings.getSingletonInstance().setProperty("default.local.path", directory);
        Settings.getSingletonInstance().save("default.local.path");
        for (File fileName : fileNames) {
            if (fileName.isFile())
                Load.image.get(fileName.toURI());
        }
    }
}
 
開發者ID:Helioviewer-Project,項目名稱:JHelioviewer-SWHV,代碼行數:22,代碼來源:OpenLocalFileAction.java

示例8: actionPerformed

import java.awt.FileDialog; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog fileDialog = new FileDialog(ImageViewerGui.getMainFrame(), "Choose a file", FileDialog.LOAD);
    // does not work on Windows
    fileDialog.setFilenameFilter(new JsonFilenameFilter());
    fileDialog.setMultipleMode(true);
    fileDialog.setDirectory(Settings.getSingletonInstance().getProperty("default.local.path"));
    fileDialog.setVisible(true);

    String directory = fileDialog.getDirectory();
    File[] fileNames = fileDialog.getFiles();
    if (fileNames.length > 0 && directory != null) {
        // remember the current directory for future
        Settings.getSingletonInstance().setProperty("default.local.path", directory);
        Settings.getSingletonInstance().save("default.local.path");
        for (File fileName : fileNames) {
            if (fileName.isFile())
                Load.timeline.get(fileName.toURI());
        }
    }
}
 
開發者ID:Helioviewer-Project,項目名稱:JHelioviewer-SWHV,代碼行數:22,代碼來源:OpenLocalFileAction.java

示例9: loadDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
void loadDialog() {
    FileDialog fd = new FileDialog(visual.frame, "Choose a file", FileDialog.LOAD);
    fd.setFilenameFilter(sf.getLoadFilenameFilter());
    fd.setFile("*");
    fd.setVisible(true);
    if (fd.getFiles().length == 0) {
        return;
    }
    File f = fd.getFiles()[0];
    try {
        if (f.exists()) {
            importFile(f);
            visual.init(2);
        } else {
            JOptionPane.showMessageDialog(visual.frame, f.getName() + " does not exist");
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(visual.frame, "error loading " + f.getName() + ": " + ex);
    }
}
 
開發者ID:habo,項目名稱:stickes,代碼行數:21,代碼來源:Files.java

示例10: saveDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
void saveDialog(String text) {
    try {
        FileDialog fd = new FileDialog(visual.frame, text, FileDialog.SAVE);
        fd.setFilenameFilter(sf.getSaveFilenameFilter());
        fd.setVisible(true);
        if (fd.getFiles().length == 0) {
            return;
        }
        sf.save(fd.getFiles()[0], visual.getStichData());

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(visual.frame, "error during save: " + ex.getMessage());
        Logger
                .getLogger(Visual.class
                        .getName()).log(Level.SEVERE, null, ex);
    }
}
 
開發者ID:habo,項目名稱:stickes,代碼行數:18,代碼來源:Files.java

示例11: showFileDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
/**
 * Displays a standard AWT file dialog for choosing a file for loading or
 * saving.
 * 
 * @param frame
 *            parent frame
 * @param title
 *            dialog title
 * @param path
 *            base directory (or null)
 * @param filter
 *            a FilenameFilter implementation (or null)
 * @param mode
 *            either FileUtils.LOAD or FileUtils.SAVE
 * @return path to chosen file or null, if user has canceled
 */
public static String showFileDialog(final Frame frame, final String title,
        String path, FilenameFilter filter, final int mode) {
    String fileID = null;
    FileDialog fd = new FileDialog(frame, title, mode);
    if (path != null) {
        fd.setDirectory(path);
    }
    if (filter != null) {
        fd.setFilenameFilter(filter);
    }
    fd.setVisible(true);
    if (fd.getFile() != null) {
        fileID = fd.getFile();
        fileID = fd.getDirectory() + fileID;
    }
    return fileID;
}
 
開發者ID:postspectacular,項目名稱:toxiclibs,代碼行數:34,代碼來源:FileUtils.java

示例12: open

import java.awt.FileDialog; //導入方法依賴的package包/類
public void open() {
	final FileDialog openDialog = new FileDialog(this);
	openDialog.setDirectory(Preferences.getInstance().getOpenPath());
	openDialog.setMode(FileDialog.LOAD);
	openDialog.setFilenameFilter(new FilenameFilter() {
		public boolean accept(File dir, String name) {
			String[] supportedFiles = { "PGM", "pgm" };
			for (int i = 0; i < supportedFiles.length; i++) {
				if (name.endsWith(supportedFiles[i])) {
					return true;
				}
			}
			return false;
		}
	});
	openDialog.setVisible(true);
	Preferences.getInstance().setOpenPath(openDialog.getDirectory());
	if (openDialog.getDirectory() != null && openDialog.getFile() != null) {
		String filePath = openDialog.getDirectory() + openDialog.getFile();
		System.out.println(filePath);
		final File pgmFile = new File(filePath);
		final MainFrame newFrame = new MainFrame(pgmFile);
		newFrame.show();
	}
}
 
開發者ID:cyriux,項目名稱:mpcmaid,代碼行數:26,代碼來源:MainFrame.java

示例13: ReadFileButton

import java.awt.FileDialog; //導入方法依賴的package包/類
/**
 * Constructs a button for reading in a music file.
 *
 * @param owner {@link Frame} which is the owner of this button.  Access to
 *              this <CODE>Frame</CODE> will be suspended when the user is
 *              selecting a music file and when error messages are
 *              displayed.
 */
public ReadFileButton(final Frame owner) {
    super("Read File");
    final FileDialog load = new FileDialog(owner,
            "Select a Midi or jMusic file to import",
            FileDialog.LOAD);
    load.setFilenameFilter(new ReadFilenameFilter());

    addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            load.show();

            Score score = Read.midiOrJmWithAWTMessaging(load.getDirectory(),
                                                        load.getFile(),
                                                        owner); 
            if (score == null) {
                return;
            }
            if (readListenerList != null) {
                score = readListenerList.scoreRead(score);
                readListenerList.finishedReading();
            }
        }
    }
    );
}
 
開發者ID:Impro-Visor,項目名稱:Impro-Visor,代碼行數:34,代碼來源:ReadFileButton.java

示例14: actionPerformed

import java.awt.FileDialog; //導入方法依賴的package包/類
public void actionPerformed( ActionEvent e ) {
    Object source = e.getSource();
    if ( source == quitMI ) {
        quit();
    }
    else if ( source == optionsMI ) {
        preferences();
    }
    else if ( source == aboutMI ) {
        about();
    }
    else if ( source == openMI ) {
        // File:Open action shows a FileDialog for loading displayable images
        FileDialog openDialog = new FileDialog( this );
        openDialog.setMode( FileDialog.LOAD );
        openDialog.setFilenameFilter( new FilenameFilter() {
            public boolean accept( File dir, String name ) {
                String[] supportedFiles = ImageIO.getReaderFormatNames();
                for ( int i = 0; i < supportedFiles.length; i++ ) {
                    if ( name.endsWith( supportedFiles[i] ) ) {
                        return true;
                    }
                }
                return false;
            }
        } );
        openDialog.setVisible( true );
        String filePath = openDialog.getDirectory() + openDialog.getFile();
        if ( filePath != null ) {
            loadImageFile( filePath );
        }
    }
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:34,代碼來源:MyApp.java

示例15: showOpenDialog

import java.awt.FileDialog; //導入方法依賴的package包/類
public static File showOpenDialog(Frame f,String title,String... extensions) {
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.LOAD);
	if(extensions!=null && extensions.length>0)
		fd.setFilenameFilter(new SuffixFilenameFilter(extensions));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	if(fd.getFile()==null)
		return null;
	return new File(fd.getDirectory() + fd.getFile());
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:13,代碼來源:FileDialogUtils.java


注:本文中的java.awt.FileDialog.setFilenameFilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。