#13 solved: Exceptions, die nicht direkt behandelt werden können,
werden, bis auf wenige Ausnahmen, an die Main-Klasse weitergereicht, um dort aufgefangen zu werden. Die Software hat jetzt einen eigenen Logger und Util-Funktionen, für das einfache Werfen von Fehlermeldungen.
This commit is contained in:
49
src/de/katho/kBorrow/KLogger.java
Normal file
49
src/de/katho/kBorrow/KLogger.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package de.katho.kBorrow;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.Handler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
|
public class KLogger {
|
||||||
|
private static Logger logger;
|
||||||
|
private Handler fileHandler;
|
||||||
|
private Formatter plainText;
|
||||||
|
|
||||||
|
|
||||||
|
private KLogger() throws IOException {
|
||||||
|
logger = Logger.getLogger(Util.class.getName());
|
||||||
|
String fDir = System.getProperty("user.home")+"/kBorrow";
|
||||||
|
String fName = "kBorrow.log";
|
||||||
|
File dir = new File(fDir);
|
||||||
|
File file = new File(fDir+"/"+fName);
|
||||||
|
|
||||||
|
if(!dir.isDirectory()) dir.mkdir();
|
||||||
|
if(!file.isFile()) file.createNewFile();
|
||||||
|
|
||||||
|
fileHandler = new FileHandler(fDir+"/"+fName, true);
|
||||||
|
plainText = new SimpleFormatter();
|
||||||
|
fileHandler.setFormatter(plainText);
|
||||||
|
logger.addHandler(fileHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(){
|
||||||
|
if(logger == null){
|
||||||
|
try{
|
||||||
|
new KLogger();
|
||||||
|
} catch(IOException e){
|
||||||
|
Util.showError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(Level pLevel, String pMsg, Exception e){
|
||||||
|
getLogger().log(pLevel, pMsg, e);
|
||||||
|
System.out.println(pMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,13 +15,13 @@ public class Settings {
|
|||||||
private String filePath;
|
private String filePath;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
public Settings() {
|
public Settings() throws Exception {
|
||||||
this.properties = new Properties();
|
properties = new Properties();
|
||||||
this.filePath = System.getProperty("user.home")+"/kBorrow";
|
filePath = System.getProperty("user.home")+"/kBorrow";
|
||||||
this.fileName = "Settings.cfg";
|
fileName = "Settings.cfg";
|
||||||
|
|
||||||
if(!this.filePathHasValidConfig()){
|
if(!filePathHasValidConfig()){
|
||||||
this.createDefaultConfig();
|
createDefaultConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,14 +31,14 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
private boolean filePathHasValidConfig(){
|
private boolean filePathHasValidConfig(){
|
||||||
try {
|
try {
|
||||||
InputStream in = new FileInputStream(this.filePath+"/"+this.fileName);
|
InputStream in = new FileInputStream(filePath+"/"+fileName);
|
||||||
this.properties = new Properties();
|
properties = new Properties();
|
||||||
|
|
||||||
this.properties.load(in);
|
properties.load(in);
|
||||||
|
|
||||||
// Check if the properties file holds certain keys and values.
|
// Check if the properties file holds certain keys and values.
|
||||||
if( (this.properties.containsKey("dBType") && this.properties.containsValue("sqlite") && this.properties.containsKey("sqlitePath")) ||
|
if( (properties.containsKey("dBType") && properties.containsValue("sqlite") && properties.containsKey("sqlitePath")) ||
|
||||||
(this.properties.contains("dbType") && this.properties.containsValue("mysql") && this.properties.containsKey("mysqlDB") && this.properties.containsKey("mysqlHost") && this.properties.containsKey("mysqlUser") && this.properties.containsKey("mysqlPass"))) {
|
(properties.contains("dbType") && properties.containsValue("mysql") && properties.containsKey("mysqlDB") && properties.containsKey("mysqlHost") && properties.containsKey("mysqlUser") && properties.containsKey("mysqlPass"))) {
|
||||||
in.close();
|
in.close();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -49,21 +49,23 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
Util.showWarning(new Exception("Kann die Settingsdatei nicht finden. Versuche, eine neue zu erzeugen.", e));
|
||||||
return false;
|
return false;
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a default config to the config file.
|
* Writes a default config to the config file.
|
||||||
|
* @throws Exception
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void createDefaultConfig() {
|
private void createDefaultConfig() throws Exception {
|
||||||
try {
|
try {
|
||||||
File dir = new File(this.filePath);
|
File dir = new File(filePath);
|
||||||
File file = new File(this.filePath+"/"+this.fileName);
|
File file = new File(filePath+"/"+fileName);
|
||||||
if(!dir.isDirectory()) dir.mkdir();
|
if(!dir.isDirectory()) dir.mkdir();
|
||||||
if(!file.isFile()) file.createNewFile();
|
if(!file.isFile()) file.createNewFile();
|
||||||
else {
|
else {
|
||||||
@@ -73,39 +75,36 @@ public class Settings {
|
|||||||
|
|
||||||
OutputStream os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
OutputStream os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
||||||
|
|
||||||
this.properties.put("dBType", "sqlite");
|
properties.put("dBType", "sqlite");
|
||||||
this.properties.put("sqlitePath",System.getProperty("user.home").replace("\\", "/")+"/kBorrow/kBorrow.db" );
|
properties.put("sqlitePath",System.getProperty("user.home").replace("\\", "/")+"/kBorrow/kBorrow.db" );
|
||||||
this.properties.store(os, null);
|
properties.store(os, null);
|
||||||
|
|
||||||
os.close();
|
os.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("I couldn't find the specified properties file while trying to create a default config.");
|
throw new Exception("I couldn't find the specified properties file while trying to create a default config.", e);
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("I had problems, writing to the properties file while trying to create a default config.");
|
throw new Exception("I had problems writing to the properties file while trying to create a default config.", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProperty(String pKey){
|
public String getProperty(String pKey){
|
||||||
return this.properties.getProperty(pKey);
|
if(properties.containsKey(pKey)) return properties.getProperty(pKey);
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperty(String pKey, String pValue){
|
public void setProperty(String pKey, String pValue) throws IOException{
|
||||||
this.properties.put(pKey, pValue);
|
properties.put(pKey, pValue);
|
||||||
|
|
||||||
OutputStream os;
|
OutputStream os;
|
||||||
try {
|
try {
|
||||||
os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
||||||
this.properties.store(os, null);
|
properties.store(os, null);
|
||||||
|
|
||||||
os.close();
|
os.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("I couldn't find the specified properties file while trying to write the config.");
|
throw new FileNotFoundException("I couldn't find the specified properties file while trying to write the config.");
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("I had problems, writing to the properties file while saving a setting.");
|
throw new IOException("I had problems, writing to the properties file while saving a setting.");
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,16 @@ import java.text.DateFormat;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Util {
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
import org.jdesktop.swingx.JXErrorPane;
|
||||||
|
import org.jdesktop.swingx.error.ErrorInfo;
|
||||||
|
|
||||||
|
public final class Util {
|
||||||
|
private static JFrame mainwindow;
|
||||||
|
|
||||||
public static String getCurrentDate(){
|
public static String getCurrentDate(){
|
||||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
@@ -25,4 +33,20 @@ public class Util {
|
|||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showWarning(Exception e){
|
||||||
|
KLogger.log(Level.WARNING, e.getMessage(), e);
|
||||||
|
ErrorInfo info = new ErrorInfo("Warnung", e.getMessage(), null, null, e, Level.WARNING, null);
|
||||||
|
JXErrorPane.showDialog(mainwindow, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showError(Exception e){
|
||||||
|
KLogger.log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
ErrorInfo info = new ErrorInfo("Fehler", e.getMessage(), null, null, e, Level.SEVERE, null);
|
||||||
|
JXErrorPane.showDialog(mainwindow, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMainWindow(JFrame p){
|
||||||
|
mainwindow = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ public class NewLendingController {
|
|||||||
* 4: Die gegebene Kombination aus Lender-Name, -Surname und -Studentnumber
|
* 4: Die gegebene Kombination aus Lender-Name, -Surname und -Studentnumber
|
||||||
* existiert mehrmals in der Datenbank. Das darf nicht sein und wirft daher einen Fehler!
|
* existiert mehrmals in der Datenbank. Das darf nicht sein und wirft daher einen Fehler!
|
||||||
* 5: Matrikelnummer muss eine Zahl sein!
|
* 5: Matrikelnummer muss eine Zahl sein!
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public int newLending(int pArtId, String pLName, String pLSurname, String pLSN, String pStartDate, Date pEstEndDate, String pUsername){
|
public int newLending(int pArtId, String pLName, String pLSurname, String pLSN, String pStartDate, Date pEstEndDate, String pUsername) throws Exception{
|
||||||
if(pArtId == -1 || pStartDate.isEmpty() || pEstEndDate == null || pLName.isEmpty() || pLSurname.isEmpty() || pUsername.isEmpty()) return 2;
|
if(pArtId == -1 || pStartDate.isEmpty() || pEstEndDate == null || pLName.isEmpty() || pLSurname.isEmpty() || pUsername.isEmpty()) return 2;
|
||||||
if(pEstEndDate.before(new Date())) return 3;
|
if(pEstEndDate.before(new Date())) return 3;
|
||||||
if(!pLSN.matches("[0-9]+")) return 5;
|
if(!pLSN.matches("[0-9]+")) return 5;
|
||||||
@@ -97,7 +98,7 @@ public class NewLendingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createPdfFile(int pLendingId){
|
private void createPdfFile(int pLendingId) throws Exception {
|
||||||
KLending lending = lendingTableModel.getLendingById(pLendingId);
|
KLending lending = lendingTableModel.getLendingById(pLendingId);
|
||||||
KArticle article = articleTableModel.getArticleById(lending.getArticleId());
|
KArticle article = articleTableModel.getArticleById(lending.getArticleId());
|
||||||
KUser user = userListModel.getUserById(lending.getUserId());
|
KUser user = userListModel.getUserById(lending.getUserId());
|
||||||
@@ -174,7 +175,7 @@ public class NewLendingController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException | COSVisitorException e) {
|
} catch (IOException | COSVisitorException e) {
|
||||||
e.printStackTrace();
|
throw new Exception("Problem bei der Erstellung der PDF-Datei.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,22 +7,22 @@ public class KArticle {
|
|||||||
private boolean isFree;
|
private boolean isFree;
|
||||||
|
|
||||||
public KArticle(int pId, String pName, boolean pFree, String pDesc) {
|
public KArticle(int pId, String pName, boolean pFree, String pDesc) {
|
||||||
this.id = pId;
|
id = pId;
|
||||||
this.name = pName;
|
name = pName;
|
||||||
this.description = pDesc;
|
description = pDesc;
|
||||||
isFree = pFree;
|
isFree = pFree;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return this.id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return this.description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsFree(){
|
public boolean getIsFree(){
|
||||||
@@ -30,11 +30,11 @@ public class KArticle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String pName){
|
public void setName(String pName){
|
||||||
this.name = pName;
|
name = pName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String pDesc){
|
public void setDescription(String pDesc){
|
||||||
this.description = pDesc;
|
description = pDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsFree(boolean pFree){
|
public void setIsFree(boolean pFree){
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.Util;
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.KArticle;
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.KLender;
|
||||||
import de.katho.kBorrow.data.KLending;
|
import de.katho.kBorrow.data.KLending;
|
||||||
@@ -92,7 +93,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,7 +202,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return userArr;
|
return userArr;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +222,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return userArr;
|
return userArr;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,7 +242,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return artArr;
|
return artArr;
|
||||||
}
|
}
|
||||||
catch (SQLException ex){
|
catch (SQLException ex){
|
||||||
ex.printStackTrace();
|
Util.showWarning(ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,7 +262,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return artArr;
|
return artArr;
|
||||||
}
|
}
|
||||||
catch(SQLException ex){
|
catch(SQLException ex){
|
||||||
ex.printStackTrace();
|
Util.showWarning(ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,7 +282,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return lendArr;
|
return lendArr;
|
||||||
}
|
}
|
||||||
catch(SQLException ex){
|
catch(SQLException ex){
|
||||||
ex.printStackTrace();
|
Util.showWarning(ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +303,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -323,7 +324,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,7 +346,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -361,7 +362,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,7 +378,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,7 +394,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -408,7 +409,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,7 +425,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -462,7 +463,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return new int[]{1,0};
|
return new int[]{1,0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,7 +478,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -493,7 +494,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +511,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,13 @@ import javax.swing.JTabbedPane;
|
|||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
|
|
||||||
import org.jdesktop.swingx.JXErrorPane;
|
|
||||||
import org.jdesktop.swingx.error.ErrorInfo;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.katho.kBorrow.Settings;
|
import de.katho.kBorrow.Settings;
|
||||||
|
import de.katho.kBorrow.Util;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
import de.katho.kBorrow.db.SqlConnector;
|
import de.katho.kBorrow.db.SqlConnector;
|
||||||
import de.katho.kBorrow.db.SqliteConnector;
|
import de.katho.kBorrow.db.SqliteConnector;
|
||||||
@@ -48,13 +43,7 @@ public class MainWindow {
|
|||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public MainWindow() throws IOException {
|
public MainWindow() {
|
||||||
set = new Settings();
|
|
||||||
frame = new JFrame();
|
|
||||||
frame.setResizable(false);
|
|
||||||
frame.setBounds(100, 100, 600, 500);
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
// Delete all files in tmp-dir
|
// Delete all files in tmp-dir
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(){
|
Runtime.getRuntime().addShutdownHook(new Thread(){
|
||||||
public void run(){
|
public void run(){
|
||||||
@@ -66,6 +55,13 @@ public class MainWindow {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
frame = new JFrame();
|
||||||
|
frame.setResizable(false);
|
||||||
|
frame.setBounds(100, 100, 600, 500);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
Util.setMainWindow(frame);
|
||||||
|
set = new Settings();
|
||||||
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
||||||
if(set.getProperty("dBType").equals("sqlite")){
|
if(set.getProperty("dBType").equals("sqlite")){
|
||||||
@@ -84,23 +80,22 @@ public class MainWindow {
|
|||||||
models.put("lendingtablemodel", new LendingTableModel(dbCon, models));
|
models.put("lendingtablemodel", new LendingTableModel(dbCon, models));
|
||||||
|
|
||||||
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||||
frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER);
|
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||||
tabbedPane.addTab("Neue Ausleihe", new NewLendingPanel(this.dbCon, models, set));
|
tabbedPane.addTab("Neue Ausleihe", new NewLendingPanel(this.dbCon, models, set));
|
||||||
tabbedPane.addTab("Ausleihen verwalten", new ManageLendingsPanel(this.dbCon, models));
|
tabbedPane.addTab("Ausleihen verwalten", new ManageLendingsPanel(this.dbCon, models));
|
||||||
tabbedPane.addTab("Artikel verwalten", new ArticlePanel(this.dbCon, models));
|
tabbedPane.addTab("Artikel verwalten", new ArticlePanel(this.dbCon, models));
|
||||||
tabbedPane.addTab("Benutzer verwalten", new UserPanel(this.dbCon, models));
|
tabbedPane.addTab("Benutzer verwalten", new UserPanel(this.dbCon, models));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(ClassNotFoundException | InstantiationException | IllegalAccessException | IOException | UnsupportedLookAndFeelException | SQLException e) {
|
catch(Exception e) {
|
||||||
ErrorInfo info = new ErrorInfo("Exception", e.getMessage(), null, null, e, null, null);
|
Util.showError(e);
|
||||||
JXErrorPane.showDialog(frame, info);
|
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException{
|
public static void main(String[] args) {
|
||||||
new MainWindow();
|
new MainWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
tfStudentNumber.setText("");
|
tfStudentNumber.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveButtonPressed(){
|
private void saveButtonPressed() throws Exception {
|
||||||
String pLName = tfName.getText();
|
String pLName = tfName.getText();
|
||||||
String pLSurname = tfSurname.getText();
|
String pLSurname = tfSurname.getText();
|
||||||
String startDate = lblStartDate.getText();
|
String startDate = lblStartDate.getText();
|
||||||
@@ -267,7 +267,11 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(pEvent.getSource() == btnSave){
|
if(pEvent.getSource() == btnSave){
|
||||||
saveButtonPressed();
|
try {
|
||||||
|
saveButtonPressed();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.showError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -288,7 +292,12 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void keyPressed(KeyEvent pKeyPress) {
|
public void keyPressed(KeyEvent pKeyPress) {
|
||||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER)
|
||||||
|
try {
|
||||||
|
saveButtonPressed();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.showError(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user