|
|
@@ -0,0 +1,183 @@
|
|
|
+package com.leanwo.management;
|
|
|
+
|
|
|
+import java.awt.AWTEvent;
|
|
|
+import java.awt.AWTException;
|
|
|
+import java.awt.BorderLayout;
|
|
|
+import java.awt.GridBagConstraints;
|
|
|
+import java.awt.GridBagLayout;
|
|
|
+import java.awt.Image;
|
|
|
+import java.awt.Insets;
|
|
|
+import java.awt.SystemTray;
|
|
|
+import java.awt.TrayIcon;
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
+import java.awt.event.ActionListener;
|
|
|
+import java.awt.event.MouseAdapter;
|
|
|
+import java.awt.event.MouseEvent;
|
|
|
+import java.awt.event.WindowAdapter;
|
|
|
+import java.awt.event.WindowEvent;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URL;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.swing.BorderFactory;
|
|
|
+import javax.swing.JButton;
|
|
|
+import javax.swing.JFrame;
|
|
|
+import javax.swing.JLabel;
|
|
|
+import javax.swing.JOptionPane;
|
|
|
+import javax.swing.JPanel;
|
|
|
+import javax.swing.JTextArea;
|
|
|
+import javax.swing.JTextField;
|
|
|
+import javax.swing.Timer;
|
|
|
+
|
|
|
+import org.leanwo.management.util.SpringUtil;
|
|
|
+import org.leanwo.management.util.XmlConfigPathService;
|
|
|
+
|
|
|
+import com.leanwo.management.model.ApplicationSetting;
|
|
|
+import com.leanwo.management.model.XmlConfigPath;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 服务器配置
|
|
|
+ * @author YangZhiJie
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class ServerSettingJFrame extends JFrame{
|
|
|
+ private ApplicationSetting applicationSetting;
|
|
|
+ private XmlConfigPath xmlConfigPath;
|
|
|
+ private XmlConfigPathService xmlConfigPathService;
|
|
|
+ private JPanel jPanel = null;
|
|
|
+ private GridBagConstraints constrains = null;
|
|
|
+ private JLabel label = null;
|
|
|
+ private JTextField portTextField;
|
|
|
+ private JTextField tokenTextField;
|
|
|
+ private Map<String, JTextArea> textAreas = new HashMap<String, JTextArea>();
|
|
|
+ private JButton saveButton;
|
|
|
+
|
|
|
+ private int index = 0;
|
|
|
+
|
|
|
+ public ServerSettingJFrame(ApplicationSetting applicationSetting) {
|
|
|
+ this.setLayout(new BorderLayout());
|
|
|
+ this.setSize(800, 600);
|
|
|
+ this.setTitle("程序配置管理器");
|
|
|
+ this.xmlConfigPathService = (XmlConfigPathService) SpringUtil.getSingleBean(XmlConfigPathService.class);
|
|
|
+ this.applicationSetting = applicationSetting;
|
|
|
+ this.xmlConfigPathService.load(applicationSetting);
|
|
|
+ this.xmlConfigPath = applicationSetting.getXmlConfigPath();
|
|
|
+ this.jPanel = new JPanel(new GridBagLayout());
|
|
|
+ this.add(jPanel, BorderLayout.NORTH);
|
|
|
+
|
|
|
+ if(this.xmlConfigPath != null) {
|
|
|
+ label = new JLabel("端口号");
|
|
|
+ constrains = new GridBagConstraints();
|
|
|
+ constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
+ constrains.fill = GridBagConstraints.BOTH;
|
|
|
+ constrains.gridx = 0;
|
|
|
+ constrains.gridy = index;
|
|
|
+ constrains.weightx = 100;
|
|
|
+ constrains.anchor = GridBagConstraints.NORTH;
|
|
|
+ jPanel.add(label, constrains);
|
|
|
+
|
|
|
+ index++;
|
|
|
+ portTextField = new JTextField();
|
|
|
+ if(xmlConfigPath.getPortNo() != null) {
|
|
|
+ portTextField.setText(xmlConfigPath.getPortNo().toString());
|
|
|
+ }
|
|
|
+ constrains = new GridBagConstraints();
|
|
|
+ constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
+ constrains.fill = GridBagConstraints.BOTH;
|
|
|
+ constrains.gridx = 0;
|
|
|
+ constrains.gridy = index;
|
|
|
+ constrains.weightx = 100;
|
|
|
+ constrains.anchor = GridBagConstraints.NORTH;
|
|
|
+ jPanel.add(portTextField, constrains);
|
|
|
+
|
|
|
+
|
|
|
+ index++;
|
|
|
+ label = new JLabel("Token");
|
|
|
+ constrains = new GridBagConstraints();
|
|
|
+ constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
+ constrains.fill = GridBagConstraints.BOTH;
|
|
|
+ constrains.gridx = 0;
|
|
|
+ constrains.gridy = index;
|
|
|
+ constrains.weightx = 100;
|
|
|
+ constrains.anchor = GridBagConstraints.NORTH;
|
|
|
+ jPanel.add(label, constrains);
|
|
|
+
|
|
|
+ index++;
|
|
|
+ tokenTextField = new JTextField();
|
|
|
+ tokenTextField.setText(xmlConfigPath.getToken());
|
|
|
+ constrains = new GridBagConstraints();
|
|
|
+ constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
+ constrains.fill = GridBagConstraints.BOTH;
|
|
|
+ constrains.gridx = 0;
|
|
|
+ constrains.gridy = index;
|
|
|
+ constrains.weightx = 100;
|
|
|
+ constrains.anchor = GridBagConstraints.NORTH;
|
|
|
+ jPanel.add(tokenTextField, constrains);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, String> contents = applicationSetting.getXmlConfigPath().getContents();
|
|
|
+ for(String key : contents.keySet()) {
|
|
|
+ index ++;
|
|
|
+ label = new JLabel(key);
|
|
|
+ constrains = new GridBagConstraints();
|
|
|
+ constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
+ constrains.fill = GridBagConstraints.BOTH;
|
|
|
+ constrains.gridx = 0;
|
|
|
+ constrains.gridy = index;
|
|
|
+ constrains.weightx = 100;
|
|
|
+ constrains.anchor = GridBagConstraints.NORTH;
|
|
|
+ jPanel.add(label, constrains);
|
|
|
+
|
|
|
+ index ++;
|
|
|
+ JTextArea textArea = new JTextArea();
|
|
|
+ textArea.setText(contents.get(key));
|
|
|
+ textArea.setRows(5);
|
|
|
+ constrains = new GridBagConstraints();
|
|
|
+ constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
+ constrains.fill = GridBagConstraints.BOTH;
|
|
|
+ constrains.gridx = 0;
|
|
|
+ constrains.gridy = index;
|
|
|
+ constrains.weightx = 100;
|
|
|
+ constrains.anchor = GridBagConstraints.NORTH;
|
|
|
+ jPanel.add(textArea, constrains);
|
|
|
+ textAreas.put(key, textArea);
|
|
|
+ }
|
|
|
+
|
|
|
+ index ++;
|
|
|
+ saveButton = new JButton("保存");
|
|
|
+ constrains = new GridBagConstraints();
|
|
|
+ constrains.insets = new Insets(0, 0, 0, 0);
|
|
|
+ constrains.fill = GridBagConstraints.BOTH;
|
|
|
+ constrains.gridx = 0;
|
|
|
+ constrains.gridy = index;
|
|
|
+ constrains.weightx = 100;
|
|
|
+ constrains.anchor = GridBagConstraints.NORTH;
|
|
|
+ jPanel.add(saveButton, constrains);
|
|
|
+
|
|
|
+ saveButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ String portStr = portTextField.getText();
|
|
|
+ if(portStr != null) {
|
|
|
+ try {
|
|
|
+ xmlConfigPath.setPortNo(Integer.parseInt(portStr));
|
|
|
+ }catch(Exception ex) {
|
|
|
+ JOptionPane.showMessageDialog(null, "端口号必须为整数", "端口号必须为整数", JOptionPane.ERROR_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ xmlConfigPath.setToken(tokenTextField.getText());
|
|
|
+ if(xmlConfigPath.getContents() != null) {
|
|
|
+ for(String key : textAreas.keySet()) {
|
|
|
+ xmlConfigPath.getContents().put(key, textAreas.get(key).getText());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ xmlConfigPathService.save(applicationSetting);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|