Search in sources :

Example 1 with ExpandOption

use of beast.app.draw.InputEditor.ExpandOption in project beast2 by CompEvol.

the class BeautiPanel method refreshInputPanel.

void refreshInputPanel() throws NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    doc.currentInputEditors.clear();
    InputEditor.Base.g_nLabelWidth = config.labelWidthInput.get();
    BEASTInterface beastObject = config;
    final Input<?> input = config.resolveInput(doc, partitionIndex);
    boolean addButtons = config.addButtons();
    ExpandOption forceExpansion = config.forceExpansion();
    refreshInputPanel(beastObject, input, addButtons, forceExpansion);
}
Also used : BEASTInterface(beast.core.BEASTInterface) ExpandOption(beast.app.draw.InputEditor.ExpandOption)

Example 2 with ExpandOption

use of beast.app.draw.InputEditor.ExpandOption 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)

Aggregations

ExpandOption (beast.app.draw.InputEditor.ExpandOption)2 BEASTInterface (beast.core.BEASTInterface)2 BeautiDoc (beast.app.beauti.BeautiDoc)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