DlgMainConfig.java 6.4 KB
package org.emercit.components;


import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GraphicsEnvironment;
import java.awt.Image;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.SwingConstants;

import java.awt.event.KeyEvent;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JLabel;

import java.awt.ComponentOrientation;
import java.awt.Font;

import javax.swing.UIManager;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.SystemColor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.ImageIcon;
import javax.swing.SwingWorker;

import java.util.ArrayList;
import java.io.File;




import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;

import org.emercit.model.*;
import org.emercit.service.SData;
import org.emercit.szsterminal.*;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JCheckBox;
import javax.swing.JTextField;
import javax.swing.JFormattedTextField;
import javax.swing.text.MaskFormatter;

import org.emercit.config.*;
public class DlgMainConfig extends JDialog {

	
	private final JPanel contentPanel = new JPanel();

	
	private JButton ApplyButton = new JButton("ПРИМЕНИТЬ");
	
	
	
	private JLabel lblGUID=new JLabel("GUID:");

	private JLabel lblProxyServer=new JLabel("Server:");
	private JLabel lblProxyPort=new JLabel("Port:");
	private JLabel lblPassword=new JLabel("Password:");
	
	public static  JCheckBox chkUseProxy=new JCheckBox();
	
	public static JTextField txtGUID=new JTextField();
	

	public static JFormattedTextField txtProxyServer;
	

	public  static JFormattedTextField txtProxyPort;
		

	
	private void setIsOpen(boolean visible) {
		this.setVisible(visible);
	}
	
	
	public void setValue(Config config) {
		
		this.txtGUID.setText(config.getRegKey());
		this.txtProxyServer.setText(config.getProxyServer());
		this.txtProxyPort.setText(String.valueOf(config.getProxyPort()));
		this.chkUseProxy.setSelected(config.getProxyEnabled());
		
	
		
	}
	
	
	private void setVisibleFalse() {
		this.setVisible(false);
	}

	
	
	
	
	


	
	
	public DlgMainConfig() {

		try {
		contentPanel.setLayout(null);
		contentPanel.setBorder(new LineBorder(new Color(100, 149, 237), 10));

		this.setTitle("Настройка программы");
		//this.setUndecorated(true);
		this.setForeground(UIManager.getColor("activeCaption"));
		this.setBackground(Color.BLUE);
		this.setLayout(null);
		this.setSize(500, 400);

		this.setLocationRelativeTo(null); // CENTER

		this.setAlwaysOnTop(true);
		this.setModal(true);
		
		contentPanel.setForeground(Color.BLUE);

		this.setBackground(Color.BLUE);
		
		
		// GUID
		this.lblGUID.setFont(new Font(null, Font.BOLD, 18));
		this.lblGUID.setBounds(15, 20, 110, 35);
		contentPanel.add(lblGUID);
		this.txtGUID.setFont(new Font(null, Font.BOLD, 18));
		this.txtGUID.setBounds(80, 20, 370, 35);	
		contentPanel.add(txtGUID);

		// use Proxy
		this.chkUseProxy.setFont(new Font(null, Font.BOLD, 18));
		this.chkUseProxy.setBounds(15, 57, 370, 35);
		this.chkUseProxy.setText("Proxy");
		contentPanel.add(chkUseProxy);
		
		//Server
		this.lblProxyServer.setFont(new Font(null, Font.BOLD, 18));
		this.lblProxyServer.setBounds(15, 100, 110, 35);
		contentPanel.add(lblProxyServer);
		
		 MaskFormatter formatteIp = new MaskFormatter("###.###.###.###");
		 this.txtProxyServer = new JFormattedTextField(formatteIp);
		
		
		
		
		this.txtProxyServer.setFont(new Font(null, Font.BOLD, 18));
		this.txtProxyServer.setBounds(90, 100, 350, 35);
		contentPanel.add(txtProxyServer);
		
		// Port
		this.lblProxyPort.setFont(new Font(null, Font.BOLD, 18));
		this.lblProxyPort.setBounds(15, 143, 110, 35);
		contentPanel.add(lblProxyPort);	
		
		
		 MaskFormatter formattePort = new MaskFormatter("####");
		 this.txtProxyPort = new JFormattedTextField(formattePort);
		
		
		this.txtProxyPort.setFont(new Font(null, Font.BOLD, 18));
		this.txtProxyPort.setBounds(90, 143, 350, 35);
		contentPanel.add(txtProxyPort);
		  
	
		contentPanel.setBounds(5, 5, 490, 280);
		add(contentPanel);

		ApplyButton.setBorder(new LineBorder(new Color(100, 149, 237), 7));
		ApplyButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
		ApplyButton.setPreferredSize(new Dimension(320, 80));
		ApplyButton.setMinimumSize(new Dimension(220, 80));
		ApplyButton.setMaximumSize(new Dimension(220, 80));
		ApplyButton.setMnemonic(KeyEvent.VK_COMPOSE);
		ApplyButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				SwingUtilities.invokeLater(new Runnable() {
					public void run() {

					
						setVisibleFalse();
						
						try 
						{
								Config config=SData.INSTANCE.getConfig();
								
								
								
								
								config.setRegkey(DlgMainConfig.txtGUID.getText());
								config.setProxyServer(DlgMainConfig.txtProxyServer.getText());
								config.setProxyPort(Integer.valueOf(DlgMainConfig.txtProxyPort.getText()));
								config.setProxyEnabled(DlgMainConfig.chkUseProxy.isSelected());
	
								config.Save();
								
								SData.INSTANCE.SetConfig(config);
								
								//configmain.setServer(DlgMainConfig.txtProxyServer.getText());
								
								//configmain.setPort(Integer.valueOf(DlgMainConfig.txtProxyPort.getText()));
								
								
								//	String inputpassword=DlgMainConfig.txtPassword.getText();
								//	String pass=SZSTerminal.configmain.getPassword();
									
								//	if (inputpassword.trim().equals(pass.trim())) {
								//		SZSTerminal.configmain.Save();
								//	}

						}
						catch (Exception e) {
							
						}
						
						
					
						
				
						
							
						}
				});
				
			

			}
		});

		ApplyButton.setBounds(5, 290, 488, 75);

		add(ApplyButton);
		
		}
	catch(Exception e) {
		
	}
	

	}

}