1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-12 10:42:21 -05:00

Add swing log4j UI option

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@9 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2006-12-14 12:32:48 +00:00
parent a874175698
commit 7ddb77af7a
3 changed files with 71 additions and 43 deletions

View File

@ -2,11 +2,14 @@ package davmail;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.apache.log4j.lf5.LF5Appender;
import org.apache.log4j.lf5.LogLevel;
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
/**
@ -104,12 +107,10 @@ public class DavGatewayTray {
try {
if (SystemTray.isSupported()) {
// set native look and feel
try
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
catch (Exception e) {
// ignore
}
@ -124,7 +125,7 @@ public class DavGatewayTray {
// create a popup menu
PopupMenu popup = new PopupMenu();
final SettingsFrame settingsFrame = new SettingsFrame();
// create an action exitListener to listen for settings action executed on the tray icon
// create an action settingsListener to listen for settings action executed on the tray icon
ActionListener settingsListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
settingsFrame.setVisible(true);
@ -135,6 +136,25 @@ public class DavGatewayTray {
defaultItem.addActionListener(settingsListener);
popup.add(defaultItem);
MenuItem logItem = new MenuItem("Logs...");
logItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger rootLogger = Logger.getRootLogger();
LF5Appender lf5Appender = (LF5Appender) rootLogger.getAppender("LF5Appender");
if (lf5Appender == null) {
lf5Appender = new LF5Appender(new LogBrokerMonitor(LogLevel.getLog4JLevels()) {
protected void closeAfterConfirm() {
hide();
}
});
lf5Appender.setName("LF5Appender");
rootLogger.addAppender(lf5Appender);
}
lf5Appender.getLogBrokerMonitor().show();
}
});
popup.add(logItem);
// create an action exitListener to listen for exit action executed on the tray icon
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {

View File

@ -1,67 +1,76 @@
package davmail;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
/**
* DavMail settings frame
*/
public class SettingsFrame extends JFrame {
protected void addSettingComponent(JPanel panel, String label, Component component) {
JLabel fieldLabel = new JLabel(label);
fieldLabel.setHorizontalAlignment(SwingConstants.RIGHT);
panel.add(fieldLabel);
panel.add(component);
}
public SettingsFrame() {
setTitle("DavMail Settings");
JPanel panel = new JPanel(new GridLayout(3, 2));
panel.setBorder(BorderFactory.createTitledBorder("Gateway settings"));
final TextField urlField = new TextField("", 20);
final JTextField urlField = new JTextField("", 15);
final JTextField popPortField = new JTextField(4);
final JTextField smtpPortField = new JTextField(4);
Label urlLabel = new Label("OWA url:");
urlLabel.setAlignment(Label.RIGHT);
panel.add(urlLabel);
panel.add(urlField);
final TextField popPortField = new TextField(4);
Label popPortLabel = new Label("Local POP port:");
popPortLabel.setAlignment(Label.RIGHT);
panel.add(popPortLabel);
panel.add(popPortField);
final TextField smtpPortField = new TextField(4);
Label smtpPortLabel = new Label("Local SMTP port:");
smtpPortLabel.setAlignment(Label.RIGHT);
panel.add(smtpPortLabel);
panel.add(smtpPortField);
addSettingComponent(panel, "OWA url: ", urlField);
addSettingComponent(panel, "Local POP port: ", popPortField);
addSettingComponent(panel, "Local SMTP port: ", smtpPortField);
add("North", panel);
panel = new JPanel(new GridLayout(2, 2));
panel = new JPanel(new GridLayout(5, 2));
panel.setBorder(BorderFactory.createTitledBorder("Proxy settings"));
final TextField httpProxyField = new TextField(System.getProperty("http.proxyHost"), 20);
final JCheckBox enableProxyField = new JCheckBox();
final JTextField httpProxyField = new JTextField(System.getProperty("http.proxyHost"), 15);
final JTextField httpProxyPortField = new JTextField(System.getProperty("http.proxyPort"), 4);
final JTextField httpProxyUserField = new JTextField(System.getProperty("http.proxyUser"), 4);
final JTextField httpProxyPasswordField = new JPasswordField (System.getProperty("http.proxyPassword"), 4);
Label httpProxyLabel = new Label("Proxy server:");
httpProxyLabel.setAlignment(Label.RIGHT);
panel.add(httpProxyLabel);
panel.add(httpProxyField);
boolean enableProxy = enableProxyField.isSelected();
httpProxyField.setEnabled(enableProxy);
httpProxyPortField.setEnabled(enableProxy);
httpProxyUserField.setEnabled(enableProxy);
httpProxyPasswordField.setEnabled(enableProxy);
final TextField httpProxyPortField = new TextField(System.getProperty("http.proxyPort"), 4);
Label httpProxyPortLabel = new Label("Proxy port:");
httpProxyPortLabel.setAlignment(Label.RIGHT);
panel.add(httpProxyPortLabel);
panel.add(httpProxyPortField);
enableProxyField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
boolean enableProxy = enableProxyField.isSelected();
httpProxyField.setEnabled(enableProxy);
httpProxyPortField.setEnabled(enableProxy);
httpProxyUserField.setEnabled(enableProxy);
httpProxyPasswordField.setEnabled(enableProxy);
}
});
// TODO : add proxy user and password
addSettingComponent(panel, "Enable proxy: ", enableProxyField);
addSettingComponent(panel, "Proxy server: ", httpProxyField);
addSettingComponent(panel, "Proxy port: ", httpProxyPortField);
addSettingComponent(panel, "Proxy user: ", httpProxyUserField);
addSettingComponent(panel, "Proxy password: ", httpProxyPasswordField);
add("Center", panel);
panel = new JPanel();
Button cancel = new Button("Cancel");
Button ok = new Button("Save");
JButton cancel = new JButton("Cancel");
JButton ok = new JButton("Save");
ActionListener save = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// TODO : sava options
// TODO : save options
setVisible(false);
}
};

View File

@ -11,12 +11,11 @@ log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
#log4j.appender.FileAppender=org.apache.log4j.FileAppender
log4j.appender.FileAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FileAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.FileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.FileAppender.maxBackupIndex=4
# Path and name of log file
log4j.appender.FileAppender.File=davmail.log
# ConsoleAppender uses PatternLayout.
log4j.appender.FileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.FileAppender.layout.ConversionPattern=%d{ISO8601} - %m%n
log4j.appender.FileAppender.layout.ConversionPattern=%d{ISO8601} - %m%n