Commit 6c18ec87 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Fixed launcher bugs around drag and drop install of plugins (JM-268, JM-269).


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1298 b35dd754-fafc-0310-a699-88a17e54d16e
parent aef7183f
...@@ -198,9 +198,23 @@ ...@@ -198,9 +198,23 @@
<variables /> <variables />
<customScriptLines /> <customScriptLines />
</unixArchive> </unixArchive>
<win32Archive name="Windows Archive" id="31" mediaFileName="" installDir="%APP_SHORT_NAME%" allLaunchers="false" includedJRE="" manualJREEntry="false">
<selectedLaunchers>
<launcher id="2" />
<launcher id="12" />
<launcher id="15" />
</selectedLaunchers>
<messageSet language="English" />
<exclude>
<entry location="bin/extra" launcher="false" />
<entry location="bin/messenger.bat" launcher="false" />
<entry location="bin/messenger.sh" launcher="false" />
</exclude>
<variables />
</win32Archive>
</mediaSets> </mediaSets>
<buildIds buildAll="true"> <buildIds buildAll="true">
<mediaSet refId="18" /> <mediaSet refId="31" />
</buildIds> </buildIds>
</install4j> </install4j>
...@@ -16,36 +16,27 @@ import javax.swing.JFrame; ...@@ -16,36 +16,27 @@ import javax.swing.JFrame;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants; import java.awt.dnd.*;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* Creates a DroppableFrame. A droppable frame allows for DnD of file objects from the OS onto the actual frame * A droppable frame allows for DnD of file objects from the OS onto the actual
* via <code>File</code> * frame via <code>File</code>.
*/ */
public class DroppableFrame extends JFrame implements DropTargetListener, DragSourceListener, DragGestureListener { public class DroppableFrame extends JFrame implements DropTargetListener, DragSourceListener,
private DropTarget dropTarget = new DropTarget(this, this); DragGestureListener
{
private DragSource dragSource = DragSource.getDefaultDragSource(); private DragSource dragSource = DragSource.getDefaultDragSource();
/** /**
* Creates an Instance of the Droppable Frame. * Creates a droppable rame.
*/ */
public DroppableFrame() { public DroppableFrame() {
new DropTarget(this, this);
dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this); dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
} }
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2005 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.launcher;
import javax.swing.*;
import java.awt.dnd.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.util.List;
import java.util.Iterator;
import java.io.File;
import java.io.IOException;
/**
* A droppable text pane allows for DnD of file objects from the OS onto the actual
* pane via <code>File</code>.
*
* @author Matt Tucker
*/
public abstract class DroppableTextPane extends JTextPane implements DropTargetListener,
DragSourceListener, DragGestureListener
{
private DragSource dragSource = DragSource.getDefaultDragSource();
/**
* Creates a droppable text pane.
*/
public DroppableTextPane() {
new DropTarget(this, this);
dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
}
public void dragDropEnd(DragSourceDropEvent DragSourceDropEvent) {
}
public void dragEnter(DragSourceDragEvent DragSourceDragEvent) {
}
public void dragExit(DragSourceEvent DragSourceEvent) {
}
public void dragOver(DragSourceDragEvent DragSourceDragEvent) {
}
public void dropActionChanged(DragSourceDragEvent DragSourceDragEvent) {
}
public void dragEnter(DropTargetDragEvent dropTargetDragEvent) {
dropTargetDragEvent.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
}
public void dragExit(DropTargetEvent dropTargetEvent) {
}
public void dragOver(DropTargetDragEvent dropTargetDragEvent) {
}
public void dropActionChanged(DropTargetDragEvent dropTargetDragEvent) {
}
public void drop(DropTargetDropEvent dropTargetDropEvent) {
try {
Transferable transferable = dropTargetDropEvent.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
Iterator iterator = fileList.iterator();
while (iterator.hasNext()) {
File file = (File) iterator.next();
if (file.isFile()) {
fileDropped(file);
}
if (file.isDirectory()) {
directoryDropped(file);
}
}
dropTargetDropEvent.getDropTargetContext().dropComplete(true);
}
else {
dropTargetDropEvent.rejectDrop();
}
}
catch (IOException io) {
io.printStackTrace();
dropTargetDropEvent.rejectDrop();
}
catch (UnsupportedFlavorException ufe) {
ufe.printStackTrace();
dropTargetDropEvent.rejectDrop();
}
}
public void dragGestureRecognized(DragGestureEvent dragGestureEvent) {
}
/**
* Notified when a file has been dropped onto the frame.
*
* @param file the file that has been dropped.
*/
public void fileDropped(File file){
}
/**
* Notified when a directory has been dropped onto the frame.
*
* @param file the directory that has been dropped.
*/
public void directoryDropped(File file){
}
}
\ No newline at end of file
...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.launcher; ...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.launcher;
import org.jdesktop.jdic.tray.SystemTray; import org.jdesktop.jdic.tray.SystemTray;
import org.jdesktop.jdic.tray.TrayIcon; import org.jdesktop.jdic.tray.TrayIcon;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.WebManager; import org.jivesoftware.util.WebManager;
import org.jivesoftware.util.XMLProperties; import org.jivesoftware.util.XMLProperties;
...@@ -136,7 +135,6 @@ public class Launcher { ...@@ -136,7 +135,6 @@ public class Launcher {
catch (Exception e) { catch (Exception e) {
} }
mainPanel.setLayout(new BorderLayout()); mainPanel.setLayout(new BorderLayout());
cardPanel.setBackground(Color.white); cardPanel.setBackground(Color.white);
...@@ -312,7 +310,7 @@ public class Launcher { ...@@ -312,7 +310,7 @@ public class Launcher {
// Setup command area // Setup command area
final ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("splash2.gif")); final ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("splash2.gif"));
pane = new JTextPane() { pane = new DroppableTextPane() {
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
final Dimension size = pane.getSize(); final Dimension size = pane.getSize();
...@@ -327,6 +325,13 @@ public class Launcher { ...@@ -327,6 +325,13 @@ public class Launcher {
setOpaque(false); setOpaque(false);
super.paintComponent(g); super.paintComponent(g);
} }
public void fileDropped(File file) {
String fileName = file.getName();
if (fileName.endsWith(".jar") || fileName.endsWith(".war")) {
installPlugin(file);
}
}
}; };
pane.setEditable(false); pane.setEditable(false);
...@@ -391,7 +396,8 @@ public class Launcher { ...@@ -391,7 +396,8 @@ public class Launcher {
while ((c = in.read()) != -1) { while ((c = in.read()) != -1) {
try { try {
StyleConstants.setFontFamily(styles, "courier new"); StyleConstants.setFontFamily(styles, "courier new");
pane.getDocument().insertString(pane.getDocument().getLength(), "" + (char)c, styles); pane.getDocument().insertString(pane.getDocument().getLength(),
"" + (char)c, styles);
} }
catch (BadLocationException e) { catch (BadLocationException e) {
} }
...@@ -492,7 +498,7 @@ public class Launcher { ...@@ -492,7 +498,7 @@ public class Launcher {
final SwingWorker installerThread = new SwingWorker() { final SwingWorker installerThread = new SwingWorker() {
public Object construct() { public Object construct() {
File pluginsDir = new File(JiveGlobals.getHomeDirectory(), "plugins"); File pluginsDir = new File(binDir.getParentFile(), "plugins");
String tempName = plugin.getName() + ".part"; String tempName = plugin.getName() + ".part";
File tempPluginsFile = new File(pluginsDir, tempName); File tempPluginsFile = new File(pluginsDir, tempName);
......
...@@ -243,46 +243,46 @@ public class WebManager extends WebBean { ...@@ -243,46 +243,46 @@ public class WebManager extends WebBean {
} }
/** /**
* Copies the contents at <CODE>src</CODE> to <CODE>dst</CODE>. * Copies the contents at <CODE>src</CODE> to <CODE>dst</CODE>.
*/ */
public static void copy(URL src, File dst) throws IOException { public static void copy(URL src, File dst) throws IOException {
InputStream in = null; InputStream in = null;
OutputStream out = null; OutputStream out = null;
try {
in = src.openStream();
out = new FileOutputStream(dst);
dst.mkdirs();
copy(in, out);
}
finally {
try { try {
in = src.openStream(); if (in != null) {
out = new FileOutputStream(dst); in.close();
dst.mkdirs();
copy(in, out);
}
finally {
try {
if (in != null) in.close();
} }
catch (IOException e) { }
} catch (IOException e) { }
try { try {
if (out != null) out.close(); if (out != null) {
} out.close();
catch (IOException e) {
} }
} }
catch (IOException e) { }
} }
}
/** /**
* Common code for copy routines. By convention, the streams are * Common code for copy routines. By convention, the streams are
* closed in the same method in which they were opened. Thus, * closed in the same method in which they were opened. Thus,
* this method does not close the streams when the copying is done. * this method does not close the streams when the copying is done.
*/ */
private static void copy(InputStream in, OutputStream out) private static void copy(InputStream in, OutputStream out) throws IOException {
throws IOException { byte[] buffer = new byte[4096];
final byte[] buffer = new byte[4096]; while (true) {
while (true) { int bytesRead = in.read(buffer);
final int bytesRead = in.read(buffer); if (bytesRead < 0) {
if (bytesRead < 0) { break;
break;
}
out.write(buffer, 0, bytesRead);
} }
out.write(buffer, 0, bytesRead);
} }
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment