Commit 14fefa0e authored by Ondra's avatar Ondra
Browse files

Edited last changes

parent 43f328be
File added
......@@ -3,15 +3,15 @@ Popis tréninku: relaxace
Délka tréninku: 45 min
Uběhnutá vzdálenost: 4,5 km
Průměrná tepová frekvence: 119 tepů za vteřinu
Typ tréninku: Relax running
Type: Relax running
Čas: 22.4.2014 17:50
Popis tréninku: trenink s adou
Popis tréninku: trenink s adou :)
Délka tréninku: 60 min
Uběhnutá vzdálenost: 7,0 km
Průměrná tepová frekvence: 125 tepů za vteřinu
Typ tréninku: Basic training
Type: Basic training
Čas: 22.4.2014 17:50
......@@ -19,7 +19,7 @@ Popis tréninku: trénink
Délka tréninku: 60 min
Uběhnutá vzdálenost: 10,0 km
Průměrná tepová frekvence: 140 tepů za vteřinu
Typ tréninku: Sprint running
Type: Sprint running
Čas: 22.4.2014 17:50
......@@ -27,7 +27,7 @@ Popis tréninku: lehká relaxace
Délka tréninku: 45 min
Uběhnutá vzdálenost: 4,5 km
Průměrná tepová frekvence: 119 tepů za vteřinu
Typ tréninku: Relax running
Type: Relax running
Čas: 22.4.2014 17:50
......@@ -35,7 +35,7 @@ Popis tréninku: tvrdý trenink
Délka tréninku: 60 min
Uběhnutá vzdálenost: 7,0 km
Průměrná tepová frekvence: 140 tepů za vteřinu
Typ tréninku: Expert training
Type: Expert training
Čas: 22.4.2014 17:50
......@@ -43,6 +43,38 @@ Popis tréninku: trenink v horách
Délka tréninku: 75 min
Uběhnutá vzdálenost: 6,0 km
Průměrná tepová frekvence: 140 tepů za vteřinu
Typ tréninku: Expert training
Type: Expert training
Čas: 22.4.2014 22:00
Popis tréninku: Gregory
Délka tréninku: 100 min
Uběhnutá vzdálenost: 10,0 km
Průměrná tepová frekvence: 150 tepů za vteřinu
Type: Relax running
Čas: 29.5.2014 23:25
Popis tréninku: Jimmy
Délka tréninku: 120 min
Uběhnutá vzdálenost: 12,0 km
Průměrná tepová frekvence: 135 tepů za vteřinu
Type: Marathon running
Čas: 29.5.2014 23:27
Popis tréninku: Trénink
Délka tréninku: 60 min
Uběhnutá vzdálenost: 8,0 km
Průměrná tepová frekvence: 145 tepů za vteřinu
Type: Advanced training
Čas: 30.5.2014 0:35
Popis tréninku: Desc
Délka tréninku: 45 min
Uběhnutá vzdálenost: 1,0 km
Průměrná tepová frekvence: 120 tepů za vteřinu
Type: Relax running
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
----------------------------------------------------------------
Fri May 30 00:40:51 CEST 2014:
Booting Derby version The Apache Software Foundation - Apache Derby - 10.10.2.0 - (1582446): instance a816c00e-0146-4a24-995b-000000b33730
on database directory C:\Users\Ondra\Documents\NetBeansProjects\Training diary\database with class loader sun.misc.Launcher$AppClassLoader@601bb1
Mon Jun 02 22:17:53 CEST 2014:
Booting Derby version The Apache Software Foundation - Apache Derby - 10.10.2.0 - (1582446): instance a816c00e-0146-5e3b-257a-000000b44820
on database directory C:\Users\Ondra\Documents\NetBeansProjects\Training diary\database with class loader sun.misc.Launcher$AppClassLoader@df6ccd
Loaded from file:/C:/Users/Ondra/Documents/NetBeansProjects/Training%20diary/libraries/derby.jar
java.vendor=Oracle Corporation
java.runtime.version=1.7.0_40-b43
......
package cz.cvut.fel.skoumond.gui;
import cz.cvut.fel.skoumond.entities.TypeEntity;
import cz.cvut.fel.skoumond.exceptions.NoConnectionException;
import cz.cvut.fel.skoumond.sql.TypeRepository;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
/**
*
* @author Ondra
*/
public class DeleteTypeDialog extends JDialog {
private JTextField typeField;
private JPanel jPanel;
private JLabel jLabel;
private JComboBox<TypeEntity> jComboBox;
private List<TypeEntity> arrayList = TypeRepository.getInstance().all();
private TypeEntity activityType;
private Mainframe mainframe;
public DeleteTypeDialog(Mainframe mainframe) {
super(mainframe, "Edit activity types", true);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(getJPanel(), BorderLayout.NORTH);
pane.add(new JSeparator(), BorderLayout.CENTER);
pane.add(getButtonPanel(), BorderLayout.SOUTH);
this.mainframe = mainframe;
pack();
setLocationRelativeTo(null);
setVisible(true);
}
private JPanel getJPanel() {
GridLayout gridLayout = new GridLayout(1, 2);
setResizable(false);
jPanel = new JPanel();
jPanel.setLayout(gridLayout);
jLabel = new JLabel(" Choose the activity type: ", JLabel.LEFT);
jPanel.add(jLabel);
jPanel.add(getComboBox());
return jPanel;
}
private JComboBox getComboBox() {
jComboBox = new JComboBox<>();
for (TypeEntity typeEntity : arrayList) {
jComboBox.addItem(typeEntity);
}
jComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ie) {
activityType = jComboBox.getItemAt(jComboBox.getSelectedIndex());
}
});
return jComboBox;
}
private JPanel getButtonPanel() {
JPanel panel = new JPanel();
JButton jButton = new JButton("Ok");
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
onDialogOk();
}
});
panel.add(jButton);
jButton = new JButton("Back");
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
onDialogCancel();
}
});
panel.add(jButton);
return panel;
}
private void onDialogOk() {
try {
TypeRepository.getInstance().delete((TypeEntity) jComboBox.getSelectedItem());
JOptionPane.showMessageDialog(this,
"Activity type was deleted.",
"Information Message",
JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
dispose();
} catch (NumberFormatException | NoConnectionException ex) {
JOptionPane.showMessageDialog(this,
"Bad entered information. Try it again.",
"Error Message",
JOptionPane.ERROR_MESSAGE);
}
}
private void onDialogCancel() {
setVisible(false);
dispose();
}
public JTextField getTypeField() {
return typeField;
}
}
package cz.cvut.fel.skoumond.gui;
import cz.cvut.fel.skoumond.entities.RunEntity;
import cz.cvut.fel.skoumond.exceptions.NoConnectionException;
import cz.cvut.fel.skoumond.utilities.DateReader;
import javax.swing.JOptionPane;
/**
*
* @author Ondra
*/
public class EditRunDialog extends RunDialog {
private RunEntity entity;
public EditRunDialog(Mainframe mainframe, RunEntity entity) {
super(mainframe);
this.entity = entity;
presetFields();
this.setVisible(true);
}
private void presetFields() {
super.getDateField().setText(DateReader.formatData.format(entity.getDateTime().getTime()));
super.getDescField().setText(entity.getDesc());
super.getSessionTimeField().setText(String.valueOf(entity.getSessionTime()));
super.getDistInKmField().setText(String.valueOf(entity.getDistInKm()));
super.getAvrgHeartRateField().setText(String.valueOf(entity.getAvrgHeartRate()));
}
@Override
protected void onDialogOk() {
try {
super.getMainframe().editRow(
super.getCalendar(),
super.getDescField().getText(),
Integer.parseInt(super.getSessionTimeField().getText()),
Float.parseFloat(super.getDistInKmField().getText()),
Integer.parseInt(super.getAvrgHeartRateField().getText()),
super.getActivityType());
JOptionPane.showMessageDialog(this,
"Activity edited.",
"Information Message",
JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
dispose();
} catch (NumberFormatException | NoConnectionException ex) {
JOptionPane.showMessageDialog(this,
"Bad entered information. Try it again.",
"Error Message",
JOptionPane.ERROR_MESSAGE);
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cz.cvut.fel.skoumond.gui;
import java.awt.BorderLayout;
......
This diff is collapsed.
package cz.cvut.fel.skoumond.gui;
import cz.cvut.fel.skoumond.exceptions.NoConnectionException;
import javax.swing.JOptionPane;
/**
*
* @author Ondra
*/
public class NewRunDialog extends RunDialog {
public NewRunDialog(Mainframe mainframe) {
super(mainframe);
setVisible(true);
}
@Override
protected void onDialogOk() {
try {
super.getMainframe().createNewRow(
super.getCalendar(),
super.getDescField().getText(),
Integer.parseInt(super.getSessionTimeField().getText()),
Float.parseFloat(super.getDistInKmField().getText()),
Integer.parseInt(super.getAvrgHeartRateField().getText()),
super.getActivityType());
JOptionPane.showMessageDialog(this,
"New activity added.",
"Information Message",
JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
dispose();
} catch (NumberFormatException | NoConnectionException ex) {
JOptionPane.showMessageDialog(this,
"Bad entered information. Try it again.",
"Error Message",
JOptionPane.ERROR_MESSAGE);
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cz.cvut.fel.skoumond.gui;
import cz.cvut.fel.skoumond.entities.TypeEntity;
import cz.cvut.fel.skoumond.exceptions.NoConnectionException;
import cz.cvut.fel.skoumond.sql.TypeRepository;
import javax.swing.JOptionPane;
/**
*
* @author Ondra
*/
public class NewTypeDialog extends TypeDialog {
public NewTypeDialog(Mainframe mainframe) {
super(mainframe);
setVisible(true);
}
@Override
protected void onDialogOk() {
try {
TypeRepository.getInstance().save(new TypeEntity(
TypeRepository.getInstance().getFreeId(),
super.getTypeField().getText()));
JOptionPane.showMessageDialog(this,
"New activity type added.",
"Information Message",
JOptionPane.INFORMATION_MESSAGE);
setVisible(false);
dispose();
} catch (NumberFormatException | NoConnectionException ex) {
JOptionPane.showMessageDialog(this,
"Bad entered information. Try it again.",
"Error Message",
JOptionPane.ERROR_MESSAGE);
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cz.cvut.fel.skoumond.gui;
import cz.cvut.fel.skoumond.utilities.DateReader;
......@@ -19,9 +16,19 @@ import javax.swing.table.AbstractTableModel;
class ResultSetTableModel extends AbstractTableModel {
private RunRepository repository;
private final String[] columnNames = {"Date", "Description",
"Session time", "Distance", "HeartRate", "Activity type"};
private final String[] columnNames = {
"Date",
"Description",
"Session time",
"Distance",
"HeartRate",
"Activity type"
};
private List<RunEntity> arrayList;
private int row;
public ResultSetTableModel() {
repository = RunRepository.getInstance();
......@@ -79,7 +86,7 @@ class ResultSetTableModel extends AbstractTableModel {
arrayList.add(entity);
// Update database
RunRepository.getInstance().save(entity);
repository.save(entity);
// Get database know something happened
fireTableDataChanged();
......@@ -89,23 +96,75 @@ class ResultSetTableModel extends AbstractTableModel {
return arrayList.get(row).getId();
}
public RunEntity getEntity(int row) {
this.row = row;
return arrayList.get(row);
}
public void updateRow(Calendar dateTime, String desc,
int sessionTime, float distInKm,
int avrgHeartRate, TypeEntity type) {
// Get run object
RunEntity entity = arrayList.get(row);
// Update actual tablemodel
entity.setDateTime(dateTime);
entity.setDesc(desc);
entity.setSessionTime(sessionTime);
entity.setDistInKm(distInKm);
entity.setAvrgHeartRate(avrgHeartRate);
entity.setType(type);
// Update database
repository.update(entity);
// Get database know something happened
fireTableDataChanged();
}
public void removeRow(int id) {
RunEntity tmp = null;
for (RunEntity re : arrayList) {
if (re.getId() == id) {
tmp = re;
for (RunEntity entity : arrayList) {
if (entity.getId() == id) {
tmp = entity;
break;
}
}
// Update actual tablemodel
arrayList.remove(tmp);
// Update database
repository.delete(tmp);
// Get database know something happened
fireTableDataChanged();
}
public void removeAllRows() {
// Update actual tablemodel
arrayList.clear();
// Update database
repository.deleteAll();
// Get database know something happened
fireTableDataChanged();
}
public void newType() {
}
public void editType() {
}
@Override
public boolean isCellEditable(int row, int column) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment