use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class BEASTObjectPanel method getOutputs.
/* calculate outputs for each beastObject
* and put them as ArrayLists in a Map
* so they can be retrieved indexed by beastObject like this:
* ArrayList<BEASTObject> output = outputs.get(beastObject)*/
static HashMap<BEASTInterface, List<BEASTInterface>> getOutputs(Collection<BEASTInterface> beastObjects) {
HashMap<BEASTInterface, List<BEASTInterface>> outputs = new HashMap<>();
for (BEASTInterface beastObject : beastObjects) {
outputs.put(beastObject, new ArrayList<>());
}
for (BEASTInterface beastObject : beastObjects) {
try {
for (Input<?> input2 : beastObject.listInputs()) {
Object o = input2.get();
if (o != null && o instanceof BEASTInterface) {
List<BEASTInterface> list = outputs.get(o);
// if (list == null) {
// int h = 3;
// h++;
// } else {
list.add(beastObject);
// }
}
if (o != null && o instanceof List<?>) {
for (Object o2 : (List<?>) o) {
if (o2 != null && o2 instanceof BEASTInterface) {
List<BEASTInterface> list = outputs.get(o2);
if (list != null) {
list.add(beastObject);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return outputs;
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class BEASTObjectPanel method main.
/**
* rudimentary test *
*/
public static void main(String[] args) {
init();
BEASTObjectPanel pluginPanel = null;
try {
if (args.length == 0) {
pluginPanel = new BEASTObjectPanel(new MCMC(), Runnable.class, null);
} else if (args[0].equals("-x")) {
StringBuilder text = new StringBuilder();
String NL = System.getProperty("line.separator");
Scanner scanner = new Scanner(new File(args[1]));
try {
while (scanner.hasNextLine()) {
text.append(scanner.nextLine() + NL);
}
} finally {
scanner.close();
}
BEASTInterface beastObject = new beast.util.XMLParser().parseBareFragment(text.toString(), false);
pluginPanel = new BEASTObjectPanel(beastObject, beastObject.getClass(), null);
} else if (args.length == 1) {
pluginPanel = new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[0]), null);
} else if (args.length == 2) {
pluginPanel = new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[1]), null);
} else {
throw new IllegalArgumentException("Incorrect number of arguments");
}
} catch (Exception e) {
e.printStackTrace();
System.err.println("Usage: " + BEASTObjectPanel.class.getName() + " [-x file ] [class [type]]\n" + "where [class] (optional, default MCMC) is a BEASTObject to edit\n" + "and [type] (optional only if class is specified, default Runnable) the type of the BEASTObject.\n" + "for example\n" + "");
System.exit(1);
}
pluginPanel.setVisible(true);
if (pluginPanel.m_bOK) {
BEASTInterface beastObject = pluginPanel.m_beastObject;
String xml = new XMLProducer().modelToXML(beastObject);
System.out.println(xml);
}
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method setPluginID.
void setPluginID(BEASTObjectShape shape) {
if (shape.m_beastObject.getID() != null && shape.m_beastObject.getID().length() > 0) {
return;
}
BEASTInterface beastObject = shape.m_beastObject;
String base = beastObject.getClass().getName().replaceAll(".*\\.", "");
int _id = 0;
while (containsID(base + _id, m_objects, null)) {
_id++;
}
beastObject.setID(base + _id);
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method process.
void process(BEASTObjectShape shape, int depth) throws IllegalArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException {
BEASTInterface beastObject = shape.m_beastObject;
List<Input<?>> inputs = beastObject.listInputs();
for (Input<?> input_ : inputs) {
Object o = input_.get();
if (o != null) {
if (o instanceof List<?>) {
for (Object o2 : (List<?>) o) {
addInput(shape, o2, depth + 1, input_.getName());
}
} else if (o instanceof BEASTInterface) {
addInput(shape, o, depth + 1, input_.getName());
// } else {
// it is a primitive type
}
}
}
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method init.
public void init(BEASTInterface plugin0) {
try {
if (plugin0 instanceof BEASTObjectSet) {
List<BEASTInterface> set = ((BEASTObjectSet) plugin0).m_plugins.get();
if (set == null) {
return;
}
for (BEASTInterface beastObject : set) {
BEASTObjectShape shape = new BEASTObjectShape(beastObject, this);
shape.m_beastObject = beastObject;
setPluginID(shape);
m_objects.add(shape);
process(shape, 1);
shape.m_x = DX;
shape.m_w = 100;
Random random = new Random();
shape.m_y = random.nextInt(800);
shape.m_h = 50;
}
} else {
BEASTObjectShape shape = new BEASTObjectShape(plugin0, this);
shape.m_beastObject = plugin0;
setPluginID(shape);
m_objects.add(shape);
process(shape, 1);
shape.m_x = DX;
shape.m_w = 100;
Random random = new Random();
shape.m_y = random.nextInt(800);
shape.m_h = 50;
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
// clear undo stack after all items have been
// added since the stack is affected by parsing...
clearUndoStack();
recalcArrows();
layout();
adjustArrows();
}
Aggregations