Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gui #18

Merged
merged 7 commits into from
Feb 4, 2024
Merged

Gui #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions src/efakturaplus/App.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
package efakturaplus;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStreamReader;

import efakturaplus.gui.Window;
import efakturaplus.models.User;

public class App {

public static void main(String[] args) {
try {
File f = new File("user.enc");

if(f.exists()) {
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuilder sb = new StringBuilder();
String line;
while((line = br.readLine()) == null) {
sb.append(line);
}

User.API_KEY = sb.toString();
}

}catch(Exception e){
System.out.println("Error reading a file!");
};

@SuppressWarnings("unused")
Window w = new Window();
}
Expand Down
4 changes: 4 additions & 0 deletions src/efakturaplus/gui/InvoiceList.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.swing.border.Border;

import efakturaplus.models.Invoice;
import efakturaplus.models.InvoiceStatus;
import efakturaplus.models.InvoiceType;
import efakturaplus.util.EFakturaUtil;
import efakturaplus.util.PrintColor;
Expand Down Expand Up @@ -350,6 +351,9 @@ private void deselect(InvoiceListItem item) {
}

private void approveOrReject(boolean approve) {
if(approve)
this.invoice.status = InvoiceStatus.Approved;

EFakturaUtil util = EFakturaUtil.getInstance();

util.approveOrReject(this.invoice, approve);
Expand Down
47 changes: 29 additions & 18 deletions src/efakturaplus/gui/KeyPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.awt.event.*;
import java.io.*;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
Expand All @@ -15,47 +12,57 @@
import javax.crypto.*;
import javax.crypto.spec.*;

import sun.misc.*;

import java.util.Arrays;
import java.util.Base64;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import ch.randelshofer.util.ArrayUtil;
import efakturaplus.models.User;

public class KeyPanel extends JPanel {

private static final long serialVersionUID = 1L;

private String password;
private byte[] iv;

JLabel keyLabel, passLabel, passLabel2;
JTextField keyInput;
JPasswordField passInput, passInput2;

private Window parent;

private boolean registeredUser;

public KeyPanel(Window parent, int width, int height) {
this.parent = parent;
this.setSize(width, height);
this.setLayout(null);

loadAPIKey();
addComponents(width, height);
}

private void loadAPIKey() {
try {
File f = new File("user.enc");

if(f.exists()) {
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuilder sb = new StringBuilder();
String line;
while((line = br.readLine()) == null) {
sb.append(line);
}

User.API_KEY = sb.toString();

br.close();
fis.close();
}

}catch(Exception e){
System.out.println("Error reading a file!");
};
}

private void addComponents(int width, int height) {

Expand Down Expand Up @@ -200,6 +207,8 @@ private void encryptData() throws NoSuchAlgorithmException, InvalidKeySpecExcept
fos.write(iv);
fos.write(salt);
fos.write(ciphertext);

fos.close();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -230,6 +239,8 @@ private String decryptData() {
String plaintext = new String(cis.readAllBytes());

content = plaintext;

cis.close();

}catch(Exception e) {
e.printStackTrace();
Expand Down
23 changes: 20 additions & 3 deletions src/efakturaplus/gui/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public class MainPanel extends JPanel {
private JPanel navigator;
private JButton purchaseBtn;
private JButton salesBtn;
private JButton statsBtn;

private InvoiceList purchaseIl;
private InvoiceList salesIl;

private StatisticsPanel statsPanel;

public MainPanel(Window parent) {
this.parent = parent;
Expand All @@ -57,6 +60,9 @@ public MainPanel(Window parent) {
salesIl = new InvoiceList();
dataPanel.add(salesIl, "SALES");

statsPanel = new StatisticsPanel();
dataPanel.add(statsPanel, "STATS");

dataPanelLayout.show(dataPanel, "PURCHASE");

this.add(dataPanel, BorderLayout.CENTER);
Expand All @@ -68,10 +74,12 @@ public MainPanel(Window parent) {
private void createNavigator() {
Image purchaseBtnImg = null;
Image salesBtnImg = null;
Image statsButtonImg = null;
Image logoutImg = null;
try {
purchaseBtnImg = ImageIO.read(new File("icons/invoice-purchase.png"));
salesBtnImg = ImageIO.read(new File("icons/invoice-sales.png"));
statsButtonImg = ImageIO.read(new File("icons/stats.png"));
logoutImg = ImageIO.read(new File("icons/logout.png"));

//this.purchaseBtn.add(new JLabel("Sales"));
Expand Down Expand Up @@ -99,9 +107,8 @@ public void actionPerformed(ActionEvent e) {

navigator.add(purchaseBtn, gbc);

gbc.gridy = 1;


gbc.gridy = 1;
this.salesBtn = makeButton(salesBtnImg, "Sales", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -111,14 +118,24 @@ public void actionPerformed(ActionEvent e) {

navigator.add(salesBtn, gbc);

gbc.gridy = 2;
this.statsBtn = makeButton(statsButtonImg, "Statistics", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dataPanelLayout.show(dataPanel, "STATS");
}
});

navigator.add(statsBtn, gbc);

JButton logout = makeButton(logoutImg, "Log out", new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
parent.showKeyPanel();
}
});

gbc.gridy = 2;
gbc.gridy = 3;
gbc.anchor = GridBagConstraints.LAST_LINE_END;
gbc.weighty = 1;

Expand Down
Loading
Loading