package views;
import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import model.Model;
import antlr.CommonAST;
import antlr.debug.misc.JTreeASTModel;
import application.Application;
public class RegExTreePanel extends JPanel implements PropertyChangeListener{
private JTreeASTModel treeModel = null;
private DefaultTreeCellRenderer renderer = null;
private JScrollPane jScrollPane = null;
private JTree jTree = null;
public RegExTreePanel(Model model) {
super();
model.addPropertyChangeListener(this);
initialize();
}
/**
* This method initializes this
*
*/
private void initialize() {
// Graphic settings
renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(new ImageIcon(this.getClass().getClassLoader().getResource("images/item.png")));
renderer.setClosedIcon(new ImageIcon(this.getClass().getClassLoader().getResource("images/folder_blue.png")));
renderer.setOpenIcon(new ImageIcon(this.getClass().getClassLoader().getResource("images/folder_blue_open.png")));
this.setLayout(new BorderLayout());
this.setSize(new java.awt.Dimension(300,550));
this.setBorder(BorderFactory.createTitledBorder(Application.messages.getString("TITLE_REGULAR_EXPRESSION_TREE")));
this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTree());
}
return jScrollPane;
}
/**
* This method initializes jTree
*
* @return javax.swing.JTree
*/
private JTree getJTree() {
jTree = new JTree(treeModel);
jTree.setRootVisible(false);
jTree.setCellRenderer(renderer);
return jTree;
}
public void propertyChange(PropertyChangeEvent arg0) {
if (arg0.getPropertyName() == "regExTree" && arg0.getNewValue() != null) {
if(arg0.getNewValue() == null)
return;
this.treeModel = new JTreeASTModel((CommonAST)arg0.getNewValue());
this.jScrollPane.setViewportView(getJTree());
this.validate();
}
}
}