|
@@ -4,7 +4,6 @@ import java.awt.AWTEvent;
|
|
|
import java.awt.AWTException;
|
|
import java.awt.AWTException;
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Color;
|
|
import java.awt.Color;
|
|
|
-import java.awt.Container;
|
|
|
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.GridBagConstraints;
|
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagLayout;
|
|
|
import java.awt.Image;
|
|
import java.awt.Image;
|
|
@@ -24,16 +23,19 @@ import java.util.Map;
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.BorderFactory;
|
|
|
-import javax.swing.BoxLayout;
|
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
+import javax.swing.JScrollPane;
|
|
|
import javax.swing.JTextArea;
|
|
import javax.swing.JTextArea;
|
|
|
import javax.swing.JTextField;
|
|
import javax.swing.JTextField;
|
|
|
import javax.swing.Timer;
|
|
import javax.swing.Timer;
|
|
|
|
|
|
|
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
|
|
+import org.leanwo.management.exception.ConfigFileException;
|
|
|
import org.leanwo.management.util.SpringUtil;
|
|
import org.leanwo.management.util.SpringUtil;
|
|
|
import org.leanwo.management.util.XmlConfigPathService;
|
|
import org.leanwo.management.util.XmlConfigPathService;
|
|
|
|
|
|
|
@@ -46,71 +48,99 @@ import com.leanwo.management.model.XmlConfigPath;
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
public class ServerSettingJFrame extends JFrame{
|
|
public class ServerSettingJFrame extends JFrame{
|
|
|
|
|
+
|
|
|
|
|
+ private static Log logger = LogFactory.getLog(ServerSettingJFrame.class);
|
|
|
|
|
+
|
|
|
private ApplicationSetting applicationSetting;
|
|
private ApplicationSetting applicationSetting;
|
|
|
private XmlConfigPath xmlConfigPath;
|
|
private XmlConfigPath xmlConfigPath;
|
|
|
private XmlConfigPathService xmlConfigPathService;
|
|
private XmlConfigPathService xmlConfigPathService;
|
|
|
- private Container jPanel = null;
|
|
|
|
|
|
|
+ private JPanel mainPanel = null;
|
|
|
|
|
+ private JPanel innerPanel = null;
|
|
|
|
|
+ private GridBagConstraints constrains = null;
|
|
|
private JLabel label = null;
|
|
private JLabel label = null;
|
|
|
private JTextField portTextField;
|
|
private JTextField portTextField;
|
|
|
private JTextField tokenTextField;
|
|
private JTextField tokenTextField;
|
|
|
private Map<String, JTextArea> textAreas = new HashMap<String, JTextArea>();
|
|
private Map<String, JTextArea> textAreas = new HashMap<String, JTextArea>();
|
|
|
private JButton saveButton;
|
|
private JButton saveButton;
|
|
|
|
|
|
|
|
|
|
+ private int index = 0;
|
|
|
|
|
+
|
|
|
public ServerSettingJFrame(ApplicationSetting applicationSetting) {
|
|
public ServerSettingJFrame(ApplicationSetting applicationSetting) {
|
|
|
-
|
|
|
|
|
- this.jPanel = this.getContentPane();
|
|
|
|
|
-
|
|
|
|
|
this.setSize(800, 600);
|
|
this.setSize(800, 600);
|
|
|
this.setTitle("程序配置管理器");
|
|
this.setTitle("程序配置管理器");
|
|
|
|
|
+
|
|
|
|
|
+ this.mainPanel = new JPanel(new BorderLayout());
|
|
|
|
|
+ this.add(mainPanel);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
this.xmlConfigPathService = (XmlConfigPathService) SpringUtil.getSingleBean(XmlConfigPathService.class);
|
|
this.xmlConfigPathService = (XmlConfigPathService) SpringUtil.getSingleBean(XmlConfigPathService.class);
|
|
|
this.applicationSetting = applicationSetting;
|
|
this.applicationSetting = applicationSetting;
|
|
|
- this.xmlConfigPathService.load(applicationSetting);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ this.xmlConfigPathService.load(applicationSetting);
|
|
|
|
|
+ }catch(ConfigFileException ex) {
|
|
|
|
|
+ logger.error("配置文件异常", ex);
|
|
|
|
|
+ JOptionPane.showMessageDialog(null, ex.getMessage(), "配置文件异常", JOptionPane.ERROR_MESSAGE);
|
|
|
|
|
+ this.dispose();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
this.xmlConfigPath = applicationSetting.getXmlConfigPath();
|
|
this.xmlConfigPath = applicationSetting.getXmlConfigPath();
|
|
|
- jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
|
|
|
|
|
|
|
+ this.innerPanel = new JPanel(new GridBagLayout());
|
|
|
|
|
+
|
|
|
|
|
+ this.constrains = new GridBagConstraints();
|
|
|
|
|
+ this.constrains.insets = new Insets(5, 5, 5, 5);
|
|
|
|
|
+ this.constrains.fill = GridBagConstraints.BOTH;
|
|
|
|
|
+ this.constrains.gridx = 0;
|
|
|
|
|
+ this.constrains.gridy = index;
|
|
|
|
|
+ this.constrains.weightx = 100;
|
|
|
|
|
+ this.constrains.anchor = GridBagConstraints.NORTH;
|
|
|
|
|
+
|
|
|
|
|
+ JScrollPane scrollPanel = new JScrollPane(innerPanel);
|
|
|
|
|
+ mainPanel.add(scrollPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
if(this.xmlConfigPath != null) {
|
|
if(this.xmlConfigPath != null) {
|
|
|
- label = new JLabel("端口号");
|
|
|
|
|
- label.setAlignmentY(LEFT_ALIGNMENT);
|
|
|
|
|
-
|
|
|
|
|
- jPanel.add(label);
|
|
|
|
|
|
|
+ label = new JLabel("端口号");
|
|
|
|
|
+ innerPanel.add(label, constrains);
|
|
|
|
|
|
|
|
portTextField = new JTextField();
|
|
portTextField = new JTextField();
|
|
|
- portTextField.setAlignmentY(LEFT_ALIGNMENT);
|
|
|
|
|
|
|
+ portTextField.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK));
|
|
|
if(xmlConfigPath.getPortNo() != null) {
|
|
if(xmlConfigPath.getPortNo() != null) {
|
|
|
portTextField.setText(xmlConfigPath.getPortNo().toString());
|
|
portTextField.setText(xmlConfigPath.getPortNo().toString());
|
|
|
}
|
|
}
|
|
|
- jPanel.add(portTextField);
|
|
|
|
|
|
|
+ this.constrains.gridy = ++ index;
|
|
|
|
|
+ innerPanel.add(portTextField, constrains);
|
|
|
|
|
|
|
|
|
|
|
|
|
label = new JLabel("Token");
|
|
label = new JLabel("Token");
|
|
|
- label.setAlignmentY(LEFT_ALIGNMENT);
|
|
|
|
|
- jPanel.add(label);
|
|
|
|
|
|
|
+ this.constrains.gridy = ++ index;
|
|
|
|
|
+ innerPanel.add(label, constrains);
|
|
|
|
|
|
|
|
tokenTextField = new JTextField();
|
|
tokenTextField = new JTextField();
|
|
|
- tokenTextField.setAlignmentY(LEFT_ALIGNMENT);
|
|
|
|
|
- tokenTextField.setText(xmlConfigPath.getToken());
|
|
|
|
|
- jPanel.add(tokenTextField);
|
|
|
|
|
|
|
+ tokenTextField.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK));
|
|
|
|
|
+ this.constrains.gridy = ++ index;
|
|
|
|
|
+ innerPanel.add(tokenTextField, constrains);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> contents = applicationSetting.getXmlConfigPath().getContents();
|
|
Map<String, String> contents = applicationSetting.getXmlConfigPath().getContents();
|
|
|
for(String key : contents.keySet()) {
|
|
for(String key : contents.keySet()) {
|
|
|
label = new JLabel(key);
|
|
label = new JLabel(key);
|
|
|
- label.setAlignmentY(LEFT_ALIGNMENT);
|
|
|
|
|
- jPanel.add(label);
|
|
|
|
|
|
|
+ this.constrains.gridy = ++ index;
|
|
|
|
|
+ innerPanel.add(label, constrains);
|
|
|
|
|
|
|
|
JTextArea textArea = new JTextArea();
|
|
JTextArea textArea = new JTextArea();
|
|
|
- textArea.setAlignmentY(LEFT_ALIGNMENT);
|
|
|
|
|
textArea.setText(contents.get(key));
|
|
textArea.setText(contents.get(key));
|
|
|
- textArea.setSelectedTextColor(Color.RED);
|
|
|
|
|
- textArea.setLineWrap(true); //激活自动换行功能
|
|
|
|
|
- textArea.setWrapStyleWord(true); // 激活断行不断字功能
|
|
|
|
|
- jPanel.add(textArea);
|
|
|
|
|
|
|
+ textArea.setRows(5);
|
|
|
|
|
+ textArea.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK));
|
|
|
textAreas.put(key, textArea);
|
|
textAreas.put(key, textArea);
|
|
|
|
|
+ this.constrains.gridy = ++ index;
|
|
|
|
|
+ innerPanel.add(textArea, constrains);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ index ++;
|
|
|
saveButton = new JButton("保存");
|
|
saveButton = new JButton("保存");
|
|
|
- jPanel.add(saveButton);
|
|
|
|
|
|
|
+ this.constrains.gridy = ++ index;
|
|
|
|
|
+ innerPanel.add(saveButton, constrains);
|
|
|
|
|
|
|
|
saveButton.addActionListener(new ActionListener() {
|
|
saveButton.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
@Override
|
|
@@ -136,5 +166,10 @@ public class ServerSettingJFrame extends JFrame{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
|
|
|
+// this.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
|
|
|
+// public void windowClosing(java.awt.event.WindowEvent e) {
|
|
|
|
|
+// ServerSettingJFrame.this.setVisible(false);
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|