javax.swing.filechooser.FileNameExtensionFilter Java Examples

The following examples show how to use javax.swing.filechooser.FileNameExtensionFilter. 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 check out the related API usage on the sidebar.
Example #1
Source File: ForceOpDialog.java    From Wurst7 with GNU General Public License v3.0 7 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 #2
Source File: OperatorMenu.java    From snap-desktop with 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 #3
Source File: ChartPanel.java    From buffer_bci with 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 #4
Source File: EChartPanel.java    From mzmine3 with 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 File: ScreenshotPlugin.java    From ghidra with 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 File: Lizzie.java    From mylizzie with 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 File: ContainerStatusBarWidget.java    From silex-idea-plugin with 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
Source File: ChangeAvatarPanel.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
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 File: TICVisualizerWindow.java    From mzmine2 with 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 File: PictureEdit.java    From CyberSecurity with 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 #11
Source File: MainMemoryPanel.java    From BART with 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 #12
Source File: TransportationBalloonPanel.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
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 #13
Source File: MainWin.java    From openprodoc with 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 #14
Source File: MainWindow.java    From jadx with 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 #15
Source File: CityObjectGroupBalloonPanel.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
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 #16
Source File: MainFrame.java    From ios-image-util with 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 #17
Source File: GraphDialog.java    From Digital with 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 #18
Source File: ExportToPNGAction.java    From orson-charts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Writes the content of the panel to a PNG image, using Java's ImageIO.
 * 
 * @param e  the event.
 */
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser fileChooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
        Resources.localString("PNG_FILE_FILTER_DESCRIPTION"), "png");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);

    int option = fileChooser.showSaveDialog(this.panel);
    if (option == JFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getPath();
        if (!filename.endsWith(".png")) {
            filename = filename + ".png";
        }
        Dimension2D size = this.panel.getSize();
        int w = (int) size.getWidth();
        int h = (int) size.getHeight();
        BufferedImage image = new BufferedImage(w, h, 
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = image.createGraphics();
        this.panel.getDrawable().draw(g2, new Rectangle(w, h));
        try {
            ImageIO.write(image, "png", new File(filename));
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
 
Example #19
Source File: FileChooserDemo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private FileFilter createFileFilter(String description,
        boolean showExtensionInDescription, String... extensions) {
    if (showExtensionInDescription) {
        description = createFileNameFilterDescriptionFromExtensions(
                description, extensions);
    }
    return new FileNameExtensionFilter(description, extensions);
}
 
Example #20
Source File: FileChooserDemo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private FileFilter createFileFilter(String description,
        boolean showExtensionInDescription, String... extensions) {
    if (showExtensionInDescription) {
        description = createFileNameFilterDescriptionFromExtensions(
                description, extensions);
    }
    return new FileNameExtensionFilter(description, extensions);
}
 
Example #21
Source File: ExportLipidModificationsAction.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {

  // Parent component.
  final LipidModificationChoiceComponent parent =
      (LipidModificationChoiceComponent) SwingUtilities
          .getAncestorOfClass(LipidModificationChoiceComponent.class, (Component) e.getSource());

  if (parent != null) {

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

      chooser = new LoadSaveFileChooser("Select lipid modifications File");
      chooser.addChoosableFileFilter(
          new FileNameExtensionFilter("Comma-separated values files", FILENAME_EXTENSION));
    }

    // Choose the file.
    final File file = chooser.getSaveFile(parent, FILENAME_EXTENSION);
    if (file != null) {

      // Export the modifications.
      try {

        exportLipidModificationsToFile(file, (LipidModification[]) parent.getChoices());
      } catch (IOException ex) {
        final Window window =
            (Window) SwingUtilities.getAncestorOfClass(Window.class, (Component) e.getSource());
        final String msg = "There was a problem writing the lipid modifications file.";
        MZmineCore.getDesktop().displayErrorMessage(window, "I/O Error",
            msg + "\n(" + ex.getMessage() + ')');
        LOG.log(Level.SEVERE, msg, ex);
      }
    }
  }
}
 
Example #22
Source File: ZipDialog.java    From Compressor with 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 #23
Source File: FileChooserDemo.java    From darklaf with 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 #24
Source File: FileChoosers.java    From TinkerTime with GNU General Public License v3.0 5 votes vote down vote up
public static Path chooseModZip() throws FileNotFoundException {
	JFileChooser chooser = new JFileChooser(lastZipLocation != null ? lastZipLocation.toFile() : null);
	chooser.setDialogTitle("Please select the mod zip to add.");
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);  // Only accept files
	chooser.setFileFilter(new FileNameExtensionFilter("Zip Archive", "zip"));

	return lastZipLocation = showOpenDialog(chooser);
}
 
Example #25
Source File: HotelPropertiesWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
private ActionListener addPictureListener() {
    final ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser sec = new JFileChooser();
            FileNameExtensionFilter JpegFilter = new FileNameExtensionFilter("JPG & GIF & PNG Images", "jpg", "gif", "png");
            sec.setFileFilter(JpegFilter);
            sec.setAcceptAllFileFilterUsed(false);
            sec.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int result = sec.showOpenDialog(sec);
            if (result == JFileChooser.APPROVE_OPTION) {
                try {

                    newImage = ImageIO.read(sec.getSelectedFile());

                    final int pictureWidth = 586;
                    final int pictureHeight = 218;

                    BufferedImage hotelPicture = new BufferedImage(pictureWidth, pictureHeight, newImage.getType());
                    Graphics2D g = hotelPicture.createGraphics();
                    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                    g.drawImage(newImage, 0, 0, pictureHeight, pictureHeight, null);
                    g.dispose();

                    pictlabel.setIcon(new ImageIcon(hotelPicture));
                    pictlabel.revalidate();
                    pictlabel.repaint();

                } catch (IOException e1) {
                    JOptionPane.showMessageDialog(modalFrame, "Image cannot be null !",
                            JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE);
                }
            }

        }
    };
    return listener;
}
 
Example #26
Source File: FileUtils.java    From ocr-neuralnet with GNU General Public License v3.0 5 votes vote down vote up
public static File chooseFile(Component parent, String description, String ... extensions) {
    JFileChooser fileChooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter(description, extensions);
    fileChooser.setFileFilter(filter);
    fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
    int returnVal = fileChooser.showOpenDialog(parent);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
        return fileChooser.getSelectedFile();
    } else {
        return null;
    }
}
 
Example #27
Source File: Selenium2Customizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void bUserExtensionFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bUserExtensionFileActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setFileFilter(new FileNameExtensionFilter("Javascript File", "js"));
    chooser.setSelectedFile(new File(tfUserExtensionFile.getText().trim()));
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        tfUserExtensionFile.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example #28
Source File: FPMLParserTest.java    From finmath-lib with 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 #29
Source File: ImportZIP.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages("LBL_zip_files=ZIP files")
private void zipButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zipButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new FileNameExtensionFilter(LBL_zip_files(), "zip", "jar"));
    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        zipField.setText(fc.getSelectedFile().getAbsolutePath());
        firePropertyChange("validity", null, null);
    }
}
 
Example #30
Source File: SaveAsAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    Node node = activatedNodes[0];
    FileObject fo = node.getLookup().lookup(FileObject.class);
    if (fo != null) {
        FileChooserBuilder builder = new FileChooserBuilder(SaveAsAction.class);
        builder.setDirectoriesOnly(false);
        builder.setApproveText("Save");
        builder.setControlButtonsAreShown(true);
        builder.setTitle("Save As...");
        builder.setFilesOnly(true);
        builder.setFileFilter(new FileNameExtensionFilter(fo.getExt(), fo.getExt()));
        JFileChooser chooser = builder.createFileChooser();
        chooser.setSelectedFile(new File(fo.getNameExt()));
        int resp = chooser.showSaveDialog(findDialogParent());
        if (JFileChooser.APPROVE_OPTION == resp) {
            File saveFile = chooser.getSelectedFile();
            if (saveFile != null) {
                try {
                    saveFile.getParentFile().mkdirs();
                    FileObject dfo = FileUtil.toFileObject(saveFile.getParentFile());
                    if (dfo == null) {
                        NotifyDescriptor nd = new NotifyDescriptor.Message("Unable to Save file!", NotifyDescriptor.ERROR_MESSAGE);
                        DialogDisplayer.getDefault().notifyLater(nd);
                        return;
                    }
                    if (saveFile.exists()) {
                        saveFile.delete();
                    }
                    fo.copy(dfo, saveFile.getName(), "");
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}