use of gov.sandia.n2a.db.MVolatile in project n2a by frothga.
the class ParserBibtex method parseTags.
public MNode parseTags(BufferedReader reader) throws IOException {
MNode result = new MVolatile();
// read to first ,
String id = "";
while (true) {
int c = reader.read();
if (c < 0 || c == '}') {
result.set(id.trim());
return result;
}
if (c == ',')
break;
id += (char) c;
}
// TODO: should this be lower-case as well?
result.set(id.trim());
while (parseTag(reader, result)) ;
return result;
}
use of gov.sandia.n2a.db.MVolatile in project n2a by frothga.
the class ImportJob method remap.
public void remap(MNode part, NameMap nameMap) {
MNode temp = new MVolatile();
temp.merge(part);
part.clear();
for (MNode v : temp) {
String key = nameMap.importName(v.key());
part.set(key, v);
}
}
use of gov.sandia.n2a.db.MVolatile in project n2a by frothga.
the class ImportNative method process.
@Override
public void process(File source) {
try (BufferedReader reader = new BufferedReader(new FileReader(source))) {
// dispose of schema line
reader.readLine();
MVolatile doc = new MVolatile();
doc.read(reader);
PanelModel.instance.undoManager.add(new AddDoc(source.getName(), doc));
} catch (IOException e) {
}
}
use of gov.sandia.n2a.db.MVolatile in project n2a by frothga.
the class NodePart method add.
public NodeBase add(String type, JTree tree, MNode data) {
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
if (// The node is deliberately closed to indicate user intent.
tree.isCollapsed(new TreePath(getPath())) && model.getChildCount(this) > 0 && !isRoot()) {
// The only thing that can contain a NodePart is another NodePart. (If that ever changes, the following code will break.)
if (type.isEmpty())
return ((NodePart) getParent()).add("Part", tree, data);
return ((NodePart) getParent()).add(type, tree, data);
}
int variableIndex = -1;
int subpartIndex = -1;
int metadataIndex = 0;
// unfiltered, so we can insert at the correct place in the underlying collection
int count = getChildCount();
for (int i = 0; i < count; i++) {
TreeNode t = getChildAt(i);
if (t instanceof NodeInherit) {
metadataIndex = i + 1;
}
if (t instanceof NodePart) {
if (variableIndex < 0)
variableIndex = i;
subpartIndex = i + 1;
}
}
if (variableIndex < 0)
variableIndex = count;
if (subpartIndex < 0)
subpartIndex = count;
TreePath path = tree.getSelectionPath();
if (path != null) {
NodeBase selected = (NodeBase) path.getLastPathComponent();
if (selected.getParent() == this) {
// When we have a specific item selected, the user expects the new item to appear directly below it.
// unfiltered
int selectedIndex = getIndex(selected);
variableIndex = selectedIndex + 1;
subpartIndex = selectedIndex + 1;
}
}
if (type.equals("Annotation")) {
AddAnnotation aa = new AddAnnotation(this, metadataIndex, data);
// aa will automagically insert a $metadata block if needed
PanelModel.instance.undoManager.add(aa);
return aa.createdNode;
} else if (type.equals("Annotations")) {
// TODO: figure out how to handle this case
return null;
} else if (type.equals("Reference")) {
AddReference ar = new AddReference(this, metadataIndex, data);
PanelModel.instance.undoManager.add(ar);
return ar.createdNode;
} else if (type.equals("References")) {
// TODO: figure out how to handle this case
return null;
} else if (type.equals("Part")) {
AddPart ap = new AddPart(this, subpartIndex, data);
PanelModel.instance.undoManager.add(ap);
return ap.createdNode;
} else if (type.equals("Inherit")) {
Undoable un = null;
NodeInherit inherit = (NodeInherit) child("$inherit");
String value = "";
if (data != null)
value = data.get();
if (inherit == null) {
un = new AddInherit(this, value);
} else if (!value.isEmpty()) {
un = new ChangeInherit(inherit, value);
}
if (un != null)
PanelModel.instance.undoManager.add(un);
return child("$inherit");
} else // treat all other requests as "Variable"
{
if (data != null && type.equals("Equation")) {
// convert equation into nameless variable
data = new MVolatile("", data.get() + data.key());
}
AddVariable av = new AddVariable(this, variableIndex, data);
PanelModel.instance.undoManager.add(av);
return av.createdNode;
}
}
use of gov.sandia.n2a.db.MVolatile in project n2a by frothga.
the class Outsource method redo.
public void redo() {
super.redo();
MNode subtree = new MVolatile();
subtree.set("$inherit", inherit);
apply(subtree);
}
Aggregations