use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.
the class ImportQifAction method importQif.
private static void importQif() {
final ResourceBundle rb = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(ImportQifAction.class);
final Logger logger = Logger.getLogger("qifimport");
if (debug) {
try {
Handler fh = new FileHandler("%h/jgnash%g.log");
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.setLevel(Level.FINEST);
} catch (IOException ioe) {
logger.log(Level.SEVERE, "Could not install file handler", ioe);
}
}
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
if (engine.getRootAccount() == null) {
StaticUIMethods.displayError(rb.getString("Message.Error.CreateBasicAccounts"));
return;
}
final JFileChooser chooser = new JFileChooser(pref.get(QIFDIR, null));
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Qif Files (*.qif)", "qif"));
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
pref.put(QIFDIR, chooser.getCurrentDirectory().getAbsolutePath());
boolean fullFile = QifUtils.isFullFile(chooser.getSelectedFile());
if (fullFile) {
// prompt for date format
final DateFormat dateFormat = getQIFDateFormat();
class ImportFile extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
UIApplication.getFrame().displayWaitMessage(rb.getString("Message.ImportWait"));
QifImport imp = new QifImport();
try {
imp.doFullParse(chooser.getSelectedFile(), dateFormat);
} catch (NoAccountException e) {
logger.log(Level.SEVERE, "Mistook partial qif file as a full qif file", e);
}
imp.dumpStats();
imp.doFullImport();
if (imp.getDuplicateCount() > 0) {
String message = imp.getDuplicateCount() + " duplicate transactions were found";
logger.info(message);
}
return null;
}
@Override
protected void done() {
UIApplication.getFrame().stopWaitMessage();
}
}
new ImportFile().execute();
} else {
final QifImport imp = new QifImport();
if (!imp.doPartialParse(chooser.getSelectedFile())) {
StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
return;
}
imp.dumpStats();
if (imp.getParser().accountList.isEmpty()) {
StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
return;
}
PartialDialog dlg = new PartialDialog(imp.getParser());
DialogUtils.addBoundsListener(dlg);
dlg.setVisible(true);
if (dlg.isWizardValid()) {
imp.doPartialImport(dlg.getAccount());
if (imp.getDuplicateCount() > 0) {
if (YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new MultiLineLabel(TextResource.getString("DupeTransImport.txt")), rb.getString("Title.DuplicateTransactionsFound"), YesNoDialog.WARNING_MESSAGE)) {
Transaction[] t = imp.getDuplicates();
for (Transaction element : t) {
engine.addTransaction(element);
}
}
}
}
}
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project MatematicaDiscreta by Leoginski.
the class main method jbArquivoActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void jbArquivoActionPerformed(java.awt.event.ActionEvent evt) {
//GEN-FIRST:event_jbArquivoActionPerformed
// TODO add your handling code here:
StorageSession.resetStorage();
jcbConjunto1.removeAllItems();
jcbConjunto2.removeAllItems();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("Filtro .txt", "txt"));
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.showOpenDialog(this);
File txtFileLer = new File(fileChooser.getSelectedFile().getAbsolutePath());
jtfArquivo.setText(txtFileLer.getName());
// Leitura do arquivo
try {
FileReader arq = new FileReader(txtFileLer);
BufferedReader lerArq = new BufferedReader(arq);
// Pegando linhas do arquivo
String linha = lerArq.readLine();
//Expressoes regulares
Pattern acharConjunto = Pattern.compile("[A-Z]");
Pattern acharElemento = Pattern.compile("([a-z])");
Pattern numero = Pattern.compile("\\d+");
// Varrendo as linhas
while (linha != null) {
// Aplicando regex
Matcher acharConjuntoMatcher = acharConjunto.matcher(linha);
Matcher acharElementoMatcher = acharElemento.matcher(linha);
Matcher numeroMatcher = numero.matcher(linha);
// Econtrando conjuntos
if (acharConjuntoMatcher.find()) {
// Nome do conjunto
String nome = acharConjuntoMatcher.group();
// Instancia objeto e adiciona ao ArrayList
if (!StorageSession.existeNomeIgualConjunto(nome)) {
Conjunto target = new Conjunto(nome);
while (numeroMatcher.find()) {
// Obtém valor
int value = Integer.parseInt(numeroMatcher.group());
Elemento elemento = new Elemento(Integer.toString(value), value);
target.addElemento(elemento);
}
// adiciona conjunto
StorageSession.setConjuntos(target);
} else {
JOptionPane.showMessageDialog(null, "Conjunto " + nome + " já existe!");
}
}
// Encontrando elementos
if (acharElementoMatcher.find()) {
// Nome do elemento
String nome = acharElementoMatcher.group();
int value = 0;
if (!StorageSession.existeNomeIgualElemento(nome)) {
// O loop pegará o elemento com 1 ou mais digitos.
while (numeroMatcher.find()) {
value = Integer.parseInt(numeroMatcher.group());
}
Elemento shot = new Elemento(nome, value);
// adiciona elemento
StorageSession.setElementos(shot);
} else {
JOptionPane.showMessageDialog(null, "Elemento " + nome + " já existe!");
}
}
// lê da segunda até a última linha
linha = lerArq.readLine();
}
arq.close();
} catch (IOException e) {
System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage());
}
// PREENCHER O COMBOBOX
for (String obj : StorageSession.getComboItens()) {
jcbConjunto1.addItem(obj);
jcbConjunto2.addItem(obj);
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project DistributedFractalNetwork by Budder21.
the class FractalChooserMenu method chooseFractal.
/**
* Allows a user to choose a saved fractal and set zoom speed and resolution
* parameters
* @return a RenderManger for the network to use. Will return null if no fractal if the window is closed
*/
public static RenderManager chooseFractal() {
waiting = true;
manager = null;
JFrame f = new JFrame();
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
JLabel message = new JLabel(" Fractal:");
message.setFont(Constants.mediumFont);
p.add(message, BorderLayout.WEST);
RoundedButton chooseFile = new RoundedButton();
chooseFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Fractal", "prop");
fileChooser.setFileFilter(filter);
manager = new RenderManager(fileChooser.getSelectedFile());
}
});
p.add(chooseFile, BorderLayout.CENTER);
f.setContentPane(p);
f.pack();
f.setLocationRelativeTo(null);
f.setResizable(false);
f.addWindowListener(new WindowListener() {
public void windowOpened(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
waiting = false;
}
});
f.setVisible(true);
while (manager == null || waiting) {
}
return manager;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project javatari by ppeccin.
the class FileROMChooser method chooseFileToLoad.
public static File chooseFileToLoad() throws AccessControlException {
if (chooser != null && chooser.isShowing())
return null;
if (lastLoadFileChosen == null)
lastLoadFileChosen = new File(Parameters.LAST_ROM_LOAD_FILE_CHOSEN);
if (chooser == null)
createChooser();
chooser.setFileFilter(new FileNameExtensionFilter(ROMLoader.VALID_LOAD_FILES_DESC, ROMLoader.VALID_LOAD_FILE_EXTENSIONS));
chooser.setSelectedFile(lastLoadFileChosen);
int res = chooser.showOpenDialog(null);
if (res != 0)
return null;
lastLoadFileChosen = chooser.getSelectedFile();
Parameters.LAST_ROM_LOAD_FILE_CHOSEN = lastLoadFileChosen.toString();
Parameters.savePreferences();
return lastLoadFileChosen;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project pcgen by PCGen.
the class PCGenFrame method showOpenPartyChooser.
void showOpenPartyChooser() {
PCGenSettings context = PCGenSettings.getInstance();
chooser.setCurrentDirectory(new File(context.getProperty(PCGenSettings.PCP_SAVE_PATH)));
chooser.resetChoosableFileFilters();
chooser.setFileFilter(new FileNameExtensionFilter("Pcp files only", "pcp"));
int returnVal = chooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
loadPartyFromFile(file);
}
}
Aggregations