MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / open

Method open

src/org/opensourcephysics/tools/DataTool.java:688–743  ·  view source on GitHub ↗

Opens an xml or data file specified by name. @param fileName the file name

(File file)

Source from the content-addressed store, hash-verified

686 * @param fileName the file name
687 */
688 public void open(File file) {
689 // @return the file name, if successfully opened (datasets loaded)
690 // BH 2020.02.13 return was string;
691 OSPLog.fine("opening " + file); //$NON-NLS-1$
692 Resource res = new Resource(file);
693 Reader in = res.openReader();
694 String firstLine = readFirstLine(in);
695 // if xml, read the file into an XML control and add tab
696 if (firstLine.startsWith("<?xml")) { //$NON-NLS-1$
697 XMLControlElement control = new XMLControlElement(file);
698 addTabs(control, new Consumer<ArrayList<DataToolTab>>() {
699
700 @Override
701 public void accept(ArrayList<DataToolTab> tabs) {
702 if (tabs.isEmpty()) {
703 OSPLog.finest("no data found"); //$NON-NLS-1$
704 } else {
705 for (DataToolTab tab : tabs) {
706 refreshDataBuilder();
707 if (tabs.size() == 1) {
708 tab.fileName = file.toString();
709 }
710 tab.tabChanged(false);
711 }
712 try {
713 in.close();
714 } catch (IOException e) {
715 // e.printStackTrace();
716 }
717 }
718 }
719
720 });
721 return;
722 }
723 if (res.getString() != null) {
724 // if not xml, attempt to import data and add tab(s)
725 setMultipleTabPolicy(res.getString());
726 Data[] data = parseData(res.getString(), file.toString());
727 if (data != null) {
728 DataToolTab first = null;
729 for (int i = 0; i < data.length; i++) {
730 DataToolTab tab = createTab(data[i]);
731 first = first == null? tab: first;
732 addTab(tab);
733 if (data.length == 1)
734 tab.fileName = file.getAbsolutePath();
735 tab.tabChanged(false);
736 }
737 setSelectedTab(first);
738 refreshDataBuilder();
739 return;
740 }
741 }
742 OSPLog.finest("no data found"); //$NON-NLS-1$
743 }
744
745 /**

Callers 10

DataToolMethod · 0.95
loadDatasetURLMethod · 0.95
runMethod · 0.95
actionPerformedMethod · 0.95
saveTabSetMethod · 0.45
mainMethod · 0.45
importDataMethod · 0.45
undoMethod · 0.45
redoMethod · 0.45
refreshNextMethod · 0.45

Calls 15

fineMethod · 0.95
openReaderMethod · 0.95
readFirstLineMethod · 0.95
addTabsMethod · 0.95
getStringMethod · 0.95
setMultipleTabPolicyMethod · 0.95
parseDataMethod · 0.95
createTabMethod · 0.95
addTabMethod · 0.95
tabChangedMethod · 0.95
setSelectedTabMethod · 0.95
refreshDataBuilderMethod · 0.95

Tested by

no test coverage detected