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 #5

Merged
merged 8 commits into from
Sep 15, 2023
Merged
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
5 changes: 3 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-20">
<classpathentry exported="true" kind="lib" path="include/pdf-renderer-1.0.5.1.jar"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-20">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="include/json-tool.jar"/>
<classpathentry exported="true" kind="lib" path="include/json-tool.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file added include/pdf-renderer-1.0.5.1.jar
Binary file not shown.
27 changes: 11 additions & 16 deletions src/efakturaplus/App.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
package efakturaplus;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Scanner;

import efakturaplus.gui.Window;
import efakturaplus.models.Invoice;
import efakturaplus.util.EFakturaUtil;

public class App {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.println("Please enter your API key:");

//String API_KEY = sc.next();

sc.close();

/*EFakturaUtil efaktura = EFakturaUtil.getInstance(API_KEY);

ArrayList<String> ids = efaktura.getIdsList();

for(String id : ids) {
Invoice invoice = efaktura.getInvoice(id);

DateFormat format = new SimpleDateFormat("dd.MM.yyyy");

System.out.println("<"+format.format(invoice.deliveryDate)+"> ("+invoice.paymentMod+")"+invoice.paymentId);

if(invoice.payeeFinancialAccs != null) {
for(String financialAcc : invoice.payeeFinancialAccs) {
System.out.println("<"+financialAcc+">");
}
}

System.out.println(invoice.supplier);
System.out.println(invoice.customer);
System.out.println("--> " + invoice.payableAmount+" RSD");
}*/

Window w = new Window();
}

Expand Down
164 changes: 109 additions & 55 deletions src/efakturaplus/gui/InvoiceList.java
Original file line number Diff line number Diff line change
@@ -1,70 +1,103 @@
package efakturaplus.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.Border;

import efakturaplus.models.*;
import efakturaplus.models.Invoice;;

public class InvoiceList extends JComponent {
public class InvoiceList extends JPanel {

private static final long serialVersionUID = 1L;

ArrayList<Invoice> invoices;

private JPanel invoiceDisplay;

public InvoiceList(int width, int height) {
this.setSize(width, height);
this.setLayout(null);
this.setLayout(new BorderLayout());

this.invoices = new ArrayList<Invoice>();
}

public int getLength() {
return this.invoices.size();
this.invoices = new ArrayList<>();

this.invoiceDisplay = new JPanel(new GridBagLayout());

JScrollPane sp = new JScrollPane(invoiceDisplay);
this.add(sp, BorderLayout.CENTER);
}

public void addInvoice(Invoice invoice) {
this.add(new InvoiceListItem(invoice, new Dimension(this.getWidth(), 35), this.invoices.size()));
this.validate();
InvoiceListItem item = new InvoiceListItem(invoice, new Dimension(this.getWidth(), 35), this.invoices.size());

this.invoices.add(invoice);
int n = this.invoices.size();

GridBagConstraints constr = new GridBagConstraints();
constr.gridy = n*45;
constr.anchor = GridBagConstraints.CENTER;
constr.weightx = 0.5;
constr.weighty = 1.0;
constr.ipadx = 15;
constr.ipady = 12;
constr.fill = GridBagConstraints.BOTH;

constr.gridx = 0;
constr.gridwidth = 1;
this.invoiceDisplay.add(item.date, constr);

constr.gridx = 1;
constr.gridwidth = 1;
this.invoiceDisplay.add(item.amount, constr);

constr.gridx = 2;
constr.gridwidth = 2;
this.invoiceDisplay.add(item.supplier, constr);

this.invoices.add(invoice);
}

}

class InvoiceListItem extends JComponent implements MouseListener{

private static final long serialVersionUID = 1L;

private Invoice invoice;

private Color borderColor;

Invoice invoice;

Color borderColor;
private boolean selected = false;

public JLabel date;
public JLabel amount;
public JLabel supplier;

public InvoiceListItem(Invoice invoice, Dimension size, int idx) {
super();
this.invoice = invoice;

int w = size.width;
int h = size.height;
this.setBounds(0, h*idx, w, h);


this.selectBorderColor();
this.display();

this.loadComponents();

this.addMouseListener(this);

this.setVisible(true);
}

private void selectBorderColor() {
switch (this.invoice.status) {
case ReNotified:
Expand All @@ -73,6 +106,9 @@ private void selectBorderColor() {
case New:
this.borderColor = Color.green;
break;
case Seen:
this.borderColor = Color.blue;
break;
case Approved:
this.borderColor = Color.cyan;
break;
Expand All @@ -82,55 +118,73 @@ private void selectBorderColor() {
break;
}
}

private void display() {
Border border = BorderFactory.createLineBorder(this.borderColor, 1);
this.setBorder(border);

JLabel date = new JLabel(this.invoice.getDateString());
JLabel supplier = new JLabel(this.invoice.supplier.toString());
JLabel amount = new JLabel("" + this.invoice.payableAmount);

date.setBounds(15, 5, this.getWidth()/4, 25);
supplier.setBounds(this.getWidth()/2, 5, this.getWidth()/2, 25);
amount.setBounds(this.getWidth()/4, 5, this.getWidth()/4, 25);

this.add(date);
this.add(supplier);
this.add(amount);

/*label.setFont(new Font("Arial", Font.PLAIN, 20));
label.setForeground(Color.black);
*/

private void loadComponents() {
this.removeAll();
this.setBorder(null);

this.date = new JLabel(this.invoice.getDateString(), JLabel.CENTER);
this.amount = new JLabel("" + this.invoice.payableAmount, JLabel.CENTER);
this.supplier = new JLabel(this.invoice.supplier.name.toString());

Border border = BorderFactory.createMatteBorder(0, 0, 1, 0, borderColor);
this.date.setBorder(border);
this.amount.setBorder(border);
this.supplier.setBorder(border);

this.date.addMouseListener(this);
this.amount.addMouseListener(this);
this.supplier.addMouseListener(this);
}

@Override
public void mouseClicked(MouseEvent e) {
System.out.println(this.invoice);
if(this.selected) {
JFrame frame1 = new JFrame("PDF Document");
PDFDisplay pdfDisplay1 = new PDFDisplay(this.invoice.pdfInvoice);
frame1.add(pdfDisplay1);
frame1.setSize(700, 1000);
frame1.setVisible(true);

if(this.invoice.pdfAttachment != null) {
JFrame frame2 = new JFrame("PDF Attachment");
PDFDisplay pdfDisplay2 = new PDFDisplay(this.invoice.pdfAttachment);
frame2.add(pdfDisplay2);
frame2.setSize(700, 1000);
frame2.setVisible(true);
}

selected = false;
}else {
this.date.setBackground(borderColor);
this.amount.setBackground(borderColor);
this.supplier.setBackground(borderColor);
selected = true;
}

}

@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}
}
}
28 changes: 14 additions & 14 deletions src/efakturaplus/gui/KeyPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,52 @@
public class KeyPanel extends JPanel {

private static final long serialVersionUID = 1L;

private Window parent;

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

addLabel(width, height);
addTextField(width, height);
}

private void addLabel(int width, int height) {
JLabel label = new JLabel("Please enter your API key here:");
label.setFont(new Font("Arial", Font.PLAIN, 20));
label.setBounds(width/2-150, height/2-75, 350, 50);

label.setForeground(Color.black);

this.add(label);
}

private void addTextField(int width, int height) {
JTextField keyInput = new JTextField();
keyInput.setBounds(width/2-150, height/2-25, 300, 60);

keyInput.setBorder(BorderFactory.createLineBorder(Color.black, 3, true));

keyInput.setBorder(BorderFactory.createCompoundBorder(
keyInput.getBorder(),
keyInput.getBorder(),
BorderFactory.createEmptyBorder(15, 15, 15, 15)));

keyInput.setFont(new Font("Arial", Font.PLAIN, 20));

keyInput.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
User.API_KEY = keyInput.getText();
System.out.println(User.API_KEY);

parent.switchPanels();
}
});

this.add(keyInput);
}

}
Loading