Search in sources :

Example 1 with DTDResolver

use of ffx.ui.commands.DTDResolver in project ffx by mjschnie.

the class ModelingPanel method initialize.

private void initialize() {
    // Command Description
    descriptTextArea = new JTextArea();
    descriptTextArea.setEditable(false);
    descriptTextArea.setLineWrap(true);
    descriptTextArea.setWrapStyleWord(true);
    descriptTextArea.setDoubleBuffered(true);
    Insets insets = descriptTextArea.getInsets();
    insets.set(5, 5, 5, 5);
    descriptTextArea.setMargin(insets);
    descriptScrollPane = new JScrollPane(descriptTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    descriptScrollPane.setBorder(etchedBorder);
    // Command Input
    commandTextArea = new JTextArea();
    commandTextArea.setEditable(false);
    commandTextArea.setLineWrap(true);
    commandTextArea.setWrapStyleWord(true);
    commandTextArea.setDoubleBuffered(true);
    commandTextArea.setMargin(insets);
    // Command Options
    optionsTabbedPane = new JTabbedPane();
    statusLabel = new JLabel();
    statusLabel.setBorder(etchedBorder);
    statusLabel.setToolTipText("  Modeling command that will be executed");
    commandPanel = new JPanel(flowLayout);
    commandPanel.add(optionsTabbedPane);
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, commandPanel, descriptScrollPane);
    splitPane.setContinuousLayout(true);
    splitPane.setResizeWeight(1.0d);
    splitPane.setOneTouchExpandable(true);
    setLayout(new BorderLayout());
    add(splitPane, BorderLayout.CENTER);
    add(statusLabel, BorderLayout.SOUTH);
    // Initialize the Amino/Nucleic Acid ComboBox.
    acidComboBox.setEditable(false);
    acidComboBox.setMaximumSize(sizer.getPreferredSize());
    acidComboBox.setPreferredSize(sizer.getPreferredSize());
    acidComboBox.setMinimumSize(sizer.getPreferredSize());
    acidComboBox.setFont(Font.decode("Monospaced"));
    acidTextField.setMaximumSize(sizer.getPreferredSize());
    acidTextField.setMinimumSize(sizer.getPreferredSize());
    acidTextField.setPreferredSize(sizer.getPreferredSize());
    acidTextArea.setEditable(false);
    acidTextArea.setWrapStyleWord(true);
    acidTextArea.setLineWrap(true);
    acidTextArea.setFont(Font.decode("Monospaced"));
    acidScrollPane = new JScrollPane(acidTextArea);
    Dimension d = new Dimension(300, 400);
    acidScrollPane.setPreferredSize(d);
    acidScrollPane.setMaximumSize(d);
    acidScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    // Load the FFX commands.xml file that defines FFX commands.
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setEntityResolver(new DTDResolver());
        URL comURL = getClass().getClassLoader().getResource("ffx/ui/commands/commands.xml");
        Document doc = db.parse(comURL.openStream());
        NodeList nodelist = doc.getChildNodes();
        Node commandroot = null;
        for (int i = 0; i < nodelist.getLength(); i++) {
            commandroot = nodelist.item(i);
            if (commandroot.getNodeName().equals("FFXCommands") && commandroot instanceof Element) {
                break;
            }
        }
        if (commandroot == null || !(commandroot instanceof Element)) {
            commandList = null;
        }
        commandList = ((Element) commandroot).getElementsByTagName("Command");
    } catch (ParserConfigurationException | SAXException | IOException e) {
        System.err.println(e);
    } finally {
        if (commandList == null) {
            System.out.println("Force Field X commands.xml could not be parsed.");
            logger.severe("Force Field X will exit.");
            System.exit(-1);
        }
    }
    // Create a ComboBox with commands specific to each type of coordinate
    // file.
    xyzCommands = new JComboBox<>();
    intCommands = new JComboBox<>();
    arcCommands = new JComboBox<>();
    pdbCommands = new JComboBox<>();
    anyCommands = new JComboBox<>();
    Element command;
    String name;
    int numcommands = commandList.getLength();
    for (int i = 0; i < numcommands; i++) {
        command = (Element) commandList.item(i);
        name = command.getAttribute("name");
        String temp = command.getAttribute("fileType");
        if (temp.contains("ANY")) {
            temp = "XYZ INT ARC PDB";
            anyCommands.addItem(name);
        }
        String[] types = temp.split(" +");
        for (String type : types) {
            if (type.contains("XYZ")) {
                xyzCommands.addItem(name);
            }
            if (type.contains("INT")) {
                intCommands.addItem(name);
            }
            if (type.contains("ARC")) {
                arcCommands.addItem(name);
            }
            if (type.contains("PDB")) {
                pdbCommands.addItem(name);
            }
        }
    }
    initCommandComboBox(xyzCommands);
    initCommandComboBox(intCommands);
    initCommandComboBox(arcCommands);
    initCommandComboBox(pdbCommands);
    initCommandComboBox(anyCommands);
    currentCommandBox = anyCommands;
    activeCommand = (String) anyCommands.getSelectedItem();
    // Load the default Command.
    loadCommand();
    // Load the default Log File Settings.
    logSettings.setActionCommand("LogSettings");
    loadLogSettings();
    // Create the Toolbar.
    toolBar = new JToolBar("Modeling Commands", JToolBar.HORIZONTAL);
    toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
    jbLaunch = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/cog_go.png")));
    jbLaunch.setActionCommand("Launch");
    jbLaunch.setToolTipText("Launch the Force Field X Command");
    jbLaunch.addActionListener(this);
    insets.set(2, 2, 2, 2);
    jbLaunch.setMargin(insets);
    toolBar.add(jbLaunch);
    jbStop = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/stop.png")));
    jbStop.setActionCommand("End");
    jbStop.setToolTipText("Terminate the Current Force Field X Command");
    jbStop.addActionListener(this);
    jbStop.setMargin(insets);
    jbStop.setEnabled(false);
    toolBar.add(jbStop);
    toolBar.addSeparator();
    toolBar.add(anyCommands);
    currentCommandBox = anyCommands;
    toolBar.addSeparator();
    /*
         toolBar.add(logSettings);
         JButton jbdelete = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/page_delete.png")));
         jbdelete.setActionCommand("Delete");
         jbdelete.setToolTipText("Delete Log Files");
         jbdelete.addActionListener(this);
         jbdelete.setMargin(insets);
         toolBar.add(jbdelete);
         toolBar.addSeparator();
         */
    ImageIcon icinfo = new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/information.png"));
    descriptCheckBox = new JCheckBoxMenuItem(icinfo);
    descriptCheckBox.addActionListener(this);
    descriptCheckBox.setActionCommand("Description");
    descriptCheckBox.setToolTipText("Show/Hide Modeling Command Descriptions");
    descriptCheckBox.setMargin(insets);
    toolBar.add(descriptCheckBox);
    toolBar.add(new JLabel(""));
    toolBar.setBorderPainted(false);
    toolBar.setFloatable(false);
    toolBar.setRollover(true);
    add(toolBar, BorderLayout.NORTH);
    // Load ModelingPanel preferences.
    Preferences prefs = Preferences.userNodeForPackage(ffx.ui.ModelingPanel.class);
    descriptCheckBox.setSelected(!prefs.getBoolean("JobPanel_description", true));
    descriptCheckBox.doClick();
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) JTextArea(javax.swing.JTextArea) Insets(java.awt.Insets) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) FlowLayout(java.awt.FlowLayout) JTabbedPane(javax.swing.JTabbedPane) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) JButton(javax.swing.JButton) Document(org.w3c.dom.Document) URL(java.net.URL) SAXException(org.xml.sax.SAXException) DTDResolver(ffx.ui.commands.DTDResolver) BorderLayout(java.awt.BorderLayout) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Preferences(java.util.prefs.Preferences) JScrollPane(javax.swing.JScrollPane) NodeList(org.w3c.dom.NodeList) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) IOException(java.io.IOException) JToolBar(javax.swing.JToolBar) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) DocumentBuilder(javax.xml.parsers.DocumentBuilder) JSplitPane(javax.swing.JSplitPane)

Example 2 with DTDResolver

use of ffx.ui.commands.DTDResolver in project ffx by mjschnie.

the class KeywordPanel method loadXML.

/**
 * Load up the Force Field X Keyword Definitions
 */
private void loadXML() {
    NodeList groups, keywords, values;
    Element group, keyword, value;
    String groupName;
    String keywordName, keywordDescription, keywordGUI;
    groups = null;
    try {
        // Build the Document from the keywords.xml file
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setEntityResolver(new DTDResolver());
        URL keyURL = getClass().getClassLoader().getResource("ffx/ui/commands/keywords.xml");
        Document doc = db.parse(keyURL.openStream());
        Element document = doc.getDocumentElement();
        Element body = (Element) document.getElementsByTagName("body").item(0);
        groups = body.getElementsByTagName("section");
    } catch (ParserConfigurationException | SAXException | IOException e) {
        logger.warning(e.toString());
    }
    keywordHashMap = new LinkedHashMap<>();
    groupHashMap = new LinkedHashMap<>();
    groupHashMap.put("ACTIVE KEYWORDS", "Active Keywords");
    groupHashMap.put("FLAT FILE VIEW", "Flat File View");
    groupComboBox = new JComboBox<>();
    groupComboBox.addItem("Active Keywords");
    groupComboBox.addItem("Flat File View");
    descriptTextArea = new JTextArea();
    descriptTextArea.setLineWrap(true);
    descriptTextArea.setWrapStyleWord(true);
    Insets insets = descriptTextArea.getInsets();
    insets.set(5, 5, 5, 5);
    descriptTextArea.setMargin(insets);
    int length = groups.getLength();
    // Iterate through the Keyword Groups
    for (int i = 0; i < length; i++) {
        group = (Element) groups.item(i);
        groupName = group.getAttribute("name");
        groupComboBox.addItem(groupName);
        keywords = group.getElementsByTagName("subsection");
        int klength = keywords.getLength();
        for (int j = 0; j < klength; j++) {
            keyword = (Element) keywords.item(j);
            keywordName = keyword.getAttribute("name");
            Node text = keyword.getFirstChild();
            keywordDescription = text.getNodeValue().replace('\n', ' ');
            keywordDescription = keywordDescription.replaceAll("  +", " ");
            keywordGUI = keyword.getAttribute("rep");
            KeywordComponent.SwingRepresentation type;
            try {
                type = KeywordComponent.SwingRepresentation.valueOf(keywordGUI.toUpperCase());
            } catch (Exception e) {
                type = null;
                logger.log(Level.WARNING, "{0}: Unknown GUI Component - {1}", new Object[] { keywordName, type });
                System.exit(-1);
            }
            KeywordComponent key;
            if (type == KeywordComponent.SwingRepresentation.CHECKBOXES || type == KeywordComponent.SwingRepresentation.COMBOBOX) {
                values = keyword.getElementsByTagName("Value");
                String[] labels = new String[values.getLength()];
                for (int k = 0; k < values.getLength(); k++) {
                    value = (Element) values.item(k);
                    labels[k] = value.getAttribute("name");
                }
                key = new KeywordComponent(keywordName, groupName, type, keywordDescription, descriptTextArea, labels);
            } else {
                key = new KeywordComponent(keywordName, groupName, type, keywordDescription, descriptTextArea);
            }
            keywordHashMap.put(keywordName.toUpperCase(), key);
            groupHashMap.put(groupName.toUpperCase(), groupName);
        }
    }
    groupComboBox.setSelectedIndex(0);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) JTextArea(javax.swing.JTextArea) Insets(java.awt.Insets) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) DTDResolver(ffx.ui.commands.DTDResolver) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

DTDResolver (ffx.ui.commands.DTDResolver)2 Insets (java.awt.Insets)2 IOException (java.io.IOException)2 URL (java.net.URL)2 JTextArea (javax.swing.JTextArea)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 SAXException (org.xml.sax.SAXException)2 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 FileNotFoundException (java.io.FileNotFoundException)1 Preferences (java.util.prefs.Preferences)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1