Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Añadido historial de dispositivos... supongo que solo de lujo. Cambia…
Browse files Browse the repository at this point in the history
…dos algunos elementos para soportar los campos de habilitados en Componente y Usuario. Fixeado autoguardado.
  • Loading branch information
xman40100 committed May 7, 2019
1 parent be30e03 commit db7b7fe
Show file tree
Hide file tree
Showing 17 changed files with 654 additions and 257 deletions.
8 changes: 4 additions & 4 deletions settings.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#1
#Thu Apr 18 11:34:29 COT 2019
autosavetimer=1
deteriorationprogress=100
hostname=localhost
#Tue May 07 13:42:40 COT 2019
port=3306
hostname=localhost
deteriorationprogress=100
autosavetimer=1
daemon=false
6 changes: 3 additions & 3 deletions src/techdomotica/java/forms/LoginPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void logIn() {
String pswdd = Util.SHA256(String.valueOf(pswd));
if(!email.isEmpty() && pswd.length != 0) {
if(Util.esCorreo(email)) {
if(conx.executeRSOne("SELECT id_usuario, dni, password, nom1, id_rol FROM usuario WHERE correo = '"+ email +"';")) {
if(conx.executeRSOne("SELECT id_usuario, dni, password, nom1, id_rol FROM usuario WHERE correo = '"+ email +"' AND habilitado = 1;")) {
String realPswd = String.valueOf(conx.getResultSetRow("password"));
System.out.println(String.format("%s - %s", realPswd, pswdd));
if(realPswd.equals(pswdd)) {
Expand Down Expand Up @@ -297,7 +297,7 @@ public void run() {
else JOptionPane.showMessageDialog(null, "El usuario ingresado no está registrado. Por favor, intentelo de nuevo.", "Credenciales incorrectas", JOptionPane.ERROR_MESSAGE);
}
else if(Util.esNumerico(email)) {
if(conx.executeRSOne("SELECT id_usuario, password, nom1, id_rol FROM usuario WHERE dni = '"+ email +"';")) {
if(conx.executeRSOne("SELECT id_usuario, password, nom1, id_rol FROM usuario WHERE dni = '"+ email +"' AND habilitado = 1;")) {
String realPswd = String.valueOf(conx.getResultSetRow("password"));
System.out.println(String.format("%s - %s", realPswd, pswdd));
if(realPswd.equals(pswdd)) {
Expand Down Expand Up @@ -333,7 +333,7 @@ public void run() {
else JOptionPane.showMessageDialog(null, "Este documento de identificación no está registrado. Por favor, intentelo de nuevo.", "Credenciales incorrectas", JOptionPane.ERROR_MESSAGE);
}
else JOptionPane.showMessageDialog(null, "El texto ingresado en el campo de correo electrónico o cédula no corresponde a ninguno de los tipos requeridos.\nIntentelo de nuevo.", "Credenciales incorrectas", JOptionPane.ERROR_MESSAGE);
conx.destroyResultSet();
if(conx.getResultSet() != null) conx.destroyResultSet();
}
else JOptionPane.showMessageDialog(null, "Uno o más campos de texto están vacío. Rellenos e intentelo de nuevo.", "Error", JOptionPane.ERROR_MESSAGE);
}
Expand Down
3 changes: 3 additions & 0 deletions src/techdomotica/java/forms/Main.form
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
</Property>
<Property name="text" type="java.lang.String" value="Ver historial de dispositivos"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem11ActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
Expand Down
105 changes: 54 additions & 51 deletions src/techdomotica/java/forms/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* Querido Andrés del futuro,
* quizás leas este código, o quizás no. Se sincero contigo mismo, realmente has mejorado desde
* este momento?
* Aquí tiene es el putisimo código del proyecto del SENA de Tech Domótica.
* Y a los que vienen de GitHub, alistense para un spanglish, porque no me defino :v
*/
package techdomotica.java.forms;

Expand All @@ -21,7 +23,6 @@
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;

import techdomotica.objs.Admin;
Expand All @@ -34,6 +35,7 @@
import techdomotica.java.forms.devices.SensorView;
import techdomotica.java.forms.devices.CameraView;
import techdomotica.java.forms.devices.CameraViewTodas;
import techdomotica.java.forms.devices.DeviceHistory;
import techdomotica.java.forms.devices.DeviceManager;

import techdomotica.java.forms.gestorusuarios.Registrar;
Expand All @@ -42,43 +44,50 @@

import techdomotica.java.forms.security.SecurityHistory;

/**
* @author Andres
*/
public class Main extends javax.swing.JFrame {

/**
* Creates new form Dispositivos
*/
public boolean onSystemTray = false;

private Thread mainChanger;

private Admin adminEncargado = null;
private Ambiente ambiente;

private boolean continueAutosaving = true;

private TrayIcon appSystemTray = null;

private boolean[] warningDisplayed = new boolean[4];

private Config cfg;

private Timer autosaveTimer;
private Thread autosaveTimer;

public Main(Admin admin) {
adminEncargado = admin;
ambiente = new Ambiente(adminEncargado);
cfg = ambiente.getConfig();
System.out.println(String.format("Timer starting with the following: %d s (%d ms)", (Integer.parseInt(cfg.getConfigKey("autosavetimer")) * 60), (Integer.parseInt(cfg.getConfigKey("autosavetimer")) * 60) * (1000)));
autosaveTimer = new Timer( (Integer.parseInt(cfg.getConfigKey("autosavetimer")) * 60) * (1000), new ActionListener() {
final int confT = Integer.parseInt(cfg.getConfigKey("autosavetimer")) * 60;
autosaveTimer = new Thread(new Runnable() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("I suck pee pee");
saveAllDevices();
public void run() {
while(continueAutosaving) {
for(int i = 0 ; i < confT ; i++ ) {
try {
Thread.sleep(1000);
System.out.println("Executing... " + confT + ":00 from 0:" + i);
if(i == 59) {
i = 0;
saveAllDevices();
}
} catch (InterruptedException ex) {
System.out.println(ex);
}
}
}
}
});
autosaveTimer.setRepeats(true);
autosaveTimer.start();
initComponents();

Expand All @@ -105,7 +114,7 @@ public void run() {
}
}

//Cambio de temperatura ambiente por medio del hilo del tiempo.
//That's how an AI works my brave soul
public void changeAmbientWeather() {
Time runTime = ambiente.getTimeThread();
System.out.println(String.format("%02d:%02d:%02d", runTime.getHours(), runTime.getMinutes(), runTime.getSeconds()));
Expand Down Expand Up @@ -142,22 +151,6 @@ else if(ambiente.getACondicionado(0).getUsoComponente() <= 30.0 || ambiente.getA
warningDisplayed[3] = true;
}
}

/*if((ambiente.getACondicionado(0) == null || ambiente.getACondicionado(0).getUsoComponente() <= 10.0) || ambiente.getACondicionado(1) == null) {
ambiente.setTemperaturaAmbiente(ambiente.getTemperaturaAmbiente());
if(!warningDisplayed[0]) {
JOptionPane.showMessageDialog(null, "Atención. no se dispone de uno o más aires acondicionados en el ambiente debido a que no\nhan sido asignados o presentan problemas y requieren mantenimiento. La temperatura\npodría incrementar y ocasionar daños en los equipos.", "Advertencia de temperatura", JOptionPane.WARNING_MESSAGE);
warningDisplayed[0] = true;
}
if(!warningDisplayed[1] && ambiente.getTemperaturaAmbiente() >= 28.0) {
JOptionPane.showMessageDialog(null, "ATENCIÓN: La temperatura ambiental está sobre 28°C. Esta temperatura, con los equipos encendidos,\npodría ocasionar daños graves en los equipos que generen calor.", "Alerta crítica de temperatura", JOptionPane.WARNING_MESSAGE);
warningDisplayed[1] = true;
}
}
else {
if(ambiente.getACondicionado(0).)
}
else ambiente.setTemperaturaAmbiente((ambiente.getTemperaturaAmbiente() + ambiente.getTemperaturaSala()) / 2);*/
}
});
mainChanger.start();
Expand All @@ -166,13 +159,6 @@ else if(ambiente.getACondicionado(0).getUsoComponente() <= 30.0 || ambiente.getA

checkDeviceAvailability();
addAppToSystemTray();
/*camera1.setIcon(new ImageIcon(new ImageIcon(getClass().getResource("/resources/media/simulator/camera-r.png")).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH)));
camera2.setIcon(new ImageIcon(new ImageIcon(getClass().getResource("/resources/media/simulator/camera.png")).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH)));
camera3.setIcon(new ImageIcon(new ImageIcon(getClass().getResource("/resources/media/simulator/camera-r.png")).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH)));
camera4.setIcon(new ImageIcon(new ImageIcon(getClass().getResource("/resources/media/simulator/camera.png")).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH)));
*/

//sensor1.setIcon(new ImageIcon(new ImageIcon(getClass().getResource("/resources/media/simulator/sensor.png")).getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)));
}

public void checkDeviceAvailability() {
Expand Down Expand Up @@ -444,6 +430,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

jMenuItem11.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem11.setText("Ver historial de dispositivos");
jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem11ActionPerformed(evt);
}
});
jMenu9.add(jMenuItem11);

jMenu4.add(jMenu9);
Expand Down Expand Up @@ -603,7 +594,7 @@ private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
//Not really a daemon but ok... Guess I'll work with this.
if(cfg.getConfigKey("daemon").equalsIgnoreCase("true")) {
appSystemTray.displayMessage("Tech Domótica se ha minimizado", "Tech Domótica se seguirá ejecutando en segundo plano. Usa este icono para abrir de nuevo la aplicación.", TrayIcon.MessageType.INFO);
this.setVisible(false);
Expand Down Expand Up @@ -702,12 +693,12 @@ private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
public void saveChangesToMain() {
super.saveChangesToMain();
saveAllDevices();
//System.out.println("We're out of here!");

ambiente.toggleAmbienteThread(true);
ambiente.toggleDeviceThread(true);

ambiente.startAmbienteThread();
//ambiente.startDeviceThread();

checkDeviceAvailability();

}
Expand All @@ -725,7 +716,15 @@ private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
modal.setVisible(true);
}//GEN-LAST:event_jMenuItem13ActionPerformed

private void saveAllDevices() { }
private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
DeviceHistory devices = new DeviceHistory(ambiente);
devices.setVisible(true);
}//GEN-LAST:event_jMenuItem11ActionPerformed

private void saveAllDevices() {
System.out.println("Autosaving...");
ambiente.saveAllDevicesFromQuit();
}

private void cameraView(String campath, String title, boolean ison) {
CameraView camView = new CameraView(ambiente, campath, ison) {
Expand Down Expand Up @@ -862,10 +861,13 @@ public void mouseExited(MouseEvent e) { }
}

private void openApp() {
this.setVisible(true);
SystemTray tray = SystemTray.getSystemTray();
tray.remove(appSystemTray);
onSystemTray = false;
if(this.isVisible()) {
this.requestFocus();
}
else {
this.setVisible(true);
this.requestFocus();
}
}

private void logOut() {
Expand All @@ -880,7 +882,8 @@ private void logOut() {
ambiente.toggleTimeThread(false);
ambiente.toggleAmbienteThread(false);
ambiente.toggleDeviceThread(false);
autosaveTimer.stop();
continueAutosaving = false;
autosaveTimer.interrupt();
ambiente = null;
this.dispose();
}
Expand All @@ -889,7 +892,7 @@ private void logOut() {
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//Nimbus is fucking awful looking.
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
Expand Down
92 changes: 92 additions & 0 deletions src/techdomotica/java/forms/devices/DeviceHistory.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" value="Historial de dispositivos - Tech Dom&#xf3;tica"/>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="507" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="checkTable" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" pref="25" max="-2" attributes="0"/>
<EmptySpace pref="29" max="32767" attributes="0"/>
<Component id="checkTable" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="262" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="18" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="Historial de dispositivos"/>
</Properties>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="tableDevices">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="0" rowCount="4"/>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0"/>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JTable() {&#xa; @Override&#xa; public boolean isCellEditable(int row, int column) {&#xa; return false;&#xa; }&#xa;}"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JCheckBox" name="checkTable">
<Properties>
<Property name="text" type="java.lang.String" value="Mostrar dispositivos desinstalados"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="checkTableActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
Loading

0 comments on commit db7b7fe

Please sign in to comment.