move from native code to java 6

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@10975 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Michael Will
2009-03-13 19:08:06 +00:00
committed by michael.will
parent 0bd3593153
commit 680062be00
18 changed files with 307 additions and 924 deletions

View File

@ -10,29 +10,6 @@
package org.jivesoftware;
import org.jivesoftware.resource.Default;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatFrame;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.SwingTimerTask;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.TaskEngine;
import org.jivesoftware.spark.util.URLFileSystem;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.alerts.InputTextAreaDialog;
import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettings;
import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettingsManager;
import org.jivesoftware.sparkimpl.settings.JiveInfo;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import org.jivesoftware.sparkimpl.updater.CheckUpdates;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
@ -61,6 +38,29 @@ import javax.swing.JSplitPane;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import org.jivesoftware.resource.Default;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatFrame;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.SwingTimerTask;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.TaskEngine;
import org.jivesoftware.spark.util.URLFileSystem;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.alerts.InputTextAreaDialog;
import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettings;
import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettingsManager;
import org.jivesoftware.sparkimpl.settings.JiveInfo;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import org.jivesoftware.sparkimpl.updater.CheckUpdates;
/**
* The <code>MainWindow</code> class acts as both the DockableHolder and the proxy
* to the Workspace in Spark.
@ -68,6 +68,8 @@ import javax.swing.JToolBar;
* @version 1.0, 03/12/14
*/
public final class MainWindow extends ChatFrame implements ActionListener {
private static final long serialVersionUID = -6062104959613603510L;
private final Set<MainWindowListener> listeners = new HashSet<MainWindowListener>();
private final JMenu connectMenu = new JMenu();
@ -324,10 +326,12 @@ public final class MainWindow extends ChatFrame implements ActionListener {
command = starterExe + " \"" + sparkExe + "\"";
}
else if (Spark.isLinux()) {
command = Spark.getBinDirectory().getParentFile().getCanonicalPath() + File.separator + "spark";
}
else if (Spark.isMac()) {
command = "open -a Spark";
}
Runtime.getRuntime().exec(command);
}
catch (IOException e) {
@ -396,6 +400,8 @@ public final class MainWindow extends ChatFrame implements ActionListener {
Action updateAction = new AbstractAction() {
private static final long serialVersionUID = -2159350387773310325L;
public void actionPerformed(ActionEvent actionEvent) {
checkForUpdates(true);
}
@ -406,6 +412,8 @@ public final class MainWindow extends ChatFrame implements ActionListener {
// Add Error Dialog Viewer
Action viewErrors = new AbstractAction() {
private static final long serialVersionUID = -420926784631340112L;
public void actionPerformed(ActionEvent e) {
File logDir = new File(Spark.getLogDirectory(), "errors.log");
if (!logDir.exists()) {
@ -420,11 +428,13 @@ public final class MainWindow extends ChatFrame implements ActionListener {
viewErrors.putValue(Action.NAME, Res.getString("menuitem.view.logs"));
final Action viewHelpGuideAction = new AbstractAction() {
private static final long serialVersionUID = 2680369963282231348L;
public void actionPerformed(ActionEvent actionEvent) {
try {
BrowserLauncher.openURL("http://www.igniterealtime.org/builds/spark/docs/spark_user_guide.pdf");
}
catch (IOException e) {
catch (Exception e) {
Log.error("Unable to load online help.", e);
}
}
@ -453,12 +463,16 @@ public final class MainWindow extends ChatFrame implements ActionListener {
// Register shutdown with the exit menu.
exitMenuItem.addActionListener(new AbstractAction() {
private static final long serialVersionUID = -2301236575241532698L;
public void actionPerformed(ActionEvent e) {
shutdown();
}
});
helpMenuItem.addActionListener(new AbstractAction() {
private static final long serialVersionUID = -1423433460333010339L;
public void actionPerformed(ActionEvent e) {
try {
BrowserLauncher.openURL("http://www.igniterealtime.org/forum/forum.jspa?forumID=49");
@ -471,6 +485,8 @@ public final class MainWindow extends ChatFrame implements ActionListener {
// Show About Box
menuAbout.addActionListener(new AbstractAction() {
private static final long serialVersionUID = -7173666373051354502L;
public void actionPerformed(ActionEvent e) {
showAboutBox();
}

View File

@ -46,10 +46,13 @@ public class Restarter {
try {
String command = "";
if (Spark.isWindows()) {
if (isWindows()) {
command = file.getCanonicalPath();
}
else if (Spark.isMac()) {
if (isLinux()) {
command = file.getCanonicalPath();
}
else if (isMac()) {
command = "open -a Spark";
}
@ -61,6 +64,46 @@ public class Restarter {
}
/**
* Return if we are running on windows.
*
* @return true if we are running on windows, false otherwise.
*/
public static boolean isWindows() {
final String osName = System.getProperty("os.name").toLowerCase();
return osName.startsWith("windows");
}
/**
* Returns true if Spark is running on vista.
*
* @return true if running on Vista.
*/
public static boolean isVista() {
final String osName = System.getProperty("os.name").toLowerCase();
return osName.contains("vista");
}
/**
* Return if we are running on a mac.
*
* @return true if we are running on a mac, false otherwise.
*/
public static boolean isMac() {
String lcOSName = System.getProperty("os.name").toLowerCase();
return lcOSName.indexOf("mac") != -1;
}
/**
* Return if we are running on Linux.
*
* @return true if we are running on Linux, false otherwise.
*/
public static boolean isLinux() {
final String osName = System.getProperty("os.name").toLowerCase();
return osName.startsWith("linux");
}
}

View File

@ -11,7 +11,6 @@
package org.jivesoftware.spark;
import java.awt.Window;
import java.io.File;
/**
* Implementations of this interface define native mechanisms based on the Operating System
@ -48,31 +47,4 @@ public interface NativeHandler {
* @return true to handle.
*/
boolean handleNotification();
/**
* Open File using native operation.
*
* @param file the name of the file.
* @return true if the file was executed.
*/
boolean openFile(File file);
/**
* Launches email client.
*
* @param to who the message should go to.
* @param subject the subject.
* @return true if the email client was launched.
*/
boolean launchEmailClient(String to, String subject);
/**
* Launches browser with specified url string.
*
* @param url the url string.
* @return true if the browser was launched.
*/
boolean launchBrowser(String url);
}

View File

@ -18,6 +18,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.SwingUtilities;
/**
* The AlertManager handles the delegation of Alerting based.
*
@ -101,46 +103,4 @@ public class NativeManager {
}
}
public boolean openFile(File file) {
final Iterator alertNotifiers = ModelUtil.reverseListIterator(nativeHandlers.listIterator());
while (alertNotifiers.hasNext()) {
final NativeHandler alert = (NativeHandler)alertNotifiers.next();
boolean handle = alert.handleNotification();
if (handle) {
boolean couldOpenFile = alert.openFile(file);
return couldOpenFile;
}
}
return false;
}
public boolean launchBrowser(String url) {
final Iterator alertNotifiers = ModelUtil.reverseListIterator(nativeHandlers.listIterator());
while (alertNotifiers.hasNext()) {
final NativeHandler alert = (NativeHandler)alertNotifiers.next();
boolean handle = alert.handleNotification();
if (handle) {
alert.launchBrowser(url);
return true;
}
}
return false;
}
public boolean launchEmailClient(String to, String subject) {
final Iterator alertNotifiers = ModelUtil.reverseListIterator(nativeHandlers.listIterator());
while (alertNotifiers.hasNext()) {
final NativeHandler alert = (NativeHandler)alertNotifiers.next();
boolean handle = alert.handleNotification();
if (handle) {
alert.launchEmailClient(to, subject);
return true;
}
}
return false;
}
}

View File

@ -10,16 +10,15 @@
package org.jivesoftware.spark.component;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import javax.swing.JLabel;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.log.Log;
/**
* The <code>LinkLabel</code> class is a JLabel subclass
@ -30,6 +29,7 @@ import java.io.IOException;
*/
final public class LinkLabel extends JLabel implements MouseListener {
private static final long serialVersionUID = 454820993140807217L;
// cursors used in url-link related displays and default display
private Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR);
@ -75,7 +75,7 @@ final public class LinkLabel extends JLabel implements MouseListener {
try {
BrowserLauncher.openURL(labelURL);
}
catch (IOException e) {
catch (Exception e) {
Log.error(e);
}
}

View File

@ -56,6 +56,7 @@ import java.awt.AWTException;
import java.awt.Component;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.GraphicsDevice;
@ -178,7 +179,11 @@ public class SparkTransferManager {
actionsMenu.add(downloadsMenu);
downloadsMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Downloads downloads = Downloads.getInstance();
try {
Desktop.getDesktop().browse(Downloads.getDownloadDirectory().toURI());
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
@ -202,13 +207,13 @@ public class SparkTransferManager {
contactList.addFileDropListener(new FileDropListener() {
public void filesDropped(Collection files, Component component) {
public void filesDropped(Collection<File> files, Component component) {
if (component instanceof ContactItem) {
ContactItem item = (ContactItem)component;
ChatRoom chatRoom = null;
for (Object file : files) {
chatRoom = sendFile((File) file, item.getJID());
for (File file : files) {
chatRoom = sendFile(file, item.getJID());
}
if (chatRoom != null) {
@ -232,7 +237,11 @@ public class SparkTransferManager {
commandPanel.add(viewDownloads);
viewDownloads.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Downloads downloads = Downloads.getInstance();
try {
Desktop.getDesktop().browse(Downloads.getDownloadDirectory().toURI());
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
@ -465,10 +474,10 @@ public class SparkTransferManager {
ArrayList<File> list = waitMap.get(bareJID);
if (list != null) {
// Iterate through list and send.
Iterator iter = list.iterator();
Iterator<File> iter = list.iterator();
ChatRoom room = null;
while (iter.hasNext()) {
File file = (File)iter.next();
File file = iter.next();
room = sendFile(file, bareJID);
}

View File

@ -10,16 +10,17 @@
package org.jivesoftware.spark.ui;
import org.jivesoftware.Spark;
import org.jivesoftware.resource.Res;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.plugin.ContextMenuListener;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonManager;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import javax.swing.AbstractAction;
import javax.swing.Icon;
@ -37,17 +38,15 @@ import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.jivesoftware.resource.Res;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.plugin.ContextMenuListener;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonManager;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
/**
* The ChatArea class handles proper chat text formatting such as url handling. Use ChatArea for proper
@ -434,14 +433,9 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
final String url = (String)o;
boolean handled = fireLinkInterceptors(e, url);
if (!handled) {
if (Spark.isWindows()) {
SparkManager.getNativeManager().launchBrowser(url);
}
else {
BrowserLauncher.openURL(url);
}
}
}
catch (Exception ioe) {
Log.error("Error launching browser:", ioe);
}

View File

@ -11,6 +11,7 @@
package org.jivesoftware.spark.ui;
import java.awt.Component;
import java.io.File;
import java.util.Collection;
/**
@ -28,6 +29,6 @@ public interface FileDropListener {
* @param files the Collection of Files.
* @param component the Component the files were dropped on.
*/
void filesDropped(Collection files, Component component);
void filesDropped(Collection<File> files, Component component);
}

View File

@ -10,6 +10,26 @@
package org.jivesoftware.spark.ui;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.spark.SparkManager;
@ -18,22 +38,6 @@ import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.log.Log;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* UI to display VCard Information in Wizards, Dialogs, Chat Rooms and any other container.
*
@ -41,6 +45,7 @@ import javax.swing.JPanel;
*/
public class VCardPanel extends JPanel {
private static final long serialVersionUID = -5810110243694315630L;
private Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR);
@ -185,7 +190,15 @@ public class VCardPanel extends JPanel {
}
private void startEmailClient(String emailAddress) {
SparkManager.getNativeManager().launchEmailClient(emailAddress, "");
try {
Desktop.getDesktop().mail(new URI("mailto:" + emailAddress));
} catch (IOException e) {
Log.error("Can't open Mailer", e);
} catch (URISyntaxException e) {
Log.error("URI Wrong", e);
}
}

View File

@ -21,6 +21,7 @@ import org.jivesoftware.spark.util.log.Log;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@ -28,6 +29,9 @@ import java.awt.Image;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.BorderFactory;
import javax.swing.Icon;
@ -42,6 +46,7 @@ import javax.swing.JPanel;
*/
public class VCardViewer extends JPanel {
private static final long serialVersionUID = -5642099937626355102L;
private Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR);
@ -249,7 +254,13 @@ public class VCardViewer extends JPanel {
private void startEmailClient(String emailAddress) {
SparkManager.getNativeManager().launchEmailClient(emailAddress, "");
try {
Desktop.getDesktop().mail(new URI("mailto:" + emailAddress));
} catch (IOException e) {
Log.error("Can't open Mailer", e);
} catch (URISyntaxException e) {
Log.error("URI Wrong", e);
}
}

View File

@ -132,6 +132,8 @@ public final class InputTextAreaDialog implements PropertyChangeListener {
* Move to focus forward action.
*/
public Action nextFocusAction = new AbstractAction("Move Focus Forwards") {
private static final long serialVersionUID = 1238373124060258519L;
public void actionPerformed(ActionEvent evt) {
((Component)evt.getSource()).transferFocus();
}
@ -141,6 +143,8 @@ public final class InputTextAreaDialog implements PropertyChangeListener {
* Moves the focus backwards in the dialog.
*/
public Action prevFocusAction = new AbstractAction("Move Focus Backwards") {
private static final long serialVersionUID = 7927553016576134725L;
public void actionPerformed(ActionEvent evt) {
((Component)evt.getSource()).transferFocusBackward();
}
@ -148,11 +152,11 @@ public final class InputTextAreaDialog implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) {
String value = (String)optionPane.getValue();
if ("Cancel".equals(value)) {
if (Res.getString("cancel").equals(value)) {
stringValue = null;
dialog.setVisible(false);
}
else if ("Ok".equals(value)) {
else if (Res.getString("ok").equals(value)) {
stringValue = textArea.getText();
if (stringValue.trim().length() == 0) {
stringValue = null;

View File

@ -10,6 +10,19 @@
package org.jivesoftware.sparkimpl.plugin.bookmarks;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smackx.bookmark.BookmarkedConference;
import org.jivesoftware.smackx.bookmark.BookmarkedURL;
@ -18,25 +31,12 @@ import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.io.IOException;
/**
*
*/
public class BookmarkItem extends JPanel {
private static final long serialVersionUID = -3120765894005887305L;
private JLabel imageLabel;
private JLabel nameLabel;
private JLabel descriptionLabel;
@ -70,11 +70,13 @@ public class BookmarkItem extends JPanel {
descriptionLabel.setText(bookmark.getURL());
action = new AbstractAction() {
private static final long serialVersionUID = 6986851628853679682L;
public void actionPerformed(ActionEvent e) {
try {
BrowserLauncher.openURL(bookmark.getURL());
}
catch (IOException e1) {
catch (Exception e1) {
Log.error(e1);
}
}
@ -86,6 +88,8 @@ public class BookmarkItem extends JPanel {
nameLabel.setText(bookmark.getName());
descriptionLabel.setText(bookmark.getJid());
action = new AbstractAction() {
private static final long serialVersionUID = 4324785627112595384L;
public void actionPerformed(ActionEvent e) {
SwingWorker worker = new SwingWorker() {
public Object construct() {

View File

@ -10,6 +10,14 @@
package org.jivesoftware.sparkimpl.plugin.bookmarks;
import java.awt.event.ActionEvent;
import java.util.Collection;
import java.util.TimerTask;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenu;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPException;
@ -26,15 +34,6 @@ import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.TaskEngine;
import org.jivesoftware.spark.util.log.Log;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.Collection;
import java.util.TimerTask;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenu;
/**
* Allows for adding and removal of Bookmarks within Spark.
*/
@ -76,11 +75,13 @@ public class BookmarkPlugin implements Plugin {
final BookmarkedURL link = (BookmarkedURL) bookmarkedLink;
Action urlAction = new AbstractAction() {
private static final long serialVersionUID = 4246574779205966917L;
public void actionPerformed(ActionEvent actionEvent) {
try {
BrowserLauncher.openURL(link.getURL());
}
catch (IOException e) {
catch (Exception e) {
Log.error(e);
}
}
@ -96,6 +97,8 @@ public class BookmarkPlugin implements Plugin {
final BookmarkedConference conferences = (BookmarkedConference) bookmarkedConference;
Action conferenceAction = new AbstractAction() {
private static final long serialVersionUID = 5964584172262968704L;
public void actionPerformed(ActionEvent actionEvent) {
final TimerTask task = new SwingTimerTask() {
public void doRun() {

View File

@ -10,292 +10,29 @@
package org.jivesoftware.sparkimpl.plugin.filetransfer.transfer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.filechooser.FileSystemView;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import org.jivesoftware.Spark;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatFrame;
import org.jivesoftware.spark.util.WindowsFileSystemView;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
public class Downloads {
final JPanel mainPanel = new JPanel();
private File downloadedDir;
private JPanel list = new JPanel();
private Runtime rt = Runtime.getRuntime();
private static Downloads singleton;
private static final Object LOCK = new Object();
private JFileChooser chooser;
private JDialog dlg;
private static File downloadedDir;
private static JFileChooser chooser;
private LocalPreferences pref;
private Model model;
private File[] file;
private JTable table;
private JScrollPane scroller = new JScrollPane();
private File dir = new File(SettingsManager.getLocalPreferences().getDownloadDir());
private ImageIcon icon = SparkRes.getImageIcon("LEFT_ARROW_IMAGE");
private JButton backButton = new JButton(icon);
private JTextField path = new JTextField();
private JButton renewExplorer;
private JPopupMenu popup = new JPopupMenu();
private JMenuItem mi_delete = new JMenuItem(Res.getString("menuitem.delete"));
private JMenuItem mi_rename = new JMenuItem(Res.getString("menuitem.rename"));
private JMenuItem mi_open = new JMenuItem(Res.getString("menuitem.open.with"));
/**
* Returns the singleton instance of <CODE>Downloads</CODE>,
* creating it if necessary.
* <p/>
*
* @return the singleton instance of <Code>Downloads</CODE>
*/
public static Downloads getInstance() {
// Synchronize on LOCK to ensure that we don't end up creating
// two singletons.
synchronized (LOCK) {
if (null == singleton) {
Downloads controller = new Downloads();
singleton = controller;
return controller;
}
}
singleton.model.objects = new Object[singleton.dir.listFiles().length][3];
singleton.fillDownloadPanel(singleton.dir);
singleton.updateTable();
if(Spark.isMac())
singleton.openFile(singleton.downloadedDir);
else
singleton.dlg.setVisible(true);
return singleton;
}
private Downloads() {
ChatFrame frame = SparkManager.getChatManager().getChatContainer().getChatFrame();
dlg = new JDialog(SparkManager.getMainWindow(), Res.getString("title.downloads"), false);
dlg.setContentPane(mainPanel);
dlg.pack();
dlg.setSize(600, 550);
dlg.setResizable(true);
dlg.setLocationRelativeTo(frame);
pref = SettingsManager.getLocalPreferences();
public static File getDownloadDirectory() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
downloadedDir = new File(pref.getDownloadDir());
downloadedDir.mkdirs();
path.setText(dir.getAbsolutePath());
path.setEditable(false);
path.setBackground(null);
pref.setDownloadDir(downloadedDir.getAbsolutePath());
SettingsManager.saveSettings();
if(Spark.isLinux())
popup.add(mi_open);
popup.add(mi_rename);
popup.add(mi_delete);
mi_open.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
mi_open();
}
});
mi_rename.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String name = JOptionPane.showInputDialog(Res.getString("title.input.newname"), model.objects[table.getSelectedRow()][1]);
if(name != null)
{
try
{
if(Spark.isLinux())
rt.exec("mv " + model.objects[table.getSelectedRow()][1] + " " + name, null, dir);
else
{
File file = new File(dir.getAbsolutePath() + "\\" + model.objects[table.getSelectedRow()][1]);
boolean isFileRenamed = file.renameTo(new File(dir.getAbsolutePath() + "\\" + name));
if(!isFileRenamed)
{
JOptionPane.showMessageDialog(dlg, Res.getString("title.error.rename.file"));
}
}
updateTable();
}
catch (IOException e1)
{
JOptionPane.showMessageDialog(dlg, Res.getString("title.error.rename.file"));
}
}
}
});
mi_delete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
int loeschen = JOptionPane.showOptionDialog(dlg, Res.getString("title.delete.file"), "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
try
{
if(loeschen == 0)
{
if(Spark.isLinux())
rt.exec("rm -R " + model.objects[table.getSelectedRow()][1], null, dir);
else
{
File file = new File(dir.getAbsolutePath() + "\\" + model.objects[table.getSelectedRow()][1]);
boolean isFileDeleted = file.delete();
if(!isFileDeleted)
{
JOptionPane.showMessageDialog(dlg, Res.getString("title.error.delete.file"));
}
}
}
updateTable();
}
catch (IOException e1)
{
JOptionPane.showMessageDialog(dlg, Res.getString("title.error.delete.file"));
}
}
});
list.setLayout(new BorderLayout());
list.setBackground(Color.white);
JButton refreshTable = new JButton(SparkRes.getImageIcon("REFRESH_IMAGE"));
JPanel UpperPanel = new JPanel();
UpperPanel.add(backButton);
UpperPanel.add(refreshTable);
mainPanel.setLayout(new GridBagLayout());
mainPanel.add(UpperPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
mainPanel.add(path, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
mainPanel.add(list, new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
if(dir.getAbsolutePath().equals(pref.getDownloadDir()))
backButton.setEnabled(false);
backButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String str = dir.getAbsolutePath().replace("\\", "/");
String[] array_str = str.split("/");
if(Spark.isLinux())
str = "/";
else if(!Spark.isLinux())
str = array_str[0] + "/";
for(int i = 1; i < array_str.length-1; i++)
{
str = str + array_str[i] + "/";
}
if(str.equals((pref.getDownloadDir() + "/").replace("\\", "/")))
backButton.setEnabled(false);
else
backButton.setEnabled(true);
path.setText(str);
dir = new File(str);
updateTable();
}
});
renewExplorer = new JButton(Res.getString("button.unset.file.explorer"), SparkRes.getImageIcon(SparkRes.SMALL_DELETE));
if(pref.getFileExplorer() == null || pref.getFileExplorer().equals(""))
renewExplorer.setEnabled(false);
JLabel locationLabel = new JLabel(Res.getString("label.downloads"));
JButton userHomeButton = new JButton(Res.getString("title.downloads"), null);
Action openFolderAction = new AbstractAction() {
/**
*
*/
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
if (!downloadedDir.exists()) {
downloadedDir.mkdirs();
}
showDownloadsDirectory();
}
};
userHomeButton.addActionListener(openFolderAction);
// ---------- Tabelle initialisieren ---------------
initalizeTable();
model.objects = new Object[dir.listFiles().length][3];
fillDownloadPanel(dir);
// -------------------------------------------------------
mainPanel.add(locationLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
mainPanel.add(userHomeButton, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
mainPanel.add(renewExplorer, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
refreshTable.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateTable();
}
});
renewExplorer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
pref.setFileExplorer("");
renewExplorer.setEnabled(false);
}
});
if(Spark.isLinux())
renewExplorer.setVisible(true);
else
{
renewExplorer.setVisible(false);
return downloadedDir;
}
dlg.setVisible(true);
}
public JFileChooser getFileChooser() {
public static JFileChooser getFileChooser() {
if (chooser == null) {
downloadedDir = new File(SparkManager.getUserDirectory(), "downloads");
if (!downloadedDir.exists()) {
@ -308,361 +45,6 @@ public class Downloads {
}
return chooser;
}
private void openFile(File downloadedFile) {
try {
if (Spark.isMac()) {
Runtime.getRuntime().exec("open " + downloadedFile.getCanonicalPath());
}
else if (!Spark.isMac()) {
boolean couldOpenFile = SparkManager.getNativeManager().openFile(downloadedFile);
if(!couldOpenFile)
JOptionPane.showMessageDialog(dlg, Res.getString("title.error.couldnt.open.file"));
}
}
catch (IOException e1) {
Log.error(e1);
}
}
public File getDownloadDirectory() {
return downloadedDir;
}
public void addDownloadPanel(JScrollPane scroller) {
list.add(scroller);
}
public void removeDownloadPanel(JPanel panel) {
list.remove(panel);
list.validate();
list.repaint();
}
public void showDownloadsDirectory() {
downloadedDir = new File(pref.getDownloadDir());
if (!downloadedDir.exists()) {
downloadedDir.mkdirs();
}
if(!Spark.isLinux())
openFile(downloadedDir);
else if(Spark.isLinux())
{
try
{
String str;
if(pref.getFileExplorer() == null || pref.getFileExplorer().equals(""))
{
str = JOptionPane.showInputDialog(Res.getString("title.input.fileexplorer"));
if(str != null)
{
str = str.toLowerCase();
pref.setFileExplorer(str);
}
}
if(pref.getFileExplorer() == null || pref.getFileExplorer().equals(""));
else
{
rt.exec(pref.getFileExplorer() + " " + downloadedDir);
renewExplorer.setEnabled(true);
}
}
catch (IOException e1)
{
JOptionPane.showMessageDialog(dlg, Res.getString("title.error.find.app") );
pref.setFileExplorer("");
renewExplorer.setEnabled(false);
}
/* try
{
Desktop.getDesktop().open(new File(pref.getDownloadDir()));
}
catch (IOException e1)
{
JOptionPane.showMessageDialog(dlg, "Der Dateimanager konnte nicht geöffnet werden!");
}
*/
}
}
public String filesize(File file)
{
float filesize = file.length();
filesize = filesize/1000/1000;
DecimalFormat df = new DecimalFormat( "0.00" );
String s = df.format( filesize );
return s + " MB";
}
public void fillDownloadPanel(File dir)
{
file = dir.listFiles();
int x = 0;
// ----- insert Folders into tablemodel -----
for(int i = 0; i < file.length; i++)
{
if(file[i].isDirectory())
{
model.setValue( SparkRes.getImageIcon("FOLDER_CLOSED"),
file[i],
"", x);
x++;
}
}
// -------------------------------------------
int folder_count = x;
// ----------- Sorting Folders ---------------
String[] str = new String[x];;
for(int i = 0; i < x; i++)
{
str[i] = model.objects[i][1].toString();
}
java.util.Arrays.sort(str, 0, str.length);
for(int i = 0; i < x; i++)
{
model.objects[i][1] = str[i];
}
// ------------------------------------------
int i;
// ----- insert files into tablemodel -------
for(i = 0; i < file.length; i++)
{
if(file[i].isDirectory() == false)
{
FileSystemView view = FileSystemView.getFileSystemView();
ImageIcon icon = (ImageIcon)view.getSystemIcon(file[i]);
model.setValue( icon,
file[i],
filesize(file[i]), x);
x++;
}
}
// ------------------------------------------
// ------------ sorting files ---------------
str = new String[i];
for(int y = folder_count; y < x; y++)
{
str[y] = model.objects[y][1].toString();
}
java.util.Arrays.sort(str, folder_count, str.length);
for(int y = folder_count; y < x; y++)
{
model.objects[y][1] = str[y];
model.objects[y][2] = filesize(new File(dir + "/" + model.objects[y][1].toString()));
model.objects[y][0] = FileSystemView.getFileSystemView().getSystemIcon(new File(dir + "/" + model.objects[y][1].toString()));
}
// ------------------------------------------
}
public void initalizeTable()
{
model = new Model();
table = new JTable( model );
table.getColumn("0").setHeaderValue("");
table.getColumn("1").setHeaderValue(Res.getString("title.file"));
table.getColumn("2").setHeaderValue(Res.getString("title.filesize"));
table.getColumn("").setMaxWidth(20);
table.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e)
{
String name = (String)table.getValueAt(table.getSelectedRow(), 1);
int index_files = 0;
for(int i = 0; i < file.length; i++)
{
if(name.equals(file[i].getName()))
{
index_files = i;
break;
}
}
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2)
{
if(file[index_files].isDirectory())
{
backButton.setEnabled(true);
dir = new File(dir + "/" +file[index_files].getName());
path.setText(dir.getAbsolutePath());
updateTable();
}
else if(!file[index_files].isDirectory())
{
if(Spark.isLinux())
mi_open();
else
openFile(file[index_files]);
}
}
if ((e.getButton() == MouseEvent.BUTTON3)
&& table.getSelectedRow() != -1 && !file[index_files].isDirectory())
{
popup.setLocation(e.getX(), e.getY());
popup.show(table, e.getX(), e.getY());
}
else
popup.setVisible(false);
}
});
table.setDefaultRenderer( Object.class, new Renderer() );
table.add(popup);
scroller.getViewport().add(table);
addDownloadPanel(scroller);
}
public void updateTable()
{
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
model.clear();
fillDownloadPanel(dir);
model.fireTableDataChanged();
}
public void mi_open()
{
String str;
str = JOptionPane.showInputDialog(Res.getString("title.input.openwith"));
if(str != null)
{
str = str.toLowerCase();
try
{
rt.exec(str + " " + model.objects[table.getSelectedRow()][1], null, dir);
}
catch (IOException e1)
{
JOptionPane.showMessageDialog(dlg, Res.getString("title.error.find.app"));
}
}
}
// ----------------------------------------------------------------------------------------
class Model extends AbstractTableModel{
/**
*
*/
private static final long serialVersionUID = 1L;
private Object[][] objects;
public Model()
{
objects = new Object[downloadedDir.listFiles().length][3];
}
public void clear()
{
objects = new Object[dir.listFiles().length][3];
}
// Die Anzahl Columns
public int getColumnCount() {
return 3;
}
// Die Anzahl Rows
public int getRowCount() {
return objects.length;
}
// Die Titel der einzelnen Columns
public String getColumnName(int column) {
return String.valueOf( column );
}
// Der Wert der Zelle (rowIndex, columnIndex)
public Object getValueAt(int rowIndex, int columnIndex) {
return objects[ rowIndex ][ columnIndex ];
}
// Eine Angabe, welchen Typ von Objekten in den Columns angezeigt werden soll
public Class<Object> getColumnClass(int columnIndex) {
return Object.class;
}
public void setValue(ImageIcon icon, File file, String filesize, int rowIndex)
{
objects[rowIndex][0] = icon;
objects[rowIndex][1] = file.getName();
objects[rowIndex][2] = filesize;
}
}
// -------------------------------------------------------------------------------------------
class Renderer extends JLabel implements TableCellRenderer{
/**
*
*/
private static final long serialVersionUID = 1L;
private Color colorSelected = new Color( 200, 200, 255 );
private Color colorNormal = Color.white;
public Renderer(){
setOpaque( true );
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
// die normalen Farben
setForeground( Color.BLACK );
if( hasFocus )
setBackground( colorSelected);
else if( isSelected )
setBackground( colorSelected );
else
setBackground( colorNormal );
setText( null );
setIcon( null );
if( value instanceof Icon )
setIcon( (Icon)value );
else if( value instanceof Boolean ){
if( ((Boolean)value).booleanValue() )
setText( "yes" );
else
setText( "no" );
}
else
try
{
setText( value.toString() );
}
catch (Exception e1)
{
System.out.println(e1);
}
return this;
}
}
}

View File

@ -32,6 +32,7 @@ import org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.Downloads;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@ -218,9 +219,7 @@ public class ReceiveMessage extends JPanel {
transfer = request.accept();
try {
Downloads downloads = Downloads.getInstance();
final File downloadedFile = new File(downloads.getDownloadDirectory(), request.getFileName());
final File downloadedFile = new File(Downloads.getDownloadDirectory(), request.getFileName());
progressBar.setMaximum((int)request.getFileSize());
@ -390,8 +389,7 @@ public class ReceiveMessage extends JPanel {
add(openFileButton, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
add(openFolderButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
Downloads downloads = Downloads.getInstance();
final File downloadedFile = new File(downloads.getDownloadDirectory(), request.getFileName());
final File downloadedFile = new File(Downloads.getDownloadDirectory(), request.getFileName());
openFileButton.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
@ -420,16 +418,9 @@ public class ReceiveMessage extends JPanel {
public void mousePressed(MouseEvent event) {
try {
Downloads downloads = Downloads.getInstance();
if (!Spark.isMac()) {
SparkManager.getNativeManager().openFile(downloads.getDownloadDirectory());
}
else if (Spark.isMac()) {
Runtime.getRuntime().exec("open " + downloads.getDownloadDirectory().getCanonicalPath());
}
}
catch (IOException e1) {
Log.error(e1);
Desktop.getDesktop().open(Downloads.getDownloadDirectory());
} catch (IOException e) {
Log.error(e);
}
}
});
@ -481,18 +472,9 @@ public class ReceiveMessage extends JPanel {
private void openFile(File downloadedFile) {
try {
if (!Spark.isMac()) {
boolean opened = SparkManager.getNativeManager().openFile(downloadedFile);
if (!opened) {
JOptionPane.showMessageDialog(this, Res.getString("title.error"), "No application associated with file type.", JOptionPane.ERROR_MESSAGE);
}
}
else if (Spark.isMac()) {
Runtime.getRuntime().exec("open " + downloadedFile.getCanonicalPath());
}
}
catch (IOException e1) {
Log.error(e1);
Desktop.getDesktop().open(downloadedFile);
} catch (IOException e) {
Log.error(e);
}
}
@ -598,7 +580,7 @@ public class ReceiveMessage extends JPanel {
private static final long serialVersionUID = -3010501340128285438L;
public void actionPerformed(ActionEvent e) {
final JFileChooser chooser = Downloads.getInstance().getFileChooser();
final JFileChooser chooser = Downloads.getFileChooser();
File selectedFile = chooser.getSelectedFile();
if (selectedFile != null) {
selectedFile = new File(selectedFile.getParent(), downloadedFile.getName());

View File

@ -10,25 +10,9 @@
package org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui;
import org.jivesoftware.Spark;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.filetransfer.FileTransfer;
import org.jivesoftware.smackx.filetransfer.FileTransfer.Status;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.FileDragLabel;
import org.jivesoftware.spark.ui.ContactItem;
import org.jivesoftware.spark.ui.ContactList;
import org.jivesoftware.spark.util.ByteFormat;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@ -47,10 +31,25 @@ import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.filetransfer.FileTransfer;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;
import org.jivesoftware.smackx.filetransfer.FileTransfer.Status;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.FileDragLabel;
import org.jivesoftware.spark.ui.ContactItem;
import org.jivesoftware.spark.ui.ContactList;
import org.jivesoftware.spark.util.ByteFormat;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
public class SendMessage extends JPanel {
private static final long serialVersionUID = -4403839897649365671L;
@ -232,18 +231,9 @@ public class SendMessage extends JPanel {
private void openFile(File downloadedFile) {
try {
if (!Spark.isMac()) {
boolean opened = SparkManager.getNativeManager().openFile(downloadedFile);
if (!opened) {
JOptionPane.showMessageDialog(this, Res.getString("title.error"), "No application associated with file type.", JOptionPane.ERROR_MESSAGE);
}
}
else if (Spark.isMac()) {
Runtime.getRuntime().exec("open " + downloadedFile.getCanonicalPath());
}
}
catch (IOException e1) {
Log.error("Exception occured while opening file.", e1);
Desktop.getDesktop().open(downloadedFile);
} catch (IOException e) {
Log.error(e);
}
}

View File

@ -10,23 +10,6 @@
package org.jivesoftware.sparkimpl.plugin.viewer;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.PluginManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.plugin.PublicPlugin;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.URLFileSystem;
import org.jivesoftware.spark.util.log.Log;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
@ -37,10 +20,26 @@ import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.PluginManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.plugin.PublicPlugin;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.URLFileSystem;
import org.jivesoftware.spark.util.log.Log;
public class SparkPlugUI extends JPanel {
private static final long serialVersionUID = -4206533328807591854L;
@ -108,7 +107,7 @@ public class SparkPlugUI extends JPanel {
try {
BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&changeLog=true");
}
catch (IOException e1) {
catch (Exception e1) {
Log.error(e1);
}
}
@ -119,7 +118,7 @@ public class SparkPlugUI extends JPanel {
try {
BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&readme=true");
}
catch (IOException e1) {
catch (Exception e1) {
Log.error(e1);
}
}

View File

@ -459,7 +459,7 @@ public class CheckUpdates {
}
}
catch (IOException e) {
catch (Exception e) {
Log.error(e);
}
UPDATING = false;
@ -580,7 +580,7 @@ public class CheckUpdates {
try {
DiscoverItems items = SparkManager.getSessionManager().getDiscoveredItems();
Iterator iter = items.getItems();
Iterator<DiscoverItems.Item> iter = items.getItems();
while (iter.hasNext()) {
DiscoverItems.Item item = (DiscoverItems.Item)iter.next();
if ("Spark Updater".equals(item.getName())) {