001package com.ganteater.ae.desktop.ui;
002
003import java.awt.BorderLayout;
004import java.util.Vector;
005
006import javax.swing.BorderFactory;
007import javax.swing.BoxLayout;
008import javax.swing.JCheckBox;
009import javax.swing.JLabel;
010import javax.swing.JPanel;
011import javax.swing.JScrollPane;
012import javax.swing.JTabbedPane;
013import javax.swing.JTextArea;
014import javax.swing.JTextField;
015
016import org.apache.commons.lang.StringUtils;
017
018import com.ganteater.ae.AEWorkspace;
019import com.ganteater.ae.util.xml.easyparser.Node;
020
021public class ConfigurationPanel extends JPanel {
022
023        private static final long serialVersionUID = 1L;
024        private AEFrame aeFrame;
025
026        public ConfigurationPanel(AEFrame aeFrame) {
027                setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
028                this.aeFrame = aeFrame;
029        }
030
031        public void setConfigNode(Node configs) throws Exception {
032
033                removeAll();
034
035                Vector<String> names = new Vector<>();
036                names.add(StringUtils.EMPTY);
037                for (int i = 0; i < configs.size(); i++) {
038                        Node node = configs.getNode(i);
039                        if (AEWorkspace.CONFIGURATION_TITLE.equals(node.getTag())) {
040                                String attribute = node.getAttribute("name");
041                                if (attribute != null) {
042                                        names.add(attribute);
043                                }
044                        }
045                }
046
047                JTabbedPane tabbedPane = new JTabbedPane();
048                for (int i = 0; i < configs.size(); i++) {
049                        JTextArea textArea = new JTextArea();
050                        textArea.setBorder(BorderFactory.createRaisedBevelBorder());
051                        textArea.setTabSize(2);
052                        textArea.setEditable(false);
053                        textArea.setLineWrap(true);
054
055                        Node node = configs.getNode(i);
056                        String name = node.getAttribute("name");
057
058                        if (!"Comment".equals(node.getTag())) {
059                                JPanel panel = new JPanel(new BorderLayout());
060
061                                StringBuilder text = new StringBuilder();
062                                for (int j = 0; j < node.size(); j++) {
063                                        text.append(node.getNode(j).getXMLText());
064                                }
065                                textArea.setText(text.toString());
066
067                                JPanel panel2 = new JPanel();
068                                JCheckBox checkBox = new JCheckBox(" Configuration name:");
069                                Node configNode = aeFrame.getWorkspace().getConfigNode();
070                                String attribute = configNode.getAttribute("name");
071                                boolean equals = StringUtils.equals(name, attribute);
072                                checkBox.setSelected(equals);
073                                checkBox.setEnabled(false);
074                                panel2.add(checkBox);
075
076                                JTextField textField = new JTextField(name);
077                                textField.setOpaque(false);
078                                textField.setEditable(false);
079                                textField.setBorder(BorderFactory.createEmptyBorder());
080
081                                JPanel panel3 = new JPanel(new BorderLayout(4, 4));
082                                panel3.add(textField);
083                                panel3.add(panel2, BorderLayout.WEST);
084
085                                String base = node.getAttribute("base");
086                                if (base != null) {
087                                        panel2 = new JPanel();
088                                        panel2.add(new JLabel("Base configuration:"));
089                                        panel2.add(new JLabel(base));
090                                        panel3.add(panel2, BorderLayout.EAST);
091                                }
092
093                                panel.add(panel3, BorderLayout.NORTH);
094                                panel.add(new JScrollPane(textArea));
095                                tabbedPane.add(name, panel);
096                        }
097
098                }
099                add(tabbedPane);
100        }
101
102}