diff --git a/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/IUpdate.java b/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/IUpdate.java index 9b496c4..d51c8a7 100644 --- a/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/IUpdate.java +++ b/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/IUpdate.java @@ -4,4 +4,5 @@ public interface IUpdate { void onUpdateEmailBox(int current, int total, String host); void onUpdateEmailLoading(int current, int total); void onUpdateSending(int current, int total); + void onDone(); } \ No newline at end of file diff --git a/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/Window.java b/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/Window.java index 7b98c08..108512f 100644 --- a/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/Window.java +++ b/src/main/java/com/github/tobiasmiosczka/cinema/KDMManager/gui/Window.java @@ -8,6 +8,7 @@ import javax.mail.MessagingException; import javax.swing.*; +import javax.swing.border.LineBorder; import java.awt.*; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -20,10 +21,19 @@ public class Window extends JFrame implements IUpdate { private JList lEmailLoginList; private JList lFtpLoginList; + private static final Font headerFont = new Font("Arial", Font.BOLD, 20); + private final DefaultListModel dlmFtpLogins = new DefaultListModel<>(); private final DefaultListModel dlmEmailLogin = new DefaultListModel<>(); private JProgressBar pbMajor, pbMinor; + JButton btLoadKdms, + btAddEmailLogin, + btEditEmailLogin, + btDeleteEmailLogin, + btAddFtpLogin, + btEditFtpLogin, + btDeleteFtpLogin; private Config config = new Config(); @@ -52,8 +62,8 @@ public Window() throws IOException, JDOMException { @Override public void onUpdateEmailLoading(int current, int total) { - System.out.println("onUpdateEmailLoading " + current + "/" + total); EventQueue.invokeLater(() -> { + pbMinor.setString(current + "/" + total); pbMinor.setMaximum(total); pbMinor.setValue(current); }); @@ -61,9 +71,8 @@ public void onUpdateEmailLoading(int current, int total) { @Override public void onUpdateSending(int current, int total) { - System.out.println("onUpdateSending " + current + "/" + total); - System.out.println("onUpdateEmailLoading " + current + "/" + total); EventQueue.invokeLater(() -> { + pbMajor.setString(current + "/" + total); pbMajor.setMaximum(total); pbMajor.setValue(current); }); @@ -71,7 +80,6 @@ public void onUpdateSending(int current, int total) { @Override public void onUpdateEmailBox(int current, int total, String host) { - System.out.println("onUpdateEmailBox " + current + "/" + total + " " + host); EventQueue.invokeLater(() -> { pbMajor.setMaximum(total); pbMajor.setValue(current); @@ -79,6 +87,24 @@ public void onUpdateEmailBox(int current, int total, String host) { }); } + @Override + public void onDone() { + EventQueue.invokeLater(() -> { + setUiEnabled(true); + }); + } + + private void setUiEnabled(boolean enabled) { + btLoadKdms.setEnabled(enabled); + btAddEmailLogin.setEnabled(enabled); + btEditEmailLogin.setEnabled(enabled); + btDeleteEmailLogin.setEnabled(enabled); + btAddFtpLogin.setEnabled(enabled); + btEditFtpLogin.setEnabled(enabled); + btDeleteFtpLogin.setEnabled(enabled); + } + + private void init() { this.setTitle("KDMManager"); this.setLayout(null); @@ -86,16 +112,18 @@ private void init() { Container c = this.getContentPane(); c.setPreferredSize(new Dimension(600, 665)); - JLabel lbEmailLogins = new JLabel("Email Logins"); - lbEmailLogins.setBounds(5, 5, 190, 30); + JLabel lbEmailLogins = new JLabel("Email Logins", SwingConstants.CENTER); + lbEmailLogins.setFont(headerFont); + lbEmailLogins.setBounds(5, 5, 590, 30); c.add(lbEmailLogins); lEmailLoginList = new JList<>(); + lEmailLoginList.setBorder(new LineBorder(Color.BLACK, 1)); lEmailLoginList.setModel(dlmEmailLogin); lEmailLoginList.setBounds(5, 40, 590, 200); c.add(lEmailLoginList); - JButton btAddEmailLogin = new JButton("Add"); + btAddEmailLogin = new JButton("Add"); btAddEmailLogin.addActionListener(a -> { EmailLogin emailLogin = EmailLoginDialog.getEmailLogin(new EmailLogin("", 21, "", "", "pop3s", "INNOX", false)); if (emailLogin != null){ @@ -107,7 +135,7 @@ private void init() { btAddEmailLogin.setBounds(5, 245, 190, 30); c.add(btAddEmailLogin); - JButton btEditEmailLogin = new JButton("Edit"); + btEditEmailLogin = new JButton("Edit"); btEditEmailLogin.addActionListener(a -> { if (lEmailLoginList.getSelectedIndices().length != 1) return; @@ -121,7 +149,7 @@ private void init() { btEditEmailLogin.setBounds(205, 245, 190, 30); c.add(btEditEmailLogin); - JButton btDeleteEmailLogin = new JButton("Delete"); + btDeleteEmailLogin = new JButton("Delete"); btDeleteEmailLogin.addActionListener(a -> { lEmailLoginList.getSelectedValuesList().forEach(config.getEmailLogins()::remove); saveConfig(); @@ -130,16 +158,18 @@ private void init() { btDeleteEmailLogin.setBounds(405, 245, 190, 30); c.add(btDeleteEmailLogin); - JLabel lbFtpLogins = new JLabel("FTP Logins"); - lbFtpLogins.setBounds(5, 280, 190, 30); + JLabel lbFtpLogins = new JLabel("FTP Logins", SwingConstants.CENTER); + lbFtpLogins.setFont(headerFont); + lbFtpLogins.setBounds(5, 280, 590, 30); c.add(lbFtpLogins); lFtpLoginList = new JList<>(); + lFtpLoginList.setBorder(new LineBorder(Color.BLACK, 1)); lFtpLoginList.setModel(dlmFtpLogins); lFtpLoginList.setBounds(5, 315, 590, 200); c.add(lFtpLoginList); - JButton btAddFtpLogin = new JButton("Add"); + btAddFtpLogin = new JButton("Add"); btAddFtpLogin.addActionListener(a -> { FtpLogin ftpLogin = FtpLoginDialog.getFtpLogin(new FtpLogin("", 995, "", "", "")); if (ftpLogin != null) { @@ -151,7 +181,7 @@ private void init() { btAddFtpLogin.setBounds(5, 520, 190, 30); c.add(btAddFtpLogin); - JButton btEditFtpLogin = new JButton("Edit"); + btEditFtpLogin = new JButton("Edit"); btEditFtpLogin.addActionListener(a -> { if (lFtpLoginList.getSelectedIndices().length != 1) return; @@ -165,7 +195,7 @@ private void init() { btEditFtpLogin.setBounds(205, 520, 190, 30); c.add(btEditFtpLogin); - JButton btDeleteFtpLogin = new JButton("Delete"); + btDeleteFtpLogin = new JButton("Delete"); btDeleteFtpLogin.addActionListener(a -> { lFtpLoginList.getSelectedValuesList().forEach(config.getFtpLogins()::remove); saveConfig(); @@ -184,13 +214,15 @@ private void init() { pbMinor.setBounds(5, 585, 590, 30); c.add(pbMinor); - JButton btLoadKdms = new JButton("Load KDMs"); + btLoadKdms = new JButton("Load KDMs"); btLoadKdms.addActionListener(a -> loadKdms()); btLoadKdms.setBounds(5, 625, 590, 30); c.add(btLoadKdms); } private void loadKdms() { + btLoadKdms.setEnabled(false); + setUiEnabled(false); new Thread(() -> { Collection kdms = null; long start = System.currentTimeMillis();