MCPcopy Create free account
hub / github.com/rambaut/figtree / readData

Method readData

src/figtree/application/FigTreeFrame.java:727–789  ·  view source on GitHub ↗
(Reader reader, boolean isNexus)

Source from the content-addressed store, hash-verified

725 }
726
727 protected boolean readData(Reader reader, boolean isNexus) throws IOException {
728
729 List<Tree> trees = new ArrayList<Tree>();
730
731 boolean hasSettings = false;
732
733 try {
734 Map<String, Object> settings = new HashMap<String, Object>();
735 // First of all, fully populate the settings map so that
736 // all the settings have defaults
737 controlPalette.getSettings(settings);
738
739 if (isNexus) {
740 FigTreeNexusImporter importer = new FigTreeNexusImporter(reader);
741 while (importer.hasTree()) {
742 Tree tree = importer.importNextTree();
743 trees.add(tree);
744 }
745 // Try to find a figtree block and if found, parse the settings
746 while (true) {
747 try {
748 importer.findNextBlock();
749 if (importer.getNextBlockName().equalsIgnoreCase("FIGTREE")) {
750 importer.parseFigTreeBlock(settings);
751 hasSettings = true;
752 }
753 } catch (EOFException ex) {
754 break;
755 }
756 }
757 } else {
758 NewickImporter importer = new NewickImporter(reader, true);
759 while (importer.hasTree()) {
760 Tree tree = importer.importNextTree();
761 trees.add(tree);
762 }
763 }
764
765 if (trees.size() == 0) {
766 throw new ImportException("This file contained no trees.");
767 }
768
769 checkLabelAttribute(trees);
770
771 treeViewer.setTrees(trees);
772 controlPalette.setSettings(settings);
773 } catch (ImportException ie) {
774 JOptionPane.showMessageDialog(this, "Error reading tree file: \n" + ie.getMessage(),
775 "Import Error",
776 JOptionPane.ERROR_MESSAGE);
777 return false;
778 }
779
780 if (!hasSettings) {
781 // If there weren't settings in the file then this wasn't a TreeDraw
782 // created document so we don't want to be able to overwrite it without
783 // explicit action of the user...
784 setDirty();

Callers 3

readFromFileMethod · 0.95
readFromURLMethod · 0.95
readFromStringMethod · 0.95

Calls 6

checkLabelAttributeMethod · 0.95
parseFigTreeBlockMethod · 0.80
getSettingsMethod · 0.45
addMethod · 0.45
setTreesMethod · 0.45
setSettingsMethod · 0.45

Tested by

no test coverage detected