use of javax.swing.JFileChooser in project hackpad by dropbox.
the class JSConsole method createFileChooser.
public void createFileChooser() {
dlg = new JFileChooser();
javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String name = f.getName();
int i = name.lastIndexOf('.');
if (i > 0 && i < name.length() - 1) {
String ext = name.substring(i + 1).toLowerCase();
if (ext.equals("js")) {
return true;
}
}
return false;
}
@Override
public String getDescription() {
return "JavaScript Files (*.js)";
}
};
dlg.addChoosableFileFilter(filter);
}
use of javax.swing.JFileChooser in project pcgen by PCGen.
the class SpellSupportFacadeImpl method exportSpells.
@Override
public void exportSpells() {
final String template = PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
if (StringUtils.isEmpty(template)) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_spellNoSheet"));
return;
}
String ext = template.substring(template.lastIndexOf('.'));
// Get the name of the file to output to.
JFileChooser fcExport = new JFileChooser();
fcExport.setCurrentDirectory(new File(PCGenSettings.getPcgDir()));
fcExport.setDialogTitle(LanguageBundle.getString("InfoSpells.export.spells.for") + //$NON-NLS-1$
charDisplay.getDisplayName());
if (fcExport.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) {
return;
}
final String aFileName = fcExport.getSelectedFile().getAbsolutePath();
if (aFileName.length() < 1) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("InfoSpells.must.set.filename"));
return;
}
try {
final File outFile = new File(aFileName);
if (outFile.isDirectory()) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("InfoSpells.can.not.overwrite.directory"));
return;
}
if (outFile.exists()) {
int reallyClose = JOptionPane.showConfirmDialog(null, LanguageBundle.getFormattedString("InfoSpells.confirm.overwrite", //$NON-NLS-1$
outFile.getName()), LanguageBundle.getFormattedString("InfoSpells.overwriting", outFile.getName()), //$NON-NLS-1$
JOptionPane.YES_NO_OPTION);
if (reallyClose != JOptionPane.YES_OPTION) {
return;
}
}
// Output the file
File templateFile = new File(template);
boolean success;
if (ExportUtilities.isPdfTemplate(templateFile)) {
success = BatchExporter.exportCharacterToPDF(pcFacade, outFile, templateFile);
} else {
success = BatchExporter.exportCharacterToNonPDF(pcFacade, outFile, templateFile);
}
if (!success) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("InfoSpells.export.failed", //$NON-NLS-1$
charDisplay.getDisplayName()));
}
} catch (Exception ex) {
Logging.errorPrint(LanguageBundle.getFormattedString("InfoSpells.export.failed", charDisplay.getDisplayName()), //$NON-NLS-1$
ex);
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("InfoSpells.export.failed.retry", //$NON-NLS-1$
charDisplay.getDisplayName()));
}
}
use of javax.swing.JFileChooser in project pcgen by PCGen.
the class SourceSelectionPanel method setupDisplay.
@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
panel.setLayout(new GridBagLayout());
JLabel label = new JLabel("Please select the Source Directory to Convert: ");
GridBagConstraints gbc = new GridBagConstraints();
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
gbc.insets = new Insets(50, 25, 10, 25);
panel.add(label, gbc);
JButton button = new JButton("Browse...");
button.setMnemonic('r');
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser(SourceFolder.OTHER.getFile());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
chooser.setSelectedFile(path);
while (true) {
int open = chooser.showOpenDialog(null);
if (open == JFileChooser.APPROVE_OPTION) {
File fileToOpen = chooser.getSelectedFile();
if (fileToOpen.isDirectory()) {
path = fileToOpen;
SourceFolder.OTHER.setFile(fileToOpen);
pc.put(ObjectKey.DIRECTORY, path);
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path.getAbsolutePath());
JRadioButton button = radioButtons[SourceFolder.OTHER.ordinal()];
button.setSelected(true);
button.setText(buildFolderText(SourceFolder.OTHER, fileToOpen.getAbsolutePath()));
break;
}
JOptionPane.showMessageDialog(null, "Selection must be a valid Directory");
chooser.setSelectedFile(path);
} else if (open == JFileChooser.CANCEL_OPTION) {
break;
}
}
}
});
radioButtons = new JRadioButton[SourceFolder.values().length];
String selectedPath = null;
File selectedFile = pc.get(ObjectKey.DIRECTORY);
if (selectedFile != null) {
selectedPath = selectedFile.getAbsolutePath();
} else {
PCGenSettings context = PCGenSettings.getInstance();
selectedPath = context.getProperty(PCGenSettings.CONVERT_INPUT_PATH, null);
}
ButtonGroup group = new ButtonGroup();
boolean haveSelected = false;
Font font = panel.getFont();
font = FontManipulation.plain(font);
for (SourceFolder folder : SourceFolder.values()) {
JRadioButton pathButton = new JRadioButton();
final SourceFolder buttonFolder = folder;
pathButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, buttonFolder.getFile().getAbsolutePath());
pc.put(ObjectKey.DIRECTORY, buttonFolder.getFile());
}
});
String path;
if (folder.getFile() == null) {
path = "Undefined";
pathButton.setEnabled(false);
} else {
path = folder.getFile().getAbsolutePath();
if (path.equals(selectedPath)) {
pathButton.setSelected(true);
haveSelected = true;
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path);
selectedFile = folder.getFile();
}
}
pathButton.setText(buildFolderText(folder, path));
pathButton.setFont(font);
radioButtons[folder.ordinal()] = pathButton;
group.add(pathButton);
if (folder == SourceFolder.OTHER) {
Utility.buildRelativeConstraints(gbc, 1, GridBagConstraints.REMAINDER, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
} else {
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
}
gbc.insets = new Insets(10, 25, 10, 25);
panel.add(pathButton, gbc);
if (folder == SourceFolder.OTHER) {
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
gbc.insets = new Insets(10, 25, 10, 25);
panel.add(button, gbc);
}
}
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);
panel.add(new JLabel(" "), gbc);
if (!haveSelected) {
if (selectedPath != null) {
JRadioButton btn = radioButtons[SourceFolder.OTHER.ordinal()];
btn.setSelected(true);
selectedFile = new File(selectedPath);
SourceFolder.OTHER.setFile(selectedFile);
path = selectedFile;
btn.setText(buildFolderText(SourceFolder.OTHER, selectedFile.getAbsolutePath()));
} else if (radioButtons[SourceFolder.VENDORDATA.ordinal()].isEnabled()) {
JRadioButton btn = radioButtons[SourceFolder.VENDORDATA.ordinal()];
btn.setSelected(true);
selectedFile = SourceFolder.VENDORDATA.getFile();
} else if (radioButtons[SourceFolder.HOMEBREWDATA.ordinal()].isEnabled()) {
JRadioButton btn = radioButtons[SourceFolder.HOMEBREWDATA.ordinal()];
btn.setSelected(true);
selectedFile = SourceFolder.HOMEBREWDATA.getFile();
} else {
JRadioButton btn = radioButtons[SourceFolder.DATA.ordinal()];
btn.setSelected(true);
selectedFile = SourceFolder.DATA.getFile();
}
}
pc.put(ObjectKey.DIRECTORY, selectedFile);
}
use of javax.swing.JFileChooser in project OpenAM by OpenRock.
the class ListJPanel method containerDirBrowsejButtonActionPerformed.
private void containerDirBrowsejButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (containerDirChooser == null) {
String initDir = System.getProperty("user.home");
if (initDir != null) {
containerDirChooser = new JFileChooser(initDir);
} else {
containerDirChooser = new JFileChooser();
}
} else {
if (containerDirFile != null) {
containerDirChooser.setCurrentDirectory(containerDirFile);
}
}
containerDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
containerDirChooser.setMultiSelectionEnabled(false);
containerDirChooser.setDialogTitle(rb.getString("dlg_open_wc_base_dir_title"));
if (containerDirChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
containerDirFile = containerDirChooser.getSelectedFile();
if ((containerDirFile != null) && containerDirFile.exists() && containerDirFile.isDirectory()) {
containerDirjTextField.setText(containerDirFile.getAbsolutePath());
}
}
}
use of javax.swing.JFileChooser in project OpenAM by OpenRock.
the class ListJPanel method containerDomainDirBrowsejButtonActionPerformed.
private void containerDomainDirBrowsejButtonActionPerformed(java.awt.event.ActionEvent evt) {
if (containerDomainDirChooser == null) {
String initDir = System.getProperty("user.home");
if (initDir != null) {
containerDomainDirChooser = new JFileChooser(initDir);
} else {
containerDomainDirChooser = new JFileChooser();
}
} else {
if (containerDomainDirFile != null) {
containerDomainDirChooser.setCurrentDirectory(containerDomainDirFile);
}
}
containerDomainDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
containerDomainDirChooser.setMultiSelectionEnabled(false);
containerDomainDirChooser.setDialogTitle(rb.getString("dlg_open_wc_domain_dir_title"));
if (containerDomainDirChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
containerDomainDirFile = containerDomainDirChooser.getSelectedFile();
if ((containerDomainDirFile != null) && containerDomainDirFile.exists() && containerDomainDirFile.isDirectory()) {
containerDomainDirjTextField.setText(containerDomainDirFile.getAbsolutePath());
}
}
}
Aggregations