Search in sources :

Example 1 with BeautiDoc

use of beast.app.beauti.BeautiDoc in project beast2 by CompEvol.

the class BeautiTest method testCustomBatchMode.

@Test
public void testCustomBatchMode() {
    BeautiDoc doc = new BeautiDoc();
    try {
        PrintStream out = new PrintStream(templateFile);
        out.print(template);
        out.close();
        doc.processTemplate(templateFile);
    } catch (Exception e) {
        assertEquals(true, false);
    }
    // ignore test if no X11 display available
    if (!java.awt.GraphicsEnvironment.isHeadless()) {
        File f = new File(fileName);
        if (f.exists()) {
            f.delete();
        }
        Beauti.main(("-template " + templateFile + " -nex examples/nexus/anolis.nex -out " + fileName + " -exitaction writexml").split(" "));
        f = new File(fileName);
        assertEquals(f.exists() && f.length() > 0, true);
    }
}
Also used : PrintStream(java.io.PrintStream) File(java.io.File) BeautiDoc(beast.app.beauti.BeautiDoc) ExampleXmlParsingTest(test.beast.integration.ExampleXmlParsingTest) Test(org.junit.Test)

Example 2 with BeautiDoc

use of beast.app.beauti.BeautiDoc in project beast2 by CompEvol.

the class InputEditorFactory method createInputEditor.

public InputEditor createInputEditor(Input<?> input, int listItemNr, BEASTInterface beastObject, boolean addButtons, ExpandOption forceExpansion, ButtonStatus buttonStatus, InputEditor editor, BeautiDoc doc) throws NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (input.getType() == null) {
        input.determineClass(beastObject);
    }
    // Class<?> inputClass = input.get() != null ? input.get().getClass(): input.getType();
    Class<?> inputClass = input.getType();
    if (inputClass == null) {
        return null;
    }
    if (listItemNr >= 0) {
        inputClass = ((List<?>) input.get()).get(listItemNr).getClass();
    } else {
        if (input.get() != null && !input.get().getClass().equals(inputClass) && !(input.get() instanceof ArrayList)) {
            Log.trace.println(input.get().getClass() + " != " + inputClass);
            inputClass = input.get().getClass();
        }
    }
    // Log.trace.print(inputClass.getName() + " => ");
    InputEditor inputEditor;
    // check whether the super.editor has a custom method for creating an Editor
    if (editor != null) {
        try {
            String name = input.getName();
            name = new String(name.charAt(0) + "").toUpperCase() + name.substring(1);
            name = "create" + name + "Editor";
            Class<?> _class = editor.getClass();
            Method method = _class.getMethod(name);
            inputEditor = (InputEditor) method.invoke(editor);
            // Log.trace.println(inputEditor.getClass().getName() + " (CUSTOM EDITOR)");
            return inputEditor;
        } catch (Exception e) {
        // ignore
        }
    }
    if (listItemNr < 0 && (List.class.isAssignableFrom(inputClass) || (input.get() != null && input.get() instanceof List<?>))) {
        // handle list inputs
        if (listInputEditorMap.containsKey(inputClass)) {
            // use custom list input editor
            String inputEditorName = listInputEditorMap.get(inputClass);
            Constructor<?> con = Class.forName(inputEditorName).getConstructor(BeautiDoc.class);
            inputEditor = (InputEditor) con.newInstance(doc);
        // inputEditor = (InputEditor) Class.forName(inputEditor).newInstance();
        } else {
            // otherwise, use generic list editor
            inputEditor = new ListInputEditor(doc);
        }
        ((ListInputEditor) inputEditor).setButtonStatus(buttonStatus);
    } else if (input.possibleValues != null) {
        // handle enumeration inputs
        inputEditor = new EnumInputEditor(doc);
    } else {
        Class<?> inputClass2 = inputClass;
        while (inputClass2 != null && !inputEditorMap.containsKey(inputClass2)) {
            inputClass2 = inputClass2.getSuperclass();
        }
        if (inputClass2 == null) {
            inputEditor = new BEASTObjectInputEditor(doc);
        } else {
            // handle BEASTObject-input with custom input editors
            String inputEditorName = inputEditorMap.get(inputClass2);
            Constructor<?> con = Class.forName(inputEditorName).getConstructor(BeautiDoc.class);
            inputEditor = (InputEditor) con.newInstance(doc);
        }
    }
    // } else if (inputEditorMap.containsKey(inputClass)) {
    // // handle BEASTObject-input with custom input editors
    // String inputEditor = inputEditorMap.get(inputClass);
    // 
    // Constructor<?> con = Class.forName(inputEditor).getConstructor(BeautiDoc.class);
    // inputEditor = (InputEditor) con.newInstance(doc);
    // //inputEditor = (InputEditor) Class.forName(inputEditor).newInstance(doc);
    // //} else if (inputClass.isEnum()) {
    // //    inputEditor = new EnumInputEditor();
    // } else {
    // // assume it is a general BEASTObject, so create a default BEASTObject input editor
    // inputEditor = new PluginInputEditor(doc);
    // }
    String fullInputName = beastObject.getClass().getName() + "." + input.getName();
    // System.err.println(fullInputName);
    ExpandOption expandOption = forceExpansion;
    if (doc.beautiConfig.inlineBEASTObject.contains(fullInputName) || forceExpansion == ExpandOption.TRUE_START_COLLAPSED) {
        expandOption = ExpandOption.TRUE;
        // deal with initially collapsed beastObjects
        if (doc.beautiConfig.collapsedBEASTObjects.contains(fullInputName) || forceExpansion == ExpandOption.TRUE_START_COLLAPSED) {
            if (input.get() != null) {
                Object o = input.get();
                if (o instanceof ArrayList) {
                    for (Object o2 : (ArrayList<?>) o) {
                        if (o2 instanceof BEASTInterface) {
                            String id = ((BEASTInterface) o2).getID();
                            if (!ListInputEditor.g_initiallyCollapsedIDs.contains(id)) {
                                ListInputEditor.g_initiallyCollapsedIDs.add(id);
                                ListInputEditor.g_collapsedIDs.add(id);
                            }
                        }
                    }
                } else if (o instanceof BEASTInterface) {
                    String id = ((BEASTInterface) o).getID();
                    if (!ListInputEditor.g_initiallyCollapsedIDs.contains(id)) {
                        ListInputEditor.g_initiallyCollapsedIDs.add(id);
                        ListInputEditor.g_collapsedIDs.add(id);
                    }
                }
            }
        }
    }
    inputEditor.setDoc(doc);
    inputEditor.init(input, beastObject, listItemNr, expandOption, addButtons);
    ((JComponent) inputEditor).setBorder(BorderFactory.createEmptyBorder());
    inputEditor.getComponent().setVisible(true);
    // Log.trace.println(inputEditor.getClass().getName());
    return inputEditor;
}
Also used : Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) Method(java.lang.reflect.Method) ExpandOption(beast.app.draw.InputEditor.ExpandOption) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) List(java.util.List) BEASTInterface(beast.core.BEASTInterface) BeautiDoc(beast.app.beauti.BeautiDoc)

Example 3 with BeautiDoc

use of beast.app.beauti.BeautiDoc in project beast2 by CompEvol.

the class BeautiTest method testStarBeastBatchMode.

@Test
public // as testStandarBatchMode() but for the *Beast template
void testStarBeastBatchMode() {
    BeautiDoc doc = new BeautiDoc();
    try {
        doc.processTemplate("templates/StarBeast.xml");
    } catch (Exception e) {
        assertEquals(true, false);
    }
    // ignore test if no X11 display available
    if (!java.awt.GraphicsEnvironment.isHeadless()) {
        File f = new File(fileName);
        if (f.exists()) {
            f.delete();
        }
        Beauti.main(("-template templates/StarBeast.xml -nex examples/nexus/26.nex -nex examples/nexus/29.nex -out " + fileName + " -exitaction writexml").split(" "));
        f = new File(fileName);
        assertEquals(f.exists() && f.length() > 0, true);
    }
}
Also used : File(java.io.File) BeautiDoc(beast.app.beauti.BeautiDoc) ExampleXmlParsingTest(test.beast.integration.ExampleXmlParsingTest) Test(org.junit.Test)

Example 4 with BeautiDoc

use of beast.app.beauti.BeautiDoc in project beast2 by CompEvol.

the class BeautiTest method testStandarBatchMode.

@Test
public // this requires that the standard template can be read
void testStandarBatchMode() {
    BeautiDoc doc = new BeautiDoc();
    try {
        doc.processTemplate("templates/Standard.xml");
    } catch (Exception e) {
        assertEquals(true, false);
    }
    // ignore test if no X11 display available
    if (!java.awt.GraphicsEnvironment.isHeadless()) {
        File f = new File(fileName);
        if (f.exists()) {
            f.delete();
        }
        Beauti.main(("-template templates/Standard.xml -nex examples/nexus/dna.nex -out " + fileName + " -exitaction writexml").split(" "));
        f = new File(fileName);
        assertEquals(f.exists() && f.length() > 0, true);
    }
}
Also used : File(java.io.File) BeautiDoc(beast.app.beauti.BeautiDoc) ExampleXmlParsingTest(test.beast.integration.ExampleXmlParsingTest) Test(org.junit.Test)

Aggregations

BeautiDoc (beast.app.beauti.BeautiDoc)4 File (java.io.File)3 Test (org.junit.Test)3 ExampleXmlParsingTest (test.beast.integration.ExampleXmlParsingTest)3 ExpandOption (beast.app.draw.InputEditor.ExpandOption)1 BEASTInterface (beast.core.BEASTInterface)1 PrintStream (java.io.PrintStream)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JComponent (javax.swing.JComponent)1