Java Code Examples for javax.swing.filechooser.FileNameExtensionFilter

The following examples show how to use javax.swing.filechooser.FileNameExtensionFilter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: ios-image-util   Source File: MainFrame.java    License: MIT License 6 votes vote down vote up
/**
 * Load properties from choosen file.
 */
private void loadProperties() {
	JFileChooser chooser = new JFileChooser();
	chooser.setFileFilter(new FileNameExtensionFilter("Properties XML files", "xml"));
	chooser.setApproveButtonText(getResource("button.approve", "Choose"));
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	if (propertiesFile != null) {
		chooser.setCurrentDirectory(propertiesFile.getParentFile());
	} else {
		File dir = IOSImageUtil.getDefaultDirectory(this);
		if (dir == null) {
			dir = getChosenDirectory();
		}
		if (dir != null) {
			chooser.setCurrentDirectory(dir);
		}
	}
	int returnVal = chooser.showOpenDialog(this);
	if(returnVal == JFileChooser.APPROVE_OPTION) {
		loadProperties(chooser.getSelectedFile());
    }
}
 
Example 2
Source Project: buffer_bci   Source File: ChartPanel.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart
 * in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
public void doSaveAs() throws IOException {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs);
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
                localizationResources.getString("PNG_Image_Files"), "png");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);

    int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getPath();
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
                getWidth(), getHeight());
    }
}
 
Example 3
Source Project: Wurst7   Source File: ForceOpDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void browsePwList()
{
	JFileChooser fsTXTList = new JFileChooser();
	fsTXTList.setAcceptAllFileFilterUsed(false);
	fsTXTList.addChoosableFileFilter(
		new FileNameExtensionFilter("TXT files", new String[]{"txt"}));
	fsTXTList.setFileSelectionMode(JFileChooser.FILES_ONLY);
	
	int action = fsTXTList.showOpenDialog(this);
	if(action != JFileChooser.APPROVE_OPTION)
		return;
	
	if(!fsTXTList.getSelectedFile().exists())
	{
		JOptionPane.showMessageDialog(this, "File does not exist!", "Error",
			JOptionPane.ERROR_MESSAGE);
		return;
	}
	
	String pwList = fsTXTList.getSelectedFile().getPath();
	System.out.println("list " + pwList);
}
 
Example 4
Source Project: mzmine3   Source File: EChartPanel.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
@Override
public void doSaveAs() throws IOException {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setCurrentDirectory(this.getDefaultDirectoryForSaveAs());
  FileNameExtensionFilter filter =
      new FileNameExtensionFilter(localizationResources.getString("PNG_Image_Files"), "png");
  fileChooser.addChoosableFileFilter(filter);
  fileChooser.setFileFilter(filter);

  int option = fileChooser.showSaveDialog(this);
  if (option == JFileChooser.APPROVE_OPTION) {
    String filename = fileChooser.getSelectedFile().getPath();
    if (isEnforceFileExtensions()) {
      if (!filename.endsWith(".png")) {
        filename = filename + ".png";
      }
    }
    ChartUtils.saveChartAsPNG(new File(filename), getChart(), getWidth(), getHeight(),
        getChartRenderingInfo());
  }
}
 
Example 5
Source Project: ghidra   Source File: ScreenshotPlugin.java    License: Apache License 2.0 6 votes vote down vote up
private File getFile(String fileName) {
	if (fileChooser == null) {
		fileChooser = new JFileChooser();
		fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
		fileChooser.setDialogTitle("Save Image");
		fileChooser.setFileFilter(new FileNameExtensionFilter("Portable Network Graphics",
			"png"));
	}

	File selectedFile = new File(fileName);
	fileChooser.setSelectedFile(selectedFile);
	if (fileChooser.showSaveDialog(tool.getToolFrame()) == JFileChooser.APPROVE_OPTION) {
		File file = fileChooser.getSelectedFile();
		if (file != null && !file.getName().endsWith(".png")) {
			// force the png extension
			return new File(file.getParentFile(), file.getName() + ".png");
		}
		return file;
	}

	return null;
}
 
Example 6
Source Project: mylizzie   Source File: Lizzie.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void loadGameByPrompting() {
    FileNameExtensionFilter filter = new FileNameExtensionFilter("*.sgf", "SGF");
    final JFileChooser chooser = new JFileChooser(optionSetting.getLastChooserLocation());
    chooser.addChoosableFileFilter(filter);
    chooser.setMultiSelectionEnabled(false);
    chooser.setAcceptAllFileFilterUsed(false);

    setFileChooserAutoFocusOnTextField(chooser);

    int state = chooser.showOpenDialog(frame);
    if (state == JFileChooser.APPROVE_OPTION) {
        optionSetting.setLastChooserLocation(chooser.getSelectedFile().toPath().getParent().toString());

        File file = chooser.getSelectedFile();
        if (!file.getPath().toLowerCase().endsWith(".sgf")) {
            file = new File(file.getPath() + ".sgf");
        }

        loadGameByFile(file.toPath());
    }
}
 
Example 7
Source Project: silex-idea-plugin   Source File: ContainerStatusBarWidget.java    License: MIT License 6 votes vote down vote up
@Nullable
@Override
public Consumer<MouseEvent> getClickConsumer() {
    return new Consumer<MouseEvent>() {
        @Override
        public void consume(MouseEvent mouseEvent) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Pimple Definition File", "json"));
            fileChooser.setCurrentDirectory(new File(project.getBasePath()));

            int returnValue = fileChooser.showOpenDialog(null);
            if (returnValue == JFileChooser.APPROVE_OPTION) {
                Configuration.getInstance(project).containerDefinitionFileName = fileChooser.getSelectedFile().getAbsolutePath();
                ProjectComponent.configChanged(project);
            }
        }
    };
}
 
Example 8
private void chooseImage()
{
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("请选择图片");
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileFilter(new FileNameExtensionFilter("图像", "jpg", "jpeg", "png", "JPG", "JPEG", "PNG"));

    fileChooser.showDialog(MainFrame.getContext(), "上传");
    if (fileChooser.getSelectedFile() != null)
    {
        selectedFile = fileChooser.getSelectedFile();

        String extension = selectedFile.getName();
        if (!extension.endsWith(".jpg") && !extension.endsWith(".jpeg") && !extension.endsWith(".png")
        		 && !extension.endsWith(".JPG") && !extension.endsWith(".JPEG") && !extension.endsWith(".PNG"))
        {
            JOptionPane.showMessageDialog(MainFrame.getContext(), "请选择图像文件", "文件类型不正确", JOptionPane.WARNING_MESSAGE);
            return;
        }

        openImage(selectedFile);

    }
}
 
Example 9
Source Project: mzmine2   Source File: TICVisualizerWindow.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Export a file's chromatogram.
 *
 * @param file the file.
 */
public void exportChromatogram(RawDataFile file) {

  // Get the data set.
  final TICDataSet dataSet = ticDataSets.get(file);
  if (dataSet != null) {

    // Create the chooser if necessary.
    if (exportChooser == null) {

      exportChooser = new LoadSaveFileChooser("Select Chromatogram File");
      exportChooser.addChoosableFileFilter(
          new FileNameExtensionFilter("Comma-separated values files", CSV_EXTENSION));
    }

    // Choose an export file.
    final File exportFile = exportChooser.getSaveFile(this, file.getName(), CSV_EXTENSION);
    if (exportFile != null) {

      MZmineCore.getTaskController().addTask(new ExportChromatogramTask(dataSet, exportFile));
    }
  }
}
 
Example 10
Source Project: Digital   Source File: GraphDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser fileChooser = new MyFileChooser();

    ElementAttributes settings = Settings.getInstance().getAttributes();
    File exportDir = settings.getFile("exportDirectory");
    if (exportDir != null)
        fileChooser.setCurrentDirectory(exportDir);


    fileChooser.setFileFilter(new FileNameExtensionFilter("SVG", "svg"));
    new SaveAsHelper(GraphDialog.this, fileChooser, "svg")
            .checkOverwrite(file -> {
                settings.setFile("exportDirectory", file.getParentFile());
                try (Graphic gr = factory.create(new FileOutputStream(file))) {
                    GraphicMinMax minMax = new GraphicMinMax();
                    graphComponent.getPlotter().drawTo(minMax, null);
                    gr.setBoundingBox(minMax.getMin(), minMax.getMax());
                    graphComponent.getPlotter().drawTo(gr, null);
                }
            });
}
 
Example 11
Source Project: CyberSecurity   Source File: PictureEdit.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Opens a file by opening a JFileChooser which allows the user to select
 * the file they would like to open.
 *
 * @return true if the file successfully opened, false otherwise.
 */

public boolean open()
{
JFileChooser chooser = new JFileChooser(".");
  	FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG Images", "png");
   chooser.setFileFilter(filter);
   int returnVal = chooser.showOpenDialog(null);
   if(returnVal == JFileChooser.APPROVE_OPTION) {
	try{
		File file = chooser.getSelectedFile();
		image = ImageIO.read(file);
		revertImage = copyImage(image);
	}
	catch(Exception e){
		return false;
	}

	return true;
   }
   else
   {
   	return false;
   }
}
 
Example 12
Source Project: BART   Source File: MainMemoryPanel.java    License: MIT License 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    File home = new File(System.getProperty("user.home"));
    File toLoad = new FileChooserBuilder(" 'Instance/Schema' XML File")
                                .setTitle("Choose File")
                                .setDefaultWorkingDirectory(home)
                                .setApproveText("OK")
                                .setAcceptAllFileFilterUsed(false)
                                .addFileFilter(new FileNameExtensionFilter("XML import file", "xml","XML"))
                                .showOpenDialog();
                
        if(toLoad==null){
            return;
        }
        FileObject fo = FileUtil.toFileObject(toLoad);
        if(fo.isFolder()){
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Select 'file.xml' no folder", NotifyDescriptor.INFORMATION_MESSAGE));
            return;
        }
        field.setText(fo.getPath());
}
 
Example 13
private void loadFile() {
	JFileChooser fileChooser = new JFileChooser();

	FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
	fileChooser.addChoosableFileFilter(filter);
	fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
	fileChooser.setFileFilter(filter);

	if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
	} else {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath()));
	}
	int result = fileChooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return;
	try {
		String exportString = fileChooser.getSelectedFile().toString();
		browseText.setText(exportString);
		internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
		internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
	}
	catch (Exception e) {
		//
	}
}
 
Example 14
Source Project: openprodoc   Source File: MainWin.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Returns the path of a selected file.
 * @param RecomFileName default name
 * @param Ext Default extension for the type
 * @param Save indicates if selecting an existing file or destination for saving a new one.
 * @return
 */
static public String SelectDestination(String RecomFileName, String Ext, boolean Save)
{
JFileChooser fc = new JFileChooser(getIO_OSFolder());
if (Ext!=null)
    fc.setFileFilter(new FileNameExtensionFilter("file "+Ext, Ext));
if (RecomFileName!=null)
    fc.setSelectedFile(new File(RecomFileName));
if (!Save)
    {
    if (fc.showOpenDialog(null)!=JFileChooser.APPROVE_OPTION)
        return("");
    }
else
    {
    if (fc.showSaveDialog(null)!=JFileChooser.APPROVE_OPTION)
        return("");
    }
setIO_OSFolder(fc.getSelectedFile().getParent());
return(fc.getSelectedFile().getAbsolutePath());
}
 
Example 15
Source Project: jadx   Source File: MainWindow.java    License: Apache License 2.0 6 votes vote down vote up
public void openFileOrProject() {
	JFileChooser fileChooser = new JFileChooser();
	fileChooser.setAcceptAllFileFilterUsed(true);
	String[] exts = { JadxProject.PROJECT_EXTENSION, "apk", "dex", "jar", "class", "smali", "zip", "aar", "arsc" };
	String description = "supported files: " + Arrays.toString(exts).replace('[', '(').replace(']', ')');
	fileChooser.setFileFilter(new FileNameExtensionFilter(description, exts));
	fileChooser.setToolTipText(NLS.str("file.open_action"));
	Path currentDirectory = settings.getLastOpenFilePath();
	if (currentDirectory != null) {
		fileChooser.setCurrentDirectory(currentDirectory.toFile());
	}
	int ret = fileChooser.showDialog(mainPanel, NLS.str("file.open_title"));
	if (ret == JFileChooser.APPROVE_OPTION) {
		settings.setLastOpenFilePath(fileChooser.getCurrentDirectory().toPath());
		open(fileChooser.getSelectedFile().toPath());
	}
}
 
Example 16
private void loadFile() {
	JFileChooser fileChooser = new JFileChooser();

	FileNameExtensionFilter filter = new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
	fileChooser.addChoosableFileFilter(filter);
	fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
	fileChooser.setFileFilter(filter);

	if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
	} else {
		fileChooser.setCurrentDirectory(new File(internalBalloon.getBalloonContentPath().getStandardPath()));
	}
	int result = fileChooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return;
	try {
		String exportString = fileChooser.getSelectedFile().toString();
		browseText.setText(exportString);
		internalBalloon.getBalloonContentPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
		internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
	}
	catch (Exception e) {
		//
	}
}
 
Example 17
Source Project: snap-desktop   Source File: OperatorMenu.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    JFileChooser fileChooser = new JFileChooser();
    FileNameExtensionFilter parameterFileFilter = createParameterFileFilter();
    fileChooser.addChoosableFileFilter(parameterFileFilter);
    fileChooser.setFileFilter(parameterFileFilter);
    fileChooser.setDialogTitle(TITLE);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    applyCurrentDirectory(fileChooser);
    int response = fileChooser.showDialog(parentComponent, "Load");
    if (JFileChooser.APPROVE_OPTION == response) {
        try {
            preserveCurrentDirectory(fileChooser);
            readFromFile(fileChooser.getSelectedFile());
        } catch (Exception e) {
            Debug.trace(e);
            AbstractDialog.showErrorDialog(parentComponent, "Could not load parameters.\n" + e.getMessage(), TITLE);
        }
    }
}
 
Example 18
Source Project: Digital   Source File: Main.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static JFileChooser getJFileChooser(File filename) {
    File folder = null;
    if (filename != null)
        folder = filename.getParentFile();

    JFileChooser fileChooser = new MyFileChooser(folder);
    fileChooser.setFileFilter(new FileNameExtensionFilter("Circuit", "dig"));
    return fileChooser;
}
 
Example 19
Source Project: Compressor   Source File: ZipDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
private File getSelectedArchiverFile(FileNameExtensionFilter filter) {
	JFileChooser o = new JFileChooser(".");
	o.setFileSelectionMode(JFileChooser.FILES_ONLY);
	o.setMultiSelectionEnabled(false);
	o.addChoosableFileFilter(filter);
	int returnVal = o.showOpenDialog(this);
	if (returnVal != JFileChooser.APPROVE_OPTION) {
		return null;
	}
	return o.getSelectedFile();
}
 
Example 20
Source Project: darklaf   Source File: FileChooserDemo.java    License: MIT License 5 votes vote down vote up
public static void main(final String[] args) {
    SwingUtilities.invokeLater(() -> {
        LafManager.install(ComponentDemo.getTheme());
        JFileChooser chooser = new JFileChooser(System.getProperty("user.home"));
        chooser.addChoosableFileFilter(new FileNameExtensionFilter("Test Filter", ".svg"));
        chooser.setMultiSelectionEnabled(true);
        chooser.showOpenDialog(null);
    });
}
 
Example 21
Source Project: finmath-lib   Source File: FPMLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This main method will prompt the user for a test file an run the test with the given file.
 *
 * @param args Arguments - not used.
 * @throws ParserConfigurationException Thrown by the parser.
 * @throws IOException Thrown, e.g., if the file could not be opened.
 * @throws SAXException Thrown by the XML parser.
 */
public static void main(final String[] args) throws SAXException, IOException, ParserConfigurationException
{
	final JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	jfc.setDialogTitle("Choose XML");
	jfc.setFileFilter(new FileNameExtensionFilter("FIPXML (.xml)", "xml"));
	if(jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
		System.exit(1);
	}

	(new FPMLParserTest(jfc.getSelectedFile())).testGetSwapProductDescriptor();
}
 
Example 22
Source Project: scelight   Source File: RepFiltersEditorDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent event ) {
 final XFileChooser fc = new XFileChooser( SAVE_FOLDER );
 fc.setDialogTitle( "Choose a file to save Replay Filters" );
 fc.setFileFilter( new FileNameExtensionFilter( "Replay Filter files (*."
         + REP_FILTERS_FILE_EXT + ')', REP_FILTERS_FILE_EXT ) );
 
 // Suggested file name
 fc.setSelectedFile( Utils.uniqueFile(
         SAVE_FOLDER.resolve( "replay-filters." + REP_FILTERS_FILE_EXT ) ).toFile() );
 
 if ( XFileChooser.APPROVE_OPTION != fc.showSaveDialog( RepFiltersEditorDialog.this ) )
  return;
 Path path = fc.getSelectedPath();
 // Ensure proper extension
 if ( !path.getFileName().toString().toLowerCase().endsWith( '.' + REP_FILTERS_FILE_EXT ) )
  path = path.resolveSibling( path.getFileName().toString() + '.'
          + REP_FILTERS_FILE_EXT );
 if ( Files.exists( path ) )
  if ( !GuiUtils.confirm( "The selected file already exists?", "Overwrite it?" ) )
   return;
 
 try {
  JAXB.marshal( repFiltersBean, path.toFile() );
 } catch ( final Exception e ) {
  Env.LOGGER.error( "Failed to write to file: " + path, e );
  GuiUtils.showErrorMsg( "Failed to write to file:", path );
 }
}
 
Example 23
private File chooseFile() {
  JFileChooser chooser = new JFileChooser();

  FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT & CSV files", "txt", "csv");
  chooser.setDialogTitle("Please select a file containing project parameter values for files.");
  chooser.setFileFilter(filter);
  int returnVal = chooser.showOpenDialog(desktop.getMainWindow());
  if (returnVal == JFileChooser.CANCEL_OPTION) {
    return null;
  }

  return chooser.getSelectedFile();
}
 
Example 24
Source Project: openAGV   Source File: StatisticsPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new StatisticsPanel.
 */
public StatisticsPanel() {
  initComponents();

  inputFileChooser.setMultiSelectionEnabled(false);
  inputFileChooser.setFileFilter(new FileNameExtensionFilter(BUNDLE.getString("statisticsPanel.fileChooser_inputFile.fileFilter.description"),
                                                             "txt"));
}
 
Example 25
Source Project: PacketProxy   Source File: SampleItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void action() throws Exception{
	JFileChooser saveFile = new JFileChooser("packet.dat");
	saveFile.setAcceptAllFileFilterUsed(false);
	saveFile.addChoosableFileFilter(new FileNameExtensionFilter("データファイル (.dat)", "dat"));
	saveFile.showSaveDialog((JFrame) this.dependentData.get("main_frame"));
	File file = saveFile.getSelectedFile();
	GUIPacket gui_packet = (GUIPacket) this.dependentData.get("gui_packet");
	byte[] data = gui_packet.getPacket().getReceivedData();
	FileUtils.writeByteArrayToFile(file, data);
	JOptionPane.showMessageDialog((JFrame) this.dependentData.get("main_frame"), String.format("%sに保存しました!", file.getPath()));
	
}
 
Example 26
Source Project: importer-exporter   Source File: KmlExportPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void saveFile() {
	JFileChooser fileChooser = new JFileChooser();

	FileNameExtensionFilter filter = new FileNameExtensionFilter("KML Files (*.kml, *.kmz)", "kml", "kmz");
	fileChooser.addChoosableFileFilter(filter);
	fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
	fileChooser.setFileFilter(filter);

	if (config.getProject().getKmlExporter().getPath().isSetLastUsedMode()) {
		fileChooser.setCurrentDirectory(new File(config.getProject().getKmlExporter().getPath().getLastUsedPath()));
	} else {
		fileChooser.setCurrentDirectory(new File(config.getProject().getExporter().getPath().getStandardPath()));
	}
	int result = fileChooser.showSaveDialog(getTopLevelAncestor());
	if (result == JFileChooser.CANCEL_OPTION) return;
	try {
		String exportString = fileChooser.getSelectedFile().toString();
		if (exportString.lastIndexOf('.') != -1	&&
				exportString.lastIndexOf('.') > exportString.lastIndexOf(File.separator)) {
			exportString = exportString.substring(0, exportString.lastIndexOf('.'));
		}
		exportString = config.getProject().getKmlExporter().isExportAsKmz() ?
				exportString + ".kmz":
					exportString + ".kml";

		browseText.setText(exportString);
		config.getProject().getKmlExporter().getPath().setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
	}
	catch (Exception e) {
		//
	}
}
 
Example 27
Source Project: SubTitleSearcher   Source File: MainWinJsApp.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 选择视频文件
 * @return
 */
public boolean openMovFile() {
	JFileChooser jfc = new JFileChooser();
	
	jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
	FileNameExtensionFilter filter = new FileNameExtensionFilter(
			"视频文件(*.mkv; *mp4; *.mov; *.avi; *.ts)", "mkv", "mp4", "mov", "avi", "ts");
	jfc.setFileFilter(filter);
	if(MovFileInfo.lastSelPath!=null) {
		jfc.setCurrentDirectory(new File(MovFileInfo.lastSelPath));
	}
	int status = jfc.showDialog(new JLabel(), "选择视频文件");
	
	if(JFileChooser.APPROVE_OPTION == status) {
		File file = jfc.getSelectedFile();
		if (file != null && file.isFile()) {
			String filepath = file.getAbsolutePath();
			if(file.isDirectory()) {
				alert("请选择有效的视频文件");
				return false;
			}
			MovFileInfo.setFile(filepath);
			return true;
		}
	}else if(JFileChooser.ERROR_OPTION == status) {
		alert("选择文件失败");
		return false;
	}
	return false;
}
 
Example 28
Source Project: Wurst7   Source File: ImportAltsFileChooser.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args)
{
	SwingUtils.setLookAndFeel();
	JFileChooser fileChooser = new ImportAltsFileChooser(new File(args[0]));
	
	fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.addChoosableFileFilter(
		new FileNameExtensionFilter("TXT file (username:password)", "txt"));
	
	if(fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
		return;
	
	File file = fileChooser.getSelectedFile();
	try
	{
		for(String line : Files.readAllLines(file.toPath()))
			System.out.println(line);
		
	}catch(IOException e)
	{
		e.printStackTrace();
		StringWriter writer = new StringWriter();
		e.printStackTrace(new PrintWriter(writer));
		String message = writer.toString();
		JOptionPane.showMessageDialog(fileChooser, message, "Error",
			JOptionPane.ERROR_MESSAGE);
	}
}
 
Example 29
private FileFilter createFileFilter(String description,
        boolean showExtensionInDescription, String... extensions) {
    if (showExtensionInDescription) {
        description = createFileNameFilterDescriptionFromExtensions(
                description, extensions);
    }
    return new FileNameExtensionFilter(description, extensions);
}
 
Example 30
private FileFilter createFileFilter(String description,
        boolean showExtensionInDescription, String... extensions) {
    if (showExtensionInDescription) {
        description = createFileNameFilterDescriptionFromExtensions(
                description, extensions);
    }
    return new FileNameExtensionFilter(description, extensions);
}