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