/* Valhalla MailChecker -- Simple IMAP Mail Checker
* Copyright (C) 2010-2011 Guillaume Florimond (gflorimond at gmail dot com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* CheckPane.java
*
* Created on 22 mai 2010, 14:22:21
*/
package fr.valhalla.mailcheck.gui.classic;
import fr.valhalla.mailcheck.Checker;
import fr.valhalla.mailcheck.gui.AccountConfigFrame;
import fr.valhalla.mailcheck.utils.NiceColors;
/**
*
* @author guillaume
*/
public class CheckPane extends javax.swing.JPanel {
private Checker checker;
/** Creates new form CheckPane */
public CheckPane(Checker c) {
checker = c;
initComponents();
}
public Checker getChecker() {
return checker;
}
public void setAccountName(String accountName) {
setBorder(javax.swing.BorderFactory.createTitledBorder(accountName));
}
public void setLastUpdate(String updateTime) {
lastUpdateLabel.setText("Dernière MàJ: " + updateTime);
}
public void setNextUpdate(String updateTime) {
nextUpdateLabel.setText("Prochaine MàJ: " + updateTime);
}
public void setAllMessagesCount(int messages) {
String msg = "";
if(messages == 0) {
msg = "aucun message";
allMessagesLabel.setForeground(NiceColors.NICKEL);
} else if(messages == 1) {
msg = "1 message";
allMessagesLabel.setForeground(NiceColors.LAVENDER);
} else {
msg = new Integer(messages).toString() + " messages";
allMessagesLabel.setForeground(NiceColors.LAVENDER);
}
allMessagesLabel.setText(msg);
}
public void setNewMessagesCount(int messages) {
String msg = "";
if(messages == 0) {
msg = "aucun nouveau message";
newMessagesLabel.setForeground(NiceColors.NICKEL);
} else if(messages == 1) {
msg = "1 nouveau message";
newMessagesLabel.setForeground(NiceColors.SALMON);
} else {
msg = new Integer(messages).toString() + " nouveaux messages";
newMessagesLabel.setForeground(NiceColors.SALMON);
}
newMessagesLabel.setText(msg);
}
public void setUnreadMessagesCount(int messages) {
String msg = "";
if(messages == 0) {
msg = "aucun message non lu";
unreadMessagesLabel.setForeground(NiceColors.NICKEL);
} else if(messages == 1) {
msg = "1 message non lu";
unreadMessagesLabel.setForeground(NiceColors.SALMON);
} else {
msg = new Integer(messages).toString() + " messages non lus";
unreadMessagesLabel.setForeground(NiceColors.SALMON);
}
unreadMessagesLabel.setText(msg);
}
public void setDetailsButtonSelected(boolean selected) {
detailsButton.setSelected(selected);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonsPanel = new javax.swing.JPanel();
connectionButton = new javax.swing.JToggleButton();
configButton = new javax.swing.JButton();
detailsButton = new javax.swing.JToggleButton();
centerPanel = new javax.swing.JPanel();
updatePanel = new javax.swing.JPanel();
lastUpdateLabel = new javax.swing.JLabel();
nextUpdateLabel = new javax.swing.JLabel();
messagesPanel = new javax.swing.JPanel();
allMessagesLabel = new javax.swing.JLabel();
unreadMessagesLabel = new javax.swing.JLabel();
newMessagesLabel = new javax.swing.JLabel();
setBorder(javax.swing.BorderFactory.createTitledBorder("[Account Name]"));
setLayout(new java.awt.BorderLayout());
buttonsPanel.setMaximumSize(null);
buttonsPanel.setOpaque(false);
buttonsPanel.setLayout(new java.awt.GridLayout(3, 1));
connectionButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fr/valhalla/mailcheck/resources/images/connect.png"))); // NOI18N
connectionButton.setSelected(true);
connectionButton.setBorderPainted(false);
connectionButton.setMargin(null);
connectionButton.setMaximumSize(null);
connectionButton.setMinimumSize(null);
connectionButton.setPreferredSize(null);
connectionButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
connectionButtonActionPerformed(evt);
}
});
buttonsPanel.add(connectionButton);
configButton.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
configButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fr/valhalla/mailcheck/resources/images/configuration.png"))); // NOI18N
configButton.setBorderPainted(false);
configButton.setMaximumSize(null);
configButton.setMinimumSize(null);
configButton.setPreferredSize(null);
configButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
configButtonActionPerformed(evt);
}
});
buttonsPanel.add(configButton);
detailsButton.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
detailsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fr/valhalla/mailcheck/resources/images/list.png"))); // NOI18N
detailsButton.setBorderPainted(false);
detailsButton.setMaximumSize(null);
detailsButton.setMinimumSize(null);
detailsButton.setPreferredSize(null);
detailsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
detailsButtonActionPerformed(evt);
}
});
buttonsPanel.add(detailsButton);
add(buttonsPanel, java.awt.BorderLayout.WEST);
centerPanel.setLayout(new java.awt.BorderLayout());
updatePanel.setOpaque(false);
lastUpdateLabel.setText("[Last Update]");
updatePanel.add(lastUpdateLabel);
nextUpdateLabel.setText("[Next Update]");
updatePanel.add(nextUpdateLabel);
centerPanel.add(updatePanel, java.awt.BorderLayout.SOUTH);
messagesPanel.setMaximumSize(null);
messagesPanel.setOpaque(false);
messagesPanel.setLayout(new java.awt.GridLayout(3, 1));
allMessagesLabel.setFont(new java.awt.Font("Lucida Grande", 1, 15)); // NOI18N
allMessagesLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
allMessagesLabel.setText("[All Messages]");
messagesPanel.add(allMessagesLabel);
unreadMessagesLabel.setFont(new java.awt.Font("Lucida Grande", 1, 15)); // NOI18N
unreadMessagesLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
unreadMessagesLabel.setText("[Unread Messages]");
messagesPanel.add(unreadMessagesLabel);
newMessagesLabel.setFont(new java.awt.Font("Lucida Grande", 1, 15)); // NOI18N
newMessagesLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
newMessagesLabel.setText("[New Messages]");
messagesPanel.add(newMessagesLabel);
centerPanel.add(messagesPanel, java.awt.BorderLayout.CENTER);
add(centerPanel, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void configButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configButtonActionPerformed
AccountConfigFrame acf = new AccountConfigFrame(checker.getAccount());
acf.setVisible(true);
}//GEN-LAST:event_configButtonActionPerformed
private void detailsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detailsButtonActionPerformed
// Enfoncé
if(detailsButton.isSelected()) {
checker.showCheckFrame();
} else { // Relâché
checker.hideCheckFrame();
}
}//GEN-LAST:event_detailsButtonActionPerformed
private void connectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectionButtonActionPerformed
// Enfoncé : on se connecte
if(connectionButton.isSelected()) {
connectionButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fr/valhalla/mailcheck/resources/images/connect.png")));
checker = new Checker(checker.getAccount(), checker.getKernel(), this);
checker.start();
} else { // Relâché : on se déconnecte
connectionButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fr/valhalla/mailcheck/resources/images/disconnect.png")));
setNextUpdate("-");
checker.stopChecker();
}
}//GEN-LAST:event_connectionButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel allMessagesLabel;
private javax.swing.JPanel buttonsPanel;
private javax.swing.JPanel centerPanel;
private javax.swing.JButton configButton;
private javax.swing.JToggleButton connectionButton;
private javax.swing.JToggleButton detailsButton;
private javax.swing.JLabel lastUpdateLabel;
private javax.swing.JPanel messagesPanel;
private javax.swing.JLabel newMessagesLabel;
private javax.swing.JLabel nextUpdateLabel;
private javax.swing.JLabel unreadMessagesLabel;
private javax.swing.JPanel updatePanel;
// End of variables declaration//GEN-END:variables
}