mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
Initial settings panel implementation
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@8 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
bf37056509
commit
a874175698
@ -3,6 +3,7 @@ package davmail;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Priority;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
@ -60,7 +61,7 @@ public class DavGatewayTray {
|
||||
if (messageType != null) {
|
||||
trayIcon.displayMessage("DavMail gateway", message, messageType);
|
||||
}
|
||||
trayIcon.setToolTip("DavMail gateway \n"+message);
|
||||
trayIcon.setToolTip("DavMail gateway \n" + message);
|
||||
}
|
||||
logger.log(priority, message);
|
||||
}
|
||||
@ -102,6 +103,16 @@ public class DavGatewayTray {
|
||||
public static void init() {
|
||||
try {
|
||||
if (SystemTray.isSupported()) {
|
||||
// set native look and feel
|
||||
try
|
||||
{
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
// get the SystemTray instance
|
||||
SystemTray tray = SystemTray.getSystemTray();
|
||||
// load an image
|
||||
@ -110,24 +121,37 @@ public class DavGatewayTray {
|
||||
image = Toolkit.getDefaultToolkit().getImage(imageUrl);
|
||||
URL imageUrl2 = classloader.getResource("tray2.png");
|
||||
image2 = Toolkit.getDefaultToolkit().getImage(imageUrl2);
|
||||
// create a action listener to listen for default action executed on the tray icon
|
||||
ActionListener listener = new ActionListener() {
|
||||
// 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
|
||||
ActionListener settingsListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
settingsFrame.setVisible(true);
|
||||
}
|
||||
};
|
||||
// create menu item for the default action
|
||||
MenuItem defaultItem = new MenuItem("Settings...");
|
||||
defaultItem.addActionListener(settingsListener);
|
||||
popup.add(defaultItem);
|
||||
|
||||
// create an action exitListener to listen for exit action executed on the tray icon
|
||||
ActionListener exitListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SystemTray.getSystemTray().remove(trayIcon);
|
||||
System.exit(0);
|
||||
}
|
||||
};
|
||||
// create a popup menu
|
||||
PopupMenu popup = new PopupMenu();
|
||||
// create menu item for the default action
|
||||
MenuItem defaultItem = new MenuItem("Exit");
|
||||
defaultItem.addActionListener(listener);
|
||||
popup.add(defaultItem);
|
||||
// create menu item for the exit action
|
||||
MenuItem exitItem = new MenuItem("Exit");
|
||||
exitItem.addActionListener(exitListener);
|
||||
popup.add(exitItem);
|
||||
|
||||
/// ... add other items
|
||||
// construct a TrayIcon
|
||||
trayIcon = new TrayIcon(image, "DavMail Gateway", popup);
|
||||
// set the TrayIcon properties
|
||||
trayIcon.addActionListener(listener);
|
||||
trayIcon.addActionListener(settingsListener);
|
||||
// ...
|
||||
// add the tray image
|
||||
try {
|
||||
|
90
src/java/davmail/SettingsFrame.java
Normal file
90
src/java/davmail/SettingsFrame.java
Normal file
@ -0,0 +1,90 @@
|
||||
package davmail;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
/**
|
||||
* DavMail settings frame
|
||||
*/
|
||||
public class SettingsFrame extends JFrame {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
add("North", panel);
|
||||
|
||||
panel = new JPanel(new GridLayout(2, 2));
|
||||
panel.setBorder(BorderFactory.createTitledBorder("Proxy settings"));
|
||||
|
||||
final TextField httpProxyField = new TextField(System.getProperty("http.proxyHost"), 20);
|
||||
|
||||
Label httpProxyLabel = new Label("Proxy server:");
|
||||
httpProxyLabel.setAlignment(Label.RIGHT);
|
||||
panel.add(httpProxyLabel);
|
||||
panel.add(httpProxyField);
|
||||
|
||||
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);
|
||||
|
||||
// TODO : add proxy user and password
|
||||
|
||||
add("Center", panel);
|
||||
|
||||
panel = new JPanel();
|
||||
Button cancel = new Button("Cancel");
|
||||
Button ok = new Button("Save");
|
||||
ActionListener save = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
// TODO : sava options
|
||||
setVisible(false);
|
||||
}
|
||||
};
|
||||
ok.addActionListener(save);
|
||||
|
||||
cancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
panel.add(ok);
|
||||
panel.add(cancel);
|
||||
|
||||
add("South", panel);
|
||||
|
||||
pack();
|
||||
setResizable(false);
|
||||
// center frame
|
||||
setLocation(getToolkit().getScreenSize().width / 2 -
|
||||
getSize().width / 2,
|
||||
getToolkit().getScreenSize().height / 2 -
|
||||
getSize().height / 2);
|
||||
urlField.requestFocus();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user