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

The following are Jave code examples for showing how to use setFileView() 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: CreateJREPanel.java   Source Code and License Vote up 6 votes
private void buttonBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBrowseActionPerformed
    final String oldValue = jreCreateLocation.getText();
    final JFileChooser chooser = new JFileChooser() {
        @Override
        public void approveSelection() {
            if (EJDKFileView.isEJDK(getSelectedFile())) {
                super.approveSelection();
            } else {
                DialogDisplayer.getDefault().notify(
                    new NotifyDescriptor.Message(
                        NbBundle.getMessage(CreateJREPanel.class, "TXT_InvalidEJDKFolder", getSelectedFile().getName()),
                        NotifyDescriptor.ERROR_MESSAGE));
            }
        }
    };
    chooser.setFileView(new EJDKFileView(chooser.getFileSystemView()));
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (oldValue != null) {
        chooser.setSelectedFile(new File(oldValue));
    }
    chooser.setDialogTitle(NbBundle.getMessage(CreateJREPanel.class, "Title_Chooser_SelectJRECreate")); //NOI18N
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        jreCreateLocation.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 2
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License Vote up 5 votes
private void prepareFileChooser(JFileChooser chooser) {
    chooser.setFileSelectionMode(dirsOnly ? JFileChooser.DIRECTORIES_ONLY
            : filesOnly ? JFileChooser.FILES_ONLY :
            JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setFileHidingEnabled(fileHiding);
    chooser.setControlButtonsAreShown(controlButtonsShown);
    chooser.setAcceptAllFileFilterUsed(useAcceptAllFileFilter);
    if (title != null) {
        chooser.setDialogTitle(title);
    }
    if (approveText != null) {
        chooser.setApproveButtonText(approveText);
    }
    if (badger != null) {
        chooser.setFileView(new CustomFileView(new BadgeIconProvider(badger),
                chooser.getFileSystemView()));
    }
    if (PREVENT_SYMLINK_TRAVERSAL) {
        FileUtil.preventFileChooserSymlinkTraversal(chooser,
                chooser.getCurrentDirectory());
    }
    if (filter != null) {
        chooser.setFileFilter(filter);
    }
    if (aDescription != null) {
        chooser.getAccessibleContext().setAccessibleDescription(aDescription);
    }
    if (!filters.isEmpty()) {
        for (FileFilter f : filters) {
            chooser.addChoosableFileFilter(f);
        }
    }
}
 
Example 3
Project: incubator-netbeans   File: ProjectChooserAccessory.java   Source Code and License Vote up 4 votes
public ProjectFileView(JFileChooser chooser) {
    this.chooser = chooser;
    chooser.setFileView(this);
    task.setPriority(Thread.MIN_PRIORITY);
}
 
Example 4
Project: AgentWorkbench   File: BasicGraphGui.java   Source Code and License Vote up 4 votes
/**
 * Export the current graph as image by using a file selection dialog.
 */
private void exportAsImage() {

	String currentFolder = null;
	if (Application.getGlobalInfo() != null) {
		// --- Get the last selected folder of Agent.GUI ---
		currentFolder = Application.getGlobalInfo().getLastSelectedFolderAsString();
	}

	// --- Create instance of JFileChooser -----------------
	JFileChooser jfc = new JFileChooser();
	jfc.setMultiSelectionEnabled(false);
	jfc.setAcceptAllFileFilterUsed(false);

	// --- Add custom icons for file types. ----------------
	jfc.setFileView(new ImageFileView());
	// --- Add the preview pane. ---------------------------
	jfc.setAccessory(new ImagePreview(jfc));

	// --- Set the file filter -----------------------------
	String[] extensionsJPEG = { ImageUtils.jpg, ImageUtils.jpeg };

	ConfigurableFileFilter filterJPG = new ConfigurableFileFilter(extensionsJPEG, "JPEG - Image");
	ConfigurableFileFilter filterPNG = new ConfigurableFileFilter(ImageUtils.png, "PNG - File");
	ConfigurableFileFilter filterGIF = new ConfigurableFileFilter(ImageUtils.gif, "GIF - Image");

	jfc.addChoosableFileFilter(filterGIF);
	jfc.addChoosableFileFilter(filterJPG);
	jfc.addChoosableFileFilter(filterPNG);

	jfc.setFileFilter(filterPNG);

	// --- Maybe set the current directory -----------------
	if (currentFolder != null) {
		jfc.setCurrentDirectory(new File(currentFolder));
	}

	// === Show dialog and wait on user action =============
	int state = jfc.showSaveDialog(this);
	if (state == JFileChooser.APPROVE_OPTION) {

		ConfigurableFileFilter cff = (ConfigurableFileFilter) jfc.getFileFilter();
		String selectedExtension = cff.getFileExtension()[0];
		String mustExtension = "." + selectedExtension;

		File selectedFile = jfc.getSelectedFile();
		if (selectedFile != null) {
			String selectedPath = selectedFile.getAbsolutePath();
			if (selectedPath.endsWith(mustExtension) == false) {
				selectedPath = selectedPath + mustExtension;
			}
			// ---------------------------------------------
			// --- Export current display to image ---------
			// ---------------------------------------------
			this.exportAsImage(this.getVisualizationViewer(), selectedPath, selectedExtension);
			// ---------------------------------------------

			if (Application.getGlobalInfo() != null) {
				Application.getGlobalInfo().setLastSelectedFolder(jfc.getCurrentDirectory());
			}
		}
	} // end APPROVE_OPTION

}
 
Example 5
Project: AgentWorkbench   File: ChartEditorJPanel.java   Source Code and License Vote up 4 votes
private void saveAsImage(){
	
	// --- Determine image size ----------------------------
	Integer imageWidth = Integer.parseInt(this.getTfImageWidth().getText());
	if (imageWidth==0) {
		JOptionPane.showMessageDialog(this, Language.translate("Bitte nur ganze Zahlen größer 0 eingeben!"), Language.translate("Fehlerhafte Eingabe"), JOptionPane.ERROR_MESSAGE);
		this.setImageDefaultValues();
		return;
	}
	Integer imageHeight = Integer.parseInt(this.getTfImageHeight().getText());
	if (imageHeight==0) {
		JOptionPane.showMessageDialog(this, Language.translate("Bitte nur ganze Zahlen größer 0 eingeben!"), Language.translate("Fehlerhafte Eingabe"), JOptionPane.ERROR_MESSAGE);
		this.setImageDefaultValues();
		return;
	}
	
	String currentFolder = null;
	if (Application.getGlobalInfo()!=null) {
		// --- Get the last selected folder of Agent.GUI ---
		currentFolder = Application.getGlobalInfo().getLastSelectedFolderAsString();
	}

	// --- Create instance of JFileChooser -----------------
	JFileChooser jfc = new JFileChooser();
	jfc.setMultiSelectionEnabled(false);
	jfc.setAcceptAllFileFilterUsed(false);

	// --- Add custom icons for file types. ----------------
	jfc.setFileView(new ImageFileView());
	// --- Add the preview pane. ---------------------------
	jfc.setAccessory(new ImagePreview(jfc));

	// --- Set the file filter -----------------------------
	String[] extensionsJPEG = {ImageUtils.jpg, ImageUtils.jpeg};

	ConfigurableFileFilter filterJPG = new ConfigurableFileFilter(extensionsJPEG, "JPEG - Image");
	ConfigurableFileFilter filterPNG = new ConfigurableFileFilter(ImageUtils.png, "PNG - File");
	ConfigurableFileFilter filterGIF = new ConfigurableFileFilter(ImageUtils.gif, "GIF - Image");

	jfc.addChoosableFileFilter(filterGIF);
	jfc.addChoosableFileFilter(filterJPG);
	jfc.addChoosableFileFilter(filterPNG);

	jfc.setFileFilter(filterPNG);

	// --- Maybe set the current directory -----------------
	if (currentFolder != null) {
		jfc.setCurrentDirectory(new File(currentFolder));
	}
	
	// === Show dialog and wait on user action =============
	int state = jfc.showSaveDialog(this);
	
	if (state == JFileChooser.APPROVE_OPTION) {
		ConfigurableFileFilter cff = (ConfigurableFileFilter) jfc.getFileFilter();
		String selectedExtension = cff.getFileExtension()[0];
		String mustExtension = "." + selectedExtension;

		File selectedFile = jfc.getSelectedFile();
		if (selectedFile != null) {
			String selectedPath = selectedFile.getAbsolutePath();
			if (selectedPath.endsWith(mustExtension) == false) {
				selectedPath = selectedPath + mustExtension;
			}
			
			BufferedImage image = this.exportChartAsImage(imageWidth, imageHeight);
			this.writeImageFile(image, selectedPath, selectedExtension);
			
			if (Application.getGlobalInfo() != null) {
				Application.getGlobalInfo().setLastSelectedFolder(jfc.getCurrentDirectory());
			}
		}
	}
}