mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-05 18:58:02 -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.Logger;
|
||||||
import org.apache.log4j.Priority;
|
import org.apache.log4j.Priority;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -102,6 +103,16 @@ public class DavGatewayTray {
|
|||||||
public static void init() {
|
public static void init() {
|
||||||
try {
|
try {
|
||||||
if (SystemTray.isSupported()) {
|
if (SystemTray.isSupported()) {
|
||||||
|
// set native look and feel
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
// get the SystemTray instance
|
// get the SystemTray instance
|
||||||
SystemTray tray = SystemTray.getSystemTray();
|
SystemTray tray = SystemTray.getSystemTray();
|
||||||
// load an image
|
// load an image
|
||||||
@ -110,24 +121,37 @@ public class DavGatewayTray {
|
|||||||
image = Toolkit.getDefaultToolkit().getImage(imageUrl);
|
image = Toolkit.getDefaultToolkit().getImage(imageUrl);
|
||||||
URL imageUrl2 = classloader.getResource("tray2.png");
|
URL imageUrl2 = classloader.getResource("tray2.png");
|
||||||
image2 = Toolkit.getDefaultToolkit().getImage(imageUrl2);
|
image2 = Toolkit.getDefaultToolkit().getImage(imageUrl2);
|
||||||
// create a action listener to listen for default action executed on the tray icon
|
// create a popup menu
|
||||||
ActionListener listener = new ActionListener() {
|
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) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
SystemTray.getSystemTray().remove(trayIcon);
|
SystemTray.getSystemTray().remove(trayIcon);
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// create a popup menu
|
// create menu item for the exit action
|
||||||
PopupMenu popup = new PopupMenu();
|
MenuItem exitItem = new MenuItem("Exit");
|
||||||
// create menu item for the default action
|
exitItem.addActionListener(exitListener);
|
||||||
MenuItem defaultItem = new MenuItem("Exit");
|
popup.add(exitItem);
|
||||||
defaultItem.addActionListener(listener);
|
|
||||||
popup.add(defaultItem);
|
|
||||||
/// ... add other items
|
/// ... add other items
|
||||||
// construct a TrayIcon
|
// construct a TrayIcon
|
||||||
trayIcon = new TrayIcon(image, "DavMail Gateway", popup);
|
trayIcon = new TrayIcon(image, "DavMail Gateway", popup);
|
||||||
// set the TrayIcon properties
|
// set the TrayIcon properties
|
||||||
trayIcon.addActionListener(listener);
|
trayIcon.addActionListener(settingsListener);
|
||||||
// ...
|
// ...
|
||||||
// add the tray image
|
// add the tray image
|
||||||
try {
|
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