Java Code Examples for javax.swing.JFileChooser.addChoosableFileFilter()

The following are Jave code examples for showing how to use addChoosableFileFilter() of the javax.swing.JFileChooser class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: LibraryStartVisualPanel.java   Source Code and License Vote up 7 votes
private void browseLibraryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLibraryButtonActionPerformed
    JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastChosenLibraryLocation());
    File[] olds = convertStringToFiles(txtLibrary.getText().trim());
    chooser.setSelectedFiles(olds);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(true);
    chooser.addChoosableFileFilter(new JarZipFilter());
    int ret = chooser.showDialog(this, getMessage("LBL_Select"));
    if (ret == JFileChooser.APPROVE_OPTION) {
        File[] files =  chooser.getSelectedFiles();
        if (files.length == 0) {
            return;
        }
        String path = "";
        for (int i = 0; i < files.length; i++) {
            path = path + files[i] + ( i == files.length - 1 ? "" : File.pathSeparator);
        }
        txtLibrary.setText(path);
        ModuleUISettings.getDefault().setLastChosenLibraryLocation(files[0].getParentFile().getAbsolutePath());
    }
}
 
Example 2
Project: jaer   File: RNNfilter.java   Source Code and License Vote up 6 votes
synchronized public void loadFromXML() {
    this.setProcessingEnabled(false);
    JFileChooser c = new JFileChooser(this.getLastRNNXMLFile());
    FileFilter filter = new FileNameExtensionFilter("XML File", "xml");
    c.addChoosableFileFilter(filter);
    c.setFileFilter(filter);
    c.setSelectedFile(new File(this.getLastRNNXMLFile()));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File f = c.getSelectedFile();
    try {
        this.rnnetwork.loadFromXML(f);
        this.setLastRNNXMLFile(f.toString());
        putString("lastRNNXMLFile", this.getLastRNNXMLFile());
        // this.testNumpyData.rnnetwork.loadFromXML(c.getSelectedFile()); //debug
    } catch (Exception e) {
        log.log(Level.WARNING, "Couldn't upload the xml file, please check. Caught exception {0}", e);
    }
    this.resetFilter();
}
 
Example 3
Project: Rubus   File: FileDrop.java   Source Code and License Vote up 6 votes
@Override
public void mouseClicked(MouseEvent e) {
	JFileChooser fileChooser = new JFileChooser(".");
	fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
	String[] filterArr = new String[] {
			".class", ".jar" };
	FileFilter filter = new ExtensionFileFilter(null, filterArr);
	fileChooser.addChoosableFileFilter(filter);

	int selection = fileChooser.showOpenDialog(null);
	if (selection == JFileChooser.APPROVE_OPTION) {
		if (!fileChooser.getSelectedFile().isDirectory()||!recursive) {
			File[] files = { fileChooser.getSelectedFile() };
			listener.filesDropped(files);

		} else {

			listener.filesDropped(getAllFilesArray(fileChooser
					.getSelectedFile(),filterArr));
		}
	}
	if (selection == JFileChooser.CANCEL_OPTION) {

	}

}
 
Example 4
Project: parabuild-ci   File: ChartPanel.java   Source Code and License Vote up 6 votes
/**
 * 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();
    ExtensionFileFilter filter = new ExtensionFileFilter(
            localizationResources.getString("PNG_Image_Files"), ".png");
    fileChooser.addChoosableFileFilter(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 5
Project: incubator-netbeans   File: IdeSnapshotAction.java   Source Code and License Vote up 6 votes
@NbBundle.Messages({
    "ACTION_IdeSnapshot_dialog=Load IDE Snapshot",
    "ACTION_IdeSnapshot_filter=IDE Snapshots"
})
private static JFileChooser createFileChooser(File directory) {
    JFileChooser chooser = new JFileChooser();

    chooser.setDialogTitle(Bundle.ACTION_IdeSnapshot_dialog());
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    chooser.setAcceptAllFileFilterUsed(false);
    if (directory != null) {
        chooser.setCurrentDirectory(directory);
    }
    
    String descr = Bundle.ACTION_IdeSnapshot_filter();
    String ext = "."+ResultsManager.STACKTRACES_SNAPSHOT_EXTENSION; // NOI18N
    Filter filter = Filter.create(descr, ext);
    chooser.addChoosableFileFilter(filter);

    return chooser;
}
 
Example 6
Project: incubator-netbeans   File: ExportSnapshotAction.java   Source Code and License Vote up 6 votes
private static JFileChooser createFileChooser() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogTitle(Bundle.ExportSnapshotAction_FileChooserCaption());
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setApproveButtonText(Bundle.ExportSnapshotAction_ExportButtonText());
    fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.addChoosableFileFilter(new FileFilter() {
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(NPSS_EXT);
        }
        public String getDescription() {
            return Bundle.ExportSnapshotAction_NpssFileFilter(NPSS_EXT);
        }
    });
    return fileChooser;
}
 
Example 7
Project: jaer   File: DavisDeepLearnCnnProcessor_HJ.java   Source Code and License Vote up 6 votes
/**
 * Loads a convolutional neural network (CNN) trained using DeapLearnToolbox
 * for Matlab (https://github.com/rasmusbergpalm/DeepLearnToolbox) that was
 * exported using Danny Neil's XML Matlab script cnntoxml.m.
 *
 */
synchronized public void doLoadApsDvsNetworkFromXML() {
    JFileChooser c = new JFileChooser(lastApsDvsNetXMLFilename);
    FileFilter filt = new FileNameExtensionFilter("XML File", "xml");
    c.addChoosableFileFilter(filt);
    c.setFileFilter(filt);
    c.setSelectedFile(new File(lastApsDvsNetXMLFilename));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    lastApsDvsNetXMLFilename = c.getSelectedFile().toString();
    putString("lastAPSNetXMLFilename", lastApsDvsNetXMLFilename);
    try {
        apsDvsNet.loadFromXMLFile(c.getSelectedFile());
        dvsSubsampler = new DvsFramerSingleFrame(chip);
        dvsSubsampler.setFromNetwork(apsDvsNet);
    } catch (Exception ex) {
        Logger.getLogger(DavisDeepLearnCnnProcessor_HJ.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't load net from this file, caught exception " + ex + ". See console for logging.", "Bad network file", JOptionPane.WARNING_MESSAGE);
    }

}
 
Example 8
Project: openjdk-jdk10   File: SelectAllFilesFilterTest.java   Source Code and License Vote up 5 votes
private static void createAndShowGUI() {
    fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    FileFilter txtFilter = new FileNameExtensionFilter("Text files", "txt");
    fileChooser.addChoosableFileFilter(txtFilter);
    fileChooser.setFileFilter(txtFilter);
    fileChooser.showOpenDialog(null);
}
 
Example 9
Project: Moenagade   File: Project.java   Source Code and License Vote up 5 votes
public void openSound(Frame frame)
{
    JFileChooser fc = new JFileChooser();
    fc.setSelectedFile(new File(lastOpenedSound));
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            if (f.isDirectory()) 
            {
                return true;
            }

            String extension = getExtension(f);
            if (extension != null) {
                if (extension.equals("wav")) 
                {
                        return true;
                } 
                else 
                {
                    return false;
                }
            }

            return false;
        }

        @Override
        public String getDescription() {
            return "Supported sound files (*.wav)";
        }
    });
    int returnVal = fc.showDialog(frame, "Add sound"); 
    if(returnVal == JFileChooser.APPROVE_OPTION)
    {
        loadSound(fc.getSelectedFile());
    }
    
}
 
Example 10
Project: java-course   File: FIleFactory.java   Source Code and License Vote up 5 votes
/**
 * Opens a file from disk.
 * 
 * @param frame
 *            Parent frame.
 * @return Opened file.
 */
public static File getFile(JVDraw frame) {
    JFileChooser fc = new JFileChooser("./");
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileNameExtensionFilter(".jvd", "jvd"));
    int status = fc.showSaveDialog(frame);

    if (status == JFileChooser.OPEN_DIALOG) {
        return setExtension(fc.getSelectedFile(), ".jvd");
    }
    return null;
}
 
Example 11
Project: SER316-Munich   File: EditorPanel.java   Source Code and License Vote up 4 votes
void importB_actionPerformed(ActionEvent e) {
	// Fix until Sun's JVM supports more locales...
	UIManager.put("FileChooser.lookInLabelText", Local
			.getString("Look in:"));
	UIManager.put("FileChooser.upFolderToolTipText", Local
			.getString("Up One Level"));
	UIManager.put("FileChooser.newFolderToolTipText", Local
			.getString("Create New Folder"));
	UIManager.put("FileChooser.listViewButtonToolTipText", Local
			.getString("List"));
	UIManager.put("FileChooser.detailsViewButtonToolTipText", Local
			.getString("Details"));
	UIManager.put("FileChooser.fileNameLabelText", Local
			.getString("File Name:"));
	UIManager.put("FileChooser.filesOfTypeLabelText", Local
			.getString("Files of Type:"));
	UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
	UIManager.put("FileChooser.openButtonToolTipText", Local
			.getString("Open selected file"));
	UIManager
			.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
	UIManager.put("FileChooser.cancelButtonToolTipText", Local
			.getString("Cancel"));

	JFileChooser chooser = new JFileChooser();
	chooser.setFileHidingEnabled(false);
	chooser.setDialogTitle(Local.getString("Insert file"));
	chooser.setAcceptAllFileFilterUsed(false);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
	chooser.setPreferredSize(new Dimension(550, 375));
	String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
	if (lastSel != null)
		chooser.setCurrentDirectory(new java.io.File(lastSel));
	if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
		return;

	Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile()
			.getPath());

	File f = chooser.getSelectedFile();
	new HTMLFileImport(f, editor);
}
 
Example 12
Project: Neukoelln_SER316   File: EditTypeDialog.java   Source Code and License Vote up 4 votes
void setIconB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
    UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
    
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(550, 375));
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Choose icon file"));
    //chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(
        new File(net.sf.memoranda.ui.AppFrame.class.getResource("resources/icons/mimetypes").getPath()));
    /*if (System.getProperty("os.name").startsWith("Win")) {
        chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
        chooser.setCurrentDirectory(new File("C:\\Program Files"));
    }
    else */
    chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
       }
        catch (Exception ex) {
  //ex.printStackTrace();
 }
        finally {
            iconPath = chooser.getSelectedFile().getPath();
        }

    }
}
 
Example 13
Project: Tarski   File: EditorActions.java   Source Code and License Vote up 4 votes
/**
 * 
 */
public void actionPerformed(ActionEvent e) {
  BasicGraphEditor editor = getEditor(e);

  if (editor != null) {
    if (!editor.isModified() || JOptionPane.showConfirmDialog(editor,
        mxResources.get("loseChanges")) == JOptionPane.YES_OPTION) {
      mxGraph graph = editor.getGraphComponent().getGraph();

      if (graph != null) {
        String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir");

        JFileChooser fc = new JFileChooser(wd);

        // Adds file filter for supported file format
        DefaultFileFilter defaultFilter = new DefaultFileFilter(".mxe",
            mxResources.get("allSupportedFormats") + " (.mxe, .png, .vdx)") {

          public boolean accept(File file) {
            String lcase = file.getName().toLowerCase();

            return super.accept(file) || lcase.endsWith(".png") || lcase.endsWith(".vdx");
          }
        };
        fc.addChoosableFileFilter(defaultFilter);

        fc.addChoosableFileFilter(new DefaultFileFilter(".mxe",
            "mxGraph Editor " + mxResources.get("file") + " (.mxe)"));
        fc.addChoosableFileFilter(
            new DefaultFileFilter(".png", "PNG+XML  " + mxResources.get("file") + " (.png)"));

        // Adds file filter for VDX import
        fc.addChoosableFileFilter(new DefaultFileFilter(".vdx",
            "XML Drawing  " + mxResources.get("file") + " (.vdx)"));

        // Adds file filter for GD import
        fc.addChoosableFileFilter(new DefaultFileFilter(".txt",
            "Graph Drawing  " + mxResources.get("file") + " (.txt)"));

        fc.setFileFilter(defaultFilter);

        int rc = fc.showDialog(null, mxResources.get("openFile"));

        if (rc == JFileChooser.APPROVE_OPTION) {
          lastDir = fc.getSelectedFile().getParent();

          try {
            if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".png")) {
              openXmlPng(editor, fc.getSelectedFile());
            } else if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".txt")) {
              openGD(editor, fc.getSelectedFile(),
                  mxUtils.readFile(fc.getSelectedFile().getAbsolutePath()));
            } else {
              Document document =
                  mxXmlUtils.parseXml(mxUtils.readFile(fc.getSelectedFile().getAbsolutePath()));

              mxCodec codec = new mxCodec(document);
              codec.decode(document.getDocumentElement(), graph.getModel());
              editor.setCurrentFile(fc.getSelectedFile());

              resetEditor(editor);
            }
          } catch (IOException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(editor.getGraphComponent(), ex.toString(),
                mxResources.get("error"), JOptionPane.ERROR_MESSAGE);
          }
        }
      }
    }
  }
}
 
Example 14
Project: SER316-Ingolstadt   File: EditTypeDialog.java   Source Code and License Vote up 4 votes
void setIconB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
    UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
    
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(550, 375));
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Choose icon file"));
    //chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(
        new File(net.sf.memoranda.ui.AppFrame.class.getResource("resources/icons/mimetypes").getPath()));
    /*if (System.getProperty("os.name").startsWith("Win")) {
        chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
        chooser.setCurrentDirectory(new File("C:\\Program Files"));
    }
    else */
    chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
       }
        catch (Exception ex) {
  //ex.printStackTrace();
 }
        finally {
            iconPath = chooser.getSelectedFile().getPath();
        }

    }
}
 
Example 15
Project: Wilmersdorf_SER316   File: EditTypeDialog.java   Source Code and License Vote up 4 votes
void setIconB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
    UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
    
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(550, 375));
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Choose icon file"));
    //chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(
        new File(net.sf.memoranda.ui.AppFrame.class.getResource("resources/icons/mimetypes").getPath()));
    /*if (System.getProperty("os.name").startsWith("Win")) {
        chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
        chooser.setCurrentDirectory(new File("C:\\Program Files"));
    }
    else */
    chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
       }
        catch (Exception ex) {
  //ex.printStackTrace();
 }
        finally {
            iconPath = chooser.getSelectedFile().getPath();
        }

    }
}
 
Example 16
Project: incubator-netbeans   File: ExportDiffSupport.java   Source Code and License Vote up 4 votes
private JFileChooser createFileChooser(File curentDir) {
    final JFileChooser chooser = new AccessibleJFileChooser(NbBundle.getMessage(ExportDiffSupport.class, "ACSD_Export"));
    chooser.setDialogTitle(NbBundle.getMessage(ExportDiffSupport.class, "CTL_Export_Title"));
    chooser.setMultiSelectionEnabled(false);
    javax.swing.filechooser.FileFilter[] old = chooser.getChoosableFileFilters();
    for (int i = 0; i < old.length; i++) {
        javax.swing.filechooser.FileFilter fileFilter = old[i];
        chooser.removeChoosableFileFilter(fileFilter);

    }
    chooser.setCurrentDirectory(curentDir); // NOI18N
    chooser.addChoosableFileFilter(getFileFilter());

    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setApproveButtonMnemonic(NbBundle.getMessage(ExportDiffSupport.class, "MNE_Export_ExportAction").charAt(0));
    chooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String state = e.getActionCommand();
            if (state.equals(JFileChooser.APPROVE_SELECTION)) {
                File destination = chooser.getSelectedFile();
                destination = getTargetFile(destination);
                if (destination.exists()) {
                    NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(ExportDiffSupport.class, "BK3005", destination.getAbsolutePath()));
                    nd.setOptionType(NotifyDescriptor.YES_NO_OPTION);
                    DialogDisplayer.getDefault().notify(nd);
                    if (nd.getValue().equals(NotifyDescriptor.OK_OPTION) == false) {
                        return;
                    }
                }
                preferences.put("ExportDiff.saveFolder", destination.getParent()); // NOI18N
                panel.setOutputFileText(destination.getAbsolutePath());
            } else {
                dd.setValue(null);
            }
            if(dialog != null) {
                dialog.dispose();
            }
        }
    });
    return chooser;
}
 
Example 17
Project: Dahlem_SER316   File: EditTypeDialog.java   Source Code and License Vote up 4 votes
void setIconB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));
    UIManager.put("FileChooser.acceptAllFileFilterText", Local.getString("All Files") + " (*.*)");
    
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(550, 375));
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Choose icon file"));
    //chooser.setAcceptAllFileFilterUsed(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setCurrentDirectory(
        new File(net.sf.memoranda.ui.AppFrame.class.getResource("resources/icons/mimetypes").getPath()));
    /*if (System.getProperty("os.name").startsWith("Win")) {
        chooser.setFileFilter(new AllFilesFilter(AllFilesFilter.ICO));
        chooser.setCurrentDirectory(new File("C:\\Program Files"));
    }
    else */
    chooser.addChoosableFileFilter(new net.sf.memoranda.ui.htmleditor.filechooser.ImageFilter());
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            iconLabel.setIcon(new ImageIcon(chooser.getSelectedFile().getPath()));
       }
        catch (Exception ex) {
  //ex.printStackTrace();
 }
        finally {
            iconPath = chooser.getSelectedFile().getPath();
        }

    }
}
 
Example 18
Project: Reinickendorf_SER316   File: EditorPanel.java   Source Code and License Vote up 4 votes
void importB_actionPerformed(ActionEvent e) {
	// Fix until Sun's JVM supports more locales...
	UIManager.put("FileChooser.lookInLabelText", Local
			.getString("Look in:"));
	UIManager.put("FileChooser.upFolderToolTipText", Local
			.getString("Up One Level"));
	UIManager.put("FileChooser.newFolderToolTipText", Local
			.getString("Create New Folder"));
	UIManager.put("FileChooser.listViewButtonToolTipText", Local
			.getString("List"));
	UIManager.put("FileChooser.detailsViewButtonToolTipText", Local
			.getString("Details"));
	UIManager.put("FileChooser.fileNameLabelText", Local
			.getString("File Name:"));
	UIManager.put("FileChooser.filesOfTypeLabelText", Local
			.getString("Files of Type:"));
	UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
	UIManager.put("FileChooser.openButtonToolTipText", Local
			.getString("Open selected file"));
	UIManager
			.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
	UIManager.put("FileChooser.cancelButtonToolTipText", Local
			.getString("Cancel"));

	JFileChooser chooser = new JFileChooser();
	chooser.setFileHidingEnabled(false);
	chooser.setDialogTitle(Local.getString("Insert file"));
	chooser.setAcceptAllFileFilterUsed(false);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
	chooser.setPreferredSize(new Dimension(550, 375));
	String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
	if (lastSel != null)
		chooser.setCurrentDirectory(new java.io.File(lastSel));
	if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
		return;

	Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile()
			.getPath());

	File f = chooser.getSelectedFile();
	new HTMLFileImport(f, editor);
}
 
Example 19
Project: SER316-Ingolstadt   File: EditorPanel.java   Source Code and License Vote up 4 votes
void importB_actionPerformed(ActionEvent e) {
	// Fix until Sun's JVM supports more locales...
	UIManager.put("FileChooser.lookInLabelText", Local
			.getString("Look in:"));
	UIManager.put("FileChooser.upFolderToolTipText", Local
			.getString("Up One Level"));
	UIManager.put("FileChooser.newFolderToolTipText", Local
			.getString("Create New Folder"));
	UIManager.put("FileChooser.listViewButtonToolTipText", Local
			.getString("List"));
	UIManager.put("FileChooser.detailsViewButtonToolTipText", Local
			.getString("Details"));
	UIManager.put("FileChooser.fileNameLabelText", Local
			.getString("File Name:"));
	UIManager.put("FileChooser.filesOfTypeLabelText", Local
			.getString("Files of Type:"));
	UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
	UIManager.put("FileChooser.openButtonToolTipText", Local
			.getString("Open selected file"));
	UIManager
			.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
	UIManager.put("FileChooser.cancelButtonToolTipText", Local
			.getString("Cancel"));

	JFileChooser chooser = new JFileChooser();
	chooser.setFileHidingEnabled(false);
	chooser.setDialogTitle(Local.getString("Insert file"));
	chooser.setAcceptAllFileFilterUsed(false);
	chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
	chooser.setPreferredSize(new Dimension(550, 375));
	String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
	if (lastSel != null)
		chooser.setCurrentDirectory(new java.io.File(lastSel));
	if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
		return;

	Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile()
			.getPath());

	File f = chooser.getSelectedFile();
	new HTMLFileImport(f, editor);
}
 
Example 20
Project: incubator-netbeans   File: ApplyDiffPatchAction.java   Source Code and License Vote up 4 votes
@Override
protected void performContextAction(Node[] nodes) {
    VCSContext ctx = HgUtils.getCurrentContext(nodes);
    final File roots[] = HgUtils.getActionRoots(ctx);
    if (roots == null || roots.length == 0) {
        return;
    }
    final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);

    final JFileChooser fileChooser = new AccessibleJFileChooser(Bundle.ACSD_ApplyDiffPatchBrowseFolder(), null);
    fileChooser.setDialogTitle(Bundle.ApplyDiffPatchBrowse_title());
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setApproveButtonMnemonic(Bundle.ApplyDiffPatch_Apply().charAt(0));
    fileChooser.setApproveButtonText(Bundle.ApplyDiffPatch_Apply());
    fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
    // setup filters, default one filters patch files
    FileFilter patchFilter = new javax.swing.filechooser.FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.getName().endsWith("diff") || f.getName().endsWith("patch") || f.isDirectory();  // NOI18N
        }
        @Override
        public String getDescription() {
            return Bundle.CTL_PatchDialog_FileFilter();
        }
    };
    fileChooser.addChoosableFileFilter(patchFilter);
    fileChooser.setFileFilter(patchFilter);

    DialogDescriptor dd = new DialogDescriptor(fileChooser, Bundle.ApplyDiffPatchBrowse_title());
    dd.setOptions(new Object[0]);
    final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
    
    fileChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String state = e.getActionCommand();
            if (state.equals(JFileChooser.APPROVE_SELECTION)) {
                final File patchFile = fileChooser.getSelectedFile();
                final RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
                new HgProgressSupport() {

                    @Override
                    protected void perform () {
                        if (isNetBeansPatch(patchFile)) {
                            PatchAction.performPatch(patchFile, roots[0]);
                        } else {
                            new ImportDiffAction.ImportDiffProgressSupport(root, patchFile, false, ImportDiffAction.ImportDiffProgressSupport.Kind.PATCH)
                                    .start(rp, root, Bundle.MSG_ApplyDiffPatch_importingPatch());
                        }
                    }
                }.start(rp, root, Bundle.MSG_ApplyDiffPatch_checkingFile());
            }
            dialog.dispose();
        }
    });
    dialog.setVisible(true);
}