Search in sources :

Example 1 with TetradLoggerConfig

use of edu.cmu.tetrad.util.TetradLoggerConfig in project tetrad by cmu-phil.

the class SessionEditorNode method addEditLoggerSettings.

// private void addConsistentChildBoxMenus(JPopupMenu menu, List<String> consistentChildBoxes) {
// for (String _type : consistentChildBoxes) {
// final JMenuItem menuItem = new JMenuItem(_type);
// 
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// String text = menuItem.getText();
// String[] tokens = text.split(" ");
// String type = tokens[1];
// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, type);
// }
// });
// 
// menu.add(menuItem);
// }
// }
// private JMenu addConsistentChildBoxMenus(List<String> consistentChildBoxes) {
// JMenu newChildren = new JMenu("New Child Box");
// 
// for (String _type : consistentChildBoxes) {
// final JMenuItem menuItem = new JMenuItem(_type);
// 
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, menuItem.getText());
// }
// });
// 
// 
// 
// newChildren.add(menuItem);
// }
// return newChildren;
// }
// private JMenu addConsistentParentMenuItems(JPopupMenu menu, List<SessionNode> consistentParentNodes) {
// final JMenu newParents = new JMenu("New Parent Box");
// 
// for (final SessionNode node : consistentParentNodes) {
// final JMenuItem menuItem = new JMenuItem("Add Links: " + node.getDisplayName());
// 
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// String displayName1 = node.getDisplayName();
// String displayName2 = SessionEditorNode.this.getSessionNode().getDisplayName();
// new ConstructTemplateAction("Test").addEdge(displayName1, displayName2);
// }
// });
// 
// menu.add(menuItem);
// }
// 
// return newParents;
// }
// private List<String> getConsistentChildBoxTypes(SessionNode thisNode, SessionModel model) {
// List<String> consistentChildBoxes = new ArrayList<>();
// 
// List<Node> nodes = sessionWorkbench.getSessionWrapper().getNodes();
// List<SessionNode> sessionNodes = new ArrayList<>();
// for (Node node : nodes) sessionNodes.add(((SessionNodeWrapper) node).getSessionNode());
// 
// Set<String> strings = TetradApplicationConfig.getInstance().getConfigs().keySet();
// 
// for (String type : strings) {
// SessionNodeConfig config = TetradApplicationConfig.getInstance().getSessionNodeConfig(type);
// Class[] modelClasses = config.getModels();
// 
// SessionNode newNode = new SessionNode(modelClasses);
// 
// if (newNode.isConsistentParent(thisNode, sessionNodes)) {
// consistentChildBoxes.add("Add " + type);
// }
// }
// 
// return consistentChildBoxes;
// }
// private List<SessionNode> getConsistentParentBoxTypes(SessionNode thisNode) {
// List<SessionNode> consistentParentBoxes = new ArrayList<>();
// 
// for (Node _node : getSessionWorkbench().getSessionWrapper().getNodes()) {
// SessionNode node = ((SessionNodeWrapper) _node).getSessionNode();
// 
// if (sessionWorkbench.getSessionWrapper().isAncestorOf(thisNode, node)) {
// continue;
// }
// 
// if (!thisNode.getParents().contains(node) && thisNode.isConsistentParent(node)) {
// consistentParentBoxes.add(node);
// }
// }
// 
// return consistentParentBoxes;
// }
/**
 * Adds the "Edit logger" option if applicable.
 */
private void addEditLoggerSettings(JPopupMenu menu) {
    SessionNodeWrapper modelNode = (SessionNodeWrapper) getModelNode();
    SessionNode sessionNode = modelNode.getSessionNode();
    final TetradLoggerConfig config = sessionNode.getLoggerConfig();
    if (config != null) {
        JMenuItem item = new JMenuItem("Edit Logger Settings ...");
        item.addActionListener((e) -> {
            showLogConfig(config);
        });
        menu.add(item);
    }
}
Also used : TetradLoggerConfig(edu.cmu.tetrad.util.TetradLoggerConfig) SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode) JMenuItem(javax.swing.JMenuItem)

Example 2 with TetradLoggerConfig

use of edu.cmu.tetrad.util.TetradLoggerConfig in project tetrad by cmu-phil.

the class SessionEditorNode method showLogConfig.

/**
 * Shows a dialog that allows the user to change the settings for the box's
 * model logger.
 */
private void showLogConfig(final TetradLoggerConfig config) {
    List<TetradLoggerConfig.Event> events = config.getSupportedEvents();
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(3, events.size() / 3));
    for (TetradLoggerConfig.Event event : events) {
        final String id = event.getId();
        JCheckBox checkBox = new JCheckBox(event.getDescription());
        checkBox.setHorizontalTextPosition(AbstractButton.RIGHT);
        checkBox.setSelected(config.isEventActive(id));
        checkBox.addActionListener((e) -> {
            JCheckBox box = (JCheckBox) e.getSource();
            config.setEventActive(id, box.isSelected());
        });
        panel.add(checkBox);
    }
    panel.setBorder(new TitledBorder("Select Events to Log"));
    // how show the dialog
    JOptionPane.showMessageDialog(this, panel, "Edit Events to Log", JOptionPane.PLAIN_MESSAGE);
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) TetradLoggerConfig(edu.cmu.tetrad.util.TetradLoggerConfig) GridLayout(java.awt.GridLayout) ComponentEvent(java.awt.event.ComponentEvent) InternalFrameEvent(javax.swing.event.InternalFrameEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) MouseEvent(java.awt.event.MouseEvent) SessionEvent(edu.cmu.tetrad.session.SessionEvent) TitledBorder(javax.swing.border.TitledBorder)

Example 3 with TetradLoggerConfig

use of edu.cmu.tetrad.util.TetradLoggerConfig in project tetrad by cmu-phil.

the class TetradApplicationConfig method buildModelConfigs.

/**
 * Builds the model configs from the models element.
 */
private static List<SessionNodeModelConfig> buildModelConfigs(Element models) {
    Elements modelElements = models.getChildElements();
    List<SessionNodeModelConfig> configs = new LinkedList<>();
    ClassLoader loader = getClassLoader();
    for (int i = 0; i < modelElements.size(); i++) {
        Element model = modelElements.get(i);
        String name = model.getAttributeValue("name");
        String acronym = model.getAttributeValue("acronym");
        String help = model.getAttributeValue("help");
        String category = model.getAttributeValue("category");
        Class modelClass = null;
        Class editorClass = null;
        Class paramsClass = null;
        Class paramsEditorClass = null;
        TetradLoggerConfig loggerConfig = null;
        Elements elements = model.getChildElements();
        for (int k = 0; k < elements.size(); k++) {
            Element element = elements.get(k);
            if ("model-class".equals(element.getQualifiedName())) {
                modelClass = loadClass(loader, element.getValue());
            } else if ("editor-class".equals(element.getQualifiedName())) {
                editorClass = loadClass(loader, element.getValue());
            // } else if ("params-class".equals(element.getQualifiedName())) {
            // paramsClass = loadClass(loader, element.getValue());
            } else if ("params-editor-class".equals(element.getQualifiedName())) {
                paramsEditorClass = loadClass(loader, element.getValue());
            } else if ("logger".equals(element.getQualifiedName())) {
                loggerConfig = configureLogger(element);
            } else {
                throw new IllegalStateException("Unknown element: " + element.getQualifiedName());
            }
        }
        // if there is a logger config, add it with its model to the tetrad logger.
        if (loggerConfig != null) {
            TetradLogger.getInstance().addTetradLoggerConfig(modelClass, loggerConfig);
        }
        SessionNodeModelConfig config = new DefaultModelConfig(modelClass, paramsClass, paramsEditorClass, editorClass, name, acronym, help, category);
        configs.add(config);
    }
    return configs;
}
Also used : DefaultTetradLoggerConfig(edu.cmu.tetrad.util.DefaultTetradLoggerConfig) TetradLoggerConfig(edu.cmu.tetrad.util.TetradLoggerConfig) Element(nu.xom.Element) Elements(nu.xom.Elements)

Example 4 with TetradLoggerConfig

use of edu.cmu.tetrad.util.TetradLoggerConfig in project tetrad by cmu-phil.

the class TetradApplicationConfig method configureLogger.

/**
 * Configures the logger that the given element represents and returns its
 * id.
 */
private static TetradLoggerConfig configureLogger(Element logger) {
    Elements elements = logger.getChildElements();
    List<TetradLoggerConfig.Event> events = new LinkedList<>();
    List<String> defaultLog = new LinkedList<>();
    for (int i = 0; i < elements.size(); i++) {
        Element event = elements.get(i);
        String eventId = event.getAttributeValue("id");
        String description = event.getAttributeValue("description");
        String defaultOption = event.getAttributeValue("default");
        if (defaultOption != null && defaultOption.equals("on")) {
            defaultLog.add(eventId);
        }
        events.add(new DefaultTetradLoggerConfig.DefaultEvent(eventId, description));
    }
    TetradLoggerConfig config = new DefaultTetradLoggerConfig(events);
    // set any defaults
    for (String event : defaultLog) {
        config.setEventActive(event, true);
    }
    return config;
}
Also used : DefaultTetradLoggerConfig(edu.cmu.tetrad.util.DefaultTetradLoggerConfig) TetradLoggerConfig(edu.cmu.tetrad.util.TetradLoggerConfig) Element(nu.xom.Element) Elements(nu.xom.Elements) DefaultTetradLoggerConfig(edu.cmu.tetrad.util.DefaultTetradLoggerConfig)

Aggregations

TetradLoggerConfig (edu.cmu.tetrad.util.TetradLoggerConfig)4 DefaultTetradLoggerConfig (edu.cmu.tetrad.util.DefaultTetradLoggerConfig)2 Element (nu.xom.Element)2 Elements (nu.xom.Elements)2 SessionEvent (edu.cmu.tetrad.session.SessionEvent)1 SessionNode (edu.cmu.tetrad.session.SessionNode)1 SessionNodeWrapper (edu.cmu.tetradapp.model.SessionNodeWrapper)1 GridLayout (java.awt.GridLayout)1 ComponentEvent (java.awt.event.ComponentEvent)1 MouseEvent (java.awt.event.MouseEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 JCheckBox (javax.swing.JCheckBox)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 TitledBorder (javax.swing.border.TitledBorder)1 InternalFrameEvent (javax.swing.event.InternalFrameEvent)1