Author: nextgens
Date: 2008-03-12 03:59:50 +0000 (Wed, 12 Mar 2008)
New Revision: 18479
Added:
trunk/apps/thingamablog/src/freenet/
trunk/apps/thingamablog/src/freenet/utils/
trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
Modified:
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/JAboutBox.java
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/ViewerPane.java
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/WeblogPreviewer.java
Log:
Thingamablog: temporary fix to the browser-preview (I can't use it without it)
Added: trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
===================================================================
--- trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
(rev 0)
+++ trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
2008-03-12 03:59:50 UTC (rev 18479)
@@ -0,0 +1,52 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+
+package freenet.utils;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+
+/**
+ * A simple class to load an URL in a browser
+ *
+ * @author Florent Daignière <nextgens at freenetproject.org>
+ */
+public class BrowserLaunch {
+ public static void main(String arg[]) {
+ launch(arg[0]);
+ }
+
+ public static void launch(URL url) {
+ launch(url.toString());
+ }
+
+ public static void launch(String url) {
+ String osName = System.getProperty("os.name");
+ try {
+ if (osName.startsWith("Mac OS")) {
+ Class fileMgr =
Class.forName("com.apple.eio.FileManager");
+ Method openURL =
fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
+
+ openURL.invoke(null, new Object[] { url });
+ }
+ else if (osName.startsWith("Windows"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
+ else {
+ //assume Unix or Linux
+ String[] browsers = {"firefox", "opera",
"konqueror", "epiphany", "mozilla", "netscape", "seamonkey" };
+ String browser = null;
+
+ for (int count = 0; count < browsers.length &&
browser == null; count++)
+ if (Runtime.getRuntime().exec( new
String[] { "which", browsers[count]} ).waitFor() == 0)
+ browser = browsers[count];
+ if (browser == null)
+ throw new Exception("Could not find
web browser");
+ else
+ Runtime.getRuntime().exec(new String[]
{ browser, url});
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Unable to detect/startup your
browser... please go to " + url + " for futher instructions");
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/apps/thingamablog/src/net/sf/thingamablog/gui/JAboutBox.java
===================================================================
--- trunk/apps/thingamablog/src/net/sf/thingamablog/gui/JAboutBox.java
2008-03-12 02:55:38 UTC (rev 18478)
+++ trunk/apps/thingamablog/src/net/sf/thingamablog/gui/JAboutBox.java
2008-03-12 03:59:50 UTC (rev 18479)
@@ -20,6 +20,7 @@
package net.sf.thingamablog.gui;
+import freenet.utils.BrowserLaunch;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
@@ -421,15 +422,7 @@
}
public void mousePressed(MouseEvent e)
{
- try
- {
- //Browser.displayURL(url);
- Desktop.browse(new URL(url));
- }
- catch(Exception ex)
- {
- System.out.println("Can't open " + url);
//$NON-NLS-1$
- }
+ BrowserLaunch.launch(url);
}
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
Modified: trunk/apps/thingamablog/src/net/sf/thingamablog/gui/ViewerPane.java
===================================================================
--- trunk/apps/thingamablog/src/net/sf/thingamablog/gui/ViewerPane.java
2008-03-12 02:55:38 UTC (rev 18478)
+++ trunk/apps/thingamablog/src/net/sf/thingamablog/gui/ViewerPane.java
2008-03-12 03:59:50 UTC (rev 18479)
@@ -22,6 +22,7 @@
package net.sf.thingamablog.gui;
+import freenet.utils.BrowserLaunch;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
@@ -141,8 +142,7 @@
try
{
if(e.getEventType() ==
HyperlinkEvent.EventType.ACTIVATED)
-
//Browser.displayURL(e.getURL().toString());
- Desktop.browse(e.getURL());
+
BrowserLaunch.launch(e.getURL());
}
catch(Exception ex){}
}
Modified:
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java
===================================================================
---
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java
2008-03-12 02:55:38 UTC (rev 18478)
+++
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java
2008-03-12 03:59:50 UTC (rev 18479)
@@ -99,7 +99,6 @@
import net.sf.thingamablog.gui.editor.EntryEditor;
import net.sf.thingamablog.gui.editor.HTMLEditor;
import net.sf.thingamablog.gui.properties.TBFlogNodeWizardDialog;
-import net.sf.thingamablog.gui.properties.TBFlogWizardDialog;
import net.sf.thingamablog.gui.properties.TBWizardDialog;
import net.sf.thingamablog.gui.properties.WeblogPropertiesDialogFactory;
import net.sf.thingamablog.gui.table.JSortTable;
@@ -111,6 +110,7 @@
import org.jdesktop.jdic.desktop.Desktop;
import com.l2fprod.common.swing.JDirectoryChooser;
+import freenet.utils.BrowserLaunch;
@@ -3543,9 +3543,8 @@
TBWeblog tb = (TBWeblog) curSelWeblog;
if(tb.getType().equals("internet")){
try
- {
-
//Browser.displayURL(curSelWeblog.getFrontPageUrl());
- Desktop.browse(new URL(curSelWeblog.getFrontPageUrl()));
+ {
+
BrowserLaunch.launch(curSelWeblog.getFrontPageUrl());
}
catch(Exception ex)
{
@@ -3556,7 +3555,7 @@
try
{
String nodeHostname =
TBGlobals.getProperty("NODE_HOSTNAME");
- Desktop.browse(new URL("http://" +
nodeHostname + ":8888" + curSelWeblog.getFrontPageUrl()));
+ BrowserLaunch.launch("http://" +
nodeHostname + ":8888" + curSelWeblog.getFrontPageUrl());
}
catch(Exception ex)
{
@@ -3567,9 +3566,8 @@
}
}else{
try
- {
-
//Browser.displayURL(curSelWeblog.getFrontPageUrl());
- Desktop.browse(new URL(curSelWeblog.getFrontPageUrl()));
+ {
+
BrowserLaunch.launch(curSelWeblog.getFrontPageUrl());
}
catch(Exception ex)
{
@@ -4394,9 +4392,8 @@
public void actionPerformed(ActionEvent e)
{
try
- {
- //Browser.displayURL(TBGlobals.APP_URL);
- Desktop.browse(new URL(TBGlobals.APP_URL));
+ {
+ BrowserLaunch.launch(TBGlobals.APP_URL);
}
catch(Exception ex)
{
Modified:
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/WeblogPreviewer.java
===================================================================
---
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/WeblogPreviewer.java
2008-03-12 02:55:38 UTC (rev 18478)
+++
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/WeblogPreviewer.java
2008-03-12 03:59:50 UTC (rev 18479)
@@ -3,6 +3,7 @@
*/
package net.sf.thingamablog.gui.app;
+import freenet.utils.BrowserLaunch;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -21,10 +22,6 @@
import net.sf.thingamablog.blog.TemplatePack;
import net.sf.thingamablog.blog.WeblogBackend;
-import org.jdesktop.jdic.desktop.Desktop;
-
-
-
/**
* @author Bob Tantlinger
*
@@ -130,12 +127,7 @@
try
{
previewBlog.publishAll(new NullPublishProgress());
- if(previewBlog.getType().equals("internet")) {
- Desktop.browse(new URL(previewBlog.getFrontPageUrl()));
- } else {
- String nodeHostname = TBGlobals.getProperty("NODE_HOSTNAME");
- Desktop.browse(new URL("http://" + nodeHostname + ":8888/" +
previewBlog.getFrontPageUrl()));
- }
+ BrowserLaunch.launch(previewBlog.getFrontPageUrl());
}
catch(Exception ex)
{