diff --git a/build.xml b/build.xml index 325ffe2d..21d93b89 100644 --- a/build.xml +++ b/build.xml @@ -38,7 +38,15 @@ - + + +
+ + + +
+
+
diff --git a/src/java/davmail/AboutFrame.java b/src/java/davmail/AboutFrame.java new file mode 100644 index 00000000..16baa864 --- /dev/null +++ b/src/java/davmail/AboutFrame.java @@ -0,0 +1,102 @@ +package davmail; + +import org.apache.log4j.Logger; + +import javax.imageio.ImageIO; +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.StyleSheet; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.net.URL; + +/** + * About frame + */ +public class AboutFrame extends JFrame { + protected static final Logger LOGGER = Logger.getLogger(AboutFrame.class); + + public AboutFrame() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setTitle("About DavMail"); + try { + JLabel imageLabel = new JLabel(); + ClassLoader classloader = this.getClass().getClassLoader(); + URL imageUrl = classloader.getResource("tray32.png"); + Image iconImage = ImageIO.read(imageUrl); + ImageIcon icon = new ImageIcon(iconImage); + imageLabel.setIcon(icon); + JPanel imagePanel = new JPanel(); + imagePanel.add(imageLabel); + add("West", imagePanel); + } catch (IOException e) { + LOGGER.error("Unable to create icon", e); + } + Package davmailPackage = this.getClass().getPackage(); + StringBuilder buffer = new StringBuilder(); + buffer.append("DavMail Gateway
"); + String version = davmailPackage.getImplementationVersion(); + if (version != null) { + buffer.append("Version ").append(version).append("
"); + } + buffer.append("By Mickaël Guessant
" + + "
" + + "Help and setup instructions available at:
" + + "http://davmail.sourceforge.net
" + + "
" + + "To send comments or report bugs,
use " + + "DavMail Sourceforge trackers
" + + "or contact me at mguessan@free.fr" + + ""); + JEditorPane jEditorPane = new JEditorPane("text/html", buffer.toString()); + StyleSheet stylesheet = ((HTMLEditorKit) jEditorPane.getEditorKit()).getStyleSheet(); + stylesheet.addRule("body { font-size:small;font-family: " + jEditorPane.getFont().getFamily() + "}"); + + jEditorPane.setEditable(false); + jEditorPane.setOpaque(false); + jEditorPane.addHyperlinkListener(new HyperlinkListener() { + public void hyperlinkUpdate(HyperlinkEvent hle) { + if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { + try { + Desktop desktop = Desktop.getDesktop(); + desktop.browse(hle.getURL().toURI()); + dispose(); + } catch (Exception e) { + LOGGER.error("Unable to open link", e); + } + } + } + }); + + + JPanel mainPanel = new JPanel(); + mainPanel.add(jEditorPane); + add("Center", mainPanel); + + JPanel buttonPanel = new JPanel(); + JButton ok = new JButton("OK"); + ActionListener close = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + dispose(); + } + }; + ok.addActionListener(close); + + buttonPanel.add(ok); + + add("South", buttonPanel); + + pack(); + setResizable(false); + // center frame + setLocation(getToolkit().getScreenSize().width / 2 - + getSize().width / 2, + getToolkit().getScreenSize().height / 2 - + getSize().height / 2); + } + +} diff --git a/src/java/davmail/SettingsFrame.java b/src/java/davmail/SettingsFrame.java index a156868d..388d9cef 100644 --- a/src/java/davmail/SettingsFrame.java +++ b/src/java/davmail/SettingsFrame.java @@ -17,6 +17,7 @@ public class SettingsFrame extends JFrame { } public SettingsFrame() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setTitle("DavMail Settings"); JTabbedPane tabbedPane = new JTabbedPane(); @@ -78,6 +79,7 @@ public class SettingsFrame extends JFrame { tabbedPane.add("Main", mainPanel); JPanel advancedPanel = new JPanel(); + advancedPanel.setLayout(new BorderLayout()); JPanel networkSettingsPanel = new JPanel(new GridLayout(2, 2)); networkSettingsPanel.setBorder(BorderFactory.createTitledBorder("Network settings")); @@ -92,8 +94,8 @@ public class SettingsFrame extends JFrame { addSettingComponent(networkSettingsPanel, "Bind address: ", bindAddressField); addSettingComponent(networkSettingsPanel, "Allow Remote Connections: ", allowRemoteField); - advancedPanel.add(networkSettingsPanel); - + advancedPanel.add("North", networkSettingsPanel); + tabbedPane.add("Advanced", advancedPanel); add("Center", tabbedPane); @@ -116,7 +118,7 @@ public class SettingsFrame extends JFrame { Settings.setProperty("davmail.proxyUser", httpProxyUserField.getText()); Settings.setProperty("davmail.proxyPassword", httpProxyPasswordField.getText()); Settings.save(); - setVisible(false); + dispose(); // restart listeners with new config DavGateway.start(); } @@ -142,7 +144,7 @@ public class SettingsFrame extends JFrame { httpProxyPortField.setText(Settings.getProperty("davmail.proxyPort")); httpProxyUserField.setText(Settings.getProperty("davmail.proxyUser")); httpProxyPasswordField.setText(Settings.getProperty("davmail.proxyPassword")); - setVisible(false); + dispose(); } }); diff --git a/src/java/davmail/tray/AwtGatewayTray.java b/src/java/davmail/tray/AwtGatewayTray.java index afab3fe8..1a2385e3 100644 --- a/src/java/davmail/tray/AwtGatewayTray.java +++ b/src/java/davmail/tray/AwtGatewayTray.java @@ -2,6 +2,7 @@ package davmail.tray; import davmail.Settings; import davmail.SettingsFrame; +import davmail.AboutFrame; import org.apache.log4j.Logger; import org.apache.log4j.Priority; import org.apache.log4j.lf5.LF5Appender; @@ -82,6 +83,20 @@ public class AwtGatewayTray implements DavGatewayTrayInterface { image2 = Toolkit.getDefaultToolkit().getImage(imageUrl2); // create a popup menu PopupMenu popup = new PopupMenu(); + + final AboutFrame aboutFrame = new AboutFrame(); + aboutFrame.setIconImage(image); + // create an action settingsListener to listen for settings action executed on the tray icon + ActionListener aboutListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + aboutFrame.setVisible(true); + } + }; + // create menu item for the default action + MenuItem aboutItem = new MenuItem("About..."); + aboutItem.addActionListener(aboutListener); + popup.add(aboutItem); + final SettingsFrame settingsFrame = new SettingsFrame(); settingsFrame.setIconImage(image); // create an action settingsListener to listen for settings action executed on the tray icon diff --git a/src/java/davmail/tray/SwtGatewayTray.java b/src/java/davmail/tray/SwtGatewayTray.java index a99a79d9..39ff9db1 100644 --- a/src/java/davmail/tray/SwtGatewayTray.java +++ b/src/java/davmail/tray/SwtGatewayTray.java @@ -2,6 +2,7 @@ package davmail.tray; import davmail.Settings; import davmail.SettingsFrame; +import davmail.AboutFrame; import org.apache.log4j.Logger; import org.apache.log4j.Priority; import org.apache.log4j.lf5.LF5Appender; @@ -145,6 +146,23 @@ public class SwtGatewayTray implements DavGatewayTrayInterface { } }); + MenuItem aboutItem = new MenuItem(popup, SWT.PUSH); + aboutItem.setText("About..."); + final AboutFrame aboutFrame = new AboutFrame(); + if (awtImage != null) { + aboutFrame.setIconImage(awtImage); + } + aboutItem.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + display.asyncExec( + new Runnable() { + public void run() { + aboutFrame.setVisible(true); + } + }); + } + }); + final SettingsFrame settingsFrame = new SettingsFrame(); if (awtImage != null) { settingsFrame.setIconImage(awtImage); @@ -205,10 +223,12 @@ public class SwtGatewayTray implements DavGatewayTrayInterface { public void handleEvent(Event event) { shell.dispose(); - if (image != null) + if (image != null) { image.dispose(); - if (image2 != null) + } + if (image2 != null) { image2.dispose(); + } display.dispose(); //noinspection CallToSystemExit @@ -222,14 +242,17 @@ public class SwtGatewayTray implements DavGatewayTrayInterface { } while (!shell.isDisposed()) { - if (!display.readAndDispatch()) + if (!display.readAndDispatch()) { display.sleep(); + } } - if (image != null) + if (image != null) { image.dispose(); - if (image2 != null) + } + if (image2 != null) { image2.dispose(); + } display.dispose(); } }