ConcreteSyntaxTreePanel.java

/*
 * Copyright 2013 Michael Mackenzie High
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mackenziehigh.snowflake.designer.gui.tabs;

import com.mackenziehigh.snowflake.designer.gui.DisplayableTreeNode;
import java.awt.Color;
import javax.swing.JTextArea;
import javax.swing.JTree;

/**
 *
 * @author mackenzie
 */
public class ConcreteSyntaxTreePanel
        extends javax.swing.JPanel
{
    /**
     * Creates new form ConcreteSyntaxTreePanel
     */
    public ConcreteSyntaxTreePanel()
    {
        initComponents();
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jScrollPane2 = new javax.swing.JScrollPane();
        nodeTextArea = new javax.swing.JTextArea();

        setName("Form"); // NOI18N

        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTree1.setModel(null);
        jTree1.setName("jTree1"); // NOI18N
        jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener()
        {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt)
            {
                jTree1ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jTree1);

        jSplitPane1.setLeftComponent(jScrollPane1);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        nodeTextArea.setColumns(20);
        nodeTextArea.setRows(5);
        nodeTextArea.setName("nodeTextArea"); // NOI18N
        jScrollPane2.setViewportView(nodeTextArea);

        jSplitPane1.setRightComponent(jScrollPane2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        jSplitPane1.setResizeWeight(0.5);
    }// </editor-fold>//GEN-END:initComponents

    private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTree1ValueChanged

        final Object obj = evt.getPath().getLastPathComponent();

        if (obj instanceof DisplayableTreeNode)
        {
            nodeTextArea.setForeground(Color.BLACK);
            nodeTextArea.setText(((DisplayableTreeNode) obj).getMatchText());
        }
        else
        {
            nodeTextArea.setForeground(Color.RED);
            nodeTextArea.setText("<error>");
        }
    }//GEN-LAST:event_jTree1ValueChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTree jTree1;
    private javax.swing.JTextArea nodeTextArea;
    // End of variables declaration//GEN-END:variables

    public JTree getParseTree()
    {
        return jTree1;
    }

    public JTextArea getTextArea()
    {
        return nodeTextArea;
    }
}