001package com.ganteater.ae.desktop.ui;
002
003import java.awt.BorderLayout;
004
005import javax.swing.JPanel;
006import javax.swing.JScrollPane;
007import javax.swing.JTabbedPane;
008import javax.swing.JTextArea;
009
010import com.ganteater.ae.AEWorkspace;
011import com.ganteater.ae.util.xml.easyparser.EasyUtils;
012import com.ganteater.ae.util.xml.easyparser.Node;
013
014public class ConfigurationView extends JPanel implements AEPanel {
015
016        private static final long serialVersionUID = 1L;
017
018        private JTextArea resultConfiguration;
019
020        private ConfigurationPanel configuration;
021
022        private AEFrame aeFrame;
023
024        public ConfigurationView(AEFrame aeFrame) {
025                super(new BorderLayout());
026
027                this.aeFrame = aeFrame;
028                setLayout(new BorderLayout(4, 4));
029                resultConfiguration = new JTextArea();
030                resultConfiguration.setTabSize(2);
031                resultConfiguration.setEditable(false);
032
033                configuration = new ConfigurationPanel(aeFrame);
034
035                JTabbedPane panel = new JTabbedPane();
036                panel.addTab("Defined", configuration);
037                panel.addTab("Effective", new JScrollPane(resultConfiguration));
038
039                add(panel, BorderLayout.CENTER);
040        }
041
042        public JPanel getMainPanel() {
043                return this;
044        }
045
046        public String getPanelName() {
047                return AEWorkspace.CONFIGURATION_TITLE;
048        }
049
050        @Override
051        public void setVisible(boolean aFlag) {
052                refreshActiveConfig();
053                super.setVisible(aFlag);
054        }
055
056        public void refreshActiveConfig() {
057                Node configNode = aeFrame.getWorkspace().getConfigNode();
058                EasyUtils.removeTagId(configNode);
059                resultConfiguration.setText(configNode.getXMLText());
060                try {
061                        Node configs = aeFrame.getWorkspace().getAllConfigNode();
062                        configuration.setConfigNode(configs);
063                        invalidate();
064
065                } catch (Exception e) {
066                        e.printStackTrace();
067                }
068        }
069
070        public void showPanel(JTabbedPane panel, String name) {
071                if (name == null) {
072                        name = getPanelName();
073                }
074                panel.addTab(getPanelName(), this);
075                panel.setSelectedComponent(this);
076                panel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
077        }
078
079}