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; 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.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
@ -61,6 +38,29 @@ import javax.swing.JSplitPane;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import javax.swing.JToolBar; 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 * The <code>MainWindow</code> class acts as both the DockableHolder and the proxy
* to the Workspace in Spark. * to the Workspace in Spark.
@ -68,7 +68,9 @@ import javax.swing.JToolBar;
* @version 1.0, 03/12/14 * @version 1.0, 03/12/14
*/ */
public final class MainWindow extends ChatFrame implements ActionListener { public final class MainWindow extends ChatFrame implements ActionListener {
private final Set<MainWindowListener> listeners = new HashSet<MainWindowListener>(); private static final long serialVersionUID = -6062104959613603510L;
private final Set<MainWindowListener> listeners = new HashSet<MainWindowListener>();
private final JMenu connectMenu = new JMenu(); private final JMenu connectMenu = new JMenu();
private final JMenu contactsMenu = new JMenu(); private final JMenu contactsMenu = new JMenu();
@ -324,10 +326,12 @@ public final class MainWindow extends ChatFrame implements ActionListener {
command = starterExe + " \"" + sparkExe + "\""; command = starterExe + " \"" + sparkExe + "\"";
} }
else if (Spark.isLinux()) {
command = Spark.getBinDirectory().getParentFile().getCanonicalPath() + File.separator + "spark";
}
else if (Spark.isMac()) { else if (Spark.isMac()) {
command = "open -a Spark"; command = "open -a Spark";
} }
Runtime.getRuntime().exec(command); Runtime.getRuntime().exec(command);
} }
catch (IOException e) { catch (IOException e) {
@ -383,11 +387,11 @@ public final class MainWindow extends ChatFrame implements ActionListener {
}); });
if (Spark.isWindows()) { if (Spark.isWindows()) {
connectMenu.add(logoutMenuItem); connectMenu.add(logoutMenuItem);
connectMenu.add(logoutWithStatus); connectMenu.add(logoutWithStatus);
} }
connectMenu.addSeparator(); connectMenu.addSeparator();
if (!Spark.isMac()) { if (!Spark.isMac()) {
@ -396,7 +400,9 @@ public final class MainWindow extends ChatFrame implements ActionListener {
Action updateAction = new AbstractAction() { Action updateAction = new AbstractAction() {
public void actionPerformed(ActionEvent actionEvent) { private static final long serialVersionUID = -2159350387773310325L;
public void actionPerformed(ActionEvent actionEvent) {
checkForUpdates(true); checkForUpdates(true);
} }
}; };
@ -406,7 +412,9 @@ public final class MainWindow extends ChatFrame implements ActionListener {
// Add Error Dialog Viewer // Add Error Dialog Viewer
Action viewErrors = new AbstractAction() { Action viewErrors = new AbstractAction() {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -420926784631340112L;
public void actionPerformed(ActionEvent e) {
File logDir = new File(Spark.getLogDirectory(), "errors.log"); File logDir = new File(Spark.getLogDirectory(), "errors.log");
if (!logDir.exists()) { if (!logDir.exists()) {
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "No error logs found.", "Error Log", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "No error logs found.", "Error Log", JOptionPane.INFORMATION_MESSAGE);
@ -420,11 +428,13 @@ public final class MainWindow extends ChatFrame implements ActionListener {
viewErrors.putValue(Action.NAME, Res.getString("menuitem.view.logs")); viewErrors.putValue(Action.NAME, Res.getString("menuitem.view.logs"));
final Action viewHelpGuideAction = new AbstractAction() { final Action viewHelpGuideAction = new AbstractAction() {
public void actionPerformed(ActionEvent actionEvent) { private static final long serialVersionUID = 2680369963282231348L;
public void actionPerformed(ActionEvent actionEvent) {
try { try {
BrowserLauncher.openURL("http://www.igniterealtime.org/builds/spark/docs/spark_user_guide.pdf"); 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); Log.error("Unable to load online help.", e);
} }
} }
@ -453,13 +463,17 @@ public final class MainWindow extends ChatFrame implements ActionListener {
// Register shutdown with the exit menu. // Register shutdown with the exit menu.
exitMenuItem.addActionListener(new AbstractAction() { exitMenuItem.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -2301236575241532698L;
public void actionPerformed(ActionEvent e) {
shutdown(); shutdown();
} }
}); });
helpMenuItem.addActionListener(new AbstractAction() { helpMenuItem.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -1423433460333010339L;
public void actionPerformed(ActionEvent e) {
try { try {
BrowserLauncher.openURL("http://www.igniterealtime.org/forum/forum.jspa?forumID=49"); BrowserLauncher.openURL("http://www.igniterealtime.org/forum/forum.jspa?forumID=49");
} }
@ -471,7 +485,9 @@ public final class MainWindow extends ChatFrame implements ActionListener {
// Show About Box // Show About Box
menuAbout.addActionListener(new AbstractAction() { menuAbout.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -7173666373051354502L;
public void actionPerformed(ActionEvent e) {
showAboutBox(); showAboutBox();
} }
}); });

View File

@ -46,10 +46,13 @@ public class Restarter {
try { try {
String command = ""; String command = "";
if (Spark.isWindows()) { if (isWindows()) {
command = file.getCanonicalPath(); command = file.getCanonicalPath();
} }
else if (Spark.isMac()) { if (isLinux()) {
command = file.getCanonicalPath();
}
else if (isMac()) {
command = "open -a Spark"; command = "open -a Spark";
} }
@ -60,7 +63,47 @@ 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; package org.jivesoftware.spark;
import java.awt.Window; import java.awt.Window;
import java.io.File;
/** /**
* Implementations of this interface define native mechanisms based on the Operating System * Implementations of this interface define native mechanisms based on the Operating System
@ -48,31 +47,4 @@ public interface NativeHandler {
* @return true to handle. * @return true to handle.
*/ */
boolean handleNotification(); 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.Iterator;
import java.util.List; import java.util.List;
import javax.swing.SwingUtilities;
/** /**
* The AlertManager handles the delegation of Alerting based. * 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; 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.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; 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 * The <code>LinkLabel</code> class is a JLabel subclass
@ -29,8 +28,9 @@ import java.io.IOException;
* @author Derek DeMoro * @author Derek DeMoro
*/ */
final public class LinkLabel extends JLabel implements MouseListener { final public class LinkLabel extends JLabel implements MouseListener {
// cursors used in url-link related displays and default display 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 DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR); private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR);
private Color rolloverTextColor; private Color rolloverTextColor;
@ -75,7 +75,7 @@ final public class LinkLabel extends JLabel implements MouseListener {
try { try {
BrowserLauncher.openURL(labelURL); BrowserLauncher.openURL(labelURL);
} }
catch (IOException e) { catch (Exception e) {
Log.error(e); Log.error(e);
} }
} }

View File

@ -56,6 +56,7 @@ import java.awt.AWTException;
import java.awt.Component; import java.awt.Component;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.FileDialog; import java.awt.FileDialog;
import java.awt.Frame; import java.awt.Frame;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
@ -177,8 +178,12 @@ public class SparkTransferManager {
ResourceUtils.resButton(downloadsMenu, Res.getString("menuitem.view.downloads")); ResourceUtils.resButton(downloadsMenu, Res.getString("menuitem.view.downloads"));
actionsMenu.add(downloadsMenu); actionsMenu.add(downloadsMenu);
downloadsMenu.addActionListener(new ActionListener() { downloadsMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { 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() { contactList.addFileDropListener(new FileDropListener() {
public void filesDropped(Collection files, Component component) { public void filesDropped(Collection<File> files, Component component) {
if (component instanceof ContactItem) { if (component instanceof ContactItem) {
ContactItem item = (ContactItem)component; ContactItem item = (ContactItem)component;
ChatRoom chatRoom = null; ChatRoom chatRoom = null;
for (Object file : files) { for (File file : files) {
chatRoom = sendFile((File) file, item.getJID()); chatRoom = sendFile(file, item.getJID());
} }
if (chatRoom != null) { if (chatRoom != null) {
@ -231,8 +236,12 @@ public class SparkTransferManager {
viewDownloads.setToolTipText(Res.getString("menuitem.view.downloads")); viewDownloads.setToolTipText(Res.getString("menuitem.view.downloads"));
commandPanel.add(viewDownloads); commandPanel.add(viewDownloads);
viewDownloads.addActionListener(new ActionListener() { viewDownloads.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { 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); ArrayList<File> list = waitMap.get(bareJID);
if (list != null) { if (list != null) {
// Iterate through list and send. // Iterate through list and send.
Iterator iter = list.iterator(); Iterator<File> iter = list.iterator();
ChatRoom room = null; ChatRoom room = null;
while (iter.hasNext()) { while (iter.hasNext()) {
File file = (File)iter.next(); File file = iter.next();
room = sendFile(file, bareJID); room = sendFile(file, bareJID);
} }

View File

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

View File

@ -11,6 +11,7 @@
package org.jivesoftware.spark.ui; package org.jivesoftware.spark.ui;
import java.awt.Component; import java.awt.Component;
import java.io.File;
import java.util.Collection; import java.util.Collection;
/** /**
@ -28,6 +29,6 @@ public interface FileDropListener {
* @param files the Collection of Files. * @param files the Collection of Files.
* @param component the Component the files were dropped on. * @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; 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.resource.SparkRes;
import org.jivesoftware.smackx.packet.VCard; import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.spark.SparkManager; 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.ModelUtil;
import org.jivesoftware.spark.util.log.Log; 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. * UI to display VCard Information in Wizards, Dialogs, Chat Rooms and any other container.
* *
@ -41,7 +45,8 @@ import javax.swing.JPanel;
*/ */
public class VCardPanel extends JPanel { public class VCardPanel extends JPanel {
private Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR); private static final long serialVersionUID = -5810110243694315630L;
private Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR); private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR);
private final String jid; private final String jid;
@ -185,7 +190,15 @@ public class VCardPanel extends JPanel {
} }
private void startEmailClient(String emailAddress) { 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.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font; import java.awt.Font;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
@ -28,6 +29,9 @@ import java.awt.Image;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Icon; import javax.swing.Icon;
@ -42,7 +46,8 @@ import javax.swing.JPanel;
*/ */
public class VCardViewer extends JPanel { public class VCardViewer extends JPanel {
private Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR); private static final long serialVersionUID = -5642099937626355102L;
private Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR);
private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR); private Cursor LINK_CURSOR = new Cursor(Cursor.HAND_CURSOR);
private final String jid; private final String jid;
@ -249,7 +254,13 @@ public class VCardViewer extends JPanel {
private void startEmailClient(String emailAddress) { 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,7 +132,9 @@ public final class InputTextAreaDialog implements PropertyChangeListener {
* Move to focus forward action. * Move to focus forward action.
*/ */
public Action nextFocusAction = new AbstractAction("Move Focus Forwards") { public Action nextFocusAction = new AbstractAction("Move Focus Forwards") {
public void actionPerformed(ActionEvent evt) { private static final long serialVersionUID = 1238373124060258519L;
public void actionPerformed(ActionEvent evt) {
((Component)evt.getSource()).transferFocus(); ((Component)evt.getSource()).transferFocus();
} }
}; };
@ -141,18 +143,20 @@ public final class InputTextAreaDialog implements PropertyChangeListener {
* Moves the focus backwards in the dialog. * Moves the focus backwards in the dialog.
*/ */
public Action prevFocusAction = new AbstractAction("Move Focus Backwards") { public Action prevFocusAction = new AbstractAction("Move Focus Backwards") {
public void actionPerformed(ActionEvent evt) { private static final long serialVersionUID = 7927553016576134725L;
public void actionPerformed(ActionEvent evt) {
((Component)evt.getSource()).transferFocusBackward(); ((Component)evt.getSource()).transferFocusBackward();
} }
}; };
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
String value = (String)optionPane.getValue(); String value = (String)optionPane.getValue();
if ("Cancel".equals(value)) { if (Res.getString("cancel").equals(value)) {
stringValue = null; stringValue = null;
dialog.setVisible(false); dialog.setVisible(false);
} }
else if ("Ok".equals(value)) { else if (Res.getString("ok").equals(value)) {
stringValue = textArea.getText(); stringValue = textArea.getText();
if (stringValue.trim().length() == 0) { if (stringValue.trim().length() == 0) {
stringValue = null; stringValue = null;

View File

@ -10,6 +10,19 @@
package org.jivesoftware.sparkimpl.plugin.bookmarks; 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.resource.SparkRes;
import org.jivesoftware.smackx.bookmark.BookmarkedConference; import org.jivesoftware.smackx.bookmark.BookmarkedConference;
import org.jivesoftware.smackx.bookmark.BookmarkedURL; import org.jivesoftware.smackx.bookmark.BookmarkedURL;
@ -18,26 +31,13 @@ import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.SwingWorker; import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log; 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 { public class BookmarkItem extends JPanel {
private JLabel imageLabel; private static final long serialVersionUID = -3120765894005887305L;
private JLabel imageLabel;
private JLabel nameLabel; private JLabel nameLabel;
private JLabel descriptionLabel; private JLabel descriptionLabel;
@ -70,11 +70,13 @@ public class BookmarkItem extends JPanel {
descriptionLabel.setText(bookmark.getURL()); descriptionLabel.setText(bookmark.getURL());
action = new AbstractAction() { action = new AbstractAction() {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 6986851628853679682L;
public void actionPerformed(ActionEvent e) {
try { try {
BrowserLauncher.openURL(bookmark.getURL()); BrowserLauncher.openURL(bookmark.getURL());
} }
catch (IOException e1) { catch (Exception e1) {
Log.error(e1); Log.error(e1);
} }
} }
@ -86,7 +88,9 @@ public class BookmarkItem extends JPanel {
nameLabel.setText(bookmark.getName()); nameLabel.setText(bookmark.getName());
descriptionLabel.setText(bookmark.getJid()); descriptionLabel.setText(bookmark.getJid());
action = new AbstractAction() { action = new AbstractAction() {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 4324785627112595384L;
public void actionPerformed(ActionEvent e) {
SwingWorker worker = new SwingWorker() { SwingWorker worker = new SwingWorker() {
public Object construct() { public Object construct() {
try { try {

View File

@ -10,6 +10,14 @@
package org.jivesoftware.sparkimpl.plugin.bookmarks; 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.Res;
import org.jivesoftware.resource.SparkRes; import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPException; 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.TaskEngine;
import org.jivesoftware.spark.util.log.Log; 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. * Allows for adding and removal of Bookmarks within Spark.
*/ */
@ -76,11 +75,13 @@ public class BookmarkPlugin implements Plugin {
final BookmarkedURL link = (BookmarkedURL) bookmarkedLink; final BookmarkedURL link = (BookmarkedURL) bookmarkedLink;
Action urlAction = new AbstractAction() { Action urlAction = new AbstractAction() {
public void actionPerformed(ActionEvent actionEvent) { private static final long serialVersionUID = 4246574779205966917L;
public void actionPerformed(ActionEvent actionEvent) {
try { try {
BrowserLauncher.openURL(link.getURL()); BrowserLauncher.openURL(link.getURL());
} }
catch (IOException e) { catch (Exception e) {
Log.error(e); Log.error(e);
} }
} }
@ -96,7 +97,9 @@ public class BookmarkPlugin implements Plugin {
final BookmarkedConference conferences = (BookmarkedConference) bookmarkedConference; final BookmarkedConference conferences = (BookmarkedConference) bookmarkedConference;
Action conferenceAction = new AbstractAction() { Action conferenceAction = new AbstractAction() {
public void actionPerformed(ActionEvent actionEvent) { private static final long serialVersionUID = 5964584172262968704L;
public void actionPerformed(ActionEvent actionEvent) {
final TimerTask task = new SwingTimerTask() { final TimerTask task = new SwingTimerTask() {
public void doRun() { public void doRun() {
ConferenceUtils.joinConferenceOnSeperateThread(conferences.getName(), conferences.getJid(), conferences.getPassword()); ConferenceUtils.joinConferenceOnSeperateThread(conferences.getName(), conferences.getJid(), conferences.getPassword());

View File

@ -10,292 +10,29 @@
package org.jivesoftware.sparkimpl.plugin.filetransfer.transfer; 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.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.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.Spark;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.SparkManager; import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.ui.ChatFrame;
import org.jivesoftware.spark.util.WindowsFileSystemView; 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.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager; import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
public class Downloads { public class Downloads {
final JPanel mainPanel = new JPanel(); private static File downloadedDir;
private File downloadedDir; private static JFileChooser chooser;
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 LocalPreferences pref; public static File getDownloadDirectory() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
private Model model; downloadedDir = new File(pref.getDownloadDir());
private File[] file; downloadedDir.mkdirs();
private JTable table;
private JScrollPane scroller = new JScrollPane(); return downloadedDir;
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;
} }
public static JFileChooser getFileChooser() {
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();
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);
}
dlg.setVisible(true);
}
public JFileChooser getFileChooser() {
if (chooser == null) { if (chooser == null) {
downloadedDir = new File(SparkManager.getUserDirectory(), "downloads"); downloadedDir = new File(SparkManager.getUserDirectory(), "downloads");
if (!downloadedDir.exists()) { if (!downloadedDir.exists()) {
@ -308,361 +45,6 @@ public class Downloads {
} }
return chooser; 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.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font; import java.awt.Font;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
@ -218,9 +219,7 @@ public class ReceiveMessage extends JPanel {
transfer = request.accept(); transfer = request.accept();
try { try {
final File downloadedFile = new File(Downloads.getDownloadDirectory(), request.getFileName());
Downloads downloads = Downloads.getInstance();
final File downloadedFile = new File(downloads.getDownloadDirectory(), request.getFileName());
progressBar.setMaximum((int)request.getFileSize()); 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(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)); 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() { openFileButton.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
@ -419,18 +417,11 @@ public class ReceiveMessage extends JPanel {
} }
public void mousePressed(MouseEvent event) { public void mousePressed(MouseEvent event) {
try { try {
Downloads downloads = Downloads.getInstance(); Desktop.getDesktop().open(Downloads.getDownloadDirectory());
if (!Spark.isMac()) { } catch (IOException e) {
SparkManager.getNativeManager().openFile(downloads.getDownloadDirectory()); Log.error(e);
} }
else if (Spark.isMac()) {
Runtime.getRuntime().exec("open " + downloads.getDownloadDirectory().getCanonicalPath());
}
}
catch (IOException e1) {
Log.error(e1);
}
} }
}); });
@ -480,20 +471,11 @@ public class ReceiveMessage extends JPanel {
} }
private void openFile(File downloadedFile) { private void openFile(File downloadedFile) {
try { try {
if (!Spark.isMac()) { Desktop.getDesktop().open(downloadedFile);
boolean opened = SparkManager.getNativeManager().openFile(downloadedFile); } catch (IOException e) {
if (!opened) { Log.error(e);
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);
}
} }
private class TransferButton extends JButton { private class TransferButton extends JButton {
@ -598,7 +580,7 @@ public class ReceiveMessage extends JPanel {
private static final long serialVersionUID = -3010501340128285438L; private static final long serialVersionUID = -3010501340128285438L;
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
final JFileChooser chooser = Downloads.getInstance().getFileChooser(); final JFileChooser chooser = Downloads.getFileChooser();
File selectedFile = chooser.getSelectedFile(); File selectedFile = chooser.getSelectedFile();
if (selectedFile != null) { if (selectedFile != null) {
selectedFile = new File(selectedFile.getParent(), downloadedFile.getName()); selectedFile = new File(selectedFile.getParent(), downloadedFile.getName());

View File

@ -10,25 +10,9 @@
package org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui; 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.Color;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Font; import java.awt.Font;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
@ -47,10 +31,25 @@ import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JProgressBar; 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 { public class SendMessage extends JPanel {
private static final long serialVersionUID = -4403839897649365671L; private static final long serialVersionUID = -4403839897649365671L;
@ -231,20 +230,11 @@ public class SendMessage extends JPanel {
} }
private void openFile(File downloadedFile) { private void openFile(File downloadedFile) {
try { try {
if (!Spark.isMac()) { Desktop.getDesktop().open(downloadedFile);
boolean opened = SparkManager.getNativeManager().openFile(downloadedFile); } catch (IOException e) {
if (!opened) { Log.error(e);
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);
}
} }
private void updateBar(final OutgoingFileTransfer transfer, String nickname) { private void updateBar(final OutgoingFileTransfer transfer, String nickname) {

View File

@ -10,23 +10,6 @@
package org.jivesoftware.sparkimpl.plugin.viewer; 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.Color;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.Font; import java.awt.Font;
@ -37,10 +20,26 @@ import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; 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 { public class SparkPlugUI extends JPanel {
private static final long serialVersionUID = -4206533328807591854L; private static final long serialVersionUID = -4206533328807591854L;
@ -108,7 +107,7 @@ public class SparkPlugUI extends JPanel {
try { try {
BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&changeLog=true"); BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&changeLog=true");
} }
catch (IOException e1) { catch (Exception e1) {
Log.error(e1); Log.error(e1);
} }
} }
@ -119,7 +118,7 @@ public class SparkPlugUI extends JPanel {
try { try {
BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&readme=true"); BrowserLauncher.openURL("http://www.igniterealtime.org/updater/retrieve.jsp?filename=" + getFilename() + "&readme=true");
} }
catch (IOException e1) { catch (Exception e1) {
Log.error(e1); Log.error(e1);
} }
} }

View File

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