DlgConfirm.java 7.06 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.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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.google.gson.Gson;


import java.io.BufferedReader;
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 java.util.Timer;
import java.util.TimerTask;

import org.emercit.config.Config;

import org.emercit.service.SData;


import org.emercit.szsterminal.SZSTerminal;



public class DlgConfirm extends JDialog {

	

	private Timer timer = new Timer();

	boolean animate = false;

	private final JPanel contentPanel = new JPanel();

	JLabel lblTitleAgk = new JLabel();
	JLabel lblTitleStatus = new JLabel();
	JLabel lblTitleTime = new JLabel();
	JLabel lblTitleRiver = new JLabel();
	JLabel lblTitleRepair = new JLabel();
	JLabel lblTitleOpenDoor = new JLabel();
	JLabel lblTitleVeracity = new JLabel();

	ImageIcon IconNotification = new ImageIcon(getClass().getResource(
			"/notification.png"));
	JLabel lblIcon = new JLabel();

	JButton okButton = new JButton("ПОДТВЕРЖДЕНИЕ");

	public MdlEvent ev;

	private void setVisibleFalse() {
		this.setVisible(false);
	}
	

	private class AnimateTask extends TimerTask {

		@Override
		public void run() {
			EventQueue.invokeLater(new Runnable() {

				//@Override
				public void run() {

					if (ev != null) {

						if (animate) {
							contentPanel
									.setBackground(new Color(102, 102, 255));
							animate = false;
						} else {
							animate = true;
							contentPanel
									.setBackground(new Color(204, 102, 102));
						}

						int countanimate = ev.getCoundAnimate();
						if (countanimate > 0) {
							ev.setCountAnimate(countanimate - 1);
						} else {
							if (ev.getSound()) {

								int countsound = ev.getCountSound();
								// on sound method
								Util.Alarm();

								if (countsound > 0) {
									ev.setCountSound(countsound - 1);
								} else {
									if (ev.getSiren()) {
										Util.RunSiren();
									}
								}
							}
						}

					} 

				}
			});
		}
	}

	public void setEvent(MdlEvent event) {

		SData.INSTANCE.setIsOpenDialog(true);
		this.ev = event;


		lblTitleAgk.setText(event.getTitleAgk());
		lblTitleAgk.setForeground(Color.WHITE);

		lblTitleStatus.setText(event.getTitleStatusForConfirm());
		lblTitleStatus.setForeground(Color.WHITE);
		lblTitleStatus.setIcon(event.getIconStatusLarge());

		lblTitleTime.setText(event.getDateTime());
		lblTitleTime.setIcon(event.getIconDateTime());
		lblTitleTime.setForeground(Color.WHITE);

		lblTitleRiver.setText(event.getTitleRiver());
		lblTitleRiver.setIcon(event.getIconRiver());
		lblTitleRiver.setForeground(Color.WHITE);

		lblTitleRepair.setText(event.getTitleRepair());
		lblTitleRepair.setForeground(Color.WHITE);
		lblTitleRepair.setIcon(event.getIconRepairLarge());

		lblTitleOpenDoor.setText(event.getTitleOpenDorr());
		lblTitleOpenDoor.setForeground(Color.WHITE);
		lblTitleOpenDoor.setIcon(event.getIconOpenDoorLarge());

		lblTitleVeracity.setText(event.getTitleVeracity());
		lblTitleVeracity.setForeground(Color.WHITE);
		lblTitleVeracity.setIcon(event.getIconVeracityLarge());
		
	

	}

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

		this.setUndecorated(true);
		this.setForeground(UIManager.getColor("activeCaption"));
		this.setBackground(Color.BLUE);
		this.setLayout(null);
		this.setSize(500, 370);

		this.setLocationRelativeTo(null); // CENTER

		this.setAlwaysOnTop(true);
		this.setModal(true);

		lblTitleAgk.setFont(new Font(null, Font.BOLD, 18));
		lblTitleStatus.setFont(new Font(null, Font.BOLD, 18));
		lblTitleTime.setFont(new Font(null, Font.BOLD, 18));
		lblTitleRiver.setFont(new Font(null, Font.BOLD, 18));

		lblTitleRepair.setFont(new Font(null, Font.ITALIC, 14));
		lblTitleVeracity.setFont(new Font(null, Font.ITALIC, 14));
		lblTitleOpenDoor.setFont(new Font(null, Font.ITALIC, 14));

		contentPanel.setForeground(Color.BLUE);

		this.setBackground(Color.BLUE);

		lblTitleAgk.setBounds(15, 15, 300, 35);
		contentPanel.add(lblTitleAgk);

		lblTitleStatus.setBounds(15, 50, 450, 35);
		contentPanel.add(lblTitleStatus);

		lblTitleRiver.setBounds(15, 85, 345, 35);
		contentPanel.add(lblTitleRiver);

		lblTitleTime.setBounds(15, 120, 300, 35);
		contentPanel.add(lblTitleTime);

		lblTitleRepair.setBounds(15, 155, 300, 35);
		contentPanel.add(lblTitleRepair);

		lblTitleVeracity.setBounds(15, 190, 300, 35);
		contentPanel.add(lblTitleVeracity);

		lblTitleOpenDoor.setBounds(15, 225, 300, 35);
		contentPanel.add(lblTitleOpenDoor);

		lblIcon.setBounds(350, 100, 124, 124);
		Image img = IconNotification.getImage();
		Image newimg = img.getScaledInstance(124, 124,
				java.awt.Image.SCALE_SMOOTH);
		IconNotification = new ImageIcon(newimg);
		lblIcon.setIcon(IconNotification);
		contentPanel.add(lblIcon);

		contentPanel.setBounds(5, 5, 490, 280);
		add(contentPanel);

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

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

						MdlEvent buff = ev;
						ev = null;
						Util.StopSiren();

						EventTableModel model = (EventTableModel) SZSTerminal.jpnllog.table
								.getModel();
						model.AddRow(buff);
						model.Update();
						SZSTerminal.jpnllog.table.updateUI();

						setVisibleFalse();
						
						SData.INSTANCE.Confirm(buff);
					}
				
				});

			}
		});

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

		add(okButton);

		timer.schedule(new AnimateTask(), 0, 1000);

	}

}