1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -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.Logger;
import org.apache.log4j.Priority; 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 javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL; import java.net.URL;
/** /**
@ -104,12 +107,10 @@ public class DavGatewayTray {
try { try {
if (SystemTray.isSupported()) { if (SystemTray.isSupported()) {
// set native look and feel // set native look and feel
try try {
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} }
catch(Exception e) catch (Exception e) {
{
// ignore // ignore
} }
@ -124,7 +125,7 @@ public class DavGatewayTray {
// create a popup menu // create a popup menu
PopupMenu popup = new PopupMenu(); PopupMenu popup = new PopupMenu();
final SettingsFrame settingsFrame = new SettingsFrame(); 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() { ActionListener settingsListener = new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
settingsFrame.setVisible(true); settingsFrame.setVisible(true);
@ -135,6 +136,25 @@ public class DavGatewayTray {
defaultItem.addActionListener(settingsListener); defaultItem.addActionListener(settingsListener);
popup.add(defaultItem); 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 // create an action exitListener to listen for exit action executed on the tray icon
ActionListener exitListener = new ActionListener() { ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {

View File

@ -1,67 +1,76 @@
package davmail; package davmail;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.*;
/** /**
* DavMail settings frame * DavMail settings frame
*/ */
public class SettingsFrame extends JFrame { 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() { public SettingsFrame() {
setTitle("DavMail Settings"); setTitle("DavMail Settings");
JPanel panel = new JPanel(new GridLayout(3, 2)); JPanel panel = new JPanel(new GridLayout(3, 2));
panel.setBorder(BorderFactory.createTitledBorder("Gateway settings")); 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:"); addSettingComponent(panel, "OWA url: ", urlField);
urlLabel.setAlignment(Label.RIGHT); addSettingComponent(panel, "Local POP port: ", popPortField);
panel.add(urlLabel); addSettingComponent(panel, "Local SMTP port: ", smtpPortField);
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);
add("North", panel); add("North", panel);
panel = new JPanel(new GridLayout(2, 2)); panel = new JPanel(new GridLayout(5, 2));
panel.setBorder(BorderFactory.createTitledBorder("Proxy settings")); 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:"); boolean enableProxy = enableProxyField.isSelected();
httpProxyLabel.setAlignment(Label.RIGHT); httpProxyField.setEnabled(enableProxy);
panel.add(httpProxyLabel); httpProxyPortField.setEnabled(enableProxy);
panel.add(httpProxyField); httpProxyUserField.setEnabled(enableProxy);
httpProxyPasswordField.setEnabled(enableProxy);
final TextField httpProxyPortField = new TextField(System.getProperty("http.proxyPort"), 4); enableProxyField.addActionListener(new ActionListener() {
Label httpProxyPortLabel = new Label("Proxy port:"); public void actionPerformed(ActionEvent evt) {
httpProxyPortLabel.setAlignment(Label.RIGHT); boolean enableProxy = enableProxyField.isSelected();
panel.add(httpProxyPortLabel); httpProxyField.setEnabled(enableProxy);
panel.add(httpProxyPortField); 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); add("Center", panel);
panel = new JPanel(); panel = new JPanel();
Button cancel = new Button("Cancel"); JButton cancel = new JButton("Cancel");
Button ok = new Button("Save"); JButton ok = new JButton("Save");
ActionListener save = new ActionListener() { ActionListener save = new ActionListener() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
// TODO : sava options // TODO : save options
setVisible(false); setVisible(false);
} }
}; };

View File

@ -11,9 +11,8 @@ log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 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.RollingFileAppender
log4j.appender.FileAppender=org.apache.log4j.DailyRollingFileAppender log4j.appender.FileAppender.maxBackupIndex=4
log4j.appender.FileAppender.DatePattern='.'yyyy-MM-dd
# Path and name of log file # Path and name of log file
log4j.appender.FileAppender.File=davmail.log log4j.appender.FileAppender.File=davmail.log