mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
SWT failover for Desktop.browse with Program.launch in AboutFrame
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@147 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
295682f621
commit
1176f7891b
@ -1,6 +1,6 @@
|
|||||||
package davmail;
|
package davmail;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import davmail.tray.DavGatewayTray;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -18,8 +18,6 @@ import java.net.URL;
|
|||||||
* About frame
|
* About frame
|
||||||
*/
|
*/
|
||||||
public class AboutFrame extends JFrame {
|
public class AboutFrame extends JFrame {
|
||||||
protected static final Logger LOGGER = Logger.getLogger(AboutFrame.class);
|
|
||||||
|
|
||||||
public AboutFrame() {
|
public AboutFrame() {
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
setTitle("About DavMail");
|
setTitle("About DavMail");
|
||||||
@ -34,7 +32,7 @@ public class AboutFrame extends JFrame {
|
|||||||
imagePanel.add(imageLabel);
|
imagePanel.add(imageLabel);
|
||||||
add("West", imagePanel);
|
add("West", imagePanel);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("Unable to create icon", e);
|
DavGatewayTray.error("Unable to create icon", e);
|
||||||
}
|
}
|
||||||
Package davmailPackage = this.getClass().getPackage();
|
Package davmailPackage = this.getClass().getPackage();
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
@ -62,11 +60,28 @@ public class AboutFrame extends JFrame {
|
|||||||
public void hyperlinkUpdate(HyperlinkEvent hle) {
|
public void hyperlinkUpdate(HyperlinkEvent hle) {
|
||||||
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
|
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
|
||||||
try {
|
try {
|
||||||
Desktop desktop = Desktop.getDesktop();
|
// trigger ClassNotFoundException
|
||||||
desktop.browse(hle.getURL().toURI());
|
ClassLoader classloader = AboutFrame.class.getClassLoader();
|
||||||
|
classloader.loadClass("java.awt.Desktop");
|
||||||
|
|
||||||
|
// Open link in default browser
|
||||||
|
AwtDesktopBrowser.browse(hle.getURL().toURI());
|
||||||
dispose();
|
dispose();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
DavGatewayTray.debug("Java 6 Desktop class not available");
|
||||||
|
// failover : try SWT
|
||||||
|
try {
|
||||||
|
// trigger ClassNotFoundException
|
||||||
|
ClassLoader classloader = AboutFrame.class.getClassLoader();
|
||||||
|
classloader.loadClass("org.eclipse.swt.program.Program");
|
||||||
|
SwtDesktopBrowser.browse(hle.getURL().toURI());
|
||||||
|
} catch (ClassNotFoundException e2) {
|
||||||
|
DavGatewayTray.error("Open link not supported (tried AWT Desktop and SWT Program");
|
||||||
|
} catch (Exception e2) {
|
||||||
|
DavGatewayTray.error("Unable to open link", e2);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Unable to open link", e);
|
DavGatewayTray.error("Unable to open link", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
src/java/davmail/AwtDesktopBrowser.java
Normal file
17
src/java/davmail/AwtDesktopBrowser.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package davmail;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper class to call Java6 Desktop class to launch default browser.
|
||||||
|
*/
|
||||||
|
public class AwtDesktopBrowser {
|
||||||
|
|
||||||
|
public static void browse(URI location) throws IOException {
|
||||||
|
Desktop desktop = Desktop.getDesktop();
|
||||||
|
desktop.browse(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/java/davmail/SwtDesktopBrowser.java
Normal file
16
src/java/davmail/SwtDesktopBrowser.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package davmail;
|
||||||
|
|
||||||
|
import org.eclipse.swt.program.Program;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper class to call SWT Program class to launch default browser.
|
||||||
|
*/
|
||||||
|
public class SwtDesktopBrowser {
|
||||||
|
public static void browse(URI location) throws IOException {
|
||||||
|
Program.launch(location.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -219,13 +219,13 @@ public class ExchangeSession {
|
|||||||
final String FORM_ACTION = "<FORM action=\"";
|
final String FORM_ACTION = "<FORM action=\"";
|
||||||
final String DESTINATION_INPUT = "name=\"destination\" value=\"";
|
final String DESTINATION_INPUT = "name=\"destination\" value=\"";
|
||||||
//noinspection StatementWithEmptyBody
|
//noinspection StatementWithEmptyBody
|
||||||
while ((line = loginFormReader.readLine()) != null && line.indexOf(FORM_ACTION) == -1) ;
|
while ((line = loginFormReader.readLine()) != null && line.indexOf(FORM_ACTION) == -1){}
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
int start = line.indexOf(FORM_ACTION) + FORM_ACTION.length();
|
int start = line.indexOf(FORM_ACTION) + FORM_ACTION.length();
|
||||||
int end = line.indexOf("\"", start);
|
int end = line.indexOf("\"", start);
|
||||||
logonMethodPath = line.substring(start, end);
|
logonMethodPath = line.substring(start, end);
|
||||||
//noinspection StatementWithEmptyBody
|
//noinspection StatementWithEmptyBody
|
||||||
while ((line = loginFormReader.readLine()) != null && line.indexOf(DESTINATION_INPUT) == -1) ;
|
while ((line = loginFormReader.readLine()) != null && line.indexOf(DESTINATION_INPUT) == -1) {}
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
start = line.indexOf(DESTINATION_INPUT) + DESTINATION_INPUT.length();
|
start = line.indexOf(DESTINATION_INPUT) + DESTINATION_INPUT.length();
|
||||||
end = line.indexOf("\"", start);
|
end = line.indexOf("\"", start);
|
||||||
@ -285,7 +285,7 @@ public class ExchangeSession {
|
|||||||
// find base url
|
// find base url
|
||||||
final String BASE_HREF = "<base href=\"";
|
final String BASE_HREF = "<base href=\"";
|
||||||
//noinspection StatementWithEmptyBody
|
//noinspection StatementWithEmptyBody
|
||||||
while ((line = mainPageReader.readLine()) != null && line.toLowerCase().indexOf(BASE_HREF) == -1) ;
|
while ((line = mainPageReader.readLine()) != null && line.toLowerCase().indexOf(BASE_HREF) == -1){}
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
int start = line.toLowerCase().indexOf(BASE_HREF) + BASE_HREF.length();
|
int start = line.toLowerCase().indexOf(BASE_HREF) + BASE_HREF.length();
|
||||||
int end = line.indexOf("\"", start);
|
int end = line.indexOf("\"", start);
|
||||||
@ -302,7 +302,7 @@ public class ExchangeSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mailPath == null) {
|
if (mailPath == null) {
|
||||||
throw new HttpException(destination + " not found in body, authentication failed");
|
throw new HttpException(destination + " not found in body, authentication failed: password expired ?");
|
||||||
}
|
}
|
||||||
|
|
||||||
// got base http mailbox http url
|
// got base http mailbox http url
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package davmail.tray;
|
package davmail.tray;
|
||||||
|
|
||||||
|
import davmail.AboutFrame;
|
||||||
import davmail.Settings;
|
import davmail.Settings;
|
||||||
import davmail.SettingsFrame;
|
import davmail.SettingsFrame;
|
||||||
import davmail.AboutFrame;
|
|
||||||
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.LF5Appender;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package davmail.tray;
|
package davmail.tray;
|
||||||
|
|
||||||
import davmail.Settings;
|
import davmail.Settings;
|
||||||
import org.apache.log4j.Priority;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.log4j.Priority;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package davmail.tray;
|
package davmail.tray;
|
||||||
|
|
||||||
|
import davmail.AboutFrame;
|
||||||
import davmail.Settings;
|
import davmail.Settings;
|
||||||
import davmail.SettingsFrame;
|
import davmail.SettingsFrame;
|
||||||
import davmail.AboutFrame;
|
|
||||||
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.LF5Appender;
|
||||||
@ -10,10 +10,15 @@ import org.apache.log4j.lf5.LogLevel;
|
|||||||
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
|
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.swt.widgets.*;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Event;
|
import org.eclipse.swt.widgets.Event;
|
||||||
|
import org.eclipse.swt.widgets.Listener;
|
||||||
import org.eclipse.swt.widgets.Menu;
|
import org.eclipse.swt.widgets.Menu;
|
||||||
import org.eclipse.swt.widgets.MenuItem;
|
import org.eclipse.swt.widgets.MenuItem;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.eclipse.swt.widgets.ToolTip;
|
||||||
|
import org.eclipse.swt.widgets.Tray;
|
||||||
|
import org.eclipse.swt.widgets.TrayItem;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user