Einiges an Refactoring durchgeführt. Übliche Anwendungsfälle, wie mit
Tab durch Textfelder skippen und mit Enter ein Formular abschicken implementiert. Begonnen, neue Ausleihen zu implementieren.
This commit is contained in:
BIN
assets/icons/go-down.png
Normal file
BIN
assets/icons/go-down.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 874 B |
@@ -53,10 +53,10 @@ public class MainWindow {
|
||||
|
||||
this.tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
this.frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER);
|
||||
this.tabbedPane.addTab("Neue Ausleihe", new NewLendingTab(this.dbCon));
|
||||
this.tabbedPane.addTab("Ausleihen verwalten", new ManageLendingTab(this.dbCon));
|
||||
this.tabbedPane.addTab("Artikel verwalten", new ArticleTab(this.dbCon));
|
||||
this.tabbedPane.addTab("Benutzer verwalten", new UserTab(this.dbCon));
|
||||
this.tabbedPane.addTab("Neue Ausleihe", new PanelNewLending(this.dbCon));
|
||||
this.tabbedPane.addTab("Ausleihen verwalten", new PanelManageLendings(this.dbCon));
|
||||
this.tabbedPane.addTab("Artikel verwalten", new PanelArticle(this.dbCon));
|
||||
this.tabbedPane.addTab("Benutzer verwalten", new PanelUser(this.dbCon));
|
||||
|
||||
}
|
||||
catch(ClassNotFoundException | InstantiationException | IllegalAccessException | IOException | UnsupportedLookAndFeelException | SQLException e) {
|
||||
|
||||
45
src/de/katho/kBorrow/gui/MyFocusTraversalPolicy.java
Normal file
45
src/de/katho/kBorrow/gui/MyFocusTraversalPolicy.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package de.katho.kBorrow.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.FocusTraversalPolicy;
|
||||
import java.util.Vector;
|
||||
|
||||
public class MyFocusTraversalPolicy extends FocusTraversalPolicy {
|
||||
|
||||
private Vector<Component> order;
|
||||
|
||||
public MyFocusTraversalPolicy(Vector<Component> pOrder){
|
||||
this.order = new Vector<Component>(pOrder.size());
|
||||
this.order.addAll(pOrder);
|
||||
}
|
||||
|
||||
public Component getComponentAfter(Container aContainer, Component aComponent) {
|
||||
int index = (order.indexOf(aComponent) + 1);
|
||||
|
||||
if(index >= order.size()) index = 0;
|
||||
|
||||
return order.get(index);
|
||||
}
|
||||
|
||||
public Component getComponentBefore(Container aContainer, Component aComponent) {
|
||||
int index = (order.indexOf(aComponent) - 1);
|
||||
|
||||
if(index < 0) index = order.size() -1;
|
||||
|
||||
return order.get(index);
|
||||
}
|
||||
|
||||
public Component getDefaultComponent(Container aContainer) {
|
||||
return order.firstElement();
|
||||
}
|
||||
|
||||
public Component getFirstComponent(Container aContainer) {
|
||||
return order.firstElement();
|
||||
}
|
||||
|
||||
public Component getLastComponent(Container aContainer) {
|
||||
return order.lastElement();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package de.katho.kBorrow.gui;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
|
||||
public class NewLendingTab extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7346953418572781322L;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
* @param dbCon
|
||||
*/
|
||||
public NewLendingTab(DbConnector dbCon) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,10 +2,14 @@ package de.katho.kBorrow.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
@@ -21,8 +25,9 @@ import javax.swing.border.TitledBorder;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.listener.ArticleDeleteTableButton;
|
||||
import de.katho.kBorrow.listener.ArticleEditTableButton;
|
||||
import de.katho.kBorrow.models.ArticleTableModel;
|
||||
|
||||
public class ArticleTab extends JPanel implements ActionListener {
|
||||
public class PanelArticle extends JPanel implements ActionListener, KeyListener {
|
||||
|
||||
private static final long serialVersionUID = -8511924597640457608L;
|
||||
private ArticleTableModel articleTableModel;
|
||||
@@ -38,7 +43,7 @@ public class ArticleTab extends JPanel implements ActionListener {
|
||||
* Create the panel.
|
||||
* @throws IOException
|
||||
*/
|
||||
public ArticleTab(final DbConnector dbCon) throws IOException {
|
||||
public PanelArticle(final DbConnector dbCon) throws IOException {
|
||||
super();
|
||||
this.setLayout(null);
|
||||
|
||||
@@ -86,6 +91,7 @@ public class ArticleTab extends JPanel implements ActionListener {
|
||||
this.textFieldArticleName = new JTextField();
|
||||
this.textFieldArticleName.setBounds(90, 30, 250, 20);
|
||||
this.textFieldArticleName.setColumns(10);
|
||||
this.textFieldArticleName.addKeyListener(this);
|
||||
|
||||
//Edit: Desc-TextArea
|
||||
this.textAreaArticleDescription = new JTextArea(5, 30);
|
||||
@@ -104,6 +110,14 @@ public class ArticleTab extends JPanel implements ActionListener {
|
||||
this.btnArticleCancel.addActionListener(this);
|
||||
this.btnArticleCancel.setBounds(490, 102, 89, 23);
|
||||
|
||||
//Traversal-Policy
|
||||
Vector<Component> order = new Vector<Component>();
|
||||
order.add(this.textFieldArticleName);
|
||||
order.add(this.textAreaArticleDescription);
|
||||
order.add(this.btnArticleCancel);
|
||||
order.add(this.btnArticleSave);
|
||||
MyFocusTraversalPolicy focusPolicy = new MyFocusTraversalPolicy(order);
|
||||
|
||||
/*
|
||||
* PanelArticleEdit
|
||||
*/
|
||||
@@ -118,6 +132,8 @@ public class ArticleTab extends JPanel implements ActionListener {
|
||||
panelArticleEdit.add(this.btnArticleSave);
|
||||
panelArticleEdit.add(this.btnArticleCancel);
|
||||
panelArticleEdit.add(lblArticleStatus);
|
||||
panelArticleEdit.setFocusTraversalPolicy(focusPolicy);
|
||||
panelArticleEdit.setFocusCycleRoot(true);
|
||||
|
||||
this.add(panelArticleList);
|
||||
this.add(panelArticleEdit);
|
||||
@@ -156,25 +172,7 @@ public class ArticleTab extends JPanel implements ActionListener {
|
||||
}
|
||||
|
||||
else {
|
||||
int re = this.articleTableModel.createArticle(this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
||||
|
||||
switch(re){
|
||||
case 0:
|
||||
this.lblArticleStatus.setText("Artikel \""+this.textFieldArticleName.getText()+"\" erfolgreich hinzugefügt.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht erstellt werden.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this.lblArticleStatus.setText("Es muss ein Artikelname vergeben werden");
|
||||
break;
|
||||
}
|
||||
saveButtonPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,4 +193,42 @@ public class ArticleTab extends JPanel implements ActionListener {
|
||||
this.textAreaArticleDescription.setText(articleDescription);
|
||||
}
|
||||
|
||||
private void saveButtonPressed(){
|
||||
int re = this.articleTableModel.createArticle(this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
||||
|
||||
switch(re){
|
||||
case 0:
|
||||
this.lblArticleStatus.setText("Artikel \""+this.textFieldArticleName.getText()+"\" erfolgreich hinzugefügt.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht erstellt werden.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this.lblArticleStatus.setText("Es muss ein Artikelname vergeben werden");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// Nothign to implement
|
||||
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
// Nothing to implement
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import javax.swing.JPanel;
|
||||
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
|
||||
public class ManageLendingTab extends JPanel {
|
||||
public class PanelManageLendings extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -15,7 +15,7 @@ public class ManageLendingTab extends JPanel {
|
||||
* Create the panel.
|
||||
* @param dbCon
|
||||
*/
|
||||
public ManageLendingTab(DbConnector dbCon) {
|
||||
public PanelManageLendings(DbConnector dbCon) {
|
||||
|
||||
}
|
||||
|
||||
71
src/de/katho/kBorrow/gui/PanelNewLending.java
Normal file
71
src/de/katho/kBorrow/gui/PanelNewLending.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package de.katho.kBorrow.gui;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.listener.NewLendingTableButton;
|
||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
||||
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PanelNewLending extends JPanel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7346953418572781322L;
|
||||
private FreeArticleTableModel freeArticleTableModel;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
* @param dbCon
|
||||
* @throws IOException
|
||||
*/
|
||||
public PanelNewLending(final DbConnector dbCon) throws IOException {
|
||||
this.setLayout(null);
|
||||
|
||||
// FreeArticleTable
|
||||
this.freeArticleTableModel = new FreeArticleTableModel(dbCon);
|
||||
JTable freeArticleTable = new JTable(freeArticleTableModel);
|
||||
freeArticleTable.setRowHeight(30);
|
||||
|
||||
NewLendingTableButton newLendingTableButton = new NewLendingTableButton("Artikel ausleihen", freeArticleTable, this);
|
||||
freeArticleTable.getColumnModel().getColumn(3).setCellEditor(newLendingTableButton);
|
||||
freeArticleTable.getColumnModel().getColumn(3).setCellRenderer(newLendingTableButton);
|
||||
freeArticleTable.getColumnModel().getColumn(3).setMinWidth(30);
|
||||
freeArticleTable.getColumnModel().getColumn(3).setMaxWidth(30);
|
||||
freeArticleTable.getColumnModel().getColumn(3).setPreferredWidth(30);
|
||||
|
||||
|
||||
freeArticleTable.setFillsViewportHeight(true);
|
||||
|
||||
|
||||
// Panel: FreeArticleList
|
||||
JPanel panelFreeArticleList = new JPanel();
|
||||
panelFreeArticleList.setBorder(new TitledBorder(null, "Vorhandene Artikel", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panelFreeArticleList.setBounds(0, 0, 589, 253);
|
||||
panelFreeArticleList.setLayout(new BorderLayout(0, 0));
|
||||
panelFreeArticleList.add(new JScrollPane(freeArticleTable));
|
||||
|
||||
|
||||
// Panel: NewLending
|
||||
JPanel panelNewLending = new JPanel();
|
||||
panelNewLending.setBorder(new TitledBorder(null, "Neue Ausleihe", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panelNewLending.setBounds(0, 252, 589, 205);
|
||||
|
||||
this.add(panelFreeArticleList);
|
||||
this.add(panelNewLending);
|
||||
|
||||
}
|
||||
|
||||
public void setModeNewLending(int articleId, String articleName,
|
||||
String articleDescription) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package de.katho.kBorrow.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
@@ -17,8 +21,9 @@ import javax.swing.border.TitledBorder;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.listener.UserDeleteTableButton;
|
||||
import de.katho.kBorrow.listener.UserEditTableButton;
|
||||
import de.katho.kBorrow.models.UserTableModel;
|
||||
|
||||
public class UserTab extends JPanel implements ActionListener {
|
||||
public class PanelUser extends JPanel implements ActionListener, KeyListener {
|
||||
|
||||
private static final long serialVersionUID = -319340262589243978L;
|
||||
private JLabel lblUserStatus;
|
||||
@@ -30,7 +35,7 @@ public class UserTab extends JPanel implements ActionListener {
|
||||
private int userEditId;
|
||||
private UserTableModel userTableModel;
|
||||
|
||||
public UserTab(final DbConnector dbCon) throws IOException{
|
||||
public PanelUser(final DbConnector dbCon) throws IOException{
|
||||
super();
|
||||
this.setLayout(null);
|
||||
|
||||
@@ -74,6 +79,8 @@ public class UserTab extends JPanel implements ActionListener {
|
||||
textFieldUserName.setColumns(10);
|
||||
textFieldUserSurname.setBounds(90, 61, 121, 20);
|
||||
textFieldUserSurname.setColumns(10);
|
||||
textFieldUserName.addKeyListener(this);
|
||||
textFieldUserSurname.addKeyListener(this);
|
||||
|
||||
// Edit: Buttons
|
||||
btnUserSave = new JButton("Speichern");
|
||||
@@ -83,6 +90,14 @@ public class UserTab extends JPanel implements ActionListener {
|
||||
btnUserCancel.setBounds(479, 30, 100, 20);
|
||||
btnUserCancel.addActionListener(this);
|
||||
|
||||
//Traversal-Policy
|
||||
Vector<Component> order = new Vector<Component>();
|
||||
order.add(this.textFieldUserName);
|
||||
order.add(this.textFieldUserSurname);
|
||||
order.add(this.btnUserCancel);
|
||||
order.add(this.btnUserSave);
|
||||
MyFocusTraversalPolicy focusPolicy = new MyFocusTraversalPolicy(order);
|
||||
|
||||
// User-Edit-Pane
|
||||
JPanel panelUserEdit = new JPanel();
|
||||
panelUserEdit.setBounds(0, 331, 589, 111);
|
||||
@@ -96,6 +111,8 @@ public class UserTab extends JPanel implements ActionListener {
|
||||
panelUserEdit.add(this.btnUserSave);
|
||||
panelUserEdit.add(this.lblUserStatus);
|
||||
panelUserEdit.add(this.btnUserCancel);
|
||||
panelUserEdit.setFocusTraversalPolicy(focusPolicy);
|
||||
panelUserEdit.setFocusCycleRoot(true);
|
||||
|
||||
this.add(panelUserList);
|
||||
this.add(panelUserEdit);
|
||||
@@ -130,25 +147,7 @@ public class UserTab extends JPanel implements ActionListener {
|
||||
this.userEditId = -1;
|
||||
}
|
||||
else {
|
||||
int re = this.userTableModel.createUser(this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
||||
|
||||
switch (re){
|
||||
case 0:
|
||||
this.lblUserStatus.setText("Benutzer \""+this.textFieldUserName.getText()+" "+this.textFieldUserSurname.getText()+"\" erfolgreich hinzugefügt.");
|
||||
this.textFieldUserName.setText("");
|
||||
this.textFieldUserSurname.setText("");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
this.lblUserStatus.setText("SQL-Fehler. Benutzer konnte nicht erstellt werden.");
|
||||
this.textFieldUserName.setText("");
|
||||
this.textFieldUserSurname.setText("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this.lblUserStatus.setText("Entweder Vor- oder Nachname müssen ausgefüllt sein.");
|
||||
break;
|
||||
}
|
||||
saveButtonPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,4 +168,43 @@ public class UserTab extends JPanel implements ActionListener {
|
||||
this.textFieldUserName.setText(pName);
|
||||
this.textFieldUserSurname.setText(pSurname);
|
||||
}
|
||||
|
||||
private void saveButtonPressed(){
|
||||
int re = this.userTableModel.createUser(this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
||||
|
||||
switch (re){
|
||||
case 0:
|
||||
this.lblUserStatus.setText("Benutzer \""+this.textFieldUserName.getText()+" "+this.textFieldUserSurname.getText()+"\" erfolgreich hinzugefügt.");
|
||||
this.textFieldUserName.setText("");
|
||||
this.textFieldUserSurname.setText("");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
this.lblUserStatus.setText("SQL-Fehler. Benutzer konnte nicht erstellt werden.");
|
||||
this.textFieldUserName.setText("");
|
||||
this.textFieldUserSurname.setText("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this.lblUserStatus.setText("Entweder Vor- oder Nachname müssen ausgefüllt sein.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent pKeyPress) {
|
||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent arg0) {
|
||||
// Nothing to implement
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent arg0) {
|
||||
// Nothing to implement
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package de.katho.kBorrow.listener;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -10,7 +9,7 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import de.katho.kBorrow.gui.ArticleTableModel;
|
||||
import de.katho.kBorrow.models.ArticleTableModel;
|
||||
|
||||
public class ArticleDeleteTableButton extends TableButton {
|
||||
|
||||
@@ -19,16 +18,20 @@ public class ArticleDeleteTableButton extends TableButton {
|
||||
*/
|
||||
private static final long serialVersionUID = 7701712368979056068L;
|
||||
|
||||
public ArticleDeleteTableButton(String pLabel, JTable pTable) throws IOException {
|
||||
super(new ImageIcon(ImageIO.read(new File("assets/icons/edit-delete.png"))), pTable);
|
||||
|
||||
public ArticleDeleteTableButton(String pLabel, final JTable pTable) throws IOException {
|
||||
super(pLabel);
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(new File("assets/icons/edit-delete.png")));
|
||||
|
||||
this.buttonE.setIcon(icon);
|
||||
this.buttonR.setIcon(icon);
|
||||
|
||||
this.buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
|
||||
ArticleTableModel model = (ArticleTableModel) table.getModel();
|
||||
ArticleTableModel model = (ArticleTableModel) pTable.getModel();
|
||||
|
||||
int row = table.getSelectedRow();
|
||||
int row = pTable.getSelectedRow();
|
||||
int id = model.getArticleId(row);
|
||||
|
||||
model.deleteArticle(id);
|
||||
|
||||
@@ -9,8 +9,8 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import de.katho.kBorrow.gui.ArticleTab;
|
||||
import de.katho.kBorrow.gui.ArticleTableModel;
|
||||
import de.katho.kBorrow.gui.PanelArticle;
|
||||
import de.katho.kBorrow.models.ArticleTableModel;
|
||||
|
||||
public class ArticleEditTableButton extends TableButton {
|
||||
|
||||
@@ -19,15 +19,19 @@ public class ArticleEditTableButton extends TableButton {
|
||||
*/
|
||||
private static final long serialVersionUID = -5902626427691636902L;
|
||||
|
||||
public ArticleEditTableButton(String pLabel, JTable pTable, final ArticleTab articleTab) throws IOException {
|
||||
super(new ImageIcon(ImageIO.read(new File("assets/icons/accessories-text-editor.png"))), pTable);
|
||||
public ArticleEditTableButton(String pLabel, final JTable pTable, final PanelArticle articleTab) throws IOException {
|
||||
super(pLabel);
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(new File("assets/icons/accessories-text-editor.png")));
|
||||
|
||||
this.buttonE.setIcon(icon);
|
||||
this.buttonR.setIcon(icon);
|
||||
|
||||
this.buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
|
||||
ArticleTableModel model = (ArticleTableModel) table.getModel();
|
||||
int row = table.getSelectedRow();
|
||||
ArticleTableModel model = (ArticleTableModel) pTable.getModel();
|
||||
int row = pTable.getSelectedRow();
|
||||
|
||||
articleTab.setModeEditArticle(model.getArticleId(row), model.getArticleName(row), model.getArticleDescription(row));
|
||||
}
|
||||
|
||||
41
src/de/katho/kBorrow/listener/NewLendingTableButton.java
Normal file
41
src/de/katho/kBorrow/listener/NewLendingTableButton.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package de.katho.kBorrow.listener;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import de.katho.kBorrow.gui.PanelNewLending;
|
||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
||||
|
||||
public class NewLendingTableButton extends TableButton {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7492272258718253745L;
|
||||
|
||||
public NewLendingTableButton(String pLabel, final JTable pTable, final PanelNewLending pPanel) throws IOException {
|
||||
super(pLabel);
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(new File("assets/icons/go-down.png")));
|
||||
|
||||
this.buttonE.setIcon(icon);
|
||||
this.buttonR.setIcon(icon);
|
||||
|
||||
this.buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
|
||||
FreeArticleTableModel model = (FreeArticleTableModel) pTable.getModel();
|
||||
int row = pTable.getSelectedRow();
|
||||
|
||||
pPanel.setModeNewLending(model.getArticleId(row), model.getArticleName(row), model.getArticleDescription(row));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package de.katho.kBorrow.listener;
|
||||
import java.awt.Component;
|
||||
|
||||
import javax.swing.AbstractCellEditor;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
@@ -12,15 +11,15 @@ import javax.swing.table.TableCellRenderer;
|
||||
public abstract class TableButton extends AbstractCellEditor implements TableCellRenderer, TableCellEditor {
|
||||
private static final long serialVersionUID = -5902626427691636902L;
|
||||
private String label;
|
||||
protected JTable table;
|
||||
protected JButton buttonR;
|
||||
protected JButton buttonE;
|
||||
|
||||
public TableButton (ImageIcon pIcon, JTable pTable) {
|
||||
//this.label = pLabel;
|
||||
this.table = pTable;
|
||||
this.buttonR = new JButton(pIcon);
|
||||
this.buttonE = new JButton(pIcon);
|
||||
public TableButton (String pLabel) {
|
||||
this.label = pLabel;
|
||||
this.buttonR = new JButton();
|
||||
this.buttonE = new JButton();
|
||||
this.buttonE.setToolTipText(this.label);
|
||||
this.buttonR.setToolTipText(this.label);
|
||||
}
|
||||
|
||||
public Object getCellEditorValue() {
|
||||
|
||||
@@ -9,22 +9,26 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import de.katho.kBorrow.gui.UserTableModel;
|
||||
import de.katho.kBorrow.models.UserTableModel;
|
||||
|
||||
public class UserDeleteTableButton extends TableButton {
|
||||
|
||||
private static final long serialVersionUID = -886584066497429394L;
|
||||
|
||||
public UserDeleteTableButton(String pLabel, JTable pTable) throws IOException{
|
||||
super(new ImageIcon(ImageIO.read(new File("assets/icons/edit-delete.png"))), pTable);
|
||||
|
||||
public UserDeleteTableButton(String pLabel, final JTable pTable) throws IOException{
|
||||
super(pLabel);
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(new File("assets/icons/edit-delete.png")));
|
||||
|
||||
this.buttonE.setIcon(icon);
|
||||
this.buttonR.setIcon(icon);
|
||||
|
||||
this.buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
|
||||
UserTableModel model = (UserTableModel) table.getModel();
|
||||
UserTableModel model = (UserTableModel) pTable.getModel();
|
||||
|
||||
int row = table.getSelectedRow();
|
||||
int row = pTable.getSelectedRow();
|
||||
int id = model.getUserId(row);
|
||||
|
||||
model.deleteUser(id);
|
||||
|
||||
@@ -9,8 +9,8 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import de.katho.kBorrow.gui.UserTab;
|
||||
import de.katho.kBorrow.gui.UserTableModel;
|
||||
import de.katho.kBorrow.gui.PanelUser;
|
||||
import de.katho.kBorrow.models.UserTableModel;
|
||||
|
||||
public class UserEditTableButton extends TableButton {
|
||||
|
||||
@@ -19,15 +19,19 @@ public class UserEditTableButton extends TableButton {
|
||||
*/
|
||||
private static final long serialVersionUID = -886584066497429394L;
|
||||
|
||||
public UserEditTableButton(String pLabel, JTable pTable, final UserTab pPanel) throws IOException{
|
||||
super(new ImageIcon(ImageIO.read(new File("assets/icons/accessories-text-editor.png"))), pTable);
|
||||
|
||||
public UserEditTableButton(String pLabel, final JTable pTable, final PanelUser pPanel) throws IOException{
|
||||
super(pLabel);
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(new File("assets/icons/accessories-text-editor.png")));
|
||||
|
||||
this.buttonE.setIcon(icon);
|
||||
this.buttonR.setIcon(icon);
|
||||
|
||||
this.buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
|
||||
UserTableModel model = (UserTableModel) table.getModel();
|
||||
int row = table.getSelectedRow();
|
||||
UserTableModel model = (UserTableModel) pTable.getModel();
|
||||
int row = pTable.getSelectedRow();
|
||||
|
||||
pPanel.setModeEditUser(model.getUserId(row), model.getUserName(row), model.getUserSurname(row));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.katho.kBorrow.gui;
|
||||
package de.katho.kBorrow.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
74
src/de/katho/kBorrow/models/FreeArticleTableModel.java
Normal file
74
src/de/katho/kBorrow/models/FreeArticleTableModel.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package de.katho.kBorrow.models;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.data.KArticle;
|
||||
|
||||
public class FreeArticleTableModel extends AbstractTableModel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7318589937150373541L;
|
||||
private DbConnector dbCon;
|
||||
String[] header = {"ID", "Artikelname", "Artikelbeschreibung", ""};
|
||||
private ArrayList<KArticle> data = new ArrayList<KArticle>();
|
||||
|
||||
public FreeArticleTableModel(DbConnector pDbCon) {
|
||||
this.dbCon = pDbCon;
|
||||
this.updateTable();
|
||||
}
|
||||
|
||||
public String getColumnName(int pIndex){
|
||||
return header[pIndex];
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return header.length;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
public Object getValueAt(int pRow, int pCol) {
|
||||
switch(pCol){
|
||||
case 0:
|
||||
return String.valueOf(data.get(pRow).getId());
|
||||
|
||||
case 1:
|
||||
return data.get(pRow).getName();
|
||||
|
||||
case 2:
|
||||
return data.get(pRow).getDescription();
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCellEditable(int row, int col){
|
||||
if (col > 2) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Implement!
|
||||
private void updateTable(){
|
||||
|
||||
}
|
||||
|
||||
public int getArticleId(int pRow){
|
||||
return data.get(pRow).getId();
|
||||
}
|
||||
|
||||
public String getArticleName(int pRow){
|
||||
return data.get(pRow).getName();
|
||||
}
|
||||
|
||||
public String getArticleDescription(int pRow){
|
||||
return data.get(pRow).getDescription();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.katho.kBorrow.gui;
|
||||
package de.katho.kBorrow.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
Reference in New Issue
Block a user