public void doImport() { try { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select input tree file..."); chooser.setMultiSelectionEnabled(false); chooser.setCurrentDirectory(frame.getWorkingDirectory()); int returnValue = chooser.showOpenDialog(Utils.getActiveFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (file != null) { // dataList.treeFilesList.add(file); treeFileNameText.setText(file.getName()); importFromFile(file); File tmpDir = chooser.getCurrentDirectory(); if (tmpDir != null) { frame.setWorkingDirectory(tmpDir); } } // END: file opened check } // END: dialog cancelled check } catch (IOException e) { e.printStackTrace(); } catch (ImportException e) { e.printStackTrace(); } // END: try-catch block } // END: doImport
public void importFromFile(final File file) throws IOException, ImportException { frame.setBusy(); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { // Executed in background thread public Void doInBackground() { try { BufferedReader reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); Tree tree; if (line.toUpperCase().startsWith("#NEXUS")) { NexusImporter importer = new NexusImporter(reader); tree = importer.importTree(null); } else { NewickImporter importer = new NewickImporter(reader); tree = importer.importTree(null); } // TODO Add taxons from a new tree to that list and display // them in Taxa panel dataList.taxonList = tree; dataList.forestMap.put(file, new TreeModel(tree)); reader.close(); } catch (Exception e) { Utils.handleException(e); } // END: try-catch block return null; } // END: doInBackground() // Executed in event dispatch thread public void done() { frame.setIdle(); frame.fireTaxaChanged(); } // END: done }; worker.execute(); } // END: importFromFile